Home AMX User Forum NetLinx Studio

creating/using time variables

I'm trying to come up with a simple on/off timer for a system without using i-schedule or anything like that. I figured it should be easy to create my own time variable, and have an IF statement to match the system 'TIME' against that. I've got a working interface that manipulates system_on/system_off variables such as as CHAR Start_Time[8], so that they look like '12:05:00'. I stuck an IF in DEFINE_PROGRAM so that IF(TIME = Start_Time) it would set a flag, but it doesn't seem to work. Perhaps I'm missing something really simple, it just doesn't seem like this should be a difficult thing to do. Any suggestions?

Matt.

Comments

  • creating/using time variables

    There is nothing wrong with the time comparison IF statement that you noted in your message. It is identical to the samples provided in the online help for TIME and the construct is used in the AMX SunriseSunset axi file for determining when to check for daylight savings time.

    One possibility is that your mainline code (DEFINE_PROGRAM) is not executing every second and therefore when the check is executed, the time does not match. This could be the case if you have a system with a lot of events, a system with a lot of mainline code that takes a while to run, or a combination of both.

    Keep in mind that you could modify the TIME string you store in Start_Time such that Start_Time[8] = '?' and then use COMPARE_STRING to compare the current time in mainline to Start_Time. The '?' is a wildcard comparison character and therefore the conditional would match the time down to a 10 second interval (i.e. 12:05:00 -> 12:05:09 using 12:05:0?). I use this type of construct frequently just in case mainline was delayed in running by events such that one or more seconds went by before it was executed.

    Hope this helps --

    Reese
  • Thanks a lot Reese. It worked with the compare. I didn't much figure that I would have that kind of issue, as I just wrote a simple test program that had only those time functions in it. I know that I've used IF(TIME = '23:59:59') type statements on working systems in the past, but I think I'll switch to using COMPARE_STRING with wildcards from now on. That's what I enjoy this stuff; I never stop finding new ways to do things.
  • AFAIK the '?' wildcards in TIME and DATE string will not work in NetLinx!!!

    What I do in such applications is to separate the time or date elements into numeric values:

    INTEGER nMyHour
    INTEGER nMyMinute
    INTEGER nMySecond

    nMyHour = TIME_TO_HOUR(TIME)
    nMyMinute = TIME_TO_MINUTE(TIME)
    nMySecond = TIME_TO_SECOND(TIME)

    Almost the same with DATE:
    INTEGER nMyDay
    INTEGER nMyMonth
    INTEGER nMyYear

    nMyDay = DATE_TO_DAY(DATE)
    nMyMonth = DATE_TO_MONTH(DATE)
    nMyYear = DATE_TO_YEAR(DATE)
  • creating/using time variables

    Marc,

    You are correct that WILDCARDs do not work in Netlinx if used directly in a comparison statement such as:
    IF(TIME = '12:00:0?')
    {
        // works in Axcess but not in Netlinx!
    }
    
    This apparently used to work in Axcess but is one of the constructs that needs to be converted during a migration to Netlinx since it does not work in Netlinx. However, WILDCARDs that are utilized in conjunction with the COMPARE_STRING() function work fine. I have tested it (and have modules that use it) and it does work. This is why I pointed out to Matt that COMPARE_STRING() was required if the WILDCARD construct was to be used -- it could not be substituted directly in the IF comparison and work correctly in Netlinx.

    Also, see AMX TechNote 555 which explains the difference between Axcess and Netlinx with respect to WILDCARD handling.

    Reese
  • GSLogicGSLogic Posts: 562
    Not to make things more complicated, but I've found that if you don't use a Timeline that triggers every minute to check your COMPARE_STRING, the command in your statement can repeat. The processer can loop a couple times over the 10th of a second that it is looking to COMPARE_STRING.

    I set mine to COMPARE_STRING(time == '12:30:??'), this way I know it will only trigger one time.

    You can test this by adding a nCOUNT++ in the statement and watch it count up, every increase in nCOUNT would be another command sent. This is also effected by how many lines of code are in the DEFINE_PROGRAM section, the more code less repeats.
  • IF (COMPARE_STRING(TIME,''12:00:??'))
    

    This works ok for me.
  • DHawthorneDHawthorne Posts: 4,584
    A comparison of that nature will only actually fire when the time in question occurs. I have found that to be inadequate for things that I wanted to make certain always happen ... what, for example, if the power cycles, and your device is off, but wasn't set to go on by timer again until the next day? It stays off for a day? That's OK for some things, but for events like thermostat setbacks, it's not good enough.

    So, instead of simply testing a time, I keep a persistent array of event flags and test for a time range instead. I'll break the time string into hours and minutes using TIME_TO_HOUR() and TIME_TO_MINUTE(), then test if the current time is greater than those values. If it is, and the flag is not set, then set the flag and fire the event. The set flag prevents it from firing twice, and if the system reboots at noon, you won't lose your 7AM event. All tests are done in a repeating timeline, usually run more than once a minute, depending on how precise I need it to be. Also in that timeline, I test the date, and if the date has changed, reset all the flags to false so the events will happen again on a new day.
  • Time

    Hopefully somedoby can help me, I have a similar issue, I have a NI-700 and NI-2100. I asked for help here on the forum, and tried to load the code and it turns it off, by the projector gets into stand by instead of turn it off. Panasonic 80U and 60U. Anyway here is the code first try

    (* FORCE PROJECTOR TURN OFF *****************************************************)
    IF (COMPARE_STRING(TIME,'16:20:0?'))
    {
    wait 1810
    {
    SEND_STRING dvPROJ,"$02,'POF',$03"
    proj_off=0

    }
    }

    here is the other

    (*********************************Auto Shutdown *****************************)

    IF (COMPARE_STRING(TIME,'22:00:00'))

    {
    {
    SEND_STRING dvProjector,"$02,'POF',$03";
    }
    }
  • Time

    I was reading some threads and this is what I found. Click on the link

    http://www.amxforums.com/showthread.php?3470-Commands-at-Certain-Times&highlight=COMPARE_STRING
  • Time

    Finally I figure out how to make my projectors turn off, after reading and reading and too many test's, I got it. Thank God for this forum and genorous people for posting their solutions.
    here is the code from B_Clements

    Define_Program

    IF (TIME='22:00:00') // Execute everyday at 10 PM
    {
    Wait 11
    fnSystem_Power(nOff) // Excute system off function
    }

    Here is my code for Panasonic projector

    Define_Program

    ******************Shutdown**************)
    IF (TIME='13:34:00')
    {
    wait 11
    SEND_STRING dvProjector,"$02,'POF',$03";
    }

    Again I thank to everybody for the post
Sign In or Register to comment.