Home AMX User Forum NetLinx Studio

TIME Command

Does anyone use the TIME command?

I am using it to send the current time to AXB-TMCs once a day in DEFINE_PROGRAM with a flag so my event only occurs once each time 06:00:00 comes around.

Is this a typical usage for the TIME command?

Does anyone find it otherwise useful?

Thanks!

Comments

  • JoeJoe Posts: 99
    I use it in instances where someone may leave a system on and go home for the weekend, thus running up hours on a projector, or burning in a plasma.

    IF(TIME='23:00:00')
    {
    // SHUT SYSTEM DOWN
    }

    Joe
  • banobano Posts: 173
    Joe wrote:
    I use it in instances where someone may leave a system on and go home for the weekend, thus running up hours on a projector, or burning in a plasma.

    IF(TIME='23:00:00')
    {
    // SHUT SYSTEM DOWN
    }

    Joe

    Or if you want to use the wildcard(??), valdating the expression for the entire minute:

    IF (COMPARE_STRING(TIME,''12:00:??'))
    {
    // SHUT SYSTEM DOWN
    }
  • hmm, i like the wild card, had missed that before. thanks for the insight.

    i do things with TIME, like downloading tv guides early in the morning for the next day; reseting log files just after midnight; for very remote systems, i ensure they do a reboot at 4am every day (i don't want an inaccessible device that's 300 kilometres away to hang); if the time is equal to sunset, turn on some lights, or open/close blinds :)

    i tend to place repeating, relative time events into a timeline. this is better for example when checking weather or news, every 60 minutes or so.

    just my 2 cents worth.
  • dchristodchristo Posts: 177
    Joe wrote:
    I use it in instances where someone may leave a system on and go home for the weekend, thus running up hours on a projector, or burning in a plasma.

    IF(TIME='23:00:00')
    {
    // SHUT SYSTEM DOWN
    }

    Joe


    Also keep in mind that the "If(Time='23:00:00')" will be true for a full second, and will execute multiple times. Make sure if you're doing something that should only be done once that you set a flag or somthing to make sure that it doesn't happen multiple times. I usually use a "Wait 11" for that purpose.

    --D
  • bano wrote:
    Or if you want to use the wildcard(??), valdating the expression for the entire minute:

    IF (COMPARE_STRING(TIME,''12:00:??'))
    {
    // SHUT SYSTEM DOWN
    }

    The '??' wildcard will not work in NetLinx!!!

    Some kind of funtion I'd do:
    DEFINE_VARIABLE
    VOLATILE INTEGER ZeitFlag
    
    DEFINE_FUNCTION CheckForTime()
    {
    	STACK_VAR SINTEGER Hour, Minute, Secund
    	// get current time
    	Hour = TIME_TO_HOUR(TIME) 		// get hour of system time as a numeric value
    	Minute = TIME_TO_MINUTE(TIME)
    	Second = TIME_TO_SECOND(TIME)
    	SELECT
    	{
    		ACTIVE((Hour = 12) AND (Minute = 0)): //
    		{
    			IF(NOT(TimeFlag)) // to prevent multiple executions
    			{
    				// Lock time check
    				TimeFlag = 1
    				// Do what you want
    			}
    		}
    		ACTIVE((Hour = 12) AND (Minute = 1)): // activate timecheck again
    		{
    			TimeFlag = 0
    		}
          }
    }
    
    DEFINE_PROGRAM
    WAIT 200 // check every 20 seconds only
    {
    	CheckForTime()
    }
    
  • banobano Posts: 173
    The '??' wildcard will not work in NetLinx!!!

    Some kind of funtion I'd do:
    DEFINE_VARIABLE
    VOLATILE INTEGER ZeitFlag
    
    DEFINE_FUNCTION CheckForTime()
    {
    	STACK_VAR SINTEGER Hour, Minute, Secund
    	// get current time
    	Hour = TIME_TO_HOUR(TIME) 		// get hour of system time as a numeric value
    	Minute = TIME_TO_MINUTE(TIME)
    	Second = TIME_TO_SECOND(TIME)
    	SELECT
    	{
    		ACTIVE((Hour = 12) AND (Minute = 0)): //
    		{
    			IF(NOT(TimeFlag)) // to prevent multiple executions
    			{
    				// Lock time check
    				TimeFlag = 1
    				// Do what you want
    			}
    		}
    		ACTIVE((Hour = 12) AND (Minute = 1)): // activate timecheck again
    		{
    			TimeFlag = 0
    		}
          }
    }
    
    DEFINE_PROGRAM
    WAIT 200 // check every 20 seconds only
    {
    	CheckForTime()
    }
    


    Please read Tech Note Number 555
  • Ups..... thanks Bano :rolleyes:

    However... nice to have functions to get the time elements numeric :D
  • viningvining Posts: 4,368
    This might be of use as well. JUst replace the 05 and 01 in this line ( if (Mytime.Minute == '05' && Mytime.Seconds == '01') to what ever you want, add the hour if you want, make them varialbes and change it from the keyboard. Then run in define program. Works good in lieu of single event time_line for things you want to happen every x hour, every x minute or x seconds.

    Every 15 minutes
     local_var integer nRunOnce
         If (Mytime.Minute == '00' || Mytime.Minute == '15' || 
              Mytime.Minute == '45' && Mytime.Seconds == '01' )
    	  {
    	  if (!nRunOnce)
    	       {
    	       // do something
    	       nRunOnce = 1
    	       wait 15
    		    {
    		    nRunOnce = 0
    		    } 
    	       }
    	  }
      
    

    I use the seconds to allow for a short wait to keep the event from repeating during the duration of the minute. So I wait for 1.5 seconds whichs is 1/2 second longer than the duration of the second of which the event would evaluate as true and keep repeating through every pass if not for the wait and the local variable nSBRunOnce.

    DEFINE_TYPE
    structure sTime
         {
         char Hour [2]
         char Minute [2]
         char Seconds [2]
         }
    DEFINE_VARIABLE
    
    non_volatile sTime MyTime
    
    DEFINE_FUNCTION fnProcessTime(char iMyTime [8])
         {
         if(length_string(iMyTime) == 8)
    	  {
    	  MyTime.Hour = get_buffer_string(iMyTime,2)
    	  cRSSTrash = remove_string(iMyTime,':',1)
    	  MyTime.Minute = get_buffer_string(iMyTime,2)
    	  cRSSTrash = remove_string(iMyTime,':',1)
    	  MyTime.Seconds = get_buffer_string(iMyTime,2)
    	  }
         }
    
    DEFINE_PROGRAM
         {
         stack_var char cMytime [8]
         if (cMyTime != TIME)
    	  {
    	  cMyTime = TIME
    	  fnProcessTime(cMyTime)
    	  }
         if (Mytime.Minute == '05' && Mytime.Seconds == '01')
    	  {
    	  local_var integer nRunOnce
    	  if (!nRunOnce)
    	       {
    	       send_string 0,"'Time ',Time,' - Updating Doing Something!',crlf"
    	       Do something
    	       nRunOnce = 1
    	       wait 15
    		    {
    		    nRunOnce = 0
    		    } 
    	       }
    	  }
         }
    
    
  • GSLogicGSLogic Posts: 562
    The wildcard will stay active for a full minute, this is simple but it works!
      IF(COMPARE_STRING(TIME,'10:00:??') AND nBLOCK == 0)
      {  
             nBLOCK = 1;
             //DO SOMETHING
            WAIT 700 nBLOCK = 0;	//reset
      }
    
  • davieodavieo Posts: 42
    String

    I use the time string for HVAC setbacks - we have a customer who sometimes turns zones off, but forgets to turn them back on. With Michigan weather - this can become an issue quickly from rapids temperature changes.

    As a result in my timeline for feedback I use this:

    IF(TIME='02:00:00')
    {
    //TO SAVE SPACE I WONT WRITE OUT THE LOOP,
    //BUT IT IS A FOR LOOP THAT TURNS THE ZONES ON.
    }

    Works well.
  • viningvining Posts: 4,368
    davieo wrote:
    As a result in my timeline for feedback I use this:
    
    IF(TIME='02:00:00')
    {
    //TO SAVE SPACE I WONT WRITE OUT THE LOOP,
    //BUT IT IS A FOR LOOP THAT TURNS THE ZONES ON.
    }
    
    Just keep in mind that if your feed back timeline repeats @ 200ms your code will run 4 or 5 times before the "if" is no longer true. 9 or 10 times if your feedback timeline is 100ms. If it were in define_program w/o a wait it would probably run 1100 times.
  • davieodavieo Posts: 42
    Correct

    vining,

    You are absolutely right, which is why this time line is at 1000ms. It is a seperate timeline for the HVAC feedback. You do point out something that is a good detail that less experienced programmers might miss. Also you made me realize that I did not put enough detail in my hastily crafted post. Sorry to all for any confusion.

    Dave
  • GSLogicGSLogic Posts: 562
    vining wrote:
    Just keep in mind that if your feed back timeline repeats @ 200ms your code will run 4 or 5 times before the "if" is no longer true. 9 or 10 times if your feedback timeline is 100ms. If it were in define_program w/o a wait it would probably run 1100 times.
    I've been trying to say this from the beginning. I gave up on the discussion, let them loop.:)
Sign In or Register to comment.