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 #include <string.h>
26 
30 class SerialIO
31 {
32 public:
33  // ---------------------- Constants
36  {
40  };
41 
44  {
48 // UNIX serial drivers only support even, odd, and no parity bit generation.
51  };
52 
54  enum StopBits
55  {
57  SB_ONE_5, // ????? returns an error ?????
59  };
60 
62  SerialIO();
63 
65  virtual ~SerialIO();
66 
71  void setDeviceName(const char *Name) { m_DeviceName = Name; }
72 
77  void setBaudRate(int BaudRate) { m_BaudRate = BaudRate; }
78 
84  void changeBaudRate(int BaudRate);
85 
91  void setMultiplier(double Multiplier = 1) { m_Multiplier = Multiplier; };
92 
96  void SetFormat(int ByteSize, ParityFlags Parity, int StopBits)
97  { m_ByteSize = ByteSize; m_Parity = Parity; m_StopBits = StopBits; }
98 
102  void setHandshake(HandshakeFlags Handshake) { m_Handshake = Handshake; }
103 
109  void setBufferSize(int ReadBufSize, int WriteBufSize)
110  { m_ReadBufSize = ReadBufSize; m_WriteBufSize = WriteBufSize; }
111 
116  void setTimeout(double Timeout);
117 
124  void setBytePeriod(double Period);
125 
130  int openIO();
131 
135  void closeIO();
136 
144  int readBlocking(char *Buffer, int Length);
145 
146 
153  int readNonBlocking(char *Buffer, int Length);
154 
160  int writeIO(const char *Buffer, int Length);
161 
165  int getSizeRXQueue();
166 
167 
170  void purge()
171  {
172  ::tcflush(m_Device, TCIOFLUSH);
173  }
174 
177  void purgeRx() {
178  tcflush(m_Device, TCIFLUSH);
179 }
180 
185  void purgeTx() {
186  tcflush(m_Device, TCOFLUSH);
187  }
188 
193  void flushTx() {
194  tcdrain(m_Device);
195  }
196 
197 protected:
198  ::termios m_tio;
199  std::string m_DeviceName;
200  int m_Device;
202  double m_Multiplier;
207  double m_Timeout;
208  ::timeval m_BytePeriod;
210 };
211 
212 
213 #endif //
214 
int getSizeRXQueue()
Definition: SerialIO.cpp:404
void purge()
Definition: SerialIO.h:170
void setBytePeriod(double Period)
Definition: SerialIO.cpp:309
void SetFormat(int ByteSize, ParityFlags Parity, int StopBits)
Definition: SerialIO.h:96
int m_Device
Definition: SerialIO.h:200
std::string m_DeviceName
Definition: SerialIO.h:199
int m_StopBits
Definition: SerialIO.h:203
void closeIO()
Definition: SerialIO.cpp:289
void setHandshake(HandshakeFlags Handshake)
Definition: SerialIO.h:102
virtual ~SerialIO()
Destructor.
Definition: SerialIO.cpp:120
void setBufferSize(int ReadBufSize, int WriteBufSize)
Definition: SerialIO.h:109
void flushTx()
Definition: SerialIO.h:193
void purgeRx()
Definition: SerialIO.h:177
int m_ReadBufSize
Definition: SerialIO.h:206
HandshakeFlags m_Handshake
Definition: SerialIO.h:205
void setTimeout(double Timeout)
Definition: SerialIO.cpp:298
void setMultiplier(double Multiplier=1)
Definition: SerialIO.h:91
int m_BaudRate
Definition: SerialIO.h:201
::termios m_tio
Definition: SerialIO.h:198
void changeBaudRate(int BaudRate)
Definition: SerialIO.cpp:317
void setDeviceName(const char *Name)
Definition: SerialIO.h:71
int writeIO(const char *Buffer, int Length)
Definition: SerialIO.cpp:376
int readBlocking(char *Buffer, int Length)
Definition: SerialIO.cpp:340
bool m_ShortBytePeriod
Definition: SerialIO.h:209
SerialIO()
Default constructor.
Definition: SerialIO.cpp:102
double m_Timeout
Definition: SerialIO.h:207
int readNonBlocking(char *Buffer, int Length)
Definition: SerialIO.cpp:353
void setBaudRate(int BaudRate)
Definition: SerialIO.h:77
ParityFlags m_Parity
Definition: SerialIO.h:204
void purgeTx()
Definition: SerialIO.h:185
int m_ByteSize
Definition: SerialIO.h:203
double m_Multiplier
Definition: SerialIO.h:202
int openIO()
Definition: SerialIO.cpp:125
::timeval m_BytePeriod
Definition: SerialIO.h:208
int m_WriteBufSize
Definition: SerialIO.h:206
HandshakeFlags
Constants for defining the handshake.
Definition: SerialIO.h:35
StopBits
Constants for defining the stop bits.
Definition: SerialIO.h:54
ParityFlags
Constants for defining the parity bits.
Definition: SerialIO.h:43
Length


cob_sick_s300
Author(s): Florian Weisshardt
autogenerated on Wed Apr 7 2021 02:11:50