import serial
while True:
ser=serial.Serial(port='COM30',baudrate=9600)
print "try"
s=ser.read(100) #reading up to 100 bytes
print s
ser.close()
装置经理:
我正在尝试使用 python 从端口读取数据。但它显示错误:
Traceback (most recent call last):
File "new_python.py", line 3, in <module>
ser=serial.Serial(port='COM30',baudrate=9600)
File "C:\Anaconda\lib\site-packages\serial\serialwin32.py", line 38, in __init__
SerialBase.__init__(self, *args, **kwargs)
File "C:\Anaconda\lib\site-packages\serial\serialutil.py", line 282, in __init__
self.open()
File "C:\Anaconda\lib\site-packages\serial\serialwin32.py", line 66, in open
raise SerialException("could not open port %r: %r" % (self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM30': WindowsError(5, 'Access is denied.')
***Repl Closed***
现在,从堆栈上的先前解决方案中,我尝试使用 python 32 位并从具有管理员权限但同样错误的 cmd 调用它!
当我尝试使用 matlab 时,它向我展示了这一点:
s = serial('COM30')
Serial Port Object : Serial-COM30
Communication Settings
Port: COM30
BaudRate: 9600
Terminator: 'LF'
Communication State
Status: closed
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0