3 years, 11 months ago.

How to create objects dynamically with mbed_rpc

I've been very successful controlling pre instantiated objects over a serial port with mbed_rpc, but I've been unable to create objects on the fly. I tried adding the add_rpc_class method calls to my example but that didn't help.

mbed_rpc test

#include "mbed.h"
#include "mbed_rpc.h"
int main()

// they calls didn't seem to do much
//    RPC::add_rpc_class<RpcAnalogIn>();
//    RPC::add_rpc_class<RpcPwmOut>();

    RpcPwmOut rpc_p(PA_5,"p");
    RpcAnalogIn rpc_ain(PC_0,"a");
    Serial pc(USBTX, USBRX);

    char buf[256], outbuf[256]; 
    while(1) {
        pc.gets(buf, 256);
    //Call the static call method on the RPC class
        RPC::call(buf, outbuf); 
        pc.printf("%s\n", outbuf);                    

If I send over the serial port:

"/DigitalOut/new PA_4 anled \r\n"

"/anled/write 1"

nothing happens because "anled" is not pre declared/instantiated in the code. But if i send: "/p/write 0.5"

this works because the "p" object is pre declared/instantiated in the code. Any ideas on how to dynamically create objects over the serial port ?

Be the first to answer this question.