Linux Serial禁用DTR PHP

时间:2016-03-19 10:26:26

标签: php linux arduino serial-port

我尝试使用PHP在Linux上使用Arduino 我有一个工作脚本,但是(DTR option已启用。这让Arduino重启打开连接,所以问题是如何禁用DTR。

我已经运行过一次

stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

这是我的PHP代码:

<?php
$fp =fopen("/dev/ttyACM0", "w+");
if( !$fp) {
        echo "Error";die("can't open Serialport!");
}
sleep(2);// wait while restart
fwrite($fp, "1");// turn LED on
$s = null;
while($s != "0"){// wait for answer
        $s = fread($fp, 1);
}
echo $s."<- relsult";
fclose($fp);
?>

这是Arduino代码:

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}
void loop() {
  if ( Serial.available() > 0 ) {
    int inByte = Serial.read(); 
    if (inByte == 0x30) {digitalWrite(13, HIGH);}
    if (inByte == 0x31) {digitalWrite(13, LOW);}
    delay(50);//psydo for doing other things
    Serial.print("0");//say i am ready for the next
  }
} 

有任何想法禁用DTR选项。

0 个答案:

没有答案