|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-03-28 03:56 UTC] mccaskey at stanford dot edu
Description:
------------
(1) Open a COM port as a serial input using fopen. Read using fread or fgets. No data appears until 8K bytes have been read. There is an 8K buffer on writes, but there shouldn't be one on reads. (Should there?) Are reads somehow using the write buffer? Sure enough:
(2) Again, open a COM port as a serial input using fopen. This time, write some characters using fwrite. Now fread 8K of serial data. At the head of that stream appears the data you had written with fwrite. Oops.
[Several people have reported an inability to get fgets to read COM data, saying they tried and fgets just never sees any input. I assume this was their problem. But others have reported using fgets on COM successfully. Something specific to OS/PHP versions?]
Reproduce code:
---------------
(1)
$serial_port = fopen("COM4", "r+");
echo(fread($serial_port, 8192));
(2)
$serial_port = fopen("COM4", "r+");
fwrite($serial_port, "MP");
echo(fread($serial_port, 8192));
Expected result:
----------------
(1) & (2)
serial data starting with the first byte that came in on the serial line
Actual result:
--------------
(1) Nothing until 8K of data has been read in.
(2) After enough serial data to fill the buffer, first the data written ("MP" in this example), then the data that came in on the serial line.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
In windows one way to make work fopen("COM4","r+") and then sucesives fread() is previusly do this: start->control panel->modem and phone then select de modem and click propertys and make a test or Diagnostic of the device. After that work properly fopen() and fread() under serial port while not disconnect de port. I work in project with PHP to SEND SMS with my cell phone SAMGSUNG E2222 Sorry my English