【发布时间】:2019-07-04 06:01:54
【问题描述】:
我在 GPIO 引脚上触发了一个回调方法,该方法在触发时会调用读取输入设备寄存器,但是在调用时我得到 -
Traceback(最近一次调用最后一次): 文件“/home/coder/Try2.py”,第 35 行,在 NewPins 中 x = self.mcp.readGPIO() AttributeError:“int”对象没有属性“mcp”
如果我输入-
a.mcp.readGPIO()
`BitArray('0xffff')` <-expected result
>>>
RotaryEncoder 类被实例化为 'a'
`class RotaryEncoder:`
`def __init__(self,IntPin, Start, Id):`
.... initialise some variables then open the device as 'mcp' -
`self.mcp = MCP23S17(bus=0x00, pin_cs=0x00, device_id=Id)`
`self.mcp.open()`
`def NewPins(self):`
` global OldPins`
` x = self.mcp.readGPIO()`
..... irrelevant code
回调线是
gpio.add_event_detect(IntPin, gpio.FALLING, callback=NewPins)
预期的读取值为 BitArray 实际结果是 AttributeError:“int”对象没有属性“mcp”
【问题讨论】:
标签: python-3.x class