ljean / modbus-tk

Create Modbus app easily with Python
Other
566 stars 212 forks source link

Error when writing to high address register #120

Open Grandpa-G opened 4 years ago

Grandpa-G commented 4 years ago

I am trying to write a single integer to register 27301. I get the following error.

2019-12-12 15:21:17,320 INFO modbus-tk.main MainThread connected 2019-12-12 15:21:17,322 DEBUG modbus-tk.on_before_connect MainThread on_before_connect 192.168.1.150 502 2019-12-12 15:21:17,328 DEBUG modbus-tk.on_after_recv MainThread on_after_recv 29 bytes received 2019-12-12 15:21:17,330 INFO modbus-tk.on_after_recv MainThread bytearray(b'\x00\x01\x00\x00\x00\x17\x01\x03\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') 2019-12-12 15:21:17,332 INFO modbus-tk.main MainThread (0, 0, 0, 0, 0, 0, 0, 0, 0, 0) 2019-12-12 15:21:17,335 DEBUG modbus-tk.on_after_recv MainThread on_after_recv 8 bytes received 2019-12-12 15:21:17,337 INFO modbus-tk.on_after_recv MainThread bytearray(b'\x00\x02\x00\x00\x00\x02\x01\x90') Traceback (most recent call last): File "modbus-tk.py", line 74, in <module> main() File "modbus-tk.py", line 51, in main logger.info(master.execute(1, cst.WRITE_MULTIPLE_REGISTERS, 27301, output_value={54})) File "/usr/local/lib/python3.7/dist-packages/modbus_tk/utils.py", line 39, in new raise excpt File "/usr/local/lib/python3.7/dist-packages/modbus_tk/utils.py", line 37, in new ret = fcn(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/modbus_tk/modbus.py", line 309, in execute (return_code, byte_2) = struct.unpack(">BB", response_pdu[0:2]) struct.error: unpack requires a buffer of 2 bytes

the code is

logger.info(master.execute(1, cst.READ_HOLDING_REGISTERS, 27300, 10)) logger.info(master.execute(1, cst.WRITE_MULTIPLE_REGISTERS, 27301, output_value={54})) logger.info(master.execute(1, cst.READ_HOLDING_REGISTERS, 27300, 10))

This works fine for a small address like 920.

What do I do?