USBSerial | |
---|---|
Quick Look | |
Hardware | USB Capable Boards (WF32, Fubarino) |
Core | HardwareSerial.h |
The USBSerial class implements methods for communicating over USB using the Wiring Serial objects.
The USBSerial class is derived from class Stream. It's purpose is to provide methods for sending and receiving data over the available USB ports when available. Boards must have USB capability such as the WF32 or Fubarino. Note that if USB is used for serial, the USB serial port gets instantiated as Serial and hardware serial port 0 gets instantiated as Serial0. If USBSSerial is not used then Hardware Serial (UART) gets instantiated as Serial.
USBSerial(ring_buffer *rx_buffer);
Create a new USBSerial object.
#define kMaxUSBxmitPkt 63
void (*rxIntr)(int);
Interrupt callback routine.
void attachInterrupt(void (*callback)(int));
Attach the interrupt. The callback parameter takes a funtion pointer.
void detachInterrupt();
Detach the interrupt
void begin(unsigned long baudRate);
Initialize the USB port for use. The baudRate parameted is required but the value is never used and therefore can be set to anything.
void end();
Has no functionality implemented and therefore it does nothing.
virtual in available(void);
Return the number of characters currently available in the receive buffer.
virtual int peek();
This returns the next character in the receive buffer without removing it from the buffer, or -1 if no characters are in the buffer.
virtual int read(void);
Return the next character from the receive buffer and remove it from the buffer, or -1 if no characters are available in the buffer.
virtual void flush(void);
Empty the send buffer.
virtual size_t write(uint8_t);
Transmit the specified character.
virtual size_t write(const char *str);
Transmits the characters from the specified pointer.
virtual size_t write(const uint8_t *buffer, size_t size);
Transmits the specified number of characters from the buffer pointer. The size parameter is used to specify the number of characters to transmit. If size is less than kMaxUSBxmitPkt a single packet will be transmitted. However if if (size < kMaxUSBxmitPkt is transmitted then multiple packets will be sent.
virtual unsigned long c;
Returns a baud rate.
operator int();
Returns 1 if the com port is open and 0 if the com port is closed.
The following write functions are pulled in from the Print class.
size_t write(const char *str);
size_t write(const char *buffer, size_t size);