SerialIO.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016  
00017 
00018 #ifndef _SerialIO_H
00019 #define _SerialIO_H
00020 
00021 #include <termios.h>
00022 #include <sys/select.h>
00023 
00024 #include <string>
00025 #include <string.h>
00026 
00030 class SerialIO
00031 {
00032 public:
00033         // ---------------------- Constants
00035         enum HandshakeFlags
00036         {
00037                 HS_NONE,
00038                 HS_HARDWARE,
00039                 HS_XONXOFF
00040         };
00041 
00043         enum ParityFlags
00044         {
00045                 PA_NONE,
00046                 PA_EVEN,
00047                 PA_ODD,
00048 // UNIX serial drivers only support even, odd, and no parity bit generation.
00049                 PA_MARK,
00050                 PA_SPACE
00051         };
00052 
00054         enum StopBits
00055         {
00056                 SB_ONE,
00057                 SB_ONE_5, // ????? returns an error ?????
00058                 SB_TWO
00059         };
00060 
00062         SerialIO();
00063 
00065         virtual ~SerialIO();
00066 
00071         void setDeviceName(const char *Name) { m_DeviceName = Name; }
00072 
00077         void setBaudRate(int BaudRate) { m_BaudRate = BaudRate; }
00078 
00084         void changeBaudRate(int BaudRate);
00085 
00091         void setMultiplier(double Multiplier = 1) { m_Multiplier = Multiplier; };
00092 
00096         void SetFormat(int ByteSize, ParityFlags Parity, int StopBits)
00097                 { m_ByteSize = ByteSize; m_Parity = Parity; m_StopBits = StopBits; }
00098 
00102         void setHandshake(HandshakeFlags Handshake) { m_Handshake = Handshake; }
00103 
00109         void setBufferSize(int ReadBufSize, int WriteBufSize)
00110                 { m_ReadBufSize = ReadBufSize; m_WriteBufSize = WriteBufSize; }
00111 
00116         void setTimeout(double Timeout);
00117 
00124         void setBytePeriod(double Period);
00125 
00130         int openIO();
00131 
00135         void closeIO();
00136 
00144         int readBlocking(char *Buffer, int Length);
00145 
00146 
00153         int readNonBlocking(char *Buffer, int Length);
00154 
00160         int writeIO(const char *Buffer, int Length);
00161 
00165         int getSizeRXQueue();
00166 
00167 
00170         void purge()
00171         {
00172                 ::tcflush(m_Device, TCIOFLUSH);
00173         }
00174 
00177         void purgeRx() {
00178                 tcflush(m_Device, TCIFLUSH);
00179 }
00180 
00185         void purgeTx() {
00186                 tcflush(m_Device, TCOFLUSH);
00187         }
00188 
00193         void flushTx() {
00194                 tcdrain(m_Device);
00195         }
00196 
00197 protected:
00198         ::termios m_tio;
00199         std::string m_DeviceName;
00200         int m_Device;
00201         int m_BaudRate;
00202         double m_Multiplier;
00203         int m_ByteSize, m_StopBits;
00204         ParityFlags m_Parity;
00205         HandshakeFlags m_Handshake;
00206         int m_ReadBufSize, m_WriteBufSize;
00207         double m_Timeout;
00208         ::timeval m_BytePeriod;
00209         bool m_ShortBytePeriod;
00210 };
00211 
00212 
00213 #endif //
00214 


cob_sick_s300
Author(s): Florian Weisshardt
autogenerated on Sat Jun 8 2019 21:02:23