首页  编辑  

串口列表

Tags: /超级猛料/Hardware.硬件相关/其它硬件/   Date Created:

系统里面有哪些串口?

get names of available comm ports?

{

 Show the names of available comm ports (com1, com2, ...)

 Used registry key: hkey_local_machine\hardware\devicemap\serialcomm

}

uses

 Registry;

procedure TForm1.Button1Click(Sender: TObject);

var

 reg: TRegistry;

 st: Tstrings;

 i: Integer;

begin

 reg := TRegistry.Create;

 try

   reg.RootKey := HKEY_LOCAL_MACHINE;

   reg.OpenKey('hardware\devicemap\serialcomm', False);

   st := TstringList.Create;

   try

     reg.GetValueNames(st);

     for i := 0 to st.Count - 1 do  

       Memo1.Lines.Add(reg.Readstring(st.strings[i]));

   finally

     st.Free;

   end;

   reg.CloseKey;

 finally

   reg.Free;

 end;

end;