阅读:1700回复:3
可以打开设设备,并可以向下传数,启动线程也正确,但线程中调用deviceiocontrol 函数后,没有传回来值。
////可以打开设设备,并可以向下传数,启动线程也正确,但线程中调用deviceiocontrol 函数后,没有传回来值。
跟踪时InBuffer数据是错的。查了几遍都找不出错误。请高手指点下。高分相送。 部分程序 如下 : ////////////////////打开设备 BOOLEAN CUsbhostDlg::UsbOpenDriver (HANDLE *phDeviceHandle, PCHAR devname) { char completeDeviceName[64] = \"\"; char pcMsg[64] = \"\"; strcat (completeDeviceName,\"\\\\\\\\.\\\\\"); strcat (completeDeviceName,devname); *phDeviceHandle = CreateFile(completeDeviceName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (*phDeviceHandle == INVALID_HANDLE_VALUE) return (FALSE); else return (TRUE); } /////应用程序可以打开设备 void CUsbhostDlg::OnRunButton() { // TODO: Add your control notification handler code here // TODO: Add your control notification handler code here // TODO: Add your control notification handler code here // TODO: Add your control notification handler code here HANDLE hDevice = NULL; BOOLEAN bResult = FALSE; long AimPosition1[3]; float AimSpeed[3]; unsigned long input=3; ULONG nBytes; BULK_TRANSFER_CONTROL bulkControl; AimPosition1[0]=m_nAimPosition_du; AimPosition1[1]=m_nAimPosition_fen; AimPosition1[2]=m_fAimPosition_miao; if(g_KeepGoing) { MessageBox(\"请首先结束当前线程!\", \"错误\", MB_ICONERROR | MB_OK); return; } if (UsbOpenDriver (&hDevice, \"Ezusb-0\") != TRUE) { MessageBox(\"无效设备,请重试!\", \"错误\", MB_ICONERROR | MB_OK); return; } ///////////////////////////////////////////在调试环境下,跟踪到这里也正确,bResult =1,为True bulkControl.pipeNum = 2; bResult = DeviceIoControl (hDevice, IOCTL_EZUSB_BULK_WRITE, &bulkControl, sizeof(BULK_TRANSFER_CONTROL), AimPosition1, 3, ////////////数据个数 &nBytes, NULL); if (bResult != TRUE) { AfxMessageBox(\"发送位移失败!\"); CloseHandle(hDevice); return; } g_KeepGoing = true; if(_beginthread(ReceiveThreadFunction, 0, hDevice) < 0) //////线程可以启动。 { AfxMessageBox(\"启动接收数据线程失败!\"); } m_nCurrentPosition_du =nCurrentPosition_du; //把线程得到的位移给对应变量; 这里出现错误,三个。。值都没改变。 m_nCurrentPosition_fen =nCurrentPosition_fen; m_fCurrentPosition_miao=fCurrentPosition_miao; } void __cdecl ReceiveThreadFunction(HANDLE hDevice) /////////////////接收线程。 { BOOLEAN bResult = FALSE; ULONG nBytes; BULK_TRANSFER_CONTROL bulkControl; static unsigned long InBuffer[3]= int i=0; while(g_KeepGoing) { nBytes = 3; bulkControl.pipeNum = 4; // g_Transfering= FALSE; bResult = DeviceIoControl (hDevice, IOCTL_EZUSB_BULK_READ, &bulkControl, sizeof(BULK_TRANSFER_CONTROL), InBuffer, 3, &nBytes, NULL); if (bResult != TRUE) { AfxMessageBox(\"接收数据失败!\"); goto exit; } if (nBytes==3) { nCurrentPosition_du =InBuffer[0]; ////跟踪时InBuffer数据是错的。 nCurrentPosition_fen =InBuffer[1]; fCurrentPosition_miao=InBuffer[2]; } } exit: CloseHandle(hDevice); g_KeepGoing=false; _endthread(); } ////可以打开设设备,并可以向下传数,启动线程也正确,但线程中调用deviceiocontrol 函数后,没有传回来值。 跟踪时InBuffer数据是错的。查了几遍都找不出错误。请高手指点下。高分相送。 |
|
沙发#
发布于:2005-04-22 21:18
自己顶一下,高手过来帮下忙了。我快崩溃了,
|
|
板凳#
发布于:2005-04-23 14:45
可以接受一个数据了,估计是固件的问题。
|
|
地板#
发布于:2005-04-24 11:18
确实是你的固件问题,你的固件要配合你的驱动,2发,4收,在TD_POLL()中用自动指针吧2发的数据付给4,设置端点字节计数,
初始话要对 |
|