2013-03-11 79 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