当前位置: 首页 > news >正文

QT调用最新的libusb库

一:下载libusb文件

下载最新的库的下载网站:https://libusb.info/

下载:

解压后目录如下:

二:库文件添加QT中

根据自己的编译器选择库:

①将头文件中添加libusb.h

②源文件中添加libusb-1.0.lib

③添加库文件:

三:编译工程

添加库后直接编译,不报错即为成功:

四:example

参考例程中的调用方法:

/*
* Test suite program based of libusb-0.1-compat testlibusb
* Copyright (c) 2013 Nathan Hjelm <hjelmn@mac.ccom>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/#include <stdio.h>
#include <string.h>
#include "libusb.h"int verbose = 0;static void print_endpoint_comp(const struct libusb_ss_endpoint_companion_descriptor *ep_comp)
{printf("      USB 3.0 Endpoint Companion:\n");printf("        bMaxBurst:           %u\n", ep_comp->bMaxBurst);printf("        bmAttributes:        %02xh\n", ep_comp->bmAttributes);printf("        wBytesPerInterval:   %u\n", ep_comp->wBytesPerInterval);
}static void print_endpoint(const struct libusb_endpoint_descriptor *endpoint)
{int i, ret;printf("      Endpoint:\n");printf("        bEndpointAddress:    %02xh\n", endpoint->bEndpointAddress);printf("        bmAttributes:        %02xh\n", endpoint->bmAttributes);printf("        wMaxPacketSize:      %u\n", endpoint->wMaxPacketSize);printf("        bInterval:           %u\n", endpoint->bInterval);printf("        bRefresh:            %u\n", endpoint->bRefresh);printf("        bSynchAddress:       %u\n", endpoint->bSynchAddress);for (i = 0; i < endpoint->extra_length;) {if (LIBUSB_DT_SS_ENDPOINT_COMPANION == endpoint->extra[i + 1]) {struct libusb_ss_endpoint_companion_descriptor *ep_comp;ret = libusb_get_ss_endpoint_companion_descriptor(NULL, endpoint, &ep_comp);if (LIBUSB_SUCCESS != ret)continue;print_endpoint_comp(ep_comp);libusb_free_ss_endpoint_companion_descriptor(ep_comp);}i += endpoint->extra[i];}
}static void print_altsetting(const struct libusb_interface_descriptor *interface)
{uint8_t i;printf("    Interface:\n");printf("      bInterfaceNumber:      %u\n", interface->bInterfaceNumber);printf("      bAlternateSetting:     %u\n", interface->bAlternateSetting);printf("      bNumEndpoints:         %u\n", interface->bNumEndpoints);printf("      bInterfaceClass:       %u\n", interface->bInterfaceClass);printf("      bInterfaceSubClass:    %u\n", interface->bInterfaceSubClass);printf("      bInterfaceProtocol:    %u\n", interface->bInterfaceProtocol);printf("      iInterface:            %u\n", interface->iInterface);for (i = 0; i < interface->bNumEndpoints; i++)print_endpoint(&interface->endpoint[i]);
}static void print_2_0_ext_cap(struct libusb_usb_2_0_extension_descriptor *usb_2_0_ext_cap)
{printf("    USB 2.0 Extension Capabilities:\n");printf("      bDevCapabilityType:    %u\n", usb_2_0_ext_cap->bDevCapabilityType);printf("      bmAttributes:          %08xh\n", usb_2_0_ext_cap->bmAttributes);
}static void print_ss_usb_cap(struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap)
{printf("    USB 3.0 Capabilities:\n");printf("      bDevCapabilityType:    %u\n", ss_usb_cap->bDevCapabilityType);printf("      bmAttributes:          %02xh\n", ss_usb_cap->bmAttributes);printf("      wSpeedSupported:       %u\n", ss_usb_cap->wSpeedSupported);printf("      bFunctionalitySupport: %u\n", ss_usb_cap->bFunctionalitySupport);printf("      bU1devExitLat:         %u\n", ss_usb_cap->bU1DevExitLat);printf("      bU2devExitLat:         %u\n", ss_usb_cap->bU2DevExitLat);
}static void print_bos(libusb_device_handle *handle)
{struct libusb_bos_descriptor *bos;uint8_t i;int ret;ret = libusb_get_bos_descriptor(handle, &bos);if (ret < 0)return;printf("  Binary Object Store (BOS):\n");printf("    wTotalLength:            %u\n", bos->wTotalLength);printf("    bNumDeviceCaps:          %u\n", bos->bNumDeviceCaps);for (i = 0; i < bos->bNumDeviceCaps; i++) {struct libusb_bos_dev_capability_descriptor *dev_cap = bos->dev_capability[i];if (dev_cap->bDevCapabilityType == LIBUSB_BT_USB_2_0_EXTENSION) {struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension;ret = libusb_get_usb_2_0_extension_descriptor(NULL, dev_cap, &usb_2_0_extension);if (ret < 0)return;print_2_0_ext_cap(usb_2_0_extension);libusb_free_usb_2_0_extension_descriptor(usb_2_0_extension);} else if (dev_cap->bDevCapabilityType == LIBUSB_BT_SS_USB_DEVICE_CAPABILITY) {struct libusb_ss_usb_device_capability_descriptor *ss_dev_cap;ret = libusb_get_ss_usb_device_capability_descriptor(NULL, dev_cap, &ss_dev_cap);if (ret < 0)return;print_ss_usb_cap(ss_dev_cap);libusb_free_ss_usb_device_capability_descriptor(ss_dev_cap);}}libusb_free_bos_descriptor(bos);
}static void print_interface(const struct libusb_interface *interface)
{int i;for (i = 0; i < interface->num_altsetting; i++)print_altsetting(&interface->altsetting[i]);
}static void print_configuration(struct libusb_config_descriptor *config)
{uint8_t i;printf("  Configuration:\n");printf("    wTotalLength:            %u\n", config->wTotalLength);printf("    bNumInterfaces:          %u\n", config->bNumInterfaces);printf("    bConfigurationValue:     %u\n", config->bConfigurationValue);printf("    iConfiguration:          %u\n", config->iConfiguration);printf("    bmAttributes:            %02xh\n", config->bmAttributes);printf("    MaxPower:                %u\n", config->MaxPower);for (i = 0; i < config->bNumInterfaces; i++)print_interface(&config->interface[i]);
}static void print_device(libusb_device *dev, libusb_device_handle *handle)
{struct libusb_device_descriptor desc;unsigned char string[256];const char *speed;int ret;uint8_t i;switch (libusb_get_device_speed(dev)) {case LIBUSB_SPEED_LOW:		speed = "1.5M"; break;case LIBUSB_SPEED_FULL:		speed = "12M"; break;case LIBUSB_SPEED_HIGH:		speed = "480M"; break;case LIBUSB_SPEED_SUPER:	speed = "5G"; break;case LIBUSB_SPEED_SUPER_PLUS:	speed = "10G"; break;default:			speed = "Unknown";}ret = libusb_get_device_descriptor(dev, &desc);if (ret < 0) {fprintf(stderr, "failed to get device descriptor");return;}printf("Dev (bus %u, device %u): %04X - %04X speed: %s\n",libusb_get_bus_number(dev), libusb_get_device_address(dev),desc.idVendor, desc.idProduct, speed);if (!handle)libusb_open(dev, &handle);if (handle) {if (desc.iManufacturer) {ret = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string));if (ret > 0)printf("  Manufacturer:              %s\n", (char *)string);}if (desc.iProduct) {ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string));if (ret > 0)printf("  Product:                   %s\n", (char *)string);}if (desc.iSerialNumber && verbose) {ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string));if (ret > 0)printf("  Serial Number:             %s\n", (char *)string);}}if (verbose) {for (i = 0; i < desc.bNumConfigurations; i++) {struct libusb_config_descriptor *config;ret = libusb_get_config_descriptor(dev, i, &config);if (LIBUSB_SUCCESS != ret) {printf("  Couldn't retrieve descriptors\n");continue;}print_configuration(config);libusb_free_config_descriptor(config);}if (handle && desc.bcdUSB >= 0x0201)print_bos(handle);}if (handle)libusb_close(handle);
}#ifdef __linux__
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>static int test_wrapped_device(const char *device_name)
{libusb_device_handle *handle;int r, fd;fd = open(device_name, O_RDWR);if (fd < 0) {printf("Error could not open %s: %s\n", device_name, strerror(errno));return 1;}r = libusb_wrap_sys_device(NULL, fd, &handle);if (r) {printf("Error wrapping device: %s: %s\n", device_name, libusb_strerror(r));close(fd);return 1;}print_device(libusb_get_device(handle), handle);close(fd);return 0;
}
#else
static int test_wrapped_device(const char *device_name)
{(void)device_name;printf("Testing wrapped devices is not supported on your platform\n");return 1;
}
#endifint main(int argc, char *argv[])
{const char *device_name = NULL;libusb_device **devs;ssize_t cnt;int r, i;for (i = 1; i < argc; i++) {if (!strcmp(argv[i], "-v")) {verbose = 1;} else if (!strcmp(argv[i], "-d") && (i + 1) < argc) {i++;device_name = argv[i];} else {printf("Usage %s [-v] [-d </dev/bus/usb/...>]\n", argv[0]);printf("Note use -d to test libusb_wrap_sys_device()\n");return 1;}}r = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0);if (r < 0)return r;if (device_name) {r = test_wrapped_device(device_name);} else {cnt = libusb_get_device_list(NULL, &devs);if (cnt < 0) {libusb_exit(NULL);return 1;}for (i = 0; devs[i]; i++)print_device(devs[i], NULL);libusb_free_device_list(devs, 1);}libusb_exit(NULL);return r;
}

相关文章:

QT调用最新的libusb库

一&#xff1a;下载libusb文件 下载最新的库的下载网站&#xff1a;https://libusb.info/ 下载&#xff1a; 解压后目录如下&#xff1a; 二&#xff1a;库文件添加QT中 根据自己的编译器选择库&#xff1a; ①将头文件中添加libusb.h ②源文件中添加libusb-1.0.lib ③添加…...

白嫖EarMaster Pro 7简体中文破解版下载永久激活

EarMaster Pro 7 简体中文破解版功能介绍 俗话说得好&#xff0c;想要成为音乐家&#xff0c;就必须先拥有音乐家的耳朵&#xff0c;相信很多小伙伴都已经具备了一定的音乐素养&#xff0c;或者是说想要进一步得到提升。那我们就必须练好听耳的能力&#xff0c;并且把这种能力…...

使用JavaScript写一个网页端的四则运算器

目录 style(内联样式表部分) body部分 html script 总的代码 网页演示 style(内联样式表部分) <style>body {font-family: Arial, sans-serif;display: flex;justify-content: center;align-items: center;height: 100vh;background-color: #f0f0f0;}.calculator {…...

Linux find命令详解及实用示例

Linux 系统中的 find 命令是一个功能强大的工具&#xff0c;用于在文件系统中搜索文件并执行相应的操作。无论是系统管理员还是普通用户&#xff0c;掌握 find 命令都能极大地提高工作效率。本文将详细介绍 find 命令的用法&#xff0c;并通过多个示例展示其在实际中的应用。 …...

CSS基础-常见属性(二)

6、CSS三大特性 6.1 层叠性 如果样式发生冲突&#xff0c;则按照优先级进行覆盖。 6.2 继承性 元素自动继承其父元素、祖先元素所设置的某些元素&#xff0c;优先继承较近的元素。 6.3 优先级 6.3.1 简单分级 1、内联样式2、ID选择器3、类选择器/属性选择器4、标签名选择器/…...

Spring Boot 2.4.3 + Java 8 升级为 Java 21 + Spring Boot 3.2.0

简简单单 Online zuozuo: 简简单单 Online zuozuo 简简单单 Online zuozuo 简简单单 Online zuozuo 简简单单 Online zuozuo :本心、输入输出、结果 简简单单 Online zuozuo : 文章目录 Spring Boot 2.4.3 + Java 8 升级为 Java 21 + Spring Boot 3.2.0前言更换 Java 21 SD…...

如何利用免费音频剪辑软件制作出精彩音频

现在有许多免费的音频剪辑软件可供选择&#xff0c;它们为广大用户提供了丰富的功能和便捷的操作体验&#xff0c;让音频编辑变得更加轻松和有趣。接下来&#xff0c;让我们一起走进这些免费音频剪辑软件的世界&#xff0c;探索它们的独特魅力和强大功能。 1.福昕音频剪辑 链…...

安宝特分享 | AR技术重塑工业:数字孪生与沉浸式培训的创新应用

在数字化转型的浪潮中&#xff0c;AR&#xff08;增强现实&#xff09;技术与工业的结合正在呈现新的趋势和应用延伸。特别是“数字孪生”概念的崛起&#xff0c;为AR技术在工业中提供了独特而创新的切入点。 本文将探索AR如何与数字孪生、沉浸式体验和实用案例相结合&#xf…...

专题十_穷举vs暴搜vs深搜vs回溯vs剪枝_二叉树的深度优先搜索_算法专题详细总结

目录 搜索 vs 深度优先遍历 vs 深度优先搜索 vs 宽度优先遍历 vs 宽度优先搜索 vs 暴搜 1.深度优先遍历 vs 深度优先搜索(dfs) 2.宽度优先遍历 vs 宽度优先搜索(bfs) 2.关系图暴力枚举一遍所有的情况 3.拓展搜索问题全排列 决策树 1. 计算布尔⼆叉树的值&#xff08;medi…...

基于springboot vue3 在线考试系统设计与实现 源码数据库 文档

博主介绍&#xff1a;专注于Java&#xff08;springboot ssm springcloud等开发框架&#xff09; vue .net php phython node.js uniapp小程序 等诸多技术领域和毕业项目实战、企业信息化系统建设&#xff0c;从业十五余年开发设计教学工作☆☆☆ 精彩专栏推荐订阅☆☆☆☆…...

什么是 HTTP 请求中的 options 请求?

在 Chrome 开发者工具中的 Network 面板看到的 HTTP 方法 OPTIONS&#xff0c;其实是 HTTP 协议的一部分&#xff0c;用于客户端和服务器之间进行“预检”或“协商”。OPTIONS 请求的作用是让客户端能够获取关于服务器支持的 HTTP 方法和其他跨域资源共享 (CORS) 相关的信息&am…...

[图形学]smallpt代码详解(1)

一、简介 本文介绍了著名的99行代码实现全局光照的光线跟踪代码smallpt。 包括对smallpt的功能介绍、编译运行介绍&#xff0c;和对代码的详细解释。希望能够帮助读者更进一步的理解光线跟踪。 二、smallpt介绍 1.smallpt是什么 smallpt(small Path Tracing) 是一个全局光照…...

Vite多环境配置与打包:

环境变量必须以VITE开头 1.VITE_BASE_API&#xff1a; 在开发环境中设置为 /dev-api&#xff0c;这是一个本地 mock 地址&#xff0c;通常用于模拟后端接口。 2.VITE_ENABLE_ERUDA&#xff1a; 设置为 "true"&#xff0c;表示启用调试工具&#xff0c;通常是为了…...

git维护【.gitignore文件】

在工程下添加 .gitignore 文件【git忽略文件】 *.class .idea *.iml *.jar /*/target/...

