日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

hidapi在linux下编译,HIDAPI

發布時間:2023/12/15 linux 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。