繁体   English   中英

arduino php串行,无串行监视器

[英]arduino php serial with no serial monitor

我在尝试从php站点控制arduino时遇到一些情况,它工作正常,但我需要保持arduino应用程序以及串行监视器的打开状态。 有没有可以在不打开显示器的情况下与arduino交谈的方法?

我使用php_serial_class并仅使用fopen进行此操作:

带fopen的基本版本

<?

if (isset($_GET["action"])){


    $comPort = "/dev/tty.usbmodemfa131"; /*change to correct com port */

    if ($_GET['action']=='on') {


    $fp =fopen($comPort, "w");
    fwrite($fp, 'a'); /* this is the number that it will write */
    fclose($fp);

}

if ($_GET['action']=='off') {


    $fp =fopen($comPort, "w");
    fwrite($fp, 'b'); /* this is the number that it will write */
    fclose($fp);
    }


}


?>

<body>
<h1>Controllering the Arduino from php</h1>

    <a href="controller.php?action=on">Turn ON!!!</a>
    <a href="controller.php?action=off">Turn OFF</a>


</body>

这就是php_class

<?

include "php_serial.class.php";

// Let's start the class
$serial = new phpSerial;
$serial->deviceSet("/dev/tty.usbmodemfa131");
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
$serial->deviceOpen();

$serial->sendMessage("a\r");

$serial->deviceClose();


?>

应该在

也许在打开端口后尝试读取(fgets)...也许arduino在等待您阅读命令之前先阅读它。

另外,看看http://php.net/dio

暂无
暂无

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

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