PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
30 #ifndef PTLIB_SERIALCHANNEL_H
31 #define PTLIB_SERIALCHANNEL_H
32 
33 #ifdef P_USE_PRAGMA
34 #pragma interface
35 #endif
36 
37 
38 class PConfig;
39 
40 #if HAVE_TERMIOS_H
41  #include <termios.h>
42 #elif HAVE_SYS_TERMIOS_H
43  #include <sys/termios.h>
44 #endif
45 
46 
48 // Serial Channel
49 
53 class PSerialChannel : public PChannel
54 {
55  PCLASSINFO(PSerialChannel, PChannel);
56 
57  public:
62 
64  enum Parity {
77  };
78 
80  enum FlowControl {
89  };
90 
100  const PString & port,
105  DWORD speed = 0,
109  BYTE data = 0,
114  Parity parity = DefaultParity,
118  BYTE stop = 0,
120  FlowControl inputFlow = DefaultFlowControl,
122  FlowControl outputFlow = DefaultFlowControl
123  );
124 
125 #if P_CONFIG_FILE
126 
132  PConfig & cfg
133  );
134 #endif // P_CONFIG_FILE
135 
137  ~PSerialChannel();
139 
140 
148  virtual PString GetName() const = 0;
149 
154  virtual PBoolean Open(
159  const PString & port,
164  DWORD speed = 0,
168  BYTE data = 0,
173  Parity parity = DefaultParity,
177  BYTE stop = 0,
179  FlowControl inputFlow = DefaultFlowControl,
181  FlowControl outputFlow = DefaultFlowControl
182  );
183 
184 #if P_CONFIG_FILE
185 
190  virtual PBoolean Open(
191  PConfig & cfg
192  );
193 #endif // P_CONFIG_FILE
194 
203  static PStringList GetPortNames();
205 
206 
215  DWORD speed
216  );
217 
223  DWORD GetSpeed() const;
224 
231  BYTE data
232  );
233 
239  BYTE GetDataBits() const;
240 
247  Parity parity
248  );
249 
255  Parity GetParity() const;
256 
263  BYTE stop
264  );
265 
271  BYTE GetStopBits() const;
272 
280  FlowControl flowControl
281  );
282 
290 
298  FlowControl flowControl
299  );
300 
308 
309 #if P_CONFIG_FILE
310 
313  virtual void SaveSettings(
314  PConfig & cfg
315  );
316 #endif // P_CONFIG_FILE
317 
318 
319 
323  void SetDTR(
324  PBoolean state = true
325  );
326 
330  void ClearDTR();
331 
333  void SetRTS(
334  PBoolean state = true
335  );
336 
340  void ClearRTS();
341 
343  void SetBreak(
344  PBoolean state = true
345  );
346 
350  void ClearBreak();
351 
357  PBoolean GetCTS();
358 
364  PBoolean GetDSR();
365 
371  PBoolean GetDCD();
372 
378  PBoolean GetRing();
380 
381 
382  private:
383  void Construct();
384  // Platform dependent construct of the serial channel.
385 
386  PString m_portName;
387 
388 // Include platform dependent part of class
389 #ifdef _WIN32
390 #include "msos/ptlib/serchan.h"
391 #else
392 #include "unix/ptlib/serchan.h"
393 #endif
394 };
395 
396 
397 #endif // PTLIB_SERIALCHANNEL_H
398 
399 
400 // End Of File ///////////////////////////////////////////////////////////////
Set the port for software or XON/XOFF flow control.
Definition: serchan.h:86
Set the port to generate parity and make it odd.
Definition: serchan.h:72
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:62
virtual PString GetName() const =0
Get the platform and I/O channel type name of the channel.
This class defines an I/O channel that communicates via a serial port.
Definition: serchan.h:53
Set the port for hardware or RTS/CTS flow control.
Definition: serchan.h:88
PBoolean GetDCD()
Get the Data Carrier Detect signal of the serial port.
Set the port for no flow control.
Definition: serchan.h:84
DWORD GetSpeed() const
Get the speed (baud rate) of the serial channel.
Parity GetParity() const
Get the parity 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:80
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:103
Set the port for no parity bit.
Definition: serchan.h:68
bool PBoolean
Definition: object.h:174
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.
BYTE GetDataBits() const
Get the data bits (5, 6, 7 or 8) of the serial port.
The character string class.
Definition: pstring.h:108
FlowControl GetInputFlowControl() const
Get the flow control (handshaking) protocol of the input to the serial port.
Set the port parity bit to mark only.
Definition: serchan.h:74
PBoolean GetDSR()
Get the Data Set Ready signal of the serial port.
Set the port parity bit to space only.
Definition: serchan.h:76
Parity
Configuration of serial port parity options.
Definition: serchan.h:64
This is a list collection class of PString objects.
Definition: pstring.h:2562
Set the port to generate parity and make it even.
Definition: serchan.h:70
void SetBreak(PBoolean state=true)
Set the break condition of the serial port.
FlowControl GetOutputFlowControl() const
Get the flow control (handshaking) protocol of the output from 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:82
Use the default parity, ie do not change it.
Definition: serchan.h:66
static PStringList GetPortNames()
Get a list of the available serial ports.
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.