9 Replies Latest reply on Mar 19, 2015 5:32 AM by Doddabasappa

    Mutlithreading, PI SDK Call



      I want to get bulk list of tags along with snapshot value and few tag attribute names.  Would like to go with multithreading option, because some time I may need to query lacks of tag. So need help here.

      It would be helpful if you provide me sample snippet.





        • Re: Mutlithreading, PI SDK Call
          Dan Fishman

          Do you want to use the PI SDK or AF SDK?  I would recommend going with the AF SDK for many reasons when building a .NET application.  If you truly need multithreading I would definitely use the AF SDK to avoid STA, MTA and COM object issues with threading using the PI SDK.  Do you need snapshot values continuously?  If so, you should use a DataPipe instead of making a bulk call to the snapshot table and looping. In general, make bulk calls if you can to reduce the number of round trips to the PI Server or AF Server.  How many are lots of tags?  What do you mean by "few tag attribute names".  If you want to obtain PI tag attribute values (description, point source and others) these typically don't change much so you it might make sense to take advantage of the SDK cache.  There are a number of ways to use multiple threads with our SDKs and I can provide a more accurate example once we understand what you are doing.  Does an AF database come in play at all here?

          • Re: Mutlithreading, PI SDK Call
            Rhys Kirk

            Agree with Dan's comments; switch to AF SDK and look to make efficient use of DataPipes for continuous streaming of snapshots PI Events.

            • Re: Mutlithreading, PI SDK Call
              Eugene Lee

              Hi, if you do decide to go with the AF SDK as per Dan's suggestion, here is a code snippet that can get you started. It is from the AF SDK reference. Language is C#.


              // Get the PIPoints from the PIServer on the local computer
              PISystems myPISystems = new PISystems();
              PISystem myPISystem = myPISystems.DefaultPISystem;
              PIServer myPIServer = PIServer.FindPIServer(myPISystem, piServerName);
              PIPointList myPIPointList = new PIPointList(PIPoint.FindPIPoints(myPIServer, "Sin*"));
              // Display information about the PIPoints
              foreach (PIPoint point in myPIPointList)
                  Console.WriteLine("Name of the PIPoint = {0}", point.Name);
                  Console.WriteLine("ID of the PIPoint = {0}", point.ID);
                  Console.WriteLine("Type of the PIPoint = {0}", point.PointType);
                  Console.WriteLine("PIPoint Current Value = '{0}'", point.Snapshot());
              // Get and display current value for all PIPoints
              AFListResults<PIPoint, AFValue> results = myPIPointList.Snapshot();
              IList<AFValue> values = results.Results;
              foreach (AFValue value in values)
                  Console.WriteLine("Current Value = '{0}'", value);


              Regarding the part on multithreading, .NET4 has new classes that can help you do that.


              Parallel Programming in .NET Framework 4: Getting Started - The C# Team - Site Home - MSDN Blogs

                • Re: Mutlithreading, PI SDK Call

                  Hi Dan,


                  Find below comments.


                  Do you want to use the PI SDK or AF SDK?

                  Thought of going with PI SDK but when I tried, ended up in "Com Object" issue as you mentioned.


                  Do you need snapshot values continuously?

                  I don't need continuous snapshot value, just want to check current snapshot value for all tags at that point of time.


                  How many are lots of tags?  What do you mean by "few tag attribute names"?

                  I have around 30 lacs of PIPoints, need PI tag attributes like Pointsource, Location1, Digitalset and pointtype to group tags based on interface and perform some validations. 


                  Does an AF database come in play at all here?



                  Hope Eugene code would help me for some extent. Thanks Eugene.

                    • Re: Mutlithreading, PI SDK Call
                      Dan Fishman

                      By tag attributes I was being vague intentionally in case you really wanted AF attribute values.  Another PI term that is somewhat overloaded and context is important to the meaning.


                      I'll try and post a link to where Eugene's code came from if I can locate it today!


                      Also check out the PIPoint.GetAttributes method as well as the remarks on this.  I believe this is a bulk call and probably more efficient than looping.  You might want to periodically refresh the cache if you think PI Point attributes have changed. The array you provide GetAttributes will have the form: string[] attributes = new string[]{PICommonPointAttributes.CompressionDeviation, PICommonPointAttributes.CompressionMaximum,


                        • Re: Mutlithreading, PI SDK Call

                          Hi Doddabasappa,


                          If you want to load the attributes in bulk for a list of tags, you can use PIPointList.LoadAttributes to load the specified list of attributes from the server into the client's cache. Subsequent PIPoint.GetAttribute or PIPoint.GetAttributes will read from the cache instead of making a roundtrip to the server. The argument for PIPointList.LoadAttributes is the same as PIPoint.GetAttributes (sting[] attributes as mentioned by Dan above).

                    • Re: Mutlithreading, PI SDK Call

                      Hi Doddabasappa,


                      Have you found a solution for this issue? It would help others if you mark the answer that helped you as correct, otherwise you can give us more details so we can further assist you. Thanks.