Delay in reading from serial port on Windows
I run a tool on both Linux and Windows to interact with a USB device over a serial port. The tool is written in C/C++ (cygwin on Windows).
On Linux this runs smoothly, but on Windows I get a delay.
I connect like this (leaving out some error checking):
device = open("/dev/ttyS0", O_RDWR | O_NOCTTY);
tcflush(device, TCIOFLUSH); // flush before configuring
options.c_cflag = B230400|CS8|CREAD|CLOCAL;
options.c_iflag = 0;
options.c_oflag = 0;
options.c_lflag = 0;
// avoid canonical mode
options.c_cc[VMIN] = 255; // block for up till x characters (0-255)
options.c_cc[VTIME] = 1; // x tenths of seconds read timeout
tcsetattr(device, TCSANOW, &options);
The device sends packets of over 100 bytes at 25Hz, but in Windows (not on Linux) data comes through with a delay of about 1 sec. The delays does not change over time.
I already tried:
- read through Serial Programming Wikibook
- open with O_NDELAY
- set termios VMIN/VTIME to 0 (in different combinations)
- the tool is multi-threaded, so I disabled all locking to avoid any waiting
Any suggestions would be highly appreciated.
serial-port cygwin usbserial