打印本文 打印本文 关闭窗口 关闭窗口
检查RS232(串口)是否接有设备
作者:武汉SEO闵涛  文章来源:敏韬网  点击数834  更新时间:2009/4/23 18:27:16  文章录入:mintao  责任编辑:mintao
在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)

打印本文 打印本文 关闭窗口 关闭窗口