HIDAPI 是一个 USB 和蓝牙的 hid 类设备在 Windows、Linux、FreeBSD 和 Mac 的 C 语言通用库,使用 HIDAPI 可以在 Windows、Linux、FreeBSD 和 Mac 平台进行 USB 和蓝牙的 hid 类设备通信,非常简单实用。

示例代码:

#include

#include

#include "hidapi.h"

int main(int argc, char* argv[])

{

int res;

unsigned char buf[65];

#define MAX_STR 255

wchar_t wstr[MAX_STR];

hid_device *handle;

int i;

// Enumerate and print the HID devices on the system

struct hid_device_info *devs, *cur_dev;

devs = hid_enumerate(0x0, 0x0);

cur_dev = devs;

while (cur_dev) {

printf("Device Found\n  type: %04hx %04hx\n  path: %s\n  serial_number: %ls",

cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);

printf("\n");

printf("  Manufacturer: %ls\n", cur_dev->manufacturer_string);

printf("  Product:      %ls\n", cur_dev->product_string);

printf("\n");

cur_dev = cur_dev->next;

}

hid_free_enumeration(devs);

// Open the device using the VID, PID,

// and optionally the Serial number.

handle = hid_open(0x4d8, 0x3f, NULL);

// Read the Manufacturer String

res = hid_get_manufacturer_string(handle, wstr, MAX_STR);

printf("Manufacturer String: %ls\n", wstr);

// Read the Product String

res = hid_get_product_string(handle, wstr, MAX_STR);

printf("Product String: %ls\n", wstr);

// Read the Serial Number String

res = hid_get_serial_number_string(handle, wstr, MAX_STR);

printf("Serial Number String: %ls", wstr);

printf("\n");

// Send a Feature Report to the device

buf[0] = 0x2; // First byte is report number

buf[1] = 0xa0;

buf[2] = 0x0a;

res = hid_send_feature_report(handle, buf, 17);

// Read a Feature Report from the device

buf[0] = 0x2;

res = hid_get_feature_report(handle, buf, sizeof(buf));

// Print out the returned buffer.

printf("Feature Report\n   ");

for (i = 0; i

printf("%02hhx ", buf[i]);

printf("\n");

// Set the hid_read() function to be non-blocking.

hid_set_nonblocking(handle, 1);

// Send an Output report to toggle the LED (cmd 0x80)

buf[0] = 1; // First byte is report number

buf[1] = 0x80;

res = hid_write(handle, buf, 65);

// Send an Output report to request the state (cmd 0x81)

buf[1] = 0x81;

hid_write(handle, buf, 65);

// Read requested state

res = hid_read(handle, buf, 65);

if (res

printf("Unable to read()\n");

// Print out the returned buffer.

for (i = 0; i

printf("buf[%d]: %d\n", i, buf[i]);

return 0;

}

HIDAPI 有四个后端:

Windows (using hid.dll)

Linux/hidraw (using the Kernel's hidraw driver)

Linux/libusb (using libusb-1.0)

FreeBSD (using libusb-1.0)

Mac (using IOHidManager)

c语言hid,HIDAPI首页、文档和下载 - HID 设备的 C 语言通用库相关推荐

  1. JavaCC首页、文档和下载 - 语法分析生成器 - 开源中国社区

    JavaCC首页.文档和下载 - 语法分析生成器 - 开源中国社区

  2. Chronos首页、文档和下载 - 作业调度器 - 开源中国社区

    Chronos首页.文档和下载 - 作业调度器 - 开源中国社区

  3. DotProject首页、文档和下载 - 项目管理工具 - 开源中国社区

    DotProject首页.文档和下载 - 项目管理工具 - 开源中国社区

  4. python-docx中文开发文档_使用Python语言-docx生成Word文档

    本文主要向大家介绍了使用Python语言-docx生成Word文档,通过具体的内容向大家展示,希望对大家学习Python语言有所帮助. < 学会来使用python操作数据表和PDF,今天我们尝试 ...

  5. 最新网页素材文档图库下载类网站源码+织梦CMS内核

    正文: 网页素材文档图库下载类网站源码+织梦CMS内核,本程序采用一库两站简洁方便管理后台,一个后台管理两网站,电脑版+手机版 程序特点: 1.网站手工DIV+css,代码精简,首页排版整洁大方.布局 ...

  6. 打包文档_苏教版小学数学16年级全十二册教案Word文档打包下载

    扫码查看下载 全部资源 部编小学语文1-6年级课程资料汇总苏教版小学数学1-6年级教学资料汇编苏教版小学数学1-6年级电子课本汇编苏教版小学数学1-6年级期末试题卷汇编▼ 1 年级 苏教版一年级数学上 ...

  7. 喜讯,Asp.net Ajax 文档提供下载

    今天去了一下 Asp.net Ajax 的官方网站,准备挑战自己的耐心去映着头皮跨过那所谓的修好的电缆去读 Asp.net Ajax 的文档.发现一个喜讯,不知道到什么时候,Asp.net Ajax ...

  8. 清理掉Win10“另存为“和“此电脑“里3D对象、视频、图片、文档、下载、音乐、桌面

    新建一个文本文档,复制下列代码 Windows Registry Editor Version 5.00 ;删除Win10[此电脑]{3D对象.视频.图片.文档.下载.音乐.桌面} ; 3D对象 [- ...

  9. 使用Java实现文档的下载(Excel,Word文档等)

    实现文档的下载 前端页面 1.在前端页面中访问后端控制层方法,传值(此处无需传参数) //下载Excel模板 监听table中的toolbar table中必须定义 lay-filter='downl ...

最新文章

  1. sklearn 主成分分析法 PCA和IPCA
  2. 电脑记时----千年虫
  3. monk js_对象检测-使用Monk AI进行文档布局分析
  4. c# 使用GDAL处理大图
  5. unity3d 求两个点长度_三年级上册求组合图形周长专项练习,附答案
  6. delphi mysql 图片_delphi数据库图片的存取 【转】
  7. 618活动海报还没想法?PSD页面设计参考能给你灵感
  8. mysql sql执行cmd命令行_命令行执行MySQL的sql文件
  9. 在python中单线程,多线程,多进程对CPU的利用率实测以及GIL原理分析
  10. extundelete实现Linux下文件/文件夹数据恢复!
  11. 4412 学习目录总结
  12. 计算机网络使用的通信线路分为两类,计算机网络技术阶段测试题
  13. 电阻电容电感PCB封装真实尺寸大小
  14. 新浪微博开放平台第三方登陆请求授权出现错误码:21322(重定向地址不匹配)的解决方法
  15. 20190328-几种数据清洗的方法
  16. 通过关键词采集百度网址脚本
  17. 10.13 写一个用矩形法求定积分的通用函数,分别求∫_0^1▒sinxdx 、∫_0^1▒cosxdx、∫_0^1▒〖e^x dx〗的值。
  18. Postman批量执行接口
  19. python大学生社团管理系统
  20. Calcite CBO 分析1

热门文章

  1. 常用二极管,三极管参数
  2. “因为无法从捐赠中抽成,谷歌把我的开源 App 下架了!”
  3. 路由器设置服务器用什么协议,路由器配置基础知识
  4. hgetall php,HGETALL命令_视频讲解_用法示例-redis编程词典-php中文网
  5. 金融衍生品PK:期权和权证俩兄弟
  6. 大数据学习路线图,大数据需要学什么
  7. position粘性定位sticky
  8. Centos 鼠标左键突然失灵问题与解决
  9. Java与数据库中的datetime Timestamp以及String之间的转换
  10. GeneXus for SAP的最新动态