Closed brainelectronics closed 1 year ago
And only the first coil value is correct, the others always appears as false.
And only the first coil value is correct, the others always appears as false.
That's correct @javiercp64 for default definitions example because the len is 1
("len": 1
) for the value 1
("val": 1
), so others bits that are not set, are 0
(False
) by default.
If you change the definitions to set others bit values you will receive True
if you set as 1
. See example below with new definitions - look at "val"
:
register_definitions = { "COILS": { "EXAMPLE_COIL": { "register": 123, "len": 3, "val": [1, 0, 1] } },
Output:
>>> host.read_coils(slave_addr=10, starting_addr=123, coil_qty=3)
[True, False, True, False, False, False, False, False]
>>>
However, the write multiple COILS has a bug, as reported on the PR #10, in this section, item 2
.
As detected by @brainelectronics on the thread https://github.com/brainelectronics/micropython-modbus/pull/10#issuecomment-1203521346 is correct to return always multiple of 8 bits. So is correct when coil_qty=1
returning the 8 bits/elements. But the bug still exists, once that coil_qty=20
is returning just first 8 bits.
host.read_coils(slave_addr=10, starting_addr=123, coil_qty=1)
[True, False, False, False, False, False, False, False] # CORRECT: "coil_qty=1" and showed 8 bits (multiple of 8).
host.read_coils(slave_addr=10, starting_addr=123, coil_qty=20)
[True, False, False, False, False, False, False, False] # NOT CORRECT: "coil_qty=20" showing only first 8 bits.
@brainelectronics Check Implementation to follow requirement of returning multiple coils as requested, see http://www.simplymodbus.ca/FC01.htm
related to #25
As found out during #10 the
coil_qty
parameter of theread_coils
function of TCP and RTU is not working.