📄 admdm.pas
字号:
end;
{$ENDIF}
finally
{ eat the exeption here }
end;
end;
function TAdCustomModem.SendCommand(const Command: string): Boolean;
{ send a command to the modem, returns when the response is received }
{ or on a timeout }
var
ET : EventTimer; {!!.04}
Res : Word; {!!.04}
begin
if WaitingForResponse then begin
Result := False;
DoFail(ecModemBusy);
Exit;
end;
CheckReady;
LastCommand := StripXML(Command); {!!.04}
Result := True;
WaitingForResponse := True;
OKResponse := False;
ErrorResponse := False;
ConnectResponse := False;
TimedOut := False;
ResponsePacket.Timeout := 0;{ApxDefCommandTimeout;} {!!.05}
ResponsePacket.Enabled := True;
if Command = '<DTR>' then {!!.05}
FComPort.DTR := False {!!.05}
else {!!.05}
FComPort.Output := ConvertXML(Command); {!!.04}
{ wait for the response }
if ModemState = msHangup then {!!.05}
{ if we're hanging up, only wait 6 seconds for the response }
NewTimer(ET, Secs2Ticks(6)) {!!.05}
else {!!.05}
NewTimer(ET, Secs2Ticks(30)); {!!.05}
repeat
{Application.HandleMessage;} {!!.02}
//Res := SafeYield; {!!.04} {!!.05}
Res := DelayTicks(2,True); {!!.05}
if (csDestroying in ComponentState) or (Res = WM_QUIT) then Exit; {!!.04}
TimedOut := TimerExpired(ET); {!!.04}
until not(WaitingForResponse) or TimedOut; {!!.04}
ResponsePacket.Enabled := False;
if TimedOut or TimerExpired(ET) then {!!.04}
DoFail(ecModemNotResponding)
else if ErrorResponse then
DoFail(ecModemRejectedCommand);
Result := not(TimedOut) and not(ErrorResponse);
WaitingForResponse := False; {!!.04}
end;
function TAdCustomModem.SendCommands(Commands: TList) : Boolean;
{ internal method to send all commands in the TLmCommands list }
var
I : Integer;
begin
Result := False;
if Commands.Count > 0 then begin
for I := 0 to pred(Commands.Count) do begin
Result := SendCommand(ConvertXML(PLmModemCommand(Commands[I]).Command));
if not Result then
Break;
end;
end else
{ return False if no commands were available }
Result := False;
end;
procedure TAdCustomModem.SetAnswerOnRing(const Value: Integer);
{ write access method for AnswerOnRing property }
begin
FAnswerOnRing := Value;
end;
procedure TAdCustomModem.SetComPort(const Value: TApdCustomComPort);
{ write access method for ComPort property }
begin
if FComPort <> Value then begin {!!.05}
if FComPort <> nil then {!!.05}
{ deregister our callback with the old port }
FComPort.DeregisterUserCallbackEx(PortOpenCloseEx); {!!.05}
FComPort := Value; {!!.05}
if FComPort <> nil then {!!.05}
{ register our callback with the new port }
FComPort.RegisterUserCallbackEx(PortOpenCloseEx); {!!.05}
end; {!!.05}
end;
procedure TAdCustomModem.SetDevConfig(const Config: TApdModemConfig);
{ forces new configuration }
begin
{$IFDEF AdModemDebug}
if Assigned(FComPort) then
FComPort.AddStringToLog('ConfigChange');
{$ENDIF}
if CompareMem(@FModemConfig, @Config, SizeOf(TApdModemConfig)) then {!!.06}
Initialized := False; {!!.06}
FModemConfig := Config;
end;
procedure TAdCustomModem.SetDialTimeout(const Value: Integer);
{ write access method for DialTimeout property }
begin
FDialTimeout := Value;
end;
procedure TAdCustomModem.SetModemCapFolder(const Value: string);
{ write access method for ModemCapFolder property }
begin
FModemCapFolder := Value;
LibModem.LibModemPath := ModemCapFolder; {!!.02}
end;
procedure TAdCustomModem.SetRingWaitTimeout(const Value: DWORD);
{ write access method for RingWaitTimeout property }
begin
FRingWaitTimeout := Value;
end;
procedure TAdCustomModem.SetSelectedDevice( {!!.02}
const Value: TApdModemNameProp);
{ write access method for SelectedDevice property }
var
Res : Integer;
begin
{ try to select a specific modem from a specific detail file }
FDeviceSelected := False; {!!.05}
if (Value.ModemFile <> '') and (Value.Name <> '') then begin
Res := LibModem.GetModem(Value.ModemFile, Value.Name, LmModem);
case Res of
ecOK : { we found the modem, accept the value }
begin
FSelectedDevice.Assign(Value);
FDeviceSelected := True; {!!.04}{!!.05}
end;
{ these are error conditions, can't raise an exception at design-time }
{ so we'll just ignore the .set }
ecFileNotFound : { couldn't find the ModemFile }
begin
if not(csDesigning in ComponentState) then
raise EInOutError.CreateFmt('Modem file not found(%s)',
[Value.ModemFile]);
end;
ecModemNotFound : { couldn't find the modem in ModemFile }
begin
if not(csDesigning in ComponentState) then
raise EModem.Create(ecModemNotFound, False);
end;
end;
end;
{$IFDEF AdMdmDebug}
if Assigned(FComPort) then {!!.01}
FComPort.AddStringToLog('.SetSelectedDevice');
{$ENDIF}
end;
procedure TAdCustomModem.SetStatusDisplay(
const Value: TAdAbstractModemStatus);
{ write access method for StatusDisplay property }
begin
FStatusDisplay := Value;
end;
function TAdCustomModem.StripXML(const S: string): string; {!!.04}
{ strip the XML tags out of the string }
var
Psn : Integer;
begin
Result := S;
while Pos('<CR>', AnsiUpperCase(Result)) > 0 do begin
Psn := Pos('<CR>', AnsiUpperCase(Result));
Delete(Result, Psn, Length('<CR>'));
end;
while Pos('<LF>', AnsiUpperCase(Result)) > 0 do begin
Psn := Pos('<LF>', AnsiUpperCase(Result));
Delete(Result, Psn, Length('<LF>'));
end;
{ XML also doubles any '%' char, strip that }
while Pos('%%', Result) > 0 do
Delete(Result, Pos('%%', Result), 1);
end;
function TAdCustomModem.GetDeviceSelected: Boolean; {!!.04}
begin {!!.04}
Result := FDeviceSelected; {!!.05}
{Result := LibModem.IsModemValid(FSelectedDevice.FModemFile,} {!!.04}{!!.05}
{FSelectedDevice.FName);} {!!.04}{!!.05}
end; {!!.04}{!!.05}
procedure TAdCustomModem.PortOpenCloseEx(CP: TObject; {!!.05}
CallbackType: TApdCallbackType); {!!.05}
{- Extended event handler for the port open/close event}
begin {!!.05}
if (CallbackType in [ctClosing, ctClosed]) and FConnected then {!!.05}
DoDisconnect; {!!.05}
end; {!!.05}
function TAdCustomModem.ParseStandardConnect(const Response: string) : Boolean;{!!.05}
var
Position : Integer;
Len : Integer;
SavedPosition : Integer;
S : string;
procedure SkipWhitespace;
begin
while (Position <= Len) and (Response[Position] = ' ') do
Inc (Position);
while (Position <= Len) and
((Copy (Response, Position, 4) = '<cr>') or
(Copy (Response, Position, 4) = '<lf>')) do
inc(Position, 4);
while (Position <= Len) and (Response[Position] = ' ') do
inc(Position);
end;
begin
// A standard Connect response is in the form of
// (<cr>|<lf>)*[[:space:]]*CONNECT[[:space:]]*[[:digit:]]*(/tag)*(<cr>)*
// a custom regex parser is used below
Result := False;
Position := 1;
Len := Length (Response);
SkipWhitespace;
// Look for the all important CONNECT keyword.
if Copy (Response, Position, 7) <> 'CONNECT' then
Exit;
// Assume now that this WILL be a Connection
Result := True;
Position := Position + 7;
SkipWhitespace;
// extract the baud rate
SavedPosition := Position;
while (Position <= Len) and (Response[Position] in ['0'..'9']) do
Inc (Position);
if SavedPosition <> Position then begin
S := Copy (Response, SavedPosition, Position - SavedPosition);
FBPSRate := StrToIntDef(S, FBPSRate);
end;
end;
{ TAdAbstractModemStatus }
constructor TAdAbstractModemStatus.Create(AOwner: TComponent);
begin
inherited;
Caption := ApxDefModemStatusCaption;
FStarted := False;
FModem := nil;
FStatusDialog := nil;
end;
destructor TAdAbstractModemStatus.Destroy;
begin
FStatusDialog.Free;
inherited;
end;
procedure TAdAbstractModemStatus.SetCaption(const Value: string);
begin
if FCaption <> Value then begin
FCaption := Value;
if Assigned(FStatusDialog) then
FStatusDialog.Caption := Value;
end;
end;
procedure TAdAbstractModemStatus.SetModem(const Value: TAdCustomModem);
begin
FModem := Value;
if FStarted then begin
SetStarted(False);
SetStarted(True);
end;
end;
procedure TAdAbstractModemStatus.SetStarted(Start: Boolean);
begin
if Start = FStarted then exit;
if Start then begin
FStatusDialog := TApdModemStatusDialog.Create(self);
FStatusDialog.Caption := Caption;
TApdModemStatusDialog(FStatusDialog).Modem := FModem;
TApdModemStatusDialog(FStatusDialog).UpdateDisplay('', '', '', msaStart);{!!.04}
{FStatusDialog.Show;} {!!.04}
end else begin
FStatusDialog.Free;
FStatusDialog := nil;
end;
FStarted := Start;
end;
procedure TAdAbstractModemStatus.UpdateDisplay(Modem: TAdCustomModem;
const StatusStr, TimeStr, DetailStr : string;
Action : TApdModemStatusAction);
begin
if Action = msaClose then begin
SetStarted(False);
Exit;
end;
if (not Started) then
{ create the dialog }
SetStarted(True);
TApdModemStatusDialog(FStatusDialog).UpdateDisplay(
StatusStr, { the status line }
TimeStr, { the 'Elapsed time' line }
DetailStr, { detail list }
Action); { how we're going to display it }
if FModem.FModemState in [msUnknown, msIdle, msConnected] then
SetStarted(False);
end;
function TAdCustomModem.ShowConfigDialog : Boolean;
var
MdmCfgDlg : TApdModemConfigDialog;
begin
MdmCfgDlg := nil;
try
MdmCfgDlg := TApdModemConfigDialog.Create(nil);
MdmCfgDlg.LmModem := LmModem;
if FModemConfig.AttachedTo = '' then
FModemConfig.AttachedTo := FComPort.Dispatcher.DeviceName;
MdmCfgDlg.ModemConfig := GetDevConfig; {!!.02}
Result := MdmCfgDlg.ShowModal = mrOK;
if Result then begin
FModemConfig := MdmCfgDlg.ModemConfig;
end;
finally
MdmCfgDlg.Free;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -