2 Replies Latest reply on Oct 26, 2009 2:17 PM by inform2prabhat

    Find Summaries Method in c#.net

    inform2prabhat

      Hi,

       

      can somebody help me out with this.

       

      i am trying do some calculations (average,min,max)in C#.net using the summaries functions given in pisdk.chm in Visual basic 6.0 syntax. I tried but not able to complete the same.

       

      Getting errors at the places where i have given RED COLOR.

       

       

       

       **************************************************************************

       

                  PISDK.PIPoint pt;

       

                  PISDK.PIData pdata;

       

                  PISDK.IPICalculation ipiCalc;

       

                  PISDK.IPIData2 ipid2;

       

                  PISDK.PIValues valsum;

       

                  int i;PISDKCommon.NamedValues nvsSum;

       

                  string strtag = "sinusoid";

       

                  string starttime = "10/26/2009 10:00:00";

       

                  string endtime = "10/25/2009 10:00:00";

       

                  string interval = "1D";

       

       

       

                  nvsSum = new PISDKCommon.NamedValuesClass();

       

                  pt = myServer.PIPoints["cdt158"];

       

                  pdata = pt.Data;

       

                  ipid2= pdata; //get pointer to IPIData2 Interface.

       

      // Error 1: Cannot implicitly convert type 'PISDK.PIData' to 'PISDK.IPIData2'. An explicit conversion //exists (are you missing a cast?

       

                 

       

      nvsSum = ipid2.Summaries2(starttime, endtime, interval, asAverage, cbTimeWeighted);

       

      //Error 2: The name 'asAverage' and cbTimeWeighted does not exist in the current

       

       

       

                 valsum = nvsSum("Average").Value;

       

      //Error 3:'nvsSum' is a 'variable' but is used like a 'method'

       

       

       

                 for (i = 1; i < valsum.Count; i++)

       

                   {textbox1.Text = valsum(i);}

       

      Error 4:'nvsSum' is a 'variable' but is used like a 'method

       

       

       

        **************************************************************************

       

      Great if somebody can help me out with the summaries functions example of PI-sdk using c#.net.

       

       

        • Re: Find Summaries Method in c#.net

          Error 1: replace "ipid2 = pdata;" with "ipid2 = (PISDK.IPIData2)pdata;" (you need an explicit conversion/cast)

           

          Error 2: replace "asAverage, cbTimeWeighted" with "PISDK.ArchiveSummariesTypeConstants.asAverage, PISDK.CalculationBasisConstants.cbTimeWeighted". You'll also need to add a 6th parameter to the method, the PIAsyncStatus object (just pass null if you want to run this method synchronously)

           

          Error 3: the error you are seeing here is because unlike in VB.NET, collection items are accessed with square brackets in C#. One might be tempted to simply replace "nvsSum("Average")" with "nvsSum["Average"]". In this case (it's a long story of COM vs. .NET interoperability), you will need to make use of the "get_Item" method and using the boxing/unboxing technique via an "object" object - see below:

          object o = "Average";
          valsum = (PISDK.PIValues)nvsSum.get_Item(ref o).Value;

          Error 4: again, collection items are accessed using square brackets. Also, you will never get in the loop if you keep "i = 1; i < valsum.Count; i++": because the .Count will most likely be 1, you want to use "i = 1; i <= valsum.Count; i++".

           

          Last but not least, you will need to use the .Value property to access the value on the PIValue object and put it in the textbox. Unlike VB6/VBA, .NET languages will not try to find some "default" value and throwing a whole PISDK.PIValue object in a TextBox' Text property will not work. Try this:

          textBox1.Text = valsum.Value.ToString();

          Hope this helps!