Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
|
Class that provides a serial port interface. More...
#include <SerialPort.hpp>
Public Member Functions | |
SerialPort ()=delete | |
SerialPort (const iv::model::comms::serial::PortSettings &settings) | |
SerialPort (const std::string &portName, iv::model::comms::serial::eBaudRate baudRate, iv::model::comms::serial::eDataBits dataBits, iv::model::comms::serial::eParity parity, iv::model::comms::serial::eStopBits stopBits, iv::model::comms::serial::eFlowControl flowControl, const iv::comms::serial::Timeout &timeout) | |
SerialPort (const SerialPort &other)=delete | |
SerialPort (SerialPort &&other) noexcept=delete | |
~SerialPort () | |
SerialPort & | operator= (const SerialPort &other)=delete |
SerialPort & | operator= (SerialPort &&other) noexcept=delete |
uint64_t | available () const |
void | close () |
void | open () |
iv::comms::serial::size_t | read (uint8_t *buffer, iv::comms::serial::size_t size) const |
iv::comms::serial::size_t | read (std::vector< uint8_t > &buffer, iv::comms::serial::size_t size=1) const |
iv::comms::serial::size_t | read (std::string &buffer, iv::comms::serial::size_t size=1) const |
std::string | read (iv::comms::serial::size_t size=1) const |
size_t | readLine (std::string &buffer, iv::comms::serial::size_t size=65536, const std::string &eol="\n") const |
std::string | readLine (iv::comms::serial::size_t size=65536, const std::string &eol="\n") const |
std::vector< std::string > | readLines (iv::comms::serial::size_t size=65536, const std::string &eol="\n") const |
iv::comms::serial::size_t | write (const uint8_t *data, iv::comms::serial::size_t size) const |
iv::comms::serial::size_t | write (const std::vector< uint8_t > &data) const |
iv::comms::serial::size_t | write (const std::vector< std::byte > &data) const |
iv::comms::serial::size_t | write (const std::string &data) const |
bool | waitReadable (uint32_t timeout) const |
Block until there is serial data to read or read_timeout_constant number of milliseconds have elapsed. The return value is true when the function exits with the port in a readable state, false otherwise (due to timeout or select interruption). | |
void | waitByteTimes (iv::comms::serial::size_t count) const |
Block for a period of time corresponding to the transmission time of count characters at present serial settings. This may be used in conjunction with waitReadable to read larger blocks of data from the port. | |
void | flush () const |
void | flushInput () const |
void | flushOutput () const |
void | sendBreak (uint32_t duration) const |
void | setPort (const std::string &port) |
void | setBaudRate (iv::model::comms::serial::eBaudRate baudRate) |
void | setByteSize (iv::model::comms::serial::eDataBits byteSize) |
void | setParity (iv::model::comms::serial::eParity parity) |
void | setStopBits (iv::model::comms::serial::eStopBits stopBits) |
void | setFlowControl (iv::model::comms::serial::eFlowControl flowControl) |
void | setTimeout (const iv::comms::serial::Timeout &timeout) |
void | setTimeout (uint32_t interByteTimeout, uint32_t readTimeoutConstant, uint32_t readTimeoutMultiplier, uint32_t writeTimeoutConstant, uint32_t writeTimeoutMultiplier) |
void | setBreak (bool level=true) const |
void | setRTS (bool level=true) const |
void | setDTR (bool level=true) const |
bool | waitForChange () const |
std::string | getPort () const |
iv::model::comms::serial::eBaudRate | getBaudRate () const |
iv::model::comms::serial::eDataBits | getByteSize () const |
iv::model::comms::serial::eParity | getParity () const |
iv::model::comms::serial::eStopBits | getStopBits () const |
iv::model::comms::serial::eFlowControl | getFlowControl () const |
iv::comms::serial::Timeout | getTimeout () const |
bool | getCTS () const |
bool | getDSR () const |
bool | getRI () const |
bool | getCD () const |
bool | isOpen () const |
Private Member Functions | |
iv::comms::serial::size_t | _read (uint8_t *buffer, iv::comms::serial::size_t size) const |
iv::comms::serial::size_t | _write (const uint8_t *data, iv::comms::serial::size_t size) const |
void | reconfigurePort () const |
void | readLock () |
void | readUnlock () |
void | writeLock () |
void | writeUnlock () |
Static Private Member Functions | |
static timespec | timespecFromMs (const uint32_t &millis) |
Private Attributes | |
std::string | m_port |
int32_t | m_fd |
bool | m_isOpen |
bool | m_xOnXOff |
bool | m_rtsCts |
iv::comms::serial::Timeout | m_timeout |
iv::model::comms::serial::PortSettings | m_settings |
uint32_t | byteTimeNs |
std::mutex | m_readMutex |
std::mutex | m_writeMutex |
Class that provides a serial port interface.
|
delete |
|
explicit |
iv::comms::serial::SerialPort::SerialPort | ( | const std::string & | portName, |
iv::model::comms::serial::eBaudRate | baudRate, | ||
iv::model::comms::serial::eDataBits | dataBits, | ||
iv::model::comms::serial::eParity | parity, | ||
iv::model::comms::serial::eStopBits | stopBits, | ||
iv::model::comms::serial::eFlowControl | flowControl, | ||
const iv::comms::serial::Timeout & | timeout ) |
|
delete |
|
deletenoexcept |
iv::comms::serial::SerialPort::~SerialPort | ( | ) |
|
private |
|
private |
|
nodiscard |
void iv::comms::serial::SerialPort::close | ( | ) |
void iv::comms::serial::SerialPort::flush | ( | ) | const |
Flush the input and output buffers
void iv::comms::serial::SerialPort::flushInput | ( | ) | const |
Flush only the input buffer
void iv::comms::serial::SerialPort::flushOutput | ( | ) | const |
Flush only the output buffer
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
void iv::comms::serial::SerialPort::open | ( | ) |
|
delete |
|
deletenoexcept |
|
nodiscard |
iv::comms::serial::size_t iv::comms::serial::SerialPort::read | ( | std::string & | buffer, |
iv::comms::serial::size_t | size = 1 ) const |
iv::comms::serial::size_t iv::comms::serial::SerialPort::read | ( | std::vector< uint8_t > & | buffer, |
iv::comms::serial::size_t | size = 1 ) const |
iv::comms::serial::size_t iv::comms::serial::SerialPort::read | ( | uint8_t * | buffer, |
iv::comms::serial::size_t | size ) const |
|
nodiscard |
size_t iv::comms::serial::SerialPort::readLine | ( | std::string & | buffer, |
iv::comms::serial::size_t | size = 65536, | ||
const std::string & | eol = "\n" ) const |
|
nodiscard |
|
private |
|
private |
|
private |
void iv::comms::serial::SerialPort::sendBreak | ( | uint32_t | duration | ) | const |
Sends the RS-232 break signal.
void iv::comms::serial::SerialPort::setBaudRate | ( | iv::model::comms::serial::eBaudRate | baudRate | ) |
void iv::comms::serial::SerialPort::setBreak | ( | bool | level = true | ) | const |
Set the break condition to a given level. Defaults to true.
void iv::comms::serial::SerialPort::setByteSize | ( | iv::model::comms::serial::eDataBits | byteSize | ) |
void iv::comms::serial::SerialPort::setDTR | ( | bool | level = true | ) | const |
Set the DTR handshaking line to the given level. Defaults to true.
void iv::comms::serial::SerialPort::setFlowControl | ( | iv::model::comms::serial::eFlowControl | flowControl | ) |
void iv::comms::serial::SerialPort::setParity | ( | iv::model::comms::serial::eParity | parity | ) |
void iv::comms::serial::SerialPort::setPort | ( | const std::string & | port | ) |
Sets the serial port identifier
port | A const std::string reference containing the address of the serial port |
void iv::comms::serial::SerialPort::setRTS | ( | bool | level = true | ) | const |
Set the RTS handshaking line to the given level. Defaults to true.
void iv::comms::serial::SerialPort::setStopBits | ( | iv::model::comms::serial::eStopBits | stopBits | ) |
void iv::comms::serial::SerialPort::setTimeout | ( | const iv::comms::serial::Timeout & | timeout | ) |
void iv::comms::serial::SerialPort::setTimeout | ( | uint32_t | interByteTimeout, |
uint32_t | readTimeoutConstant, | ||
uint32_t | readTimeoutMultiplier, | ||
uint32_t | writeTimeoutConstant, | ||
uint32_t | writeTimeoutMultiplier ) |
|
staticprivate |
void iv::comms::serial::SerialPort::waitByteTimes | ( | iv::comms::serial::size_t | count | ) | const |
Block for a period of time corresponding to the transmission time of count characters at present serial settings. This may be used in conjunction with waitReadable to read larger blocks of data from the port.
count |
|
nodiscard |
Blocks until CTS, DSR, RI, CD changes or something interrupts it.
Can throw an exception if an error occurs while waiting. You can check the status of CTS, DSR, RI, and CD once this returns. Uses TIOCMIWAIT via ioctl if available (mostly only on Linux) with a resolution of less than +-1ms and as good as +-0.2ms. Otherwise a polling method is used which can give +-2ms.
|
nodiscard |
Block until there is serial data to read or read_timeout_constant number of milliseconds have elapsed. The return value is true when the function exits with the port in a readable state, false otherwise (due to timeout or select interruption).
|
nodiscard |
|
nodiscard |
|
nodiscard |
iv::comms::serial::size_t iv::comms::serial::SerialPort::write | ( | const uint8_t * | data, |
iv::comms::serial::size_t | size ) const |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |