2

I am trying to communicate with a micro controller trough a serial port under Linux. I am using a USB to serial cable for the purpose, but my php script is giving me the following error:

Fatal error: Call to undefined function deviceSet()

Here is my script

error_reporting(E_ALL);
ini_set('display_errors', '1');     //displays php errors

include("php_serial.class.php");

$serial = new phpSerial();

deviceSet('ttyUSB0'); //for linux serial /dev/ttySP(0-4) for usb /dev/ttyUSBN

// If you want to change the configuration, the device must be closed 
//$serial->deviceClose();
$serial->confBaudRate(9600); //Baud rate: 9600
$serial->confParity("none");  //Parity (this is the "N" in "8-N-1")
$serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1")
    $serial->confStopBits(2);  //Stop bits (this is the "1" in "8-N-1")
$serial->confFlowControl("none");

$serial->deviceOpen();
// To write into $serial->sendMessage("1");
$read = $serial->readPort();

I have my doubts that the php_serial.class file has trouble running the serial connection through USB, any ideas?

Also it seems like there is a problem with this:

# dmesg | grep tty
console [tty0] enabled
usb 3-2: FTDI USB Serial Device converter now attached to ttyUSB0
ftdi_sio ttyUSB0: ftdi_submit_read_urb - failed submitting read urb, error -1

Thanks.

I edited the $serial ->deviceSet() and now a bunch of errors appear

Specified serial port is not valid in /var/www/html/php_serial.class.php on line 111 Warning: Unable to set the baud rate : the device is either not set or opened in /var/www/html/php_serial.class.php on line 204 Warning: Unable to set parity : the device is either not set or opened in /var/www/html/php_serial.class.php on line 254 Warning: Unable to set length of a character : the device is either not set or opened in /var/www/html/php_serial.class.php on line 298 Warning: Unable to set the length of a stop bit : the device is either not set or opened in /var/www/html/php_serial.class.php on line 335 Warning: Unable to set flow control mode : the device is either not set or opened in /var/www/html/php_serial.class.php on line 376 Warning: The device must be set before to be open in /var/www/html/php_serial.class.php on line 137 Warning: Device must be opened to read it in /var/www/html/php_serial.class.php on line 474

Is this a problem with the php_serial.class

1
  • 1
    deviceSet() is not a native PHP function. Where are you expecting it from? Commented Mar 11, 2013 at 15:29

1 Answer 1

1

deviceSet() is a method of the serial class. The way you're calling it, it would need to be a native PHP function.

It should be: $serial->deviceSet('ttyUSB0');

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.