Hi all,
I have a 64bit user mode driver created using UMDF based on the examples that ship with the SDK. Communication between app and device works fine for the most part with a combination of device io requests and bulk i/o.
Most commands occur via bulk i/o with a short 8 byte packet coming in via OnWrite and been passed onto the appropriate usb endpoint. This is followed a short time later by an OnRead request to obtain the result of the command.
Most of the write/read requests are completing correctly with the bytes requested in the OnRead matching the bytes transfered as shown in the OnCompletion callback. However, those read requests are for small amounts of 2, 4, 8 or 17 bytes at a time.
The problem begins when a read request comes in for 10,202,400 bytes (which is following a OnWrite request for a full field readout of the camera of 10,202,400 bytes). The OnRead request has 10,202,400 bytes in the BytesToRead parameter and the output buffer in the request parameter is 10,202,400 in size.
When the OnCompletion callback fires however, it reports 10,202,112 bytes were actually transferred.
I’ve read a few posts on here about the buffer needing to be a multiple of the endpoint packet size. As the output buffer is not a multiple of 512 but the returned 10,202,112 is, could that be a cause of the problem?
It does look like the remainder of the data is coming in during subsequent reads, which then throws things out of sync.
If the buffer used in the OnRead callback needs to be a multiple of 512, how can I reformat it during the OnRead callback before it’s passed on to the endpoint with a send?
Or could something else be the cause?
Here’s my current OnRead callback for the Queue.
STDMETHODIMP_ (void)
CMyQueue::OnRead(
/\* [in] \*/ IWDFIoQueue \*pWdfQueue,
/\* [in] \*/ IWDFIoRequest \*pWdfRequest,
/\* [in] \*/ SIZE_T BytesToRead
)
{
UNREFERENCED_PARAMETER(pWdfQueue);
TraceEvents(TRACE_LEVEL_INFORMATION,
TEST_TRACE_QUEUE,
"%!FUNC!: Queue %p Request %p BytesToTransfer %d\n",
this,
pWdfRequest,
(ULONG)(ULONG_PTR)BytesToRead
);
HRESULT hr = S_OK;
IWDFMemory \* pOutputMemory = NULL;
pWdfRequest-\>GetOutputMemory(&pOutputMemory);
hr = m_Parent-\>GetInputPipe()-\>FormatRequestForRead(
pWdfRequest,
NULL, //pFile
pOutputMemory,
NULL, //Memory offset
NULL //DeviceOffset
);
if (FAILED(hr))
{
TraceEvents(TRACE_LEVEL_INFORMATION, TEST_TRACE_QUEUE, "Format request failed");
pWdfRequest-\>Complete(hr);
}
else
{
ForwardFormattedRequest(pWdfRequest, m_Parent-\>GetInputPipe());
}
SAFE_RELEASE(pOutputMemory);
return;
}
I’ve tried creating a new memory object in the OnRead callback and using that in the format call to no avail.
Any suggestions appreciated.