📄 usbapp.c
字号:
MessageBox(hdlg, "Read String Descriptor Failure!","Error",MB_ICONERROR);
Testing=FALSE;
return;
}
else {
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_STRING_DESCRIPTOR,
&input,
sizeof(GET_STRING_DESCRIPTOR_IN),
&output0,
output.bLength,
&nBytes,
NULL);
if (bResult!=TRUE) {
MessageBox(hdlg, "Read String Descriptor Failure!","Error",MB_ICONERROR);
Testing=FALSE;
return;
}
else {
SetDlgItemText (hdlg, IDC_INFORMATION, "Test-String Descrioptor:");
SendMessage (houtputlist, LB_RESETCONTENT, 0, 0);
SendMessage (htestlist, LB_RESETCONTENT, 0, 0);
sprintf(tempbuff[0],"String Descriptor[0]:");
sprintf(tempbuff[1],"[0]Length(bLength): 0x%xH",output0[0]);
sprintf(tempbuff[2],"[1]Type(bDescriptorType):0x0%xH",output0[1]);
sprintf(tempbuff[3],"[2]String(bString):");
for (i=0;i<output.bLength-2;i++) {
sprintf(tempbuff[4],"0%d",output0[i+2]);
strcat(tempbuff[3],tempbuff[4]);
}
for(i=0;i<4;i++)
SendMessage (houtputlist, LB_ADDSTRING, 0, (LPARAM)tempbuff[i]);
}
}
input.Index=1;
input.LanguageId=0;
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_STRING_DESCRIPTOR,
&input,
sizeof(GET_STRING_DESCRIPTOR_IN),
&output,
4,
&nBytes,
NULL);
if (bResult!=TRUE) {
MessageBox(hdlg, "Read String Descriptor Failure!","Error",MB_ICONERROR);
Testing=FALSE;
return;
}
else {
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_STRING_DESCRIPTOR,
&input,
sizeof(GET_STRING_DESCRIPTOR_IN),
&output0,
output.bLength,
&nBytes,
NULL);
if (bResult!=TRUE) {
MessageBox(hdlg, "Read String Descriptor Failure!","Error",MB_ICONERROR);
Testing=FALSE;
return;
}
else {
sprintf(tempbuff[0],"String Descriptor[1]:");
sprintf(tempbuff[1],"[0]Length(bLength): 0x%xH",output0[0]);
sprintf(tempbuff[2],"[1]Type(bDescriptorType):0x0%xH",output0[1]);
sprintf(tempbuff[3],"[2]String(bString):");
for (i=0;i<output.bLength-2;i++) {
sprintf(tempbuff[4],"%c",output0[i+2]);
strcat(tempbuff[3],tempbuff[4]);
}
for(i=0;i<4;i++)
SendMessage (houtputlist, LB_ADDSTRING, 0, (LPARAM)tempbuff[i]);
}
}
input.Index=2;
input.LanguageId=0;
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_STRING_DESCRIPTOR,
&input,
sizeof(GET_STRING_DESCRIPTOR_IN),
&output,
4,
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox(hdlg, "Read String Descriptor Failure!","Error",MB_ICONERROR);
else {
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_STRING_DESCRIPTOR,
&input,
sizeof(GET_STRING_DESCRIPTOR_IN),
&output0,
output.bLength,
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox(hdlg, "Read String Descriptor Failure!","Error",MB_ICONERROR);
else {
sprintf(tempbuff[0],"String Descriptor[2]:");
sprintf(tempbuff[1],"[0]Length(bLength): 0x%xH",output0[0]);
sprintf(tempbuff[2],"[1]Type(bDescriptorType):0x0%xH",output0[1]);
sprintf(tempbuff[3],"[2]String(bString):");
for (i=0;i<output.bLength-2;i++) {
sprintf(tempbuff[4],"%c",output0[i+2]);
strcat(tempbuff[3],tempbuff[4]);
}
for(i=0;i<4;i++)
SendMessage (houtputlist, LB_ADDSTRING, 0, (LPARAM)tempbuff[i]);
}
}
CloseHandle(hDevice);
Testing=FALSE;
return;
}
}
void GetFrameNumber(HWND hdlg)
{
if (Testing ==TRUE) {
MessageBox(hdlg, "Testing,Please Stop Current Test!","Error",MB_ICONINFORMATION);
return;
}
Testing=TRUE;
{
HANDLE hDevice=NULL;
HWND htestlist;
BOOL bResult = FALSE;
ULONG nBytes;
char DeviceName[MAX_DEVICE_NAME] = "";
char tempbuff[256];
unsigned long output;
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_CURRENT_FRAME_NUMBER,
NULL,
0,
&output,
sizeof(unsigned long),
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox(hdlg, "Read Frame Number Failure!","Error",MB_ICONERROR);
else {
SendMessage (htestlist, LB_RESETCONTENT, 0, 0);
sprintf(tempbuff,"Frame Number:%d",output);
SendMessage (htestlist, LB_ADDSTRING, 0, (LPARAM)tempbuff);
}
CloseHandle(hDevice);
Testing=FALSE;
return;
}
}
void Usb8051Reset(HWND hdlg)
{
if (Testing ==TRUE) {
MessageBox(hdlg, "Testing,Please Stop Current Test!","Error",MB_ICONINFORMATION);
return;
}
Testing=TRUE;
{
HANDLE hDevice=NULL;
HWND htestlist;
BOOL bResult = FALSE;
ULONG nBytes;
char DeviceName[MAX_DEVICE_NAME] = "";
char tempbuff[256];
VENDOR_REQUEST_IN myRequest;
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;
}
myRequest.bRequest = 0xA0;
myRequest.wValue = 0xE600;
myRequest.wIndex = 0x00;
myRequest.wLength = 0x01;
myRequest.bData = 0;
myRequest.direction = 0x00;
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_VENDOR_REQUEST,
&myRequest,
sizeof(VENDOR_REQUEST_IN),
NULL,
0,
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox(hdlg, "Reset 8051 Failure!","Error",MB_ICONERROR);
else {
SendMessage (htestlist, LB_RESETCONTENT, 0, 0);
sprintf(tempbuff,"Reset 8051 Success!");
SendMessage (htestlist, LB_ADDSTRING, 0, (LPARAM)tempbuff);
}
CloseHandle(hDevice);
Testing=FALSE;
return;
}
}
void Usb8051Hold(HWND hdlg)
{
if (Testing ==TRUE) {
MessageBox(hdlg, "Testing,Please Stop Current Test!","Error",MB_ICONINFORMATION);
return;
}
Testing=TRUE;
{
HANDLE hDevice=NULL;
HWND htestlist;
BOOL bResult = FALSE;
ULONG nBytes;
char DeviceName[MAX_DEVICE_NAME] = "";
char tempbuff[256];
VENDOR_REQUEST_IN myRequest;
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;
}
myRequest.bRequest = 0xA0;
myRequest.wValue = 0xE600;
myRequest.wIndex = 0x00;
myRequest.wLength = 0x01;
myRequest.bData = 1;
myRequest.direction = 0x00;
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_VENDOR_REQUEST,
&myRequest,
sizeof(VENDOR_REQUEST_IN),
NULL,
0,
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox(hdlg, "Lock 8051 Failure!","Error",MB_ICONERROR);
else {
SendMessage (htestlist, LB_RESETCONTENT, 0, 0);
sprintf(tempbuff,"Lock 8051 Success!");
SendMessage (htestlist, LB_ADDSTRING, 0, (LPARAM)tempbuff);
}
CloseHandle(hDevice);
Testing=FALSE;
return;
}
}
void Download8051File(HWND hdlg)
{
if (Testing ==TRUE) {
MessageBox(hdlg, "Testing,Please Stop Current Test!","Error",MB_ICONINFORMATION);
return;
}
Testing=TRUE;
{
HANDLE hDevice=NULL;
HWND htestlist;
HWND houtlist;
BOOL bResult = FALSE;
ULONG nBytes;
char DeviceName[MAX_DEVICE_NAME] = "";
char tempbuff[256];
char temp[256];
char DownloadFilename[16];
FILE *fp;
unsigned char buffer[MAX_FILE_SIZE];
int numreadfile = 0;
int i;
htestlist = GetDlgItem (hdlg, IDC_TEST_LIST);
houtlist = GetDlgItem (hdlg, IDC_OUTPUT_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;
}
GetDlgItemText (hdlg, IDC_DOWNLOAD_FILENAME, DownloadFilename, 16);
if ((fp = fopen(DownloadFilename,"rb")) == NULL) {
MessageBox(hdlg, "Not Find This File!","Error",MB_ICONERROR);
Testing=FALSE;
return;
}
SetDlgItemText (hdlg, IDC_INFORMATION, "Download 8051 Program:");
SendMessage (houtlist, LB_RESETCONTENT, 0, 0);
SendMessage (htestlist, LB_RESETCONTENT, 0, 0);
numreadfile = fread(buffer,sizeof(unsigned char),MAX_FILE_SIZE,fp);
sprintf (tempbuff, "File%dB",numreadfile);
SendMessage (houtlist, LB_ADDSTRING, 0, (LPARAM)tempbuff);
fclose(fp);
sprintf (tempbuff, "");
for (i=0;i<numreadfile;i++) {
sprintf(temp,"[%d]%x ",i,buffer[i]);
strcat(tempbuff,temp);
if(i%5==0 && i!=0) {
SendMessage (htestlist, LB_ADDSTRING, 0, (LPARAM)tempbuff);
sprintf(tempbuff,"");
}
}
SendMessage (htestlist, LB_ADDSTRING, 0, (LPARAM)tempbuff);
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_ANCHOR_DOWNLOAD,
buffer,
numreadfile,
NULL,
0,
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox(hdlg, "Download 8051 Program Failure!","Error",MB_ICONERROR);
else {
sprintf(tempbuff,"Download 8051 Program Success!");
SendMessage (houtlist, LB_ADDSTRING, 0, (LPARAM)tempbuff);
sprintf(tempbuff,"**Detail Inforamtion In Testing Frame!**");
}
CloseHandle(hDevice);
Testing=FALSE;
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -