def open_phidget(self):
        #Create an temperaturesensor object
        try:
            temperatureSensor = TemperatureSensor()
        except RuntimeError as e:
            print("Runtime Exception: %s" % e.details)
            print("Exiting....")
            exit(1)

        try:
            temperatureSensor.openPhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)

        try:
            temperatureSensor.waitForAttach(10000)
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            try:
                temperatureSensor.closePhidget()
            except PhidgetException as e:
                print("Phidget Exception %i: %s" % (e.code, e.details))
                print("Exiting....")
                exit(1)
            print("Exiting....")
            exit(1)

        self.sensor = temperatureSensor
        return 1
Exemple #2
0
    def open_phidget(self):
        #Create an temperaturesensor object
        try:
            temperatureSensor = TemperatureSensor()
        except RuntimeError as e:
            print("Runtime Exception: %s" % e.details)
            print("Exiting....")
            exit(1)

        try:
            temperatureSensor.openPhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)

        try:
            temperatureSensor.waitForAttach(10000)
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            try:
                temperatureSensor.closePhidget()
            except PhidgetException as e:
                print("Phidget Exception %i: %s" % (e.code, e.details))
                print("Exiting....")
                exit(1)
            print("Exiting....")
            exit(1)

        self.sensor = temperatureSensor
        return 1
class PhidgetTemperatureSensor:
    
    def __init__(self, sensor_index=0):
        self.sensor_index = sensor_index
        self.lock = threading.RLock()
        self.temp = 0
        self.temperatureSensor = TemperatureSensor()
        self.temperatureSensor.openPhidget()
        print("Waiting for attach....")
        self.temperatureSensor.waitForAttach(10000)
        print "Temperature sensor %s (serial %d)\nSensor type %s input %d" % \
            (self.temperatureSensor.getDeviceName(), 
             self.temperatureSensor.getSerialNum(), 
             self.temperatureSensor.getDeviceType(), 
             self.sensor_index)
        self.temperatureSensor.setTemperatureChangeTrigger(self.sensor_index, 0.05)
        self.temperatureSensor.setOnTemperatureChangeHandler(self._temp_changed)
    
    def close(self):
        self.temperatureSensor.closePhidget()
        
    def _temp_changed(self, e):
        with self.lock:
            self.temp = e.temperature
            
    def get_temperature(self):
        with self.lock:
            return self.temp
Exemple #4
0
class PhidgetTemp():
    def __init__(self):
        self.temperatureSensor = TemperatureSensor()
        self.temperatureSensor.setOnAttachHandler(TemperatureSensorAttached)
        self.temperatureSensor.setOnDetachHandler(TemperatureSensorDetached)
        self.temperatureSensor.setOnErrorhandler(TemperatureSensorError)
        self.temperatureSensor.setOnTemperatureChangeHandler(
            TemperatureSensorTemperatureChanged)
#         self.data_to_be_sent_bridge = []
#         self.times_to_be_sent_bridge = []

    def open(self, waitTimeMS):
        self.temperatureSensor.openPhidget()
        try:
            self.temperatureSensor.waitForAttach(waitTimeMS)
            time.sleep(0.5)
            self.temperatureSensor.setThermocoupleType(
                0, ThermocoupleType.PHIDGET_TEMPERATURE_SENSOR_K_TYPE)
            self.temperatureSensor.setThermocoupleType(
                1, ThermocoupleType.PHIDGET_TEMPERATURE_SENSOR_K_TYPE)
            self.temperatureSensor.setThermocoupleType(
                2, ThermocoupleType.PHIDGET_TEMPERATURE_SENSOR_K_TYPE)
            self.temperatureSensor.setThermocoupleType(
                3, ThermocoupleType.PHIDGET_TEMPERATURE_SENSOR_K_TYPE)
            self.temperatureSensor.setTemperatureChangeTrigger(0, 0.1)
            #             self.temperatureSensor.setTemperatureChangeTrigger(1, 0.1)
            #             self.temperatureSensor.setTemperatureChangeTrigger(2, 0.1)
            #             self.temperatureSensor.setTemperatureChangeTrigger(3, 0.1)
            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):
        #return the data and times and update the lists
        thermocouple0 = self.temperatureSensor.getTemperature(0)
        thermocouple1 = self.temperatureSensor.getTemperature(1)
        thermocouple2 = self.temperatureSensor.getTemperature(2)
        thermocouple3 = self.temperatureSensor.getTemperature(3)
        timeStamp = time.time()
        data_to_return = [
            thermocouple0, thermocouple1, thermocouple2, thermocouple3,
            timeStamp
        ]
        data_to_be_sent_temperature = []
        times_to_be_sent_temperature = []
        return data_to_return

    def close(self):
        self.temperatureSensor.setEnabled(0, False)
        time.sleep(2)
        self.temperatureSensor.closePhidget()
