Attribute Referencing and Parameterized Types
As mentioned above, many properties in the member Tag configuration can reference the parameters available in the data type. When instances are created, these references are replaced with the values defined for the type. Parameter references also support basic offsets and numerical formatting, providing a great deal of flexibility. To reference a parameter, use the syntax {ParameterName}.
To offset a value, use the form {ParameterName+offset}
.
To format a value, use the form {ParameterName|format}
. The format pattern is the same as that used for the numberFormat
expression function. In short, "0" can be used to require a digit, and "#" can be used for optional digits. ie: ##0
Example:
For this example, we'll assume that we're parameterizing the OPC Item Path, and that the data type has an integer attribute named BaseAddress
defined. We'll pretend the OPC Server provides Tags named like DataPoint1
.
Standard Referencing
OPC Item Path: DataPoint{BaseAddress}
Offset
Imagine that our data type had three fields, and these were laid out sequentially in the device.
Instead of specifying each address for each Tag, we can simply offset from the base address:
Member 1: DataPoint{BaseAddress+0}
Member 2: DataPoint{BaseAddress+1}
Member 3: DataPoint{BaseAddress+2}
Continuing from the example above, imagine that our OPC server actually provided addresses in the form DataPoint001
, in order to stay consistent up to "DataPoint999". This can be accommodated
using number formatting in the reference:
Member 1: DataPoint{BaseAddress+0|000}
Member 2: DataPoint{BaseAddress+1|000}
Member 3: DataPoint{BaseAddress+2|000}
This format of three zeros means "three required digits". If our instance has a base address of 98, the resulting paths will be DataPoint098, DataPoint099, DataPoint100
.
Parameters support more mathematical operators in addition to offsets and formatting. There is a simple expression language available that can be used in conjunction with formatting. The following table shows all available operators in their order of operations (they are evaluated starting at the top of the table).
Operator | Description | Example |
---|
() | Parenthesis. These operators are used for grouping any number of values. Also used to change the order of operations. | {Baseaddress*(2+3)} |
^ | Power. This operator is used to raise a number to a power. | {BaseAddress^2} |
- | Negative. Used to create a negative value from one number. | {BaseAddress*-2} |
* | Multiplication. Multiply two numbers. | {BaseAddress*2} |
/ | Division. Dividing the first number by the second number. | {BaseAddress/2} |
% | Modulus. This operator returns the remainder of a division operation. IE: 7/3 = 2 with a remainder of 1, so 7%3 = 1 | {BaseAddress%2} |
+ | Addition. Add two numbers. | {BaseAddress+2} |
- | Subtraction. Subtract two numbers | {BaseAddress-2} |
| | Used to define a formatting pattern. Patterns are defined with 0 and # characters. | {BaseAddress|##0.00} |
# This dynamic OPC Item path takes in three parameters to determine the tag path
ns=1;s=[DeviceName]Path/to/tag{BaseAddress+(ParamNum*Multiplier)|0000}
# The OPC Item path resolves to the following assuming the following values:
# BaseAddress = 5
# ParamNum = 8
# Multiplier = 2
ns=1;s=[DeviceName]Path/to/tag0021
Calculations and Numerical Parameter Names
If the parameter names are purely numerical values (we don't recommend this: it gets confusing), then quotation marks must encase the parameter to run any sort of calculations on the value of the parameter.
For example, if a UDT contains a parameter named 0, and its value is 10:
// This will evaluate to 0, because it thinks you mean the integer 0, not the parameter named "0"
{0 * 1000}
// This will evaluate to 10000, because the quotation marks denote a parameter named "0"
{"0" * 1000}