def openBridge(serialNum): # Create a bridge object try: bridge = Bridge() except RuntimeError as e: print("Runtime Exception: %s" % e.details) print("Exiting....") exit(1) try: bridge.setOnAttachHandler(BridgeAttached) bridge.setOnDetachHandler(BridgeDetached) bridge.setOnErrorhandler(BridgeError) bridge.setOnBridgeDataHandler(BridgeData) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Calibration Script.\nOpening phidget object....") try: bridge.openPhidget(serialNum) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Waiting for attach....") try: bridge.waitForAttach(20000) print("Set data rate to %i ms ..." % (rate)) bridge.setDataRate(rate) sleep(1) print("Set Gain to %s..." % str(gainTable[gain])) setGainAllChanels(bridge, gain) sleep(1) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) try: bridge.closePhidget() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Exiting....") exit(1) else: displayDeviceInfo(bridge) return bridge
def openBridge(serialNum): #Create a bridge object try: bridge = Bridge() except RuntimeError as e: print("Runtime Exception: %s" % e.details) print("Exiting....") exit(1) try: bridge.setOnAttachHandler(BridgeAttached) bridge.setOnDetachHandler(BridgeDetached) bridge.setOnErrorhandler(BridgeError) bridge.setOnBridgeDataHandler(BridgeData) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Calibration Script.\nOpening phidget object....") try: bridge.openPhidget(serialNum) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Waiting for attach....") try: bridge.waitForAttach(20000) print("Set data rate to %i ms ..." % (rate)) bridge.setDataRate(rate) sleep(1) print("Set Gain to %s..." % str(gainTable[gain])) setGainAllChanels(bridge,gain) sleep(1) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) try: bridge.closePhidget() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Exiting....") exit(1) else: displayDeviceInfo(bridge) return bridge
class PhidgetBridge(): def __init__(self): self.bridge = Bridge() self.bridge.setOnAttachHandler(BridgeAttached) self.bridge.setOnDetachHandler(BridgeDetached) self.bridge.setOnErrorhandler(BridgeError) self.bridge.setOnBridgeDataHandler(BridgeData) # self.data_to_be_sent_bridge = [] # self.times_to_be_sent_bridge = [] def open(self,waitTimeMS): self.bridge.openPhidget() try: self.bridge.waitForAttach(waitTimeMS) time.sleep(0.2) self.bridge.setDataRate(8) time.sleep(0.2) self.bridge.setGain(0, BridgeGain.PHIDGET_BRIDGE_GAIN_8) time.sleep(0.2) self.bridge.setEnabled(0, True) time.sleep(0.2) return 1 except: return -1 # def BridgeData(self,e): # timeStamp = time.time() # self.data_to_be_sent_bridge.append(e.value) # self.times_to_be_sent_bridge.append(timeStamp) def getData(self): global data_to_be_sent_bridge global times_to_be_sent_bridge #return the data and times and update the lists data_to_return = [data_to_be_sent_bridge,times_to_be_sent_bridge] data_to_be_sent_bridge = [] times_to_be_sent_bridge = [] return data_to_return def close(self): self.bridge.setEnabled(0,False) time.sleep(2) self.bridge.closePhidget()
class PhidgetBridge(): def __init__(self): self.bridge = Bridge() self.bridge.setOnAttachHandler(BridgeAttached) self.bridge.setOnDetachHandler(BridgeDetached) self.bridge.setOnErrorhandler(BridgeError) self.bridge.setOnBridgeDataHandler(BridgeData) # self.data_to_be_sent_bridge = [] # self.times_to_be_sent_bridge = [] def open(self, waitTimeMS): self.bridge.openPhidget() try: self.bridge.waitForAttach(waitTimeMS) time.sleep(0.2) self.bridge.setDataRate(8) time.sleep(0.2) self.bridge.setGain(0, BridgeGain.PHIDGET_BRIDGE_GAIN_8) time.sleep(0.2) self.bridge.setEnabled(0, True) time.sleep(0.2) return 1 except: return -1 # def BridgeData(self,e): # timeStamp = time.time() # self.data_to_be_sent_bridge.append(e.value) # self.times_to_be_sent_bridge.append(timeStamp) def getData(self): global data_to_be_sent_bridge global times_to_be_sent_bridge #return the data and times and update the lists data_to_return = [data_to_be_sent_bridge, times_to_be_sent_bridge] data_to_be_sent_bridge = [] times_to_be_sent_bridge = [] return data_to_return def close(self): self.bridge.setEnabled(0, False) time.sleep(2) self.bridge.closePhidget()
try: bridge.openPhidget() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Waiting for attach....") try: bridge.waitForAttach(10000) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) try: bridge.closePhidget() except PhidgetException as e: print("Phidget Exception %i: %s\n" % (e.code, e.details)) print("Exiting....") exit(1) print("Exiting....") exit(1) else: displayDeviceInfo() try: print("Set data rate to 40ms ...") bridge.setDataRate(40) sleep(1) print("Set Gain to 8...")
try: bridge.openPhidget() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Waiting for attach....") try: bridge.waitForAttach(10000) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) try: bridge.closePhidget() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Exiting....") exit(1) else: displayDeviceInfo() try: print("Set data rate to 8ms ...") bridge.setDataRate(8) sleep(2) print("Set Gain to 8...")
try: tempBridge.openPhidget(serial) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) if options.verbose: print("Waiting for attach....") try: tempBridge.waitForAttach(20000) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) try: tempBridge.closePhidget() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Exiting....") exit(1) else: lBridges.append(tempBridge) # if options.verbose: displayDeviceInfo(lBridges[len(lBridges)-1]) sleep(1) #Configure settings on each bridge for bridge in lBridges: print("---Configuring %i...---"%bridge.getSerialNum()) try: bridge.setDataRate(int(options.dataRate))
try: tempBridge.openPhidget(serial) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) if options.verbose: print("Waiting for attach....") try: tempBridge.waitForAttach(20000) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) try: tempBridge.closePhidget() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Exiting....") exit(1) else: lBridges.append(tempBridge) # if options.verbose: displayDeviceInfo(lBridges[len(lBridges)-1]) sleep(1) #Configure settings on each bridge for bridge in lBridges: print("---Configuring %i...---" % bridge.getSerialNum()) try: bridge.setDataRate(int(options.dataRate))