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.
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
SetData(speed, "MODBUS TCP/IP", 4x, 27, 1) // Write speed data into modbus register 4x-27
Example: What this code looks like within the Macro workspace.