2 Replies Latest reply on Nov 15, 2017 3:13 PM by nstudanski

    [PISDK] PIPoint.PointAttributes.ModifyAttributes() doesn't save the changes to the PIPoint or server


      Running into a problem with the ModifyAttributes method. Have a custom point with name and attributes and custom Historian object storing a PISDK server. Goal is to read PIPoints from the server and compare to the points set up on local PLC. I'm accessing the PIPoints by IHistorian2.GetPoints2() with * for tags and NamedValues, then accessing that with direct path. Wrote a function that will compare each <key, value> attribute from the custom point and PIPoint to compile a dictionary to turn into NamedValues for the <key, value> of the attributes that differ. This should be more efficient than just writing every attribute individually to the Server. Problem is that my ModifyAttributes call with a list of several NamedValues to change will not show up when importing all the points from PI-SMT excel add-in, and they also have not changed when I debug and write what should be the updated calls. I have not been able to find a save or checkin or any similar method that might be necessary. Is there another call I need to be making to save the changes or anything else to make it work, or will I need to find a different solution? Appreciate any help.



      Snippet comes from my Historian class, findDifferences simply compares the two dictionaries from the PI and custom point attributes to return the ones that should be updated. First set of debugs works correctly, so if custom had <Location1, 1> and PI had <Location1, 2> it will have (Location1, 1) pair in it. I would expect that the second debug would then show that it was changed to <Location1, 1> from the PIPoint, but it stays as <Location1, 2>


      Dictionary<string, object> needToBeUpdated = utility.FindDifferences(point, pointAttributesDictionary);

                  if(needToBeUpdated.Count > 0)
                      var changes = new NamedValues();
                      NamedValues outErrors;

                      foreach (var attribute in needToBeUpdated)
                          changes.Add(attribute.Key, attribute.Value);

                      foreach (NamedValue nv in changes)
                          Debug.WriteLine($"{nv.Name} change to {nv.Value}");
                      piPoint.PointAttributes.ReadOnly = false;
                      piPoint.PointAttributes.ModifyAttributes(changes, out outErrors);
                      piPoint.PointAttributes.ReadOnly = true;
                      NamedValues newAttributes = piPoint.PointAttributes.GetAttributes();
                      foreach (NamedValue attribute in newAttributes)
                          Debug.WriteLine($"{attribute.Name}: {attribute.Value}");

        • Re: [PISDK] PIPoint.PointAttributes.ModifyAttributes() doesn't save the changes to the PIPoint or server

          Hi Nathan.


          I tested this out on my system and didn't run into the same problem that you are reporting. Here is my small test application:

          Server srv = sdk.Servers.DefaultServer;
          PIPoint pt = srv.PIPoints["testtagtochange"];
          Console.WriteLine($"{pt.PointAttributes["location1"].Name} {pt.PointAttributes["location1"].Value}");
          Console.WriteLine($"{pt.PointAttributes["location2"].Name} {pt.PointAttributes["location2"].Value}");
          NamedValues attrChanges = new NamedValues();
          attrChanges.Add("location1", 4);
          attrChanges.Add("location2", 5);
          pt.PointAttributes.ReadOnly = false;
          pt.PointAttributes.ModifyAttributes(attrChanges, out NamedValues attrErrors);
          pt.PointAttributes.ReadOnly = true;
          Console.WriteLine($"{pt.PointAttributes["location1"].Name} {pt.PointAttributes["location1"].Value}");
          Console.WriteLine($"{pt.PointAttributes["location2"].Name} {pt.PointAttributes["location2"].Value}");


          Upon running this application, I can see the location1 and location2 attributes change from whatever their existing values are to the new values that I've specified (in this case the numbers 4 and 5). Looking at the documentation for the ModifyAttributes method, it says the following:


          "This method modifies a number of attribute values in a single call. The desired changes are passed in a NamedValues collection. If any of the specified modifications fail, no changes are made. The nvErrors argument indicates which of the entries was in error and what type of error was encountered."


          Is there any chance that some of the attributes that you are trying to modify are incorrect? Is there anything in the NamedValues outError object that you created or is it empty? Please let me know.


          Also, I think it's worth mentioning here that you should consider using AF SDK over PI SDK whenever possible. In this case, you can use AF SDK to edit existing PI Point attributes, so it would be the preferred option for your project.


          Let me know if you have any questions.



          1 of 1 people found this helpful
            • Re: [PISDK] PIPoint.PointAttributes.ModifyAttributes() doesn't save the changes to the PIPoint or server

              I'm planning to look into the code today because I was starting to run into problems where the objects were not typecast correctly and then failing equality checks and wanting to change points that didn't need changing. So perhaps the ModifyAttributes has been working and the problems I'm having are more with the type equality checking. It's good to see that it worked for you as intended so I should be able to model it on that. Part of problem I'm facing with it and the program is trying to limit reads and writes to as few as possible with the historian and ME. And agreed that AFSDK would be best; however, client needs to use PISDK on it to match with the rest of their code.