11 Replies Latest reply on Jul 31, 2013 12:43 PM by David Hearn

    AFAttribute.SetValue()

    guillaume_seurin

      Hi guys,

       

      I have an issue with AF and would like to have some help from you.

       

      I have a function which use SetValue() for write value in AFAttribute. Those attributes in which I was writing have datareference to a PIpoint and it was working very well.

       

      My issue has occurred  when I started to use AFAttributes without DataReferences. When I try to put a new value, it doesn’t work.

       

      I would like to store some values in AFAttributes which hasn’t any datareferences. Is it possible?

       

       

       

      For information, I was using something like this before in my ACE module:

       

              Dim oObjectAF As OSIsoft.AF.AFObject

       

              Dim oAttribut As OSIsoft.AF.Asset.AFAttribute

       

              Dim oTimeStamp As OSIsoft.AF.Time.AFTime

       

              Dim oAFValue As OSIsoft.AF.Asset.AFValue

       

              Dim tHeureExecution As Date

       

                   oObjectAF = OSIsoft.AF.AFObject.FindObject(Me._sPathAF)

       

                  oAttribut = CType(oObjectAF, OSIsoft.AF.Asset.AFAttribute)

       

                  oTimeStamp = New OSIsoft.AF.Time.AFTime(tHeureExecution)

       

                  oAFValue = New OSIsoft.AF.Asset.AFValue(Me.ValeurDouble, oTimeStamp, oAttribut.DefaultUOM)

       

                  oAttribut.SetValue(oAFValue)

       

       

       

      It could be great if you have some idea to help me.

       

      Thanks,

       

       

       

      PS: AFSDK v2.4.0.4431

        • Re: AFAttribute.SetValue()
          mhamel

          @Guillaume: If the given attribute has been created with the IsConfigurationItem set to true, you will need to apply the change by invoking the CheckIn method on the element or at the database level. When it is not a configuration item, the change will be applied automatically.

           

          Can you validate what is your scenario here?

            • Re: AFAttribute.SetValue()
              guillaume_seurin

              @Mathieu: Good remark but it's not my case here I'm trying to put value in an AFAttribute which isn't a Configuration Item.

               

              My changes are applied directly when there is a datareference, if not it doesn't work.

                • Re: AFAttribute.SetValue()
                  David Hearn

                  In order to see the updated value for an attribute that does not have a DataReference, you will need to refresh the element if it was previously loaded in order to update the client's cached value.

                    • Re: AFAttribute.SetValue()
                      Marcos Vainer Loeff

                      Hello Guillaume,

                       

                      I have tested your problem and it seems that if you don’t execute the CheckIn() method, the value, which was setted up through the SetValue() method, will only be shown while your application is still in execution.

                       

                      Please run the code snippet below on a console application and check the results. It has worked for me but I am testing with the most recent version of PI AF SDK.

                       

                       

                       
                                  AFDatabase myDB = AFObject.FindObject(@"\\MARC-PI2012\SeminarioRegional") as AFDatabase;
                                  AFAttribute myAttribute = AFObject.FindObject(@"\\MARC-PI2012\SeminarioRegional\Cidades|Attribute1") as AFAttribute;
                                  Console.WriteLine("Name of the attribute:" + myAttribute.Name);
                                  Console.WriteLine("Current value: " + myAttribute.GetValue().ToString());
                                  AFValue myValue = new AFValue(2);
                                  myAttribute.SetValue(myValue);
                                  Console.WriteLine("Current value: " + myAttribute.GetValue().ToString());
                                  myDB.CheckIn();         
                                  Console.ReadKey();
                      

                       

                       

                      Hope this helps you!

                        • Re: AFAttribute.SetValue()
                          guillaume_seurin

                          Hi!

                           

                          @David: Yep, I have already try this. When I refresh my System Explorer, no new values appears in my AFAttribute.

                           

                          @Marcos: It seems that the CheckIn operation don't change anything. I have tried in my function and there is still no value.

                           

                          And the problem you described is not like mine. I haven't no new value even if my application is still in execution.

                            • Re: AFAttribute.SetValue()
                              guillaume_seurin

                              I want to share with you an extract of the AFSDK reference.

                               

                              In the paragraph about AFAttribute.SetValue Method, we can read this:

                               

                              "A value of any type may be written with SetValue, however, in order for a value to be saved, it must either be a .NET base type, a .NET serializable type, or support the PI SDK's IPIPersist interface. This means it is possible to write values such as Array, DataSet, PISDK.PIPoint, and references to other AF SDK objects. All DataReferences are not required to support all .NET types so the value must be compatible with the underlying AFDataReference configured for the attribute. "

                               

                              I wonder that "in order for a value to be saved" match with my issue. Insofar as there isn't underlying AFDatareference configured for my AFAttribute, my question is still: is it possible to store some values in an AFAttribute which has no datareference? It seems that it's possible but I don't know how.

                               

                              Thanks for help!

                                • Re: AFAttribute.SetValue()
                                  David Hearn

                                  You can store any value that meets the above criteria as the value of an attribute without a DataReference. It appears you are attempting to write a double value based upon the name of the variable. If so, that should work without any problems. It could be a security permission problem but you should be getting an error in that case when calling SetValue. You must have WriteData permission on the element in order to set its value and Write permission on the Database.

                                   

                                  Just to be sure, you can also try shutting down PI System Explorer and re-opening to check if the value was saved. This would remove any chance of PSE not being updated correctly with a Refresh.

                                  • Re: AFAttribute.SetValue()
                                    Marcos Vainer Loeff

                                    Hello Guillaume,

                                     

                                    Please create a new AF database with an element and an attribute with no datareference. Edit and run my code snippet from my last post (which worked perfectly with me) in a console application and send us the error message.

                                     

                                    If that doesn’t work, could you also upgrade your PI AF SDK to version 2012 just for testing purposes? You can install the old version later if you want to.

                                      • Re: AFAttribute.SetValue()

                                        Are you using an AF Collective?

                                         

                                        Can you store a value to the attribute manually in PSE? Using the same credentials as your application.

                                          • Re: AFAttribute.SetValue()
                                            guillaume_seurin

                                            Hi,

                                             

                                            @David: I have re-open my system explorer, it doesn't change anything.

                                             

                                            @Marcos: I have tried your code. It works well. I have to catch the difference in my code which makes the setvalue impossible.

                                             

                                            @Rhys: I'm not using an AF Collective. But when I have tried to put a value manually in PSE in my AFAttribute, at first, it seems to be ok but when I refresh it, the value disappears and the last one comes back. I have to click on CheckIn Button in order to keep the new value although my attribute isn't an configuration item...

                                              • Re: AFAttribute.SetValue()
                                                David Hearn

                                                The fact that you must call CheckIn for the value to be persisted indicates that in fact it is set as a configuration item or the attribute belongs to a new element that has never been checked in. The property AFAttribute.IsConfigurationItem should be set to false for your attribute. By default, it will be set to true for attributes without a DataReference. In PI System Explorer you will see this as a check box in the attribute's property page and should be unchecked.