SerialIO.h
Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2010
00004  *
00005  * Fraunhofer Institute for Manufacturing Engineering   
00006  * and Automation (IPA)
00007  *
00008  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00009  *
00010  * Project name: care-o-bot
00011  * ROS stack name: cob_driver
00012  * ROS package name: cob_sick_s300
00013  * Description:
00014  *                                                              
00015  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00016  *                      
00017  * Author: Christian Connette, email:christian.connette@ipa.fhg.de
00018  * Supervised by: Christian Connette, email:christian.connette@ipa.fhg.de
00019  *
00020  * Date of creation: Jan 2009
00021  * ToDo:
00022  *
00023  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00024  *
00025  * Redistribution and use in source and binary forms, with or without
00026  * modification, are permitted provided that the following conditions are met:
00027  *
00028  *     * Redistributions of source code must retain the above copyright
00029  *       notice, this list of conditions and the following disclaimer.
00030  *     * Redistributions in binary form must reproduce the above copyright
00031  *       notice, this list of conditions and the following disclaimer in the
00032  *       documentation and/or other materials provided with the distribution.
00033  *     * Neither the name of the Fraunhofer Institute for Manufacturing 
00034  *       Engineering and Automation (IPA) nor the names of its
00035  *       contributors may be used to endorse or promote products derived from
00036  *       this software without specific prior written permission.
00037  *
00038  * This program is free software: you can redistribute it and/or modify
00039  * it under the terms of the GNU Lesser General Public License LGPL as 
00040  * published by the Free Software Foundation, either version 3 of the 
00041  * License, or (at your option) any later version.
00042  * 
00043  * This program is distributed in the hope that it will be useful,
00044  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00045  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00046  * GNU Lesser General Public License LGPL for more details.
00047  * 
00048  * You should have received a copy of the GNU Lesser General Public 
00049  * License LGPL along with this program. 
00050  * If not, see <http://www.gnu.org/licenses/>.
00051  *
00052  ****************************************************************/
00053 
00054 #ifndef _SerialIO_H
00055 #define _SerialIO_H
00056 
00057 #include <termios.h>
00058 #include <sys/select.h>
00059 
00060 #include <string>
00061 #include <string.h>
00062 
00066 class SerialIO  
00067 {
00068 public:
00069         // ---------------------- Constants
00071         enum HandshakeFlags
00072         {
00073                 HS_NONE,
00074                 HS_HARDWARE,
00075                 HS_XONXOFF
00076         };
00077 
00079         enum ParityFlags 
00080         { 
00081                 PA_NONE, 
00082                 PA_EVEN,
00083                 PA_ODD,
00084 // UNIX serial drivers only support even, odd, and no parity bit generation.
00085                 PA_MARK,
00086                 PA_SPACE
00087         };
00088 
00090         enum StopBits
00091         { 
00092                 SB_ONE, 
00093                 SB_ONE_5, // ????? returns an error ?????
00094                 SB_TWO 
00095         };
00096 
00098         SerialIO();
00099 
00101         virtual ~SerialIO();
00102 
00107         void setDeviceName(const char *Name) { m_DeviceName = Name; }
00108 
00113         void setBaudRate(int BaudRate) { m_BaudRate = BaudRate; }
00114 
00120         void changeBaudRate(int BaudRate);
00121 
00127         void setMultiplier(double Multiplier = 1) { m_Multiplier = Multiplier; };
00128 
00132         void SetFormat(int ByteSize, ParityFlags Parity, int StopBits)
00133                 { m_ByteSize = ByteSize; m_Parity = Parity; m_StopBits = StopBits; }
00134 
00138         void setHandshake(HandshakeFlags Handshake) { m_Handshake = Handshake; }
00139 
00145         void setBufferSize(int ReadBufSize, int WriteBufSize)
00146                 { m_ReadBufSize = ReadBufSize; m_WriteBufSize = WriteBufSize; }
00147 
00152         void setTimeout(double Timeout);
00153 
00160         void setBytePeriod(double Period);
00161 
00166         int openIO();
00167 
00171         void closeIO();
00172 
00180         int readBlocking(char *Buffer, int Length);
00181 
00182 
00189         int readNonBlocking(char *Buffer, int Length);
00190 
00196         int writeIO(const char *Buffer, int Length);
00197 
00201         int getSizeRXQueue();
00202 
00203 
00206         void purge()
00207         {
00208                 ::tcflush(m_Device, TCIOFLUSH);
00209         }
00210 
00213         void purgeRx() {
00214                 tcflush(m_Device, TCIFLUSH);
00215 }
00216 
00221         void purgeTx() {
00222                 tcflush(m_Device, TCOFLUSH);
00223         }
00224 
00229         void flushTx() {
00230                 tcdrain(m_Device);
00231         }
00232 
00233 protected:
00234         ::termios m_tio;
00235         std::string m_DeviceName;
00236         int m_Device;
00237         int m_BaudRate;
00238         double m_Multiplier;
00239         int m_ByteSize, m_StopBits;
00240         ParityFlags m_Parity;
00241         HandshakeFlags m_Handshake;
00242         int m_ReadBufSize, m_WriteBufSize;
00243         double m_Timeout;
00244         ::timeval m_BytePeriod;
00245         bool m_ShortBytePeriod;
00246 };
00247 
00248 
00249 #endif //
00250 


cob_sick_s300
Author(s): Florian Weisshardt
autogenerated on Thu Aug 27 2015 12:45:42