TomKo TomKo - 1 year ago 208
Python Question

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 =
print signal
print "running"

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

Answer Source

Under Windows, I've always used the port=<int> approach with success.

I.e. change your code to:

c = serial.Serial(3, 9600)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download