繁体   English   中英

我正在尝试通过串行端口与微控制器通信。 但是我的PHP脚本给我一个错误

[英]I am trying to communicate with a micro controller through a serial port . but my php script is giving me an error

<?php
include "php_serial.class.php";

// Let's start the class
$serial = new phpSerial();

// First we must specify the device. This works on both Linux and Windows (if
// your Linux serial device is /dev/ttyS0 for COM1, etc.)
$serial->deviceSet("COM3");

// Set for 9600-8-N-1 (no flow control)
$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");

// Then we need to open it
$serial->deviceOpen();

// Read dataa
$read = $serial->readPort();

print "<pre>";
print_r($read);
print "</pre>";

// Print out the data
echo $read;
// print exec("echo 'r9g9b9' > /dev/ttyACM0");
print "RESPONSE(1): {$read}<br><br>";

// If you want to change the configuration, the device must be closed.
$serial->deviceClose();

// If you want to change the configuration, the device must be closed.
$serial->deviceClose();
?>

这些是错误

警告:无法设置波特率:在第253行的C:\\ xampp \\ htdocs \\ sensorsApp \\ php_serial.class.php中

警告:无法在299行的C:\\ xampp \\ htdocs \\ sensorsApp \\ php_serial.class.php中设置奇偶校验:

警告:无法设置字符长度:在第337行的C:\\ xampp \\ htdocs \\ sensorsApp \\ php_serial.class.php中

警告:无法设置停止位长度:在第375行的C:\\ xampp \\ htdocs \\ sensorsApp \\ php_serial.class.php中

致命错误:无法设置流控制:在第424行的C:\\ xampp \\ htdocs \\ sensorsApp \\ php_serial.class.php中

PS如何将接收到的数据保存到mysql数据库中

我假设您的php_serial.class.php是这样的: https : //code.google.com/p/php-serial/source/browse/trunk/php_serial.class.php? r =11

在设置波特率之前,应先执行var_dump($serial) ,以查看初始化是否按预期工作。 它应大致包含以下内容:

_os = "windows";
_windevice = "COM3"
_device = "\\.\com3"
_dState = 1  // SERIAL_DEVICE_SET

如果到目前为止仍然有效,请打开一个外壳,然后查看手动设置波特率是否有效:

mode COM3 BAUD=9600

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM