.. _program_listing_file__tmp_ws_src_ecl_core_ecl_devices_include_ecl_devices_serial_w32.hpp: Program Listing for File serial_w32.hpp ======================================= |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/ecl_core/ecl_devices/include/ecl/devices/serial_w32.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /***************************************************************************** ** Ifdefs *****************************************************************************/ #ifndef ECL_THREADS_SERIAL_W32_HPP_ #define ECL_THREADS_SERIAL_W32_HPP_ /***************************************************************************** ** Platform Check *****************************************************************************/ #include #ifdef ECL_IS_WIN32 /***************************************************************************** ** Includes *****************************************************************************/ #include #include #include #include #include #include "serial_parameters.hpp" #include "traits.hpp" #include "macros.hpp" /***************************************************************************** ** Namespaces *****************************************************************************/ namespace ecl { /***************************************************************************** ** Interface [Serial] *****************************************************************************/ class ecl_devices_PUBLIC Serial { public: /********************* ** C&D **********************/ Serial() : is_open(false), is_run(false), file_descriptor(INVALID_HANDLE_VALUE), error_handler(NoError) {}; Serial(const std::string& port_name, const BaudRate &baud_rate = BaudRate_115200, const DataBits &data_bits = DataBits_8, const StopBits &stop_bits = StopBits_1, const Parity &parity = NoParity ); virtual ~Serial(); /********************* ** Open/Close **********************/ void open(const std::string& port_name, const BaudRate &baud_rate = BaudRate_115200, const DataBits &data_bits = DataBits_8, const StopBits &stop_bits = StopBits_1, const Parity &parity = NoParity ); void close(); bool open() const { return is_open; } /********************* ** Writing **********************/ long write(const char &c); long write(const char *s, unsigned long n); void flush() {} /********************* ** Reading Modes **********************/ void block(const long &timeout = 500); void unblock(); /********************* ** Reading **********************/ long remaining(); long read(char &c); long read(char *s, const unsigned long &n); /********************* ** Serial Specific **********************/ void clear() { PurgeComm( file_descriptor, PURGE_RXCLEAR ); PurgeComm( file_descriptor, PURGE_TXCLEAR ); } void clearInputBuffer() { PurgeComm( file_descriptor, PURGE_RXCLEAR ); } void clearOutputBuffer() { PurgeComm( file_descriptor, PURGE_TXCLEAR ); } const Error& error() const { return error_handler; } private: /********************* ** Variables **********************/ HANDLE file_descriptor; OVERLAPPED m_osRead, m_osWrite; // Offsets std::string port; bool is_open; ecl::Error error_handler; Thread event_receiver; bool is_run; private: friend void event_proc(void* arg); }; /***************************************************************************** ** Traits [Serial] *****************************************************************************/ template <> class is_sink : public True {}; template <> class is_source : public True {}; template <> class is_sourcesink : public True {}; } // namespace ecl #endif /* ECL_IS_WIN32 */ #endif /* ECL_THREADS_SERIAL_W32_HPP_ */