📄 set_opt.c
字号:
#include "set_opt.h"int Speed_attr[]={B460800, B115200,B9600,B4800,B2400};int Speed_name[]={460800,115200,9600,4800,2400};int set_opt(int fd,int nSpeed,int nBits,char nEvent,int nStop) { struct termios newtio,oldtio; int i; if( tcgetattr(fd,&oldtio)!=0) { perror("Serial oldtio error"); return -1; } bzero(&newtio,sizeof(struct termios)); newtio.c_cflag |=CLOCAL |CREAD; newtio.c_cflag &=~CSIZE; switch(nBits) { case 7: newtio.c_cflag |=CS7; break; case 8: newtio.c_cflag |=CS8; break; } switch(nEvent) { case 'o': case 'O': newtio.c_cflag|=PARENB; newtio.c_cflag|=PARODD; newtio.c_iflag|=(INPCK|ISTRIP); break; case 'e': case 'E': newtio.c_cflag|=PARENB; newtio.c_cflag&=~PARODD; newtio.c_iflag|=(INPCK|ISTRIP); break; case 'n': case 'N': newtio.c_cflag&=~PARENB; break; } for( i=0 ; i<sizeof(Speed_name)/sizeof(int);i++) { if(nSpeed==Speed_name[i]) { cfsetispeed(&newtio,Speed_attr[i]); cfsetospeed(&newtio,Speed_attr[i]); } } if(nStop==1) newtio.c_cflag&=~CSTOPB; else if(nStop==2) newtio.c_cflag|=CSTOPB; newtio.c_cc[VTIME]=10; newtio.c_cc[VMIN]=0; tcflush(fd,TCIFLUSH); if((tcsetattr(fd,TCSANOW,&newtio))!=0) { perror("tcsetattr error"); return -1 ; } printf("set com OK!!\n"); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -