Add Dynamic Calculations

This example explains how to add a linear function f(x)= ax+b to a source item by using the ApisCalculate module. The source item we use is "ApisOPC1.PUMP1.Flow", but it can be any available item.

For a full list of mathematical expressions, see ApisCalculate.

Add calculate module

Follow the guide Add Module to Apis Hive, but this time select a module of type ApisCalculate from the "Module type" dropdown list.

  • After adding the module, select the new module named "ApisCalculate1" from the Solution Explorer.
  • Set the "ExchangeRate" property to, for example, 1000 ms. This is the update rate for how often this module exchanges data with other modules.

!> The ExhangeRate property is a required field. No calculations will occur if the ExhangeRate is 0.

Add items

Follow the guide Add Items to a Module, but this time click on "ApisCalculate1".

  • Add one Item of type "Variable" and name it, for example, "Scale". This item corresponds to the coefficient a.
  • Add one item of type "Variable" and name it, for example, "Offset". This item corresponds to the coefficient b.
  • Add one item of type "AggregatedItem" and name it "FlowCalculated". This item will show the calculated result.

Set coefficients

  • Select the item "ApisCalculate.Scale" and in the Properties Editor, click "Add Property"

  • Select "Valuetype" and set it to 4 byte float

  • Set the "Value" property. In this example we will set it to 2.

  • Click "Apply" when done
  • Use the same procedure and set the value for the item "ApisCalculate.Offset". In this example we will set the value to 10.

Connect the aggregated item to variable items

  • Right-click on the aggregated item "ApisCalculate.FlowCalculated" and select "Connect"

  • Connect "FlowCalculated" to the following items:

    • "ApisCalculate1.Scale"
    • "ApisOPC1.PUMP1.Flow"
    • "ApisCalculate1.Offset"

  • Click "Ok" when done.

Add the mathematical expression

  • Click on the item "ApisCalculate.FlowCalculated" and add the calculation "ex1*ex2 + ex3" in the "Expression" property.
    • ex1 is a keyword for ExternalItem1, ex2 is a keyword for ExternalItem2, and so on.