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: register_qty do not works on the read_holding_registers() #25

Closed
beyonlo opened this issue Nov 11, 2022 · 1 comment
Closed

Bug: register_qty do not works on the read_holding_registers() #25

beyonlo opened this issue Nov 11, 2022 · 1 comment
Assignees
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:

The register_qty do not works on the read_holding_registers():

>>> host.read_holding_registers(slave_addr=10, starting_addr=93, register_qty=1, signed=False)
(19,)
>>> host.read_holding_registers(slave_addr=10, starting_addr=93, register_qty=2, signed=False)
(19,) <-- I believe that here should be (19, 786) - register address 93 and 94
>>> host.read_holding_registers(slave_addr=10, starting_addr=94, register_qty=2, signed=False)
(786,)
>>> 

Using this register_definitions:
{'COILS': {'EXAMPLE_COIL': {'register': 123, 'len': 3, 'val': [1, 1, 1]}}, 'HREGS': {'EXAMPLE_HREG': {'register': 93, 'len': 4, 'val': 19}, 'EXAMPLE_HREG_2': {'register': 94, 'len': 2, 'val': 786}}, 'ISTS': {'EXAMPLE_ISTS': {'register': 67, 'len': 1, 'val': [1, 0, 0, 1]}}, 'IREGS': {'EXAMPLE_IREG': {'register': 10, 'len': 2, 'val': 60001}}}

Testing a different register_definitions model:

If I change the register_definitions to this:
{'COILS': {'EXAMPLE_COIL': {'register': 123, 'len': 3, 'val': [1, 1, 1]}}, 'HREGS': {'EXAMPLE_HREG': {'register': 93, 'len': 1, 'val': [19, 23494]}}, 'ISTS': {'EXAMPLE_ISTS': {'register': 67, 'len': 1, 'val': [1, 0, 0, 1]}}, 'IREGS': {'EXAMPLE_IREG': {'register': 10, 'len': 2, 'val': 60001}}}

I have this results:
*1. The register_qty still not works, but when I try to read, address 93, 94 came together
*2. When I try to read/write address 94, I have error
*3. When I try to write address 93, the value on address 94 is lost.

>>> host.read_holding_registers(slave_addr=10, starting_addr=93, register_qty=1, signed=False)
(19, 23494) <-- (1) register_qty is 1, but came 2 address: the 93 and 94
>>> host.read_holding_registers(slave_addr=10, starting_addr=94, register_qty=1, signed=False) <-- (2) 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "umodbus/tcp.py", line 118, in read_holding_registers
  File "umodbus/tcp.py", line 89, in _send_receive
  File "umodbus/tcp.py", line 74, in _validate_resp_hdr
ValueError: slave returned exception code: 131
>>> 
>>> host.read_holding_registers(slave_addr=10, starting_addr=93, register_qty=1, signed=False)
(19, 23494)
>>> 
>>> host.write_single_register(slave_addr=10, register_address=94, register_value=555, signed=False) <-- (2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "umodbus/tcp.py", line 157, in write_single_register
  File "umodbus/tcp.py", line 89, in _send_receive
  File "umodbus/tcp.py", line 74, in _validate_resp_hdr
ValueError: slave returned exception code: 134
>>> host.write_single_register(slave_addr=10, register_address=93, register_value=15, signed=False)
True
>>> host.read_holding_registers(slave_addr=10, starting_addr=93, register_qty=2, signed=False)
(15,) <-- (3) Check que value 23494 was lost
>>> 

Well, in the second test I think that I broken the register_refinitions logic, but I do not know what is the correct rules for it. What is the correct usage on the register definitions?

@brainelectronics
Copy link
Owner

See Modbus Application Protocol section 6.3

Relates to #18

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