Finds USB2CAN Serial Number by USB Name #1129
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR changes the method of finding USB2CAN devices from querying all
USB_ControllerDevices
whose serial numbers start with "ED" to querying allCIM_LogicalDevices
that contains the name "USB2CAN".Background:
I recently bought a USB2CAN dongle from 8devices and it didn't show up in python-can. After looking through the source code, I realized it's because my dongle's serial number didn't start with "ED" (but did end with it) which is how python-can determines if a USB2CAN dongle is connected.
To make things more robust, I changed the query to find all devices that contain "USB2CAN" in their name and return the serial number by parsing the
DeviceID
which is in the formatUSB\<VID><PID>\<SERIAL_NUMBER>
. I also kept the serial matching argument so users can select one if multiple are connected. I can also switch this to use the VID/PID of the dongle if that's more robust than the USB name.