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_relayboard
00013  * Description: Class for communication with relayboard. The relayboard is mainly used for reading the Emergencystop and Laserscannerstop states.
00014  *                                                              
00015  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00016  *                      
00017  * Author: Philipp Koehler
00018  * Supervised by: Christian Connette, email:christian.connette@ipa.fhg.de
00019  *
00020  * Date of creation: March 2010
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 
00065 class SerialIO  
00066 {
00067 public:
00068         // ---------------------- Constants
00070         enum HandshakeFlags
00071         {
00072                 HS_NONE,
00073                 HS_HARDWARE,
00074                 HS_XONXOFF
00075         };
00076 
00078         enum ParityFlags 
00079         { 
00080                 PA_NONE, 
00081                 PA_EVEN,
00082                 PA_ODD,
00083 // UNIX serial drivers only support even, odd, and no parity bit generation.
00084                 PA_MARK,
00085                 PA_SPACE
00086         };
00087 
00089         enum StopBits
00090         { 
00091                 SB_ONE, 
00092                 SB_ONE_5, // ????? returns an error ?????
00093                 SB_TWO 
00094         };
00095 
00097         SerialIO();
00098 
00100         virtual ~SerialIO();
00101 
00106         void setDeviceName(const char *Name) { m_DeviceName = Name; }
00107 
00112         void setBaudRate(int BaudRate) { m_BaudRate = BaudRate; }
00113 
00119         void changeBaudRate(int BaudRate);
00120 
00126         void setMultiplier(double Multiplier = 1) { m_Multiplier = Multiplier; };
00127 
00131         void SetFormat(int ByteSize, ParityFlags Parity, int StopBits)
00132                 { m_ByteSize = ByteSize; m_Parity = Parity; m_StopBits = StopBits; }
00133 
00137         void setHandshake(HandshakeFlags Handshake) { m_Handshake = Handshake; }
00138 
00144         void setBufferSize(int ReadBufSize, int WriteBufSize)
00145                 { m_ReadBufSize = ReadBufSize; m_WriteBufSize = WriteBufSize; }
00146 
00151         void setTimeout(double Timeout);
00152 
00159         void setBytePeriod(double Period);
00160 
00165         int open();
00166 
00170         void close();
00171 
00179         int readBlocking(char *Buffer, int Length);
00180 
00181 
00188         int readNonBlocking(char *Buffer, int Length);
00189 
00195         int write(const char *Buffer, int Length);
00196 
00200         int getSizeRXQueue();
00201 
00202 
00205         void purge()
00206         {
00207                 ::tcflush(m_Device, TCIOFLUSH);
00208         }
00209 
00212         void purgeRx() {
00213                 tcflush(m_Device, TCIFLUSH);
00214 }
00215 
00220         void purgeTx() {
00221                 tcflush(m_Device, TCOFLUSH);
00222         }
00223 
00228         void flushTx() {
00229                 tcdrain(m_Device);
00230         }
00231 
00232 protected:
00233         ::termios m_tio;
00234         std::string m_DeviceName;
00235         int m_Device;
00236         int m_BaudRate;
00237         double m_Multiplier;
00238         int m_ByteSize, m_StopBits;
00239         ParityFlags m_Parity;
00240         HandshakeFlags m_Handshake;
00241         int m_ReadBufSize, m_WriteBufSize;
00242         double m_Timeout;
00243         ::timeval m_BytePeriod;
00244         bool m_ShortBytePeriod;
00245 };
00246 
00247 
00248 #endif //
00249 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


cob_relayboard
Author(s): Christian Connette
autogenerated on Fri Mar 1 2013 17:46:29