BioUsb-线程中读取数据至缓冲以及将缓冲数据保存在m_ObArray中

程序数据流程大致是;

1、  读取线程每隔一段时间从usb设备端点取出数据至缓冲区,并发送消息通知主程序“读取已完成”。

2、  主程序(WindowProc())通过pDoc->AddFrames(&(pIO->pInBuffer[0]),dwCurNum);将缓冲区数据保存至数组m_ObArray中。

 

1. 读取线程每隔一段时间从usb设备端点取出数据至缓冲区,并发送消息通知主程序“读取已完成”。

 

DWORD WINAPI ThreadExecute_Read(PVOID pContext) { •••• if(!ReadFile(pUSBAPI->stRead.hDevice, pUSBAPI->stRead.pInBuffer, pUSBAPI->stRead.dwInSize, pUSBAPI->stRead.lpBytesReturned, //本周期已读取的字节数 &olRead)) { } SendMessage(pUSBAPI->stRead.hTargetWnd, MSG_READ_COMPLETION, 0, (LPARAM)&pUSBAPI->stRead); ••• }

2. 主程序(WindowProc())通过pDoc->AddFrames(&(pIO->pInBuffer[0]),dwCurNum);将缓冲区数据保存至数组m_ObArray中。

消息处理函数:

LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { ••• DWORD dwCurNum = *(pIO->lpBytesReturned); ••• pDoc->AddFrames(&(pIO->pInBuffer[0]),dwCurNum); ••• }

 

 void CScanViewerDoc::AddFrames(PBYTE pData,int wNums) { SetModifiedFlag(TRUE); SetPathName("Bioscan.scv*"); for( int i = 0;i<wNums;i++) { CDataFrame * pDataFrame = new CDataFrame(); pDataFrame->AddData(pData + i * EP_PACKET_SIZE); m_ObArray.Add(pDataFrame); } } void CDataFrame::AddData(PBYTE pData) { // char bDotOrder[16] = {16,32,30,46,28,44,26,42,24,40,22,38,20,36,18,34}; if(!pData) return; int i; for (i=0;i<EP_PACKET_SIZE;i++) { m_bData[i] = pData[i]; } } class CDataFrame : public CObject { protected: DECLARE_SERIAL(CDataFrame) BYTE m_bData[EP_PACKET_SIZE];//20 public: CDataFrame() {}; void AddData(PBYTE pData); virtual void Serialize(CArchive& ar); };

你可能感兴趣的:(Class,winapi)