这个你自己去看CnPack的源代码,那里有一个Modem控制模块,在CnPack->Source->NetComm->CnModem.pas,看看他的源代码,用起来会很方便
贴出其中回应发送信息的一段代码,呵呵,我没有侵权吧
// 等待一条AT命令执行结果
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;
// 发送一条AT命令,返回是否成功
function TCnModem.SendATOk(AT: string; Delay: Cardinal): Boolean;
var
i, j: Integer;
s: string;
begin
Result := False;
for i := 0 to 2 do
begin
WriteATCommand(AT);
for j := 0 to 2 do
begin
s := Trim(UpperCase(WaitATResult(Delay)));
if Pos('OK', s) > 0 then
begin
Result := True;
Exit;
end
else if Pos('ERROR', s) > 0 then
begin
InvalidCommand(AT);
Exit;
end;
end;
end;
end;
// 接收到数据
procedure TCnModem.ReceiveData(Buffer: PChar; BufferLength: WORD);
var
s: string;
begin
if FWaitATResult then // 正在等待AT命令执行结果
begin
FATResult := Buffer;
Exit;
end;
s := Buffer;
s := Trim(UpperCase(s));
if (ModemState in [msOffline, msOnlineCommand, msConnecting]) and (s = 'RING') then
Ring // 振铃信号
else if (ModemState = msOnline) and (s = 'NO CARRIER') then
DisConnect // 载波丢失
else
inherited;
end;