i2c_write_read()


向I2C传送数据读取接收数据

Description

int i2c_write_read(int $i2c_id, string $wbuf, string &$rbuf, int $rlen)

Parameters

Return Value

成功时读取或是写的长度(字节),失败时0

Example

<?php
include "/lib/sd_340.php";
$rbuf = "";
$wbuf = "\x05\x03";
$rlen = 0;
i2c_setup(0, 0x1e);                         // configuring I2C
$rlen = i2c_write_read(0, $wbuf, $rbuf, 2); // writing and reading to/from the I2C
if($rlen == 2)
  echo "$rbuf";                             // outputting the received data
?>

See also