logo

how to show the rpc return data in python3 output print.

2024-01-17 17:19
A
dtvb

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 !!!

2024-01-19 13:50
A
dtvb

不好意思, 我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 执行后,直接打印出来.谢谢

2024-01-19 19:52
I
网红小智智 星瞳科技

问题很简单,因为你的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模块。否则代码报错了你都不知道。

2024-01-23 17:30
A
dtvb

@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()

2024-01-24 18:49
I
网红小智智 星瞳科技

你运行`脱机运行`的步骤了吗?

2024-01-24 19:29
A
dtvb

脱机运行,不就是把上面openmv 端的脚本放在mian.py 里面,就会自动运行么

2024-01-24 21:25
I
网红小智智 星瞳科技

@dtvb 还要重启。

2024-02-05 18:24
A
dtvb

我重新插拔了模块,还是和以前一样。

“我建议你先用uart作rpc,电脑端加一个ttl转usb模块。否则代码报错了你都不知道。”你的意思是我需要加一个串口调试扩展板 uart 转usb 的板子来调试程序是么?

还有我现在的IDE 环境直接调用popular features as the remote device 示例脚本,会报错"no module named serial",我看是import rpc 时需要import serial .但是IDE 没有找到serial。