pyserial doesn't recognize virtual serial port

N

naveen.sabapathy

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 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\serialutil.py", line 156,
in __init__
self.open()
File "c:\Python25\Lib\site-packages\serial\serialwin32.py", 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.')
--------------

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? Please
help.

--Thanks
--NS
 
G

Grant Edwards

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\serialutil.py", line 156,
in __init__
self.open()
File "c:\Python25\Lib\site-packages\serial\serialwin32.py", 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.]
 
N

naveen.sabapathy

Hi Grant,
It worked... I had the same suspicion and changed the port names to
COM2 and COM4 and it worked.

--NS
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\serialutil.py", line 156,
in __init__
self.open()
File "c:\Python25\Lib\site-packages\serial\serialwin32.py", 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.]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,010
Latest member
MerrillEic

Latest Threads

Top