Skip to 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 Numbers Type Address Name Data Type Value Range
1-9999 Read-Write %IX Status/Coil (State controls) bool 0 or 1
10001-19999 Read-Only %QX Input Contact (State information) bool 0 or 1
30001-39999 Read-Only %QW Input Registers (Numerical values) uint, word 0 to 32767
40001-49999 Read-Write %IW Holding Registers (Numerical values) uint, word 0 to 32767

Parameters

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

  • host: the slave ip address, default = '127.0.0.1'
  • port: the slave port to connect to, default = 502

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.