Get time in PhidgetSBC

C, C++, and Visual C++
mkunkel

Get time in PhidgetSBC

Postby mkunkel » Tue Nov 03, 2009 12:12 pm

Hi all,

We develop in C on the PhidgetSBC.
What is the best method to get the current time or the time since the program started (as accurate as possible)?

Martin

User avatar
Patrick
Lead Developer
Posts: 3105
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Get time in PhidgetSBC

Postby Patrick » Tue Nov 03, 2009 1:55 pm

This is the normal way to get time in Linux:

Code: Select all

#include <sys/time.h>
...
struct timeval now;
gettimeofday(&now, NULL);


You get microsecond accuracy.

-Patrick

jaromrax
Phidgetly
Posts: 23
Joined: Wed May 21, 2008 11:10 am

Re: Get time in PhidgetSBC

Postby jaromrax » Mon Dec 21, 2009 5:12 pm

Dear Patrick,
I just made first trials with sbc. I am used to g++ and I see I have some problems with the beginings.

patrick wrote:This is the normal way to get time in Linux:

Code: Select all

#include <sys/time.h>
...
struct timeval now;
gettimeofday(&now, NULL);


You get microsecond accuracy.

-Patrick


I just did in sbc: gcc -lphidget21 -ldl -lpthread -lm helo.c
to compile

Code: Select all

#include <sys/time.h>
int main(){
 printf("Hello world %s\n", "");
 struct timeval now;
 gettimeofday(&now, NULL);
 }

and the reply was
helo.c:7: error: 'NULL' undeclared (first use in this function)
helo.c:7: error: (Each undeclared identifier is reported only once
helo.c:7: error: for each function it appears in.)

I think I mix g++ and gcc and may be your example was intended for xcompilation with g++. Dont you have some basic example?

Thank you
Jaromir

User avatar
Patrick
Lead Developer
Posts: 3105
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Get time in PhidgetSBC

Postby Patrick » Mon Dec 21, 2009 5:58 pm

You'll want to #include <stdio.h>

-Patrick


Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 2 guests