Advertisement
dehqan

Untitled

Nov 11th, 2011
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. <?php
  2. if (!extension_loaded("dio")) print "skip";
  3.  
  4. // declare variables
  5. $handle = $reply = null;
  6. $filename = '/dev/ttyUSB1';
  7. $handle = dio_open($filename, O_RDWR | O_NOCTTY | O_NONBLOCK);
  8.  
  9. //validate file handle
  10. if ( !is_file($handle) ){
  11.  
  12. echo 'The device isn\'t detected';
  13.  
  14. }else{ // main code.
  15. dio_fcntl($handle, F_SETFL, O_SYNC);
  16.  
  17. dio_tcsetattr($handle, array(
  18. 'baud' => 9600,
  19. 'bits' => 7,
  20. 'stop' => 1,
  21. 'parity' => 0));
  22.  
  23. if ( dio_write($handle, 'AT') ) {
  24. echo 'Command is sent';
  25. $reply = dio_read($handle, 10);
  26. //echo $reply;
  27.  
  28.  
  29. }else{
  30. echo 'The device isn\'t read';
  31. }
  32.  
  33. dio_close( $handle );
  34. }
  35.  
  36. die;
  37.  
  38. ?>
  39.  
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement