title: php read data from serial port on linux
body: <p>I try to read serial port on Linux platform using PHP.<br>
  But I cant read any data. When I try to read using .net, this time I can read.</p>
  
  <p>I use "php_serial.class.php" class for serial port operations.  You can read this class from this link :<br>
  <a href="http://www.phpclasses.org/browse/file/17926.html" rel="nofollow">here</a></p>
  
  <p>My code is like this :  </p>
  
  <pre><code>&lt;?php  
   include "php_serial.class.php";  
  
  // Let's start the class
  $serial = new phpSerial;
  
  // First we must specify the device. This works on both linux and windows (if
  // your linux serial device is /dev/ttyS0 for COM1, etc)
  $serial-&gt;deviceSet("/dev/ttyS1");
  
  // We can change the baud rate, parity, length, stop bits, flow control
  $serial-&gt;confBaudRate(19200);
  $serial-&gt;confParity("none");
  $serial-&gt;confCharacterLength(8);
  $serial-&gt;confStopBits(1);
  $serial-&gt;confFlowControl("none");
  
  // Then we need to open it
  $serial-&gt;deviceOpen();  
  
  // read from serial port
  $read = $serial-&gt;readPort();
  
  //Determine if a variable is set and is not NULL
  if(isset($read)){
     while(1){
         $read = $serial-&gt;readPort();
         print_r(" (size ".strlen($read). " ) ");
         for($i = 0; $i &lt; strlen($read); $i++)
         {
            echo ord($read[$i])." ";
         }
         print_r("\n");
         sleep(1);
    }// end while
  }// end if  
  
  
  // If you want to change the configuration, the device must be closed
  $serial-&gt;deviceClose();
  
  // We can change the baud rate
  $serial-&gt;confBaudRate(19200);  
  ?&gt;  
  </code></pre>
  
  <p>the line "print_r(" (size ".strlen($read). " ) ");" always return zero. What is the reason why I cant read data from serial port?</p>