Myserial Library extends RawSerial

Committer:
naao
Date:
Thu Jul 03 02:37:41 2014 +0000
Revision:
11:34ae126807a0
Parent:
9:981384455445
Child:
12:02b3877b48c6
changed library RawSerial to Serial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
naao 0:5b0b84a10bba 1 #include "MySerial.h"
naao 0:5b0b84a10bba 2
naao 11:34ae126807a0 3 MySerial::MySerial(PinName tx,PinName rx, char *name):Serial(tx,rx,name) //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 9:981384455445 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 0:5b0b84a10bba 19 memset(cWord, '\0', strlen(cWord)); //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 }