16.9. Regular Expressions

In previous sections we added some variables, with corresponding states and scripts. Instead of assigning single values to all of the variables, we can use regular expressions for some of them, to allow alarms to be generated from multiple points with similar names.

[Note]

Regular expressions are a way that programmers use place-holders and wild cards in a variable name so that it can refer to multiple names at one time. The DataHub program uses .NET Regular Expressions, whose use and syntax can be found here.

  1. Go to the Variable Bindings tab and click the Add button. This will add a new binding definition to the Binding Definitions list, and show you the first variable (input).

    The first variable is used to create regular expressions for the binding definition. Any additional variables in the binding definition can access matches within the regular expressions for the first variable.

  2. Check the Is Regex box.

  3. In the Variable Bindings enter the following for the input variable:

    DataPid(.*):PID1\.(.p|.v)$

    This regular expression selects any point with the following characteristics:

    • DataPid(.*): chooses any data domain that starts with DataPid

    • PID1\. chooses the PID1. branch.

    • (.p|.v) selects any single letter, followed by p or v. In this case, it will select Sp, Mv, or Pv.

    • $ ends the expression.

  4. For the output variable enter:

    default:PID{0}.{1}Alarm

    The numbers within the curly brackets { } will bring in whatever value corresponds within the parentheses ( ) in the input variable, in order. That is, the 0 matches the content of the first set of parentheses, the 1 matches the content of the second set, and so on.

  5. For the rest of the variables, the limits, you can enter constant values.

    For example, 70 and 60 for the hihilimit and hilimit, and 40 and 30 for the lolimit and lololimit.

  6. In the Regex Explorer section you can test your regular expression.

    Enter a point name that you think matches the regular expression, such as DataPid:PID1.Pv in the First Variable field. If your regular expression is correct, you should see how that entry will appear for all of the related variables.

This completes the OPC A&E example. To test:

  1. Click the OK button to return to the Notification Configuration window.,

  2. Check the Enable Notification and HiLoAlarm boxes and click Apply.

  3. Start DataPid.

  4. In the Data Browser, open the OPCAE tree and click on Status.

    You should see the values of the *HighLowTest points changing between HiHi, Hi, LoLo, Lo, and Normal.

    If you have installed the DataHub OPC A&E plug-in, you can view these alarms with any OPC A&E client application.

[Note]

It is also possible to view OPC A&E alarm data in DataHub WebView's Alarm List control.