我正在开发一个项目,涉及使用Raspberry Pi上的UART引脚读取和写入串行板。但是,我已经打了一堵砖墙。每当我尝试使用PhpSerial
时,我总会收到错误:
致命错误:没有stty可用,无法运行。在第56行的/var/www/PHP-Serial/examples/PhpSerial.php中
我已尝试使用输入进行多种配置:
// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)
$serial->deviceSet("/dev/ttyAMA0");
// We can change the baud rate, parity, length, stop bits, flow control
$serial->confBaudRate(38400);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
php/lighthttpd
正在作为www-data运行,我尝试将/dev/ttyAMA0
chown给该用户,我已将拨出组添加到该用户。我在php.ini中看不到任何禁用功能或任何东西。我也没有根据wiki在pi上使用串行设备的标准设置,并且我能够使用
sudo minicom -b 38400 -o -D / dev / ttyAMA0
以下是错误所指的行:
if (substr($sysName, 0, 5) === "Linux") {
$this->_os = "linux";
if ($this->_exec("stty") === 0) {
register_shutdown_function(array($this, "deviceClose"));
} else {
trigger_error(
"No stty available, unable to run.",
E_USER_ERROR
);
}
我无法理解它,但其他人可能会这样。提前谢谢。
答案 0 :(得分:4)
您必须更改PhpSerial.php类中的以下代码行
发件人:强>
if ($this->_exec("stty") === 0) {
以强>
if ($this->_exec("stty --version") === 0) {
=>这因此解决了#34;没有stty可用,无法运行......"错误。请参阅此主题:https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=100481
我还应该补充一点,在我写出串行数据之前,我必须延迟一段时间。
<?php
的error_reporting(E_ALL); ini_set(&#39; display_errors&#39;,&#39; 1&#39;);
include "PhpSerial.php";//serial class: https://github.com/Xowap/PHP-Serial/blob/develop/examples/VS421CPNTA.php
$serial = new phpSerial;
//$serial->deviceSet("/dev/ttyAMA0");
$serial->deviceSet("/dev/ttyACM0");
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->deviceOpen();
sleep(3);//delay
$serial->sendMessage("1");
$serial->deviceClose();
echo "Serial message sent! \n";
答案 1 :(得分:0)
答案 2 :(得分:0)
Rasbian上的STTY在exec上返回1,而不是0
不幸的是,如果您绕过此代码,它会挂起register_shutdown_function。
目前我正在将文件写入磁盘,并尝试将它们发送到端口(因为它们是二进制文本而不是ascii而苦苦挣扎)。如果您要发送ascii信息,那么
stty -F /dev/ttyAMA0 38400
并且
exec("cat filename.txt > //dev//ttyAMA0");