-
Notifications
You must be signed in to change notification settings - Fork 89
Windows detection update #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows detection update #281
Conversation
The Windows registry is responsible for keeping track of all USB devices. Previously, we were using a portion of the registry that is always cached, even if a device is removed. This caused certain network drives to appear as mbeds if they attached to a previously attached mbed's drive letter (network drives don't appear to update the registry). Now we are checking the enumeration part of the registry to ensure the device is actually plugged in before return it as a result.
This could use a little more testing, specifically on Windows 7 since I've been testing on Windows 10 |
Ok, I've tested this on a Windows 7 VM and I'm reasonably confident that this isn't breaking any of the detection! |
There's apparently an issue with the detection with this update, just got an incorrect serial port name using this branch, so let's hold off on this for now. |
I believe I've patched the issue, however I still need to test with a bunch of hardware again to make sure I didn't break anything. I probably should document the full detection strategy at the top of the file too. |
Ok, I've ran this a bunch of hardware on my desk and things didn't break, so I'm reasonably happy with this at the moment. Open to review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a few comments waiting!
mbed_lstools/windows.py
Outdated
for name, vid in zip(self.iter_keys_as_str(usb_devs), | ||
self.iter_keys(usb_devs)): | ||
|
||
def composite_device_key(device): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this method-private funciton into a private static method?
# These keys in the registry enumerate all composite DosDevices | ||
# as a value with an integer. This check ensures we ignore a few | ||
# helper values in the registry key. | ||
_ = int(point) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might need point.decode("utf-16le", "ignore")
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that and it broke the whole thing on my machine lol. For debugging this I added this code:
logger.warning(point)
logger.warning(point.decode("utf-16le", "ignore"))
logger.warning('------')
_ = int(point)
$ mbedls
WARNING:mbedls.lstools_win7:0
WARNING:mbedls.lstools_win7:
WARNING:mbedls.lstools_win7:------
WARNING:mbedls.lstools_win7:Count
WARNING:mbedls.lstools_win7:潃湵
WARNING:mbedls.lstools_win7:------
WARNING:mbedls.lstools_win7:NextInstance
WARNING:mbedls.lstools_win7:敎瑸湉瑳湡散
WARNING:mbedls.lstools_win7:------
WARNING:mbedls.lstools_win7:1
WARNING:mbedls.lstools_win7:
WARNING:mbedls.lstools_win7:------
WARNING:mbedls.lstools_win7:Count
WARNING:mbedls.lstools_win7:潃湵
WARNING:mbedls.lstools_win7:------
WARNING:mbedls.lstools_win7:NextInstance
WARNING:mbedls.lstools_win7:敎瑸湉瑳湡散
WARNING:mbedls.lstools_win7:------
WARNING:mbedls.lstools_win7:0
WARNING:mbedls.lstools_win7:
WARNING:mbedls.lstools_win7:------
If you think I need to try different decode options, just let me know!
except ValueError: | ||
continue | ||
|
||
label_parts = label.split('\\') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might need label.decode("utf-16le", "ignore").split('\\')
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto here as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually strike that, doesn't seem to break anything.
try: | ||
composite_parent_id_prefix, _ = winreg.QueryValueEx(composite_key, | ||
'ParentIdPrefix') | ||
parent_id_prefixes.append(composite_parent_id_prefix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decode?
@theotherjimmy and I went through this offline, looks like it doesn't need |
@theotherjimmy I went over this again and I think everything is ok. I fixed the static function you mentioned above. I also added back the I think I need to get a test in for this implementation of |
Ok, test coverage added! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thanks for the test updates!
This was made in response to #279.
The Windows registry is responsible for keeping track of all USB
devices. Previously, we were using a portion of the registry that is
always cached, even if a device is removed. This caused certain network
drives to appear as mbeds if they attached to a previously attached
mbed's drive letter (network drives don't appear to update the registry).
Now we are checking the enumeration part of the registry to ensure the
device is actually plugged in before return it as a result.
This also has the benefit that we no longer need to call the subprocess
dir
for each potentially found device. This translate to an execution speed up! My preliminary tests show the speed up is on the order of 50-100ms.