Jump to content

Looping through Com Ports


JonBMN
 Share

Recommended Posts

  • Moderators

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!

Link to comment
Share on other sites

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 by JonBMN
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...