1

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)
Venki WAR
  • 1,997
  • 4
  • 25
  • 38
user3005949
  • 117
  • 2
  • 12
  • When you are calling write_register with negative values the last parameter (“signed”) must be true. – algrid May 13 '18 at 08:13
  • That worked for using 2 individual write_register commands. Thank, but write_float and write registers have no sign option. Is that just the only way it is ? – user3005949 May 14 '18 at 01:18

0 Answers0