TI论坛
直播中

李中宏

8年用户 1379经验值
私信 关注
[问答]

DLPLCR4500EVM二次开发时在hid_write函数处出错是什么原因导致的?


  • 二次开发时在hid_write函数处出错,之前没有错误不知道动了什么导致出错了,环境为X64的C++,使用下载的GUI软件是可以连接并投影图片的。
    错误信息如下图

回帖(1)

张瑞娟

2025-2-23 09:49:08
  有可能是DeviceHandle没有成功打开。端口占用或者超出范围。
 
 
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *data, size_t length)
{
              DWORD bytes_written;
              BOOL res;
 
              OVERLAPPED ol;
              unsigned char *buf;
              memset(&ol, 0, sizeof(ol));
 
              /* Make sure the right number of bytes are passed to WriteFile. Windows
                 expects the number of bytes which are in the _longest_ report (plus
                 one for the report number) bytes even if the data is a report
                 which is shorter than that. Windows gives us this value in
                 caps.OutputReportByteLength. If a user passes in fewer bytes than this,
                 create a temporary buffer which is the proper size. */
              if (length >= dev->output_report_length) {
                             /* The user passed the right number of bytes. Use the buffer as-is. */
                             buf = (unsigned char *) data;
              } else {
                             /* Create a temporary buffer and copy the user's data
                                into it, padding the rest with zeros. */
                             buf = (unsigned char *) malloc(dev->output_report_length);
                             memcpy(buf, data, length);
                             memset(buf + length, 0, dev->output_report_length - length);
                             length = dev->output_report_length;
              }
 
              res = WriteFile(dev->device_handle, buf, length, NULL, &ol);
             
              if (!res) {
                             if (GetLastError() != ERROR_IO_PENDING) {
                                           /* WriteFile() failed. Return error. */
                                           register_error(dev, "WriteFile");
                                           bytes_written = -1;
                                           goto end_of_function;
                             }
              }
 
              /* Wait here until the write is done. This makes
                 hid_write() synchronous. */
              res = GetOverlappedResult(dev->device_handle, &ol, &bytes_written, TRUE/*wait*/);
              if (!res) {
                             /* The Write operation failed. */
                             register_error(dev, "WriteFile");
                             bytes_written = -1;
                             goto end_of_function;
              }
 
end_of_function:
              if (buf != data)
                             free(buf);
 
              return bytes_written;
}
举报

更多回帖

发帖
×
20
完善资料,
赚取积分