-
Could not lock target memory
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
-
Which compiler and OS are you using? Not all OSs allow you to access memory directly in this manner. Also, can you run the code in a debugger and see which line causes this error?
Danny Kalev
-
Thanks for your reply Danny,
I am using Visual Studio 2008, Windows XP.
I did run the code in Debugger mode and every time when I am in this for loop
Code:
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);
}
The message is adding up to the previous same message on dos screen as
ReadArea:Could not lock target memory.
-
I would first look into the following memset call:
Code:
memset(pHostBuffFrame + attr.dwWidth * attr.dwHeight * attr.dwBytesPerPixel,0,
attr.dwWidth * (attr.dwHeight-AcquiredDy) * attr.dwBytesPerPixel);
What's the type of pHosBuffRame? I assume it's unsigned char (or BYTE). If so, you want to break this complex expressions into individual steps that can be debugged easily. First, calculate the correct address:
Code:
char * ptemp=pHostBuffFrame + (attr.dwWidth * attr.dwHeight * attr.dwBytesPerPixel);
Then calculate the sizeof of the buffer being reset:
Code:
size_t reset_size=attr.dwWidth * (attr.dwHeight-AcquiredDy) * attr.dwBytesPerPixel;
Once you've verified that both temps have the right values, call memset.
In the meantime, you can comment out the memset call and see if it stops the crashes (the program shouldn't produce correct output but the aim is to locate the line that causes the crash).
Danny Kalev
-
I guess that was the problem with memory allocation with m_pixarrbuf
so I changed it from
Code:
m_pixarrbuf->AllocateBuffer(num*m_nAnalogChannel);
to
Code:
m_pixarrbuf = (BYTE*)GlobalAllocPtr(GMEM_FIXED,attr.dwWidth * attr.dwHeight * attr.dwBytesPerPixel * FRAMES_IN_HOSTBUFF);
also some other minor changes related to this.
I am able to access the data now.
Thanks
Similar Threads
-
By computeruser in forum Architecture and Design
Replies: 1
Last Post: 07-08-2008, 02:22 AM
-
By Ron Weller in forum VB Classic
Replies: 0
Last Post: 05-17-2008, 06:22 AM
-
Replies: 11
Last Post: 11-16-2007, 12:23 PM
-
By Geoff Lingham in forum VB Classic
Replies: 5
Last Post: 04-22-2002, 05:46 PM
-
Replies: 0
Last Post: 11-02-2001, 04:22 PM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks