Use Regular Expressions to Filter Application Variables

The OPC UA server allows you to generate OPC UA variables at runtime and to map them to application variables. The application variables to be mapped are filtered out of all available application variables using regular expressions.

To create such a mapping rule, proceed as follows:

  1. Select an object (not a variable) in the information model.
  2. Open the “Mapping” tab in the information model.
  3. For OPC UA objects, the context-sensitive mapping configuration is offered here using regular expressions.
  4. Regular Expressions in the “Mapping” Tab
  5. Configure the regular expressions with which variables are automatically generated under the selected OPC UA object at runtime (see example below).
  6. Click [Confirm] to apply the changes.

Example of Using Regular Expressions

In this example, you map all application variables below an OPC UA variable whose name is preceded by the prefix “opc_”. It should be irrelevant whether these are defined in the “PLC_PRG” program or the “GVL” global variable list. The following symbol configuration serves as the starting point for the example:

Symbol Configuration (Example)
Symbol Configuration (Example)
  1. First, create an OPC UA object instance (e.g., with the name “RegExpMapping”). For the example, you can leave the object type at the default value (“BaseObjectType”).
  2. Select the newly created object and edit the regular expressions in the “Mapping” tab under the information model as follows:
  3. DataSourceIdentifier
    Enter a regular expression under “DataSourceIdentifier” with which the symbol paths of all available application variables are filtered.
    Note: The symbol paths contain periods as separators (“.”). In the regular expression, precede the period with a backslash (“\”). Otherwise, the period will be interpreted as a wildcard (unless you actually want to use the period as a wildcard).
  4. Example: .*\.opc_.*
  5. NodeId
    For each symbol path already filtered using the “DataSourceIdentifier”, a NodeId string is generated using the “NodeId” and “NodeIdTarget” properties.
    Enter a regular expression as the “NodeId” property that will be applied to the symbol path that has already been filtered.
  6. Example: .*\.(.*)\.opc_(.*)
  7. NodeIdTarget
    The “NodeIdTarget” property compiles the final NodeId value of the OPC UA variable from the components of the regular expression of the “NodeId”.
  8. Example: nodeid_$1_$2
    For the symbol path advanced.GVL.opc_global_input01, nodeid_GVL_global_input01 would result as the “Nodeld”.
  9. Note: Note that the NodeId string must be unique according to the OPC UA specification. To ensure this, part of the symbol path (GVL or PLC_PRG) is included in the example, as otherwise there would be a risk of a duplicate NodeId.
  10. BrowseName / BrowseNameTarget
    Enter the properties “BrowseName” and “BrowseNameTarget” to create the OPC UA BrowseName from the symbol path that has already been filtered.
  11. Example:
    BrowseName: *\.(.*)\.opc_(.*)
    BrowseNameTarget: browsename_$1_$2
    The result for advanced.GVL.opc_global_input01 is browsename_GVL_global_input01.
  12. DisplayName / DisplayNameTarget
    Enter the properties “DisplayName” and “DisplayNameTarget” to create the OPC UA DisplayName from the already filtered symbol path.
  13. Example:
    DisplayName: *\.(.*)\.opc_(.*)
    DisplayNameTarget: $2 from $1
    The result for advanced.GVL.opc_global_input01 is global_input01 from GVL.
  14. Click [Confirm].
  15. Use Regular Expressions
  16. You can view the result of the variables filtered by regular expressions with an OPC client (view here as an example for the OPC UA client “UAexpert”).
  17. Hit List from the Regular Expressions (View in the OPC UA Client “UAexpert”)
  18. If you view the attributes, you will find the NodeId, BrowseName and DisplayName, for example. These were formed from the regular expressions that you entered for NodeID, NodeIdTarget, etc.
  19. Result from the Regular Expressions (View in the OPC UA Client “UAexpert”)

Note

The OPC UA variables are generated at runtime!

The OPC UA variables are only generated by the OPC UA server at runtime. For this reason, they are not displayed in the OPC UA Mapping Editor under the selected OPC UA object in the information model.

Note

You can also filter using regular expressions without importing a symbol configuration!

The regular expressions are always used by the OPC UA server at runtime on the symbol configuration of the currently active application. For this reason, you can also use the OPC UA Mapping Editor directly to enter regular expressions without having to import a symbol configuration. You just have to export the mapping and load it into the controller. The regular expressions are applied to the currently active application at runtime.