4

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.

1
  • 1
    you can create your own driver BUT that will require quite some work ... i recommend using a pre-written virtual serial port application / driver - but beware : many of these are basically packages full of fraud, most of them dont even handle IOCTL at all, rendering the port mostly useless / only useful for the most simple data transmissions.
    – specializt
    Nov 20, 2014 at 12:22

2 Answers 2

14

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 samples.

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

3
  • 2
    note that the virtual serial driver sample basically doesnt route much, its just a data-sink - since OP wants to let his driver communicate with an other port there is much to be done, many important IOCTL-codes are left out in the sample - and im guessing since he even needed to ask about this topic this solution will be quite overwhelming for him :-)
    – specializt
    Nov 20, 2014 at 12:19
  • Good point. Also, agree with your earlier comment re "only useful for the most simple data transmissions." OTOH, if you've got to worry about serial communications in this day and age, it might be enough - you could be talking to some seriously challenged devices.
    – frasnian
    Nov 20, 2014 at 12:35
  • Extended my answer a little bit with some pointers to start searching Nov 20, 2014 at 13:03
6

I am assuming you are asking this for a Windows environment because you tagged with winapi.

Yes, you will need to write a virtual driver for this. The good news is, the DDK (now called the WDK) is freely available from MS. If you don't have VS2013 (required for the 8.1 version of the WDK), you can get the Express Edition from the MS web site for free.

on edit: you might want to check this out - http://com0com.sourceforge.net/. From the description:

The Null-modem emulator is an open source kernel-mode virtual serial port driver for Windows, available freely under GPL license.

The Null-modem emulator allows you to create an unlimited number of virtual COM port pairs and use any pair to connect one COM port based application to another. Each COM port pair provides two COM ports. The output to one port is the input from other port and vice versa.

It sounds like it might be pretty much what you're looking for.

3
  • The Null-modem emulator is to connect 2 or more serial port based applications with each other, not to connect a virtual serial port with a real serial port. Nov 20, 2014 at 13:02
  • @Wouter Huysentruit: Ah, thanks. I thought it might be at least a good start for OP, but I was thinking virtual<-->virtual.
    – frasnian
    Nov 20, 2014 at 13:13
  • Still might be a good example of how driver communication works. Nov 20, 2014 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.