Examples of Expressions
The following examples may be adapted to your application, or they may spark an idea for what you can achieve using expressions.
Simple math. Add two AI tag values together:
[Valve1Flow] + [Valve2Flow]
Using logic to check conditions. All the tags in this example are Digital Inputs that will be 1 (TRUE) or 0 (FALSE). In this test, we’re checking whether either both of Valves 1 and 2 are open, or else if the overflow valve is open.
( [Valve1Status] && [Valve2Status] ) || [OverflowValveStatus]
Limit a return value to be no less than 0
Max([Valve1Flow], 0)
Are you viewing an object in the Idea Studio or in the Operator View? The following returns TRUE in the Idea Studio and false otherwise.
ParentWindow()\Editing
Write a 1 when a test is true, otherwise write nothing. The following example takes advantage of the fact that VTScada will not write an Invalid.
If the following were being used to control a pump for example, it would turn the pump on when the flow rate went above 1500, but would not turn the pump off.
[Flow] > 1500 ? 1 : INVALID
Conditional math. Add together only the MVAR values (in AI tags) for generators whose breakers are closed (DI tags == 1)
([Gen1Breaker] == 1) * [Gen1Mvar] +
([Gen2Breaker] == 1) * [Gen2Mvar] +
([Gen3Breaker] == 1) * [Gen3Mvar]
Get the value of an INI file variable for display:
Scope(Code, "MyAppVersion")
Build an English text string based on values in bits of registers read from a PLC.
Bit([AI3], 15) ? "On " : "Off "
Calculate a steam flow from a DP cell reading on an analog tag:
SQRT((([FT-518-RAW])/4095)*100) * 1000
Calculate a steam flow from a DP cell reading on an analog tag. Force to 0 if a digital tag is not on:
[BLR-001]==1 ? SQRT([FT-506-RAW]) * 3000 : 0
Figure out the bit number that is turned on in a word read from a PLC into an AI tag:
Int((Log([AI3] % 65536) / Log(2)) + .5) + 1
Create a time string based on an analog tag, AI3, and replace the 00 hour reading with 24:
Concat("HE ",Replace(Substr(Time((Scope([AMA.STA.MW-TS]) - (9 * 3600)) % 86400, 2), 0,2), 0,2,"00","24"))
Get the name of the PC that the application is running on:
\RPCManager\WkStnName
Get the version of VTScada that is running:
Version()
Create a flag that toggles every 10 seconds
Latch(AbsTime(1, 20, 0), AbsTime(1, 20, 10))
Given a Context-derived tag at the top level of the tag hierarchy named "Station 1", suppose that you want an expression in a calculation tag that will return the total number of unacknowledged alarms in that context. The expression would be:
\AlarmManager\GetContainerNumUnacked([<Station 1>]\Root)
Check if any user is signed in to a client PC. This example returns a message, but you could just as easily return a 1 or 0 to determine whether a control action should proceed. (A unilingual example.)
\SecurityManager\IsLoggedOn() ? "" : "Authorized Access Only. Please sign in."
Get the name of the operator who is signed in:
\SecurityManager\GetUserName()
Given an application with the following set of custom privileges, you want to configure the Push Button widget so that confirmation is required when the button is pressed by anyone whose account does not have the "Confirmation Not Reqd" privilege.
<SECURITYMANAGER-PRIVAPP>
PrivBitsTotal = 3
PrivDesc0 = Page Priv,0
PrivDesc1 = Operational Priv,1
PrivDesc2 = Confirmation Not Reqd,2
Confirmation Not Reqd is enumerated as privilege 2, therefore its index value is 16 + 2 = 18. The expression for the Confirmation Dialog parameter of the widget would be:
1 - PickValid(\SecurityManager\SecurityCheck(18, 1), 0)
In a parameterized page, find the full name of the tag that was used for a given parameter:
\NameOfGivenParameter\Name
In a parameterized page, where a parameter is of type tag, use the name of the tag as part of the title:
concat("Details for: ", \NameOfGivenParameter\ShortName)