#49976 [Fbk-Opn]: Can't read anything from serial port
ID: 49976 User updated by: rpiccini at software4u dot it Reported By: rpiccini at software4u dot it -Status: Feedback +Status: Open Bug Type: Filesystem function related Operating System: WIN XP / UBUNTU 9.04 PHP Version: 5.2.11 New Comment: Thanks for reply, but binary mode doesn't help to make it works. On WIN XP and Ubuntu too nothing's changed. Anyway, I found a difference during fread instruction between WIN and Ubuntu that I haven't seen before (doesn't matter if binary mode is activated or not): [CODE] $buffer = fread($fp,128); //$buffer = fgets($fp); // tried also with fgets [/CODE] On WIN XP fread (and fgets too) hangs (never ending loop), while on UBUNTU $buffer is always empty (can't read reply from serial port) but the script doesn't loop on fread and goes (for the rest of my code) correctly to the end. It seems like stream_set_blocking($fp,0) doesn't work at all on WIN. By the way, I haven't yet solved my problem... Previous Comments: [2009-10-25 20:23:06] j...@php.net Oops, and this of course: $fp = fopen('COM1:','rb+'); [2009-10-25 20:22:36] j...@php.net How about you open it in binary mode? Like this: $fp = fopen('/dev/ttyS0','rb+'); Might work bit better on windows..? [2009-10-25 15:33:32] rpiccini at software4u dot it First of all sorry for my bad english. Anyway. Yes, I'm sure that with my code can't read anything back on the serial port. Can write but can't read replies. I've already tried with other applications and the serial port has always worked good as I expected. As I've already wrote in my firs post I can correclty send the same commands to the serial port using other programming languages (and also with a specific built-up application under WIN XP) and I get back the right reply from the port (ASCII chr(6) in this case) using always the same hardwar during my tests. Just for information. I've a dual-boot PC (WIN XP and Ubuntu linux 9.04) so the hardware (PC, serial port, fiscal printer) are exactly the same for both operating system. I'm developing a cross-platform application (WIN/Linux) so I MUST find a way to make the serial port to be read correctly on both o.s. I don't have much experience with dio/pecl functions...but I wouldn't like to use them, I'd prefer to have the standard PHP functions (fgets/fread) working correctly (Why can I write correctly with fputs but can't read with fgets/fread ???). I've also tried to insert a sleep between the fputs and fread operations just to verify any eventually time-related issue...but it still doesn't work: ?php // on UBUNTU $fp = fopen('/dev/ttyS0','r+'); // on WIN XP /*fp = fopen('COM1:','r+');*/ stream_set_timeout($fp, 0, 100); stream_set_blocking($fp,0); $stx = chr(2); $etx = chr(3); $string = $stx.030301346.$etx; // command to eject paper fputs($fp,$string); echo SENT: .$string.br /\n; // display string sent to serial port usleep(200); // a delay before reading the port //sleep(1);// more delay tried... $buffer = fread($fp,128); // tested with several int values echo RECEIVED: .$buffer.br /\n; // display NOTHING! fclose($fp); ? Curiosity. I've found a PHP class on www.phpclasses.org/browse/package/3679.html in which is developed a function for serial port reading ONLY on Linux (but it seems doesn't work!) and NOT for WINDOWS...why seems this thing so difficult to manage?? I do think this is a bug...pleas help me! [2009-10-23 18:22:27] johan...@php.net For using the serial port from linux I'd suggest to take a look at the dio extension so you can set baud rate, parity, ... via dio_tcsetattr() Are you sure your device really returns anything? did you try other serial port applications? [2009-10-23 17:43:08] rpiccini at software4u dot it Description: Either on WIN XP or UBUNTU 9.0 can't read back any data from serial port after correctly written to. I'm trying to talk to a fiscal printer trough a custom protocol based on ACK/NACK technique (send data - receive answer - respond to answer - ...) With a serial port scanner (and from the ticket that are correctly printed) I can see that the sent data are well received from fiscal printer. But any replay to sent data (which are present if data are sent to serial port from other kind of software/programming languages) are present. The PHP Version is 5.2.11. There were a similar bug report on http://bugs.php.net/bug.php?id=35531 but its state is closed (even if the case history is very similar
#49976 [Fbk-Opn]: Can't read anything from serial port
ID: 49976 User updated by: rpiccini at software4u dot it Reported By: rpiccini at software4u dot it -Status: Feedback +Status: Open Bug Type: Filesystem function related Operating System: WIN XP / UBUNTU 9.04 PHP Version: 5.2.11 New Comment: First of all sorry for my bad english. Anyway. Yes, I'm sure that with my code can't read anything back on the serial port. Can write but can't read replies. I've already tried with other applications and the serial port has always worked good as I expected. As I've already wrote in my firs post I can correclty send the same commands to the serial port using other programming languages (and also with a specific built-up application under WIN XP) and I get back the right reply from the port (ASCII chr(6) in this case) using always the same hardwar during my tests. Just for information. I've a dual-boot PC (WIN XP and Ubuntu linux 9.04) so the hardware (PC, serial port, fiscal printer) are exactly the same for both operating system. I'm developing a cross-platform application (WIN/Linux) so I MUST find a way to make the serial port to be read correctly on both o.s. I don't have much experience with dio/pecl functions...but I wouldn't like to use them, I'd prefer to have the standard PHP functions (fgets/fread) working correctly (Why can I write correctly with fputs but can't read with fgets/fread ???). I've also tried to insert a sleep between the fputs and fread operations just to verify any eventually time-related issue...but it still doesn't work: ?php // on UBUNTU $fp = fopen('/dev/ttyS0','r+'); // on WIN XP /*fp = fopen('COM1:','r+');*/ stream_set_timeout($fp, 0, 100); stream_set_blocking($fp,0); $stx = chr(2); $etx = chr(3); $string = $stx.030301346.$etx; // command to eject paper fputs($fp,$string); echo SENT: .$string.br /\n; // display string sent to serial port usleep(200); // a delay before reading the port //sleep(1);// more delay tried... $buffer = fread($fp,128); // tested with several int values echo RECEIVED: .$buffer.br /\n; // display NOTHING! fclose($fp); ? Curiosity. I've found a PHP class on www.phpclasses.org/browse/package/3679.html in which is developed a function for serial port reading ONLY on Linux (but it seems doesn't work!) and NOT for WINDOWS...why seems this thing so difficult to manage?? I do think this is a bug...pleas help me! Previous Comments: [2009-10-23 18:22:27] johan...@php.net For using the serial port from linux I'd suggest to take a look at the dio extension so you can set baud rate, parity, ... via dio_tcsetattr() Are you sure your device really returns anything? did you try other serial port applications? [2009-10-23 17:43:08] rpiccini at software4u dot it Description: Either on WIN XP or UBUNTU 9.0 can't read back any data from serial port after correctly written to. I'm trying to talk to a fiscal printer trough a custom protocol based on ACK/NACK technique (send data - receive answer - respond to answer - ...) With a serial port scanner (and from the ticket that are correctly printed) I can see that the sent data are well received from fiscal printer. But any replay to sent data (which are present if data are sent to serial port from other kind of software/programming languages) are present. The PHP Version is 5.2.11. There were a similar bug report on http://bugs.php.net/bug.php?id=35531 but its state is closed (even if the case history is very similar and the problem persists). Reproduce code: --- ?php // on UBUNTU $fp = fopen('/dev/ttyS0','r+'); // on WIN XP /*fp = fopen('COM1:','r+');*/ stream_set_timeout($fp, 0, 100); stream_set_blocking($fp,0); $stx = chr(2); $etx = chr(3); $string = $stx.030301346.$etx; // command to eject paper fputs($fp,$string); echo SENT: .$string.br /\n; // display string sent to serial port $buffer = fread($fp,128); // tested with several int values echo RECEIVED: .$buffer.br /\n; // display NOTHING! fclose($fp); ? Expected result: a correct ACK (chr(6)) or an incorrect NACK (chr(15)) from serial port (sent by the fiscal printer) Actual result: -- NOTHING (no a single char) -- Edit this bug report at http://bugs.php.net/?id=49976edit=1
#49976 [NEW]: Can't read anything from serial port
From: rpiccini at software4u dot it Operating system: WIN XP / UBUNTU 9.04 PHP version: 5.2.11 PHP Bug Type: Filesystem function related Bug description: Can't read anything from serial port Description: Either on WIN XP or UBUNTU 9.0 can't read back any data from serial port after correctly written to. I'm trying to talk to a fiscal printer trough a custom protocol based on ACK/NACK technique (send data - receive answer - respond to answer - ...) With a serial port scanner (and from the ticket that are correctly printed) I can see that the sent data are well received from fiscal printer. But any replay to sent data (which are present if data are sent to serial port from other kind of software/programming languages) are present. The PHP Version is 5.2.11. There were a similar bug report on http://bugs.php.net/bug.php?id=35531 but its state is closed (even if the case history is very similar and the problem persists). Reproduce code: --- ?php // on UBUNTU $fp = fopen('/dev/ttyS0','r+'); // on WIN XP /*fp = fopen('COM1:','r+');*/ stream_set_timeout($fp, 0, 100); stream_set_blocking($fp,0); $stx = chr(2); $etx = chr(3); $string = $stx.030301346.$etx; // command to eject paper fputs($fp,$string); echo SENT: .$string.br /\n; // display string sent to serial port $buffer = fread($fp,128); // tested with several int values echo RECEIVED: .$buffer.br /\n; // display NOTHING! fclose($fp); ? Expected result: a correct ACK (chr(6)) or an incorrect NACK (chr(15)) from serial port (sent by the fiscal printer) Actual result: -- NOTHING (no a single char) -- Edit bug report at http://bugs.php.net/?id=49976edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49976r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49976r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49976r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49976r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49976r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49976r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49976r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49976r=needscript Try newer version: http://bugs.php.net/fix.php?id=49976r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49976r=support Expected behavior: http://bugs.php.net/fix.php?id=49976r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49976r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49976r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49976r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49976r=php4 Daylight Savings:http://bugs.php.net/fix.php?id=49976r=dst IIS Stability: http://bugs.php.net/fix.php?id=49976r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49976r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49976r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49976r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49976r=mysqlcfg