Go to the documentation of this file.00001
00008
00009
00010
00011
00012 #ifndef ECL_THREADS_SERIAL_W32_HPP_
00013 #define ECL_THREADS_SERIAL_W32_HPP_
00014
00015
00016
00017
00018
00019 #include <ecl/config.hpp>
00020 #ifdef ECL_IS_WIN32
00021
00022
00023
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
00035
00036
00037 namespace ecl {
00038
00039
00040
00041
00113 class Serial {
00114 public:
00115
00116
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
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
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
00222
00232 void block(const long &timeout = 500) ecl_assert_throw_decl(StandardException);
00239 void unblock();
00240
00241
00242
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
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
00314
00315 HANDLE file_descriptor;
00316 OVERLAPPED m_osRead, m_osWrite;
00317 std::string port;
00318 bool is_open;
00319 ecl::Error error_handler;
00320
00321 };
00322
00323
00324
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 }
00351
00352 #endif
00353 #endif