From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Buffer is NULL When Using Ring Mode Acquisition In C

I put the data acquisition in a loop,and there is a error check part to determine whether the buffer is empty or not.

Error always occurs that buffer is always empty,what's worng with my code?

Here's part of my code:

 

void AcquireThread::Acquire(void)
{
sprintf_s(intfName, "img0");//img0 Basler///img3 Atmel
imgInterfaceOpen(intfName, &Iid);
imgSessionOpen(Iid, &Sid);
AcqWinWidth = globalOptions->IMAGEWIDTH;
AcqWinHeight = globalOptions->IMAGEHEIGHT;

imgSetAttribute2(Sid, IMG_ATTR_ROI_WIDTH, AcqWinWidth);
imgSetAttribute2(Sid, IMG_ATTR_ROI_HEIGHT, AcqWinHeight);
imgSetCameraAttributeNumeric(Sid, "Exposure Time", 12);


for (int i = 0; i<NUM_RING_BUFFERS; i++)
ImaqBuffers[i] = NULL;

// Setup and launch the ring acquisition
imgRingSetup(Sid, NUM_RING_BUFFERS, (void**)ImaqBuffers, 0, TRUE);
uInt32 currBufNum;

//Infinite Loop
//Temporarily we have incorporated an infinite loop. Stop the program execution by closing the program.
//Threads can also be suspended and resumed via the start/stop buttons
while (true)
{
DataFramePos = RawData; //Reset the DataFramePos pointer to the beginning, pointed to by RawData
if (globalOptions->volumeReady < 1)
{
for (int framenum = 0; framenum < globalOptions->NumFramesPerVol; framenum++)
{
if (breakLoop)
break;

imgSessionExamineBuffer2(Sid, IMG_CURRENT_BUFFER, &currBufNum, (void**)&ImaqBuffer);
if (!ImaqBuffer) { //Check if Camera is on and properly connected   
printf("ERROR: Camera is either off, or miscommunication with framegrabber.\n Exiting Program...\n");
Sleep(2000);
exit(1);
}

memcpy(DataFramePos, ImaqBuffer, AcqWinHeight*AcqWinWidth*sizeof(unsigned short));
DataFramePos = &DataFramePos[AcqWinHeight*AcqWinWidth];
imgSessionReleaseBuffer(Sid);


}

if (breakLoop) {
breakLoop = false; //Reset the breakLoop flag after each time
}
else {
globalOptions->volumeReady++;
}
}
else
{
if (globalOptions->saveVolumeflag == true)
{
fwrite(DataFramePos, 2, AcqWinWidth*AcqWinHeight*globalOptions->NumFramesPerVol, globalOptions->fid);
globalOptions->saveVolumeflag = false;
fclose(globalOptions->fid);
printf("VolumeData Has Been Saved...\n");

}
globalOptions->volumeReady = 0;
}
}
}

 

  P.S:I can connect my camera using NIMAX and Labview.

0 Kudos
Message 1 of 1
(4,261 Views)