#define FALSE -1
#define TRUE 0
/*********************************************************************/
int OpenDev(char *Dev)
{
//Dev 就是设备,设备就是文件
int fd = open(Dev, O_RDWR ); //| O_NOCTTY | O_NDELAY
if (-1 == fd) {
perror("Can't Open Serial Port");
return -1;
}else return fd;
}
int main(int argc, char **argv) {
int fd; int nread;
char buff[512];
char *dev = "/dev/ttyS1"; //串口二
fd = OpenDev(dev);
set_speed(fd, 19200);
if (set_Parity(fd, 8, 1, 'N') == FALSE)
{
printf("Set Parity Error\n");
exit (0);
}
while (1) //循环读取数据
{
while ((nread = read(fd, buff, 512))>0)
{
printf("\nLen %d\n", nread);
buff[nread+1] = '\0';
printf("\n%s", buff);
}
}