""" 
Create a device listener to interrupt the scan
"""
import java.lang.InterruptedException

class Listener (DeviceListener):
    def onStateChanged(self, device, state, former):
        pass
    def onValueChanged(self, device, value, former):
        if value > 1.01:
            print "Value over limit-> aborting"
            abort()

listener = Listener()

ai1.addListener(listener)
try:
    lscan(ao1, (ai1), 0, 40, 200, 0.01) 
except java.lang.InterruptedException:
    print "Aborted"
finally:
    ai1.removeListener(listener)



