Filter3Parameters

Parent Previous Next

Filter3Parameters

Function that performs a search on a specific tag name. It is different than Filter with 2 parameters because in this one, you know where to look. It is useful when filtering a tag of data type for example, and you don't want the search to look on all tags.

Let's say you have 10 tanks. The tanks have many parameters on their data type and it repeats to the 10 tanks. But you only want to filter tank 1 for example. In this case, you would use this function to look for a Temperature tag inside of the tank where temperature is 200 degrees. If you were using the Filter with 2 parameters you would get 10 occurrences of Temperature.


Syntax:

List<string> Filter(string tagName, Dictionary<string, List<string>> filters, bool satisfies);


Parameters:

String tagName: a string parameter that contains the name of the tag members in which the filters will be done.

Dictionary<string, string> filters: a Dictionary <string, string> parameter that contains the filters to be used in the search: key tag name / member to be searched; value the current value of the tag.

Boolean satisfies: a Boolean parameter that indicates whether the search should return the tags that conform or those not in accordance with the filters.


Return:

List<string>: a string list containing the full names of all tags that conform or not to the filters.


Example: Filtering tags and getting their values using SVTags.


In this example, we will need to create the following scenario:


.     Create a data type and 10 tags with their default Type as integer:


graphic

      


.     Create 3  tags of type dtFilter


graphic



.     Create a graphic with 1 button as in the image below:


graphic



.    Now let's configure the button with the following code.

  


Dictionary<string, List<string>> filters = new Dictionary<string, List<string>>();

List<string> lsF = new List<string>();

lsF.Add("0");

filters.Add("NewTag", lsF);

List<string> lstreturn = SVTags.Filter("objFilter1", filters, true);


SVApplications.Output("Found " + lstreturn.Count.ToString() + " ocurrences");


foreach(string str in lstreturn)

{

            object objVal = SVTags.GetValue(str);

            int tagVal = (int)objVal;

            SVApplications.Output("Value read from tag " + str + " = " + tagVal.ToString());

}

 



.     We are creating a dictionary and adding to it a filter where the tag "objFilter1" with the *NewTag* text on the name must have value equals 0. The result will be written to the output log. We also use the SVTags.GetValue function to return the tag's value.


.     Now let's run a test.


.     Run the Application (F5) and see the results.


graphic



.     Open the Data Watcher.

            

graphic



.     Click the Check button and take a look at the Engineering Log.


graphic



.     The result will be the list of values from the tag "objFilter1.NewTag*". As we used this function passing the name of the tag "objFilter", the search had been done in this tag specifically. If you want to check on all tags of the project, you must use Filter with 2 parameters function as mentioned before.


graphic