ModbusSlave¶
Description¶
The ModbusSlave object represents a remote Modbus slave and is instantiated inside an appropriate ModbusClient object. It implements register read and write operations through the Modbus client.
› Inherits: | Object |
---|
Properties¶
address¶
This property holds the address of the Modbus slave. It is also known as slave ID.
› Type: | SignedInteger |
---|---|
› Default: | 0 |
› Signal: | addressChanged() |
› Attributes: | Writable |
client¶
This property holds the Modbus client which to use for reading/writing Modbus requests. If unset, the parent object will be used.
This property was introduced in InCore 2.6.
› Type: | ModbusClient |
---|---|
› Signal: | clientChanged() |
› Attributes: | Writable |
enabled¶
This property holds whether the slave is enabled or not. Polling on registers will only work when enabled is true
.
› Type: | Boolean |
---|---|
› Default: | true |
› Signal: | enabledChanged() |
› Attributes: | Writable |
error¶
This property holds the most recently occurred error or ModbusSlave.NoError if no error occurred. If the same error occurs multiple times this property does not change. Use the errorOccurred() signal to detect multiple occurrences of the same error.
› Type: | Error |
---|---|
› Signal: | errorChanged() |
› Attributes: | Readonly |
errorString¶
This property holds the current human readable error string corresponding to the current value in the error property. It may include additional information such as failure reasons or locations.
› Type: | String |
---|---|
› Signal: | errorStringChanged() |
› Attributes: | Readonly |
interBlockDelay¶
This property holds the delay which between registers pollings. The configured delay applies to all poll modes.
› Type: | SignedInteger |
---|---|
› Default: | 0 |
› Signal: | interBlockDelayChanged() |
› Attributes: | Writable, Optional |
maximumBlockGap¶
This property holds the greatest distance between the addresses of two registers. If the distance does not exceed this value, requests to read individual registers are combined to block read requests. This property has an effect only if pollMode is set to:ref:ModbusSlave.PollRegisterBlocks <enumitem_ModbusSlave_PollRegisterBlocks>.
› Type: | SignedInteger |
---|---|
› Default: | 0 |
› Signal: | maximumBlockGapChanged() |
› Attributes: | Writable, Optional |
maximumBlockLength¶
This property holds the maximum number of modbus registers which are allowed to be combined in one block. Reduce this number if you encounter problems when requesting large register blocks. This property affects requests of combined registers only. If the maximum block length is set lower than a registers count it will be ignored and the ModbusRegister will be polled at one block anyway. This property only has an effect if pollMode is set to ModbusSlave.PollRegisterBlocks.
This property was introduced in InCore 2.1.
› Type: | SignedInteger |
---|---|
› Default: | 128 |
› Signal: | maximumBlockLengthChanged() |
› Attributes: | Writable, Optional |
pollMode¶
This property holds the used poll mode. Setting this property to ModbusSlave.PollRegisterBlocks can save bus traffic by reducing the Modbus protocol overhead of the individual requests.
› Type: | PollMode |
---|---|
› Default: | ModbusSlave.PollSingleRegisters |
› Signal: | pollModeChanged() |
› Attributes: | Writable |
registers¶
This property holds a list of registers to read or write from the Modbus slave.
› Type: | List<ModbusRegister> |
---|---|
› Signal: | registersChanged() |
› Attributes: | Readonly, Requires Polling |
Methods¶
Signals¶
errorOccurred()¶
This signal is emitted whenever an error has occurred, regardless of whether the error property has changed or not. In contrast to the change notification signal of the error property this signal is also emitted several times if a certain error occurs several times in succession.
registersDataChanged(SignedInteger index)¶
This signal is emitted whenever the List.dataChanged() signal is emitted, i.e. the item at index
in the registers list itself emitted the dataChanged() signal.
Enumerations¶
Error¶
This enumeration describes all errors which can occur in ModbusSlave objects. The most recently occurred error is stored in the error property.
Name | Value | Description |
---|---|---|
ModbusSlave.NoError |
0 |
No error occurred or was detected. |
ModbusSlave.InvalidClientError |
1 |
Can’t send requests without a ModbusClient parent. |
ModbusSlave.ClientNotConnectedError |
2 |
Can’t send requests when modbus client is not connected. |
ModbusSlave.ReadError |
3 |
An error occurred while reading data from the Modbus slave. |
ModbusSlave.WriteError |
4 |
An error occurred while writing data to the Modbus slave. |
ModbusSlave.RequestError |
5 |
A general error occurred while sending a request to the Modbus slave. |
ModbusSlave.RegisterTypeError |
6 |
Can’t send requests; ModbusRegister type is InvalidType. |
Example¶
import InCore.Foundation 2.5
import InCore.Modbus 2.5
Application {
name: "Modbus slave example"
ModbusRtuMaster {
ModbusSlave {
address: 1
pollMode: ModbusSlave.PollSingleRegisters //default
interBlockDelay: 100
// each register will be polled with a delay of 100 ms
// read temperature from input register 7
ModbusRegister {
id: temperature1
type: ModbusRegister.Input
dataType: ModbusRegister.UnsignedSmallInteger
address: 7
onDataChanged: console.log("Temperature1", data)
}
ModbusRegister {
id: humidity1
type: ModbusRegister.Input
dataType: ModbusRegister.Float
address: 10
count: 2
onDataChanged: console.log("Humidity1", data)
}
}
ModbusSlave {
address: 2
pollMode: ModbusSlave.PollRegisterBlocks
maximumBlockGap: 2
// both registers will be polled in one request
// this can reduce traffic significantly if the registers are nearby
// read temperature from input register 7
ModbusRegister {
id: temperature2
type: ModbusRegister.Input
dataType: ModbusRegister.UnsignedSmallInteger
address: 7
onDataChanged: console.log("Temperature2", data)
}
ModbusRegister {
id: humidity2
type: ModbusRegister.Input
dataType: ModbusRegister.Float
address: 10
count: 2
onDataChanged: console.log("Humidity2", data)
}
}
// read all registers from all slaves every 5 seconds
Polling on slaves { interval: 5000 }
}
}