Skip to content

Commit

Permalink
First attempt to add new feature to umodbus.client.serial.rtu
Browse files Browse the repository at this point in the history
Sending rtu ADU over tcp socket aka "modbus rtu over tcp"

Should fix AdvancedClimateSystems#91
  • Loading branch information
azat385 committed May 28, 2020
1 parent 749d69f commit 24d4050
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions umodbus/client/serial/rtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,26 @@ def send_message(adu, serial_port):
serial_port.read, expected_response_size - exception_adu_size)

return parse_response_adu(response_error_adu + response_remainder, adu)


def send_message_over_tcp(adu, sock):
""" Send ADU over tcp to server and return parsed response.
:param adu: Request ADU.
:param sock: Sock instance.
:return: Parsed response from server.
"""
sock.sendall(adu)

# Check exception ADU (which is shorter than all other responses) first.
exception_adu_size = 5
response_error_adu = recv_exactly(sock.recv, exception_adu_size)
raise_for_exception_adu(response_error_adu)

expected_response_size = \
expected_response_pdu_size_from_request_pdu(adu[1:-2]) + 3
response_remainder = recv_exactly(
sock.recv, expected_response_size - exception_adu_size)

return parse_response_adu(response_error_adu + response_remainder, adu)

0 comments on commit 24d4050

Please sign in to comment.