当前位置: 首页 > 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的滑动窗口…...

【大数据入门 | Hive】函数{单行函数,集合函数,炸裂函数,窗口函数}

1. 函数简介&#xff1a; Hive会将常用的逻辑封装成函数给用户进行使用&#xff0c;类似于Java中的函数。 好处&#xff1a;避免用户反复写逻辑&#xff0c;可以直接拿来使用。 重点&#xff1a;用户需要知道函数叫什么&#xff0c;能做什么。 Hive提供了大量的内置函数&am…...

python sqlite3 工具函数

起因&#xff0c; 目的: sqlite3 最常用的函数。 比如&#xff0c;某人给了一个 database.db 文件。 但是你登录的时候&#xff0c;不知道账号密码。 此文件就是&#xff0c;查看这个数据库的详细内容。 有哪些表某个表的全部内容。添加数据 代码&#xff0c; 见注释 impor…...

顺丰Android面试题集锦及参考答案

TCP 三次握手和四次挥手是什么,挥手过程中主动方的状态是什么? TCP 三次握手是建立连接的过程: 第一次握手:客户端向服务器发送一个 SYN 报文,该报文包含客户端的初始序列号(seq=x)。此时客户端进入 SYN_SENT 状态。第二次握手:服务器收到客户端的 SYN 报文后,向客户端…...

uniapp中检测应用更新的两种方式-升级中心之uni-upgrade-center-app

uniapp一个很是用的功能&#xff0c;就是在我们发布新版本的app后&#xff0c;需要提示用户进行app更新&#xff0c;并告知用户我们新版的app更新信息&#xff0c;以使得用户能及时使用上我们新开发的功能&#xff0c;提升用户的实用度和粘性。注意:这个功能只能在app端使用 效…...

Python爬虫通过 Cookie 和会话管理来维持其在网站上的会话状态

Python 爬虫虽然是一个热门且非常实用的技术领域&#xff0c;但在实际开发中&#xff0c;确实存在一些困难的地方。以下是 Python 爬虫开发中常见的难点和挑战&#xff1a; 1. 处理反爬虫机制 许多网站为防止爬虫的恶意访问&#xff0c;采取了各种反爬虫措施。常见的反爬虫技…...

使用STM32单片机实现无人机控制系统

无人机控制系统是无人机的大脑&#xff0c;负责处理无人机的姿态控制、导航和通信等功能。本文将详细介绍如何使用STM32单片机实现无人机控制系统&#xff0c;包括硬件设计、软件设计、系统调试与测试等内容。 一、系统概述 无人机控制系统通常包括飞行控制器、传感器、执行器…...

【包教包会】2D图片实现3D透视效果(支持3.x、支持原生、可合批)

将去年写的SpriteFlipper从2.x升级到3.x。 如果需要2.x版本或需要了解算法思路&#xff0c;请移步&#xff1a;https://blog.csdn.net/weixin_42714632/article/details/136745051 优化功能&#xff1a;可同时绕X轴和Y轴旋转&#xff0c;两者效果会叠加。 完美适配Web、原生…...

解决nginx+tomcat宕机完美解决方案

问题描述&#xff1a;公司项目太老了&#xff0c;还是tomcat项目&#xff0c;部署两台tomcat,做了nginx负载。最近发现每到上午10&#xff0c;下午3点&#xff0c;tomcat就宕机了&#xff0c;死活找不到原因&#xff0c;客户影响超期差&#xff0c;实在让人头疼。 解决思路&am…...

第十一章 缓存之更新/穿透/雪崩/击穿

目录 一、什么是缓存 二、缓存更新策略 2.1. 缓存主动更新策略 2.1.1. Cache Aside模式&#xff08;主流&#xff09;‌ 2.1.2. Read/Write Through模式‌ 2.1‌.3. Write Behind模式‌ 2.1.4. 总结 三、缓存穿透 四、缓存雪崩 五、缓存击穿 5.1. 互斥锁实现 5.1.1…...

一款完全开源并免费的监测与分析系统,支持监测,预警,分析,报告,支持本地化部署(附源码)

前言 在当今这个信息爆炸的时代&#xff0c;企业和个人都需要时刻了解网络上的动态&#xff0c;以便及时了解自身品牌形象和社会舆论的变化。然而&#xff0c;现有的舆情监测工具往往价格昂贵&#xff0c;且cao作复杂&#xff0c;难以满足普通用户的需求。 在这种背景下&…...