AdvancedClimateSystems / uModbus

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

have util.pack_exception_pdu error when function_code is bigger then 16 #69

Closed Blacklagoon21 closed 5 years ago

Blacklagoon21 commented 5 years ago

In function pack_exception_pdu, when function_code is bigger then 16, struct.pack will error return.

:param error_code: Error code.
:param function_code: Function code.
:return: PDU of 2 bytes.
"""
return struct.pack('>BB', function_code + 0x80, error_code)
jaapz commented 5 years ago

According to the modbus specification, the function code should never be larger than 16. How do you propose we fix this? Maybe we should just validate whether the function code is in the list of modbus defined function codes and raise an exception when it's not?

Blacklagoon21 commented 5 years ago

I tried to make same situation for the error. and I realize that choose wrong modbus mode (it was RTU over TCP/IP). and it works on modbus TCP/IP and without any error.