void serial_init(int fd)options.c_cflag |= ( CLOCAL | CREAD ); options.c_cflag &= ~CSIZE;
{
struct termios options;
tcgetattr(fd, &options);
options.c_cflag &= ~CRTSCTS;要點2:讀取數據的時候要注意,因為節點發送數據的時候,控制中心的ZigBee已經收到數據,而我們還未 做好準備,當ZigBee往串口寫數據寫到一半的時候,我們才做好準備收,這時候只能收到后半部分的數據,
options.c_cflag |= CS8; // 8位數據
options.c_cflag &= ~CSTOPB; //停止位
options.c_iflag |= IGNPAR; // 忽略校驗錯誤
options.c_oflag = 0; // 無輸出模式
options.c_lflag = 0; //本地模式禁用
options.c_cc[VTIME] = 10; // 表示 read() 超時值 50 表示 5秒后仍沒有數據則返回
options.c_cc[VMIN] = 1; // 表示讀到多少個字節就返回 5 表示讀完5個字節就返回
cfsetispeed(&options, B115200); // 設置波特率
cfsetospeed(&options, B115200);
tcsetattr(fd,TCSANOW,&options);
}
| 歡迎光臨 (http://www.raoushi.com/bbs/) | Powered by Discuz! X3.1 |