Forum > Windows

serial port properties

(1/2) > >>

Rik:
Elsewhere in this forum (https://forum.lazarus.freepascal.org/index.php/topic,16616.msg90544.html#msg90544) I found a script that return the friendly name of a serial port via the Windows Registry.
The friendly name is retrieved using the TRegistry.ReadString('FriendlyName') function.
I would expect that it is possible to retrieve other serial port properties as wel via the ReadString function?
With properties I mean those that can be found via the Device Manager -> Ports (COM & LPT)-> Device -> Properties -> Details.
As a quick and dirty test I tried to get the Device description using TRegistry.ReadString('DeviceDescription'), but that failed.

Is it possible to retrieve other properties as wel via the ReadString function?
If so, where can I find a list of the strings to be used and the corresponding properties?
.

gues1:
All Hardware properties (where settings were maintained) are described in the key:

HKLM/System/CurrentControlSet/Enum

But more subkey are locked (you neede special auth to access them, admin is not enough).

You can access to these data and more via WMI interface, here one example: https://theroadtodelphi.com/category/wmi/

For serial port you can also open all of them and read directly the properties, but you will not know the limits (for example maximun baud rates supported).

Rik:

--- Quote ---All Hardware properties (where settings were maintained) are described in the key: HKLM/System/CurrentControlSet/Enum
--- End quote ---
Indeed, but I already tried that ...

--- Quote ---But more subkey are locked (you neede special auth to access them, admin is not enough)
--- End quote ---
.. and got stuck on an access denied error for the subkey Properties, even with admin privileges.


--- Quote ---You can access to these data and more via WMI interface
--- End quote ---
That's new stuff to me, I'll have a look at it.

Rik:
WMI is not needed for what I was looking for.
The funcion TRegistry.GetValueNames: TUnicodeStringArray returns the names of all available properties of the serial port.

CM630:
I use this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function GetComFriendlyName (PortName : string) : String;var  Registry : TRegistry;  PortType: String = '';  VID_PID: String = '';  ID: string = '';  Contents : array of String;  KeyName: String = '';begin  Result := '';  Registry := TRegistry.Create(KEY_READ);  try    Registry.RootKey := HKEY_LOCAL_MACHINE;    if Registry.OpenKey('\SYSTEM\ControlSet001\Control\COM Name Arbiter\Devices',False) then    begin      Contents := Registry.ReadString(PortName).Split(['#']);      if (Length(Contents) > 2) then      begin        PortType := copy(Contents[0],5,MaxInt) ;        VID_PID := Contents[1];        ID := Contents[2];        KeyName := '\SYSTEM\ControlSet001\Enum\' + PortType + '\' + VID_PID + '\' + ID;        if Registry.OpenKey(KeyName,False) then          Result := Registry.ReadString('FriendlyName');      end; //Length    end; //if Registry.OpenKey  finally    Registry.Free;  end; //tryend; procedure TForm1.FormCreate(Sender: TObject);begin  ShowMessage (GetComFriendlyName('COM51'));end;

I get the port names from GetSerialPortNames, which is a routine of the multiplatform TLazSerial.
How to get friendly names in Linux (if they exist) - I do not know.


Navigation

[0] Message Index

[#] Next page

Go to full version