|
SBB Host
Host communication with the self balancing bike.
|
A class for serial communication. More...
#include <Serial.h>
Public Member Functions | |
| Serial () | |
| Constructor. More... | |
| ~Serial () | |
| Desctructor. More... | |
| bool | begin (unsigned int port, unsigned int baud, unsigned int timeout) |
| Begin the serial. More... | |
| bool | begin (unsigned int port, unsigned int baud) |
| Begin the serial. More... | |
| void | flush () |
| Flush the serial. More... | |
| bool | end () |
| Close the serial. More... | |
| bool | write (unsigned char c) |
| Send a byte. More... | |
| size_t | write (unsigned char *buf, size_t len) |
| Send a buffer. More... | |
| unsigned char | read () |
| Read a byte. More... | |
| size_t | read (unsigned char *buf, size_t len) |
| Read a buffer. More... | |
| void | setTimeout (unsigned int timeout) |
| Set the timeout. More... | |
| unsigned int | getTimeout () |
| Get the timeout. More... | |
| operator bool () | |
| Check if serial is open. More... | |
Static Public Member Functions | |
| static std::vector< int > | get_availableSerialPorts (unsigned int maxPortNumber) |
| Get the available serial ports. More... | |
Static Public Attributes | |
| static constexpr unsigned int | TIMEOUT = 10 |
| Default timeout. More... | |
Private Attributes | |
| int | _serialPort |
| serial port More... | |
| struct termios | _serialParams |
| serial param struct More... | |
| bool | _isInit = false |
| true if serial has been initialized More... | |
| unsigned int | _timeout = TIMEOUT |
| timeout of the serial port More... | |
A class for serial communication.
Class for managing a general-purpose serial communication in Windows (using COM port) and Linux (using /dev/ttyACM). This is just a C++ wrapper for the HANDLE type in Windows, and the open, write, read, etc functions in Linux.
| Serial::Serial | ( | ) |
Constructor.
Default constructor for the serial class. No parameter is necessary.
| Serial::~Serial | ( | ) |
Desctructor.
Default destructor for the serial class. No parameter is necessary. It automatically closes the communication if open.
| bool Serial::begin | ( | unsigned int | port, |
| unsigned int | baud | ||
| ) |
Begin the serial.
Function to begin the serial communication with the specified configuration (with a default timeout of 10ms).
| port | the port to be used for the serial communication. |
| baud | the baudrate of the serial communication. |
| bool Serial::begin | ( | unsigned int | port, |
| unsigned int | baud, | ||
| unsigned int | timeout | ||
| ) |
Begin the serial.
Function to begin the serial communication with the specified configuration (including timeout).
| port | the port to be used for the serial communication. |
| baud | the baudrate of the serial communication. |
| timeout | the timeout of the serial communication (in ms). |
| bool Serial::end | ( | ) |
Close the serial.
Function to close the serial communication. Serial must be opened before.
| void Serial::flush | ( | ) |
Flush the serial.
Function to flush the receive buffer of the serial communication. Serial must be opened before.
|
static |
Get the available serial ports.
Function to get the available serial ports. Ports from 0 to maxPorts are checked.
| maxPortNumber | The max port number to be checked. |
| unsigned int Serial::getTimeout | ( | ) |
Get the timeout.
Function to get the timeout the serial communication.
|
inline |
Check if serial is open.
Boolean operator to check if the serial communication has been open successfully.
| unsigned char Serial::read | ( | ) |
Read a byte.
Function to read a byte via the serial communication. Serial must be opened before.
| size_t Serial::read | ( | unsigned char * | buf, |
| size_t | len | ||
| ) |
Read a buffer.
Function to read a buffer via the serial communication. Serial must be opened before.
| buf | The pointer to the buffer where the read bytes are stored. |
| len | The number of bytes to read. |
| void Serial::setTimeout | ( | unsigned int | timeout | ) |
Set the timeout.
Function to set the timeout the serial communication.
| timeout | The timeout to use (in ms). |
| size_t Serial::write | ( | unsigned char * | buf, |
| size_t | len | ||
| ) |
Send a buffer.
Function to send a buffer via the serial communication. Serial must be opened before.
| buf | The pointer to the buffer to be sent. |
| len | The length of the buffer to be sent (in bytes). |
| bool Serial::write | ( | unsigned char | c | ) |
Send a byte.
Function to send a byte via the serial communication. Serial must be opened before.
| c | The byte to be sent. |
|
private |
true if serial has been initialized
|
private |
serial param struct
|
private |
serial port
|
private |
timeout of the serial port
|
staticconstexpr |
Default timeout.