AttributeError:'NoneType'对象没有属性'send'Pigpiod

时间:2018-12-04 22:15:44

标签: python-3.x raspberry-pi3 gpio

因此,我创建了另一个程序,该程序可以在其中顺时针和逆时针运行步进电机,并在其中进行斜坡上升和下降,并在GPIO 16和26上添加限幅器开关以停止pi.wave_send_using_mode(wid2, pigpio.WAVE_MODE_ONE_SHOT_SYNC)给出链波,这是我的代码:

import time
import pigpio

START_DELAY=600
FINAL_DELAY=500
STEP=1

GPIO=20

pi = pigpio.pi()

pi.set_mode(GPIO, pigpio.OUTPUT)
pi.set_mode(21, pigpio.OUTPUT)
pi.set_mode(26,pigpio.INPUT)
pi.set_mode(16,pigpio.INPUT)
#pi.write(21,1)
pi.wave_clear()

statee = 0
try:
    while True:

        pi.write(21,statee)
        pi.wave_clear()

        wf=[]
        offset = pi.wave_get_micros()
        for delay in range(START_DELAY, FINAL_DELAY, -STEP):
           wf.append(pigpio.pulse(1<<GPIO, 0,       delay))
           wf.append(pigpio.pulse(0,       1<<GPIO, delay))

        for i in range(500):
            wf.append(pigpio.pulse(1<<GPIO, 0,       FINAL_DELAY))
            wf.append(pigpio.pulse(0,       1<<GPIO, FINAL_DELAY))
        wf.append(pigpio.pulse(0, 0, offset))

        for delay in range(FINAL_DELAY, START_DELAY, STEP):
           wf.append(pigpio.pulse(1<<GPIO, 0,       delay))
           wf.append(pigpio.pulse(0,       1<<GPIO, delay))

        pi.wave_add_generic(wf)

        wid2 = pi.wave_create()

        #pi.wave_send_once(wid2)
        pi.wave_send_using_mode(wid2, pigpio.WAVE_MODE_ONE_SHOT_SYNC)

        if pi.read(26) == 0:
            pi. wave_tx_stop()
            pi.stop()
        if pi.read(16) == 0:
            pi.wave_tx_stop()
            pi.stop()

        time.sleep(0.75)
        if statee == 0:
            statee = 1
        elif statee == 1:
            statee = 0
except KeyboardInterrupt:
    print ("\nCtrl-C pressed.  Stopping PIGPIO and exiting...")
    pi.wave_tx_stop()
    pi.stop()

当马达运行5到10分钟左右时会发生问题,我给出如下错误消息:

Traceback (most recent call last):


File "/home/pi/Desktop/ramp.py", line 49, in <module>
    if pi.read(16) == 0:
  File "/usr/local/lib/python3.4/dist-packages/pigpio.py", line 1401, in read
    return _u2i(_pigpio_command(self.sl, _PI_CMD_READ, gpio, 0))
  File "/usr/local/lib/python3.4/dist-packages/pigpio.py", line 989, in _pigpio_command
    sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))
AttributeError: 'NoneType' object has no attribute 'send'

那么,我的代码中的错误原因是什么?是由pi.read(26)pi.read(16)引起的吗?还有其他方法可以在过程中间停止或终止pi.wave_send_using_mode(wid2, pigpio.WAVE_MODE_ONE_SHOT_SYNC)吗?谢谢 小提示:我将Pigpiod守护程序设置为通过以下方式在启动时启动(https://raspberrypi.stackexchange.com/questions/70568/how-to-run-pigpiod-on-boot KimSJ回答),runimg Pigpiod的方法是否会导致此错误?谢谢

更新:  在我清除pi.stop()pi.read(26)上的pi.read(26)并将Pigpiod版本更新为v68之后,所有内容都会正确运行而没有错误

1 个答案:

答案 0 :(得分:1)

在我清除pi.stop()pi.read(26)上的pi.read(26)并将Pigpiod版本更新为v68之后,所有内容都会正确运行而没有错误