4 * Asynchronous Serial I/O channel class.
6 * Portable Windows Library
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
27 * Contributor(s): ______________________________________.
30 * Revision 1.18 2005/11/25 03:43:47 csoutheren
31 * Fixed function argument comments to be compatible with Doxygen
33 * Revision 1.17 2005/02/20 21:18:30 dereksmithies
34 * Fix documentation typos.
36 * Revision 1.16 2003/09/17 05:41:59 csoutheren
37 * Removed recursive includes
39 * Revision 1.15 2003/09/17 01:18:02 csoutheren
40 * Removed recursive include file system and removed all references
41 * to deprecated coooperative threading support
43 * Revision 1.14 2002/09/16 01:08:59 robertj
44 * Added #define so can select if #pragma interface/implementation is used on
45 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
47 * Revision 1.13 2001/05/22 12:49:32 robertj
48 * Did some seriously wierd rewrite of platform headers to eliminate the
49 * stupid GNU compiler warning about braces not matching.
51 * Revision 1.12 1999/03/09 02:59:50 robertj
52 * Changed comments to doc++ compatible documentation.
54 * Revision 1.11 1999/02/16 08:11:10 robertj
55 * MSVC 6.0 compatibility changes.
57 * Revision 1.10 1998/09/23 06:21:21 robertj
58 * Added open source copyright license.
60 * Revision 1.9 1995/07/31 12:15:46 robertj
61 * Removed PContainer from PChannel ancestor.
63 * Revision 1.8 1995/06/17 11:13:18 robertj
64 * Documentation update.
66 * Revision 1.7 1995/03/14 12:42:33 robertj
67 * Updated documentation to use HTML codes.
69 * Revision 1.6 1995/01/14 06:19:37 robertj
72 * Revision 1.5 1994/08/23 11:32:52 robertj
75 * Revision 1.4 1994/08/22 00:46:48 robertj
76 * Added pragma fro GNU C++ compiler.
78 * Revision 1.3 1994/07/17 10:46:06 robertj
79 * Moved data to PChannel class.
81 * Revision 1.2 1994/06/25 11:55:15 robertj
82 * Unix version synchronisation.
84 * Revision 1.1 1994/04/20 12:17:44 robertj
89 #ifndef _PSERIALCHANNEL
90 #define _PSERIALCHANNEL
100 ///////////////////////////////////////////////////////////////////////////////
103 /**This class defines an I/O channel that communicates via a serial port. This
104 is usually an RS-232 port.
106 class PSerialChannel
: public PChannel
108 PCLASSINFO(PSerialChannel
, PChannel
);
111 /**@name Construction */
113 /// Create a new serial channel object, but do not open it.
116 /// Configuration of serial port parity options.
118 /// Use the default parity, ie do not change it.
120 /// Set the port for no parity bit.
122 /// Set the port to generate parity and make it even.
124 /// Set the port to generate parity and make it odd.
126 /// Set the port parity bit to mark only.
128 /// Set the port parity bit to space only.
132 /// Configuration of serial port flow control options.
134 /// Use the default flow control, ie do not change it.
136 /// Set the port for no flow control.
138 /// Set the port for software or XON/XOFF flow control.
140 /// Set the port for hardware or RTS/CTS flow control.
144 /**Create a serial channal.
145 The channel is opened it on the specified port and with the specified
149 /**The name of the serial port to connect to. This is a platform
150 dependent string and woiuld rarely be a literal. The static function
151 #GetPortNames()# can be used to find the platforms serial ports.
153 const PString
& port
,
154 /**Serial port speed or baud rate. The actual values possible here are
155 platform dependent, but the standard value of 300, 1200, 2400, 4800,
156 9600, 19200, 38400 always be legal.
159 /**Number of data bits for serial port. The actual values possible here
160 are platform dependent, but 7 and 8 should always be legal.
163 /**Parity for serial port. The actual values possible here are platform
164 dependent, but #NoParity#, #OddParity# and
165 #EvenParity# should always be legal.
167 Parity parity
= DefaultParity
,
168 /**Number of stop bits for serial port. The actual values possible here
169 are platform dependent, but 1 and 2 should always be legal.
172 /**Flow control for data from the remote system into this conputer.*/
173 FlowControl inputFlow
= DefaultFlowControl
,
174 /**Flow control for data from this conputer out to remote system. */
175 FlowControl outputFlow
= DefaultFlowControl
178 /**Create a serial channal.
179 The channel is opened using attributes obtained from standard variables
180 in the configuration file. Note that it assumed that the correct
181 configuration file section is already set.
184 PConfig
& cfg
///< Configuration file to read serial port attributes from.
187 /// Close the serial channel on destruction.
192 /**@name Open functions */
194 /**Open a serial channal.
195 The channel is opened it on the specified port and with the specified
199 /**The name of the serial port to connect to. This is a platform
200 dependent string and woiuld rarely be a literal. The static function
201 #GetPortNames()# can be used to find the platforms serial ports.
203 const PString
& port
,
204 /**Serial port speed or baud rate. The actual values possible here are
205 platform dependent, but the standard value of 300, 1200, 2400, 4800,
206 9600, 19200, 38400 always be legal.
209 /**Number of data bits for serial port. The actual values possible here
210 are platform dependent, but 7 and 8 should always be legal.
213 /**Parity for serial port. The actual values possible here are platform
214 dependent, but #NoParity#, #OddParity# and
215 #EvenParity# should always be legal.
217 Parity parity
= DefaultParity
,
218 /**Number of stop bits for serial port. The actual values possible here
219 are platform dependent, but 1 and 2 should always be legal.
222 /**Flow control for data from the remote system into this conputer.*/
223 FlowControl inputFlow
= DefaultFlowControl
,
224 /**Flow control for data from this conputer out to remote system. */
225 FlowControl outputFlow
= DefaultFlowControl
228 /**Open a serial channal.
229 The channel is opened using attributes obtained from standard variables
230 in the configuration file. Note that it assumed that the correct
231 configuration file section is already set.
234 PConfig
& cfg
///< Configuration file to read serial port attributes from.
237 /**Get a list of the available serial ports. This returns a set of
238 platform dependent strings which describe the serial ports of the
239 computer. For example under unix it may be "ttyS0", under MS-DOS or
240 NT it would be "COM1" and for the Macintosh it could be "Modem".
243 list of strings for possible serial ports.
245 static PStringList
GetPortNames();
249 /**@name Configuration functions */
251 /**Set the speed (baud rate) of the serial channel.
254 TRUE if the change was successfully made.
257 DWORD speed
///< New speed for serial channel.
260 /**Get the speed (baud rate) of the serial channel.
265 DWORD
GetSpeed() const;
267 /**Set the data bits (5, 6, 7 or 8) of the serial port.
270 TRUE if the change was successfully made.
273 BYTE data
///< New number of data bits for serial channel.
276 /**Get the data bits (5, 6, 7 or 8) of the serial port.
281 BYTE
GetDataBits() const;
283 /**Set the parity of the serial port.
286 TRUE if the change was successfully made.
289 Parity parity
///< New parity option for serial channel.
292 /**Get the parity of the serial port.
297 Parity
GetParity() const;
299 /**Set the stop bits (1 or 2) of the serial port.
302 TRUE if the change was successfully made.
305 BYTE stop
///< New number of stop bits for serial channel.
308 /**Get the stop bits (1 or 2) of the serial port.
313 BYTE
GetStopBits() const;
315 /**Set the flow control (handshaking) protocol of the input to the serial
319 TRUE if the change was successfully made.
321 BOOL
SetInputFlowControl(
322 FlowControl flowControl
///< New flow control for serial channel input.
325 /**Get the flow control (handshaking) protocol of the input to the serial
331 FlowControl
GetInputFlowControl() const;
333 /**Set the flow control (handshaking) protocol of the output to the serial
337 TRUE if the change was successfully made.
339 BOOL
SetOutputFlowControl(
340 FlowControl flowControl
///< New flow control for serial channel output.
343 /**Get the flow control (handshaking) protocol of the output from the
349 FlowControl
GetOutputFlowControl() const;
351 /**Save the current port settings into the configuration file. Note that
352 it assumed that the correct configuration file section is already set.
354 virtual void SaveSettings(
355 PConfig
& cfg
///< Configuration file to save setting into.
360 /**@name Status functions */
362 /** Set the Data Terminal Ready signal of the serial port. */
364 BOOL state
= TRUE
///< New state of the DTR signal.
367 /**Clear the Data Terminal Ready signal of the serial port. This is
368 equivalent to #SetDTR(FALSE)#.
372 /**Set the Request To Send signal of the serial port. */
374 BOOL state
= TRUE
///< New state of the RTS signal.
377 /**Clear the Request To Send signal of the serial port. This is equivalent
382 /** Set the break condition of the serial port. */
384 BOOL state
= TRUE
///< New state of the serial port break condition.
387 /**Clear the break condition of the serial port. This is equivalent to
392 /**Get the Clear To Send signal of the serial port.
395 TRUE if the CTS signal is asserted.
399 /**Get the Data Set Ready signal of the serial port.
402 TRUE if the DSR signal is asserted.
406 /**Get the Data Carrier Detect signal of the serial port.
409 TRUE if the DCD signal is asserted.
413 /**Get the Ring Indicator signal of the serial port.
416 TRUE if the RI signal is asserted.
424 // Platform dependent construct of the serial channel.
427 // Include platform dependent part of class
429 #include "msos/ptlib/serchan.h"
431 #include "unix/ptlib/serchan.h"
437 // End Of File ///////////////////////////////////////////////////////////////