Raspberry Pi Pin State改变活动 [英] Raspberry Pi Pin State change event

查看:78
本文介绍了Raspberry Pi Pin State改变活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我们正在开发一个涉及反复检查引脚状态高/低的应用程序。如果高,我们应该执行一个函数。有什么方法可以避免长时间的民意调查吗? https://github.com/raspberry-sharp/raspberry-sharp-io/blob/master/Tests/Test.Gpio.WatchPin/Program.cs我得到了单引脚的解决方案但多个引脚没有成功可以解决这个问题问题?

Hi we are developing one application which involves in repeatedly check the pin status high / low. if high we should execute one function. is there any way to avoid long polling ? https://github.com/raspberry-sharp/raspberry-sharp-io/blob/master/Tests/Test.Gpio.WatchPin/Program.cs i got solution for single pin but no success with multiple pins can any one solve this issue ?

推荐答案

不幸的是,我没有使用这个单元,但我知道你必须寻找硬件中断及其处理。以下是我到目前为止所发现的内容:

https://projects.drogon.net/ raspberry-pi / wiringpi / functions [ ^ ](参见 waitForInterrupt wiringPiISR )。



另请参阅线程API。



注意:GPIO可以设置为在输入信号的上升沿,下降沿或两个边沿中断。基本上,您需要在输入信号上的某些外部事件上设置/启用中断。然后你应该在一些你可以允许阻止的线程中调用 waitForInterrupt 。这将是一个阻塞调用,它应该使线程处于等待状态,该状态花费零CPU时间:切换出来并且没有安排执行直到它被某个事件唤醒;其中一个事件是你正在等待的中断。这样,您将避免任何处理器时间的轮询和浪费。



即使没有调用硬件事件,您还应该学习如何终止此系统中的线程。但是如果你提供外部事件,线程将始终通过等待。然后你可以通过检查主要(或其他)线程可以设置的退出标志来循环并退出线程执行。



或者,你可以在 wiringPiISR 的最后一个参数中提供一个处理程序。这样,您可以根据需要处理的每个引脚多次处理多个调用此函数的引脚。由于传递的函数不接受任何参数,因此您可以为每个引脚分别设置处理程序。



我对Raspberry PI的CLR一无所知,但我希望你可以使用它并使用我提到的功能的可用管理类比,或者可以使用P /调用。



-SA
Unfortunately, I did not work with this unit, but I know that you have to look for hardware interrupts and their handling. Here is what I found so far:
https://projects.drogon.net/raspberry-pi/wiringpi/functions[^] (see waitForInterrupt, wiringPiISR).

See also threading API.

Note: "The GPIO can be set to interrupt on a rising, falling or both edges of the incoming signal". Basically, you need to setup/enable interrupts on some external events on incoming signal. Then you should call waitForInterrupt in some thread which you can allow to block. This will be a blocking call which should put the thread in the wait state, which spends zero CPU time: switched out and not scheduled to execution until it is waken up by some event; one of such events is the interrupt you are waiting for. This way, you will avoid any polling and wast of any processor time.

You should also learn how to terminate the thread in this system even if no hardware events are invoked. But if you supply the external event, the thread will always pass the wait. Then you can cycle it and exit the thread execution simply by checking some "exit" flag you could set by your main (or other) thread.

Alternatively, you can supply a handler in the last parameter of wiringPiISR. This way, you can handle multiple pins calling this function several time, per each pin you need to handle. As the function passed accepts no parameters, you can have separate handler for each of the pins.

I know nothing about the CLR of Raspberry PI, but I hope you can use it and use available managed analogs of the functions I mentioned or can make them using P/Invoke.

—SA


这篇关于Raspberry Pi Pin State改变活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