Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

open com port list

by perly_newbie (Novice)
on Feb 05, 2010 at 16:07 UTC ( #821593=perlquestion: print w/ replies, xml ) Need Help??
perly_newbie has asked for the wisdom of the Perl Monks concerning the following question:

Hi can any one please let me know how to get a list of all open com ports? I mean I go to the My Computer>Properties>Harware>device manager>ports to find the open com ports. And use one of them for communication to my device. Is there a way to automatically get the list of all open com ports? If so Please let me know. Thanks.

Comment on open com port list
Re: open com port list
by zentara (Archbishop) on Feb 05, 2010 at 17:15 UTC
    See serial port control on Windows for starters

    A crude way of getting an available port is to just sequentially attempt to open them until you get one that succeeds. Start at 0 and count up to 9 ( I do recall there are some tricks to win32 com ports over 9, but I doubt you have more than 9 going :-)


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku
Re: open com port list
by BrowserUk (Pope) on Feb 05, 2010 at 17:31 UTC

    You could try:

    #! perl -slw use strict; use Data::Dumper; use DBI; my $dbh = DBI->connect('dbi:WMI:'); my $sth = $dbh->prepare(<<WQL); SELECT * FROM Win32_SerialPort WQL $sth->execute(); while (my( $serial ) = $sth->fetchrow) { print Dumper $serial; }

    I can't confirm if it works, because I just discovered that this machine doesn't have any serial ports!

    I guess if I ever need one, I'd have to buy a USB-serial adapter.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: open com port list
by rpnoble419 (Pilgrim) on Feb 06, 2010 at 02:17 UTC
    You might want to try this:
    #! perl -slw use strict; use Win32::TieRegistry 0.20; # open registry node my $key= new Win32::TieRegistry "LMachine\\Hardware\\DEVICEMAP\\SERIAL +COMM\\"; # Get list of value names: my @valueNames= $key->ValueNames; foreach my $item (@valueNames) { my $valueString= $key->GetValue($item); print $valueString."\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://821593]
Approved by starX
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-12-25 15:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls