Codesys Modbus RTU - when are values read?

I’m working on a small project using a self designed modbus RTU board.

I have set up the modbus connection through the codesys modbus configurator, and use trigger variables to control when to read and write to the registers.
I’m having some trouble with a register that I need to both read and write to.
As it is right now, I trigger a read, look at the data, update the register and trigger a write. However, it seems like the register is read again every time the program loops around, without me triggering it.

Are there any resources that explain how codesys handles this stuff?

If most of your Modbus settings are left to default, the Modbus Channel is getting scanned cyclically. You can change that in the channel settings to “Application” so that you get programmatic control.

image

This lets you use a function block from the auto-added IoDrvModbus library. This ModbusChannel function block is used to select the desired Modbus_Slave, pick the Channel to operate, and then Execute the assigned Modbus function code.

I hope this helps!

–Adam

2 Likes