PTLib
Version 2.12.9
|
A class representing a modem attached to a serial port. More...
#include <modem.h>
Public Types | |
enum | Status { Unopened, Uninitialised, Initialising, Initialised, InitialiseFailed, Dialling, DialFailed, AwaitingResponse, LineBusy, NoCarrier, Connected, HangingUp, HangUpFailed, Deinitialising, DeinitialiseFailed, SendingUserCommand, NumStatuses } |
![]() | |
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... | |
![]() | |
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... | |
![]() | |
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 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... | |
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... | |
![]() | |
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 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 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 PObject * | PTraceObjectInstance () 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 PStringList | GetPortNames () |
Get a list of the available serial ports. More... | |
![]() | |
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 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 PObject * | PTraceObjectInstance (const char *) |
static __inline const PObject * | PTraceObjectInstance (const PObject *obj) |
![]() | |
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) |
PBoolean | PXSetIOBlock (PXBlockType type, const PTimeInterval &timeout) |
P_INT_PTR | GetOSHandleAsInt () const |
int | PXClose () |
PChannel () | |
Create the channel. More... | |
![]() |
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
enum PModem::Status |
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 |
||
) |
port | Serial port name to open. |
speed | Speed of serial port. |
data | Number of data bits for serial port. |
parity | Parity for serial port. |
stop | Number of stop bits for serial port. |
inputFlow | Input flow control. |
outputFlow | Output 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.
cfg | Configuration file to read parameters from. |
void PModem::Abort | ( | ) |
PBoolean PModem::CanDeinitialise | ( | ) | const |
The modem is in a state that allows the de-initialise to start.
PBoolean PModem::CanDial | ( | ) | const |
The modem is in a state that allows the dial to start.
PBoolean PModem::CanHangUp | ( | ) | const |
The modem is in a state that allows the hang up to start.
PBoolean PModem::CanInitialise | ( | ) | const |
The modem is in a state that allows the initialise to start.
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.
PBoolean PModem::CanSendUser | ( | ) | const |
The modem is in a state that allows the user command to start.
|
virtual |
Close the channel, shutting down the link to the data source.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Status PModem::GetStatus | ( | ) | const |
Get the modem objects current state.
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.
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.
|
virtual |
Open the modem serial channel on the specified port.
See the PSerialChannel class for more information on the parameters.
port | Serial port name to open. |
speed | Speed of serial port. |
data | Number of data bits for serial port. |
parity | Parity for serial port. |
stop | Number of stop bits for serial port. |
inputFlow | Input flow control. |
outputFlow | Output flow control. |
Reimplemented from PSerialChannel.
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.
cfg | Configuration file to read parameters from. |
Reimplemented from PSerialChannel.
|
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 write parameters to. |
Reimplemented from PSerialChannel.
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.
str | User 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.
str | New 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.
str | New 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.
str | New 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.
str | New 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.
str | New 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.
str | New 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.
str | New 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.
str | New pre-dial command string. |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |