|
|
 |
 |
 |
 |
Python Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
Pyserial example program error: win32file.SetupComm reports 'Incorrect function.'
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 <cliec@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)
On Wed, 07 Feb 2007 11:14:39 -0800, Ron Jackson <R@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?) -- Wulfraed Dennis Lee Bieber KD6MOG wlfr@ix.netcom.com wulfr@bestiaria.com HTTP://wlfraed.home.netcom.com/ (Bestiaria Support Staff: web-a@bestiaria.com) HTTP://www.bestiaria.com/
Dennis Lee Bieber wrote: > On Wed, 07 Feb 2007 11:14:39 -0800, Ron Jackson > <R @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
|
 |
 |
 |
 |
|