📄 admdm.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 ***** *)
{*********************************************************}
{* ADMDM.PAS 4.06 *}
{*********************************************************}
{* TAdModem component *}
{*********************************************************}
{Global defines potentially affecting this unit}
{$I AWDEFINE.INC}
unit AdMdm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OOMisc, AdPort, AdPacket, AdLibMdm, AdExcept, FileCtrl;
const
ApxDefModemCapFolder = ''; {!!.04}
ApxDefModemStatusCaption = 'Modem status';
ApxDefOKResponse = 'OK'#13#10;
ApxDefErrorResponse = 'ERROR'#13#10;
ApxDefBusyResponse = 'BUSY'#13#10;
ApxDefConnectResponse = 'CONNECT';
ApxDefRingResponse = 'RING'#13#10;
ApxDefModemEscape = '+++';
ApxDefAnswerCommand = 'ATA'#13;
ApxDefHangupCmd = 'ATH0'#13;
ApxDefCommandTimeout = 30000; { 30 second timeout waiting for modem to respond }
ApxDefConnectTimeout = 60000; { 60 second timeout waiting for modems to negotiate }
ApxDefDTRTimeout = 1000; { 1 second timeout for the modem to hangup after dropping DTR }
ApxModemConfigVersion = '1.00';
type
{ predefine our class }
TAdCustomModem = class;
TAdAbstractModemStatus = class;
TApdModemState = (
msUnknown, { Hasn't been initialized }
msIdle, { Idle and ready }
msInitializing, { Starting initialization process }
msAutoAnswerBackground, { AutoAnswer, no rings received }
msAutoAnswerWait, { AutoAnswer, waiting for Nth ring }
msAnswerWait, { Answering call, waiting for connect }
msDial, { Sending Dial command }
msConnectWait, { Sent the Dial command, wait for connect }
msConnected, { Done with connection process }
msHangup, { Starting hangup process }
msCancel { Starting cancel process }
);
TApdModemLogCode = (
mlNone, { None, nothing to log }
mlDial, { Dialing }
mlAutoAnswer, { Initiated AutoAnswer }
mlAnswer, { Answering an incoming call }
mlConnect, { Connected }
mlCancel, { Call cancelled }
mlBusy, { Called number was busy }
mlConnectFail { Connection attempt failed }
);
{ used for the UpdateStatus method }
TApdModemStatusAction = (
msaStart, { first time status display (clears everything) }
msaClose, { last time, cleans up }
msaUpdate, { normal updating }
msaDetailReplace, { replaces last line of details }
msaClear { clears all details and adds DetailStr }
);
TApdModemSpeakerVolume = (svLow, svMed, svHigh);
TApdModemSpeakerMode = (smOff, smOn, smDial);
TApdModemFlowControl = (fcOff, fcHard, fcSoft);
TApdModemErrorControl = (ecOff, ecOn, ecForced, ecCellular);
TApdModemModulation = (smBell, smCCITT, smCCITT_V23);
TApdModemConfig = record
ConfigVersion : string[8]; { version tag to support future features }
{ port settings }
AttachedTo : string[20];
Manufacturer : string[100];
ModemName : string[100];
ModemModel : string[100];
DataBits : Word;
Parity : TParity;
StopBits : Word;
{ speaker options }
SpeakerVolume : TApdModemSpeakerVolume;
SpeakerMode : TApdModemSpeakerMode;
{ connection control }
FlowControl : TApdModemFlowControl;
ErrorControl : set of TApdModemErrorControl;
Compression : Boolean;
Modulation : TApdModemModulation;
ToneDial : Boolean;
BlindDial : Boolean;
CallSetupFailTimeout : Integer;
InactivityTimeout : Integer;
{ extra commands }
ExtraSettings : string[50];
Padding : Array[81..128] of Byte; { Expansion room }
end;
TApdModemNameProp = class(TPersistent)
private
FManufacturer: string;
FName: string;
FModemFile: string;
procedure SetManufacturer(const Value: string);
procedure SetName(const Value: string);
procedure SetModemFile(const Value: string);
public
procedure Assign(Source: TPersistent); override; {!!.02}
procedure Clear; {!!.02}
published
property Manufacturer : string
read FManufacturer write SetManufacturer;
property Name : string
read FName write SetName;
property ModemFile : string
read FModemFile write SetModemFile;
end;
TApdCallerIDInfo = record
HasData : Boolean;
Date : string;
Time : string;
Number : string;
Name : string;
Msg : string;
end;
{ event types }
TModemCallerIDEvent = procedure(Modem : TAdCustomModem;
CallerID : TApdCallerIDInfo) of object;
TModemNotifyEvent = procedure(Modem : TAdCustomModem) of object;
TModemFailEvent = procedure(Modem : TAdCustomModem; FailCode : Integer) of object;
TModemLogEvent = procedure(Modem : TAdCustomModem;
LogCode : TApdModemLogCode) of object;
TModemStatusEvent = procedure(Modem : TAdCustomModem;
ModemState : TApdModemState) of object;
TAdCustomModem = class(TApdBaseComponent)
private
FAnswerOnRing: Integer;
FBPSRate: DWORD;
FComPort: TApdCustomComPort;
FDialTimeout: Integer;
FFailCode: Integer;
FModemCapFolder: string;
FRingWaitTimeout: DWORD;
FRingCount: Integer;
FStatusDisplay: TAdAbstractModemStatus;
FSelectedDevice: TApdModemNameProp;
FModemState: TApdModemState;
FNegotiationResponses : TStringList;
FOnModemCallerID: TModemCallerIDEvent;
FOnModemLog: TModemLogEvent;
FOnModemDisconnect: TModemNotifyEvent;
FOnModemConnect: TModemNotifyEvent;
FOnModemFail: TModemFailEvent;
FOnModemStatus: TModemStatusEvent;
FConnected: Boolean;
FPhoneNumber: string;
FStartTime : DWORD;
FDeviceSelected: Boolean; {!!.04}{!!.05}
FModemConfig : TApdModemConfig;
FCallerIDInfo : TApdCallerIDInfo;
FHandle : THandle;
{ flag to indicate the state of the port, 0=not set, 1=closed, 2=open }
FPortWasOpen : byte; {!!.05}
FSavedOnTrigger : TTriggerEvent; {!!.06}
function GetElapsedTime : DWORD;
function GetNegotiationResponses: TStringList;
procedure SetAnswerOnRing(const Value: Integer);
procedure SetComPort(const Value: TApdCustomComPort);
procedure SetDialTimeout(const Value: Integer);
procedure SetModemCapFolder(const Value: string);
procedure SetRingWaitTimeout(const Value: DWORD);
procedure SetSelectedDevice(const Value: TApdModemNameProp);
procedure SetStatusDisplay(const Value: TAdAbstractModemStatus);
function GetDeviceSelected: Boolean; {!!.04}
procedure PortOpenCloseEx(CP: TObject; CallbackType: TApdCallbackType);{!!.05}
{- Extended event handler for the port open/close event}
protected
{ Protected declarations }
ResponsePacket : TApdDataPacket;
Initialized : Boolean;
PassthroughMode : Boolean;
WaitingForResponse : Boolean;
OKResponse : Boolean;
ErrorResponse : Boolean;
ConnectResponse : Boolean;
TimedOut : Boolean;
LastCommand : string;
DcdTrigger : Word;
StatusTimerTrigger : Word;
FCallerIDProvided : Boolean;
{ opens port and ensures we are ready }
procedure CheckReady;
{ generate the OnModemCallerID event }
procedure DoCallerID;
{ generate the OnModemConnect event }
procedure DoConnect;
{ generate the OnModemDisconnect event }
procedure DoDisconnect;
{ generate the OnModemFail event }
procedure DoFail(Failure : Integer);
{ generate the OnModemLog event }
procedure DoLog(LogCode: TApdModemLogCode);
{ generate the OnModemStatus event }
procedure DoStatus(NewModemState: TApdModemState);
{ initialize/configure the modem }
procedure Initialize;
{ do stuff when other components are added to the form }
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
{ the AxModem message handler }
procedure ModemMessage(var Message : TMessage);
{ add triggers to detect connection state }
procedure PrepForConnect(EnableTriggers : Boolean);
{ detect modem responses }
procedure ResponseStringPacket(Sender: TObject; Data: String);
{ detect timeouts }
procedure ResponseTimeout(Sender : TObject);
{ status trigger notification event }
{procedure TriggerEvent(CP: TObject; TriggerHandle: Word);} {!!.06}
procedure TriggerEvent(CP : TObject; Msg, TriggerHandle, Data: Word);{!!.06}
{ send all commands in the list }
function SendCommands(Commands : TList) : Boolean;
{ check the responses for the response }
function CheckResponses(const Response, DefResponse : string;
Responses : TList) : Boolean;
{ check the response for any errors }
function CheckErrors(const Response : string) : Integer;
{ check for the CallerID tags }
procedure CheckCallerID(const Response : string);
{ check <StandardConnect> response for extra info }
function ParseStandardConnect(const Response : string): Boolean; {!!.05}
public
{ Public declarations }
LmModem : TLmModem;
LibModem : TApdLibModem;
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
property AnswerOnRing : Integer
read FAnswerOnRing write SetAnswerOnRing
default 2;
property BPSRate : DWORD
read FBPSRate;
property CallerIDInfo : TApdCallerIDInfo
read FCallerIDInfo;
property ComPort : TApdCustomComPort
read FComPort write SetComPort;
property Connected : Boolean
read FConnected;
property DeviceSelected : Boolean
read GetDeviceSelected; {!!.04}
property DialTimeout : Integer
read FDialTimeout write SetDialTimeout
default 60;
property ElapsedTime : DWORD
read GetElapsedTime;
property FailureCode : Integer
read FFailCode;
property Handle : THandle
read FHandle;
property ModemCapFolder : string
read FModemCapFolder write SetModemCapFolder;
property ModemState : TApdModemState
read FModemState;
property NegotiationResponses : TStringList
read GetNegotiationResponses;
property PhoneNumber : string
read FPhoneNumber;
property RingCount : Integer
read FRingCount;
property RingWaitTimeout : DWORD
read FRingWaitTimeout write SetRingWaitTimeout
default 1200;
property SelectedDevice : TApdModemNameProp
read FSelectedDevice write SetSelectedDevice;
property StatusDisplay : TAdAbstractModemStatus
read FStatusDisplay write SetStatusDisplay;
procedure AutoAnswer;
procedure CancelCall;
procedure ConfigAndOpen;
function DefaultDeviceConfig : TApdModemConfig;
procedure Dial(const ANumber : string);
function FailureCodeMsg(const FailureCode : Integer) : string;
function GetDevConfig : TApdModemConfig;
function ModemLogToString(LogCode : TApdModemLogCode) : string;
function ModemStatusMsg(Status : TApdModemState) : string;
function SelectDevice : Boolean;
function SendCommand(const Command : string) : Boolean;
procedure SetDevConfig(const Config : TApdModemConfig);
function ShowConfigDialog : Boolean;
{ undocumented }
function ConvertXML(const S : string) : string;
function StripXML(const S : string) : string; {!!.04}
property OnModemCallerID : TModemCallerIDEvent
read FOnModemCallerID write FOnModemCallerID;
property OnModemConnect : TModemNotifyEvent
read FOnModemConnect write FOnModemConnect;
property OnModemDisconnect : TModemNotifyEvent
read FOnModemDisconnect write FOnModemDisconnect;
property OnModemFail : TModemFailEvent
read FOnModemFail write FOnModemFail;
property OnModemLog : TModemLogEvent
read FOnModemLog write FOnModemLog;
property OnModemStatus : TModemStatusEvent
read FOnModemStatus write FOnModemStatus;
end;
TAdModem = class(TAdCustomModem)
published
property AnswerOnRing;
property ComPort;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -