#include <SerialReaderWriter.h>
|  | 
|  | SerialReaderWriter (BaseLib::SharedObjects *baseLib, std::string device, int32_t baudrate, int32_t flags, bool createLockFile, int32_t readThreadPriority, bool writeOnly=false) | 
|  | Constructor.  More... 
 | 
|  | 
| virtual | ~SerialReaderWriter () | 
|  | Destructor.  More... 
 | 
|  | 
| bool | isOpen () | 
|  | 
| std::shared_ptr< FileDescriptor > | fileDescriptor () | 
|  | 
| void | openDevice (bool parity, bool oddParity, bool events=true, CharacterSize characterSize=CharacterSize::Eight, bool twoStopBits=false) | 
|  | Opens the serial device.  More... 
 | 
|  | 
| void | closeDevice () | 
|  | Closes the serial device.  More... 
 | 
|  | 
| int32_t | readLine (std::string &data, uint32_t timeout=500000, char splitChar='\n') | 
|  | SerialReaderWriter can either be used through events (by implementing ISerialReaderWriterEventSink and usage of addEventHandler) or by polling using this method.  More... 
 | 
|  | 
| int32_t | readChar (char &data, uint32_t timeout=500000) | 
|  | SerialReaderWriter can either be used through events (by implementing ISerialReaderWriterEventSink and usage of addEventHandler) or by polling using this method.  More... 
 | 
|  | 
| void | writeLine (std::string &data) | 
|  | Writes one line of data.  More... 
 | 
|  | 
| void | writeData (const std::vector< char > &data) | 
|  | Writes binary data to the serial device.  More... 
 | 
|  | 
| void | writeData (const std::vector< uint8_t > &data) | 
|  | Writes binary data to the serial device.  More... 
 | 
|  | 
| void | writeChar (char data) | 
|  | Writes one character to the serial device.  More... 
 | 
|  | 
|  | IEventsEx () | 
|  | 
| virtual | ~IEventsEx () | 
|  | 
| virtual PEventHandler | addEventHandler (IEventSinkBase *eventHandler) | 
|  | 
| virtual std::vector< PEventHandler > | addEventHandlers (EventHandlers eventHandlers) | 
|  | 
| virtual void | removeEventHandler (PEventHandler eventHandler) | 
|  | 
| virtual EventHandlers | getEventHandlers () | 
|  | 
§ CharacterSize
| Enumerator | 
|---|
| Five |  | 
| Six |  | 
| Seven |  | 
| Eight |  | 
 
 
§ SerialReaderWriter()
      
        
          | BaseLib::SerialReaderWriter::SerialReaderWriter | ( | BaseLib::SharedObjects * | baseLib, | 
        
          |  |  | std::string | device, | 
        
          |  |  | int32_t | baudrate, | 
        
          |  |  | int32_t | flags, | 
        
          |  |  | bool | createLockFile, | 
        
          |  |  | int32_t | readThreadPriority, | 
        
          |  |  | bool | writeOnly = false | 
        
          |  | ) |  |  | 
      
 
Constructor. 
- Parameters
- 
  
    | baseLib | The base library object. |  | device | The device to use (e. g. "/dev/ttyUSB0") |  | baudrate | The baudrate (e. g. 115200) |  | flags | Flags passed to the C function "open". 0 should be fine for most cases. "O_NDELAY" is always added by the constructor. By default "O_RDWR | O_NOCTTY | O_NDELAY" is used. |  | createLockFile | Dummy parameter for compatibility. |  | readThreadPriority | The priority of the read thread between 0 and 99. Set to -1 to not prioritize the thread. Only relevent when "events" are enabled in "openDevice()". |  | writeOnly | Open the device for writing only. |  
 
 
 
§ ~SerialReaderWriter()
  
  | 
        
          | BaseLib::SerialReaderWriter::~SerialReaderWriter | ( |  | ) |  |  | virtual | 
 
 
§ closeDevice()
      
        
          | void BaseLib::SerialReaderWriter::closeDevice | ( |  | ) |  | 
      
 
Closes the serial device. 
 
 
§ fileDescriptor()
  
  | 
        
          | std::shared_ptr<FileDescriptor> BaseLib::SerialReaderWriter::fileDescriptor | ( |  | ) |  |  | inline | 
 
 
§ isOpen()
  
  | 
        
          | bool BaseLib::SerialReaderWriter::isOpen | ( |  | ) |  |  | inline | 
 
 
§ openDevice()
      
        
          | void BaseLib::SerialReaderWriter::openDevice | ( | bool | parity, | 
        
          |  |  | bool | oddParity, | 
        
          |  |  | bool | events = true, | 
        
          |  |  | CharacterSize | characterSize = CharacterSize::Eight, | 
        
          |  |  | bool | twoStopBits = false | 
        
          |  | ) |  |  | 
      
 
Opens the serial device. 
- Parameters
- 
  
    | evenParity | Enable parity checking using an even parity bit. |  | oddParity | Enable parity checking using an odd parity bit. "evenParity" and "oddParity" are mutually exclusive. |  | events | Enable events. This starts a thread which calls "lineReceived()" in a derived class for each received packet. |  | characterSize | Set the character Size. |  | twoStopBits | Enable two stop bits instead of one. |  
 
 
 
§ readChar()
      
        
          | int32_t BaseLib::SerialReaderWriter::readChar | ( | char & | data, | 
        
          |  |  | uint32_t | timeout = 500000 | 
        
          |  | ) |  |  | 
      
 
SerialReaderWriter can either be used through events (by implementing ISerialReaderWriterEventSink and usage of addEventHandler) or by polling using this method. 
- Parameters
- 
  
    | data | The variable to write the returned character into. |  | timeout | The maximum amount of time to wait in microseconds before the function returns (default: 500000). |  
 
- Returns
- Returns "0" on success, "1" on timeout or "-1" on error. 
 
 
§ readLine()
      
        
          | int32_t BaseLib::SerialReaderWriter::readLine | ( | std::string & | data, | 
        
          |  |  | uint32_t | timeout = 500000, | 
        
          |  |  | char | splitChar = '\n' | 
        
          |  | ) |  |  | 
      
 
SerialReaderWriter can either be used through events (by implementing ISerialReaderWriterEventSink and usage of addEventHandler) or by polling using this method. 
- Parameters
- 
  
    | data | The variable to write the returned line into. |  | timeout | The maximum amount of time to wait in microseconds before the function returns (default: 500000). |  | splitChar | The character to split at (default: ' ')
 |  
 
- Returns
- Returns "0" on success, "1" on timeout or "-1" on error. 
 
 
§ readThread()
  
  | 
        
          | void BaseLib::SerialReaderWriter::readThread | ( | bool | parity, |  
          |  |  | bool | oddParity, |  
          |  |  | CharacterSize | characterSize, |  
          |  |  | bool | twoStopBits |  
          |  | ) |  |  |  | protected | 
 
 
§ writeChar()
      
        
          | void BaseLib::SerialReaderWriter::writeChar | ( | char | data | ) |  | 
      
 
Writes one character to the serial device. 
- Parameters
- 
  
    | data | The (binary) character to write. |  
 
 
 
§ writeData() [1/2]
      
        
          | void BaseLib::SerialReaderWriter::writeData | ( | const std::vector< char > & | data | ) |  | 
      
 
Writes binary data to the serial device. 
- Parameters
- 
  
    | data | The data to write. It is written as is without any modification. |  
 
 
 
§ writeData() [2/2]
      
        
          | void BaseLib::SerialReaderWriter::writeData | ( | const std::vector< uint8_t > & | data | ) |  | 
      
 
Writes binary data to the serial device. 
- Parameters
- 
  
    | data | The data to write. It is written as is without any modification. |  
 
 
 
§ writeLine()
      
        
          | void BaseLib::SerialReaderWriter::writeLine | ( | std::string & | data | ) |  | 
      
 
Writes one line of data. 
- Parameters
- 
  
    | data | The data to write. If data is not terminated by a new line character, it is appended. |  
 
 
 
§ _baudrate
  
  | 
        
          | int32_t BaseLib::SerialReaderWriter::_baudrate = 0 |  | protected | 
 
 
§ _bl
§ _device
  
  | 
        
          | std::string BaseLib::SerialReaderWriter::_device |  | protected | 
 
 
§ _fileDescriptor
  
  | 
        
          | std::shared_ptr<FileDescriptor> BaseLib::SerialReaderWriter::_fileDescriptor |  | protected | 
 
 
§ _flags
  
  | 
        
          | int32_t BaseLib::SerialReaderWriter::_flags = 0 |  | protected | 
 
 
§ _handles
  
  | 
        
          | int32_t BaseLib::SerialReaderWriter::_handles = 0 |  | protected | 
 
 
§ _openDeviceThread
  
  | 
        
          | std::thread BaseLib::SerialReaderWriter::_openDeviceThread |  | protected | 
 
 
§ _openDeviceThreadMutex
  
  | 
        
          | std::mutex BaseLib::SerialReaderWriter::_openDeviceThreadMutex |  | protected | 
 
 
§ _readThread
  
  | 
        
          | std::thread BaseLib::SerialReaderWriter::_readThread |  | protected | 
 
 
§ _readThreadMutex
  
  | 
        
          | std::mutex BaseLib::SerialReaderWriter::_readThreadMutex |  | protected | 
 
 
§ _readThreadPriority
  
  | 
        
          | int32_t BaseLib::SerialReaderWriter::_readThreadPriority = 0 |  | protected | 
 
 
§ _sendMutex
  
  | 
        
          | std::mutex BaseLib::SerialReaderWriter::_sendMutex |  | protected | 
 
 
§ _stopReadThread
  
  | 
        
          | std::atomic_bool BaseLib::SerialReaderWriter::_stopReadThread |  | protected | 
 
 
§ _termios
  
  | 
        
          | struct termios BaseLib::SerialReaderWriter::_termios |  | protected | 
 
 
§ _writeOnly
  
  | 
        
          | bool BaseLib::SerialReaderWriter::_writeOnly = false |  | protected | 
 
 
The documentation for this class was generated from the following files: