6 years, 4 months 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

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


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;
Be the first to answer this question.