AttributeError: 'NoneType' object has no attribute 'send' pigpiod
AttributeError: 'NoneType' object has no attribute 'send' pigpiod
所以我创建了另一个程序,可以 运行 步进电机顺时针和逆时针旋转,并在那里进行斜坡上升和斜坡下降,并在 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)
?谢谢你
小记:我通过follow(https://raspberrypi.stackexchange.com/questions/70568/how-to-run-pigpiod-on-boot KimSJ answer)设置了pigpiod daemon start on boot,是运行img pigpiod 的方法导致了这个错误吗?谢谢
更新:
在我清除 pi.read(26)
和 pi.read(26)
上的 pi.stop()
并将 pigpiod 版本更新为 v68 后,所有内容 运行 正确无误
在我清除 pi.read(26)
和 pi.read(26)
上的 pi.stop()
并将 pigpio 版本更新到 v68 后,一切 运行 正确无误
所以我创建了另一个程序,可以 运行 步进电机顺时针和逆时针旋转,并在那里进行斜坡上升和斜坡下降,并在 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)
?谢谢你
小记:我通过follow(https://raspberrypi.stackexchange.com/questions/70568/how-to-run-pigpiod-on-boot KimSJ answer)设置了pigpiod daemon start on boot,是运行img pigpiod 的方法导致了这个错误吗?谢谢
更新:
在我清除 pi.read(26)
和 pi.read(26)
上的 pi.stop()
并将 pigpiod 版本更新为 v68 后,所有内容 运行 正确无误
在我清除 pi.read(26)
和 pi.read(26)
上的 pi.stop()
并将 pigpio 版本更新到 v68 后,一切 运行 正确无误