function testModem(Modem:Integer):Integer; var CommPort:string; hCommFile:THandle; ModemStatword; begin Result := 1; CommPort := 'COM' + inttostr(Modem); hCommFile := createfile(PChar(CommPort), 0, //generic_read, 0, nil, open_existing, 0, 0); if hCommFile=INVALID_HANDLE_VALUE then exit; {Get the Modem Status} if GetCommModemStatus(hCommFile, ModemStat) <> false then begin if ModemStat and MS_CTS_ON <> 0 then begin // ShowMessage('The CTS (clear-to-send) is on.'); Result := 0; CloseHandle(hCommFile); exit; end; if ModemStat and MS_DSR_ON <> 0 then ShowMessage('The DSR (data-set-ready) is on.'); if ModemStat and MS_RING_ON <> 0 then ShowMessage('The ring indicator is on.'); if ModemStat and MS_RLSD_ON <> 0 then ShowMessage('The RLSD (receive-line-signal-detect) is on.'); end; end; for i := 1 to 5 do begin if TestModem(i) = 0 then begin Receive.Lines.Add('Modem在串口' + inttostr(i) + '上');http://topic.csdn.net/t/20050525/10/4033849.html