当我尝试通过python中的rpyc连接时,ev3关闭连接

时间:2018-03-13 20:06:52

标签: python mindstorms rpyc

我在我的ev3砖上安装了ev3dev,所以我可以用python在它上面创建程序。我正在尝试使用python的“rpyc”库,可以找到here.但是,当我尝试运行这个基本脚本时,它在上面的链接中作为示例给出:

import rpyc
conn = rpyc.classic.connect('192.168.137.3') # host name or IP address of the EV3
ev3 = conn.modules['ev3dev.ev3']      # import ev3dev.ev3 remotely
m = ev3.LargeMotor('outA')
m.run_timed(time_sp=1000, speed_sp=600)

我通过终端向我发出多个错误,然后关闭连接。我已经按照页面上的所有说明操作了,我还事先在ev3砖上启动了服务器脚本。当我运行上面的程序时,会显示python中的错误:

Traceback (most recent call last):
  File "C:/Python27/cooode/moottertest.py", line 2, in <module>
    conn = rpyc.classic.connect('192.168.137.3') # host name or IP address of the EV3
  File "C:\Python27\lib\site-packages\rpyc\utils\classic.py", line 65, in connect
    return factory.connect(host, port, SlaveService, ipv6 = ipv6)
  File "C:\Python27\lib\site-packages\rpyc\utils\factory.py", line 90, in connect
    return connect_stream(s, service, config)
  File "C:\Python27\lib\site-packages\rpyc\utils\factory.py", line 51, in connect_stream
    return connect_channel(Channel(stream), service = service, config = config)
  File "C:\Python27\lib\site-packages\rpyc\utils\factory.py", line 40, in connect_channel
    return Connection(service, channel, config = config)
  File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 147, in __init__
    self._init_service()
  File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 150, in _init_service
    self._local_root.on_connect()
  File "C:\Python27\lib\site-packages\rpyc\core\service.py", line 145, in on_connect
    self._conn.builtin = self._conn.modules.__builtin__
  File "C:\Python27\lib\site-packages\rpyc\core\service.py", line 114, in __getattr__
    return self[name]
  File "C:\Python27\lib\site-packages\rpyc\core\service.py", line 111, in __getitem__
    self.__cache[name] = self.__getmodule(name)
  File "C:\Python27\lib\site-packages\rpyc\core\netref.py", line 196, in __call__
    return syncreq(_self, consts.HANDLE_CALL, args, kwargs)
  File "C:\Python27\lib\site-packages\rpyc\core\netref.py", line 71, in syncreq
    return conn.sync_request(handler, oid, *args)
  File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 435, in sync_request
    self.serve(0.1)
  File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 383, in serve
    data = self._recv(timeout, wait_for_lock = True)
  File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 341, in _recv
    data = self._channel.recv()
  File "C:\Python27\lib\site-packages\rpyc\core\channel.py", line 50, in recv
    header = self.stream.read(self.FRAME_HEADER.size)
  File "C:\Python27\lib\site-packages\rpyc\core\stream.py", line 190, in read
    raise EOFError("connection closed by peer")
EOFError: connection closed by peer
>>> 

然后在我的SSH会话中,以下是显示的错误:

robot@ev3dev:~$ ./rpyc_server.sh
INFO:SLAVE/18812:server started on [0.0.0.0]:18812
INFO:SLAVE/18812:accepted 192.168.137.1:5725
INFO:SLAVE/18812:welcome [192.168.137.1]:5725
INFO:SLAVE/18812:goodbye [192.168.137.1]:5725
ERROR:SLAVE/18812:client connection terminated abruptly
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 172, in _authenticate_and_serve_client
    self._serve_client(sock2, credentials)
  File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 197, in _serve_client
    conn._init_service()
  File "/usr/lib/python3/dist-packages/rpyc/core/protocol.py", line 154, in _init_service
    self._local_root.on_connect()
  File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 150, in on_connect
    self._conn.builtin = self._conn.modules.builtins
  File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 121, in __getattr__
    return self[name]
  File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 118, in __getitem__
    self.__cache[name] = self.__getmodule(name)
TypeError: 'b'instancemethod'' object is not callable
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 172, in _authenticate_and_serve_client
    self._serve_client(sock2, credentials)
  File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 197, in _serve_client
    conn._init_service()
  File "/usr/lib/python3/dist-packages/rpyc/core/protocol.py", line 154, in _init_service
    self._local_root.on_connect()
  File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 150, in on_connect
    self._conn.builtin = self._conn.modules.builtins
  File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 121, in __getattr__
    return self[name]
  File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 118, in __getitem__
    self.__cache[name] = self.__getmodule(name)
TypeError: 'b'instancemethod'' object is not callable

这些错误在这里出了什么问题?

1 个答案:

答案 0 :(得分:0)

你在连接python2和python3吗? ev3dev使用python2。

使用pyenv安装python3并使用它,以便你的python版本的PC和ev3是相同的。

Database tool window

您可能需要先运行此命令才能通过curl安装:

{{1}}