Z
zshan_haina1
Unregistered / Unconfirmed
GUEST, unregistred user!
我想写一个向通信口发命令的拨号程序,请问以下的代码有问题吗?
注:端口已经打开,已经检测到信号CTS,DSR,但是无法检测到RLSD,RING的信号。
procedure TForm1.Button1Click(Sender: TObject);
var errorcode: integer;
PhoneNumber : string;
NumberWritten : DWord;
CommPort : string;
hCommFile : DWORD;
begin
{Open the comm port}
CommPort :='COM2';
hCommFile := CreateFile(pchar(CommPort),GENERIC_WRITE,0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if hCommFile=INVALID_HANDLE_VALUE then
begin
errorcode:=getlasterror();
ShowMessage('不能打开通信端口 '+INTTOSTR(HCOMMFILE));
CloseHandle(hCommFile);
exit;
end;
PhoneNumber := 'atdt 23120265' + #13 + #10;
NumberWritten:=0;
if WriteFile(hCommFile,PChar(PhoneNumber)^,Length(PhoneNumber),NumberWritten,nil) = false then
begin
ShowMessage('不能写端口 ' + CommPort);
end;
end;
注:端口已经打开,已经检测到信号CTS,DSR,但是无法检测到RLSD,RING的信号。
procedure TForm1.Button1Click(Sender: TObject);
var errorcode: integer;
PhoneNumber : string;
NumberWritten : DWord;
CommPort : string;
hCommFile : DWORD;
begin
{Open the comm port}
CommPort :='COM2';
hCommFile := CreateFile(pchar(CommPort),GENERIC_WRITE,0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if hCommFile=INVALID_HANDLE_VALUE then
begin
errorcode:=getlasterror();
ShowMessage('不能打开通信端口 '+INTTOSTR(HCOMMFILE));
CloseHandle(hCommFile);
exit;
end;
PhoneNumber := 'atdt 23120265' + #13 + #10;
NumberWritten:=0;
if WriteFile(hCommFile,PChar(PhoneNumber)^,Length(PhoneNumber),NumberWritten,nil) = false then
begin
ShowMessage('不能写端口 ' + CommPort);
end;
end;