import serial
import time
from subprocess import call
ser = serial.Serial( "/dev/ttyACM0" , 9600 )
while 1:
try:
ard = ser.readline()
if('smile' in ard):
print 'Smiling'
call(["bin/video_player.py -s 80x32 -l bin/smile.mp4"])
elif('laugh' in ard):
print 'Laughing'
call(["bin/video_player.py -s 80x32 -l bin/laugh.mp4"])
elif('wink' in ard):
print 'Winking'
call(["bin/video_player.py -s 80x32 -l bin/wink.mp4"])
time.sleep(1)
except ser.SerialTimeoutException:
print('Data could not be read')
time.sleep(1)
---------------------------------------------------------------------------------------------------
And here's the error I'm receiving (happens because when I try to call a subprocess):
File "commands.py", line 23, in <module>
except ser.SerialTimeoutException:
AttributeError: 'Serial' object has no attribute 'SerialTimeoutException'
---------------------------------------------------------------------------------------------------
Thanks for the help!
- John
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to a topic in the Google Groups "BeagleBoard" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beagleboard/B1qWMFAdcsQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beagleboard...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
So catch serial.SerialException.
I think you're importing and handling the exceptions fine. For importing, you won't be able to access all the other stuff in the serial module if you just import the Serial class. Also, polluting the global name space makes things confusing for those reading your code ("where did this come from?" rather than, "this is obviously from the serial module").
For the exception, there's no reason to catch all here. Catch what you expect and leave the regular traceback for the rest.