Multiple AFValues at the same timestamp using AF SDK

Is there a way to use AF SDK to write multiple AF Values at the same timestamp?

I already tried something like:

            OSIsoft.AF.PI.PIServer piServer = OSIsoft.AF.PI.PIServers.GetPIServers().DefaultPIServer;

            var piServerNetCredential = new NetworkCredential("piadmin", "****");
            piServer.Connect(piServerNetCredential);

            OSIsoft.AF.PI.PIPoint point;
            if (!OSIsoft.AF.PI.PIPoint.TryFindPIPoint(piServer, "Multivalue Test", out point)) {
                point = piServer.CreatePIPoint("Multivalue Test");
            }

            OSIsoft.AF.Asset.AFValues newValues = new OSIsoft.AF.Asset.AFValues();
            AFTime startTime = new AFTime("T-15d", CultureInfo.CurrentCulture);

            newValues.Add(new OSIsoft.AF.Asset.AFValue(5.0, startTime.LocalTime.AddDays(10)));
            newValues.Add(new OSIsoft.AF.Asset.AFValue(6.0, startTime.LocalTime.AddDays(11).AddTicks(0)));
            newValues.Add(new OSIsoft.AF.Asset.AFValue(7.0, startTime.LocalTime.AddDays(11).AddTicks(0)));
            newValues.Add(new OSIsoft.AF.Asset.AFValue(8.0, startTime.LocalTime.AddDays(11).AddTicks(1)));
            newValues.Add(new OSIsoft.AF.Asset.AFValue(9.0, startTime.LocalTime.AddDays(12)));
            newValues.Add(new OSIsoft.AF.Asset.AFValue(10.0, startTime.LocalTime.AddDays(13)));
            newValues.Add(new OSIsoft.AF.Asset.AFValue(11.0, startTime.LocalTime.AddMonths(10)));

But value 6 is replaced by value 7.

I want to add multiple values at the same timestamp.

Parents
  • First off, if you applied some using statements at the top of your file, it would be easier to read the code since it would reduce things like:

    • Without usings: new OSIsoft.AF.Asset.AFValue
    • With usings: new AFValue

     

    Thanks for sharing the code but you left the most critical piece out for answering your question. What UpdateValues method are you using AND more importantly, what is the value for AFUpdateOption. The default is Replace, which would explain why 7 replaces 6, i.e. last one with same timestamp replaces previous.

     

    ANSWER:

    If you want multiples at the same timestamp, use AFUpdateOption.Insert.

     

    Also, .AddTicks(0) is utterly useless.

     

    The one line I find most curious is:

    newValues.Add(new AFValue(8.0, startTime.LocalTime.AddDays(11).AddTicks(1)));

     

    I am surprised it did not replace 7 with 8. The reason being is that PI Server time precision is 1/65536th of a second, which is between 152 and 153 ticks. When inserting into the data archive, PI Server will call the equivalent of ToPIPrecision(). The help says it would round to nearest time, which same as AddTicks(0).

     

    All that said, my personal choice would be to take whatever measures I can to AVOID duplicate timestamps. Are you just exploring capabilities of the server and your code, or do you have a legitimate business purpose for such duplicates?

Reply
  • First off, if you applied some using statements at the top of your file, it would be easier to read the code since it would reduce things like:

    • Without usings: new OSIsoft.AF.Asset.AFValue
    • With usings: new AFValue

     

    Thanks for sharing the code but you left the most critical piece out for answering your question. What UpdateValues method are you using AND more importantly, what is the value for AFUpdateOption. The default is Replace, which would explain why 7 replaces 6, i.e. last one with same timestamp replaces previous.

     

    ANSWER:

    If you want multiples at the same timestamp, use AFUpdateOption.Insert.

     

    Also, .AddTicks(0) is utterly useless.

     

    The one line I find most curious is:

    newValues.Add(new AFValue(8.0, startTime.LocalTime.AddDays(11).AddTicks(1)));

     

    I am surprised it did not replace 7 with 8. The reason being is that PI Server time precision is 1/65536th of a second, which is between 152 and 153 ticks. When inserting into the data archive, PI Server will call the equivalent of ToPIPrecision(). The help says it would round to nearest time, which same as AddTicks(0).

     

    All that said, my personal choice would be to take whatever measures I can to AVOID duplicate timestamps. Are you just exploring capabilities of the server and your code, or do you have a legitimate business purpose for such duplicates?

Children
No Data