Item type: Function item

This Item is a calculated value based on existing items in Hive. The calculation is formula based on inputs from external Items.

The Function item item type has the following properties:

NameDescriptionIDFlags
ExpressionAn expression used to calculate the value of this item5110Persisted
External ItemsThe external items are identified as 'ex1, 'ex2, ..., 'exN' in the formula given by the Expression property.

20000 ... 20000+N

Persisted
QualityItem quality3NormalPage
RightsItem access rights5ReadOnly
TimeItem timestamp4NormalPage
TypeItem canonical datatype1ReadOnly
ValueItem value2NormalPage
ValuetypeItem canonical datatype.19100Persisted, Enumerated

See also Predefined Item Properties and OPC DA Properties

Calculation

The formula can an expression with the names ex1, ex2,ex3,...exN. The formula can include the following Operators, Functions, and Logic.
In most cases when using expressions of kind All*, e.g. AllGoodCount, you will most likely need to have the module property ExtItem pass-through quality is set to Any quality.
Otherwise, one or more external item having a bad quality will prevent the Function item from being evaluated completely.
See also: ExtItem pass-through quality.

OperatorDescriptionExampleItem Type
+The sum of two valuesex1 + ex28 byte float (default)
-The subtraction of one value from anotherex1 - ex28 byte float (default)
*The multiplication of two valuesex1 * ex28 byte float (default)
/The division of one value by anotherex1 / ex2

8 byte float (default)

%The modulus of one value by anotherex1 % ex2

8 byte float (default)

Function Description Example Item Type
( Left bracket 1.0 / ( ex1 + ex2 )

 

) Right bracket 1.0 / ( ex1 + ex2 )

 

/**/ Comment. In a function Item everything between /* and */ will be omitted. /* a comment */  
abs The absolute value abs(ex1) 8 byte float (default) or custom scalar number
asinh Represents the inverse of the hyperbolic sine function asinh(ex1) 8 byte float (default) or custom scalar number
acosh Represents the inverse of the hyperbolic cosine function. acosh(ex1) 8 byte float (default) or custom scalar number
atanh Represents the inverse of the hyperbolic tangent function. atanh(ex1) 8 byte float (default) or custom scalar number
arcsin

Returns the angle, θ, measured in radians, such that -π/2 ≤θ≤π/2 .

The argument is a number must be greater than or equal to -1, but less than or equal to 1

 

Remarks:

A positive return value represents a counterclockwise angle from the x-axis; a negative return value represents a clockwise angle.

Multiply the return value by 180/Math.PI to convert from radians to degrees

arcsin(ex1) 8 byte float (default) or custom scalar number
arccos

Returns the angle, θ, measured in radians, such that 0 ≤θ≤π.

The argument is a number must be greater than or equal to -1, but less than or equal to 1

 

Remarks:

Multiply the return value by 180/Math.PI to convert from radians to degrees.

arccos(ex1) 8 byte float (default) or custom scalar number
arctan

Returns the angle, θ, measured in radians, such that -π/2 ≤θ≤π/2.

-or-

NaN if d equals NaN, -π/2 rounded to double precision (-1.5707963267949) if d equals NegativeInfinity, or π/2 rounded to double precision (1.5707963267949) if d equals PositiveInfinity.

 

Remarks:

A positive return value represents a counterclockwise angle from the x-axis; a negative return value represents a clockwise angle.

Multiply the return value by 180/Math.PI to convert from radians to degrees

arctan(ex1) 8 byte float (default) or custom scalar number
cos The cosine of a value, in radians cos(ex1) 8 byte float (default) or custom scalar number
cosh

The hyperbolic cosine of value. If value is equal to NegativeInfinity or PositiveInfinity, PositiveInfinity is returned. If value is equal to NaN, NaN is returned. The parameter is an angle, measured in radians.

Remarks:

The angle, value, must be in radians. Multiply by Math.PI/180 to convert degrees to radians.

