11-30-2014 04:19 AM
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.