Определить, доступен ли COM порт



Оформил: DeeCo

{ 
  This tip uses the API of Windows to determine 
  if a this available certain COM. 
  Port: COM1, COM2, COM3... 
}

 function ComPortAvailable(Port: PChar): Boolean;
 var
   DeviceName: array[0..80] of Char;
   ComFile: THandle;
 begin
   StrPCopy(DeviceName, Port);

   ComFile := CreateFile(DeviceName, GENERIC_READ or GENERIC_WRITE, 0, nil,
     OPEN_EXISTING,
     FILE_ATTRIBUTE_NORMAL, 0);

   Result := ComFile <> INVALID_HANDLE_VALUE;
   CloseHandle(ComFile);
 end;

 procedure TForm1.Button1Click(Sender: TObject);
 begin
   if ComPortAvailable('COM1:') then
     ShowMessage('Port available')
   else
     ShowMessage('Port not available');
 end;




Похожие по теме исходники

DBLookupComboBox in StringGrid

e-Bay Commerce

Fractal Compression

Easy Compress Jpg

 

Component TClock

Component ZSImage

Compare Algo Circles

SMTP Component

 

fwIoCompletionPipe

Экспорт баз данных в Excel

BComPort (com порт)