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.

See the diagram below: enter image description here

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
log = logging.getLogger()

from pymodbus.client.sync import ModbusTcpClient as ModbusClient

client = ModbusClient('10.x.x.x1', port=502)


def powerOn():
    for i in range(3):
        client.write_coil(i, True, unit=0x0)
        client.read_coils(i, 1, unit=0x0)

def powerOff():
    for i in range(3):
        client.write_coil(i, False, unit=0x0)
        client.read_coils(i, 1, unit=0x0)



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?

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.