logo

H7 Plus如何通过modbus把数据传输下图0x0000里面?

2021-07-09 17:56
1
Pro
bea0137f-cf36-4d11-ae63-42ac26a317ee.png
2021-07-09 19:28
I
网红小智智 星瞳科技

https://singtown.com/learn/50806/

这个代码OpenMV是slave模式,不是master模式。

2021-07-09 20:02
1
Pro

@kidswong999 那我应该怎么编写程序呢?

2021-07-09 20:08
1
Pro

@kidswong999

import sensor, image, time, pyb
from pyb import UART
from modbus import ModbusRTU

uart = UART(1,9600, parity=None, stop=2, timeout=1, timeout_char=4)
modbus = ModbusRTU(uart, slave_id=1, register_num=9999)
sensor.reset()
sensor.set_pixformat(sensor.RGB565) #GRAYSCALE,RGB565
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
led = pyb.LED(3)

while(True):
    clock.tick()
    img = sensor.snapshot().lens_corr(1.8)
    for c in img.find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10,r_min = 2, r_max = 100, r_step = 2):
        img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
        if modbus.any():
            modbus.handle(debug=True)
        else:
            led.on()
            time.sleep_ms(100)
            modbus.REGISTER[0] = ('%d' % c.x())
            modbus.REGISTER[2] = ('%d' % c.y())
            led.off()
            print(modbus.REGISTER[0],modbus.REGISTER[2],sep=" ")

这是我写的一个查找圆中心传送到modbus的代码,请问是否正确

2021-07-10 20:27
I
网红小智智 星瞳科技

不正确, modbus.REGISTER[0] = ('%d' % c.x()),不应该是字符串。

参考:https://book.openmv.cc/example/32-Modbus/modbus-apriltag.html