PHP按钮将数据发送到串行端口(而不是CGI脚本

时间:2013-08-03 16:29:53

标签: php html sockets cgi

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

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

我想使用PHP网页,其中一些按钮现在正常运行(打开PHP套接字并将数据发送到IP地址),但也有一些按钮可以将数据发送到串口而不使用CGI脚本或Java。

以下是适用的基本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”&gt;的/ dev / ttyACM0。此命令将“OF1 / r”发送到串行端口。

谢谢!

0 个答案:

没有答案