Don't like ads? PRO users don't see any ads ;-)
Guest

serialcontrol

By: a guest on Aug 1st, 2012  |  syntax: PHP  |  size: 1.73 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3.  
  4. /* Simple serial script for turning two leds on
  5. and off from the web!
  6.  
  7. Utilizes the PHP Serial class by Rémy Sanchez <thenux@gmail.com>
  8. (Thanks you rule!!) to communicate with the Arduino Serial!
  9.  
  10. */
  11.  
  12.  
  13. //check the GET action var to see if an action is to be performed
  14. if (isset($_GET['action'])) {
  15.     //Action required
  16.      
  17.     //Load the serial port class
  18.     require("php_serial.class.php");
  19.      
  20.     //Initialize the class
  21.     $serial = new phpSerial();
  22.  
  23.     //Specify the serial port to use... in this case COM1
  24.     $serial->deviceSet(COM3); //SET THIS TO WHATEVER YOUR SERIAL DEVICE HAPPENS TO BE, YOU CAN FIND THIS UNDER THE ARDUINO SOFTWARE'S MENU
  25.      
  26.     //Set the serial port parameters. The documentation says 9600 8-N-1, so
  27.     $serial->confBaudRate(9600); //Baud rate: 9600
  28.    // $serial->confParity("none");  //Parity (this is the "N" in "8-N-1") ******THIS PART OF THE CODE WAS NOT NEEDED
  29.   // $serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1") ******THIS PART OF THE CODE WAS NOT NEEDED
  30.    // $serial->confStopBits(1);  //Stop bits (this is the "1" in "8-N-1") ******THIS PART OF THE CODE WAS NOT NEEDED
  31.     //$serial->confFlowControl("none"); //******THIS PART OF THE CODE WAS NOT NEEDED
  32.  
  33.  
  34.     //Now we "open" the serial port so we can write to it
  35.     $serial->deviceOpen();
  36.  
  37.     // OLD CODE LISTED FOR REFERENCE    
  38.     //} else if ($_GET['action'] == "redoff") {
  39.     //    //to turn the RED LED OFF, we issue this command
  40.     //    $serial->sendMessage("3\r");
  41.     //}
  42.        
  43.     $action = $_GET['action'];
  44.         $serial->sendMessage($action);
  45.     //We're done, so close the serial port again
  46.     $serial->deviceClose();
  47.         echo $action;
  48.  
  49. }
  50.  
  51.  
  52. ?>