Myserial Library extends RawSerial

Files at this revision

API Documentation at this revision

Comitter:
naao
Date:
Tue Jun 24 08:58:43 2014 +0000
Parent:
8:a7aaafa19db6
Child:
10:930d325f3d31
Commit message:
added procedure to set rx wait time

Changed in this revision

MySerial.cpp Show annotated file Show diff for this revision Revisions of this file
MySerial.h Show annotated file Show diff for this revision Revisions of this file
--- a/MySerial.cpp	Tue Jun 24 03:16:30 2014 +0000
+++ b/MySerial.cpp	Tue Jun 24 08:58:43 2014 +0000
@@ -2,6 +2,14 @@
 
 MySerial::MySerial(PinName tx,PinName rx):RawSerial(tx,rx)          //constructor
 {
+    fRxStartWait = 0.01;    //wait getting a 1st char after interrupted
+    fRxEachWait = 0.001;    //wait getting each char
+}
+
+void MySerial::SetRxWait(float _fRxStartWait, float _fRxEachWait)
+{
+    fRxStartWait = _fRxStartWait;   //wait getting a 1st char after interrupted
+    fRxEachWait = _fRxEachWait;     //wait getting each char
 }
 
 int MySerial::GetString(int size, char *cWord)            //by pointer
@@ -10,7 +18,7 @@
     int ichar;
     memset(cWord, '\0', strlen(cWord));  //initialise chars
 
-    wait(0.01);
+    wait(fRxStartWait);
 
     while(1) {
         if(!readable())    {
@@ -22,7 +30,7 @@
             //putc(ichar);
         }
         i++;
-        wait(0.001);
+        wait(fRxEachWait);
     }
     return 0;
 }
--- a/MySerial.h	Tue Jun 24 03:16:30 2014 +0000
+++ b/MySerial.h	Tue Jun 24 08:58:43 2014 +0000
@@ -30,6 +30,9 @@
  *    int iRtn =  pc.GetString(6,cWord); //Serial received chars byref of cWord
  * }
  * int main() {
+ *    pc.baud(9600);                  //set baud rate
+ *    pc.format(8, MySerial::None, 1);//set bits for a byte, parity bit, stop bit
+ *    pc.SetRxWait(0.01, 0.001);       //set wait getting chars after interrupted, each char
  *    pc.attach( readbuf, MySerial::RxIrq );    //Set Interrupt by Serial receive
  * }
  * @endcode
@@ -37,13 +40,20 @@
 class MySerial : public RawSerial{
     
 public:
-    /** get chars received by serial
+    /** constructor to get chars received by serial
      * 
      * @param PinName tx
      * @param PinName rx
      */
     MySerial(PinName tx, PinName rx);
    
+    /** set wait getting chars after interrupted
+     * 
+     * @param float _fRxStartWait wait getting a 1st char after interrupted
+     * @param float _fRxEachWait wait getting each char
+    */
+    void SetRxWait(float _fRxStartWait, float _fRxEachWait);
+
     /** function to get chars after received shars by serial
      * 
      * @param int size for get chars
@@ -64,7 +74,8 @@
     }
 
 protected:
-
+    float fRxStartWait;
+    float fRxEachWait;
 };
 
 #endif
\ No newline at end of file