Hello
I need a simple script to read the information from a serial port (ttyS0 / ttyUSB0) using PHP on CentosLinux.
I have tried th following code but the code hangs and no results are returned.
<?php
$myFile = "/dev/ttyUSB0";
$handle = fopen($myFile, 'rb+');
$Data = fread($handle, 15);
fclose($handle);
echo $Data;
?>
Information from the serial port could come at anytime so there needs to be some sort of continuous polling waiting to receive the data from serial port.
Warning: fopen(/dev/ttyUSB0): failed to open stream: Permission denied in /var/www/html/scripts/[login to view URL] on line 2
my proposal is using c/c++ languege to create a listener of events from the port, and write the outup into file. then your script php can read data from the file. i did something like this for another client.
contact me on private to talk about details.
thank you
hi, you tested with minicom the /dev/ttyUSB0 first? which user run the script, you have tester with root. give me more info via freelancer chat. regards