php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32469 With COM ports (Windows), fread sees nothing until 8K
Submitted: 2005-03-28 03:56 UTC Modified: 2005-05-23 16:22 UTC
From: mccaskey at stanford dot edu Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5CVS-2005-03-29 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
42 - 15 = ?
Subscribe to this entry?

 
 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-02 20:29 UTC] mccaskey at stanford dot edu
(2) was an artifact of my test setup. Ignore that. But (1) stands: I can't see any input until 8K bytes have been read.

Using a COM-port monitoring program, I can see and count the bytes coming in, and a terminal emulator gets them starting with the first byte, but php (fread, fgets, or fgetc) doesn't.
 [2005-05-23 14:59 UTC] sniper@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2012-10-17 20:41 UTC] xodrf at hotmail dot com
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 19:01:29 2024 UTC