Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/LockIn-SignalRecovery_7265DSP/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,16 +505,11 @@ def find_best_time_constant_key(self, time_constant):

time_constant = self.value_to_float(time_constant)

# sum over boolean entries leads to index of new time_constant
# this also works if the order of the time constants list is lost as the number of True and False
# remains the same
tc_index = sum(np.array(self.timeconstants_numbers) < time_constant) # sum over boolean entries
tc_index = sum(np.array(self.timeconstants_numbers) > time_constant) # sum over boolean entries

if tc_index < len(self.timeconstants):
new_tc_key = list(self.timeconstants.keys())[tc_index]
else:
# if tc_index equals the length of time constants, the request time constant is longer than any possible
# time constant, so we just return the key of the highest possible one.
new_tc_key = "100k"

return new_tc_key
Expand All @@ -529,8 +524,10 @@ def auto_time_constant(self, factor=10.0):
"""

frq = self.get_frequency()
period = 1.0/frq
new_tc = factor*period

period = 1.0 / frq
new_tc = factor / period

new_tc_key = self.find_best_time_constant_key(new_tc)

# sending the new time constant command
Expand All @@ -541,11 +538,11 @@ def wait_for_complete(self):

starttime = time.time()
while True:
# only the direct GPIB status byte call works as it can be acquired even when the lock-in is
# busy with auto sensitivity operation
stb = self.port.port.read_stb()
if stb & 1 == 1: # first byte indicates whether command is processed or not

if stb & 1 == 0:
break

time.sleep(0.01)
if time.time() - starttime > 20:
raise Exception("Timeout during wait for completion.")
Comment on lines 541 to 548

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/implement Make this wait_for_complete method work like it's commonly done in the repo.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Implementation 🛠️

Implementation: Refactor the wait_for_complete method to follow common patterns in the repository by using a timeout parameter and implementing a more structured polling loop with proper timeout handling.

Suggested change
stb = self.port.port.read_stb()
if stb & 1 == 1: # first byte indicates whether command is processed or not
if stb & 1 == 0:
break
time.sleep(0.01)
if time.time() - starttime > 20:
raise Exception("Timeout during wait for completion.")
def wait_for_complete(self, timeout=20.0):
"""
Wait for the device to complete the current operation.
Args:
timeout: float, maximum time to wait in seconds
"""
start_time = time.time()
while (time.time() - start_time) < timeout:
stb = self.port.port.read_stb()
if stb & 1 == 0:
break
time.sleep(0.01)
else:
raise Exception("Timeout during wait for completion.")
📄 References

See review comment here

Expand Down