Synchronously completes an application defined number of transfers.
#define EP_ADDRESS 0x81
#define SYNC_TRANSFER_COUNT 3
DWORD __cdecl main(int argc, char* argv[])
{
DWORD errorCode = ERROR_SUCCESS;
BOOL success;
UCHAR myBuffer[4096];
ULONG totalLength = 0;
ULONG transferredLength;
ULONG transferIndex;
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");
transferIndex = (DWORD) - 1;
while (++transferIndex < SYNC_TRANSFER_COUNT)
{
success = Usb.
ReadPipe(usbHandle, EP_ADDRESS, myBuffer,
sizeof(myBuffer), &transferredLength, NULL);
else
success = Usb.
WritePipe(usbHandle, EP_ADDRESS, myBuffer,
sizeof(myBuffer), &transferredLength, NULL);
if (!success)
{
errorCode = GetLastError();
break;
}
totalLength += transferredLength;
printf("Transfer #%u completed with %u bytes.\n", transferIndex, transferredLength);
}
printf("Transferred %u bytes in %u transfers. errorCode=%08Xh\n", totalLength, transferIndex, errorCode);
Done:
if (usbHandle) Usb.
Free(usbHandle);
return errorCode;
}