LastTemplar

Hi again So I got my Arduino yesterday, played with it the whole day and managed to control it through PHP. All I do is send a string through the serial port which is then compared in Arduino, and if the string is "on" it lights up the LED on pin13. So I managed to get it to work just as I wanted through the Serial Monitor, I send the "on" string and the LED lights up. In PHP however I send the "on" string but the LED just blinks once and that's all. Could someone help me out here?

$serial->deviceOpen();if ($_GET['action'] == "on") {$serial->sendMessage("on");} $serial->deviceClose();Open the port, causing the Arduino to reset, then jam some data out and slam the port shut, causing another reset, without giving the Arduino time to get ready to read the data.

You posted all of your code. I pointed out why that wouldn't work, so you posted a snippet of your revised code. Posting snippets is not the way to get help. Post all of your code.

It is likely that when the PHP parser ends, that it closes the serial port. So, when you execute the script again (how you are doing is a bit of a mystery, since there is no form with submit buttons), with a different action, the port you are trying to write to is not open.

Do you have warnings/errors in PHP enabled?

The art of getting good answers lies in asking good questions.

LastTemplar

<?php//check the GET action var to see if an action is to be performedif (isset($_GET['action'])) {//Action required//Load the serial port classrequire("php_serial.class.php");//Initialize the class$serial = new phpSerial();

Certainly, C# (or other application that maintains state) is able to maintain an open connection. I was concerned that each invocation of the script opened and closed the serial port.

Can you see that the Arduino does indeed restart each time the script is invoked? Watch the onboard LEDs that flash when the Arduino starts. If they flash the same way when the script is invoked, then the script is opening and closing the port each time.