Linux中的php串行通信 [英] php serial communication in linux

查看:83
本文介绍了Linux中的php串行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在fedora 13中安装了xampp.我正在尝试使用php串行类通过串行端口与微控制器进行通信. 我的代码是example.php

I have installed xampp in fedora 13.I am trying to communicate with microcontroller through serial port using php serial class. My code is example.php

include("php_serial.class.php");
$serial = new phpSerial();
$serial->deviceSet("0");

$serial->confBaudRate(9600); //Baud rate: 9600 
$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 of any kind, so set it to none.

//Now we "open" the serial port so we can write to it
$serial->deviceOpen();

$serial->sendMessage("*1" ); //sleep(1); // echo "hi"; $serial->deviceClose();

?>

php脚本被执行,但给出以下警告.

The php script gets executed but gives the following warnings .

警告:第147行上的/opt/lampp/htdocs/xampp/php_serial.class.php中指定的串行端口无效 警告:无法设置波特率:设备未设置或未在第241行的/opt/lampp/htdocs/xampp/php_serial.class.php中打开 警告:无法设置奇偶校验:第295行的/opt/lampp/htdocs/xampp/php_serial.class.php中未设置或打开设备

Warning: Specified serial port is not valid in /opt/lampp/htdocs/xampp/php_serial.class.php on line 147 Warning: Unable to set the baud rate : the device is either not set or opened in /opt/lampp/htdocs/xampp/php_serial.class.php on line 241 Warning: Unable to set parity : the device is either not set or opened in /opt/lampp/htdocs/xampp/php_serial.class.php on line 295

...我已经使用命令:chmod 0777/dev/ttyUSB0授予权限.我还尝试通过使用命令将apache用户"prudhvi"添加到拨出组: $ usermod -a -G拨出prudhvi

... I have used the command : chmod 0777 /dev/ttyUSB0 to give permissions . I have also tried to add the apache user "prudhvi" to the dialout group by using command : $ usermod -a -G dialout prudhvi

但是它不起作用.当我使用以下命令直接从终端发送命令:echo 1>/dev/ttyUSB0时,它将起作用,并且'1'传输到串行端口.但是使用php时,我得到了以上警告.

But it doesnt work . When I send a command directly from the terminal using the command : echo 1 > /dev/ttyUSB0 it works and '1' is transmitted to the serial port . But using php I get the above warnings .

我已使用"$ whoami"检查用户的名称,并将该用户"prudhvi"添加到了拨出组.它仍然不起作用.请帮助我.

I have used the "$whoami" to check name of user and added that user "prudhvi" to the dialout group . It still doesnt work . Please help me guys.

推荐答案

我曾经和Debian一起用PHP脚本控制Arduino板,最初遇到了同样的问题.

I did this once with Debian to control an Arduino board with a PHP script and initially ran into the same problem.

在Debian中,您需要将Apache用户添加到拨出组中,以允许它发出串行连接请求.我认为Fedora也是一样.

In Debian, you need to add the Apache user to the dialout group in order to allow it to make serial connection requests. I would assume the same is true for Fedora.

在Debian中,命令是:

In Debian the command is:

useradd -G dialout www-data

但是我相信Fedora将Apache用户命名为apache.我没有要测试的Fedora机器,但是我认为您需要运行的命令是:

However I believe Fedora names the Apache user as apache instead. I don't have a Fedora machine to test on, but I would assume the command you need to run is:

useradd -G dialout apache

然后,您将需要重新启动xampp服务器.

You will then need to restart your xampp server.

请参阅以下内容以供参考:

See the following for reference:

http://www.cyberciti.biz/faq /howto-linux-add-user-to-group/ http://fedoraproject.org/wiki/Administration_Guide_Draft/Apache#Apache_File_Security

尼尔

这篇关于Linux中的php串行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