SerialIO.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef _SerialIO_H
19 #define _SerialIO_H
20 
21 #include <termios.h>
22 #include <sys/select.h>
23 
24 #include <string>
25 
29 class SerialIO
30 {
31 public:
32  // ---------------------- Constants
35  {
39  };
40 
43  {
47 // UNIX serial drivers only support even, odd, and no parity bit generation.
50  };
51 
53  enum StopBits
54  {
56  SB_ONE_5, // ????? returns an error ?????
58  };
59 
61  SerialIO();
62 
64  virtual ~SerialIO();
65 
70  void setDeviceName(const char *Name) { m_DeviceName = Name; }
71 
76  void setBaudRate(int BaudRate) { m_BaudRate = BaudRate; }
77 
83  void changeBaudRate(int BaudRate);
84 
90  void setMultiplier(double Multiplier = 1) { m_Multiplier = Multiplier; };
91 
95  void SetFormat(int ByteSize, ParityFlags Parity, int StopBits)
96  { m_ByteSize = ByteSize; m_Parity = Parity; m_StopBits = StopBits; }
97 
101  void setHandshake(HandshakeFlags Handshake) { m_Handshake = Handshake; }
102 
108  void setBufferSize(int ReadBufSize, int WriteBufSize)
109  { m_ReadBufSize = ReadBufSize; m_WriteBufSize = WriteBufSize; }
110 
115  void setTimeout(double Timeout);
116 
123  void setBytePeriod(double Period);
124 
129  int openIO();
130 
134  void closeIO();
135 
143  int readBlocking(char *Buffer, int Length);
144 
145 
152  int readNonBlocking(char *Buffer, int Length);
153 
159  int writeIO(const char *Buffer, int Length);
160 
164  int getSizeRXQueue();
165 
166 
169  void purge()
170  {
171  ::tcflush(m_Device, TCIOFLUSH);
172  }
173 
176  void purgeRx() {
177  tcflush(m_Device, TCIFLUSH);
178 }
179 
184  void purgeTx() {
185  tcflush(m_Device, TCOFLUSH);
186  }
187 
192  void flushTx() {
193  tcdrain(m_Device);
194  }
195 
196 protected:
197  ::termios m_tio;
198  std::string m_DeviceName;
199  int m_Device;
201  double m_Multiplier;
206  double m_Timeout;
207  ::timeval m_BytePeriod;
209 };
210 
211 
212 #endif //
213 
int getSizeRXQueue()
Definition: SerialIO.cpp:407
void purge()
Definition: SerialIO.h:169
void setBytePeriod(double Period)
Definition: SerialIO.cpp:312
void SetFormat(int ByteSize, ParityFlags Parity, int StopBits)
Definition: SerialIO.h:95
int m_Device
Definition: SerialIO.h:199
std::string m_DeviceName
Definition: SerialIO.h:198
int m_StopBits
Definition: SerialIO.h:202
void closeIO()
Definition: SerialIO.cpp:292
void setHandshake(HandshakeFlags Handshake)
Definition: SerialIO.h:101
virtual ~SerialIO()
Destructor.
Definition: SerialIO.cpp:123
void setBufferSize(int ReadBufSize, int WriteBufSize)
Definition: SerialIO.h:108
void flushTx()
Definition: SerialIO.h:192
void purgeRx()
Definition: SerialIO.h:176
int m_ReadBufSize
Definition: SerialIO.h:205
HandshakeFlags m_Handshake
Definition: SerialIO.h:204
void setTimeout(double Timeout)
Definition: SerialIO.cpp:301
void setMultiplier(double Multiplier=1)
Definition: SerialIO.h:90
int m_BaudRate
Definition: SerialIO.h:200
::termios m_tio
Definition: SerialIO.h:197
void changeBaudRate(int BaudRate)
Definition: SerialIO.cpp:320
void setDeviceName(const char *Name)
Definition: SerialIO.h:70
int writeIO(const char *Buffer, int Length)
Definition: SerialIO.cpp:379
int readBlocking(char *Buffer, int Length)
Definition: SerialIO.cpp:343
bool m_ShortBytePeriod
Definition: SerialIO.h:208
SerialIO()
Default constructor.
Definition: SerialIO.cpp:105
double m_Timeout
Definition: SerialIO.h:206
int readNonBlocking(char *Buffer, int Length)
Definition: SerialIO.cpp:356
void setBaudRate(int BaudRate)
Definition: SerialIO.h:76
ParityFlags m_Parity
Definition: SerialIO.h:203
void purgeTx()
Definition: SerialIO.h:184
int m_ByteSize
Definition: SerialIO.h:202
double m_Multiplier
Definition: SerialIO.h:201
int openIO()
Definition: SerialIO.cpp:128
::timeval m_BytePeriod
Definition: SerialIO.h:207
int m_WriteBufSize
Definition: SerialIO.h:205
HandshakeFlags
Constants for defining the handshake.
Definition: SerialIO.h:34
StopBits
Constants for defining the stop bits.
Definition: SerialIO.h:53
ParityFlags
Constants for defining the parity bits.
Definition: SerialIO.h:42
Length


cob_relayboard
Author(s): Christian Connette
autogenerated on Wed Apr 7 2021 02:11:46