|  |   
 INTRODUCTION
 Overview
 Download and Install
 Documentation
 Publications
 
 REPOSITORY
 Libraries
 
 DEVELOPER
 Dev Guide
 Dashboard
 
 PEOPLE
 Contributors
 Users
 
 
  Project
 Download
 Mailing lists
   |  |  | gbxserialacfr::Serial Class ReferenceEncapsulates a serial port.  
More...
#include <serial.h> 
List of all members. 
|  |  | 
 Public Member Functions |  |  | Serial (const std::string &dev, int baudRate, const Timeout &timeout, int debuglevel=0, bool useLockFile=true) |  |  | ~Serial () |  |  | Destructor closes serial port. 
 |  | void | setDebugLevel (int debugLevel) |  |  | Debug messages are printed to stdout. debugLevel should be in the range [0,3]. 
 |  | void | setBaudRate (int baud) |  |  | Sets the baud rate. Flushes any data. 
 |  | void | setTimeout (const Timeout &timeout) |  | const Timeout & | timeout () const |  | int | read (void *buf, int count) |  | int | readFull (void *buf, int count) |  | int | readStringUntil (std::string &str, char termchar) |  | int | readLine (std::string &str) |  | int | bytesAvailable () |  |  | Returns the number of bytes available for reading (non-blocking). 
 |  | int | bytesAvailableWait () |  | int | write (const void *buf, int count) |  |  | Writes some data. Returns the number of bytes written. 
 |  | int | writeString (const char *buf) |  | void | flush () |  | void | drain () |  |  | Finishes transmission from output buffers and drains input buffers. 
 |  | int | fileDescriptor () |  |  | This gives direct access to the file descriptor: be careful with this... 
 |  | std::string | getStatusString () |  |  | Print some diagnostic information about the current status of the port to cout. 
 |  
 Detailed DescriptionEncapsulates a serial port.
This class hard-codes some options, such as: 
8 data bitsno handshaking 
 Author:Matthew Ridley, Alex Brooks 
 
 
 Constructor & Destructor Documentation
      
        
          | gbxserialacfr::Serial::Serial | ( | const std::string & | dev, |  
          |  |  | int | baudRate, |  
          |  |  | const Timeout & | timeout, |  
          |  |  | int | debuglevel = 0, |  
          |  |  | bool | useLockFile = true |  |  
          |  | ) |  |  |  |  
Opens a device dev. Throws SerialException's or LockFileException's (both derive from std::exception) on error. Timeouts control the various read functions below. A timeout value of (sec=0,usec=0) indicates 'timeouts disabled'. If useLockFile is set to true, Serial will use the file-system to prevent concurrent access to a serial device by multiple instances of Serial. 
 
 Member Function Documentation
      
        
          | int gbxserialacfr::Serial::bytesAvailableWait | ( |  | ) |  |  
Returns the number of bytes available for reading. Waits according to the timeout. Returns: 
<0 : timed out>0 : data ready  
 
      
        
          | void gbxserialacfr::Serial::flush | ( |  | ) |  |  
Flushs both input and output buffers. This discards all data in buffers. 
 
 
      
        
          | int gbxserialacfr::Serial::read | ( | void * | buf, |  
          |  |  | int | count |  |  
          |  | ) |  |  |  |  
Reads up to countbytes into bufferbuf. Returns the number of bytes read, or '-1' on timeout (if timeouts are enabled). If timeouts are not enabled, blocks till it gets something. 
 
      
        
          | int gbxserialacfr::Serial::readFull | ( | void * | buf, |  
          |  |  | int | count |  |  
          |  | ) |  |  |  |  
Tries to read exactly countbytes intobuf. Returns the number of bytes read, or throws an exception. 
If timeouts are not enabled we might block forever, waiting for the number of bytes we want or an error. 
If timeouts are enabled we won't block more than the timeout specified. Returns -1 if it timed out. NOTE: The timeout applies for each individual read() call. We might have to make lots of them, so the total time for which this function blocks might be longer than the specified timeout. 
 
 
      
        
          | int gbxserialacfr::Serial::readLine | ( | std::string & | str | ) |  [inline] |  
Short-hand for "readStringUntil(str,'\n');" Reads everything up to and including the ''.
 
 
      
        
          | int gbxserialacfr::Serial::readStringUntil | ( | std::string & | str, |  
          |  |  | char | termchar |  |  
          |  | ) |  |  |  |  
Reads a string into , up to and including the first instance of  Returns the number of bytes read (or '-1' on timeout). 
If timeouts are not enabled we might block forever, waiting for the number of bytes we want or an error. 
If timeouts are enabled we won't block more than the timeout specified. Returns -1 if it timed out. NOTE: The timeout applies for each individual read() call. We might have to make lots of them, so the total time for which this function blocks might be longer than the specified timeout. 
 
 
      
        
          | void gbxserialacfr::Serial::setTimeout | ( | const Timeout & | timeout | ) |  |  
Sets timeout. Can be used to change the value of timeouts if they're set, but can't set the {en|dis}abled state of timeouts. 
 
 
      
        
          | const Timeout& gbxserialacfr::Serial::timeout | ( |  | ) | const  [inline] |  
Gets the current timeout. A timeout value of (sec=0,usec=0) indicates 'timeouts disabled'. 
 
 
      
        
          | int gbxserialacfr::Serial::writeString | ( | const char * | buf | ) |  |  
Writes a ("\0"-terminated) string. Returns the number of bytes written. 
 
 The documentation for this class was generated from the following files:
 |  |