串口无响应

时间:2013-12-19 03:20:24

标签: c serial-port

我编写了一个与串口通信的程序,使用termios,该程序将以非阻塞模式读取串口,并在读取数据后写入对串口的响应。如果没有从串口读取数据,程序将执行其他操作,在下一个循环中,程序再次读取串口。

现在问题是,在有时消失之后,可能是几分钟,或者几个小时,串口不再响应我的程序了。即使我执行echo 'HB\n' > /dev/ttyUSB0(然后串口应该响应'HACK'),它也不再响应..

我甚至不知道串口何时“死”,我没有任何线索......它'死'不合时宜。

这是我的配置:

/// set local mode options 
//tminfo.c_lflag |= ICANON;                                                                       
tminfo.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);                                             

/// set control mode options                                                                   
tminfo.c_cflag |= (CLOCAL | CREAD);                                                               
tminfo.c_cflag |= HUPCL; 

// set hardware flow control 
tminfo.c_cflag &= ~CRTSCTS;       

// set how many bits in a character                                                               
tminfo.c_cflag &= ~CSIZE;
tminfo.c_cflag |= CS8;      

// set parity mode (default to odd validation), this option (PARENB) will both enable input and output parity checking
tminfo.c_cflag &= ~PARENB; // we don't need prity checking now                                                                                                                                 

/// set input mode options  
// set input parity checking
tminfo.c_iflag &= ~INPCK; 
tminfo.c_cflag &= ~CSTOPB;                                                                                                                                                                

/// set output mode options                                                                                                                      
tminfo.c_oflag &= ~OPOST;                                                                


tminfo.c_cc[VMIN] = 1; 
tminfo.c_cc[VTIME] = 1;                                                                  

/// set line speed, defaults to 38400bps, both for input and output                           
// this call will set both input and output speed                                                 
cfsetspeed(&tminfo, B38400);

在这种情况下很难调试串口。我真的无法弄清楚是什么导致串口'死'在地球上。我差点儿疯了......

可能的原因是什么?任何帮助将不胜感激!

更新

我已经在串口的另一端写了一些代码,当它收到'HB'时,会响应'HACK'

0 个答案:

没有答案