How to select a recipe using a PLC tag

How to select a recipe using a PLC tag
none 0.0 0
  • HMI Model: cMT-FHDX-820
  • EasyBuilder Pro Version: V6.10.01.422 build 2025.07.01

Hello,

I have a recipe application where by I want to used a number within my PLC (integer) to select a hmi recipe that contains this number.

Currently, if I add an entry to my recipe, it’s assigned a selection number automatically on the weintek side. I’m assuming this is the sequential order it was added to the recipe.

However, since this ‘selection’ number does not align with my program number, I want to have an item within my recipe called program number that can assign an integer value and then I want this to be the value used to load my recipe.

So to summarize, currently if I add a new entry to my recipe it might be assigned say 22 as it’s ‘selection’ number. But I need it to be loaded then the PLC sends 234 for example. I want to add an element to my recipe called program number, assign the number 234 to it and then I want this to be the recipe that is loaded when I send 234.

Is a macro the best approach here?

Thanks

Hi @Nortech ,

We recommend that you create your own field like “Recipe ID number” to keep track of the PLC ID number for each entry. Then use a macro to perform a recipe query like SELECT a record WHERE “Recipe ID Number” == “ID”. Below is a forum post that demonstrates this.

How to search for or filter items within a recipe database (Advanced Section)

Thanks Aaron, I’ll give this a try.

Hi Aaron,

Here’s what I have so far:

macro_command main()
//Start of concatonated string
char SQL[100] = “SELECT * FROM Lane1 WHERE GeneralProgramNum LIKE”
char ProductID[4] = {0,0,0,0}

 GetData(ProductID[0] "Local HMI", LW, 1000, 4)
 
 StringCat(ProductID[0],SQL[0])
 
 short n_records = 0

 RecipeQuery(SQL[0], n_records)
 //
 if n_records > 0 then
 	short recordID = 0
 	short i = 0 
 	RecipeQueryGetRecordID(recordID, i)
    SetData(i, "Local HMI", LW, 3000, 1)
 end if	
 
 TRACE("a=%c",ProductID[0])
 //

end macro_command

So what I am trying to do is search in my recipe ‘Lane1’ for GeneralProductID. I am trying to set a value in LW1000 (say 22) and hoping that LW3000 will be set to the recipe that contains GeneralProductID = 22.

It’s compiling fine but I’m struggling with troubleshooting it. I see that there’s some debug file required. Also, I was trying to use the trace instruction to display the values for troubleshooting but not quite sure where this is displayed.

Any pointers? Thanks!

Hi @Nortech ,

The macro looks great!

Below is a post on macro debugging using the Debug Resource and breakpoints. You can set breakpoints throughout the macro and add watch variables to see which values are being populated.

I think this will help speed up your troubleshooting process.

Hi Aaron, Just want to say thanks for the assistance here. It was very good information and all worked in the end.

2 Likes