1 of 1 people found this helpful
You could take a general approach and hide the value for any bad status bu multistating the symbol. For example, if you have a Value symbol set to Sinusoid then multistate it based on Sinusoid too. Then for the "Color for bad data" set it to No Color:
Note, that will hide it for any bad status.
If you want to get a particular bad status then you'll likely best to use VBA (without the need of using an AF Formula or Dataset calculation).
An example of how to handle it via VBA would be as follows - you'll need to adjust the status number for the No Data error state:
Dim st As Variant, val As Variant val = Value1.GetValue("*", st) If st = 248 Then Value1.Visible = False Else Value1.Visible = True End If
thank you for replying.
I did what you suggested. I added the following VBA code in the Display_Open procedure.
Private Sub Display_Open() Dim vrStatus As Variant Dim MyValue As Variant MyValue = valSymbol.GetValue("*", vrStatus) MsgBox "MyValue: " + CStr(MyValue) + ", Status: " + CStr(vrStatus) End Sub
When the user has read access on the PI Tag, the message box shows: "MyValue: 2, Status: 0"
When the user has no read access on the PI Tag, the message box shows: "MyValue: , Status: -1"
What does the status -1 mean ?
A non-zero status is usually the result of an error state in the PI Point/AFAttribute/Dataset. It will depend on the error. -1 may be a general error status, or a specific one for No Data. I don't know if the full list of status values are published anywhere.
Thank you for your help.
Actually, I would like to hide the value symbol, only when the user has no read access on the associated PI tag, not for bad value. So, when the status is 248.
Why the status is -1 and not 248 whereas the user has no read access on the PI tag ?
Hello Nicolas, and Rhys,
Returned status, when positive, can be correlated with the System digital state set: PI System Management Tools > Points > Digital Sates > System.
So in this case, statis 248 means No Data.
On my end, when a PI tag cannot be read, Status returned is 0. and value is empty.
If it can be read, and value is good, Status is also 0 but Value is also returned.
Hope this helps!
I believe the PB symbol.GetValue implementation might be different than the more familiar PI SDK calls/conventions. What is the version of PB? I wonder if there is some PI API functions being used. For example, -1 can indicate Bad Point Number in PI API...
To resolve the issue, a more familiar approach (rather than trying to decipher the peculiars of vrStatus) might be to get the tagname associated with the symbol, and make a test PISDK snapshot call. The returned PIValue.Value should be a DigitalState object (if value.IsGood=false), and then the digstate.Name or Code can be inspected and different system digital states can be handled as desired.
Hello Barry, Patrice and Rhys,
thank you for all your replies.
I did what Barry suggested. I use PB 2015.
I developed the following code:
Private Sub Display_Open() Dim srv As Server, piPt As PIPoint, piVal As PIValue Set srv = Servers.DefaultServer On Error GoTo ErrHandler Set piPt = srv.PIPoints("MyPoint") Set piVal = piPt.Data.Snapshot If (Not piVal.IsGood()) Then Dim digState As DigitalState Set digState = piVal.Value If (digState.Code = 248) Then ' Read access error, hide the symbols End If End If Exit Sub ErrHandler: Dim errCode As String errCode = Hex(Err.Number) If (errCode = "80070005") Or (errCode = "8004040B") Then ' Read access error, hide the symbols End If End Sub
Actually, if the user has no read access on the PITag, the PIData.Snapshot property raises an exception. That's why, I check the error number in the error handler.
Is there a better way to check if the user has read access on a PI Tag ?
If there is no better way, I will content with this solution.