PTLib  Version 2.10.11
serchan.h
Go to the documentation of this file.
1 /*
2  * serchan.h
3  *
4  * Asynchronous Serial I/O channel class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
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/
14  *
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
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 24177 $
30  * $Author: rjongbloed $
31  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
32  */
33 
34 #ifndef PTLIB_SERIALCHANNEL_H
35 #define PTLIB_SERIALCHANNEL_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 
42 class PConfig;
43 
44 
46 // Serial Channel
47 
51 class PSerialChannel : public PChannel
52 {
53  PCLASSINFO(PSerialChannel, PChannel);
54 
55  public:
60 
62  enum Parity {
75  };
76 
78  enum FlowControl {
87  };
88 
98  const PString & port,
103  DWORD speed = 0,
107  BYTE data = 0,
112  Parity parity = DefaultParity,
116  BYTE stop = 0,
118  FlowControl inputFlow = DefaultFlowControl,
120  FlowControl outputFlow = DefaultFlowControl
121  );
122 
123 #if P_CONFIG_FILE
124 
130  PConfig & cfg
131  );
132 #endif // P_CONFIG_FILE
133 
135  ~PSerialChannel();
137 
138 
145  virtual PBoolean Open(
150  const PString & port,
155  DWORD speed = 0,
159  BYTE data = 0,
164  Parity parity = DefaultParity,
168  BYTE stop = 0,
170  FlowControl inputFlow = DefaultFlowControl,
172  FlowControl outputFlow = DefaultFlowControl
173  );
174 
175 #if P_CONFIG_FILE
176 
181  virtual PBoolean Open(
182  PConfig & cfg
183  );
184 #endif // P_CONFIG_FILE
185 
194  static PStringList GetPortNames();
196 
197 
206  DWORD speed
207  );
208 
214  DWORD GetSpeed() const;
215 
222  BYTE data
223  );
224 
230  BYTE GetDataBits() const;
231 
238  Parity parity
239  );
240 
246  Parity GetParity() const;
247 
254  BYTE stop
255  );
256 
262  BYTE GetStopBits() const;
263 
271  FlowControl flowControl
272  );
273 
281 
289  FlowControl flowControl
290  );
291 
299 
300 #if P_CONFIG_FILE
301 
304  virtual void SaveSettings(
305  PConfig & cfg
306  );
307 #endif // P_CONFIG_FILE
308 
309 
310 
314  void SetDTR(
315  PBoolean state = true
316  );
317 
321  void ClearDTR();
322 
324  void SetRTS(
325  PBoolean state = true
326  );
327 
331  void ClearRTS();
332 
334  void SetBreak(
335  PBoolean state = true
336  );
337 
341  void ClearBreak();
342 
348  PBoolean GetCTS();
349 
355  PBoolean GetDSR();
356 
362  PBoolean GetDCD();
363 
369  PBoolean GetRing();
371 
372 
373  private:
374  void Construct();
375  // Platform dependent construct of the serial channel.
376 
377 
378 // Include platform dependent part of class
379 #ifdef _WIN32
380 #include "msos/ptlib/serchan.h"
381 #else
382 #include "unix/ptlib/serchan.h"
383 #endif
384 };
385 
386 
387 #endif // PTLIB_SERIALCHANNEL_H
388 
389 
390 // End Of File ///////////////////////////////////////////////////////////////
Set the port for software or XON/XOFF flow control.
Definition: serchan.h:84
FlowControl GetInputFlowControl() const
Get the flow control (handshaking) protocol of the input to the serial port.
Set the port to generate parity and make it odd.
Definition: serchan.h:70
virtual void SaveSettings(PConfig &cfg)
Save the current port settings into the configuration file.
virtual PBoolean Open(const PString &port, DWORD speed=0, BYTE data=0, Parity parity=DefaultParity, BYTE stop=0, FlowControl inputFlow=DefaultFlowControl, FlowControl outputFlow=DefaultFlowControl)
Open a serial channal.
void ClearBreak()
Clear the break condition of the serial port.
A class representing a configuration for the application.
Definition: config.h:67
This class defines an I/O channel that communicates via a serial port.
Definition: serchan.h:51
Set the port for hardware or RTS/CTS flow control.
Definition: serchan.h:86
PBoolean GetDCD()
Get the Data Carrier Detect signal of the serial port.
Set the port for no flow control.
Definition: serchan.h:82
BYTE GetDataBits() const
Get the data bits (5, 6, 7 or 8) of the serial port.
BYTE GetStopBits() const
Get the stop bits (1 or 2) of the serial port.
FlowControl
Configuration of serial port flow control options.
Definition: serchan.h:78
BOOL PBoolean
Definition: object.h:102
PBoolean SetParity(Parity parity)
Set the parity of the serial port.
void SetDTR(PBoolean state=true)
Set the Data Terminal Ready signal of the serial port.
void ClearRTS()
Clear the Request To Send signal of the serial port.
PBoolean SetStopBits(BYTE stop)
Set the stop bits (1 or 2) of the serial port.
PBoolean GetCTS()
Get the Clear To Send signal of the serial port.
Abstract class defining I/O channel semantics.
Definition: channel.h:107
Set the port for no parity bit.
Definition: serchan.h:66
PSerialChannel()
Create a new serial channel object, but do not open it.
PBoolean SetOutputFlowControl(FlowControl flowControl)
Set the flow control (handshaking) protocol of the output to the serial port.
The character string class.
Definition: pstring.h:108
Set the port parity bit to mark only.
Definition: serchan.h:72
PBoolean GetDSR()
Get the Data Set Ready signal of the serial port.
Set the port parity bit to space only.
Definition: serchan.h:74
FlowControl GetOutputFlowControl() const
Get the flow control (handshaking) protocol of the output from the serial port.
Parity
Configuration of serial port parity options.
Definition: serchan.h:62
This is a list collection class of PString objects.
Definition: pstring.h:2184
Set the port to generate parity and make it even.
Definition: serchan.h:68
void SetBreak(PBoolean state=true)
Set the break condition of the serial port.
void ClearDTR()
Clear the Data Terminal Ready signal of the serial port.
Use the default flow control, ie do not change it.
Definition: serchan.h:80
Use the default parity, ie do not change it.
Definition: serchan.h:64
static PStringList GetPortNames()
Get a list of the available serial ports.
DWORD GetSpeed() const
Get the speed (baud rate) of the serial channel.
Parity GetParity() const
Get the parity of the serial port.
PBoolean SetInputFlowControl(FlowControl flowControl)
Set the flow control (handshaking) protocol of the input to the serial port.
PBoolean GetRing()
Get the Ring Indicator signal of the serial port.
PBoolean SetDataBits(BYTE data)
Set the data bits (5, 6, 7 or 8) of the serial port.
~PSerialChannel()
Close the serial channel on destruction.
void SetRTS(PBoolean state=true)
Set the Request To Send signal of the serial port.
PBoolean SetSpeed(DWORD speed)
Set the speed (baud rate) of the serial channel.