我能够发送数据给我的arduino,当我发送信息时,板子中间的LED闪烁。 完全相同的情况发生在我不发送消息时,只是打开并关闭串口。这可能意味着PhpSerial类没有发送消息,或者arduino设置不正确。Arduino没有收到串口信息
我的Arduino代码:
#include "USBSerial_main.h"
int incomingByte = 0;
int pin = 2;
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
digitalWrite(2, false);
}
void loop() {
if(Serial.available() > 0){
Serial.read();
digitalWrite(2, true);
delay(100);
digitalWrite(2, false);
}
}
我的PHP代码:
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
include "PhpSerial.php";
$msg = '';
$comPort = "/dev/ttyACM0";
if(isset($_POST["hi"])){
$serial = new phpSerial;
$serial->deviceSet($comPort);
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->deviceOpen();
$serial->sendMessage("Well hello!");
$serial->serialflush();
$serial->deviceClose();
$msg = "Your message has been sent!";
}
?>
<html>
<head>
<title>hi</title>
</head>
<body>
<form method="POST">
<input type="submit" name="hi" value="Send">
</form><br>
<?=$msg?>
</body>
</head>
我已经修改了PhpSerial.php文件,因为它没有检测stty命令,这实际上是可用,coreutils软件包完全是最新的。
我只是拿出这样的检查:
//if ($this->_exec("stty") === 0) {
register_shutdown_function(array($this, "deviceClose"));
//} else {
// trigger_error(
// "No stty availible, unable to run.",
// E_USER_ERROR
// );
//}
到底哪里出问题了,什么办解决这一问题?它是否与PhpSerial的版本(我刚刚从几小时前从github直接拉出)或其他内容有关?
还有一个注意事项:它正在使用fopen来做这件事。
系统:在VBox中运行Ubuntu 14.02 LTS。
谢谢你十几次,那有效!它需要准确的2秒的延迟,这对PHP应用程序来说是个好消息。但不管怎么说。有用! – rhbvkleef