I am trying to communicate with an iRobot Roomba through the serial port using the PHP class developed by Remy Sanchez. I am sure it is sending the data as the iRobot USB cable is receiving the data and lighting up, however, the Roomba doesn't seem to be acknowledging the commands as defined in the Roomba Serial Command Interface (SCI) Specification manual. Is there a possible reason for this? Does the class distort the data in some way or does the Roomba require a certain data type to be sent to it that PHP doesn't support?
Additional Information (I'm not sure if this is relevant)
Using RealTerm, I can communicate with the Roomba directly using the Send Numbers function (if I try to communicate any other way, it sends every keypress). Using PuTTY, the Roomba doesn't accept my commands, even though I can force local echo + line editing on. It receives the commands, but doesn't do anything with them even though the baud rate is configured correctly.
Code
require("php_serial.class.php");
$serial = new phpSerial();
$serial->deviceSet("COM1");
$serial->confBaudRate(115200); //Baud rate: 115200
$serial->confParity("none"); //Parity (this is the "N" in "8-N-1")
$serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1")
$serial->confStopBits(1); //Stop bits (this is the "1" in "8-N-1")
$serial->confFlowControl("none"); //Device does not support flow control
$serial->deviceOpen();
$start = sprintf("%c",128);
$power = sprintf("%c",133);
$serial->sendMessage("$start");
$time_start = microtime(true);
// Sleep for a while
usleep(1000000);
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "Did nothing in $time seconds <br>";
$serial->sendMessage("$power");
$serial->deviceClose();
The result of -(pow(2, 8) - N) is an integer. PHP internally stores integer values as signed long.
Use pack()
!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With