Hello, I´m trying to count how many times an specific instrument was in alarm due to a low value. Is there an specific instruction in PI datalink or an equation that can solve my problem?. Thanks!
Thanks for reaching out to us on PI Square.
This can be done in PI DataLink, and you'll need to use the PI Advanced Calculation function to do this.
You'll want to select the tag as you Data Item, give it some kind of time interval, in your filter expression you'll want to put 'tagname' < (whatever value the low limit is). Calculation mode should be count. I suspect you're looking for the actual number of archived events below that lower limit, rather than the amount of time spent below that lower limit so you'll want to Open Adavanced and use "event-weighted" as a calculation basis rather than time weighted with Expression sampling being "compressed."
In the end you'll get something that looks like this:
And the output cell should contain something like the following: =PIAdvCalcFilVal("<DUMMY_SERVER_NAME>\SINUSOID","Y","T","'sinusoid' < 70","count","event-weighted","compressed","10m",0,1,0,"")
In my example above, I'm getting the number of events the "sinusoid" tag which were below the value of 70 between yesterday at midnight and this morning at midnight.
If you're looking for the amount of time the tag spent below that lower limit, let me know and we can alter the calculation to give you that instead.
I would always recommend first creating a calculation tag for this pupose, but if this is not possible then a fairly pain free way to do this would be to use the PI-SDK, pull back all the values, and iterate through them all, increasing a counter every time you first go below the limit, and keep a Boolean to say whether you're below limit so you know when you're back in range. Presumably when the tag goes below range there could be many more values also under range so Datalink's native features come up a bit short (ie. there could be 100 values under range, but it only went under range once or twice, say a tag updating every 10 seconds)
In Excel VBA editor (Alt+F11) add the PI-SDK 1.3 Type Library reference (Tools > References)
I created something simple like this, it shows the count and lists the first time the value went below range.
And this is the code for the button
Dim pisrv As PISDK.Server
Dim pipt As PISDK.PIPoint
Dim pivals As PISDK.PIValues
Dim pival As PISDK.PIValue
Dim belowLimit As Boolean
Dim prevBelow As Boolean
Dim vCount As Integer
' Clear previous results
Range("C8").Value = ""
Range("E:F").Value = ""
' Get User Input
vDate = Range("C2").Value
vTag = Range("C4").Value
vLow = Range("C6").Value
Set pisrv = PISDK.Servers("YOURPISERVERNAME")
Set pipt = pisrv.PIPoints(vTag)
Set pivals = pipt.Data.RecordedValues(vDate, vDate + 1, btAuto)
For Each pival In pivals
If pival.Value < vLow Then
If belowLimit = False Then
belowLimit = True
vCount = vCount + 1
Range("E" & vCount + 1).Value = pival.TimeStamp.LocalDate
Range("F" & vCount + 1).Value = pival.Value
belowLimit = False
Range("C8").Value = vCount
The answers above may have already provided what you desire. However, the subject line and the actual text of your thread cause me to wonder what answer it is that you are actually seeking...
Would you like to count the number of times that a point value was below a limit?
How many times was the threshold crossed going into alarm?
Next question would be whether we only count values were archived, or either snapshot or archive?
If counting snapshot occurrences, this could done with a totalizer or performance equation. If just looking at archived values, it's possible either the DataLink and/ or the SDK examples above are golden.
Thank you all for your answer. I finally use Robert Schmitz advise; using Calculated Data in Datalink; with the expresion TAG< value; where value is the low limit of the alarm. This allow me to count in one day how many times the value was below the alarm.
Thank you all!!!
Retrieving data ...