Advertisement
Guest User

PHP accessing AT command

a guest
Dec 1st, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2. //error_reporting(-1);
  3. require "php_serial.class.php";
  4. // Source: https://github.com/Xowap/PHP-Serial/blob/develop/src/PhpSerial.php
  5. $serial = new phpSerial;
  6. $serial->deviceSet("COM4");
  7. $serial->confBaudRate(9600);                    // Baud rate: 9600
  8. $serial->confParity("none");                    // Parity (this is the "N" in "8-N-1")
  9. $serial->confCharacterLength(8);                // Character length     (this is the "8" in "8-N-1")
  10. $serial->confStopBits(1);                   // Stop bits (this is the "1" in "8-N-1")
  11. $serial->confFlowControl("none");               //
  12. $serial->deviceOpen();                      // Then we need to open it
  13. $serial->sendMessage("AT+CUSD=1,'*152#',15");           // To write into
  14. sleep(3);                           // wait for modem to send message
  15. $read=$serial->readPort();                  // read the response
  16. $response = $serial->_dHandle;
  17.  
  18. echo "Response: ".$response."<br>";
  19.  
  20. //echo get_resource_type ( $serial->_dHandle );exit;
  21.  
  22. if(is_resource($serial->_dHandle) AND !feof($serial->_dHandle))
  23. {
  24.     print_r(stream_get_meta_data($serial->_dHandle));
  25.    
  26.     $stdin = fopen('php://stdin', 'r');
  27.     $res = stream_get_contents($stdin, -1, 10);
  28.  
  29.     //var_dump(fread($stdin,8));
  30.     var_dump($res);
  31.     //print_r(stream_get_meta_data($stdin));
  32. }else{
  33.     echo "no response";
  34. }
  35. $serial->deviceClose();
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement