Reputation: 1503
I am writing Python v2.x in Windows7 OS. When I run my code, the following error happens frequently.
serial.serialutil.SerialException: could not open port 'COM4': WindowsError(5, 'Access is denied.')
Here are what I did:
1) I check device manager, COM 4
can be seen, but cannot open
2) In my code, I do close COM
port after using it
3) Here is COM
config in my code: ser = serial.Serial( "COM4", 9600, timeout=0.05)
4) I reboot computer, the problem is gone, but it happens again after a while
5) I wonder it is a problem related to my Python code or Windows system?
So considering above fact, could anyone help me out? Thanks and Happy New Year!
=)
Upvotes: 22
Views: 169303
Reputation: 13
I had the same issue whilst using the latest esp-idf 5.4, and latest Espressif IDE Version: 3.1.0. (Note, i had been using Ubuntu and WSL2 but it took too much space, so wanted to get the WIN only dev environment working, even though it still needs WSL)
BUT, kept getting lockouts on the UART, as frequent as everytime I hit build, or 'Go' to flash and open the Terminal within the IDE. Tried to load all the various new drivers, inc 'CP210x Universal Windows Driver' v11.4.0 12/18/2024, also the old rollback to 6.4)
The solution, which works EVERY time: We get a stray PYTHON App/Task - you can kill all of them, it doesn't stop the IDE from working, its just the old TERMINAL that is still running in the background (even though you hit the 'X' and killed it in the IDE'
Killing the 'PYTHON' app, allows you to re click the 'RUN' icon and now finds the UART and programs it.
Upvotes: 0
Reputation: 404
If you are using python or any language then please try to keep the ser = serial.Serial( "COM4", 9600, timeout=0.05) in out of loop. It needs to create only once and close only once. So If you have written above code in side the loop you will end up with the same error. :)
Hope this is some what helpful to anyone who is initializing this in the loop.
Upvotes: 1
Reputation: 329
I hope you are talking about this error.
serial.serialutil.SerialException: could not open port 'COM6': PermissionError(13, 'Access is denied.', None, 5).
It means that the COM6 is being used by some other program e.g Arduino IDE. So close the serial monitor in IDE and then run your code. Now this is one of the many possibilities only.
Upvotes: 2
Reputation: 257
I was having this problem trying to download code to an ESP32 from my Windows 10 PC. I downloaded and installed the Serial Port Monitor app from https://serial-port-monitor.org which showed that my MalwareBytes Antimalware was interfering with opening the port. I disabled MBAM Ransomware Protection and all was well. Remember to turn Ransomware Protection back on when you've finished!
Upvotes: 0
Reputation: 1039
I had Ultimaker Cura Slicer (for my 3D printer) open, and that was holding control of the COM3 port for some reason. Once I killed that app, then it (VSCode) worked fine for uploading code to my ESP-8266
Upvotes: 48
Reputation: 375
You port COM4 may be open in the arduino IDE serial monitor.
close the serial monitor in the arduino IDE.
This may solve your issue.
Upvotes: 36
Reputation: 11
Had you closed your serial after you excute your project? Maybe you can try to close you port and open it again everytime when you execute you program. just like:
ser = Serial('COM3', 115200)
if not ser.isOpen():
ser.open()
print('com3 is open', ser.isOpen())
Upvotes: 1