Announcement

Collapse
No announcement yet.

Is hs.DeviceValueEx rounding at 3 decimal places?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Is hs.DeviceValueEx rounding at 3 decimal places?

    While migrating application scripts from HS2 to HS4 4.2.7.0 (HomeTroller HS4 Pro/Windows 10 Pro), I have observed that when device double precision values are returned to a script using hs.DeviceValueEx(), the values are rounded at the 3rd decimal point. e.g. the device detail display will show the value as 1.54138886928558, and the status as 1.541389 Hours (6 decimal places as configured, with Hours as the suffix).

    However, when the midnight history snapshot script runs, this value is returned by hs.DeviceValueEx() as 1.541.

    I have tested values like 1.23456789, this would be returned as 1.235 (rounded up at the 3rd decimal point).

    The test values were formated both with Format() and CStr(), both yielding the same result, rounding at the 3rd decimal point.

    hs.SetDeviceValueByRef() seems to take any specified double precision value and deposit it in the device,

    As I never went through the HS3 cycle, I don't know if this is a known phenomena

    TIA

    Best Regards

    #2
    I don't see that here.

    I ran this simple script which sets the device value and then reads it back to the HS Log:

    Code:
        Sub Main(ByVal Parm As Object)
    
            hs.SetDeviceValueByRef(2766, 1.23456789, True)
            hs.writelog("Test", hs.DeviceValueEx(2766))
    
        End Sub
    Click image for larger version

Name:	Capture.PNG
Views:	277
Size:	2.5 KB
ID:	1526446

    Jon

    Comment


      #3
      I copy/pasted your script just changing the device address.

      Still rounding here (Hometroller HS4 Pro 4.2.7.0/WIndows 10 Pro).

      Thanks for the assist.
      Attached Files

      Comment


        #4
        Some interesting data..

        As mentioned previously, this database was not migrated from HS3, it was scratch built after an HS2 system failure. Almost all the device values are computed in scripts, there is no need to be able to enter any values from the screen.

        Consequently, my HS4 device configurations contain no 'Controls' section, only the 'Status/Graphics' section is used as this was all that was required to display a value on the device detail display.

        The following tests were done this morning assuming that the device configuration was somehow involved.

        1) deposit 0.123456789 into the device from the script into the existing test device (no 'Controls', 'Status/Graphics' is defined)

        2) delete the 'Status/Graphics' configuration - at this point there is no 'Controls' or 'Status/Graphics' configuration
        3) fetch the value in a script and write to log -> 0.123

        4) Add 'Controls' with a range of 0..1, decimal places is unchanged at 0.
        5) fetch the value in a script and write to log -> 0.123

        6) Change decimal places from 0 -> 5
        7) fetch the value in a script and write to log -> 0.12346 (rounded at the 5th decimal)

        6) Change decimal places from 5 -> 9
        7) fetch the value in a script and write to log -> 0.123456789


        At the very least is seems that the device confguration ('Controls' and/or 'Status/Graphics') is involved in the precision of the value returned by hs.DeviceValueEx(). Apparently if no decimal is specified, then 3 places are returned by default. Or possibly there is some other configuraton which is causing this 'apparent' involvment of the 'Controls' configuration.

        In your test case, does device 2766 have a 'Controls' section defined?

        Attached Files

        Comment


          #5
          Well I deleted the controls and status graphics for the device and then ran the script again.

          That does return the value to 3 decimal places. Looks like a bug and should be reported.
          Jon

          Comment


            #6
            Thanks for double checking. Duly reported. I could make a case for using the 'Status/Graphics' decimal places, but not the 'Controls' decimal places.

            In the meantime, I'll modify the applications to use different engineering units to remove the precision issue.

            Best Regards

            Comment

            Working...
            X