Skip to first unread message

John McClaire

unread,
Jun 27, 2014, 3:58:16 PM6/27/14
to beagl...@googlegroups.com
Hey guys,

I'm looking for some help with an error I'm getting. I think it's just a syntax sorta thing. 

Here's my python code:

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

William Hermans

unread,
Jun 27, 2014, 5:18:05 PM6/27/14
to beagl...@googlegroups.com


--
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.

John McClaire

unread,
Jun 27, 2014, 5:51:49 PM6/27/14
to beagl...@googlegroups.com
Yeah I saw that, but rushed through it. I'll take a closer look. Thanks for helping the n00b.


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.



--
John McClaire | Creative Technologist 

William Hermans

unread,
Jun 27, 2014, 7:42:46 PM6/27/14
to beagl...@googlegroups.com
Keep in mind I am not all that familiar with Python, but have been programming in multiple other languages since the 90's. Meaning, I dont write code in Python, but can usually read through it ok.

Anyhow, according to that post this error is due to namespace resolution. Meaning . ..

import serial  should instead be from serial import serial

The second answer although seemingly rewarded with more votes is FUD, and would be what I'd consider very bad programming technique.  Never name your project the same as an already existing module.

Miguel Aveiro

unread,
Jun 28, 2014, 1:20:09 AM6/28/14
to beagl...@googlegroups.com
Nope, it's not namespacing. In python it's safe to just "import serial"

You know the problem is due the "call" function.

Instead using:
    except ser.SerialTimeoutException:

use:
 except serial.SerialTimeoutException:

  print('Data could not be read')
 except:
  print 'Error', sys.exc_info()

And see a better log message.
Don't forget to "import sys"

I belive the problem is the "video_player.py" or the ".mp4" files are not in /bin. Or you don't have permission in those files...

Brandon I

unread,
Jun 29, 2014, 7:47:54 AM6/29/14
to beagl...@googlegroups.com
That exception class is an attribute of the serial module, not of the Serial object instance, "ser", that you have there.

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.

John McClaire

unread,
Jun 30, 2014, 5:40:32 PM6/30/14
to beagl...@googlegroups.com
I got it working by adding shell=True to my call function:
call(["bin/video_player.py -s 80x32 -l bin/stufy_animation.mp4"], shell=True)


Reply all
Reply to author
Forward
0 new messages