Advertisement
dehqan

Untitled

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