为什么接收不到USB的数据,且打开的文件是空的?
这是我的代码,求指教!!!!!!! mfile.Open(_T("e:\\1.txt"), CFile::modeCreate);
mfile.Close();
XferThread = NULL; //线程禁止
USBDevice = new CCyUSBDevice(m_hWnd); // Create an instance of CCyUSBDevice
if (XferThread) { //如果线程已经开始
bLooping = false; //置线程循环标志为假
InEndpt->Abort();
InEndpt->Reset();
AfxMessageBox(_T("开始"));
//m_StartBtn.SetWindowText(_T("be start")); //开始按钮为“start”
}
else {
if(USBDevice->Open(0))
InEndpt = USBDevice->EndPointOf(0x02);
// Launch the looping thread (Calls XferLoop() function, above.)
//启动线程循环,调用xferloop函数
if (USBDevice->IsOpen()) { //如果USB设备已经打开且传输自己不为0
bLooping = true; //线程循环标志为真
AfxMessageBox(_T("开始读线程"));
XferThread = AfxBeginThread(XferLoop, this); //启动线程
AfxMessageBox(_T("结束"));
}
//m_StartBtn.SetWindowText(_T("读取结束"));
}
UINT XferLoop(LPVOID params) {
OVERLAPPED inOvLap;
CMFCApplication1Dlg *dlg = (CMFCApplication1Dlg *)params; //使该线程可访问CBulkLoopDlg类的所有公有成员
PUCHAR inData = new UCHAR[512];
CString str;
//ZeroMemory(inData, WINDOW_X*WINDOW_Y * 2); //存储从USB固件发来的数据
ZeroMemory(inData, 512);
inOvLap.hEvent = CreateEvent(NULL, false, false, L"CYUSB_IN");
bool success;
dlg->InEndpt->TimeOut = 2000;
for (; dlg->bLooping;) { //线程循环,直到循环标志blooping为假
LONG inlen;
//inlen = WINDOW_X*WINDOW_Y * 2;
inlen = 512;
UCHAR *inContext = dlg->InEndpt->BeginDataXfer(inData, inlen, &inOvLap);
dlg->InEndpt->WaitForXfer(&inOvLap, 1200);
success = dlg->InEndpt->FinishDataXfer(inData, inlen, &inOvLap, inContext);
if (success) {
mfile.Open(_T("e:\\1.txt"), CFile::modeWrite);
mfile.SeekToEnd();
mfile.Write(inData, inlen);
mfile.Close();;
}
if (!success)
dlg->bLooping = false;
}
CloseHandle(inOvLap.hEvent);
delete[] inData;
dlg->XferThread = NULL;
dlg->USBDevice->Close();
return true;
}