Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed writing multiple registers for Modbus Connector #1035

Merged
merged 1 commit into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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