Jump to content
OMRON Forums

"Sys.Time" in Cplc


sbrun
 Share

Recommended Posts

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

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

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

  • 5 months later...

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

Guest
This topic is now closed to further replies.
 Share


×
×
  • Create New...