From 736a5a8e141cb3f71421408af7626930d9d946f9 Mon Sep 17 00:00:00 2001 From: ryantan Date: Tue, 15 Apr 2025 13:56:54 +0200 Subject: [PATCH] added write_no_echo in listen helper func --- Mag_Field_Sweep_2024_10_21.py | 29 +++++++++++++++++++---------- Test.py | 8 ++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Mag_Field_Sweep_2024_10_21.py b/Mag_Field_Sweep_2024_10_21.py index a06a5f3..1b75d9f 100644 --- a/Mag_Field_Sweep_2024_10_21.py +++ b/Mag_Field_Sweep_2024_10_21.py @@ -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() diff --git a/Test.py b/Test.py index 2a70cfa..33b9349 100644 --- a/Test.py +++ b/Test.py @@ -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)) + \ No newline at end of file