arduino php串口没有串口显示器

时间:2013-12-06 16:49:20

标签: php linux arduino

我有一点情况我试图从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();


?>

应该在

1 个答案:

答案 0 :(得分:0)

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

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