fsock and fget driving me mad!
| From: | Zac Hillier | Date: | Thu, 11 Jul 2002 14:37:46 +0000 |
| Subject: | fsock and fget driving me mad! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-107143@lists.php.net to get a copy of this message | ||
Hi
Can anyone in the group help, I'm trying to read and write from a serial
port using php.
So far using fsockopen I've managed to open and send data through a serial
port but I'm having real problems reading a response. I've tried fgets
really to no success can anyone spare me some ideas or thoughts?
Setup:
Linux box running serproxy ( A tcp to serial port proxy ) IP 192.168.123.192
I connect to this from a webserver running on another machine with:
<?php
$fp = fsockopen ("192.168.123.192", 5331, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
if(fputs ($fp, "test data".chr(37))){
echo 'data sent';
} else {
echo 'no data sent';
}
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}
?>
The output is being read by a small ap that displays the serial port data
and allows me to send a response, I've logged the response I send at the
linux box on the serial port and serproxy is supposed to translate this back
to tcp port 5331 however I cannot read it with fgets?
Please help it's driving me mad and I'm sure I'm just being stupid : {
Thanks for any help.
Zac