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