Beispiel #1
0
        /// <summary>
        /// Configures the camera setting up required buffers.
        /// Allows separation of this time-intensive task from
        /// acquisition start.
        /// </summary>
        /// <param name="bufferCount">The number of frames requested as buffer</param>
        public void Configure(uint bufferCount)
        {
            //set up ring buffer pointers
            _ringBuffer = new IntPtr[bufferCount];
            //create buffer list
            NIImaq.CheckError(NIImaq.imgCreateBufList(bufferCount, out _bufId));
            //compute required buffer size
            uint bufSize = _width * _height * BytesPerPixel;

            //if this is a 16bit acquisition we pre-allocate an internal buffer
            //to allow us handing out 8bit images instead
            _imgDownsize = new Image16((int)Width, (int)Height);
            //Create our camera buffers and set up the buffer list
            //We set the list up as a ring buffer which means that the command
            //is NEXT for each buffer except the last one, where it will be loop
            for (uint i = 0; i < bufferCount; i++)
            {
                //Let imaq obtain the buffer memory
                NIImaq.CheckError(NIImaq.imgCreateBuffer(_sid, Buffer_Location.IMG_HOST_FRAME, bufSize, out _ringBuffer[i]));
                //assign buffer to our buffer list
                NIImaq.CheckError(NIImaq.imgSetBufferElement2(_bufId, i, BlItemType.IMG_BUFF_ADDRESS, _ringBuffer[i]));
                //tell the list about our buffer size
                NIImaq.CheckError(NIImaq.imgSetBufferElement2(_bufId, i, BlItemType.IMG_BUFF_SIZE, bufSize));
                //Set the appropriate buffer command
                var bufCmd = i < (bufferCount - 1) ? BuffCommands.IMG_CMD_NEXT : BuffCommands.IMG_CMD_LOOP;
                NIImaq.CheckError(NIImaq.imgSetBufferElement2(_bufId, i, BlItemType.IMG_BUFF_COMMAND, bufCmd));
            }
            //lock buffer list (supposed to be obsolote but example still does it...)
            NIImaq.CheckError(NIImaq.imgMemLock(_bufId));
            //configure the session to use this buffer list
            NIImaq.CheckError(NIImaq.imgSessionConfigure(_sid, _bufId));
            _configured = true;
        }