📄 main.c
字号:
0,
&nBytes,
NULL);
if (bResult != TRUE)
{
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Pipe Reset Failed");
CloseHandle (hDevice);
break;
}
// perform the ISO transfer
IsoControl.PacketCount = GetDlgItemInt(hDlg,IDC_ISO_PACKETS,&Success,FALSE);
IsoControl.PipeNum = GetDlgItemInt(hDlg,IDC_ISO_PIPE,&Success,FALSE);
IsoControl.BufferCount = GetDlgItemInt(hDlg,IDC_ISO_BUFFER_COUNT,&Success,FALSE);
IsoControl.FramesPerBuffer = GetDlgItemInt(hDlg,IDC_ISO_FRAMES_PER_BUFFER,&Success,FALSE);
bResult = DeviceIoControl (hDevice,
IOCTL_EZUSB_START_ISO_STREAM,
&IsoControl,
sizeof(ISO_TRANSFER_CONTROL),
NULL,
0,
&nBytes,
NULL);
if (bResult != TRUE)
{
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"ISO Transfer Failed");
CloseHandle (hDevice);
break;
}
CloseHandle (hDevice);
}
break;
case IDC_STOP_ISO_STREAM:
{
// Open the driver
GetDlgItemText (hDlg, IDC_DRIVER_NAME, pcDriverName, MAX_DRIVER_NAME);
if (bOpenDriver (&hDevice, pcDriverName) == TRUE)
{
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Opened Driver Successfully");
} else {
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Failed to Open Driver");
hDevice = NULL;
break;
}
bResult = DeviceIoControl (hDevice,
IOCTL_EZUSB_STOP_ISO_STREAM,
NULL,
0,
NULL,
0,
&nBytes,
NULL);
if (bResult != TRUE)
{
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"ISO Transfer Failed");
CloseHandle (hDevice);
break;
}
CloseHandle (hDevice);
}
break;
case IDC_START_READ_THREAD:
StopTest = FALSE;
_beginthread(TestThread,0,hDlg);
break;
case IDC_STOP_READ_THREAD:
StopTest = TRUE;
break;
case IDC_READ_ISO_BUFFER:
{
ISO_TRANSFER_CONTROL IsoControl;
ULONG bytesToRead;
BOOL Success;
PUCHAR buffer = NULL;
ULONG packetsRead;
PUSBD_ISO_PACKET_DESCRIPTOR isoDesc;
ULONG i;
PUCHAR ptr;
// Open the driver
GetDlgItemText (hDlg, IDC_DRIVER_NAME, pcDriverName, MAX_DRIVER_NAME);
if (bOpenDriver (&hDevice, pcDriverName) == TRUE)
{
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Opened Driver Successfully");
} else {
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Failed to Open Driver");
hDevice = NULL;
break;
}
IsoControl.PacketSize = GetDlgItemInt(hDlg,IDC_ISO_PACKET_SIZE,&Success,FALSE);
IsoControl.PacketCount = GetDlgItemInt(hDlg,IDC_ISO_PACKETS,&Success,FALSE);
IsoControl.PipeNum = GetDlgItemInt(hDlg,IDC_ISO_PIPE,&Success,FALSE);
IsoControl.BufferCount = GetDlgItemInt(hDlg,IDC_ISO_BUFFER_COUNT,&Success,FALSE);
IsoControl.FramesPerBuffer = GetDlgItemInt(hDlg,IDC_ISO_FRAMES_PER_BUFFER,&Success,FALSE);
bytesToRead = IsoControl.PacketCount * (IsoControl.PacketSize + sizeof(USBD_ISO_PACKET_DESCRIPTOR));
buffer = (PUCHAR) malloc(bytesToRead);
sprintf(tempbuff, "requesting %d bytes",bytesToRead);
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM) tempbuff);
if (!buffer)
{
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"alloc Failed");
break;
}
QueryPerformanceFrequency(&llnHPTimerFreq);
QueryPerformanceCounter(&llnHPT1);
bResult = DeviceIoControl (hDevice,
IOCTL_EZUSB_READ_ISO_BUFFER,
&IsoControl,
sizeof(ISO_TRANSFER_CONTROL),
buffer,
bytesToRead,
&nBytes,
NULL);
QueryPerformanceCounter(&llnHPT2);
llnT_uSec.QuadPart = ( (llnHPT2.QuadPart - llnHPT1.QuadPart) * // Time Delta
((LONGLONG)1E9/llnHPTimerFreq.QuadPart) ) /
(LONGLONG)1E3; // could divide by 1E9 for Time in Sec
sprintf(tempbuff,"DMA completed in %3d Sec: %03d mSec: %03d uSec\n",
llnT_uSec.LowPart/(LONG)1E6, (llnT_uSec.LowPart/(LONG)1E3)%(1000),
(llnT_uSec.LowPart)%(1000));
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM) tempbuff);
if (bResult != TRUE)
{
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"ISO Read Failed");
CloseHandle (hDevice);
break;
}
sprintf(tempbuff, "transferred %d bytes",nBytes);
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM) tempbuff);
packetsRead = nBytes / (IsoControl.PacketSize + sizeof(USBD_ISO_PACKET_DESCRIPTOR));
ptr = buffer;
isoDesc = (PUSBD_ISO_PACKET_DESCRIPTOR) (buffer + (packetsRead * IsoControl.PacketSize));
for (i=0;i<packetsRead;i++)
{
sprintf(tempbuff, "Packet %d length = %d status = %d val = %d",i,isoDesc[i].Length,isoDesc[i].Status,*ptr);
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM) tempbuff);
ptr += IsoControl.PacketSize;
}
free(buffer);
CloseHandle (hDevice);
}
break;
} /*end switch wParam*/
break;
} /*end switch message*/
return FALSE;
} /*end MainDlgProc*/
#define BYTES_PER_LINE 0x10
void
DumpBuffer(PVOID pvBuffer, ULONG length, HWND hOutputBox)
{
int nItems = 0;
char temp[64] = "";
char temp2[64] = "";
ULONG i;
ULONG j;
PUCHAR ptr;
MAINTAIN_OUTPUT_BOX (hOutputBox, nItems);
ptr = (PUCHAR) pvBuffer;
for (i = 0; i < ((length + BYTES_PER_LINE - 1) / BYTES_PER_LINE); i++)
{
wsprintf(temp,"%04X ",(i*BYTES_PER_LINE));
for (j = 0; j < BYTES_PER_LINE; j++)
{
if (((i * BYTES_PER_LINE) + j) < length)
{
wsprintf(temp2,"%02X ",*ptr++);
strcat(temp,temp2);
}
}
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);
}
}
/**************************************************
* bOpenDriver proc *
* *
* Purpose: *
* Opens the device driver using symbolic *
* name provided *
* *
* Input: *
* phDeviceHandle: *
* Pointer to Device Driver handle where *
* the file handle is placed. *
* devname: *
* Null terminated string containing the *
* device name *
* *
* Return Value: *
* Boolean that indicates if the driver was *
* successfully opened or not. *
* *
**************************************************/
BOOLEAN
bOpenDriver (HANDLE * phDeviceHandle, PCHAR devname)
{
char completeDeviceName[64] = "";
char pcMsg[64] = "";
strcat (completeDeviceName,
"\\\\.\\"
);
strcat (completeDeviceName,
devname
);
*phDeviceHandle = CreateFile( completeDeviceName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
if (*phDeviceHandle == INVALID_HANDLE_VALUE) {
return (FALSE);
} else {
return (TRUE);
} /*else*/
}//OpenDevice
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -