added a small test prg for serial in

This commit is contained in:
tTh 2018-12-12 16:06:18 +01:00
parent be3792f0bb
commit 0514cc5d10
5 changed files with 51 additions and 1 deletions

2
.gitignore vendored
View File

@ -1,7 +1,7 @@
a.out a.out
*.o *.o
fake-values fake-values
essai essai serail/t
doc/*.toc doc/*.log doc/*.aux doc/*.pdf doc/*.toc doc/*.log doc/*.aux doc/*.pdf

9
serial/Makefile Normal file
View File

@ -0,0 +1,9 @@
serial.o: serial.c serial.h Makefile
gcc -Wall -c $<
t: t.c serial.o Makefile
gcc -Wall $< serial.o -o $@

View File

@ -96,3 +96,21 @@ tcsetattr(uart0, TCSANOW, &options);
return uart0; return uart0;
} }
/* -------------------------------------------------------------------- */
int getbyte(int fd)
{
unsigned char byte;
int foo;
foo = read(fd, &byte, 1);
if (1 != foo)
{
perror("read a byte");
return -1;
}
return (int)byte;
}
/* -------------------------------------------------------------------- */

View File

@ -4,3 +4,5 @@
int prepare_UART(char *port, int bauds); int prepare_UART(char *port, int bauds);
int getbyte(int fd);

21
serial/t.c Normal file
View File

@ -0,0 +1,21 @@
#include <stdio.h>
#include "serial.h"
int main (int argc, char *argv[])
{
int serial_in;
int byte, foo;
serial_in = prepare_UART("/dev/ttyS0", 9600);
fprintf(stderr, "prepare uart -> %d\n", serial_in);
for (foo=0; foo<20; foo++) {
byte = getbyte(serial_in);
printf("%6d %02x\n", foo, byte);
}
return 0;
}