Engineering Tip

A common thing that we have always wanted to do with FL is to draw just one screen and then point the screen at one of many sets of tags.  An example would be to have ten tanks and corresponding valves, levels, and other drawing animation.  They are identical but have different tags for each tank.  Such an approach allows you to press a button on the screen to show one of ten tanks without having to draw and maintain ten drawings.

There are now two different approaches for accomplishing this.  FactoryLink version 7.2 added a new feature called “Branching.”  Branching provides the ability to easily “multiplex” a mimic with multiple tag sets as well as do the same thing for smaller “Symbol” components that may be used as sub components for FactoryLink mimics.  Before FactoryLink version 7.2, this was accomplished via a much more code intensive approach.  If you are building a multiplexed mimic “from scratch” in FactoryLink version 7.2 or higher, you will definitely want to use the Branching approach.  The last part of this document will give details on using the Animation Property approach as information for those of you who might be modifying or maintaining an application that was created with the pre FactoryLink version 7.2 approach.

Branching Approach

Refer to the FactoryLink Fundamentals Guide, Internal Architecture Section if you wish to study an in depth explanation of branching.

Branching can be summarized as a hierarchical data structure.  To take advantage of this technology, simply name your tags in a hierarchical manner delimited with an underscore  “_”.     As in the ten tank hypothetical example we might have a tag list as follows:

Tank1_Valve1              Tank2_Valve1              Tank3_Valve1  ………………            Tank10_Valve1           

Tank1_Valve2              Tank2_Valve2              Tank3_Valve2  ………………            Tank10_Valve2

Tank1_Level1              Tank2_Level1              Tank3_Level1  ………………            Tank10_Level1

Tank1_Level2              Tank2_Level2              Tank3_Level2  ………………            Tank10_Level2

 

With such a group of tags to work with for our hypothetical ten identical tank application, we simply build the mimic, and animate the mimic using the branched tags.  In the Variable browser you will select the correct Valve or Level number for the particular function being animated.  Once the mimic has been animated and tested, the branch will be selected in one of two ways; when initially building the mimic, or with the Link Open animation panel.

 

When Building a New Mimic

 

When building a new mimic you can select the branch for a particular mimic in the “New Mimic” panel that is displayed upon selecting   “File, New.”  When clicking the green arrow in the Branch field the Variable Browser panel will appear, from which you can select the Tank1, Tank2, etc.  You can then copy and paste the entire mimic from your original mimic that has been created and tested.  That mimic will have a unique name and be connected to the desired branch so that the appropriate tag values will be automatically linked to the appropriate animation.

 

Once these ten mimics are created, opening that mimic will show the mimic with the tag values from the selected branch of Tank1 through Tank10.

 

When Using Link Open

 

This is the simpler approach for use where the mimics are absolutely identical except for the tag values.  In this approach you use the same Mimic Name for all ten tanks, but open the mimic with the correct branch.  To identify the tank, simply animate a tag onto the mimic to identify the tag set.  This would probably be a prominent area at the top center of the mimic to make it quite obvious to the operator which tank he/she is monitoring or controlling.

 

To configure this for our hypothetical ten tank system, you would incorporate ten buttons labeled Tank1, Tank2……….. Tank10.  Upon selecting each button and then choosing Link, Open animation, a properties panel will be displayed with a Mimic Name and a “Branch” field.  In the “Branch” field, choose the appropriate branch, Tank1 through Tank10 for that button.  At runtime the same mimic will be opened but the appropriate branch will be used to connect the appropriate tag set to the animations on the mimic.

Animation Properties Approach

Beginning with FactoryLink 7.0, Client Builder Mimics gave us a great new tool, animation properties.  Because each object on a mimic has properties, the animations have properties and one of the properties is the OPC item (tag).  All we have to do is change the properties of the animations and we have it.  That would take a lot of code...

If you choose a "parseable" tag naming convention, this is easy and it takes only a little bit of code.  This is a subroutine that was written in Client Builder and called on a button press (click event) and passed the new array number along with the mimic name:

Click event on a text object:

Private Sub Text5_Click()
   Call TagSwitch("overview", 1)
End Sub

The TagSwitch function found in a module:

Public Function TagSwitch(mimicname As String, arrayindx As Integer)
   Dim objMimic As Object, objGraphics As Object
  
Dim objAnim As Object
  
Dim ioflag As Integer, bracket As Integer
  
Dim newvar As String

    For Each objMimic In ThisProject.Mimics
       If objMimic.FileName = mimicname Then
          For
Each objGraphics In objMimic.Graphics
                   For Each objAnim In objGraphics.Animations
                        On Error GoTo BadProperty
                  ioflag =
InStr(objAnim.Var, "io")
                         If ioflag > 0 Then
                             bracket = InStr(objAnim.Var, "[")
                    newvar =
Mid(objAnim.var, 1, bracket)
                    newvar = newvar & arrayindx & "]"
                    objAnim.var = newvar

                         End If
                        BadProperty:
                   Next
          Next
       End
If
    Next
End
Function

If this looks like a bunch of code for such a simple thing, you may not notice that this code changes each and every tag on this mimic that has the string "io" in it regardless of where the animation is found!

To understand this code, first you have to understand that there are objects, properties, methods and events.  There are also collections.  A collection is a named entity that you can reference if you know its name.  Because we cannot know all of the names defined in a collection, we can have the system do it for us.  This is where the code that starts: for each ____ in ____  This will return each item in the collection.

Another part of this code that gets a bit odd is that we can only affect our own mimic because it has to be open in the Client Builder to change it.  Mimics that are not loaded cannot be affected, so we much limit our selves to the mimic with which we are interacting.  If you need to do this on other mimics, you have to run this routine for each mimic when opened.

    For Each objMimic In ThisProject.Mimics
    
If objMimic.FileName = mimicname Then
This code searches the collection of mimics and draws each name from the collection.  We check to see if the selection is the mimic that we are currently viewing.

    For Each objGraphics In objMimic.Graphics
This code returns each and every object on this mimic

      For Each objAnim In objGraphics.Animations
This code returns each animation attached to the object found in the previous line

      On Error GoTo BadProperty
This is an error trap.  We are going to ask for something that might not exist and therefor we have to have a way out without popping up an error at run-time

      ioflag = InStr(objAnim.Var, "io")
            If ioflag > 0 Then
This code defines what special tag naming convention we are using.  In this case, we are looking for the letters "io" in the string, if that is true, then the if-then is true.

              bracket = InStr(objAnim.Var, "[")
First we find the start of the array (note, this is good for 1 dimention only)

       newvar = Mid(objAnim.var, 1, bracket)
Then we get everything up to the start of the array

       newvar = newvar & arrayindx & "]"
Finally we append the new array index and close the syntax by closing the array bracket

       objAnim.var = newvar
This is the real change, we then change the animation to the new tag which has changed only the index of the array.

If you have hundreds of variables on a screen, this call will take a few seconds, but saves you from drawing a new mimic for each io data set.

Be aware that this is actually changing animation.  When you go back to this mimic, the animation will be whatever was set the last time.  The changes are perminate, if you want it to default to a particular set of tags, make sure to handle that in the mimic open event.