MVCam H7 to IBM Cloud Services

Hello,

I got the RPC working great and am able to transfer images, very exciting. However, I am currently stuck on an issue. Im connecting via usb, and with slave master,
1.) I’m not sure how to get the the master to send data to the slave, like a string for example
2.) I cant write my own function in the slave that returns text

I tried the code below and it wouldn’t work.


import image, network, math, rpc, sensor, struct, tf

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

interface = rpc.rpc_usb_vcp_slave()

def jpeg_snapshot(data):
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    return sensor.snapshot().compress(quality=90).bytearray()

def process_ready():
    return "True"

# Register call backs.
interface.register_callback(jpeg_snapshot)
interface.register_callback(process_ready)

# Once all call backs have been registered we can start
# processing remote events. interface.loop() does not return.

interface.loop()

Hi, did you read the API? It’s clear that it will only call a function that takes an argument and returns an argument… E.g. you have to add an unused argument to the process_ready() method. You should also convert the “True” message to a byte array.

Thank you so much! I did read, but had trouble following in parts. How can the master send data to slave?

Just updated my code and had no luck.

import image, network, math, rpc, sensor, struct, tf

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

interface = rpc.rpc_usb_vcp_slave()

def jpeg_snapshot(data):
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    return sensor.snapshot().compress(quality=90).bytearray()

def ready(s):
    return "true".bytearray()


# Register call backs.
interface.register_callback(jpeg_snapshot)
interface.register_callback(ready)

# Once all call backs have been registered we can start
# processing remote events. interface.loop() does not return.

interface.loop()

Take a look at the other example scripts… In particular, the popular features one.

Also, what you wrote is not valid python. Strings have no .bytearray() method. You have to use the .encode() method.

The argument passed to the method is what the slave receives.

The master does .call(“method_name”, argument) and the slave gets the argument in the function that is called. Whatever the slave returns will be what the master receives as the return value to call().

Okay, thank your for your patience and reply. I also wanted to verify when sending an argument from master should i do struct.pack(argument) and then struc.unpack(data) on the slave end. Will this maintain the variable type of the argument?

Hello,

I wanted to follow up on the python request module and see if there was an update to this.

Sincerely,
Andrew karam

Hi, I’ve been sucked into other things. It’s in my todo list. However, I don’t expect to finish it soon.