View previous topic :: View next topic |
Author |
Message |
cmxflash -
Joined: 11 Dec 2004 Posts: 872
|
Posted: Fri Mar 31, 2006 6:43 pm Post subject: Receiving infrared trough PHP |
|
|
I just found an infrared interface to my computer that uses my COM-port. I use PHP to write to it using this script:
Code: | <?php
$hax = fopen("COM1:", "w+");
fputs ($hax, "This will be sent");
fclose ($hax);
?> |
That script is working, and it sends the text out.
I've tried using it with Hyperterminal, and it works great. If I put my TV-remote in front of it, I can see Hyperterminal is receiving data.
I've also tried using PHP to recive data as well, but got no luck.
Does anyone have any idea of how I could use PHP to recive data from it? |
|
Back to top |
|
 |
Yami King -
Joined: 08 Sep 2005 Posts: 120
|
Posted: Fri Mar 31, 2006 9:18 pm Post subject: |
|
|
change w+ into r+
and change fputs into fread... |
|
Back to top |
|
 |
cmxflash -
Joined: 11 Dec 2004 Posts: 872
|
Posted: Fri Mar 31, 2006 10:26 pm Post subject: |
|
|
Yami King wrote: | change w+ into r+
and change fputs into fread... |
Dosn't work, this is the script I was trying:
Code: |
<?php
while(true) {
$fp = fopen("COM1:", "r+");
$c = fread($fp, 1024);
echo $c;
fclose ($fp);
}
?> |
|
|
Back to top |
|
 |
Yami King -
Joined: 08 Sep 2005 Posts: 120
|
Posted: Fri Mar 31, 2006 11:10 pm Post subject: |
|
|
<?php
while(true) {
$fp = fopen("COM1:", "r+");
$c = fread($fp, 1024);
echo $c;
fclose ($fp);
}
?>
this is quite an ugly and bad code. Because if COM1: keeps returning the true the script keeps trying opening and reading from the COM object.
Use a while(!feof) {} this should work better and put it around the fread instead of instead the fopen! |
|
Back to top |
|
 |
cmxflash -
Joined: 11 Dec 2004 Posts: 872
|
Posted: Sat Apr 01, 2006 12:53 pm Post subject: |
|
|
I tried that before, and it didn't work out.
Code: | <?php
while(1) {
$fp = fopen("COM1:", "r+");
while(!feof($fp)) {
$c = fread($fp, 1024);
echo $c;
echo "."; //Just for testing
}
fclose ($fp);
}
?> |
!feof($fp) never returns true, even if I send data to COM1. |
|
Back to top |
|
 |
|