serialport.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __SERIALPORT_H
00030 #define __SERIALPORT_H
00031
00032 #include <flexiport/port.h>
00033
00034 #include <map>
00035 #include <string>
00036 #if defined (WIN32)
00037 #include <Windows.h>
00038 #endif
00039
00044 namespace flexiport
00045 {
00046
00074 class FLEXIPORT_EXPORT SerialPort : public Port
00075 {
00076 public:
00077 SerialPort (std::map<std::string, std::string> options);
00078 ~SerialPort ();
00079
00081 void Open ();
00083 void Close ();
00085 ssize_t Read (void * const buffer, size_t count);
00087 ssize_t ReadFull (void * const buffer, size_t count);
00089 ssize_t BytesAvailable ();
00095 ssize_t BytesAvailableWait ();
00097 ssize_t Write (const void * const buffer, size_t count);
00099 void Flush ();
00101 void Drain ();
00103 std::string GetStatus () const;
00105 void SetTimeout (Timeout timeout);
00107 void SetCanRead (bool canRead);
00109 void SetCanWrite (bool canWrite);
00111 bool IsOpen () const { return _open; }
00112
00114 void SetBaudRate (unsigned int baud);
00116 unsigned int GetBaudRate () const { return _baud; }
00117
00118 private:
00119 #if defined (WIN32)
00120 HANDLE _fd;
00121 #else
00122 int _fd;
00123 #endif
00124
00125 std::string _device;
00126 unsigned int _baud;
00127 unsigned int _dataBits;
00128 unsigned int _stopBits;
00129 typedef enum {PAR_NONE, PAR_EVEN, PAR_ODD} Parity;
00130 Parity _parity;
00131 bool _hwFlowCtrl;
00132 bool _open;
00133
00134 void CheckPort (bool read);
00135 bool ProcessOption (const std::string &option, const std::string &value);
00136
00137 bool IsDataAvailable ();
00138 #if !defined (WIN32)
00139 typedef enum {TIMED_OUT, DATA_AVAILABLE, CAN_WRITE} WaitStatus;
00140 WaitStatus WaitForDataOrTimeout ();
00141 WaitStatus WaitForWritableOrTimeout ();
00142 #endif
00143 void SetPortSettings ();
00144 void SetPortTimeout ();
00145 };
00146
00147 }
00148
00151 #endif // __SERIALPORT_H
00152