tios.c_cc[VMIN] = 1;

This commit is contained in:
tth 2018-12-29 09:45:22 +01:00
parent c7053d9c30
commit 654453f0db
2 changed files with 23 additions and 5 deletions

View File

@ -213,9 +213,9 @@ for(;;) {
}
#if DEBUG_LEVEL
fprintf(stderr, "%s -> '%s'\n", __func__, where);
#endif
return retval;
}
/* -------------------------------------------------------------------- */

View File

@ -2,10 +2,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h> //Used for UART
#include <fcntl.h> //Used for UART
#include <errno.h>
#include <termios.h> //Used for UART
#include "serial.h"
@ -26,7 +29,17 @@ if (uart < 0)
return uart;
}
/* ----------------------------------------------------- */
int configserial(int fd)
{
struct termios tios;
bzero(&tios, sizeof(tios));
tios.c_cflag = B9600 | CRTSCTS | CS8 | CLOCAL | CREAD;
tios.c_lflag = ICANON;
tios.c_cc[VMIN] = 1; /* read bloquant ??? */
tcsetattr(fd,TCSANOW,&tios);
return 0;
}
/* ----------------------------------------------------- */
int main (int argc, char *argv[])
{
int serial_in, foo;
@ -40,15 +53,20 @@ if (2 != argc) {
serial_in = openserial(argv[1]);
fprintf(stderr, "openserial -> %d\n", serial_in);
(void)configserial(serial_in);
for (;;) {
foo = read(serial_in, &byte, 1);
if (1 != foo) {
fprintf(stderr, "get byte : got %d, err is %d\n", foo, errno);
fprintf(stderr, "get byte : got %d, err is %d\n",
foo, errno);
}
else {
printf("%9ld $%02x ", time(NULL), byte);
if (isprint(byte)) putchar(byte);
if (isprint(byte)) putchar(byte);
puts("");
if ('\n'==byte) puts("");
}
}