Hello everyone,
I can not understand how I can get the system time in milliseconds, someone can give an example to do this?
Thank you
Serghei
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2016-05-01
Originally created by: scott_cunningham
For a PC, you need the SysTimeRtc library (part of the system library). Look for the function SysTimeRtcHighResGet. You can use the pTimestamp to get your time. See the library documentation. The most confusing part for me was the library implies pTimestamp is a pointer, but for my CoDeSys install, it is a ULINT. When you use other hardware besides a PC (i.e. PLC or embedded controller), the hardware vendor will have different libraries to access a realtime clock (if it exists on the hardware).
VARÂ Â Rtc:ULINT;Â Â Clock:TOD;END_VARSysTimeRtcHighResGet(pTimestamp:=Rtc);Clock:=ULINT_TO_TOD(Rtc);
For your needs, just use the ULINT - it is already in milliseconds.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Tank you for the answer, but i need thys for RaspBerry pi 3 and not for PC.
I try with thys:
  LTIME1:LTIME;  TimeOFDay:TOD;  milliseconds:DINT;  LTIME1:=LTIME();  TimeOFDay:=LTIME_TO_TOD(LTIME1);  milliseconds:=TOD_TO_DINT(TimeOFDay);
With thys not work... the value is not stable e not good increment,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I solved the problem!
The value was not stable because it was testing the application from a webvisualization, and this was set by default to a 100 ms cycle time.
Therefore, when I went to see the value it did not seem a plausible time. I apologize for the inconvenience, I hope it can serve to someone.
The final code is as follows:
  TIME1:TIME;  milliseconds:DINT;  TIME1:=TIME();  milliseconds:=TIME_TO_DINT(TIME1)/10;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everyone,
I can not understand how I can get the system time in milliseconds, someone can give an example to do this?
Thank you
Serghei
Originally created by: scott_cunningham
For a PC, you need the SysTimeRtc library (part of the system library). Look for the function SysTimeRtcHighResGet. You can use the pTimestamp to get your time. See the library documentation. The most confusing part for me was the library implies pTimestamp is a pointer, but for my CoDeSys install, it is a ULINT. When you use other hardware besides a PC (i.e. PLC or embedded controller), the hardware vendor will have different libraries to access a realtime clock (if it exists on the hardware).
For your needs, just use the ULINT - it is already in milliseconds.
Hy Scott,
Tank you for the answer, but i need thys for RaspBerry pi 3 and not for PC.
I try with thys:
With thys not work... the value is not stable e not good increment,
Hello,
I solved the problem!
The value was not stable because it was testing the application from a webvisualization, and this was set by default to a 100 ms cycle time.
Therefore, when I went to see the value it did not seem a plausible time. I apologize for the inconvenience, I hope it can serve to someone.
The final code is as follows:
Hi, thanks for sharing your final results. may I ask why are you diving by 10?
Last edit: nilo 2024-02-28