ModbusRtuSlave

Description

The ModbusRtuSlave object implements a Modbus RTU slave which communicates with a Modbus RTU master via a serial port.

This object was introduced in InCore 2.0.

› Inherits:ModbusServer

Properties

baudRate

This property holds the data baud rate of the serial port used for communicating with the Modbus RTU master.

› Type:SerialPort.BaudRate
› Default:SerialPort.Baud115200
› Signal:baudRateChanged()
› Attributes:Writable

dataBits

This property holds the number of data bits of the serial port used for communicating with the Modbus RTU master.

› Type:SerialPort.DataBits
› Default:SerialPort.Data8
› Signal:dataBitsChanged()
› Attributes:Writable

parity

This property holds the parity mode of the serial port used for communicating with the Modbus RTU master.

› Type:SerialPort.Parity
› Default:SerialPort.NoParity
› Signal:parityChanged()
› Attributes:Writable

portName

This property holds the name of the serial port used for communicating with the Modbus RTU master.

› Type:String
› Signal:portNameChanged()
› Attributes:Writable

stopBits

This property holds the number of stop bits of the serial port used for communicating with the Modbus RTU master.

› Type:SerialPort.StopBits
› Default:SerialPort.OneStop
› Signal:stopBitsChanged()
› Attributes:Writable

Example

import InCore.Foundation 2.5
import InCore.Modbus 2.5
import InCore.IO 2.5

Application {

    name: "Modbus RTU slave example"

    System {
        id: system
        Polling on cpuLoad { }
        Polling on deviceHumidity { }
        Polling on deviceTemperature { }
    }

    LED {
        index: LED.StatusBlue
        value: ledReg.data
    }

    ModbusRtuSlave {
        id: slave
        address: 1
        portName: "ttyO1"
        baudRate: SerialPort.Baud250000

        // expose CPU load as float (address 0+1)
        ModbusRegister {
            type: ModbusRegister.Input
            address: 0
            dataType: ModbusRegister.Float
            count: 2
            data: system.cpuLoad
        }

        // expose device temperature and humidity at address 2+3
        ModbusRegister {
            type: ModbusRegister.Input
            address: 2
            count: 2
            data: [ system.deviceTemperature, system.deviceHumidity ]
        }

        // control blue status LED through coil 0
        ModbusRegister {
            id: ledReg
            type: ModbusRegister.Coil
            address: 0
        }
    }
}