Как определить, доступен ли COM порт?
function isComPortAvailable( 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 isComPortAvailable( 'COM1' ) then
ShowMessage( 'Порт доступен' )
else
ShowMessage( 'Порт недоступен' );
end;
|