Macro Question

Macro Question
none 0.0 0
  • HMI Model: CMT2078X
  • EasyBuilder Pro Version:6.08.02.449

Customer is claiming they have to subtract a value of 1 for the calculation to work otherwise value is off by one. Any idea why?

macro_command main()

int value1 // value1 is a 16bit word
int value2 // value2 is a 16bit word
int result // result is a 16bit word

GetData(value1, “Local HMI”, “Tag_5”, 1) // get value1 from HMI LW0
GetData(value2, “Local HMI”, “Tag_6”, 1) // get value2 from HMI LW1

result = value1 - value2 - 1 // result = value1 - value2

SetData(result, “Local HMI”, “Tag_10”, 1) // put result in LW 10

end macro_command

Hi @SteveV,

I was not able to reproduce this issue, but I suppose it may be at least in part attributed to data overlap, the int data type in our macro work space is used to represent a 32-bit integer. When a variable of an int data type is used within a GetData() command, value1 as in this example will be read from both LW-0 and LW-1 as 2 HMI registers are needed to hold 32-bit data. Can you please change the data type to short and advise if this resolves the issue?

macro_command main()

short value1 // value1 is a 16bit word
short value2 // value2 is a 16bit word
short result // result is a 16bit word

GetData(value1, “Local HMI”, “Tag_5”, 1) // get value1 from HMI LW0
GetData(value2, “Local HMI”, “Tag_6”, 1) // get value2 from HMI LW1

result = value1 - value2 - 1 // result = value1 - value2

SetData(result, “Local HMI”, “Tag_10”, 1) // put result in LW 10

end macro_command