gunnaraherman

Programatically Select Recipe

24 posts in this topic

Hello,

I am looking for a way to programatically select a recipe. Any time that a recipe is change or saved, the recipe viewer object always resets its view and selects the first recipe. This will lead to possibly writing the wrong recipe to the controller, as well as frustrate the user if they have to scroll through a hundred items to find the recipe again.

I looked at the VB functions, but the only one I could find that was close was the .SelectedRecipe, which is a read only.

I am using Sysmac Studio v1.1.7, and an NA5 HMI.

Any help would be appreciated.

Share this post


Link to post
Share on other sites

You can set the recipe name or record name as fixed text parameters in your scripts.  The .Selected item is based on the screen object, not the recipe data files.

Share this post


Link to post
Share on other sites

Could you explain this more? Specifically how to set it as fixed parameters in my scripts. You said the .SelectedItem is for the recipe viewer, which is where I would like to programmatically select the recipe. However, I do understand that the method is read only, and not used for setting. 

In my mind, what I think I need to do is before each action that resets the selected recipe is store the recipe in a variable. Then at the end of the Sub, do something like 'rcpViewer.selectedRecipe = varRecipe' - just not a read only method. 

Thanks for the help. 

Edited by gunnaraherman

Share this post


Link to post
Share on other sites

Sounded to me like you were looking for a way to make a specific recipe load without using the screen object.

Look at the built in help on the WriteRecipeToController or ReadRecipeFromController functions for script.  After the command, in parentheses, it wants the name of the recipe object and the name of the record.  Instead of using the settings including .SelectedRecipe, you can enter text there directly in quotes.

Share this post


Link to post
Share on other sites

How I can display selected recipe name in other place? like using dispalydata. It is possible?

Share this post


Link to post
Share on other sites

I have this VB code which fires every time I write a new recipe:

Sub WriteSelectedRecipe()
	Try
		Dim rcpSelectedTemplate As String = GetSelectedRecipeTemplate("Main", "rcpMold")
		Dim rcpSelectedRcp As String = GetSelectedRecipe("Main", "rcpMold")
		
		WriteRecipeToController(rcpSelectedTemplate, rcpSelectedRcp)
		
		NJ1_HMI_Loaded_Program = rcpSelectedRcp 'Selected reciped gets set here
		Global_Sub.ShowSuccessPage("Program '" & rcpSelectedRcp & "' has been written.")
	Catch ex As Exception
		Global_sub.ShowErrorPage(ex.message)
	End Try
End Sub

I created a variable named  NJ1_HMI_Loaded_Program which is set in the above code. You can then use a Data Display control and set the Expression as NJ1_HMI_Loaded_Program.

Hope this helps. 

 

 

 

Share this post


Link to post
Share on other sites

I will get this value after recipe will be save in controller? I try to simulate this but now im only working on HMI. I do not have controller yet. When i do simulation it's not showing recipe name after i click download recipe. It's that's make sens that this will be appear only when value is write in PLC?

Share this post


Link to post
Share on other sites

You should be able to get this value even in Simulation mode. I tested it myself and was able to get it. In the above code, these two lines get the selected recipe template and selected recipe, make sure the parameters are correct.

Dim rcpSelectedTemplate As String = GetSelectedRecipeTemplate("Main", "rcpMold")
Dim rcpSelectedRcp As String = GetSelectedRecipe("Main", "rcpMold")

"Main" is the page name, and "rcpMold" is the name of the recipe viewer object.

I find that looking up the function in Help -> Instruction Help is very helpful in answering any questions about it.

Share this post


Link to post
Share on other sites
WriteRecipeToController(rcpSelectedTemplate, rcpSelectedRcp)
		
		NJ1_HMI_Loaded_Program = rcpSelectedRcp 'Selected reciped gets set here
		Global_Sub.ShowSuccessPage("Program '" & rcpSelectedRcp & "' has been written.")
	Catch ex As Exception
		Global_sub.ShowErrorPage(ex.message)

 

What i should put in "rcpSelectedTemplate" , "rcpSelectedRcp" ? And what suppose to be in this line : Global_Sub.ShowSuccessPage("Program '" & rcpSelectedRcp & "' has been written.") ?

Share this post


Link to post
Share on other sites

I get error in this two lines :

Global_Sub.ShowSuccessPage("Program '" & rcpSelectedRcp & "' has been written.")
	Catch ex As Exception
		Global_sub.ShowErrorPage(ex.message)

Share this post


Link to post
Share on other sites

For now you can remove the Try Catch statement and the Global_Sub references. I was using those as well as the Global_Sub routines to communicate success or errors. If you simply have this inside your subroutine, it should work:

Dim rcpSelectedTemplate As String = GetSelectedRecipeTemplate([name_of_page], [name_of_recipeviewer_object])
Dim rcpSelectedRcp As String = GetSelectedRecipe([name_of_page], [name_of_recipeviewer_object])
		
WriteRecipeToController(rcpSelectedTemplate, rcpSelectedRcp)
		
NJ1_HMI_Loaded_Program = rcpSelectedRcp 

Where NJ1_HMI_Loaded Program is a global string variable.  Use the Watch window or a data display to view the value of the Loaded Program variable.

Share this post


Link to post
Share on other sites

Still not working... maybe my Download recipe function is not working correctly.

Public Sub DownloadRecipe
    WriteRecipeToController(RecipeViewer0.SelectedTemplate, RecipeViewer0.SelectedRecipe)
End Sub

I use this VB code for DownloadRecipe. It is correct? It's seems to be working when i do simulation. Is saving the value and upload the value like a 0.

Edited by marcinmrag

Share this post


Link to post
Share on other sites

