![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Use of the rpc library on the freedom kl25Z. Simple program to enable use of digital pins, and an example of a custom rpc function to access the analog pins
Using pyserial in python for the serial communication
Some python code to run the RPC function on embedded on the card.
import numpy as np import serial import time ser=serial.Serial(3,57600, parity='N',bytesize=8,stopbits=1, timeout=None, xonxoff=1) for i in range(0,100): ser.write(b"/AnIn/run\n") print(time.clock(),ser.readline()) ser.close()
Revision 0:42d2df2b1c47, committed 2014-12-01
- Comitter:
- sas37
- Date:
- Mon Dec 01 10:05:56 2014 +0000
- Commit message:
- testing the freedom RPC interface
Changed in this revision
diff -r 000000000000 -r 42d2df2b1c47 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Dec 01 10:05:56 2014 +0000 @@ -0,0 +1,54 @@ +/* getting the RPC working on the Freedom Boards + +Able to initialise the digital classes, but not the analoge functions for this board + +A simple wrapper function is provided which sets up an analoge input on PTC2 which can then accessed +by sending /AnIn/run down the serial line. + +*/ + +#include "mbed.h" +#include "mbed_rpc.h" + + + +using namespace mbed; + +AnalogIn Ain(PTC2); + +Serial pc(USBTX, USBRX); + + +void doSAnalogeIn(Arguments* input, Reply * output ); + +RPCFunction AnIn(&doSAnalogeIn,"AnIn"); + + + +int main() { + pc.baud(57600); + // call the static RPC member functions to add classes to the list available + // these appear to be listed in rpcclasses.h, and are templated + RPC::add_rpc_class<RpcDigitalIn>(); + RPC::add_rpc_class<RpcDigitalOut>(); + //RPC::add_rpc_class<RpcAnalogIn>(); + //RPC::add_rpc_class<RpcAnalogOut>(); + + // receive commands, and send back the responses + char buf[RPC_MAX_STRING], outbuf[RPC_MAX_STRING]; + while(1) { + pc.gets(buf, RPC_MAX_STRING); + RPC::call(buf, outbuf); + pc.printf("%s\n", outbuf); + } + +}; + +void doSAnalogeIn(Arguments * input, Reply * output) +{ + //custom code to add access to the Analoge ports + + output->putData(Ain.read()); +}; + +
diff -r 000000000000 -r 42d2df2b1c47 mbed-rpc.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rpc.lib Mon Dec 01 10:05:56 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/mbed-official/code/mbed-rpc/#2a26fd6a2b36
diff -r 000000000000 -r 42d2df2b1c47 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Dec 01 10:05:56 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file