- HMI Model: CMT-FHDX-820
- EasyBuilder Pro Version: 6.10.01.510
I have a real number (always going to be in decimal format) being pulled from the plc and want to be able to add or subtract to this valve based on a user input. I would prefer using a macro to run the calculation.
I first tried using a float variable for the user input value but negatives (unsigned) are not accepted. It would be ideal if i could use the following: (user input could be either plus or minus)
a + (+/-b) = c
What would be the best approach to achieve this goal?
Hi @outbound6 ,
We recommend using a macro, as you suggested. With a macro, you can pull values from your PLC and store them in a float variable. Then you can also read the user input from a local register.
To obtain a negative float value, I placed a numeric object, selected 32-bit float as the device data format, set 2 digits (or more) to the right of the decimal point, and configured a negative value as the device low limit.
Now, my numeric object can accept negative float values. Macros can then be used to get the values from the user, perform the necessary calculations, and write the result back to a numeric object or a memory address.
Below are the numeric object setup and the macro used.
macro_command main()
float a , b, c
GetData(a, "Local HMI", LW, 10, 1)
GetData(b, "Local HMI", LW, 0, 1)
c = a + b
SetData(c, "Local HMI", LW, 100, 1)
end macro_command