def device_query(self, command): if self.status_flag == 1: if config['interface'] == 'rs232': answer = self.device.query(command) # device is quite slow general.wait('10 ms') elif config['interface'] == 'ethernet': answer = self.device.query(command) # device is quite slow general.wait('10 ms') return answer else: general.message("No Connection") self.status_flag = 0 sys.exit()
def power_supply_interlock(self, *interlock): if test_flag != 'test': if len(interlock) == 0: raw_answer = int(self.device_query('ILOC?')) answer = cutil.search_keys_dictionary(lock_dict, raw_answer) return answer else: general.message("Invalid argument") sys.exit() elif test_flag == 'test': if len(interlock) == 0: answer = test_lock return answer else: assert (1 == 2), "Invalid argument"
def delay_gen_output_polarity(self, *polarity): if test_flag != 'test': if len(polarity) == 2: ch = str(polarity[0]) plr = str(polarity[1]) if ch in output_channel_dict: flag_1 = output_channel_dict[ch] if plr in polarity_dict: flag_2 = polarity_dict[plr] if int(self.device_query('OM ' + str(flag_1))) != 3: general.wait('30 ms') self.device_write('OP ' + str(flag_1) + ',' + str(flag_2)) else: general.message("You are in Variable mode") else: general.message("Incorrect polarity") sys.exit() else: general.message("Invalid channel") sys.exit() elif len(polarity) == 1: ch = str(polarity[0]) if ch in output_channel_dict: flag = output_channel_dict[ch] raw_answer = int(self.device_query('OP ' + str(flag))) answer = cutil.search_keys_dictionary(polarity_dict, raw_answer) return answer else: general.message("Invalid channel") sys.exit() else: general.message("Invalid argument") sys.exit() elif test_flag == 'test': if len(polarity) == 2: ch = str(polarity[0]) plr = str(polarity[1]) assert(ch in output_channel_dict), 'Invalid channel argument' assert(plr in polarity_dict), 'Invalid polarity argument' elif len(polarity) == 1: ch = str(polarity[0]) assert(ch in output_channel_dict), 'Invalid channel argument' answer = test_polarity return answer
def __init__(self): if test_flag != 'test': if config['interface'] == 'rs232': try: self.status_flag = 1 rm = pyvisa.ResourceManager() self.device = rm.open_resource( config['serial_address'], read_termination=config['read_termination'], write_termination=config['write_termination'], baud_rate=config['baudrate'], data_bits=config['databits'], parity=config['parity'], stop_bits=config['stopbits']) self.device.timeout = config['timeout'] # in ms try: # test should be here self.device_write('*CLS') # better to have a pause here general.wait('30 ms') # When TOKN OFF, the DC205 responds with # the numeric version of the token quantity self.device_write('TOKN 0') except pyvisa.VisaIOError: self.status_flag = 0 general.message("No connection") sys.exit() except BrokenPipeError: general.message("No connection") self.status_flag = 0 sys.exit() except pyvisa.VisaIOError: general.message("No connection") self.status_flag = 0 sys.exit() except BrokenPipeError: general.message("No connection") self.status_flag = 0 sys.exit() elif config['interface'] != 'rs232': general.message('Invalid interface') sys.exit() elif test_flag == 'test': pass
def power_supply_measure(self, channel): if test_flag != 'test': ch = str(channel) if ch in channel_dict: raw_answer_1 = self.device_query('VOUT?') general.wait('20 ms') raw_answer_2 = self.device_query('IOUT?') answer = [float(raw_answer_1), float(raw_answer_2)] return answer else: general.message('Invalid channel') sys.exit() elif test_flag == 'test': ch = str(channel) assert (ch in channel_dict), 'Invalid channel' answer = test_measure return answer
def freq_counter_period(self, channel): if test_flag != 'test': if channel == 'CH1': answer = float( self.device_query(':MEASURE:PERiod? (@1)')) * 1000000 return answer elif channel == 'CH2': answer = float( self.device_query(':MEASURE:PERiod? (@2)')) * 1000000 return answer else: general.message('Invalid argument') sys.exit() elif test_flag == 'test': assert (channel == 'CH1' or channel == 'CH2'), 'Invalid channel is given' answer = test_period return answer
def freq_counter_impedance(self, *impedance): if test_flag != 'test': if len(impedance) == 2: ch = str(impedance[0]) imp = str(impedance[1]) if imp in impedance_dict: flag = impedance_dict[imp] if ch == 'CH1': self.device_write(":INPut1:IMPedance " + str(flag)) elif ch == 'CH2': general.message('The impedance for CH2 is only 50 Ohm') elif ch == 'CH3': general.message('Invalid channel') elif len(impedance) == 1: ch = str(impedance[0]) if ch == 'CH1': raw_answer = float(self.device_query(":INPut1:IMPedance?")) answer = cutil.search_keys_dictionary( impedance_dict, raw_answer) return answer elif ch == 'CH2': answer = '50' general.message('The impedance for CH2 is only 50 Ohm') return answer elif ch == 'CH3': general.message('Invalid channel') else: general.message('Invalid argument') sys.exit() elif test_flag == 'test': if len(impedance) == 2: ch = str(impedance[0]) imp = str(impedance[1]) assert (ch == 'CH1' or ch == 'CH2'), 'Invalid channel is given' assert (imp in impedance_dict), 'Invalid impedance is given' elif len(impedance) == 1: ch = str(impedance[0]) assert (ch == 'CH1' or ch == 'CH2'), 'Invalid channel is given' answer = test_impedance return answer else: assert (1 == 2), "Incorrect impedance argument"
def freq_counter_coupling(self, *coupling): if test_flag != 'test': if len(coupling) == 2: ch = str(coupling[0]) cpl = str(coupling[1]) if ch == 'CH1': self.device_write(":INPut1:COUPling " + str(cpl)) elif ch == 'CH2': general.message('The coupling for CH2 is only AC') elif ch == 'CH3': general.message('Invalid channel') elif len(coupling) == 1: ch = str(coupling[0]) if ch == 'CH1': answer = str(self.device_query(":INPut1:COUPling?")) return answer elif ch == 'CH2': answer = 'AC' general.message('The coupling for CH2 is only AC') return answer elif ch == 'CH3': general.message('Invalid channel') else: general.message('Invalid argument') sys.exit() elif test_flag == 'test': if len(coupling) == 2: ch = str(coupling[0]) cpl = str(coupling[1]) assert (ch == 'CH1' or ch == 'CH2'), 'Invalid channel is given' assert (cpl == 'AC' or cpl == 'DC'), 'Invalid coupling is given' elif len(coupling) == 1: ch = str(coupling[0]) assert (ch == 'CH1' or ch == 'CH2'), 'Invalid channel is given' answer = test_coupling return answer else: assert (1 == 2), "Incorrect coupling argument"
def __init__(self): if test_flag != 'test': if config['interface'] == 'gpib': try: import Gpib self.status_flag = 1 self.device = Gpib.Gpib(config['board_address'], config['gpib_address']) try: pass # test should be here #self.device_write('*CLS') except BrokenPipeError: general.message("No connection") self.status_flag = 0 sys.exit() except BrokenPipeError: general.message("No connection") self.status_flag = 0 sys.exit() else: general.message("Incorrect interface setting") self.status_flag = 0 sys.exit() elif test_flag == 'test': pass
def __init__(self): if test_flag != 'test': if config['interface'] == 'rs232': try: self.status_flag = 1 rm = pyvisa.ResourceManager() self.device = rm.open_resource( config['serial_address'], write_termination=config['write_termination'], baud_rate=config['baudrate'], data_bits=config['databits'], parity=config['parity'], stop_bits=config['stopbits']) self.device.timeout = config['timeout'] # in ms self.field = 0. self.field_step = 0. try: # test should be here self.status_flag = 1 except pyvisa.VisaIOError: self.status_flag = 0 general.message("No connection") sys.exit() except BrokenPipeError: general.message("No connection") self.status_flag = 0 sys.exit() except pyvisa.VisaIOError: general.message("No connection") sys.exit() except BrokenPipeError: general.message("No connection") self.status_flag = 0 sys.exit() # measure field in Tesla self.device_write('D1') # switch to multiplexer A self.device_write('PA') # switch to AUTO mode self.device_write('A1') # activate the search, starting at about 3.5 T self.device_write('H3500') elif test_flag == 'test': pass