AnsweredAssumed Answered

PIPoint.UpdateValues only updating the snapshot value?

Question asked by v_dahbura on Jan 29, 2020
Latest reply on Feb 5, 2020 by v_dahbura

Hi all. Whenever I attempt to run the following code to update a point with data from a datatable out of a .csv file it looks like I am only writing/updating the snapshot value of the point, what am I doing wrong here?: 

 

private static void UpdatePiPoints(DataTable csvTable)
{
   int rowCount = csvTable.Rows.Count;
   string tagName, startTime, endTime;
   tagName = startTime = endTime = string.Empty;
   DataRow firstRow = csvTable.Rows[0];
   DataRow lastRow = csvTable.Rows[rowCount - 1];

   tagName = firstRow["Tag"].ToString();
   startTime = firstRow["Timestamp"].ToString();
   endTime = lastRow["Timestamp"].ToString();
   IList<AFValue> vals = new List<AFValue>();

 

   if (AFData.BufferOption != AFBufferOption.Buffer)
   {
      AFData.BufferOption = AFBufferOption.Buffer;
      Console.WriteLine("Current Buffer Option for this instance has been changed to: {0}",       AFData.BufferOption);
   }

 

   PIPoint tag = PIPoint.FindPIPoint(piServer, tagName);


   foreach (DataRow row in csvTable.Rows)
   {
      DateTime timeStamp = DateTime.Parse(row["TimeStamp"].ToString());
      timeStamp = DateTime.SpecifyKind(timeStamp, DateTimeKind.Local);

      AFTime timeVal = new AFTime(timeStamp).LocalTime;

      AFValue val = new AFValue(row["Value"].ToString(), timeVal);
      vals.Add(val);
   }

 

   tag.UpdateValues(vals, AFUpdateOption.InsertNoCompression);  
}

 

 

 

This is what the .csv file looks like:

 

tag, timestamp, value
Admin.DataTag_001,1/1/2018 12:00:00 AM,10.10
Admin.DataTag_001,1/2/2018 12:00:00 AM,27.20
Admin.DataTag_001,1/3/2019 12:00:00 AM,33.30

 


For example, the code above only updates the point with the last row in the .csv file.

 

Thanks!

Outcomes