cosh(ex1) 8 byte float (default) or custom scalar number
exp Exponent of an expression exp( ex1 ) 8 byte float (default)
floor Rounds the value to nearest integer towards minus infinity floor(ex1) 16 byte fixed point (default) or custom scalar number
ln Logarithm of a value ln(ex1 + ex2) 8 byte float (default)
neg Invert sign neg(ex1) 8 byte float (default) or custom scalar number
pow The first value raised to the power of the second value pow(ex1 , ex2) 8 byte float (default) or custom scalar number
sin The sine of a value, in radians sin(ex1) 8 byte float (default) or custom scalar number
sinh

The hyperbolic sine of value. If value is equal to NegativeInfinity. The parameter is an angle, measured in radians.

 

Remarks:

The angle, value, must be in radians. Multiply by Math.PI/180 to convert degrees to radians.

sinh(ex1) 8 byte float (default) or custom scalar number
sqrt The square root of a value sqrt(ex1) 8 byte float (default) or custom scalar number
tan The tangent of a value, in radians tan(ex1) 8 byte float (default) or custom scalar number
tanh

The hyperbolic tangent of value. If value is equal to NegativeInfinity, this method returns -1. If value is equal to PositiveInfinity, this method returns 1. If value is equal to NaN, this method returns NaN. The parameter is an angle, measured in radians.

Remarks:

The angle, value, must be in radians. Multiply by Math.PI/180 to convert degrees to radians.

tanh(ex1) 8 byte float (default) or custom scalar number
max

Return max value of two values.

max(ex1,ex2) 8 byte float (default) or custom scalar number
min

Return min value of two values.

min(ex1,ex2) 8 byte float (default) or custom scalar number
bit Return a bit either 0 or 1 bit(ex1,X) return the bit X in ex1. X = 0,1,2,3,4,....
allgoodavg

Return the average of all external items that have good quality.

If no good extenal value exist, then NAN and bad quality is returned.

allgoodavg() 8 byte float (default)
allgoodmin

Return the minimum of all external items that have good quality.

If no good extenal value exist, then NAN and bad quality is returned.

allgoodmin() 8 byte float (default)
allgoodmax

Return the maksimum of all external items that have good quality.

If no good extenal value exist, then NAN and bad quality is returned.

allgoodmax() 8 byte float (default)
allgoodmed

Return the median of all external items that have good quality.

If no good extenal value exist, then NAN and bad quality is returned.

allgoodmed() 8 byte float (default)
allgoodstd

Return the standard diviation of all external items that have good quality.

If no good extenal value exist, then NAN and bad quality is returned.

allgoodstd() 8 byte float (default)
allgoodvarians

Return the varians of all external items that have good quality.

If no good extenal value exist, then NAN and bad quality is returned.

allgoodvarians() 8 byte float (default)
allgoodcount

Return the number of all external items that have good quality.

allgoodcount() int
allgoodsum

Return the sum of all external items that have good quality.

If no good extenal value exist, then NAN and bad quality is returned.

allgoodsum() int (default)
allgoodcountvalue

Return the number of all external items that have good quality and value equal to the given value.

allgoodcountvalue(5.1) int
allgoodlastdatetime

Return the newest timestamp of all external items that have good quality.

If no good extenal value exist, then NAN and bad quality is returned.

allgoodlastdatetime() DATE
allgoodlastunixtime

Return the newest timestamp of all external items that have good quality. The value is a double with ms as decimals.

If no good extenal value exist, then NAN and bad quality is returned.

allgoodlastunixtime() 8 byte float (default)
allgoodfirstdatetime

Return the oldest timestamp of all external items that have good quality.

If no good extenal value exist, then NAN and bad quality is returned.

allgoodfirstdatetime() DATE
allgoodfirstunixtime

Return the oldest timestamp of all external items that have good quality. The value is a double with ms as decimals.

If no good extenal value exist, then NAN and bad quality is returned.

allgoodfirstunixtime() 8 byte float (default)
allgoodgreatherthanavg

