Create Virtual com port

Bobby picture Bobby · Nov 20, 2014 · Viewed 10.2k times · Source

I have to create virtual com port,by which I can communicate with other com port on machine,It is a part of device driver development?or simply we can write in c++.

Anyone can help me on this Thanks in advance.

Answer

huysentruitw picture huysentruitw · Nov 20, 2014

You'll have to write a driver, so you'll need to install the WDK (previously called DDK). But you're lucky, because the Windows Driver Kit Samples Pack contains a Virtual Serial port sample.

It seems that you want a 'translater' to talk with a device, why not simply write a filter driver and implement some additional IOControls?

If you really want to access an other port from within your driver (which I already did once), you should look up following functions:

  • IoGetDeviceObjectPointer / ObDereferenceObject (for opening/closing the port)
  • IoBuildDeviceIoControlRequest / IoCallDriver (for sending IOCTL's to change port settings)
  • IoBuildSynchronousFsdRequest / IoCallDriver (for writing/reading data)

Structures/IOCTL's you'll need:

  • SERIAL_BAUD_RATE (for IOCTL_SERIAL_SET_BAUD_RATE/IOCTL_SERIAL_GET_BAUD_RATE)
  • IOCTL_SERIAL_SET_TIMEOUTS
  • SERIAL_HANDFLOW (for IOCTL_SERIAL_SET_HANDFLOW/IOCTL_SERIAL_GET_HANDFLOW)
  • SERIAL_LINE_CONTROL (for IOCTL_SERIAL_SET_LINE_CONTROL)
  • IOCTL_SERIAL_PURGE
  • IOCTL_SERIAL_SET_WAIT_MASK/IOCTL_SERIAL_GET_WAIT_MASK
  • IOCTL_SERIAL_SET_CHARS/IOCTL_SERIAL_GET_CHARS
  • IOCTL_SERIAL_WAIT_ON_MASK

A complete overview of control requests can be found here

Have a nice trip :)