在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 = on,b = off)来打开二极管。在 Linux 中,我只通过键入数字来打开二极管...
我看到Arduino正在"读取"我的发送字节a或b,但它没有执行任何操作。
好的,
我通过设置来做到这一点:
if ($_GET['action'] == "a") {
$serial->sendMessage("aaaa");