Listing Com Ports Systems in Delphi

Purpose: I would like to be able to list the available COM ports on the system in Delphi.

Homework: I read this SO stream when listing the LPT ports of a system using the registry. I also found that the COM ports are listed in the registry on HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM, but found unresponsive gestures in the same stream that it might not be so reliable on different machines and in different versions of windows.

I also found articles citing the use of QueryDosDevice (), but when I tried this sample code , I found that it did not appear in the list of any COM ports at all.

Question: What is the most reliable way (through unknown versions of Windows) to list COM ports on a Windows machine?

+1
source share
3 answers

DEVICEMAP \ SERIALCOMM is good for all versions of NT. You will probably have to search under DYN_DATA for Win9x.

Use this method if you need reliable execution.

+1
source

Go through a URL that is written in C ++

http://www.codeproject.com/KB/system/serial_portsenum_fifo.aspx

and the same approach can be implemented in delphi .. or someone can convert for you in SO ..

This will work for all versions of Windows, as it works on the principle of a device manager, which is available for all window versions.

+1

This code for LINUX is not for WINDOWS ....

function GetSerialPortNames: string;
var
  Index: Integer;
  Data: string;
  TmpPorts: String;
  sr : TSearchRec;
begin
  try
    TmpPorts := '';
    if FindFirst('/dev/ttyS*', $FFFFFFFF, sr) = 0 then
    begin
      repeat
        if (sr.Attr and $FFFFFFFF) = Sr.Attr then
        begin
          data := sr.Name;
          index := length(data);
          while (index > 1) and (data[index] <> '/') do
            index := index - 1;
          TmpPorts := TmpPorts + ' ' + copy(data, 1, index + 1);
        end;
      until FindNext(sr) <> 0;
    end;
    FindClose(sr);
  finally
    Result:=TmpPorts;
  end;
end;
0
source

All Articles