【Canvas与色彩】十六等分多彩隔断圆环

【成图】 【代码】 <!DOCTYPE html> <html lang"utf-8"> <meta http-equiv"Content-Type" content"text/html; charsetutf-8"/> <head><title>隔断圆环Draft5十六等分多彩</title><style type"text…...

什么是pip? -- Python 包管理工具

前言 不同的编程语言通常都有自己的包管理工具&#xff0c;这些工具旨在简化项目的依赖管理、构建过程和开发效率&#xff0c;同时促进代码的复用和共享。每个包管理工具都有其独特的特点和优势&#xff0c;开发者可以根据自己的编程语言和项目需求选择合适的包管理工具。 pip是…...

FastAPI框架使用枚举来型来限定参数、FastApi框架隐藏没多大意义的Schemes模型部分内容以及常见的WSGI服务器Gunicorn、uWSGI了解

一、FastAPI框架使用枚举来型来限定参数 FastAPI框架验证时&#xff0c;有时需要通过枚举的方式来限定参数只能为某几个值中的一个&#xff0c;这时就可以使用FastAPI框架的枚举类型Enum了。publish:December 23, 2020 -Wednesday 代码如下&#xff1a; #引入Enum模块 from fa…...

OceanBase—02(入门篇——对于单副本单节点,由1个observer扩容为3个observer集群)——之前的记录,当初有的问题未解决,目前新版未尝试

OceanBase—02&#xff08;入门篇——对于单副本单节点&#xff0c;由1个observer扩容为3个observer集群&#xff09;——之前的记录&#xff0c;有的问题未解决&#xff0c;新版未尝试 1、前言—安装单副本单节点集群1.1 docker安装OB 2、查看现有集群情况2.1 进入容器&#x…...

前沿论文创新点集合

系列文章目录 文章目录 系列文章目录一、《LAMM: Label Alignment for Multi-Modal Prompt Learning》二、《MaPLe: Multi-modal Prompt Learning》三、《Learning to Prompt for Vision-Language Models》CoOp四、《MobileCLIP: Fast Image-Text Models through Multi-Modal R…...

刷题记录(好题)

Problem - D - Codeforces 思路&#xff1a; 滑动窗口思想&#xff0c;一个数组记录起始点&#xff08;记录出现过的次数&#xff09;&#xff0c;另一个数组记录截至点&#xff08;记录出现过的次数&#xff09;&#xff0c;从0开始遍历&#xff0c;设定一个长度为d的滑动窗口…...

Xshell远程连接Kali(默认 | 私钥)Note版

前言:xshell远程连接&#xff0c;私钥连接和常规默认连接 任务一 开启ssh服务 service ssh status //查看ssh服务状态 service ssh start //开启ssh服务 update-rc.d ssh enable //开启自启动ssh服务 任务二 修改配置文件 vi /etc/ssh/ssh_config //第一…...

