Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Roomba Serial Port Communication

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();
like image 330
tushark Avatar asked Nov 14 '22 02:11

tushark


1 Answers

The result of -(pow(2, 8) - N) is an integer. PHP internally stores integer values as signed long.

Use pack()!

like image 200
rik Avatar answered Dec 18 '22 20:12

rik