vrpn
07.35
Virtual Reality Peripheral Network
Toggle main menu visibility
Loading...
Searching...
No Matches
vrpn_SerialPort.h
Go to the documentation of this file.
1
13
14
// Copyright Iowa State University 2012.
15
// Distributed under the Boost Software License, Version 1.0.
16
// (See accompanying file LICENSE_1_0.txt or copy at
17
// http://www.boost.org/LICENSE_1_0.txt)
18
19
#pragma once
20
21
// Internal Includes
22
#include "
vrpn_Configure.h
"
// for VRPN_API
23
#include "
vrpn_Serial.h
"
// for ::vrpn_SER_PARITY_NONE, etc
24
25
// Library/third-party includes
26
// - none
27
28
// Standard includes
29
#include <stdexcept>
// for runtime_error, logic_error
30
#include <string>
// for string
31
34
class
VRPN_API
vrpn_SerialPort
{
35
public
:
36
typedef
int
file_handle_type
;
40
vrpn_SerialPort
(
const
char
*portname,
long
baud,
int
charsize = 8,
41
vrpn_SER_PARITY
parity =
vrpn_SER_PARITY_NONE
);
42
44
vrpn_SerialPort
();
45
47
~vrpn_SerialPort
();
48
54
void
open
(
const
char
*portname,
long
baud,
int
charsize = 8,
55
vrpn_SER_PARITY
parity =
vrpn_SER_PARITY_NONE
);
56
bool
is_open
()
const
;
57
60
void
close
();
62
67
int
write
(std::string
const
&buffer);
68
int
write
(
const
unsigned
char
*buffer,
int
bytes);
70
76
int
read_available_characters
(
unsigned
char
*buffer,
int
count);
77
80
std::string
read_available_characters
(
int
count = -1);
81
84
int
read_available_characters
(
unsigned
char
*buffer,
int
count,
85
struct
timeval &timeout);
86
89
std::string
read_available_characters
(
int
count,
struct
timeval &timeout);
91
94
97
void
flush_input_buffer
();
98
101
void
flush_output_buffer
();
102
105
void
drain_output_buffer
();
107
116
void
set_rts
();
117
void
clear_rts
();
118
void
assign_rts
(
bool
set);
120
123
struct
AlreadyOpen
;
124
struct
CloseFailure
;
125
struct
DrainFailure
;
126
struct
FlushFailure
;
127
struct
NotOpen
;
128
struct
OpenFailure
;
129
struct
RTSFailure
;
130
struct
ReadFailure
;
131
struct
WriteFailure
;
133
134
private
:
135
void
requiresOpen()
const
;
138
vrpn_SerialPort
(
vrpn_SerialPort
const
&);
139
vrpn_SerialPort
const
&operator=(
vrpn_SerialPort
const
&);
141
file_handle_type
_comm;
142
bool
_rts_status;
143
};
144
145
struct
vrpn_SerialPort::AlreadyOpen
: std::logic_error {
146
AlreadyOpen
()
147
: std::logic_error(
"Tried to open a serial port that was already open."
)
148
{
149
}
150
};
151
152
struct
vrpn_SerialPort::NotOpen
: std::logic_error {
153
NotOpen
()
154
: std::logic_error(
"Tried to use a serial port that was not yet open."
)
155
{
156
}
157
};
158
159
struct
vrpn_SerialPort::OpenFailure
: std::runtime_error {
160
OpenFailure
()
161
: std::runtime_error(
162
"Received an error when trying to open serial port."
)
163
{
164
}
165
};
166
167
struct
vrpn_SerialPort::CloseFailure
: std::runtime_error {
168
CloseFailure
()
169
: std::runtime_error(
170
"Received an error when trying to close serial port."
)
171
{
172
}
173
};
174
175
struct
vrpn_SerialPort::RTSFailure
: std::runtime_error {
176
RTSFailure
()
177
: std::runtime_error(
"Failed to modify serial port RTS status."
)
178
{
179
}
180
};
181
182
struct
vrpn_SerialPort::ReadFailure
: std::runtime_error {
183
ReadFailure
()
184
: std::runtime_error(
"Failure on serial port read."
)
185
{
186
}
187
};
188
189
struct
vrpn_SerialPort::WriteFailure
: std::runtime_error {
190
WriteFailure
()
191
: std::runtime_error(
"Failure on serial port write."
)
192
{
193
}
194
};
195
196
struct
vrpn_SerialPort::FlushFailure
: std::runtime_error {
197
FlushFailure
()
198
: std::runtime_error(
"Failure on serial port flush."
)
199
{
200
}
201
};
202
203
struct
vrpn_SerialPort::DrainFailure
: std::runtime_error {
204
DrainFailure
()
205
: std::runtime_error(
"Failure on serial port drain."
)
206
{
207
}
208
};
209
210
inline
bool
vrpn_SerialPort::is_open
()
const
{
return
_comm != -1; }
211
212
inline
void
vrpn_SerialPort::assign_rts
(
bool
set)
213
{
214
if
(set) {
215
set_rts
();
216
}
217
else
{
218
clear_rts
();
219
}
220
}
221
222
inline
void
vrpn_SerialPort::requiresOpen()
const
223
{
224
if
(!
is_open
()) {
225
throw
NotOpen();
226
}
227
}
vrpn_SerialPort::vrpn_SerialPort
vrpn_SerialPort(const char *portname, long baud, int charsize=8, vrpn_SER_PARITY parity=vrpn_SER_PARITY_NONE)
Construct and open port.
Definition
vrpn_SerialPort.C:36
vrpn_SerialPort::flush_output_buffer
void flush_output_buffer()
Throw out any characters (do not send) within the output buffer.
Definition
vrpn_SerialPort.C:170
vrpn_SerialPort::close
void close()
Close the serial port.
Definition
vrpn_SerialPort.C:77
vrpn_SerialPort::read_available_characters
int read_available_characters(unsigned char *buffer, int count)
Definition
vrpn_SerialPort.C:105
vrpn_SerialPort::clear_rts
void clear_rts()
Definition
vrpn_SerialPort.C:197
vrpn_SerialPort::write
int write(std::string const &buffer)
Definition
vrpn_SerialPort.C:86
vrpn_SerialPort::set_rts
void set_rts()
Definition
vrpn_SerialPort.C:188
vrpn_SerialPort::is_open
bool is_open() const
Definition
vrpn_SerialPort.h:210
vrpn_SerialPort::flush_input_buffer
void flush_input_buffer()
Throw out any characters within the input buffer.
Definition
vrpn_SerialPort.C:161
vrpn_SerialPort::assign_rts
void assign_rts(bool set)
Definition
vrpn_SerialPort.h:212
vrpn_SerialPort::open
void open(const char *portname, long baud, int charsize=8, vrpn_SER_PARITY parity=vrpn_SER_PARITY_NONE)
Definition
vrpn_SerialPort.C:64
vrpn_SerialPort::drain_output_buffer
void drain_output_buffer()
Wait until all of the characters in the output buffer are sent, then return.
Definition
vrpn_SerialPort.C:179
vrpn_SerialPort::file_handle_type
int file_handle_type
Definition
vrpn_SerialPort.h:36
vrpn_SerialPort::AlreadyOpen
Definition
vrpn_SerialPort.h:145
vrpn_SerialPort::AlreadyOpen::AlreadyOpen
AlreadyOpen()
Definition
vrpn_SerialPort.h:146
vrpn_SerialPort::CloseFailure
Definition
vrpn_SerialPort.h:167
vrpn_SerialPort::CloseFailure::CloseFailure
CloseFailure()
Definition
vrpn_SerialPort.h:168
vrpn_SerialPort::DrainFailure
Definition
vrpn_SerialPort.h:203
vrpn_SerialPort::DrainFailure::DrainFailure
DrainFailure()
Definition
vrpn_SerialPort.h:204
vrpn_SerialPort::FlushFailure
Definition
vrpn_SerialPort.h:196
vrpn_SerialPort::FlushFailure::FlushFailure
FlushFailure()
Definition
vrpn_SerialPort.h:197
vrpn_SerialPort::NotOpen
Definition
vrpn_SerialPort.h:152
vrpn_SerialPort::NotOpen::NotOpen
NotOpen()
Definition
vrpn_SerialPort.h:153
vrpn_SerialPort::OpenFailure
Definition
vrpn_SerialPort.h:159
vrpn_SerialPort::OpenFailure::OpenFailure
OpenFailure()
Definition
vrpn_SerialPort.h:160
vrpn_SerialPort::RTSFailure
Definition
vrpn_SerialPort.h:175
vrpn_SerialPort::RTSFailure::RTSFailure
RTSFailure()
Definition
vrpn_SerialPort.h:176
vrpn_SerialPort::ReadFailure
Definition
vrpn_SerialPort.h:182
vrpn_SerialPort::ReadFailure::ReadFailure
ReadFailure()
Definition
vrpn_SerialPort.h:183
vrpn_SerialPort::WriteFailure
Definition
vrpn_SerialPort.h:189
vrpn_SerialPort::WriteFailure::WriteFailure
WriteFailure()
Definition
vrpn_SerialPort.h:190
vrpn_Configure.h
VRPN_API
#define VRPN_API
Definition
vrpn_Configure.h:648
vrpn_Serial.h
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...
vrpn_SER_PARITY
vrpn_SER_PARITY
Definition
vrpn_Serial.h:15
vrpn_SER_PARITY_NONE
@ vrpn_SER_PARITY_NONE
Definition
vrpn_Serial.h:16
vrpn_SerialPort.h
Generated by
1.17.0