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

Connecting to Serial Ports greater than COM9 on win32

by slloyd (Hermit)
on Jul 14, 2009 at 18:55 UTC ( [id://780033]=perlquestion: print w/replies, xml ) Need Help??

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

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

s/te/ve/

Replies are listed 'Best First'.
Re: Connecting to Serial Ports greater than COM9 on win32
by Anonymous Monk on Dec 08, 2017 at 06:13 UTC
    hey i tried giving the ComPort input in the way you have done, it still says the same thing. Can you please help me or suggest some other modules that i can use??

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found