Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #24566

Re: PySerial could not open port COM4: [Error 5] Access is denied - please help

From "Adam" <adam@no_thanks.com>
Newsgroups comp.lang.python
Subject Re: PySerial could not open port COM4: [Error 5] Access is denied - please help
Date 2012-06-27 17:14 -0700
Organization A noiseless patient Spider
Message-ID <jsg7m0$6mn$1@dont-email.me> (permalink)
References (11 earlier) <jsg05u$mgk$1@reader1.panix.com> <jsg0sj$4t9$1@reader1.panix.com> <ra2nu7h75720i75ijhabg12dngrab756e8@4ax.com> <jsg2pt$87s$1@dont-email.me> <jsg4o8$o4p$1@reader1.panix.com>

Show all headers | View raw


"Grant Edwards" <invalid@invalid.invalid> wrote in message 
news:jsg4o8$o4p$1@reader1.panix.com...
> On 2012-06-27, Adam <adam@no_thanks.com> wrote:
>>
>>> Actually, I believe someone in an earlier thread in the newsgroup or
>>> elsewhere pointed out that serial ports automatically open under
>>> Windows. I'd have to look it back up when I have the time, which I
>>> don't have at the moment, unfortunately.
>
> What they're referring to is that on startup, Windows used to open
> serial ports and query them to see if there was a serial mouse
> connected.  If it _thought_ it found a mouse, it would then hold the
> port. I don't think that behavior has been enabled by default for a
> long time.
>
> If that were the case, then your terminal program wouldn't be able to
> open the port either.
>
> However, IIRC, some versions of windows do open and then close the
> ports during the bus/device enumeration step of startup. However, they
> don't keep the port open, so it doesn't affect the ability of user
> applications to later open the port.
>
>> Thanks, I think I read that as well but can't recall where.
>>
>> I am just running Python scripts (downloaded), which is not opening
>> the serial port more than once (as Grant keeps assuming).
>
> Well, I'm assuming your description of what you're doing is accurate.
>
> If you're telling the truth, then the program is opening the port more
> than once.
>
> If the port wasn't already open, then calling ser.close() wouldn't do
> _anything_.  Here's the close() implmentation from pyserial:
>
>    def close(self):
>        """Close port"""
>        if self._isOpen:
>            if self.hComPort:
>                # Restore original timeout values:
>                win32.SetCommTimeouts(self.hComPort, self._orgTimeouts)
>                # Close COM-Port:
>                win32.CloseHandle(self.hComPort)
>                win32.CloseHandle(self._overlappedRead.hEvent)
>                win32.CloseHandle(self._overlappedWrite.hEvent)
>                self.hComPort = None
>            self._isOpen = False
>
> There's only _one_ place where self._isOpen is set to True, and that's
> at the end of the open() call:
>
>    def open(self):
>        """Open port with current settings. This may throw a 
> SerialException
>           if the port cannot be opened."""
> [...]
>        self._overlappedWrite.hEvent = win32.CreateEvent(None, 0, 0, None)
>        self._isOpen = True
>
> If you have to add the call "ser.close()" before you can open the port
> with "ser.open()", then that means that the port _was_already_open_.
>
> -- 
> Grant Edwards               grant.b.edwards        Yow! World War III?
>                                  at               No thanks!
>                              gmail.com


Obviously pySerial considers the serial port open and will not open an 
already open serial port.
However, why is it that TeraTerm can open the serial port?

Here's the link where I read about calling ser.close() before ser.open() ...

Trying to open a serial port with pyserial on WinXP -> "Access denied"
http://stackoverflow.com/questions/2063257/trying-to-open-a-serial-port-with-pyserial-on-winxp-access-denied


Here's the Python scripts ...
https://github.com/adafruit/Tweet-a-Watt/downloads
Click on the "Download as ..." button for the Python scripts

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

PySerial could not open port COM4: [Error 5] Access is denied - please help "Adam" <adam@no_thanks.com> - 2012-06-26 21:12 -0700
  Re: PySerial could not open port COM4: [Error 5] Access is denied - please help John Nagle <nagle@animats.com> - 2012-06-26 22:33 -0700
    Re: PySerial could not open port COM4: [Error 5] Access is denied - please help "Adam" <adam@no_thanks.com> - 2012-06-27 02:10 -0700
      Re: PySerial could not open port COM4: [Error 5] Access is denied - please help Paul <nospam@needed.com> - 2012-06-27 08:28 -0400
        Re: PySerial could not open port COM4: [Error 5] Access is denied - please help "Adam" <adam@no_thanks.com> - 2012-06-27 08:26 -0700
          Re: PySerial could not open port COM4: [Error 5] Access is denied - please help Paul <nospam@needed.com> - 2012-06-27 12:04 -0400
            Re: PySerial could not open port COM4: [Error 5] Access is denied - please help "Adam" <adam@no_thanks.com> - 2012-06-27 10:41 -0700
              Re: PySerial could not open port COM4: [Error 5] Access is denied - please help Paul <nospam@needed.com> - 2012-06-27 14:04 -0400
                Re: PySerial could not open port COM4: [Error 5] Access is denied - please help "Adam" <adam@no_thanks.com> - 2012-06-27 13:40 -0700
                Re: PySerial could not open port COM4: [Error 5] Access is denied - please help Grant Edwards <invalid@invalid.invalid> - 2012-06-27 21:18 +0000
                Re: PySerial could not open port COM4: [Error 5] Access is denied - please help "Adam" <adam@no_thanks.com> - 2012-06-27 14:48 -0700
                Re: PySerial could not open port COM4: [Error 5] Access is denied - please help Grant Edwards <invalid@invalid.invalid> - 2012-06-27 22:06 +0000
                Re: PySerial could not open port COM4: [Error 5] Access is denied - please help Grant Edwards <invalid@invalid.invalid> - 2012-06-27 22:18 +0000
                Re: PySerial could not open port COM4: [Error 5] Access is denied - please help Temia Eszteri <lamialily@cleverpun.com> - 2012-06-27 15:31 -0700
                Re: PySerial could not open port COM4: [Error 5] Access is denied - please help "Adam" <adam@no_thanks.com> - 2012-06-27 15:51 -0700
                Re: PySerial could not open port COM4: [Error 5] Access is denied - please help Grant Edwards <invalid@invalid.invalid> - 2012-06-27 23:24 +0000
                Re: PySerial could not open port COM4: [Error 5] Access is denied - please help "Adam" <adam@no_thanks.com> - 2012-06-27 17:14 -0700
                Re: PySerial could not open port COM4: [Error 5] Access is denied - please help Grant Edwards <invalid@invalid.invalid> - 2012-06-28 14:15 +0000
                Re: PySerial could not open port COM4: [Error 5] Access is denied - please help "Adam" <adam@no_thanks.com> - 2012-06-28 13:31 -0700
                Re: PySerial could not open port COM4: [Error 5] Access is denied - please help Roel Schroeven <roel@roelschroeven.net> - 2012-06-28 21:08 +0200
                Re: PySerial could not open port COM4: [Error 5] Access is denied- please help "Adam" <adam@no_thanks.com> - 2012-06-28 14:48 -0700
      Re: PySerial could not open port COM4: [Error 5] Access is denied - please help "David H. Lipman" <DLipman~nospam~@Verizon.Net> - 2012-06-27 08:28 -0400
        Re: PySerial could not open port COM4: [Error 5] Access is denied - please help Grant Edwards <invalid@invalid.invalid> - 2012-06-27 14:53 +0000

csiph-web