Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Yes, using the code from AnonMonk...

You have to ask Win32 what the names of the COM ports are or probe up to a certain COMxx number.

There are USB ports that can show up as COM ports and I don't know how to create a complete list. I think its hard to do because a new COM port can just "show up" dynamically (i.e. when you plug in a new USB device).

This may not be right, but this is what it does on my machine.

#!/usr/bin/perl -w use strict; use Data::Dumper; use Win32::SerialPort; use Win32::OLE('in'); use constant wbemFlagReturnImmediately => 0x10; use constant wbemFlagForwardOnly => 0x20; my $computer = "."; my $objWMIService = Win32::OLE->GetObject ("winmgmts:\\\\$computer\\root\\CIMV2") or die "WMI connection failed.\n"; my $colItems = $objWMIService->ExecQuery ("SELECT * FROM Win32_SerialPortConfiguration", "WQL",wbemFlagReturnImmediately | wbemFlagForwardOnly); foreach my $objItem (in $colItems) { print "Caption: $objItem->{Caption}\n"; print "Name: $objItem->{Name}\n"; } __END__ prints: Caption: COM1 Name: COM1
I think perhaps another possibility is to "probe COM ports". Use a block "eval" on the "open_uart($_);" statement. >br> Run through the first 32 ports. If a port works works then $_ is a valid COM port and push it onto some stack.

my @valid_com_ports; foreach my $com ( map{"COM$_"}1..32) { # decide if this $com is ok or not.. # perhaps use the open_uart function() # and then push @valid_com_ports, $com; }

In reply to Re^3: finding a serial port with Win32::SerialPort by Marshall
in thread finding a serial port with Win32::SerialPort by pashanoid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found