在RS232中有4个脚位可用来回应讯号给电脑分別为CTS,DSR,RING,RLSD当未接上设备时,脚位的电太皆为低电压,讯号传回OFF,很多设备都利用此四个脚位与电脑沟通,所以检查脚位电压就知道改COM上是否有设备存在
MS_CTS_ON,MS_DSR_ON,MS_RING_ON,MS_RLSD_ON
procedure TForm1.Button1Click(Sender: TObject);
var
cc:TCommConfig;
hComm:THandle;
Com:String;
lS:dword;
begin
Com:='COM2';
hComm:=CreateFile(Pchar(Com),Generic_read or Generic_write,0,nil,open_existing,0,0);
if GetCommModemStatus(hcomm,lS) then
begin
if(ls and MS_CTS_ON)=MS_CTS_ON then
begin
Button1.Caption:='CTSON'
end;
end;
closeHandle(hcomm);
end;
(作者 anykey)
end.
2.检查Handle所得到的值
procedure TForm1.Button1Click(Sender: TObject);
var
cc:TCommConfig;
hComm:THandle;
Com:String;
lS:dword;
begin
Com:='COM2';
hComm:=CreateFile(Pchar(Com),Generic_read or Generic_write,0,nil,open_existing,0,0);
if(hComm=invalid_Handle_value) then
begin
showmessage('通讯口错误);
end;
closeHandle(hcomm);
end;(作者 anykey)
本文地址:http://com.8s8s.com/it/it4317.htm