ISoftUSBEndpointEvents::OnReadTransfer Method
The OnReadTransfer event enables the device simulator to directly return data to the host controller for the transaction. This event is fired when an IN transaction is received from the host.
Syntax
HRESULT OnReadTransfer(
[in] BYTE DataToggle,
[out] BYTE *pbDataBuffer,
[in] ULONG cbDataBuffer,
[out] ULONG *cbDataWritten,
[out] BYTE *pbStatus
);
Parameters
DataToggle [in]
The data toggle value for the request from the host controller.pbDataBuffer [out]
Caller-allocated buffer to hold the data that is returned from the request.cbDataBuffer [in]
The size of the data buffer that holds the returned data.cbDataWritten [out]
The actual amount of data that is returned in the data buffer.pbStatus [out]
The USB status that is returned to the host controller in response to the request.
Return Value
OnReadTransfer returns an HRESULT value.
Remarks
The following C++ code example shows to handle a read request from the host controller.
STDMETHODIMP CSoftUSBEndpointEvent::OnReadTransfer(__in BYTE DataToggle,
__in_bcount(cbDataBuffer) BYTE *pbDataBuffer,
__in ULONG cbDataBuffer,
__out ULONG *cbDataWritten,
__out BYTE *pbStatus)
{
HRESULT hr = S_OK;
BYTE bScalar = 0;
BYTE bSetData = 0;
BYTE bCount = 0;
int iRandom = 0;
if (NULL == pbRetStatus)
{
hr = E_POINTER;
goto Exit;
}
*pbRetStatus = USB_ACK;
// Handle the IN transfer
if (cbDataBuffer < 10)
{
printf("FAIL: IN Buffer is not big enough \n");
hr = E_FAIL;
}
else
{
// Check that the data is valid
// Get a random number between 1 and 10
srand( (unsigned)time( NULL ) );
iRandom = rand();
bScalar = (BYTE)iRandom % 10;
*cbDataWritten = 10;
for (bCount = 0; bCount < *cbDataWritten ; bCount++)
{
bSetData = (bCount+1) * bScalar;
*pbDataBuffer = bSetData;
pbDataBuffer++;
}
}
Exit:
if (S_OK != hr && NULL != pbRetStatus)
{
*pbRetStatus = USB_STALL;
}
return hr;
}
Requirements
Header |
SoftUSBif.h |
See Also
Send comments about this topic to Microsoft
Build date: 9/21/2010