问题
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