AdvancedClimateSystems / uModbus

Python implementation of the Modbus protocol.
Mozilla Public License 2.0
211 stars 81 forks source link

Simple TCP server example does not work, always returns error #99

Closed rgov closed 4 years ago

rgov commented 4 years ago

I'm using umodbus 1.0.3 with Python 2.7 (due to an environment that doesn't support Python 3). I started with the example code but then simplified it to tell me if any message is received:

@app.route()
def any_message(*args, **kwargs):
    print(args, kwargs)

I use the modbus_cli command-line program to read coil 3:

client -> server: b9 54 00 00 00 06 ff 01  00 03 00 01               .T...... ....

The server replies back without my route function being invoked:

server -> client: b9 54 00 00 00 03 ff 81  02                        .T...... .

The 81 byte represents an exception, and 02 is "Illegal data address".

rgov commented 4 years ago

The issue is that modbus_cli uses a slave ID of 255 (-1) by default, which the route was not configured to accept.