What can cause CreateFile calls on a serial port to be extremely slow? What can cause CreateFile calls on a serial port to be extremely slow? windows windows

What can cause CreateFile calls on a serial port to be extremely slow?


OK, problem is understood, if not solved. I was playing with a different serial device and the problem began manifesting even more frequently.

The problem seems to be that when the VM is in control of some of the serial ports, the drivers become intermittently slow to open the available ports.

My test program opens then closes the port 1000 times, timing the open call. It does NOT set the serial port parameters in any way. Prior to running the test program, I was doing actual work with a device that uses the baud rate 460800.

When the VM is in possession of 4 of the ports, then opens on the remaining 4 ports can sometimes (20-30 times out of 1000 attempts) take 20-30 seconds to complete. When the VM is not running, the opens happen quickly all 1000 attempts. With the VM running, but no USB serial ports in it's possession, the opens happened quickly on all 1000 attempts.

Since the VM is a development tool, not part of our intended deployment scenario, I can live with this issue.

Interestingly, this effect seems to be dependent on what baud rate the port was last used at. Prior to my initial inquiries I'd been operating at 9600 baud and below and don't recall ever seeing the problem. When I first asked the question, I was working with a device that was at 115000 baud, and was having the problem intermittently. With the latest device at 460800 baud, I get the problem often enough to be able to hunt the problem down. No idea why, but there it is.


The serial control lines interacting with a device driver issue is a likely cause.

Do you have the control signals correctly connected?

If not, connect RTS to CTS and connect CD, DTR and DSR. On a DB25, this means connecting pins 4 and 5 and connecting pins 6, 8 and 20. On a DB9, connect pins 7 and 8 and connect pins 1, 4 and 6.

If this fixes the problem, you should look for driver settings to ignore the control signals on open.