Myserial Library extends RawSerial
MySerial.h
- Committer:
- naao
- Date:
- 2014-07-04
- Revision:
- 16:596e062f6c45
- Parent:
- 15:a0b05e764268
File content as of revision 16:596e062f6c45:
/** mbed Serial Library extend RawSerial * Copyright (c) 2014 Naoki Okino * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #ifndef MBED_MYSERIAL_H #define MBED_MYSERIAL_H #include "mbed.h" /** MySerial control class, based on a RawSerial * * Example: * @code * #include "mbed.h" * #include "MySerial.h" * * MySerial pc(USBTX,USBRX); //instance of MySerial Class * char cWord[16]; //receive chars or cWord[256], cWord[1024] etc.. * int readSize = 15; * * void readbuf() * { * if (readSize >= sizeof(cWord)) { readSize = sizeof(cWord)-1; } * // int iRtn = pc.GetString(readSize,&cWord); //Serial received chars by pointer cWord * int iRtn = pc.GetString(readSize,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 */ class MySerial : public Serial{ public: /** 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 chars by serial * * @param int size for get chars * @param *cWord returns got chars by pointer * @param returns success by 0 */ virtual int GetString(int size, char *cWord); /** overload function to get chars after received chars by serial * * @param int size for get chars * @param cWord returns got chars by ref * @param returns success by 0 */ template <class X> int GetString(int size, X cWord) { return GetString(size, &cWord); } protected: float fRxStartWait; float fRxEachWait; }; /* class MySerial */ #endif