473,721 Members | 2,133 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 8150
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
1577
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
11028
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
7928
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
3739
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
11622
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
6666
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
6211
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
10646
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
8730
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
9367
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...
0
9215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9131
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
9064
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3189
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

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.