检查RS232(串口)是否接有设备

时间:2010-01-29 08:56:01  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:table bordercolor="#d0a070" cellspacing="0" bordercolordark="#ffffff" cellpadding="5" width="99%" bgcolor="#ffffc0" border="1">procedure TForm1.Button1Click(Sender: TObject);varcc:TCommConfig;hComm:THandle;Com:String;lS:dword;begin  Com:='COM2';  hComm:=CreateFile(...
  正文:在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;
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;

检查RS232(串口)是否接有设备》由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/12572.html


关键字:

关于《检查RS232(串口)是否接有设备》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td