[[home/harland/serial.py]]

kwatters

9 years 11 months ago

if you have a line of code that can blow up and throw an exception.  you can wrap it in a try/except block in python like the following.

 

the "pass" line says, move along, these aren't the errors you're looking for.



try:
  ser.foobar()
except:
  print "oops. it blew up"
  pass

This is a bit of a strange way to do it.. but we start by defining a byte array of length 1

This is the input buffer.  if we pass in a byte array to the read method, we can also pass a time out.

the ser.read(buff, timeoutMS) will return the number of chars read into the buffer 

 

 

buff = [0]
print "Reading 1 byte"
numread = ser.read(buff, 1000)
print "Done waiting"