Linux串行通信,php脚本问题
我试图在Linux下通过串口与微控制器通信。 我使用的是USB到串行电缆,但我的php脚本显示以下错误: 致命错误:调用未定义的函数deviceSet() 这是我的剧本Linux串行通信,php脚本问题,php,linux,serial-port,usb,Php,Linux,Serial Port,Usb,我试图在Linux下通过串口与微控制器通信。 我使用的是USB到串行电缆,但我的php脚本显示以下错误: 致命错误:调用未定义的函数deviceSet() 这是我的剧本 error_reporting(E_ALL); ini_set('display_errors', '1'); //displays php errors include("php_serial.class.php"); $serial = new phpSerial(); deviceSet('ttyUSB0')
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
谢谢
我编辑了$serial->deviceSet(),现在出现了一系列错误
第111行的/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行的/var/www/html/php_serial.class.php中打开设备
这是php_serial的一个问题。类是serial类的一个方法。按照您调用它的方式,它需要是一个本机PHP函数
它应该是:$serial->deviceSet('ttyUSB0')
deviceSet()
不是本机PHP函数。你在哪里期待它?