Is there a way for PLCNext runtime to get a millisecond count?
In AllenBradley, there was GSV (get system value) of WallClockTime, with attribute CurrentValue. It was a millisecond, 64 bit timestamp of the current dateTime.
I found such a thing very useful for referencing globally and building extremely resource efficient timing code for various things.
In PLCNext, I've found that I'm only able to get time down to the second and not as a Unix epoch time (like, since 1/1/1970 or since 1/1/2000, etc.)
If this isn't possible,
I'd also be very interested in finding any globally accessible millisecond incrementing integer. In microcontroller environments, this is called with a millis() function. It's quite common and just counts the milliseconds since the controller entered run-mode.
I ended up making my own millis with a program set to interval 1 millisecond, containing only the code
millis := millis + 1;
with millis being a global double 32 bit int.
I'm concerned about the reliability of that method
I obviously set the millis program to have the lowest priority value so it will always interrupt any other program, but I can't guarantee some system-level stuff won't mess with my millisecond timing.
Comments
Does anything in the PLCnextBase library help?
According to Martin's suggestion, you can pay attention to
for milliseconds timer:
8.62 FunctionBlock: PBCL_SysGetCycletime_1
8.65 Function: PBCL_SysGetMicrotick_1
8.66 Function: PBCL_SysGetMicrotick_2
for unix timestamp generation
8.35 Function: PBCL_DateTimeToUnix_1
All from rom PLCNextBase lib
Also take a look under the hood of ESM_DATA\ESM_INFOS[*]\TASK_INFOS[*] of system variables space.
Best regards.
Would you suggest that I add the output of GetCycletime or GetMicrotick to a global integer every execution of my program to have a running milli / microsecond counter? Or does DateTimeToUnix product a millisecond Unix time value?
Yes, it will be one of the simplest methods.
DateTimeToUnix produce timestamp in seconds, but it can be easy extended up to microseconds.
PBCL_SysGetCycletime();
PBCL_DateTimeGet();
ext_tmstp := TO_ULINT(PBCL_DateTimeToUnix_1(PBCL_DateTimeGet.dtDateTime)) * 1000000
+ TO_ULINT(PBCL_DateTimeGet.iMillisecond) * 1000
+ TO_ULINT(PBCL_DateTimeGet.iMicrosecond);
PBCL_SysGetCycletime(udiDelta => cycle1)