dio-test-read.php 342 B

123456789101112131415
  1. <?php
  2. $fd = dio_open("/dev/ttyACM0", O_RDWR | O_NONBLOCK | O_NOCTTY);
  3. // first read after initial power up:
  4. $first = dio_read($fd, 1024);
  5. // send an 'R', then read again
  6. dio_write($fd, "R" . PHP_EOL);
  7. sleep(1);
  8. $second = dio_read($fd, 1024);
  9. dio_close($fd);
  10. var_dump(strlen($first), $first, PHP_EOL, "hello", strlen($second), $second);