The DownloadRecipe appears to be fine. I tested it in Simulation mode and it worked for me. I've attached an image of the value in the watch window. For your DataDisplay, just make sure that the variable is entered as the expression (attached image).

Capture.PNG

Capture_2.PNG

Share this post


Link to post
Share on other sites

It's seems that the value is not written down to Variable. I didn't get any online value but anyway when i modify this value i get massage in ma display window. What function is responsible for the write down recipe name in this variable? Im using only Download  to the controller and your function. Shell i use also save recipe?

Edited by marcinmrag

Share this post


Link to post
Share on other sites

This line assigns the selected recipe to a global string variable:

NJ1_HMI_Loaded_Program = rcpMold.SelectedRecipe

In your case it should be:

<your_global_string_variable> = RecipeViewer0.SelectedRecipe

 

Share this post


Link to post
Share on other sites

Still i do not get any value. Im using a button which call subroutine DownloadRecipe. I did a test i connect this button with your subroutine and this same. Are you sure that i should get the value without controller?

This is how look my code :

'Code behind Page - Add local subroutines for the page.

Public Sub DownloadRecipe
    WriteRecipeToController(RecipeViewer0.SelectedTemplate, RecipeViewer0.SelectedRecipe)
End Sub

Public Sub UploadRecipe
    ReadRecipeFromController(RecipeViewer0.SelectedTemplate, RecipeViewer0.SelectedRecipe)
End Sub

Sub WriteSelectedRecipe()
        Dim rcpSelectedTemplate As String = GetSelectedRecipeTemplate("RECEPTY", "RecipeViewer0")
        Dim rcpSelectedRcp As String = GetSelectedRecipe("RECEPTY", "RecipeViewer0")
        
        WriteRecipeToController(RecipeViewer0.SelectedTemplate, RecipeViewer0.SelectedRecipe)
        
        NJ1_HMI_Loaded_Program = RecipeViewer0.SelectedRecipe 'Selected reciped gets set here
        
End Sub

 

I figure out that all codes are need to be placed in vb code where is recipeViewer but still is not returning any value in NJ1_HMI_Loaded_Program variable.

Share this post


Link to post
Share on other sites

This Sysmac Stiudio is killing me. It's possible to add new recipe by the button and choose the name? I tested AddRecipe code but is adding recipe only with the name specified in code. Also i would like to use option save as and put the name from keyboard.

Share this post


Link to post
Share on other sites

If you're using the DownloadRecipe subroutine, place the variable assignment in there. So it should look like 

Public Sub DownloadRecipe
    WriteRecipeToController(RecipeViewer0.SelectedTemplate, RecipeViewer0.SelectedRecipe)

    NJ1_HMI_Loaded_Program = RecipeViewer0.SelectedRecipe
End Sub

It would then seem like you don't need the WriteSelectedRecipe subroutine. 

As far as creating a new recipe, I would start a new topic to keep subjects and comments organized. 

Share this post


Link to post
Share on other sites

I just tried like you said. Still nothing ;/ When you simulate this are you connected to controller? I have only HMI project. I do not start plc project yet. Maybe this is the problem?

Share this post


Link to post
Share on other sites

I don't think so. I opened a new project and added an HMI with a recipe viewer object and it worked in simulation mode. I've attached the project so you can see yourself.  Make sure the DataDisplay type is set to String, not Numeric. 

 

Hope this helps.

test.smc2

1 person likes this

Share this post


Link to post
Share on other sites

It's string i check few times. You right in your project is working. I will try to create new recipeviewer and etc and than test again

 

Edited by marcinmrag

Share this post


Link to post
Share on other sites
On 20.09.2017 at 2:55 PM, gunnaraherman said:

Hello,

I know that is wrong topic but maybe someone can explain me how can i get the value from HMI recipie in my controller project?

 

Share this post


Link to post
Share on other sites
On 24/01/2017 at 4:20 AM, gunnaraherman said:

Hello,

I am looking for a way to programatically select a recipe. Any time that a recipe is change or saved, the recipe viewer object always resets its view and selects the first recipe. This will lead to possibly writing the wrong recipe to the controller, as well as frustrate the user if they have to scroll through a hundred items to find the recipe again.

I looked at the VB functions, but the only one I could find that was close was the .SelectedRecipe, which is a read only.

I am using Sysmac Studio v1.1.7, and an NA5 HMI.

Any help would be appreciated.

Was there a solution posted to this question? I can't seem to find it.

I also have an application where I have close to 100 recipe names. It is very cumbersome for the operator to scroll through all recipe names to select the one they want to use. Ideally they would enter the recipe name in a data entry field and select it that way.

But we also still want to be able to use the recipe viewer to select the recipe name.

I was looking at writing a script:

WriteRecipeToController(RecipeViewer0.SelectedRecipe)

where the SelectedRecipe is entered in the data entry field.

Share this post


Link to post
Share on other sites

Posted (edited)

This script works.

Sub Enter_Product
	Dim RecipeName As String
	RecipeName = st_Prod_Enter
	st_Template=GetSelectedRecipeTemplate("Part_Enter","RecipeViewer0")
		WriteRecipeToController (st_Template,RecipeName)
End Sub

HMI Page name is "Part_Enter.

"st_Prod_Enter" is the string variable entered in the data field below. Press "confirm product" will write all the recipe ingredients to the NX1P controller.

Good thing is that if you enter a part number (recipe name) which is not already in the recipe, an error message pops up letting you know. So you can only enter valid recipe names.

HMI1.JPG

Note: you have to place the recipe viewer in the screen, it is the recipe viewer used in the script, "RecipeViewer0". I have made it invisible and disabled it.

Code1.JPG

Edited by tulip

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now