"TIME" as an integer..
Rod N
Junior Member
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??
I need to 'timestamp' some communications between systems and have a measurable number to calculate with.
Any ideas??
Comments
-
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))
-
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. -
How about GET_TIMER? It returns to the tenth of a second but I think the time is measured from boot up
-
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? -
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. -
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)" } -
Thanks Chris ! Thats as precise as I would ever need..
and thanx to Joe and vining -
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.
Leave a Comment
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums
