Notes on Quality
July 27th, 2011I have a couple notes on quality to share. Not code quality or manufacturing quality, but OPC quality. For a quick read & good background on how the OPC quality integer is constructed, read this. I needed a couple SQL functions that mirror the IAS quality checking functions. FYI, for those that don’t know, there are 5 of these functions: IsGood, IsBad, IsUncertain, IsInitializing, & IsUsable.
Here’s a somewhat abbreviated run down of how the OPC quality number is constructed. An OPC quality is made up of 4 chucks: extended status (vendor specific; 1 byte), major status (good, bad, or uncertain; 2 bits), minor status (based on the major status; 4 bits), and limit status (is it clamped or not; 2 bits). For each major status, there are 16 available minor statuses possible (0-15) though only the first 8 are defined.
I ran a quick test to reverse engineer the IAS functions (see script at bottom of blog). What I found was the following:
| Major | Minor | IsBad | IsInitializing | IsUncertain | IsGood | IsUsable |
| 0 | 0-7 | True | False | False | False | False |
| 0 | 8-15 | False | True | False | False | False |
| 1 | 0-7 | False | False | True | False | True |
| 1 | 8-15 | True | False | False | False | False |
| 2 | 0-7 | True | False | False | False | False |
| 2 | 8-15 | True | False | False | False | False |
| 3 | 0-7 | False | False | False | True | True |
| 3 | 8-15 | True | False | False | False | False |
To summarize the table, it looks like they appropriated part of the bad quality range (major = 0) for initializing which makes sense. Though you could argue that there was already a status defined for this scenario (Not Connected: Major = 0, Minor = 2). Major status 2 isn’t used anywhere, so it got lumped into Bad, which also makes sense. The minor statuses 0-7 for Good (Major = 3) and Uncertain (Major = 1) work as expected, but 8-15 got lumped into Bad. I know they’re not defined, but they’re still part of the Good/Uncertain major status. Glad I ran the test. Maybe this is different in later versions (the tested version is 3.0 SP2). The final observation is that IsUsable checks the quality for Good or Uncertain as well as checking the value is also a valid value (i.e. not NaN).
The test script:
(The one interesting note here is that you can write directly to the UDA.Quality attribute, which could be useful if you’re doing something fancy surrounding the data’s quality.)
Dim i as Integer;
‘ Log header row
LogMessage("Value,Quality,IsGood,IsBad,IsUncertain,IsInitializing,IsUsable");
‘ Iterate through all of the possible OPC qualities
For i = 0 to 255
‘ Force the PV quality
Me.PV.Quality = i;
‘ Log data row for the quality
LogMessage(
Me.PV.Value + "," +
Me.PV.Quality + "," +
IsGood(Me.PV) + "," +
IsBad(Me.PV) + "," +
IsUncertain(Me.PV) + "," +
IsInitializing(Me.PV) + "," +
IsUsable(Me.PV));
Next;‘ Log message for end of test
LogMessage("——————-");

