php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35531 php wont get input from a serialport after writing to it
Submitted: 2005-12-03 18:26 UTC Modified: 2005-12-11 01:00 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: roman-lehnert at gmx dot de Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 4.4.1 OS: Linux 2.6.12
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: roman-lehnert at gmx dot de
New email:
PHP Version: OS:

 

 [2005-12-03 18:26 UTC] roman-lehnert at gmx dot de
Description:
------------
Php doesn't get any input from a serialport, after opening the devicefile and writing to it. Maybe this is thought to be so - and maybe it is a feature. For those cases: sorry for stealing ur time. 


Infact, there IS a response from the device. The difference between "strace php -f example.php" and "strace cat /dev/ttyUSB0" (nonblocking-mode in php):

php wont get the input. for php, the device is "temporarily unavailable":
"read(3, 0x17e4a4, 1024)                 = -1 EAGAIN (Resource temporarily unavailable)"

cat gets the answer from the device:
"read(3, "\0\340", 4096)                 = 2"


There is no difference, if i use fopen, or dio_open: php wont get the answer from my device.
There is also no difference, if i use fread, fgets or dio_read. 

The lib i used can be seen here: http://nopaste.php-q.net/176167


Tested on a x86 and an embedded-arm machine, both running an actual linux >2.6.12-r1 kernel. The chmods for the devices were set correctly. 

Reproduce code:
---------------
<?php
$fp = fopen('/dev/ttyUSB0','r+');
#fp = fopen('/dev/ttyUSB0','w+');
fputs($fp,chr(0xff),1);
$buffer = fread($fp,1);
fclose($fp);
?>

<?php
$fp = dio_open('/dev/ttyUSB0', O_RDWR | O_NOCTTY | O_NONBLOCK | O_APPEND);
dio_write($fp,chr(0xff));
$buffer = dio_read($fp,1);
dio_close($fp);
?>


Expected result:
----------------
I expected to get the answer in $buffer by fread, fgets or dio_read. But the answer from the device (wich i can see in cat /dev/ttyUSB0) didnt came up in php. 

Actual result:
--------------
The strace of "cat /dev/ttyUSB0", you can see here:
<snip>
read(3, "\0\340", 4096)                 = 2
</snip>

Should appear also at "strace php -f example.php". but it doesnt. When the devicefile is opened in nonblocking mode, the relevant strace-output is:
<snip>
read(3, 0x17e4a4, 1024)                 = -1 EAGAIN (Resource temporarily unavailable)
</snip>

When the devicefile is opened in blockingmode, it just hangs at
<snip>
read(3,
</snip>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-03 23:50 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip


 [2005-12-11 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC