pyserial doesn't recognize virtual serial port

Grant Edwards grante at
Fri Oct 12 17:34:37 CEST 2007

On 2007-10-12, naveen.sabapathy at <naveen.sabapathy at> wrote:
> Hi,
>   I am trying to use virtual serial ports to develop/test my serial
> communication program. Running in to trouble...
>   I am using com0com to create the virtual ports. The virtual ports
> seem to be working fine when I test it with Hyperterminal.

I'm not sure what you mean by "virtual ports".  I've used
pyserial with several different network attached devices that
provide drivers that make them appear as COMnn devices under
windows.  I never had any problems.

> I am using the example program that comes with pyserial, as below.
> ---------------
> import serial
> ser = serial.Serial('CNCA0') #open virtual serial port
> print ser.portstr            #check which port was realy used
> ser.write("Hello")           #write a string
> ser.close()                  #close port
> -----------------
> The following is the error message:
> --------------
> Traceback (most recent call last):
>   File "C:\Python25\Naveen Files\TestSerial", line 2, in <module>
>     ser = serial.Serial('CNCA0') #open first serial port
>   File "c:\Python25\Lib\site-packages\serial\", line 156,
> in __init__
>   File "c:\Python25\Lib\site-packages\serial\", line 55,
> in open
>     raise SerialException("could not open port: %s" % msg)
> SerialException: could not open port: (2, 'CreateFile', 'The system
> cannot find the file specified.')
> --------------

If you specify a filename that the OS doesn't recognize there's
nothing pyserial can do about it.

> When I try with 'COM3', which comes inbuilt in my laptop, COM3 is
> recognized. Few other posts on the web seem to indicate pyserial
> should work fine with virtual serial ports. What am I missing?

My guess is you're not spelling the device name correctly.
Device names under Windows are even more screwed up than the
rest of the OS.  By default there are a limited set of devices
with specially mapped "DOS compatible" names such as LPT1,
COM3, etc.  My guess is that the device you're attempting to
use doesn't have a name that's mapped to the DOS-compatible
namespace as CNCA0.

You could try using the name \\.\CNCA0

Or you could try to figure otu how to map the device into the
DOS namespace as CNCA0.

You could also try running some sort of system call trace on
HyperTerminal to find out what name it's using to open the
device when you tell it to use port CNCA0.

Or you could just give up and switch to Linux.  [That's what
I'd recommend, personally.]

Grant Edwards                   grante             Yow! YOU PICKED KARL
                                  at               MALDEN'S NOSE!!

More information about the Python-list mailing list