Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help - Trying to compare to Time fields
#1
Here is my situation. I have a counter that runs with my HVAC system. I want to compare that total time value to a defined number to determine if the filters need to be changed. For example, if the system has run 300 hours, I want to know it.

So I created a variable driver field that holds my triggering time (300 hours for example). It is a MEng.Time field and I set the value to 1290745203 (which is 300 hours I believe).

I also trigger off the Timer driver's "Previous Run Time Elapsed" field. I choose this field because it only changes once per HVAC cycle. If I triggered off the actual counter, it would trigger every millisecond the HVAC unit was on.

My problem comes in the fact that I get an error when I try to use simple logic in my triggered actions.

Code:
If System::GrThanOrEq($(HVAC_Filter_Timer.FilterTimer_TotalRunTimeElapsed), $(HVAC_RunTime_VarDriver.HVAC_Filter_Replacement_Time)
   //
   // If HVAC system is greater than the variable, then change the replace filter variable to true
   Devices::FieldWrite(Primary_Var_Driver.HVAC-ChangeFilters, True, True)
   //
End

This tries to compare the two time fields, but I get an error when it runs; "Could not convert 35F8F8EE0530 to binary value of type 'tCIDLib:TInt4'"

So it seems that you cannot do simple math logic with time fields. Can someone please assist me on how to work this out. I suspect it requires a simple macro, but I don't have the programming knowledge to write even something as simple as this might need.

Thanks,
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
Reply
#2
Yeh, when you do a command like that, the values passed just get converted to strings which then are converted by the target command to something it can use. When the parameters are numeric, they get converted to an int currently, so it's trying to convert those values to ints, and it can't do that.

Given that you don't need to be super-precise, one way might be to create two local variables, of Card8 type. Copy these values into them. Then divide them by one second to get number of seconds, then you can create two Int4 local variables and do a SetValueFrom to directly pass the Card8 values to the Int4 variables, which will just truncate the values down, but that'll be ok now since you've reduced the size of the numbers. You can then compare those variables.

This is something that needs to be dealt with in 3.5. One way to do that would be to have a Numeric action parameter type. Right now it has to be some specific numeric type, so these types of non-type specific ones are set to take integers, so it has to convert them to integers. If we had a generic Numeric parameter type, then in those cases it could look at them and decide an optimal representation and do the operation in those terms.
Dean Roddey
Explorans limites defectum
Reply
#3
Dean,

I'm having trouble getting that idea to work. Here is my action commands for you to check. I was trying to follow your suggestions above....

Code:
[OnClick]
   // =====================================================================
   // Determines if the HVAC Filters need to be changed
   // ---------------------------------------------------------------------
   //
   // We need to see if the total run time is longer than the
   //  HVAC Filter Replacement Time Variable
   //
   // Since the system cannot compare time values, we must read the
   // values into some LVars and do some math to compare them
   LocalVars::CreateVariable(LVar:TotalTime, Card, , $(HVAC_Filter_Timer.FilterTim...)
   LocalVars::CreateVariable(LVar:FilterChangeTime, Card, , $(HVAC_RunTime_VarDriver.HVAC...)
   //
   // Divide the LVars by 1000 to get the number of seconds
   LocalVars::Divide(LVar:TotalTime, 1000)
   LocalVars::Divide(LVar:FilterChangeTime, 1000)
   //
   // Then read the LVars into two new Int4 LVars so we can compare them
   LocalVars::CreateVariable(LVar:TotalTimeInt, Int, , %(LVar:TotalTime))
   LocalVars::CreateVariable(LVar:FilterChangeTimeInt, Int, , %(LVar:FilterChangeTime))
   //
   //
   // Compare the values to see if the system has run long enough to change the filters
   If System::GrThanOrEq(%(LVar:TotalTimeInt), %(LVar:FilterChangeTimeInt))
      //
      // If HVAC system is greater than the variable, then change the replace filter variable to true
      Devices::FieldWrite(Primary_Var_Driver.HVAC-Chang..., True, True)
      //
   End

But looking at the action trace (I put the command in a button to test), it seems that the time value for the total run time field is weird as it shows 35FC82F05820 as the value even though the actual value in the field shows as 59358644820000 (looking at it via the Admin Interface). This causes the system to end up dividing by Zero which causes the answer to be zero. What is weird is that the 2nd variable is read correctly and the dividing command works and ends up with a non-zero answer.

Code:
TRC: Start Action
CMD: 010.  (19ms) - LocalVars::CreateVariable
    P1=LVar:TotalTime
    P2=Card
    P3=
    P4=35FC82F05820

CMD: 011.  (35ms) - LocalVars::CreateVariable
    P1=LVar:FilterChangeTime
    P2=Card
    P3=
    P4=1290745203

CMD: 014.  (35ms) - LocalVars::Divide
    P1=LVar:TotalTime
    P2=1000

CMD: 015.  (35ms) - LocalVars::Divide
    P1=LVar:FilterChangeTime
    P2=1000

VAR: Set variable 'LVar:FilterChangeTime'
       =1290745

CMD: 018.  (35ms) - LocalVars::CreateVariable
    P1=LVar:TotalTimeInt
    P2=Int
    P3=
    P4=0

CMD: 019.  (35ms) - LocalVars::CreateVariable
    P1=LVar:FilterChangeTimeInt
    P2=Int
    P3=
    P4=1290745

CMD: 023.  (35ms) - If System::GrThanOrEq
    P1=0
    P2=1290745

TRC: End Action [Result=Success]

Any suggestions?

Thanks,
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
Reply
#4
Oh, duh. Sorry. Create Time based variable fields and put the values into them, do the division by one second (which is a legal int value and will be accepted), then assign that result to a card variable to get it to card format for comparison.

Try that and see if it works. But read it into the variable using ReadField, not passing it in as $(device.field), which will require it go through the same sort of conversion as above. Reading it into the variable using ReadField will bypass that I would think.

The difference in values you are seeing is due to display radix. One place is showing it in decimal form and the other in hex form.
Dean Roddey
Explorans limites defectum
Reply
#5
OK - I think I made the changes as you suggested. I'm using Time Based LVars and I am reading the values into the LVar instead of setting them.

Code:
[OnClick]
   // =====================================================================
   // Determines if the HVAC Filters need to be changed
   // ---------------------------------------------------------------------
   //
   // We need to see if the total run time is longer than the
   //  HVAC Filter Replacement Time Variable
   //
   // Since the system cannot compare time values, we must read the
   // values into some LVars and do some math to compare them
   LocalVars::CreateVariable(LVar:TotalTime, Time, , )
   Devices::FieldRead2(HVAC_Filter_Timer, FilterTimer_TotalRunTimeElapsed, LVar:TotalTime, True)
   LocalVars::CreateVariable(LVar:FilterChangeTime, Time, , )
   Devices::FieldRead2(HVAC_RunTime_VarDriver, HVAC_Filter_Replacement_Time, LVar:FilterChangeTime, True)
   //
   // Divide the LVars by 1000 to get the number of seconds
   LocalVars::Divide(LVar:TotalTime, 1000)
   LocalVars::Divide(LVar:FilterChangeTime, 1000)
   //
   // Then read the LVars into two new Int4 LVars so we can compare them
   LocalVars::CreateVariable(LVar:TotalTimeInt, Int, , %(LVar:TotalTime))
   LocalVars::CreateVariable(LVar:FilterChangeTimeInt, Int, , %(LVar:FilterChangeTime))
   //
   //
   // Compare the values to see if the system has run long enough to change the filters
   If System::GrThanOrEq(%(LVar:TotalTimeInt), %(LVar:FilterChangeTimeInt))
      //
      // If HVAC system is greater than the variable, then change the replace filter variable to true
      Devices::FieldWrite(Primary_Var_Driver.HVAC-Chang..., True, True)
      //
   End

But it looks like the values for both LVars are set as hex values now. I'm not sure if that is an issue or not, but I don't think the math works with the hex values. The end result is still that I am comparing a zero value for some reason.

Action Trace:
Code:
TRC: Start Action
CMD: 010.  (6ms) - LocalVars::CreateVariable
    P1=LVar:TotalTime
    P2=Time
    P3=
    P4=

CMD: 011.  (6ms) - Devices::FieldRead2
    P1=HVAC_Filter_Timer
    P2=FilterTimer_TotalRunTimeElapsed
    P3=LVar:TotalTime
    P4=True

VAR: Set variable 'LVar:TotalTime'
       =0x35FC82F05820

CMD: 012.  (109ms) - LocalVars::CreateVariable
    P1=LVar:FilterChangeTime
    P2=Time
    P3=
    P4=

CMD: 013.  (109ms) - Devices::FieldRead2
    P1=HVAC_RunTime_VarDriver
    P2=HVAC_Filter_Replacement_Time
    P3=LVar:FilterChangeTime
    P4=True

VAR: Set variable 'LVar:FilterChangeTime'
       =0x1290745203

CMD: 016.  (138ms) - LocalVars::Divide
    P1=LVar:TotalTime
    P2=1000

VAR: Set variable 'LVar:TotalTime'
       =0xDD20D0A54

CMD: 017.  (138ms) - LocalVars::Divide
    P1=LVar:FilterChangeTime
    P2=1000

VAR: Set variable 'LVar:FilterChangeTime'
       =0x4C0A0D9

CMD: 020.  (138ms) - LocalVars::CreateVariable
    P1=LVar:TotalTimeInt
    P2=Int
    P3=
    P4=0xDD20D0A54

CMD: 021.  (138ms) - LocalVars::CreateVariable
    P1=LVar:FilterChangeTimeInt
    P2=Int
    P3=
    P4=0x4C0A0D9

CMD: 025.  (138ms) - If System::GrThanOrEq
    P1=0
    P2=79732953

TRC: End Action [Result=Success]

Any more thoughts?
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
Reply
#6
Oh, you aren't dividing by a big enough number. The values are 100-ns intervals, not milliseconds, so the 1000 isn't large enough to do the trick, and the value is still too large to fit into the target variable.

One second would be: 10000000
Dean Roddey
Explorans limites defectum
Reply
#7
Ahh, nanoseconds not miliseconds... that gets me every time!

Changed it to divide by 10000000 and it seems to work fine now.

Thanks!!
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
Reply
#8
Well the logic apparently is working, but the numbers are still weird. The math already comes up as telling me I need to change the filters after just a day or two. So clearly it isn't doing what I want.

Here is the action trace showing the current values and the end result of the >= equation being true. But it shouldn't be true until the HVAC system runs 300 hours which cannot be possible yet even if the HVAC system was running 24/7.

Code:
TRC: Start Action
CMD: 010.  (0ms) - LocalVars::CreateVariable
    P1=LVar:TotalTime
    P2=Time
    P3=
    P4=

CMD: 011.  (0ms) - Devices::FieldRead2
    P1=HVAC_Filter_Timer
    P2=FilterTimer_TotalRunTimeElapsed
    P3=LVar:TotalTime
    P4=True

VAR: Set variable 'LVar:TotalTime'
       =0x3457642400

CMD: 012.  (10ms) - LocalVars::CreateVariable
    P1=LVar:FilterChangeTime
    P2=Time
    P3=
    P4=

CMD: 013.  (10ms) - Devices::FieldRead2
    P1=HVAC_RunTime_VarDriver
    P2=HVAC_Filter_Replacement_Time
    P3=LVar:FilterChangeTime
    P4=True

VAR: Set variable 'LVar:FilterChangeTime'
       =0x1290745203

CMD: 016.  (20ms) - LocalVars::Divide
    P1=LVar:TotalTime
    P2=10000000

VAR: Set variable 'LVar:TotalTime'
       =0x57D0

CMD: 017.  (20ms) - LocalVars::Divide
    P1=LVar:FilterChangeTime
    P2=10000000

VAR: Set variable 'LVar:FilterChangeTime'
       =0x1F25

CMD: 020.  (20ms) - LocalVars::CreateVariable
    P1=LVar:TotalTimeInt
    P2=Int
    P3=
    P4=0x57D0

CMD: 021.  (20ms) - LocalVars::CreateVariable
    P1=LVar:FilterChangeTimeInt
    P2=Int
    P3=
    P4=0x1F25

CMD: 025.  (20ms) - If System::GrThanOrEq
    P1=22480
    P2=7973

CMD: 028.  (20ms) - Devices::FieldWrite
    P1=Primary_Var_Driver.HVAC-ChangeFilters
    P2=True
    P3=True

TRC: End Action [Result=Success]
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
Reply
#9
OK - looking at the action trace, it seems that instead of putting in the value of 1290745203 for the HVAC_Filter_Replacement_Time value, it is putting in a hex value of 0x1290745203.

Likewise, for the FilterTimer_TotalRunTimeElapsed which the current value is actually 224804480000 it is using a hex value of 0x3457642400 which I have no idea how it is coming up with. That hex value equals a decimal value of 59358644820000 which is clearly not the number I am looking for.

[Image: FilterTimer-1.jpg]

[Image: FilterTimer.jpg]

Any suggestions?
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
Reply
#10
Oh yeh, I forgot. The time guys assume a hex number. This was a bad decision made long ago but now too late to change. Just bring up the Windows calculator, enter the decimal value you want, then select the hex mode, and that's the value to provide.
Dean Roddey
Explorans limites defectum
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Time to replace my mSata HDD. ellisr63 4 1,407 11-23-2018, 11:47 AM
Last Post: ellisr63
  how to synchronize 2 fields lleo 3 1,613 12-01-2015, 01:56 PM
Last Post: Dean Roddey
  Return time from UPB rtarver 9 2,563 08-01-2015, 08:34 AM
Last Post: Dean Roddey
  Daylight Savings Time Deane Johnson 9 3,231 03-08-2015, 12:28 PM
Last Post: Deane Johnson
  Turning light off after certain time royalj7 8 2,229 11-04-2012, 02:35 PM
Last Post: royalj7
  run time driver potts.mike 3 1,562 02-06-2011, 06:49 PM
Last Post: Dean Roddey
  Formatting STDRtv time / date Sendero 2 1,712 01-27-2009, 12:56 AM
Last Post: Sendero
  Control fields in Main Template Trioxide 29 6,172 05-02-2008, 07:23 PM
Last Post: ellisr63
  Lights go off after set time ellisr63 3 1,638 12-16-2007, 09:05 AM
Last Post: ellisr63
  Variables and Zone Controls for driver fields jmwhooper 2 1,599 08-15-2007, 01:15 PM
Last Post: jmwhooper

Forum Jump:


Users browsing this thread: 1 Guest(s)