epoll机制读取linux串口数据
https://blog.csdn.net/coding__madman/article/details/51657944
com.c
#include "com.h"
int openSerial(char *cSerialName)
{
int iFd;
struct termios opt;
iFd = open(cSerialName, O_RDWR | O_NOCTTY |O_NONBLOCK);
//iFd = open(cSerialName, O_RDWR | O_NOCTTY | O_NDELAY);//阻塞 |O_RSYNC
if(iFd < 0) {
perror(cSerialName);
return -1;
}
tcgetattr(iFd, &opt);
cfsetispeed(&opt, B9600);
cfsetospeed(&opt, B9600);
/*
* raw mode
*/
opt.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
opt.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
opt.c_oflag &= ~(OPOST);
opt.c_cflag &= ~(CSIZE | PARENB);
opt.c_cflag |= CS8;
/*
* 'DATA_LEN' byte