serchan.h
Go to the documentation of this file.
/*
* serchan.h
*
* Asynchronous Serial I/O channel class.
*
* Portable Windows Library
*
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Portions are Copyright (C) 1993 Free Software Foundation, Inc.
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24177 $
* $Author: rjongbloed $
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef PTLIB_SERIALCHANNEL_H
#define PTLIB_SERIALCHANNEL_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
class PConfig;
// Serial Channel
class PSerialChannel : public PChannel
{
PCLASSINFO(PSerialChannel, PChannel);
public:
PSerialChannel();
enum Parity {
DefaultParity,
NoParity,
EvenParity,
OddParity,
MarkParity,
SpaceParity
};
enum FlowControl {
DefaultFlowControl,
NoFlowControl,
XonXoff,
RtsCts
};
PSerialChannel(
const PString & port,
DWORD speed = 0,
BYTE data = 0,
Parity parity = DefaultParity,
BYTE stop = 0,
FlowControl inputFlow = DefaultFlowControl,
FlowControl outputFlow = DefaultFlowControl
);
#if P_CONFIG_FILE
PSerialChannel(
PConfig & cfg
);
#endif // P_CONFIG_FILE
~PSerialChannel();
virtual PBoolean Open(
const PString & port,
DWORD speed = 0,
BYTE data = 0,
Parity parity = DefaultParity,
BYTE stop = 0,
FlowControl inputFlow = DefaultFlowControl,
FlowControl outputFlow = DefaultFlowControl
);
#if P_CONFIG_FILE
virtual PBoolean Open(
PConfig & cfg
);
#endif // P_CONFIG_FILE
static PStringList GetPortNames();
PBoolean SetSpeed(
DWORD speed
);
DWORD GetSpeed() const;
PBoolean SetDataBits(
BYTE data
);
BYTE GetDataBits() const;
PBoolean SetParity(
Parity parity
);
Parity GetParity() const;
PBoolean SetStopBits(
BYTE stop
);
BYTE GetStopBits() const;
PBoolean SetInputFlowControl(
FlowControl flowControl
);
FlowControl GetInputFlowControl() const;
PBoolean SetOutputFlowControl(
FlowControl flowControl
);
FlowControl GetOutputFlowControl() const;
#if P_CONFIG_FILE
virtual void SaveSettings(
PConfig & cfg
);
#endif // P_CONFIG_FILE
void SetDTR(
PBoolean state = true
);
void ClearDTR();
void SetRTS(
PBoolean state = true
);
void ClearRTS();
void SetBreak(
PBoolean state = true
);
void ClearBreak();
PBoolean GetCTS();
PBoolean GetDSR();
PBoolean GetDCD();
PBoolean GetRing();
private:
void Construct();
// Platform dependent construct of the serial channel.
// Include platform dependent part of class
#ifdef _WIN32
#include "msos/ptlib/serchan.h"
#else
#include "unix/ptlib/serchan.h"
#endif
};
#endif // PTLIB_SERIALCHANNEL_H
// End Of File ///////////////////////////////////////////////////////////////
PSerialChannel::XonXoff
Set the port for software or XON/XOFF flow control.
Definition: serchan.h:84
PSerialChannel::OddParity
Set the port to generate parity and make it odd.
Definition: serchan.h:70
PSerialChannel::SaveSettings
virtual void SaveSettings(PConfig &cfg)
Save the current port settings into the configuration file.
PSerialChannel::Open
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.
PSerialChannel::ClearBreak
void ClearBreak()
Clear the break condition of the serial port.
PConfig
A class representing a configuration for the application.
Definition: config.h:67
PSerialChannel
This class defines an I/O channel that communicates via a serial port.
Definition: serchan.h:51
PSerialChannel::RtsCts
Set the port for hardware or RTS/CTS flow control.
Definition: serchan.h:86
PSerialChannel::GetDCD
PBoolean GetDCD()
Get the Data Carrier Detect signal of the serial port.
PSerialChannel::NoFlowControl
Set the port for no flow control.
Definition: serchan.h:82
PSerialChannel::GetSpeed
DWORD GetSpeed() const
Get the speed (baud rate) of the serial channel.
PSerialChannel::GetParity
Parity GetParity() const
Get the parity of the serial port.
PSerialChannel::GetStopBits
BYTE GetStopBits() const
Get the stop bits (1 or 2) of the serial port.
PSerialChannel::FlowControl
FlowControl
Configuration of serial port flow control options.
Definition: serchan.h:78
PBoolean
BOOL PBoolean
Definition: object.h:102
PSerialChannel::SetParity
PBoolean SetParity(Parity parity)
Set the parity of the serial port.
PSerialChannel::SetDTR
void SetDTR(PBoolean state=true)
Set the Data Terminal Ready signal of the serial port.
PSerialChannel::ClearRTS
void ClearRTS()
Clear the Request To Send signal of the serial port.
PSerialChannel::SetStopBits
PBoolean SetStopBits(BYTE stop)
Set the stop bits (1 or 2) of the serial port.
PSerialChannel::GetCTS
PBoolean GetCTS()
Get the Clear To Send signal of the serial port.
PChannel
Abstract class defining I/O channel semantics.
Definition: channel.h:107
PSerialChannel::NoParity
Set the port for no parity bit.
Definition: serchan.h:66
PSerialChannel::PSerialChannel
PSerialChannel()
Create a new serial channel object, but do not open it.
PSerialChannel::SetOutputFlowControl
PBoolean SetOutputFlowControl(FlowControl flowControl)
Set the flow control (handshaking) protocol of the output to the serial port.
PSerialChannel::GetDataBits
BYTE GetDataBits() const
Get the data bits (5, 6, 7 or 8) of the serial port.
PString
The character string class.
Definition: pstring.h:108
PSerialChannel::GetInputFlowControl
FlowControl GetInputFlowControl() const
Get the flow control (handshaking) protocol of the input to the serial port.
PSerialChannel::MarkParity
Set the port parity bit to mark only.
Definition: serchan.h:72
PSerialChannel::GetDSR
PBoolean GetDSR()
Get the Data Set Ready signal of the serial port.
PSerialChannel::SpaceParity
Set the port parity bit to space only.
Definition: serchan.h:74
PSerialChannel::Parity
Parity
Configuration of serial port parity options.
Definition: serchan.h:62
PStringList
This is a list collection class of PString objects.
Definition: pstring.h:2184
PSerialChannel::EvenParity
Set the port to generate parity and make it even.
Definition: serchan.h:68
PSerialChannel::SetBreak
void SetBreak(PBoolean state=true)
Set the break condition of the serial port.
PSerialChannel::GetOutputFlowControl
FlowControl GetOutputFlowControl() const
Get the flow control (handshaking) protocol of the output from the serial port.
PSerialChannel::ClearDTR
void ClearDTR()
Clear the Data Terminal Ready signal of the serial port.
PSerialChannel::DefaultFlowControl
Use the default flow control, ie do not change it.
Definition: serchan.h:80
PSerialChannel::DefaultParity
Use the default parity, ie do not change it.
Definition: serchan.h:64
PSerialChannel::GetPortNames
static PStringList GetPortNames()
Get a list of the available serial ports.
PSerialChannel::SetInputFlowControl
PBoolean SetInputFlowControl(FlowControl flowControl)
Set the flow control (handshaking) protocol of the input to the serial port.
PSerialChannel::GetRing
PBoolean GetRing()
Get the Ring Indicator signal of the serial port.
PSerialChannel::SetDataBits
PBoolean SetDataBits(BYTE data)
Set the data bits (5, 6, 7 or 8) of the serial port.
PSerialChannel::~PSerialChannel
~PSerialChannel()
Close the serial channel on destruction.
PSerialChannel::SetRTS
void SetRTS(PBoolean state=true)
Set the Request To Send signal of the serial port.
PSerialChannel::SetSpeed
PBoolean SetSpeed(DWORD speed)
Set the speed (baud rate) of the serial channel.