Myserial Library extends RawSerial

Committer:
naao
Date:
Fri Jul 04 11:10:06 2014 +0000
Revision:
16:596e062f6c45
Parent:
15:a0b05e764268
fixed exmaple

Who changed what in which revision?

UserRevisionLine numberNew contents of line
naao 0:5b0b84a10bba 1 #include "MySerial.h"
naao 0:5b0b84a10bba 2
naao 14:8bd054a87ac5 3 MySerial::MySerial(PinName tx,PinName rx):Serial(tx,rx) //constructor
naao 0:5b0b84a10bba 4 {
naao 9:981384455445 5 fRxStartWait = 0.01; //wait getting a 1st char after interrupted
naao 9:981384455445 6 fRxEachWait = 0.001; //wait getting each char
naao 9:981384455445 7 }
naao 9:981384455445 8
naao 9:981384455445 9 void MySerial::SetRxWait(float _fRxStartWait, float _fRxEachWait)
naao 9:981384455445 10 {
naao 9:981384455445 11 fRxStartWait = _fRxStartWait; //wait getting a 1st char after interrupted
naao 14:8bd054a87ac5 12 fRxEachWait = _fRxEachWait; //wait getting each char
naao 0:5b0b84a10bba 13 }
naao 0:5b0b84a10bba 14
naao 0:5b0b84a10bba 15 int MySerial::GetString(int size, char *cWord) //by pointer
naao 0:5b0b84a10bba 16 {
naao 0:5b0b84a10bba 17 int i=0;
naao 0:5b0b84a10bba 18 int ichar;
naao 15:a0b05e764268 19 memset(cWord, '\0', size+1); //initialise chars
naao 0:5b0b84a10bba 20
naao 9:981384455445 21 wait(fRxStartWait);
naao 8:a7aaafa19db6 22
naao 0:5b0b84a10bba 23 while(1) {
naao 0:5b0b84a10bba 24 if(!readable()) {
naao 0:5b0b84a10bba 25 break;
naao 0:5b0b84a10bba 26 }
naao 0:5b0b84a10bba 27 ichar = getc();
naao 0:5b0b84a10bba 28 if(i<size) {
naao 0:5b0b84a10bba 29 cWord[i] =ichar;
naao 3:e4c443ce0fbe 30 //putc(ichar);
naao 0:5b0b84a10bba 31 }
naao 0:5b0b84a10bba 32 i++;
naao 9:981384455445 33 wait(fRxEachWait);
naao 0:5b0b84a10bba 34 }
naao 0:5b0b84a10bba 35 return 0;
naao 0:5b0b84a10bba 36 }