Getting sub-second System Time

Hi all. Stupid question, but I can’t find it…

We are using SNAP PAC, are moving to 10.2 and are adding some functionality.

We have a “Dispatch” Chart running that communicates with an external windows based process. This Dispatch Chart is only used for tasks that must be synchronous with external hardware not controlled by OPTO22 hardware or processes. Until recently we were able to capture the System time and log it as part of a log record. Simply: “TimeToString(sSystemTimeDispatch);”. Dispatch can initiate and control a little over 60 tasks. We now would like sub-second resolution on the start and end times. I know we can use up timers, but those are not “human readable”. We could start one at midnight and convert the value to HH:MM:SS.000, but there are a lot of locations and it introduces errors between 2 tasks that span midnight…

Is there a mechanism to capture the System Time in higher than 1 Second resolution?

Thanks in advance,

Yes, but I don’t think you are going to like it much…

The only sub-second time that I know of is ‘Milliseconds since powerup’.

You might need a subroutine to format it a little if you are going to use it a lot or in different places.

Perhaps you could continue to use your “TimeToString(sSystemTimeDispatch);” and append the last three digits of Milliseconds Since Powerup. Elapsed Time and Milliseconds Since Powerup are already synchronized. If you go with this approach, consider the very rare occurrence of when Milliseconds Since Powerup ‘rolls over’, but this may be perfectly divisible by total seconds (the ideal situation here), or if not, the very rare error of less than a second may be acceptable to you.
[edit] (FFFF F030 010C) Milliseconds Since Powerup ‘rolls over’ every 49.71 days (Page 92 of OPTOMMP Protocol Guide Form 1465-200312—March 2020). Or (FFFF F030 0228) Milliseconds Since Powerup ‘rolls over’ every 584,542,046 years (Page 93). Both of these are available in my PAC-R1, PAC-R2, PAC-EB1, PAC-EB2, and GRV-EPIC-PR1.

R2 image

EB2 image

EPIC-PR1 010C image


EPIC-PR1 0228 image


Being a hack in OPTO programming, I do not yet know how to access “Milliseconds Since Powerup” but once I learn, I could use:

NumberToString( (However I get ‘Milliseconds Since Powerup’ ) %1000 , sTemp);
sSystemTimeDispatch += “.” + sTemp;

Most of the time, I am looking at relative times that are 10’s of minutes apart.

The few rollovers are not a risk.

The command you want is;
Read Number from I/O Unit Memory Map

Take a read of the command help, but you should end up with something like this;

I should note that this command only works on SNAP PAC Controllers. EPIC has a real time clock and this memory map location does not exist on (in?) that controller.

The easiest way to get milliseconds is to use the GetDateTime command. It sets an integer table with the current date and time. The milliseconds value is in index 7. This will work on PAC and EPIC.

Thanks @philip that’s a much better way to get the whole range in one hit.

Here is what it looks like;

Perfect. Already implemented. Thank you.

Be careful if concatenating the milliseconds result from GetDateTime with TimeToString, since you are getting these values at two different times and it will not be an atomic operation. It is possible towards the end of the second that you could end up with the previous second in TimeToString, and the milliseconds from the next second.

It would be best practice to build the time string all from the date/time table returned by GetDateTime.

@Beno, why does the ms entry show -792? :astonished:

I wondered if I could slip it past everyone… beta firmware on an EPIC… Its been fixed.
One of the joys and hazards of the job.
(That and I wanted to prove to myself that the command worked fine on an EPIC).

Oh good - I can image that could screw up a few things…

That is how I did it. Only one call… Thanks.