PTLib
Version 2.18.8
|
This class defines an I/O channel that communicates via a serial port. More...
#include <serchan.h>
Public Member Functions | |
PBoolean | Close () |
Close the channel, shutting down the link to the data source. More... | |
Configuration functions | |
PBoolean | SetSpeed (DWORD speed) |
Set the speed (baud rate) of the serial channel. More... | |
DWORD | GetSpeed () const |
Get the speed (baud rate) of the serial channel. More... | |
PBoolean | SetDataBits (BYTE data) |
Set the data bits (5, 6, 7 or 8) of the serial port. More... | |
BYTE | GetDataBits () const |
Get the data bits (5, 6, 7 or 8) of the serial port. More... | |
PBoolean | SetParity (Parity parity) |
Set the parity of the serial port. More... | |
Parity | GetParity () const |
Get the parity of the serial port. More... | |
PBoolean | SetStopBits (BYTE stop) |
Set the stop bits (1 or 2) of the serial port. More... | |
BYTE | GetStopBits () const |
Get the stop bits (1 or 2) of the serial port. More... | |
PBoolean | SetInputFlowControl (FlowControl flowControl) |
Set the flow control (handshaking) protocol of the input to the serial port. More... | |
FlowControl | GetInputFlowControl () const |
Get the flow control (handshaking) protocol of the input to the serial port. More... | |
PBoolean | SetOutputFlowControl (FlowControl flowControl) |
Set the flow control (handshaking) protocol of the output to the serial port. More... | |
FlowControl | GetOutputFlowControl () const |
Get the flow control (handshaking) protocol of the output from the serial port. More... | |
virtual void | SaveSettings (PConfig &cfg) |
Save the current port settings into the configuration file. More... | |
Status functions | |
void | SetDTR (PBoolean state=true) |
Set the Data Terminal Ready signal of the serial port. More... | |
void | ClearDTR () |
Clear the Data Terminal Ready signal of the serial port. More... | |
void | SetRTS (PBoolean state=true) |
Set the Request To Send signal of the serial port. More... | |
void | ClearRTS () |
Clear the Request To Send signal of the serial port. More... | |
void | SetBreak (PBoolean state=true) |
Set the break condition of the serial port. More... | |
void | ClearBreak () |
Clear the break condition of the serial port. More... | |
PBoolean | GetCTS () |
Get the Clear To Send signal of the serial port. More... | |
PBoolean | GetDSR () |
Get the Data Set Ready signal of the serial port. More... | |
PBoolean | GetDCD () |
Get the Data Carrier Detect signal of the serial port. More... | |
PBoolean | GetRing () |
Get the Ring Indicator signal of the serial port. More... | |
![]() | |
PBoolean | SetErrorValues (Errors errorCode, int osError, ErrorGroup group=LastGeneralError) |
Set error values to those specified. More... | |
virtual Comparison | Compare (const PObject &obj) const |
Get the relative rank of the two strings. More... | |
virtual PINDEX | HashFunction () const |
Calculate a hash value for use in sets and dictionaries. More... | |
virtual PBoolean | IsOpen () const |
Determine if the channel is currently open. More... | |
virtual P_INT_PTR | GetHandle () const |
Get the integer operating system handle for the channel. More... | |
FILE * | FDOpen (const char *mode) |
Re-open the device using the stdio library. More... | |
virtual PChannel * | GetBaseReadChannel () const |
Get the base channel of channel indirection using PIndirectChannel. More... | |
virtual PChannel * | GetBaseWriteChannel () const |
Get the base channel of channel indirection using PIndirectChannel. More... | |
virtual bool | CloseBaseReadChannel () |
Close the base channel of channel indirection using PIndirectChannel. More... | |
virtual bool | CloseBaseWriteChannel () |
Close the base channel of channel indirection using PIndirectChannel. More... | |
void | SetReadTimeout (const PTimeInterval &time) |
Set the timeout for read operations. More... | |
PTimeInterval | GetReadTimeout () const |
Get the timeout for read operations. More... | |
virtual PBoolean | Read (void *buf, PINDEX len) |
Low level read from the channel. More... | |
virtual PINDEX | GetLastReadCount () const |
Get the number of bytes read by the last Read() call. More... | |
virtual PINDEX | SetLastReadCount (PINDEX count) |
virtual int | ReadChar () |
Read a single character from the channel. More... | |
PBoolean | ReadBlock (void *buf, PINDEX len) |
Read len bytes into the buffer from the channel. More... | |
PString | ReadString (PINDEX len) |
Read len character into a string from the channel. More... | |
void | SetWriteTimeout (const PTimeInterval &time) |
Set the timeout for write operations to complete. More... | |
PTimeInterval | GetWriteTimeout () const |
Get the timeout for write operations to complete. More... | |
virtual PBoolean | Write (const void *buf, PINDEX len) |
Low level write to the channel. More... | |
virtual PBoolean | Write (const void *buf, PINDEX len, const void *) |
Low level write to the channel with marker. More... | |
virtual PINDEX | GetLastWriteCount () const |
Get the number of bytes written by the last Write() call. More... | |
virtual PINDEX | SetLastWriteCount (PINDEX count) |
PBoolean | WriteChar (int c) |
Write a single character to the channel. More... | |
PBoolean | WriteString (const PString &str) |
Write a string to the channel. More... | |
~PChannel () | |
Close down the channel. More... | |
Errors | GetErrorCode (ErrorGroup group=NumErrorGroups) const |
Get normalised error code. More... | |
int | GetErrorNumber (ErrorGroup group=NumErrorGroups) const |
Get OS errro code. More... | |
virtual PString | GetErrorText (ErrorGroup group=NumErrorGroups) const |
Get error message description. More... | |
virtual bool | ReadAsync (AsyncContext &context) |
Begin an asynchronous read from channel. More... | |
virtual void | OnReadComplete (AsyncContext &context) |
User callback function for when a ReadAsync() call has completed or timed out. More... | |
virtual bool | WriteAsync (AsyncContext &context) |
Begin an asynchronous write from channel. More... | |
virtual void | OnWriteComplete (AsyncContext &context) |
User callback function for when a WriteAsync() call has completed or timed out. More... | |
virtual PBoolean | Shutdown (ShutdownValue option) |
Close one or both of the data streams associated with a channel. More... | |
virtual bool | SetLocalEcho (bool localEcho) |
Set local echo mode. More... | |
virtual bool | FlowControl (const void *flowData) |
Flow Control information Pass data to the channel for flowControl determination. More... | |
PBoolean | SetBufferSize (PINDEX newSize) |
Set the iostream buffer size for reads and writes. More... | |
PBoolean | SendCommandString (const PString &command) |
Send a command meta-string. More... | |
void | AbortCommandString () |
Abort a command string that is in progress. More... | |
![]() | |
__inline unsigned | GetTraceContextIdentifier () const |
Get PTRACE context identifier. More... | |
__inline void | SetTraceContextIdentifier (unsigned id) |
__inline void | SetTraceContextIdentifier (const PObject &obj) |
__inline void | SetTraceContextIdentifier (const PObject *obj) |
__inline void | CopyTraceContextIdentifier (PObject &obj) const |
__inline void | CopyTraceContextIdentifier (PObject *obj) const |
virtual | ~PObject () |
__inline const char * | GetClass () const |
__inline bool | IsClass (const char *name) const |
__inline const PObject * | PTraceObjectInstance () const |
virtual PObject * | Clone () const |
Create a copy of the class on the heap. More... | |
template<class CLS > | |
CLS * | CloneAs () const |
As for Clone() but converts to specified type. More... | |
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const |
Determine the byte wise comparison of two objects. More... | |
bool | operator== (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator!= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator< (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator> (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator<= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator>= (const PObject &obj) const |
Compare the two objects. More... | |
virtual void | PrintOn (ostream &strm) const |
Output the contents of the object to the stream. More... | |
virtual void | ReadFrom (istream &strm) |
Input the contents of the object from the stream. More... | |
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. More... | |
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. More... | |
PSerialChannel (PConfig &cfg) | |
Create a serial channal. More... | |
~PSerialChannel () | |
Close the serial channel on destruction. More... | |
Open functions | |
virtual PString | GetName () const =0 |
Get the platform and I/O channel type name of the channel. More... | |
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. More... | |
virtual PBoolean | Open (PConfig &cfg) |
Open a serial channal. More... | |
static PStringList | GetPortNames () |
Get a list of the available serial ports. More... | |
Additional Inherited Members | |
![]() | |
enum | PXBlockType { PXReadBlock, PXWriteBlock, PXAcceptBlock, PXConnectBlock } |
enum | Errors { NoError, NotFound, FileExists, DiskFull, AccessDenied, DeviceInUse, BadParameter, NoMemory, NotOpen, Timeout, Interrupted, BufferTooSmall, Miscellaneous, ProtocolFailure, Unavailable, NumNormalisedErrors } |
Normalised error codes. More... | |
enum | ErrorGroup { LastReadError, LastWriteError, LastGeneralError, NumErrorGroups } |
Error groups. More... | |
typedef PNotifierTemplate < PChannel::AsyncContext & > | AsyncNotifier |
enum | ShutdownValue { ShutdownRead = 0, ShutdownWrite = 1, ShutdownReadAndWrite = 2 } |
![]() | |
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 } |
Result of the comparison operation performed by the Compare() function. More... | |
![]() | |
static PString | GetErrorText (Errors lastError, int osError=0) |
Get error message description. More... | |
![]() | |
static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject &from) |
static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject *from) |
static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject &from) |
static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject *from) |
static __inline const char * | Class () |
static __inline const PObject * | PTraceObjectInstance (const char *) |
static __inline const PObject * | PTraceObjectInstance (const PObject *obj) |
template<typename T > | |
static Comparison | Compare2 (T v1, T v2) |
Compare two types, returning Comparison type. More... | |
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size) |
Internal function caled from CompareObjectMemoryDirect() More... | |
![]() | |
PChannel (const PChannel &) | |
PChannel & | operator= (const PChannel &) |
virtual PBoolean | ConvertOSError (P_INT_PTR libcReturnValue, ErrorGroup group=LastGeneralError) |
Convert an operating system error into platform independent error. More... | |
int | ReadCharWithTimeout (PTimeInterval &timeout) |
Read a character with specified timeout. More... | |
PBoolean | ReceiveCommandString (int nextChar, const PString &reply, PINDEX &pos, PINDEX start) |
bool | CheckNotOpen () |
virtual int | os_errno () const |
PBoolean | PXSetIOBlock (PXBlockType type, const PTimeInterval &timeout) |
P_INT_PTR | GetOSHandleAsInt () const |
int | PXClose () |
PDECLARE_MUTEX (px_threadMutex) | |
PDECLARE_MUTEX (px_writeMutex) | |
PChannel () | |
Create the channel. More... | |
![]() | |
PObject () | |
Constructor for PObject, made protected so cannot ever create one on its own. More... | |
![]() | |
PTimeInterval | readTimeout |
Timeout for read operations. More... | |
PTimeInterval | writeTimeout |
Timeout for write operations. More... | |
atomic< P_INT_PTR > | os_handle |
The operating system file handle return by standard open() function. More... | |
PThreadLocalStorage< Status > | m_status [NumErrorGroups+1] |
PXBlockType | px_lastBlockType |
PThread * | px_readThread |
PThread * | px_writeThread |
PThread * | px_selectThread [3] |
PCriticalSection | px_selectMutex [3] |
![]() | |
unsigned | m_traceContextIdentifier |
This class defines an I/O channel that communicates via a serial port.
This is usually an RS-232 port.
Configuration of serial port parity options.
PSerialChannel::PSerialChannel | ( | ) |
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.
port | The 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. |
speed | Serial 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. |
data | Number of data bits for serial port. The actual values possible here are platform dependent, but 7 and 8 should always be legal. |
parity | Parity for serial port. The actual values possible here are platform dependent, but NoParity , OddParity and EvenParity should always be legal. |
stop | Number of stop bits for serial port. The actual values possible here are platform dependent, but 1 and 2 should always be legal. |
inputFlow | Flow control for data from the remote system into this conputer. |
outputFlow | Flow control for data from this conputer out to remote system. |
PSerialChannel::PSerialChannel | ( | PConfig & | cfg | ) |
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.
cfg | Configuration file to read serial port attributes from. |
PSerialChannel::~PSerialChannel | ( | ) |
Close the serial channel on destruction.
void PSerialChannel::ClearBreak | ( | ) |
Clear the break condition of the serial port.
This is equivalent to SetBreak(false)
.
void PSerialChannel::ClearDTR | ( | ) |
Clear the Data Terminal Ready signal of the serial port.
This is equivalent to SetDTR(false)
.
void PSerialChannel::ClearRTS | ( | ) |
Clear the Request To Send signal of the serial port.
This is equivalent to SetRTS(false)
.
|
virtual |
Close the channel, shutting down the link to the data source.
Reimplemented from PChannel.
PBoolean PSerialChannel::GetCTS | ( | ) |
Get the Clear To Send signal of the serial port.
BYTE PSerialChannel::GetDataBits | ( | ) | const |
Get the data bits (5, 6, 7 or 8) of the serial port.
PBoolean PSerialChannel::GetDCD | ( | ) |
Get the Data Carrier Detect signal of the serial port.
PBoolean PSerialChannel::GetDSR | ( | ) |
Get the Data Set Ready signal of the serial port.
FlowControl PSerialChannel::GetInputFlowControl | ( | ) | const |
Get the flow control (handshaking) protocol of the input to the serial port.
|
pure virtual |
FlowControl PSerialChannel::GetOutputFlowControl | ( | ) | const |
Get the flow control (handshaking) protocol of the output from the serial port.
Parity PSerialChannel::GetParity | ( | ) | const |
Get the parity of the serial port.
|
static |
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".
PBoolean PSerialChannel::GetRing | ( | ) |
Get the Ring Indicator signal of the serial port.
DWORD PSerialChannel::GetSpeed | ( | ) | const |
Get the speed (baud rate) of the serial channel.
BYTE PSerialChannel::GetStopBits | ( | ) | const |
Get the stop bits (1 or 2) of the serial port.
|
virtual |
Open a serial channal.
The channel is opened it on the specified port and with the specified attributes.
port | The 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. |
speed | Serial 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. |
data | Number of data bits for serial port. The actual values possible here are platform dependent, but 7 and 8 should always be legal. |
parity | Parity for serial port. The actual values possible here are platform dependent, but NoParity , OddParity and EvenParity should always be legal. |
stop | Number of stop bits for serial port. The actual values possible here are platform dependent, but 1 and 2 should always be legal. |
inputFlow | Flow control for data from the remote system into this conputer. |
outputFlow | Flow control for data from this conputer out to remote system. |
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.
cfg | Configuration file to read serial port attributes from. |
|
virtual |
Save the current port settings into the configuration file.
Note that it assumed that the correct configuration file section is already set.
cfg | Configuration file to save setting into. |
void PSerialChannel::SetBreak | ( | PBoolean | state = true | ) |
Set the break condition of the serial port.
state | New state of the serial port break condition. |
PBoolean PSerialChannel::SetDataBits | ( | BYTE | data | ) |
Set the data bits (5, 6, 7 or 8) of the serial port.
data | New number of data bits for serial channel. |
void PSerialChannel::SetDTR | ( | PBoolean | state = true | ) |
Set the Data Terminal Ready signal of the serial port.
state | New state of the DTR signal. |
PBoolean PSerialChannel::SetInputFlowControl | ( | FlowControl | flowControl | ) |
Set the flow control (handshaking) protocol of the input to the serial port.
flowControl | New flow control for serial channel input. |
PBoolean PSerialChannel::SetOutputFlowControl | ( | FlowControl | flowControl | ) |
Set the flow control (handshaking) protocol of the output to the serial port.
flowControl | New flow control for serial channel output. |
Set the parity of the serial port.
parity | New parity option for serial channel. |
void PSerialChannel::SetRTS | ( | PBoolean | state = true | ) |
Set the Request To Send signal of the serial port.
state | New state of the RTS signal. |
PBoolean PSerialChannel::SetSpeed | ( | DWORD | speed | ) |
Set the speed (baud rate) of the serial channel.
speed | New speed for serial channel. |
PBoolean PSerialChannel::SetStopBits | ( | BYTE | stop | ) |
Set the stop bits (1 or 2) of the serial port.
stop | New number of stop bits for serial channel. |