阅读:1256回复:1
请教usb板与主机通讯的问题,给高分!
各位大侠,请教个问题,我的板子是89c52+d12,大批量向主机传输数据是采用管道2。但传输一段时间后就会出现deviceiocontrol失败的消息,请问是怎么回事情啊,这部分程序如下:UINT ReadPipe(void * pParam)
{ char temp[80]; unsigned int i; BOOLEAN bResult = FALSE; ULONG nBytes = 0; struct CThreadParam * threadParam; CXugy03Dlg * testDlg; HANDLE hFile,hDevice; DWORD time0, time1; IO_BLOCK ioBlock; IO_REQUEST ioRequest; threadParam = (struct CThreadParam *) pParam; threadParam->bInThread = FALSE; testDlg = threadParam->testDlg; threadParam ->bUpdate = FALSE; hFile = open_file(threadParam->pipe_name); if(hFile == INVALID_HANDLE_VALUE) { strcpy(temp,\"open_file打开失败 \"); strcat(temp,threadParam->pipe_name); testDlg->MessageBox(temp, \" ReadPipe err notice:\",MB_OK); testDlg->m_InStartBtn.EnableWindow(TRUE); testDlg->m_InStopBtn.EnableWindow(FALSE); return 0; } hDevice = open_dev(); if (hDevice == INVALID_HANDLE_VALUE) { CloseHandle(hFile); strcpy(temp,\"open_dev打开失败 \"); strcat(temp,threadParam->pipe_name); testDlg->MessageBox(temp, \" ReadPipe err notice:\",MB_OK); testDlg->m_InStartBtn.EnableWindow(TRUE); testDlg->m_InStopBtn.EnableWindow(FALSE); return 0; } threadParam->pcIoBuffer = (unsigned char *) malloc (threadParam->uiLength+16); if(threadParam->pcIoBuffer == NULL) { testDlg->MessageBox(\"内存不够\", \"ReadPipe:\", MB_ICONSTOP); testDlg->EndDialog(0); return 0; } threadParam->ulCount =0; threadParam->total_time = 0; threadParam->max_rate = 0; threadParam->cur_rate = 0; if(hFile != INVALID_HANDLE_VALUE) { threadParam->bInThread = TRUE; do { Sleep(7); //10:163k; 5:202k; 6:226k;7:241 ioRequest.uAddressL = 0; ioRequest.bAddressH = 0; ioRequest.uSize = threadParam->uiLength; ioRequest.bCommand = 0x81; //start read ioBlock.uOffset = 0; ioBlock.uLength = sizeof(IO_REQUEST); ioBlock.pbyData = (PUCHAR)&ioRequest; ioBlock.uIndex = SETUP_DMA_REQUEST; bResult = DeviceIoControl(hDevice, IOCTL_WRITE_REGISTERS, (PVOID)&ioBlock, sizeof(IO_BLOCK), NULL, 0, &nBytes, NULL); if(!bResult) { threadParam->bInThread = FALSE; strcpy(temp,\"DeviceIoControl 失败 \"); strcat(temp,threadParam->pipe_name); testDlg->MessageBox(temp, \" ReadPipe err notice:\",MB_OK); break; } time0 = timeGetTime(); bResult = ReadFile(hFile, threadParam->pcIoBuffer, threadParam->uiLength, &nBytes, NULL); // threadParam->ulCount +=nBytes; time1 = timeGetTime(); if(!bResult) { DeviceIoControl(hFile, IOCTL_D12_RESET_PIPE, 0, 0, 0, 0, &nBytes, NULL); threadParam->bInThread = FALSE; strcpy(temp,\"ReadFile失败 \"); strcat(temp,threadParam->pipe_name); testDlg->MessageBox(temp, \" ReadPipe err notice:\",MB_OK); break; } else { for(i=0;i<threadParam->uiLength;i++) threadParam->ulData=* (threadParam->pcIoBuffer+i); threadParam->ulCount+=nBytes; if (time0!=time1) { threadParam->cur_rate = (nBytes*1000)/(time1-time0); if(threadParam->cur_rate > threadParam->max_rate) { threadParam->max_rate = threadParam->cur_rate; } threadParam->total_time += (time1 - time0 ); threadParam->bUpdate = TRUE; } else { if (nBytes>0) { threadParam->cur_rate = (nBytes*1000)/1; if(threadParam->cur_rate > threadParam->max_rate) { threadParam->max_rate = threadParam->cur_rate; } threadParam->total_time += (time1-time0); threadParam->bUpdate = TRUE; // time2 = timeGetTime(); } } }//end if(!bRequest),else } while(threadParam->bInThread == TRUE); } //end if(hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); CloseHandle(hDevice); free(threadParam->pcIoBuffer); threadParam->pcIoBuffer = NULL; threadParam->bInThread = FALSE; testDlg->m_InStartBtn.EnableWindow(TRUE); testDlg->m_InStopBtn.EnableWindow(FALSE); return 0; } |
|
沙发#
发布于:2003-01-18 10:46
Please modify USB firmware and set host\'s process/thread priority higher.
|
|
|