diff options
Diffstat (limited to 'arduino-serial.c')
-rw-r--r-- | arduino-serial.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/arduino-serial.c b/arduino-serial.c index 3f5987b..bf57f2b 100644 --- a/arduino-serial.c +++ b/arduino-serial.c @@ -43,6 +43,9 @@ * Added --timeout option * Added -q/-quiet option * + * Update XX April 2019 + * Added --receive_u option + * Fixed output issues */ #include <stdio.h> // Standard input/output definitions @@ -67,6 +70,7 @@ void usage(void) " -S, --sendline=string Send string with newline to Arduino\n" " -i --stdinput Use standard input\n" " -r, --receive Receive string from Arduino & print it out\n" + " -R, --receive_u Same as --receive, but no timeout\n" " -n --num=num Send a number as a single byte\n" " -F --flush Flush serial port buffers for fresh reading\n" " -d --delay=millis Delay for specified milliseconds\n" @@ -121,11 +125,12 @@ int main(int argc, char *argv[]) {"eolchar", required_argument, 0, 'e'}, {"timeout", required_argument, 0, 't'}, {"quiet", no_argument, 0, 'q'}, - {NULL, 0, 0, 0} + {"receive_u", no_argument, 0, 'R'}, + {NULL, 0, 0, 0} }; while(1) { - opt = getopt_long (argc, argv, "hp:b:s:S:i:rFn:d:qe:t:", + opt = getopt_long (argc, argv, "hp:b:s:S:i:rRFn:d:qe:t:", loptions, &option_index); if (opt==-1) break; switch (opt) { @@ -188,17 +193,31 @@ int main(int argc, char *argv[]) if(rc==-1) error("error writing"); break; case 'r': + if( fd == -1 ) error("serial port not opened"); memset(buf,0,buf_max); // serialport_read_until(fd, buf, eolchar, buf_max, timeout); - if( !quiet ) printf("read string:"); - printf("%s\n", buf); - break; + printf("%s", buf); + fflush(stdout); + break; case 'F': if( fd == -1 ) error("serial port not opened"); if( !quiet ) printf("flushing receive buffer\n"); serialport_flush(fd); break; + //we just want to scan for input constantly with no timeout + case 'R': + while(1) + { + if( fd == -1 ) {error("serial port not opened"); break;} + memset(buf,0,buf_max); // + serialport_read_unlimited(fd, buf, eolchar, buf_max); + //'printf("%s\n", buf)' places *two* newlines after output and output cannot be redirected. + //remove DOS newline. NOTE; only one character output is supported like this + printf("%s", buf); + fflush(stdout); + } + break; } } |