Save-Path-File-Changes #1

Merged
rtan merged 41 commits from Save-Path-File-Changes into main 2025-04-23 13:56:19 +00:00
2 changed files with 27 additions and 10 deletions
Showing only changes of commit 736a5a8e14 - Show all commits

View File

@ -792,7 +792,7 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R
endangle = endangle % 360 # ensures that the angles are within [0,360)
idnstr1 = query_no_echo(instr1, '*IDN?')
idnstr2 = query_no_echo(instr1, '*IDN?')
idnstr2 = query_no_echo(instr2, '*IDN?')
intensity_data = [] # To store data from each scan
cwd = os.getcwd() # save original directory
@ -855,15 +855,26 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R
# value = 0 # Simulate receiving a float from the device INSERT QUERY NO ECHO HERE TO ASK FOR DEVICE IMAG
if '2301034' in device_id:
value = sep_num_from_units(query_no_echo(instr1, 'IMAG?'))[0]*0.1 # convert kG to T
if value <= target_value[device_id]:
write_no_echo(instr1, f"CHAN 2;ULIM {target_value[device_id]*10};SWEEP UP")
else:
write_no_echo(instr1, "CHAN 2;LLIM {target_value[device_id]*10};SWEEP DOWN")
elif '2101014' in device_id:
value = sep_num_from_units(query_no_echo(instr2, 'IMAG?'))[0]*0.1 # convert kG to T
if value <= target_value[device_id]:
write_no_echo(instr2, f"ULIM {target_value[device_id]*10};SWEEP UP")
else:
write_no_echo(instr2, "LLIM {target_value[device_id]*10};SWEEP DOWN")
else:
continue # Skip if device ID is not recognized
print(f"Device {device_id} reports value: {value} T")
with lock:
shared_values[device_id] = value
# Check if both devices have met their targets
if all(shared_values.get(device) is not None and abs(shared_values[device] - target_value[device]) <= 0.0001
for device in shared_values):
if all(shared_values.get(device) is not None and abs(value - target_value[device]) <= 0.0001
for device,value in shared_values.items()):
print(f"Both devices reached their target values: {shared_values}")
all_targets_met_event.set() # Signal that both targets are met
@ -891,6 +902,10 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R
# Wait until both devices meet their target values
all_targets_met_event.wait()
print(f"Both target values for iteration {iteration+1} met. Performing action...")
# Clean up threads
for thread in threads:
thread.join()
print(f"Threads for iteration {iteration+1} closed.\n")
# Perform some action after both targets are met
# we acquire with the LF
@ -912,12 +927,6 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R
#append the intensity data as it is (so after every #of_wl_points, the spectrum of the next point begins)
intensity_data.append(loaded_files.data[0][0][0])
# Clean up threads
for thread in threads:
thread.join()
print(f"Threads for iteration {iteration+1} closed.\n")
#prints total time the mapping lasted
end_time = time.time()

View File

@ -138,5 +138,13 @@ if __name__=="__main__":
# print(generate_coord_list_fixed_angle(10, 5, 1, reverse=False))
testdict = [{'2301034': bval[0], '2101014': bval[1]} for bval in coordinates]
print(f"{testdict=}")
for i, target in enumerate(testdict):
print(i, target.keys())
# for key in target.keys():
# print(type(key))