Php没有写入串口

时间:2014-06-10 16:35:35

标签: php serial-port arduino debian

我现在已经在试用我的arduino一段时间了。几周前,我决定通过网站控制它。 我的网络服务器在Linux交钥匙上运行(这是一个debian发行版),但它也不能在我的Ubuntu 14.02 LTS上运行vBox(usb配置正确,再次使用屏幕工作)

我正在运行php 5.4.4-14 + deb7u10和apache 2.2.22

我已将arduino的端口识别为/ dev / ttyACM0,我可以使用(sudo) screen /dev/ttyACM0向其发送数据,但它不能使用以下代码:
此代码是Instructable

的直接副本
<?php


$verz="1.0";
$comPort = "/dev/ttyACM0";

if (isset($_POST["rcmd"])) {
$rcmd = $_POST["rcmd"];

switch ($rcmd) {
     case Stop:
        $fp =fopen($comPort, "w");
        fwrite($fp, 1);
        echo 'Stop, 1';
        fclose($fp);
        break;
    case Slow:
        $fp =fopen($comPort, "w");
        fwrite($fp, 2);
        fclose($fp);
        echo 'Slow operation, 2';
        break;
    case Medium:
        $fp =fopen($comPort, "w");
        fwrite($fp, 3);
        fclose($fp);
        echo 'Medium operation, 3';
        break;
    case Fast:
        $fp =fopen($comPort, "w");
        fwrite($fp, 4);
        fclose($fp);
        echo 'Fast operation, 4';
        break;
    case Right:
        $fp =fopen($comPort, "w");
        fwrite($fp, 5);
        fclose($fp);
        echo 'Right operation, 5';
        break;
    case Left:
        $fp =fopen($comPort, "w");
        fwrite($fp, 6);
        fclose($fp);
        echo 'Left operation, 6';
        break;
    default:
        die('Crap, something went wrong. The page just puked.');
}

}
?>
<html>
<body>

<center><h1>Arduino from PHP Example</h1><b>Version <?php echo $verz; ?></b></center>

<form method="post" action="<?php echo $PHP_SELF;?>">
<input type="submit" value="Left" name="rcmd">
<input type="submit" value="Right" name="rcmd"><br/>
<br />
<input type="submit" value="Stop" name="rcmd"><br/>
<br />
<input type="submit" value="Slow" name="rcmd">
<input type="submit" value="Medium" name="rcmd">
<input type="submit" value="Fast" name="rcmd">
<br />
<br />
<br />
<br />
<br />
<br />

</form>
</body>
</html>

是的,我知道,代码编写得很糟糕。我知道,但这不是我的代码,我不想改变它。

我也尝试使用php_serial库,它也不起作用。

0 个答案:

没有答案