.. _object_ModbusDevice: :index:`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**: :ref:`Object ` :**› Inherited by**: :ref:`ModbusClient `, :ref:`ModbusRtuMaster `, :ref:`ModbusServer ` Overview ******** Properties ++++++++++ .. hlist:: :columns: 1 * :ref:`activityLed ` * :ref:`autoConnect ` * :ref:`error ` * :ref:`errorString ` * :ref:`state ` * :ref:`Object.objectId ` * :ref:`Object.parent ` Methods +++++++ .. hlist:: :columns: 1 * :ref:`connectDevice() ` * :ref:`disconnectDevice() ` * :ref:`Object.deserializeProperties() ` * :ref:`Object.fromJson() ` * :ref:`Object.serializeProperties() ` * :ref:`Object.toJson() ` Signals +++++++ .. hlist:: :columns: 1 * :ref:`connected() ` * :ref:`disconnected() ` * :ref:`errorOccurred() ` * :ref:`Object.completed() ` Enumerations ++++++++++++ .. hlist:: :columns: 1 * :ref:`BusInterface ` * :ref:`Error ` * :ref:`State ` Properties ********** .. _property_ModbusDevice_activityLed: .. _signal_ModbusDevice_activityLedChanged: .. index:: single: activityLed activityLed +++++++++++ This property holds an LED which to let blink on bus activity. Only supported for Modbus RTU. This property was introduced in InCore 2.8. :**› Type**: :ref:`LED ` :**› Signal**: activityLedChanged() :**› Attributes**: Writable .. _property_ModbusDevice_autoConnect: .. _signal_ModbusDevice_autoConnectChanged: .. index:: single: autoConnect 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 .. _property_ModbusDevice_error: .. _signal_ModbusDevice_errorChanged: .. index:: single: error error +++++ This property holds the most recently occurred error or :ref:`ModbusDevice.NoError ` if no error occurred. If the same error occurs multiple times this property does not change. Use the :ref:`errorOccurred() ` signal to detect multiple occurrences of the same error. :**› Type**: :ref:`Error ` :**› Signal**: errorChanged() :**› Attributes**: Readonly .. _property_ModbusDevice_errorString: .. _signal_ModbusDevice_errorStringChanged: .. index:: single: errorString errorString +++++++++++ This property holds the current human readable error string corresponding to the current value in the :ref:`error ` property. It may include additional information such as failure reasons or locations. :**› Type**: String :**› Signal**: errorStringChanged() :**› Attributes**: Readonly .. _property_ModbusDevice_state: .. _signal_ModbusDevice_stateChanged: .. index:: single: state state +++++ This property holds the current state of the Modbus device. See the :ref:`State ` enumeration for details. :**› Type**: :ref:`State ` :**› Default**: :ref:`ModbusDevice.UnconnectedState ` :**› Signal**: stateChanged() :**› Attributes**: Readonly Methods ******* .. _method_ModbusDevice_connectDevice: .. index:: single: connectDevice connectDevice() +++++++++++++++ This method connects the device or master to the network. If :ref:`autoConnect ` is ``true`` calling this function is not necessary. :**› Returns**: Boolean .. _method_ModbusDevice_disconnectDevice: .. index:: single: disconnectDevice disconnectDevice() ++++++++++++++++++ This method disconnects the device or master from the network. Set :ref:`autoConnect ` to ``false`` to make this function work properly. Signals ******* .. _signal_ModbusDevice_connected: .. index:: single: connected connected() +++++++++++ This signal is emitted when the connection to the network is established. .. _signal_ModbusDevice_disconnected: .. index:: single: disconnected disconnected() ++++++++++++++ This signal is emitted when the connection to the network is lost or closed. .. _signal_ModbusDevice_errorOccurred: .. index:: single: errorOccurred errorOccurred() +++++++++++++++ This signal is emitted whenever an error has occurred, regardless of whether the :ref:`error ` property has changed or not. In contrast to the change notification signal of the :ref:`error ` property this signal is also emitted several times if a certain error occurs several times in succession. Enumerations ************ .. _enum_ModbusDevice_BusInterface: .. index:: single: BusInterface BusInterface ++++++++++++ This enumeration describes supported bus interface types used for Modbus RTU-based communication This enumeration was introduced in InCore 2.8. .. index:: single: ModbusDevice.SerialPort .. index:: single: ModbusDevice.BuiltinRS485 .. index:: single: ModbusDevice.BackplaneBus .. list-table:: :widths: auto :header-rows: 1 * - Name - Value - Description .. _enumitem_ModbusDevice_SerialPort: * - ``ModbusDevice.SerialPort`` - ``0`` - use the serial port as specified in the :ref:`portName ` property. .. _enumitem_ModbusDevice_BuiltinRS485: * - ``ModbusDevice.BuiltinRS485`` - ``1`` - use the builtin RS485 interface (availability depends on hardware type). .. _enumitem_ModbusDevice_BackplaneBus: * - ``ModbusDevice.BackplaneBus`` - ``2`` - use the backplane bus interface (availability depends on hardware type). .. _enum_ModbusDevice_Error: .. index:: single: Error Error +++++ This enumeration describes all possible errors which can occur when connecting to or communicating with other Modbus devices. .. index:: single: ModbusDevice.NoError .. index:: single: ModbusDevice.ReadError .. index:: single: ModbusDevice.WriteError .. index:: single: ModbusDevice.ConnectionError .. index:: single: ModbusDevice.ConfigurationError .. index:: single: ModbusDevice.TimeoutError .. index:: single: ModbusDevice.ProtocolError .. index:: single: ModbusDevice.ReplyAbortedError .. index:: single: ModbusDevice.UnknownError .. index:: single: ModbusDevice.BusOverloadError .. list-table:: :widths: auto :header-rows: 1 * - Name - Value - Description .. _enumitem_ModbusDevice_NoError: * - ``ModbusDevice.NoError`` - ``0`` - No error occurred or was detected. .. _enumitem_ModbusDevice_ReadError: * - ``ModbusDevice.ReadError`` - ``1`` - An error occurred during a read operation. .. _enumitem_ModbusDevice_WriteError: * - ``ModbusDevice.WriteError`` - ``2`` - An error occurred during a write operation. .. _enumitem_ModbusDevice_ConnectionError: * - ``ModbusDevice.ConnectionError`` - ``3`` - An error occurred when attempting to open the serial port or TCP connection. .. _enumitem_ModbusDevice_ConfigurationError: * - ``ModbusDevice.ConfigurationError`` - ``4`` - An error occurred when attempting to set a configuration parameter. .. _enumitem_ModbusDevice_TimeoutError: * - ``ModbusDevice.TimeoutError`` - ``5`` - A timeout occurred during I/O. An I/O operation did not finish within a given time frame. .. _enumitem_ModbusDevice_ProtocolError: * - ``ModbusDevice.ProtocolError`` - ``6`` - A Modbus specific protocol error occurred. .. _enumitem_ModbusDevice_ReplyAbortedError: * - ``ModbusDevice.ReplyAbortedError`` - ``7`` - The reply was aborted due to a disconnection of the device. .. _enumitem_ModbusDevice_UnknownError: * - ``ModbusDevice.UnknownError`` - ``8`` - An unknown error occurred. .. _enumitem_ModbusDevice_BusOverloadError: * - ``ModbusDevice.BusOverloadError`` - ``9`` - The bus is overloaded with requests or timeouts so at least one request has been dropped. .. _enum_ModbusDevice_State: .. index:: single: State State +++++ This enumeration describes all possible states of the Modbus device. .. index:: single: ModbusDevice.UnconnectedState .. index:: single: ModbusDevice.ConnectingState .. index:: single: ModbusDevice.ConnectedState .. index:: single: ModbusDevice.ClosingState .. list-table:: :widths: auto :header-rows: 1 * - Name - Value - Description .. _enumitem_ModbusDevice_UnconnectedState: * - ``ModbusDevice.UnconnectedState`` - ``0`` - The Modbus device is disconnected. .. _enumitem_ModbusDevice_ConnectingState: * - ``ModbusDevice.ConnectingState`` - ``1`` - The Modbus device is being connected. .. _enumitem_ModbusDevice_ConnectedState: * - ``ModbusDevice.ConnectedState`` - ``2`` - The Modbus device is connected. .. _enumitem_ModbusDevice_ClosingState: * - ``ModbusDevice.ClosingState`` - ``3`` - The Modbus device is closing/shutting down.