Skip to content

Commit

Permalink
Allow slave=0 in serial communication. (#2023)
Browse files Browse the repository at this point in the history
* Update test.

* Correct slave=0 in RTU_FRAMER.
  • Loading branch information
janiversen authored Feb 16, 2024
1 parent 0e6ce02 commit 0d00cd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion examples/client_test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,17 @@ async def main(comm: CommType):
async def client_calls(client):
"""Test client API."""
Log.debug("--> Client calls starting.")
_resp = await client.read_holding_registers(address=124, count=4, slave=1)
_resp = await client.read_holding_registers(address=124, count=4, slave=0)

def handle_stub_data(transport: ModbusProtocol, data: bytes):
"""Respond to request at transport level."""
Log.debug("--> stub called with request {}.", data, ":hex")
response = b'\x01\x03\x08\x00\x05\x00\x05\x00\x00\x00\x00\x0c\xd7'

# Multiple send is allowed, to test fragmentation
# for data in response:
# to_send = data.to_bytes()
# transport.transport_send(to_send)
transport.transport_send(response)


Expand Down
3 changes: 2 additions & 1 deletion pymodbus/framer/rtu_framer.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ def buildPacket(self, message):
)
packet += struct.pack(">H", computeCRC(packet))
# Ensure that transaction is actually the slave id for serial comms
message.transaction_id = message.slave_id
if message.slave_id:
message.transaction_id = message.slave_id
return packet

def sendPacket(self, message):
Expand Down

0 comments on commit 0d00cd7

Please sign in to comment.