user1454201
user1454201

Reputation: 3

Pymodbus serial forwarder with multiple slaves

I am using Pymodbus serial forwarder example which works fine for one serial device. I want to be able to poll more than one device in the bus. As discussed here it seems (and my tests confirm) that the ModbusServerContext does not pass down unit id. Is there any workaround to enable polling of more than one device (say unit ids 1 & 2) in the serial forwarder example?

Upvotes: 0

Views: 614

Answers (2)

Peter
Peter

Reputation: 16

I think the above should be:

store = {
    1: RemoteSlaveContext(client, unit=1),
    2: RemoteSlaveContext(client, unit=2)}
context = ModbusServerContext(slaves=store, single=False)

Since I want to forward all normal addresses, I am doing this:

  store = {unit_number: RemoteSlaveContext(client, unit=unit_number) 
           for unit_number in range(1, 248)}
  context = ModbusServerContext(slaves=store, single=False)

Upvotes: 0

user1454201
user1454201

Reputation: 3

To answer my question, one could use the following:

store = {0x1:RemoteSlaveContext(client),0x2:RemoteSlaveContext(client)}
context = ModbusServerContext(slaves=store, single=False)

With this setup, unit ids are passed down. But till now there is a bug and the response might originate from either (1 or 2) serial unit ids.

Upvotes: 0

Related Questions