I have two Moxa modbuses that I have daisy-chained together, and then connected to my network's ethernet port. The modbuses are hooked up to a control board with LED lights for the coils and buttons for Digital Inputs.
I have setup the modbus device to have a static IP address, and can connect to it from the raspberry pi. I can turn the LEDs on and off BUT only for Modbus A with the code below. I can't seem to access the other modbus unit, and I do not know the unit ID for this device (how can I get a hold of it?)
import time import logging logging.basicConfig() log = logging.getLogger() log.setLevel(logging.DEBUG) from pymodbus.client.sync import ModbusTcpClient as ModbusClient client = ModbusClient('10.x.x.x1', port=502) client.connect() def powerOn(): for i in range(3): client.write_coil(i, True, unit=0x0) client.read_coils(i, 1, unit=0x0) time.sleep(1) def powerOff(): for i in range(3): client.write_coil(i, False, unit=0x0) client.read_coils(i, 1, unit=0x0) time.sleep(1) powerOn() powerOff() client.close()
The Modbus Addressing is setup the following way. With the "Enable Modbus/TCP Slave Protocol" in the top left corner. However, I am not entirely sure how to read these numbers and apply them to the RBP, so could someone give me some guidance in the right direction to access the slave and the master?