Linux串口通讯,php脚本问题

时间:2022-10-18 16:11:14

I am trying to communicate with a micro controller trough a serial port under Linux. I am using a USB to serial cable for the purpose, but my php script is giving me the following error:

我试图通过Linux下的串口与微控制器进行通信。我正在使用USB转串口电缆,但我的PHP脚本给了我以下错误:

Fatal error: Call to undefined function deviceSet()

致命错误:调用未定义的函数deviceSet()

Here is my script

这是我的剧本

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();

I have my doubts that the php_serial.class file has trouble running the serial connection through USB, any ideas?

我怀疑php_serial.class文件在通过USB运行串行连接时遇到了麻烦,有什么想法吗?

Also it seems like there is a problem with this:

这似乎也有问题:

# 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

Thanks.

I edited the $serial ->deviceSet() and now a bunch of errors appear

我编辑了$ serial - > deviceSet(),现在出现了一堆错误

Specified serial port is not valid in /var/www/html/php_serial.class.php on line 111 Warning: Unable to set the baud rate : the device is either not set or opened in /var/www/html/php_serial.class.php on line 204 Warning: Unable to set parity : the device is either not set or opened in /var/www/html/php_serial.class.php on line 254 Warning: Unable to set length of a character : the device is either not set or opened in /var/www/html/php_serial.class.php on line 298 Warning: Unable to set the length of a stop bit : the device is either not set or opened in /var/www/html/php_serial.class.php on line 335 Warning: Unable to set flow control mode : the device is either not set or opened in /var/www/html/php_serial.class.php on line 376 Warning: The device must be set before to be open in /var/www/html/php_serial.class.php on line 137 Warning: Device must be opened to read it in /var/www/html/php_serial.class.php on line 474

指定的串行端口在第111行的/var/www/html/php_serial.class.php中无效警告:无法设置波特率:未在/var/www/html/php_serial.class中设置或打开设备第204行的.php警告:无法设置奇偶校验:未在第254行的/var/www/html/php_serial.class.php中设置或打开设备警告:无法设置字符的长度:设备是未在第298行的/var/www/html/php_serial.class.php中设置或打开警告:无法设置停止位的长度:未在/ var / www / html / php_serial中设置或打开设备。第335行上的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中读取它

Is this a problem with the php_serial.class

这是php_serial.class的问题

1 个解决方案

#1


1  

deviceSet() is a method of the serial class. The way you're calling it, it would need to be a native PHP function.

deviceSet()是串行类的一种方法。你调用它的方式,它需要是一个原生的PHP函数。

It should be: $serial->deviceSet('ttyUSB0');

它应该是:$ serial-> deviceSet('ttyUSB0')​​;

#1


1  

deviceSet() is a method of the serial class. The way you're calling it, it would need to be a native PHP function.

deviceSet()是串行类的一种方法。你调用它的方式,它需要是一个原生的PHP函数。

It should be: $serial->deviceSet('ttyUSB0');

它应该是:$ serial-> deviceSet('ttyUSB0')​​;