How to Create a Calculation Tag

How to Create a Calculation Tag

When configuring Tags in the OAS server, you can choose Calculation as the Data Source. This allows you to create dynamic data transformations on existing values already being monitored from local or remote sources. You can even use input data directly from OPC Servers with the DirectOPC interface and these items can come from the local service or a remote service.

In this guide you will learn how to create a simple calculation tag to convert a temperature from degrees Celsius to degrees Fahrenheit.

1 - Add Tag for Temperature in Degrees Celsius

In this section you will create a Tag to represent a temperature value in degrees Celsius.

  1. Select Configure > Tags from the top menu.

    Configure tags menu

  2. If you want to add a Tag to the root Tags group make sure the Tags node is selected in the tag list and click on the ADD TAG button.

    Add tag button

    If you want to add a Tag to a Tag Group, select the Tag Group first and then click on the ADD TAG button.

    You can also add Tag Groups by using the ADD GROUP button.

  3. Provide the Tag Name Temperature C and click the OK button.

    Add tag to root node dialog

2 - Add Tag for Temperature in Degrees Fahrenheit

In this section you will create a Tag to represent a temperature value in degrees Fahrenheit.

  1. Select Configure > Tags from the top menu.

    Configure tags menu

  2. If you want to add a Tag to the root Tags group make sure the Tags node is selected in the tag list and click on the ADD TAG button.

    Add tag button

    If you want to add a Tag to a Tag Group, select the Tag Group first and then click on the ADD TAG button.

    You can also add Tag Groups by using the ADD GROUP button.

  3. Provide the Tag Name Temperature F and click the OK button.

    Add tag to root node dialog

3 - Set Tag Data Source

You will now set the Data Source of the Temperature F tag to Calculation so that you can write the function that will convert the temperature from Celsius to Fahrenheit.

  1. Select the Temperature F tag.

    Tag

  2. Set the Data Source to Calculation.

  3. Click on the EDIT button next to the Calculation field to open the Calculation Editor window.

    Click calculations edit button

4 - Apply Temperature Conversion Function

You will now write the function that will convert the temperature from Celsius to Fahrenheit. This function will reference the Temperature C tag and scale the value accordingly.

  1. In the Calculations Editor window type the following function:

    ([Temperature C.Value] * 9/5) + 32
    

    This should appear as follows.

    Fahrenheit to Celsius conversion function

    Tips

    To insert a tag you can either type the tag path manually and surround it using square brackets [] or you can use the Tag Browser by selecting the INSERT TAG button.

    Tips

    To reference a Tag's value remember to add .Value at the end of the tag path.

  2. Click on the OK button and then the Apply Changes button to apply the changes.

  3. Check that the quality status is Good Quality and the data in the Value field is as expected.

    Tag

5 - Verify Calculation

Let's check that the conversion function is working as expected.

  1. Select the Temperature C tag.

    Select Temperature C tag

  2. In the Enter Value field type in a temperature value in Degrees Celsius and press the Enter key on the keyboard.

    Set Temperature C tag value

  3. Click on Apply Changes.

  4. Select the Temperature F tag and check that the value matches the expected value.

    Check Temperature F tag value