Return the the average of all good values greather than X.

If no good extenal value exist, then NAN and bad quality is returned.

allgoodgreatherthanavg(XX) 8 byte float (default)
allgoodlessthanavg

Return the the average of ajl good values less than X.

If no good extenal value exist, then NAN and bad quality is returned.

allgoodlessthanavg(XX) 8 byte float (default)
allavg

Return the average of all external items.

Quality will be the worst quality.

If error in conversion to double, the value will be omitted, and quality will be set to BAD

allavg() 8 byte float (default)
allmin

Return the minimum of all external items that have good quality.

Quality will be the worst quality.

If error in conversion to double, the value will be omitted, and quality will be set to BAD

allmin() 8 byte float (default)
allmax

Return the maksimum of all external item.

Quality will be the worst quality.

If error in conversion to double, the value will be omitted, and quality will be set to BAD

allmax() 8 byte float (default)
allmed

Return the median of all external.

Quality will be the worst quality.

If error in conversion to double, the value will be omitted, and quality will be set to BAD

allmed() 8 byte float (default)
allstd

Return the standard diviation of all external items.

Quality will be the worst quality.

If error in conversion to double, the value will be omitted, and quality will be set to BAD

allstd() 8 byte float (default)
allvarians

Return the varians of all external.

Quality will be the worst quality.

If error in conversion to double, the value will be omitted, and quality will be set to BAD

allvarians() 8 byte float (default)
allcount

Return the number of all external items.

allcount() int
allsum

Return the sum of all external items.

Quality will be the worst quality.

If error in conversion to double, the value will be omitted, and quality will be set to BAD

allsum() int (default)
allcountvalue

Return the number of all external items that have value equal to the given value.

Quality will be the worst quality.

If error in conversion to double, the value will be omitted, and quality will be set to BAD

allcountvalue(5.1) int
allgreatherthanavg

Return the the average of all values greather than X.

If error in conversion to double, the value will be omitted, and quality will be set to BAD

allgreatherthanavg(XX) 8 byte float (default)
alllessthanavg

Return the the average of all values less than X.

If error in conversion to double, the value will be omitted, and quality will be set to BAD

alllessthanavg(XX) 8 byte float (default)
movingavg

Calculate the moving average of the last 5 values of calculation defined in the bracketts

movingavg(ex1) 8 byte float (default) or custom scalar number
movingavgXX

Create an moving average of last XX values

movingavg10(ex1) 8 byte float (default) or custom scalar number
deltaavg

Create an moving average of last 5 values, but the value is only updated when calculation is based on 5 new values.

deltaavg(ex1) 8 byte float (default) or custom scalar number
deltaavgXX

Create an moving average of last XX values, but the value is only updated when calculation is based on XX new values.

deltaavg10(ex1) 8 byte float (default) or custom scalar number
movingtimeavg

Calculate the moving tima average of the last 5 seconds of calculation defined in the bracketts, Value updates every 5 seconds. First calculated value will be first time a measurement is equal or grearter than next 5 sec expected timepoint.

movingtimeavg(ex1) 8 byte float (default)
movingtimeavgXX

Calculate the moving average of the last XX seconds of the calculation defined in the bracketts. If XX is 60, then the function return the moving average of the last 60 seconds.

movingavg100(ex1) 8 byte float (default)
deltatimeavg

Calculate the moving time average of the last 5 seconds of the calculation defined in the bracketts. This calculation return a new value ecery 5 second. The calculation is also synchronized in time, a new value at 10:00:00, 10:00:05, 10:00:10, etc. First calculated value will be first time a measurement is equal or grearter than next 5 sec expected timepoint.

deltaavg100(ex1) 8 byte float (default)
deltatimeavgXX

Calculate the moving time average of the last XX seconds of the calculation defined in the bracketts. If XX is 60, then the function return the moving average of the last 60 seconds every 60 seconds. The calculation is also synchronized to XX. If XX is 60 a new value will becalculated every minutes e.g. 10:01:00 and 10:02:00 , etc. If XX is 600, there will be a new value at 10:00:00, 10:10:00, 10:20:00, etc.

