Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
HardwareSerial Class Reference

Hardware serial class. More...

#include <HardwareSerial.h>

Inheritance diagram for HardwareSerial:
Stream Print

Public Member Functions

 HardwareSerial (const int uartPort)
 Create instance of a hardware serial port object. More...
 
void begin (const uint32_t baud=9600)
 Initialise the serial port. More...
 
void begin (const uint32_t baud, SerialConfig config)
 Initialise and set its configuration. More...
 
void begin (const uint32_t baud, SerialConfig config, SerialMode mode)
 Initialise, set its configuration and mode. More...
 
void begin (const uint32_t baud, SerialConfig config, SerialMode mode, uint8_t txPin)
 
void end ()
 
size_t setRxBufferSize (size_t size)
 
void swap ()
 
void swap (uint8_t tx_pin)
 
void setTx (uint8_t tx_pin)
 
void pins (uint8_t tx, uint8_t rx)
 
int available ()
 Get quantity characters available from serial input. More...
 
int read ()
 Read a character from serial port. More...
 
int readMemoryBlock (char *buf, int max_len)
 Read a block of characters from serial port. More...
 
int peek ()
 Read a character from serial port without removing from input buffer. More...
 
void flush ()
 Clear the serial port receive buffer. More...
 
size_t write (uint8_t oneChar)
 write a character to serial port More...
 
void systemDebugOutput (bool enabled)
 Configure serial port for system debug output and redirect output from debugf. More...
 
void commandProcessing (bool reqEnable)
 Configure serial port for command processing. More...
 
bool setCallback (StreamDataReceivedDelegate reqCallback)
 Set handler for received data. More...
 
void resetCallback ()
 Remove handler for received data. More...
 
bool isTxEnabled (void)
 Checks if the current UART can transmit(print) information. More...
 
bool isRxEnabled (void)
 Checks if the current UART can receive information. More...
 
int baudRate (void)
 Get the current baud rate. More...
 
 operator bool () const
 Operator that returns true if the uart structure is set. More...
 
void setTimeout (unsigned long timeout)
 
bool find (char *target)
 
bool find (char *target, size_t length)
 
bool findUntil (char *target, char *terminator)
 
bool findUntil (char *target, size_t targetLen, char *terminate, size_t termLen)
 
long parseInt ()
 
float parseFloat ()
 
size_t readBytes (char *buffer, size_t length)
 
size_t readBytesUntil (char terminator, char *buffer, size_t length)
 
String readString ()
 
String readStringUntil (char terminator)
 
int getWriteError ()
 Gets last error. More...
 
void clearWriteError ()
 Clears the last write error. More...
 
size_t write (const char *str)
 Writes a c-string to output stream. More...
 
virtual size_t write (const uint8_t *buffer, size_t size)
 Writes characters from a buffer to output stream. More...
 
size_t write (const char *buffer, size_t size)
 Writes characters from a buffer to output stream. More...
 
size_t print (char)
 Prints a single character to output stream. More...
 
size_t print (const char[])
 Prints a c-string to output stream. More...
 
size_t print (unsigned long, int base=DEC)
 Prints a number to output stream. More...
 
size_t print (long, int base=DEC)
 Prints a number to output stream. More...
 
size_t print (unsigned int, int base=DEC)
 
size_t print (unsigned char, int base=DEC)
 
size_t print (int, int base=DEC)
 Prints a number to output stream. More...
 
size_t print (double, int digits=2)
 Prints number to output stream. More...
 
size_t print (const Printable &p)
 Prints a Printable object to output stream. More...
 
size_t print (const String &s)
 Prints a String to output stream. More...
 
size_t println (void)
 Prints a newline to output stream. More...
 
size_t println (const char[])
 Prints a c-string to output stream, appending newline. More...
 
size_t println (char)
 Prints a single character to output stream, appending newline. More...
 
size_t println (unsigned char, int base=DEC)
 Prints a number to output stream, appending newline. More...
 
size_t println (unsigned int, int base=DEC)
 
size_t println (unsigned long, int base=DEC)
 
size_t println (int, int base=DEC)
 Prints a number to output stream, appending newline. More...
 
size_t println (long, int base=DEC)
 Prints a number to output stream, appending newline. More...
 
size_t println (double, int digits=2)
 Prints a number to output stream, appending newline. More...
 
size_t println (const Printable &p)
 Prints a Printable object to output stream, appending newline. More...
 
size_t println (const String &s)
 Prints a String to output stream, appending newline. More...
 
size_t printf (const char *fmt,...)
 Prints a formatted c-string to output stream. More...
 

Protected Member Functions

int timedRead ()
 
int timedPeek ()
 
int peekNextDigit ()
 
long parseInt (char skipChar)
 
float parseFloat (char skipChar)
 
void setWriteError (int err=1)
 

Protected Attributes

unsigned long _timeout
 
unsigned long _startMillis
 

Detailed Description

Hardware serial class.

Constructor & Destructor Documentation

HardwareSerial::HardwareSerial ( const int  uartPort)

Create instance of a hardware serial port object.

Parameters
uartPortUART number [0 | 1]
Note
A global instance of UART 0 is already defined as Serial

Member Function Documentation

int HardwareSerial::available ( )
virtual

Get quantity characters available from serial input.

Return values
intQuantity of characters in receive buffer

Implements Stream.

int HardwareSerial::baudRate ( void  )

Get the current baud rate.

Return values
intbaud rate
void HardwareSerial::begin ( const uint32_t  baud = 9600)
inline

Initialise the serial port.

Parameters
baudBAUD rate of the serial port (Default: 9600)
void HardwareSerial::begin ( const uint32_t  baud,
SerialConfig  config 
)
inline

Initialise and set its configuration.

Parameters
SerialConfigcan be 5, 6, 7, 8 data bits, odd (O), even (E), and no (N) parity, and 1 or 2 stop bits. To set the desired mode, call Serial.begin(baudrate, SERIAL_8N1), Serial.begin(baudrate, SERIAL_6E2), etc.
void HardwareSerial::begin ( const uint32_t  baud,
SerialConfig  config,
SerialMode  mode 
)
inline

Initialise, set its configuration and mode.

Parameters
SerialConfigcan be 5, 6, 7, 8 data bits, odd (O), even (E), and no (N) parity, and 1 or 2 stop bits. To set the desired mode, call Serial.begin(baudrate, SERIAL_8N1), Serial.begin(baudrate, SERIAL_6E2), etc.
SerialModespecifies if the UART supports receiving (RX), transmitting (TX) or both (FULL) operations
void Print::clearWriteError ( )
inlineinherited

Clears the last write error.

void HardwareSerial::commandProcessing ( bool  reqEnable)

Configure serial port for command processing.

Parameters
reqEnableTrue to enable command processing
Note
Command processing provides a CLI to the system
See also
commandHandler
void HardwareSerial::flush ( )
virtual

Clear the serial port receive buffer.

Note
All received data is removed from the serial port buffer

Implements Stream.

int Print::getWriteError ( )
inlineinherited

Gets last error.

Return values
intError number of last write error
bool HardwareSerial::isRxEnabled ( void  )

Checks if the current UART can receive information.

Return values
booltrue if receiving is allowed
bool HardwareSerial::isTxEnabled ( void  )

Checks if the current UART can transmit(print) information.

Return values
booltrue if transmitting is allowed
HardwareSerial::operator bool ( ) const

Operator that returns true if the uart structure is set.

int HardwareSerial::peek ( )
virtual

Read a character from serial port without removing from input buffer.

Return values
intCharacter read from serial port or -1 if buffer empty
Note
The character remains in serial port input buffer

Implements Stream.

size_t Print::print ( char  )
inherited

Prints a single character to output stream.

Return values
size_tQuantity of characters written to stream
size_t Print::print ( const char  [])
inherited

Prints a c-string to output stream.

Parameters
char[]c-string to print
Return values
size_tQuantity of characters written to output stream
size_tQuantity of characters written to stream
size_t Print::print ( unsigned  char,
int  base = DEC 
)
inherited

Prints a number to output stream.

Parameters
unsigned longNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
Parameters
unsigned intNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
Parameters
unsigned charNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
size_t Print::print ( long  ,
int  base = DEC 
)
inherited

Prints a number to output stream.

Parameters
longNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
size_t Print::print ( int  ,
int  base = DEC 
)
inherited

Prints a number to output stream.

Parameters
intNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
size_t Print::print ( double  ,
int  digits = 2 
)
inherited

Prints number to output stream.

Prints a number to output stream.

