【问题标题】:PHP communication with Arduino under Windows and LinuxWindows和Linux下与Arduino的PHP通信
【发布时间】:2013-09-30 11:22:52
【问题描述】:

在 Windows 中,我可以毫无问题地连接到 Arduino,我可以发送所有字节,如数字 (0-9) 和字母 (a-z)。但是我在 Linux (ubuntu) 中遇到了问题,因为我只能发送数字 (0-9)。当我使用相同的代码时,在 Windows 中我可以发送所有内容,在 Linux 中我正在发送但它根本不起作用。

这是我的代码:

<?php

error_reporting(E_ALL); 
ini_set("display_errors", 1);  

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

    require("php_serial.class.php");

        $serial = new phpSerial();
        $serial->deviceSet("/dev/ttyACM0");
        $serial->confBaudRate(9600);
        $serial->confCharacterLength(8);
        $serial->deviceOpen();

if ($_GET['action'] == "1") {

        $serial->sendMessage("1");

} else if ($_GET['action'] == "2") {

        $serial->sendMessage("2");
}

if ($_GET['action'] == "a") {

        $serial->sendMessage("a");

} else if ($_GET['action'] == "b") {

        $serial->sendMessage("b");
}

$serial->deviceClose();

}

?>

在 Windows 中,我需要将“/dev/ttyACM0”替换为“COM3”,但它仍然是相同的代码。此代码打开/关闭我的二极管。如果我在 Windows 中使用它,我可以通过输入数字(1 开,2 关)或字母(a = 开,b = 关)来打开二极管。在 Linux 中,我只通过输入数字打开二极管...

我看到 Arduino 正在“读取”我的发送字节 a 或 b,但它没有执行任何操作。

【问题讨论】:

  • 你能提供图书馆的网址吗!

标签: php arduino


【解决方案1】:

好的,我通过设置做到了这一点:

if ($_GET['action'] == "a") {

        $serial->sendMessage("aaaa");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多