Skip to main content

Modbus TCP Master

Driver that creates a Modbus TCP master (client) to communicate with ModBus TCP slaves (servers). The Modbus protocol exchanges information using a request-reply mechanism between a master (client) and a slave (server). The master-slave principle is a model for a communication protocol in which one device (the master) controls one or more other devices (the slaves).

Uses the library pyModbusTCP.

Register NumbersTypeAddressNameData TypeValue Range
1-9999Read-Write%IXStatus/Coil (State controls)bool0 or 1
10001-19999Read-Only%QXInput Contact (State information)bool0 or 1
30001-39999Read-Only%QWInput Registers (Numerical values)uint, word0 to 32767
40001-49999Read-Write%IWHolding Registers (Numerical values)uint, word0 to 32767

Parameters

Aside from the common parameters described in the communication_driver docs, this driver includes:

ParameterDefault ValueDescription
host'127.0.0.1'The slave IP address
port502The slave port to connect to

Setup data

The setup data will give values to the parameters required and will specify the I/O variables info.

{
"parameters": {
"host": "127.0.0.1",
"port": 502
},
"variables": {
"1": {
"datatype": "bool",
"size": 1,
"operation": "write"
},
"10001": {
"datatype": "bool",
"size": 1,
"operation": "read"
},
"30001": {
"datatype": "word",
"size": 1,
"operation": "read"
},
"40001": {
"datatype": "word",
"size": 1,
"operation": "write"
}
}
}
tip

In most cases we recommend using the %QW and %IW addresses (registers 30000 -> 49999) even when dealing with boolean variables, since this allows sending the information of 16 booleans using a single register.

note

The setup_params in the generic PLC components for modbustcp_master will need the following format:

{ "host": "127.0.0.1", "port": 502 }