将参数传递给piface数字回调

时间:2018-05-02 11:37:33

标签: python websocket

我正在尝试注册按钮,因此每次设置事件时,都会通过我的websocket发送消息。

/home/imx7/build/imx7-firmware-dev-package/src/maketools/obj.iMX7/bin/arm-devolo-linux-g++  -fexceptions -frtti -pthread -g  -rdynamic CMakeFiles/databaseManager.dir/DatabaseManagerEventHandler.cpp.o CMakeFiles/databaseManager.dir/DatabaseManagerHandler.cpp.o CMakeFiles/databaseManager.dir/DatabaseManagerServer.cpp.o CMakeFiles/databaseManager.dir/DatabaseManagerService.cpp.o CMakeFiles/databaseManager.dir/Logger.cpp.o CMakeFiles/databaseManager.dir/dbConnection.cpp.o CMakeFiles/databaseManager.dir/thrift_common/base_constants.cpp.o CMakeFiles/databaseManager.dir/thrift_common/base_types.cpp.o CMakeFiles/databaseManager.dir/thrift_dbManager/DatabaseManager.cpp.o CMakeFiles/databaseManager.dir/thrift_dbManager/dbManager_constants.cpp.o CMakeFiles/databaseManager.dir/thrift_dbManager/dbManager_types.cpp.o CMakeFiles/databaseManager.dir/thrift_supervisor/Info.cpp.o CMakeFiles/databaseManager.dir/thrift_supervisor/Supervision.cpp.o CMakeFiles/databaseManager.dir/thrift_supervisor/supervision_constants.cpp.o CMakeFiles/databaseManager.dir/thrift_supervisor/supervision_types.cpp.o  -o databaseManager  -L/usr/lib/cross/official_libs  -L/usr/lib/cross/boost/lib -Wl,-rpath,/usr/lib/cross/official_libs:/usr/lib/cross/boost/lib: /usr/lib/cross/boost/lib/libboost_system.so /usr/lib/cross/boost/lib/libboost_atomic.so /usr/lib/cross/boost/lib/libboost_filesystem.so /usr/lib/cross/boost/lib/libboost_log.so /usr/lib/cross/boost/lib/libboost_exception.a /usr/lib/cross/boost/lib/libboost_date_time.so /usr/lib/cross/boost/lib/libboost_log_setup.so /usr/lib/cross/boost/lib/libboost_thread.so /usr/lib/cross/boost/lib/libboost_regex.so /usr/lib/cross/boost/lib/libboost_chrono.so -lthrift -lcrypto -lssl -lsqlcipher 
/home/imx7/build/imx7-firmware-dev-package/src/maketools/binaries.iMX7/tools/bin/../lib/gcc/arm-devolo-linux-gnueabihf/4.9.4/../../../../arm-devolo-linux-gnueabihf/bin/ld: warning: libz.so.1, needed by /usr/lib/cross/official_libs/libsqlcipher.so, not found (try using -rpath or -rpath-link)
/usr/lib/cross/boost/lib/libboost_date_time.so: undefined reference to `boost::throw_exception(std::exception const&)'
collect2: error: ld returned 1 exit status
src/CMakeFiles/databaseManager.dir/build.make:471: recipe for target 'src/databaseManager' failed
make[2]: Leaving directory '/var/cppbuild/DatabaseManager/build/Linux-Debug'
CMakeFiles/Makefile2:88: recipe for target 'src/CMakeFiles/databaseManager.dir/all' failed
make[1]: Leaving directory '/var/cppbuild/DatabaseManager/build/Linux-Debug'
make[2]: *** [src/databaseManager] Error 1
make[1]: *** [src/CMakeFiles/databaseManager.dir/all] Error 2
Makefile:132: recipe for target 'all' failed
make: *** [all] Error 2

我传递的函数有这样的论点:

pifacedigitalio.init()
listener = pifacedigitalio.InputEventListener()
listener.register(1, pifacedigitalio.IODIR_ON, self.sendEventPushed)   
listener.activate()

documentation我无法找到是否可以将自己的参数传递给函数,执行:

async def sendEventPushed(self,websocket,path):
    await websocket.send(str(1))
    print("sent")

只需调用它并将结果传递给侦听器,这不是我想要的。

1 个答案:

答案 0 :(得分:1)

给出一个不带参数的函数并调用self.sendEventPushed(websocket,path),例如:

def callback():
    self.sendEventPushed(websocket, path)

listener.register(1, pifacedigitalio.IODIR_ON, callback)

listener.register(1, pifacedigitalio.IODIR_ON, lambda: self.sendEventPushed(websocket, path))