Applies To:
  • CitectSCADA 5.xx
  • CitectHMI 5.xx

Summary:
I have an ActiveX control that dividing a circle into a number of sectors and each sector has a fill level proportional to a Citect variable. I would like to enter the number of sectors as a property and then have the tag association list for that number of tags. As it is I have to set my array for a maximum number of sectors and have the associations for unused variables at design time. Is there a way to code my control to have a variable number of associations based on a property? 

Solution:
This question has touched both ActiveX and CitectSCADA sides.

On ActiveX Control, you should

1. Raise an event (SectorsChange) when the number of sectors have changed (it's better to pass the number of sectors as an argument).

2. Make all sector properties names generic, for example Sector1, ... SectorN where N is the maximum sectors of your circle.

3. Define a property to expose the current number of sectors, say "NumberOfSectors"

On CitectSCADA, you should

1. Make names of associated tags generic, for example Tag1, ...TagN.

2. Use the following Cicode functions to dynamically associate tags at runtime depending on the number of sectors

Function PageSector_AN35_SectorsChange(Object This, Int NumberOfSectors)
    MyTagAssociation(NumberIfSectors);
End

Function MyTagAssociation(Int NumberIfSectors = 0)
    INT iSecNum;
    INT index;
    STRING sPropertyName;
    STRING sTagName;

    If (NumberIfSectors = 0 ) Then
        iSecNum = _ObjectGetProperty(ObjectByName("AN35"), "NumberOfSectors");
    Else
        iSecNum = NumberIfSectors;
    End
    For index = 1 To SecNum DO
        sPropertyName = "Sector" + IntToStr(index);
        sTagName = "Tag" + IntToStr(index);
        ObjectAssociatePropertyWithTag(ObjectByName("AN35"), sPropertyName, sTagName, 
            "Your OnChangeEvent")
    End
End

For this application, the data flow is from Tags to Properties. So in this case, the fourth parameter ("Your OnChangeEvent") of function ObjectAssociatePropertyWithTag should be empty string.

So how does it work?

When the property of the number of sectors is changed, the ActiveX control will raise the event "SectorsChanges". Then CitectSCADA catches this event and executes function "MyTagAssociation".

It is noted that once a tag association is added, it cannot be removed. This could be a potential problem in operation of the above code. For example, the number of sectors increases while the page is open, event PageSector_AN35_SectorsChange will be triggered and function "MyTagAssociation" will be called again. That's ok as CitectSCADA will check if a tag is already on the update list before adding. But the problem occurs when the number of sectors decreases because there is no Cicode function to remove a tag association. So be aware of this problem when you implement this feature in your project.

See also KB Articles Q3876 and Q3900

 

Keywords:
 

Attachments