2019独角兽企业重金招聘Python工程师标准>>>

HID API for Linux, Mac OS X, and Windows

About

来自: http://www.signal11.us/oss/hidapi/

HIDAPI is a multi-platform library which allows an application to interface with USB and Bluetooth HID-Class devices on Windows, Linux, and Mac OS X. While it can be used to communicate with standard HID devices like keyboards, mice, and Joysticks, it is most useful when used with custom (Vendor-Defined) HID devices. Many devices do this in order to not require a custom driver to be written for each platform. HIDAPI is easy to integrate with the client application, just requiring a single source file to be dropped into the application. On Windows, HIDAPI can optionally be built into a DLL.

Programs which use HIDAPI are driverless, meaning they do not require the use of a custom driver for each device on each platform.

HIDAPI provides a clean and consistent interface for each platform, making it easier to develop applications which communicate with USB HID devices without having to know the details of the HID libraries and interfaces on each platform.

The HIDAPI source also provides a GUI test application which can enumerate and communicate with any HID device attached to the system. The test GUI compiles and runs on all platforms supported by HIDAPI.

What Does the API Look Like?

Doxygen HTML documentation can be found here.

The API provides an easy method to enumerate HID devices attached to the system, and easy access to the functionality of the most commonly used HID functions including transfer of Input, Output, and Feature Reports. The sample program, which communicates with a modified version of the USB Generic HID sample which is part of the Microchip Application Library (in folder "Microchip Solutions\USB Device - HID - Custom Demos\Generic HID - Firmware" when the Microchip Application Framework is installed), looks like this (with error checking removed for simplicity):

#include <stdio.h> #include <stdlib.h> #include "hidapi.h" int main(int argc, char* argv[])
{int res;unsigned char buf[65];#define MAX_STR 255wchar_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 < res; 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 < 0)printf("Unable to read()\n");// Print out the returned buffer.   for (i = 0; i < res; i++)printf("buf[%d]: %d\n", i, buf[i]);return 0;
}

License

HIDAPI may be used by one of three licenses as outlined in LICENSE.txt. These licenses are:

  • GPL v3 (see LICENSE-gpl3.txt),
  • BSD (see LICENSE-bsd.txt),
  • The more liberal original HIDAPI license (see LICENSE-orig.txt).

The user of HIDAPI (the developer who uses HIDAPI in their code) can choose to use HIDAPI under any of the three licenses at their discretion. For example:

  1. An author of GPL software would likely use HIDAPI under the terms of the GPL.
  2. An author of commercial, closed-source software would likely use HIDAPI under the terms of either the BSD-style license or the original HIDAPI license.

The idea is to make HIDAPI accessable to as many users as possible for both open- and closed-source applications, and to give users the flexibility to link with the code in any way they see fit.

Download

