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:
Overview
Properties
Methods
Signals
Enumerations
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:
- › 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:
- › 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:
- › Default:
- › Signal:
pollModeChanged()
- › Attributes:
Writable
pollQueueSizeLimit
This property holds the limit for the internal poll queue. If its size exceeds this value further poll calls are ignored until the queue size is below the limit again.
This property was introduced in InCore 2.8.
- › Type:
SignedInteger
- › Default:
100- › Signal:
pollQueueSizeLimitChanged()
- › Attributes:
Writable
queuePollRequests
This property holds whether to queue poll requests such that a read request is only sent after a previous read request has been replied to or timed out. Consider setting queueWriteRequests to the same value.
This property was introduced in InCore 2.9.
- › Type:
Boolean
- › Default:
false- › Signal:
queuePollRequestsChanged()
- › Attributes:
Writable
queueWriteRequests
This property holds whether to queue write requests such that a write request is only sent after a previous write request has been replied to or timed out. Consider setting queuePollRequests to the same value.
This property was introduced in InCore 2.9.
- › Type:
Boolean
- › Default:
false- › Signal:
queueWriteRequestsChanged()
- › Attributes:
Writable
registers
This property holds a list of registers to read or write from the Modbus slave.
- › Type:
- › Signal:
registersChanged()
- › Attributes:
Readonly, Requires Polling
writeQueueSizeLimit
This property holds the limit for the internal write queue. If its size exceeds this value further write calls are ignored until the queue size is below the limit again.
This property was introduced in InCore 2.9.
- › Type:
SignedInteger
- › Default:
100- › Signal:
writeQueueSizeLimitChanged()
- › Attributes:
Writable
Methods
pollRegisters()
This method polls the registers property. It is called automatically when using a Polling property modifier on this property and usually does not have to be called manually.
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 |
|---|---|---|
|
|
No error occurred or was detected. |
|
|
Can’t send requests without a ModbusClient parent. |
|
|
Can’t send requests when modbus client is not connected. |
|
|
An error occurred while reading data from the Modbus slave. |
|
|
An error occurred while writing data to the Modbus slave. |
|
|
Can’t send requests; ModbusRegister type is InvalidType. |
|
|
A read or write request timed out. |
|
|
The bus is overloaded with requests or timeouts. |
PollMode
This enumeration describes supported modes when using Polling on the registers property.
Name |
Value |
Description |
|---|---|---|
|
|
Each register is polled individually. |
|
|
The slave will group registers in blocks and poll each block. |
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 }
}
}