class PhidgetTemp():
    def __init__(self):
        self.temperatureSensor = TemperatureSensor()
        self.temperatureSensor.setOnAttachHandler(TemperatureSensorAttached)
        self.temperatureSensor.setOnDetachHandler(TemperatureSensorDetached)
        self.temperatureSensor.setOnErrorhandler(TemperatureSensorError)
        self.temperatureSensor.setOnTemperatureChangeHandler(TemperatureSensorTemperatureChanged)
#         self.data_to_be_sent_bridge = []
#         self.times_to_be_sent_bridge = []
        
    def open(self,waitTimeMS):
        self.temperatureSensor.openPhidget()
        try:
            self.temperatureSensor.waitForAttach(waitTimeMS)
            time.sleep(0.5)
            self.temperatureSensor.setThermocoupleType(0, ThermocoupleType.PHIDGET_TEMPERATURE_SENSOR_K_TYPE)
            self.temperatureSensor.setThermocoupleType(1, ThermocoupleType.PHIDGET_TEMPERATURE_SENSOR_K_TYPE)
            self.temperatureSensor.setThermocoupleType(2, ThermocoupleType.PHIDGET_TEMPERATURE_SENSOR_K_TYPE)
            self.temperatureSensor.setThermocoupleType(3, ThermocoupleType.PHIDGET_TEMPERATURE_SENSOR_K_TYPE)
            self.temperatureSensor.setTemperatureChangeTrigger(0, 0.1)
#             self.temperatureSensor.setTemperatureChangeTrigger(1, 0.1)
#             self.temperatureSensor.setTemperatureChangeTrigger(2, 0.1)
#             self.temperatureSensor.setTemperatureChangeTrigger(3, 0.1)
            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):
        #return the data and times and update the lists
        thermocouple0 = self.temperatureSensor.getTemperature(0)
        thermocouple1 = self.temperatureSensor.getTemperature(1)
        thermocouple2 = self.temperatureSensor.getTemperature(2)
        thermocouple3 = self.temperatureSensor.getTemperature(3)
        timeStamp = time.time()
        data_to_return = [thermocouple0,thermocouple1,thermocouple2,thermocouple3,timeStamp]
        data_to_be_sent_temperature = []
        times_to_be_sent_temperature = []
        return data_to_return
    
    def close(self):
        self.temperatureSensor.setEnabled(0,False)
        time.sleep(2)
        self.temperatureSensor.closePhidget()
Exemple #6
0
try:
    temperatureSensor.openPhidget()
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)

print("Waiting for attach....")

try:
    temperatureSensor.waitForAttach(10000)
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        temperatureSensor.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    print("Exiting....")
    exit(1)
else:
    DisplayDeviceInfo()

#print("Setting Thermocouple type...")
#temperatureSensor.setThermocoupleType(0, ThermocoupleType.PHIDGET_TEMPERATURE_SENSOR_K_TYPE)

print("Setting sensitivity of the thermocouple....")
temperatureSensor.setTemperatureChangeTrigger(0, 5.00)  #set the amount of degrees to trigger an update.
sleep(1) #sleep for 5 seconds
    print("Could not connect to InterfaceKit. Exiting....")
    exit(1)
else:
    if kit_connected == "Y":
        displayDeviceInfo()

# Make sure thermocouple is attached
try:
    if couple_connected == "Y":
        temperatureSensor.waitForAttach(10000)
        print("Thermocouple connected")
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        if couple_connected == "Y":
            temperatureSensor.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Could not close Thermocouple. Exiting....")
        exit(1)
    print("Could not connect to Thermocouple. Exiting....")
    exit(1)
else:
    if couple_connected == "Y":
        DisplayDeviceInfo()

