Skip to content

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.

MQTT

For the latter, the registers exposed to clients have been added.

MQTT

Server

The server is started and Holding Register 0 is initialized in Init.

MQTT

Within Loop, some Coils are cyclically set to 1.

MQTT

In Finalize, the server is stopped after a short delay to allow the client to finish its read/write operations.

MQTT

Client

In Init, the client connects to the server after a short delay to allow the server to start up.

MQTT

In Loop, the value of Coil 0 is cyclically read and inverted. Holding Register 0 is read and compared with a fixed value.

MQTT

The value of the register is passed as a parameter to IfElse.

MQTT

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.

MQTT

If the comparison is negative, the false branch of the IfElse statement resets the register.

MQTT

You can always use the Modbus Inspector to read the values.

MQTT

In Finalize, the client is disconnected.

MQTT

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.

MQTT