You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
960 B

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. error_reporting( E_ALL );
  3. function microtime_float(){
  4. list($usec, $sec) = explode(" ", microtime());
  5. return ((float) $usec + (float) $sec);
  6. };
  7. require_once('uartPort.php');
  8. $myPort = new uartPort();
  9. $myPort->deviceSet('/dev/ttyUSB0');
  10. $myPort->confBaudRate(9600);
  11. $myPort->confParity("none");
  12. $myPort->confCharacterLength(8);
  13. $myPort->confStopBits(1);
  14. $myPort->confFlowControl("none");
  15. print_r( $myPort );
  16. // Then we need to open it
  17. if( $myPort->deviceOpen() ){
  18. $read = '';
  19. $start = microtime_float();
  20. while ( ($read == '') && (microtime_float() <= $start + 2.5) ) {
  21. $read = trim( $myPort->readPort() );
  22. if ($read != '') {
  23. echo '['.trim($read) . "]\n";
  24. $theResult .= $read;
  25. $read = '';
  26. };
  27. };
  28. // If you want to change the configuration, the device must be closed
  29. $myPort->deviceClose();
  30. } else echo "Error oppening device \n";
  31. ?>