Serial library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems

Dependents:   mDot_AT_firmware mtsas mtsas MTDOT-EVB-LinkCheck-AL ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MTSSerial.h Source File

MTSSerial.h

00001 #ifndef MTSSERIAL_H
00002 #define MTSSERIAL_H
00003 
00004 #include "MTSBufferedIO.h"
00005 
00006 namespace mts
00007 {
00008 
00009 /** This class derives from MTSBufferedIO and provides a buffered wrapper to the
00010 * standard mbed Serial class. Since it depends only on the mbed Serial class for
00011 * accessing serial data, this class is inherently portable accross different mbed
00012 * platforms.
00013 */
00014 class MTSSerial : public MTSBufferedIO
00015 {
00016 public:
00017     /** Creates a new MTSSerial object that can be used to talk to an mbed serial port
00018     * through internal SW buffers.
00019     *
00020     * @param TXD the transmit data pin on the desired mbed Serial interface.
00021     * @param RXD the receive data pin on the desired mbed Serial interface.
00022     * @param txBufferSize the size in bytes of the internal SW transmit buffer. The
00023     * default is 256 bytes.
00024     * @param rxBufferSize the size in bytes of the internal SW receive buffer. The
00025     * default is 256 bytes.
00026     */
00027     MTSSerial(PinName TXD, PinName RXD, int txBufferSize = 256, int rxBufferSize = 256);
00028 
00029     /** Destructs an MTSSerial object and frees all related resources, including
00030     * internal buffers.
00031     */
00032     ~MTSSerial();
00033 
00034     /**
00035      * Attach the internal serial object to provided pins
00036      * @param TXD the transmit data pin on the desired mbed Serial interface.
00037      * @param RXD the receive data pin on the desired mbed Serial interface.
00038      */
00039     void reattach(PinName TXD, PinName RXD);
00040 
00041     /** This method is used to the set the baud rate of the serial port.
00042     *
00043     * @param baudrate the baudrate in bps as an int. The default is 9600 bps.
00044     */
00045     void baud(int baudrate);
00046 
00047     /** This method sets the transmission format used by the serial port.
00048     *
00049     * @param bits the number of bits in a word (5-8; default = 8)
00050     * @param parity the parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even,
00051     * SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
00052     * @param stop the number of stop bits (1 or 2; default = 1)
00053     */
00054     void format(int bits=8, SerialBase::Parity parity=mbed::SerialBase::None, int stop_bits=1);
00055 
00056     /** Generate a break condition on the serial line
00057      */
00058     void sendBreak();
00059 
00060 protected:
00061     RawSerial* _serial; // Internal mbed Serial object
00062     int _baudrate;
00063     int _bits;
00064     SerialBase::Parity _parity;
00065     int _stop_bits;
00066 
00067 
00068 private:
00069     virtual void handleWrite(); // Method for handling data to be written
00070     virtual void handleRead(); // Method for handling data to be read
00071 };
00072 
00073 }
00074 
00075 #endif /* MTSSERIAL_H */