AdvancedClimateSystems / uModbus

Python implementation of the Modbus protocol.
Mozilla Public License 2.0
211 stars 82 forks source link

Allow clients to select format character themselves based on signess of value. #40

Closed OrangeTux closed 7 years ago

OrangeTux commented 8 years ago

Currently you've to configure whether values are signed or unsigned. The following code results in an IllegalValueError:

conf.SIGNED_VALUES = False

with tcp.Client() as c:
    # Raises IllegalValueError
    c.write_single_register(slave_id=1, address=1, value=-5)

I new option should be introducted: conf.DYNAMIC_SIGNESS. This value, False by default, allows a a client to determine the type character based on the signess of the value that is being written.

conf.DYNAMIC_TYPE_CHAR = True

with tcp.Client() as c:
    # In modbus.functions this call is done: struct.pack('>h', -5)
    c.write_single_register(slave_id=1, address=1, value=-5)

    # In umodbus.functions this call is done: struct.pack('>H', 5)
     c.write_single_register(slave_id=1, address=1, value=-5)
OrangeTux commented 7 years ago

Won't implemented because both sides of the connection has to agree upfront whether values are send signed or unsigned.