AnsweredAssumed Answered

Help on using C# and SDK to retreive Calculated data like in PI DataLink

Question asked by ebelaski on Dec 16, 2014
Latest reply on Dec 18, 2014 by ebelaski

Hello,

I am new to SDK developent and C# so tying to get this to work has been difficult. I have an XML file that is read by the app that has the tag mask and point sources and other variables

From that I can get a list of points from the PI Server. I have the App pulling snapshot data for short periods but what I would like to do is pull hourly averages of many tags over a long period such as a month or so. I am able to do something similiar in DataLink by entering a start and end date, time interval and selecting average as the calculation mode.

Below is my code but it does not work as it says I need to cast things. I think I am not understanding the difference in PIPoints and PIValues etc. Thanks for your help.

 

class PiDataExport
    {
        private PISDK.PointList pointList = new PISDK.PointList();

        private List<string> lstTagMask { get; set; }
        private List<string> lstPointSource { get; set; }
       private string startDate {get; set; }
        private string endDate { get; set; }
        private string dateFormat { get; set; }
        private string timeFormat { get; set; }
        private string outputFileName { get; set; }
        private PITimeFormat sDate = new PITimeFormat();
        private PITimeFormat eDate = new PITimeFormat();
  
  string tagFilter = "";
  PISDK.Server piServer;
  PISDK.PISDK piSDK = new PISDK.PISDK();
  PISDK.ServerManager serverManager = new PISDK.ServerManager();
  piServer = serverManager.PISDK.Servers.DefaultServer;
  
  foreach (var filter in lstTagMask)
  {
   tagFilter = "";
   foreach (var ptsource in lstPointSource)
   {
    //Set the tag filter
    tagFilter = "tag = '" + filter + "' AND pointsource = '" + ptsource + "'";
    //get the points
    pointList = piServer.GetPoints(tagFilter);
    if (pointList.Count > 0)
    {
     
     PIData pdata;
     IPIData2 ipid2;
     NamedValues nvsSum;
     PIValues valsum;
     NamedValue nv;
     PIPoint pt;
     string msg;
     string duration = "1h";
     foreach (PISDK.PIPoint piPoint in pointList)
     {
      pt = piPoint;
      pdata = pt.Data;
      ipid2 = (IPIData2)pdata;
      nvsSum = ipid2.Summaries2(sDate,eDate,duration,ArchiveSummariesTypeConstants.asAverage,CalculationBasisConstants.cbTimeWeighted);
      valsum = (PIValues)nvsSum;
      msg = valsum.Value.toString;
     }     

    }
   }
  }
 }

Outcomes