Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- kuldipmaharjan
- Date:
- 2014-01-08
- Revision:
- 0:d5aa0b91d111
File content as of revision 0:d5aa0b91d111:
//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;
}