Skip to content

Commit

Permalink
Merge pull request #1035 from samson0v/master
Browse files Browse the repository at this point in the history
Fixed writing multiple registers for Modbus Connector
  • Loading branch information
imbeacon authored Dec 29, 2022
2 parents 6d9650a + 868ac5f commit 5a47687
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 4 additions & 3 deletions thingsboard_gateway/connectors/modbus/modbus_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 5a47687

Please sign in to comment.