Serial time read error[SOLVED]!
hello guys!i've got very big problem!so give hand me 1 more time...
i'm newbie forgive mistakes!
arduino source code:
i want take string time that! 00:00:00, because should connect values c# application.
something else:
when i'm sending pulse ( unix time) synchronize pc e.g t18384590 etc i'm taking response fine.
but don't take correct strings modify them in application.
the 1st string e.g 12:
and other 1 00:00\n\r00:00:00\n\r00:00:00\n\r
please me if can!!!
thanks
i'm newbie forgive mistakes!
arduino source code:
code: [select]
#include <time.h>
#include <stdio.h>
#define time_msg_len 11 // time sync consists of header followed ten ascii digits
#define time_header 't' // header tag serial time sync message
void setup() {
serial.begin(9600);
//serial.println("waiting time sync message");
}
void loop(){
if(serial.available() )
{
processsyncmessage();
}
if(timestatus()!= timenotset)
{
// here if time has been set
digitalclockdisplay();
}
delay(1000);
}
void digitalclockdisplay(){
// digital clock display of time
/*serial.print(hour());
printdigits(minute());
printdigits(second());*/
serial.println(string(hour())+string(printdigits(minute()))+string(printdigits(second())));
/*serial.print(" ");
serial.print(day());
serial.print(" ");
serial.print(month());
serial.print(" ");
serial.print(year());*/
serial.println();
}
string printdigits(int digits){
string str = "";
string padding = "";
// utility function digital clock display: prints preceding colon , leading 0
//serial.print(':');
padding = ":";
if(digits < 10){
//serial.print('0');
//serial.print(digits);
str = ('0'+string(digits));
}
return (padding + str);
}
void processsyncmessage() {
// if time sync available serial port, update time , return true
// time message consists of header , ten ascii digits
while(serial.available() >= time_msg_len ){
char c = serial.read() ;
serial.print(c);
if( c == time_header ) {
time_t pctime = 0;
for(int i=0; < time_msg_len -1; i++){
c = serial.read();
if( c >= '0' && c <= '9'){
pctime = (10 * pctime) + (c - '0') ; // convert digits number
}
}
settime(pctime); // sync clock time received on serial port
}
}
}
i want take string time that! 00:00:00, because should connect values c# application.
something else:
when i'm sending pulse ( unix time) synchronize pc e.g t18384590 etc i'm taking response fine.
but don't take correct strings modify them in application.
the 1st string e.g 12:
and other 1 00:00\n\r00:00:00\n\r00:00:00\n\r
please me if can!!!
thanks
it not clear problem is. what, exactly, data sent arduino like?
what issues having arduino code?
what issues having arduino code?
Arduino Forum > Using Arduino > Interfacing w/ Software on the Computer > Serial time read error[SOLVED]!
arduino
Comments
Post a Comment