Board logo

Subject: CnModem错误报告 [Print This Page]

Author: zj_yqj    Time: 2009-3-28 10:08     Subject: CnModem错误报告

procedure TCnModem.Escape;
var
  Tick: Integer;
begin
  if CommOpened and (ModemState = msOnline) then
  begin
    Tick := Round(FWaitEscapeTime * 0.02 * 1.3);
    Sleep(Tick);
    WriteATCommand('+++', False);
    Sleep(Tick);
    ModemState := msOnlineCommand;
  end;
end;

这里的0.02应该为20.因为下面的Sleep中的单位是毫秒。
Author: zj_yqj    Time: 2009-3-28 12:10

function TCnModem.WaitATResult(Delay: Cardinal): string;
var
  Tick: Cardinal;
begin
  FWaitATResult := True;
  try
    FATResult := '';
    Tick := GetTickCount;
    while (GetTickCount - Tick < Delay) and (FATResult = '') do
      Application.ProcessMessages;
    Result := FATResult;
    FATResult := '';
  finally
    FWaitATResult := False;
  end;
end;

Application.ProcessMessages;
后面要加一行
Sleep(1);
否则等待时CPU打满了了
Author: zjy    Time: 2009-3-28 19:42     Subject: 感谢报告!

0.02 的问题估计是当初疏忽,刚才看到 SkyJacker 写的 Demo 里也提到了这个疑问,已改为 20。
ProcessMessages 修改为 HandleMessage,后者会调用 Idle,比 Sleep 更规范。

已提交 CVS,有空请验证。




Welcome to CnPack Forum (http://bbs.cnpack.org/) Powered by Discuz! 5.0.0