USBCDCDevice Class

USBCDCDevice Class

Description
A class for managing, transmitting, and receiving data using USB CDC ACM device class.

Syntax
class USBCDCDevice

Members

Public Constructors
The public constructor should not be used as this class is intended to be a singleton class. Access member functions using the object instance named SerialUSB.
Public Methods 
USBCDCDevice::setVIDSet USB vendor ID value.
USBCDCDevice::setPIDSet USB product ID value.
USBCDCDevice::setManufacturerStringSet USB manufacturer string
USBCDCDevice::setModelStringSet USB product model string.
USBCDCDevice::setSerialStringSet USB product serial number string.
USBCDCDevice::USBconnectedCheck if the USB port is connected to a host.
USBCDCDevice::connectedCheck if the USB CDC serial terminal is ready on the host.
USBCDCDevice::dtrCheck DTR signal state.
USBCDCDevice::rtsCheck RTS signal state.
USBCDCDevice::beginStart serial communication using USB CDC.
USBCDCDevice::endStop serial communication using USB CDC.
USBCDCDevice::availableGet the number of bytes (characters) available for reading from the USB serial port.
USBCDCDevice::peekGet the next byte (character) of incoming serial data without removing it from the internal buffer.
USBCDCDevice::readRead incoming serial data.
USBCDCDevice::flushWait for the transmission of outgoing serial data to complete.
USBCDCDevice::writeWrite binary data to the serial port.

USBCDCDevice::setVID

Description
Set USB vendor ID value.

Syntax
void setVID(uint16_t VID);

Parameters
VID: vendor ID

Returns
NA

Example Code
NA

Notes and Warnings
The VID should be configured before USBCDCDevice::begin() function is called.
“USBCDCDevice.h” must be included to use the class function.

USBCDCDevice::setPID

Description
Set USB product ID value.

Syntax
void setPID(uint16_t PID);

Parameters
PID: product ID

Returns
NA

Example Code
NA

Notes and Warnings
The PID should be configured before USBCDCDevice::begin() function is called. “USBCDCDevice.h” must be included to use the class function.

USBCDCDevice::setManufacturerString

Description
Set USB manufacturer string.

Syntax
void setManufacturerString(const char* manufacturer);

Parameters
manufacturer: Character string containing manufacturer name. Default “Reaktek”.

Returns
NA

Example Code
NA
<
Notes and Warnings
The manufacturer string should be configured before USBCDCDevice::begin() function is called. “USBCDCDevice.h” must be included to use the class function.

USBCDCDevice::setModelString

Description
Set USB product model name string.

Syntax
void setModelString(const char* model);

Parameters
model: Character string containing model name. Default “Realtek USB VCP”.

Returns
NA

Example Code
NA

Notes and Warnings
The model string should be configured before USBCDCDevice::begin() function is called. “USBCDCDevice.h” must be included to use the class function.

USBCDCDevice::setSerialString

Description
Set USB product serial number string.

Syntax
void setSerialString(const char* serial);

Parameters
serial: Character string containing serial number. Default “0123456789”.

Returns
NA

Example Code
NA

Notes and Warnings
The serial string should be configured before USBCDCDevice::begin() function is called. “USBCDCDevice.h” must be included to use the class function.

USBCDCDevice::USBconnected

Description
Check if the USB port is connected to a host.

Syntax
uint8_t USBconnected(void);

Parameters
NA

Returns
The function returns TRUE if the USB port is connected to a host, FALSE if it is not connected.

Example Code
NA

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

USBCDCDevice::connected

Description
Check if the USB CDC serial terminal is ready on the host.

Syntax
uint8_t connected(void);

Parameters
NA

Returns
This function returns TRUE if the USB port is connected to a host and the DTR and RTS signals are set, else returns FALSE.

Example Code
NA

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

USBCDCDevice::dtr

Description
Check DTR signal state.

Syntax
uint8_t dtr(void);

Parameters
NA

Returns
This function returns the state of the DTR signal line.

Example Code
NA

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

USBCDCDevice::rts

Description
Check RTS signal state.

Syntax
uint8_t rts(void);

Parameters
NA

Returns
This function returns the state of the RTS signal line.

Example Code
NA

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

USBCDCDevice::begin

Description
Start serial communication using USB CDC.

Syntax
void begin(uint32_t baud);

Parameters
baud: baud rate

Returns
NA

Example Code
Example: USBCDCSerial
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/USB/examples/USBCDCSerial/USBCDCSerial.ino)

Notes and Warnings
The baud rate parameter has no significance in the context of a USB CDC serial port and can be left empty. “USBCDCDevice.h” must be included to use the class function.

USBCDCDevice::end

Description
Stop serial communication using USB CDC.

Syntax
void end(void);

Parameters
NA

Returns
NA

Example Code
NA

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

USBCDCDevice::available

Description
Get the number of bytes (characters) available for reading from the USB serial port.

Syntax
int available(void);

Parameters
NA

Returns
This function returns the number of bytes received in the buffer.

Example Code
Example: USBCDCSerial
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/USB/examples/USBCDCSerial/USBCDCSerial.ino)

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

USBCDCDevice::peek

Description
Get the next byte (character) of incoming serial data without removing it from the internal buffer.

Syntax
int peek(void);

Parameters
NA

Returns
This function returns the next byte of received serial data without removing it from the internal buffer else returns error(-1).

Example Code
NA

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

USBCDCDevice::read

Description
Reads incoming serial data.

Syntax
int read(void);

Parameters
NA

Returns
This function returns the next byte of received serial data, else returns error(-1).

Example Code
Example: USBCDCSerial
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/USB/examples/USBCDCSerial/USBCDCSerial.ino)

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

USBCDCDevice::flush

Description
Wait for the transmission of outgoing serial data to complete.

Syntax
void flush(void);

Parameters
NA

Returns
NA

Example Code
NA

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

USBCDCDevice::write

Description
Write binary data to the serial port.

Syntax
size_t write(uint8_t data);
size_t write(const uint8_t* buffer, size_t size);

Parameters
data: 1 byte of data to write to serial port.
buffer: pointer to buffer containing data to write to serial port.
size: number of bytes of data in buffer to write to serial port.

Returns
This function returns the number of bytes written to serial port.

Example Code
Example: USBCDCSerial
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/USB/examples/USBCDCSerial/USBCDCSerial.ino)

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

Please confirm that QQ communication software is installed