Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php-serial not working

I am trying to use PHP to make my Arduino send out a signal. Whenever I run the code below, it says "Invalid serial port", though 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, link here: http://www.phpclasses.org/package/3679-PHP-Communicate-with-a-serial-port.html

Here is my Arduino sketch:

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.

like image 283
cheese5505 Avatar asked Nov 25 '12 04:11

cheese5505


1 Answers

Check that your COM2 is installed, enabled, and working right in device manager, if you haven't. Also what model of Arduino are you using? I don't think this question can be answered without more information. It might be wise to add that info to your original question. Also, we can't see the source of the php_serial class without registering for an account, which I do not wish to do. I realize this is more of a comment than an answer, but I need a bit more rep to comment (a flaw in S.O.'s reputation system, in my opinion.) But the original question will not get an answer without more information, so I felt it was pertinent to add. Best of luck.

like image 193
Jeremy Anderson Avatar answered Sep 23 '22 18:09

Jeremy Anderson