Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I am working on Perl Win32::SerialPort. I have a query.
Generally to create a new port object we write:

 $PortObj=Win32::SerialPort->new("COM1",$quiet);
But now i want to generalize the port selection. In detail I am planning to get a list of all the ports (COM1, COM2 etc) that are available on my system.
on selecting a particular port then check for connectivity and then create the Serial Object.
But i have no idea on how to get the ports listed. I hope you monks can help me out with your ideas to achieve my task.

Replies are listed 'Best First'.
Re: Query regarding Ports
by BrowserUk (Patriarch) on Feb 19, 2009 at 06:16 UTC

    Get DBD::WMI and try this:

    #! perl -slw use strict; use DBI; my $dbh = DBI->connect('dbi:WMI:'); my $sth = $dbh->prepare(<<WQL); SELECT DeviceID, Description FROM Win32_SerialPort WQL $sth->execute(); while( my @row = $sth->fetchrow ) { printf "DeviceID: %s Description: %s \n", @row; } __END__ C:\test>SerialPorts.pl DeviceID: COM3 Description: BCM V.92 56K Voicemodem DeviceID: COM1 Description: Communications Port

    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.