簡體   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