⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admdm.pas

📁 Async Professional 4.04
💻 PAS
📖 第 1 页 / 共 4 页
字号:
  if FModemState in [msAutoAnswerBackground, msAutoAnswerWait, msAnswerWait] then begin
    CheckCallerID(Data);
    ResponsePacket.Enabled := True;
  end;

  { interpret the response based on what state we're in }
   case FModemState of
    msUnknown,
    msIdle,
    msConnected : { anything here means that the packet wasn't disabled }
      begin
        ResponsePacket.Enabled := False;
        WaitingForResponse := False;
      end;
    msInitializing : { anything here should be a OK or ERROR response }
      begin
        if CheckResponses(Data, ApxDefOKResponse, LmModem.Responses.OK) then begin
          { it's an OK }
          {$IFDEF AdModemDebug}
          FComPort.AddStringToLog('OKResponse');
          {$ENDIF}
          OKResponse := True;
          WaitingForResponse := False;
        end else
          if Pos(LastCommand, Data) > 0 then begin
            {$IFDEF AdModemDebug}
            FComPort.AddStringToLog('EchoResponse');
            {$ENDIF}
            ResponsePacket.Enabled := True;
          end {$IFDEF AdModemDebug} else
            FComPort.AddStringToLog('Unknown response');
            {$ENDIF}
      end;
    msAutoAnswerBackground :
      begin
        if CheckResponses(Data, ApxDefRingResponse, LmModem.Responses.Ring) then begin
          { it's the first RING }
          if not FCallerIDProvided and CallerIDInfo.HasData then begin
            DoCallerID;
          end;
          FRingCount := 1;  
          {$IFDEF AdModemDebug}
          FComPort.AddStringToLog('Ring' + IntToStr(FRingCount));
          {$ENDIF}
          DoStatus(msAutoAnswerWait);
          ResponsePacket.TimeOut := FRingWaitTimeout;
          ResponsePacket.EnableTimeOut := FRingWaitTimeout;              {!!.04} 
          ResponsePacket.Enabled := True;
        end;
      end;
    msAutoAnswerWait : { looking for more RINGs }
      begin
        if CheckResponses(Data, ApxDefRingResponse, LmModem.Responses.Ring) then begin
          { it's another RING }
          inc(FRingCount);
          if not FCallerIDProvided and CallerIDInfo.HasData then begin
            DoCallerID;
          end;
          { see if we need to answer it now }
          if FRingCount >= FAnswerOnRing then begin
            DoStatus(msAnswerWait);
            WaitingForResponse := False;
            { send the ATA }  
            {$IFDEF AdModemDebug}
            FComPort.AddStringToLog('AutoAnswer post');
            {$ENDIF}
            Postmessage(Handle, apw_AutoAnswer, 0, 0);
          end else begin
            { not enough rings }
            {$IFDEF AdModemDebug}
            FComPort.AddStringToLog('Ring' + IntToStr(FRingCount));
            {$ENDIF}
            DoStatus(msAutoAnswerWait);
            ResponsePacket.TimeOut := FRingWaitTimeout;
            ResponsePacket.EnableTimeOut := FRingWaitTimeout;            {!!.04}
            ResponsePacket.Enabled := True;
          end;
        end;
      end;

    msAnswerWait,
    msDial,
    msConnectWait : { waiting for connect or error }
      begin
        if CheckResponses(Data, ApxDefConnectResponse, LmModem.Responses.Connect) then begin
          { it's a CONNECT }
          ConnectResponse := True;
          OKResponse := True;
          WaitingForResponse := False;
          {$IFDEF AdModemDebug}
          FComPort.AddStringToLog('Connect response');
          {$ENDIF}
          if not FConnected then begin
            DoStatus(msConnected);
            DoConnect;
          end;
        end else
          ResponsePacket.Enabled := True;
      end;
    msHangup,
    msCancel : { starting hangup }
      begin
        WaitingForResponse :=False;
      end;
  end;
end;

procedure TAdCustomModem.ResponseTimeout(Sender: TObject);
begin
  { data packet timed out }
  TimedOut := True;
  if FModemState = msAutoAnswerWait then begin
    FRingCount := 0;
    DoStatus(msAutoAnswerBackground);
    ResponsePacket.Timeout := 0;
    ResponsePacket.Enabled := True;
  end;
end;

function TAdCustomModem.SelectDevice: Boolean;
  { display the modem selection dialog }
begin
  try
    {$IFDEF AdModemDebug}
    if Assigned(FComPort) then
      FComPort.AddStringToLog('Selecting');
    {$ENDIF}
    LibModem.LibModemPath := FModemCapFolder;
    Result := LibModem.SelectModem(
      FSelectedDevice.FModemFile,
      FSelectedDevice.FManufacturer,
      FSelectedDevice.FName, LmModem);
    {FDeviceSelected := Result;}                                         {!!.04}
    {$IFDEF AdModemDebug}
    if Result and Assigned(FComPort) then begin
       FComPort.AddStringToLog('Selected from ' + FSelectedDevice.FModemFile);
       FComPort.AddStringToLog('Selected manufacturer: ' + FSelectedDevice.FManufacturer);
       FComPort.AddStringToLog('Selected device: ' + FSelectedDevice.FName);
    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 := ApxDefCommandTimeout;
  ResponsePacket.Enabled := True;
  FComPort.Output := ConvertXML(Command);                                {!!.04}

  { wait for the response }
  NewTimer(ET, Secs2Ticks(ApxDefCommandTimeout));                        {!!.04}
  repeat
    {Application.HandleMessage;}                                         {!!.02}
    Res := SafeYield;                                                    {!!.04}
    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
  FComPort := Value;
end;

procedure TAdCustomModem.SetDevConfig(const Config: TApdModemConfig);
  { forces new configuration }
begin
  {$IFDEF AdModemDebug}
  if Assigned(FComPort) then
    FComPort.AddStringToLog('ConfigChange');
  {$ENDIF}
  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 }
  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}
        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 := LibModem.IsModemValid(FSelectedDevice.FModemFile,            {!!.04}
    FSelectedDevice.FName);                                              {!!.04}
end;                                                                     {!!.04}

{ 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 + -