"TIME" as an integer..
Rod N
Posts: 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??
I need to 'timestamp' some communications between systems and have a measurable number to calculate with.
Any ideas??
0
Comments
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.
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?
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: 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.
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)" }and thanx to Joe and vining