Parameters
doubleNumber to print
intDecimal places to show
Return values
size_tQuantity of characters written to output stream
Parameters
doubleNumber to print
digitsThe decimal places to print (Default: 2, e.g. 21.35)
Return values
size_tQuantity of characters written to stream
size_t Print::print ( const Printable p)
inherited

Prints a Printable object to output stream.

Parameters
pObject to print
Return values
size_tQuantity of characters written to stream
size_t Print::print ( const String s)
inherited

Prints a String to output stream.

Parameters
sString to print
Return values
size_tQuantity of characters written to stream
size_t Print::printf ( const char *  fmt,
  ... 
)
inherited

Prints a formatted c-string to output stream.

Parameters
fmtPointer to formated c-string to print
...Parameters for placeholders within formated string
Return values
size_tQuantity of characters written to stream
Note
Use standard printf placeholders, e.g. d for integer, s for c-string, etc.
size_t Print::println ( void  )
inherited

Prints a newline to output stream.

Parameters
Printsnewline to output stream
Return values
size_tQuantity of characters written to output stream
size_tQuantity of characters written to stream
size_t Print::println ( const char  [])
inherited

Prints a c-string to output stream, appending newline.

Parameters
char[]c-string to print
Return values
size_tQuantity of characters written to stream
size_t Print::println ( char  )
inherited

Prints a single character to output stream, appending newline.

Parameters
charCharacter to print
Return values
size_tQuantity of characters written to stream
size_t Print::println ( unsigned  long,
int  base = DEC 
)
inherited

Prints a number to output stream, appending newline.

Parameters
unsigned charNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
Parameters
unsigned intNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
Parameters
unsigned longNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
size_t Print::println ( int  ,
int  base = DEC 
)
inherited

Prints a number to output stream, appending newline.

Parameters
intNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
size_t Print::println ( long  ,
int  base = DEC 
)
inherited

Prints a number to output stream, appending newline.

Parameters
longNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
size_t Print::println ( double  ,
int  digits = 2 
)
inherited

Prints a number to output stream, appending newline.

Parameters
doubleNumber to print
digitsThe decimal places to print (Default: 2, e.g. 21.35)
Return values
size_tQuantity of characters written to stream
size_t Print::println ( const Printable p)
inherited

Prints a Printable object to output stream, appending newline.

Parameters
pObject to print
Return values
size_tQuantity of characters written to stream
size_t Print::println ( const String s)
inherited

Prints a String to output stream, appending newline.

Parameters
sString to print
Return values
size_tQuantity of characters written to stream
int HardwareSerial::read ( )
virtual

Read a character from serial port.

Return values
intCharacter read from serial port or -1 if buffer empty
Note
The character is removed from the serial port input buffer

Implements Stream.

int HardwareSerial::readMemoryBlock ( char *  buf,
int  max_len 
)

Read a block of characters from serial port.

Parameters
bufPointer to buffer to hold received data
max_lenMaximum quantity of characters to read
Return values
intQuantity of characters read
void HardwareSerial::resetCallback ( )

Remove handler for received data.

bool HardwareSerial::setCallback ( StreamDataReceivedDelegate  reqCallback)

Set handler for received data.

Parameters
reqCallbackFunction to handle received data
Return values
boolReturns true if the callback was set correctly
void HardwareSerial::systemDebugOutput ( bool  enabled)

Configure serial port for system debug output and redirect output from debugf.

Parameters
enabledTrue to enable this port for system debug output
Note
If enabled, port will issue system debug messages
size_t Print::write ( const char *  str)
inlineinherited

Writes a c-string to output stream.

Parameters
strPointer to c-string
Return values
size_tQuantity of characters written to stream
size_t Print::write ( const uint8_t *  buffer,
size_t  size 
)
virtualinherited

Writes characters from a buffer to output stream.

Parameters
bufferPointer to character buffer
sizeQuantity of characters to write
Return values
size_tQuantity of characters written to stream

Reimplemented in MemoryDataStream, and TwoWire.

size_t Print::write ( const char *  buffer,
size_t  size 
)
inlineinherited

Writes characters from a buffer to output stream.

Parameters
bufferPointer to character buffer
sizeQuantity of characters to write
Return values
size_tQuantity of characters written to stream
size_t HardwareSerial::write ( uint8_t  oneChar)
virtual

write a character to serial port

Parameters
oneCharCharacter to write to the serial port
Return values
size_tQuantity of characters written (always 1)

Implements Print.