PHP Roomba串口通信

发布于 2024-10-17 13:03:50 字数 1427 浏览 10 评论 0原文

我正在尝试使用 通过串行端口与 iRobot Roomba 进行通信由 Remy Sanchez 开发的 PHP 类。我确信它正在发送数据,因为 iRobot USB 电缆正在接收数据并点亮,但是,Roomba 似乎没有确认 Roomba 串行命令接口 (SCI) 规范手册。这有可能的原因吗?该类是否以某种方式扭曲了数据,或者 Roomba 是否需要向其发送 PHP 不支持的某种数据类型?

其他信息(我不确定这是否相关)

使用 RealTerm,我可以使用发送号码功能直接与 Roomba 进行通信(如果我尝试以任何其他方式进行通信,它会发送每次按键) 。使用 PuTTY,Roomba 不接受我的命令,即使我可以强制打开本地回显 + 行编辑。它接收命令,但不会对它们执行任何操作,即使波特率配置正确。

代码

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();

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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧夏天 2024-10-24 13:03:50

-(pow(2, 8) - N) 的结果是一个整数。 PHP 在内部将整数值存储为有符号长整型。

使用pack()

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

Use pack()!

兮子 2024-10-24 13:03:50

确保在任何命令后正确使用 CR 和/或 LF。有些程序会自动发送 1、两者或都不发送......

Make sure that CR and/or LF is correctly being used after any commands. Some programs automatically send 1, both, or none....

在你怀里撒娇 2024-10-24 13:03:50

使用 Putty 时,您的操作系统是 Linux,对吧?所以COM1可能是错误的。
尝试类似 $serial->deviceSet("/dev/ttyAMA0");
并确保您的网络用户(www-data?)位于“拨出”组内。

但首先要从命令行(Bash)开始工作:

正确配置串口: sudo stty 115200 -F /dev/ttyAMA0 cs8 cread clocal

从 bash 发送一些测试数据(启动被动模式) : sudo echo -n -e "\x80" > /dev/ttyAMA0

让 Roomba 清洁:sudo echo -n -e "\x87" > /dev/ttyAMA0

While using Putty your OS is Linux, right? So COM1 might be wrong.
Try something like $serial->deviceSet("/dev/ttyAMA0");
And make sure your web-user (www-data?) is within the 'dialout' group.

But first of all get it working from the commandline (Bash):

Correct configuration of the serial port: sudo stty 115200 -F /dev/ttyAMA0 cs8 cread clocal

Send some testdata from bash (start passive mode): sudo echo -n -e "\x80" > /dev/ttyAMA0

Let the roomba clean: sudo echo -n -e "\x87" > /dev/ttyAMA0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文