Assigning string value to HMI variable

Assigning string value to HMI variable
none 5.0 1
  • HMI Model: cMT3072XH
  • EasyBuilder Pro Version: V6.09.02.651

To start off, I am fairly new to the macro editor in EasyBuilder Pro.
I am trying to assign a string value to a variable based on the numeric value in another variable (utilizing a case statement) in a macro, but I keep getting the compile error “error C34: expected constant expression” for the actions in my case statement. Any help would be appreciated.

NOTE, I am also doing this because it seems the Allen Bradley SLC5/03 DH485 driver does not support string addresses. Previously, when using the RS232/DF1 driver, I just did all of this in the PLC and then pulled the data from the string address in the PLC.



macro_command main()

//Initialize variables
int DieRecipeInt = 0
char DieRecipeName[16] = ""

//Pull data from tag containing the die recipe number
GetData(DieRecipeInt, "Local HMI", LW, 24,1)

//Determine which recipe is currently running and fill DieRecipeName with the corresponding recipe name
select case DieRecipeInt
	
	case 1 
		DieRecipeName = "ULTRA SLOW"
		break
		
	case 2
		DieRecipeName = "SLOW"
		break
		
	case 3
		DieRecipeName = "SLOW UP, MID SLOW DOWN"
		break
		
	case 4
		DieRecipeName = "MID-SLOW"
		break
		
	case 5
		DieRecipeName = "SLOW UP, MID DOWN"
		break
		
	case 6
		DieRecipeName = "MEDIUM"
		break
		
	case 7
		DieRecipeName = "MEDIUM-LONG"
		break
		
	case 8
		DieRecipeName = "HIGH-MID"
		break	
		
	case 9
		DieRecipeName = "MID-AGGRESSIVE"
		break
		
	case 10
		DieRecipeName = "SLOW UP, MID SLOW DOWN"
		break
		
	case 11
		DieRecipeName = "MIDD-AGG-LONG"
		break

	case 12
		DieRecipeName = "AGGRESSIVE"
		break
	
	case else
		DieRecipeName = "INVALID RECIPE NAME"
		break
end select

//Send data to HMI variables for display objects
SetData(DieRecipeName, "Local HMI", LW, 25,16)

			
end macro_command

Hi @mb_ppt ,

Thank you for contributing to our forum.
Below, I have updated your macro, and it should work. The main changes are:

  • Switching the “DieRecipeInt” from an INT to a SHORT. INTs are 32-bit and SHORTs are 16-bit; therefore, the variable was previously accessing two LW registers instead of one.

  • Within each case, I defined the recipe name to a char array, cleared out the LW-25 register, and then placed the correct recipe name in LW-25 using the SetData function.

We also wanted to point out that using a word lamp is possible in this scenario if you don’t want to use macros. The word lamp can read the value at LW-24, which will change the state of the word lamp. This can be mapped to a label, which you can then read for your project.

Please let us know if you have any other questions!

macro_command main()

//Initialize variables
short DieRecipeInt = 0 // this needs to be a short 
char clear[16]  = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} // set this to clear out the LW register. 


//Pull data from tag containing the die recipe number
GetData(DieRecipeInt, "Local HMI", LW, 24,1)

//Determine which recipe is currently running and fill DieRecipeName with the corresponding recipe name

select case DieRecipeInt


	case 1 
		char ULTRA[16] = "ULTRA SLOW" // Needs to be a constant varible. 
		SetData(clear[0], "Local HMI", LW, 25, 16) // clear out the lw regiester 
		SetData(ULTRA[0], "Local HMI", LW, 25, 16) // set the value in there. 
		
		break
		
		// Repeat steps. 
		
	case 2
		char SLOW[16] = "SLOW"
		SetData(clear[0], "Local HMI", LW, 25, 16)
		SetData(SLOW[0], "Local HMI", LW, 25, 16)
		break
		

end select



			
end macro_command

Word Lamp Set up


1 Like

Thanks for your help! That is also true, that completely slipped my mind!

1 Like