USB论坛-百合电子工作室USB专题站
标题: Mac OS X HID 开发 [打印本页]
作者: gason 时间: 2015-1-29 16:03
标题: Mac OS X HID 开发
请问一下哪一位大侠有相关Mac OS X HID 开发资料,还有怎么开发流程?
作者: baiheee 时间: 2015-1-29 18:55
这里有一个适用于MAX OS的HID函数接口(HID API),下面是关于此API的简单说明。
HIDAPI是一个适用于多平台的HID设备类应用程序接口函数,它适用于Windows、Linux和Mac OS x三种系统,,它可以用于标准HID设备,如键盘,鼠标,游戏手柄,以及自定义HID设备。 HIDAPI很容易集成到客户端应用程序中。
在Windows上,有一个编译好的DLL,在其它平台上,只需要将一个源文件导入应用程序的源代码中即可使用。
HIDAPI为每个平台提供了一个干净的和一致的接口,使其更容易开发与USB HID设备通信的应用程序。
HIDAPI还提供了一个GUI测试应用程序,在所有平台上运行上都有对应的测试程序。
下面是windows下使用HIDAPI的一个范例
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "hidapi.h"
#define MAX_STR 255
int main(int argc, char* argv[])
{
int res;
unsigned char buf[65];
wchar_t wstr[MAX_STR];
hid_device *handle;
int i;
// 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);
wprintf(L"Manufacturer String: %s\n", wstr);
// Read the Product String
res = hid_get_product_string(handle, wstr, MAX_STR);
wprintf(L"Product String: %s\n", wstr);
// Read the Serial Number String
res = hid_get_serial_number_string(handle, wstr, MAX_STR);
wprintf(L"Serial Number String: (%d) %s\n", wstr[0], wstr);
// Read Indexed String 1
res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
wprintf(L"Indexed String 1: %s\n", wstr);
// Toggle LED (cmd 0x80). The first byte is the report number (0x0).
buf[0] = 0x0;
buf[1] = 0x80;
res = hid_write(handle, buf, 65);
// Request state (cmd 0x81). The first byte is the report number (0x0).
buf[0] = 0x0;
buf[1] = 0x81;
res = hid_write(handle, buf, 65);
// Read requested state
hid_read(handle, buf, 65);
// Print out the returned buffer.
for (i = 0; i < 4; i++)
printf("buf[%d]: %d\n", i, buf);
return 0;
}
作者: gason 时间: 2015-1-29 19:21
感谢baiheee的帮助!
欢迎光临 USB论坛-百合电子工作室USB专题站 (http://usb.baiheee.com/usb_bbs/) |
Powered by Discuz! X2.5 |