Public Member Functions
-
~Serial ()
-
const Device &
-
voidreadBytes (void *data, size_t numBytes)
Reads numBytes bytes of data from the serial port to data .
-
size_treadAvailableBytes (void *data, size_t maximumBytes)
Reads up to maximumBytes bytes of data from the serial port to data . Returns the number of bytes read.
-
voidwriteBytes (const void *data, size_t numBytes)
Writes numBytes bytes of data to the serial port from data .
-
voidwriteByte (uint8_t data)
Writes a single byte data to the serial port.
-
uint8_treadByte ()
Returns a single byte read from the serial port.
-
charreadChar ()
Returns a single character read from the serial port.
-
std::stringreadStringUntil (char token, size_t maxLength=0, double timeoutSeconds=-1.0)
Returns a string composed of bytes read until a character token is found, or up to maxLength bytes have been read and maxLength > 0. Throws a SerialTimeoutExc() if timeoutSeconds > 0 and timeoutSeconds seconds pass before token is found.
-
voidwriteString (const std::string &str)
Writes a string str to the serial port, excluding the null terminator.
-
voidflush (bool input=true, bool output=true)
Forces the device to flush any buffered input and/or output bytes.
-
size_tgetNumBytesAvailable () const
Returns the number of bytes available for reading from the device.
Static Public Member Functions
-
const std::vector< Serial::Device > &getDevices (bool forceRefresh=false)
Returns a vector of all serial devices available on the machine. Uses a cached list unless forceRefresh .
-
findDeviceByName (const std::string &name, bool forceRefresh=false)
Returns the first Serial::Device whose name is name . Returns a null Serial::Device if none are found. Uses a cached list of the serial devices unless forceRefresh .
-
findDeviceByNameContains (const std::string &searchString, bool forceRefresh=false)
Returns the first Serial::Device whose name contains the string searchString . Returns a null Serial::Device if none are found. Uses a cached list of the serial devices unless forceRefresh .
-
create (const Serial::Device &device, int baudRate)
Creates and returns a shared Serial object.