阅读:869回复:0
求教!
我做的是USB接口数据采集器,是利用周立功的D12开发板来开发的,我分别做了发送数据的函数和接收数据的函数,下面是这两个函数的实现,而对应的消息函数OnReceive()和OnSend()和周立功的代码写的相似,但发送函数应该没有问题,接收就收不到,请高手们帮我看一下,先谢啦
UINT Receive(void*pParam) { char temp[80]; ULONG nBytes ; BOOLEAN bResult=FALSE; struct CThreadParam * threadParam; CD12TestDlg* testDlg; HANDLE hFile, hDevice; // unsigned char *iobuf; 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, \"驱动程序打开失败! 不能从 \"); strcat(temp, threadParam->pipe_name); strcat(temp, \" 中读出数据。\"); testDlg->MessageBox((LPCSTR)temp, \"测试错误\"); return 0; } hDevice = open_dev(); threadParam->uiLength=testDlg->m_ed1.GetLength(); threadParam->pcIoBuffer = (unsigned char *)malloc (threadParam->uiLength + 16); 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_READ_REGISTERS,(PVOID)&ioBlock,sizeof(IO_BLOCK),threadParam->pcIoBuffer,threadParam->uiLength,&nBytes,NULL); //bResult = DeviceIoControl(hDevice,IOCTL_READ_REGISTERS,(PVOID)&ioBlock,sizeof(IO_BLOCK),NULL,0,&nBytes,NULL); //bResult = ReadFile(hFile,threadParam->pcIoBuffer,threadParam->uiLength,&nBytes,NULL); for(int i=0;i<testDlg->m_ed1.GetLength();i++) { testDlg->m_ed2+=threadParam->pcIoBuffer; // threadParam->testDlg->m_ed1.Empty(); } return 0; } UINT Send(void*pParam) { // TODO: Add your control notification handler code here char temp[80]; ULONG nBytes ; BOOLEAN bResult=FALSE; struct CThreadParam * threadParam; CD12TestDlg* testDlg; HANDLE hFile, hDevice; // unsigned char *iobuf; 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, \"驱动程序打开失败! 不能从 \"); strcat(temp, threadParam->pipe_name); strcat(temp, \" 中读出数据。\"); testDlg->MessageBox((LPCSTR)temp, \"测试错误\"); return 0; } hDevice = open_dev(); threadParam->pcIoBuffer = (unsigned char *)malloc (threadParam->uiLength + 16); threadParam->uiLength=testDlg->m_ed1.GetLength(); for(int i=0;i<threadParam->testDlg->m_ed1.GetLength();i++) { threadParam->pcIoBuffer=threadParam->testDlg->m_ed1.GetAt(i); } ioRequest.uAddressL = 0; ioRequest.bAddressH = 0; ioRequest.uSize = threadParam->uiLength; ioRequest.bCommand = 0x80; //start, write 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),threadParam->pcIoBuffer,threadParam->testDlg->m_ed1.GetLength(),&nBytes, NULL); //bResult = WriteFile(hFile,threadParam->pcIoBuffer,threadParam->uiLength,&nBytes,NULL); return 0; } |
|