15 Replies Latest reply on Oct 1, 2014 1:36 AM by Mark Langford

    Reading/Writing to a PI Collective using AFSDK

    sean.mcguinness

      Hi,

       

      I've coded a custom Windows service executable using VBA.NET 4.0 and AF SDK 2.5 which runs a simple calculation on snapshot events every second and writes the output data to a PI tag via AFListData.UpdateValues().

       

      As it stands I'm just grabbing the default PI Server using the PIServers.GetPIServer().DefaultPIServer method, but obviously this only reads/writes to the default server, so I would like to revise the program to read/write from/to the PI Collective instead. Ideally, I would like the output data to be buffered as well.

       

      Could anyone recommend a suitable approach for achieving these two objectives?

       

      Sean

        • Re: Reading/Writing to a PI Collective using AFSDK

          Hello Sean,

           

          The current AF SDK (2012 - 2.5.0.5039) ships with 2 different library versions, one for .NET Framework 3.5 and another one for .NET Framework 4.

           

          What's the version that you are using?

           

          Please allow me to quote AF SDK Reference manual (%PIHOME%\Help\AFSDK.chm with PI AF Developer Tools 2012 installed):

           

          Buffering

           

          The .NET 4 AF SDK does not support buffering of PI Server data writes nor direct fanning of data writes to PI Server Collectives. For PI Server Collectives, data writes will be made to the currently connected collective member, if supported. Users who need to write data to PI Collectives are encouraged to use the PI SDK or .NET 3.5 AF SDK, with buffering enabled. Buffering and fanning of PI Server data writes with the .NET 4 AF SDK is scheduled for a later release.

            • Re: Reading/Writing to a PI Collective using AFSDK
              sean.mcguinness

              Hi Gregor,

               

              I'm using .NET Framework 4.

               

              Looks like I received bad advice - I originally began writing the application using PISDK, but was persuaded by tech support to re-code it in AFSDK instead!

               

              Is there much of a speed hit or future-proofing issues associated with using PISDK? My calculation uses twelve input+two output tags per device and new samples arrive every 0.02 seconds. At the moment we have thirteen devices in operation, but that will increase to forty in the next few months and could reach over a hundred down the line.

               

              Sean

                • Re: Reading/Writing to a PI Collective using AFSDK

                  Hello Sean,

                   

                  We recommend using AF SDK as the future-proof choice.

                   

                  It's always difficult to reply to performance related questions because there are too many factors involved. I have to few experience using AF SDK to feel able making any performance related statement.

                   

                  Sampling is at 50 Hz. Is this after applying exception and compression? Does your application make use of PI Update Manager?

                   

                  However, my idea would be changing the library reference to the .NET 3.5 AF SDK and to see how it goes.

                    • Re: Reading/Writing to a PI Collective using AFSDK
                      skwan

                      I want to provide some clarifications on this thread.

                       

                      AFSDK is where we're putting the majority of efforts moving forward and not the PISDK.  There's been several threads in the past, vCampus webinars and UC presentations on this topic.  From a SDK perspective, the AFSDK will essentially morph into the PI System SDK.

                       

                      AF 2.5 was the first version of the AFSDK that allows direct access to PI time series data.  Prior to AF 2.5, the AFSDK never directly connects to the PI data archive, but rather uses the PISDK to retrieve PI time series data.  In AF 2.5, two versions of the AFSDK are provided; one based on .NET 4 and one based on .NET 3.5.  The .NET 4 version allows direct access to PI time series data whereas the .NET 3.5 version continues to use the PISDK to access PI time series data.  As such, the .NET 3.5 version provides backward compatibility with legacy data references that many vCampus users have built in the past.

                       

                      Testing has shown that AFSDK (.NET 4) in AF 2.5 retrieves PI time series data faster than PISDK in many scenarios and also significantly reduces memory usage.  AFSDK avoids STA/MTA issues commonly seen in PISDK development and also eliminates COM interop overhead.  For your use case of 50Hz data, from a performance perspective, I think you would be better off using the AFSDK.

                       

                      However, it was not practical for the AFSDK (.NET 4) to completely replace all PISDK functions in one single release.  Afterall, the PISDK evolved over many years and has many features and functions.  We chose to release the AFSDK with direct access to PI time series data in multiple releases.  Buffering was one of the features that did not make the AF 2.5 release (among others - see this vCampus webinar from Feb. 2012 on Rich Data Access).

                       

                      As to the recommendation from our tech support on your using the AFSDK 2.5 for your current project, perhaps the tech support engineer did not understand your need for buffering.  I hope I have given you the relevant information to make a decision on how to move forward.  If you have other questions or comments, please let us know.

                        • Re: Reading/Writing to a PI Collective using AFSDK
                          Marcos Vainer Loeff

                          Hello Sean,

                           

                          Remember that you could use PItoPI interface to send data from the primary to the secondary as a workaround to solve your problem. The advantage is that when next version of AF SDK that supports buffering is released, you will be using our most modern technology without having to rewrite your application in order to get the best performance.

                           

                          There are several other workarounds to transfer data from the primary PI Server to the secondary, however if performance is important, you should avoid using PI SDK.

                            • Re: Reading/Writing to a PI Collective using AFSDK
                              sean.mcguinness

                              Thanks for all the feedback guys.

                               

                              I would prefer not to use PItoPI as the intention was for the application to operate in a high-availability manner. I had intended to run the service on two separate servers and replicate the common PI interface hot-failover functionality in the code.

                               

                              Considering your combined advice I will stick to AF SDK, but I might try to modify the code to write to both PI Servers in the collective and see what I can do to incorporate some basic exception compression and limited local buffering of the output data.

                                • Re: Reading/Writing to a PI Collective using AFSDK

                                  You know if you have a specific need to implement UniInt type failover, have fanning and buffering then we should mention getting in touch with the OSIsoft Interfaces team to discuss developing an Interface for your data source assuming one doesn't already exist. The Interfaces team are awesome and good at what they do.

                                   

                                  That said, the coder in me is telling myself to shut up...

                                   

                                  Is your data continuous, or does it come in batches?

                                   

                                  The PI to PI option is actually a good call when used in the right scenario. Typical usage of PItoPI is to install PItoPI on the server side (for lack of SSB ) but you could do something different to get what you want and still use AF SDK RDA.

                                   

                                  When AF SDK supports buffering it is highly likely it will involve PIBufss and not reinvent the wheel, at least until the PI System SDK provides us options for tagging data for SSB. (Had to mention it again.) PIBufss uses the same queue technology as the PI Server so you could look at the PIBufss as a light weight, watered down PI Server - data comes in, it gets queued, data goes out. The only bit missing is the "data gets archived". So on your server where you intend to run your custom interface you install a PI Server, a bare minimum PI Server where only the core subsystems are running and the rest are disabled / not installed. You even disable auto archiving (set tuning parameter to overwrite on error), disable compression, turn off exception (not applicable for custom interface anyway) and have one big archive sufficient for your buffering requirements in addition to PIBufss - coming to that part next. Your interface writes to that local PI Server.
                                  PI to PI then takes over, it signs up for exceptions from your local PI Server and writes to your PI Collective taking care of the fanning and buffering via the API buffering queues of PIBufss. You could even split PI to PI out to 2 other separate interface servers and use UniInt failover.

                                   

                                  It adds an extra point of failure to your architecture and possibly considered unconventional but would meet your requirements for (client/interface) interface fail-over, (client/interface) buffering & fanning.

                                   

                                  When AF SDK RDA provides native buffering and fanning you simply cut out the middle men - local PI Server and PI to PI.

                                    • Re: Reading/Writing to a PI Collective using AFSDK
                                      sean.mcguinness

                                      Thanks Ryhs.

                                       

                                      The data is continuous 24/7. I work for a power utility and we're measuring electrical currents and voltages - the AFSDK code that I've implemented calculates power (=V*I), which is used directly for visualisation and also for further analysis through a PI FFT Server.

                                       

                                      We're running PI in a high-availability manner with duplicate redundancy wherever possible - we have two PI servers forming a collective. The servers are in different physical locations with a high capacity link between them. The PI Interfaces to our devices are also duplicated at the two locations and the comms to the end devices don't overlap (excepting oddball cases). With our application I had wanted to extend the high-availability to this custom power calculation code as well; hence the desire to extend it to support buffering and read/writing to the collective rather than individual PI Servers. I think one mini PI Server at each of the two sites might work best, but I'll raise the prospect of a dedicated interface as well as our application would be common in the industry so it might be worth their while looking into it.

                                        • Re: Reading/Writing to a PI Collective using AFSDK
                                          skwan

                                          Sean:

                                           

                                          Are you aware of the Asset Based Analytics CTP?  (project Abacus) Your application is actually a good use case for this CTP.  A webinar was given recently on this project.  You may want to spend a few minutes looking over the recording here.

                                            • Re: Reading/Writing to a PI Collective using AFSDK
                                              sean.mcguinness

                                              Hi Steve,

                                               

                                              Abacus was recommended to us back when we realised that our calculation could not be executed by PI ACE. We are signed-up for the CTP, so hopefully that will provide the long-term solution.

                                               

                                              Sean

                                                • Re: Reading/Writing to a PI Collective using AFSDK
                                                  skwan

                                                  Sean:

                                                   

                                                  I sent you the necessary info to download the CTP on 8June2013.  If you did not get my email, please let me know.

                                                    • Re: Reading/Writing to a PI Collective using AFSDK
                                                      Gael

                                                      Hi,

                                                       

                                                      I am getting exactly the same problem than Sean regarding the write of data to a collective.

                                                       

                                                      I want to use AF SDK 2.5 and I am not interested at all to use the PI-to-PI interface (that doesn't give).

                                                       

                                                      Meanwhile AF SDK 2.6 (and as an alternive), I would like to be able to write to both members of the collective by programmation (2 different connections).

                                                       

                                                      Do you have an example of code that allows to write to both members of the collective by programmation using AFSDK 2.5?

                                                       

                                                      Thanks in advance

                                                       

                                                      Best Regards,

                                                       

                                                      Gael

                                                        • Re: Reading/Writing to a PI Collective using AFSDK
                                                          Gael

                                                          I am doing this just for testing  (using the 2 ways Data & PIPoint):

                                                           

                                                           

                                                           
                                                          MyAFAttribute3.Data.UpdateValue(myValueDataPrim, AFUpdateOption.Replace);         
                                                          MyPIPoint3.UpdateValue(myValuePrim, AFUpdateOption.Replace);
                                                                      
                                                          // Get the PIServers collection for the current user and default PIServer.
                                                          PIServer myPIServer = new PIServers().DefaultPIServer;
                                                          
                                                          // Secondary
                                                          PICollectiveMember myMember = myPIServer.Collective.Members[1];
                                                          myMember.Connect();
                                                          
                                                          MyAFAttribute3.Data.UpdateValue(myValueDataPrim, AFUpdateOption.Replace);
                                                          MyPIPoint3.UpdateValue(myValuePrim, AFUpdateOption.Replace);
                                                          

                                                           This is working.

                                                           

                                                          However, this will be executed in a ACE environnment.

                                                           

                                                          I want to know if the mymember.connect() to the secondary will switch all other connections to the secondary PI server?

                                                           

                                                          I will have several ACE executables doing different stuff and I want that all these exécutables are independant.

                                                           

                                                          Or do I need to use a specific user for each ACE exécutables to avoid side effects?

                                                           

                                                           

                                                           

                                                          Thanks for your reply

                                                           

                                                           

                                                           

                                                          Gael

                                                            • Re: Reading/Writing to a PI Collective using AFSDK
                                                              hanyong

                                                              Thanks for sharing your finding Gael.

                                                               

                                                              I think PICollectiveMember.Connect method is meant to open a connection to a specific member instead of switching connections, hence differentiating it with the method PICollective.SwitchMember which is meant to switch the connection to another collective member.

                                                               

                                                              Han Yong

                                                                • Re: Reading/Writing to a PI Collective using AFSDK
                                                                  Mark Langford

                                                                  This is how you can ensure you open the server you require i.e. Primary or Secondary

                                                                   

                                                                   

                                                                   
                                                                  IPICollective piCollective = (IPICollective)server83;
                                                                  CollectiveList collectiveList = piCollective.ListMembers();
                                                                  
                                                                  CollectiveMember member1 = collectiveList["myPrimaryServer"];
                                                                  Server server1 = piCollective.MemberOpen(member1, "");
                                                                  
                                                                  CollectiveMember member2 = collectiveList["mySecondaryServer"];
                                                                  Server server2 = piCollective.MemberOpen(member2, "");