PTLib  Version 2.10.4
PModem Class Reference

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

#include <modem.h>

Inheritance diagram for PModem:
PSerialChannel PChannel PObject

List of all members.

Public Types

enum  Status {
  Unopened, Uninitialised, Initialising, Initialised,
  InitialiseFailed, Dialling, DialFailed, AwaitingResponse,
  LineBusy, NoCarrier, Connected, HangingUp,
  HangUpFailed, Deinitialising, DeinitialiseFailed, SendingUserCommand,
  NumStatuses
}

Public Member Functions

 PModem ()
 Create a modem object on the serial port specified.
 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.
virtual PBoolean Close ()
 Close the channel, shutting down the link to the data source.
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.
virtual PBoolean Open (PConfig &cfg)
 Open the modem serial port obtaining the parameters from standard variables in the configuration file.
virtual void SaveSettings (PConfig &cfg)
 Save the current port settings into the configuration file.
void SetInitString (const PString &str)
 Set the modem initialisation meta-command string.
PString GetInitString () const
 Get the modem initialisation meta-command string.
PBoolean CanInitialise () const
 The modem is in a state that allows the initialise to start.
PBoolean Initialise ()
 Send the initialisation meta-command string to the modem.
void SetDeinitString (const PString &str)
 Set the modem de-initialisation meta-command string.
PString GetDeinitString () const
 Get the modem de-initialisation meta-command string.
PBoolean CanDeinitialise () const
 The modem is in a state that allows the de-initialise to start.
PBoolean Deinitialise ()
 Send the de-initialisation meta-command string to the modem.
void SetPreDialString (const PString &str)
 Set the modem pre-dial meta-command string.
PString GetPreDialString () const
 Get the modem pre-dial meta-command string.
void SetPostDialString (const PString &str)
 Set the modem post-dial meta-command string.
PString GetPostDialString () const
 Get the modem post-dial meta-command string.
void SetBusyString (const PString &str)
 Set the modem busy response meta-command string.
PString GetBusyString () const
 Get the modem busy response meta-command string.
void SetNoCarrierString (const PString &str)
 Set the modem no carrier response meta-command string.
PString GetNoCarrierString () const
 Get the modem no carrier response meta-command string.
void SetConnectString (const PString &str)
 Set the modem connect response meta-command string.
PString GetConnectString () const
 Get the modem connect response meta-command string.
PBoolean CanDial () const
 The modem is in a state that allows the dial to start.
PBoolean Dial (const PString &number)
 Send the dial meta-command strings to the modem.
void SetHangUpString (const PString &str)
 Set the modem hang up meta-command string.
PString GetHangUpString () const
 Get the modem hang up meta-command string.
PBoolean CanHangUp () const
 The modem is in a state that allows the hang up to start.
PBoolean HangUp ()
 Send the hang up meta-command string to the modem.
PBoolean CanSendUser () const
 The modem is in a state that allows the user command to start.
PBoolean SendUser (const PString &str)
 Send an arbitrary user meta-command string to the modem.
void Abort ()
PBoolean CanRead () const
 The modem is in a state that allows the user application to read from the channel.
Status GetStatus () const
 Get the modem objects current state.

Protected Attributes

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

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

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 ( )

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

Returns:
true if the Deinitialise() function may proceeed.

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

Returns:
true if the Dial() function may proceeed.

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

Returns:
true if the HangUp() function may proceeed.

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

Returns:
true if the Initialise() function may proceeed.

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".

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Get the modem objects current state.

Returns:
modem status.

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.

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::initCmd [protected]
Status PModem::status [protected]

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