void USBDevice::ScanUsbDevices()
{
libusb_context *ctx = nullptr;
libusb_device **device_list = nullptr;
ssize_t count;
if (libusb_init(&ctx) != 0) {
qWarning() << "Error initializing libusb";
}
// Get the device list
count = libusb_get_device_list(ctx, &device_list);
if (count < 0) {
usbList->addItem("Error: Unable to get the device list.");
libusb_exit(ctx);
return;
}
qDebug() << "USB devices found:" << count;
// usbList->addItem(QString("USB devices found: %1").arg(count));
// Iterate over the found devices
for (ssize_t i = 0; i < count; i++) {
libusb_device *device = device_list[i];
libusb_device_descriptor desc;
if (libusb_get_device_descriptor(device, &desc) == 0) {
.
arg(desc.
idVendor,
4,
16,
QChar('0')) .
arg(desc.
idProduct,
4,
16,
QChar('0'));
// Try to open the device to read extra information
libusb_device_handle *handle;
if (libusb_open(device, &handle) == 0) {
unsigned char buffer[256];
if (desc.iManufacturer && libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, buffer, sizeof(buffer)) > 0) {
info
+= " | Manufacturer: " + QString::fromUtf8(reinterpret_cast<char
*>
(buffer
));
}
if (desc.iProduct && libusb_get_string_descriptor_ascii(handle, desc.iProduct, buffer, sizeof(buffer)) > 0) {
info
+= " | Product: " + QString::fromUtf8(reinterpret_cast<char
*>
(buffer
));
}
libusb_close(handle);
}
// usbList->addItem(info);
qDebug() << info;
}
}
// Free the device list
libusb_free_device_list(device_list, 1);
libusb_exit(ctx);
}
void USBDevice::ScanUsbDevices()
{
libusb_context *ctx = nullptr;
libusb_device **device_list = nullptr;
ssize_t count;
if (libusb_init(&ctx) != 0) {
qWarning() << "Error initializing libusb";
}
// Get the device list
count = libusb_get_device_list(ctx, &device_list);
if (count < 0) {
usbList->addItem("Error: Unable to get the device list.");
libusb_exit(ctx);
return;
}
qDebug() << "USB devices found:" << count;
// usbList->addItem(QString("USB devices found: %1").arg(count));
// Iterate over the found devices
for (ssize_t i = 0; i < count; i++) {
libusb_device *device = device_list[i];
libusb_device_descriptor desc;
if (libusb_get_device_descriptor(device, &desc) == 0) {
QString info = QString("VID: 0x%1 PID: 0x%2")
.arg(desc.idVendor, 4, 16, QChar('0'))
.arg(desc.idProduct, 4, 16, QChar('0'));
// Try to open the device to read extra information
libusb_device_handle *handle;
if (libusb_open(device, &handle) == 0) {
unsigned char buffer[256];
if (desc.iManufacturer && libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, buffer, sizeof(buffer)) > 0) {
info += " | Manufacturer: " + QString::fromUtf8(reinterpret_cast<char*>(buffer));
}
if (desc.iProduct && libusb_get_string_descriptor_ascii(handle, desc.iProduct, buffer, sizeof(buffer)) > 0) {
info += " | Product: " + QString::fromUtf8(reinterpret_cast<char*>(buffer));
}
libusb_close(handle);
}
// usbList->addItem(info);
qDebug() << info;
}
}
// Free the device list
libusb_free_device_list(device_list, 1);
libusb_exit(ctx);
}
To copy to clipboard, switch view to plain text mode
AllK required contiguous memory = 675016 (64bit)
8 HotK Handles: HandleSize 2112 PoolSize 16912 (bytes)
64 LstK Handles: HandleSize 64 PoolSize 4112 (bytes)
2048 LstInfoK Handles: HandleSize 64 PoolSize 131088 (bytes)
128 UsbK Handles: HandleSize 96 PoolSize 12304 (bytes)
64 DevK Handles: HandleSize 112 PoolSize 7184 (bytes)
2048 OvlK Handles: HandleSize 104 PoolSize 213008 (bytes)
64 OvlPoolK Handles: HandleSize 96 PoolSize 6160 (bytes)
32 StmK Handles: HandleSize 176 PoolSize 5648 (bytes)
2048 IsochK Handles: HandleSize 136 PoolSize 278544 (bytes)
Dynamically allocated as needed:
KLST_DEVINFO = 2596 bytes each
USB devices found: 6
"VID: 0x8086 PID: 0xa36d"
"VID: 0x8087 PID: 0x0aaa"
"VID: 0x10de PID: 0x1ada"
"VID: 0x0b05 PID: 0x1866 | Manufacturer: ASUSTeK Computer Inc. | Product: N-KEY Device"
"VID: 0x046d PID: 0xc01e | Manufacturer: Logitech | Product: USB-PS/2 Optical Mouse"
"VID: 0x1366 PID: 0x1050"
AllK required contiguous memory = 675016 (64bit)
8 HotK Handles: HandleSize 2112 PoolSize 16912 (bytes)
64 LstK Handles: HandleSize 64 PoolSize 4112 (bytes)
2048 LstInfoK Handles: HandleSize 64 PoolSize 131088 (bytes)
128 UsbK Handles: HandleSize 96 PoolSize 12304 (bytes)
64 DevK Handles: HandleSize 112 PoolSize 7184 (bytes)
2048 OvlK Handles: HandleSize 104 PoolSize 213008 (bytes)
64 OvlPoolK Handles: HandleSize 96 PoolSize 6160 (bytes)
32 StmK Handles: HandleSize 176 PoolSize 5648 (bytes)
2048 IsochK Handles: HandleSize 136 PoolSize 278544 (bytes)
Dynamically allocated as needed:
KLST_DEVINFO = 2596 bytes each
USB devices found: 6
"VID: 0x8086 PID: 0xa36d"
"VID: 0x8087 PID: 0x0aaa"
"VID: 0x10de PID: 0x1ada"
"VID: 0x0b05 PID: 0x1866 | Manufacturer: ASUSTeK Computer Inc. | Product: N-KEY Device"
"VID: 0x046d PID: 0xc01e | Manufacturer: Logitech | Product: USB-PS/2 Optical Mouse"
"VID: 0x1366 PID: 0x1050"
To copy to clipboard, switch view to plain text mode
Bookmarks