A SerialPort class.  
 More...
#include <serial_port.h>
 | 
| 
  | SerialPort () | 
|   | Default constructor. Does not open any port. 
  | 
|   | 
|   | SerialPort (const Settings &settings) | 
|   | Create a port with specific settings (but do not open it)  
  | 
|   | 
|   | SerialPort (const std::string &port_name, int baud_rate, Parity parity=Parity::kNone, NumStopBits stop_bits=serial_port::NumStopBits::kOne, bool hardware_flow_control=false, unsigned long int timeout_s=0, unsigned long int timeout_ms=0) | 
|   | Create a port with specific settings (but do not open it)  
  | 
|   | 
| 
  | ~SerialPort ()=default | 
|   | Default destructor. Port will be closed. 
  | 
|   | 
| 
  | SerialPort (SerialPort &&)=default | 
|   | SerialPort objects may be moved. 
  | 
|   | 
| 
SerialPort &  | operator= (SerialPort &&other) noexcept | 
|   | 
| 
  | SerialPort (const SerialPort &)=delete | 
|   | SerialPort objects may not be copied. 
  | 
|   | 
| 
SerialPort &  | operator= (const SerialPort &other)=delete | 
|   | 
| 
void  | Open () const | 
|   | Open the port with the current settings. If a port was opened through this object previously, it will be closed first. 
  | 
|   | 
| 
void  | Close () const | 
|   | Close the port. 
  | 
|   | 
| 
bool  | IsOpen () const | 
|   | Returns whether or not the port is currently open. 
  | 
|   | 
| 
const Settings &  | GetSettings () const | 
|   | Get the currently defined settings. 
  | 
|   | 
| 
unsigned long  | NumBytesAvailable () const | 
|   | Return the number of bytes available in the RX buffer. 
  | 
|   | 
| 
void  | FlushBuffer () const | 
|   | Flush the RX and TX buffers. 
  | 
|   | 
| unsigned long  | ReadData (char *data, unsigned long num_bytes) const | 
|   | Read data from the port.  
  | 
|   | 
| 
std::string  | ReadString () const | 
|   | Read a string from the port terminated with a '\n' symbol. 
  | 
|   | 
| unsigned long  | WriteData (const char *data, unsigned long num_bytes) const | 
|   | Write data to the port.  
  | 
|   | 
| unsigned long  | WriteString (const std::string &str) const | 
|   | Write a string to the port.  
  | 
|   | 
 | 
| 
std::ostream &  | operator<< (std::ostream &os, const SerialPort &obj) | 
|   | Overloaded stream output operator to print the port settings. 
  | 
|   | 
A SerialPort class. 
This class represents a serial port on the machine and handles opening, writing, reading, and closing a port. 
 
◆ SerialPort() [1/2]
  
  
      
        
          | serial_port::SerialPort::SerialPort  | 
          ( | 
          const Settings & |           settings | ) | 
           | 
         
       
   | 
  
explicit   | 
  
 
Create a port with specific settings (but do not open it) 
- Parameters
 - 
  
  
 
 
 
◆ SerialPort() [2/2]
      
        
          | serial_port::SerialPort::SerialPort  | 
          ( | 
          const std::string & |           port_name,  | 
        
        
           | 
           | 
          int |           baud_rate,  | 
        
        
           | 
           | 
          Parity |           parity = Parity::kNone,  | 
        
        
           | 
           | 
          NumStopBits |           stop_bits = serial_port::NumStopBits::kOne,  | 
        
        
           | 
           | 
          bool |           hardware_flow_control = false,  | 
        
        
           | 
           | 
          unsigned long int |           timeout_s = 0,  | 
        
        
           | 
           | 
          unsigned long int |           timeout_ms = 0 ) | 
        
      
 
Create a port with specific settings (but do not open it) 
- Parameters
 - 
  
    | port_name | Name of the port (e.g. "COM1" on Windows or "/dev/ttyS0" on Linux)  | 
    | baud_rate | A baud rate. Any value will be accepted here. It will be checked for validity when the port is actually opened.  | 
    | parity | The parity setting for the port.  | 
    | stop_bits | The number of stop bits being used.  | 
    | hardware_flow_control | Whether or not to use hardware flow control.  | 
    | timeout_s | Timeout value in seconds (currently not used!)  | 
    | timeout_ms | Timeout value in milliseconds (currently not used!)  | 
  
   
 
 
◆ EnumeratePorts()
A static function to enumerate available ports. 
- Returns
 - A list of PortInfo objects describing the available ports 
 
 
 
◆ ReadData()
      
        
          | unsigned long serial_port::SerialPort::ReadData  | 
          ( | 
          char * |           data,  | 
        
        
           | 
           | 
          unsigned long |           num_bytes ) const | 
        
      
 
Read data from the port. 
- Parameters
 - 
  
    | data | A pointer to a char array. Must be at least num_bytes elements long!  | 
    | num_bytes | The number of bytes to attempt to read from the port  | 
  
   
- Returns
 - The actual number of bytes read 
 
 
 
◆ WriteData()
      
        
          | unsigned long serial_port::SerialPort::WriteData  | 
          ( | 
          const char * |           data,  | 
        
        
           | 
           | 
          unsigned long |           num_bytes ) const | 
        
      
 
Write data to the port. 
- Parameters
 - 
  
    | data | An array of bytes to write  | 
    | num_bytes | the number of bytes in the array  | 
  
   
- Returns
 - The number of bytes actually written 
 
 
 
◆ WriteString()
      
        
          | unsigned long serial_port::SerialPort::WriteString  | 
          ( | 
          const std::string & |           str | ) | 
           const | 
        
      
 
Write a string to the port. 
- Parameters
 - 
  
    | str | A string terminated by a '\n' symbol  | 
  
   
- Returns
 - The number of bytes actually written 
 
 
 
The documentation for this class was generated from the following files: