如何与UART通信?

时间:2016-11-15 10:21:34

标签: python uart

我正在尝试执行一个python文件,我是python的初学者,我安装了WinPython-64bit-2.7.6.4,我打开WinPython命令Prompt.exe,我尝试执行这个文件:

import serial
ser = serial.Serial('COM4')  # open serial port
print(ser.name)         # check which port was really used
ser.write(b'hello')     # write a string
ser.close()             # close port

我的结果是:

Traceback (most recent call last):
  File "hello.py", line 2, in <module>
    ser = serial.Serial('COM4')  # open serial port
  File "C:\Users\user\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\site-packages\serial\serialwin32.py", line 38, in __init__
    SerialBase.__init__(self, *args, **kwargs)
  File "C:\Users\user\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\site-packages\serial\serialutil.py", line 282, in __init__
    self.open()
  File "C:\Users\user\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\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 'COM4': WindowsError(5, 'Access is denied.')

我真的不明白这个问题。

如果你能帮助我,我将非常感激。

0 个答案:

没有答案