Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00028
00029 #ifndef ICL_COMM_SERIAL_SERIAL_H_INCLUDED
00030 #define ICL_COMM_SERIAL_SERIAL_H_INCLUDED
00031
00032 #include <icl_core/BaseTypes.h>
00033
00034 #include "icl_comm_serial/ImportExport.h"
00035 #include "icl_comm_serial/Logging.h"
00036 #include "icl_comm_serial/SerialFlags.h"
00037
00038 #ifdef _SYSTEM_WIN32_
00039 typedef unsigned int speed_t;
00040 typedef int ssize_t;
00041 #endif
00042
00043 #ifdef _SYSTEM_POSIX_
00044 # include <unistd.h>
00045 # ifdef _SYSTEM_DARWIN_
00046 # include <termios.h>
00047 # else
00048 # include <termio.h>
00049 # endif
00050 #endif
00051
00052 namespace icl_comm {
00053 namespace serial {
00054
00056
00060 class ICL_COMM_SERIAL_IMPORT_EXPORT Serial
00061 {
00062 public:
00080 Serial(const char* dev_name, const SerialFlags& flags);
00081
00086 Serial(const char* dev_name, SerialFlags::BaudRate baud_rate, const SerialFlags& flags);
00087
00091 ~Serial();
00100 int ChangeBaudrate(SerialFlags::BaudRate speed);
00101
00105 int ClearReceiveBuffer();
00106
00110 int ClearSendBuffer();
00111
00115 bool Open(const SerialFlags& flags)
00116 {
00117 m_serial_flags=flags;
00118 return Open();
00119 }
00120
00124 bool Open();
00125
00130 bool IsOpen() const;
00131
00135 void Close();
00136
00137
00141 ssize_t Write(const void *data, ssize_t size);
00150 ssize_t Read(void *data, ssize_t size, unsigned long time = 100, bool return_on_less_data = true);
00158 int Status() const
00159 {
00160 return m_status;
00161 }
00162
00163 std::string StatusText() const;
00164
00165 const char* DeviceName()const { return m_dev_name;}
00166
00170 int FileDescriptor()
00171 {
00172 #ifdef _SYSTEM_POSIX_
00173 return file_descr;
00174 #else
00175 return 0;
00176 #endif
00177 }
00178
00179 private:
00180
00181 Serial(const Serial&);
00182 Serial& operator = (const Serial&);
00183
00184 void DumpData(void *data, size_t length);
00185
00186 #ifdef _SYSTEM_WIN32_
00187 HANDLE m_com;
00188 unsigned char m_read_buffer[0x4000];
00189 ssize_t m_read_buffer_fill;
00190 #endif
00191
00192 #ifdef _SYSTEM_POSIX_
00193 int file_descr;
00194 termios io_set_old;
00195
00196 bool is_lxrt_serial;
00197 # ifdef _SYSTEM_LXRT_
00198 bool IsLXRTDeviceName(const char* device_name);
00199 int tty;
00200 # endif
00201 #endif
00202
00203 char *m_dev_name;
00204 SerialFlags m_serial_flags;
00205 int m_status;
00206
00207 };
00208
00209 }
00210 }
00211
00212 #endif