PTLib  Version 2.12.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PModem Class Reference

A class representing a modem attached to a serial port. More...

#include <modem.h>

Inheritance diagram for PModem:
Collaboration diagram for PModem:

Public Types

enum  Status {
  Unopened, Uninitialised, Initialising, Initialised,
  InitialiseFailed, Dialling, DialFailed, AwaitingResponse,
  LineBusy, NoCarrier, Connected, HangingUp,
  HangUpFailed, Deinitialising, DeinitialiseFailed, SendingUserCommand,
  NumStatuses
}
 
- Public Types inherited from PSerialChannel
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...
 

Public Member Functions

 PModem ()
 Create a modem object on the serial port specified. More...
 
 PModem (const PString &port, DWORD speed=0, BYTE data=0, Parity parity=DefaultParity, BYTE stop=0, FlowControl inputFlow=DefaultFlowControl, FlowControl outputFlow=DefaultFlowControl)
 
 PModem (PConfig &cfg)
 Open the modem serial channel obtaining the parameters from standard variables in the configuration file. More...
 
virtual PBoolean Close ()
 Close the channel, shutting down the link to the data source. 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 the modem serial channel on the specified port. More...
 
virtual PBoolean Open (PConfig &cfg)
 Open the modem serial port obtaining the parameters from standard variables in the configuration file. More...
 
virtual void SaveSettings (PConfig &cfg)
 Save the current port settings into the configuration file. More...
 
void SetInitString (const PString &str)
 Set the modem initialisation meta-command string. More...
 
PString GetInitString () const
 Get the modem initialisation meta-command string. More...
 
PBoolean CanInitialise () const
 The modem is in a state that allows the initialise to start. More...
 
PBoolean Initialise ()
 Send the initialisation meta-command string to the modem. More...
 
void SetDeinitString (const PString &str)
 Set the modem de-initialisation meta-command string. More...
 
PString GetDeinitString () const
 Get the modem de-initialisation meta-command string. More...
 
PBoolean CanDeinitialise () const
 The modem is in a state that allows the de-initialise to start. More...
 
PBoolean Deinitialise ()
 Send the de-initialisation meta-command string to the modem. More...
 
void SetPreDialString (const PString &str)
 Set the modem pre-dial meta-command string. More...
 
PString GetPreDialString () const
 Get the modem pre-dial meta-command string. More...
 
void SetPostDialString (const PString &str)
 Set the modem post-dial meta-command string. More...
 
PString GetPostDialString () const
 Get the modem post-dial meta-command string. More...
 
void SetBusyString (const PString &str)
 Set the modem busy response meta-command string. More...
 
PString GetBusyString () const
 Get the modem busy response meta-command string. More...
 
void SetNoCarrierString (const PString &str)
 Set the modem no carrier response meta-command string. More...
 
PString GetNoCarrierString () const
 Get the modem no carrier response meta-command string. More...
 
void SetConnectString (const PString &str)
 Set the modem connect response meta-command string. More...
 
PString GetConnectString () const
 Get the modem connect response meta-command string. More...
 
PBoolean CanDial () const
 The modem is in a state that allows the dial to start. More...
 
PBoolean Dial (const PString &number)
 Send the dial meta-command strings to the modem. More...
 
void SetHangUpString (const PString &str)
 Set the modem hang up meta-command string. More...
 
PString GetHangUpString () const
 Get the modem hang up meta-command string. More...
 
PBoolean CanHangUp () const
 The modem is in a state that allows the hang up to start. More...
 
PBoolean HangUp ()
 Send the hang up meta-command string to the modem. More...
 
PBoolean CanSendUser () const
 The modem is in a state that allows the user command to start. More...
 
PBoolean SendUser (const PString &str)
 Send an arbitrary user meta-command string to the modem. More...
 
void Abort ()
 
PBoolean CanRead () const
 The modem is in a state that allows the user application to read from the channel. More...
 
Status GetStatus () const
 Get the modem objects current state. More...
 
- Public Member Functions inherited from PSerialChannel
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...
 
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...
 
 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...
 
- Public Member Functions inherited from PChannel
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 PString GetName () const
 Get the platform and I/O channel type name of the channel. More...
 
P_INT_PTR GetHandle () const
 Get the integer operating system handle for the channel. More...
 
virtual PChannelGetBaseReadChannel () const
 Get the base channel of channel indirection using PIndirectChannel. More...
 
virtual PChannelGetBaseWriteChannel () const
 Get 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 int ReadChar ()
 Read a single 8 bit byte 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...
 
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...
 
- Public Member Functions inherited from PObject
unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
void SetTraceContextIdentifier (unsigned id)
 
void GetTraceContextIdentifier (PObject &obj)
 
void GetTraceContextIdentifier (PObject *obj)
 
void SetTraceContextIdentifier (const PObject &obj)
 
void SetTraceContextIdentifier (const PObject *obj)
 
virtual ~PObject ()
 
virtual PObjectClone () 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 const char * GetClass (unsigned ancestor=0) const
 Get the current dynamic type of the object instance. More...
 
PBoolean IsClass (const char *cls) const
 
