ModbusRegister¶
Description¶
The ModbusRegister object encapsulates a modbus register or a array of it. This can be used for example to read a character string with 20 characters in 10 consecutive registers. The DataObject.dataType has to be set to work properly. Unlike the default value in the DataObject base class the the data type defaults to DataObject.UnsignedSmallInteger for all ModbusRegister objects. Always check byteOrder and registerOrder if you encounter any problems.
› Inherits: | DataObject |
---|
Properties¶
address¶
This property holds the address of the register to poll.
› Type: | SignedInteger |
---|---|
› Default: | -1 |
› Signal: | addressChanged() |
› Attributes: | Writable |
byteOrder¶
This property holds the byte order which is used to combine two bytes to one 16-bit register. Transmitted data 0xDE 0xAD
would be interpreted as unsigned integer as 57005
(BigEndian) or 44510
(LittleEndian).
› Type: | ByteOrder |
---|---|
› Default: | ModbusRegister.LittleEndian |
› Signal: | byteOrderChanged() |
› Attributes: | Writable |
count¶
This property holds the number of contiguous entries to poll at once. This number has to be a multiple of the size needed by DataObject.dataType to work properly. For example count has to be 2
to poll one single float, for a string containing 5 characters it has to be 3
(2 character per register + 1 padding). Be carefull with byteOrder and registerOrder.
› Type: | SignedInteger |
---|---|
› Default: | 1 |
› Signal: | countChanged() |
› Attributes: | Writable |
enabled¶
This property holds whether the register is enabled. Poll will work only if enabled is true
.
› Type: | Boolean |
---|---|
› Default: | true |
› Signal: | enabledChanged() |
› Attributes: | Writable |
error¶
This property holds the most recently occurred error or ModbusRegister.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 |
registerOrder¶
This property holds the register order which is used when count is greater than 1
. This property is similar to byteOrder but considers the order between the registers.
› Type: | RegisterOrder |
---|---|
› Default: | ModbusRegister.MostSignificantRegisterFirst |
› Signal: | registerOrderChanged() |
› Attributes: | Writable |
type¶
This property holds the type of the register. Writing on input registers is not allowed.
› Type: | Type |
---|---|
› Default: | ModbusRegister.InvalidType |
› Signal: | typeChanged() |
› Attributes: | Writable |
Methods¶
pollData()¶
This method polls the DataObject.data property. It is called automatically when using a Polling property modifier on this property and usually does not have to be called manually.
Signals¶
Enumerations¶
ByteOrder¶
This enumeration describes the supported byte orders.
Name | Value | Description |
---|---|---|
ModbusRegister.BigEndian |
0 |
The Most Significant Byte is stored first (in lowest address). |
ModbusRegister.LittleEndian |
1 |
The Least Significant Byte is stored first. |
Error¶
This enumeration describes all errors which can occur in ModbusRegister objects. The most recently occurred error is stored in the error property.
Name | Value | Description |
---|---|---|
ModbusRegister.NoError |
0 |
No error occurred or was detected. |
ModbusRegister.InvalidSlaveError |
1 |
Can’t send requests without a ModbusSlave parent. |
ModbusRegister.SlaveDisabledError |
2 |
Can’t send requests when ModbusSlave is not enabled. |
ModbusRegister.UnsupportedDataTypeError |
3 |
Selected data type is not supported for Modbus registers. |
RegisterOrder¶
This enumeration describes the supported register orders.
Name | Value | Description |
---|---|---|
ModbusRegister.MostSignificantRegisterFirst |
0 |
The most significant register is stored first (in lowest address). |
ModbusRegister.LeastSignificantRegisterFirst |
1 |
The least significant register is stored first. |
Type¶
This enumeration describes all supported register types
Name | Value | Description |
---|---|---|
ModbusRegister.InvalidType |
0 |
This type is an invalid type. |
ModbusRegister.DiscreteInput |
1 |
1-bit single input. |
ModbusRegister.Coil |
2 |
1-bit input/output. |
ModbusRegister.Input |
3 |
16-bit input only. |
ModbusRegister.Holding |
4 |
16-bit input/output. |
Example¶
import InCore.Foundation 2.5
import InCore.Modbus 2.5
Application {
name: "Modbus register example"
ModbusRtuMaster {
ModbusSlave {
// talk to slave with ID 5
address: 5
// read pressure from input register 7
ModbusRegister {
id: pressure
type: ModbusRegister.Input
// dataType: ModbusRegister.UnsignedSmallInteger - not needed; it is default
address: 7
onDataChanged: console.log("Pressure", data)
}
// define Modbus register for a coil with an imaginary LED
ModbusRegister {
id: led
type: ModbusRegister.Coil
address: 3
}
// read serial number of slave
ModbusRegister {
id: serialNumber
type: ModbusRegister.Holding
dataType: ModbusRegister.String
byteOrder: ModbusRegister.BigEndian
registerOrder: ModbusRegister.LeastSignificantRegisterFirst
address: 200
// read 20 chars packed in 10 x 16-bit
count: 10
onDataChanged: console.log("serial number", data)
}
Polling on registers { interval: 100 }
}
onConnected: {
pressure.pollData()
led.data = true
}
}
}