gpt4 book ai didi

windows - 当我在 Windows 上的 HID 设备上执行 ReadFile() 时会发生什么?

转载 作者:可可西里 更新时间:2023-11-01 09:59:01 25 4
gpt4 key购买 nike

当我对 CreateFile(HID_DEVICE_NAME,...) 提供的句柄执行 ReadFile/WriteFile 时,HID 操作方面会发生什么情况?

它是向 HID 设备(在我的例子中是 USB)发出直接写入/读取请求,还是在底层驱动程序的某处进行转换以读取具有此类 ID 的最后缓存的 HID 报告?


ReadFile 调用:

syncDevice.OutputReportBuffer[0] = 0;
syncDevice.OutputReportBuffer[1] = reportID;
HANDLE writeHandle = CreateFile(pDevice->DevicePath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
HANDLE readHandle = CreateFile(pDevice->DevicePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
success = WriteFile(writeHandle, (void*) syncDevice.OutputReportBuffer, syncDevice.Caps.OutputReportByteLength, &bytecnt, 0);
success = ReadFile(readHandle, syncDevice.InputReportBuffer, syncDevice.Caps.InputReportByteLength, &bytecnt, 0);

最佳答案

来自 USB Complete by Jan Axelson :

The Windows HID driver causes the host controller to request Input reports. The driver stores received reports in a buffer. ReadFile retrieves one or more reports from the buffer. If the buffer is empty, ReadFile waits for a report to arrive. In other words, ReadFile doesn’t cause a device to send a report but just reads reports that the driver has requested.

WriteFile sends an Output report. The function uses an interrupt transfer if the HID has an interrupt OUT endpoint and the operating system is later than Windows 98 Gold. Otherwise, WriteFile uses a control transfer with a Set Report request. If using interrupt transfers, WriteFile will wait if the device NAKs. If using control transfers, WriteFile returns with an error code on failure or a timeout.

关于windows - 当我在 Windows 上的 HID 设备上执行 ReadFile() 时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26508601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com