USB论坛-百合电子工作室USB专题站

 找回密码
 我要注册
搜索
热搜: USB学习板
查看: 9466|回复: 2

Mac OS X HID 开发

[复制链接]

2

主题

0

好友

48

积分

新手上路

Rank: 1

发表于 2015-1-29 16:03:05 |显示全部楼层
    请问一下哪一位大侠有相关Mac OS X HID 开发资料,还有怎么开发流程?
回复

使用道具 举报

6

主题

0

好友

1154

积分

管理员

Rank: 9Rank: 9Rank: 9

发表于 2015-1-29 18:55:19 |显示全部楼层
这里有一个适用于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;
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?我要注册

回复

使用道具 举报

2

主题

0

好友

48

积分

新手上路

Rank: 1

发表于 2015-1-29 19:21:19 |显示全部楼层
感谢baiheee的帮助!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 我要注册

USB开发网 (渝ICP备09006681号-4)

GMT+8, 2024-3-29 08:33 , Processed in 0.050834 second(s), 20 queries .

百合电子工作室版权所有
回顶部