$search
00001 00008 /***************************************************************************** 00009 ** Ifdefs 00010 *****************************************************************************/ 00011 00012 #ifndef ECL_THREADS_SERIAL_W32_HPP_ 00013 #define ECL_THREADS_SERIAL_W32_HPP_ 00014 00015 /***************************************************************************** 00016 ** Platform Check 00017 *****************************************************************************/ 00018 00019 #include <ecl/config.hpp> 00020 #ifdef ECL_IS_WIN32 00021 00022 /***************************************************************************** 00023 ** Includes 00024 *****************************************************************************/ 00025 00026 #include <windows.h> 00027 #include <string> 00028 #include <ecl/exceptions/standard_exception.hpp> 00029 #include <ecl/utilities/parameter.hpp> 00030 #include "serial_parameters.hpp" 00031 #include "traits.hpp" 00032 00033 /***************************************************************************** 00034 ** Namespaces 00035 *****************************************************************************/ 00036 00037 namespace ecl { 00038 00039 /***************************************************************************** 00040 ** Interface [Serial] 00041 *****************************************************************************/ 00113 class Serial { 00114 public: 00115 /********************* 00116 ** C&D 00117 **********************/ 00125 Serial() : is_open(false), error_handler(NoError) {}; 00142 Serial(const std::string& port_name, const BaudRate &baud_rate = BaudRate_115200, const DataBits &data_bits = DataBits_8, 00143 const StopBits &stop_bits = StopBits_1, const Parity &parity = NoParity ) ecl_throw_decl(StandardException); 00144 00150 virtual ~Serial(); 00151 00152 /********************* 00153 ** Open/Close 00154 **********************/ 00171 void open(const std::string& port_name, const BaudRate &baud_rate = BaudRate_115200, const DataBits &data_bits = DataBits_8, 00172 const StopBits &stop_bits = StopBits_1, const Parity &parity = NoParity ) ecl_throw_decl(StandardException); 00173 00181 void close(); 00187 bool open() const { return is_open; } 00188 00189 /********************* 00190 ** Writing 00191 **********************/ 00200 long write(const char &c) ecl_assert_throw_decl(StandardException); 00201 00210 long write(const char *s, unsigned long n) ecl_assert_throw_decl(StandardException); 00211 00218 void flush() {} 00219 00220 /********************* 00221 ** Reading Modes 00222 **********************/ 00232 void block(const long &timeout = 500) ecl_assert_throw_decl(StandardException); 00239 void unblock(); 00240 00241 /********************* 00242 ** Reading 00243 **********************/ 00251 long remaining(); 00262 long read(char &c) ecl_assert_throw_decl(StandardException); 00274 long read(char *s, const unsigned long &n) ecl_assert_throw_decl(StandardException); 00275 00276 00277 /********************* 00278 ** Serial Specific 00279 **********************/ 00286 void clear() { 00287 PurgeComm( file_descriptor, PURGE_RXCLEAR ); 00288 PurgeComm( file_descriptor, PURGE_TXCLEAR ); 00289 } 00295 void clearInputBuffer() { PurgeComm( file_descriptor, PURGE_RXCLEAR ); } 00301 void clearOutputBuffer() { PurgeComm( file_descriptor, PURGE_TXCLEAR ); } 00302 00309 const Error& error() const { return error_handler; } 00310 00311 private: 00312 /********************* 00313 ** Variables 00314 **********************/ 00315 HANDLE file_descriptor; 00316 OVERLAPPED m_osRead, m_osWrite; // Offsets 00317 std::string port; 00318 bool is_open; 00319 ecl::Error error_handler; 00320 00321 }; 00322 00323 /***************************************************************************** 00324 ** Traits [Serial] 00325 *****************************************************************************/ 00331 template <> 00332 class is_sink<Serial> : public True {}; 00333 00339 template <> 00340 class is_source<Serial> : public True {}; 00341 00347 template <> 00348 class is_sourcesink<Serial> : public True {}; 00349 00350 } // namespace ecl 00351 00352 #endif /* ECL_IS_WIN32 */ 00353 #endif /* ECL_THREADS_SERIAL_W32_HPP_ */