如何在libusb中为python切换后端?
我正在使用pyusb,根据文档,它可以在三个后端中的任何一个上运行. libusb01 libusb10和openusb.我已经安装了所有三个后端.如何知道正在使用哪个后端以及如何切换到其他后端?
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?
我通过查看usb.core源文件找到了答案.
I found the answer by looking inside the usb.core source file.
您可以通过导入后端,然后在usb.core的find方法内设置参数来实现.像这样:
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() )
这假设您正在使用pyusb-1.0.0a3.对于1.0.0a2,这些库称为libusb10,libusb01和openusb.当然,您只需要导入所需的那个.
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.