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 
00029 class SerialIO
00030 {
00031 public:
00032         // ---------------------- Constants
00034         enum HandshakeFlags
00035         {
00036                 HS_NONE,
00037                 HS_HARDWARE,
00038                 HS_XONXOFF
00039         };
00040 
00042         enum ParityFlags
00043         {
00044                 PA_NONE,
00045                 PA_EVEN,
00046                 PA_ODD,
00047 // UNIX serial drivers only support even, odd, and no parity bit generation.
00048                 PA_MARK,
00049                 PA_SPACE
00050         };
00051 
00053         enum StopBits
00054         {
00055                 SB_ONE,
00056                 SB_ONE_5, // ????? returns an error ?????
00057                 SB_TWO
00058         };
00059 
00061         SerialIO();
00062 
00064         virtual ~SerialIO();
00065 
00070         void setDeviceName(const char *Name) { m_DeviceName = Name; }
00071 
00076         void setBaudRate(int BaudRate) { m_BaudRate = BaudRate; }
00077 
00083         void changeBaudRate(int BaudRate);
00084 
00090         void setMultiplier(double Multiplier = 1) { m_Multiplier = Multiplier; };
00091 
00095         void SetFormat(int ByteSize, ParityFlags Parity, int StopBits)
00096                 { m_ByteSize = ByteSize; m_Parity = Parity; m_StopBits = StopBits; }
00097 
00101         void setHandshake(HandshakeFlags Handshake) { m_Handshake = Handshake; }
00102 
00108         void setBufferSize(int ReadBufSize, int WriteBufSize)
00109                 { m_ReadBufSize = ReadBufSize; m_WriteBufSize = WriteBufSize; }
00110 
00115         void setTimeout(double Timeout);
00116 
00123         void setBytePeriod(double Period);
00124 
00129         int openIO();
00130 
00134         void closeIO();
00135 
00143         int readBlocking(char *Buffer, int Length);
00144 
00145 
00152         int readNonBlocking(char *Buffer, int Length);
00153 
00159         int writeIO(const char *Buffer, int Length);
00160 
00164         int getSizeRXQueue();
00165 
00166 
00169         void purge()
00170         {
00171                 ::tcflush(m_Device, TCIOFLUSH);
00172         }
00173 
00176         void purgeRx() {
00177                 tcflush(m_Device, TCIFLUSH);
00178 }
00179 
00184         void purgeTx() {
00185                 tcflush(m_Device, TCOFLUSH);
00186         }
00187 
00192         void flushTx() {
00193                 tcdrain(m_Device);
00194         }
00195 
00196 protected:
00197         ::termios m_tio;
00198         std::string m_DeviceName;
00199         int m_Device;
00200         int m_BaudRate;
00201         double m_Multiplier;
00202         int m_ByteSize, m_StopBits;
00203         ParityFlags m_Parity;
00204         HandshakeFlags m_Handshake;
00205         int m_ReadBufSize, m_WriteBufSize;
00206         double m_Timeout;
00207         ::timeval m_BytePeriod;
00208         bool m_ShortBytePeriod;
00209 };
00210 
00211 
00212 #endif //
00213 


cob_relayboard
Author(s): Christian Connette
autogenerated on Sat Jun 8 2019 21:02:18