fread from /dev/ttyS0 without EOF
| From: | Tobias Fritz | Date: | Wed, 04 Jul 2001 10:12:32 +0000 |
| Subject: | fread from /dev/ttyS0 without EOF | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-56153@lists.php.net to get a copy of this message | ||
Hi,
I have a GSM modem connected to /dev/ttyS0 and would like to use php
to communicate with the modem. Writing works perfectly like this:
$fp=fopen("/dev/ttyS0","r+");
fwrite($fp,"AT+CMGL\r");
but reading is a little problem because if the modem for example answers
to the "AT+CMGL" message I sent to it with the command above it does NOT
put an EOF at the end of the stream. For example the following code
while (!feof($fp)) {
print=fgetc($fp);
}
blocks after it read the last char and waits for the next char that will
never come. I tried to use filesize() and
fseek ($fp,0,SEEK_END);
print ftell($fp);
to find out the length of the answer of the modem but it didn't work.
Anybody knows a solution? For example a timeout parameter of fread, fgetc?
Or whatever ...
Thanks
Tobias
--
Sign the Petition for a Software Patent Free Europe:
http://petition.eurolinux.org/
Tobias Fritz
tobias.fritz@gmx.net
http://tobias.fritz.net/