Program Listing for File serial_stream.hpp

Return to documentation for file (/tmp/ws/src/ecl_core/ecl_streams/include/ecl/streams/serial_stream.hpp)

/*****************************************************************************
** Ifdefs
*****************************************************************************/

#ifndef ECL_STREAMS_SERIAL_STREAM_HPP_
#define ECL_STREAMS_SERIAL_STREAM_HPP_

/*****************************************************************************
** Includes
*****************************************************************************/

#include <string>
#include <ecl/config/macros.hpp>
#include <ecl/devices/serial.hpp>
#include <ecl/exceptions/standard_exception.hpp>
#include "text_stream.hpp"

/*****************************************************************************
** Namespaces
*****************************************************************************/

namespace ecl {

/*****************************************************************************
** Interfaces [SerialStream]
*****************************************************************************/
class ecl_streams_PUBLIC SerialStream : public TextStream<Serial> {
public:
    SerialStream() {};
    SerialStream(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)
    {
        ecl_try {
            this->device().open(port_name, baud_rate, data_bits, stop_bits, parity);
            if ( !this->device().open() ) {
                error = this->device().error();
            }
        } ecl_catch(StandardException &e) {
            ecl_throw(StandardException(LOC,e));
        }
    }
    virtual ~SerialStream() {};

};

} // namespace ecl


#endif /* ECL_STREAMS_SERIAL_STREAM_HPP_ */