# Main function: Sensor Value -> Email -> LEDFlash
try:
    SensorValue()
    if kit_connected == "Y":
        LEDon_off()
Exemple #8
0
    def start_measuring(self):
    #Create an temperaturesensor object
        try:
            temperatureSensor = TemperatureSensor()
        except RuntimeError as e:
            print("Runtime Exception: %s" % e.details)
            print("Exiting....")
            exit(1)

        #Information Display Function
        def DisplayDeviceInfo():
            inputCount = temperatureSensor.getTemperatureInputCount()
            print("|------------|----------------------------------|--------------|------------|")
            print("|- Attached -|-              Type              -|- Serial No. -|-  Version -|")
            print("|------------|----------------------------------|--------------|------------|")
            print("|- %8s -|- %30s -|- %10d -|- %8d -|" % (temperatureSensor.isAttached(), temperatureSensor.getDeviceName(), temperatureSensor.getSerialNum(), temperatureSensor.getDeviceVersion()))
            print("|------------|----------------------------------|--------------|------------|")
            print("Number of Temperature Inputs: %i" % (inputCount))
            for i in range(inputCount):
                print("Input %i Sensitivity: %f" % (i, temperatureSensor.getTemperatureChangeTrigger(i)))

        #Event Handler Callback Functions
        def TemperatureSensorAttached(e):
            attached = e.device
            print("TemperatureSensor %i Attached!" % (attached.getSerialNum()))

        def TemperatureSensorDetached(e):
            detached = e.device
            print("TemperatureSensor %i Detached!" % (detached.getSerialNum()))

        def TemperatureSensorError(e):
            try:
                source = e.device
                if source.isAttached():
                    print("TemperatureSensor %i: Phidget Error %i: %s" % (source.getSerialNum(), e.eCode, e.description))
            except PhidgetException as e:
                print("Phidget Exception %i: %s" % (e.code, e.details))

        def TemperatureSensorTemperatureChanged(e):
            try:
                ambient = temperatureSensor.getAmbientTemperature()
            except PhidgetException as e:
                print("Phidget Exception %i: %s" % (e.code, e.details))
                ambient = 0.00

            source = e.device
            # print("TemperatureSensor %i: Ambient Temp: %f -- Thermocouple %i temperature: %f -- Potential: %f" % (source.getSerialNum(), ambient, e.index, e.temperature, e.potential))
            if e.index == 0:
                #print("Temperature: %f" % (e.temperature))
                self.logger.add_row(e.temperature,"-","-")

        #Main Program Code
        try:
        	#logging example, uncomment to generate a log file
            #temperatureSensor.enableLogging(PhidgetLogLevel.PHIDGET_LOG_VERBOSE, "phidgetlog.log")

            temperatureSensor.setOnAttachHandler(TemperatureSensorAttached)
            temperatureSensor.setOnDetachHandler(TemperatureSensorDetached)
            temperatureSensor.setOnErrorhandler(TemperatureSensorError)
            temperatureSensor.setOnTemperatureChangeHandler(TemperatureSensorTemperatureChanged)
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)

        print("Opening phidget object....")

        try:
            temperatureSensor.openPhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)

        print("Waiting for attach....")

        try:
            temperatureSensor.waitForAttach(10000)
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            try:
                temperatureSensor.closePhidget()
            except PhidgetException as e:
                print("Phidget Exception %i: %s" % (e.code, e.details))
                print("Exiting....")
                exit(1)
            print("Exiting....")
            exit(1)
        else:
            DisplayDeviceInfo()

        print("Setting Thermocouple type...")
        temperatureSensor.setThermocoupleType(0, ThermocoupleType.PHIDGET_TEMPERATURE_SENSOR_K_TYPE)

        print("Setting sensitivity of the thermocouple....")
        temperatureSensor.setTemperatureChangeTrigger(0, 0.10)
        sleep(5) #sleep for 5 seconds
        print("Sensitivity of thermocouple index 0 is now %f" % (temperatureSensor.getTemperatureChangeTrigger(0)))

        print("Press Enter to quit....")

        #chr = sys.stdin.read(1)
        while True:
            #print("sensing")
            a = 1

        #print("Closing...")

        try:
            temperatureSensor.closePhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)

        print("Done.")
        exit(0)