gpt4 book ai didi

python - 使用 pyserial 处理 com 端口时出现错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:22:38 25 4
gpt4 key购买 nike

我正在尝试与我的 com 端口连接,特别是使用此代码连接到 thi 的 XBee。

from xbee import XBee
from serial import Serial

PORT = 'COM3'
BAUD = 9600

ser = Serial(PORT, BAUD)

xbee = XBee(ser)
# Send the string 'Hello World' to the module with MY set to 1
xbee.tx(dest_addr='\x00\x01', data='Hello World')

# Wait for and get the response
print(xbee.wait_read_frame())

ser.close()

但是,这个错误不断出现。

SerialException:无法打开端口“COM3”:WindowsError(5,“访问被拒绝。”)。当我重新启动计算机时它消失了,但它不断返回。我更愿意了解为什么会发生这种情况,这样我就不需要不断重新启动计算机。非常感谢任何帮助,谢谢。我正在使用 python 2.7 使用 IDLE 接口(interface),以防万一相关。

最佳答案

串行端口一次只能在一个应用程序中“打开”。一旦应用程序“A”打开端口,应用程序“B”在尝试打开同一端口时将收到“拒绝访问”错误。在您的情况下,您需要弄清楚哪些其他应用程序正在占用该端口并首先将其关闭。

关于python - 使用 pyserial 处理 com 端口时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38276704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com