 by RNope » Tue Jan 29, 2013 3:14 pm
                by RNope » Tue Jan 29, 2013 3:14 pm
            
            
                     by RNope
                by RNope
Tue Jan 29, 2013 3:14 pm
            
            
            Thanks for your answers !
Pushing a step further i wanted to tried "over the web control" with this PHP -serial class:
(cannot put a direct link due to forum limitation sorry)
code.google(DOTcom)/p/php-serial/
I installed a local Wampserver and tried to send data on serial port but i seem to have a problem converting the 8 bit command into byte array :
I tried sending "raw"  data from the result of single "byte conversion" i did in processing  and a web-to-arduino-example using this class:
- Code: Select all
-      <php>deviceSet("COM9"); //SET THIS TO WHATEVER YOUR SERIAL DEVICE HAPPENS TO BE
 
 //Set the serial port parameters.
 $serial->confBaudRate(115200); //Baud rate:
 //$serial->confParity("none");  //Parity
 //$serial->confCharacterLength(8); //Character length
 //$serial->confStopBits(1);  //Stop bits
 //$serial->confFlowControl("none");
 
 
 //Now we "open" the serial port so we can write to it
 $serial->deviceOpen();
 
 //Issue the appropriate command according to the Arduino source code 0=Green On, 1=Green Off, 2=Red On, 3=Red Off.
 if ($_GET['action'] == "greenon") {
 
 //$serial->sendMessage("-1 -1 -86 85 -86 85 55 -70"); //header
 $serial->sendMessage("-1");
 $serial->sendMessage("-1");
 $serial->sendMessage("-86");
 $serial->sendMessage("85");
 $serial->sendMessage("-86");
 $serial->sendMessage("85");
 $serial->sendMessage("55");
 $serial->sendMessage("-70");
 //$serial->sendMessage("20 0 0 0 0 1 1 1"); //inner
 $serial->sendMessage("20");
 $serial->sendMessage("0");
 $serial->sendMessage("0");
 $serial->sendMessage("0");
 $serial->sendMessage("0");
 $serial->sendMessage("1");
 $serial->sendMessage("1");
 $serial->sendMessage("1");
 //We're done, so close the serial port again
 $serial->deviceClose();
 
 }
 
 
 ?><DOCTYPE>
 <html>
 <head>
 <meta>
 <title>Arduino Project 1: Serial LED Control</title>
 </head>
 <body>
 
 <h1>Arduino Project 1: Serial LED Control</h1>
 <p><a href="<?=$_SERVER['PHP_SELF'] . ">
 </body>
 </html>
 
Wich doesn't work : (USB red light on for 10s but no motion played)
Searching around the web , assuming it was a "type" problem i found two posts indicating quite the same method to transform hexadecimal  to "raw" (assuming byte ?) array :
1 using str_plit (or explode) >convert string to array
2 using hexdec function >convert hex to dec
3 using chr function  > return string from ASII code
(cannot put a direct link sorry) phpclasses(DOTorg)/discuss/package/3679/thread/16/
(cannot put a direct link sorry) stackoverflow(DOTcom)/questions/11352193/php-convert-c-sharp-hex-blob-hexadecimal-string-back-to-byte-array-prior-to-decr
Adaptating it to my problem :
- Code: Select all
 $headerHex = 'FFFFAA55AA5537BA';
 $innerHex = '1400000000010101';
 //$header = join(',', array_map('hexdec', str_split($headerHex, 2)));
 $header = join(',', array_map('chr', array_map('hexdec', str_split($headerHex, 2))));
 //$inner = join(',',  array_map('hexdec', str_split($innerHex, 2)));
 $inner = join(',', array_map('chr', array_map('hexdec', str_split($innerHex, 2))));
 $serial->sendMessage($header);
 $serial->sendMessage($inner);
 
 
- Code: Select all
- <php>deviceClose("COM9"); //Make sure port is closed
 $serial->deviceSet("COM9"); //Set the comport (/dev/ttyS0)
 $serial->confBaudRate(115200); //Set the baurd rate
 $serial->confParity(none); //Set the Parity
 $serial->confCharacterLength(8); //Set the word length
 $serial->confStopBits(1); //Set Stop Bit
 $serial->confFlowControl(none); //Set FLow Control
 
 
 
 $packet = $_POST["newPacket"];
 $explodedPacket = explode(",",$packet);
 
 $concat = "";
 
 for($i=0; $i<sizeof>deviceOpen(); //Open the port ready for transmitt
 $serial->sendMessage($concat);
 }
 ?>
