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