void CameraOpen() { char name[256]; for (int i=0;;i++) { if (0 != imgInterfaceQueryNames(i, name)) break; dbgprintf("IMAQ interface: %s\n", name); } if (fastCMOS) CameraClose(); imgInterfaceOpen("img0", &ifid); imgSessionOpen(ifid, &session); fastCMOS = new FastCMOS(session); std::string info = fastCMOS->readInfo(); CameraConfigure(); int fps = fastCMOS->getFramerate().fps; dbgprintf("FPS: %d\n", fps); }
/** * gst_niimaqsrc_start: * src: #GstBaseSrc instance * * Open necessary resources * * Returns: TRUE on success */ static gboolean gst_niimaqsrc_start (GstBaseSrc * bsrc) { GstNiImaqSrc *src = GST_NIIMAQSRC (bsrc); Int32 rval; gint i; gst_niimaqsrc_reset (src); GST_LOG_OBJECT (src, "Opening IMAQ interface: %s", src->interface_name); /* open IMAQ interface */ rval = imgInterfaceOpen (src->interface_name, &(src->iid)); if (rval) { gst_niimaqsrc_report_imaq_error (rval); GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Failed to open IMAQ interface"), ("Failed to open camera interface %s", src->interface_name)); goto error; } GST_LOG_OBJECT (src, "Opening IMAQ session: %s", src->interface_name); /* open IMAQ session */ rval = imgSessionOpen (src->iid, &(src->sid)); if (rval) { gst_niimaqsrc_report_imaq_error (rval); GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Failed to open IMAQ session"), ("Failed to open IMAQ session %d", src->sid)); goto error; } /* Allow use of 1428 and other 32-bit DMA cards on 64-bit systems with greater than 3GB of memory. */ niimaquDisable32bitPhysMemLimitEnforcement (src->sid); GST_LOG_OBJECT (src, "Creating ring with %d buffers", src->bufsize); /* create array of pointers to give to IMAQ for creating internal buffers */ src->buflist = g_new (guint32 *, src->bufsize); src->times = g_new (GstClockTime, src->bufsize); for (i = 0; i < src->bufsize; i++) { src->buflist[i] = 0; src->times[i] = GST_CLOCK_TIME_NONE; } /* CAUTION: if this is ever changed to manually allocate memory, we must be careful about allocating 64-bit addresses, as some IMAQ cards don't support this, and can give a runtime error. See above call to niimaquDisable32bitPhysMemLimitEnforcement */ rval = imgRingSetup (src->sid, src->bufsize, (void **) (src->buflist), 0, FALSE); if (rval) { gst_niimaqsrc_report_imaq_error (rval); GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Failed to create ring buffer"), ("Failed to create ring buffer with %d buffers", src->bufsize)); goto error; } GST_LOG_OBJECT (src, "Registering callback functions"); rval = imgSessionWaitSignalAsync2 (src->sid, IMG_SIGNAL_STATUS, IMG_FRAME_START, IMG_SIGNAL_STATE_RISING, gst_niimaqsrc_frame_start_callback, src); rval |= imgSessionWaitSignalAsync2 (src->sid, IMG_SIGNAL_STATUS, IMG_AQ_IN_PROGRESS, IMG_SIGNAL_STATE_RISING, gst_niimaqsrc_aq_in_progress_callback, src); rval |= imgSessionWaitSignalAsync2 (src->sid, IMG_SIGNAL_STATUS, IMG_AQ_DONE, IMG_SIGNAL_STATE_RISING, gst_niimaqsrc_aq_done_callback, src); if (rval) { gst_niimaqsrc_report_imaq_error (rval); GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Failed to register callback(s)"), ("Failed to register callback(s)")); goto error; } return TRUE; error: gst_niimaqsrc_close_interface (src); return FALSE;; }
void AcquireThreadBasler::BaslerAcquire (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); imgSessionTriggerConfigure2(Sid, IMG_SIGNAL_EXTERNAL, 0, IMG_TRIG_POLAR_ACTIVEH, 5000, IMG_TRIG_ACTION_BUFFER); 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 Basler Camera is on and properly connected printf("ERROR: Basler 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(!globalOptions->bVolumeScan) DataFramePos = RawData; } 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); ScanThrPtr->InitializeSyncAndScan(); } globalOptions->volumeReady = 0; } } }