Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __version__ = '1.94'
- from pythonui import Ui_MainWindow
- from PyQt5 import QtGui, QtWidgets
- import FunctionGenerator
- import threads_calibration
- import threads_sweep
- import threads_console
- import threads_ampwarmup
- import probe_class
- import os
- import csv #used to pull amp type from cal file
- import amp_class #Amp
- import time
- #import warning_sys_class
- from datetime import datetime
- import _GLOBALS
- #AMP_WARMUPTIME = amp_class.AMP_WARMUPTIME #Amp
- #AMP_WARMUPTIME = _GLOBALS.AMP_WARMUPTIME_MINS
- #DEBUG = True #True to send additional terminal outputs: Production this value is false
- #START_PWR = -10 #adjust start power to -10 cut down on time needed to find the right dbm from siggen to amp
- '''
- TESTAMP = "uhf" # change to the amp that needs testing, provides default settings in the Ui option vhf, uhf, shf->AMP_DICT
- TESTAMPGAIN = False
- AMP_DICT = {"uhf":[50, 3000, 6000,"Horn"],
- "vhf":[50, 500, 1000],
- "shf":[50, 7000, 8000,""]}
- '''
- #class: UI
- #This class inherits the Ui_Mainwindow class from "python.ui" file to enable updating the pythonui without having to copy code.
- #This class also adds more functionality that is outside the scope of the Pyqt5 Designer software.
- class Ui(QtWidgets.QMainWindow,Ui_MainWindow):
- def __init__(self):
- super().__init__()
- self.setupUi(self)
- self.update_COMPorts()
- self.filename = ""
- self.versionsw = "SWVer: "+__version__
- self.swver.setText("SWVer: "+__version__)
- sys.stdout = threads_console.Stream(newText=self.reportDebug)
- #Connecting button clicks with functions
- #Equipment Tab buttons
- self.COMRefresh.clicked.connect(self.update_COMPorts)
- self.OpenPorts.clicked.connect(self.equipment_open_ports)
- self.Equipment_closeButton.clicked.connect(self.equipment_close_ports)
- self.DebugFile_button.clicked.connect(self.logfile_location)
- self.DebugLogCheck.clicked.connect(self.debugcheck)
- #Calibration Tab buttons
- self.Mod_box.currentIndexChanged.connect(self.update_modulation)
- self.CalFile.clicked.connect(self.save_file_location)
- self.CalButton.clicked.connect(self.start_cal)
- self.CalPause.clicked.connect(self.pause_cal)
- self.CalResume.clicked.connect(self.resume_cal)
- self.threads_ampwarmup = threads_ampwarmup # why???? we are not doing this for any other import???????
- self.amp_cdwn_timer = ""
- #Sweeper Tab buttons
- self.Sweepfile_button.clicked.connect(self.sweep_file)
- self.SweepButton.clicked.connect(self.start_sweep)
- self.SweepResume.clicked.connect(self.resume_sweep)
- self.SweepPause.clicked.connect(self.pause_sweep)
- self.QuitSweep.clicked.connect(self.finished_sweep)
- self.SweepLog_Button.clicked.connect(self.SweepLog_location)
- #Field Probe Tab
- self.COMRefresh_2.clicked.connect(self.update_COMPorts)
- self.StartFB_Button_2.clicked.connect(self.equipment_open_fp_port)
- self.CloseFB_Button_2.clicked.connect(self.equipment_close_fp_port)
- #setting defaults for boxes in the Ui
- self.Mod_box.setCurrentIndex(0) #1000Hz 80% depth by default
- self.Cal_FieldStrength_Box.setValue(10.5) #10.5Vm by default
- self.Gentype_combo.setCurrentIndex(2)
- #C:\Users\SVC-ADCRFLAB\Documents\EMCChamberDev\Projects
- #self.DebugLog_text.setText(DEBUGLOG_PATH) #"/Projects"
- #self.total_seconds(int) #AttributeError: 'Ui' object has no attribute 'total_seconds' in threads warmup
- #self.testbutton.clicked.connect(self.test_button)
- self.DEBUG = _GLOBALS.DEBUG
- self.equipment_amp = "" #selection of amps if no amp selected then we will turn then all off or on.
- if self.DEBUG:
- if _GLOBALS.TESTAMP in _GLOBALS.AMP_DICT:
- self.Cal_step_box.setValue(_GLOBALS.AMP_DICT[_GLOBALS.TESTAMP][0])
- self.Cal_startfreq_box.setValue(_GLOBALS.AMP_DICT[_GLOBALS.TESTAMP][1])
- self.Cal_endfreq_box.setValue(_GLOBALS.AMP_DICT[_GLOBALS.TESTAMP][2])
- else:
- print("Amp does not exist")
- self.TESTAMPGAIN = _GLOBALS.TESTAMPGAIN # curretnly unused but is to convert the standard gain level to 0 in amp_class
- self.amp_in_use = True #Amp in use flag, once an amp is chosen in cal or sweep modes
- def test_button(self):
- self.Sweep_status.setText("RF On")
- self.Sweep_status.setStyleSheet("""QLineEdit { background-color: yellow; color: red }""")
- #function: start_cal
- #description: This function initializes and creates a separate thread for the calibration sequence to run in.
- #A seperate thread is necessary to have the User Interface continue to update and have the Pause/Resume button function
- def start_cal(self):
- print("clicked start Calibration")
- self.CalPause.setEnabled(True)
- self.CalButton.setEnabled(False)
- self.Status.setText("RF On")
- self.Status.setStyleSheet("""QLineEdit { background-color: yellow; color: red }""")
- self.Mod_shape_box.setEnabled(False)
- self.Mod_freq_box.setEnabled(False)
- self.Mod_depth_box.setEnabled(False)
- mod_index = self.Mod_box.currentIndex()
- mod_shape = self.Mod_shape_box.currentIndex()
- mod_freq = self.Mod_freq_box.value()
- mod_depth = self.Mod_depth_box.value()
- start_freq = self.Cal_startfreq_box.value()
- end_freq = self.Cal_endfreq_box.value()
- #kill amps not in use
- if start_freq > 79 and end_freq < 1001: #Amp
- print("===kill uhf===")
- self.amp_in_use = False #we don't need the use data for the amps we are turning off amp class
- self.equipment_uhf_amp.off(self.amp_in_use)
- print("===kill shf===")
- self.equipment_shf_amp.off(self.amp_in_use)
- print("===RFon vhf===")
- self.amp_in_use = True #we do want the use data for the amps we using amp class
- self.equipment_vhf_amp.on() #RFon
- self.equipment_amp = "vhf" #4 cal file
- elif start_freq > 999 and end_freq < 6001: #Amp
- print("===kill vhf===")
- self.amp_in_use = False #we don't need the use data for the amps we are turning off amp class
- self.equipment_vhf_amp.off(self.amp_in_use)
- print("===kill shf===")
- self.equipment_shf_amp.off(self.amp_in_use)
- print("===RFon uhf===")
- self.amp_in_use = True #we do want the use data for the amps we using amp class
- self.equipment_uhf_amp.on() #RFon
- self.equipment_amp = "uhf" #4 cal file
- elif start_freq > 5999 and end_freq < 18000: #Amp
- print("===kill vhf===")
- self.amp_in_use = False #we don't need the use data for the amps we are turning off amp class
- self.equipment_vhf_amp.off(self.amp_in_use)
- print("===kill uhf===")
- self.equipment_uhf_amp.off(self.amp_in_use)
- print("===RFon shf===")
- self.amp_in_use = True #we do want the use data for the amps we using amp class
- self.equipment_shf_amp.on() #RFon
- self.equipment_amp = "shf" #4 cal file
- if self.amp_warmup_calc(): #Amp
- #print("AmpWarmUpCalc 101 = ", self.amp_warmup_calc())
- self.Status.setStyleSheet("""QLineEdit { background-color: yellow; color: red }""")
- self.Status.setText("WARM UP")
- if self.DEBUG:
- print("Starting AmpWarming in cal")
- #self.jnk = threads_ampwarmup.cntdwn_amp_warmuptime
- if self.threads_ampwarmup.cntdwn_amp_warmuptime.start(self, _GLOBALS.AMP_WARMUPTIME_MINS, 00):
- #emit example:
- #self.get_thread.amp_cdwn_timer.connect(self.reportAmpTimer) #Added to connect the timer to calibration tab
- print("warm up completed")
- #else:
- #Done with Warmup
- self.Status.setText("RF On")
- self.Status.setStyleSheet("""QLineEdit { background-color: red; color: yellow }""")
- self.equipment_siggen.rf_on()
- start_power = _GLOBALS.SIGGEN_START_PWR
- targetfield = self.Cal_FieldStrength_Box.value() #moved below We need away to emit this value from threads calibration for the proximity fields
- step_size = self.Cal_step_box.value()
- self.create_filename()
- file_name = self.Savelocation_box.text() + "/" +self.filename
- tolerance =self.Tolerance_box.value()
- #def __init__(self,step,endfreq,startfreq,siggen,rfpower,fieldprobe,targetfield,tolerance,file_name,mod_box,mod_shape,mod_freq,mod_depth,prox_flag):
- #initializing the variables needed for the calibration thread
- self.get_thread = threads_calibration.calibration_thread(step_size,end_freq,start_freq,self.equipment_siggen,start_power,self.equipment_probe,targetfield,tolerance,file_name,mod_index,mod_shape,mod_freq,mod_depth,self.Prox_fields_box.currentIndex())
- #connecting the signals to front UI elements or functions to update
- self.get_thread.finished_signal.connect(self.finished_cal)
- self.get_thread.progress_signal.connect(self.reportProgress)
- self.get_thread.estimated_time_signal.connect(self.reportTime)
- self.get_thread.current_freq_signal.connect(self.reportFreq)
- self.get_thread.measuredfield_signal.connect(self.reportField)
- self.get_thread.rfpower_signal.connect(self.reportPower)
- self.get_thread.batvolt_signal.connect(self.reportBat)
- #emit example:
- self.get_thread.amp_cdwn_timer_signal.connect(self.reportAmpTimer_Cal) #Added to connect the timer to calibration tab
- self.get_thread.start()
- #Function: create_filename
- #this function creates a filename based on the inputs from the user on the UI and the current date/time
- #added field_probe_sn & amp_type to the output files
- def create_filename(self):
- orientation = self.Orientation.currentText()
- start_freq = str(self.Cal_startfreq_box.value())
- end_freq = str(self.Cal_endfreq_box.value())
- step_size = str(self.Cal_step_box.value())
- target_field = str(self.Cal_FieldStrength_Box.value())
- field_probe_sn = "fpsn#" #place holder for field probe serial number
- amp_type = self.equipment_amp
- # datetime object containing current date and time
- now = datetime.now()
- # dd/mm/YY H:M:S
- dt_string = now.strftime("%d-%b-%Y_%H%M")
- filename = "_" + orientation[0] + start_freq + "-" + end_freq + "MHz-" + step_size +"s-" + target_field + "Vm_" + dt_string +".csv"
- self.filename = filename
- file_name = self.Savelocation_box.text() + "/" +self.filename
- print(file_name)
- cal_pos = self.Cal_Position_Box.currentText()
- comments = self.Comments_box.text()
- if os.path.isfile(file_name) == False:
- file1 = open(file_name,'a+')
- file1.write('Frequency(MHz),Sig.Gen.Power(dBm),Field Probe Measurement(V/m),Target FIeld (V/m),Mod_shape,Mod_freq(Hz),Mod_depth(%),Cal Pos:'+ cal_pos + ',' + field_probe_sn +',' + amp_type +','+comments)
- file1.write("\n")
- print("created file"+file_name)
- file1.close()
- def pause_cal(self):
- self.get_thread.stop_signal = True
- print("paused")
- self.Status.setText("Paused")
- self.Status.setStyleSheet("""QLineEdit { background-color: green; color: white }""")
- self.CalPause.setEnabled(False)
- self.CalResume.setEnabled(True)
- def resume_cal(self):
- self.get_thread.stop_signal = False
- self.equipment_siggen.rf_on()
- print("resumed")
- self.Status.setText("RF On")
- self.Status.setStyleSheet("""QLineEdit { background-color: yellow; color: red }""")
- self.CalPause.setEnabled(True)
- self.CalResume.setEnabled(False)
- def finished_cal(self):
- self.equipment_siggen.rf_off()
- self.get_thread.quit()
- self.Status.setText("Completed")
- self.Status.setStyleSheet("""QLineEdit { background-color: green; color: white }""")
- self.CalPause.setEnabled(False)
- self.CalButton.setEnabled(True)
- def quit_cal(self):
- self.pause_cal(self)
- #############################################
- #Sweep thread functions
- def start_sweep(self):
- print("clicked start Sweep button")
- self.SweepButton.setEnabled(False)
- self.SweepPause.setEnabled(True)
- self.Dwell_box.setEnabled(False)
- self.QuitSweep.setEnabled(True)
- self.sweepfile = self.Sweepfile_box.text()
- #sweepfile = self.sweepfile
- #find the amp list in header
- #sweepfile_header_lst = file_get_headers_lst(sweepfile)
- #created a function for this but can't use it???????????????????
- file_path = self.sweepfile
- print("opening file:", file_path)
- try:
- with open(file_path, 'r') as file:
- csv_reader = csv.reader(file)
- header_list = next(csv_reader)
- except FileNotFoundError:
- print(f"Error: File not found at '{file_path}'")
- except Exception as e:
- print(f"An error occurred: {e}")
- finally:
- print("done")
- #can't figure out why this doesn't work!!!!!!!!!!!!!!!!!!!!!!!
- #header_list = file_get_headers_lst(self.sweepfile)
- #---------------
- self.equipment_amp = header_list[9] #assign the amp for both debug and playback logs
- if self.equipment_amp:
- #kill amps not in use
- if self.equipment_amp == "vhf": #Amp
- print("===kill uhf===")
- self.equipment_uhf_amp.off(self.amp_in_use)
- print("===kill shf===")
- self.equipment_shf_amp.off(self.amp_in_use)
- print("===RFon vhf===")
- self.equipment_vhf_amp.on() #RFon
- self.equipment_amp = "vhf" #4 cal file
- elif self.equipment_amp == "uhf": #Amp
- print("===kill vhf===")
- self.equipment_vhf_amp.off(self.amp_in_use)
- print("===kill shf===")
- self.equipment_shf_amp.off(self.amp_in_use)
- print("===RFon uhf===")
- self.equipment_uhf_amp.on() #RFon
- self.equipment_amp = "uhf" #4 cal file
- elif self.equipment_amp == "shf": #Amp
- print("===kill vhf===")
- self.equipment_vhf_amp.off(self.amp_in_use)
- print("===kill uhf===")
- self.equipment_uhf_amp.off(self.amp_in_use)
- print("===RFon shf===")
- self.equipment_shf_amp.on() #RFon
- self.equipment_amp = "shf" #4 cal file
- else:
- print("amp selection error in cal file:", self.equipment_amp)
- #depreciated - threads_ampwarmup.py
- if self.amp_warmup_calc(): #Amp not(self.amp_warmup) inverted logic with threads warmup
- print("Starting warmup in sweeper")
- self.Sweep_status.setText("WARMUP: ")
- self.Sweep_status.setStyleSheet("""QLineEdit { background-color: red; color: white }""")
- threads_ampwarmup.cntdwn_amp_warmuptime.start(self, _GLOBALS.AMP_WARMUPTIME_MINS, 00)
- else:
- self.Sweep_status.setText("RF On")
- self.Sweep_status.setStyleSheet("""QLineEdit { background-color: red; color: white }""")
- #print("skipped over amp warmup() sweeper", self.sweepfile)
- self.sweeplog =self.SweepLog_Box.text()
- dwell = self.Dwell_box.value()
- #def __init__(self,dwell,inputfile,siggen,fieldprobe,modenable,outputfile,swver):
- self.get_sweep = threads_sweep.sweep_thread(dwell, self.sweepfile, self.equipment_siggen,self.equipment_probe,self.Modenable_box.isChecked(),self.sweeplog,self.versionsw)
- self.get_sweep.finished_signal.connect(self.finished_sweep)
- self.get_sweep.progress_signal.connect(self.reportProgress_Sweep)
- self.get_sweep.estimated_time_signal.connect(self.reportTime_Sweep)
- self.get_sweep.current_freq_signal.connect(self.reportFreq_Sweep)
- self.get_sweep.rfpower_signal.connect(self.reportPower_Sweep)
- self.get_sweep.modshape_signal.connect(self.reportModshape_Sweep)
- self.get_sweep.modfreq_signal.connect(self.reportModfreq_Sweep)
- self.get_sweep.moddepth_signal.connect(self.reportModdepth_Sweep)
- self.get_sweep.measuredfield_signal.connect(self.reportProbe_Sweep)
- self.get_sweep.start()
- def pause_sweep(self):
- print("paused")
- self.Sweep_status.setText("Paused")
- self.Sweep_status.setStyleSheet("""QLineEdit { background-color: red; color: white }""")
- self.equipment_siggen.rf_off()
- self.get_sweep.pause_signal = True
- self.SweepPause.setEnabled(False)
- self.SweepResume.setEnabled(True)
- def resume_sweep(self):
- print("resumed sweep")
- self.equipment_siggen.rf_on()
- self.Sweep_status.setText("RF On")
- self.Sweep_status.setStyleSheet("""QLineEdit { background-color: red; color: yellow }""") #R2 mod changed coler to red/yellow
- self.get_sweep.pause_signal= False
- self.SweepPause.setEnabled(True)
- self.SweepResume.setEnabled(False)
- def finished_sweep(self):
- self.equipment_siggen.rf_off()
- self.get_sweep.stop_signal = False
- self.get_sweep.quit()
- self.Sweep_status.setText("Completed")
- self.Sweep_status.setStyleSheet("""QLineEdit { background-color: green; color: black }""")
- self.SweepPause.setEnabled(False)
- self.SweepButton.setEnabled(True)
- self.SweepResume.setEnabled(False)
- self.QuitSweep.setEnabled(False)
- self.Dwell_box.setEnabled(True)
- def start_fp(self):
- #print("clicked start Field Probe") We have no need to log anything in Field Probe Tab, Ref Only
- '''
- self.CalPause.setEnabled(True)
- self.CalButton.setEnabled(False)
- self.Status.setText("RF On")
- self.Status.setStyleSheet("""QLineEdit { background-color: yellow; color: red }""")
- self.Mod_shape_box.setEnabled(False)
- self.Mod_freq_box.setEnabled(False)
- self.Mod_depth_box.setEnabled(False)
- mod_index = self.Mod_box.currentIndex()
- mod_shape = self.Mod_shape_box.currentIndex()
- mod_freq = self.Mod_freq_box.value()
- mod_depth = self.Mod_depth_box.value()
- start_freq = self.Cal_startfreq_box.value()
- end_freq = self.Cal_endfreq_box.value()
- #kill amps not in use
- if start_freq > 79 and end_freq < 1001: #Amp
- print("===kill uhf===")
- self.amp_in_use = False #we don't need the use data for the amps we are turning off amp class
- self.equipment_uhf_amp.off(self.amp_in_use)
- print("===kill shf===")
- self.equipment_shf_amp.off(self.amp_in_use)
- print("===RFon vhf===")
- self.amp_in_use = True #we do want the use data for the amps we using amp class
- self.equipment_vhf_amp.on() #RFon
- self.equipment_amp = "vhf" #4 cal file
- elif start_freq > 999 and end_freq < 6001: #Amp
- print("===kill vhf===")
- self.amp_in_use = False #we don't need the use data for the amps we are turning off amp class
- self.equipment_vhf_amp.off(self.amp_in_use)
- print("===kill shf===")
- self.equipment_shf_amp.off(self.amp_in_use)
- print("===RFon uhf===")
- self.amp_in_use = True #we do want the use data for the amps we using amp class
- self.equipment_uhf_amp.on() #RFon
- self.equipment_amp = "uhf" #4 cal file
- elif start_freq > 5999 and end_freq < 18000: #Amp
- print("===kill vhf===")
- self.amp_in_use = False #we don't need the use data for the amps we are turning off amp class
- self.equipment_vhf_amp.off(self.amp_in_use)
- print("===kill uhf===")
- self.equipment_uhf_amp.off(self.amp_in_use)
- print("===RFon shf===")
- self.amp_in_use = True #we do want the use data for the amps we using amp class
- self.equipment_shf_amp.on() #RFon
- self.equipment_amp = "shf" #4 cal file
- if self.amp_warmup_calc(): #Amp
- #print("AmpWarmUpCalc 101 = ", self.amp_warmup_calc())
- self.Status.setStyleSheet("""QLineEdit { background-color: yellow; color: red }""")
- self.Status.setText("WARM UP")
- if self.DEBUG:
- print("Starting AmpWarming in cal")
- #self.jnk = threads_ampwarmup.cntdwn_amp_warmuptime
- if self.threads_ampwarmup.cntdwn_amp_warmuptime.start(self, _GLOBALS.AMP_WARMUPTIME_MINS, 00):
- #emit example:
- #self.get_thread.amp_cdwn_timer.connect(self.reportAmpTimer) #Added to connect the timer to calibration tab
- print("warm up completed")
- #else:
- #Done with Warmup
- self.Status.setText("RF On")
- self.Status.setStyleSheet("""QLineEdit { background-color: red; color: yellow }""")
- self.equipment_siggen.rf_on()
- start_power = _GLOBALS.SIGGEN_START_PWR
- '''
- targetfield = self.Cal_FieldStrength_Box.value() #moved below We need away to emit this value from threads calibration for the proximity fields
- '''
- step_size = self.Cal_step_box.value()
- self.create_filename()
- file_name = self.Savelocation_box.text() + "/" +self.filename
- tolerance =self.Tolerance_box.value()
- #def __init__(self,step,endfreq,startfreq,siggen,rfpower,fieldprobe,targetfield,tolerance,file_name,mod_box,mod_shape,mod_freq,mod_depth,prox_flag):
- #initializing the variables needed for the calibration thread
- self.get_thread = threads_calibration.calibration_thread(step_size,end_freq,start_freq,self.equipment_siggen,start_power,self.equipment_probe,targetfield,tolerance,file_name,mod_index,mod_shape,mod_freq,mod_depth,self.Prox_fields_box.currentIndex())
- #connecting the signals to front UI elements or functions to update
- self.get_thread.finished_signal.connect(self.finished_cal)
- self.get_thread.progress_signal.connect(self.reportProgress)
- self.get_thread.estimated_time_signal.connect(self.reportTime)
- self.get_thread.current_freq_signal.connect(self.reportFreq)
- '''
- self.get_thread.measuredfield_signal.connect(self.reportField)
- '''
- self.get_thread.rfpower_signal.connect(self.reportPower)
- '''
- self.get_thread.batvolt_signal.connect(self.reportBat)
- '''
- #emit example:
- self.get_thread.amp_cdwn_timer_signal.connect(self.reportAmpTimer_Cal) #Added to connect the timer to calibration tab
- '''
- self.get_thread.start()
- ###############################################################################################
- #The following "report" functions update the User interface with information as the program is running.
- #The functions take the signal emitted by a thread and gives the User Interface information.
- #------ I think this first group of reports for emits is for the Cal Tab
- #------ future: maybe rename each report for it's tab so it's clearer
- """
- Â Â Â The following group of functions are for updating
- the Ui Calibration Tab
- """
- def reportFinished(self,finished):
- self.Status.setText("Complete")
- self.Status.setStyleSheet("""QLineEdit { background-color: green; color: white }""")
- def reportProgress(self,progress):
- print("Progress is " + str(progress))
- self.progressBar.setProperty("value", int(progress))
- def reportTime(self,time):
- timestring = str(time) +"mins"
- self.TextEstimatedTime.setText(timestring)
- def reportFreq(self,freq):
- self.Cal_Freq_Box.setText(str(freq))
- def reportField(self,field):
- self.Cal_Probe_strength_box.setText(str(field))
- def reportPower(self,power):
- self.Cal_siggen_box.setText(str(power))
- #Narda or ETS Probe Bat Low
- def reportBat(self,bat):
- self.Text_BatV.setText(str(bat)+" V")
- if self.Probetype_combo.currentText() == "Narda":
- if bat < 2.05:
- self.Status.setText("BAT LOW")
- self.Status.setStyleSheet("""QLineEdit { background-color: yellow; color: red }""") #when bat low
- elif self.Probetype_combo.currentText() == "ETS":
- if bat < 4.0:
- self.Status.setText("BAT LOW")
- self.Status.setStyleSheet("""QLineEdit { background-color: yellow; color: red }""") #when bat low
- def reportDebug(self, text):
- cursor = self.DebugOutput.textCursor()
- cursor.movePosition(QtGui.QTextCursor.End)
- cursor.insertText(text)
- self.DebugOutput.setTextCursor(cursor)
- self.DebugOutput.ensureCursorVisible()
- if self.DebugLogCheck.isChecked():
- filestring = self.DebugLog_text.text() + '/'+'debug.txt'
- sys.stdout.logenable = True
- sys.stdout.logfile= filestring
- file1 = open(filestring,'a+')
- file1.write(str(text))
- file1.close()
- #emit example:
- def reportAmpTimer_Cal(self,amp_cdwn_timer): #added to send cnt down to Ui
- self.a_cdwn_t = "Start In:",str(amp_cdwn_timer) # need to adjust the font size
- self.Status.setStyleSheet("""QLineEdit { background-color: yellow; color: red }""")
- self.Status.setText(str(amp_cdwn_timer))
- #------ this sencond group of reports for emits is for the Sweep Tab
- """
- Â Â Â The following group of functions are for updating
- the Ui Sweep Tab
- """
- def reportProgress_Sweep(self,progress):
- print("Progress is " + str(progress))
- self.Sweep_progressbar.setProperty("value", int(progress))
- def reportTime_Sweep(self,time):
- timestring = str(time) +"mins"
- self.SweepEstimatedTime_text.setText(timestring)
- def reportFreq_Sweep(self,freq):
- self.Sweep_freq_box.setText(str(freq))
- def reportPower_Sweep(self,power):
- self.Sweep_siggen_box.setText(str(power))
- def reportModshape_Sweep(self,shape):
- self.Sweep_modshape_box.setText(shape)
- def reportModfreq_Sweep(self,freq):
- self.Sweep_modfreq_box.setText(str(freq))
- def reportModdepth_Sweep(self,depth):
- self.Sweep_moddepth_box.setText(str(depth))
- def reportProbe_Sweep(self,field):
- self.Sweep_FieldProbe_box.setText(str(field))
- #############################################################################################
- #*******************************************************************************************
- #The following functions update the front user interface
- #Function: save_file_location
- #this function creates a popup directory search to get a save directory
- def save_file_location (self):
- fname = QtWidgets.QFileDialog.getExistingDirectory()
- print ("save file location updated to "+fname)
- self.Savelocation_box.setText(fname)
- #Function: sweep_file
- #This funcion creates a pop file search to get a file for sweep parameters
- def sweep_file(self):
- fname = QtWidgets.QFileDialog.getOpenFileName()[0] #Sweep files will be kept in C:\Users\SVC-ADCRFLAB\Documents\EMC Chamber Software\Cal
- print ("sweep file updated to " + fname)
- self.Sweepfile_box.setText(fname)
- def SweepLog_location(self):
- fname = QtWidgets.QFileDialog.getExistingDirectory() #sweep logs base directory to open up in C:\Users\SVC-ADCRFLAB\Documents\EMC Chamber Software\Projects\ by user/project name
- print ("log file location updated to "+fname)
- self.SweepLog_Box.setText(fname)
- def logfile_location(self):
- fname = QtWidgets.QFileDialog.getExistingDirectory() #debug log will be kept automatically the same dir as sweeplog
- print ("log file location updated to "+fname)
- self.DebugLog_text.setText(fname)
- def debugcheck(self):
- if self.DebugLogCheck.isChecked():
- self.DebugLog_text.setEnabled(False)
- self.DebugFile_button.setEnabled(False)
- else:
- self.DebugLog_text.setEnabled(True)
- self.DebugFile_button.setEnabled(True)
- #Function: update_COMPorts
- #This function clears the COM Ports for the siggen and probe.
- #Then it gets an updated list of the connected COM items and adds them to the list.
- def update_COMPorts(self):
- self.FieldProbe_combo.clear()
- #self.FieldProbe_combo_2.clear() #wtf
- p = probe_class.COM_list()
- for COM in p:
- self.FieldProbe_combo.addItem(str(COM))
- #self.FieldProbe_combo_2.addItem(str(COM)) #wtf
- self.Siggen_combo.clear()
- visa_devices = FunctionGenerator.visa_devices()
- print(visa_devices)
- if visa_devices:
- for visas in visa_devices:
- self.Siggen_combo.addItem(visas)
- def update_fp_COMPorts(self):
- self.FieldProbe_combo_2.clear()
- p = probe_class.COM_list()
- for COM in p:
- self.FieldProbe_combo_2.addItem(str(COM))
- '''
- self.Siggen_combo.clear()
- visa_devices = FunctionGenerator.visa_devices()
- if visa_devices:
- for visas in visa_devices:
- self.Siggen_combo.addItem(visas)
- '''
- #Function: update_modulation
- #This function enables/disables the modulation selection boxes based on the index
- def update_modulation(self):
- print ("modulation box changed to "+self.Mod_box.currentText())
- if ( self.Mod_box.currentIndex() >= 1):
- self.Mod_shape_box.setEnabled(True)
- self.Mod_freq_box.setEnabled(True)
- self.Mod_depth_box.setEnabled(True)
- elif (self.Mod_box.currentIndex() == 0):
- self.Mod_shape_box.setEnabled(False)
- self.Mod_freq_box.setEnabled(False)
- self.Mod_depth_box.setEnabled(False)
- #open ports button on Equipment Tab
- def equipment_open_ports(self):
- x = str(self.FieldProbe_combo.currentText())
- y = x.split(":")
- #Amp
- #we probably should check to make sure each amp is connected or toss an error and or notify operator
- #Open all three Amps & use the warmup gain constant which shold = 20 min. The intent is to start them all automatically,
- #because we want to minimize the wait time to RF On, either sweep or calibration
- self.equipment_vhf_amp = amp_class.pwramps("search", "vhf", _GLOBALS.AMP_GAIN) #Amp
- self.equipment_uhf_amp = amp_class.pwramps("search", "uhf", _GLOBALS.AMP_GAIN) #Amp
- self.equipment_shf_amp = amp_class.pwramps("search", "shf", _GLOBALS.AMP_GAIN) #Amp
- self.dtAmpLog = datetime.now() #Amp
- print("Amp DT Sartup at : "+ str(self.dtAmpLog)) #Amp log the time for start up
- #Field Probe Selection
- if self.Probetype_combo.currentIndex() != 0 and self.FieldProbeActive.isChecked() == False:
- self.equipment_probe = probe_class.fieldprobe(y[0],self.Probetype_combo.currentText())
- if self.equipment_probe.probe:
- self.FieldProbe_status.setText("Opened " + y[0])
- print(self.equipment_probe.probe.isOpen())
- probe_info = self.equipment_probe.Probe_info()
- #[probe_model,sw_rev,probe_sn,cal_date]
- self.Text_Model.setText(probe_info[0])
- self.Text_SN.setText(probe_info[1])
- self.Text_CalDate.setText(probe_info[2])
- self.FieldProbe_combo.setEnabled(False)
- self.FieldProbeActive.setChecked(True)
- self.FieldProbeActive_2.setChecked(True)
- self.FieldProbe_status.setStyleSheet("""QLineEdit { background-color: green; color: white }""")
- else:
- self.FieldProbe_status.setText("unable to open COM Port")
- self.FieldProbe_status.setStyleSheet("""QLineEdit { background-color: red; color: white }""")
- self.FieldProbeActive.setChecked(False)
- #Generator Selection
- if self.Gentype_combo.currentIndex() != 0 and self.SigGenActive.isChecked() == False:
- self.equipment_siggen = FunctionGenerator.Func_gen(self.Siggen_combo.currentText(),self.Gentype_combo.currentText())
- if self.equipment_siggen.Siggen:
- self.Siggen_status.setText("opened " + self.Siggen_combo.currentText())
- self.Siggen_combo.setEnabled(False)
- self.SigGenActive.setChecked(True)
- self.SigGenActive_2.setChecked(True)
- self.Siggen_status.setStyleSheet("""QLineEdit { background-color: green; color: white }""")
- else:
- self.SigGenActive.setChecked(False)
- self.SigGenActive_2.setChecked(False)
- self.Siggen_status.setStyleSheet("""QLineEdit { background-color: red; color: white }""")
- if self.SigGenActive.isChecked():
- if self.FieldProbeActive.isChecked():
- self.CalButton.setEnabled(True)
- self.OpenPorts.setEnabled(False)
- self.SweepButton.setEnabled(True)
- z = str(self.FieldProbe_c)
- #Start Fp button on field prbee Tab
- def equipment_open_fp_port(self):
- x = str(self.FieldProbe_combo_2.currentIndex()) #.currentText())
- z = str(self.FieldProbe_)
- y = x.split(":")
- #Field Probe Selection
- if self.Probetype_combo_2.currentIndex() != 0 and self.FieldProbeActive.isChecked() == False:
- self.equipment_probe_2 = probe_class.fieldprobe(y[0],self.Probetype_combo_2.currentText())
- if self.equipment_probe_2.probe:
- self.FieldProbe_status_2.setText("Opened " + y[0])
- #print(self.equipment_probe_2.probe.isOpen())
- probe_info = self.equipment_probe_2.Probe_info()
- #[probe_model,sw_rev,probe_sn,cal_date]
- self.Text_Model_2.setText(probe_info[0])
- self.Text_SN_2.setText(probe_info[1])
- self.Text_CalDate_2.setText(probe_info[2])
- self.FieldProbe_combo_2.setEnabled(False)
- self.FieldProbeActive_2.setChecked(True)
- '''
- else:
- self.FieldProbe_status_2.setText("unable to open COM Port")
- self.FieldProbe_status_2.setStyleSheet("""QLineEdit { background-color: red; color: white }""")
- self.FieldProbeActive_2.setChecked(False)
- '''
- #This is the warmup time for the amps based on the time logged for power on i.e dtAmpLog
- #We are creating a class thread to feed back the count down to the UI
- #depreciated for threads ampwarmup
- def amp_warmup_calc(self): #Amp
- if self.DEBUG:
- print("In amp_warmup_calc() dtlog = ", self.dtAmpLog)
- time.sleep(1)
- temp = datetime.now()
- diff = temp - self.dtAmpLog
- diff = diff.total_seconds()/60
- if self.DEBUG:
- print("In amp_warmup_calc() dtlog diff =", diff)
- #timer_format = '{:02d}:{:02d}'.format(mins, secs)
- #print(diff)
- if diff < _GLOBALS.AMP_WARMUPTIME_MINS:
- #print("amp_warmup_calc() true")
- self.Status.setText("WARM UP")
- self.Status.setStyleSheet("""QLineEdit { background-color: yellow; color: red }""")
- return True
- else: #This does not seem to be needed
- #print("amp_warmup_calc() false")
- return False
- def equipment_close_ports(self):
- if self.FieldProbeActive.isChecked():
- self.equipment_probe.Close_probe()
- self.FieldProbe_combo.setEnabled(True)
- self.OpenPorts.setEnabled(True)
- self.FieldProbeActive.setChecked(False)
- self.FieldProbeActive_2.setChecked(False)
- self.FieldProbe_status.setText("Closed Port")
- self.FieldProbe_status.setStyleSheet("""QLineEdit { background-color: red; color: white }""")
- if self.SigGenActive.isChecked():
- self.Siggen_status.setText("Closed Port")
- self.Siggen_status.setStyleSheet("""QLineEdit { background-color: red; color: white }""")
- self.Siggen_combo.setEnabled(True)
- self.SigGenActive.setChecked(False)
- self.SigGenActive_2.setChecked(False)
- self.SweepButton.setEnabled(False)
- #kill all amps
- if self.equipment_amp == "vhf":
- self.equipment_vhf_amp.off(self.amp_in_use) #Amp
- elif self.equipment_amp == "uhf":
- self.equipment_uhf_amp.off(self.amp_in_use) #Amp
- elif self.equipment_amp =="shf":
- self.equipment_shf_amp.off(self.amp_in_use) #Amp
- else:
- self.amp_in_use = False
- self.equipment_vhf_amp.off(self.amp_in_use) #Amp
- self.equipment_uhf_amp.off(self.amp_in_use) #Amp
- self.equipment_shf_amp.off(self.amp_in_use) #Amp
- def equipment_close_fp_port(self):
- if self.FieldProbeActive_2.isChecked():
- self.equipment_probe_2.Close_probe()
- self.FieldProbe_combo_2.setEnabled(True)
- self.StartFB_Button_2.setEnabled(True)
- #self.FieldProbeActive_2.setChecked(False)
- #self.FieldProbeActive_2_2.setChecked(False)
- #-------Opens a CSV file and returns the first line as a list.
- # used to fetch the header of the cal file but not used because it seems to be out of scope??
- def file_get_headers_lst(file_path):
- print("opening file:", file_path)
- try:
- with open(file_path, 'r') as file:
- csv_reader = csv.reader(file)
- header_list = next(csv_reader)
- return header_list
- except FileNotFoundError:
- print(f"Error: File not found at '{file_path}'")
- return None
- except Exception as e:
- print(f"An error occurred: {e}")
- return None
- finally:
- print("done---------------------------------------------------")
- #**********************************************************************************************
- #kill equipment and update the UI
- def closeEvent(self, event):
- """Shuts down application on close."""
- # Return standard output to defaults.
- sys.stdout = sys.__stdout__
- super().closeEvent(event)
- #kill sig gen
- if self.SigGenActive.isChecked():
- self.equipment_siggen.rf_off()
- #kill all amps
- if self.equipment_amp == "vhf":
- self.equipment_vhf_amp.off(self.amp_in_use) #Amp
- elif self.equipment_amp == "uhf":
- self.equipment_uhf_amp.off(self.amp_in_use) #Amp
- elif self.equipment_amp =="shf":
- self.equipment_shf_amp.off(self.amp_in_use) #Amp
- else:
- self.amp_in_use = False
- self.equipment_vhf_amp.off(self.amp_in_use) #Amp
- self.equipment_uhf_amp.off(self.amp_in_use) #Amp
- self.equipment_shf_amp.off(self.amp_in_use) #Amp
- #kill field probe
- self.equipment_probe.Close_probe()
- if __name__ == "__main__":
- import sys
- app = QtWidgets.QApplication(sys.argv)
- ui = Ui()
- ui.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement