Modbus
We combined with multithread feature, the Modbus client and server examples into a single project to facilitate testing.
The server is in MainThread, while the client is in ModbusClient; some delay instructions have been added to make the client find the active server.
The example should be run in Run AllThreads.
Modbus Client and Server devices are declared in System.
For the latter, the registers exposed to clients have been added.
Server
The server is started and Holding Register 0 is initialized in Init.
Within Loop, some Coils are cyclically set to 1.
In Finalize, the server is stopped after a short delay to allow the client to finish its read/write operations.
Client
In Init, the client connects to the server after a short delay to allow the server to start up.
In Loop, the value of Coil 0 is cyclically read and inverted. Holding Register 0 is read and compared with a fixed value.
The value of the register is passed as a parameter to IfElse.
If the comparison is successful, the true branch of the instruction IfElse increments it by a fixed value, which is then written back to the same register.
If the comparison is negative, the false branch of the IfElse statement resets the register.
You can always use the Modbus Inspector to read the values.
In Finalize, the client is disconnected.
HMI
To inspect the project's behavior a simple HMI is designed to show the value of some register and can be used to start the project.