I'm working on a project which involves reading and writing to a Serial board, using the UART pins on my Raspberry Pi. However, I have hit a brick wall already. Any time I try use PhpSerial
I always get the error:
Fatal error: No stty available, unable to run. in /var/www/PHP-Serial/examples/PhpSerial.php on line 56
I've tried numerous configurations with the input:
// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)
$serial->deviceSet("/dev/ttyAMA0");
// We can change the baud rate, parity, length, stop bits, flow control
$serial->confBaudRate(38400);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
php/lighthttpd
is running as www-data, Ive tried chowning the /dev/ttyAMA0
to that user, and I've added the dialout group to said user. I cant see any disable functions or anything in my php.ini. I've also don't the standard setup for using serial devices on the pi as per the wiki, and I am able to read/write data to and from the circuit using
sudo minicom -b 38400 -o -D /dev/ttyAMA0
Here are the line(s) that the error is referring to:
if (substr($sysName, 0, 5) === "Linux") {
$this->_os = "linux";
if ($this->_exec("stty") === 0) {
register_shutdown_function(array($this, "deviceClose"));
} else {
trigger_error(
"No stty available, unable to run.",
E_USER_ERROR
);
}
I can't make sense of it but someone else might. Thanks in advance.
The solution to your problem is as follows:
You have to change the following line of code in the PhpSerial.php class
FROM:
TO:
=> This consequently resolves the "No stty available, unable to run..." error. See this thread: https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=100481
I should also add that I've had to place a delay before I write serial data out e.g.
error_reporting(E_ALL); ini_set('display_errors', '1');
STTY on Rasbian returns a 1 on the exec, rather than 0
Unfortunately if you just bypass this code, it hangs on register_shutdown_function.
Currently I am writing files to disk, and trying to send them to the port (struggling because they are binary text rather than ascii). If you have ascii info to send, then
And
As you can see PhpSerial needs stty utility to get/set serial parameters like baudrate, parity etc. The solution is to install
stty
by the means of your Linux distribution