Php-serial not working

I am trying to use PHP to make Arduino send a signal. Whenever I run the code below, it says "Invalid serial port", although it is valid?

<?php include 'serial_connect.php'; $serial = new phpSerial; $serial->deviceSet("COM2"); $serial->deviceOpen(); $serial->sendMessage("1000"); $serial->deviceClose(); ?> 

The serial_connect.php class is php-serial, the link is here: http://www.phpclasses.org/package/3679-PHP-Communicate-with-a-serial-port.html

Here is my sketch of the Arduino:

 int ledPin = 13; void setup() { pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { if(Serial.available() > 0) { int time = Serial.parseInt(); digitalWrite(ledPin, HIGH); delay(time); digitalWrite(ledPin, LOW); } } 

Please, help. Thanks.

+7
source share
3 answers

Make sure your COM2 is installed, turned on, and works right in the device manager, if you haven’t. Also, which Arduino model are you using? I do not think that this question can be answered without additional information. It might be wise to add this information to your original question. In addition, we cannot see the source of the php_serial class without registering for an account, which I do not want to do. I understand that this is more of a comment than an answer, but I need a little more comments for comments (a flaw in the SO reputation system, in my opinion.) But the original question will not get an answer without additional information, so I felt it was appropriate to add. Good luck.

+2
source

You do not set the transfer rate in PHP code.

Have you tried using a terminal emulator (like Hyperterm) to make sure your serial port is connected correctly?

You may need to use the string \\.\COM2 as the name of the serial port - what I am doing in the C program that I wrote. Note that you may have to avoid these backslashes: "\\\\.\\COM2" .

+2
source

There are several errors in the code of the PHP-serial class.

DeviceSet function does not work on Linux for ttyUSB0 or ​​ttyACM0 out of the box;

confstopbits function, if for $ this-> os === osx must be ELSEIF

And yet, when trying to connect to Arduino with a PI or BBB, you need stty -F / dev / ttyACM0 ignpar to make it work properly ...

0
source

All Articles