Serial.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
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   // Forbid copying.
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


fzi_icl_comm
Author(s):
autogenerated on Thu Jun 6 2019 21:31:31