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

Dear Monks, I'm trying to open a modem port using Win32::SerialPort.
When running: $PortObj = new Win32API::CommPort ($Port)
on port equal or higher then "COM10", the command fails.
For ports "COM9" and lower the command succeeds.
The failure point is in the return from WIN32::CreateFile.
Hyper terminal can open the modem on port "COM24".
Will be glad for a clue,
Thanks in advance.

Replies are listed 'Best First'.
Re: Problem: Win32::SerialPort
by BrowserUk (Patriarch) on Dec 02, 2007 at 09:29 UTC

    This note from the MS docs for CreateFile explain the problem and the solution:

    To specify a COM port number greater than 9, use the following syntax: "\\.\COM10". This syntax works for all port numbers and hardware that allows COM port numbers to be specified.

    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.
Re: Problem: Win32::SerialPort
by roboticus (Chancellor) on Nov 29, 2007 at 16:35 UTC
    kfiryaar:

    Well, which is it CommPort or SerialPort? ;^)

    Seriously, though, show a bit of code so we can get a clue. Even if I had the package installed on my machine, I wouldn't have a way to reproduce the problem without some code to do so. Generally when using a well-used module, you can assume that any errors are on your side of the fence, which is another reason it would be good to show some code.

    ...roboticus

      Comments in RED:

      $PortName = "COM24";
      $PortObj = new Win32API::CommPort ($PortName) || die "Can't open $PortName: $^E\n";
      # die if the modem is mapped to port that is higher then 9 ("COM24" here).
      # "query modem" using device manager is successful.
      # When I re-assign the modem port to "COM4", the new works just fine.


      $ob->baudrate(38400);
      $ob->parity("none");
      $ob->parity_enable(1); # for any parity except "none"
      $ob->databits(8);
      $ob->stopbits(1);
      $ob->handshake('rts');
      my $baud = $ob->baudrate;
      print "baud from configuration: $baud\n";
      $ob->write("ATE0X4\r");
      sleep 1;
      my $result = $ob->input;
      print "result = $result\n";

      undef $ob;


      Thanks,
      Kfir