0

1 つにマージしようとしている 2 つの作業中の Web ページがあります。1 つ目は PHP で、ボタンを押すとソケットが開き、データの文字列がネットワーク上のデバイスに送信されます。

2 番目の Web ページには同様の機能がありますが、PHP ではありません。このページには、呼び出されてシリアル ポートにデータを送信する CGI スクリプトにリンクされたボタンがあります。

PHP Web ページを使用したいのですが、いくつかのボタンは現在のように機能します (PHP ソケットを開き、データを IP アドレスに送信します)。ただし、CGI スクリプトを使用せずにシリアル ポートにデータを送信できるボタンもいくつかあります。ジャバ。

動作する基本的な PHP ページは次のとおりです。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<?php

// Checks to see if button pressed
if(isset($_POST['input'])) {

// Assigns value of button press to $input variable
$input=$_POST['input'];
//echo "$input<br />";

// Open the socket to the IP address
$sock = fsockopen('192.168.5.30:4660', NULL, $errno, $errstr);

// Send the value of the button press to the IP address
fwrite($sock, $input);

// Display the response from the socket on the webpage
echo fread($sock, 4096)."\n";

// Close the socket
fclose($sock); }

// If input is not set, then wait
else {
   //input is not set, do something about it, raise an error, throw an exception, or      whatever


}
?>


<head>
<style type="text/css">

 body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #666666;
margin: 0; 
padding: 0;
text-align: center;
color: #000000;
}

.newStyle1 {
float: left; 
}

.auto-style1 {
color: #FFFFFF;
font-size: 20px;
}

</style>
<title>Audio Control</title>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<body>

<form action="" method="post" >


<fieldset style="display:inline; border:none; padding:0px; margin:0px; vertical-align:top; class="newStyle1" style="height: 450px" >
  <legend align="center"; class="auto-style1">Backyard Audio</legend>
  <br/>
  <button name="input" style="height: 1.8em; width: 10em; font-size: 16px;" value="CL2I1O1T" type="submit">Computer</button>
  <br />
  <br />
  <button name="input" style="height: 1.8em; width: 10em; font-size: 16px;" value="CL2I2O1T" type="submit">Tuner</button>
  <br />
  <br />
  <button name="input" style="height: 1.8em; width: 10em; font-size: 16px;" value="CL2I3O1T" type="submit">Send serial data 1</button>
  <br />
  <br />
  <button name="input" style="height: 1.8em; width: 10em; font-size: 16px;" value="CL2I4O1T" type="submit">Send serial data 2</button>
      <br />
      <br />


</form>
</body>
</html>

そして、これが私が実行している基本的な CGI スクリプトです。

#!/bin/sh -ax

#Send out the serial command in Hex code

 echo -e "OF1/r" > /dev/ttyACM0


#Redirect the browser back to the index page

 echo "Content-type: text/html"
 echo ""
 echo "<html><head><title>Audio Control</title>"
 echo "</head><body>"
 echo "<script type="text/javascript"><!--"
 echo "setTimeout('Redirect()',0);"
 echo " function Redirect(){  location.href = '../index.html';}"
PHP echo " --></script></body></html>"

PHP Web ページのボタンに統合したいと考えている機能は、echo -e "OF1/r" > /dev/ttyACM0 です。このコマンドは、"OF1/r" をシリアル ポートに送信します。

ありがとう!

4

0 に答える 0