Go Down

Topic: Arduino Windows PHP (Read 1 time) previous topic - next topic

RamiDuino

Hello everybody,

I am trying to get an arduino uno to work with PHP through the serial port using the USB cable of Arduino.

I have used the codes that are available in internet that allow you to make this communication between PHP and Arduino without having to install any additional software, library or whatever.

I have programmed the website as follows:

1st file "Serial.php":
-------------------------------------------------
<?php

// declare port

 `mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;

?>
-------------------------------------------------


2nd file "SerialTest.php":
-------------------------------------------------
<?php

 //open port com1

 $fp = fopen ("COM1:", "w+");

 if (!$fp) {

    echo "Error while opening COM1.";
 
} else {

    $data = escapeshellcmd($_REQUEST["data"]);
    fwrite ($fp, $data );
}

fclose ($fp);

?>

<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Serial port connection</title>
</head>
<body>
 <form method="get" action="SerialTest.php">
   <br />
   <button type="submit" name="data" value="1">ONE</button>
   <br />
   <button type="submit" name="data" value="2">TWO</button>
   <br />
 </form>
</body>
</html>
-------------------------------------------------


The first file seems to work although I am not 100% sure but the leds of the card blink.

the 2nd file gives this error

Warning: fopen(COM1:) [function.fopen]: failed to open stream: Permission denied in <filepath>\SerialTest.php on line 5

Might anyone help me with this issue?

Thank you very much in advance.

RamiDuino

Well, I don't understand this witchery very well, but it looks like the matter is that the first file doesn't do it's job well.

To make it to work I had to start the port COM1 from the Arduino's IDE. And looks like not all ports work, I didn't try it but I found somewhere that just port COM1 to COM4 can be used.

So if you have to change the number of the port because you got something like port COM6 you may change it to COM1 or COM2, COM3, COM4 with the "device manager".

there has to be any other better way using just PHP and Windows for sure.

if you know it please let me know if you got the same problem I may try to help you as soon as I can.

Greetings everybody!

Go Up