Function Evaluation

Hide Topic ContentsShow Topic Contents
  1. What is a Function Evaluation
  2. How to Use a Function Evaluation
  3. Defining a Function
  4. Functional Evaluation Examples

What is a Function Evaluation

Function evaluations provide on-the-fly acquisition tag conversion in the OT bus stops using a mathematical or logical expression. Where translation tables provide a static conversion, function evaluations provide a dynamic conversion of data. Function evaluations are applied on the source of an acquisition tag meaning:

If the tag is used in an upload direction, the source is the data coming from the channel and the expression is applied before the data is converted to a shopfloor message.

If the tag is used in a download direction, the source is the data coming from the internal shopfloor message and the expression is applied before it is sent to the channel.

How to Use a Function Evaluation

Function Evaluation can be selected when adding a tag to a channel message.

Selecting ‘Function evaluation’ for the Data Source will provide an additional field that holds the function:

The variable ‘x’ is the original tag value that is specified by the XPath for XML, access path for OPC, position for CSV, etc. The result/outcome of the function is used as the ‘new’ source value.

The function evaluation supports the following:

One variable named ‘x’ which represents the original tag value.

Brackets: e.g. ((36+x)/(45-21))

All basic mathematical operators like + (add), - (subtract), / (divide), * (multiply)

Advanced math operations e.g.:

Math.Pow(x,2)+x

100+Math.Abs(x)

Math.Sqrt(x*100)

For more examples check this website.

You still need to link the acquisition tag to a message field. The tag needs to have a reference to its context (message field type etc.).

Defining a Function

The function can be entered directly into the Function Expression field.

However, to use function templates or to test the function do the following:

Click the ellipsis button () next to the Function Expression field. This will open the following dialog.

All available functions are listed.

Select a function template and click Insert.

The Function updates to display that formula. You can build more complex formulas by inserting more function templates or by entering functions manually.

Replace each x with one of the following:

Numerical values.

Tags belonging to the same channel message. Include in square brackets. e.g. [GoodCount_1], [AvTemp].

Bus stop variables. Include in square brackets and prefix with @. e.g. [@BusStopVar]

The formula will only work if the following rules are followed:

The number of opening and closing parenthesis match.

The data type of the outcome matches the data type of the Acquisition tag. The function evaluation throws an exception if the data types don’t match.

It does not exceed 255 characters.

To test the formula enable Evaluate function.

Enter Test values, the values that would be received from the source, and click Evaluate function.

The result that would be sent to the destination is shown in the fx= field.

Click OK.

The function is entered in the function field for the tag.

Functional Evaluation Examples

In this example the tags ‘Property2’ and ‘Property3’ are defined as Boolean tags and the result is a string that matches the data type of ‘Property1’. The function shown in the screenshot uses a conditional operator. More complex functions using multiple conditional operators are allowed too. The following function could be used to set an equipment state value based on 2 Boolean tag values.

[A] && [B] ? "1" : (![A] && [B] ? "2" : ([A] && ![B] ? "3" : "4"))

Here are more function evaluation examples:

Math.Pow([IntegerProperty],2)+ [IntegerProperty]

100+Math.Abs([FloatProperty])

Math.Sqrt([IntegerProperty]*100)

((36+[IntegerProperty])/(45-21))

Can we improve this topic?