15,471
社区成员
发帖
与我相关
我的任务
分享
/**
往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);