使用tcgetattr函数与tcsetattr函数的有关问题

使用tcgetattr函数与tcsetattr函数的问题
tcgetattr函数与tcsetattr函数在设置串口时的作用是搞什么的,就是在linux串口编程时用到的

int tty_end()
{
  tcsetattr(fd,TCSANOW,&oldtio); // restore old modem setings //
  //int tcsetattr (int FILEDES, int WHEN, const struct termios
  *TERMIOS-P)
  //This function sets the attributes of the terminal device with file
  // descriptor FILEDES. The new attributes are taken from the
  //structure that TERMIOS-P points to//
}

/************************************************************************/
int set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop)
{

 if ( tcgetattr( fd,&oldtio) != 0) {
  perror("SetupSerial 1");
  return -1;
 }
 bzero( &newtio, sizeof( newtio ) );
 newtio.c_cflag |= CLOCAL | CREAD;
 newtio.c_cflag &= ~CSIZE;


tcsetattr(fd,TCSANOW,&oldtio); // restore old modem setings //
不是写的很清楚么,保存上一次连接的设备设定值
函数是在设备结束的时候调用的


if ( tcgetattr( fd,&oldtio) != 0) {
看tcgetattr就是拿设备的设定值
set_opt中,如果上一次设备依旧没有注销,就报错


tcsetattr设置串口属性包括波特率设置,效验位和停止位设置
串口的设置主要是设置 struct termios 结构体的各成员值
tcgetattr获取串口属性。


tcgetattr是用来获取串口属性的,在这里主要是用来保存当前串口的设定值
tcsetattr是用来设置串口属性的,比如波特率,校验位等等

使用tcgetattr函数与tcsetattr函数的有关问题

相关文章:

你感兴趣的文章:

标签云: