"Virtual" Serial Ports in win32

Working with a serial (rs232) port should be an easy thing. Generally you open a serial port as though it were a file, set a few parameters, and you are on your way. This is true on Linux and it’s true on Win32 as well. There’s one gotcha that you need to watch out for. When you open the serial port with CreateFile you must prefix the serial port name with “\.”. The gotcha is that if you open com1 through com4 without that prefix everything will work fine. If you try to open a higher numbered port then you’ll get a “file not found” sort of error. I think the English error text on Windows is “The system could not find the file specified.” You should open every port with the prefix as it is the correct operation. I suspect that com1-com4 works only due to backwards compatibility.

I figured this out thanks to this post.

Advertisements
This entry was posted in Code, Geek. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s