Browse Source

added a small test prg for serial in

tTh 1 year ago
parent
commit
0514cc5d10
5 changed files with 51 additions and 1 deletions
  1. 1
    1
      .gitignore
  2. 9
    0
      serial/Makefile
  3. 18
    0
      serial/serial.c
  4. 2
    0
      serial/serial.h
  5. 21
    0
      serial/t.c

+ 1
- 1
.gitignore View File

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

+ 9
- 0
serial/Makefile View File

@@ -0,0 +1,9 @@
1
+
2
+
3
+
4
+serial.o:	serial.c serial.h Makefile
5
+	gcc -Wall -c $<
6
+
7
+t:	t.c serial.o Makefile
8
+	gcc -Wall  $< serial.o -o $@
9
+

+ 18
- 0
serial/serial.c View File

@@ -96,3 +96,21 @@ tcsetattr(uart0, TCSANOW, &options);
96 96
 
97 97
 return uart0;
98 98
 }
99
+
100
+/* -------------------------------------------------------------------- */
101
+
102
+int getbyte(int fd)
103
+{
104
+unsigned char   byte;
105
+int             foo;
106
+
107
+foo = read(fd, &byte, 1);
108
+if (1 != foo)
109
+        {
110
+        perror("read a byte");
111
+        return -1;
112
+        }
113
+return (int)byte;
114
+}
115
+
116
+/* -------------------------------------------------------------------- */

+ 2
- 0
serial/serial.h View File

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

+ 21
- 0
serial/t.c View File

@@ -0,0 +1,21 @@
1
+
2
+
3
+#include  <stdio.h>
4
+
5
+#include  "serial.h"
6
+
7
+int main (int argc, char *argv[])
8
+{
9
+int	serial_in;
10
+int	byte, foo;
11
+
12
+serial_in = prepare_UART("/dev/ttyS0", 9600);
13
+fprintf(stderr, "prepare uart -> %d\n", serial_in);
14
+
15
+for (foo=0; foo<20; foo++) {
16
+	byte = getbyte(serial_in);
17
+	printf("%6d    %02x\n", foo, byte);
18
+	}
19
+
20
+return 0;
21
+}

Loading…
Cancel
Save