Example #1
0
    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("Sensitivity of thermocouple index 0 is now %f" % (temperatureSensor.getTemperatureChangeTrigger(0)))

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

### put the new code here 

csv_file="goose.csv"
in_img="return-pic.jpg"
out_img="left-pic.jpg"
fmt = '%Y-%m-%d %H:%M:%S'

#f = open (csv_file)
#lineList = f.readlines()
#f.close()
#parts=(lineList[-1]).split(',')
#word1=str(parts[4])
Example #2
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)
    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)

print("Closing...")

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

print("Done.")
        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)

print("Closing...")

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

print("Done.")