Hi,
This is my first post on this discussion group. I am writing a code to collect data from a Camera using a Frame Grabber Board.
After the camera has been initialized and when I click on grab icon of my GUI with the code
Code:UINT CDAQControl::DAQContThreadProc(LPVOID param) { CDAQControl* daq = (CDAQControl*)param; DWORD object; BOOL bResult; for(;;) { if(!daq->m_PA->DAQScan(1)) { // daq->_lock.Unlock(); CError::PrintErrMsg(ERR_SCAN); break; }//end if bResult = daq->m_PA->ScanDone(); object = ::WaitForSingleObject(daq->_hStop,0); if(object != WAIT_OBJECT_0 && bResult) { daq->m_PA->PostProcessing(1); //add file processing code daq->Notify(CONTMODE); } else break; } daq->_lock.Unlock(); ::PostMessage(ThisApp->m_pMainWnd->GetSafeHwnd(),USER_UPDATE_TOOLBAR,0,0); return 0; }//end daqcontthreadproc
Code:int C975010TC::DAQScan(int num) { if(m_nSamples != num) { m_pixarrbuf->AllocateBuffer(num*m_nAnalogChannel); m_nSamples = num; } m_GrabID = m_pCamera->Grab(0,m_pixarrbuf->GetBuffer(), FRAMES_IN_HOSTBUFF); return true; }
Code:BOOL C975010TC::ScanDone() { DWORD AcquiredDy; DWORD last_time,old_time; DWORD deltaTime; DWORD totalTime; GRAB_EXT_ATTR ExtendedAttr; CAM_ATTR attr; totalTime = 0; m_maxTime = 0; m_minTime = 1000; m_avgTime = 0; last_time = 0; m_pCamera->GetAttr(&attr); BYTE *pHostBuffFrame; int iSeqNum,iCount; for (iCount=0;iCount<attr.dwHeight;iCount++) //Height=64,Width=1280 { // Wait for a new frame to become available, and lock it // so it can't be overwritten while we are processing and then displaying it if (((iSeqNum=m_pCamera->GrabWaitFrameEx(m_GrabID,&pHostBuffFrame,IFC_WAIT_NEWER_FRAME,500,TRUE,&AcquiredDy,NULL,&ExtendedAttr)) >= 0)) { old_time = last_time; m_pCap->m_os->GetSystimeMillisecs(); if (iCount > 0) { deltaTime = last_time-old_time; totalTime += deltaTime; if (deltaTime > m_maxTime) m_maxTime = deltaTime; if (deltaTime < m_minTime) m_minTime = deltaTime; } if (AcquiredDy < attr.dwHeight) { memset(pHostBuffFrame + attr.dwWidth * attr.dwHeight * attr.dwBytesPerPixel,0, attr.dwWidth * (attr.dwHeight-AcquiredDy) * attr.dwBytesPerPixel); } // Release the frame back into the active circular acquistion buffer m_pCamera->GrabRelease(m_GrabID,iSeqNum); if (AcquiredDy < attr.dwHeight) { CError::PrintErrMsg(IDS_ERR_IMAGE_ACQUIRED); return false; } } Sleep(1); } if (iCount > 1) m_avgTime = totalTime / (iCount-1); return true; }
Code:int C975010TC::GetScanData(short *pixarr) { if(!pixarr || !m_pixarrbuf) return false; ReorderingBuf(pixarr, (short *)m_pixarrbuf->GetBuffer()); return true; }
Code:void C975010TC::ReorderingBuf(short* dest, short *src) { int i,j,m,joffset, koffset, moffset, noffset, frames; frames = m_nSamples/m_nPixels; joffset = 0; koffset = 0; for(i=0; i<frames; i++) // loop through number of requested scans { moffset = 0; for(m=0;m<m_nAnalogChannel;m++) { noffset = joffset; for(j=0;j<m_nPixels;j++) { dest[m_pixelmap[j]+koffset] = src[noffset+moffset]; noffset += m_nAnalogChannel; } moffset++; koffset += m_nPixels; } joffset += m_nPixels*m_nAnalogChannel; } }
When I run this code I am getting a message on DOS screen repeatedly
ReadArea:Could not lock target memory.
Can someone please help me in solving this problem.
Thank You


Reply With Quote



Bookmarks