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

Adam adam at no_thanks.com
Thu Jun 28 17:48:08 EDT 2012


"Roel Schroeven" <roel at roelschroeven.net> wrote in message 
news:mailman.1618.1340910525.4697.python-list at python.org...
> Temia Eszteri schreef:
>> 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.
>
> That doesn't have anything to do with Windows, but with how pySerial 
> works. See the documentation for __init__():
>
> "The port is immediately opened on object creation, when a port is given. 
> It is not opened when port is None and a successive call to open() will be 
> needed."
>
> So if your script does something like
>
> prt = serial.Serial('COM4')
>
> then pySerial automatically opens the port, and you shouldn't call 
> prt.open() anymore.
>
> If, on the contrary, you do something like
>
> prt = serial.Serial()
> prt.port = 'COM4'
>
> then pySerial doesn't open the port, and you have to call prt.open() to do 
> it.
>
> PySerial has this same behavior on both Windows and Linux. The difference 
> might be that on Linux it is possible to open serial ports more than once, 
> while that doesn't work on Windows.
>
> Best regards,
> Roel
>


Thanks for the info.  Your explanation helps a lot.






More information about the Python-list mailing list