Exemple #1
0
def read_stuff():
    a_list = []
    _thread.start_new_thread(input_thread, (a_list, ))

    while not a_list:  #Checks for termination keystroke on separate thread

        try:  # If no term. keystroke, collect data

            ser.write(send_string)  #Sends command send_string to serial port

            # Read 2 bytes and converts to integer as little endian,
            # assign to read_serial
            read_serial = struct.unpack('<H', ser.read(size=2))

            scanvalue = ul.t_in(board_num, channel, tempscale)

            csvData = [
                datetime.datetime.now().timestamp(), read_serial[0], scanvalue
            ]

            print(csvData)
            writeCSV.writerow(csvData)
            time.sleep(1)

        except ULError as e:
            # Display the error
            print("A UL error occurred. Code: " + str(e.errorcode) +
                  " Message: " + e.message)
            break
Exemple #2
0
def run_example():
    board_num = 0

    if use_device_detection:
        ul.ignore_instacal()
        if not util.config_first_detected_device(board_num):
            print("Could not find device.")
            return

    channel = 0

    ai_props = AnalogInputProps(board_num)
    if ai_props.num_ti_chans < 1:
        util.print_unsupported_example(board_num)
        return

    try:
        # Get the value from the device (optional parameters omitted)
        value = ul.t_in(board_num, channel, TempScale.CELSIUS)

        # Display the value
        print("Channel " + str(channel) + " Value (deg C): " + str(value))
    except ULError as e:
        util.print_ul_error(e)
    finally:
        if use_device_detection:
            ul.release_daq_device(board_num)
Exemple #3
0
    def getTemp(self):
        if not self.isInit:
            print("Device Not Initialized")
            return 0
        try:
            startTime = time.time()
            # Get the value from the device (optional parameters omitted)
            value = ul.t_in(self.board_num, self.channel, TempScale.CELSIUS)

            # Display the value
            #print("Channel " + str(self.channel) + " Value (deg C): " + str(value))
            #print("Temp acquisition time is : {}".format(time.time()-startTime))
            return value
        except ULError as e:
            util.print_ul_error(e)
            return 0
Exemple #4
0
    def update_value(self):
        channel = self.get_channel_num()

        try:
            # Get a value from the device
            value = ul.t_in(self.board_num, channel, TempScale.CELSIUS)

            # Display the raw value
            self.value_label["text"] = '{:.3f}'.format(value)

            # Call this method again until the stop button is pressed (or an
            # error occurs)
            if self.running:
                self.after(100, self.update_value)
        except ULError as e:
            self.stop()
            show_ul_error(e)
Exemple #5
0
def run_example():
    # By default, the example detects and displays all available devices and
    # selects the first device listed. Use the dev_id_list variable to filter
    # detected devices by device ID (see UL documentation for device IDs).
    # If use_device_detection is set to False, the board_num variable needs to
    # match the desired board number configured with Instacal.
    use_device_detection = True
    dev_id_list = []
    board_num = 0

    try:
        if use_device_detection:
            config_first_detected_device(board_num, dev_id_list)

        daq_dev_info = DaqDeviceInfo(board_num)
        if not daq_dev_info.supports_analog_input:
            raise Exception('Error: The DAQ device does not support '
                            'analog input')

        print('\nActive DAQ device: ',
              daq_dev_info.product_name,
              ' (',
              daq_dev_info.unique_id,
              ')\n',
              sep='')

        ai_info = daq_dev_info.get_ai_info()
        if ai_info.num_temp_chans <= 0:
            raise Exception('Error: The DAQ device does not support '
                            'temperature input')
        channel = 0

        # Get the value from the device (optional parameters omitted)
        value = ul.t_in(board_num, channel, TempScale.CELSIUS)

        # Display the value
        print('Channel', channel, 'Value (deg C):', value)
    except Exception as e:
        print('\n', e)
    finally:
        if use_device_detection:
            ul.release_daq_device(board_num)
Exemple #6
0
for i in range(runs):
    # add chamber control

    time.sleep(10)
    ser0.write(cmd0.encode())
    ser1.write(cmd1.encode())
    time.sleep(0.5)
    s0 = ser0.read(100).decode('utf-8')
    acc_temp = int(s0.split()[3][17:])
    s1 = ser1.read(200).decode('utf-8')
    t1 = s1.find("test")
    t2 = s1.find("please")
    s1 = s1[t1 + 6:t2 - 3]
    ain6 = int(s1[7:])

    ch0 = float("{:.2f}".format(ul.t_in(board_num, channel0, 0)))
    ch1 = float("{:.2f}".format(ul.t_in(board_num, channel1, 0)))
    ch2 = float("{:.2f}".format(ul.t_in(board_num, channel2, 0)))
    ch3 = float("{:.2f}".format(ul.t_in(board_num, channel3, 0)))
    print(acc_temp, ain6, ch0, ch1, ch2, ch3)

    # sheet1.write(i + 1, 0, t_start + t_step * i) # write temp setting in excel
    sheet1.write(i + 1, 1, ain6)  # write adc reading
    sheet1.write(i + 1, 2, acc_temp)
    sheet1.write(i + 1, 3, ch0)
    sheet1.write(i + 1, 4, ch1)
    sheet1.write(i + 1, 5, ch2)
    sheet1.write(i + 1, 6, ch3)
wb.close()
ser0.close()
ser1.close()
    def execute(self):
        log.info("Starting Measurement")
        #prev_T = read_T
        T_min = ul.t_in(0, 0, TempScale.KELVIN)
        T = [T_min]
        start_time = time.time()
        while np.mean(T) < self.T_max:
            log.info("Temperature is at %d, waiting for it to reach %d" % \
                     (np.mean(T), self.T_max))
            sleep(self.delay)
            elapsed_time = time.time() - start_time

            T, M1, M2, M3, M4 = [], [], [], [], []

            for i in range(self.num_averages):
                log.info("Doing average %d of %d" % (i, self.num_averages))
                if self.mm1_measurement:
                    M1.append(self.mm1.voltage)
                else:
                    M1.append(self.mm1.current)

                if self.mm2_measurement:
                    M2.append(self.mm2.voltage)
                else:
                    M2.append(self.mm2.current)

                if self.mm3_measurement:
                    M3.append(self.mm3.voltage)
                else:
                    M3.append(self.mm3.current)

                if self.mm4_measurement:
                    M4.append(self.mm4.voltage)
                else:
                    M4.append(self.mm4.current)

                T.append(ul.t_in(0, 0, TempScale.KELVIN))

                sleep(self.delay / (self.num_averages + 1))

            prog = int(100 * np.abs(
                (np.mean(T) - T_min) / (self.T_max - T_min)))
            self.emit("progress", prog)

            data = {
                'elapsed_time': elapsed_time,
                'T': np.mean(T),
                'T_err': np.std(T),
                'MM1_reading': np.mean(M1),
                'MM1_error': np.std(M1),
                'MM2_reading': np.mean(M2),
                'MM2_error': np.std(M2),
                'MM3_reading': np.mean(M3),
                'MM3_error': np.std(M3),
                'MM4_reading': np.mean(M4),
                'MM4_error': np.std(M4)
            }

            self.emit('results', data)
            if self.should_stop():
                log.warning("Catch stop command in procedure")
                break
            else:
                continue