-
Notifications
You must be signed in to change notification settings - Fork 48
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
Add all missing docstrings and typing hints, improve docs, fix some but not all bugs #39
Add all missing docstrings and typing hints, improve docs, fix some but not all bugs #39
Conversation
…ue signing in TCP and Serial modules, contribute to #23
@beyonlo here are some new bugfixes for you to test in 2.1.0-rc15.dev39 😄 and some extended documentation for register usage as well https://micropython-modbus--39.org.readthedocs.build/en/39/USAGE.html#register-usage |
Hi @brainelectronics Thank you for this new release!!
I liked so much the extended docs. I think is missing (as I commented in #24): The 0x05 write_single_coil talk about how to write single Tests reports:
Slave:
Not fixed - still have errors, details below: Master: >>> from umodbus.tcp import TCP as ModbusTCPMaster
>>> host = ModbusTCPMaster(slave_ip='192.168.1.4', slave_port=502, timeout=5)
>>> from umodbus import version
>>> version.__version__
'2.1.0-rc15.dev39'
>>> host.read_coils(slave_addr=10, starting_addr=45, coil_qty=1)
[True] <---- OK
>>> host.read_coils(slave_addr=10, starting_addr=45, coil_qty=4)
[False, False, False, True] <---- OK
>>> host.read_coils(slave_addr=10, starting_addr=45, coil_qty=6)
[False, False, False, False, False, True] <---- OK
>>> host.read_coils(slave_addr=10, starting_addr=45, coil_qty=9)
[False, False, False, False, False, False, False, True] <---- NOT OK, coil_qty=9, but return just 8 COILS
>>> host.read_coils(slave_addr=10, starting_addr=45, coil_qty=16)
[False, False, False, False, False, False, False, True] <---- NOT OK, coil_qty=16, but return just 8 COILS
>>> host.read_coils(slave_addr=10, starting_addr=123, coil_qty=4) <---- NOT OK, Python error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/umodbus/tcp.py", line 364, in read_coils
File "/lib/umodbus/functions.py", line 394, in bytes_to_bool
ValueError: invalid format specifier
>>> host.read_coils(slave_addr=10, starting_addr=123, coil_qty=1) <---- NOT OK, Python error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/umodbus/tcp.py", line 364, in read_coils
File "/lib/umodbus/functions.py", line 394, in bytes_to_bool
ValueError: invalid format specifier
>>> host.read_coils(slave_addr=10, starting_addr=123, coil_qty=10)
[True, False, False, True, True, False, True, True, True, True, True, True, True, True, False, True] <---- NOT OK, coil_qty=10, but return just 16 COILS
>>> host.read_coils(slave_addr=10, starting_addr=123, coil_qty=8)
[True, False, False, True, True, False, True, True, True, True, True, True, True, True, False, True] <---- NOT OK, coil_qty=8, but return just 16 COILS
>>>
>>> host.read_coils(slave_addr=10, starting_addr=124, coil_qty=1)
[True, True, True] <---- NOT OK, coil_qty=1, but return 3 COILS
>>> host.read_coils(slave_addr=10, starting_addr=124, coil_qty=8)
[False, False, False, False, False, True, True, True] <---- OK
>>> host.read_coils(slave_addr=10, starting_addr=124, coil_qty=16)
[False, False, False, False, False, True, True, True] <---- NOT OK, coil_qty=16, but return just 8 COILS
>>>
Works, but have some errors: a) note about that before write multiple Master: >>> host.read_coils(slave_addr=10, starting_addr=124, coil_qty=1)
[True, True, True] <-- read_coils quantity not works, but this test is about writing multiple coils
>>> host.read_coils(slave_addr=10, starting_addr=124, coil_qty=8)
[False, False, False, False, False, True, True, True]
>>> host.write_multiple_coils(slave_addr=10, starting_address=124, output_values=[1,0])
True <--- OK - No errors
>>> host.read_coils(slave_addr=10, starting_addr=124, coil_qty=8)
[False, False, False, False, False, False, False, True] <--- wrote OK - but look that lost that third COIL that was true.
>>>
>>> host.write_multiple_coils(slave_addr=10, starting_address=124, output_values=[1,0,1,1,1])
True <--- OK - No errors
>>> host.read_coils(slave_addr=10, starting_addr=124, coil_qty=1)
[True, True, True, False, True] <--- OK - Values changed to correct value!
>>> host.read_coils(slave_addr=10, starting_addr=123, coil_qty=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/umodbus/tcp.py", line 364, in read_coils
File "/lib/umodbus/functions.py", line 394, in bytes_to_bool
ValueError: invalid format specifier
>>>
>>> host.read_coils(slave_addr=10, starting_addr=123, coil_qty=16)
[True, False, False, True, True, False, True, True, True, True, True, True, True, True, False, True]
>>> host.write_multiple_coils(slave_addr=10, starting_address=123, output_values=[1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1])
True <--- OK - No errors
>>> host.read_coils(slave_addr=10, starting_addr=123, coil_qty=16)
[True, False, True, True, True, True, True, True, True, True, False, True, True, False, True, True] <--- OK - Values changed to correct value, but look that after wrote happen a time, starting to read from inverse list.
Master: a) note that, like as happen with >>> host.read_holding_registers(slave_addr=10, starting_addr=94, register_qty=50, signed=False)
(29, 38, 0, 1600, 2150, 5067, 2564, 8450, 3456)
>>> host.write_multiple_registers(slave_addr=10, starting_address=94, register_values=[2, -4, 6, -256, 1024], signed=True)
True <--- OK wrote with sucess
>>> host.read_holding_registers(slave_addr=10, starting_addr=94, register_qty=50, signed=False)
(2, 65532, 6, 65280, 1024) <--- OK, but the registers 99, 100, 101 and 102 was losted
>>> Good to see that functions 0x0F write_multiple_coils and 0x10 write_multiple_registers starting works! Still there are problems as reported above, but was a good start! Thank you very much! |
@brainelectronics more two things to report in this new version: When I was to try to do that tests over
So, all tests above was done using only the In this new version when I install using upip, it try to install
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hi @beyonlo, as discussed in #22 (comment) a COIL has a length of 1. If you define a COIL 98 with a length of 1, you can only set 98. If you define a length of 2 then coils 98+99 are configured. Due to bug #35 you can only set all coils you defined at once. But if you define a coil 98 with length 1 and another coil 99 with a length of 1 you can modify each coil without affecting any others by write singel coil function 0x05. But with this temporary trick you can not read 98+99 with Regarding the not implemented fix of #36: yes see also #38 Missing Modbus RTU process function, bugfix is on the way |
Remark |
…d discrete inputs partially, contributes to #35
@brainelectronics thank you very much for the clarifications! :) |
Added
host.write_multiple_coils()
#22host.write_multiple_registers()
#23is_bound
property in tcp.pyChanged
data_as_registers
anddata_as_bits
of common.py removed0x01
if a register other than coil or holding register is requested to be set_process_write_access
logic of tcp.pyFixed
write_multiple_registers
) is validated with respect to the providedsigned
flag in serial.py and tcp.py, see Bug: error when trying to write multiple registers -host.write_multiple_registers()
#23host.write_multiple_coils()
#22host.write_multiple_registers()
#23