Gordon Henderson | 25e4ec5 | 2012-12-06 21:49:41 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * serialRead.c: |
| 4 | * Example program to read bytes from the Serial line |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <string.h> |
| 10 | #include <errno.h> |
| 11 | |
| 12 | #include <wiringSerial.h> |
| 13 | |
| 14 | int main () |
| 15 | { |
| 16 | int fd ; |
| 17 | |
| 18 | if ((fd = serialOpen ("/dev/ttyAMA0", 115200)) < 0) |
| 19 | { |
| 20 | fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ; |
| 21 | return 1 ; |
| 22 | } |
| 23 | |
| 24 | // Loop, getting and printing characters |
| 25 | |
| 26 | for (;;) |
| 27 | { |
| 28 | putchar (serialGetchar (fd)) ; |
| 29 | fflush (stdout) ; |
| 30 | } |
| 31 | } |