Beginner Pyserial Question

J

JAMoore84

Hi Guys,

I have a project where I'd like to save GPS data that is streamed to a
Sony Vaio over bluetooth. I can monitor the data stream over Hyper
Terminal, but I'd like to use python to capture it as well. I've
installed Python 2.5, pyserial 2.2 and the appropriate pywin program
(pywin32-210.win32-py2.5.exe).

My problem comes when I try to open a serial port. After importing
"serial", I issue the following statement:

Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
GPS = serial.Serial(0)
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.')

I'm not sure where the source of the problem is. I was wondering if
someone could recognize what might be be. the Vaio is running XP
SP2. Thanks!
 
G

Grant Edwards

Hi Guys,

I have a project where I'd like to save GPS data that is streamed to a
Sony Vaio over bluetooth. I can monitor the data stream over Hyper
Terminal, but I'd like to use python to capture it as well. I've
installed Python 2.5, pyserial 2.2 and the appropriate pywin program
(pywin32-210.win32-py2.5.exe).

My problem comes when I try to open a serial port. After importing
"serial", I issue the following statement:


Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
GPS = serial.Serial(0)
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.')

I'm not sure where the source of the problem is. I was
wondering if someone could recognize what might be be.

It's Windows... it's not expected to work. ;)

My guess is that for whatever reason the 'first' serial port
(which is what you're asking for by specifying a 0 when
instantiating the Serial class) doesn't actually exist. Serial
device names under Windows are broken. Just because you have
only one serial port, it doesn't mean that serial port is the
first serial port.

Try using the actual name of the com port (e.g. 'COM3' or
'COM5') instead of 0.

Oh, if you end up having to use a com port higher than COM9,
that's broken in Windows as well, and you've got to sprinkle a
bunch of backslashes into the device name (I don't remember the
exact syntax).
 
J

JAMoore84

My guess is that for whatever reason the 'first' serial port
(which is what you're asking for by specifying a 0 when
instantiating the Serial class) doesn't actually exist. Serial
device names under Windows are broken.

I realize this. I tried connecting to different port "numbers", but I
have not tried the serial.Serial(COM1). I wasn't sure if that worked,
but I know a quick way to find out.

Try using the actual name of the com port (e.g. 'COM3' or
'COM5') instead of 0.

The com port used in Hyper Terminal is COM40. I have tried connecting
to 39/40/41 to no avail.
Oh, if you end up having to use a com port higher than COM9,
that's broken in Windows as well, and you've got to sprinkle a
bunch of backslashes into the device name (I don't remember the
exact syntax).

That might become an issue when I try to read COM40 for the GPS
bluetooth transmission. This issue does not relate to why I cannot
open smaller com ports, though.
 
J

JAMoore84

I've solved the problem- Thanks for steering me in the right
direction.

The problem is that your traditional "COM1" does not exist on this
computer (Thanks Grant). A trip to the Device manager listed all the
COM ports on the computer. After successfully connecting to COM7 (port
= serial.Serial(6)), I realized the reason I couldn't connect to COM40
was because it was tied up with hyper terminal. after closing
everything, I was able to issue a readline and collect data. Thanks
for the help!

jimmy
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top