test-read.php 462 B

12345678910111213141516171819
  1. <?php
  2. // check if we can write to the uart device file
  3. clearstatcache();
  4. if(false === is_writable("/dev/ttyACM0")) exit("check permissions: /dev/ttyACM0" . PHP_EOL);
  5. $fd = fopen("/dev/ttyACM0", "c+");
  6. // first read after initial power up:
  7. $first = fread($fd, 1024);
  8. // send an 'R', then read again
  9. fwrite($fd, "R" . PHP_EOL);
  10. sleep(1);
  11. $second = fread($fd, 1024);
  12. fclose($fd);
  13. var_dump(strlen($first), $first, PHP_EOL, "hello", strlen($second), $second);