def __init__(self, handler, channel, type, name): super().__init__() self.name = name self.channel = channel # Again, should check timing using ctypes self.type = ctypes.c_int8(thermocouple_type_map[type]) self.device = handler # Setup individual channel for reading, with couple type check_api_response( usbtc08.usb_tc08_set_channel(self.device, self.channel, self.type))
status = {} # open unit status["open_unit"] = tc08.usb_tc08_open_unit() assert_pico2000_ok(status["open_unit"]) chandle = status["open_unit"] # set mains rejection to 50 Hz status["set_mains"] = tc08.usb_tc08_set_mains(chandle, 0) assert_pico2000_ok(status["set_mains"]) # set up channel # therocouples types and int8 equivalent # B=66 , E=69 , J=74 , K=75 , N=78 , R=82 , S=83 , T=84 , ' '=32 , X=88 typeK = ctypes.c_int8(75) status["set_channel"] = tc08.usb_tc08_set_channel(chandle, 1, typeK) assert_pico2000_ok(status["set_channel"]) # get minimum sampling interval in ms status["get_minimum_interval_ms"] = tc08.usb_tc08_get_minimum_interval_ms( chandle) assert_pico2000_ok(status["get_minimum_interval_ms"]) # get single temperature reading temp = (ctypes.c_float * 9)() overflow = ctypes.c_int16(0) units = tc08.USBTC08_UNITS["USBTC08_UNITS_CENTIGRADE"] status["get_single"] = tc08.usb_tc08_get_single(chandle, ctypes.byref(temp), ctypes.byref(overflow), units) assert_pico2000_ok(status["get_single"])
def monitor_temperatures(cadence): """ Monitor temperatures thread :param cadence: Time between measurements """ global stop_acquisition # Initialise picologger device import ctypes from picosdk.usbtc08 import usbtc08 as tc08 from picosdk.functions import assert_pico2000_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # open unit chandle = None try: ret = tc08.usb_tc08_open_unit() assert_pico2000_ok(ret) chandle = ret except: logging.error( "Could not initialised picologger. Not getting temperatures") return try: # Set mains rejection to 50 Hz status["set_mains"] = tc08.usb_tc08_set_mains(chandle, 0) assert_pico2000_ok(status["set_mains"]) # Set up channels (all type K, cold junction needs to be C) typeC = ctypes.c_int8(67) assert_pico2000_ok(tc08.usb_tc08_set_channel(chandle, 0, typeC)) typeK = ctypes.c_int8(75) for channel in range(1, 9): assert_pico2000_ok( tc08.usb_tc08_set_channel(chandle, channel, typeK)) except: logging.error( "Error while setting up picologger. Not getting temperatures") tc08.usb_tc08_close_unit(chandle) return temp = (ctypes.c_float * 9)() overflow = ctypes.c_int16(0) units = tc08.USBTC08_UNITS["USBTC08_UNITS_CENTIGRADE"] # Read temperatures till told to stop while not stop_acquisition: # Read temperatures try: assert_pico2000_ok( tc08.usb_tc08_get_single(chandle, ctypes.byref(temp), ctypes.byref(overflow), units)) except: logging.error( "Error while getting temperatures, not reading temperatures anymore" ) tc08.usb_tc08_close_unit(chandle) return # Get timestamp timestamp = time.time() # Add RMS to file add_temperatures_to_file(np.array(temp), timestamp) # Sleep for required time time.sleep(cadence)