Trax Posted March 26, 2015 Posted March 26, 2015 I have been using this function for years. I want to loop through all the ComPorts on a computer and return the ComPort of any port having VID 401 and PID 6003. This has worked forever but today I found a serious problem. I guess there is a "PortName" and a "FriendlyName" for each port. I have been incorrectly using the "FriendlyName" and need to start using the "PortName" because I guess there are certain instances where the "FriendlyName" doesn't really reflect the ""PortName". Here is the code. Can anyone tell me what I have to change to get the "PortName" and not the "FriendlyName"? ; Will scan all FTDI COMPorts in the WMI and return either the comport FTDI on or "" Func FindOBD() Local $NumericPort, $Leftprens, $Rightprens, $TestDevice Local $oWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2") If @error Then Return SetError(@error, 0, "") Local $oItems = $oWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%)'", "WQL", 48) $CommPort = "" For $oItem In $oItems $TestDevice = StringInStr($oItem.DeviceID, "FTDIBUS\VID_0403+PID_6001") If $TestDevice = 0 Then ContinueLoop EndIf $Leftprens = StringInStr($oItem.Name, "(") $Rightprens = StringInStr($oItem.Name, ")") $CommPort = StringMid($oItem.Name, $Leftprens + 1, $Rightprens - $Leftprens - 1) $NumericPort = Int(StringRight($CommPort, StringLen($CommPort) - 3)) If ($NumericPort > 9) Then $CommPort = "\\.\" & $CommPort EndIf Next Return $CommPort EndFunc
JohnOne Posted March 26, 2015 Posted March 26, 2015 Maybe this will help https://msdn.microsoft.com/en-us/library/aa394353%28v=vs.85%29.aspx uint16 Availability; string Caption; string ClassGuid; string CompatibleID[]; uint32 ConfigManagerErrorCode; boolean ConfigManagerUserConfig; string CreationClassName; string Description; string DeviceID; boolean ErrorCleared; string ErrorDescription; string HardwareID[]; datetime InstallDate; uint32 LastErrorCode; string Manufacturer; string Name; string PNPClass; string PNPDeviceID; uint16 PowerManagementCapabilities[]; boolean PowerManagementSupported; boolean Present; string Service; string Status; uint16 StatusInfo; string SystemCreationClassName; string SystemName; AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
jguinch Posted March 26, 2015 Posted March 26, 2015 Maybe you can try this : ConsoleWrite( FindOBD("FTDIBUS\VID_0403+PID_60011") ) Func FindOBD($sSearch) Local $aResult[1] Local $oWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") If NOT IsObj($oWMIService) Then Return SetError(1, 0, 0) Local $oPnPDevices = $oWMIService.ExecQuery("select * from Win32_PnPDevice") For $oDevice In $oPnPDevices If StringInStr($oDevice.SystemElement, 'DeviceID="' & $sSearch & '"') Then $sPort = StringRegExpReplace( $oDevice.SameElement, '.+"([^"]+)"', "$1") Return $sPort EndIf Next Return "" EndFunc Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Trax Posted March 27, 2015 Author Posted March 27, 2015 Thank you both. @JohnOne I found that field list shortly after posting the original question and did a console write on every field. The actual Comport Number just isn't there. Only the "FriendlyName". Granted the Port Number and FiriendlyName are usually one in the same but in this case it isn't. Maybe I should start a new question and ask how to find all comports with a given pid and vid but not using the WMI services?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now