/*
* serialRead.c:
* Example program to read bytes from the Serial line
*
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <wiringSerial.h>
int main ()
{
int fd ;
//看解释 //int serialOpen (char *device, int baud) ; //This opens and initialises the serial device and sets the baud rate. It sets the port into “raw” mode //(character at a time and no translations), and sets the read timeout to 10 seconds. The return value is the file //descriptor or -1 for any error, in which case errno will be set as appropriate // 没有接到设备就是-1 超时为10秒
if ((fd = serialOpen ("/dev/ttyAMA0", 115200)) < 0)
{
fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
return 1 ;
}
// Loop, getting and printing characters
for (;;)
{
// //int serialGetchar (int fd) ;
//Returns the next character available on the serial device. This call will block for up to 10 seconds if no data //is available (when it will return -1)
putchar (serialGetchar (fd)) ;
fflush (stdout) ;
}
}
|