我在GPIO引脚上触发了一个回调方法,当被触发时,会调用输入设备寄存器的读取,但是当调用时,我得到-
追溯(最近一次调用):NewPins x= self.mcp.readGPIO() AttributeError:'int‘对象中的文件“/home/编码器/Try2.py”,第35行没有属性'mcp’。
如果我从python输入- 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’
发布于 2019-07-21 12:21:55
好吧,我的哑巴..。-我使用的RPiGPIO库返回回调中的GPIO通道号,因此回调函数需要两个参数,而不是一个参数。我原以为我搞砸了我的命名空间,所以当我遇到上面的错误时,我正试图编写代码--我是一个新手python程序员,不知道该在哪里查找!那会教我不要彻底阅读文件..。
https://stackoverflow.com/questions/56881513
复制相似问题