Artz

Calling a sub

6 posts in this topic

There are a few different ways you could do this. I personally would have a global subroutine running at an interval and in this subroutine I would examine _HMI_CurrentPageIndex and if I detected a new page (Index != lastIndex) I would have an action associated with that page index value (case statement). The action would be the recipe you want to work with. You could set this up to perform an action once per page change with a sort of "run once" latching variable.

 

Share this post


Link to post
Share on other sites
15 hours ago, photovoltaic said:

I personally would have a global subroutine running at an interval

Ok I have that

 

15 hours ago, photovoltaic said:

I would examine _HMI_CurrentPageIndex

This internal variable would not serve me in my case

 

15 hours ago, photovoltaic said:

if I detected a new page (Index != lastIndex) I would have an action associated with that page index value (case statement)

My intention would be to fill a datadisplay in the same page, where the recipeViewer is, with an Atribute/Value from the Recipe of the current Selected RecipeTemplate (each interval on the global sub would fill a variable to store the SelectedTemplate) but...

 

15 hours ago, photovoltaic said:

The action would be the recipe you want to work with

The problem is, how to call a property of a control inside a specific page on a Global event? Specifically there's no way to set something lke this:

"PageName.RecipeViewer.SelectedTemplate"

 

Share this post


Link to post
Share on other sites

Artz,

So i am a little unclear of the ultimate goal you are trying to achieve,

Simply put, it sounds like you want to select a recipe and then "load" the ingredient values from that recipe into other variables for display. Is this correct?

One question i have is why are you trying to run a global sub on a one second interval for this? Is your selected recipe changing frequently? That would mean you are coding the recipe selection to change or someone is on the recipe page selecting or changing variables frequently. If selected recipe is not changing frequently then why not just have a onetime event to "load" the recipe ingredients after a new one has been selected? It seems excessive to constantly be reading/writing data when a new recipe has not been selected/changed.

There are a couple ways you could tackle this. You could have the Sub routine that loads the recipe at the page level OR at the global level. You just need to decide what event you want to use to trigger the subroutine. If code is changing the data then use that code to trigger the "load". If someone is making the changes then they are already on the needed page and have one of their actions trigger the event to load.

I would not try to split the handling of this between both places (global and page) unless the page is calling the global routine. It may be possible, but I have not had any luck calling a page subroutine from the global level. 

 

Edited by Str8jCkt

Share this post


Link to post
Share on other sites

Your guess is good but the diference between what you explain and what I need is that there's no event, in the Page I work with, to use and so specify to a dataDisplay a String from a variable depending on the SelectedTemplate, so I cannot reproduce what other controls have as easy as check the selected element event on control Events menu. We are talking about a RecipeViewer, it has no programmed event to choose when there's a change produced by selecting different item via touch screen by the user. So I had in mind to call a global sub each second to check the selected Template. Some more info about this is that I was using the RecipeViewer like a ListBox so I was hiding the RecipeNames and their properties and just showing the TemplatesNames.

Anyways... I just figured out how to do this, and I was obssesed with using a RecipeViewer when the easiest solution was to use DataDisplays and Buttons in the end. So I was complicating myself too much. So I ended up deleting that control and remaking up the Page. I was interested to know how could I pass a specific control on a specific Page event to a global sub but there are better solutions in my case.

 

On 7/6/2023 at 3:33 PM, Str8jCkt said:

Artz,

So i am a little unclear of the ultimate goal you are trying to achieve,

Simply put, it sounds like you want to select a recipe and then "load" the ingredient values from that recipe into other variables for display. Is this correct?

One question i have is why are you trying to run a global sub on a one second interval for this? Is your selected recipe changing frequently? That would mean you are coding the recipe selection to change or someone is on the recipe page selecting or changing variables frequently. If selected recipe is not changing frequently then why not just have a onetime event to "load" the recipe ingredients after a new one has been selected? It seems excessive to constantly be reading/writing data when a new recipe has not been selected/changed.

There are a couple ways you could tackle this. You could have the Sub routine that loads the recipe at the page level OR at the global level. You just need to decide what event you want to use to trigger the subroutine. If code is changing the data then use that code to trigger the "load". If someone is making the changes then they are already on the needed page and have one of their actions trigger the event to load.

I would not try to split the handling of this between both places (global and page) unless the page is calling the global routine. It may be possible, but I have not had any luck calling a page subroutine from the global level. 

 

 

Share this post


Link to post
Share on other sites

You are correct, there is no event on the RecipeViewer when something is selected or change. These would be nice features to have added.

I have used Omron Recipes and RecipeViewer on most of the projects i build lately. Typically i only have one template and several Recipes that are selected manually. But i have had a few machines which required multiple templates with RecipeViewers on different pages. I have used Barcode scanners that would determine the product and load the appropriate Recipes by calling global subroutines.

When need manual selection/load i add a button to "load" the selected recipe/template - sounds similar to what you ended up with your DataDisaplay solution. It is nice sometimes to go to the RecipeViewer and select different recipes to compare the ingredient values without actually loading each time you select one to view.

 

For auto loading you can create a global subroutine. Depending on if you already know your needed recipe (in case i mentioned above with Barcode scanner) then you can pipe in the recipe name or you can request the selected recipe from the RecipeViewer. The Page and RecipeViewer object names can be static or dynamic depending on your need as well.

Code would be end up being something like this...

 



Public Const RecipePageName As String = "Setup"
Public Const RecipeObjName As String = "RecipeViewer0"

' ---------------------------------------------------------
' Load Selected Recipe
' ---------------------------------------------------------
Public Sub Load_Selected_Recipe
    Dim SelTemplate As String 
    Dim SelRecipe As String 
    SelTemplate = GetSelectedRecipeTemplate(RecipePageName, RecipeObjName) 
    SelRecipe = GetSelectedRecipe(RecipePageName, RecipeObjName)  ' ---- If Loading Selected Recipe of the Viewer
    SelRecipe = Barcode.ProductName                                                         ' ---- If Loading Recipe Called by PLC

    WriteRecipeToController(SelTemplate, SelRecipe)
End Sub

 

 

 

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