Lines 8-14
Link Here
|
8 |
#ifndef _SerialStream_h_ |
8 |
#ifndef _SerialStream_h_ |
9 |
#define _SerialStream_h_ |
9 |
#define _SerialStream_h_ |
10 |
|
10 |
|
11 |
#include <string> |
11 |
#include <cstring> |
12 |
#include <fstream> |
12 |
#include <fstream> |
13 |
#include <SerialStreamBuf.h> |
13 |
#include <SerialStreamBuf.h> |
14 |
|
14 |
|
Lines 42-51
Link Here
|
42 |
obtained from <a href="http://www.UNIX-systems.org/"> |
42 |
obtained from <a href="http://www.UNIX-systems.org/"> |
43 |
http://www.UNIX-systems.org/</a>. We will refer to this |
43 |
http://www.UNIX-systems.org/</a>. We will refer to this |
44 |
document as SUS-2. |
44 |
document as SUS-2. |
45 |
|
45 |
|
46 |
@author $Author: crayzeewulf $ <A HREF="pagey@gnudom.org">Manish P. Pagey</A> |
46 |
@author $Author: crayzeewulf $ <A HREF="pagey@gnudom.org">Manish P. Pagey</A> |
47 |
@version $Id: SerialStream.h,v 1.5 2004/05/06 18:32:02 crayzeewulf |
47 |
@version $Id: SerialStream.h,v 1.5 2004/05/06 18:32:02 crayzeewulf |
48 |
|
48 |
|
49 |
*/ |
49 |
*/ |
50 |
class SerialStream : public std::iostream { |
50 |
class SerialStream : public std::iostream { |
51 |
public: |
51 |
public: |
Lines 78-88
Link Here
|
78 |
stream is in a good state before using it for any further |
78 |
stream is in a good state before using it for any further |
79 |
I/O operations. |
79 |
I/O operations. |
80 |
|
80 |
|
81 |
@param fileName The filename of the serial port. |
81 |
@param fileName The filename of the serial port. |
82 |
@param openMode The openmode for the serial port file. |
82 |
@param openMode The openmode for the serial port file. |
83 |
|
83 |
|
84 |
*/ |
84 |
*/ |
85 |
explicit SerialStream( const std::string fileName, |
85 |
explicit SerialStream( const std::string fileName, |
86 |
std::ios_base::openmode openMode = |
86 |
std::ios_base::openmode openMode = |
87 |
std::ios::in|std::ios::out) ; |
87 |
std::ios::in|std::ios::out) ; |
88 |
|
88 |
|
Lines 92-103
Link Here
|
92 |
|
92 |
|
93 |
*/ |
93 |
*/ |
94 |
explicit SerialStream() ; |
94 |
explicit SerialStream() ; |
95 |
|
95 |
|
96 |
/** The destructor. It closes the stream associated with |
96 |
/** The destructor. It closes the stream associated with |
97 |
mFileDescriptor. The rest is done by the fstream destructor. |
97 |
mFileDescriptor. The rest is done by the fstream destructor. |
98 |
|
98 |
|
99 |
*/ |
99 |
*/ |
100 |
virtual ~SerialStream() ; |
100 |
virtual ~SerialStream() ; |
101 |
//@} |
101 |
//@} |
102 |
|
102 |
|
103 |
/** @name Other Public Methods |
103 |
/** @name Other Public Methods |
Lines 107-114
Link Here
|
107 |
s and the specified mode, mode. |
107 |
s and the specified mode, mode. |
108 |
|
108 |
|
109 |
*/ |
109 |
*/ |
110 |
void Open( const std::string fileName, |
110 |
void Open( const std::string fileName, |
111 |
std::ios_base::openmode openMode = |
111 |
std::ios_base::openmode openMode = |
112 |
std::ios_base::in | std::ios_base::out) ; |
112 |
std::ios_base::in | std::ios_base::out) ; |
113 |
|
113 |
|
114 |
/** Close the serial port. No communications can occur with the |
114 |
/** Close the serial port. No communications can occur with the |
Lines 122-128
Link Here
|
122 |
*/ |
122 |
*/ |
123 |
const bool IsOpen() const ; |
123 |
const bool IsOpen() const ; |
124 |
|
124 |
|
125 |
/** Set the baud rate for serial communications. |
125 |
/** Set the baud rate for serial communications. |
126 |
|
126 |
|
127 |
*/ |
127 |
*/ |
128 |
void SetBaudRate(SerialStreamBuf::BaudRateEnum baudRate ) ; |
128 |
void SetBaudRate(SerialStreamBuf::BaudRateEnum baudRate ) ; |
Lines 130-137
Link Here
|
130 |
/** Get the current baud rate being used for serial |
130 |
/** Get the current baud rate being used for serial |
131 |
communication. This routine queries the serial port for its |
131 |
communication. This routine queries the serial port for its |
132 |
current settings and returns the baud rate that is being |
132 |
current settings and returns the baud rate that is being |
133 |
used by the serial port. |
133 |
used by the serial port. |
134 |
|
134 |
|
135 |
@return The current baud rate for the serial port. |
135 |
@return The current baud rate for the serial port. |
136 |
Note: this is not a constant function because it |
136 |
Note: this is not a constant function because it |
137 |
checks to see that it is dealing with a SerialStream |
137 |
checks to see that it is dealing with a SerialStream |
Lines 140-198
Link Here
|
140 |
*/ |
140 |
*/ |
141 |
const SerialStreamBuf::BaudRateEnum BaudRate() ; |
141 |
const SerialStreamBuf::BaudRateEnum BaudRate() ; |
142 |
|
142 |
|
143 |
/** Set the character size associated with the serial port. |
143 |
/** Set the character size associated with the serial port. |
144 |
|
144 |
|
145 |
@param size The character size will be set to this value. |
145 |
@param size The character size will be set to this value. |
146 |
*/ |
146 |
*/ |
147 |
void SetCharSize(const SerialStreamBuf::CharSizeEnum charSize ) ; |
147 |
void SetCharSize(const SerialStreamBuf::CharSizeEnum charSize ) ; |
148 |
|
148 |
|
149 |
/** Get the character size being used for serial communication. |
149 |
/** Get the character size being used for serial communication. |
150 |
|
150 |
|
151 |
@return The current character size. |
151 |
@return The current character size. |
152 |
*/ |
152 |
*/ |
153 |
const SerialStreamBuf::CharSizeEnum CharSize() ; |
153 |
const SerialStreamBuf::CharSizeEnum CharSize() ; |
154 |
|
154 |
|
155 |
/** Set the number of stop bits used during serial |
155 |
/** Set the number of stop bits used during serial |
156 |
communication. The only valid values are 1 and 2. |
156 |
communication. The only valid values are 1 and 2. |
157 |
|
157 |
|
158 |
@param stop_bits The number of stop bits. (1 or 2). |
158 |
@param stop_bits The number of stop bits. (1 or 2). |
159 |
|
159 |
|
160 |
*/ |
160 |
*/ |
161 |
void SetNumOfStopBits(short stop_bits) ; |
161 |
void SetNumOfStopBits(short stop_bits) ; |
162 |
|
162 |
|
163 |
/** Get the number of stop bits being used during serial |
163 |
/** Get the number of stop bits being used during serial |
164 |
communication. |
164 |
communication. |
165 |
|
165 |
|
166 |
@return The number of stop bits. */ |
166 |
@return The number of stop bits. */ |
167 |
const short NumOfStopBits() ; |
167 |
const short NumOfStopBits() ; |
168 |
|
168 |
|
169 |
/** Set the parity for serial communication. |
169 |
/** Set the parity for serial communication. |
170 |
|
170 |
|
171 |
@param parity The parity value. |
171 |
@param parity The parity value. |
172 |
|
172 |
|
173 |
*/ |
173 |
*/ |
174 |
void SetParity(const SerialStreamBuf::ParityEnum parity) ; |
174 |
void SetParity(const SerialStreamBuf::ParityEnum parity) ; |
175 |
|
175 |
|
176 |
/** Get the current parity setting for the serial port. |
176 |
/** Get the current parity setting for the serial port. |
177 |
|
177 |
|
178 |
@return The parity setting for the serial port. |
178 |
@return The parity setting for the serial port. |
179 |
|
179 |
|
180 |
*/ |
180 |
*/ |
181 |
const SerialStreamBuf::ParityEnum Parity() ; |
181 |
const SerialStreamBuf::ParityEnum Parity() ; |
182 |
|
182 |
|
183 |
/** Use the specified flow control. |
183 |
/** Use the specified flow control. |
184 |
|
184 |
|
185 |
*/ |
185 |
*/ |
186 |
void |
186 |
void |
187 |
SetFlowControl(const SerialStreamBuf::FlowControlEnum flow_c) ; |
187 |
SetFlowControl(const SerialStreamBuf::FlowControlEnum flow_c) ; |
188 |
|
188 |
|
189 |
/** Return the current flow control setting. |
189 |
/** Return the current flow control setting. |
190 |
|
190 |
|
191 |
*/ |
191 |
*/ |
192 |
const SerialStreamBuf::FlowControlEnum FlowControl() ; |
192 |
const SerialStreamBuf::FlowControlEnum FlowControl() ; |
193 |
|
193 |
|
194 |
/** Set character buffer size. |
194 |
/** Set character buffer size. |
195 |
|
195 |
|
196 |
*/ |
196 |
*/ |
197 |
const short SetVMin( short vtime ) ; |
197 |
const short SetVMin( short vtime ) ; |
198 |
|
198 |
|
Lines 200-218
Link Here
|
200 |
/** Get current size of character buffer. |
200 |
/** Get current size of character buffer. |
201 |
Look <A HREF="http://www.unixwiz.net/techtips/termios-vmin-vtime.html">here</A> |
201 |
Look <A HREF="http://www.unixwiz.net/techtips/termios-vmin-vtime.html">here</A> |
202 |
for more documentation about VTIME and VMIN. |
202 |
for more documentation about VTIME and VMIN. |
203 |
|
203 |
|
204 |
*/ |
204 |
*/ |
205 |
const short VMin() ; |
205 |
const short VMin() ; |
206 |
|
206 |
|
207 |
/** Set character buffer timing in 10th of a second. |
207 |
/** Set character buffer timing in 10th of a second. |
208 |
|
208 |
|
209 |
*/ |
209 |
*/ |
210 |
const short SetVTime( short vtime ) ; |
210 |
const short SetVTime( short vtime ) ; |
211 |
|
211 |
|
212 |
/** Get current timing of character buffer in 10th of a second. |
212 |
/** Get current timing of character buffer in 10th of a second. |
213 |
Look <A HREF="http://www.unixwiz.net/techtips/termios-vmin-vtime.html">here</A> |
213 |
Look <A HREF="http://www.unixwiz.net/techtips/termios-vmin-vtime.html">here</A> |
214 |
for more documentation about VTIME and VMIN. |
214 |
for more documentation about VTIME and VMIN. |
215 |
|
215 |
|
216 |
*/ |
216 |
*/ |
217 |
const short VTime() ; |
217 |
const short VTime() ; |
218 |
|
218 |
|
Lines 274-280
Link Here
|
274 |
|
274 |
|
275 |
/* Enable the serial port receiver. This will allow us to read |
275 |
/* Enable the serial port receiver. This will allow us to read |
276 |
data from the serial port. |
276 |
data from the serial port. |
277 |
|
277 |
|
278 |
@param enable If true then the received will be |
278 |
@param enable If true then the received will be |
279 |
enabled. Otherwise it will be disabled. |
279 |
enabled. Otherwise it will be disabled. |
280 |
|
280 |
|
Lines 284-290
Link Here
|
284 |
} ; // class SerialStream |
284 |
} ; // class SerialStream |
285 |
|
285 |
|
286 |
inline |
286 |
inline |
287 |
SerialStream::SerialStream() : |
287 |
SerialStream::SerialStream() : |
288 |
std::iostream(0), mIOBuffer(0) { |
288 |
std::iostream(0), mIOBuffer(0) { |
289 |
// |
289 |
// |
290 |
// Close the stream |
290 |
// Close the stream |
Lines 294-300
Link Here
|
294 |
|
294 |
|
295 |
inline |
295 |
inline |
296 |
SerialStream::~SerialStream() { |
296 |
SerialStream::~SerialStream() { |
297 |
// |
297 |
// |
298 |
// If a SerialStreamBuf is associated with this SerialStream |
298 |
// If a SerialStreamBuf is associated with this SerialStream |
299 |
// then we need to destroy it here. |
299 |
// then we need to destroy it here. |
300 |
// |
300 |
// |
Lines 304-310
Link Here
|
304 |
} |
304 |
} |
305 |
|
305 |
|
306 |
inline |
306 |
inline |
307 |
void |
307 |
void |
308 |
SerialStream::Close() { |
308 |
SerialStream::Close() { |
309 |
// |
309 |
// |
310 |
// If a SerialStreamBuf is associated with the SerialStream then |
310 |
// If a SerialStreamBuf is associated with the SerialStream then |