ModbusDevice¶
Description¶
The ModbusDevice object is the base class for Modbus client or server implementations. It provides basic communication mechanisms and properties and manages communication-related errors.
This object was introduced in InCore 2.0.
› Inherits: | Object |
---|---|
› Inherited by: | ModbusClient, ModbusRtuMaster, ModbusServer |
Properties¶
autoConnect¶
This property holds whether the device should automatically reconnect if the connection is lost or closed.
› Type: | Boolean |
---|---|
› Default: | true |
› Signal: | autoConnectChanged() |
› Attributes: | Writable |
error¶
This property holds the most recently occurred error or ModbusDevice.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 |
state¶
This property holds the current state of the Modbus device. See the State enumeration for details.
› Type: | State |
---|---|
› Default: | ModbusDevice.UnconnectedState |
› Signal: | stateChanged() |
› Attributes: | Readonly |
Methods¶
connectDevice()¶
This method connects the device or master to the network. If autoConnect is true
calling this function is not necessary.
› Returns: | Boolean |
---|
disconnectDevice()¶
This method disconnects the device or master from the network. Set autoConnect to false
to make this function work properly.
Signals¶
connected()¶
This signal is emitted when the connection to the network is established.
disconnected()¶
This signal is emitted when the connection to the network is lost or closed.
Enumerations¶
Error¶
This enumeration describes all possible errors which can occur when connecting to or communicating with other Modbus devices.
Name | Value | Description |
---|---|---|
ModbusDevice.NoError |
0 |
No error occurred or was detected. |
ModbusDevice.ReadError |
1 |
An error occurred during a read operation. |
ModbusDevice.WriteError |
2 |
An error occurred during a write operation. |
ModbusDevice.ConnectionError |
3 |
An error occurred when attempting to open the serial port or TCP connection. |
ModbusDevice.ConfigurationError |
4 |
An error occurred when attempting to set a configuration parameter. |
ModbusDevice.TimeoutError |
5 |
A timeout occurred during I/O. An I/O operation did not finish within a given time frame. |
ModbusDevice.ProtocolError |
6 |
A Modbus specific protocol error occurred. |
ModbusDevice.ReplyAbortedError |
7 |
The reply was aborted due to a disconnection of the device. |
ModbusDevice.UnknownError |
8 |
An unknown error occurred. |
State¶
This enumeration describes all possible states of the Modbus device.
Name | Value | Description |
---|---|---|
ModbusDevice.UnconnectedState |
0 |
The Modbus device is disconnected. |
ModbusDevice.ConnectingState |
1 |
The Modbus device is being connected. |
ModbusDevice.ConnectedState |
2 |
The Modbus device is connected. |
ModbusDevice.ClosingState |
3 |
The Modbus device is closing/shutting down. |