0

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.

OverDemon
  • 103
  • 1
  • 3
  • 8
  • Have you tried changing ```unit= 0x01```? (from the pymodbus docs ["unit – The slave unit this request is targeting"](https://pymodbus.readthedocs.io/en/latest/source/library/pymodbus.client.html)). – Brits Jan 16 '20 at 19:56
  • I don't understand your question - can you explain further? You ordinarily "switch" the slave you're writing to by changing its number. The physical device will have a device ID associated with it, and you must know this in advance. Quite often you can set this ID on the device itself. – Hayden Eastwood Jan 28 '20 at 04:04

0 Answers0