16.7. Multiple States

This example compares the value of an "input" point to one of 5 possible states, and writes the value of an integer between -2 and 2 to a DataHub point named "output". The variables in this example were defined previously in Multiple Variables.

  1. In the HiLoAlarm template's Configuration Template window, go to the States section.

  2. Add the following states and scripts:

    On Name Entry Condition OnEntry Script
    Yes HiHi input.DblVal > hihilimit app.WritePoint(output, 2);
    Yes Hi input.DblVal > hilimit app.WritePoint(output, 1);
    Yes LoLo input.DblVal < lololimit app.WritePoint(output, -2);
    Yes Lo input.DblVal < lolimit app.WritePoint(output, -1);
    Yes Normal true app.WritePoint(output, 0);

    You can use the use the Move Up and Move Down buttons to rearrange the states in the list. The order is important because the states are evaluated from top to bottom. Notice, for example, that LoLo is listed before Lo, and that Normal is at the end. This causes the evaluator to first check the highs in order from most extreme to the least extreme. Then it checks the lows from most extreme to the least extreme. If none of those is true, then it returns normal, which is always true.