"TIME" as an integer..

Rod NRod N Junior MemberPosts: 28
Does anyone know how to display/convert a masters TIME to a number..?
I need to 'timestamp' some communications between systems and have a measurable number to calculate with.
Any ideas??

Comments

  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    The keywords TIME_TO_HOUR, TIME_TO_MINUTE, and TIME_TO_SECOND should get you where you want to go.
    DEFINE_VARIABLE _
    
    VOLATILE INTEGER nHours
    VOLATILE INTEGER nMinutes
    VOLATILE INTEGER nSeconds
    
    DEFINE_START
    
    nHours = TYPE_CAST(TIME_TO_HOUR(TIME))
    nMinutes = TYPE_CAST(TIME_TO_MINUTE(TIME))
    nSeconds = TYPE_CAST(TIME_TO_SECOND(TIME))
    
    
  • Rod NRod N Junior Member Posts: 28
    Thx Joe.. but I should have been more explicit. I need the time as one variable to log events down to the millisecond (if possible).

    I was sure there was a internal variable that each master uses to interpret the current time, date etc..

    I know I could write a function based on the "TIME_TO..." integers but I'm hoping for more precision.
  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    How about GET_TIMER? It returns to the tenth of a second but I think the time is measured from boot up
  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    If you telnet into the master and do a ‘msg on’ each message is time stamped with the number of milliseconds since the program has been running but that number has nothing to do with the time of day.

    I don’t know of any variable we can get at with Netlinx to obtain the time of day with the precision you’re looking for. Maybe Duet has something?
  • viningvining X Member Posts: 4,348
    For single variable just use a function to convert from 24 hour time, just pass the function the "TIME" keyword.
    DEFINE_FUNCTION LONG fnConv_24HrTimeToSeconds(CHAR iTime[])
    
         {
         RETURN ((((ATOI(REMOVE_STRING(iTime,"':'",1)) * 60) + ATOI(REMOVE_STRING(iTime,"':'",1))) * 60) + ATOI(iTime)) ;
         }
    

    or if you have the individual values from "TIME_TO_xxx" do this:
    sMyTime.nTime = ((((sMyTime.n24Hour * 60) + sMyTime.nMinute) * 60) + sMyTime.nSecond) ;
    
    I don't know how you would get a more precise time though unless you create a timeline and restart (sync it) every day at midnight. Run it at the precision you need and then do math on your timeline.repition or the global variable you use to hold that value.
  • HARMAN_ChrisHARMAN_Chris Harman Professional University Posts: 292
    Rod,
    A need for something similar came up recently and the code below is as close as I could get - but it isn't 100%. To create the millisecond field, I essentially created a repeating timeline that would occur more than once a second. Your testing will show the sweetspot of the timeline results in 60 passes and is repeatable. At its smallest time interval, the master (under no other load) can do this more than 1500 times per second, but that number goes down as load on the processor increases to do the rest of your system program. I was never able to achieve 100 steps (a true millisecond) reliably. There are too many unknown variables affecting the results - but 60 is achievable.
    PROGRAM_NAME='test_code'
    
    DEFINE_DEVICE
    
    (***********************************************************)
    (*               CONSTANT DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_CONSTANT
    INTEGER TL_TimeStamp	=	1
    
    (***********************************************************)
    (*               VARIABLE DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_VARIABLE
    VOLATILE FLOAT 			  fMilliTracker
    VOLATILE SLONG 				slInitialSecond
    VOLATILE SLONG 				slCurrentSecond
    VOLATILE LONG 				tlTimes_TimeStamp[1] = 	10;
    VOLATILE FLOAT				fIncrementer = 1.68;//step rate
    
    (***********************************************************)
    (*                STARTUP CODE GOES BELOW                  *)
    (***********************************************************)
    DEFINE_START
    TIMELINE_CREATE(TL_TimeStamp, tlTimes_TimeStamp, 1, TIMELINE_ABSOLUTE, TIMELINE_REPEAT);
    (***********************************************************)
    (*                THE EVENTS GO BELOW                      *)
    (***********************************************************)
    
    DEFINE_EVENT
    TIMELINE_EVENT [TL_TimeStamp]
    {
    		slCurrentSecond = TIME_TO_SECOND(TIME)
    		fMilliTracker = (fMilliTracker+fIncrementer)
    	IF(slInitialSecond<>slCurrentSecond)
    	{
    		//reset the tracker
    		fMilliTracker = 0
    		//reset the initial second
    		slInitialSecond = slCurrentSecond
    	}
    	SEND_STRING 0, "TIME,'.',ITOA(fMilliTracker)"
    }
    
  • Rod NRod N Junior Member Posts: 28
    Thanks Chris ! Thats as precise as I would ever need..
    and thanx to Joe and vining
  • truetrue Junior Member Posts: 307
    If you need UNIX timestamps, I wrote an include that is a part of the NetLinx Common Library to handle conversion to/from AMX time and to format time strings using UNIX timestamps. Not sure if you may need that in addition to sub-tenth-second timing.
Sign In or Register to comment.