Beispiel #1
0
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);
}
Beispiel #2
0
/**
* 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;;

}
Beispiel #3
0
/**
* gst_niimaqsrc_class_probe_interfaces:
* @klass: #GstNiImaqClass
* @check: whether to enumerate interfaces
*
* Probes NI-IMAQ driver for available interfaces
*
* Returns: TRUE always
*/
static gboolean
gst_niimaqsrc_class_probe_interfaces (GstNiImaqSrcClass * klass, gboolean check)
{
  if (!check) {
    guint32 n;
    gchar name[256];

    /* clear interface list */
    while (interfaces) {
      gchar *iface = interfaces->data;
      interfaces = g_list_remove (interfaces, iface);
      g_free (iface);
    }

    GST_LOG_OBJECT (klass, "About to probe for IMAQ interfaces");

    /* enumerate interfaces, limiting ourselves to the first 64 */
    for (n = 0; n < 64; n++) {
      guint32 iid;
      guint32 nports;
      guint32 port;
      gchar *iname;
      uInt32 rval;

      /* get interface names until there are no more */
      if (rval = imgInterfaceQueryNames (n, name) != 0) {
        gst_niimaqsrc_report_imaq_error (rval);
        break;
      }

      /* ignore NICFGen */
      if (g_strcmp0 (name, "NICFGen.iid") == 0)
        continue;

      /* try and open the interface */
      if (rval = imgInterfaceOpen (name, &iid) != 0) {
        gst_niimaqsrc_report_imaq_error (rval);
        continue;
      }

      /* find how many ports the interface provides */
      rval = imgGetAttribute (iid, IMG_ATTR_NUM_PORTS, &nports);
      gst_niimaqsrc_report_imaq_error (rval);
      rval = imgClose (iid, TRUE);
      gst_niimaqsrc_report_imaq_error (rval);

      /* iterate over all the available ports */
      for (port = 0; port < nports; port++) {
        /* if the there are multiple ports append the port number */
        if (nports > 1)
          iname = g_strdup_printf ("%s::%d", name, port);
        else
          iname = g_strdup (name);

        /* TODO: should check to see if a camera is actually attached */
        interfaces = g_list_append (interfaces, iname);

        GST_DEBUG_OBJECT (klass, "Adding interface '%s' to list", iname);
      }
    }

    init = TRUE;
  }

  klass->interfaces = interfaces;

  return init;
}
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;
		}
	}
}