Asynchronously submits an application defined number of transfers.
#define EP_ADDRESS 0x81
#define ASYNC_PENDING_IO_COUNT 3
#define ASYNC_TIMEOUT_MS 1000
typedef struct _MY_IO_REQUEST
{
DWORD Index;
DWORD ErrorCode;
DWORD BufferSize;
UCHAR Buffer[4096];
DWORD TransferLength;
struct _MY_IO_REQUEST* prev;
struct _MY_IO_REQUEST* next;
} MY_IO_REQUEST, *PMY_IO_REQUEST;
DWORD __cdecl main(int argc, char* argv[])
{
DWORD errorCode = ERROR_SUCCESS;
BOOL success;
MY_IO_REQUEST ovlArray[ASYNC_PENDING_IO_COUNT];
PMY_IO_REQUEST requestList = NULL;
PMY_IO_REQUEST myRequest;
DWORD ovlIndex;
ULONG totalLength = 0;
return GetLastError();
if (!Usb.
Init(&usbHandle, deviceInfo))
{
errorCode = GetLastError();
printf("Init device failed. ErrorCode: %08Xh\n", errorCode);
goto Done;
}
printf("Device opened successfully!\n");
success = Bench_Configure(usbHandle, BM_COMMAND_SET_TEST, 0, &Usb, &testType);
if (!success) printf("Bench_Configure failed.\n");
OvlK_Init(&ovlPool, usbHandle, ASYNC_PENDING_IO_COUNT, 0);
memset(ovlArray, 0, sizeof(ovlArray));
for(ovlIndex = 0; ovlIndex < ASYNC_PENDING_IO_COUNT; ovlIndex++)
{
{
errorCode = GetLastError();
printf("OvlK_Acquire failed. ErrorCode: %08Xh\n", errorCode);
goto Done;
}
ovlArray[ovlIndex].Index = ovlIndex;
ovlArray[ovlIndex].BufferSize = sizeof(ovlArray[ovlIndex].Buffer);
}
{
Usb.
ReadPipe(usbHandle, EP_ADDRESS, myRequest->Buffer, myRequest->BufferSize, NULL, myRequest->Ovl);
else
Usb.
WritePipe(usbHandle, EP_ADDRESS, myRequest->Buffer, myRequest->BufferSize, NULL, myRequest->Ovl);
myRequest->ErrorCode = GetLastError();
if (myRequest->ErrorCode != ERROR_IO_PENDING)
{
errorCode = myRequest->ErrorCode;
printf("Failed submitting transfer #%u for %u bytes.\n", myRequest->Index, myRequest->BufferSize);
break;
}
printf("Transfer #%u submitted for %u bytes.\n", myRequest->Index, myRequest->BufferSize);
}
{
if (myRequest->ErrorCode == ERROR_IO_PENDING)
{
printf("Waiting %u ms for transfer #%u to complete..\n", ASYNC_TIMEOUT_MS, myRequest->Index);
success =
OvlK_WaitOrCancel(myRequest->Ovl, ASYNC_TIMEOUT_MS, &myRequest->TransferLength);
if (!success)
{
errorCode = myRequest->ErrorCode = GetLastError();
printf("Transfer #%u did not complete. ErrorCode=%08Xh\n", myRequest->Index, myRequest->ErrorCode);
}
else
{
myRequest->ErrorCode = ERROR_SUCCESS;
totalLength += myRequest->TransferLength;
printf("Transfer #%u completed with %u bytes.\n", myRequest->Index, myRequest->TransferLength);
}
}
}
if (errorCode == ERROR_SUCCESS)
{
printf("Transferred %u bytes successfully.\n", totalLength, errorCode);
}
else
{
printf("Transferred %u bytes. ErrorCode=%08Xh\n", totalLength, errorCode);
}
Done:
if (usbHandle) Usb.
Free(usbHandle);
return errorCode;
}