Error opening port in python

I am trying to get accelerometer data from TI Chronos, I get the following error message when running 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 am a system administrator. Maybe a problem with the code?

Thanks,

Jay

+4
source share
4 answers

I get it. Simple enough, I just turned off the COM port in the device manager window and turned it back on.

+9
source

The most common source of such errors is that the port is already open by some other application, or often with the help of a previous (completed, but forgotten to destroy) instance of your code.

To test this hypothesis, the easiest way is to run another program that opens the same port (for example, Hyperterminal) when you receive an error. If this fails, try to find who is holding the port.

In addition, Portmon is a useful tool for debugging similar serial port issues.

+14
source

Since this is the top search result, I am updating it to add another situation that also creates an Access Denied error: port permissions are actually configured to refuse normal user access! Some sysadmins blocking blocks are for good reason, so only users with administrator privileges can access.

The easiest way is to run cmd.exe as an administrator. See this: http://www.howtogeek.com/howto/windows-vista/run-a-command-as-administrator-from-the-windows-vista-run-box/

Summary: Win + r, "cmd", Shift + Ctrl + Enter

"It works for me!" (Tm)

+4
source

Running python from cmd as administrator also works for me.

For start:

  • Enter cmd in the search

  • Right click and select run as administrator

0
source

All Articles