00001 //============================================================================ 00002 // Name : LxSerial.cpp 00003 // Author : Wouter Caarls,www.dbl.tudelft.nl 00004 // Version : 0.1 00005 // Copyright : Copyright (c) 2013 LGPL 00006 // Description : serial communicatin class linux FTDI 00007 //============================================================================ 00008 00009 #ifndef LXFTDI_H_ 00010 #define LXFTDI_H_ 00011 //#define __DBG__ 00012 00013 #include <ftdi.hpp> 00014 #include <threemxl/platform/hardware/serial/LxSerial.h> 00015 00016 class LxFTDI : public LxSerial 00017 { 00018 protected: 00019 Ftdi::Context dev; 00020 std::string description; 00021 00022 public: 00023 LxFTDI(); 00024 virtual ~LxFTDI(); 00025 virtual bool port_open(const std::string& portname, LxSerial::PortType port_type); // open serial port. If overridden, make sure you set s_port_name!! 00026 virtual bool is_port_open() { return dev.is_open(); } 00027 std::string& get_port_name() { description = dev.description(); return description; } 00028 virtual bool set_speed(LxSerial::PortSpeed baudrate ) { fprintf(stderr, "Unsupported function. Use set_speed_int.\n"); return false;} 00029 virtual bool set_speed_int(const int baudrate); // Set speed by integer value directly - UNPROTECTED! 00030 void set_clear_echo(bool clear) { } 00031 virtual bool port_close(); 00032 virtual int port_read(unsigned char* buffer, int numBytes); 00033 virtual int port_read(unsigned char* buffer, int numBytes, int seconds, int microseconds); 00034 virtual int port_write(unsigned char* buffer, int numBytes); 00035 virtual void flush_buffer(); // flush input and output buffers 00036 }; 00037 00038 #endif /*LXFTDI_H_*/