Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: error when trying to write multiple registers - host.write_multiple_registers() #23

Closed
beyonlo opened this issue Nov 11, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@beyonlo
Copy link

beyonlo commented Nov 11, 2022

This bug was extracted from PR #10 report, in this reply:

Error when trying to write multiple registers (host.write_multiple_registers())

>>> host.write_single_register(slave_addr=10, register_address=93, register_value=44, signed=False)
True
>>> host.read_holding_registers(slave_addr=10, starting_addr=93, register_qty=1, signed=False)
(44,)
>>> 
>>> host.write_multiple_registers(slave_addr=10, starting_address=93, register_values=[2, -4, 6, -256, 1024], signed=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "umodbus/serial.py", line 291, in write_multiple_registers
  File "umodbus/serial.py", line 173, in _send_receive
  File "umodbus/serial.py", line 190, in _validate_resp_hdr
ValueError: slave returned exception code: 1
>>> 
>>> host.write_multiple_registers(slave_addr=10, starting_address=93, register_values=[2, 1024], signed=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "umodbus/serial.py", line 291, in write_multiple_registers
  File "umodbus/serial.py", line 173, in _send_receive
  File "umodbus/serial.py", line 190, in _validate_resp_hdr
ValueError: slave returned exception code: 1
>>> 

@beyonlo beyonlo changed the title Bug: error when trying to write multiple registers (host.write_multiple_registers()) Bug: error when trying to write multiple registers - host.write_multiple_registers() Nov 11, 2022
@brainelectronics brainelectronics added the bug Something isn't working label Nov 12, 2022
@brainelectronics
Copy link
Owner

See Modbus Application Protocol section 6.12

@brainelectronics
Copy link
Owner

might be connected with this line

val = request.data_as_registers(signed=False)[0]

due to

  • always using signed=False
  • always using only first element of unpacked data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants