简体   繁体   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();
?>

These are the errors 这些是错误

Warning: Unable to set baud rate: in C:\\xampp\\htdocs\\sensorsApp\\php_serial.class.php on line 253 警告:无法设置波特率:在第253行的C:\\ xampp \\ htdocs \\ sensorsApp \\ php_serial.class.php中

Warning: Unable to set parity : in C:\\xampp\\htdocs\\sensorsApp\\php_serial.class.php on line 299 警告:无法在299行的C:\\ xampp \\ htdocs \\ sensorsApp \\ php_serial.class.php中设置奇偶校验:

Warning: Unable to set character length : in C:\\xampp\\htdocs\\sensorsApp\\php_serial.class.php on line 337 警告:无法设置字符长度:在第337行的C:\\ xampp \\ htdocs \\ sensorsApp \\ php_serial.class.php中

Warning: Unable to set stop bit length : in C:\\xampp\\htdocs\\sensorsApp\\php_serial.class.php on line 375 警告:无法设置停止位长度:在第375行的C:\\ xampp \\ htdocs \\ sensorsApp \\ php_serial.class.php中

Fatal error: Unable to set flow control : in C:\\xampp\\htdocs\\sensorsApp\\php_serial.class.php on line 424 致命错误:无法设置流控制:在第424行的C:\\ xampp \\ htdocs \\ sensorsApp \\ php_serial.class.php中

PS how to save the received data into mysql database PS如何将接收到的数据保存到mysql数据库中

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

You should first do a var_dump($serial) before setting the baud rate to see if the initialization worked as intended. 在设置波特率之前,应先执行var_dump($serial) ,以查看初始化是否按预期工作。 It should roughly contain the following: 它应大致包含以下内容:

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

If that worked so far, open a shell and see if manually setting the baud rate works: 如果到目前为止仍然有效,请打开一个外壳,然后查看手动设置波特率是否有效:

mode COM3 BAUD=9600

暂无
暂无

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

相关问题 我试图在PHP中使用亚马逊api代码,但它给了我错误的不支持版本以下是我的代码 - I am trying to use amazon api code in php but it is giving me error of not supported version following is my code 我正在尝试将数据从报告表中插入数据库,但它给了我一个错误 laravel - I am trying to insert data into database from report table but it is giving me an error laravel 当我为我的 Laravel 项目调用任何工匠命令时,它一直给我一个错误 - When I am calling any artisan command for my Laravel project, It is giving me one error all the time 我试图将我的HTML网站更改为PHP,但它显示错误? - i am trying to change my html site to php but it shows error? 我正在尝试在Laravel 5.2中发送电子邮件。 它给我的错误是“ Mailer.php第410行中的InvalidArgumentException:回调无效。” - I am trying to send email in Laravel 5.2. It giving me erros as “InvalidArgumentException in Mailer.php line 410: Callback is not valid.” 我的PHP登录脚本给出以下错误 - My PHP login script is giving the following error 我正在尝试通过我的应用程序下载文件,但出现此错误 - I am trying to download file through my application but am getting this error 当我试图将数据输入数据库时​​,不能POST /test.php给我这个错误 - Cannot POST /test.php when i am trying to enter data into database its given me this error 为什么我无法通过PHP脚本将值插入子表中? - Why am I not able to insert values into my child table through my PHP script? 试图通过我的PHP脚本在我的Apache服务器中执行bash命令,但出现错误 - trying to execute a bash command in my apache server through my php script but getting error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM