|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-04-20 02:24 UTC] cobra91 at gmx dot de
Description:
------------
I set up my USB Serial Device as COMx (COM1-COM9) and everything works fine.
But if I change it to a number with more than one digit, it shows me a warning which says 'Invalid Argument'.
Test script:
---------------
<?php
//both exec work
//exec('mode com6: baud=115200 data=8 stop=1 parity=n xon=off dtr=off rts=off');
exec('mode com11: baud=115200 data=8 stop=1 parity=n xon=off dtr=off rts=off');
//$fd = dio_open('com6:', O_RDWR); //<--works
$fd = dio_open('com11:', O_RDWR); //<-- dont work (invalid argument)
$command="\x11\x0E\x1B\x44\x4C\x1B\x47\x44\x00\x00\x00\x00\x3F\x01\xEF\x00\x9F\x00";
$len=17;
$bytes_written = dio_write($fd,$command,$len);
echo $bytes_written;
dio_close($fd);
?>
Expected result:
----------------
Using com6 -> the script echos 17
using com11 -> the script should echo 17
Actual result:
--------------
Using com6 -> the script echos 17
using com11 ->
Warning: dio_open(): cannot open file com11: with flags 2 and permissions 0: Invalid argument in ...
Warning: dio_write() expects parameter 1 to be resource, boolean given in ...
Warning: dio_close() expects parameter 1 to be resource, boolean given in
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 00:00:02 2025 UTC |
$fd = dio_open('\\\\.\COM11', O_RDWR); <-- works This sounds like a workaround and not a solution.I've been developing a desktop serial monitor in C++ for Windows. I established the serial connection by calling the CreateFile() function, which takes the same string for a file path as your question is about. And in fact, "COMx" works fine with a one digit port number. When addressing ports larger than COM9 in Windows you will have to specify the port with the syntax "\\.\COMxxx" ("\\\\.\\COMxxx" when respecting escape sequence resolving). This more detailed syntax also works with COM1-COM9, so you can safely go with this syntax for any port number contained in a variable. For as far as I know, this is at least a Windows thing. Microsoft Support has an article about this: https://support.microsoft.com/en-us/kb/115831