Robotics Library
0.6.0
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
hal
Serial.h
Go to the documentation of this file.
1
//
2
// Copyright (c) 2009, Markus Rickert
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are met:
7
//
8
// * Redistributions of source code must retain the above copyright notice,
9
// this list of conditions and the following disclaimer.
10
// * Redistributions in binary form must reproduce the above copyright notice,
11
// this list of conditions and the following disclaimer in the documentation
12
// and/or other materials provided with the distribution.
13
// * Neither the name of the Technische Universitaet Muenchen nor the names of
14
// its contributors may be used to endorse or promote products derived from
15
// this software without specific prior written permission.
16
//
17
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
// POSSIBILITY OF SUCH DAMAGE.
28
//
29
30
#ifndef _RL_HAL_SERIAL_H_
31
#define _RL_HAL_SERIAL_H_
32
33
#include <string>
34
#include <
rl/math/Real.h
>
35
36
#ifdef WIN32
37
#include <windows.h>
38
#else // WIN32
39
#include <termios.h>
40
#endif // WIN32
41
42
#include "
Com.h
"
43
44
namespace
rl
45
{
46
namespace
hal
47
{
48
class
Serial
:
public
Com
49
{
50
public
:
51
enum
BaudRate
52
{
54
BAUDRATE_110BPS
,
56
BAUDRATE_300BPS
,
58
BAUDRATE_600BPS
,
60
BAUDRATE_1200BPS
,
62
BAUDRATE_2400BPS
,
64
BAUDRATE_4800BPS
,
66
BAUDRATE_9600BPS
,
67
#ifdef WIN32
68
69
BAUDRATE_14400BPS,
70
#endif // WIN32
71
72
BAUDRATE_19200BPS
,
74
BAUDRATE_38400BPS
,
76
BAUDRATE_57600BPS
,
78
#ifdef __QNX__
79
BAUDRATE_115200BPS
80
#else // __QNX__
81
BAUDRATE_115200BPS
,
82
#endif // __QNX__
83
#ifdef WIN32
84
85
BAUDRATE_128000BPS,
87
BAUDRATE_256000BPS
88
#else // WIN32
89
#ifndef __QNX__
90
91
BAUDRATE_230400BPS
,
93
BAUDRATE_460800BPS
,
95
BAUDRATE_500000BPS
,
97
BAUDRATE_576000BPS
,
99
BAUDRATE_921600BPS
,
101
BAUDRATE_1000000BPS
,
103
BAUDRATE_1152000BPS
,
105
BAUDRATE_1500000BPS
,
107
BAUDRATE_2000000BPS
,
109
BAUDRATE_2500000BPS
,
111
BAUDRATE_3000000BPS
,
113
BAUDRATE_3500000BPS
,
115
BAUDRATE_4000000BPS
116
#endif // __QNX__
117
#endif // WIN32
118
};
119
120
enum
DataBits
121
{
123
DATABITS_5BITS
,
125
DATABITS_6BITS
,
127
DATABITS_7BITS
,
129
DATABITS_8BITS
130
};
131
132
enum
FlowControl
133
{
135
FLOWCONTROL_OFF
,
137
FLOWCONTROL_RTSCTS
,
139
FLOWCONTROL_XONXOFF
140
};
141
142
enum
Parity
143
{
145
PARITY_EVENPARITY
,
147
PARITY_NOPARITY
,
149
PARITY_ODDPARITY
150
};
151
152
enum
StopBits
153
{
155
STOPBITS_1BIT
,
157
STOPBITS_2BITS
158
};
159
160
Serial
(
161
const ::std::string&
filename
,
162
const
BaudRate
&
baudRate
=
BAUDRATE_9600BPS
,
163
const
DataBits
&
dataBits
=
DATABITS_8BITS
,
164
const
FlowControl
&
flowControl
=
FLOWCONTROL_OFF
,
165
const
Parity
&
parity
=
PARITY_NOPARITY
,
166
const
StopBits
&
stopBits
=
STOPBITS_1BIT
167
);
168
169
virtual
~Serial
();
170
171
void
changeParameters
();
172
173
void
close
();
174
175
void
flush
(
const
bool
&
read
,
const
bool
&
write
);
176
177
BaudRate
getBaudRate
()
const
;
178
179
DataBits
getDataBits
()
const
;
180
181
::std::string
getFilename
()
const
;
182
183
FlowControl
getFlowControl
()
const
;
184
185
Parity
getParity
()
const
;
186
187
StopBits
getStopBits
()
const
;
188
189
void
open
();
190
191
::std::size_t
read
(
void
* buf, const ::std::size_t& count);
192
193
::std::size_t
select
(
const
bool
&
read
,
const
bool
&
write
,
const ::rl::math::Real
& timeout);
194
195
void
setBaudRate
(
const
BaudRate
&
baudRate
);
196
197
void
setDataBits
(
const
DataBits
&
dataBits
);
198
199
void
setFilename
(const ::std::string&
filename
);
200
201
void
setFlowControl
(
const
FlowControl
&
flowControl
);
202
203
void
setParity
(
const
Parity
&
parity
);
204
205
void
setStopBits
(
const
StopBits
&
stopBits
);
206
207
::std::size_t
write
(
const
void
* buf, const ::std::size_t& count);
208
209
protected
:
210
211
private
:
212
BaudRate
baudRate
;
213
214
#ifdef WIN32
215
DCB
current
;
216
#else // WIN32
217
struct
termios
current
;
218
#endif // WIN32
219
220
DataBits
dataBits
;
221
222
#ifdef WIN32
223
HANDLE
fd
;
224
#else // WIN32
225
int
fd
;
226
#endif // WIN32
227
228
::std::string
filename
;
229
230
FlowControl
flowControl
;
231
232
Parity
parity
;
233
234
#ifdef WIN32
235
DCB
restore
;
236
#else // WIN32
237
struct
termios
restore
;
238
#endif // WIN32
239
240
StopBits
stopBits
;
241
};
242
}
243
}
244
245
#endif // _RL_HAL_SERIAL_H_
Generated on Fri Jul 5 2013 11:55:07 for Robotics Library by
1.8.3.1