Hi.
I'm trying to control my Arduino via PHP but ran into a few problems.
My setup is XAMPP on Mountain Lion, the Arduino is connected via USB.
I've stripped the code down because it already fails at opening the stream.
<?php
$f = fopen("/dev/tty.usbmodem621", "w");
fclose($f);
?>
When I open that page the Arduino restarts, so there seems to be some kind of access. But the PHP page hangs until I unplug the Arduino. Then I get this error message:
Warning: fopen(/dev/tty.usbmodem621) [function.fopen]: failed to open stream:
Device not configured in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 2
While the PHP page hangs I can't connect to the Arduino with screen or the serial monitor because it is in use, so there seems to be a connection.
This is what the Arduino is running. I can connect via the serial monitor and and screen. Turning the LED on/off works, so does the echoing of unknown commands.
char incomingByte;
int led = 13;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (Serial.available() > 0)
{
incomingByte = Serial.read();
switch ( incomingByte )
{
case '0':
digitalWrite(led, LOW);
break;
case '1':
digitalWrite(led, HIGH);
break;
default:
Serial.print(incomingByte);
}
}
}
Baud are fine, permissions allow reading:
~:$ stty -f /dev/tty.usbmodem621
speed 9600 baud;
lflags: -icanon -isig -iexten -echo
iflags: -icrnl -ixon -ixany -imaxbel -brkint
oflags: -opost -onlcr -oxtabs
cflags: cs8 -parenb crtscts
~:$ ls -la /dev/tty.usbmodem621
crw-rw-rw- 1 root wheel 18, 68 Dec 16 14:09 /dev/tty.usbmodem621
The second problem is that I can't use stty to disable hupcl. The command runs without error but checking the flags shows me that it did not stick.
~:$ stty -f /dev/tty.usbmodem621
speed 9600 baud;
lflags: -icanon -isig -iexten -echo
iflags: -icrnl -ixon -ixany -imaxbel -brkint
oflags: -opost -onlcr -oxtabs
cflags: cs8 -parenb crtscts
~:$ stty -f /dev/tty.usbmodem621 -hup
~:$ stty -f /dev/tty.usbmodem621
speed 9600 baud;
lflags: -icanon -isig -iexten -echo
iflags: -icrnl -ixon -ixany -imaxbel -brkint
oflags: -opost -onlcr -oxtabs
cflags: cs8 -parenb crtscts