Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-xxxfer.readnews.com!news-out.readnews.com!transit3.readnews.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python,microsoft.public.windowsxp.general Subject: Re: PySerial could not open port COM4: [Error 5] Access is denied - please help Date: Wed, 27 Jun 2012 22:06:54 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 53 Message-ID: References: NNTP-Posting-Host: dsl.comtrol.com X-Trace: reader1.panix.com 1340834814 23060 64.122.56.22 (27 Jun 2012 22:06:54 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Wed, 27 Jun 2012 22:06:54 +0000 (UTC) User-Agent: slrn/pre1.0.0-18 (Linux) Xref: csiph.com comp.lang.python:24548 On 2012-06-27, Adam wrote: > "Grant Edwards" wrote: >> On 2012-06-27, Adam wrote: >> >>> The Python script needed a call to ser.close() before ser.open() in >>> order to work. >> >> IOW, the port opened OK, but when you tried to open it a second time >> without closing it first, _that's_ when the .open() call failed. >> >> That's a restriction built in to Win32. You can't open a serial port >> that's already open. [Linux doesn't have that restriction.] >> >> Why do you need to open it a second time? > > As far as I can tell, the wireless hardware connected to the > USB-to-serial converter is receiving data (which may have the serial > port open?). I can see the data being received in TeraTerm (using > COM4). After closing TeraTerm, I start up the Python script and get > the following error message ... > > C:\Wattcher>python wattcher.py > Traceback (most recent call last): > File "wattcher.py", line 56, in > ser.open() > File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, in > open > raise SerialException("could not open port %s: %s" % (self.portstr, > ctypes.WinError())) > serial.serialutil.SerialException: could not open port COM4: [Error 5] > Access is denied. > > > Searching for similar encounters of this error message, some people > said that calling ser.close() before ser.open() solved the problem. > And, it worked for me as well. > > Is this considered a chicken & egg situation? Can you post a small example showing what you're doing? If you're getting that error (and calling ser.close() makes that error go away), then it's because you're trying to re-open a port that you already have open. What happens if you just get rid of both the ser.close() and ser.open() calls? IOW, the port is apparently already open -- why do you want to close() and then re-open() it? -- Grant Edwards grant.b.edwards Yow! I wonder if I should at put myself in ESCROW!! gmail.com