怎么样才能获取计算机有那几个串口?
最好能给一段代码!!!

解决方案 »

  1.   

    uses
      Windows, Classes, SysUtils, Registry;
    {*************************************************************
    ** Name      : GetSysCom                                    **
    ** Object    : 得到系统的串口                               **
    ** Calls     : None                                         **
    ** Called By :                                              **
    ** Input     : 字符串列表变量                               **
    ** Output    : 字符串列表                                   **
    ** Return    : 成功返回True, 否则返回False                 **                       **
    *************************************************************}
    function GetSysCom(var ComList: Tstrings): boolean;
    var
        i: integer;
        Reg: TRegistry;
        RegStr: string;
        tmpList: TStrings;
    begin
        RegStr := '\HARDWARE\DEVICEMAP\SERIALCOMM';
        Reg := TRegistry.Create;
        Reg.RootKey := HKEY_LOCAL_MACHINE;
        if Reg.OpenKey(RegStr, False) then
        begin
            tmpList := TStringList.Create;
            Reg.GetValueNames(tmpList);
            for i := 0 to tmpList.Count - 1 do
            begin
                ComList.Add(Reg.ReadString(tmpList.Strings[i]));
            end;
            freeAndnil(tmpList);
        end;
        freeAndnil(Reg);
        if ComList.Count > 0 then
           result := true
        else
           result := false;
    end;
      

  2.   

    reg.RootKey := HKEY_LOCAL_MACHINE;
             reg.OpenKey ('hardware\devicemap\serialcomm',false);
             reg.GetValueNames(ts);
             //slList.Sorted := true;
             for i:=0 to ts.Count -1 do begin
                sName := LowerCase(Trim(ts.Strings[i]));
                sPort := UpperCase (Trim(reg.ReadString(sName)));
                subString := Copy(sPort,1,3); //.SubString(1,3);
                if ( subString = 'COM' ) then begin
                   sPort := Copy( sPort, 4, StrLen(PChar(sPort)) -3 );  //.SubString(4, sPort.Length() - 3);
                   ComboBox1.Items.Add(sPort);
                end else begin
                   continue;
           end;
             end;_____________________
    http://lysoft.7u7.net
      

  3.   

    WINDDK 上面串口一篇上面有说明