I am using Win32::SerialPort to connect to my USB Serial Port device. When the device is assigned COM9, it connects just fine. If the device is assigned COM10 it fails to connect. Any pointers to connecting to ports greater than 9? I have verified that I have valid devices connected to both 9 and 10 and both show up as valid ports in HKEY_LOCAL_MACHINE, "Hardware\\DeviceMap\\SerialComm"
Update: I found this link on M$ site that explains the problem but I am not sure if the SerialPort module needs to be fixed to support it or if there is a work-around.
WorkAround: The work-around is to pass in the port name as "\\.\COMXX" where XX is the number. This works for me anyway.
#!perl
use strict;
use Win32::SerialPort;
my $port=shift || "COM9";
print "Connecting to $port .... ";
our $PortObj = new Win32::SerialPort($port);
unless(ref $PortObj){
print "Unable to connect to $port\n";
exit;
}
print "Connected!\n";
print "Press <ENTER> to disconnect";
my $cmd=<STDIN>;
$PortObj->close();
exit(0);
Results:
C:\Automation>test.pl COM9
Connecting to COM9 .... Connected!
Press <ENTER> to disconnect
C:\Automation>test.pl COM10
Connecting to COM10 .... The system cannot find the file specified.
can't open device: COM10
at C:\Automation\test.pl line 7
Unable to connect to COM10
C:\Automation>test.pl \\.\COM10
Connecting to \\.\COM10 .... Connected!
Press <ENTER> to disconnect
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.