程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

php 必须发送串行数据时,未找到 URL 错误

发布于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/

来源:前端黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

8 0
收藏该文
已收藏

评论内容:(最多支持255个字符)