⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 read_seri.c

📁 Linux 下 C 库及常用 系统调用的使用事例
💻 C
字号:
/*读串口*/#include <stdio.h>#include <string.h>#include <sys/types.h>#include <errno.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <termios.h>#include <stdlib.h>int main(void) {	int fd;	int nread,nwrite,i;	char buff[8];	fd_set rd;/*打开串口*/	if((fd=open_port(fd,1))<0)    { 		perror("open_port error");		return;	}/*设置串口*/	if((i=set_opt(fd,115200,8,'N',1))<0)    { 		perror("set_opt error");		return;	}/*利用select函数来实现多个串口的读写*/	FD_ZERO(&rd);	FD_SET(fd,&rd);	while(FD_ISSET(fd,&rd))    {	  if(select(fd+1,&rd,NULL,NULL,NULL)<0)      {	      perror("select");      }	  else      {		  while((nread = read(fd, buff, 8))>0)		  {			  printf("nread=%d,%s\n",nread,buff);		  }	  }    }	close(fd);	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -