A common question is "how do I write a device driver for my device which is connected over the serial port?"  The answer depends on if your device conforms to the serial device numeration protocol (officially titled "Plug and Play External COM Device Specification"), found here on WHDC.  One interesting "quirk" about the Windows implementation of this protocol is that detection is performed automatically at boot, but then becomes manual (to manually search for devices goto device manager choose Action -> Scan for hardware changes)

But what is the serial enumeration protocol and where did it come from?  It is certainly not black magic (nor very complicated).  You can see it's implementation in the WDK serenum sample (<WDKROOT>src\kernel\serenum).  As far as I know, the specification has its origins in how the original Microsoft serial mouse was detected and grew from there.  Of course, the way Microsoft serial mice are detected could have been based on a previously existing detection scheme, but my knowledge about it does not go back that far ;). 

The enumeration protocol is simply (skipping over device class specific checks)

  • Open the serial port
  • Set DTR, Clear RTS, wait 200 milliseconds
  • Check DSR.  If DSR is not set, do not quite since it could be a mouse
  • Set the baud rate to 1200, stop to 1 bit, parity to no parity, word length to 7 bit
  • Try two times
    • Clear DTR & RTS, wait 200 ms, set DTR
    • If the first time (for modems), wait 200 ms
    • Set RTS
    • Start reading bytes from the port one at a time.  Wait for 240 ms before timing out on a read.
  • Restore the serial port to its previous settings and the close it