From 868ac5fe6fe38244a44631f0ebecd8c953288b26 Mon Sep 17 00:00:00 2001 From: samson0v Date: Thu, 29 Dec 2022 14:40:11 +0200 Subject: [PATCH] Fixed writing multiple registers for Modbus Connector --- .../connectors/modbus/bytes_modbus_downlink_converter.py | 2 +- thingsboard_gateway/connectors/modbus/modbus_connector.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/thingsboard_gateway/connectors/modbus/bytes_modbus_downlink_converter.py b/thingsboard_gateway/connectors/modbus/bytes_modbus_downlink_converter.py index c3e550819..bc149557b 100644 --- a/thingsboard_gateway/connectors/modbus/bytes_modbus_downlink_converter.py +++ b/thingsboard_gateway/connectors/modbus/bytes_modbus_downlink_converter.py @@ -102,7 +102,7 @@ def convert(self, config, data): if "Exception" in str(builder): log.exception(builder) builder = str(builder) - # if function_code is 5 , is useing first coils value + # if function_code is 5 , is using first coils value if function_code == 5: if isinstance(builder, list): builder = builder[0] diff --git a/thingsboard_gateway/connectors/modbus/modbus_connector.py b/thingsboard_gateway/connectors/modbus/modbus_connector.py index 9d5e63601..4e16d663b 100644 --- a/thingsboard_gateway/connectors/modbus/modbus_connector.py +++ b/thingsboard_gateway/connectors/modbus/modbus_connector.py @@ -452,7 +452,7 @@ def __function_to_device(device, config): function_code = config.get('functionCode') result = None if function_code == 1: - #why count * 8 ? in my Modbus device one coils is 1bit, tow coils is 2bit,if * 8 can not read right coils + # why count * 8 ? in my Modbus device one coils is 1bit, tow coils is 2bit,if * 8 can not read right coils # result = device.config['available_functions'][function_code](address=config[ADDRESS_PARAMETER], # count=config.get(OBJECTS_COUNT_PARAMETER, # config.get("registersCount", @@ -579,16 +579,17 @@ def __process_request(self, content, rpc_command_config, request_type='RPC'): rpc_command_config[WORD_ORDER_PARAMETER] = device.config.get("wordOrder", "LITTLE") self.__connect_to_current_master(device) - if rpc_command_config.get(FUNCTION_CODE_PARAMETER) in (6, 16): + if rpc_command_config.get(FUNCTION_CODE_PARAMETER) in (5, 6): converted_data = device.config[DOWNLINK_PREFIX + CONVERTER_PARAMETER].convert(rpc_command_config, content) try: rpc_command_config[PAYLOAD_PARAMETER] = converted_data[0] except IndexError and TypeError: rpc_command_config[PAYLOAD_PARAMETER] = converted_data - elif rpc_command_config.get(FUNCTION_CODE_PARAMETER) in (5, 15): + elif rpc_command_config.get(FUNCTION_CODE_PARAMETER) in (15, 16): converted_data = device.config[DOWNLINK_PREFIX + CONVERTER_PARAMETER].convert(rpc_command_config, content) + converted_data.reverse() rpc_command_config[PAYLOAD_PARAMETER] = converted_data try: