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

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

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:

  1. import gpiod
  2. GPIO_CHIP = "/dev/gpiochip0"
  3. INPUT = 26
  4. def main():
  5. chip = gpiod.Chip(GPIO_CHIP)
  6. line = chip.get_line(INPUT)
  7. line.request(consumer="GPOUT", type=gpiod.LINE_REQ_DIR_IN, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)
  8. while True:
  9. if line.event_wait(600):
  10. event = line.event_read()
  11. print(event)
  12. 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:

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

because there is no event in the event-queue.

This behavior does not occur if I just use:

  1. $ gpiomon 0 26

on the command line.

Even this other python example, works as expected:

  1. import gpiod
  2. import select
  3. GPIO_CHIP = "/dev/gpiochip0"
  4. INPUT = 26
  5. def main():
  6. chip = gpiod.Chip(GPIO_CHIP)
  7. line = chip.get_line(INPUT)
  8. line.request(consumer="GPOUT", type=gpiod.LINE_REQ_EV_BOTH_EDGES, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)
  9. fd = line.event_get_fd()
  10. poll = select.poll()
  11. poll.register(fd)
  12. while True:
  13. poll.poll(None)
  14. event = line.event_read()
  15. print(event)
  16. 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:

  1. import gpiod
  2. GPIO_CHIP = &quot;/dev/gpiochip0&quot;
  3. INPUT = 26
  4. def main():
  5. chip = gpiod.Chip(GPIO_CHIP)
  6. line = chip.get_line(INPUT)
  7. line.request(consumer=&quot;GPOUT&quot;, type=gpiod.LINE_REQ_DIR_IN, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)
  8. while True:
  9. if line.event_wait(600):
  10. event = line.event_read()
  11. print(event)
  12. 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:

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

because there is no event in the event-queue.

This behaviour does not occur if I just use:

  1. $ gpiomon 0 26

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

  1. import gpiod
  2. import select
  3. GPIO_CHIP = &quot;/dev/gpiochip0&quot;
  4. INPUT = 26
  5. def main():
  6. chip = gpiod.Chip(GPIO_CHIP)
  7. line = chip.get_line(INPUT)
  8. line.request(consumer=&quot;GPOUT&quot;, type=gpiod.LINE_REQ_EV_BOTH_EDGES, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)
  9. fd = line.event_get_fd()
  10. poll = select.poll()
  11. poll.register(fd)
  12. while True:
  13. poll.poll(None)
  14. event = line.event_read()
  15. print(event)
  16. 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:

确定