int set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop)
来源:互联网 发布:手机淘宝链接复制在哪 编辑:程序博客网 时间:2024/06/08 18:59
int set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop)
{
struct termios newtio,oldtio;
if ( tcgetattr( fd,&oldtio) != 0)
{
perror("SetupSerial 1");
return -1;
}
bzero( &newtio, sizeof( newtio ) );
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': //奇校验
newtio.c_cflag |= PARENB;
newtio.c_cflag |= PARODD;
newtio.c_iflag |= (INPCK | ISTRIP);
break;
case 'E': //偶校验
newtio.c_iflag |= (INPCK | ISTRIP);
newtio.c_cflag |= PARENB;
newtio.c_cflag &= ~PARODD;
break;
case 'N': //无校验
newtio.c_cflag &= ~PARENB;
break;
}
switch( nSpeed )
{
case 2400:
cfsetispeed(&newtio, B2400);
cfsetospeed(&newtio, B2400);
break;
case 4800:
cfsetispeed(&newtio, B4800);
cfsetospeed(&newtio, B4800);
break;
case 9600:
cfsetispeed(&newtio, B9600);
cfsetospeed(&newtio, B9600);
break;
case 115200:
cfsetispeed(&newtio, B115200);
cfsetospeed(&newtio, B115200);
break;
default:
cfsetispeed(&newtio, B9600);
cfsetospeed(&newtio, B9600);
break;
}
if( nStop == 1 )
{
newtio.c_cflag &= ~CSTOPB;
}
else if ( nStop == 2 )
{
newtio.c_cflag |= CSTOPB;
}
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 0;
tcflush(fd,TCIFLUSH);
if((tcsetattr(fd,TCSANOW,&newtio))!=0)
{
qDebug()<<"com set error"<<endl;
return -1;
}
qDebug()<<"set done!"<<endl;
return 0;
}
{
struct termios newtio,oldtio;
if ( tcgetattr( fd,&oldtio) != 0)
{
perror("SetupSerial 1");
return -1;
}
bzero( &newtio, sizeof( newtio ) );
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': //奇校验
newtio.c_cflag |= PARENB;
newtio.c_cflag |= PARODD;
newtio.c_iflag |= (INPCK | ISTRIP);
break;
case 'E': //偶校验
newtio.c_iflag |= (INPCK | ISTRIP);
newtio.c_cflag |= PARENB;
newtio.c_cflag &= ~PARODD;
break;
case 'N': //无校验
newtio.c_cflag &= ~PARENB;
break;
}
switch( nSpeed )
{
case 2400:
cfsetispeed(&newtio, B2400);
cfsetospeed(&newtio, B2400);
break;
case 4800:
cfsetispeed(&newtio, B4800);
cfsetospeed(&newtio, B4800);
break;
case 9600:
cfsetispeed(&newtio, B9600);
cfsetospeed(&newtio, B9600);
break;
case 115200:
cfsetispeed(&newtio, B115200);
cfsetospeed(&newtio, B115200);
break;
default:
cfsetispeed(&newtio, B9600);
cfsetospeed(&newtio, B9600);
break;
}
if( nStop == 1 )
{
newtio.c_cflag &= ~CSTOPB;
}
else if ( nStop == 2 )
{
newtio.c_cflag |= CSTOPB;
}
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 0;
tcflush(fd,TCIFLUSH);
if((tcsetattr(fd,TCSANOW,&newtio))!=0)
{
qDebug()<<"com set error"<<endl;
return -1;
}
qDebug()<<"set done!"<<endl;
return 0;
}
阅读全文
0 0
- int set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop)
- int
- int?
- int ?
- int
- Int
- int?
- char int
- int*&、int&*
- int*&、int&*
- Int (*(*F)(int,int))(int)
- int (*func(int)) (int *,int)
- int; int*; int&区别
- SYSCALL_DEFINE2(listen, int, fd, int, backlog)
- unsigned int get_svrport(char *, char *, unsigned int);
- int (*a)(int) ; int (*a[10])(int); int *(*a)(int) ;
- int substr( char dst[], char src[], int start, int len )
- int const * 、const int *、int *const、const char **与char **
- 限制oracle字段长度
- Unity控制物体透明度的探索(包含递归遍历的方法)
- Eclipse 调试出现source not found问题
- jQuery使用插件dotdotdot.js实现段落溢出显示省略号
- 奥威Power-BI 快消行业BI解决方案——分大区分品种销售分析
- int set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop)
- 【ML--05】第五课 如何做特征工程和特征选择
- jQuery: $.extend()和$.fn.extend()的区别
- Nutch教程——准备篇 by 逼格DATA
- 谷歌浏览器Timeline用法详解 [复制链接]
- html-meta标签常用方法
- python中匿名函数
- matlab的一些语法知识
- 支付宝前端团队详解基于Node.js Web框架Chair