16 Replies Latest reply on Aug 13, 2010 6:20 PM by cescamilla

    State or Quality of an Analog point

    richs04

      I am trying to figure out what the State or Quality of a analog point.  I see the values in Digital States - SYSTEM (like Manual is 230) useing the managment tool but I need to get and set the state for all my points, both digital and analog.  Below is a C# sample of what I am doing.  I can get the data value but can't figure out the Quality of the data.

      PointValues pvsSnaps;
      pvsSnaps = lstData.get_Snapshot(out nvsErr);

      foreach (PointValue ptValue in pvsSnaps)
      {
         myValue = ptValue.PIValue;
         if (myValue.Value.GetType().IsCOMObject)
         {
              m_myDigState= (PISDK.DigitalState)myValue.Value;
              pival = (Single)m_myDigState.Code;
         }
         else
         {
             pival= (Single)myValue.Value;  <<<<  Have the value but need to check if good (0) or Manual (230)
         }
      }

        • Re: State or Quality of an Analog point
          hanyong

          Hi Richard,

           

          You can get the string representation of the Digital State using the "Name" property instead of the getting the integer code of the Digital State. Something like:

          foreach (PointValue ptValue in pvsSnaps)
          {
             myValue = ptValue.PIValue;
             if (myValue.Value.GetType().IsCOMObject)
             {
                  // when tag is a digital type
                  // or when analog tag has a system state value 
                  m_myDigState= (PISDK.DigitalState)myValue.Value;
                  String StateName = m_myDigState.Name;
             }
             else
             {
                 pival= (Single)myValue.Value;  
             }
          }

          This way you can get the string directly when the value of the tag is a digital state, instead of having to check the code and map to the string manually.

          Just to add on about looking at qualities of a tag value. In some cases, quality may not be represented as a digital state. For example, OPC interface recognize certain quality flags provided by OPC Server as "Questionable". In these case, the default setting is to save the value and mark it as "Questionable" in value attributes. There is another post here that shows how you can retrieve attribute flags using PI SDK.

           

          Hope this helps

            • Re: State or Quality of an Analog point
              cescamilla

              Richard,

               

              As Han yong's code suggests, the status can be seen if it is a digital state, when you get a value the digital state of that tag is 0. You are better suited using the 'Questionable','Substituted' or 'Annotated' attributes for the values you are sending.

                • Re: State or Quality of an Analog point
                  richs04

                  Thanks for the help but what I am really after is the SDK replacement for the API call:

                   

                  int32 pisn_getsnapshot(int32 pt, float PIPTR * rval, int32 PIPTR * istat, int32 PIPTR * timedate );

                   

                  Returns
                  >0  System error
                  0 Success
                  -1 Point does not exist
                   
                  Arguments
                  pt (passed )            Point number
                  rval (returned)         Value in engineering units, undefined for integer and digital points
                  istat (returned)        Status for type real points and value for integer and digital points
                  timedate (returned)  Time stamp

                   

                  It seems the API call can return the status of "real points" which is what I am looking for.  The pisn_putsnapshot function allows setting of "real points" status.  I can see how to read both a digital and real value with the SDK but I can't figure out the status for real values.

                    • Re: State or Quality of an Analog point

                      In PI, you either get a value OR a digital state from the "system" state set, in case of an error. The pisn_getsnapshot PI API call is a little confusing in how it exposes this - it is trying to reuse the same parameters for various purposes (value or error, it depends...).

                       

                      In PI SDK, you simply need to check whether the value is a COM object (a PISDK.DigitalState, more specifically) and then go from there: if it's a "real" PI Point and the value is a Digital State, that means you have an error code (and no value) - otherwise you have an actual (real) value and not error/digital code.

                       

                      In other words, there is no such thing as a "status for real values". The PI API documentation should read "status code for a PI Point configured with a 'real' type". Hope this clarifies a few things...

                        • Re: State or Quality of an Analog point
                          richs04

                          The pisn_getsnatshot, in the API, does return a status for analog points.  The current application I am upgrading makes the call and is getting the status of analog points, along with the value, now.  The status returned for analog points are currently 0 for good and 230 for Manual. 

                            • Re: State or Quality of an Analog point

                              There is also the "IsGood" property of a PI Value to indicate quality.  If you have an analog point then you would expect a numerical value to indicate a good value, if the IsGood property is false then you will typically have an error digital state as the value - the state will give you a description of the error aka the status.

                               

                               

                              • Re: State or Quality of an Analog point

                                Richard Sellars

                                The pisn_getsnatshot, in the API, does return a status for analog points. 
                                True, but what I'm saying is that it won't return BOTH a value and a status.

                                 

                                Richard Sellars

                                The status returned for analog points are currently 0 for good and 230 for Manual.
                                When you you get a status (istat) of 0, then you probably get an actual value (in rval). The question is: what do you get in rval when you get a status (istat) of 230?

                                  • Re: State or Quality of an Analog point
                                    richs04

                                    Currently the app considers a stat of 230 (Manual) to be good also and uses rval, which makes it all the more confusing.  I looked at the help file for "IsGood" which seems to indicate the return of a digital state if bad.  But what is BAD???  And how do I set the status when I call update on a analog point? 

                                      • Re: State or Quality of an Analog point

                                        Richard Sellars

                                        Currently the app considers a stat of 230 (Manual) to be good also and uses rval, which makes it all the more confusing
                                        Back to my question: what do you get in rval when you get a status (istat) of 230? A non-zero istat value for a real point should be considered bad, and would normally be mutually exclusive with rval.

                                      • Re: State or Quality of an Analog point

                                        The PI Server stores data for analog values as either a value, or a digital offset for the SYSTEM state set.  The only additional information for an analog event are the value attribute bits, or flag bits.

                                         

                                        So in PIAPI language, when an analog value is retrieved, check the status (istat), and if it is non-zero, then that is it's value (plus any additional flag bits).  If the status is zero, then the analog value is relevant.  For a non-zero status, the call will return a real value of 0.0.  The value is set by the translator layer in the PI Server (translate PI3 to PI2, or PIAPI format).

                                         

                                        In PISDK language, if an analog value has the PIValue.IsGood boolean set to false, or a digital in the value variant, then that would be equivalent to a real value of 0.0 as returned by the PIAPI.  We just overload the use of the PIValue.Value variant to give either the digital state or the real value.  As with the PIAPI, the PISDK also provides the value attributes for an additional bits.

                                         

                                        There have been requests, discussion and design for associated status values of non-zero when the analog value is non-zero.  This falls under the "data quality" enhancement request for the PI Server.  This would provide the functionality that I believe you are looking to use.

                                          • Re: State or Quality of an Analog point
                                            richs04

                                            I would like to thank everyone for all their help.  I have a feeling the original app didn't do everything I was told.  I am thinking of using an annotation string to hold a quality value ie: "Q-230" or "Q-0", as long as it doesn't make updating points difficult.

                                              • Re: State or Quality of an Analog point

                                                Richard, I am struggling without knowledge of your application to see the benefit of storing an annotation if a value has 0 or 230 as a quality.  For me, if you have a good value (i.e it is within range of the point configuration and is of type of the point type) then it implies a quality of 0.  What benefit in your application will you get from storing a value with a quality of 230?  I guess in the PISDK re-write of your application it would make more sense to write a digital state as the value instead of writing a string annotation as this would mimic the PIAPI behaviour - or even flagging a value as Questionable, i.e. you have a value to store but it's quality is questionable due to other inputs.

                                                 

                                                It depends on the specific need of your application and how the quality of 230 is interpreted.

                                                  • Re: State or Quality of an Analog point
                                                    richs04

                                                    In our application we monitor many devices.  In our industry all data values are releivent.  The data received can have different quality levels, good, suspect, poor, manually entered, replaced, device problem, out of range and bad (0 to 7 respectively).  A quality of good to manually entered can be considered acceptiable for storage.  Even the bad values can be stored for review.  This is why attaching a quality value to each data value is needed.  BTW, the 230 is the SYSTEM table offset to "Manual".

                                                      • Re: State or Quality of an Analog point

                                                        There are three possible solutions to keeping "data quality" information in the current PI System.  Depending on the data frequency of the PIPoint, you may have an obvious choice.

                                                         

                                                        1. The most efficient method is the Questionable bit, which is the only ValueAttribute that can be set for an event (Substituted and Annotated are set by the PI Server).  The Q bit is transferred in all events with no additional overhead or calls.

                                                         

                                                        2. The most flexible method is by adding annotations.  These can hold either a simple annotation or structured annotation.  These require additional data for the incoming event, plus a second PI Server call (internally) on retrieving the annotated event (if requested - see PIData.RetrievalAttributes).  Because of the additional payload, it would be best to annotate the beginning and end of status changes, similar to the way digital values work.  For instance "Manual-begin", "Manual-end".  Our current viewing tools do not interpolate annotations, so users would need to be informed about the convention chosen so they know to interpolate when seeing an annotation.  If status of analog values changes infrequently, this works well.

                                                         

                                                        3. If each event needs a status, then the alternative is to create an associated quality PIPoint for the analog PIPoint.  They can be plotted on a trend, for instance, and because of the interpolation behavior of digitals, a relatively pleasing display can be seen.  Also multi-state values can use color adjustments.  Additionally, calculations can be handled more easily and efficiently with this method.

                                                         

                                                        I hope this helps you decide on a path forward.