A calculated variable allows you to:
Note: Calculated variables are evaluated on the I/O server only when a subscription to the calculated variable exists.
To configure a calculated variable, you use a variable tag that addresses an I/O device with its protocol set to "CICODE". If the variable tag address is a valid Cicode expression, the Cicode I/O device will calculate the result of the expression and present it as the tag value.
Note: If the expression in the Address field reads from or writes to another tag in the system, the calculated variable is added towards the point count.
The Citect SCADA Example Project includes a number of tags that support the Steel Mill page. These tags include two tags that identify the length and width of the coil that is currently loaded on the uncoiling station.
Tag Name |
I/O Device |
Address |
Data Type |
Units |
---|---|---|---|---|
Entry_CoilLength |
SteelMillDisk |
R10 |
REAL |
meters |
Entry_CoilWidth |
SteelMillDisk |
R13 |
REAL |
millimeters |
Using a calculated variable, you could determine how many square meters of steel will be produced by the coil that is currently uncoiling. To do this, you could create the following calculated variable on an I/O device called "CicodeIODevice".
Tag Name |
I/O Device |
Address |
Data Type |
Units |
---|---|---|---|---|
Entry_CoilArea |
CicodeIODevice |
Entry_CoilLength * (Entry_CoilWidth)/1000 |
REAL |
m2 |
You could then use the value generated by this tag at runtime to estimate the production potential of the current coil.
Using a calculated variable, you can call a Cicode function for diagnostics and determine the state of an I/O device.
Tag Name |
I/O Device |
Address |
Data Type |
---|---|---|---|
IOServer_Mixer_PM800_State |
CicodeIODevice |
IODeviceInfo("IOServer_Mixer_PM800", 10) |
STRING |
In the example above, a CICODE function has been used in a calculated variable to determine the state of the specified mixer (for example, online or offline).
Note: Cicode functions used for calculated variables need to be non-blocking functions.
Using a calculated variable, you can trigger an alarm when an I/O device goes offline. In this case, you will need to:
Tag Name |
I/O Device |
Address |
Data Type |
---|---|---|---|
IOServer_Mixer_PM800_State |
Mixer |
IODeviceInfo("IOServer_Mixer_PM800", 10) |
STRING |
Alarm Tag |
I/O Device |
Expression |
---|---|---|
IOServer_Mixer_PM800_Offline |
Mixer |
(StrToInt(IOServer_Mixer_PM800_State) = 16) OR (StrToInt(IOServer_Mixer_PM800_State) = 32) |
In the example above, the variable tag calculates the state of the mixer. The alarm will be triggered if the tag is calculated to be 16 (offline) or 32 (disabled).
Using a calculated variable, you can perform mathematical calculations. In this example, the variable tag calculates the quotient of two integers and in the event of the divisor being 0 returns an error code.
Tag Name |
I/O Device |
Address |
Data Type |
---|---|---|---|
Divide_Tag_Value |
CicodeIODevice |
Divide(4,9) |
REAL |
REAL FUNCTION Divide( INT iDividend, INT iDivisor)
REAL iResult;
INT iError;
Errset(1);
iResult = iDividend / iDivisor
iError = isError();
Errset(0);
RETURN iResult;
END
See Also
Published June 2018