The PLC I am trying to use minimal modbus to write_float to needs the words swapped.
I already tested the hardware with Modbus Poll that works. The Minimal Modbus write_float also works, but with the wrong word order. I checked the documentation solution for a read_float that works with workaround.
"Workaround for floats with wrong byte order"
When I try to swap the words before the write_float
I get values that generate an error:
"raise TypeError('The {0} must be numerical.
Given: {1!r}'.format(description, inputvalue))
TypeError: The input value must be numerical.
Given: array([-9.8611155e+32], dtype=float32)"
Trying to cheat with individual write_register also generates an error for negative values:
plc1.write_register(28676, -5767,0,6,False)
"raise ValueError(errortext.format(value, formatstring))
ValueError: The value to send is probably out of range,
as the num-to-bytestring conversion failed. Value: -5767 Struct format
code is: >H"
For example:
Decimal float value of 123.456
with plc1.write_float(28672, 123.456, 2)
I need:
Word register 28672 dec-5767 hex word(42 F6)
Word register 28673 dec17142 hex word(E9 79)
I get:
Word register 28672 dec 17142 hex word(E9 79)
Word register 28673 dec-5767 hex word(42 F6)