Retrieval of the error counters via TIOCGICOUNT returns always error (-1)

青春壹個敷衍的年華 提交于 2019-12-12 12:19:16

问题


I have come across a show stopping problem when developing an interface application for a USB to RS422 converter module.

I need to retrieve the UART error counters for framing, overrun, parity and break errors. But the call to ioctl always returns -1 and the counter values from the retrieved struct are jumping to very big numbers.

The code i am using to retrieve the counters is the following:

struct serial_icounter_struct counters;
int ret = ioctl(portDescriptor, TIOCGICOUNT, &counters);

To set the portDescriptor i am using a similar code to:

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)

Sometimes we also need to enable flow control or parity e.g.

new_port_settings.c_cflag = new_port_settings.c_cflag | CRTSCTS;

I have tried the code on a Ubuntu 11.10 32bit and on a SLES11 SP1 64bit, both with the FTDI_SIO kernel module.

Is anybody aware of any kind of issue regarding the usage of TIOCGICOUNT or am i doing something wrong?

Thank you in advance for your help! Eduard

来源:https://stackoverflow.com/questions/11791813/retrieval-of-the-error-counters-via-tiocgicount-returns-always-error-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!