Setting the System DateTime on the SBC in C

C, C++, and Visual C++
TheTurningGallery
Phidgetly
Posts: 19
Joined: Wed Mar 14, 2012 4:57 pm
Contact:

Setting the System DateTime on the SBC in C

Postby TheTurningGallery » Wed Apr 25, 2012 8:07 pm

Does anyone have an example on how to set the system datetime in c for the SBC?

erik
King of the Lab
Posts: 476
Joined: Fri Mar 06, 2009 12:42 pm
Location: Calgary, Canada
Contact:

Re: Setting the System DateTime on the SBC in C

Postby erik » Thu Apr 26, 2012 11:02 am

You can send commands to the processor as if you were in a terminal cmd line from C using

Code: Select all

system("<command>");


So if you want to change the time, it would be something like

Code: Select all

system("date +%T -s \"10:57:33\" ");


And something similar for changing the date.

TheTurningGallery
Phidgetly
Posts: 19
Joined: Wed Mar 14, 2012 4:57 pm
Contact:

Re: Setting the System DateTime on the SBC in C

Postby TheTurningGallery » Thu Apr 26, 2012 9:29 pm

Perfect.... but I do my base development in windows and then export to the SBC.

1) how can I tell the OS I am running on?

erik
King of the Lab
Posts: 476
Joined: Fri Mar 06, 2009 12:42 pm
Location: Calgary, Canada
Contact:

Re: Setting the System DateTime on the SBC in C

Postby erik » Mon Apr 30, 2012 8:24 am

Something like is shown here: http://www.dreamincode.net/code/snippet1771.htm

Depending on the compiler, the #define that you should be checking for can be different, such as __WIN32__ or _WIN32 or something else. If you're using Microsoft Visual C/C++, then _MSC_VER will be defined and you can check for that.

Edit: Here's another link that can help you figure out what macros are defined by your preprocessor in your Windows and LInux environment. http://stackoverflow.com/questions/2565979/macros-for-gcc-g-to-differentiate-linux-and-mac-osx


Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 1 guest