min_range_list in b rotation added
This commit is contained in:
parent
082f99aa0d
commit
4881f4de3d
@ -303,7 +303,7 @@ def sep_num_from_units(powerbox_output :str)->list:
|
||||
else:
|
||||
return [powerbox_output,]
|
||||
|
||||
def query_no_echo(instr:pyvisa.resources.Resource, command:str, sleeptime=0.01)->str:
|
||||
def query_no_echo(instr:pyvisa.resources.Resource, command:str, sleeptime=0)->str:
|
||||
"""helper function for the Attocube APS100 that queries a function to the device, removing the echo.
|
||||
|
||||
Args:
|
||||
@ -327,7 +327,7 @@ def query_no_echo(instr:pyvisa.resources.Resource, command:str, sleeptime=0.01)-
|
||||
print(f"Error communicating with instrument: {e}")
|
||||
return None
|
||||
|
||||
def write_no_echo(instr:pyvisa.resources.Resource, command:str, sleeptime=0.01)->str:
|
||||
def write_no_echo(instr:pyvisa.resources.Resource, command:str, sleeptime=0)->str:
|
||||
"""helper function for the Attocube APS100 that writes a function to the device, removing the echo.
|
||||
|
||||
Args:
|
||||
@ -572,11 +572,60 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float,
|
||||
wl = np.array(loaded_files.wavelength)
|
||||
np.savetxt("Wavelength.txt", wl)
|
||||
|
||||
|
||||
# TODO: write a function that simultaneously controls the two power supplies and perform the rotation of the B-field. => Threading
|
||||
# in function head should be func(instr1, instr2, args1, kwargs1, args2, kwargs2)
|
||||
def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.Resource,
|
||||
Babs:float, startangle:float, endangle:float, angle_stepsize:float, clockwise=True, sweepdown=False)->None:
|
||||
Babs:float, startangle:float, endangle:float, angle_stepsize:float, path_save:str, base_file_name:str, anticlockwise=True, sweepdown=False)->None:
|
||||
"""_summary_
|
||||
|
||||
Args:
|
||||
instr1 (pyvisa.resources.Resource): _description_
|
||||
instr2 (pyvisa.resources.Resource): _description_
|
||||
Babs (float): absolute B-field value in T
|
||||
startangle (float): _description_
|
||||
endangle (float): _description_
|
||||
angle_stepsize (float): _description_
|
||||
anticlockwise (bool, optional): _description_. Defaults to True.
|
||||
sweepdown (bool, optional): _description_. Defaults to False.
|
||||
"""
|
||||
if path_save is None:
|
||||
path_save = datetime.datetime.now().strftime("%Y_%m_%d_%H%M_hrs_") # TODO: add path_save, base_file_name in the function header
|
||||
|
||||
if base_file_name =='':
|
||||
base_file_name = datetime.datetime.now().strftime('%Y_%m_%d_%H.%M')
|
||||
|
||||
start_time = time.time() # start of the scan function
|
||||
|
||||
idnstr1 = query_no_echo(instr1, '*IDN?')
|
||||
|
||||
idnstr2 = query_no_echo(instr1, '*IDN?')
|
||||
|
||||
# TODO: find which one is the dual power supply, then, ramp B_x to Babs value
|
||||
if '2301034' in idnstr1: # serial no. the dual power supply
|
||||
pass
|
||||
elif '2101034' in idnstr2:
|
||||
# swap instruments, instr 1 to be the dual power supply
|
||||
instr1, instr2 = instr2, instr1
|
||||
|
||||
# TODO: compare which device has the lower rates, save initial rates lists, then set both devices to the lower rates for each range
|
||||
# then, set the initial values back
|
||||
# list of rates (with units) for diff ranges of each device, only up to Range 1 for single power supply as that is already
|
||||
# the max recommended current.
|
||||
init_range_lst1 = list(sep_num_from_units(el) for el in query_no_echo(instr1, 'RATE? 0;RATE? 1;RATE? 2').split(';'))
|
||||
init_range_lst2 = list(sep_num_from_units(el) for el in query_no_echo(instr2, 'RATE? 0;RATE? 1').split(';'))
|
||||
|
||||
min_range_lst = [min(el1[0], el2[0]) for el1,el2 in zip(init_range_lst1, init_range_lst2)] # min rates for each given range
|
||||
|
||||
write_no_echo(instr1, f'RATE 0 {min_range_lst[0]};RATE 1 {min_range_lst[1]}')
|
||||
write_no_echo(instr2, f'RATE 0 {min_range_lst[0]};RATE 1 {min_range_lst[1]}')
|
||||
|
||||
# TODO: check the device rates and ranges in the lab tmrw or friday
|
||||
|
||||
write_no_echo(instr1, f'CHAN 2;ULIM {Babs*10};SWEEP UP') # sets to B_x, the B_x upper limit and sweeps the magnet field to the upper limit
|
||||
|
||||
# TODO: include the functionalities located in the function above, update function header with the new parameters of path_save, base_file_name
|
||||
|
||||
|
||||
################################################################# END OF FUNCTION DEFS ###########################################################################################
|
||||
|
||||
@ -584,17 +633,29 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R
|
||||
|
||||
# Initialise PYVISA ResourceManager
|
||||
rm = pyvisa.ResourceManager()
|
||||
# print(rm.list_resources()) # 'ASRL8::INSTR' for dual power supply, 'ASRL9::INSTR' for single power supply
|
||||
# print(rm.list_resources())
|
||||
# 'ASRL8::INSTR' for dual power supply, 'ASRL9::INSTR' for single power supply (online PC)
|
||||
# 'ASRL10::INSTR' for dual power supply, 'ASRL12::INSTR' for single power supply (offline PC)
|
||||
|
||||
|
||||
# Open the connection with the APS100 dual power supply
|
||||
powerbox_dualsupply = rm.open_resource('ASRL8::INSTR',
|
||||
baud_rate=9600, # Example baud rate, adjust as needed
|
||||
powerbox_dualsupply = rm.open_resource('ASRL10::INSTR',
|
||||
baud_rate=9600,
|
||||
data_bits=8,
|
||||
parity= pyvisa.constants.Parity.none,
|
||||
stop_bits= pyvisa.constants.StopBits.one,
|
||||
timeout=5000)# 5000 ms timeout
|
||||
timeout=100)# 5000 ms timeout
|
||||
|
||||
# Open the connection with the APS100 dual power supply
|
||||
powerbox_singlesupply = rm.open_resource('ASRL12::INSTR',
|
||||
baud_rate=9600,
|
||||
data_bits=8,
|
||||
parity= pyvisa.constants.Parity.none,
|
||||
stop_bits= pyvisa.constants.StopBits.one,
|
||||
timeout=100)# 5000 ms timeout
|
||||
|
||||
write_no_echo(powerbox_dualsupply, 'REMOTE') # turn on the remote mode
|
||||
write_no_echo(powerbox_singlesupply, 'REMOTE') # turn on the remote mode
|
||||
|
||||
# TODO: test functionality of the magnet_coil param later on, should work... as this code below is basically implemented inside the scan func.
|
||||
# select axis for the dual supply, either z-axis(CHAN 1 ^= Supply A) or x-axis(CHAN 2 ^= Supply B)
|
||||
@ -644,5 +705,7 @@ sweep_b_val(powerbox_dualsupply, set_llim_bval, set_ulim_bval, set_res_bval, 'z-
|
||||
# Internally, axes are numbered 0 to 2
|
||||
|
||||
write_no_echo(powerbox_dualsupply, 'LOCAL') # turn off the remote mode
|
||||
write_no_echo(powerbox_singlesupply, 'LOCAL') # turn off the remote mode
|
||||
# time.sleep(0.5)
|
||||
powerbox_dualsupply.close()
|
||||
powerbox_singlesupply.close()
|
Loading…
Reference in New Issue
Block a user