PTLib  Version 2.10.4
PSerialChannel Class Reference

This class defines an I/O channel that communicates via a serial port. More...

#include <serchan.h>

Inheritance diagram for PSerialChannel:
PChannel PObject PModem

List of all members.

Public Member Functions

PBoolean Close ()
 Close the channel, shutting down the link to the data source.
Configuration functions
PBoolean SetSpeed (DWORD speed)
 Set the speed (baud rate) of the serial channel.
DWORD GetSpeed () const
 Get the speed (baud rate) of the serial channel.
PBoolean SetDataBits (BYTE data)
 Set the data bits (5, 6, 7 or 8) of the serial port.
BYTE GetDataBits () const
 Get the data bits (5, 6, 7 or 8) of the serial port.
PBoolean SetParity (Parity parity)
 Set the parity of the serial port.
Parity GetParity () const
 Get the parity of the serial port.
PBoolean SetStopBits (BYTE stop)
 Set the stop bits (1 or 2) of the serial port.
BYTE GetStopBits () const
 Get the stop bits (1 or 2) of the serial port.
PBoolean SetInputFlowControl (FlowControl flowControl)
 Set the flow control (handshaking) protocol of the input to the serial port.
FlowControl GetInputFlowControl () const
 Get the flow control (handshaking) protocol of the input to the serial port.
PBoolean SetOutputFlowControl (FlowControl flowControl)
 Set the flow control (handshaking) protocol of the output to the serial port.
FlowControl GetOutputFlowControl () const
 Get the flow control (handshaking) protocol of the output from the serial port.
virtual void SaveSettings (PConfig &cfg)
 Save the current port settings into the configuration file.
Status functions
void SetDTR (PBoolean state=true)
 Set the Data Terminal Ready signal of the serial port.
void ClearDTR ()
 Clear the Data Terminal Ready signal of the serial port.
void SetRTS (PBoolean state=true)
 Set the Request To Send signal of the serial port.
void ClearRTS ()
 Clear the Request To Send signal of the serial port.
void SetBreak (PBoolean state=true)
 Set the break condition of the serial port.
void ClearBreak ()
 Clear the break condition of the serial port.
PBoolean GetCTS ()
 Get the Clear To Send signal of the serial port.
PBoolean GetDSR ()
 Get the Data Set Ready signal of the serial port.
PBoolean GetDCD ()
 Get the Data Carrier Detect signal of the serial port.
PBoolean GetRing ()
 Get the Ring Indicator signal of the serial port.

Construction

enum  Parity {
  DefaultParity, NoParity, EvenParity, OddParity,
  MarkParity, SpaceParity
}
 Configuration of serial port parity options. More...
enum  FlowControl { DefaultFlowControl, NoFlowControl, XonXoff, RtsCts }
 Configuration of serial port flow control options. More...
 PSerialChannel ()
 Create a new serial channel object, but do not open it.
 PSerialChannel (const PString &port, DWORD speed=0, BYTE data=0, Parity parity=DefaultParity, BYTE stop=0, FlowControl inputFlow=DefaultFlowControl, FlowControl outputFlow=DefaultFlowControl)
 Create a serial channal.
 PSerialChannel (PConfig &cfg)
 Create a serial channal.
 ~PSerialChannel ()
 Close the serial channel on destruction.

Open functions

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.
virtual PBoolean Open (PConfig &cfg)
 Open a serial channal.
static PStringList GetPortNames ()
 Get a list of the available serial ports.

Detailed Description

This class defines an I/O channel that communicates via a serial port.

This is usually an RS-232 port.


Member Enumeration Documentation

Configuration of serial port flow control options.

Enumerator:
DefaultFlowControl 

Use the default flow control, ie do not change it.

NoFlowControl 

Set the port for no flow control.

XonXoff 

Set the port for software or XON/XOFF flow control.

RtsCts 

Set the port for hardware or RTS/CTS flow control.

Configuration of serial port parity options.

Enumerator:
DefaultParity 

Use the default parity, ie do not change it.

NoParity 

Set the port for no parity bit.

EvenParity 

Set the port to generate parity and make it even.

OddParity 

Set the port to generate parity and make it odd.

MarkParity 

Set the port parity bit to mark only.

SpaceParity 

Set the port parity bit to space only.


Constructor & Destructor Documentation

Create a new serial channel object, but do not open it.

PSerialChannel::PSerialChannel ( const PString port,
DWORD  speed = 0,
BYTE  data = 0,
Parity  parity = DefaultParity,
BYTE  stop = 0,
FlowControl  inputFlow = DefaultFlowControl,
FlowControl  outputFlow = DefaultFlowControl 
)

Create a serial channal.

The channel is opened it on the specified port and with the specified attributes.

Parameters:
portThe name of the serial port to connect to. This is a platform dependent string and woiuld rarely be a literal. The static function GetPortNames() can be used to find the platforms serial ports.
speedSerial port speed or baud rate. The actual values possible here are platform dependent, but the standard value of 300, 1200, 2400, 4800, 9600, 19200, 38400 always be legal.
dataNumber of data bits for serial port. The actual values possible here are platform dependent, but 7 and 8 should always be legal.
parityParity for serial port. The actual values possible here are platform dependent, but NoParity, OddParity and EvenParity should always be legal.
stopNumber of stop bits for serial port. The actual values possible here are platform dependent, but 1 and 2 should always be legal.
inputFlowFlow control for data from the remote system into this conputer.
outputFlowFlow control for data from this conputer out to remote system.

Create a serial channal.

The channel is opened using attributes obtained from standard variables in the configuration file. Note that it assumed that the correct configuration file section is already set.

Parameters:
cfgConfiguration file to read serial port attributes from.

Close the serial channel on destruction.


Member Function Documentation

Clear the break condition of the serial port.

This is equivalent to SetBreak(false).

Clear the Data Terminal Ready signal of the serial port.

This is equivalent to SetDTR(false).

Clear the Request To Send signal of the serial port.

This is equivalent to SetRTS(false).

Close the channel, shutting down the link to the data source.

Returns:
true if the channel successfully closed.

Reimplemented from PChannel.

Reimplemented in PModem.

Get the Clear To Send signal of the serial port.

Returns:
true if the CTS signal is asserted.

Get the data bits (5, 6, 7 or 8) of the serial port.

Returns:
current setting.

Get the Data Carrier Detect signal of the serial port.

Returns:
true if the DCD signal is asserted.

Get the Data Set Ready signal of the serial port.

Returns:
true if the DSR signal is asserted.

Get the flow control (handshaking) protocol of the input to the serial port.

Returns:
current setting.

Get the flow control (handshaking) protocol of the output from the serial port.

Returns:
current setting.

Get the parity of the serial port.

Returns:
current setting.

Get a list of the available serial ports.

This returns a set of platform dependent strings which describe the serial ports of the computer. For example under unix it may be "ttyS0", under MS-DOS or NT it would be "COM1" and for the Macintosh it could be "Modem".

Returns:
list of strings for possible serial ports.

Get the Ring Indicator signal of the serial port.

Returns:
true if the RI signal is asserted.
DWORD PSerialChannel::GetSpeed ( ) const

Get the speed (baud rate) of the serial channel.

Returns:
current setting.

Get the stop bits (1 or 2) of the serial port.

Returns:
current setting.
virtual PBoolean PSerialChannel::Open ( const PString port,
DWORD  speed = 0,
BYTE  data = 0,
Parity  parity = DefaultParity,
BYTE  stop = 0,
FlowControl  inputFlow = DefaultFlowControl,
FlowControl  outputFlow = DefaultFlowControl 
) [virtual]

Open a serial channal.

The channel is opened it on the specified port and with the specified attributes.

Parameters:
portThe name of the serial port to connect to. This is a platform dependent string and woiuld rarely be a literal. The static function GetPortNames() can be used to find the platforms serial ports.
speedSerial port speed or baud rate. The actual values possible here are platform dependent, but the standard value of 300, 1200, 2400, 4800, 9600, 19200, 38400 always be legal.
dataNumber of data bits for serial port. The actual values possible here are platform dependent, but 7 and 8 should always be legal.
parityParity for serial port. The actual values possible here are platform dependent, but NoParity, OddParity and EvenParity should always be legal.
stopNumber of stop bits for serial port. The actual values possible here are platform dependent, but 1 and 2 should always be legal.
inputFlowFlow control for data from the remote system into this conputer.
outputFlowFlow control for data from this conputer out to remote system.

Reimplemented in PModem.

virtual PBoolean PSerialChannel::Open ( PConfig cfg) [virtual]

Open a serial channal.

The channel is opened using attributes obtained from standard variables in the configuration file. Note that it assumed that the correct configuration file section is already set.

Parameters:
cfgConfiguration file to read serial port attributes from.

Reimplemented in PModem.

virtual void PSerialChannel::SaveSettings ( PConfig cfg) [virtual]

Save the current port settings into the configuration file.

Note that it assumed that the correct configuration file section is already set.

Parameters:
cfgConfiguration file to save setting into.

Reimplemented in PModem.

void PSerialChannel::SetBreak ( PBoolean  state = true)

Set the break condition of the serial port.

Parameters:
stateNew state of the serial port break condition.

Set the data bits (5, 6, 7 or 8) of the serial port.

Returns:
true if the change was successfully made.
Parameters:
dataNew number of data bits for serial channel.
void PSerialChannel::SetDTR ( PBoolean  state = true)

Set the Data Terminal Ready signal of the serial port.

Parameters:
stateNew state of the DTR signal.

Set the flow control (handshaking) protocol of the input to the serial port.

Returns:
true if the change was successfully made.
Parameters:
flowControlNew flow control for serial channel input.

Set the flow control (handshaking) protocol of the output to the serial port.

Returns:
true if the change was successfully made.
Parameters:
flowControlNew flow control for serial channel output.

Set the parity of the serial port.

Returns:
true if the change was successfully made.
Parameters:
parityNew parity option for serial channel.
void PSerialChannel::SetRTS ( PBoolean  state = true)

Set the Request To Send signal of the serial port.

Parameters:
stateNew state of the RTS signal.

Set the speed (baud rate) of the serial channel.

Returns:
true if the change was successfully made.
Parameters:
speedNew speed for serial channel.

Set the stop bits (1 or 2) of the serial port.

Returns:
true if the change was successfully made.
Parameters:
stopNew number of stop bits for serial channel.

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines