sbrun Posted September 13, 2012 Share Posted September 13, 2012 In a Cplc (Rti or Bg) : I would like get the time (or TickCounts) in order to calculate the duration of my process. In PLCScript, i use Sys.Time, but in Cplc "pshm->Time" occurs a compile error. What is the best way to do that ? (Do i have to use a "struct timespec" in library or anything else like that ?) Link to comment Share on other sites More sharing options...
pennells Posted September 13, 2012 Share Posted September 13, 2012 I've done it that way (using something like... struct timespec startTime, now; clock_gettime(CLOCK_REALTIME, &startTime); // do stuff clock_gettime(CLOCK_REALTIME,&now); ) but I think you could also use changes Sys.PhaseCount changes or Sys.PhaseDeltaTime and multiply it by Sys.ClockSf -- I tried it but got close enough to the same results for my tests that it didn't matter and returned to the timespec method. In a Cplc (Rti or Bg) : I would like get the time (or TickCounts) in order to calculate the duration of my process. In PLCScript, i use Sys.Time, but in Cplc "pshm->Time" occurs a compile error. What is the best way to do that ? (Do i have to use a "struct timespec" in library or anything else like that ?) Link to comment Share on other sites More sharing options...
daves Posted September 14, 2012 Share Posted September 14, 2012 GetPmacRunTime() from the API seems to be the same as Sys.Time. I use GetCPUClock() from the API to time things which returns the current time in microseconds. These are some time related functions in the API if useful: /// Get Pmac Time of Day in seconds since Jan. 1, 1970 extern double GetPmacTimeOfDay(void); /// Get Pmac Run Time in seconds since Pwr On or $$$ extern double GetPmacRunTime(void); /// Get CPU Clock in micro-seconds extern double GetCPUClock(void); Link to comment Share on other sites More sharing options...
sbrun Posted September 14, 2012 Author Share Posted September 14, 2012 It works perfectly. Thanks to all. Link to comment Share on other sites More sharing options...
dorcsssc Posted March 1, 2013 Share Posted March 1, 2013 I've just proven that the .tv_sec field of a increments by *10* every second on a PPMAC. Here's the code: struct timespec itval; itval.tv_sec = 42; // Just to verify value is being loaded. while (1) { if (clock_gettime(CLOCK_REALTIME, &itval) < 0) fprintf(stderr, "clock_gettime() barfed, code %d.\n", errno); else fprintf(stderr, "itval.tv_sec = %ul.\n", itval.tv_sec); sleep(1); } Both the range of the number (only a few hundred thousand - no even close to the 1970 epoch) and interval (10) are wrong? What's going on here? Has Xenomai monkeyd around with clock_gettime()? Link to comment Share on other sites More sharing options...
Recommended Posts