Boost's serial io_service wrapped so it resembles Arduino's Serial
This header file provides asynchronous, non-blocking* access to utilize device’s hardware serial port in Arduino-like manner
Every write function returns instantly.
* Write will block and wait if write operation is already being performed.
typedef boost::asio::serial_port_base::flow_control::type flowControlType;
possible values:
hardware / software / none
typedef boost:
:type parityType;
possible values:
odd / even / none
typedef boost:
:type stopBitsType;
possible values:
typedef boost::system::errc::errc_t errorCode;
possible values:
enum format;
possible values:
void open(std::string name,
unsigned int baudRate = 115200,
flowControlType flowControl = flowControlType::none,
unsigned int characterSize = 8,
parityType parity = parityType::none,
stopBitsType stopBits = stopBitsType::one);
bool isOpen() const;
void close();
bool good() const;
void clear();
int getErr() const;
unsigned int write(uint8_t data);
data: A byte to write
returns: Number of bytes written
unsigned int write(std::vector<uint8_t> const & data);
data: Vector of bytes to write
returns: Number of bytes written
template<typename T>
unsigned int print(T const & data, unsigned int option = BoostSerial::DEC);
option: For anything else this argument is useless.
returns: Number of characters written
template<typename T>
unsigned int println(T const & data, unsigned int option = BoostSerial::DEC);
option: For anything else this argument is useless.
returns: Number of characters written
int16_t read();
std::vector<uint8_t> readBuffer();
std::vector<uint8_t> readBytes(uint16_t len = 0xFFFF);
len: Number of bytes to read
returns: vector of bytes of size len or smaller if given number of bytes hadn’t been read before timeout (removes read characters from the buffer)
std::vector<uint8_t> readBytesUntil(uint8_t terminator, uint16_t len = 0xFFFF);
len: Number of bytes to read
returns: Vector of bytes to given terminator or vector of size len if given terminator hadn’t been found in len bytes or smaller vector if timeout happened and any of the previous conditions hadn’t been met (read characters are removed from the buffer)
std::string readString();
std::string readStringUntil(char terminator = '\0');
terminator: Character that will end the reading (this character is not included in the return but is removed from the buffer)
returns: String to given terminator or smaller string if timeout happened and terminator hadn’t been found (read characters are removed from the buffer).
int16_t peek() const;
unsigned int available() const;
bool idle() const;
void flush();
void setBaud(unsigned int baud = 115200);
void setFlowControl(flowControlType flowControl = flowControlType::none);
void setCharacterSize(unsigned int charSize = 8);
void setPraity(parityType parity = parityType::none);
void setStopBits(stopBitsType stopBits = stopBitsType::one);
void setBufferSize(unsigned int bufSize = 256);
void setTimeout(unsigned int timeinms = 1000);
setBufferSize affects the size of the internal read buffer. If overflow happens, the data that appeared first will be lost
unsigned int getBaud() const;
flowControlType getFlowControl() const;
unsigned int getCharacterSize() const;
parityType getParity() const;
stopBitsType getStopBits() const;
unsigned int getBufferSize() const;
unsigned int getTimeout() const;