By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,563 Members | 1,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,563 IT Pros & Developers. It's quick & easy.

pyserial doesn't recognize virtual serial port

P: n/a
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

Oct 12 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 2007-10-12, na**************@gmail.com <na**************@gmail.comwrote:
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.]

--
Grant Edwards grante Yow! YOU PICKED KARL
at MALDEN'S NOSE!!
visi.com
Oct 12 '07 #2

P: n/a
Hi Grant,
It worked... I had the same suspicion and changed the port names to
COM2 and COM4 and it worked.

--NS
On Oct 12, 8:34 pm, Grant Edwards <gra...@visi.comwrote:
On 2007-10-12, naveen.sabapa...@gmail.com <naveen.sabapa...@gmail.comwrote:
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.]

--
Grant Edwards grante Yow! YOU PICKED KARL
at MALDEN'S NOSE!!
visi.com

Oct 13 '07 #3

P: n/a
Try reading the sourceforge.net help forum about com0com:
http://sourceforge.net/forum/forum.p...orum_id=440109
Maybe you can find the solution.
I think you should prefix the port name with "\\.\"
Something like "\\.\CNCA0"

Did you ever try to use the com2tcp utility?
I'm trying to use it, but there are so little information.
I posted a request on the forum, and still waiting for answer.
Salvatore

On 12 Ott, 06:50, naveen.sabapa...@gmail.com 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 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
Nov 21 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.