Best approach to Ignition Status Counter script?

So I have a bunch of tags coming from a device that give random numbers from their modbus registers , that I made some string tag that converts all those numbers into readable words such as 61 = “On” or 1412 = “Limit High” etc ,so that they are comprehendable and not just a bunch of codes you need a manual to read
and all these tags have different sets of values that they can have so they don’t even all match

then I have an All status tag which then takes all the possible strings from all these different tags and then makes a different string displaying that status
for example

if ({[.]Limit 1 Status} = “Error”,
“Limit 1 Error”,
if ({[.]Limit 2 Status} = “Limit Low”,
“Limit 2 Low Alarm”,
if ({[.]Limit 2 Status} = “Limit High”,
“Limit 2 High Alarm”,
if ({[.]Limit 2 Status} = “Error”,
“Limit 2 Error”,
if ({[.]ProfileDisable Status} = “On”,
“Profile Disabled”,

this works for these however I am trying to make a condition for “multiple alarms on” for when several of these are on

is there a way to make a counter with an expression or even a script that , whenever one of these tags string says “On” then the counter goes up by 1? that way I can make it so if its ever more than 1 at a time i can have a “Multiple Alarm Status” for this expression

Vision or Perspective

ah right, perspective

I’m not very familiar with perspective so someone else can step in. But I think it would be easier for them to be actual alarms in Ignition instead of “alarm tags”. Best approach would probably creating a UDT for all this. And then having instances of the UDT for each alarm. Adjust your folder structure so you can utilize a param and indirect addressing. Then it should be easier to check if more than one alarm is active.

Not sure if it matters Vision or Perspective, it sounds like this is just tags right now.

I’m not entirely sure what the question is to be honest. Perhaps a little more detail?

I think you’re making life very difficult for yourself and whoever has to debug the code after you.

  • Have your original Modbus tag report the actual Modbus code, e.g. 61. Now the Modbus experts don’t need a manual to reverse back from text to code.
  • Create boolean expression tags based on the Modbus tag for each condition you need to monitor. e.g., ProfileDisable and give it the expression {[.]ModbusTag1} = 61. Now you have a simple tag that is true when ModbusTag1 is 61. Do the same for Limit Low, Limit High, Error, etc. You can now use these in indicators, etc., with no messing with strings.
   Tag name            Type        Data    Expression
   Motor 1 Modbus      OPC         Int
   Motor 1 run         Expression  Bool    {[.]ModbusTag1} = 61
   Motor 1 limit high  Expression  Bool    {[.]ModbusTag1} = 1412
  • You can now count the number of tags that are true using another expression tag. e.g.,
   Tag name            Type        Data    Expression
   True Tag Count      Expression  Int     {[.]Motor 1 run} + {[.]Motor 1 limit high}

Another trick you can do is to use a tag’s Meta Data | Documentation or Tooltip to hold a string expression such as “Profile Disabled”. You can then bind a component’s props.text to
[default]test/True Tags Count.Documentation.