1

我试图使用最小的 modbus 来 write_float 的 PLC 需要交换单词。

我已经使用有效的 Modbus Poll 测试了硬件。Minimal Modbus write_float 也可以使用,但字序错误。我检查了适用于解决方法的 read_float 的文档解决方案。

    "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)"

尝试使用单独的 write_register 作弊也会产生负值错误:

    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"

例如:

Decimal float value of 123.456
with plc1.write_float(28672, 123.456, 2) 

我需要:

Word register 28672 dec-5767 hex word(42 F6) 
Word register 28673 dec17142 hex word(E9 79)

我得到:

Word register 28672 dec 17142 hex word(E9 79)
Word register 28673 dec-5767 hex word(42 F6)
4

0 回答 0