6 Replies Latest reply on Jun 9, 2016 12:23 PM by Dries.Verhees

    Returned AFValue type not always correct

    Dries.Verhees

      Hi everybody,

       

      I have noticed that in my implementation, the type in AFValue is not always in line with the type configured in AF.

      I have one attribute (Sinusoid) which is configured as a double.

      Attribute_Configuration.png

       

      I have created the following code (for testing purpose), where I execute two interpolated data calls.

      Type_Test.png

      The type is correct for the call with only one attribute, but the type is incorrect (single instead of double) for the call with two attributes.

       

      Is this the expected behavior? I'm using AF SDK 2.6.1.6238.

        • Re: Returned AFValue type not always correct
          John Messinger

          Hi Dries,

          I wouldn't expect the returned AFValue type to necessarily match the configured Attribute type. Taking your example, the tag Sinusoid is defined in PI as a Float32, which is equivalent to the Single data type in .Net. Configuring the AF Attribute that holds a PI Point DR to this tag with a data type of Double won't increase the resolution of the actual returned value from PI. This is the behaviour I would expect for compressed values. I think interpolated values could be a different story though, because you are not dealing with actual recorded values that have been written with a specific number resolution. I also expect that the issue of floating point number accuracy described in this Wikipedia article may be at play here, muddying the issue somewhat.

          1 of 1 people found this helpful
            • Re: Returned AFValue type not always correct
              Dries.Verhees

              Hi John,

               

              Thanks for you answer.

              I do understand that the PI Point is configured as float, but I don't expect different types in those two cases:

              • If I request only one attribute, I recieve a double
              • If I request two attributes in bulk, I recieve a single

              What is the reasoning behind this?

              I came across this difference because my application does some .NET type checking.

                • Re: Returned AFValue type not always correct
                  John Messinger

                  Hi Dries,

                  What AFSDK version are you using? Testing your code here on AFSDK 2.8.0.7444 (2016) with the same Element and Attribute configuration, I couldn't replicate the behaviour you saw. In my test, both values from the two bulk calls came back as the same type (Double), and all the test assertions passed.

                    • Re: Returned AFValue type not always correct
                      Dries.Verhees

                      Hi John,

                       

                      Thanks for putting effort in investigating the issue.

                      I'm developing against version 2.6.1.6238. Would it be possible to check whether you have the same behavior or not with version 2.6.1.6238?

                       

                      Update: I have just tried to rerun my tests, and now all the test assertions are passed. I haven't done anything, but maybe it was due to some caching?

                        • Re: Returned AFValue type not always correct
                          John Messinger

                          Hi Dries,

                          Tested the code against AFSDK 2.6.1.6238, and I still couldn't reproduce the behaviour you originally reported - all test assertions still passed.

                          There could well have been some AFSDK caching involved in your original encounter with this problem - did you possibly make any changes to the test element configuration in between iterations of running your code, or while the debugger was partway through execution? Calling the Refresh() method on the AFDatabase object is enough to ensure that you are not working from locally cached versions of your objects, or that any changes checked in after your initial connection are available to your calling code.

                            • Re: Returned AFValue type not always correct
                              Dries.Verhees

                              Hi John,

                               

                              Thank you for the efforts.

                               

                              I think you are right. It is probably due to caching. I was updating the AF model (including attributes/data types) regularly during my testing phase (not while running). I came across this issue because the type was different between single and bulk calls, which is probably due to different caching mechanisms. After refreshing, it seems to work fine.

                               

                              Thanks for you help.