在为USB转RS422转换器模块开发接口应用程序时,我遇到了停止显示的问题。
我需要检索UART错误计数器以进行成帧,溢出,奇偶校验和中断错误。但是对ioctl的调用总是返回-1,并且检索到的结构中的计数器值跳转到非常大的数字。
我用来检索计数器的代码如下:
struct serial_icounter_struct counters;
int ret = ioctl(portDescriptor, TIOCGICOUNT, &counters);
设置portDescriptor我使用类似的代码:
int portDescriptor = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
struct termios new_port_settings;
//clear the new struct
memset(&new_port_settings, 0, sizeof(new_port_settings));
//set port settings
new_port_settings.c_cflag = B57600 | CS8 | CLOCAL | CREAD;
new_port_settings.c_oflag = 0;
new_port_settings.c_lflag = 0;
new_port_settings.c_cc[VMIN] = 0;
new_port_settings.c_cc[VTIME] = 0;
int error = tcsetattr(portDescriptor, TCSANOW, &new_port_settings)
有时我们还需要启用流量控制或奇偶校验,例如
new_port_settings.c_cflag = new_port_settings.c_cflag | CRTSCTS;
我已尝试使用FTDI_SIO内核模块在Ubuntu 11.10 32位和SLES11 SP1 64位上运行代码。
是否有人知道有关使用TIOCGICOUNT的任何问题或我做错了什么?
提前感谢您的帮助! 爱德华