3 Replies Latest reply on Nov 2, 2015 2:19 PM by gachen

    AF SDK TimeOut Issue

    mark.arrowsmith

      Hi,

       

      I am working on a custom .NET application (Windows Service) that uses the AF SDK (PI AF Developer Tools 2014 R2 v.2.6.1.6238)  to query AF/PI and save data into SQL Server on a polling schedule, however sometimes the queries seem to lockup/timeout - no timeout or other exceptions are thrown - the call just seem to hang.

       

      I have tried setting the PISystem.ConnectionInfo.TimeOut value to a low value (e.g. 2 secs) and nothing seems to change in the AF SDK behaviour.

       

      I have looked in PI-SMT Network Statistics and the process seems to be working correctly... no errors are showing for the connection.

       

      If an exception (TImeOut or otherwise) were thrown, I could at least handle that - do some recovery and try again.

       

      Has anyone come across this before and found a solution?

       

      Kind Regards,

      Mark

        • Re: AF SDK TimeOut Issue
          gachen

          Hi Mark,

           

          If you are just trying to get PI data (no AF), then the RDBMS interface actually allows your to output PI tag data to a SQL server. However, assuming you are already aware of this and have a good reason to write custom code, it would help a lot to see what kind of calls are hanging. Could you post a couple examples from your code?

          • Re: AF SDK TimeOut Issue
            mark.arrowsmith

            Hi,

             

            Thanks for your reply, we are using AF template names to query AF and are pulling some rollup information from AF as well as some values from SQL reference tables so thats why we are using AF SDK rather than the RDBMS interface.

             

            I'm not sure exactly where its hanging as its a multi-threaded application and once deployed is managed by a separate company. I'm adding logging and profiling to the application to find out exactly where its hanging so that will help.

             

            But in the meantime, it seems that the Timeouts set via the AF SDK (e.g. specified in code) are not working and are not throwing some kind of exception that I can handle in code.

             

            I verified this by writing a simple console application... nothing happens when timeout is set really small (e.g. 1 sec).

             

            private static void Main(string[] args)
                   {
                       // Get the PIServers collection for the current user and default PIServer.
                       PIServer server = new PIServers()["mypi"];
                       // Set default for all connections to be based upon collective member's priority.
                       PIConnectionInfo.DefaultPreference = AFConnectionPreference.Any;
                       //server.ConnectionInfo.OperationTimeOut = new TimeSpan(0, 0, 1);       // Throws Ex - Zero priority of one or more collective members
                       //server.ConnectionInfo.ConnectionTimeOut = new TimeSpan(0, 0, 1);    // Throws Ex - Zero priority of one or more collective members
                       // Check if default PIServer is a Collective.
                       if (server.Collective != null)
                       {
                           // Simple connect will use Default Preference.
                           server.Connect();
                           // Must connect to the server the 1st time to populate the PI server collective details
                           server.Disconnect();
                           // Connect to a specific collective member (e.g. Primary MYPI01 or Secondary MYPI02)
                           logger.Info("Connecting to the Primary PI Server - MYPI01");
                           PICollectiveMember primaryMember = server.Collective.Members[0];
                           primaryMember.Connect();
                           //primaryMember.ConnectionTimeOut = new TimeSpan(0, 0, 1);    // Throws Ex - ReadOnly property
                           //primaryMember.OperationTimeOut = new TimeSpan(0, 0, 1);     // Throws Ex - ReadOnly property
                           //logger.Info("Connecting to the Secondary PI Server - MYPI02");
                           //PICollectiveMember secondaryMember = server.Collective.Members[1];
                           //secondaryMember.Connect();
                           //secondaryMember.ConnectionTimeOut = new TimeSpan(0, 0, 1);    // Throws Ex - ReadOnly property
                           //secondaryMember.OperationTimeOut = new TimeSpan(0, 0, 1);     // Throws Ex - ReadOnly property
                           var system = new PISystems()["myaf"];
                           // Set connection to connect to any AF server and have a 30 sec timeout
                           // NB. Must be done before opening the connection
                           system.ConnectionInfo.Preference = AFConnectionPreference.Any;
                           system.ConnectionInfo.TimeOut = new TimeSpan(0, 0, 1);  // Set to a really low value to see if timeout will throw an exception --> its not
                           var db = system.Databases["QGC"];
                           RunSimpleTest(system, db);
                           // Close connection to the AF & PI Servers and dispose
                           system.Disconnect();
                           server.Disconnect();
                           system.Dispose();
                       }
                       else
                       {
                           logger.Info("PIServer '{0}' is not a collective. No connections were made.", server.Name);
                       }
                       // Connect to SQL to save the data
                       // ...
                       //Allow viewing of results
                       System.Console.WriteLine("... press 'Enter' to exit process ...");
                       System.Console.ReadLine();
                   }
            

            Thanks!

            • Re: AF SDK TimeOut Issue
              gachen

              If it's not throwing an exception, then maybe it's not timing out and you are actually connected? Could you try adding the following line to your test code:

              var db = system.Databases["QGC"];
              System.Console.WriteLine(system.IsConnected); //new line prints whether we have connected successfully or not 
              RunSimpleTest(system, db); // Close connection to the AF & PI Servers and dispose 
              system.Disconnect();

               

              The new line will just print the Boolean property of whether we have successfully connected or not.
              As per the AFSDK reference, there are two types of exceptions that can be expected when trying to connect to a PISystem object: System.ServiceModel.CommunicationException and System.TimeoutException. It would be good to catch and handle both of these exception types. As to why your application is not throwing an exception, it would be really helpful to know exactly on which line the issue seems to be occurring.