📄 usbapp.c
字号:
if (UsbOpenDriver (&hDevice, DeviceName) != TRUE) {
MessageBox(hdlg, "USB Device Error,Please Reset!","Error",MB_ICONERROR);
Testing=FALSE;
return;
}
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR,
NULL,
0,
&output,
sizeof(USB_DEVICE_DESCRIPTOR),
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox(hdlg, "Read Device Descriptor Failure!","Error",MB_ICONERROR);
else {
SetDlgItemText (hdlg, IDC_INFORMATION, "Test-Device Descrioptor:");
SendMessage (houtputlist, LB_RESETCONTENT, 0, 0);
SendMessage (htestlist, LB_RESETCONTENT, 0, 0);
sprintf(tempbuff[0],"[0]Length(bLength): 0x%xH",output.bLength);
sprintf(tempbuff[1],"[1]Type(bDescriptorType):0x0%xH",output.bDescriptorType);
sprintf(tempbuff[2],"[2]USB Edition(bcdUSB): 0x0%0xH",output.bcdUSB);
sprintf(tempbuff[3],"[4]Class Code(bDeviceClass):0x0%xH",output.bDeviceClass);
sprintf(tempbuff[4],"[5]SubClass Code(bDeviceSubClass):0x0%xH",output.bDeviceSubClass);
sprintf(tempbuff[5],"[6]Protocol Code(bDeviceProtocol):0x0%xH",output.bDeviceProtocol);
sprintf(tempbuff[6],"[7]EP0 Packte Size(bMaxPacketSize0):0x%xH",output.bMaxPacketSize0);
sprintf(tempbuff[7],"[8]Vendor ID(idVendor):0x0%xH",output.idVendor);
sprintf(tempbuff[8],"[10]Product ID(idProduct):0x%xH",output.idProduct);
sprintf(tempbuff[9],"[12]Device Edition(bcdDevice):0x0%0xH",output.bcdDevice);
sprintf(tempbuff[10],"[14]Manufacture Descriptor(iManufacturer):0x0%xH",output.iManufacturer);
sprintf(tempbuff[11],"[15]Product Descriptor(iProduct):0x0%xH",output.iProduct);
sprintf(tempbuff[12],"[16]Serial Number(iSerialNumber):0x0%xH",output.iSerialNumber);
sprintf(tempbuff[13],"[17]Configuration Number(bNumConfigurations):0x0%xH",output.bNumConfigurations);
for(i=0;i<14;i++)
SendMessage (houtputlist, LB_ADDSTRING, 0, (LPARAM)tempbuff[i]);
}
CloseHandle(hDevice);
Testing=FALSE;
return;
}
}
void GetConfigurationDescriptorTest(HWND hdlg)
{
if (Testing ==TRUE) {
MessageBox(hdlg, "Testing,Please Stop Current Test!","Error",MB_ICONINFORMATION);
return;
}
Testing=TRUE;
{
HANDLE hDevice=NULL;
HWND houtputlist;
HWND htestlist;
BOOL bResult = FALSE;
ULONG nBytes;
char DeviceName[MAX_DEVICE_NAME] = "";
char tempbuff[18][256];
unsigned char output2[200];
int i;
USB_CONFIGURATION_DESCRIPTOR output;
houtputlist = GetDlgItem (hdlg, IDC_OUTPUT_LIST);
htestlist = GetDlgItem (hdlg, IDC_TEST_LIST);
GetDlgItemText (hdlg, IDC_DEVICE_NAME, DeviceName, MAX_DEVICE_NAME);
if (UsbOpenDriver (&hDevice, DeviceName) != TRUE) {
MessageBox(hdlg, "USB Device Error,Please Reset!","Error",MB_ICONERROR);
Testing=FALSE;
return;
}
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_CONFIGURATION_DESCRIPTOR,
NULL,
0,
&output,
sizeof(USB_CONFIGURATION_DESCRIPTOR),
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox(hdlg, "Read Configuration Descriptor Failure!","Error",MB_ICONERROR);
else {
SetDlgItemText (hdlg, IDC_INFORMATION, "Test-ConfigurationDescrioptor:");
SendMessage (houtputlist, LB_RESETCONTENT, 0, 0);
SendMessage (htestlist, LB_RESETCONTENT, 0, 0);
sprintf(tempbuff[0],"[0]Length(bLength): 0x0%xH",output.bLength);
sprintf(tempbuff[1],"[1]Type(bDescriptorType):0x0%xH",output.bDescriptorType);
sprintf(tempbuff[2],"[2]Total Length(wTotalLength): 0x%0xH",output.wTotalLength);
sprintf(tempbuff[3],"[4]Interface Number(bNumInterfaces):0x0%xH",output.bNumInterfaces);
sprintf(tempbuff[4],"[5]SetGet Request(bConfigurationValue):0x0%xH",output.bConfigurationValue);
sprintf(tempbuff[5],"[6]String Descriptor(iConfiguration):0x0%xH",output.iConfiguration);
sprintf(tempbuff[6],"[7]Setting(bmAttributes):0x%xH",output.bmAttributes);
sprintf(tempbuff[7],"[8]Current(MaxPower):0x0%xH",output.MaxPower*2);
sprintf(tempbuff[8],"**Detail Information In Testing Frame**");
for(i=0;i<9;i++)
SendMessage (houtputlist, LB_ADDSTRING, 0, (LPARAM)tempbuff[i]);
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_CONFIGURATION_DESCRIPTOR,
NULL,
0,
&output2,
output.wTotalLength,
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox(hdlg, "Read Configuration Descriptor Failure!","Error",MB_ICONERROR);
else{
sprintf(tempbuff[0],"");
for (i=0;i<output.wTotalLength;i++) {
sprintf(tempbuff[1],"[%d]%xH ",i,output2[i]);
strcat(tempbuff[0],tempbuff[1]);
if(i%5==0 && i!=0) {
SendMessage (htestlist, LB_ADDSTRING, 0, (LPARAM)tempbuff[0]);
sprintf(tempbuff[0],"");
}
}
}
}
CloseHandle(hDevice);
Testing=FALSE;
return;
}
}
void GetInterfaceDescriptorTest(HWND hdlg)
{
if (Testing ==TRUE) {
MessageBox(hdlg, "Testing,Please Stop Current Test!","Error",MB_ICONINFORMATION);
return;
}
Testing=TRUE;
{
HANDLE hDevice=NULL;
HWND houtputlist;
HWND htestlist;
BOOL bResult = FALSE;
ULONG nBytes;
char DeviceName[MAX_DEVICE_NAME] = "";
char tempbuff[18][256];
unsigned char output2[200];
int i;
USB_CONFIGURATION_DESCRIPTOR output;
USB_INTERFACE_DESCRIPTOR *output0;
houtputlist = GetDlgItem (hdlg, IDC_OUTPUT_LIST);
htestlist = GetDlgItem (hdlg, IDC_TEST_LIST);
GetDlgItemText (hdlg, IDC_DEVICE_NAME, DeviceName, MAX_DEVICE_NAME);
if (UsbOpenDriver (&hDevice, DeviceName) != TRUE) {
MessageBox(hdlg, "USB Device Error,Please Reset!","Error",MB_ICONERROR);
Testing=FALSE;
return;
}
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_CONFIGURATION_DESCRIPTOR,
NULL,
0,
&output,
sizeof(USB_CONFIGURATION_DESCRIPTOR),
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox(hdlg, "Read Interface Descriptor Failure!","Error",MB_ICONERROR);
else {
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_CONFIGURATION_DESCRIPTOR,
NULL,
0,
&output2,
output.wTotalLength,
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox(hdlg, "Read Interface Descriptor Failure!","Error",MB_ICONERROR);
else {
SetDlgItemText (hdlg, IDC_INFORMATION, "Test-Interface Descrioptor:");
SendMessage (houtputlist, LB_RESETCONTENT, 0, 0);
SendMessage (htestlist, LB_RESETCONTENT, 0, 0);
output0=(USB_INTERFACE_DESCRIPTOR *)&output2[9];
sprintf(tempbuff[0],"[0]Length(bLength): 0x0%xH",output0->bLength);
sprintf(tempbuff[1],"[1]Type(bDescriptorType):0x0%xH",output0->bDescriptorType);
sprintf(tempbuff[2],"[2]Interface Number(bInterfaceNumber): 0x%0xH",output0->bInterfaceNumber);
sprintf(tempbuff[3],"[3]Alternate Setting(bAlternateSetting):0x0%xH",output0->bAlternateSetting);
sprintf(tempbuff[4],"[4]Endpoints Number(bNumEndpoints):0x0%xH",output0->bNumEndpoints);
sprintf(tempbuff[5],"[5]Class Code(bInterfaceClass):0x0%xH",output0->bInterfaceClass);
sprintf(tempbuff[6],"[6]SubClass Code(bInterfaceSubClass):0x%xH",output0->bInterfaceSubClass);
sprintf(tempbuff[7],"[7]Protocol Code(bInterfaceProtocol):0x0%xH",output0->bInterfaceProtocol);
sprintf(tempbuff[8],"[8]String Descriptor(iInterface):0x0%xH",output0->iInterface);
sprintf(tempbuff[9],"**Detail Information In Testing Frame**");
for(i=0;i<10;i++)
SendMessage (houtputlist, LB_ADDSTRING, 0, (LPARAM)tempbuff[i]);
sprintf(tempbuff[0],"");
for (i=0;i<output.wTotalLength;i++) {
sprintf(tempbuff[1],"[%d]%xH ",i,output2[i]);
strcat(tempbuff[0],tempbuff[1]);
if(i%5==0 && i!=0) {
SendMessage (htestlist, LB_ADDSTRING, 0, (LPARAM)tempbuff[0]);
sprintf(tempbuff[0],"");
}
}
}
}
CloseHandle(hDevice);
Testing=FALSE;
return;
}
}
void GetEndPointDescriptorTest(HWND hdlg)
{
if (Testing ==TRUE) {
MessageBox(hdlg, "Testing,Please Stop Current Test!","Error",MB_ICONINFORMATION);
return;
}
Testing=TRUE;
{
HANDLE hDevice=NULL;
HWND houtputlist;
HWND htestlist;
BOOL bResult = FALSE;
ULONG nBytes;
char DeviceName[MAX_DEVICE_NAME] = "";
char tempbuff[18][256];
unsigned char output2[200];
int i,j;
USB_CONFIGURATION_DESCRIPTOR output;
USB_ENDPOINT_DESCRIPTOR *output0;
houtputlist = GetDlgItem (hdlg, IDC_OUTPUT_LIST);
htestlist = GetDlgItem (hdlg, IDC_TEST_LIST);
GetDlgItemText (hdlg, IDC_DEVICE_NAME, DeviceName, MAX_DEVICE_NAME);
if (UsbOpenDriver (&hDevice, DeviceName) != TRUE) {
MessageBox(hdlg, "USB Device Error,Please Reset!","Error",MB_ICONERROR);
Testing=FALSE;
return;
}
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_CONFIGURATION_DESCRIPTOR,
NULL,
0,
&output,
sizeof(USB_CONFIGURATION_DESCRIPTOR),
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox(hdlg, "Read Endpoint Descriptor Failure!","Error",MB_ICONERROR);
else {
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_CONFIGURATION_DESCRIPTOR,
NULL,
0,
&output2,
output.wTotalLength,
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox(hdlg, "Read Endpoint Descriptor Failure!","Error",MB_ICONERROR);
else {
SetDlgItemText (hdlg, IDC_INFORMATION, "Test-Endpoint Descrioptor:");
SendMessage (houtputlist, LB_RESETCONTENT, 0, 0);
SendMessage (htestlist, LB_RESETCONTENT, 0, 0);
for (i=0;i<4;i++) {
output0=(USB_ENDPOINT_DESCRIPTOR *)&output2[18+i*7];
sprintf(tempbuff[0],"Endpoint[%d]:",i+1);
sprintf(tempbuff[1],"[0]Length(bLength): 0x0%xH",output0->bLength);
sprintf(tempbuff[2],"[1]Type(bDescriptorType):0x0%xH",output0->bDescriptorType);
sprintf(tempbuff[3],"[2]Address(bEndpointAddress): 0x%0xH",output0->bEndpointAddress);
sprintf(tempbuff[4],"[3]Transfer Type(bmAttributes):0x0%xH",output0->bmAttributes);
sprintf(tempbuff[5],"[4]Packet Size(wMaxPacketSize):0x0%xH",output0->wMaxPacketSize);
sprintf(tempbuff[6],"[5]Interval(bInterval):0x0%xH",output0->bInterval);
for(j=0;j<7;j++)
SendMessage (houtputlist, LB_ADDSTRING, 0, (LPARAM)tempbuff[j]);
}
sprintf(tempbuff[0],"**Detail Information In Testing Frame**");
SendMessage (houtputlist, LB_ADDSTRING, 0, (LPARAM)tempbuff[0]);
sprintf(tempbuff[0],"");
for (i=0;i<output.wTotalLength;i++) {
sprintf(tempbuff[1],"[%d]%xH ",i,output2[i]);
strcat(tempbuff[0],tempbuff[1]);
if(i%5==0 && i!=0) {
SendMessage (htestlist, LB_ADDSTRING, 0, (LPARAM)tempbuff[0]);
sprintf(tempbuff[0],"");
}
}
}
}
CloseHandle(hDevice);
Testing=FALSE;
return;
}
}
void GetStringDescriptorTest(HWND hdlg)
{
if (Testing ==TRUE) {
MessageBox(hdlg, "Testing,Please Stop Current Test!","Error",MB_ICONINFORMATION);
return;
}
Testing=TRUE;
{
HANDLE hDevice=NULL;
HWND houtputlist;
HWND htestlist;
BOOL bResult = FALSE;
ULONG nBytes;
char DeviceName[MAX_DEVICE_NAME] = "";
char tempbuff[18][256];
int i;
char output0[50];
GET_STRING_DESCRIPTOR_IN input;
USB_STRING_DESCRIPTOR output;
houtputlist = GetDlgItem (hdlg, IDC_OUTPUT_LIST);
htestlist = GetDlgItem (hdlg, IDC_TEST_LIST);
GetDlgItemText (hdlg, IDC_DEVICE_NAME, DeviceName, MAX_DEVICE_NAME);
if (UsbOpenDriver (&hDevice, DeviceName) != TRUE) {
MessageBox(hdlg, "USB Device Error,Please Reset!","Error",MB_ICONERROR);
Testing=FALSE;
return;
}
input.Index=0;
input.LanguageId=0;
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_STRING_DESCRIPTOR,
&input,
sizeof(GET_STRING_DESCRIPTOR_IN),
&output,
4,
&nBytes,
NULL);
if (bResult!=TRUE) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -