#define EP_ADDRESS 0x81
DATA_COUNTER_STATS Dcs;
DWORD __cdecl main(int argc, char* argv[])
{
DWORD errorCode = ERROR_SUCCESS;
ULONG policyLength, pipeTimeout, newPipeTimeout;
UCHAR myBuffer[1024];
ULONG transferredLength, transferCount;
BOOL success;
int pass = 0;
return GetLastError();
{
printf("Warning: libusb-win32 driver (libusb0.sys) does not support the\n");
printf(" timeout pipe policy with asynchronous transfers.\n");
}
if (!Usb.
Init(&usbHandle, deviceInfo))
{
errorCode = GetLastError();
printf("Usb.Init failed. (0x%08X)\n", errorCode);
goto Done;
}
printf("Device opened successfully!\n");
newPipeTimeout = 10;
do
{
pipeTimeout = 0;
printf("[%02Xh] Getting Pipe-Timeout..\n", EP_ADDRESS);
policyLength = sizeof(ULONG);
success = Usb.
GetPipePolicy(usbHandle, EP_ADDRESS, PIPE_TRANSFER_TIMEOUT, &policyLength, &pipeTimeout);
if (!success)
{
errorCode = GetLastError();
printf("Usb.GetPipePolicy failed. (0x%08X)\n", errorCode);
goto Done;
}
printf("[%02Xh] Pipe-Timeout is %u\n", EP_ADDRESS, pipeTimeout);
if (pass == 1) break;
printf("[%02Xh] Setting Pipe-Timeout to %u..\n", EP_ADDRESS, newPipeTimeout);
policyLength = sizeof(ULONG);
success = Usb.
SetPipePolicy(usbHandle, EP_ADDRESS, PIPE_TRANSFER_TIMEOUT, policyLength, &newPipeTimeout);
if (!success)
{
errorCode = GetLastError();
printf("Usb.SetPipePolicy failed. (0x%08X)\n", errorCode);
goto Done;
}
}
while(++pass < 2);
if (newPipeTimeout != pipeTimeout)
{
errorCode = ERROR_UNIDENTIFIED_ERROR;
printf("Pipe-Timeout did not change.\n");
goto Done;
}
pipeTimeout = 1000;
transferCount = 0;
while((transferCount++ <= 3))
{
printf("[%02Xh] Transfer-Begin #%u..\n", EP_ADDRESS, transferCount);
Usb.
ReadPipe(usbHandle, EP_ADDRESS, myBuffer,
sizeof(myBuffer), NULL, ovlItem);
else
Usb.
WritePipe(usbHandle, EP_ADDRESS, myBuffer,
sizeof(myBuffer), NULL, ovlItem);
mDcs_Init(&Dcs);
{
errorCode = ERROR_MORE_DATA;
continue;
}
else
{
errorCode = GetLastError();
if (errorCode == ERROR_CANCELLED || errorCode == ERROR_OPERATION_ABORTED)
{
errorCode = ERROR_SUCCESS;
if (pipeTimeout != newPipeTimeout)
{
pipeTimeout = newPipeTimeout;
}
else
{
mDcs_MarkStop(&Dcs, 0);
printf("[%02Xh] Transfer-Duration: %.2f ms\n", EP_ADDRESS, Dcs.Duration * 1000);
}
}
else
{
printf("[%02Xh] Unexpected-Error: %08Xh!\n", EP_ADDRESS, errorCode);
break;
}
}
}
Done:
if (usbHandle) Usb.
Free(usbHandle);
return errorCode;
}