Trying to open a serial port with pyserial on WinXP -> “Access denied”

夙愿已清 提交于 2019-11-30 21:25:51
kgiannakakis

Try opening the port as \\.\COMxx

Also make sure that the port isn't already open from another application. I recommend that you use Hyperterminal to see if the port is open.

.close() before I called the .open() worked for me as well

No need to call .open if you already pass the serial port name/number in the constructor!

When you execute

self.ser=serial.Serial(port='\\.\COM1', baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1) 

the serial port is already open. On Windows, you get an error if you run .open() if the port is already open, but you don't on Linux. That's where the discrepancy is.

Calling .close() before opening the port solved a problem that was driving me nuts!

I had it working on another machine running vista 64-bit using com0com virtual ports, not a hitch.

I was trying to work on the exact same scripts on my Windows 7 box - nada - XP Mode same thing. Access Denied or couldn't find the port (when changing up how the port was addressed). HyperTerminal, of course, recognized and worked with everything flawlessly.

4 hours later I find this little nugget and now everything is humming along just fine.

It's a good thing I enjoy programming...GAH!

I had a similar problem when i was trying to get accelerometer values from TI Chronos. In the device manager i just disabled the COM port and enabled it again. Worked

Be sure the port is not open by any other program. (That's worked for me)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!