Skip to content
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

Not all devices are released with UsbTools.release_all_devices #343

Open
marcintomiczek opened this issue May 30, 2023 · 1 comment
Open

Comments

@marcintomiczek
Copy link

I am using pyftdi to communicate with USB device to perform some tests, in which I'm setting pins on the device.
To do this, I communicate with device in following manner:

ftdi = Ftdi()
device = UsbTools.get_device(UsbDeviceDescriptor(...)
ftdi.open_from_device(device, interface=1)
pins = ftdi.read_pins()
ftdi.close()

Between different test cases, external tool is executed in separate process, that verifies if test environment is in expected state, which also requires access to usb device.
It looks like before that tool is executed, all devices must have resources released back.
Calling UsbTools.release_all_devices() seems to not solve this.
This is probably due to the way UsbTools.get_device iterates over all USB devices first, and they are not kept after in UsbTools.Devices dictionary (only those that match UsbDeviceDescriptor are kept).

I do the following workaround to ensure that all resources are released:

for devs in UsbTools.UsbDevices.values():  # another dictionary
    for dev in devs:
        usb.util.dispose_resources(dev)

It was quite difficult to come up with this solution and I believe UsbTools.release_all_devices()
should allow to handle this situation on its own.

@eblot
Copy link
Owner

eblot commented Jun 29, 2023

Yes, I think you're right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants