Esempio n. 1
0
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()
Esempio n. 2
0
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()
Esempio n. 3
0
    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...")
    bridge.setGain(1, BridgeGain.PHIDGET_BRIDGE_GAIN_8)
    sleep(1)

    ##############    Select which bridge to enable   ###################
    print("Enable the Bridge input for reading data...")
    bridge.setEnabled(0, True)
    bridge.setEnabled(1, True)
    bridge.setEnabled(2, True)
    bridge.setEnabled(3, True)
    sleep(1)
    #####################################################################

except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        bridge.closePhidget()
Esempio n. 4
0
    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...")
    bridge.setGain(0, BridgeGain.PHIDGET_BRIDGE_GAIN_8)
    bridge.setGain(1, BridgeGain.PHIDGET_BRIDGE_GAIN_8)
    bridge.setGain(2, BridgeGain.PHIDGET_BRIDGE_GAIN_8)
    bridge.setGain(3, BridgeGain.PHIDGET_BRIDGE_GAIN_8)
    sleep(2)

    print("Enable the Bridge input for reading data...")
    bridge.setEnabled(0, True)
    bridge.setEnabled(1, True)
    bridge.setEnabled(2, True)
    bridge.setEnabled(3, True)
    sleep(2)

except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
Esempio n. 5
0
        exit(1)
    if debug:
       print("Exiting....")
    exit(1)
else:
    displayDeviceInfo()

try:
    if debug:
       print("Set data rate to 1000ms ...")
    bridge.setDataRate(500)
    sleep(2)

    if debug:
       print("Set Gain to 128...")
    bridge.setGain(0, BridgeGain.PHIDGET_BRIDGE_GAIN_128)
    bridge.setGain(1, BridgeGain.PHIDGET_BRIDGE_GAIN_128)
    bridge.setGain(2, BridgeGain.PHIDGET_BRIDGE_GAIN_128)
    bridge.setGain(3, BridgeGain.PHIDGET_BRIDGE_GAIN_128)
    sleep(2)

    if debug:
       print("Enable the Bridge input for reading data...")
    bridge.setEnabled(0, True)
    bridge.setEnabled(1, True)
    bridge.setEnabled(2, True)
    bridge.setEnabled(3, True)
    sleep(2)

except PhidgetException as e:
    if debug: