Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
|
Hardware serial class. More...
#include <HardwareSerial.h>
Public Member Functions | |
HardwareSerial (int uartPort) | |
Create instance of a hardware serial port object. More... | |
void | setPort (int uartPort) |
int | getPort () |
void | begin (uint32_t baud=9600) |
Initialise the serial port. More... | |
void | begin (uint32_t baud, SerialConfig config) |
Initialise and set its configuration. More... | |
void | begin (uint32_t baud, SerialConfig config, SerialMode mode) |
Initialise, set its configuration and mode. More... | |
void | begin (uint32_t baud, SerialConfig config, SerialMode mode, uint8_t txPin) |
void | end () |
De-inits the current UART if it is already used. More... | |
size_t | setRxBufferSize (size_t size) |
Sets receiving buffer size. More... | |
size_t | setTxBufferSize (size_t size) |
Sets transmit buffer size. More... | |
void | setTxWait (bool wait) |
Governs write behaviour when UART transmit buffers are full If false, writes will return short count; applications can use the txComplete callback to send more data. If true, writes will wait for more buffer space so that all requested data is written. More... | |
void | swap () |
Toggle between use of GPIO13/GPIO15 or GPIO3/GPIO(1/2) as RX and TX. More... | |
void | swap (uint8_t tx_pin) |
Toggle between use of GPIO13/GPIO15 or GPIO3/GPIO(1/2) as RX and TX. More... | |
void | setTx (uint8_t tx_pin) |
Toggle between use of GPIO1 and GPIO2 as TX on UART 0. More... | |
void | pins (uint8_t tx, uint8_t rx) |
Sets the transmission and receiving PINS. More... | |
int | available () override |
Get quantity characters available from serial input. More... | |
int | read () override |
Read a character from serial port. More... | |
uint16_t | readMemoryBlock (char *buf, int max_len) override |
Read a block of characters from serial port. More... | |
bool | seek (int len) override |
Move read cursor. More... | |
bool | isFinished () override |
Check if all data has been read. More... | |
int | peek () override |
Read a character from serial port without removing from input buffer. More... | |
void | clear (SerialMode mode=SERIAL_FULL) |
Clear the serial port transmit/receive buffers. More... | |
void | flush () override |
Flush all pending data to the serial port. More... | |
size_t | write (const uint8_t *buffer, size_t size) override |
write multiple characters 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 dataReceivedDelegate) |
Set handler for received data. More... | |
bool | onDataReceived (StreamDataReceivedDelegate dataReceivedDelegate) |
Set handler for received data. More... | |
bool | onTransmitComplete (TransmitCompleteDelegate transmitCompleteDelegate) |
Set handler for received data. More... | |
__forceinline void | setUartCallback (uart_callback_t callback, void *param=nullptr) |
Set callback ISR for received data. More... | |
bool | isTxEnabled () |
Checks if the current UART can transmit(print) information. More... | |
bool | isRxEnabled () |
Checks if the current UART can receive information. More... | |
uint32_t | baudRate () |
Get the current baud rate. More... | |
uint32_t | setBaudRate (uint32_t baudrate) |
Attempt to set the requested baud rate. More... | |
operator bool () const | |
Operator that returns true if the uart structure is set. More... | |
int | indexOf (char c) override |
Returns the location of the searched character. More... | |
uart_t * | getUart () |
Returns a pointer to the internal uart object. Use with care. More... | |
unsigned | getStatus () |
Get status error flags and clear them. More... | |
size_t | write (uint8_t charToWrite) override |
Write a single character to the stream. More... | |
size_t | write (const char *str) |
Writes a c-string to output stream. More... | |
size_t | write (const char *buffer, size_t size) |
Writes characters from a buffer to output stream. More... | |
virtual StreamType | getStreamType () const |
Get the stream type. More... | |
virtual bool | isValid () const |
Determine if the stream object contains valid data. More... | |
int | length () SMING_DEPRECATED |
Return the total length of the stream. More... | |
virtual String | id () const |
Returns unique id of the resource. More... | |
virtual String | getName () const |
Returns name of the resource. 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 | 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 | receiveTimeout = 1000 |
unsigned long | startMillis = 0 |
Hardware serial class.
|
inline |
Create instance of a hardware serial port object.
uartPort | UART number [0 | 1] |
|
inlineoverridevirtual |
Get quantity characters available from serial input.
int | Quantity of characters in receive buffer |
Reimplemented from IDataSourceStream.
|
inline |
Get the current baud rate.
uint32_t | baud rate |
|
inline |
Initialise the serial port.
baud | BAUD rate of the serial port (Default: 9600) |
|
inline |
Initialise and set its configuration.
SerialConfig | can 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. |
|
inline |
Initialise, set its configuration and mode.
SerialConfig | can 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. |
SerialMode | specifies if the UART supports receiving (RX), transmitting (TX) or both (FULL) operations |
|
inline |
Clear the serial port transmit/receive buffers.
mode | Whether to flush TX, RX or both (the default) |
|
inlineinherited |
Clears the last write error.
void HardwareSerial::commandProcessing | ( | bool | reqEnable | ) |
Configure serial port for command processing.
reqEnable | True to enable command processing |
void HardwareSerial::end | ( | ) |
De-inits the current UART if it is already used.
|
inlineoverridevirtual |
Flush all pending data to the serial port.
Reimplemented from IDataSourceStream.
|
inlinevirtualinherited |
Returns name of the resource.
String |
Reimplemented in TemplateStream, FileStream, and GdbFileStream.
|
inline |
Get status error flags and clear them.
unsigned | Status flags, combination of SerialStatus bits |
|
inlinevirtualinherited |
Get the stream type.
StreamType | The stream type. |
Reimplemented in FileStream, TemplateStream, StreamTransformer, rBootItemOutputStream, CircularBuffer, MemoryDataStream, LimitedMemoryStream, EndlessMemoryStream, UrlencodedOutputStream, FlashMemoryStream, JsonObjectStream, MultiStream, and ArduCAMStream.
|
inline |
Returns a pointer to the internal uart object. Use with care.
pointer | to uart_t |
|
inlineinherited |
Gets last error.
int | Error number of last write error |
|
inlinevirtualinherited |
Returns unique id of the resource.
String | the unique id of the stream. |
Reimplemented in FileStream, GdbFileStream, and CircularBuffer.
|
inlineoverridevirtual |
Returns the location of the searched character.
char | c - character to search for |
int | -1 if not found 0 or positive number otherwise |
Reimplemented from Stream.
|
inlineoverridevirtual |
|
inline |
Checks if the current UART can receive information.
bool | true if receiving is allowed |
|
inline |
Checks if the current UART can transmit(print) information.
bool | true if transmitting is allowed |
|
inlinevirtualinherited |
Determine if the stream object contains valid data.
bool | true if valid, false if invalid |
Reimplemented in FileStream, and GdbFileStream.
|
inlineinherited |
Return the total length of the stream.
int | -1 is returned when the size cannot be determined |
available()
instead
|
inline |
Set handler for received data.
dataReceivedDelegate | Function to handle received data |
bool | Returns true if the callback was set correctly |
|
inline |
Set handler for received data.
transmitCompleteDelegate | Function to handle received data |
bool | Returns true if the callback was set correctly |
|
inline |
Operator that returns true if the uart structure is set.
|
inlineoverridevirtual |
Read a character from serial port without removing from input buffer.
int | Character read from serial port or -1 if buffer empty |
Reimplemented from IDataSourceStream.
|
inline |
Sets the transmission and receiving PINS.
uint8_t | tx Transmission pin number |
uint8_t | rx Receiving pin number |
|
inherited |
Prints a single character to output stream.
size_t | Quantity of characters written to stream |
|
inherited |
Prints a c-string to output stream.
char[] | c-string to print |
size_t | Quantity of characters written to output stream |
size_t | Quantity of characters written to stream |
|
inherited |
Prints a number to output stream.
unsigned long | Number to print |
base | The base for output (Default: Decimal (base 10)) |
size_t | Quantity of characters written to stream |
unsigned int | Number to print |
base | The base for output (Default: Decimal (base 10)) |
size_t | Quantity of characters written to stream |
unsigned char | Number to print |
base | The base for output (Default: Decimal (base 10)) |
size_t | Quantity of characters written to stream |
|
inherited |
Prints a number to output stream.
long | Number to print |
base | The base for output (Default: Decimal (base 10)) |
size_t | Quantity of characters written to stream |
|
inherited |
Prints a number to output stream.
int | Number to print |
base | The base for output (Default: Decimal (base 10)) |
size_t | Quantity of characters written to stream |
|
inherited |
Prints number to output stream.
Prints a number to output stream.
double | Number to print |
int | Decimal places to show |
size_t | Quantity of characters written to output stream |
double | Number to print |
digits | The decimal places to print (Default: 2, e.g. 21.35) |
size_t | Quantity of characters written to stream |
|
inherited |
Prints a Printable object to output stream.
p | Object to print |
size_t | Quantity of characters written to stream |
|
inherited |
|
inherited |
Prints a formatted c-string to output stream.
fmt | Pointer to formated c-string to print |
... | Parameters for placeholders within formated string |
size_t | Quantity of characters written to stream |
|
inherited |
Prints a newline to output stream.
Prints | newline to output stream |
size_t | Quantity of characters written to output stream |
size_t | Quantity of characters written to stream |
|
inherited |
Prints a c-string to output stream, appending newline.
char[] | c-string to print |
size_t | Quantity of characters written to stream |
|
inherited |
Prints a single character to output stream, appending newline.
char | Character to print |
size_t | Quantity of characters written to stream |
|
inherited |
Prints a number to output stream, appending newline.
unsigned char | Number to print |
base | The base for output (Default: Decimal (base 10)) |
size_t | Quantity of characters written to stream |
unsigned int | Number to print |
base | The base for output (Default: Decimal (base 10)) |
size_t | Quantity of characters written to stream |
unsigned long | Number to print |
base | The base for output (Default: Decimal (base 10)) |
size_t | Quantity of characters written to stream |
|
inherited |
Prints a number to output stream, appending newline.
int | Number to print |
base | The base for output (Default: Decimal (base 10)) |
size_t | Quantity of characters written to stream |
|
inherited |
Prints a number to output stream, appending newline.
long | Number to print |
base | The base for output (Default: Decimal (base 10)) |
size_t | Quantity of characters written to stream |
|
inherited |
Prints a number to output stream, appending newline.
double | Number to print |
digits | The decimal places to print (Default: 2, e.g. 21.35) |
size_t | Quantity of characters written to stream |
|
inherited |
Prints a Printable object to output stream, appending newline.
p | Object to print |
size_t | Quantity of characters written to stream |
|
inherited |
|
inlineoverridevirtual |
Read a character from serial port.
int | Character read from serial port or -1 if buffer empty |
Reimplemented from IDataSourceStream.
|
inlineoverridevirtual |
Read a block of characters from serial port.
buf | Pointer to buffer to hold received data |
max_len | Maximum quantity of characters to read |
size_t | Quantity of characters read |
Implements IDataSourceStream.
|
inlineoverridevirtual |
Move read cursor.
len | Relative cursor adjustment |
bool | True on success. |
Implements IDataSourceStream.
|
inline |
Attempt to set the requested baud rate.
uint32_t | the actual baud rate in force |
|
inline |
Set handler for received data.
dataReceivedDelegate | Function to handle received data |
bool | Returns true if the callback was set correctly |
size_t HardwareSerial::setRxBufferSize | ( | size_t | size | ) |
Sets receiving buffer size.
size_t | requested size |
size_t | actual size |
|
inline |
Toggle between use of GPIO1 and GPIO2 as TX on UART 0.
size_t HardwareSerial::setTxBufferSize | ( | size_t | size | ) |
Sets transmit buffer size.
size_t | requested size |
size_t | actual size |
|
inline |
Governs write behaviour when UART transmit buffers are full If false, writes will return short count; applications can use the txComplete callback to send more data. If true, writes will wait for more buffer space so that all requested data is written.
|
inline |
Set callback ISR for received data.
reqCallback | Function to handle received data |
|
inline |
Toggle between use of GPIO13/GPIO15 or GPIO3/GPIO(1/2) as RX and TX.
|
inline |
Toggle between use of GPIO13/GPIO15 or GPIO3/GPIO(1/2) as RX and TX.
uint8_t | Pin number. |
void HardwareSerial::systemDebugOutput | ( | bool | enabled | ) |
Configure serial port for system debug output and redirect output from debugf.
enabled | True to enable this port for system debug output |
|
inlineoverridevirtualinherited |
Write a single character to the stream.
charToWrite |
size_t | Number of chars written (1 on success, 0 on failure) |
Reimplemented from IDataSourceStream.
|
inlineinherited |
Writes a c-string to output stream.
str | Pointer to c-string |
size_t | Quantity of characters written to stream |
|
inlineinherited |
Writes characters from a buffer to output stream.
buffer | Pointer to character buffer |
size | Quantity of characters to write |
size_t | Quantity of characters written to stream |
|
inlineoverridevirtual |
write multiple characters to serial port
buffer | data to write |
size | number of characters to write |
size_t | Quantity of characters written, may be less than size |
Implements ReadWriteStream.