forked from pyocd/libusb-package
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
34 lines (27 loc) · 1.06 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
import sys
import libusb_package
import usb.core
import usb.backend.libusb1
def main():
# Test get_library_path().
path = libusb_package.get_library_path()
print(f"Path to included library: {path}")
# Test find_library().
libusb1_backend = usb.backend.libusb1.get_backend(find_library=libusb_package.find_library)
if not libusb1_backend:
print("Unable to load libusb backend!")
sys.exit(1)
print(f"libusb1_backend = {libusb1_backend}")
# Test get_libusb1_backend().
print("usb.core.show_devices output:")
print(usb.core.show_devices(backend=libusb_package.get_libusb1_backend()))
# Try out the find() wrapper.
print("libusb_package.find output:")
for dev in libusb_package.find(find_all=True):
try:
print(f"{dev.idVendor:04x}:{dev.idProduct:04x}: {dev.manufacturer} {dev.product} ({dev.serial_number})")
except Exception as err:
print(f"{dev.idVendor:04x}:{dev.idProduct:04x}: error reading strings ({err})")
if __name__ == "__main__":
main()