From c2babde14028ad53dfdabd043d4dd6bbb6dc6ccf Mon Sep 17 00:00:00 2001 From: tamtam22 Date: Sun, 27 Mar 2016 01:49:23 +0800 Subject: [PATCH 1/2] Update arduino-serial-lib.c Fixes \n character substituted with \r character #9 & Bug fix for char and overflow #10 --- arduino-serial-lib.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arduino-serial-lib.c b/arduino-serial-lib.c index 39461ce..7f3bc41 100644 --- a/arduino-serial-lib.c +++ b/arduino-serial-lib.c @@ -71,7 +71,7 @@ int serialport_init(const char* serialport, int baud) //toptions.c_cflag &= ~HUPCL; // disable hang-up-on-close to avoid reset toptions.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines - toptions.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl + toptions.c_iflag &= ~(IXON | IXOFF | IXANY | INLCR | ICRNL); // turn off s/w flow ctrl toptions.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // make raw toptions.c_oflag &= ~OPOST; // make raw @@ -120,10 +120,10 @@ int serialport_write(int fd, const char* str) // int serialport_read_until(int fd, char* buf, char until, int buf_max, int timeout) { - char b[1]; // read expects an array, so we give it a 1-byte array + char b; int i=0; do { - int n = read(fd, b, 1); // read a char at a time + int n = read(fd, &b, 1); // read a char at a time if( n==-1) return -1; // couldn't read if( n==0 ) { usleep( 1 * 1000 ); // wait 1 msec try again @@ -134,9 +134,9 @@ int serialport_read_until(int fd, char* buf, char until, int buf_max, int timeou #ifdef SERIALPORTDEBUG printf("serialport_read_until: i=%d, n=%d b='%c'\n",i,n,b[0]); // debug #endif - buf[i] = b[0]; + buf[i] = b; i++; - } while( b[0] != until && i < buf_max && timeout>0 ); + } while( b != until && i+1 < buf_max && timeout>0 ); buf[i] = 0; // null terminate the string return 0; From e24820816da43e154911dbf01fb2757737b4ff71 Mon Sep 17 00:00:00 2001 From: tamtam22 Date: Sun, 27 Mar 2016 01:50:37 +0800 Subject: [PATCH 2/2] Update arduino-serial-lib.c Fixed debug text --- arduino-serial-lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino-serial-lib.c b/arduino-serial-lib.c index 7f3bc41..189b287 100644 --- a/arduino-serial-lib.c +++ b/arduino-serial-lib.c @@ -132,7 +132,7 @@ int serialport_read_until(int fd, char* buf, char until, int buf_max, int timeou continue; } #ifdef SERIALPORTDEBUG - printf("serialport_read_until: i=%d, n=%d b='%c'\n",i,n,b[0]); // debug + printf("serialport_read_until: i=%d, n=%d b='%c'\n",i,n,b); // debug #endif buf[i] = b; i++;