hidapi在linux下编译,HIDAPI
软件简介
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)
hidapi在linux下编译,HIDAPI相关推荐
- linux 保存编译log,(转)Linux下编译安装log4cxx
一个项目的服务器端在Linux平台下,用到了开源日志库log4cxx,这个库是apache项目的一个子库.功能很不错.下面记录下它的编译和安装过程. 第一步安装apr-1.3.8,顺序不能错,它必须首 ...
- linux下编译make文件报错“/bin/bash^M: 坏的解释器,使用grep快速定位代码位置
一.linux下编译make文件报错"/bin/bash^M: 坏的解释器 参考文章:http://blog.csdn.net/liuqiyao_01/article/details/415 ...
- 一份简单的在 Linux下编译及调试 C 代码的指南
摘要: 一份简单的在 Linux下编译及调试 C 代码的指南 对于Linux下的C程序员来说,几乎天天都会和Linux打交道.但在很多人的眼中,Linux是一个易用性极差.靠命令驱动的操作系统,根本无 ...
- linux下软件编译终止,[2018年最新整理]linux下编译运行程序命令大全.ppt
[2018年最新整理]linux下编译运行程序命令大全 1. 项目课题引入 2. Vi编辑器的使用方法 3. Linux中C语言程序的编辑 4. Linux中C语言程序的运行 5. 现场演示案例 课题 ...
- linux emule 编译 wx-config --libs,linux下编译wxwidgets所写程序所遇到的问题
记录linux下编译wxwidgets所遇到的问题 1./home/hrd/baohualib/wxWidgets-3.0.2/include/wx/platform.h:184:22: 致命错误: ...
- linux下编译wpa_supplicantnbsp;…
linux下编译wpa_supplicant 收藏 前一段时间只在vs2005下编译成功过.经过近一段时间的琢磨,今天终于在linux下成功编译了wpa_supplicant. 挺简单的事情折腾了这么 ...
- java libpcap,Linux下编译安装libpcap
要做Sniffer了,先在Linux下编译一下libpcap 1.编译安装flex #libpcap 1.1要求flex必须在2.4.6及以上 wget http://prdownloads.sour ...
- linux redis php,Linux下编译redis和phpredis的方法
这篇文章主要介绍了Linux下编译redis和phpredis的方法,分析了redis的下载,编译,安装及遇到的问题与相应的解决方法,需要的朋友可以参考下 本文讲述了Linux下编译redis和php ...
- linux下编译libuv,linux下libuv库安装教程
下载并编译libuv libuv需要自己手动下载源码,并手动编译. 当前目录为:/home/xlz/test/github/,在后面,会用$PATH来代替,我的系统的Debian8,64bit. $g ...
最新文章
- CSS.text不被选中
- linux(CentOS)磁盘挂载数据盘
- node.js实现formdata上传文件
- 微型计算机接口位于什么之间,io接口位于什么和什么之间
- dto与dto相互转换_在DTO上
- [WebApp开发]基础教程-Web App开发入门
- CentOs7 安装Hadoop-3.1.0集群环境
- 车牌识别系统论文python_车牌识别系统的设计与实现毕业论文
- 21世纪如何正确思考及开创个人事业(转发)
- html轮播图片不显示不了,图片轮播的奇怪现象【图片显示不完整】
- 【FPGA】如何理解全加器
- 全网通工业无线路由器多网口工业路由器
- 路由器IP地址的配置
- EF Core codefirst数据迁移操作
- 重做日志文件(redo log file)
- Python基础 六道简单练习
- 廖雪峰git入门教程——学习笔记
- 计算机联锁知识,6502电路动作顺序(计算机联锁基础知识)
- 中国医科大学护理学专业远程教育招生
- PhysX 物理引擎研究(一)源码编译