Receiving infrared trough PHP

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Fri Mar 31, 2006 6:43 pm    Post subject: Receiving infrared trough PHP Reply with quote

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 View user's profile Send private message
Yami King
-


Joined: 08 Sep 2005
Posts: 120

PostPosted: Fri Mar 31, 2006 9:18 pm    Post subject: Reply with quote

change w+ into r+
and change fputs into fread...
Back to top View user's profile Send private message Send e-mail
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Fri Mar 31, 2006 10:26 pm    Post subject: Reply with quote

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 View user's profile Send private message
Yami King
-


Joined: 08 Sep 2005
Posts: 120

PostPosted: Fri Mar 31, 2006 11:10 pm    Post subject: Reply with quote

<?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 View user's profile Send private message Send e-mail
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Sat Apr 01, 2006 12:53 pm    Post subject: Reply with quote

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 View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group