1、错误描述

>>> import serial;
>>> t=serial.Serial
>>> t=serial.Serial("COM1",4800);
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
t=serial.Serial("COM1",4800);
File "D:\Python\Python36\lib\site-packages\pyserial-3.3-py3.6.egg\serial\serialwin32.py", line 31, in __init__
super(Serial, self).__init__(*args, **kwargs)
File "D:\Python\Python36\lib\site-packages\pyserial-3.3-py3.6.egg\serial\serialutil.py", line 240, in __init__
self.open()
File "D:\Python\Python36\lib\site-packages\pyserial-3.3-py3.6.egg\serial\serialwin32.py", line 62, in open
raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM1': PermissionError(13, '拒绝访问。', None, 5)


2、错误原因

      由于Java自启动服务占用了串口COM1,Python程序再次调用这个串口,出现“拒绝访问”错误。


3、解决办法

(1)将Java程序占用的串口暂停掉

(2)寻找另外一个串口COM3