def stopClicked(self):
        txtmsg = "Can't establish a connection with the humidity generator, " + \
        "you may need to unplug and then replug in the DataQ DI-145 then press 'Ctrl+H' to " + \
        "reconfigure COM port."

        try:
            # Try to stop scan
            self.s.sts()  # Stop scan
            self.thread.stop_thread = True
            self.thread.exit()
        except:
            # This means that we've lost comms with device
            msg = common_def.error_msg()
            msg.setText(txtmsg)
            msg.exec_()
Пример #2
0
    def captureDataSS(self, values):
        '''Captures data for the spectra sensor.'''
        # Copy the values so that we don't modify the original list
        vals = values.copy()

        # Spectra Sensor Data ------------------------------------------
        # Indicate if recording is enabled and if this is a continuation
        if self.recEnabled and time.time() <= self.time_end:
            # Insert reading num and time into dataset
            vals.insert(0, datetime.datetime.now())
            vals.insert(0, self.rdg)

            if self.continuationSS:
                pass  # This is a continuation so we must append the data to the list

            else:
                # This is the first point to record, so we must create the new variable to store data
                self.dataSS = [
                ]  # reinitialize to clear data from previous recording

                # Turn ON continuation mode
                self.continuationSS = True

            self.dataSS.append(vals)

        else:  #  we are not in record mode
            if self.continuationSS:  # we just came out of a record
                self.continuationSS = False  # Force out of continuation

                # Go to interpret output function
                try:
                    self.interpretOutput(self.dataSS, 'WVSS')

                    # Notate info about recording
                    print('WVSS Recording Captured')
                    print('WVSS Data Length = {} rows in {} seconds'.format(
                        len(self.dataSS),
                        time.time() - self.time_start))

                except:  # file is open cannot write so throw an error
                    msg = common_def.error_msg()
                    msg.setText('DATA NOT WRITTEN TO FILE:\n\n{} is open; '.format(self.filename_ext) + \
                                'please close the file before continuing')
                    msg.exec_()

            self.continuationSS = False  # turn off continuation
    def scanClicked(self):
        txtmsg = "Can't establish a connection with the humidity generator, " + \
        "you may need to unplug and then replug in the DataQ DI-145 then press 'Ctrl+D' to " + \
        "reconfigure COM port."

        try:
            self.s.scan()  # Start scan

            # Start thread
            ## Group of Code base on https://www.youtube.com/watch?v=eYJTcLBQKug
            self.thread = self.s

            # Check if devices are being read
            #  Dew Point Generator
            if self.dpGenActive:
                self.thread.change_value.connect(self.updateLCD)
            else:
                self.updateLCD(
                    0
                )  # Should never get here because dpGenActive should always be set to true

            #  Temperature
            if self.setTempActive:
                self.use_temp_counts = True  # Indicates that temp value passed to updateTemp() is in counts
                self.thread.change_value_temp.connect(self.updateTemp)

            # [self.thread.change_value.connect(x) for x in [self.updateLCD, self.captureDataLC]]  # Connect to multiple slots

            self.thread.heartbeat.connect(self.indicateScan)
            self.thread.start()
            #---------------------------------------------------------------------------------
        except:
            # This means that we've lost comms with device
            msg = common_def.error_msg()
            msg.setText(txtmsg)
            msg.exec_()
    def setupGUIclicked(self):
        ''' Control content from setup_GUI by attempting to initiate instances
            of the LiCor and SpectraSensor'''
        global comLC, comSS
        dlg = HardwareGUI(self)
        dlg.buttonBox.accepted.connect(dlg.accept)
        dlg.buttonBox.rejected.connect(dlg.reject)

        # The following executes the dialog box and returns whether it was
        # accepted or rejected
        result = dlg.exec_()
        if result == QtWidgets.QDialog.Accepted:
            '''Try to accept the changes and initialize COM ports.  If unsuccessful,
               show a message box that request cannot be completed'''
            self.active = False
            try:
                # Activate DataQ DI145
                comLC = dlg.lineLC.text()
                self.s = ADC.DataQ_DI145(comLC)
                self.active = True  # Triggers to activate record button if one is true
                for button in self.lcRbuttons:
                    button.setEnabled(True)

                # Look for Checkboxes
                #  Dew Point Generator
                if dlg.dpGenChkBox.isChecked():
                    self.dpGenActive = True  # use dew point generator humdity value
                else:  # warn users if hum generator is not selected
                    self.dpGenActive = False
                    msg = common_def.error_msg()
                    msg.setText(
                        'DataQ DI-145 is connected but Dew Point Generator is not selected'
                    )
                    msg.exec_()
                #  Temperature
                if dlg.tempChkBox.isChecked():
                    self.setTempActive = True
                else:
                    self.setTempActive = False

            except:
                self.dpGenActive = False
                self.setTempActive = False
                msg = common_def.error_msg()
                msg.setText(
                    'Could NOT initialize DataQ DI-145 from port {}'.format(
                        comLC))
                msg.exec_()

            try:
                comSS = dlg.lineWVSS.text()
                self.ss = WVSS.WVSS_II(comSS)
                self.active = True  # Triggers to activate record button if one is true
                for button in self.ssRbuttons:
                    button.setEnabled(True)

                # Look for Pressure Checkbox
                if dlg.pressChkBox.isChecked():
                    self.setPressActive = True
                else:
                    self.setPressActive = False

            except:
                self.setPressActive = False
                msg = common_def.error_msg()
                msg.setText(
                    'Could NOT initialize Water Vapor Monitor System from port {}'
                    .format(comSS))
                msg.exec_()
    def recordGUIclicked(self):
        global avgLength, fname, outLoc

        # Read from temp file to determine defaults
        self.tmpOpen('read')

        # Connect accepted and rejected
        self.rdlg.buttonBox.accepted.connect(self.rdlg.accept)
        self.rdlg.buttonBox.rejected.connect(self.rdlg.reject)

        result = self.rdlg.exec_()
        if result == QtWidgets.QDialog.Accepted:
            # Update global variables from dialog box inputs if in valid range
            if 3 <= float(self.rdlg.avgRecEdit.text()) <= 30:
                avgLength = float(self.rdlg.avgRecEdit.text())
            else:
                msg = common_def.error_msg()
                msg.setText(
                    'Please enter an averaged reading length between 3-30 seconds'
                )
                msg.exec_()

            fname = self.rdlg.filenameEdit.text()
            outLoc = self.rdlg.outLocEdit.text()

            # Set record length, filename and filelocation from the dialog box
            self.rec.record_length = avgLength
            self.rec.filename = fname
            self.rec.fileLoc = outLoc
            self.rec.getFullFile()
            self.rec.check_for_latest_reading()

            # Set line edit values
            self.recLengthEdit.setText(str(self.rec.record_length))
            self.recLocEdit.setText(str(self.rec.full_filename))
            self.rdgNumEdit.setText(str(self.rec.rdg - 1))

            print('File to be saved as: {}'.format(self.rec.full_filename))

            # Modify record button if one of the devices is setup correctly
            if self.active:
                self.genRecordButton(
                )  # generate the record button from instance of RecordButton class
                self.recordButton.setEnabled(True)
                self.recordButton.setToolTip(
                    'Press this button to trigger a recording')
                self.recordStopButton.setEnabled(True)

                # Track output variables that are checked
                self.rec_options = []
                self.checked = []
                for chk, option in zip(self.chkboxes, self.options):
                    if chk.isChecked():
                        self.rec_options.append(option)
                        self.checked.append(chk)

                # Set proper headers
                # print(self.rec_options)
                self.rec.headers = self.rec.iheaders + self.rec_defaults + self.rec_options  # set the headers
                print('rec.headers = {}'.format(self.rec.headers))
            else:
                self.recordButton.setEnabled(False)
                self.recordButton.setToolTip(
                    'You are not configured press Ctrl+P first to ' +
                    'configure the devices, then press Ctrl+R to configure recordings'
                )
                self.recordStopButton.setEnabled(False)

            # Store data from this editing of the record GUI
            self.tmpOpen('write')