下载啦:请放心下载,安全无病毒!

软件提交最近更新 热门排行
您现在的位置: 下载啦 > 编程开发 > 编程软件 > HIDAPI(HID设备的C语言通用库) v0.10.1官方版
HIDAPI(HID设备的C语言通用库) v0.10.1官方版
0%
0%

HIDAPI(HID设备的C语言通用库) v0.10.1官方版 HIDAPI下载

  • 软件介绍
  • 软件截图
  • 相关下载
  • 相关文章

HIDAPI是一款HID多平台库文件,是USB和蓝牙的HID类设备在系统中的C语言通用库,支持Windows、Linux和Mac等系统,不同的系统包括不同的功能,即可作为一个单独的共享库,也可添加一个源文件或者头文件嵌入到第三方应用程序中。

HIDAPI(HID设备的C语言通用库) v0.10.1官方版

使用说明

HIDAPI有五个后端。

Windows (使用hid.dll)

Linux/hidraw (使用内核的hidraw驱动)

Linux/libusb (使用libusb-1.0)

FreeBSD (使用libusb-1.0)

Mac (使用IOHidManager)

在Linux上,可以使用hidraw或libusb后端。有一些取舍,支持的功能也略有不同。

Linux/hidraw(linux/hid.c)。

这个后端使用Linux内核中的hidraw接口,并支持USB和蓝牙HID设备。它需要内核版本至少为2.6.39才能构建。此外,它只能与有hidraw节点关联的设备进行通信。键盘、鼠标和其他一些被列入黑名单的设备将无法使用hidraw节点。幸运的是,对于几乎所有的hidraw用途来说,这都不是一个问题。

Linux/FreeBSD/libusb(libusb/hid.c)。

这个后端使用libusb-1.0来直接与USB设备通信。当然,这个后端不会与蓝牙设备一起工作。

HIDAPI还带有一个测试图形用户界面。该测试GUI是跨平台的,使用Fox Toolkit http://www.fox-toolkit.org。它可以在HIDAPI支持的每个平台上构建。由于它依赖于一个第三方库,构建它是可选的,但推荐使用,因为它在调试硬件时非常有用。

示例代码:

#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 Foundn type: %04hx %04hxn path: %sn serial_number: %ls",

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

printf("n");

printf(" Manufacturer: %lsn", cur_dev->manufacturer_string);

printf(" Product: %lsn", 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: %lsn", wstr);

// Read the Product String

res = hid_get_product_string(handle, wstr, MAX_STR);

printf("Product String: %lsn", 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 Reportn ");

for (i = 0; i < res; i++)

printf("%02hhx ", buf);

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]: %dn", i, buf);

return 0;

}

  • HIDAPI(HID设备的C语言通用库)v0.10.1官方版(1)

下载地址

  • Pc版

HIDAPI(HID设备的C语言通用库) v0.10.1官方版

软件评论 您的评论需要经过审核才能显示

请自觉遵守互联网相关政策法规,评论内容只代表网友观点,与本站立场无关!
网友评论