added enable output at bottom of the code

This commit is contained in:
Ryan Tan 2024-10-31 11:15:23 +01:00
parent 96405afdad
commit b74152ff2c

View File

@ -274,6 +274,7 @@ def save_as_csv(filename, position_x, position_y):
################################################################# RYAN'S FUNCTIONS HERE ##########################################################################################
# NOTE: leave this function here, could be useful for future uses
def polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True):
# TODO: DOCS
"""Creates a list of discrete cartesian coordinates (x,y), given the radius, start- and end angles, the angle step size, and the direction of rotation.
@ -359,18 +360,6 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
res:float, base_file_name='',
reversescan_bool=False, zerowhenfin_bool=False, loopscan_bool=False)->None:
# TODO: docstring
"""_summary_
Args:
handle (int): _description_
init_voltage (float): _description_
final_voltage (float): _description_
res (float): _description_
base_file_name (str, optional): _description_. Defaults to ''.
reversescan_bool (bool, optional): _description_. Defaults to False.
zerowhenfin_bool (bool, optional): _description_. Defaults to False.
loopscan_bool (bool, optional): _description_. Defaults to False.
"""
def pyramid_list(lst) -> Union[list, np.ndarray]:
"""reverses the list and removes the first element of reversed list. Then, this is appended to
the end of the original list and returned as the 'pyramid' list.
@ -407,16 +396,10 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
# creates list of voltage values to measure at, with given resolution, in V
voltage_lst = np.arange(init_voltage, final_voltage + res, res)
# TODO: remove the two lines below, probs not needed
init_lim, subsequent_lim = 'LLIM', 'ULIM'
init_sweep, subsequent_sweep = 'DOWN', 'UP'
# if reverse scan, flips the direction of the scan
if reversescan_bool:
voltage_lst = voltage_lst[::-1]
init_lim, subsequent_lim = subsequent_lim, init_lim
init_sweep, subsequent_sweep = subsequent_sweep, init_sweep
# creates the pyramid list of B vals if one were to perform a hysteresis measurement
if loopscan_bool:
@ -428,9 +411,10 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
cwd = os.getcwd() # save original directory
# TODO: edit the helpe_scan_func and scanning loop below, after this, the code should be complete!
# possibly doesnt even need the initial and ffinal lims, no need to differentiate
# NOTE: helper function for the scanning loop
def helper_scan_func(idx, bval, instr=instr, init_lim=init_lim, init_sweep=init_sweep,
subsequent_lim=subsequent_lim, subsequent_sweep=subsequent_sweep, sleep=5):
def helper_scan_func(idx, bval, instr=handle, init_lim=init_lim, init_sweep=init_sweep,
subsequent_lim=subsequent_lim, subsequent_sweep=subsequent_sweep, sleep=5): # TODO: remove sleep function argument
if idx == 0: # for first iteration, sweep to one of the limits
write_no_echo(instr, f'{init_lim} {bval*10}') # convert back to kG
write_no_echo(instr, f'SWEEP {init_sweep}')
@ -438,10 +422,11 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
write_no_echo(instr, f'{subsequent_lim} {bval*10}') # convert back to kG
write_no_echo(instr, f'SWEEP {subsequent_sweep}')
# read the actual voltage and print it out
actual_bval = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1 # convert kG to T
print(f'Actual magnet strength: {actual_bval} T,', f'Target magnet strength: {bval} T')
while abs(actual_bval - bval) > 0.0001:
while abs(actual_bval - bval) > 0.0001: # if the actual voltage
time.sleep(5) # little break
actual_bval = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1
# update the actual bval
@ -456,7 +441,7 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
if i <= middle_index_voltage_lst:
helper_scan_func(i, bval)
else:
helper_scan_func(i, bval, instr=instr, init_lim=subsequent_lim, init_sweep=subsequent_sweep,
helper_scan_func(i, bval, instr=handle, init_lim=subsequent_lim, init_sweep=subsequent_sweep,
subsequent_lim=init_lim, subsequent_sweep=init_sweep, sleep=5)
time.sleep(5)
@ -531,6 +516,16 @@ try:
sys.exit()
print("Connected to serial number ", serialnumber)
# Enable global output
# TODO: idk why disable output then only enable, maybe remove later on
klcSetEnable(KLC_handle,1) # 1 enable, 2 disable
print("Enable output\n")
if(klcSetEnable(KLC_handle, 1)<0): # 1 enable, 2 disable
print("klcSetEnable failed")
en=[0]
if(klcGetEnable(KLC_handle, en)<0): # check if the set enable fucntion was called successfully
print("klcGetEnable failed")
# TODO: remove this commented code block later
# Initialise PYVISA ResourceManager
# rm = pyvisa.ResourceManager()