Despite some communication being made (red LED lights on for 10s when i send the command) no motion is played.
Any suggestion would be greatly appreciated  !
Thanks for your answers !
Pushing a step further i wanted to tried "over the web control" with this PHP -serial class:
(cannot put a direct link due to forum limitation sorry)
code.google(DOTcom)/p/php-serial/
I installed a local Wampserver and tried to send data on serial port but i seem to have a problem converting the 8 bit command into byte array :
I tried sending "raw"  data from the result of single "byte conversion" i did in processing  and a web-to-arduino-example using this class:
- Code: Select all
-      <php>deviceSet("COM9"); //SET THIS TO WHATEVER YOUR SERIAL DEVICE HAPPENS TO BE
 
 //Set the serial port parameters.
 $serial->confBaudRate(115200); //Baud rate:
 //$serial->confParity("none");  //Parity
 //$serial->confCharacterLength(8); //Character length
 //$serial->confStopBits(1);  //Stop bits
 //$serial->confFlowControl("none");
 
 
 //Now we "open" the serial port so we can write to it
 $serial->deviceOpen();
 
 //Issue the appropriate command according to the Arduino source code 0=Green On, 1=Green Off, 2=Red On, 3=Red Off.
 if ($_GET['action'] == "greenon") {
 
 //$serial->sendMessage("-1 -1 -86 85 -86 85 55 -70"); //header
 $serial->sendMessage("-1");
 $serial->sendMessage("-1");
 $serial->sendMessage("-86");
 $serial->sendMessage("85");
 $serial->sendMessage("-86");
 $serial->sendMessage("85");
 $serial->sendMessage("55");
 $serial->sendMessage("-70");
 //$serial->sendMessage("20 0 0 0 0 1 1 1"); //inner
 $serial->sendMessage("20");
 $serial->sendMessage("0");
 $serial->sendMessage("0");
 $serial->sendMessage("0");
 $serial->sendMessage("0");
 $serial->sendMessage("1");
 $serial->sendMessage("1");
 $serial->sendMessage("1");
 //We're done, so close the serial port again
 $serial->deviceClose();
 
 }
 
 
 ?><DOCTYPE>
 <html>
 <head>
 <meta>
 <title>Arduino Project 1: Serial LED Control</title>
 </head>
 <body>
 
 <h1>Arduino Project 1: Serial LED Control</h1>
 <p><a href="<?=$_SERVER['PHP_SELF'] . ">
 </body>
 </html>
 
Wich doesn't work : (USB red light on for 10s but no motion played)
Searching around the web , assuming it was a "type" problem i found two posts indicating quite the same method to transform hexadecimal  to "raw" (assuming byte ?) array :
1 using str_plit (or explode) >convert string to array
2 using hexdec function >convert hex to dec
3 using chr function  > return string from ASII code
(cannot put a direct link sorry) phpclasses(DOTorg)/discuss/package/3679/thread/16/
(cannot put a direct link sorry) stackoverflow(DOTcom)/questions/11352193/php-convert-c-sharp-hex-blob-hexadecimal-string-back-to-byte-array-prior-to-decr
Adaptating it to my problem :
- Code: Select all
 $headerHex = 'FFFFAA55AA5537BA';
 $innerHex = '1400000000010101';
 //$header = join(',', array_map('hexdec', str_split($headerHex, 2)));
 $header = join(',', array_map('chr', array_map('hexdec', str_split($headerHex, 2))));
 //$inner = join(',',  array_map('hexdec', str_split($innerHex, 2)));
 $inner = join(',', array_map('chr', array_map('hexdec', str_split($innerHex, 2))));
 $serial->sendMessage($header);
 $serial->sendMessage($inner);
 
 
- Code: Select all
- <php>deviceClose("COM9"); //Make sure port is closed
 $serial->deviceSet("COM9"); //Set the comport (/dev/ttyS0)
 $serial->confBaudRate(115200); //Set the baurd rate
 $serial->confParity(none); //Set the Parity
 $serial->confCharacterLength(8); //Set the word length
 $serial->confStopBits(1); //Set Stop Bit
 $serial->confFlowControl(none); //Set FLow Control
 
 
 
 $packet = $_POST["newPacket"];
 $explodedPacket = explode(",",$packet);
 
 $concat = "";
 
 for($i=0; $i<sizeof>deviceOpen(); //Open the port ready for transmitt
 $serial->sendMessage($concat);
 }
 ?>
Despite some communication being made (red LED lights on for 10s when i send the command) no motion is played.
Any suggestion would be greatly appreciated  !