473,756 Members | 4,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pyserial example program error: win32file.Setup Comm reports 'Incorrectfunct ion.'

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\Do c\PySerial Examples\scan.p y", line 26, in <module>
for n,s in scan():
File "C:\Python25\Do c\PySerial Examples\scan.p y", line 17, in scan
s = serial.Serial(i )
File "C:\Python25\Li b\site-packages\serial \serialutil.py" , line 156,
in __init__
self.open()
File "C:\Python25\li b\site-packages\serial \serialwin32.py ", line 57,
in open
win32file.Setup Comm(self.hComP ort, 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.n et>

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.appen d( (i, s.portstr))
s.close() #explicit close 'cause of delayed GC in java
except serial.SerialEx ception:
pass
return available

if __name__=='__ma in__':
print "Found ports:"
for n,s in scan():
print "(%d) %s" % (n,s)
Feb 7 '07 #1
3 8157
Dennis Lee Bieber wrote:
On Wed, 07 Feb 2007 11:14:39 -0800, Ron Jackson
<Ro*@Fascinatin gElectronics.co mdeclaimed the following in
comp.lang.pytho n:

>>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.SerialEx ception:
... 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\Li b\site-packages\serial \serialutil.py" , line 156, in __init__
self.open()
File "C:\Python25\li b\site-packages\serial \serialwin32.py ", line 57, in open
win32file.Setup Comm(self.hComP ort, 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.Setup Comm(self.hComP ort, 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*@Fascinati ngElectronics.c omdeclaimed the following in
comp.lang.pyth on:

>>>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.SerialEx ception:
... 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\Li b\site-packages\serial \serialutil.py" , line 156, in
__init__
self.open()
File "C:\Python25\li b\site-packages\serial \serialwin32.py ", line 57, in
open
win32file.Setup Comm(self.hComP ort, 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.Setup Comm(self.hComP ort, 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.orgd eclaimed the
following in comp.lang.pytho n:
>>
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.netc om.com wu******@bestia ria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestia ria.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
1579
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() self.overlapped.hEvent = CreateEvent(None, 0, 0, None) hComm = win32file.CreateFile(comport, win32con.GENERIC_READ | win32con.GENERIC_WRITE,
13
11034
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 creates a "normal" comm port (like COM3). There is a C++ program that has no problem talking to the equipment, but two Python programs have trouble. One is a big, scary, controller program, and the other, since that is the one I'm having trouble...
17
7934
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 only the echo ond not the other bytes. When i meke the same project with delphi i solve this problem with the call of the sleep. But in python it don't work. Have you got some ideas for solve my problem?
2
3741
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 testing it on my computer it worked fine. I ran py2exe on the program (which uses wxpython for its gui) and sent the output from the py2exe to another computer. now when I try to run it on this other computer it fails to open the port. it gives...
0
596
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 and found (to take with care!) :
3
11631
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 be working fine when I test it with Hyperterminal . I am using the example program that comes with pyserial, as below. --------------- import serial
6
6669
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 '%' to serial port and make sure it reached the serial port. 2. Once confirmed, send another character.
3
6221
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 sometimes I get about half of the response string with beginning cut off. About half the time an empty string is returned, the other ~half time good response, and more rarely I get partial response. When I try to use the same Serial instance to...
6
10649
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 site..... Both installs use the default directories. Phyton version : Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) on win32
0
9431
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9255
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10014
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6514
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3780
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3326
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.