how to show the rpc return data in python3 output print.
-
I want to use Linux server side print the openmv device fps information directly by rpc module. in order to learn the rpc module usage method , then use it for my script . so I just modify the hello.py for learn the rpc.
so main.py as below:import sensor, time, rpc
interface = rpc.rpc_usb_vcp_slave()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
clock = time.clock()
def get_fps():
clock.tick()
return struct.pack("<f", clock.fps())Register the method to fetch FPS
interface.register_method("get_fps", get_fps)
while True:
interface.loop()and linux server execute the controller.py as below:
import json, struct, serial, rpc
interface = rpc.rpc_usb_vcp_master("/dev/ttyACM0")
def receive_and_print_fps():
result = interface.call("get_fps")
if result is not None and len(result):
fps = struct.unpack("<f", result)[0]
print("FPS received from OpenMV device:", fps)
while True:
receive_and_print_fps()after Linux server side run the python3 -u controller.py , there is no output print. I use the minicom -D /dev/ttyACM0 , I can see below output , CfC) repeat.
Welcome to minicom 2.8
OPTIONS: I18n
Port /dev/ttyACM0, 17:05:52
Press CTRL-A Z for help on special keys
)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)I want to know how to modify the script in order to print the fps information after execute the python3 -u controller.py in Linux server terminal. and why CfC) showed, not the true fps data ? thank you very much !!!
-
不好意思, 我linux server 中没有安装中文输入法,为了贴脚本方便,用英语写的帖子
我想通过helloworld 脚本来学习rpc 的用法,实验是否能满足我的需求. 通过openmv 端运行helloworld 脚本,产生一个fps 的数据.然后通过rpc 模块让linux server 端的python3 打印出fps数据.
main.py 如下:
so main.py as below:import sensor, time, rpc
interface = rpc.rpc_usb_vcp_slave()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
clock = time.clock()
def get_fps():
clock.tick()
return struct.pack("<f", clock.fps())
interface.register_method("get_fps", get_fps)
while True:
interface.loop()linux 服务器端运行的程序如下;
import json, struct, serial, rpc
interface = rpc.rpc_usb_vcp_master("/dev/ttyACM0")
def receive_and_print_fps():
result = interface.call("get_fps")
if result is not None and len(result):
fps = struct.unpack("<f", result)[0]
print("FPS received from OpenMV device:", fps)
while True:
receive_and_print_fps()linux 端运行上面的程序后,并不能得到任何输出, 通过minicom工具读取 /dev/ttyACM0 的打印信息如下:
Welcome to minicom 2.8
OPTIONS: I18n
Port /dev/ttyACM0, 17:05:52
Press CTRL-A Z for help on special keys
)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)CfC)
如果Linux 服务器端的程序在运行,这个 CfC) 就会一直重复下去.如果中断这个程序,这个CfC) 就会停止.
我的问题是,有啥办法,让fps数据在linux 服务器端 python3 -u controller.py 执行后,直接打印出来.谢谢
-
问题很简单,因为你的OpenMV上的代码有语法错误。
首先,你没有import struct
import sensor, time, rpc import struct #interface = rpc.rpc_uart_slave(9600,3) interface = rpc.rpc_usb_vcp_slave() sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time=2000) clock = time.clock() def get_fps(data): return struct.pack("<f", 1) interface.register_callback(get_fps) while True: interface.loop()
这个代码是可以的。我测试过。
我建议你先用uart作rpc,电脑端加一个ttl转usb模块。否则代码报错了你都不知道。
-
@kidswong999 已经按照你的脚本修改了main.py 的内容。但是server 端python3 执行如下脚本,还是没有任何输出. 是哪里出错了么
import json, struct, serial, rpc
interface = rpc.rpc_usb_vcp_master("/dev/ttyACM0")
def receive_and_print_fps():
result = interface.call("get_fps")
if result is not None and len(result):
fps = struct.unpack("<f", result)[0]
print("FPS received from OpenMV device:", fps)
while True:
receive_and_print_fps()
-
你运行
脱机运行
的步骤了吗?
-
脱机运行,不就是把上面openmv 端的脚本放在mian.py 里面,就会自动运行么
-
@dtvb 还要重启。
-
我重新插拔了模块,还是和以前一样。
“我建议你先用uart作rpc,电脑端加一个ttl转usb模块。否则代码报错了你都不知道。”你的意思是我需要加一个串口调试扩展板 uart 转usb 的板子来调试程序是么?还有我现在的IDE 环境直接调用popular features as the remote device 示例脚本,会报错"no module named serial",我看是import rpc 时需要import serial .但是IDE 没有找到serial。