How do I use the Macro MIN() & MAX() command?

How do I use the Macro MIN() & MAX() command?
none 0.0 0
  • HMI Model: CMT-SVR-100
  • OS Version: V6.07.02.320
  • Serial Number: Product is still enroute

I am struggling in the macro manager trying to perform a MIN() and MAX() command. I have 5 PLC tags that I need to determine the minimum value of all 5 tags. I have read through the support document and tried a variety of different macro codes but I either get a syntax error on the array definition line or the macro doesn’t give the correct result.

The value of the tags in the array change from time to time so the minimum value will forever change. I’m not as well versed in macros, thanks!

*To clarify, for the moment I am forcing the values of A thru E with int A=1, B=2, C=3, D=4, E=5 just to get the macro working. Once it works I will used a GET() function to pull the actual tag value to each variable.

macro_command main()

int A=1, B=2, C=3, D=4, E=5
int RESULT

int COg[5] = {A, B, C, D, E}

MIN(COg[0], RESULT, 5)

SetData(RESULT, “Local HMI”, LW, 50, 1)

end macro_command

This macro can work as expected:

macro_command main()

int RESULT

int COg[5] = {1,2,3,4,5} // for testing purposes, {A,B,C,D,E}

MIN(COg[0], RESULT, 5)

SetData(RESULT, “Local HMI”, LW, 50, 1) // please type " "

end macro_command

My original phrasing probably didn’t make sense, but I was able to figure it out as such:

macro_command main()

int RESULT
int COg[5]

COg[0] = 10
COg[1] = 20
COg[2] = 0
COg[3] = 0
COg[4] = 50

MIN(COg[0], RESULT, 5)

SetData(RESULT, “Local HMI”, LW, 50, 1)

end macro_command

My next question on the same note is as you can see above index 2 and 3 are 0 so the MIN()expression will always result in 0 so long as any value in array is 0. How would I go about doing a MIN()>0 function?

Again, the real scenario for this macro the array is not constant and each index points to a GetData() expression for the values.

In the example above I need the MIN() RESULT value to be 10 as it is the lowest value greater than 0.

Thanks!

macro_command main()

int RESULT=0
int COg[5]
int new_COG[5]
short i=0, j=0

FILL(COg[0], 0, 5)
FILL(new_COG[0], 0, 5)

GetData(COg[0], “Local HMI”, LW, 1000, 5) // to retrieve 5 double-word data, assumed all values are positive
//COg[0], COg[1], COg[2], COg[3], COg[4]

for i=0 to 4 step 1

if COg[i]>0 then

new_COG[j]=COg[i]

j=j+1
end if

next

if j>0 then
MIN(new_COG[0], RESULT, j)

SetData(RESULT, “Local HMI”, LW, 50, 1)
end if
end macro_command