"/>
首页 \ 问答 \ Raspberry Pi PHP GPIO读取(Raspberry Pi PHP GPIO read)

Raspberry Pi PHP GPIO读取(Raspberry Pi PHP GPIO read)

我有这个脚本来检查GPIO引脚状态:

<script type="text/javascript">

    $(document).ready(function () {
        // This is the init function
        // Runs when the page has completed loading

        $('#statusCheck').click(function() {
            //console.log('checking status');

            $.ajax({
                url: "check.php",
                success: function (data) {
                    if(data != 1 )
                    {
                      // Door is closed
                      $('#sttext').html('<span style= color:green;>Closed</span>');
                    }
                    else if(data == 1)
                    {
                      // Door is open
                      $('#sttext').html('<span style= color:green;>Open</span>Open');
                    }
                    //$('#debug').html(''); // Print null string to clear message
                    //$('#debug').html(data); // Debug message, printing out read back status.
                }

            });
        });
    });
</script>

这连接到一个按钮和跨度:

   <strong>Status: <span id="sttext"></span></strong></p>
   <button id="statusCheck" class="green-btn">Check Status </button>

检查PHP代码是:

<?php
    system(exec ( "GPIO read 1", $status ));
    system(print_r ( $status ));
?>

我一直输出Closed,虽然引脚设置为1 ...当我从Raspberry Pi上的命令行运行读取它给我1 ....但我认为PHP脚本不起作用...


I've got this script to check the GPIO pin status:

<script type="text/javascript">

    $(document).ready(function () {
        // This is the init function
        // Runs when the page has completed loading

        $('#statusCheck').click(function() {
            //console.log('checking status');

            $.ajax({
                url: "check.php",
                success: function (data) {
                    if(data != 1 )
                    {
                      // Door is closed
                      $('#sttext').html('<span style= color:green;>Closed</span>');
                    }
                    else if(data == 1)
                    {
                      // Door is open
                      $('#sttext').html('<span style= color:green;>Open</span>Open');
                    }
                    //$('#debug').html(''); // Print null string to clear message
                    //$('#debug').html(data); // Debug message, printing out read back status.
                }

            });
        });
    });
</script>

That connects to a button and span:

   <strong>Status: <span id="sttext"></span></strong></p>
   <button id="statusCheck" class="green-btn">Check Status </button>

The check PHP code is:

<?php
    system(exec ( "GPIO read 1", $status ));
    system(print_r ( $status ));
?>

I keeps outputing Closed, though the pin is set at 1... When I run the read from the commandline on the Raspberry Pi it gives me 1.... But the PHP script I think is not working...


原文:https://stackoverflow.com/questions/25103386
更新时间:2023-08-26 20:08

最满意答案

gprof是专门发明的,因为prof只给你“自我时间”。 “自我时间”告诉您在每个例程中找到程序计数器的总时间的百分比。 如果您需要考虑的唯一类型的“瓶颈”通过调用堆栈底部的剃须循环来解决,那就没问题了。

通过减少对子程序的调用次数,你可以解决什么样的“瓶颈”? 这就是gprof应该帮助你找到的,通过“回馈”自己的时间给呼叫者。 例程中的“包容时间”包括其“自我时间”,以及它所调用的例程中的泡沫。 这是gprof所做的一个简单示例:

在这里输入图像描述

A调用B十次,B调用C十次,C执行一些CPU密集型循环10次。 请注意,没有一个样本落在A或B中,因为程序计数器实际上在C. gprof花费了所有时间,通过计算调用,并跟踪谁制作它们,进行一些数学运算并向上传播时间。

所以你看,加速这个程序的方法是让A调用B次数减少,或者让B调用C次数减少,或两者兼而有之。 prof不能给你那种信息 - 你必须猜测。

如果您正在考虑使用gprof ,请注意其问题 ,例如不提供行级信息,对I / O视而不见,对递归感到困惑,并误导您认为某些事情可以帮助您找到问题,例如采样率,调用图,调用计数等。请记住,它的作者只声称它是一个测量工具,而不是一个问题查找工具,即使大多数人认为它是后者。


gprof was invented specifically because prof only gives you "self time". "self time" tells you what fraction of the total time the program counter is found in each routine. That's fine if the only kinds of "bottlenecks" you need to consider are solved by shaving cycles at the bottom of the call stack.

What about the kind of "bottleneck" that you solve by reducing the number of calls to subroutines? That's what gprof was supposed to help you find, by "charging back" self time to callers. "inclusive time" in a routine consists of its "self time", plus what bubbles up from the routines it calls. Here's a simple example of what gprof does:

enter image description here

A calls B ten times, and B calls C ten times, and C does some CPU-intensive loop for 10 sample times. Notice that none of the samples land in A or B because the program counter spends practically all of its time in C. gprof, by counting the calls, and keeping track of who made them, does some math and propagates time upward.

So you see, a way to speed up this program is to have A call B fewer times, or have B call C fewer times, or both. prof could not give you that kind of information - you'd have to guess.

