我已經在Fedora 13中安裝了xampp。我試圖通過使用php串行類的串行端口與微控制器進行通信。 我的代碼是使用example.php在Linux中的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腳本被執行,但給出了以下警告。
警告:在/opt/lampp/htdocs/xampp/php_serial.class.php上在線147 中指定的串行端口無效警告:無法設置波特率:設備未設置或未在/選擇/ LAMPP/htdocs中/ XAMPP/php_serial.class.php上線241 警告:無法設置奇偶校驗:該設備未設置或在/opt/lampp/htdocs/xampp/php_serial.class.php打開上線295
...我已經使用命令:chmod 0777/dev/ttyUSB0來授予權限。我也嘗試使用以下命令將apache用戶「prudhvi」添加到撥出組: $ usermod -a -G撥出prudhvi
但它不起作用。當我使用以下命令直接從終端發送命令時:echo 1>/dev/ttyUSB0它工作並且'1'被髮送到串行端口。但使用PHP我得到了上述警告。
我已經使用了「$ WHOAMI」來檢查用戶名和添加用戶「prudhvi」的撥出組。它仍然無法正常工作。請幫助我們。
你確定php正在訪問ttyUSB0嗎?它可以嘗試默認使用ttyS0。 –