June 13, 2005


Windows Serial Driver - score!

I spent the weekend hacking my way through the windows device driver jungle, and finally succeeded to get a basic serial port driver working (wOOt!). I'm amazed at how hard it has been to find a very simple serial port driver in C or C++ for windows. It must be an incredibly common need, but all of the search results I've found are either very out of date, don't work, or cost lots of money. So I finally started from scratch (okay, I started from a Microsoft Knowledge Base article from 1995).

This article builds an application called MTTTY that opens a teletype window and transfers files. It took me most of the day to get that code to compile because it was so out of date and used lots of deprecated API calls.

I had started with another sample app, VCTERM, but that uses an .OCX, or ActiveX control, which has the GUI part combined with the serial part. All I wanted was to actually send and receive data. So I patched up, then tore apart the MTTTY code.

What I ended up with is this: a Windows console application that builds in VC++.NET, opens, writes to and reads from, and closes any serial port, at any baud rate. It's in Visual Studio .NET, written in mostly C at the moment, but I will soon wrap it in a C++ class. I think I will use the PySerial object model as a guideline, because I like the way they did that. I will also add properties like parity, data bits, flow control, etc. to make it more general purpose.

I'm going to use this to build a Gamoto serial driver .dll, to make it really easy for any windows program to talk to the Gamoto.

Posted by randy at June 13, 2005 05:27 PM