工具/软件:
我正在为光学编码器编写一些 python 代码、但我收到了一个不明白的错误。 我能否解释一下为什么会出现此错误? 我已对其进行了研究、两种变体都应有效。
我的代码:
import TI.GPIO as GPIO import gpiod import time # Update these according to your board's GPIO chip and line numbers CHIP_NAME = '/dev/gpiochip0' PIN_A = 13 # Replace with actual GPIO line number for A PIN_B = 16 # Replace with actual GPIO line number for B chip = gpiod.Chip(CHIP_NAME) line_a = chip.get_line_info(PIN_A) line_b = chip.get_line_info(PIN_B) # Request lines as inputs with bias disabled config = gpiod.LineRequest(consumer="rotary-encoder", request_type=gpiod.LineRequest.DIRECTION_INPUT) #config.consumer = "rotary-encoder" #config.request_type = gpiod.LineRequest.DIRECTION_INPUT
我的错误:
root@am62pxx-EVM:~/ti-am62p# python3 ai_test_chcp.py
回溯(最近一次呼叫):
文件“/root/ti-am62p/ai_test_chcp.py、第 15 行、在中
config = gpiod.LineRequest (Consumer=“旋转编码器“、request_type=gpiod.LineRequest.direction_input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^μ s
AttributeError:类型对象“LineRequest"没有“没有属性“Idrection_input"</s>“
我还尝试了:
chip = gpiod.Chip('/dev/gpiochip0')
lineA = chip.get_line_info(LINE_A)
lineB = chip.get_line_info(LINE_B)
config = gpiod.LineRequest()
config.consumer - "rotary"
config.request_type = gpiod.LineRequest.DIRECTION_INPUT
config.event_flags = gpiod.LineRequest.EVENT_BOTH_EDGES
我的错误:
root@am62pxx-EVM:~/ti-am62p# python3 test_chcp.py
回溯(最近一次呼叫):
文件“/root/ti-am62p/test_chcp.py、第 74 行、在中
main()
文件/root/ti-am62p/test_chcp.py、第 41 行、位于 main 中
配置= gpiod.LineRequest ()
^^^^^^^^^^^^^^^^^^^μ s
类型错误: LineRequest.__init__() 缺少 1 个必需的位置参数:'req'