Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PySerial [Error 5] Access is Denied

I am trying to write a program in Python that will loop to keep checking the serial port (COM4) and print out a message when the character "1" is read from the serial port. I want to send "1" over the serial port from an Arduino gadget upon the push of a button.

However, I get the error "[Error 5]: Access is Denied" when I try to create an instance of a serial object. (It automatically tries to open upon instantiation, which is where the error is, from what I can see from the file in the PySerial package that handles this.)

My code:

c = serial.Serial('COM4', 9600)
while True:
    signal = c.read()
    print signal
    print "running"
    time.sleep(2)
    c.flushOutput()

It never gets past the "c = serial.Serial('COM4', 9600), though. That's where the error pops up. How can I fix this?

like image 766
TomKo Avatar asked Nov 28 '11 02:11

TomKo


People also ask

Does PySerial work on Windows?

pySerial 1.21 is compatible with Python 2.0 on Windows, Linux and several un*x like systems, MacOSX and Jython. On Windows, releases older than 2.5 will depend on pywin32 (previously known as win32all).

How do I know if PySerial is installed on Windows?

To check that it is installed, start Pyzo and at the command prompt type in: import serial If it just gives you another >>> prompt, all is good. Checking that it is really working.

What is PySerial module?

This module encapsulates the access for the serial port. It provides backends for Python running on Windows, OSX, Linux, BSD (possibly any POSIX compliant system) and IronPython. The module named “serial” automatically selects the appropriate backend.

Is PySerial full duplex?

Yes serial port hardware is full duplex. Yes, you can use threads to do Rx and Tx at the same time. Alternatively, you can use a single thread loop that does reads with a short timeout and alternates between reading and writing.


1 Answers

For me the solution didn't work but what worked was closing all the applications that were interacting with the given com port.

like image 71
Lucas B Avatar answered Sep 28 '22 01:09

Lucas B