douqian2334 2015-08-13 15:03
浏览 73

我试图通过串口与微控制器通信。 但我的PHP脚本给了我一个错误

<?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

Warning: Unable to set parity : in C:\xampp\htdocs\sensorsApp\php_serial.class.php on line 299

Warning: Unable to set character length : in C:\xampp\htdocs\sensorsApp\php_serial.class.php on line 337

Warning: Unable to set stop bit length : in C:\xampp\htdocs\sensorsApp\php_serial.class.php on line 375

Fatal error: Unable to set flow control : in C:\xampp\htdocs\sensorsApp\php_serial.class.php on line 424

P.S how to save the received data into mysql database

  • 写回答

1条回答 默认 最新

  • dqdl6469 2015-08-13 15:15
    关注

    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

    You should first do a var_dump($serial) before setting the baud rate to see if the initialization worked as intended. 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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)