serial  1.0
Cross-platformserialportlibraryforC++
 All Data Structures Namespaces Files Functions Enumerations Enumerator Defines
include/serial/impl/unix.h
Go to the documentation of this file.
00001 
00038 #ifndef SERIAL_IMPL_UNIX_H
00039 #define SERIAL_IMPL_UNIX_H
00040 
00041 #include "serial/serial.h"
00042 
00043 #include <pthread.h>
00044 
00045 namespace serial {
00046 
00047 using std::string;
00048 using std::invalid_argument;
00049 
00050 using serial::SerialExecption;
00051 using serial::IOException;
00052 
00053 class serial::Serial::SerialImpl {
00054 public:
00055   SerialImpl (const string &port,
00056               unsigned long baudrate,
00057               long timeout,
00058               bytesize_t bytesize,
00059               parity_t parity,
00060               stopbits_t stopbits,
00061               flowcontrol_t flowcontrol);
00062 
00063   virtual ~SerialImpl ();
00064 
00065   void
00066   open ();
00067 
00068   void
00069   close ();
00070 
00071   bool
00072   isOpen () const;
00073 
00074   size_t
00075   available ();
00076 
00077   size_t
00078   read (unsigned char* buf, size_t size = 1);
00079 
00080   size_t
00081   write (const string &data);
00082 
00083   void
00084   flush ();
00085 
00086   void
00087   flushInput ();
00088 
00089   void
00090   flushOutput ();
00091 
00092   void
00093   sendBreak(int duration);
00094 
00095   void
00096   setBreak(bool level);
00097 
00098   void
00099   setRTS(bool level);
00100 
00101   void
00102   setDTR(bool level);
00103 
00104   bool
00105   getCTS();
00106 
00107   bool
00108   getDSR();
00109 
00110   bool
00111   getRI();
00112 
00113   bool
00114   getCD();
00115 
00116   void
00117   setPort (const string &port);
00118 
00119   string
00120   getPort () const;
00121 
00122   void
00123   setTimeout (long timeout);
00124 
00125   long
00126   getTimeout () const;
00127 
00128   void
00129   setBaudrate (unsigned long baudrate);
00130 
00131   unsigned long
00132   getBaudrate () const;
00133 
00134   void
00135   setBytesize (bytesize_t bytesize);
00136 
00137   bytesize_t
00138   getBytesize () const;
00139 
00140   void
00141   setParity (parity_t parity);
00142 
00143   parity_t
00144   getParity () const;
00145 
00146   void
00147   setStopbits (stopbits_t stopbits);
00148 
00149   stopbits_t
00150   getStopbits () const;
00151 
00152   void
00153   setFlowcontrol (flowcontrol_t flowcontrol);
00154 
00155   flowcontrol_t
00156   getFlowcontrol () const;
00157 
00158   void
00159   readLock();
00160 
00161   void
00162   readUnlock();
00163 
00164   void
00165   writeLock();
00166 
00167   void
00168   writeUnlock();
00169 
00170 protected:
00171   void reconfigurePort ();
00172 
00173 private:
00174   string port_;               // Path to the file descriptor
00175   int fd_;                    // The current file descriptor
00176 
00177   bool is_open_;
00178   bool xonxoff_;
00179   bool rtscts_;
00180 
00181   long timeout_;              // Timeout for read operations
00182   unsigned long baudrate_;    // Baudrate
00183 
00184   parity_t parity_;           // Parity
00185   bytesize_t bytesize_;       // Size of the bytes
00186   stopbits_t stopbits_;       // Stop Bits
00187   flowcontrol_t flowcontrol_; // Flow Control
00188 
00189   // Mutex used to lock the read functions
00190   pthread_mutex_t read_mutex;
00191   // Mutex used to lock the write functions
00192   pthread_mutex_t write_mutex;
00193 };
00194 
00195 }
00196 
00197 #endif // SERIAL_IMPL_UNIX_H