virtual PBoolean InternalIsDescendant (const char *clsName) const
 Determine if the dynamic type of the current instance is a descendent of the specified class. More...
 
__inline const PObjectPTraceObjectInstance () const
 
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...
 

Protected Attributes

PString initCmd
 
PString deinitCmd
 
PString preDialCmd
 
PString postDialCmd
 
PString busyReply
 
PString noCarrierReply
 
PString connectReply
 
PString hangUpCmd
 
Status status
 

Additional Inherited Members

- Static Public Member Functions inherited from PSerialChannel
static PStringList GetPortNames ()
 Get a list of the available serial ports. More...
 
- Static Public Member Functions inherited from PChannel
static PString GetErrorText (Errors lastError, int osError=0)
 Get error message description. More...
 
static PBoolean ConvertOSError (P_INT_PTR libcReturnValue, Errors &lastError, int &osError)
 Convert an operating system error into platform independent error. More...
 
- Static Public Member Functions inherited from PObject
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
static const char * Class ()
 Get the name of the class as a C string. More...
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
- Protected Member Functions inherited from PChannel
 PChannel (const PChannel &)
 
PChanneloperator= (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)
 
PBoolean PXSetIOBlock (PXBlockType type, const PTimeInterval &timeout)
 
P_INT_PTR GetOSHandleAsInt () const
 
int PXClose ()
 
 PChannel ()
 Create the channel. More...
 
- Friends inherited from PObject

Detailed Description

A class representing a modem attached to a serial port.

This adds the usual modem operations to the basic serial port.

A modem object is always in a particular state. This state determines what operations are allowed which then move the object to other states. The operations are the exchange of strings in "chat" script.

The following defaults are used for command strings: initialise ATZ\r\w2sOK\w100m deinitialise \d2s+++\d2sATH0\r pre-dial ATDT post-dial \r busy reply BUSY no carrier reply NO CARRIER connect reply CONNECT hang up \d2s+++\d2sATH0\r

Member Enumeration Documentation

Enumerator
Unopened 

Has not been opened yet.

Uninitialised 

Is open but has not yet been initialised.

Initialising 

Is currently initialising the modem.

Initialised 

Has been initialised but is not connected.

InitialiseFailed 

Initialisation sequence failed.

Dialling 

Is currently dialling.

DialFailed 

Dial failed.

AwaitingResponse 

Dialling in progress, awaiting connection.

LineBusy 

Dial failed due to line busy.

NoCarrier 

Dial failed due to no carrier.

Connected 

Dial was successful and modem has connected.

HangingUp 

Is currently hanging up the modem.

HangUpFailed 

The hang up failed.

Deinitialising 

is currently de-initialising the modem

DeinitialiseFailed 

The de-initialisation failed.

SendingUserCommand 

Is currently sending a user command.

NumStatuses 

Constructor & Destructor Documentation

PModem::PModem ( )

Create a modem object on the serial port specified.

If no port was specified do not open it. It does not initially have a valid port name.

See the PSerialChannel class for more information on the parameters.

PModem::PModem ( const PString port,
DWORD  speed = 0,
BYTE  data = 0,
Parity  parity = DefaultParity,
BYTE  stop = 0,
FlowControl  inputFlow = DefaultFlowControl,
FlowControl  outputFlow = DefaultFlowControl 
)
Parameters
portSerial port name to open.
speedSpeed of serial port.
dataNumber of data bits for serial port.
parityParity for serial port.
stopNumber of stop bits for serial port.
inputFlowInput flow control.
outputFlowOutput flow control.
PModem::PModem ( PConfig cfg)

Open the modem serial channel obtaining the parameters 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 parameters from.

Member Function Documentation

void PModem::Abort ( )
PBoolean PModem::CanDeinitialise ( ) const

The modem is in a state that allows the de-initialise to start.

Returns
true if the Deinitialise() function may proceeed.
PBoolean PModem::CanDial ( ) const

The modem is in a state that allows the dial to start.

Returns
true if the Dial() function may proceeed.
PBoolean PModem::CanHangUp ( ) const

The modem is in a state that allows the hang up to start.

Returns
true if the HangUp() function may proceeed.
PBoolean PModem::CanInitialise ( ) const

The modem is in a state that allows the initialise to start.

Returns
true if the Initialise() function may proceeed.
PBoolean PModem::CanRead ( ) const

The modem is in a state that allows the user application to read from the channel.

Reading while this is true can interfere with the operation of the meta-string processing. This function is only usefull when multi-threading is used.

Returns
true if Read() operations are "safe".
PBoolean PModem::CanSendUser ( ) const

The modem is in a state that allows the user command to start.

Returns
true if the SendUser() function may proceeed.
virtual PBoolean PModem::Close ( )
virtual

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

Returns
true if the channel successfully closed.

Reimplemented from PSerialChannel.

PBoolean PModem::Deinitialise ( )

Send the de-initialisation meta-command string to the modem.

The return value indicates that the conditions for the operation to start were met, ie the serial port was open etc and the command was successfully sent with all replies met.

Returns
true if command string sent successfully and the objects state has changed.
PBoolean PModem::Dial ( const PString number)

