【HID相关问题】

大树学长 2018-09-11 05:07:06
两个问题:
没有用过HID,网上找的例子都不好用,有的是版本不同打不开,我是WIN10+VS2013

1、有没有刚好我可以用的,给我一个简单的demo,能收发就行。
2、WIN32中hid类在MFC中使用是不是和在WIN32中使用一样?


网上找的一个版本号这些弄对后,可以联机,可以接收下位机的数据,但就是发送有问题返回-1,这是一个DLL,也看不到是什么错误,因为只能发送UINT8的,所有只能参考下,没有什么用。

/**
往usb接口中写入数据,这里要注意写入数据的内容长度必须多加一个字节空间,需要存放
报告ID号,在这里我一门设置为0,如果你要传送64字节,此时你要提供65个字节空间大小,
而且你的有效数据从第一个字节开始存放。该函数返回实际写入的数据长度。
*/
int Write(UINT8 *data, UINT32 len)
{
int ret = 0;
if (usbDev)
{
data[0] = 0;
ret = hid_write(usbDev, data, len);
}
return ret;
}

/** @brief Write an Output report to a HID device.

The first byte of @p data[] must contain the Report ID. For
devices which only support a single report, this must be set
to 0x0. The remaining bytes contain the report data. Since
the Report ID is mandatory, calls to hid_write() will always
contain one more byte than the report contains. For example,
if a hid report is 16 bytes long, 17 bytes must be passed to
hid_write(), the Report ID (or 0x0, for devices with a
single report), followed by the report data (16 bytes). In
this example, the length passed in would be 17.

hid_write() will send the data on the first OUT endpoint, if
one exists. If it does not, it will send the data through
the Control Endpoint (Endpoint 0).

@ingroup API
@param device A device handle returned from hid_open().
@param data The data to send, including the report number as
the first byte.
@param length The length in bytes of the data to send.

@returns
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length);
...全文
211 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgl7903 2018-09-16
  • 打赏
  • 举报
回复
HID 的写 ,
如果不带ID的,缓冲区直接是数据,长的=包长度
如果包带ID的,缓冲区第一个字节是ID,后面是数据,长度=包长度+1
算什么男人000 2018-09-12
  • 打赏
  • 举报
回复
这个网站有可运行的源代码,可以看下有没有你想要的http://www.newxing.com/Code/VC/xitong/4673.html
算什么男人000 2018-09-12
  • 打赏
  • 举报
回复
百度上蛮多的吧:https://www.cnblogs.com/MMLoveMeMM/articles/3216088.html
http://blog.sina.com.cn/s/blog_b4ce638e0101emqw.html
http://www.ilovematlab.cn/thread-114034-1-1.html看看有没有能用的
赵4老师 2018-09-11
  • 打赏
  • 举报
回复
搜“devcon”?

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