Thank you.
This is my mbconfig.cfg file,
Num_Devices = "1"
Polling_Period = "100"
Timeout = "1000"
# ------------
# DEVICE 0
# ------------
device0.name = "Test_1"
device0.slave_id = "1"
device0.protocol = "TCP"
device0.address = "10.135.114.62"
device0.IP_Port = "502"
device0.RTU_Baud_Rate = "115200"
device0.RTU_Parity = "None"
device0.RTU_Data_Bits = "8"
device0.RTU_Stop_Bits = "1"
device0.RTU_TX_Pause = "0"
device0.Discrete_Inputs_Start = "0"
device0.Discrete_Inputs_Size = "8"
device0.Coils_Start = "0"
device0.Coils_Size = "8"
device0.Input_Registers_Start = "0"
device0.Input_Registers_Size = "0"
device0.Holding_Registers_Read_Start = "0"
device0.Holding_Registers_Read_Size = "0"
device0.Holding_Registers_Start = "0"
device0.Holding_Registers_Size = "0"
-------------------------
and in openplc runtime i have selected hardware layer as blank and in slave section i have selected a modbus tcp device (10.135.114.62). In this devices i am running a modbus server code:
# Set up the GPIO pins
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(27, GPIO.IN)
# Initialize the Modbus data store
store = ModbusSlaveContext(
di=ModbusSequentialDataBlock(0, [0]*100),
co=ModbusSequentialDataBlock(0, [0]*100),
hr=ModbusSequentialDataBlock(0, [0]*100),
ir=ModbusSequentialDataBlock(0, [0]*100))
context = ModbusServerContext(slaves=store, single=True)
def run_server():
log.info("Starting Modbus server...")
StartTcpServer(context, identity=identity, address=("0.0.0.0", 502))
def update_gpio():
previous_coil_value = None # Store the last known state of the coil for GPIO 17
previous_gpio_27_state = None # Store the last known state of GPIO 27 input
while True:
# Read coil value at address 0 (controls GPIO 17)
coil = context[0].getValues(5, 0, 1)
if coil[0] != previous_coil_value: # Log and update only if coil state changes
log.info(f"GPIO 17 state changed to: {coil[0]}")
GPIO.output(17, coil[0])
previous_coil_value = coil[0]
# Read the state of GPIO 27 (input pin)
gpio_27_state = GPIO.input(27)
if gpio_27_state != previous_gpio_27_state: # Log only if input state changes
log.info(f"GPIO 27 input state changed to: {gpio_27_state}")
previous_gpio_27_state = gpio_27_state
# Update the Modbus data store with the state of GPIO 27
context[0].setValues(2, 0, [gpio_27_state])
# Add a short delay to reduce CPU usage
time.sleep(0.1)
-----------------------------------------
So where my openplc runtime IX100 and QX100 address is getting mapped with the modbus server code ?