10 years ago.

RPCFunction call from MATLAB R2014a

I'm trying to call an mbed function from MATLAB 2014a and not had much luck.

The output from MATLAB is:

Matlab output

 Successfully connected to mbed
Objects that can be created or used:
  RangeFinder AnalogOut Serial BusInOut BusIn BusOut Timer PwmOut DigitalInOut DigitalOut DigitalIn AnalogIn Base

Tied MATLAB to existing RPCFunction on mbed
Error using mbed.RPCFunction/run (line 42)
Not enough input arguments.

Error in mbedB (line 11)
range = RangeFinder.run; 


Looks like there is an issue in passing arguments, but the mbed example online didn't try pass anything

The MATLAB M file is based on code from the Rangefinder example

Code on Matlab to call function on mbed

 mymbed= SerialRPC('COM5', 9600);
%device = Serial(mymbed,'%s');

%if you need to reset mbed
mymbed.reset;

%Attach to an Existing RPCFunction on mbed
RangeFinder = RPCFunction(mymbed, 'flip');
%Run its methods
range = RangeFinder.run;


mymbed.delete;
clear;

Here is the code I have on the mbed

RPCFunction test

#include "mbed.h"
#include "mbed-rpc.h"

 
 
SerialRPCInterface RPC(USBTX, USBRX); 
void flip(char *input, char *output); 
Timeout flipper;
DigitalOut led1(LED1);
DigitalOut led2(LED2);

 
void flip(char *input, char *output)  {
    led2 = !led2;
}
 
 
int main() {
    led2 = 1;
    RPCFunction RangeFinder(&flip, "RangeFinder");
 
    // spin in a main loop. Matlab will interrupt it to call flip
    while(1) {
        led1 = !led1;
        wait(0.2);
    }
}
Be the first to answer this question.