发布于2021-11-18 21:03 阅读(1218) 评论(0) 点赞(8) 收藏(5)
这是我用来与微控制器通信的代码。
一切正常,但是当我单击应该通过串行发送数据的链接 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>
有什么建议?谢谢你。
您的服务器可能没有启用短标签。
改变:
<p><a href="<?=$_SERVER['PHP_SELF'] . "?action=on" ?>">
到:
<p><a href="<?php echo $_SERVER['PHP_SELF'] . "?action=on"; ?>">
尽管您可能可以将其更改为:
<p><a href="?action=on">
作者:黑洞官方问答小能手
链接:http://www.qianduanheidong.com/blog/article/232454/33d1a6b707a27780ef5f/
来源:前端黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 前端黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-3
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!