How do I switch backends in libusb for python?

∥☆過路亽.° 提交于 2019-12-24 16:24:49

问题


I am using pyusb and according to the docs it runs on any one of three backends. libusb01 libusb10 and openusb. I have all three backends installed. How can I tell which backend it is using and how can I switch to a different one?


回答1:


I found the answer by looking inside the usb.core source file.

You do it by importing the backend and then setting a parameter inside the find method of usb.core. Like so:

import usb.backend.libusb1 as libusb1
import usb.backend.libusb0 as libusb0
import usb.backend.openusb as openusb

and then any one of:

devices = usb.core.find(find_all=1, backend=libusb1.get_backend() )    
devices = usb.core.find(find_all=1, backend=libusb0.get_backend() )    
devices = usb.core.find(find_all=1, backend=openusb.get_backend() )

This assumes you are using pyusb-1.0.0a3. For 1.0.0a2 the libs are called libusb10, libusb01 and openusb. Of course, you'd only need to import the one you want.



来源:https://stackoverflow.com/questions/19189194/how-do-i-switch-backends-in-libusb-for-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!