serial_w32.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_THREADS_SERIAL_W32_HPP_
13 #define ECL_THREADS_SERIAL_W32_HPP_
14 
15 /*****************************************************************************
16 ** Platform Check
17 *****************************************************************************/
18 
19 #include <ecl/config.hpp>
20 #ifdef ECL_IS_WIN32
21 
22 /*****************************************************************************
23 ** Includes
24 *****************************************************************************/
25 
26 #include <windows.h>
27 #include <string>
30 #include <ecl/threads/thread.hpp>
31 #include "serial_parameters.hpp"
32 #include "traits.hpp"
33 #include "macros.hpp"
34 
35 /*****************************************************************************
36 ** Namespaces
37 *****************************************************************************/
38 
39 namespace ecl {
40 
41 /*****************************************************************************
42 ** Interface [Serial]
43 *****************************************************************************/
115 class ecl_devices_PUBLIC Serial {
116 public:
117  /*********************
118  ** C&D
119  **********************/
127  Serial() : is_open(false), is_run(false), file_descriptor(INVALID_HANDLE_VALUE), error_handler(NoError) {};
144  Serial(const std::string& port_name, const BaudRate &baud_rate = BaudRate_115200, const DataBits &data_bits = DataBits_8,
145  const StopBits &stop_bits = StopBits_1, const Parity &parity = NoParity ) ecl_throw_decl(StandardException);
146 
152  virtual ~Serial();
153 
154  /*********************
155  ** Open/Close
156  **********************/
173  void open(const std::string& port_name, const BaudRate &baud_rate = BaudRate_115200, const DataBits &data_bits = DataBits_8,
174  const StopBits &stop_bits = StopBits_1, const Parity &parity = NoParity ) ecl_throw_decl(StandardException);
175 
183  void close();
189  bool open() const { return is_open; }
190 
191  /*********************
192  ** Writing
193  **********************/
202  long write(const char &c) ecl_assert_throw_decl(StandardException);
203 
212  long write(const char *s, unsigned long n) ecl_assert_throw_decl(StandardException);
213 
220  void flush() {}
221 
222  /*********************
223  ** Reading Modes
224  **********************/
234  void block(const long &timeout = 500) ecl_assert_throw_decl(StandardException);
241  void unblock();
242 
243  /*********************
244  ** Reading
245  **********************/
253  long remaining();
264  long read(char &c) ecl_assert_throw_decl(StandardException);
276  long read(char *s, const unsigned long &n) ecl_assert_throw_decl(StandardException);
277 
278 
279  /*********************
280  ** Serial Specific
281  **********************/
288  void clear() {
289  PurgeComm( file_descriptor, PURGE_RXCLEAR );
290  PurgeComm( file_descriptor, PURGE_TXCLEAR );
291  }
297  void clearInputBuffer() { PurgeComm( file_descriptor, PURGE_RXCLEAR ); }
303  void clearOutputBuffer() { PurgeComm( file_descriptor, PURGE_TXCLEAR ); }
304 
311  const Error& error() const { return error_handler; }
312 
313 private:
314  /*********************
315  ** Variables
316  **********************/
317  HANDLE file_descriptor;
318  OVERLAPPED m_osRead, m_osWrite; // Offsets
319  std::string port;
320  bool is_open;
321  ecl::Error error_handler;
322  Thread event_receiver;
323  bool is_run;
324 
325 private:
331  friend void event_proc(void* arg);
332 
333 };
334 
335 /*****************************************************************************
336 ** Traits [Serial]
337 *****************************************************************************/
343 template <>
344 class is_sink<Serial> : public True {};
345 
351 template <>
352 class is_source<Serial> : public True {};
353 
359 template <>
360 class is_sourcesink<Serial> : public True {};
361 
362 } // namespace ecl
363 
364 #endif /* ECL_IS_WIN32 */
365 #endif /* ECL_THREADS_SERIAL_W32_HPP_ */
StopBits
Stop bits used in a serial packet.
Embedded control libraries.
Cross-platform abstractions for the serial class.
Parity
Parity of the serial packet.
Bool< true > True
DataBits
Data bits used in a serial packet.
#define ecl_assert_throw_decl(exception)
#define ecl_devices_PUBLIC
Definition: macros.hpp:37
BaudRate
Serial connection baud rate.


ecl_devices
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:45