Myserial Library extends RawSerial
MySerial.h
- Committer:
- naao
- Date:
- 2014-06-23
- Revision:
- 7:d5fe75a0a885
- Parent:
- 6:7853f8641372
- Child:
- 9:981384455445
File content as of revision 7:d5fe75a0a885:
/** 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.. * * void readbuf() * { * // int iRtn = pc.GetString(6,&cWord); //Serial received chars by pointer cWord * int iRtn = pc.GetString(6,cWord); //Serial received chars byref of cWord * } * int main() { * pc.attach( readbuf, MySerial::RxIrq ); //Set Interrupt by Serial receive * } * @endcode */ class MySerial : public RawSerial{ public: /** get chars received by serial * * @param PinName tx * @param PinName rx */ MySerial(PinName tx, PinName rx); /** function to get chars after received shars 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); /** override function to get chars after received shars by serial * * @param int size for get chars * @param (&cWord)[16] returns got chars by ref * @param returns success by 0 */ template <class X> int GetString(int size, X cWord) { return GetString(size, &cWord); } protected: }; #endif