HIDAPI can be downloaded from GitHub. A zip file is available from the Download Page. To get the latest trunk revision (if you have git installed, run the following:

git clone git://github.com/signal11/hidapi.git

Build Instructions

Windows:
Build the .sln file in the windows/ directory using Visual Studio.

Linux:
Change to the linux/ directory and run make.

Mac OS X:
Change to the mac/ directory and run make.

To build the Test GUI:

  • On Windows, build the .sln file in the hidtest/ directory. Make sure to first set up the externals (Fox Toolkit) as described in README.txt.
  • On Linux and Mac, run make from the hidtest/ directory. Make sure to first install fox-toolkit as described in README.txt

Contact

A mailing list is to be set up soon. For the time being, please direct inquiries and questions to alan@signal11.us.

Signal 11 Software - Updated 2010-10-09

转载于:https://my.oschina.net/freeblues/blog/67644

HID API for Linux, Mac OS X, and Windows相关推荐

  1. 为什么linux/mac os系统和windows系统不一样(文件系统)

    Posix系统调用 windows和linux和mac os底层都采用了不同的文件系统,但是linux和mac os 在所有的文件系统上抽象出来一层虚拟文件系统.所有和文件相关的系统调用在最初的处理上 ...

  2. ActiveState Komodo IDE v5.2.1.34168 最新版for Linux/Mac OS/Windows 全5大平台

    ActiveState Komodo IDE v5.2.1.34168 最新版for Linux/Mac OS/Windows 全5大平台 转载于:https://www.cnblogs.com/ga ...

  3. cp linux 显示进度条_Unix/Linux/Mac os下 文件互传

    Unix/Linux/Mac os下 文件互传 说起文件互传,就不得不提命令scp. 他是Secure copy的缩写,使用ssh连接和加密方式, 如果两台机器之间配置了ssh免密登录, 那在使用sc ...

  4. mac linux win三系统安装教程,【教程】macbook pro上安装三系统详解教程(mac os x+windows+linux ubuntu)...

    有关如何在macbook pro上安装三系统(mac os x+windows+linux ubuntu),本人本本MB986亲自测试,经过4天奋战已初有小成,特地写下详细安装教程便于惠存,如有问题情 ...

  5. mac linux网卡驱动下载官网下载,必联BL-LW06-AR无线网卡驱动(Linux/MAC OS)

    必联BL-LW06-AR无线网卡驱动(Linux/MAC OS)是一款无线网卡驱动的官方驱动程序,USB系列无线网卡用户众多,该驱动适用于BL-LW06-AR 型号的无线网卡,电脑系统支持Linux ...

  6. windows linux mac os 区别

    1.linux的操作比较复杂,windows的比较简单.  linux速度比较快,安全性比windows好  但是有很多软件只能在windows里运行  与linux兼容的软件正在开发中.  linu ...

  7. Windows Linux Mac OS三大系统

    目前常见的三大操作系统:Windows系统.Linux系统 和 Mac OS操作系统. 普通用户一般是选择Windows或Mac OS, Linux主要是占据服务器领域市场. 不管是Windows操作 ...

  8. Python模拟Linux/Mac OS工具grep和Windows工具findstr

    在Linux和Mac OS系统中有个工具grep可以用来查找哪些文件中包含特定的字符串,Windows系统中也有类似的工具findstr,本文代码模拟了这两个工具的工作原理. from os impo ...

  9. mac安装rstudio_在Windows / Linux / Mac OS上安装R和RStudio入门

    mac安装rstudio 在Windows上安装R (Installing R on Windows) Go to r-project.org on your internet browser.在您的 ...

  10. bcd 增加 引导linux系统 mac os x 系统,Windows 7+Windows XP+Ubuntu+Mac OS多系统引导完全解决方案...

    4个操作系统集成:Windows XP(选择原版最好 15G),Windows 7(选择原版最好 25G),Ubuntu(10G),Mac OS(iDeneb版Mac OS 才能安装到PC机上 20G ...

最新文章

  1. 使用html测试数据库连接与操作(含界面) 第二步 功能实现
  2. hdu3415 单调队列模板题
  3. 突然不能访问服务器未响应,windows 访问不服务器未响应
  4. nodejs 生成证书 和 wss server
  5. PyTorch学习—1.深入浅出PyTorch(如何学习PyTorch)
  6. 17110102_Windows系统下WebLogicServer12cR2安装详解
  7. Win10新电脑里的设备和驱动器下如何分盘
  8. Unity,C#版的动画曲线,Tween:EaseIn,EaseOut,EaseInOut(语法逻辑整理版本,含测试代码)
  9. bzoj3786 星系探索(ETT)
  10. 《程序员修炼之道》读书笔记
  11. 汽车日行灯做E-mark认证必须接受要工厂审核吗?
  12. 我为什么不是清华的学生
  13. 03 - OAI接入网搭建过程 - 研0
  14. unity法线贴图,光线烘培的应用
  15. 【ManageEngine卓豪】局域网监控的作用
  16. 遇见最美的你:Flash
  17. python对excel数据统计_python读取excel数据做分类统计
  18. python如何查询数据库_python如何访问数据库
  19. 电脑BIOS 设置怎样从光盘(USB优盘)启动
  20. 从数据到价值,DataOps精益数据运营概述

热门文章

  1. flask框架+pygal+sqlit3搭建图形化业务数据分析平台
  2. 很多同学工作了,这里呢简单说说工作中吧可能会遇到的一些事情‘
  3. Mysql表编码查看修改
  4. 广东地下水资源摘录(早期版的)
  5. DeepSpeaker_RawNet_GE2E 声纹识别对比
  6. 《STL源码剖析》笔记
  7. python基础:re模块匹配时贪婪和非贪婪模式
  8. web中有关文档元素距离的几个jquery 宽度 width高度height 尺寸 属性
  9. Xcode CoreData 存储报错问题。
  10. Oracle开发:常用的数据库字段类型[转]