JonBMN Posted December 30, 2013 Posted December 30, 2013 So, I'm looking at ways to loop through the com ports. My question is, what would be the recommended way to loop through the com ports? Through the registry, and is there a certain loop for this? Through the WMI? Any help is greatly appreciated.
Moderators JLogan3o13 Posted December 30, 2013 Moderators Posted December 30, 2013 I would start with WMI, personally. WIN32_SerialPort should allow you to enumerate them (doesn't catch virtual ports IIRC). Something like this: $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $WMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") $aPorts = $WMI.ExecQuery("SELECT * FROM Win32_SerialPort", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($aPorts) then For $Port In $aPorts MsgBox(0, $Port.Caption, $Port.Name) Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_SerialPort" ) Endif "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
JonBMN Posted December 30, 2013 Author Posted December 30, 2013 (edited) Thank you for the suggestion and the example script. WMI seems to be the best bet for this. Now, what I'm trying to do with this is loop through the ports, find a specific VID & PID, but I have hit a snag. If i have two cables plugged into the computer using the same VID & PID, this creates a problem. So, I wanted to know if going through the com ports and sending a command of ATI and then parsing the results would be a good idea? The loop I have checking this would need to run almost constantly. Would this create problems running all the time? Would this even be a good solution for a computer that would have 10-15 ports initialized? It seems like that would create problems with the volume it is looping through. Can some light be shed on this? Edited December 30, 2013 by JonBMN
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