Reading from a COM port in Windows blows up

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I just recently got a new Onkyo TX-SR706 Audio Receiver that has an
RS232 interface and I thought... cool... Build a Web Interface so I
can control it from several rooms away.

The code below works using PHP 5.2.8 under Apache (XAMPP) on Windows
XP to change the current input of my Audio Receiver. So I know at
least one way communication works.

If I swap out !1SLI01 (SeLect Input 01) for !1SLIQSTN which should
query the current input and uncomment the lines that are commented out
below "COM1 Replied". That PHP session and the COM Port itself  lock
up until I reboot the machine.

Being able to query the device would be nice... but isn't strictly
necessary... So I just want to make sure I'm not doing something crazy
/ wrong.

------------------------------------------------------------------------------------------

$Set_Mode = "MODE COM1: BAUD=9600 PARITY=N DATA=8 STOP=1 DTR=OFF RTS=OFF";
exec($Set_Mode, $Output, $Result);

echo "<pre>".implode("\n",$Output)."</pre>";
echo "<br><br>";

switch($Result)
	{
	case 0:	echo "COM1 Configured<br>";		$BadConfig = false; 	break;
	default:	echo "COM1 not configured<br>";	$BadConfig = true;	break;
	}

if(!$BadConfig)
	{
	$ComPort = fopen("COM1", "wb+");

	if(!$ComPort)
		{ echo "COM1 not opened<br>"; }
	else
		{
		echo "COM1 Opened<br>";
		$Command = "!1SLI01\n";
		$result = fwrite($ComPort,$Command);
		if(!$result)
			{ echo "COM1 Error<br>"; }
		else
			{
			echo "COM1 Replied:<br>";
//			$Buffer = fgets($ComPort,1024);
//			while(trim($Buffer) != "")
//				{
//				echo $Buffer."<br>";
//				$Buffer = fgets($ComPort,1024);
//				}
			}
		if(fclose($ComPort)) { echo "COM1 Closed<br>"; }
		}
	}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux