2013-03-11 57 views
1

我想在Linux下通過串口與微控制器進行通信。 我使用的是USB轉串口線爲目的,但我的PHP腳本是給我下面的錯誤:Linux串行通信,php腳本問題

致命錯誤:調用未定義功能deviceSet()

這裏是我的腳本

error_reporting(E_ALL); 
ini_set('display_errors', '1');  //displays php errors 

include("php_serial.class.php"); 

$serial = new phpSerial(); 

deviceSet('ttyUSB0'); //for linux serial /dev/ttySP(0-4) for usb /dev/ttyUSBN 

// If you want to change the configuration, the device must be closed 
//$serial->deviceClose(); 
$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(2); //Stop bits (this is the "1" in "8-N-1") 
$serial->confFlowControl("none"); 

$serial->deviceOpen(); 
// To write into $serial->sendMessage("1"); 
$read = $serial->readPort(); 

我有我的懷疑php_serial.class文件無法通過USB運行串行連接,任何想法?

此外,它好像有這個問題:

# dmesg | grep tty 
console [tty0] enabled 
usb 3-2: FTDI USB Serial Device converter now attached to ttyUSB0 
ftdi_sio ttyUSB0: ftdi_submit_read_urb - failed submitting read urb, error -1 

感謝。

我編輯了$串行 - > deviceSet(),現在一堆錯誤出現

指定的串行端口是否在第111行警告/var/www/html/php_serial.class.php有效:無法設置波特率:設備未在/var/www/html/php_serial.class.php中設置或打開,位於第204行警告:無法設置奇偶校驗:設備未設置或在/ var/www中打開/html/php_serial.class.php 254行警告:無法設置字符的長度:設備未設置或打開在/var/www/html/php_serial.class.php在行298警告:無法設置停止位的長度:設備未在/var/www/html/php_serial.class.php行335上設置或打開警告:無法設置流量控制模式:設備未設置或未打開編輯在/var/www/html/php_serial.class.php在線376警告:設備必須在之前設置爲在/var/www/html/php_serial.class.php在137行打開警告:設備必須打開閱讀它在/var/www/html/php_serial.class.php上線474

這是與php_serial.class

+1

'deviceSet()'不是原生的PHP函數。你從哪裏期待它? – 2013-03-11 15:29:44

回答

1

deviceSet()一個問題是串行類的方法。你調用它的方式,它需要是一個本地PHP函數。

它應該是:$serial->deviceSet('ttyUSB0');

+0

謝謝我編輯了我的帖子 – user2137005 2013-03-11 15:36:48

+0

嘗試/ dev/ttyUSB0就像代碼中的註釋一樣。 – mkaatman 2013-03-11 15:39:11

+0

感謝您的幫助 – user2137005 2013-03-11 15:50:51