Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Win32: How to find out the number of serial ports?

Reply
Thread Tools

Win32: How to find out the number of serial ports?

 
 
Josef Moellers
Guest
Posts: n/a
 
      03-15-2005
Hi,

I'm helping a friend revive some old hardware (a timekeeping device
using smart cards). I've sorted out all the communications details (ISO
7816) and most of it is working fine. The program is written in (you
guessed it) Perl using Win32::API and Serial-Port.

Now I'd like to add a feature to scan the serial ports for the device,
but rather than assume that any modern PC has 2 serial ports, I'd like
to determine exactly how many serial ports the current system supports.

I've looked at the Registry, but that only carried some information
about the serial ports (if you know which ports you have, you can find
out more). A colleague suggested something like cfgmgr, but there
doesn't seem to be a module for this.

Under a more familiar OS, I'd look at /proc/tty/driver/serial, but on XP?

Josef
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

 
Reply With Quote
 
 
 
 
Thomas Kratz
Guest
Posts: n/a
 
      03-15-2005
Josef Moellers wrote:
> Hi,
>
> I'm helping a friend revive some old hardware (a timekeeping device
> using smart cards). I've sorted out all the communications details (ISO
> 7816) and most of it is working fine. The program is written in (you
> guessed it) Perl using Win32::API and Serial-Port.
>
> Now I'd like to add a feature to scan the serial ports for the device,
> but rather than assume that any modern PC has 2 serial ports, I'd like
> to determine exactly how many serial ports the current system supports.
>
> I've looked at the Registry, but that only carried some information
> about the serial ports (if you know which ports you have, you can find
> out more). A colleague suggested something like cfgmgr, but there
> doesn't seem to be a module for this.
>
> Under a more familiar OS, I'd look at /proc/tty/driver/serial, but on XP?


Here's a way using the WMI interface. I guess you could do the same by
going through the registry after resolving a bunch of cryptic device_ids,
but this is a case where WMI actually saves time and nerves.

use strict;
use warnings;

use Win32::OLE qw/in/;
Win32::OLE->Option(Warn => 1);

my $wmi = Win32::OLE->GetObject(
"winmgmts:{impersonationLevel=impersonate,(securit y)}"
) or die
"error initializing WMI interface, ",
Win32::OLE->LastError;

print $_->{DeviceID}, "\n"
for in($wmi->InstancesOf('Win32_SerialPort'));

If you need more information about the properties of the serial port, get
the "WMI Object Browser" with the free "WMI Tools" from M$.

Thomas

--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e. r^.>l^..>k^.-
 
Reply With Quote
 
 
 
 
Josef Moellers
Guest
Posts: n/a
 
      03-16-2005
Thomas Kratz wrote:
> Josef Moellers wrote:


>> Now I'd like to add a feature to scan the serial ports for the device,
>> but rather than assume that any modern PC has 2 serial ports, I'd like
>> to determine exactly how many serial ports the current system supports.


> Here's a way using the WMI interface. I guess you could do the same by
> going through the registry after resolving a bunch of cryptic
> device_ids, but this is a case where WMI actually saves time and nerves.
>
> use strict;
> use warnings;
>
> use Win32::OLE qw/in/;
> Win32::OLE->Option(Warn => 1);
>
> my $wmi = Win32::OLE->GetObject(
> "winmgmts:{impersonationLevel=impersonate,(securit y)}"
> ) or die
> "error initializing WMI interface, ",
> Win32::OLE->LastError;
>
> print $_->{DeviceID}, "\n"
> for in($wmi->InstancesOf('Win32_SerialPort'));


Thanks, "Tausend dank".

Josef
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
fcntl, serial ports and serial signals on RS232. Max Kotasek Python 4 04-09-2010 06:32 PM
350d serial number - what serial number?!? GT Digital Photography 6 04-07-2005 07:58 PM
Test Serial to Serial Connection, Protocol Down... Scooter Cisco 5 12-16-2004 04:38 PM
Can I connect router Serial interface directly to a PC serial port? Faustino Dina Cisco 2 08-18-2004 02:30 AM



Advertisments