6 Replies Latest reply on Oct 19, 2017 6:09 AM by Aysha

    PISDK - UpdateValues does not work

    HalifaxWater

      Hi,

       

      I am new to PI SDK. I am working on a code to insert the historical values into PI tags. I use UpdateValues to do this, but it does not add all values to the PI Server, instead, it only add one at the Snapshot time. Here is my code in C#:

       


      PISDK.PIPoint pt;
      PIValues vals;
      PIValue piVal;
      PIErrors piErr;

       

      _PIServerRef.PIPoints.PointLoaded(tst.ID, out pt);

       

      if (pt != null){

       

      vals = new PIValues();
      vals.ReadOnly = false;

       

      for (int j = 0; j < tst.Time.Length; j++)
      {
      piVal = vals.Add(tst.Time[j], tst.Value[j], null);

       

      }
      vals.ReadOnly = true;
      piErr = pt.Data.UpdateValues(vals, PISDK.DataMergeConstants.dmReplaceDuplicates, null);
      }

       

      I also tried UpdateValue method. In this case, It only adds about 180 values to the Point, stopping at the Snapshot time (there are more than 3000 values).

       

      Thanks,

       

      Tie

       


        • Re: PISDK - UpdateValues does not work
          Marcos Vainer Loeff

          Hello Tie,

           

           My guess is that there is something wrong with your variable tst. I have tested the code snippet below and it works fine for me. Could you test it and tell us the results please?

           

           

           
          int[] ValuesArray = new int[] { 1, 2, 3, 4, 5 };
                      DateTime[] TSArray = new DateTime[] { DateTime.Now.AddHours(-10), DateTime.Now.AddHours(-8), DateTime.Now.AddHours(-6), DateTime.Now.AddHours(-4), DateTime.Now.AddHours(-2) };
                      PISDK.PISDK sdkroot = new PISDK.PISDK();
          
                      PISDK.Server _PIServerRef = sdkroot.Servers["YOURSERVER"];
                      PISDK.PIPoint pt;
                      PIValues vals;
                      PIValue piVal;
                      PIErrors piErr;
          
                      pt = _PIServerRef.PIPoints["LabNum"];
                    
                      
                      if (pt != null)
                      {
          
                          vals = new PIValues();
                          vals.ReadOnly = false;
          
                          for (int j = 0; j < TSArray.Length; j++)
                          {
                              piVal = vals.Add(TSArray[j], ValuesArray[j], null);
          
                          }
                          vals.ReadOnly = true;
                          piErr = pt.Data.UpdateValues(vals, PISDK.DataMergeConstants.dmReplaceDuplicates, null);
                      }