Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs present in Issues #9 and #10 #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions arduino-serial-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -132,11 +132,11 @@ 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[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;
Expand Down