Created
May 26, 2020 23:17
-
-
Save RyanHope/a24dd0cf29753f83ffaa8039a62c163e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import platform | |
import usb.core | |
import usb.backend.libusb1 | |
from ctypes import c_void_p | |
from pyftdi.ftdi import Ftdi | |
backend = usb.backend.libusb1.get_backend() | |
if backend and platform.system() == "Windows": | |
backend.lib.libusb_set_usbdk.argtypes = [c_void_p] | |
backend.lib.libusb_set_usbdk(backend.ctx) | |
def get_interfaces(): | |
interfaces = {} | |
for device in usb.core.find( | |
find_all=True, idVendor=Ftdi.FTDI_VENDOR, backend=backend | |
): | |
for cfg in device.configurations(): | |
for interface in cfg.interfaces(): | |
i = list(Ftdi.PRODUCT_IDS[Ftdi.FTDI_VENDOR].values()).index( | |
device.idProduct | |
) | |
if i >= 0: | |
ftdi_url = "ftdi://ftdi:%s:%X:%X/%d" % ( | |
list(Ftdi.PRODUCT_IDS[Ftdi.FTDI_VENDOR].items())[i][0], | |
device.bus, | |
device.address, | |
interface.index + 1, | |
) | |
interfaces[ftdi_url] = interface | |
return interfaces | |
if __name__ == "__main__": | |
for _, iface in get_interfaces().items(): | |
d = Ftdi() | |
d.open_from_device(iface.device, iface.index + 1) | |
print(d) | |
d.close() | |
for _, iface in get_interfaces().items(): | |
d = Ftdi() | |
d.open_from_device(iface.device, iface.index + 1) | |
print(d) | |
d.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function libusb_set_usbdk not found
what is the function and where can i put it?