Send the dial meta-command strings to the modem.

The return value indicates that the conditions for the operation to start were met, ie the serial port was open etc and the command was successfully sent with all replies met.

The string sent to the modem is the concatenation of the pre-dial string, a \s, the number parameter and the post-dial string.

Returns
true if command string sent successfully and the objects state has changed.
PString PModem::GetBusyString ( ) const

Get the modem busy response meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Returns
string for busy response command.
PString PModem::GetConnectString ( ) const

Get the modem connect response meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Returns
string for connect response command.
PString PModem::GetDeinitString ( ) const

Get the modem de-initialisation meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Returns
string for de-initialisation command.
PString PModem::GetHangUpString ( ) const

Get the modem hang up meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Returns
string for hang up command.
PString PModem::GetInitString ( ) const

Get the modem initialisation meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Returns
string for initialisation command.
PString PModem::GetNoCarrierString ( ) const

Get the modem no carrier response meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Returns
string for no carrier response command.
PString PModem::GetPostDialString ( ) const

Get the modem post-dial meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Returns
string for post-dial command.
PString PModem::GetPreDialString ( ) const

Get the modem pre-dial meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Returns
string for pre-dial command.
Status PModem::GetStatus ( ) const

Get the modem objects current state.

Returns
modem status.
PBoolean PModem::HangUp ( )

Send the hang up meta-command string to the modem.

The return value indicates that the conditions for the operation to start were met, ie the serial port was open etc and the command was successfully sent with all replies met.

Returns
true if command string sent successfully and the objects state has changed.
PBoolean PModem::Initialise ( )

Send the initialisation meta-command string to the modem.

The return value indicates that the conditions for the operation to start were met, ie the serial port was open etc and the command was successfully sent with all replies met.

Returns
true if command string sent successfully and the objects state has changed.
virtual PBoolean PModem::Open ( const PString port,
DWORD  speed = 0,
BYTE  data = 0,
Parity  parity = DefaultParity,
BYTE  stop = 0,
FlowControl  inputFlow = DefaultFlowControl,
FlowControl  outputFlow = DefaultFlowControl 
)
virtual

Open the modem serial channel on the specified port.

See the PSerialChannel class for more information on the parameters.

Returns
true if the modem serial port was successfully opened.
Parameters
portSerial port name to open.
speedSpeed of serial port.
dataNumber of data bits for serial port.
parityParity for serial port.
stopNumber of stop bits for serial port.
inputFlowInput flow control.
outputFlowOutput flow control.

Reimplemented from PSerialChannel.

virtual PBoolean PModem::Open ( PConfig cfg)
virtual

Open the modem serial port obtaining the parameters from standard variables in the configuration file.

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

Returns
true if the modem serial port was successfully opened.
Parameters
cfgConfiguration file to read parameters from.

Reimplemented from PSerialChannel.

virtual void PModem::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 write parameters to.

Reimplemented from PSerialChannel.

PBoolean PModem::SendUser ( const PString str)

Send an arbitrary user meta-command string to the modem.

The return value indicates that the conditions for the operation to start were met, ie the serial port was open etc and the command was successfully sent with all replies met.

Returns
true if command string sent successfully.
Parameters
strUser command string to send.
void PModem::SetBusyString ( const PString str)

Set the modem busy response meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Note there is an implied \w120s before the string. Also the \s and \d commands do not operate and will simply terminate the string match.

Parameters
strNew busy response command string.
void PModem::SetConnectString ( const PString str)

Set the modem connect response meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Note there is an implied \w120s before the string. Also the \s and \d commands do not operate and will simply terminate the string match.

Parameters
strNew connect response command string.
void PModem::SetDeinitString ( const PString str)

Set the modem de-initialisation meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Note there is an implied \s before the string.

Parameters
strNew de-initialisation command string.
void PModem::SetHangUpString ( const PString str)

Set the modem hang up meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Note there is an implied \s before the string.

Parameters
strNew hang up command string.
void PModem::SetInitString ( const PString str)

Set the modem initialisation meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Note there is an implied \s before the string.

Parameters
strNew initialisation command string.
void PModem::SetNoCarrierString ( const PString str)

Set the modem no carrier response meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Note there is an implied \w120s before the string. Also the \s and \d commands do not operate and will simply terminate the string match.

Parameters
strNew no carrier response command string.
void PModem::SetPostDialString ( const PString str)

Set the modem post-dial meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Note there is not an implied \s before the string, unlike the pre-dial string.

Parameters
strNew post-dial command string.
void PModem::SetPreDialString ( const PString str)

Set the modem pre-dial meta-command string.

See the PChannel::SendCommandString() function for more information on the format of the command string.

Note there is an implied \s before the string.

Parameters
strNew pre-dial command string.

Member Data Documentation

PString PModem::busyReply
protected
PString PModem::connectReply
protected
PString PModem::deinitCmd
protected
PString PModem::hangUpCmd
protected
PString PModem::initCmd
protected
PString PModem::noCarrierReply
protected
PString PModem::postDialCmd
protected
PString PModem::preDialCmd
protected
Status PModem::status
protected

The documentation for this class was generated from the following file: