我正在使用 nxt-python 从我的树莓派连接到我的 nxt 砖。
在与蓝牙和 USB 库的 python 3.2 版本进行了一些斗争之后,我设法让它通过蓝牙连接并要求输入密码。经过一番努力后,我发现我可以bluetooth-agent PASSKEY &
在终端中键入(并用密码替换 PASSKEY),然后再运行与 nxt 砖连接的 python 脚本,据我所知,它工作正常。但是现在它抛出了一个错误。使用 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