gpt4 book ai didi

python - 连接到 nxt 砖时出错

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

我正在使用 nxt-python 从我的树莓派连接到我的 nxt 砖。

经过一番与Python 3.2版本的蓝牙和USB库的斗争后,我已经设法让它通过蓝牙连接并要求输入密码。经过一番努力,我发现我可以在运行与 nxt 砖连接的 python 脚本之前在终端中输入 bluetooth-agent PASSKEY & (并将 PASSKEY 替换为 key ),据我所知效果很好。但现在它抛出一个错误。使用 USB 连接会引发不同的错误。

这是我使用两种方法(USB 和 BT)并启用调试时遇到的错误:

USB: True BT: True Fantom: False FUSB: False FBT: False
Traceback (most recent call last):
File "/usr/local/lib/python3.2/dist-packages/nxt/locator.py", line 138, in find_one_brick
if name and info[0].strip('\0') != name:
TypeError: Type str doesn't support the buffer API
Failed to connect to possible brick
Traceback (most recent call last):
File "/usr/local/lib/python3.2/dist-packages/nxt/locator.py", line 131, in find_one_brick
info = b.get_device_info()
File "/usr/local/lib/python3.2/dist-packages/nxt/brick.py", line 27, in poll
self.sock.send(ogram.bytes())
File "/usr/local/lib/python3.2/dist-packages/nxt/bluesock.py", line 57, in send
l0 = len(data.encode('utf-8')) & 0xFF
AttributeError: 'bytes' object has no attribute 'encode'
Failed to connect to possible brick
No brick was found.
Is the brick turned on?
For more diagnosing use the debug=True argument or
try the 'nxt_test' script located in /bin or ~/.local/bin
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.2/dist-packages/nxt/locator.py", line 154, in find_one_brick
raise BrickNotFoundError
nxt.locator.BrickNotFoundError

因为我了解 python,我可能可以通过编辑源代码来修复错误,但我担心我会破坏一些东西。我尝试过编辑它(保留我编辑的每个文件的备份),然后它会超过几行,然后抛出另一个不同的错误。

编辑

当我尝试使用 python 2 导入时,它给了我这个错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nxt/__init__.py", line 15, in <module>
from nxt.locator import find_one_brick, Method
File "/usr/local/lib/python2.7/dist-packages/nxt/locator.py", line 49
if not silent: print("USB module unavailable, not searching there", file=sys.stderr)
^
SyntaxError: invalid syntax

最佳答案

我已经下载了 v2.2.2 稳定版本,而不是克隆主提交,它在 python2 下运行良好。可惜它不是 python3。

关于python - 连接到 nxt 砖时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38191619/

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