[Tutor] Pyserial and invalid handle

John Smith jocjo.s at verizon.net
Mon Nov 29 22:44:22 CET 2010


On 11/28/2010 8:06 PM, Walter Prins wrote:
> John,
(snip stuff)
> Ugh, you're probably not going to like this.  I've done some googling
> and it appears this may be a 64-bit issue with the "ctypes" module...
> apparently "64-bit ctypes can only import 64-bit libraries".  See here:
> http://ur.ly/vSMQ
>
> Then again, it also seems to be an open issue on the PySerial bug
> tracker: http://ur.ly/vZNL
>
> Note, the above ticket suggests that PySerial 2.4 works ok (impliedly
> even on 64-bit XP, so I imagine also on Windows 7.)  You should be able
> to try this out by downloading the 2.4 version instead and installing it
> in the same way you did the 2.5 version.  In any case, it might be an
> idea to post a report/add a comment to that bug report as well to maybe
> help get this issue resolved.
>
> Cheers,
>
> Walter


Hi, Walter -

Thanks for all the research. This was my second attempt at installing 
the 2.4 version. I did it thus:

E:\Python27\pyserial-2.4>..\python setup.py install
standart distutils
running install
running build
running build_py
creating build
creating build\lib
creating build\lib\serial
copying serial\serialcli.py -> build\lib\serial
copying serial\serialjava.py -> build\lib\serial
copying serial\serialposix.py -> build\lib\serial
copying serial\serialutil.py -> build\lib\serial
copying serial\serialwin32.py -> build\lib\serial
copying serial\sermsdos.py -> build\lib\serial
copying serial\__init__.py -> build\lib\serial
running install_lib
running install_egg_info
Removing E:\Python27\Lib\site-packages\pyserial-2.4-py2.7.egg-info
Writing E:\Python27\Lib\site-packages\pyserial-2.4-py2.7.egg-info

E:\Python27\pyserial-2.4>


But, when I tried it in Python, I got the same as before:


 >>> import serial
 >>> ser = serial.Serial(0, timeout = 1)
 >>> ser
Serial<id=0x225c240, open=True>(port='COM1', baudrate=9600, bytesize=8, 
parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, 
dsrdtr=False)
 >>> ser.read()

Traceback (most recent call last):
   File "<pyshell#3>", line 1, in <module>
     ser.read()
   File "E:\Python27\lib\site-packages\serial\serialwin32.py", line 236, 
in read
     raise SerialException("ReadFile failed (%s)" % ctypes.WinError())
SerialException: ReadFile failed ([Error 6] The handle is invalid.)
 >>>


Cheers,
John


More information about the Tutor mailing list