在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)