Forum > General
[SOLVED] USB connected device- How to access 'Bus Reported Device Description'
Thausand:
--- Quote from: Username on June 26, 2022, 03:26:53 am --- I'm not familiar with powershell at all so I passed on that one.
--- End quote ---
Powershell is for test alone :)
1) It standard windows so open powershell and type command. If see you device then utiliwmi can also make it see. Powershell command need translate to utilwmi.
2) page also show vba script and use two wmi exe command for show device, so translate for utilwmi more easy.
I think you description is found in second vba exe command.
The command list PNP id that is unique identify. If you know you device PNP id then you can may be recognize USB-device that you search ?
2 cent :)
--- Quote ---The VB code in the second link looks promising.
--- End quote ---
Yes, there description is read explicit and that what you look for can may be identify you device.
--- Quote ---I'm surprised that doing this is such a complex task.
--- End quote ---
All things windows is complex (for me it is) :D
Jurassic Pork:
Hello,
--- Quote from: Username on June 25, 2022, 10:25:18 pm ---I have a device connected to USB Port, I need to find it, ie, determine which com port it is connected to
I have searched and so far struck out on just how to do this. I downloaded Jurrasic Pork's Utilwmi and played with that a bit, example works fine but it looks like it is not straightforward or maybe impossible to get at this field with that.
--- End quote ---
with WMI you can try to use the class Win32_PnPEntity with a Filter on PnpClass with value Ports :
--- 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";}};} ---procedure TForm1.Button5Click(Sender: TObject);var WMIResult : TFPObjectList; i : Integer; PropNamesIndex : Integer; PropNames : Array[0..3] of String = ( 'Manufacturer','Caption','Name','Description'); PropName : String; PropValue : String;begin WMIResult := GetWMIInfo('Win32_PnPEntity', PropNames, 'Where PnpClass = ''Ports'' '); for i := 0 to Pred(WMIResult.Count) do begin Memo1.Append('================================================'); for PropNamesIndex := Low(PropNames) to High(PropNames) do begin PropName := TStringList(WMIResult[i]).Names[PropNamesIndex]; PropValue := TStringList(WMIResult[i]).ValueFromIndex[PropNamesIndex]; Memo1.Append(PropName + ' : ' + PropValue); end; end; // Clean up WMIResult.Free;
see Attachment fot Result on my computer Windows 10 Lazarus 2.0.12 and with two ports USB Serial Port connected .
if it doesn't work :
1 - Remove the filter to see all the pnp_entities
2 - Try another filter ex :
--- 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";}};} ---'Where Name LIKE ''%(COM%'' ');
Friendly, J.P
DonAlfredo:
Here is another one. A bit the same, a bit different.
--- 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";}};} ---procedure EnumerateCOMPorts(ComList: TStrings);const GUID_DEVINTERFACE_COMPORT:TGUID='{86E0D1E0-8089-11D0-9CE4-08003E301F73}';var cbRequired : DWORD; hdev : HDEVINFO; idev : Integer; did : TSPDeviceInterfaceData; pdidd : PSPDeviceInterfaceDetailData; s : string; PropertyBuffer : array[0..255] of Char; DeviceInfoData : TSPDevInfoData; PropertyRegDataType : DWORD; RequiredSize : DWORD; Key : HKEY; PortName : string; RegType,Count : DWORD;begin // enumerate the com ports LoadSetupApi; hdev := SetupDiGetClassDevs(@GUID_DEVINTERFACE_COMPORT, nil, 0, DIGCF_PRESENT OR DIGCF_DEVICEINTERFACE); if (INVALID_HANDLE_VALUE<> THandle(hdev)) then begin try idev:=0; ZeroMemory(@did, SizeOf(did)); did.cbSize := SizeOf(did); repeat if (SetupDiEnumDeviceInterfaces(hdev, nil, GUID_DEVINTERFACE_COMPORT, idev, did)) then begin cbRequired := 0; SetupDiGetDeviceInterfaceDetail(hdev, @did, nil, 0, cbRequired, nil); if (ERROR_INSUFFICIENT_BUFFER= GetLastError()) then begin pdidd:=AllocMem(cbRequired); try pdidd^.cbSize := SizeOf(TSPDeviceInterfaceDetailData); DeviceInfoData.cbSize:= SizeOf(DeviceInfoData); RequiredSize:=0; if (SetupDiGetDeviceInterfaceDetail(hdev, @did, pdidd, cbRequired, RequiredSize, @DeviceInfoData)) then begin PropertyRegDataType:=0; RequiredSize:=0; s:=''; { if SetupDiGetDeviceRegistryProperty(hdev, DeviceInfoData, SPDRP_FRIENDLYNAME, PropertyRegDataType, PBYTE(@PropertyBuffer[0]), SizeOf(PropertyBuffer), RequiredSize) then begin s:=s+PropertyBuffer; end; s:=s+DefaultFormatSettings.ListSeparator; if SetupDiGetDeviceRegistryProperty(hdev, DeviceInfoData, SPDRP_DEVICEDESC, PropertyRegDataType, PBYTE(@PropertyBuffer[0]), SizeOf(PropertyBuffer), RequiredSize) then begin s:=s+PropertyBuffer; end; s:=s+DefaultFormatSettings.ListSeparator; if SetupDiGetDeviceRegistryProperty(hdev, DeviceInfoData, SPDRP_MFG, PropertyRegDataType, PBYTE(@PropertyBuffer[0]), SizeOf(PropertyBuffer), RequiredSize) then begin s:=s+PropertyBuffer; end; s:=s+DefaultFormatSettings.ListSeparator; } Key := SetupDiOpenDevRegKey(hdev, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_QUERY_VALUE); if (Key<>0) then try SetLength({%H-}PortName, MAX_PATH); Count := Length(PortName); Windows.RegQueryValueEx(Key, 'PortName', nil, @RegType, PByte(PChar(PortName)), @Count); if (Count>0) AND (RegType=REG_SZ) then begin SetLength(PortName, Count - 1); s:=s+PortName; end; finally Windows.RegCloseKey(Key); end; s:=s+DefaultFormatSettings.ListSeparator; if Length(s)>0 then begin SetLength(s,Length(s)-1); ComList.Append(s); end; end else begin RaiseLastOSError; end; finally FreeMem(pdidd); end; end; end else begin break; end; inc(idev); until false; finally SetupDiDestroyDeviceInfoList(hdev); end; end; UnloadSetupApi;end;
bobby100:
https://sourceforge.net/projects/com-port-notifier/
with complete Lazarus/FPC source code
Username:
Wow! Thanks to everyone who so kindly replied to this post. There's a lot to look at up there! ;D
So nice to have such a helpful community here, and Lazarus is just absolutely incredible. Kudos to all who have dedicated so much work on it.
Again thanks Jamie, Thausand, JP, DonAlfredo, Bobby100. I will mark this solved when I have something that works for me!
Navigation
[0] Message Index
[#] Next page
[*] Previous page