Scott Hoppe / MTS_SPI

Fork of MTS-Serial by Scott Hoppe

Embed: (wiki syntax)

« Back to documentation index

MTSSerial Class Reference

MTSSerial Class Reference

This class derives from MTSBufferedIO and provides a buffered wrapper to the standard mbed Serial class. More...

#include <MTSSerial.h>

Inherits mts::MTSBufferedIO.

Inherited by MTSSerialFlowControl.

Public Member Functions

 MTSSerial (PinName TXD, PinName RXD, int txBufferSize=256, int rxBufferSize=256)
 Creates a new MTSSerial object that can be used to talk to an mbed serial port through internal SW buffers.
 ~MTSSerial ()
 Destructs an MTSSerial object and frees all related resources, including internal buffers.
void baud (int baudrate)
 This method is used to the set the baud rate of the serial port.
void format (int bits=8, SerialBase::Parity parity=mbed::SerialBase::None, int stop_bits=1)
 This method sets the transmission format used by the serial port.
int write (const char *data, int length, unsigned int timeoutMillis)
 This method enables bulk writes to the Tx or write buffer.
int write (const char *data, int length)
 This method enables bulk writes to the Tx or write buffer.
int write (char data, unsigned int timeoutMillis)
 This method attempts to write a single byte to the tx buffer within the timeout period.
int write (char data)
 This method writes a single byte as a char to the Tx or write buffer.
int writef (const char *format,...)
 This method enables bulk writes to the Tx or write buffer.
int writeable ()
 This method is used to get the space available to write bytes to the Tx buffer.
int read (char *data, int length, unsigned int timeoutMillis)
 This method enables bulk reads from the Rx or read buffer.
int read (char *data, int length)
 This method enables bulk reads from the Rx or read buffer.
int read (char &data, unsigned int timeoutMillis)
 This method reads a single byte from the Rx or read buffer.
int read (char &data)
 This method reads a single byte from the Rx or read buffer.
int readable ()
 This method is used to get the number of bytes available to read from the Rx or read buffer.
bool txEmpty ()
 This method determines if the Tx or write buffer is empty.
bool rxEmpty ()
 This method determines if the Rx or read buffer is empty.
bool txFull ()
 This method determines if the Tx or write buffer is full.
bool rxFull ()
 This method determines if the Rx or read buffer is full.
virtual void txClear ()
 This method clears all the data from the internal Tx or write buffer.
virtual void rxClear ()
 This method clears all the data from the internal Rx or read buffer.

Detailed Description

This class derives from MTSBufferedIO and provides a buffered wrapper to the standard mbed Serial class.

Since it depends only on the mbed Serial class for accessing serial data, this class is inherently portable accross different mbed platforms.

Definition at line 14 of file MTSSerial.h.


Constructor & Destructor Documentation

MTSSerial ( PinName  TXD,
PinName  RXD,
int  txBufferSize = 256,
int  rxBufferSize = 256 
)

Creates a new MTSSerial object that can be used to talk to an mbed serial port through internal SW buffers.

Parameters:
TXDthe transmit data pin on the desired mbed Serial interface.
RXDthe receive data pin on the desired mbed Serial interface.
txBufferSizethe size in bytes of the internal SW transmit buffer. The default is 256 bytes.
rxBufferSizethe size in bytes of the internal SW receive buffer. The default is 256 bytes.

Definition at line 7 of file MTSSerial.cpp.

~MTSSerial (  )

Destructs an MTSSerial object and frees all related resources, including internal buffers.

Definition at line 14 of file MTSSerial.cpp.


Member Function Documentation

void baud ( int  baudrate )

This method is used to the set the baud rate of the serial port.

Parameters:
baudratethe baudrate in bps as an int. The default is 9600 bps.

Definition at line 18 of file MTSSerial.cpp.

void format ( int  bits = 8,
SerialBase::Parity  parity = mbed::SerialBase::None,
int  stop_bits = 1 
)

This method sets the transmission format used by the serial port.

Parameters:
bitsthe number of bits in a word (5-8; default = 8)
paritythe parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
stopthe number of stop bits (1 or 2; default = 1)

Definition at line 23 of file MTSSerial.cpp.

int read ( char *  data,
int  length,
unsigned int  timeoutMillis 
) [inherited]

This method enables bulk reads from the Rx or read buffer.

It attempts to read the amount specified, but will complete early if the specified timeout expires.

Parameters:
datathe buffer where data read will be added to.
lengththe amount of data in bytes to be read into the buffer. amount of time to complete operation.
Returns:
the total number of bytes that were read.

Definition at line 78 of file MTSBufferedIO.cpp.

int read ( char *  data,
int  length 
) [inherited]

This method enables bulk reads from the Rx or read buffer.

This method blocks until the amount of data requested is received.

Parameters:
datathe buffer where data read will be added to.
lengththe amount of data in bytes to be read into the buffer.
Returns:
the total number of bytes that were read. This should be equal to the length parameter since this is a blocking call.

Definition at line 90 of file MTSBufferedIO.cpp.

int read ( char &  data,
unsigned int  timeoutMillis 
) [inherited]

This method reads a single byte from the Rx or read buffer.

This method attempts to read a byte, but will return without reading one if the specified timeout is reached.

Parameters:
datachar where the read byte will be stored. amount of time to complete operation.
Returns:
1 if byte is read or 0 if no byte is available.

Definition at line 100 of file MTSBufferedIO.cpp.

int read ( char &  data ) [inherited]

This method reads a single byte from the Rx or read buffer.

This method blocks until the single byte is read.

Parameters:
datachar where the read byte will be stored.
Returns:
1 once the byte has been read.

Definition at line 105 of file MTSBufferedIO.cpp.

int readable (  ) [inherited]

This method is used to get the number of bytes available to read from the Rx or read buffer.

Returns:
the number of bytes available, 0 if there are no bytes to read.

Definition at line 110 of file MTSBufferedIO.cpp.

void rxClear (  ) [virtual, inherited]

This method clears all the data from the internal Rx or read buffer.

Reimplemented in MTSSerialFlowControl.

Definition at line 139 of file MTSBufferedIO.cpp.

bool rxEmpty (  ) [inherited]

This method determines if the Rx or read buffer is empty.

Returns:
true if empty, otherwise false.

Definition at line 119 of file MTSBufferedIO.cpp.

bool rxFull (  ) [inherited]

This method determines if the Rx or read buffer is full.

Returns:
true if full, otherwise false.

Definition at line 129 of file MTSBufferedIO.cpp.

void txClear (  ) [virtual, inherited]

This method clears all the data from the internal Tx or write buffer.

Definition at line 134 of file MTSBufferedIO.cpp.

bool txEmpty (  ) [inherited]

This method determines if the Tx or write buffer is empty.

Returns:
true if empty, otherwise false.

Definition at line 114 of file MTSBufferedIO.cpp.

bool txFull (  ) [inherited]

This method determines if the Tx or write buffer is full.

Returns:
true if full, otherwise false.

Definition at line 124 of file MTSBufferedIO.cpp.

int write ( const char *  data,
int  length 
) [inherited]

This method enables bulk writes to the Tx or write buffer.

This method blocks until all the bytes are written.

Parameters:
datathe byte array to be written.
lengththe length of data to be written from the data parameter.
Returns:
the number of bytes written to the buffer, which should be equal to the length parameter since this method blocks.

Definition at line 49 of file MTSBufferedIO.cpp.

int write ( char  data ) [inherited]

This method writes a single byte as a char to the Tx or write buffer.

This method blocks until the byte is written.

Parameters:
datathe byte to be written as a char.
Returns:
1 once the byte has been written.

Definition at line 69 of file MTSBufferedIO.cpp.

int write ( char  data,
unsigned int  timeoutMillis 
) [inherited]

This method attempts to write a single byte to the tx buffer within the timeout period.

Parameters:
datathe byte to be written as a char. amount of time in milliseconds to complete operation.
Returns:
1 if the byte was written or 0 if the buffer was full and the timeout expired.

Definition at line 64 of file MTSBufferedIO.cpp.

int write ( const char *  data,
int  length,
unsigned int  timeoutMillis 
) [inherited]

This method enables bulk writes to the Tx or write buffer.

If more data is requested to be written then space available the method writes as much data as possible within the timeout period and returns the actual amount written.

Parameters:
datathe byte array to be written.
lengththe length of data to be written from the data parameter. amount of time in milliseconds to complete operation.
Returns:
the number of bytes written to the buffer, which is 0 if the buffer is full.

Definition at line 30 of file MTSBufferedIO.cpp.

int writeable (  ) [inherited]

This method is used to get the space available to write bytes to the Tx buffer.

Returns:
the number of bytes that can be written, 0 if the buffer is full.

Definition at line 74 of file MTSBufferedIO.cpp.

int writef ( const char *  format,
  ... 
) [inherited]

This method enables bulk writes to the Tx or write buffer.

This method blocks until all the bytes are written.

Parameters:
formatof the string to be written.
additionalarguments will be placed in the format string.
Returns:
the number of bytes written to the buffer.

Definition at line 17 of file MTSBufferedIO.cpp.