OAProfessor

Deep OA Product Insight

User Tools

Site Tools


dp_fct_expressions

This is an old revision of the document!


The dp_fct config for a data point element is a slick way to make new tags without scripting.

The most common use case for this is to average some sensor values to get an overall value. Let's take this example: you have a chilled tank with 3 sensor values for the temperature. You really want the overall tank temperature, but over time the tank will have different temps at the sensors. A good way to get a better feel for the tank overall temperature is the average of the temps: tank temp = (sensor1 + sensor2 + sensor3) / 3.0

when using the dp_fct: you would build it like this:

These are simple expressions using mathematical equations. What if you want to make a more complex statement? Here is another use case: If the tank is too low, the sensor1 value will be near to room temperature, ignore that one.

if(Sensor1 > 60)
  TankTemp = (sensor2 + sensor3) / 2.0;
else
  TankTemp = (sensor1 + sensor2 + sensor3) / 3.0;

Well, this takes a different kind of expression. For hard-core programmers, this is simple, but for the casual OA programmer, it is not easy. Here is the syntax for an if-then-else statement:

TankTemp = Sensor1 > 60 ? (sensor2 + sensor3) / 2.0 : (sensor1 + sensor2 + sensor3) / 3.0

The ? operator tells the parser that this is the IF part. The : operator tells the parser the ELSE part follows.

Using the syntax for the dp_fct:

p1>60?(p2+p3)/2.0:(p1+p2+p3)/3.0
dp_fct_expressions.1635273084.txt.gz · Last modified: by toddmalone

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki