FAQ
I am using Python 2.5 on Windows XP. I have installed Pyserial and
win32all extensions.

When I try to run the example program scan.py (included below), or any
other program using pyserial, as soon as it hits the statement:

s = serial.Serial(i)

I get the error:

Traceback (most recent call last):
File "C:\Python25\Doc\PySerial Examples\scan.py", line 26, in <module>
for n,s in scan():
File "C:\Python25\Doc\PySerial Examples\scan.py", line 17, in scan
s = serial.Serial(i)
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 57,
in open
win32file.SetupComm(self.hComPort, 4096, 4096)
error: (1, 'SetupComm', 'Incorrect function.')

What do I need to do to fix this? Thanks for the help!

-- Ron


The example program scan.py (from the pyserial examples folder):
-----------------------------------------------
#!/usr/bin/env python
"""Scan for serial ports.
Part of pySerial (http://pyserial.sf.net) (C)2002-2003 <cliechti at gmx.net>

The scan function of this module tries to open each port number
from 0 to 255 and it builds a list of those ports where this was
successful.
"""

import serial

def scan():
"""scan for available ports. return a list of tuples (num, name)"""
available = []
for i in range(256):
try:
s = serial.Serial(i)
available.append( (i, s.portstr))
s.close() #explicit close 'cause of delayed GC in java
except serial.SerialException:
pass
return available

if __name__=='__main__':
print "Found ports:"
for n,s in scan():
print "(%d) %s" % (n,s)

Search Discussions

  • Ron Jackson at Feb 8, 2007 at 9:04 pm

    Dennis Lee Bieber wrote:
    On Wed, 07 Feb 2007 11:14:39 -0800, Ron Jackson
    <Ron at FascinatingElectronics.com> declaimed the following in
    comp.lang.python:

    I am using Python 2.5 on Windows XP. I have installed Pyserial and
    win32all extensions.
    2.4 on XP Pro SP2...

    When I try to run the example program scan.py (included below), or any
    other program using pyserial, as soon as it hits the statement:

    s = serial.Serial(i)
    import serial
    for i in range(256):
    ... try:
    ... print i,
    ... s = serial.Serial(i)
    ... print s.portstr
    ... s.close()
    ... except serial.SerialException:
    ... print
    ...
    0 COM1
    1
    2 COM3
    3
    4
    5
    6
    7
    8
    9
    10
    11
    and on and on...

    What do I need to do to fix this? Thanks for the help!

    Does the serial port module require a compile for use with 2.5?
    Well, with only one download since Python 2.2, guess not...

    Something glitched in win32? Sorry, I don't know... However, since
    those are Python source files, you could always plug in some debugging
    lines around that win32 call to see what actually is there. Do you have
    any unnatural serial ports on the machine? (Like a USB<>serial
    converter?)
    Trying your program, I get the same error 'Incorrect function.':

    Traceback (most recent call last):
    File "<pyshell#9>", line 4, in <module>
    s = serial.Serial(i)
    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 57, in open
    win32file.SetupComm(self.hComPort, 4096, 4096)
    error: (1, 'SetupComm', 'Incorrect function.')


    I tried PySerial on a laptop, also running XP Home SP2, and both the example
    program and the program you suggested work fine on the laptop.

    The desktop computer that is giving me the error doesn't have any unnatural
    serial ports on it currently. The laptop worked fine, either with a USB device
    emulating COMM6 present or with the USB device disconnected.

    I checked and both machines are running the same version of win32file, which is
    site-packages\win32\win32file.pyd, 88 KB dated 9/22/2006.

    So my question is:

    Why would the statement win32file.SetupComm(self.hComPort, 4096, 4096)

    work just fine on one machine and not the other?

    win32file.pyd can't be opened like a .py file, and I don't know what the rather
    cryptic error 'Incorrect function.' is trying to tell me. Does anyone who is
    familiar with win32file have an idea what the problem is?

    Thanks for the help!

    -- Ron
  • Hg at Apr 7, 2007 at 9:36 am

    Ron Jackson wrote:

    Dennis Lee Bieber wrote:
    On Wed, 07 Feb 2007 11:14:39 -0800, Ron Jackson
    <Ron at FascinatingElectronics.com> declaimed the following in
    comp.lang.python:

    I am using Python 2.5 on Windows XP. I have installed Pyserial and
    win32all extensions.
    2.4 on XP Pro SP2...

    When I try to run the example program scan.py (included below), or any
    other program using pyserial, as soon as it hits the statement:

    s = serial.Serial(i)
    import serial
    for i in range(256):
    ... try:
    ... print i,
    ... s = serial.Serial(i)
    ... print s.portstr
    ... s.close()
    ... except serial.SerialException:
    ... print
    ...
    0 COM1
    1
    2 COM3
    3
    4
    5
    6
    7
    8
    9
    10
    11
    and on and on...

    What do I need to do to fix this? Thanks for the help!

    Does the serial port module require a compile for use with 2.5?
    Well, with only one download since Python 2.2, guess not...

    Something glitched in win32? Sorry, I don't know... However, since
    those are Python source files, you could always plug in some debugging
    lines around that win32 call to see what actually is there. Do you have
    any unnatural serial ports on the machine? (Like a USB<>serial
    converter?)
    Trying your program, I get the same error 'Incorrect function.':

    Traceback (most recent call last):
    File "<pyshell#9>", line 4, in <module>
    s = serial.Serial(i)
    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 57, in
    open
    win32file.SetupComm(self.hComPort, 4096, 4096)
    error: (1, 'SetupComm', 'Incorrect function.')


    I tried PySerial on a laptop, also running XP Home SP2, and both the
    example program and the program you suggested work fine on the laptop.

    The desktop computer that is giving me the error doesn't have any
    unnatural serial ports on it currently. The laptop worked fine, either
    with a USB device emulating COMM6 present or with the USB device
    disconnected.

    I checked and both machines are running the same version of win32file,
    which is site-packages\win32\win32file.pyd, 88 KB dated 9/22/2006.

    So my question is:

    Why would the statement win32file.SetupComm(self.hComPort, 4096, 4096)

    work just fine on one machine and not the other?

    win32file.pyd can't be opened like a .py file, and I don't know what the
    rather cryptic error 'Incorrect function.' is trying to tell me. Does
    anyone who is familiar with win32file have an idea what the problem is?

    Thanks for the help!

    -- Ron

    I am now facing your problem ... on a machine that used to work fine.

    Have you figured it out ?

    Could it be a conflict between pyserial and pywin32 ?

    hg
  • Hg at Apr 7, 2007 at 1:50 pm

    Dennis Lee Bieber wrote:

    On Sat, 07 Apr 2007 11:36:05 +0200, hg <hg at nospam.org> declaimed the
    following in comp.lang.python:
    I am now facing your problem ... on a machine that used to work fine.

    Have you figured it out ?

    Could it be a conflict between pyserial and pywin32 ?
    The test still runs on my system -- which is still running the
    ActiveState 2.4.3 build*... So that probably clears M$ of any
    malfeasance (via various and sundry patches).

    The closest a google search came up with was someone trying to
    control a serial port printer getting failures on setupcomm (and /not/
    via Python). I think the gist was that any port except the one the
    printer was connected to was okay.

    So... Is there some device connected to the port in question?
    Possibly a device that has a system level driver (ie, a Windows printer
    entry) that might be preventing changes...





    * Too many 3rd-party modules still aren't available in 2.5 versions
    for my tastes...
    --
    Wulfraed Dennis Lee Bieber KD6MOG
    wlfraed at ix.netcom.com wulfraed at bestiaria.com
    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: web-asst at bestiaria.com)
    HTTP://www.bestiaria.com/

    My fault,

    I actually _had_ the issue with python 2.4

    I removed everything and reinstalled python 2.4.4, pywin( lastest) and
    pyserial (latest) ... the problem is gone.

    hg

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedFeb 7, '07 at 7:14p
activeApr 7, '07 at 1:50p
posts4
users2
websitepython.org

2 users in discussion

Ron Jackson: 2 posts Hg: 2 posts

People

Translate

site design / logo © 2022 Grokbase