If you're thinking of using gprof, be aware of its problems, like not giving line-level information, being blind to I/O, getting confused by recursion, and misleading you into thinking certain things help you find problems, like sample rate, call graph, invocation counts, etc. Keep in mind that its authors only claimed it was a measurement tool, not a problem-finding tool, even though most people think it's the latter.

相关问答

更多
  • 除非你改变处理,否则gprof会正常工作。 更改处理意味着使用协处理器或gpus作为计算单元。 在最坏的情况下,您必须为每个线程手动调用setitimer函数。 但根据最新版本(2013-14),不需要它。 在某些情况下,它表现得很顽皮。 所以我建议使用英特尔的VTUNE,它可以提供更准确,更详细的信息。 Unless you change the processing the gprof would work fine. Changing the processing means using co-pro ...
  • 如果我是正确的,这可以粗略地转化为: // Typedef for brevity typedef vector::iterator uv_iter; // Actual function uv_iter::difference_type operator-(const uv_iter &, const uv_iter &); 所以,它可能是指计算矢量两个迭代器之间差异(=距离)的函数。 无论如何,当优化器在这样的功能上实际上应该被转换成简单的内联指针比较。 If ...
  • 这是一个glibc错误/限制: -pg -pie不起作用 如果您无法安装固定的glibc,可以使用-no-pie链接以禁用PIE。 您的工具链可能会自动启用PIE。 This is a glibc bug/limitation: -pg -pie doesn't work If you cannot install a fixed glibc, you can link with -no-pie to disable PIE. Your toolchain probably enables PIE auto ...
  • 很抱歉这个问题,似乎代码比gprof更快。 由于我的应用程序涉及具有多次迭代和进一步测试内核的神经网络序列,我并不怀疑快速代码可能导致问题。 我在主体中插入了一个长循环,并打印了gprof时间。 Sorry for the question, seems that the code is faster than gprof can measure. As my application involves a neural network train with several iterations and fu ...
  • 我能够确定有问题的函数是使用callgrind的第三方库的一部分 。 原始callgrind.out文件包含程序中函数的列表。 其中包括哪些函数被称为每个函数运行的一部分。 使用这个,我能够跟踪有问题的函数,直到我到达一个属于库API的函数。 至于优化的目标,占用大部分运行时间(> 75%)的API函数不能被调用的次数更少。 这使得发现其他热点变得困难(尽管不是不可能)。 I was able to determine that the functions in question were part of ...
  • 你想要速度吧? -Ofast仅在调用堆栈的底部-Ofast 。 它无法修复只有你可以修复的东西。 它只会让他们更难找到。 首先关闭优化器并修复可以修复的问题。 以下是一些人如何做到这一点的例子。 当你尽可能地离开时,打开优化器,让它发挥它的魔力。 小火焰:)很多人说配置未经优化的代码是浪费时间,但他们从不说明原因 。 他们在一个演讲厅里听到它,在博客上阅读,或者从stackoverflow,在一个明确的权威主义者无需给出理由的人身上听到它。 我认为这是一厢情愿的想法:我的代码基本上是完美的,所以加速的唯一方 ...
  • gprof是专门发明的,因为prof只给你“自我时间”。 “自我时间”告诉您在每个例程中找到程序计数器的总时间的百分比。 如果您需要考虑的唯一类型的“瓶颈”通过调用堆栈底部的剃须循环来解决,那就没问题了。 通过减少对子程序的调用次数,你可以解决什么样的“瓶颈”? 这就是gprof应该帮助你找到的,通过“回馈”自己的时间给呼叫者。 例程中的“包容时间”包括其“自我时间”,以及它所调用的例程中的泡沫。 这是gprof所做的一个简单示例: A调用B十次,B调用C十次,C执行一些CPU密集型循环10次。 请注意,没 ...
  • 根据这个文档 , _fini是一个曾经包含在库中的函数,每当卸载库时都会调用它。 它也可能是许多对象被创建和销毁的症状(在无法看到它的封面下)。 当缓慢的原因在其他地方时, gprof经常指向函数。 这只是众多问题中的一个。 如果你想从你的程序中消除浪费周期, 这就是很多人所做的事情 ,并且它有效。 According to this doc, _fini is a function that used to be included in libraries, and it would be called ...
  • 是的,可以借助此处描述的解决方法。 Yes, it is possible with the help of a workaround described here.
  • 我认为你的推理存在一个根本性的缺陷:优化版本需要68%的执行时间而未优化版本的执行时间仅为9%意味着未经优化的版本表现更好。 相反,我确信-O3版本在绝对值上表现更好,但优化器在其他函数上做得更好,因此, 与优化代码的其余部分成比例 ,给定的子例程结果更慢 -但它实际上比未经优化的版本更快 - 或者至少更快。 不过,要直接检查发出的代码的差异,您可以使用-S开关。 另外,为了看看我的想法是否正确,您可以粗略地比较-O0与-03中的函数占用的CPU时间乘以该百分比与您的程序所提供的用户时间所占用的time ( ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。