473,385 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Pyserial example program error: win32file.SetupComm reports 'Incorrectfunction.'

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 <cl******@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)
Feb 7 '07 #1
3 8131
Dennis Lee Bieber wrote:
On Wed, 07 Feb 2007 11:14:39 -0800, Ron Jackson
<Ro*@FascinatingElectronics.comdeclaimed 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
Feb 8 '07 #2
hg
Ron Jackson wrote:
Dennis Lee Bieber wrote:
>On Wed, 07 Feb 2007 11:14:39 -0800, Ron Jackson
<Ro*@FascinatingElectronics.comdeclaimed 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
Apr 7 '07 #3
hg
Dennis Lee Bieber wrote:
On Sat, 07 Apr 2007 11:36:05 +0200, hg <hg@nospam.orgdeclaimed 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
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@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

Apr 7 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jim | last post by:
Hi, All I am using python (activestate 2.2.2-224) on XP home and have suddenly got the following error from a file which worked fine under millenium. self.Overlapped = win32file.OVERLAPPED()...
13
by: Bob Greschke | last post by:
We have some equipment that communicates at 57600 baud RS232. The path from the PC is USB to a Phillips USB hub, then off of that a TUSB3410 USB/Serial converter. The driver for the 3410 chip...
17
by: luca72 | last post by:
Hello at all sorry for my english but i'm Italian. I use pyserial to communicate via rs232 with an extarnal device called smartmouse. I write the exact line that i want , but when i read i read...
2
by: Jon | last post by:
Hi, I wrote some code to read in info from a port using pyserial. the code reads info sent by a box that is connected to my computer by an rs232-to usb adapter. When I was writing the code and...
0
by: pauland80 | last post by:
<snip> <snip> Late thanks for your both answers! (Please excuse me for that) The problem was a bug in the device firmware. But before finding this, I dugg lightly in the pyserial source...
3
by: naveen.sabapathy | last post by:
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...
6
by: terry | last post by:
Hi, I am trying to send a character to '/dev/ttyS0' and expect the same character and upon receipt I want to send another character. I tired with Pyserial but in vain. Test Set up: 1. Send...
3
by: Rainy | last post by:
Hello! I'm having some trouble with pyserial package, I'm sending commands and reading responses from a custom pcb, and sometimes I get a proper response, at other times I get nothing, and...
6
by: Joe G \(Home\) | last post by:
Hi All, Background =================== I have installed Python for windows today from the python web site .I also installed pySerial using the Windows installer from the sourceforge web...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.