.. _object_ModbusTcpServer: :index:`ModbusTcpServer` ------------------------ Description *********** The ModbusTcpServer object implements a :ref:`Modbus server ` which communicates with Modbus masters (clients) via TCP network connections. This object was introduced in InCore 2.0. :**› Inherits**: :ref:`ModbusServer ` Overview ******** Properties ++++++++++ .. hlist:: :columns: 2 * :ref:`networkAddress ` * :ref:`networkPort ` * :ref:`ModbusServer.address ` * :ref:`ModbusServer.registers ` * :ref:`ModbusDevice.activityLed ` * :ref:`ModbusDevice.autoConnect ` * :ref:`ModbusDevice.error ` * :ref:`ModbusDevice.errorString ` * :ref:`ModbusDevice.state ` * :ref:`Object.objectId ` * :ref:`Object.parent ` Methods +++++++ .. hlist:: :columns: 1 * :ref:`ModbusDevice.connectDevice() ` * :ref:`ModbusDevice.disconnectDevice() ` * :ref:`Object.deserializeProperties() ` * :ref:`Object.fromJson() ` * :ref:`Object.serializeProperties() ` * :ref:`Object.toJson() ` Signals +++++++ .. hlist:: :columns: 1 * :ref:`ModbusServer.dataErrorOccurred() ` * :ref:`ModbusServer.mapErrorOccurred() ` * :ref:`ModbusServer.registersDataChanged() ` * :ref:`ModbusDevice.connected() ` * :ref:`ModbusDevice.disconnected() ` * :ref:`ModbusDevice.errorOccurred() ` * :ref:`Object.completed() ` Enumerations ++++++++++++ .. hlist:: :columns: 1 * :ref:`ModbusDevice.BusInterface ` * :ref:`ModbusDevice.Error ` * :ref:`ModbusDevice.State ` Properties ********** .. _property_ModbusTcpServer_networkAddress: .. _signal_ModbusTcpServer_networkAddressChanged: .. index:: single: networkAddress networkAddress ++++++++++++++ This property holds the local network address which to listen on for incoming connections. When set to ``0.0.0.0`` the server will listen on all addresses/interfaces. :**› Type**: String :**› Default**: ``0.0.0.0`` :**› Signal**: networkAddressChanged() :**› Attributes**: Writable .. _property_ModbusTcpServer_networkPort: .. _signal_ModbusTcpServer_networkPortChanged: .. index:: single: networkPort networkPort +++++++++++ This property holds the network port which to listen on for incoming connections. :**› Type**: SignedInteger :**› Default**: ``502`` :**› Signal**: networkPortChanged() :**› Attributes**: Writable .. _example_ModbusTcpServer: Example ******* .. code-block:: qml import InCore.Foundation 2.5 import InCore.Modbus 2.5 Application { name: "Modbus TCP server/client example" Counter { id: counter running: counterEnabledReg.data startValue: 123 } ModbusTcpServer { id: server address: 1 networkPort: 1234 networkAddress: "localhost" // expose 3 values at addresses 2…4 through one register definition ModbusRegister { type: ModbusRegister.Input address: 2 count: 3 data: [ 123, 456, 789 ] } ModbusRegister { id: counterEnabledReg type: ModbusRegister.Holding address: 0 data: false onDataChanged: console.log("Counter enabled:", data) } ModbusRegister { id: counterReg type: ModbusRegister.Input address: 123 data: counter.value } ModbusRegister { id: messageReg type: ModbusRegister.Input address: 0x1000 count: 6 dataType: ModbusRegister.String data: "Hello world!" } onConnected: console.log("Server accepting connections") onErrorOccurred: console.log("Server error:", errorString) } ModbusTcpClient { id: client networkAddress: server.networkAddress networkPort: server.networkPort numberOfRetries: 1 timeout: 500 ModbusSlave { address: server.address ModbusRegister { type: counterEnabledReg.type address: counterEnabledReg.address data: client.state === ModbusTcpClient.ConnectedState } ModbusRegister { type: counterReg.type address: counterReg.address onDataChanged: console.log( "Counter value:", data) } ModbusRegister { type: messageReg.type address: messageReg.address count: messageReg.count dataType: messageReg.dataType onDataChanged: console.log("Message register content:", data) } Polling on registers { interval: 100 } } onConnected: console.log("Connected to Modbus TCP slave") onErrorOccurred: console.log("Client error:", errorString) } }