Kuldip Maharjan
/
string_serial
Capturing string from serial port
Revision 0:d5aa0b91d111, committed 2014-01-08
- Comitter:
- kuldipmaharjan
- Date:
- Wed Jan 08 00:26:07 2014 +0000
- Commit message:
- capturing sting from serial ports
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r d5aa0b91d111 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jan 08 00:26:07 2014 +0000 @@ -0,0 +1,50 @@ +//Author: Kuldip Maharjan +//Email : kuldipmaharjan@gmail.com +//Anyone can use this code if it helps in their projects or +//for learning programing in mbed besides for commercial purposes + +//capturing string from serial ports + +#include "mbed.h" +#include "stdio.h" +#include "string.h" + +char* string_capture (char* result_string); + +Serial pc(USBTX, USBRX); // tx, rx +Serial s1(p9,p10); // tx, rx +Serial s2(p28,p27); // tx, rx + +int main() +{ + char str[1024]= ""; + pc.baud(9600); + s1.baud(9600); + s2.baud(9600); + while(1) { + pc.printf("putting $ to indicate beginning of string \n"); + s1.putc('$'); + if (s2.getc() == '$') { + pc.printf("beginning capturing string \n"); + //s1.putc('3'); + pc.printf("\n the returned string is %s",string_capture(str)); + } + wait(2); + } +} + +char* string_capture (char* result_string) +{ + char str1[25]= ""; + do + { + s1.putc(pc.getc()); //here we can get character from pc terminal + str1[0]=s2.getc(); + strcat(result_string,str1); + //while (!pc.readable()) {}; //gets stuck here until it get smth from pc + wait(0.1); + } while (str1[0] != '!'); + return result_string; +} + +
diff -r 000000000000 -r d5aa0b91d111 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Jan 08 00:26:07 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ed12d17f06 \ No newline at end of file