in reply to Re^2: finding a serial port with Win32::SerialPort
in thread finding a serial port with Win32::SerialPort
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.
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.#!/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
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: finding a serial port with Win32::SerialPort
by pashanoid (Scribe) on Aug 22, 2011 at 15:02 UTC | |
by Marshall (Canon) on Aug 24, 2011 at 11:52 UTC |