我知道关于这个问题有很多问题,但具体来说,我在 Ubuntu 上实现 libusb 库时遇到了麻烦。这是我的代码:
struct usb_bus *busses;
struct usb_bus *bus;
struct usb_device *digiSpark = NULL;
struct usb_device *device;
if(debug) printf("Detecting USB devices...\n");
// Initialize the USB library
usb_init();
// Enumerate the USB device tree
usb_find_busses();
usb_find_devices();
// Iterate through attached busses and devices
busses = usb_get_busses();
for (bus = busses; bus; bus = bus->next)
{
for (device = bus->devices; device; device = device->next)
{
// Check to see if each USB device matches the DigiSpark Vendor and Product IDs
if((device->descriptor.idVendor == 0x16c0) && (device->descriptor.idProduct == 0x05df))
{
if(debug) printf("Detected DigiSpark... \n");
digiSpark = device;
}
}
}
它几乎是从 libusb 示例中逐字记录的:
http://libusb.sourceforge.net/doc/examples-code.html
但它会产生大量“取消引用指向不完整类型的指针”错误。
具体来说,我在以下几行中得到了指向不完整类型错误的解引用指针:
busses = usb_get_busses();
for (bus = busses; bus; bus->next)
for (device = bus->devices; device; device->next)
在以下行中两次:
if((device->descriptor.idVendor == 0x16c0) && (device->descriptor.idProduct == 0x05df))
正如我所说,这很奇怪,因为我(在大多数情况下)没有编造这个,这是取自 lib 网站上已建立的示例。
任何建议都会很棒。谢谢!