Serial Port
Public Member Functions
SerialPort< PortNumber, RxBufSize, TxBufSize > Class Template Reference

Class for avr hardware USART ports. More...

#include <SerialPort.h>

List of all members.

Public Member Functions

 SerialPort ()
int available (void)
void begin (uint32_t baud, uint8_t options=SP_8_BIT_CHAR)
void clearRxError ()
void end ()
void flush ()
void flushRx ()
void flushTx ()
uint8_t getRxError ()
int peek (void)
int read ()
size_t read (uint8_t *b, size_t n)
size_t write (const char *s)
size_t write (uint8_t b)
size_t write (const __FlashStringHelper *s)
size_t write (const uint8_t *b, size_t n)
size_t write_P (PGM_P b, size_t n)
size_t writeln (const char *s)
size_t writeln ()
size_t writeln (const __FlashStringHelper *s)

Detailed Description

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
class SerialPort< PortNumber, RxBufSize, TxBufSize >

Class for avr hardware USART ports.

Definition at line 300 of file SerialPort.h.


Constructor & Destructor Documentation

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
SerialPort< PortNumber, RxBufSize, TxBufSize >::SerialPort ( ) [inline]

Constructor

Definition at line 304 of file SerialPort.h.


Member Function Documentation

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
int SerialPort< PortNumber, RxBufSize, TxBufSize >::available ( void  ) [inline]
Returns:
The number of bytes (characters) available for reading from the serial port.

Definition at line 320 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
void SerialPort< PortNumber, RxBufSize, TxBufSize >::begin ( uint32_t  baud,
uint8_t  options = SP_8_BIT_CHAR 
) [inline]

Sets the data rate in bits per second (baud) for serial data transmission.

Parameters:
[in]baudRate in bits per second (baud).
[in]optionsconstructed by a bitwise-inclusive OR of values from the following list. Choose one value for stop bit, parity, and character size.
  • SP_1_STOP_BIT - Use one stop bit (default if stop bit not specified).
  • SP_2_STOP_BIT - Use two stop bits.
  • SP_NO_PARITY - No parity bit (default if parity not specified).
  • SP_EVEN_PARITY - Add even parity bit.
  • SP_ODD_PARITY - Add odd parity bit.
  • SP_5_BIT_CHAR - Use 5-bit characters (default if size not specified).
  • SP_6_BIT_CHAR - Use 6-bit characters.
  • SP_7_BIT_CHAR - Use 7-bit characters.
  • SP_8_BIT_CHAR - Use 8-bit characters.

The default is SP_8_BIT_CHAR which results in one stop bit, no parity, and 8-bit characters.

Definition at line 349 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
void SerialPort< PortNumber, RxBufSize, TxBufSize >::clearRxError ( ) [inline]

Clear RX error bits.

Definition at line 382 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
void SerialPort< PortNumber, RxBufSize, TxBufSize >::end ( ) [inline]

Disables serial communication, allowing the RX and TX pins to be used for general input and output. To re-enable serial communication, call SerialPort::begin().

Definition at line 398 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
void SerialPort< PortNumber, RxBufSize, TxBufSize >::flush ( ) [inline]

For Arduino 1.0 and greater call flushTx().

Definition at line 412 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
void SerialPort< PortNumber, RxBufSize, TxBufSize >::flushRx ( ) [inline]

Discard any buffered incoming serial data.

Definition at line 417 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
void SerialPort< PortNumber, RxBufSize, TxBufSize >::flushTx ( ) [inline]

Waits for the transmission of outgoing serial data to complete.

Definition at line 429 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
uint8_t SerialPort< PortNumber, RxBufSize, TxBufSize >::getRxError ( ) [inline]
Returns:
RX error bits. Possible error bits are:

Definition at line 390 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
int SerialPort< PortNumber, RxBufSize, TxBufSize >::peek ( void  ) [inline]
Returns:
The first byte of incoming serial data available or -1 if no data is available. -1 is always returned for unbuffered RX.

Definition at line 439 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
int SerialPort< PortNumber, RxBufSize, TxBufSize >::read ( ) [inline]

Read incoming serial data.

Returns:
The first byte of incoming serial data available or -1 if no data is available.

Definition at line 450 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
size_t SerialPort< PortNumber, RxBufSize, TxBufSize >::read ( uint8_t *  b,
size_t  n 
) [inline]

Read incoming serial data. Stop when RX buffer is empty or n bytes have been read.

Parameters:
[in]bThe location to receive the data.
[in]nMaximum number of bytes to read.
Returns:
The number of bytes read.

Definition at line 472 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
size_t SerialPort< PortNumber, RxBufSize, TxBufSize >::write ( const __FlashStringHelper *  s) [inline]

Write a flash string to the serial port.

Parameters:
[in]sThe string to be written.
Returns:
The number of bytes written to the serial port.

Definition at line 568 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
size_t SerialPort< PortNumber, RxBufSize, TxBufSize >::write ( const char *  s) [inline]

Write a string to the serial port.

Parameters:
[in]sThe string to be written.
Returns:
The number of bytes written to the serial port

Definition at line 620 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
size_t SerialPort< PortNumber, RxBufSize, TxBufSize >::write ( const uint8_t *  b,
size_t  n 
) [inline]

Write binary data to the serial port.

Parameters:
[in]bLocation of the bytes to be written.
[in]nThe number of bytes to write.
Returns:
The number of bytes written to the serial port.

Definition at line 594 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
size_t SerialPort< PortNumber, RxBufSize, TxBufSize >::write ( uint8_t  b) [inline]

Write binary data to the serial port.

Parameters:
[in]bThe byte to be written.
Returns:
The number of bytes written to the serial port.

Definition at line 498 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
size_t SerialPort< PortNumber, RxBufSize, TxBufSize >::write_P ( PGM_P  b,
size_t  n 
) [inline]

Write binary data from flash memory to the serial port.

Parameters:
[in]bLocation of the bytes to be written.
[in]nThe number of bytes to write.
Returns:
The number of bytes written to the serial port.

Definition at line 542 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
size_t SerialPort< PortNumber, RxBufSize, TxBufSize >::writeln ( const __FlashStringHelper *  s) [inline]

Write a flash string to the serial port followed by CR/LF.

Parameters:
[in]sThe string to be written.
Returns:
The number of bytes written to the serial port.

Definition at line 581 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
size_t SerialPort< PortNumber, RxBufSize, TxBufSize >::writeln ( const char *  s) [inline]

Write a string to the serial port followed by CR/LF.

Parameters:
[in]sThe string to be written.
Returns:
The number of bytes written to the serial port.

Definition at line 529 of file SerialPort.h.

template<uint8_t PortNumber, size_t RxBufSize, size_t TxBufSize>
size_t SerialPort< PortNumber, RxBufSize, TxBufSize >::writeln ( ) [inline]

Write CR/LF.

Returns:
2

Definition at line 516 of file SerialPort.h.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Defines