0

我有 2 个工作网页,我正试图将它们合并为一个。第一个是 PHP,按一下按钮,它会打开一个套接字并将一串数据发送到我网络上的设备。

第二个网页有类似的功能,但不是 PHP。此页面有链接到 CGI 脚本的按钮,这些按钮被调用并将数据发送到串行端口。

我想使用 PHP 网页,其中一些按钮的功能与现在一样(打开 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 网页按钮中的功能是 echo -e "OF1/r" > /dev/ttyACM0。该命令向串口发送“OF1/r”。

谢谢!

4

0 回答 0