Bug->Doc #66943 [Opn]: Can't open COM10 or higher serial ports

From: Date: Mon, 07 Sep 2020 12:52:06 +0000
Subject: Bug->Doc #66943 [Opn]: Can't open COM10 or higher serial ports
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17871@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66943&edit=1

 ID:                 66943
 Updated by:         cmb@php.net
 Reported by:        mattficken@php.net
 Summary:            Can't open COM10 or higher serial ports
 Status:             Open
-Type:               Bug
+Type:               Documentation Problem
 Package:            Streams related
 Operating System:   Windows
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

This is a documented limitation of CreateFile[1]:

| To specify a COM port number greater than 9, use the following
| syntax: "\.\COM10".

Thus changing to doc problem.

[1] <https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#communications-resources>


Previous Comments:
------------------------------------------------------------------------
[2014-04-23 22:42:50] mattficken@php.net

Related To: Bug #67098

------------------------------------------------------------------------
[2014-04-23 22:33:15] mattficken@php.net

Instead of using the COMn: notation, using the \\.\COMn notation avoids this issue.

I have a PR for PhpSerial which uses this so it can open 2 digit Com ports (COM 11, COM12, etc...),
see https://github.com/Xowap/PHP-Serial/pull/6


Thanks to Dennis Ahrens for figuring this out.

------------------------------------------------------------------------
[2014-03-22 22:19:02] mattficken@php.net

Description:
------------
PHP on Windows can't open (using fopen()) serial ports greater than COM9:, fe
fopen("COM10:" or fopen("COM11:" fail.

This occurs regardless of the mode passed to fopen. "r+b" is the correct mode for serial
on Windows. "r+" allows reading and writing. "b" sets it to binary mode,
important because: Windows converts non-ASCII (>127) bytes if the stream is in text mode.

I am using Serial over USB (FTDI driver) to communicate with a microcontroller (Arduino).

In Serial over USB (not real serial) on Windows you can rename COM ports, so users can work around
this problem by renaming COM ports to unused ports like COM7 or COM8, etc... for instructions, see
my PR below for the PhpSerial class.


I have modified the PhpSerial class to work on Windows (for both read and write), see https://github.com/Xowap/PHP-Serial/pull/3  as
an example of how to use serial ports from PHP.


I suspect the cause is in the realpath() parser, checking for COM*: with a one integer but not two
(not COM**: )


Test script:
---------------
// connect Serial-over-USB device to Windows PC, such as an Arduino Uno
//         (which uses an FTDI controller, get the FTDI driver for Windows
//          from Sourceforge or Arduino)
fopen("COM10:", "r+b");

Expected result:
----------------
fopen() returns a resource handle

Actual result:
--------------
"failed to open stream: invalid argument"


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=66943&edit=1


Thread (1 message)

  • cmb@php.net
  • Unknown Message
    • cmb@php.net
« previous php.doc.bugs (#17871) next »