Creating a Virtual Parameter Alarm: A Worked Example

Modified on Wed, 23 Sep at 12:48 PM

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 a parameter has been created, creating an alarm based on it 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.

 

Creating a Virtual Parameter suitable for use with an Alarm

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

General virtual parameter tutorials can be found in the article: Creating a new virtual parameter.

But there are a few additional considerations when creating 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:

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.

 

When a success message pops up, you know you’ve created a virtual parameter!

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

 

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

 

Let's Start Coding!

We are going to write a script that will fail if either input does not return a value.


First, let’s bring in the inputs 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 how to find and fix an error.

 

The Full Program

/* This is a 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.

 

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article