📄 adsmodem.pas
字号:
(***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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 TurboPower Async Professional
*
* The Initial Developer of the Original Code is
* TurboPower Software
*
* Portions created by the Initial Developer are Copyright (C) 1991-2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** *)
{*********************************************************}
{* ADSMODEM.PAS 4.06 *}
{*********************************************************}
{* Deprecated TApdSModem component, simple modem control *}
{*********************************************************}
{Global defines potentially affecting this unit}
{$I AWDEFINE.INC}
{Options required for this unit}
{$G+,X+,F-,V-,P-,T-,B-,I+}
{$IFDEF WIN32}
{$H+}
{$ENDIF}
unit AdSModem;
{-Async Professional for Delphi -- Simplified Modem Component}
interface
uses
{-----RTL}
WinProcs,
WinTypes,
SysUtils,
Classes,
Messages,
Graphics,
Controls,
Forms,
Dialogs,
StdCtrls,
ExtCtrls,
{$IFDEF Win32}
Registry,
AwWin32,
{$ELSE}
AwComm,
{$ENDIF}
IniFiles,
OoMisc,
AwUser,
AdSelCom,
AdExcept,
AdPort,
AdSMdm1;
const
{ Constants for status messages in APW.STR }
smMsgBase = 4200;
smMsgReady = 4201;
smMsgInitialize = 4202;
smMsgInitializeTimeout = 4203;
smMsgAutoAnswerBackground = 4204;
smMsgAutoAnswerWait = 4205;
smMsgAnswerWait = 4206;
smMsgDialWait = 4207;
smMsgDialCycle = 4208;
smMsgNoDialtone = 4209;
smMsgConnectWait = 4210;
smMsgConnected = 4211;
smMsgHangup = 4212;
smMsgCancel = 4213;
adsmDefAnswerCmd = 'ATA^M';
adsmDefDialCmd = 'ATDT';
adsmDefDialCancelCmd = '^M';
adsmDefDialTerminatorCmd = '^M';
adsmDefHangupCmd = 'DTR';
adsmDefInitializeCmd = 'ATE1Q0X4V1^M';
adsmDefBusyMsg = 'BUSY';
adsmDefConnectMsg = 'CONNECT';
adsmDefDataCompressionMsg = '';
adsmDefErrorCorrectionMsg = '';
adsmDefErrorMsg = 'ERROR';
adsmDefNoCarrierMsg = 'NO CARRIER';
adsmDefNoDialToneMsg = 'NO DIALTONE';
adsmDefOkMsg = 'OK';
adsmDefRingMsg = 'RING';
adsmDefAnswerTimeout = 60; {seconds}
adsmDefCmdTimeout = 50; {ticks}
adsmDefConnectInfoTimeout = 9; {ticks}
adsmDefDialTimeout = 60; {seconds}
adsmDefRingWaitTimeout = 182; {ticks}
adsmDefDTRDropHoldDelay = 8; {ticks}
adsmDefInterCharDelay = 0; {ticks}
adsmDefInterCmdDelay = 2; {ticks}
adsmDefTildeDelay = 9; {ticks}
adsmDefModemIniName = 'AWMODEM.INI';
adsmDefaultModemTag = '<default modem>';
adsmDefExtendTime = 60; {seconds}
adsmDefRetryWaitTime = 60; {seconds}
adsmDefUpdateStatusTime = 1; {seconds}
adsmDefAutoRetryDial = True;
adsmDefForceHangup = False;
adsmDefMaxDialAttempts = 10;
adsmDefShowStatus = True;
const
{Special flags used outside of the state machine or for status info}
smsWaitForInProgress = $0001;
smsResponseReceived = $0002;
smsDataTransmitted = $0004;
smsBatchInProgress = $0008;
{Maximum size of connect message buffer}
MaxBufferSize = 4096;
type
{Simple modem machine states}
TApdSModemStates = (
smsUnknown, {hasn't been or couldn't be initialized}
smsReady, {idle and ready}
smsInitialize, {starting initialize process}
smsInitializeTimeout, {timeout waiting for initialize response}
smsAutoAnswerBackground, {autoanswer mode -- no rings received}
smsAutoAnswerWait, {autoanswer mode -- waiting for Nth ring}
smsAnswerWait, {answering call -- waiting for connect}
smsDialWait, {dialing call -- waiting for connect}
smsDialCycle, {time to retry a dial attempt (cycletime=0)}
smsNoDialTone, {no dialtone detected}
smsConnectWait, {connect in progress -- waiting for optional data}
smsConnected, {done with connect process}
smsHangup, {starting hangup process}
smsCancel, {starting cancel process}
smsAbort {cancel current operation}
);
{for internal use only -- subject to change}
TApdSModemStateData = record
TimeRemaining : Cardinal;
String1 : String;
String2 : String;
Cardinal1 : Cardinal;
Cardinal2 : Cardinal;
Byte1 : Byte;
Byte2 : Byte;
end;
TApdSModemStatusInfo = class(TApdBaseComponent)
protected {private}
msiModemState : TApdSModemStates;
msiModemStateData : TApdSModemStateData;
msiSendRecvData : TStringList;
msiSendRecvDataCopy : TStringList;
{These procedures are used by the modem component to set the status info}
procedure AddSendRecvData(Msg : String);
{Add the message to the Send/Receive string list}
procedure SetInfoAnswerWait(TimeRemaining : Cardinal);
{Set the specific parameters describing the Answer progress}
procedure SetInfoAutoAnswerWait(RingToAnswer : Byte;
RingsReceived : Byte);
{Set the specific parameters describing the AutoAnswer progress}
procedure SetInfoConnected(ErrorCorrection : String;
DataCompression : String;
ConnectSpeed : Cardinal);
{Set the specific parameters describing the Connection progress}
procedure SetInfoDialCycle(NextPhoneNumber : String;
NextAttemptNumber : Cardinal;
MaxAttempts : Cardinal;
TimeRemaining : Cardinal);
{Set the specific parameters describing the Dial Retry/Cycle progress}
procedure SetInfoDialWait(PhoneNumber : String;
AttemptNumber : Cardinal;
MaxAttempts : Cardinal;
TimeRemaining : Cardinal);
{Set the specific parameters describing the Dial progress}
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
function GetModemState : TApdSModemStates;
{Get the current state of the modem component (e.g., smsDialWait)}
function GetModemStateMsg : String;
{Get the description of the current modem state (e.g., 'Dialing')}
function GetSendRecvMessages : TStringList;
{Get a list of the available send/receive messages}
procedure GetInfoAnswerWait(var TimeRemaining : Cardinal);
{Get the specific status info when GetModemState = smsAnswerWait}
procedure GetInfoAutoAnswerWait(var RingToAnswer : Byte;
var RingsReceived : Byte);
{Get the specific status info when GetModemState = smsAutoAnswerWait}
procedure GetInfoConnected(var ErrorCorrection : String;
var DataCompression : String;
var ConnectSpeed : Cardinal);
{Get the specific status info when GetModemState = smsConnected}
procedure GetInfoDialCycle(var NextPhoneNumber : String;
var NextAttemptNumber : Cardinal;
var MaxAttempts : Cardinal;
var TimeRemaining : Cardinal);
{Get the specific status info when GetModemState = smsDialCycle}
procedure GetInfoDialWait(var PhoneNumber : String;
var AttemptNumber : Cardinal;
var MaxAttempts : Cardinal;
var TimeRemaining : Cardinal);
{Get the specific status info when GetModemState = smsDialWait}
end;
TApdSModemEvent = procedure(ModemInstance : TObject;
ModemStatus : TApdSModemStatusInfo) of object;
TApdSModemStatusDisplay = class;
TApdCustomSModem = class(TApdBaseComponent)
protected {private}
msModemStatusTrigger : Cardinal;
msUpdateStatusTrigger : Cardinal;
msTimeoutTrigger : Cardinal;
msForceUpdateStatus : Boolean;
msCRLFIndex : Byte;
msModemResponse : String;
msConnectResponses : String;
msRingReceiveCount : Byte;
msStatusVisible : Boolean;
FComPort : TApdCustomComPort;
FPhoneNumber : String;
FStarted : Boolean;
FAllowYielding : Boolean;
FAnswerCmd : String;
FDialCmd : String;
FDialCancelCmd : String;
FDialTerminatorCmd : String;
FHangupCmd : String;
FInitializeCmd : String;
FBusyMsg : String;
FConnectMsg : String;
FDataCompressionMsg : String;
FErrorCorrectionMsg : String;
FErrorMsg : String;
FNoCarrierMsg : String;
FNoDialToneMsg : String;
FOkMsg : String;
FRingMsg : String;
FAnswerTimeout : Cardinal;
FCmdTimeout : Cardinal;
FConnectInfoTimeout : Cardinal;
FDialTimeout : Cardinal;
FRingWaitTimeout : Cardinal;
FDTRDropHoldDelay : Cardinal;
FInterCharDelay : Cardinal;
FInterCmdDelay : Cardinal;
FTildeDelay : Cardinal;
FAnswerOnRing : Byte;
FAutoRetryDial : Boolean;
FConnectSpeed : Cardinal;
FDialAttempt : Cardinal;
FExtendTime : Cardinal;
FForceHangup : Boolean;
FLockDTE : Boolean;
FMaxDialAttempts : Cardinal;
FPreferredPortSpeed : Cardinal;
FRetryWaitTime : Cardinal;
FShowStatus : Boolean;
FStatusDisplay : TApdSModemStatusDisplay;
FStatusInfo : TApdSModemStatusInfo;
FUpdateStatusTime : Cardinal;
FModemState : TApdSModemStates;
FModemStateFlags : Cardinal;
FConnectionStatus : TApdSModemEvent;
procedure SimpleModemStateMachine(Msg, wParam : Cardinal;
lParam : Longint);
procedure DisplayWaitForResult(Responses : String; Index : Cardinal);
procedure HostPortClose(CP : TObject; Opening : Boolean);
function ParseMultiLineCommand(var Remainder : String) : String;
procedure SetAllDefaults; virtual;
procedure SetComPort(const NewPort : TApdCustomComPort);
procedure SetStarted(const StartIt : Boolean);
procedure VerifyStarted; virtual;
procedure RefreshModemStatus; virtual;
procedure SetModemState(ModemState : TApdSModemStates); virtual;
function msResponseMatches(StringToMatch : String) : Boolean;
function msResponseIsBusy : Boolean;
function msResponseIsConnect : Boolean;
function msResponseIsError : Boolean;
function msResponseIsNoCarrier : Boolean;
function msResponseIsNoDialTone : Boolean;
function msResponseIsOk : Boolean;
function msResponseIsRing : Boolean;
procedure msCheckForResponseTags;
procedure msPrepareForResponse(TimeoutTicks : Cardinal);
procedure msPrepareForCmdResponse;
procedure msPrepareForDialResponse;
procedure msPrepareForAnswerResponse;
procedure msPrepareForAutoAnswerResponse;
procedure msPrepareForConnectInfoResponse;
protected
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
procedure Notification(AComponent : TComponent;
Operation : TOperation); override;
property ComPort : TApdCustomComPort
read FComPort write SetComPort;
property PhoneNumber : String
read FPhoneNumber write FPhoneNumber;
property Started : Boolean
read FStarted write SetStarted;
property AllowYielding : Boolean
read FAllowYielding write FAllowYielding default False;
property AnswerCmd : String
read FAnswerCmd write FAnswerCmd;
property DialCmd : String
read FDialCmd write FDialCmd;
property DialCancelCmd : String
read FDialCancelCmd write FDialCancelCmd;
property DialTerminatorCmd : String
read FDialTerminatorCmd write FDialTerminatorCmd;
property HangupCmd : String
read FHangupCmd write FHangupCmd;
property InitializeCmd : String
read FInitializeCmd write FInitializeCmd;
property BusyMsg : String
read FBusyMsg write FBusyMsg;
property ConnectMsg : String
read FConnectMsg write FConnectMsg;
property DataCompressionMsg : String
read FDataCompressionMsg write FDataCompressionMsg;
property ErrorCorrectionMsg : String
read FErrorCorrectionMsg write FErrorCorrectionMsg;
property ErrorMsg : String
read FErrorMsg write FErrorMsg;
property NoCarrierMsg : String
read FNoCarrierMsg write FNoCarrierMsg;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -