连接到nxt brick

时间:2016-07-04 20:10:06

标签: python bluetooth raspberry-pi usb nxt-python

我使用nxt-python从我的覆盆子pi连接到我的nxt砖。

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

1 个答案:

答案 0 :(得分:1)

我已经下载了v2.2.2 stable而不是克隆主提交,它在python2下运行正常。太糟糕了,它不是python3。