系统设计 --- MongoDB亿级数据查询优化策略

系统设计 --- MongoDB亿级数据查询分表策略 背景Solution --- 分表 背景 使用audit log实现Audi Trail功能 Audit Trail范围: 六个月数据量: 每秒5-7条audi log&#xff0c;共计7千万 – 1亿条数据需要实现全文检索按照时间倒序因为license问题&#xff0c;不能使用ELK只能使用…...

转转集团旗下首家二手多品类循环仓店“超级转转”开业

6月9日&#xff0c;国内领先的循环经济企业转转集团旗下首家二手多品类循环仓店“超级转转”正式开业。 转转集团创始人兼CEO黄炜、转转循环时尚发起人朱珠、转转集团COO兼红布林CEO胡伟琨、王府井集团副总裁祝捷等出席了开业剪彩仪式。 据「TMT星球」了解&#xff0c;“超级…...

Rapidio门铃消息FIFO溢出机制

关于RapidIO门铃消息FIFO的溢出机制及其与中断抖动的关系&#xff0c;以下是深入解析&#xff1a; 门铃FIFO溢出的本质 在RapidIO系统中&#xff0c;门铃消息FIFO是硬件控制器内部的缓冲区&#xff0c;用于临时存储接收到的门铃消息&#xff08;Doorbell Message&#xff09;。…...

