以下是我用来与微控制器通信的代码。
一切正常,但是当我点击链接html时,它应该通过串口发送数据我得到:
http://project.sonar.com/%3C?=$_SERVER[%27PHP_SELF%27]%20.
The requested URL /< was not found on this server.
我知道通信初始化有效,因为只有在我添加链接
时才会出现此问题 if (isset($_GET['action']))
{
error_reporting(E_ALL);
ini_set('display_errors', '1'); //displays php errors
include("php_serial.class.php");
$serial = new phpSerial();
//$serial -> deviceClose();
$serial->deviceSet('/dev/ttyUSB0'); //for linux serial /dev/ttySP(0-4) for usb /dev/ttyUSBN
// If you want to change the configuration, the device must be closed
$serial->confBaudRate(9600); //Baud rate: 9600
$serial->confParity("none"); //Parity (this is the "N" in "8-N-1")
$serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1")
$serial->confStopBits(2); //Stop bits (this is the "1" in "8-N-1")
$serial->confFlowControl("none");
$serial->deviceOpen();
if ($_GET['action'] == "on")
{
// To write into $serial->sendMessage("1");
for ($x = 1; $x < 20; $x++)
$serial->sendMessage("1");
}
$read = $serial->readPort(); //read stores acii value from controller
if($read > "0")
{
$numberz = 20*ord($read); // number converts the value to decimal representation of distance
//echo "$numberz";
//$database="MEASURE";
$username = "xxxx";
$password = "xxxx";
$hostname = "xxxx";
$connection = mysql_connect($hostname, $username, $password);
if (!$connection)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("MEASURE", $connection);
mysql_query("INSERT INTO measurement (DATA)
VALUES
('$numberz')");
}
else
{
$serial -> deviceClose();
}
}
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" title="currentStyle" media="screen">
@import "style.css";
</style>
<body>
<p><a href="<?=$_SERVER['PHP_SELF'] . "?action=on" ?>">
Click here to turn the system on.</a></p>
<div id="wrapper">
<div id="top">
<ul id="mainmenu">
<li><a href="index.html">HOME</a></li>
<li><a href="measurement2.php">MEASUREMENTS</a></li>
<li><a href="report.html">REPORT</a></li>
<li><a href="contacts.html">CONTACTS</a></li>
</ul>
</div>
<div id="pictop">
<img src="pics/header.jpg"/>
</div>
<div id="main">
<div id="indexleft">
<h2>Table</h2>
<?php
//$database="MEASURE";
$username = "xxxx";
$password = "xxxx";
$hostname = "xxxx";
$connection = mysql_connect($hostname, $username, $password);
if (!$connection)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("MEASURE", $connection);
$result = mysql_query("SELECT * FROM measurement");
echo "<table width='80%' border='4px'>
<tr>
<th>ID</th>
<th>DATA</th>
<th>TIME</th>
</tr>";
while ($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center'>" . $row['ID'] . "</td>";
echo "<td align='center'>" . $row['data'] . "</td>";
echo "<td align='center'>" . $row['TIME'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($connection);
?>
</div>
<div id="bottom">
</div>
</div>
</div>
</body>
</html>
有什么建议吗?谢谢。
答案 0 :(得分:2)
您的服务器可能没有启用短标签。
变化:
<p><a href="<?=$_SERVER['PHP_SELF'] . "?action=on" ?>">
为:
<p><a href="<?php echo $_SERVER['PHP_SELF'] . "?action=on"; ?>">
虽然您可能会将其更改为:
<p><a href="?action=on">
答案 1 :(得分:0)
您网址中的%3c是&lt;字符。没有名为&lt;的目录或文件就不足为奇了。更改您将链接写入的位置:
<?php echo $_SERVER['PHP_SELF'] . "?action=on"; ?>