Creating a Virtual Parameter Alarm: A Worked Example

This guide is intended to show users how to:

  1. Create an Alarm from a Virtual Parameter.
  2. Create a Virtual Parameter suitable to alarm with.
  3. Understand how these items go together.

Creating an Alarm from a Virtual Parameter

If you already know of a parameter that has been made, creating an alarm based on
this parameter is fairly straightforward.

  1.  Click ‘Add Alarm’.
  2. Click ‘Select Mask’.
  3. Select the ‘Identity’ mask.
  4. Click ‘Target Input’.
  5. Find your virtual parameter and select it.
  6. Fill out the rest of the alarm.
  7. Save.
MakeAVPAlarm.gif

Creating a Virtual Parameter suitable for use with an Alarm

Creating a virtual parameter requires knowing mask script OnPing Script Language.

General virtual parameter tutorials can be found here Creating a new virtual parameter.

But there are some additional things to understand when making a Virtual Parameter for alarms.

Your Parameter Must Be Clear On Zero

For your virtual parameter to work correctly, it must be clear on zero.  Any value other than zero is considered tripped.

Your Parameter Can Include Multiple Locations

Often this feature is very useful.  In the example below, we will combine a comm loss from multiple locations into a single comm loss.

Writing The Script #

Here is a workflow that is useful for working on virtual parameter scripts.

We are going to build a two-device comm loss script from scratch and illustrate each point.

Here is an overview of the creation page:

VirtualParameterOverview.png

All new scripts require at least one Virtual Parameter to be made.  This helps prevent bad scripts from being created.

I like to program in a loop which I start by making every script the same.

  1. Name the Parameter
  2. Name the description the same
  3. Name the script
  4. Pick the group
  5. Add 1 input

6. Write this code…

output := 3.0;

Hit the test button.

CreateANewSiteCommFail.gif

When you see a success pop up, you know you have made a virtual parameter!

Now, to start editing find the VP you just created in the list and go to it.

ViewAllVPs.png

Do this so you can hit the refresh button on the browser without it resetting your virtual parameter script.

Lets Start Coding! #

We are going to write a script that will fail if either of the two inputs fails to return a value.

First, let’s bring inputs in and add a comment for other users.

Comment explaining what is happening…

/* This is multi-device comm fail alarm. It will return a status code indicating that the Nth device is in comm fail. 
The comm fail table reads as following
0 all clear
1 more than one device in comm fail
2 device one in comm fail
3 device two in comm fail ...
n device n in comm fail
We will code what each device is on display of alarm (HMI status button)*/

Bring in inputs

I like to name my input indexes for future reference.

onPingCommLossTimeIndex := 1;
deviceOneIndex := 2;
deviceTwoIndex := 3;

TEST WHILE YOU GO… #

I like to hit test after each step in the coding process.

The animation below shows finding and fixing an error.

ErrorFixError.gif

The Full Program #

/* This is multi-device comm fail alarm. It will return a status code indicating that the Nth device is in comm fail. 
The comm fail table reads as following
0 all clear
1 more than one device in comm fail
2 device one in comm fail
3 device two in comm fail ...
n device n in comm fail
We will code what each device is on display of alarm (HMI status button)
*/

numberOfCommunicatingDevices := 2;

onPingCommLossTimeIndex := 1;
deviceOneIndex :=2;
deviceTwoIndex := 3;


onPingCommLossTime := latestInput(onPingCommLossTimeIndex);

/* Guarded input for onpingCommLoss */
if (isUnit(onPingCommLossTime)) then 
onPingCommLossTime := 30.0;
end_if;


deviceOneAcc := 0;
deviceTwoAcc := 0;

WITH t FROM now - minutes(round(onPingCommLossTime)) TO now EVERY minutes(1) DO

 a := input(deviceOneIndex,t);
 b := input(deviceTwoIndex,t);


IF not(isUnit(a))
 THEN deviceOneAcc := deviceOneAcc + 1;
 END_IF;

IF not(isUnit(b))
 THEN deviceTwoAcc := deviceTwoAcc + 1;
 END_IF;

 
END_LOOP ;


/* Alarm Preparation Construct
   Each device corresponds to an output
   0 means all clear!

   You can reference these output in an HMI
*/
output := 0;

/* Device two code is 2 */
IF deviceTwoAcc == 0 then 
output := 2;
end_if;


/* Device One Code is 1 */
IF deviceOneAcc == 0 then 
output := 1;
end_if;

There is a lot going on in this code and perhaps in a follow-up post, I will explain it all.  However, notice that the indexes needed to be defined are written at the top.

  • onPingCommLossTimeIndex
  • deviceOneIndex
  • deviceTwoIndex

Each should correspond to a real parameter that you want to reference.

If you have any thoughts, ideas, or questions, please feel free to leave a comment below or use the contact feature at www.onping.net

Powered by BetterDocs