TI中文支持网
TI专业的中文技术问题搜集分享网站

DLPLCR4500EVM: 二次开发时在hid_write函数处出错

Part Number:DLPLCR4500EVM

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

错误信息如下图

MengAo Zeng:

有可能是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;

}

赞(0)
未经允许不得转载:TI中文支持网 » DLPLCR4500EVM: 二次开发时在hid_write函数处出错
分享到: 更多 (0)