6 Replies Latest reply on Apr 10, 2014 6:16 PM by matcham_n

    PI Steam Table Functions

    matcham_n

      How are the PI steam functions called from a C# program? Is there any example code demonstrating this available.

       

      Many thanks

        • Re: PI Steam Table Functions
          matcham_n

          In C# you need to add the COM reference PISTEAMTABLE. You then can defined a variable of type PISTEAMTABLE.PISTFunctionsClass, for example

           

          PISTEAMTABLE.PISTFunctionsClass SteamFunctions;

           

          You can call any of the available steam function, for example,

           

          double SaturationPressure;

           

          double Temperature;

           

          SaturationPressure = SteamFunctions.StmSI_PsatT(Temperature);

            • Re: PI Steam Table Functions

              Hello Nicholas,

               

              I like to add a reference to the PI Steam Functions Reference at PI Live Library.

               

              Using PISteamTableFunctions.dll is one approach. PI Live Library suggests using the Steam functions library inside PI ACE. You can also use PI SDK and AF SDK. I've created 2 short examples for your reference. When starting new projects today, I recommend using AF SDK instead of PI SDK.

               

              1. PI SDK

               

               

               
              using System;
              using System.Collections.Generic;
              using System.Linq;
              using System.Text;
              using PISDK;
              
              namespace PISDKCalc
              {
                  class Program
                  {
                      static void Main(string[] args)
                      {
                          try
                          {
                              PISDK.PISDK mySDK = new PISDK.PISDK();
                              Server mySrv = mySDK.Servers.DefaultServer;
                              mySrv.Open();
                              // Setting the input value for the calculation
                              Double InpVal = 5.1234;
                              // Building the Expression string
                              String sExpression = "StmEng_tsatp(" + InpVal.ToString() + ")";
                              IPICalculation myCalc = (IPICalculation)mySrv;
                              PIValues myVals = myCalc.Calculate("*", "*", sExpression, SampleTypeConstants.stInterval, "");
                              foreach (PIValue myVal in myVals)
                              {
                                  Console.ForegroundColor = ConsoleColor.White;
                                  Console.WriteLine("The result of equation {0} is {1}", sExpression, myVal.Value.ToString());
                              }
                              mySrv.Close();
                          }
                          catch (Exception ex)
                          {
                              Console.ForegroundColor = ConsoleColor.Red;
                              Console.WriteLine("Exception occured: {0}", ex.Message);
                          }
                          finally
                          {
                              Console.ForegroundColor = ConsoleColor.Gray;
                              Console.Write("Done. Press any key to quit ...");
                              Console.ReadKey();
                          }
                      }
                  }
              }
              

              2. AF SDK 

               

               

               
              using System;
              using System.Collections.Generic;
              using System.Linq;
              using System.Text;
              using OSIsoft.AF.PI;
              using OSIsoft.AF.Time;
              using OSIsoft.AF.Asset;
              using OSIsoft.AF.Data;
              
              namespace AFSDKCalc
              {
                  class Program
                  {
                      static void Main(string[] args)
                      {
                          try
                          {
                              OSIsoft.AF.PI.PIServer mySrv = new PIServers().DefaultPIServer;
                              mySrv.Connect();
                              // Setting the input value for the calculation
                              Double InpVal = 5.1234;
                              // Building the Expression string
                              String sExpression = "StmEng_tsatp(" + InpVal.ToString() + ")";
                              // We don't really need a Time reference for these kind of calculations
                              AFTimeRange timerange = new AFTimeRange("*", "*");
                              // An time interval isn't needed either but setting it to zero returns an exception
                              AFTimeSpan timespan = new AFTimeSpan(0, 0, 0, 0, 0, 1, 0);
                              AFValues myVals = AFCalculation.CalculateAtIntervals(mySrv, sExpression, timerange, timespan);
                              Console.ForegroundColor = ConsoleColor.White;
                              Console.WriteLine("The result of equation {0} is {1}", sExpression, myVals[0].Value.ToString());     
                              mySrv.Disconnect();
                          }
                          catch (Exception ex)
                          {
                              Console.ForegroundColor = ConsoleColor.Red;
                              Console.WriteLine("Exception occured: {0}", ex.Message);
                          }
                          finally
                          {
                              Console.ForegroundColor = ConsoleColor.Gray;
                              Console.Write("Done. Press any key to quit ...");
                              Console.ReadKey();
                          }
                      }
                  }
              }
              

               

                • Re: PI Steam Table Functions
                  matcham_n

                  Many thank you for reply Gregor. It is useful to see alternative methods proposed for using the PI Steam Tables. For the application I am developing, I do not need to calculate steam thermodynamic properties over time and therefore simply use 

                   

                  ...

                   

                  PISTEAMTABLE.PISTFunctionsClass SteamFunctions;

                   

                  double SaturationPressure, Temperature;

                   

                  SaturationPressure = SteamFunctions.StmSI_PsatT(Temperature);

                   

                  I find AFCalculation overly complicated. I prefer to pass one or two doubles to a function rather than having to define an input string expression that specifies the function required, a time range and span.    

                   


                   


                  • Re: PI Steam Table Functions

                    Hello Nicholas,

                     

                    My colleagues just reminded me that PI Live Library isn't yet publicly available. Sorry but the link will not work for you. The information however should be available in other documents. Please let me know if you need additional reference to documents available to you.

                      • Re: PI Steam Table Functions

                        Hello Nicholas,

                         

                        I have to again correct myself. PI Live Library is available outside OSIsoft but the link I posted goes to another resource which is not. PI Live Library as well has information about steam table functions.

                         

                        Dr Nicholas Matcham

                        I find AFCalculation overly complicated.

                         

                        We are the PI guys and expect you would record process data with your PI System. Please assume you would be recording pressure and temperature of overheated steam and like to calculate the enthalpy for the past 24 hours at 5 second intervals. When looking at the following code snippet, you will recognize the beauty:

                         

                         

                         
                                        String sExpression = "StmEng_hpt('MyPressureTag','MyTemperatureTag')"; 
                                        AFTimeRange timerange = new AFTimeRange("*-24h", "*");
                                        AFTimeSpan timespan = new AFTimeSpan(0, 0, 0, 0, 0, 5, 0);
                                        AFValues myVals = AFCalculation.CalculateAtIntervals(mySrv, sExpression, timerange, timespan);
                                        foreach (AFValue myVal in myVals)
                                        {
                                            Console.WriteLine("{0}:{1}", myVal.Timestamp.ToString(), myVal.Value.ToString());
                                        }
                        

                         

                          • Re: PI Steam Table Functions
                            matcham_n

                            Many thanks for the information PI guys. However, as the English dramatist John Lyly, wrote in 'Euphues and his England', 'Beauty is in the eye of the beholder' I do not need to determine the steam thermodynamic properties over a time period. I simply need to evaluate these properties from previously acquired PI data. I therefore prefer to use code similar to

                             

                             PISTEAMTABLE.PISTFunctionsClass SteamFunctions;

                             

                            double SaturationPressure, Temperature;

                             

                            SaturationPressure = SteamFunctions.StmSI_PsatT(Temperature);

                             

                            However, should I need to determine the properties of water, wet steam or superheated steam over a time period, I would use the approach you describe above.

                             

                            Cheers

                             

                            Nick