Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

com port

Status
Not open for further replies.

tzzdvd

Programmer
Aug 17, 2001
52
0
0
IT
Is it possible to know by any API which com port are available on the computer and which number they are?

Thanks
Davide
 
you can use registry to find this information.
you can look on borland web site there is tutorial for your problem:

the borland delphi code looks like this:
Example:

uses Registry;

procedure TForm1.Button1Click(Sender: TObject);
var
reg : TRegistry;
ts : TStrings;
i : integer;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.OpenKey('hardware\devicemap\serialcomm',
false);
ts := TStringList.Create;
reg.GetValueNames(ts);
for i := 0 to ts.Count -1 do begin
Memo1.Lines.Add(reg.ReadString(ts.Strings));
end;
ts.Free;
reg.CloseKey;
reg.free;
end;

but its easy to program this in any language just use this registry nodes and 'rip' com-ports information...

Good luck
Slobo
 
Hi,

I've taken this code from a VB App that I'm writing.

Code:
Public Function EnumCommPorts(Port As Integer) As Boolean
    Dim comCfg As COMMCONFIG, comSize As Long
    comSize = LenB(comCfg)
    EnumCommPorts = IIf(GetDefaultCommConfig(("COM" & Trim(Str(Port)) & vbNullChar), comCfg, comSize), True, False)
End Function

All you need to is create a loop and pass it an integer starting at 1 going (if needed) to 16. If it returns true then the port is present on the system. Sorted.

You'll need to tweak it to suit, but it does work.

HTH


William
Software Engineer
ICQ No. 56047340
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top