SoftwareSerial Class

SoftwareSerial Class

Description
A class for software serial implementation for Ameba.

Syntax
class SoftwareSerial

Members

Public Constructors 
SoftwareSerial::SoftwareSerialConstructs a SoftwareSerial object.
Public Methods 
SoftwareSerial::beginInitialize and set the speed (baud rate) for the serial communication.
SoftwareSerial::listenEnables the selected software serial port to listen.
SoftwareSerial::endDeinitialize the serial communication.
SoftwareSerial::isListeningCheck if requested software serial port is actively listening.
SoftwareSerial::stopListeningSelected software serial port stop listening.
SoftwareSerial::peekGet a character that was received on the RX pin of the software serial port.
SoftwareSerial::writeSend a single byte to the transmit pin of the software serial port as raw bytes.
SoftwareSerial::readRead data that was received from RX pin of the software serial port.
SoftwareSerial::availableGet the number of bytes (characters) available for reading from a software serial port.
SoftwareSerial::flushClear the received buffer.
SoftwareSerial::setBufferSizeSet buffer size.
SoftwareSerial::setAvailableCallbackSet available callback.
SoftwareSerial::handle_interruptPrivate method for handling interrupt.

SoftwareSerial::SoftwareSerial

Description
Constructs a SoftwareSerial object and sets RX and TX pin, and inverse logic.

Syntax
SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false);

Parameters
receivePin: the pin on which to receive serial data
transmitPin: the pin on which to transmit serial data
inverse_logic: is used to invert the sense of incoming bits

Returns
NA

Example Code
Example: SoftwareSerialExample
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino)

Notes and Warnings
Software Serial is using hardware serial thus DO NOT change the default pins. “SoftwareSerial_Basic.h” must be included to use the class function.

SoftwareSerial::begin

Description
Initialize and set the speed (baud rate) for the serial communication.

Syntax
void begin (long speed);
void begin (long speed, int data_bits, int parity, int stop_bits);
void begin (long speed, int data_bits, int parity, int stop_bits, int flowctrl, int rtsPin, int ctsPin);

Parameters
speed: the baud rate
data_bits: number of data bits, 8 bits (default) or 7 bits
stop_bits: number of stop bits, 1 bit (default), 1.5 bits or 2 bits
flowctrl: flow control pin
rtsPin: request to send pin
ctsPin: clear to send pin

Returns
NA

Example Code
Example: SoftwareSerialExample
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino)

Notes and Warnings
“SoftwareSerial_Basic.h” must be included to use the class function.

SoftwareSerial::listen

Description
Enables the selected software serial port to listen.

Syntax
bool listen(void);

Parameters
NA

Returns
This function returns true if it is listening, otherwise false.

Example Code
NA

Notes and Warnings
“SoftwareSerial_Basic.h” must be included to use the class function.

SoftwareSerial::end

Description
Deinitialize the serial communication. Selected software serial port stop listening.

Syntax
void end(void);

Parameters
NA

Returns
NA

Example Code
NA

Notes and Warnings
“SoftwareSerial_Basic.h” must be included to use the class function.

SoftwareSerial::isListening

Description
Check if requested software serial port is actively listening.

Syntax
bool isListening(void);

Parameters
NA

Returns
This function returns “True” if the port is actively listening.

Example Code
NA

Notes and Warnings
“SoftwareSerial_Basic.h” must be included to use the class function.

SoftwareSerial::stopListening

Description
Selected software serial port stop listening.

Syntax
bool stopListening(void);

Parameters
NA

Returns
This function returns true if the selected software serial port stop listening.

Example Code
NA

Notes and Warnings
“SoftwareSerial_Basic.h” must be included to use the class function.

SoftwareSerial::peek

Description
Get a character that was received on the RX pin of the software serial port.

Syntax
int peek(void);

Parameters
NA

Returns
This function returns the character read or returns “-1” if none is available.

Example Code
NA

Notes and Warnings
“SoftwareSerial_Basic.h” must be included to use the class function.

SoftwareSerial::write

Description
Send a single byte to the transmit pin of the software serial port as raw bytes.

Syntax
virtual size_t write(uint8_t byte);

Parameters
b: byte to be written

Returns
This function returns the number of bytes written.

Example Code
Example: SoftwareSerialExample
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino)

Notes and Warnings
“SoftwareSerial_Basic.h” must be included to use the class function.

SoftwareSerial::read

Description
Read data that was received from RX pin of the software serial port.

Syntax
virtual int read(void);

Parameters
NA

Returns
This function returns the byte read or returns -1 if none is available.

Example Code
Example: SoftwareSerialExample
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino)

Notes and Warnings
“SoftwareSerial_Basic.h” must be included to use the class function.

SoftwareSerial::available

Description
Get the number of bytes available for reading from a software serial port.

Syntax
virtual int available(void);

Parameters
NA

Returns
The function returns the number of bytes available to read.

Example Code
Example: SoftwareSerialExample
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino)

Notes and Warnings
“SoftwareSerial_Basic.h” must be included to use the class function.

SoftwareSerial::flush

Description
Clear the received buffer.

Syntax
virtual void flush(void);

Parameters
NA

Returns
This function returns if requested software serial port is not actively listening.

Example Code
NA

Notes and Warnings
“SoftwareSerial_Basic.h” must be included to use the class function.

SoftwareSerial::setBufferSize

Description
Set buffer size.

Syntax
void setBufferSize(uint32_t buffer_size);

Parameters
buffer_size: the size of the receive buffer.

Returns
NA

Example Code
NA

Notes and Warnings
“SoftwareSerial_Basic.h” must be included to use the class function.

SoftwareSerial::setAvailableCallback

Description
Set available callback.

Syntax
void setAvailableCallback(void (*callback)(char c));

Parameters
*callback: user-defined serial callback function

Returns
NA

Example Code
Example: SoftwareSerialIrqCallback
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/SoftwareSerial/examples/SoftwareSerialIrqCallback/SoftwareSerialIrqCallback.ino)

Notes and Warnings
“SoftwareSerial_Basic.h” must be included to use the class function.

SoftwareSerial::handle_interrupt

Description
A private method handles the interrupt.

Syntax
void handle_interrupt(uint32_t id, uint32_t event);

Parameters
id: the interupt id
event: interrupt event

Returns
NA

Example Code
NA

Notes and Warnings
“SoftwareSerial_Basic.h” must be included to use the class function.

請先確認已安裝QQ通訊軟體