阅读:2037回复:2
在线求助,应用程序MFC向设备端点发送数据?
我编写一下MFC程序向USB设备端点发送数据,但是没有任何发应。
设备端点枚举已经成功,就是发送数据时没有反应, 向设备端点发送数据的程序如下: void CNCAPPLICATIONDlg::OnSendEp3() { // TODO: Add your control notification handler code here BOOL Result; UINT LastError; CString Str; if(MyDevFound==FALSE) { SetDlgItemText(IDC_Information0,"NC Device is not connected"); return; } if(hMyDevHandle==INVALID_HANDLE_VALUE) { SetDlgItemText(IDC_Information0,"Invalid device handler, fail to open device"); return; } if(Ep1DataInSending==TRUE) { SetDlgItemText(IDC_Information1, "Ep3 is busy"); return; } SetDlgItemText(IDC_Information1,"Ep3 is sending data"); Str="C:\\NCDATA\\DATA.TXT"; HANDLE OpenFile=CreateFile(Str,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0); if ( OpenFile == (HANDLE)HFILE_ERROR ) { AfxMessageBox( "Fail to open file" ); return; } DWORD filesize=GetFileSize(OpenFile,NULL); DWORD writesize;; ReadFile(OpenFile,Ep3WriteBuffer,filesize,&writesize,NULL); Ep3DataInSending=TRUE; Result=DeviceIoControl(hMyDevHandle, EP3_WRITE, Ep3WriteBuffer, filesize, NULL, 0, NULL, &Ep3WriteOverlapped); if(Result==FALSE) { LastError=GetLastError(); if((LastError==ERROR_IO_PENDING)||(LastError==ERROR_SUCCESS)) { return; } else { Ep3DataInSending=FALSE; SetDlgItemText(IDC_Information1,"Error EP1 in sending"); return; } } else { Ep3DataInSending=FALSE; SetDlgItemText(IDC_Information1,"Finsishing sending files"); return; } } 欢迎加我QQ讨论:602283025 |
|
沙发#
发布于:2010-04-26 19:14
首先确定此USB驱动是否支持用户对端点的读写。EP3_WRITE是不是有效的命令,然后就是Buffer是否设置正确。
|
|
|
板凳#
发布于:2010-04-27 22:15
驱动是我自己写的,支持写端点,下位机端点三是也输出端点,就是不知道为什么数据一发就沉到海底了。
|
|