问题出现在Python3-libgpiod中的’event_wait’。

huangapple go评论84阅读模式
英文:

Problem with 'event_wait' in python3-libgpiod

问题

I am working with a Debian 11 (bullseye) based system on an aarch64 chip. The affected libraries are:

libgpiod2 1.6.2-1

python3-libgpiod 1.6.2-1

The Problem occurs in the following example:

import gpiod

GPIO_CHIP = "/dev/gpiochip0"
INPUT = 26

def main():
    chip = gpiod.Chip(GPIO_CHIP)
    line = chip.get_line(INPUT)
    line.request(consumer="GPOUT", type=gpiod.LINE_REQ_DIR_IN, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)
    while True:
        if line.event_wait(600):
            event = line.event_read()
            print(event)

main()

The problem is that the method event_wait from the class gpiod.Line immediately returns True, and the call to event_read then leads to the following error:

Traceback (most recent call last):
  File "/home/tegeth1/./IO_test_event.py", line 18, in <module>
    main()
  File "/home/tegeth1/./IO_test_event.py", line 15, in main
    event = line.event_read()
PermissionError: [Errno 1] Operation not permitted

because there is no event in the event-queue.

This behavior does not occur if I just use:

$ gpiomon 0 26 

on the command line.

Even this other python example, works as expected:

import gpiod
import select

GPIO_CHIP = "/dev/gpiochip0"
INPUT = 26

def main():
    chip = gpiod.Chip(GPIO_CHIP)
    line = chip.get_line(INPUT)
    line.request(consumer="GPOUT", type=gpiod.LINE_REQ_EV_BOTH_EDGES, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)
    fd = line.event_get_fd()
    poll = select.poll()
    poll.register(fd)
    while True:
        poll.poll(None)
        event = line.event_read()
        print(event)

main()

I have already tried different biases and executed the script also on a Raspberry Pi (same chip architecture, comparable OS) with the same result. What am I doing wrong? I would appreciate any help.

Many thanks and best regards,

Cone

英文:

I am working with a Debian 11 (bullseye) based system on a aarch64 chip. The affected libraries are:

libgpiod2 1.6.2-1

python3-libgpiod 1.6.2-1

The Problem occurs in the following example:

import gpiod

GPIO_CHIP = &quot;/dev/gpiochip0&quot;
INPUT = 26

def main():
    chip = gpiod.Chip(GPIO_CHIP)
    line = chip.get_line(INPUT)
    line.request(consumer=&quot;GPOUT&quot;, type=gpiod.LINE_REQ_DIR_IN, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)
    while True:
        if line.event_wait(600):
            event = line.event_read()
            print(event)

main()

The problem is that the method event_wait from the class gpiod.Line immediately with a True returns and the call of event_read then leads to the following error:

Traceback (most recent call last):
  File &quot;/home/tegeth1/./IO_test_event.py&quot;, line 18, in &lt;module&gt;
    main()
  File &quot;/home/tegeth1/./IO_test_event.py&quot;, line 15, in main
    event = line.event_read()
PermissionError: [Errno 1] Operation not permitted

because there is no event in the event-queue.

This behaviour does not occur if I just use:

$ gpiomon 0 26 

on the command line.
Even this other python example, works as expected:

import gpiod
import select

GPIO_CHIP = &quot;/dev/gpiochip0&quot;
INPUT = 26

def main():
    chip = gpiod.Chip(GPIO_CHIP)
    line = chip.get_line(INPUT)
    line.request(consumer=&quot;GPOUT&quot;, type=gpiod.LINE_REQ_EV_BOTH_EDGES, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)
    fd = line.event_get_fd()
    poll = select.poll()
    poll.register(fd)
    while True:
        poll.poll(None)
        event = line.event_read()
        print(event)

main()

I have already tried different biases and executed the script also on a Raspberry Pi (same chip architecture, comparable OS) with the same result. What am I doing wrong? I would appreciate any help.

Many thanks and best regards,

Cone

Edit: If you ask, why I am not simply using the second solution, look here

答案1

得分: 1

根据第二个Python示例,要接收事件,必须使用类型之一来请求该行,例如LINE_REQ_EV_BOTH_EDGES

在您的第一个示例中,您请求它作为普通输入线,使用类型LINE_REQ_DIR_IN,它不支持中断或生成边缘事件。相反,当您尝试以未请求的方式使用它时,它会返回错误。

英文:

As per the second Python example, to receive event the line must be requested with type being one of the LINE_REQ_EV_ types, such as LINE_REQ_EV_BOTH_EDGES.

What you do in your first example is request it as a plain input line, with type LINE_REQ_DIR_IN, which does not support interrupts or generate edge events. Instead it returns errors when you try to use it in a way that you did not request it for.

huangapple
  • 本文由 发表于 2023年7月13日 15:10:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676779.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定