Ejemplo n.º 1
0
    def load_devices(self, sources):
        devices = []
        handler = ctypes.c_int16()

        # Get list if ports
        device_ports = []
        for source in sources:
            device_ports.append(source["port"])
        device_ports.sort()

        for device in sources:
            # Using ctypes Handler like PicoSDK Example
            response = usbtc08.usb_tc08_open_unit()
            if response == 0:
                # Returns zero when no unopened units left
                break
            if response not in device_ports:
                check_api_response(usbtc08.usb_tc08_close_unit(handler))
                break
            else:
                # Check if opened sucessfully, and assign handler
                handler = check_api_response(response)
                # Set each device to reject either 50 or 60 Hz interference
                # 1: Reject 60Hz, 2: Reject 50Hz
                check_api_response(usbtc08.usb_tc08_set_mains(handler, 0))
            devices.append(handler)

        return devices
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"])

# print data
print("Cold Junction ", temp[0], " Channel 1 ", temp[1])

# close unit
status["close_unit"] = tc08.usb_tc08_close_unit(chandle)
assert_pico2000_ok(status["close_unit"])

# display status returns
print(status)
Ejemplo n.º 3
0
 def cleanup(self):
     # Closes all devices
     for handler in self.devices:
         check_api_response(usbtc08.usb_tc08_close_unit(handler))
     self.logger.info("Closed all devices.")
Ejemplo n.º 4
0
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)