deltaavg60(ex1) 8 byte float (default)
delay Delay the value 1 step. delay(ex1/ex2) 8 byte float (default)
delayXX Delay the value XX step. delay5(ex1/ex2) 8 byte float (default)
pulsedetect Detect a pulse defined as the previous value below 0.5 and current valiue above 0.5. If a puls is detected the return value is 1 else the value is 0. pulsedetect(ex1) 8 byte float (default)
pulsecount Count the number of detected pulses. A puls is defined bu the function pulsdetect. The counting starts from 0 when Apis is started. pulsecount(ex1) 8 byte float (default)
filetime2oadate

Converts a FILETIME value into the equivalent OLE Automation date.

A Windows file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC). Windows uses a file time to record when an application creates, accesses, or writes to a file.

An OLE Automation date is a 8 byte floating-point number whose integral component is the number of days before or after midnight, 30 December 1899, and whose fractional component represents the time on that day divided by 24. The base OLE Automation Date is midnight, 30 December 1899.

filetime2oadate(ex1) DATE
unixtime2oadate

Converts a Unix Timestamp into the equivalent OLE Automation date.

Unix Timestamp is the number of seconds that have elapsed since UTC 1970-01-01T00:00:00Z.

The OLE Automation data type is described above.

unixtime2oadate(ex1) DATE
unixtimems2oadate

Converts a Unix Timestamp with milliseconds (Unix time multiplied with 1000), into the equivalent OLE Automation date.

Unix Time and OLE Automation data types are described above.

unixtimems2oadate(ex1) DATE
getdatetime

Take the timestamp of the value and use this as the value itself.

getdatetime(ex1) DATE
getunixtime

Take the timestamp of the value and convert this to Unixtime. The decimal part is milliseconds.

getunixtime(ex1) 8 byte float (default)
if-elseif-else

Add possibilities to have IF - ELSEIF - ELSE construction in function Items. ELSE part is mandatory, but the ELSEIF can be omitted or added several times.

If (ex1 > 2)

{ex1*ex2}

ElseIf (ex1 > 1)

{(ex3+1)*ex1}

Else {5.0}

8 byte float (default)
LogicDescriptionExampleItem Type
>Greater than(ex1 > ex2)8 byte float ( 0.0 or 1.0)
>=Greater than or equal( ex1 >= 2.5 )8 byte float ( 0.0 or 1.0)
<Smaller than( ex1 < 3.4)8 byte float ( 0.0 or 1.0)
<=Smaller than or equal( ex1 <= ex2 )

8 byte float ( 0.0 or 1.0)

==Equal( ex1 == ex2 )

8 byte float ( 0.0 or 1.0)

<>Not equal( ex1 != ex2 )

8 byte float ( 0.0 or 1.0)

!=Not equal( ex1 != ex2 )

8 byte float ( 0.0 or 1.0)

!Not!( ex1 > ex2 )

8 byte float ( 0.0 or 1.0)

Logical expressions are written like (ex1 > 4.5), the result however will be a double value either 0.0 (false) or 1.0 (true). These expressions can be a part of a formula.

The result of a calculation will always be a double value.

External Items

The values ex1, ex2 are the values from the external items defined in the external items attribute.

Example 1

Expression:
ex1+ex2 + ex1+ 5.14

External Items:
ex1 : Worker.signal1
ex2: Worker.Signal2

Example 2

Expression:
(ex1+3.2) / ex2+5.3 / ( ex2-ex1 )-ex3 + Ln( ex1+ex2 ) * ( ex1 > 5.2 )

External Items:
ex1 : Worker.signal1
ex2: Worker.Signal2
ex3: Worker.Signal4 

Example 3

Expression:
Ln( ex1+ex2+ Abs(ex1) )

External Items:
ex1 : Worker.signal1
ex2: Worker.Signal2