Cita:
Empezado por kurono
y realmente funciona porq lo probe pero me pregunto como modificar este codigo para dectectar los puerto serie y paralelo
|
Interesante ... si tiene que ser modificando ese código yo lo haría así:
Código:
var
H: THandle;
Numero: Char;
begin
for Numero:= '1' to '9' do
begin
H:= CreateFile(PChar('\\.\COM' + Numero),GENERIC_READ or GENERIC_WRITE,0,
nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if GetLastError <> ERROR_FILE_NOT_FOUND then
ShowMessage('Existe el puerto COM' + Numero);
if H <> INVALID_HANDLE_VALUE then
CloseHandle(H);
end;
end;
O con el puerto paralelo:
Código:
var
H: THandle;
Numero: Char;
begin
for Numero:= '1' to '9' do
begin
H:= CreateFile(PChar('\\.\LPT' + Numero),GENERIC_READ or GENERIC_WRITE,0,
nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if GetLastError <> ERROR_FILE_NOT_FOUND then
ShowMessage('Existe el puerto LPT' + Numero);
if H <> INVALID_HANDLE_VALUE then
CloseHandle(H);
end;
end;
Aunque si no hay que ceñirse a ese código yo utilizaría alguno de los métodos que describo aquí:
http://www.clubdelphi.com/foros/showthread.php?t=39961