17 Replies Latest reply on Sep 5, 2017 7:02 AM by mdspath

    Explicitly determine whether a PI Point exists via AF SDK

    Chris_Hawkins

      I am using AFAttribute.PIPoint within my C# code. When an Attribute is not as PO Point this returns null - which is fine. However when it is a PI Point BUT the PI Point does not yet exists (for good reason) I get an exception. What is the best way to handle this? Do I simply catch the exception or is there a method in AF to check whether a PI Point exists?

        • Re: Explicitly determine whether a PI Point exists via AF SDK
          Rick Davin

          Hi Chris,

           

          I think this is expected behavior for the AFAttribute.PIPoint call.  You could wrap in a try-catch block.

           

          Or you could batch several attributes in an AFAttributeList and make a GetPIPoint call on the list.  If a PIPoint doesn't exist for a given attribute, it should return a null without throwing an exception.  Plus it should perform better because its making one bulk call instead of many smaller calls.

          1 of 1 people found this helpful
            • Re: Explicitly determine whether a PI Point exists via AF SDK
              John Messinger

              I agree with Rick regarding the use of a bulk call if possible. The AFAttribute.PIPoint property should also return null if the point doesn't exist, so I'm assuming you're doing something else immediately after accessing this property to get an exception instead. You can wrap your code for this in a try-catch block as Rick mentioned, or consider writing an extension method to handle that if this is something you use more than once or twice in your code.

              1 of 1 people found this helpful
              • Re: Explicitly determine whether a PI Point exists via AF SDK
                Chris_Hawkins

                Thanks Rick and others who also responded. Batching the points without a rethink of subsequent code is impractical. Moreover I need to be able to discriminate between a null pi point...not a pi point...and a missing pi point...defined in AF but not in PI.

                 

                Need to do the test in several places so have implemented a method that is basically a try/catch on the afattribute.pipoint. That this may be inefficient matters not as this is a utility application to locate pi points in AF and prime their with values in PI from Excel. So a one-off or infrequent operation during development and testing.

                 

                Regards

                 

                Chris

                 

                Sent from my Windows Phone

                  • Re: Explicitly determine whether a PI Point exists via AF SDK
                    gregor

                    Hello Chris,

                     

                    I've tried this and in case the DataReferencePlugin is a PIPoint Data Reference but no PI Point is assigned, the PIPoint property of the AFAttribute returns an OSIsoft.AF.PI.PIException with StatusCode -12011 and "PI Point not found .. " in the Message.

                     

                    The only alternative approach that I found is to check if AFAttribute.RawPIPoint is null but the RawPIPoint property is mentioned as obsolete with the hint to use PIPoint property instead (see above).

                     

                    Because of missing alternatives, you likely need to catch the OSIsoft.AF.PI.PIException explicitly but some of our experts may have different ideas. I am silently shouting out for David Moler and David Hearn

                      • Re: Explicitly determine whether a PI Point exists via AF SDK
                        gregor

                        .. after looking into the documentation for AFAtrribute.PIPoint property, I see a chance that it is a bug ..

                         

                        Property Value

                        Type: PIPoint

                        This property returns the PIPoint associated with this attribute. If the attribute does not have an associated PIPoint, then null is returned.

                          • Re: Explicitly determine whether a PI Point exists via AF SDK
                            gregor

                            Hello again Chris,

                             

                            I have created a Technical Support case which I will escalate with my findings. I just sent you the case details by email.

                              • Re: Explicitly determine whether a PI Point exists via AF SDK
                                Chris_Hawkins

                                Gregor (and others)

                                 

                                Thanks for you input. Pleasing (I think) to know that my question has generated some thought.

                                 

                                To my mind there should be a way to handle the situation when (1) the PI Point is defined in AF but (2) is missing in DA without using exceptions. Okay, so the condition can be caught with try/catch but I’m sufficiently old to have coded in a world where it was best, if not necessary, to code defensively rather than rely on generic error handling. (Basic, Fortran, C, …). Add to that I’m not a programmer…probably obvious from the naivety of some of the questions I’ve posed on PI Square this past year.

                                 

                                Regards

                                 

                                Chris

                                 

                                Chris Hawkins | +4401642773061

                                  • Re: Explicitly determine whether a PI Point exists via AF SDK
                                    Rick Davin

                                    Hi Chris,

                                     

                                    Thanks for your patience, and also thanks for posting your questions to PISquare.  Even naive questions deserve respect if they further the knowledge of the community.

                                     

                                    I mentioned earlier about checking for use of PIPoint Data Reference Plug-in, or an empty ConfigString.  Those would be the first measure of defensive programming.  If you insist on querying one-at-a-time for AFAttribute.PIPoint, then you will have to rely upon generic error handling - but that is your choice.  As my first suggestion from yesterday, you can get around this by querying in bulk using AFAttributeList.GetPIPoint where the exceptions will not be thrown.  That would be a second measure of defensive programming that you were hoping for.  I don't think it takes a lot of code changes to do that.  But as you now state you're not really a programmer, I can see why you would think the code would be too much.

                                     

                                    If you need some help with re-writing the relevant sections of code, you may consider opening a ticket with Tech Support.  You can even reference this thread in your call/email.  When Tech Support receives code-related problems, they put it in the Developer Support queue which makes it way to ... Gregor or myself or any of the other 4 PIDevClub engineers.  Keep in mind though that many of us are about to go off for the holidays.

                                     

                                    Good luck,

                                    Rick

                                      • Re: Explicitly determine whether a PI Point exists via AF SDK
                                        Chris_Hawkins

                                        Hi Rick

                                         

                                        I take you point about the batch read but from what I can tell this would not discriminate between a an attribute that is not defined as a PI Point and one that is but that has yet to be configured (or otherwise missing) from DA. If both return null this is of little help to me.

                                         

                                        Moreover, in my application <5% of the AF Attributes are PI Points. It would be very inefficient to batch all attributes and submit them to GetPIPoint. I simply need to know whether an AF Attribute is a PI Point and if so create an entry in a text file with the PI Point name and a value read from an associated spreadsheet in which the equivalent tag has a different name; in fact it’s the tag name in a separate application.

                                         

                                        Regards

                                         

                                        Chris

                                         

                                        Chris Hawkins | +4401642773061

                                      • Re: Explicitly determine whether a PI Point exists via AF SDK
                                        gregor

                                        Hello Chris,

                                         

                                        While summarizing the issue for Escalation, I was more attentive looking at PI System Explorer and what I saw makes me believe the Exception is returned intentionally (please see the screenshot below).

                                        On a side note, I found that if you chose the PIPoint Data Reference plug-in, leave the Configstring empty and check-in your changes, PI System Explorer reverts back to <none> Data Reference plug-in. Referencing a none existent PI Point in the Configstring however is possible. One comes to the same constellation by deleting the PI Point referenced with a particular AF Attribute. The situation however is a configuration issue and hence the PIException is thrown.

                                         

                                        To my understanding the PIException containing additional information should be mentioned in the documentation.

                                         

                                        1 of 1 people found this helpful
                                  • Re: Explicitly determine whether a PI Point exists via AF SDK
                                    dmoler

                                    I think Gregor is correct - if you want to detect this condition, you'd need to look for that exception + StatusCode.  A couple other things that might prove useful are the AFDataReference.IsConfigured property (this will report true if the configuration string is a valid) and the AFAttribute.RawPIPointPath(AFEncodeType) method. The former will check that a server and PIPoint or reference attribute are specified, the later will return the PIPoint path with substitutions and references resolved. So your steps could look like:

                                    1. Check if using PI Point Data Reference
                                    2. If so, check that attribute.DataReference.IsConfigured is true, otherwise the ConfigString has not been set to a valid attribute or PIPoint.
                                    3. Force PIPoint resolution either with the PIPoint property or a data call.  If it errors, check that it is a PIException with StatusCode -12011 to handle the case where the tag doesn't exist.
                                    4. Use attribute.RawPIPointPath(AFEncodeType.ShortName) to get the tag for later processing.

                                     

                                    For background, AFAttribute is intended to provide an abstraction layer over the data source so the caller doesn't need to know the details of where the data is coming from. This does make automated configuration tricky because available configuration settings and validation are implementation details of each plug-in and surfaced primarily though the UI. I encourage you to visit: Customer Feedback for OSIsoft & the PI System to capture your use case and request the addition of the capabilities you need.

                                    1 of 1 people found this helpful
                              • Re: Explicitly determine whether a PI Point exists via AF SDK
                                Rick Davin

                                Hi Chris,

                                 

                                Regarding the throwing an exception on AFAttribute.PIPoint, are you running in Debug mode?  For some reason I have memories from years ago that seemed to recall that this happened in Debug but not Release.

                                 

                                As for distinguishing between a null meaning a PIPoint is not expected versus a PIPoint was expected but not configured, there are ways to proceed but they require some assumptions.  The AFAttribute.PIPoint property actually just calls the data references PIPoint property.  So any custom data references may implement their own PIPoint property, which can open can of worms for your stated needs.  Instead let's assume that only the OSIsoft PIPoint Data Reference will be used for the PIPoint property.

                                 

                                The logic to be coded would be along the lines of:

                                 

                                1. Attribute does not use the PIPoint Data Reference Plug-in (helpful link).  Null result is okay because a PIPoint is not expected (due to our assumption).
                                2. Attribute uses PIPoint Data Reference Plug-in but it's ConfigString is empty.  Null result is okay here too.
                                3. Attribute uses PIPoint Data Reference Plug-in and also has a tag name in the ConfigString.  Null result means you are expecting a PIPoint but it is not defined on the Data Archive.

                                 

                                Does this help point you in the right direction?

                                 

                                Rick

                                  • Re: Explicitly determine whether a PI Point exists via AF SDK
                                    Chris_Hawkins

                                    Hi Rick

                                     

                                    I am indeed running in debug mode but also have the resultant dll running as a COM wrapper from Excel. In the later case it just bombs!

                                     

                                    Your 3-step logic appears reasonable. As I say this is a small utility routine restricted in use to development and testing. After all in a real system the PI points should have been defined in DA! But as is often the case the occurrence highlighted an oversight in my code that I wanted to address. Especially so as my routine may be used by others within Emerson, if not our clients.

                                     

                                    Somewhere in my myriad of code I have used the Data Reference Plug-In so should be able to work out what to do.

                                     

                                    Thanks for the input.

                                     

                                    Regards

                                     

                                    Chris

                                     

                                    Chris Hawkins | +4401642773061

                                    • Re: Explicitly determine whether a PI Point exists via AF SDK
                                      ekuwana

                                      Just to comment on Rick's step #3, if PIPoint does not exist in PI Data Archive, AFAttribute.PIPoint will actually throw a PIException when trying to resolve it. The documentation is not quite accurate, it needs to elaborate more in terms of Data Reference implementation. There is a work item to update it for upcoming release.

                                    • Re: Explicitly determine whether a PI Point exists via AF SDK
                                      mdspath

                                      hi,

                                       

                                      you can use "PIPoint.TryFindPIPoint" to check whether the pipint exists are not.

                                      This method returns true if found.