蓝桥杯3498 01串的熵

问题描述 对于一个长度为 23333333的 01 串, 如果其信息熵为 11625907.5798&#xff0c; 且 0 出现次数比 1 少, 那么这个 01 串中 0 出现了多少次? #include<iostream> #include<cmath> using namespace std;int n 23333333;int main() {//枚举 0 出现的次数//因…...

Java多线程实现之Thread类深度解析

Java多线程实现之Thread类深度解析 一、多线程基础概念1.1 什么是线程1.2 多线程的优势1.3 Java多线程模型 二、Thread类的基本结构与构造函数2.1 Thread类的继承关系2.2 构造函数 三、创建和启动线程3.1 继承Thread类创建线程3.2 实现Runnable接口创建线程 四、Thread类的核心…...

让回归模型不再被异常值“带跑偏“,MSE和Cauchy损失函数在噪声数据环境下的实战对比

在机器学习的回归分析中&#xff0c;损失函数的选择对模型性能具有决定性影响。均方误差&#xff08;MSE&#xff09;作为经典的损失函数&#xff0c;在处理干净数据时表现优异&#xff0c;但在面对包含异常值的噪声数据时&#xff0c;其对大误差的二次惩罚机制往往导致模型参数…...

网站指纹识别

网站指纹识别 网站的最基本组成&#xff1a;服务器&#xff08;操作系统&#xff09;、中间件&#xff08;web容器&#xff09;、脚本语言、数据厍 为什么要了解这些&#xff1f;举个例子&#xff1a;发现了一个文件读取漏洞&#xff0c;我们需要读/etc/passwd&#xff0c;如…...

C#中的CLR属性、依赖属性与附加属性

CLR属性的主要特征 封装性&#xff1a; 隐藏字段的实现细节 提供对字段的受控访问 访问控制&#xff1a; 可单独设置get/set访问器的可见性 可创建只读或只写属性 计算属性&#xff1a; 可以在getter中执行计算逻辑 不需要直接对应一个字段 验证逻辑&#xff1a; 可以…...

从实验室到产业:IndexTTS 在六大核心场景的落地实践

一、内容创作&#xff1a;重构数字内容生产范式 在短视频创作领域&#xff0c;IndexTTS 的语音克隆技术彻底改变了配音流程。B 站 UP 主通过 5 秒参考音频即可克隆出郭老师音色&#xff0c;生成的 “各位吴彦祖们大家好” 语音相似度达 97%&#xff0c;单条视频播放量突破百万…...