Question : Linux/php serial port read - How to stop fread() waiting forever if no new data?

I'm working through exactly the same issue as described by skaap2k. (11/04/07 12:01 AM, ID: 22503690)

I am using a Linux (Ubuntu) server and PHP as a web server. The solution offered appears to be for a command line version of PHP, and doesn't work in my web server.

In short, I need to read and write to a GSM modem via the serial port using php. Writing is working fine.

Reading using fread() of /dev/ttyS1 stalls the server until the required number of bytes set in fread() and a CR is received.

I need to return from checking the serial port with a null if there is no new data. I'm happy to pick a byte at a time from the serial buffer and assemble it into a string in php.

Any suggestions welcome!
Related Solutions: PHP serial port

Answer : Linux/php serial port read - How to stop fread() waiting forever if no new data?

Maybe you didn't understand the first answer correctly.
Make two programs - One is the php script you have now (but a littlebit modified).
The 2nd is a program that continuously read /writes on the Serial port what ever it's protocol requires and that either gives each change to the first program whenever is requests this. (f.e. by giving a length + data) then even if the amount of data is 0 (no data) you do pass something that it can act upon (the 0 size).

The other possiblity is that you keep a scrolling buffer in the second program (like a video buffer in VGA or a terminal) every time the front end requests it you send the whole current frame to the front end.

The valid method really depends on what you want to do with the data.
Random Solutions  
 
programming4us programming4us