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