uart_readn()


Reading designated number of bytes from the UART port

Description

int uart_readn(int $uart_id, int/string &$rbuf, int $rlen)

Parameters

Return Value

On success, returns the number of read data. On fail, returns 0.(If the number of received data is less than the $len it is fail.)

Example

<?php
include "/lib/sd_340.php";
$rbuf = "";
uart_setup(0, 9600);               // Configuring UART0 to 9600 bps
while(1)
{
  $rlen = uart_readn(0, $rbuf, 5);  // Reading 5 bytes of data from the UART0
  if($rlen)
  {
    echo "$rbuf\r\n";
    break;
  }
}
?>

See also