How do you chose which slave to control in PyModbus?

131 Views Asked by At

So I'm doing a project where I have a Raspberry Pi 4 as master controlling 4 actuators with Modbus. I'm using PyModbus (with python 3) and I've been using code like this to test the Pi (with a PC slave simulator).

client = ModbusClient(method = "rtu", port="/dev/ttySC0", stopbits = 1, bytesize = 8, parity = 'E' baudrate= 19200)

connection = client.connect()
print(connection)

result = client.read_input_register(1, 1, unit= 0x01)
#client.write_register(address, value, **kwargs)

It's been great so far. But now I've switched from testing with the simulator to testing on the real actuators and I've only just now realized that there doesn't seem to be a way to "switch" the slave you read/write to. Considering I'm aiming for 4 slaves this is a problem.

So after searching online didn't reveal an answer I'm hoping someone here has a solution. I'd rather like to avoid using something other than PyModbus since it took awhile to find a Modbus library that worked for me.

0

There are 0 best solutions below