[pywin32-bugs] [ pywin32-Bugs-2132639 ] win32file.GetCommState incorrect handling of DCB
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2008-09-27 20:13:19
|
Bugs item #2132639, was opened at 2008-09-27 13:56 Message generated for change (Comment added) made by rupole You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=2132639&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: win32 Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Alan Gardner (jiaailun) Assigned to: Nobody/Anonymous (nobody) Summary: win32file.GetCommState incorrect handling of DCB Initial Comment: I believe I have found a bug in win32file.GetCommState and win32file.SetCommState. I have seen it in Python 2.4 and Python 2.5, running an older version of pywin32, as well as the current (212) version. It exists in Win2k and WinXP. I use pyserial 2.4 as a wrapper for the comm ports, though I believe the problem is in win32file. The problem manifests itself when I try to open a com port in Python after having that port open in Procomm (an old, no longer supported terminal program). I have only seen it happen with a particular brand of USB to serial converters (Edgeport, made by Digi). In these conditions the python script will hang at the win32file.SetCommState() command, usually timing out after 5-30 seconds, and quitting with no error message. After having done some probing I think I basically understand the problem, and have a workaround, but I lack the know-how to fix it where it should be fixed, in win32file. When Procomm opens the port, it sets XoffLim to 16128 and the XonLim to 15872. When my script (actually, serialwin32.py from pyserial) tries to open the port it first reads the DCB with GetCommState(), changes baud rate, etc in the local PyDCB object, and then tries to reconfigure the port with SetCommState(). >From what I can tell, SetCommState won't accept a value for XoffLim or XonLim >4096. For example, if I try to execute the following: DCB.XoffLim = 16128 SetCommState(porthandle,DCB) I get an exception: (87, 'SetCommState', 'The parameter is incorrect.') However, if GetCommState gets a DCB which has XoffLim = 16128, and then that DCB is passed to SetCommState, the script hangs for several seconds before exiting without opening the port and with no error message. For example, after having opened and closed the port in Procomm: >>> DCB = GetCommState(porthandle) >>> DCB.XoffLim 16128L >>> SetCommState(porthandle,DCB) (...... hangs here for several seconds ......) If I set XoffLim and XonLim to values from 0-4096 before calling SetCommState, then it works fine. For example, after having opened and closed the port in Procomm: >>> DCB = GetCommState(porthandle) >>> DCB.XoffLim = 128 >>> DCB.XonLim = 512 >>> SetCommState(porthandle,DCB) >>> This works fine, and I can go on to open the port normally. I have incorporated this fix into serialwin32.py which is working for me now, but it's not an elegant solution. I am still baffled by why SetCommState limits Xon/XoffLim to 4096, and by what GetCommState does to the PyDCB to make it cause SetCommState to fail so dramatically. I also don't understand why I only see this problem with the Edgeport USB converters, and not with several other USB converters or hardware serial ports. Maybe someone with a more intimate understanding of Python and Win32 can come up with some answers. Thank you -Alan Gardner Woods Hole Oceanographic Institution Woods Hole, MA 02543 ---------------------------------------------------------------------- >Comment By: Roger Upole (rupole) Date: 2008-09-27 15:13 Message: I don't see any problem with the way the DCB is passed to/from SetCommState and GetCommState. The XonLim and XoffLim members consistently have the correct value. If I recall from looking at pyserial a while back, it sets the buffer sizes to 4096. Have you tried increasing them in the call to SetupComm ? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=2132639&group_id=78018 |