Error while opening port in Python using TI Chronos
I'm trying to get 开发者_Python百科accelerometer data from TI Chronos. I get the following error message when I run the code:
Traceback (most recent call last):
File "C:\Python32\chronos_accel.py", line 50, in <module>
.
.
.
raise SerialException("could not open port %s: %s" % (self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port COM4: [Error 5] Access is denied.
Why is access denied? I'm the system administrator. Could it be a problem with the code?
I figured it out. It was simple enough.
I just disabled the COM port in the Device Manager window and enabled it again.
The most common source of such errors is the port being already opened by some other application, or frequently by a previous (executed, but forgotten to kill) instance of your code.
To test this hypothesis, the easiest way is to run some other program that opens the same port (for example, HyperTerminal) when you're getting the error. If it fails also, try to find who's holding the port.
Also, Portmon is a useful tool in debugging similar problems with the serial port.
Another situation that also creates the Access Denied error:
The port permissions are actually set to deny normal user access! Some system administrators lock down ports for good reasons, so only users with administrator privileges can get access.
The simplest work-around is to run cmd.exe as administrator. See Run a Command as Administrator from the Run Box in Windows 7, 8, or 10
Summary: Win + R, "cmd", Shift + Ctrl + Enter
"It Works For Me!" (tm)
Sometimes a port gets blocked.
Try restarting system. It worked for me.
Running python
from cmd as administrator also works for me.
To run:
Type cmd in search
Right-click and select run as administrator
I was having a similar error today in Jupyter Notebook and managed to solve it by opening Jupyter Notebook through Anaconda Navigator instead of opening it through Anaconda Prompt.
精彩评论