Syntax examples and basic Macro logic

Syntax examples and basic Macro logic
none 0.0 0
  • HMI Model: cMT3072XH
  • OS Version:
  • Serial Number:2206113855

Hello, I need to write a macro to be able to regulate a small pump (0-5v), depending on the readings of another sensor.

I printed out a small PCB board that I can communicate with via MODBUS and then the pump connected to it.

Both the PCB board and the Sensor are communicating via MODBUS everything is working properly.

What I need to do is depending on the sensors reading increase the speed or decrease it.
This would be done by writing in specific values to some registers to the PCB board ( I already tested it with different buttons on the HMI, writing different values with the registers I need and everything works )

I want to write a macro that can automatically depending on the sensors value, it will write the different values to the registers to the PCB board to increase speed or decrease it.

Any syntax examples for macros would be useful.


Hi Gary,

Here is an example that models your application:

macro_command main()
short sensor = 0
short speed = 0
GetData(sensor, "MODBUS TCP/IP", 4x, 15, 1) // Read sensor data from modbus register 4x-15
GetData(speed, "MODBUS TCP/IP", 4x, 27, 1) // Read speed data from modbus register 4x-27
if sensor > 3 then // if sensor input is greater than 3
	speed = speed - 10 // decrease speed by 10
else if sensor < 3 then // if sensor input is less than 3
	speed = speed + 10 // increase speed by 10	
end if

SetData(speed, "MODBUS TCP/IP", 4x, 27, 1) // Write speed data into modbus register 4x-27
end macro_command

Example: What this code looks like within the Macro workspace.

Note: Please ensure that “Periodical execution” is set within your macro.


  1. Macro Basics: Click Here
  2. Macro Logic: Click Here
  3. Macro Functions: Click Here

Hi Brendon,

If I am using MODBUS RTU, should I just replaced MODBUS TCP/IP or would there be more change in the syntax.


Yes, you just need to replace “MODBUS TCP/IP” with the name you gave within the driver list.
By default, “MODBUS RTU” is given to this driver.