Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||
|
/ask How is the wait_for_complete method implemented elsewhere? |
Ask❓How is the wait_for_complete method implemented elsewhere? Answer:Based on the PR diff provided, I can only see the implementation of def wait_for_complete(self):
starttime = time.time()
while True:
stb = self.port.port.read_stb()
if stb & 1 == 0: # Changed from == 1 to == 0
break
time.sleep(0.01)
if time.time() - starttime > 20:
raise Exception("Timeout during wait for completion.")However, I cannot see implementations from other instrument drivers in this PR to make comparisons. To provide a comprehensive answer about how
The key change in this PR is the status bit check logic - it was changed from Common patterns for wait_for_complete methods in instrument drivers typically include:
If you could provide access to other driver implementations, I could give a more detailed comparison of different approaches used across the codebase. |
| 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.") |
There was a problem hiding this comment.
/implement Make this wait_for_complete method work like it's commonly done in the repo.
There was a problem hiding this comment.
Code Implementation 🛠️
Implementation: Refactor the wait_for_complete method to follow the common pattern used in the repository by using a while loop with proper timeout handling and consistent sleep intervals.
| 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.") | |
| timeout = 20.0 | |
| sleep_time = 0.01 | |
| start_time = time.time() | |
| while time.time() - start_time < timeout: | |
| stb = self.port.port.read_stb() | |
| if stb & 1 == 0: | |
| break | |
| time.sleep(sleep_time) | |
| else: | |
| raise Exception("Timeout during wait for completion.") |
See review comment here
PR Type
Bug fix, Enhancement
Description
Corrected logic for selecting time constant key.
Fixed calculation of new time constant in auto adjustment.
Improved wait loop condition for command completion.
Changes walkthrough 📝
main.py
Fix and enhance time constant handling and wait logicsrc/LockIn-SignalRecovery_7265DSP/main.py