阅读:1816回复:0
68013 bulkloop程序出现问题,多谢指正
我把程序改的特别简单,只是定义一个in端点,然后传输数据,固件程序是一直传送in数据,不接收out数据,
在使用EZ-USB Control Panel时,按bulk/int按钮可以接受数据,但是用我的程序时,虽然能打开设备, 但是一直显示error : read failed.请高手指教,多谢 void TestThread( LPVOID lpParameter ) // thread data { HWND hDlg = (HWND) lpParameter; HWND hOutputBox; HANDLE hInDevice = NULL; HANDLE hOutDevice = NULL; PUCHAR inBuffer = NULL; PUCHAR outBuffer = NULL; ULONG MaxTransferSize, CurrentTransferSize; ULONG InPipeNum; ULONG OutPipeNum; HANDLE ReadCompleteEvent; HANDLE WriteCompleteEvent; char DeviceName[MAX_DRIVER_NAME] = ""; ULONG i,j=0; BULK_TRANSFER_CONTROL inBulkControl,outBulkControl; THREAD_CONTROL inThreadControl,outThreadControl; char tempbuff[256]; hOutputBox = GetDlgItem (hDlg, IDC_OUTPUT_BOX); // // get the device handle // GetDlgItemText (hDlg, IDC_DEVICENAME, DeviceName, MAX_DRIVER_NAME);//获取设备名 if (bOpenDriver (&hInDevice, DeviceName) != TRUE)//open the device { SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Failed to Open Device"); return; } if (bOpenDriver (&hOutDevice, DeviceName) != TRUE) { SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Failed to Open Device"); return; } // // get the pipe numbers for the transfer // InPipeNum=6; OutPipeNum=2; // // get the transfer size and allocate the transfer buffers // MaxTransferSize = GetDlgItemInt(hDlg,IDC_TRANSFERSIZE,NULL,FALSE);//64 CurrentTransferSize = MaxTransferSize; outBuffer = malloc(MaxTransferSize); inBuffer = malloc(MaxTransferSize); // // Set up our event objects // ReadCompleteEvent = CreateEvent(NULL,TRUE,FALSE,NULL); //创建或打开一个命名的或无名的事件对象 WriteCompleteEvent = CreateEvent(NULL,TRUE,FALSE,NULL); // // main test loop // while (!gStopTest) { j++; // initialize the out buffer for (i=0;i<CurrentTransferSize;i++) outBuffer = (UCHAR) i+1; // initialize the in buffer memset(inBuffer, 0, MaxTransferSize); // initialize data structures for the read thread inBulkControl.pipeNum = InPipeNum; inThreadControl.hDevice = hInDevice; inThreadControl.Ioctl = IOCTL_EZUSB_BULK_READ; inThreadControl.InBuffer = (PVOID)&inBulkControl; inThreadControl.InBufferSize = sizeof(BULK_TRANSFER_CONTROL); inThreadControl.OutBuffer = inBuffer; inThreadControl.OutBufferSize = 64; inThreadControl.completionEvent = ReadCompleteEvent; inThreadControl.status = FALSE; inThreadControl.BytesReturned = 0; _beginthread(TransferThread,0,&inThreadControl); WaitForSingleObject(ReadCompleteEvent,100); //infinite也不行 // if either the read or write failed, we want to stop the test if (gEndpointSelect != OUTONLY && !inThreadControl.status) SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Error: Read failed"); for(j=0;j<i;j++) { sprintf(tempbuff, "Error(%x):expected = 0x%x actual = 0x%x", j, outBuffer[j], inBuffer[j]); SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)tempbuff); } } CloseHandle(hInDevice); CloseHandle(hOutDevice); return; } |
|