Posted by on Jul 17, 2013 in Mobile Application Development, Windows 8 | 4 comments

The Serial Port is Dead, Long Live the Serial Port!

In my day job, I work for Aton International, Inc. We are currently porting the PuTTY terminal emulation desktop application to the “Aton Connect for SSH / Telnet” product for Windows 8 Store and Windows Phone 8.

As one of its modes, PuTTY supports direct communication over serial ports: COM1, COM2, etc. Serial ports were once important to connect to dial up line modems. Now with most people using broadband, the serial port modem has largely disappeared.

Serial ports are still quite important in some areas, such as communicating with GPS receivers and for controlling industrial equipment. So, I needed to find out how I could support serial ports for our application.

It turned out that it could not be done with Windows 8.0 Store. In the highly sandboxed design, and presumable in the triage needed to get to RTM, the serial port support got left out. Serial port support was available at release for Windows 8 desktop. The good news is that with Windows 8.1 Store, a form of serial port support has been added back in.

A “real” serial port generally means a DB-9 connector (see blue connectors in photo) supporting RS-232 standard electrical signals interfaced through a computer adapter utilizing an integrated circuit that supports the features of the 8250 or 16550 UART chip designs. This implementation was a part of the original IBM PC and was integrated into motherboards for many years. More recently, motherboards have evolved to drop serial ports, parallel ports, floppy disk and IDE/ATA hard drive interfaces. Instead support was added for newer interfaces such as USB 3.0, display port, and SATA hard drives.

For the newer motherboard designs, one can purchase a separate serial port adapter card that interfaces via a PCI or PCI Express slot on the motherboard. Another technique is to purchase a serial port to USB “dongle” or short cable with a DB-9 connector on one end and a USB connector on the other. Here is one example. You will find others in a variety of price ranges by searching online.

When the dongle is plugged into the motherboard, the computer OS, perhaps with a custom driver, will mimic the traditional “COM1, COM2, etc.” “real” serial port device in such a way that application programs will not be aware that the serial port device is connected via USB rather than a “real” serial port.

Like Bluetooth, the USB driver stack employs “profiles” or classes. The one of interest here is the USB CDC (communications device class) for serial port access. Windows 8.1 added support for the CDC, allowing a USB to DB9 dongle to be plugged in and become available in the device enumeration visible to Windows “Store” Apps.

You can access a fully implemented sample to assist you in coding for the new serial port capability at: http://code.msdn.microsoft.com/windowsapps/USB-CDC-Control-sample-5ba19caa

To use this sample, you will need to install Windows 8.1 and Visual Studio 2013. It would be nice to do this in a VM under the Windows Hyper-V included in Windows. But note that Hyper-V does not support USB ports natively. There are third party USB over Ethernet schemes available, but I expect that might introduce yet one more variable into your experience. It is probably better to install Windows 8.1 on actual hardware to run the sample. This should simplify your testing and debugging.

Have you tried this? How did it work for you?