Modbus RTU/TCP communication check in CodeSys

Hi everyone,

As I am busy with projects that contain many modbus RTU remote IO’s i was wondering if someone knows the best practices to do the modbus communication check in PLC program. I would like to implement a fallback to the devices if modbus fault occurs and there is no communication with with one of nodes? i would apprecieate if someone can give me some advice.

I thought about whether it might be possible to check via xError, but I haven’t tested it directly myself.

On RTU I would check if xError is TRUE after xTrigger is reset by the function block.

For TCP you can use ComState if you are using the configurator.

Hello

As somebody has mention before, the way to monitor if a slave is alive or not is via the properties of the instance created with the Modbus configurator.

Any slave you declare is a instance of type “ModbusSlaveComPort”

you can fin the declaration at library “IoDrvModbus” and its interface is as shown

Output variable “xError” will become TRUE when communication fails. if you left “Auto-restart communication” check box unchecked, in the Mosbus Master (client)

then you can get the slave back at the poling loop by programming issuing a rise edge at “xAcknowledge” input variable of the corresponding Slave (Server), doing it in ST language may be as simple as following

We used this trick in a project where we may have variable number of slaves and we just want to run time just get into the pooling cycle just some of then.

Best regards.

Hi Guys, thank you for all your responce. Now i get the idea how can i get it done.