Asynchronously streams data to or from an endpoint.
#define EP_ADDRESS 0x81
#define MAX_TRANSFER_SIZE 4096
#define MAX_PENDING_TRANSFERS 128
#define MAX_PENDING_IO 3
DATA_COUNTER_STATS Dcs;
DWORD __cdecl main(int argc, char* argv[])
{
DWORD errorCode = ERROR_SUCCESS;
DWORD transferLength = 0;
BOOL success;
UCHAR myBuffer[MAX_TRANSFER_SIZE * MAX_PENDING_IO];
return GetLastError();
if (!Usb.
Init(&usbHandle, deviceInfo))
{
errorCode = GetLastError();
printf("Usb.Init failed. ErrorCode: %08Xh\n", errorCode);
goto Done;
}
printf("Device opened successfully!\n");
success = Bench_Configure(usbHandle, BM_COMMAND_SET_TEST, 0, &Usb, &testType);
&streamHandle,
usbHandle,
EP_ADDRESS,
MAX_TRANSFER_SIZE,
MAX_PENDING_TRANSFERS,
MAX_PENDING_IO,
NULL,
if (!success)
{
errorCode = GetLastError();
printf("StmK_Init failed. ErrorCode: %08Xh\n", errorCode);
goto Done;
}
if (!success)
{
errorCode = GetLastError();
printf("StmK_Start failed. ErrorCode: %08Xh\n", errorCode);
goto Done;
}
printf("[Start Stream] successful!\n");
mDcs_Init(&Dcs);
while(_kbhit()) _getch();
do
{
ULONG length;
success =
StmK_Read(streamHandle, myBuffer, 0,
sizeof(myBuffer), &length);
else
success =
StmK_Write(streamHandle, myBuffer, 0,
sizeof(myBuffer), &length);
if (success)
{
transferLength += length;
}
else
{
if (GetLastError() != ERROR_NO_MORE_ITEMS)
{
break;
}
if (transferLength >= sizeof(myBuffer) * 8)
{
mDcs_MarkStop(&Dcs, transferLength);
printf("Transferred bytes:%d BPS:%.2f\n", transferLength, Dcs.Bps);
transferLength = 0;
}
if ((Dcs.TotalBytes >= (sizeof(myBuffer) * 128)))
{
if (transferLength)
{
mDcs_MarkStop(&Dcs, transferLength);
transferLength = 0;
}
errorCode = (success) ? ERROR_SUCCESS : GetLastError();
if (!success) printf("StmK_Stop failed. ErrorCode: %08Xh\n", errorCode);
if (!success) goto Done;
printf("[StreamResult] "
"Bytes-total:%I64d Seconds-total:%.3f BPS-average:%.2f\n",
Dcs.TotalBytes, Dcs.Duration, Dcs.Bps);
errorCode = (success) ? ERROR_SUCCESS : GetLastError();
if (!success) printf("StmK_Start failed. ErrorCode: %08Xh\n", errorCode);
if (!success) goto Done;
mDcs_Init(&Dcs);
}
else
{
Sleep(100);
}
}
}
while(!_kbhit());
if (!success)
{
errorCode = GetLastError();
printf("StmK_Stop failed. ErrorCode: %08Xh\n", errorCode);
goto Done;
}
printf("[Stop Stream] successful!\n");
Done:
if (streamHandle)
{
}
return errorCode;
}