diff --git a/20240709SerdarModScript.py b/20240709SerdarModScript.py index d5cbe09..9f1fce3 100644 --- a/20240709SerdarModScript.py +++ b/20240709SerdarModScript.py @@ -351,11 +351,10 @@ def write_no_echo(instr:pyvisa.resources.Resource, command:str, sleeptime=0.01)- except pyvisa.VisaIOError as e: print(f"Error communicating with instrument: {e}") -# TODO: implement the reverse scan and zero when finish functionality # receive values in units of T, rescale in kg to talk with the power supplyy. 1T = 10kG def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float, res:float, Settings:str, base_file_name='', path_save="C:/Users/localadmin/Desktop/Users/Lukas/2024_02_08_Map_test", - singlepowersupply_bool=False, reversescan_bool=False, zerowhenfin_bool=False)->None: + reversescan_bool=False, zerowhenfin_bool=False)->None: """ this function performs a sweep of the B field of the chosen magnet coil. It creates a list o B values from the given min and max values, with the given resolution. For each value, a measurement of the spectrum of the probe in the cryostat is made, using the LightField spectrometer. @@ -375,26 +374,44 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float, ValueError: when By limit is exceeded. ValueError: when Bz limit is exceeded. ValueError: when Bx limit is exceeded. + ConnectionError: when no device is connected. """ '''''' if base_file_name =='': base_file_name = datetime.datetime.now().strftime('%Y_%m_%d_%H.%M') - start_time = time.time() + start_time = time.time() # start of the scan function + + # TODO: queries the serial number of the device, and from there, check the if the input limits exceed the recommended limits + instr_info = query_no_echo(instr, '*IDN?') + instr_bsettings = list(sep_num_from_units(el) for el in query_no_echo(instr, 'UNITS?;LLIM?;ULIM?').split(';')) # deliver a 3 element tuple of tuples containing the set unit, llim and ulim if instr_bsettings[0][0] == 'T': instr_bsettings[1][0] = instr_bsettings[1][0]*0.1 # rescale kG to T, device accepts values only in kG or A, eventho we set it to T instr_bsettings[2][0] = instr_bsettings[2][0]*0.1 - if singlepowersupply_bool: # checks limits of Bx or By + # if singlepowersupply_bool: # checks limits of Bx or By + # if (min_bval< -BY_MAX) or (max_bval > BY_MAX): + # raise ValueError('Input limits exceed that of the magnet By! Please input smaller limits.') + # elif '1' in query_no_echo(instr, 'CHAN?'): # check if its the coils for Bz + # if (min_bval < -BZ_MAX) or (max_bval > BZ_MAX): + # raise ValueError('Input limits exceed that of the magnet (Bz)! Please input smaller limits.') + # else: # checks limits of Bx + # if (min_bval< -BX_MAX) or (max_bval > BX_MAX): + # raise ValueError('Input limits exceed that of the magnet Bx! Please input smaller limits.') + + if '2101014' in instr_info: # single power supply if (min_bval< -BY_MAX) or (max_bval > BY_MAX): raise ValueError('Input limits exceed that of the magnet By! Please input smaller limits.') - elif '1' in query_no_echo(instr, 'CHAN?'): # check if its the coils for Bz - if (min_bval < -BZ_MAX) or (max_bval > BZ_MAX): - raise ValueError('Input limits exceed that of the magnet (Bz)! Please input smaller limits.') - else: # checks limits of Bx - if (min_bval< -BX_MAX) or (max_bval > BX_MAX): - raise ValueError('Input limits exceed that of the magnet Bx! Please input smaller limits.') + elif '2301034' in instr_info: # dual power supply + if '1' in query_no_echo(instr, 'CHAN?'): # check if its the coils for Bz + if (min_bval < -BZ_MAX) or (max_bval > BZ_MAX): + raise ValueError('Input limits exceed that of the magnet (Bz)! Please input smaller limits.') + else: # checks limits of Bx + if (min_bval< -BX_MAX) or (max_bval > BX_MAX): + raise ValueError('Input limits exceed that of the magnet Bx! Please input smaller limits.') + else: + raise ConnectionError('Device is not connected!') write_no_echo(instr, f'LLIM {min_bval*10};ULIM {max_bval*10}') # sets the given limits, must convert to kG for the device to read bval_lst = np.arange(min_bval, max_bval + res, res) # creates list of B values to measure at, with given resolution, in T @@ -476,6 +493,8 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float, elapsed_time = (end_time - start_time) / 60 print('Scan time: ', elapsed_time, 'minutes') + write_no_echo(instr, f'LLIM {instr_bsettings[1][0]*10};ULIM {instr_bsettings[2][0]*10}') # reset the initial limits of the device after the scan + if zerowhenfin_bool: write_no_echo(instr, 'SWEEP ZERO') # if switched on, discharges the magnet after performing the measurement loop above @@ -560,11 +579,10 @@ experiment_name = f"{set_llim_bval}T_to_{set_ulim_bval}T_{set_res_bval}T_{dateti # perform the B-field measurement for selected axis above # sweep_b_val(powerbox_dualsupply, set_llim_bval, set_ulim_bval, set_res_bval, experiment_settings, experiment_name) sweep_b_val(powerbox_dualsupply, set_llim_bval, set_ulim_bval, set_res_bval, - experiment_settings, experiment_name, singlepowersupply_bool=False, zerowhenfin_bool=True, reversescan_bool=False) + experiment_settings, experiment_name, zerowhenfin_bool=True, reversescan_bool=False) # Internally, axes are numbered 0 to 2 write_no_echo(powerbox_dualsupply, 'LOCAL') # turn off the remote mode # time.sleep(0.5) powerbox_dualsupply.close() -