I am using the pySerial library to have a Python script log data from an Arduino. I am trying to handle the SerialException when the script cannot connect to the port you provided, and Eclipse says “Undefined variable: SerialException”. Is there something I forgot to import?
Code:
try:
ser = serial.Serial(port, 9600)
connected = 1
except SerialException:
print "No connection to the device could be established"
You probably want:
in python,
Exceptions are classes derived fromException. So, when a module/package defines it’s own custom exceptions, they usually get imported in the module/packages’s namespace just like the other classes/functions. This said, putting a:at the top of your file would probably also do the trick.