Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 2 months ago.
Delayed PC output Python/RPC
I'm a relative beginner so any help is much appreciated.
I am running RPC over Serial and interfacing with python. Currently, I have an RPCFunction set up to pass a string from my PC to the mbed. There should be multiple prints when the function runs as I am trying to debug but they seem to get backed up and print one message every time I run the function. The output will be more clear than me explaining.
mbed code
#include "mbed.h" #include "mbed_rpc.h" #include <string> #include <iostream> using namespace std; Serial pc(USBTX, USBRX); string msg("TEST: "); void DoEcho(Arguments* input, Reply* output); RPCFunction Echo(&DoEcho, "Echo"); void DoEcho(Arguments* input, Reply* output) { output->putData(input->argv[0]); msg += input->argv[0]; pc.printf("DoEcho: %s\n", msg); } int main() { // receive commands, and send back the responses 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("OUTPUT: %s\n", outbuf); } }
Python on PC
$ python >>> from mbedRPC import * >>> serdev = "/dev/ttyACM0" >>> mbed = SerialRPC(serdev, 9600) >>> echo = RPCFunction(mbed, "Echo") >>> echo.run("Ant") 'OUTPUT: Echo RPC' >>> echo.run("Eat") 'DoEcho: TEST: Eat' >>> echo.run("Tree") 'OUTPUT: Eat' >>> echo.run("Cow") 'DoEcho: TEST: EatTree' >>> echo.run("Sand") 'OUTPUT: Tree' >>> echo.run("Burger") 'DoEcho: TEST: EatTreeCow'
Context:
My end goal is to pass a string from the pc to the mbed, then relay it to another mbed via i2c. I can do both of these things separately but when I combine both the i2c handling and RPC in the main things have fallen apart. I was using these prints to debug that issue but they were not helpful when they did not display.
It appears that this was an issue with the "\n" in printf. Removing this allowed me to get all output I was expecting.
posted by Mark Engstrom 07 Oct 2015