예제 #1
0
        //private void imageProvider_GrabbingStartedEvent()
        //{
        //    grabbing = true;

        //    if (GrabbingStatusChanged != null)
        //        GrabbingStatusChanged(this, EventArgs.Empty);
        //}

        private void BaumerProvider_BufferProduced(object sender, BufferEventArgs e)
        {
            BGAPI2.Buffer buffer = e.Buffer;
            if (buffer == null || buffer.IsIncomplete || buffer.MemPtr == IntPtr.Zero)
            {
                return;
            }

            int payloadLength = (int)buffer.SizeFilled;

            // Wrap the buffer in an image, convert if needed.
            BGAPI2.Image image = imgProcessor.CreateImage((uint)buffer.Width, (uint)buffer.Height, buffer.PixelFormat, buffer.MemPtr, buffer.MemSize);
            bool         ready = imageFormat == ImageFormat.JPEG || (imageFormat == ImageFormat.Y800 && BaumerHelper.IsY800(image.PixelFormat));

            if (!ready)
            {
                // Color conversion is required.
                BGAPI2.Image transformedImage = GetTransformedImage(image);
                image.Release();
                image = transformedImage;

                int bpp = BaumerHelper.IsY800(image.PixelFormat) ? 1 : 3;
                payloadLength = (int)(image.Width * image.Height * bpp);
            }

            CopyFrame(image, payloadLength);
            image.Release();

            if (imageFormat != ImageFormat.JPEG && finishline.Enabled)
            {
                bool flush = finishline.Consolidate(frameBuffer);
                if (flush)
                {
                    ComputeDataRate(finishline.BufferOutput.Length);

                    if (FrameProduced != null)
                    {
                        FrameProduced(this, new FrameProducedEventArgs(finishline.BufferOutput, finishline.BufferOutput.Length));
                    }
                }
            }
            else
            {
                ComputeDataRate(payloadLength);

                if (FrameProduced != null)
                {
                    FrameProduced(this, new FrameProducedEventArgs(frameBuffer, payloadLength));
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Takes a raw buffer and copy it into an existing RGB24 Bitmap.
        /// </summary>
        public unsafe bool FillRGB24(BGAPI2.Buffer buffer, Bitmap outputImage)
        {
            if (buffer == null || buffer.IsIncomplete || buffer.MemPtr == IntPtr.Zero)
            {
                return(false);
            }

            if (buffer.Width != (ulong)outputImage.Width || buffer.Height != (ulong)outputImage.Height)
            {
                return(false);
            }

            bool filled = false;

            // If the input image is a bayer pattern it will be debayered by default by the image processor.
            // If it's Mono it will be converted to RGB by the image processor.
            // The input image cannot be JPEG because we temporarily switch off that option before acquisition.
            BGAPI2.ImageProcessor imgProcessor     = new BGAPI2.ImageProcessor();
            BGAPI2.Image          img              = imgProcessor.CreateImage((uint)buffer.Width, (uint)buffer.Height, buffer.PixelFormat, buffer.MemPtr, buffer.SizeFilled);
            BGAPI2.Image          transformedImage = imgProcessor.CreateTransformedImage(img, "BGR8");
            img.Release();
            img = transformedImage;

            // Push the transformed image into the passed output bitmap.
            Rectangle  rect    = new Rectangle(0, 0, outputImage.Width, outputImage.Height);
            BitmapData bmpData = null;

            try
            {
                bmpData = outputImage.LockBits(rect, ImageLockMode.WriteOnly, outputImage.PixelFormat);
                IntPtr[] ptrBmp = new IntPtr[] { bmpData.Scan0 };
                NativeMethods.memcpy(bmpData.Scan0.ToPointer(), img.Buffer.ToPointer(), rect.Width * rect.Height * 3);
                filled = true;
            }
            catch (Exception e)
            {
                log.ErrorFormat("Error while copying bitmap. {0}", e.Message);
            }
            finally
            {
                if (bmpData != null)
                {
                    outputImage.UnlockBits(bmpData);
                }
            }

            img.Release();

            return(filled);
        }
예제 #3
0
        public bool Release()
        {
            lock (Mutex)
            {
                try
                {
                    if (mDevice == null)
                    {
                        return(true);
                    }

                    //STOP CAMERA
                    //if (mDevice.RemoteNodeList.GetNodePresent("AcquisitionAbort"))
                    //{
                    //    mDevice.RemoteNodeList["AcquisitionAbort"].Execute();
                    //}
                    //    mDevice.RemoteNodeList["AcquisitionStop"].Execute();

                    //STOP  DataStream acquisition
                    mDataStream.StopAcquisition();
                    mBufferList.DiscardAllBuffers();

                    //RESET EVENT MODE TO UNREGISTERED
                    mDataStream.UnregisterNewBufferEvent();
                    mDataStream.RegisterNewBufferEvent(BGAPI2.Events.EventMode.UNREGISTERED);

                    //Release buffers
                    while (mBufferList.Count > 0)
                    {
                        mBuffer = (BGAPI2.Buffer)mBufferList.Values.First();
                        mBufferList.RevokeBuffer(mBuffer);
                    }

                    //CLOSE
                    mDataStream.Close();
                    mDevice.Close();
                }
                catch (BGAPI2.Exceptions.IException ex)
                {
                    string str;
                    str = string.Format("ExceptionType:{0}! ErrorDescription:{1} in function:{2}", ex.GetType(), ex.GetErrorDescription(), ex.GetFunctionName());
                    //     MessageBox.Show(str);
                    return(false);
                }

                return(true);
            }
        }
예제 #4
0
        private void DiscardBuffers()
        {
            try
            {
                if (bufferList != null)
                {
                    bufferList.DiscardAllBuffers();
                    while (bufferList.Count > 0)
                    {
                        BGAPI2.Buffer buffer = (BGAPI2.Buffer)bufferList.Values.First();
                        bufferList.RevokeBuffer(buffer);
                    }

                    bufferList = null;
                }
            }
            catch (Exception e)
            {
                log.Error(e.Message);
            }
        }
예제 #5
0
        /// <summary>
        /// Thread method.
        /// </summary>
        private void Grab()
        {
            // raise event start grabbing.
            try
            {
                // setup.

                while (grabThreadRun)
                {
                    // Wait for the next buffer.
                    BGAPI2.Buffer bufferFilled = dataStream.GetFilledBuffer(1000);
                    if (bufferFilled == null || bufferFilled.IsIncomplete || bufferFilled.MemPtr == IntPtr.Zero)
                    {
                        // Grab timeout or error.
                        throw new Exception("A grab timeout or error occurred.");
                    }

                    // Post image event.
                    if (BufferProduced != null)
                    {
                        BufferProduced(this, new BufferEventArgs(bufferFilled));
                    }

                    // Make the buffer available to Baumer internals again.
                    bufferFilled.QueueBuffer();
                }

                // Normal cancellation of the grabbing thread.
                // Cleanup.
            }
            catch (Exception)
            {
                grabThreadRun = false;

                // Cleanup.
            }

            // Normal thread death.
        }
예제 #6
0
        private void BaumerProducer_BufferProduced(object sender, BufferEventArgs e)
        {
            BGAPI2.Buffer buffer = e.Buffer;
            if (buffer == null)
            {
                hadError = true;
                waitHandle.Set();
                return;
            }

            image = new Bitmap((int)buffer.Width, (int)buffer.Height, PixelFormat.Format24bppRgb);
            bool filled = FillRGB24(e.Buffer, image);

            if (filled)
            {
                int  bufferSize = ImageFormatHelper.ComputeBufferSize(image.Width, image.Height, Kinovea.Services.ImageFormat.RGB24);
                bool topDown    = true;
                imageDescriptor = new ImageDescriptor(Kinovea.Services.ImageFormat.RGB24, image.Width, image.Height, topDown, bufferSize);
            }

            waitHandle.Set();
        }
예제 #7
0
        /// <summary>
        /// Start acquisition, get one frame synchronously, convert to RGB24 Bitmap, stop acquisition.
        /// </summary>
        public void AcquireOne()
        {
            if (!opened)
            {
                return;
            }

            if (started)
            {
                Stop();
            }

            dataStream.StartAcquisition();
            //device.RemoteNodeList["AcquisitionMode"].Value = "Continuous";
            device.RemoteNodeList["AcquisitionStart"].Execute();
            started = true;

            // Wait for one frame.
            BGAPI2.Buffer bufferFilled = dataStream.GetFilledBuffer(bufferFilledTimeoutMS);
            if (bufferFilled == null || bufferFilled.IsIncomplete || bufferFilled.MemPtr == IntPtr.Zero)
            {
                // Timeout or error while waiting for the frame.
                Stop();
                return;
            }

            // At this point we have an image buffer available.
            // .MemPtr contains native memory of the raw frame.
            if (BufferProduced != null)
            {
                BufferProduced(this, new BufferEventArgs(bufferFilled));
            }

            // Make the buffer available again.
            bufferFilled.QueueBuffer();
            Stop();
        }
예제 #8
0
        protected override Result Read(Dictionary <string, string> param)
        {
            BGAPI2.Buffer image = _usbDataStream.GetFilledBuffer(1000); // image polling timeout 1000 msec

            if (image == null)
            {
                return(new Result("Fail", "No image received"));
            }
            else if (image.IsIncomplete == true)
            {
                image.QueueBuffer();
                return(new Result("Fail", "Image is not completed"));
            }
            else
            {
                _lastImage?.Release();

                _lastImage = _imgProcessor.CreateImage((uint)image.Width, (uint)image.Height, (string)image.PixelFormat, image.MemPtr, (ulong)image.MemSize);
                Bitmap b = _lastImage.CreateBitmap();

                image.QueueBuffer();
                return(new Result("Ok", "", b));
            }
        }
        public void StopBaumerCam()
        {
            if (Status != BaumerStatus.Ready && Status != BaumerStatus.Capturing)
            {
                return;
            }

            //STOP CAMERA
            if (mDevice != null)
            {
                try
                {
                    IsProcessing = true;
                    if (mDevice.RemoteNodeList.GetNodePresent("AcquisitionAbort") == true)
                    {
                        mDevice.RemoteNodeList["AcquisitionAbort"].Execute();
                        Helpers.Log.LogThisInfo("5.1.12   {0} aborted\n", mDevice.Model);
                    }

                    mDevice.RemoteNodeList["AcquisitionStop"].Execute();
                    Helpers.Log.LogThisInfo("5.1.12   {0} stopped\n", mDevice.Model);
                    Helpers.Log.LogThisInfo("\n");

                    String sExposureNodeName = "";
                    if (mDevice.GetRemoteNodeList().GetNodePresent("ExposureTime"))
                    {
                        sExposureNodeName = "ExposureTime";
                    }
                    else if (mDevice.GetRemoteNodeList().GetNodePresent("ExposureTimeAbs"))
                    {
                        sExposureNodeName = "ExposureTimeAbs";
                    }

                    Helpers.Log.LogThisInfo("         ExposureTime:                   {0} [{1}]\n", (double)mDevice.RemoteNodeList[sExposureNodeName].Value, (string)mDevice.RemoteNodeList[sExposureNodeName].Unit);
                    if (mDevice.TLType == "GEV")
                    {
                        if (mDevice.RemoteNodeList.GetNodePresent("DeviceStreamChannelPacketSize") == true)
                        {
                            Helpers.Log.LogThisInfo("         DeviceStreamChannelPacketSize:  {0} [bytes]\n", (long)mDevice.RemoteNodeList["DeviceStreamChannelPacketSize"].Value);
                        }
                        else
                        {
                            Helpers.Log.LogThisInfo("         GevSCPSPacketSize:              {0} [bytes]\n", (long)mDevice.RemoteNodeList["GevSCPSPacketSize"].Value);
                        }
                        Helpers.Log.LogThisInfo("         GevSCPD (PacketDelay):          {0} [tics]\n", (long)mDevice.RemoteNodeList["GevSCPD"].Value);
                    }
                    Helpers.Log.LogThisInfo("\n");
                    Status = BaumerStatus.Stopped;
                }
                catch (BGAPI2.Exceptions.IException ex)
                {
                    Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                    Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                    Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
                }
            }
            //STOP DataStream acquisition & release buffers
            if (mDataStream != null)
            {
                try
                {
                    if (mDataStream.TLType == "GEV")
                    {
                        //DataStream Statistics
                        Helpers.Log.LogThisInfo("         DataStream Statistics \n");
                        Helpers.Log.LogThisInfo("           GoodFrames:            {0}\n", (long)mDataStream.NodeList["GoodFrames"].Value);
                        Helpers.Log.LogThisInfo("           CorruptedFrames:       {0}\n", (long)mDataStream.NodeList["CorruptedFrames"].Value);
                        Helpers.Log.LogThisInfo("           LostFrames:            {0}\n", (long)mDataStream.NodeList["LostFrames"].Value);
                        Helpers.Log.LogThisInfo("           ResendRequests:        {0}\n", (long)mDataStream.NodeList["ResendRequests"].Value);
                        Helpers.Log.LogThisInfo("           ResendPackets:         {0}\n", (long)mDataStream.NodeList["ResendPackets"].Value);
                        Helpers.Log.LogThisInfo("           LostPackets:           {0}\n", (long)mDataStream.NodeList["LostPackets"].Value);
                        Helpers.Log.LogThisInfo("           Bandwidth:             {0}\n", (long)mDataStream.NodeList["Bandwidth"].Value);
                        Helpers.Log.LogThisInfo("\n");
                    }
                    if (mDataStream.TLType == "U3V")
                    {
                        //DataStream Statistics
                        Helpers.Log.LogThisInfo("         DataStream Statistics \n");
                        Helpers.Log.LogThisInfo("           GoodFrames:            {0}\n", (long)mDataStream.NodeList["GoodFrames"].Value);
                        Helpers.Log.LogThisInfo("           CorruptedFrames:       {0}\n", (long)mDataStream.NodeList["CorruptedFrames"].Value);
                        Helpers.Log.LogThisInfo("           LostFrames:            {0}\n", (long)mDataStream.NodeList["LostFrames"].Value);
                        Helpers.Log.LogThisInfo("\n");
                    }
                    mDataStream.StopAcquisition();
                    Helpers.Log.LogThisInfo("5.1.12   DataStream stopped \n");
                    bufferList.DiscardAllBuffers();

                    // RESET EVENT MODE TO DISABLED
                    //=============================
                    mDataStream.UnregisterNewBufferEvent();
                    mDataStream.RegisterNewBufferEvent(BGAPI2.Events.EventMode.UNREGISTERED);
                    BGAPI2.Events.EventMode currentEventMode = mDataStream.EventMode;
                    System.Console.Write("        Unregister Event Mode:    {0}\n", mDataStream.EventMode.ToString());

                    Helpers.Log.LogThisInfo("RELEASE\n");
                    Helpers.Log.LogThisInfo("#######\n\n");
                    Helpers.Log.LogThisInfo("5.1.13   Releasing the resources\n");

                    while (bufferList.Count > 0)
                    {
                        mBuffer = (BGAPI2.Buffer)bufferList.Values.First();
                        bufferList.RevokeBuffer(mBuffer);
                    }
                    Helpers.Log.LogThisInfo("         buffers after revoke:    {0}\n", bufferList.Count);

                    mDataStream.Close();
                    mDevice.Close();
                    mInterface.Close();
                    mSystem.Close();
                }
                catch (BGAPI2.Exceptions.IException ex)
                {
                    Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                    Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                    Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
                }
            }
            Helpers.Log.LogThisInfo("\n");


            Helpers.Log.LogThisInfo("\nEnd\n\n");
            Helpers.Log.LogThisInfo("Input any number to close the program:\n");
            Status       = BaumerStatus.Stopped;
            IsProcessing = false;
        }
        //EVENT HANDLER
        void mDataStream_NewBufferEvent(object sender, BGAPI2.Events.NewBufferEventArgs mDSEvent)
        {
            if (Parameters.CarImageCount <= 0 || Parameters.CarImageCount > InternalBufferCount || Parameters.CarImageCount > Parameters.BatchCaptureCount)
            {
                return;
            }

            Helpers.Log.LogThisInfo(" [event of {0}] ", ((BGAPI2.DataStream)sender).Parent.Model);             // device
            Status = BaumerStatus.Capturing;
            int i = 0;

            IsProcessing = true;

            //mDevice.RemoteNodeList["TriggerMode"].Value = "Off";
            Helpers.Log.LogThisInfo("==>> Trigger Mode: " + mDevice.RemoteNodeList["TriggerMode"].Value);

            try
            {
                BGAPI2.Buffer mBufferFilled = null;
                mBufferFilled = mDSEvent.BufferObj;
                if (mBufferFilled == null)
                {
                    System.Diagnostics.Debug.WriteLine("Error: Buffer Timeout after 1000 msec");
                }
                else if (mBufferFilled.IsIncomplete == true)
                {
                    Helpers.Log.LogThisError("Error: Image is incomplete, Trial: {0}", i);
                    // queue buffer again
                    mBufferFilled.QueueBuffer();
                }
                else
                {
                    int w = (int)mBufferFilled.Width, h = (int)mBufferFilled.Height;

                    System.Drawing.Bitmap bb = Helpers.Utility.GetGrayBitmap(w, h, mBufferFilled.MemPtr);

                    //string carPath = Path.Combine(Parameters.BasePath, string.Format("{0}", Helpers.Utility.GetTimeStamp()));
                    string destFilePath = Path.Combine(current_car_path, string.Format("{0}_{1:D3}.bmp", Helpers.Utility.GetTimeStamp(), Parameters.CarImageCount++));
                    Task.Factory.StartNew(() =>
                    {
                        bb.Save(destFilePath, System.Drawing.Imaging.ImageFormat.Bmp);
                    });


                    //event TotalImageShot is removed
                    //TotalImageShot++;
                    //if (ImageFileWritten != null)
                    //	ImageFileWritten(destFilePath);

                    mBufferFilled.QueueBuffer();
                }
            }
            catch (BGAPI2.Exceptions.LowLevelException exx)
            {
                Helpers.Log.LogThisError("-->ExceptionType:    {0} ", exx.GetType());
                Helpers.Log.LogThisError("-->Msg:    {0} ", exx.Message);
                Helpers.Log.LogThisError("-->ErrorDescription: {0} ", exx.GetErrorDescription());
                Helpers.Log.LogThisError("-->in function:      {0} ", exx.GetFunctionName());
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                Helpers.Log.LogThisError("-->ExceptionType:    {0} ", ex.GetType());
                Helpers.Log.LogThisError("-->Msg:    {0} ", ex.Message);
                Helpers.Log.LogThisError("-->ErrorDescription: {0} ", ex.GetErrorDescription());
                Helpers.Log.LogThisError("-->in function:      {0} ", ex.GetFunctionName());
            }
            Status = BaumerStatus.Ready;
            return;
        }
        void AcquisitionStart()
        {
            Helpers.Log.LogThisInfo("DEVICE PARAMETER SETUP\n");
            Helpers.Log.LogThisInfo("######################\n\n");

            IsProcessing = true;
            try
            {
                //SET TRIGGER MODE OFF (FreeRun)
                Helpers.Log.LogThisInfo("         TriggerMode:             {0}\n", (string)mDevice.RemoteNodeList["TriggerMode"].Value);

                if (Parameters.TriggerMode)
                {
                    mDevice.RemoteNodeList["TriggerMode"].Value     = "On";
                    mDevice.RemoteNodeList["LineSelector"].Value    = "Line1";
                    mDevice.RemoteNodeList["TriggerSource"].Value   = "All";                  //Or Line0
                    mDevice.RemoteNodeList["LineSelector"].Value    = "Line1";
                    mDevice.RemoteNodeList["LineSource"].Value      = "Line0";
                    mDevice.RemoteNodeList["LineInverter"].Value    = false;
                    mDevice.RemoteNodeList["UserOutputValue"].Value = true;
                    mDevice.RemoteNodeList["TriggerDelay"].Value    = (double)Parameters.TriggerDelay;
                }
                else
                {
                    mDevice.RemoteNodeList["TriggerMode"].Value  = "Off";
                    mDevice.RemoteNodeList["LineInverter"].Value = false;
                }
                if (mDevice.GetRemoteNodeList().GetNodePresent("ExposureTime"))
                {
                    sExposureNodeName = "ExposureTime";
                }
                else if (mDevice.GetRemoteNodeList().GetNodePresent("ExposureTimeAbs"))
                {
                    sExposureNodeName = "ExposureTimeAbs";
                }

                //get current value and limits
                //Parameters.ExposureValue = (double)mDevice.RemoteNodeList[sExposureNodeName].Value;
                Parameters.ExposureMin = (double)mDevice.RemoteNodeList[sExposureNodeName].Min;
                Parameters.ExposureMax = (double)mDevice.RemoteNodeList[sExposureNodeName].Max;

                if (Parameters.ExposureValue < Parameters.ExposureMin)
                {
                    Parameters.ExposureValue = Parameters.ExposureMin;
                }

                if (Parameters.ExposureValue > Parameters.ExposureMax)
                {
                    Parameters.ExposureValue = Parameters.ExposureMax;
                }

                mDevice.RemoteNodeList[sExposureNodeName].Value = Parameters.ExposureValue;

                Helpers.Log.LogThisInfo("         ==>Line Selector:             {0}\n         ==>Trigger Source:             {1}\n         ==>Line Source:             {2}\n         ==>Line Inverter:             {3}\n", mDevice.RemoteNodeList["LineSelector"].Value, mDevice.RemoteNodeList["TriggerSource"].Value, mDevice.RemoteNodeList["LineSource"].Value, mDevice.RemoteNodeList["Line Inverter"].Value);
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
            }


            Helpers.Log.LogThisInfo("DATA STREAM LIST\n");
            Helpers.Log.LogThisInfo("################\n\n");

            try
            {
                //COUNTING AVAILABLE DATASTREAMS
                datastreamList = mDevice.DataStreams;
                datastreamList.Refresh();

                //Helpers.Log.LogThisInfo("5.1.8   Detected datastreams:     {0}\n", datastreamList.Count);
                ////DATASTREAM INFORMATION BEFORE OPENING
                //foreach (KeyValuePair<string, BGAPI2.DataStream> dst_pair in datastreamList)
                //{
                //    Helpers.Log.LogThisInfo("  5.2.4   DataStream ID:          {0}\n\n", dst_pair.Key);
                //}
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
            }


            Helpers.Log.LogThisInfo("DATA STREAM\n");
            Helpers.Log.LogThisInfo("###########\n\n");

            //OPEN THE FIRST DATASTREAM IN THE LIST
            try
            {
                foreach (KeyValuePair <string, BGAPI2.DataStream> dst_pair in datastreamList)
                {
                    Helpers.Log.LogThisInfo("5.1.9   Open first datastream \n");
                    Helpers.Log.LogThisInfo("          DataStream ID:          {0}\n\n", dst_pair.Key);
                    //if (dst_pair.Value.IsOpen || dst_pair.Value.IsGrabbing )
                    //{
                    if (mDevice.RemoteNodeList.GetNodePresent("AcquisitionAbort") == true)
                    {
                        mDevice.RemoteNodeList["AcquisitionAbort"].Execute();
                        Helpers.Log.LogThisInfo("5.1.12   {0} aborted\n", mDevice.Model);
                    }

                    mDevice.RemoteNodeList["AcquisitionStop"].Execute();
                    //dst_pair.Value.Close();
                    System.Threading.Thread.Sleep(50);
                    //}
                    dst_pair.Value.Open();
                    sDataStreamID = dst_pair.Key;
                    Helpers.Log.LogThisInfo("        Opened datastream - NodeList Information \n");
                    Helpers.Log.LogThisInfo("          StreamAnnounceBufferMinimum:  {0}\n", dst_pair.Value.NodeList["StreamAnnounceBufferMinimum"].Value);
                    if (dst_pair.Value.TLType == "GEV")
                    {
                        Helpers.Log.LogThisInfo("          StreamDriverModel:            {0}\n", dst_pair.Value.NodeList["StreamDriverModel"].Value);
                    }
                    Helpers.Log.LogThisInfo("  \n");
                    break;
                }
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
            }

            if (sDataStreamID == "")
            {
                Helpers.Log.LogThisInfo(" No DataStream found \n");
                Helpers.Log.LogThisInfo("\nEnd\nInput any number to close the program:\n");
                //Console.Read();
                mDevice.Close();
                mInterface.Close();
                mSystem.Close();
                IsProcessing = false;
                return;
            }
            else
            {
                mDataStream = datastreamList[sDataStreamID];
            }


            Helpers.Log.LogThisInfo("BUFFER LIST\n");
            Helpers.Log.LogThisInfo("###########\n\n");

            try
            {
                //BufferList
                bufferList = mDataStream.BufferList;

                // 4 buffers using internal buffer mode
                for (int i = 0; i < InternalBufferCount; i++)
                {
                    mBuffer = new BGAPI2.Buffer();
                    bufferList.Add(mBuffer);
                    mBuffer.QueueBuffer();
                }
                Helpers.Log.LogThisInfo("5.1.10   Announced buffers:       {0} using {1} [bytes]\n", bufferList.AnnouncedCount, mBuffer.MemSize * bufferList.AnnouncedCount);
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
            }
            Helpers.Log.LogThisInfo("\n");

            Helpers.Log.LogThisInfo("CAMERA START\n");
            Helpers.Log.LogThisInfo("############\n\n");

            mDataStream.RegisterNewBufferEvent(BGAPI2.Events.EventMode.EVENT_HANDLER);
            System.Console.Write("        Register Event Mode to:   {0}\n\n", mDataStream.EventMode.ToString());
            mDataStream.NewBufferEvent += new BGAPI2.Events.DataStreamEventControl.NewBufferEventHandler(mDataStream_NewBufferEvent);

            //START DATASTREAM ACQUISITION
            try
            {
                mDataStream.StartAcquisition();
                Helpers.Log.LogThisInfo("5.1.12   DataStream started \n");
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
            }

            //START CAMERA
            try
            {
                mDevice.RemoteNodeList["AcquisitionStart"].Execute();
                Helpers.Log.LogThisInfo("5.1.12   {0} started \n", mDevice.Model);
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
            }

            Status = BaumerStatus.Ready;
        }
예제 #12
0
        public void mDataStream_NewBufferEvent(object sender, BGAPI2.Events.NewBufferEventArgs mDSEvent)
        {
            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Restart();

                BGAPI2.Buffer mBufferFilled = null;

                mBufferFilled = mDSEvent.BufferObj;

                if (mBufferFilled == null)
                {
                }

                else if (mBufferFilled.IsIncomplete == true)
                {
                    mBufferFilled.QueueBuffer();
                }

                else
                {
                    int width  = (int)mBufferFilled.Width;
                    int height = (int)mBufferFilled.Height;
                    m_nImageWidth  = width;
                    m_nImageHeight = height;
                    m_sPixelFormat = mBufferFilled.PixelFormat;

                    if (mBufferFilled.PixelFormat == "Mono8")
                    {
                        ulong size = mBufferFilled.SizeFilled;

                        IntPtr pBuffer = mBufferFilled.MemPtr;

                        m_pImgData = new byte[width * height];
                        Marshal.Copy(pBuffer, m_pImgData, 0, width * height);
                    }

                    else //color
                    {
                        ulong        size   = mBufferFilled.SizeFilled;
                        BGAPI2.Image mImage = imgProcessor.CreateImage((uint)mBufferFilled.Width, (uint)mBufferFilled.Height, (string)mBufferFilled.PixelFormat, mBufferFilled.MemPtr, (ulong)mBufferFilled.MemSize);

                        //  BGAPI2.Image mImageTransfer = mImage.TransformImage("BGR8");
                        BGAPI2.Image mTransformImage = imgProcessor.CreateTransformedImage(mImage, "BGR8");
                        try
                        {
                            m_pImgData = new byte[(uint)((uint)mImage.Width * (uint)mImage.Height * 3.0)];
                            Marshal.Copy(mTransformImage.Buffer, m_pImgData, 0, (int)((int)mImage.Width * (int)mImage.Height * 3.0));
                        }
                        catch (Exception)
                        {
                            GrabComplete.Set();
                            MessageBox.Show("拍照处理异常");
                        }

                        if (mImage != null)
                        {
                            mImage.Release();
                            mTransformImage.Release();
                        }
                    }
                    string mode = mDevice.RemoteNodeList["TriggerSource"].Value;

                    if (mode == "Line0")
                    {
                        HTRGNum++;
                    }
                    OnRan(m_pImgData, width, height, m_sPixelFormat);
                    GrabComplete.Set();

                    mBufferFilled.QueueBuffer();
                    sw.Stop();
                    AcqTime = sw.ElapsedMilliseconds;
                    //MessageBox.Show(AcqTime.ToString());
                }
            }

            catch (BGAPI2.Exceptions.IException ex)
            {
                GrabComplete.Set();
                string str;
                str = string.Format("ExceptionType:{0}! ErrorDescription:{1} in function:{2}", ex.GetType(), ex.GetErrorDescription(), ex.GetFunctionName());
                MessageBox.Show("002" + str);
            }
        }
예제 #13
0
        public bool Initialize(string serialNumber)
        {
            this.serialNumber = serialNumber;
            try
            {
                mDevice = BaumerCameraSystem.listCamera.Find((c) => c.strSN == serialNumber).pDevice;
                if (mDevice == null || mDevice.IsOpen)
                {
                    return(false);
                }
                this.describe = mDevice.Model;
                mDevice.Open();

                bPersistentIP = true;
                if (mDevice.TLType == "GEV")
                {
                    if (bPersistentIP)
                    {
                        long   iDevIPAddress   = (long)mDevice.NodeList["GevDeviceIPAddress"].Value;
                        string strDevIpAddress = (iDevIPAddress >> 24).ToString() + "." +
                                                 ((iDevIPAddress & 0xffffff) >> 16).ToString() + "." +
                                                 ((iDevIPAddress & 0xffff) >> 8).ToString() + "." +
                                                 (iDevIPAddress & 0xff).ToString();

                        long   iDevSubnetMask   = (long)mDevice.NodeList["GevDeviceSubnetMask"].Value;
                        string strDevSubnetMask = (iDevSubnetMask >> 24).ToString() + "." +
                                                  ((iDevSubnetMask & 0xffffff) >> 16).ToString() + "." +
                                                  ((iDevSubnetMask & 0xffff) >> 8).ToString() + "." +
                                                  (iDevSubnetMask & 0xff).ToString();

                        long   iPersistentIP             = (long)mDevice.RemoteNodeList["GevPersistentIPAddress"].Value;
                        string strDevPersistentIpAddress = (iPersistentIP >> 24).ToString() + "." +
                                                           ((iPersistentIP & 0xffffff) >> 16).ToString() + "." +
                                                           ((iPersistentIP & 0xffff) >> 8).ToString() + "." +
                                                           (iPersistentIP & 0xff).ToString();


                        if (iPersistentIP != iDevIPAddress)
                        {
                            if (iPersistentIP > 100 && iDevSubnetMask > 1000)
                            {
                                mDevice.RemoteNodeList["GevCurrentIPConfigurationPersistentIP"].Value = true;
                                mDevice.RemoteNodeList["GevPersistentIPAddress"].Value  = iDevIPAddress;
                                mDevice.RemoteNodeList["GevPersistentSubnetMask"].Value = iDevSubnetMask;
                            }

                            Thread.Sleep(1000);
                        }
                    }
                }

                mDevice.RemoteNodeList["AcquisitionStop"].Execute();

                mDatastreamList = mDevice.DataStreams;
                mDatastreamList.Refresh();

                foreach (KeyValuePair <string, BGAPI2.DataStream> dst_pair in mDatastreamList)
                {
                    dst_pair.Value.Open();

                    if (dst_pair.Key != "")
                    {
                        string sDataStreamID = dst_pair.Key;
                        mDataStream = mDatastreamList[sDataStreamID];
                        break;
                    }
                    else
                    {
                        mDevice.Close();
                        mDevice.Parent.Close();
                        return(false);
                    }
                }
                mBufferList = mDataStream.BufferList;

                for (int i = 0; i < 10; i++)
                {
                    mBuffer = new BGAPI2.Buffer();
                    mBufferList.Add(mBuffer);
                }

                foreach (KeyValuePair <string, BGAPI2.Buffer> buf_pair in mBufferList)
                {
                    buf_pair.Value.QueueBuffer();
                }
                mDevice.RemoteNodeList["TriggerMode"].Value = "On";

                mDataStream.NewBufferEvent += new BGAPI2.Events.DataStreamEventControl.NewBufferEventHandler(mDataStream_NewBufferEvent);
                mDataStream.RegisterNewBufferEvent(BGAPI2.Events.EventMode.EVENT_HANDLER);

                GrabComplete = new ManualResetEvent(false);
                mDataStream.AbortAcquisition();
                mDataStream.StartAcquisition();

                mDevice.RemoteNodeList["AcquisitionStart"].Execute();


                bOpened = true;

                return(true);
            }

            catch (BGAPI2.Exceptions.IException ex)
            {
                string str;
                str = string.Format("ExceptionType:{0}! ErrorDescription:{1} in function:{2}", ex.GetType(), ex.GetErrorDescription(), ex.GetFunctionName());
                MessageBox.Show(str);

                return(false);
            }
        }
예제 #14
0
        /// <summary>
        /// Open a specific device and allocate buffers.
        /// </summary>
        public bool Open(string systemKey, string interfaceKey, string deviceKey)
        {
            Close();

            try
            {
                // Look for the device.
                SystemList systemList = SystemList.Instance;
                systemList.Refresh();
                foreach (KeyValuePair <string, BGAPI2.System> systemPair in systemList)
                {
                    if (systemPair.Key != systemKey)
                    {
                        continue;
                    }

                    system = systemPair.Value;
                    if (!system.IsOpen)
                    {
                        system.Open();
                    }

                    break;
                }

                if (system == null || !system.IsOpen)
                {
                    return(false);
                }

                system.Interfaces.Refresh(100);
                foreach (KeyValuePair <string, BGAPI2.Interface> interfacePair in system.Interfaces)
                {
                    if (interfacePair.Key != interfaceKey)
                    {
                        continue;
                    }

                    interf = interfacePair.Value;
                    if (!interf.IsOpen)
                    {
                        interf.Open();
                    }
                    break;
                }

                if (interf == null || !interf.IsOpen)
                {
                    return(false);
                }


                interf.Devices.Refresh(100);
                foreach (KeyValuePair <string, BGAPI2.Device> devicePair in interf.Devices)
                {
                    if (devicePair.Key != deviceKey)
                    {
                        continue;
                    }

                    device = devicePair.Value;
                    if (!device.IsOpen)
                    {
                        device.Open();
                    }
                    break;
                }

                if (device == null || !device.IsOpen)
                {
                    return(false);
                }

                DataStreamList dataStreamList = device.DataStreams;
                dataStreamList.Refresh();
                foreach (KeyValuePair <string, BGAPI2.DataStream> dataStreamPair in dataStreamList)
                {
                    if (string.IsNullOrEmpty(dataStreamPair.Key))
                    {
                        continue;
                    }

                    dataStream = dataStreamPair.Value;
                    dataStream.Open();
                    break;
                }

                if (dataStream == null)
                {
                    CloseDevice();
                    return(false);
                }

                // Use buffers internal to the API.
                bufferList = dataStream.BufferList;
                int countBuffers = 4;
                for (int i = 0; i < countBuffers; i++)
                {
                    BGAPI2.Buffer buffer = new BGAPI2.Buffer();
                    bufferList.Add(buffer);
                    //ulong memSize = buffer.MemSize;
                    //log.DebugFormat("Buffer mem size: {0}", memSize);
                }

                // Make buffers available to the Baumer producer.
                if (bufferList != null && bufferList.Count == countBuffers)
                {
                    foreach (KeyValuePair <string, BGAPI2.Buffer> bufferPair in bufferList)
                    {
                        bufferPair.Value.QueueBuffer();
                    }
                }

                opened = true;
            }
            catch (Exception e)
            {
                log.ErrorFormat("Failed to open device. {0}", e);
                DiscardBuffers();
                CloseDataStream();
                CloseDevice();
            }

            return(opened);
        }
예제 #15
0
        private void DbgScanAll()
        {
            //DECLARATIONS OF VARIABLES
            BGAPI2.SystemList systemList = null;
            BGAPI2.System     mSystem    = null;
            string            sSystemID  = "";

            BGAPI2.InterfaceList interfaceList = null;
            BGAPI2.Interface     mInterface    = null;
            string sInterfaceID = "";

            BGAPI2.DeviceList deviceList = null;
            BGAPI2.Device     mDevice    = null;
            string            sDeviceID  = "";

            BGAPI2.DataStreamList datastreamList = null;
            BGAPI2.DataStream     mDataStream    = null;
            string sDataStreamID = "";

            BGAPI2.BufferList bufferList = null;
            BGAPI2.Buffer     mBuffer    = null;
            int returnCode = 0;

            System.Console.Write("\r\n");
            System.Console.Write("##############################################################\r\n");
            System.Console.Write("# PROGRAMMER'S GUIDE Example 001_ImageCaptureMode_Polling.cs #\r\n");
            System.Console.Write("##############################################################\r\n");
            System.Console.Write("\r\n\r\n");


            System.Console.Write("SYSTEM LIST\r\n");
            System.Console.Write("###########\r\n\r\n");

            //COUNTING AVAILABLE SYSTEMS (TL producers)
            try
            {
                systemList = BGAPI2.SystemList.Instance;
                systemList.Refresh();
                System.Console.Write("5.1.2   Detected systems:  {0}\r\n", systemList.Count);

                //SYSTEM DEVICE INFORMATION
                foreach (KeyValuePair <string, BGAPI2.System> sys_pair in BGAPI2.SystemList.Instance)
                {
                    System.Console.Write("  5.2.1   System Name:     {0}\r\n", sys_pair.Value.FileName);
                    System.Console.Write("          System Type:     {0}\r\n", sys_pair.Value.TLType);
                    System.Console.Write("          System Version:  {0}\r\n", sys_pair.Value.Version);
                    System.Console.Write("          System PathName: {0}\r\n\r\n", sys_pair.Value.PathName);
                }
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }


            //OPEN THE FIRST SYSTEM IN THE LIST WITH A CAMERA CONNECTED
            try
            {
                foreach (KeyValuePair <string, BGAPI2.System> sys_pair in BGAPI2.SystemList.Instance)
                {
                    System.Console.Write("SYSTEM\r\n");
                    System.Console.Write("######\r\n\r\n");

                    try
                    {
                        sys_pair.Value.Open();
                        System.Console.Write("5.1.3   Open next system \r\n");
                        System.Console.Write("  5.2.1   System Name:     {0}\r\n", sys_pair.Value.FileName);
                        System.Console.Write("          System Type:     {0}\r\n", sys_pair.Value.TLType);
                        System.Console.Write("          System Version:  {0}\r\n", sys_pair.Value.Version);
                        System.Console.Write("          System PathName: {0}\r\n\r\n", sys_pair.Value.PathName);
                        sSystemID = sys_pair.Key;
                        System.Console.Write("        Opened system - NodeList Information \r\n");
                        System.Console.Write("          GenTL Version:   {0}.{1}\r\n\r\n", (long)sys_pair.Value.NodeList["GenTLVersionMajor"].Value, (long)sys_pair.Value.NodeList["GenTLVersionMinor"].Value);


                        System.Console.Write("INTERFACE LIST\r\n");
                        System.Console.Write("##############\r\n\r\n");

                        try
                        {
                            interfaceList = sys_pair.Value.Interfaces;
                            //COUNT AVAILABLE INTERFACES
                            interfaceList.Refresh(100); // timeout of 100 msec
                            System.Console.Write("5.1.4   Detected interfaces: {0}\r\n", interfaceList.Count);

                            //INTERFACE INFORMATION
                            foreach (KeyValuePair <string, BGAPI2.Interface> ifc_pair in interfaceList)
                            {
                                System.Console.Write("  5.2.2   Interface ID:      {0}\r\n", ifc_pair.Value.Id);
                                System.Console.Write("          Interface Type:    {0}\r\n", ifc_pair.Value.TLType);
                                System.Console.Write("          Interface Name:    {0}\r\n\r\n", ifc_pair.Value.DisplayName);
                            }
                        }
                        catch (BGAPI2.Exceptions.IException ex)
                        {
                            returnCode = (0 == returnCode) ? 1 : returnCode;
                            System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                            System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                            System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
                        }


                        System.Console.Write("INTERFACE\r\n");
                        System.Console.Write("#########\r\n\r\n");

                        //OPEN THE NEXT INTERFACE IN THE LIST
                        try
                        {
                            foreach (KeyValuePair <string, BGAPI2.Interface> ifc_pair in interfaceList)
                            {
                                try
                                {
                                    System.Console.Write("5.1.5   Open interface \r\n");
                                    System.Console.Write("  5.2.2   Interface ID:      {0}\r\n", ifc_pair.Key);
                                    System.Console.Write("          Interface Type:    {0}\r\n", ifc_pair.Value.TLType);
                                    System.Console.Write("          Interface Name:    {0}\r\n", ifc_pair.Value.DisplayName);
                                    ifc_pair.Value.Open();
                                    //search for any camera is connetced to this interface
                                    deviceList = ifc_pair.Value.Devices;
                                    deviceList.Refresh(100);
                                    if (deviceList.Count == 0)
                                    {
                                        System.Console.Write("5.1.13   Close interface ({0} cameras found) \r\n\r\n", deviceList.Count);
                                        ifc_pair.Value.Close();
                                    }
                                    else
                                    {
                                        sInterfaceID = ifc_pair.Key;
                                        System.Console.Write("  \r\n");
                                        System.Console.Write("        Opened interface - NodeList Information \r\n");
                                        if (ifc_pair.Value.TLType == "GEV")
                                        {
                                            long iIPAddress = (long)ifc_pair.Value.NodeList["GevInterfaceSubnetIPAddress"].Value;
                                            System.Console.Write("          GevInterfaceSubnetIPAddress: {0}.{1}.{2}.{3}\r\n", (iIPAddress & 0xff000000) >> 24,
                                                                 (iIPAddress & 0x00ff0000) >> 16,
                                                                 (iIPAddress & 0x0000ff00) >> 8,
                                                                 (iIPAddress & 0x000000ff));
                                            long iSubnetMask = (long)ifc_pair.Value.NodeList["GevInterfaceSubnetMask"].Value;
                                            System.Console.Write("          GevInterfaceSubnetMask:      {0}.{1}.{2}.{3}\r\n", (iSubnetMask & 0xff000000) >> 24,
                                                                 (iSubnetMask & 0x00ff0000) >> 16,
                                                                 (iSubnetMask & 0x0000ff00) >> 8,
                                                                 (iSubnetMask & 0x000000ff));
                                        }
                                        if (ifc_pair.Value.TLType == "U3V")
                                        {
                                            //System.Console.Write("          NodeListCount:               {0}\r\n", ifc_pair.Value.NodeList.Count);
                                        }
                                        System.Console.Write("  \r\n");
                                        break;
                                    }
                                }
                                catch (BGAPI2.Exceptions.ResourceInUseException ex)
                                {
                                    returnCode = (0 == returnCode) ? 1 : returnCode;
                                    System.Console.Write(" Interface {0} already opened \r\n", ifc_pair.Key);
                                    System.Console.Write(" ResourceInUseException {0} \r\n", ex.GetErrorDescription());
                                }
                            }
                        }
                        catch (BGAPI2.Exceptions.IException ex)
                        {
                            returnCode = (0 == returnCode) ? 1 : returnCode;
                            System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                            System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                            System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
                        }

                        //if a camera is connected to the system interface then leave the system loop
                        if (sInterfaceID != "")
                        {
                            break;
                        }
                    }
                    catch (BGAPI2.Exceptions.ResourceInUseException ex)
                    {
                        returnCode = (0 == returnCode) ? 1 : returnCode;
                        System.Console.Write(" System {0} already opened \r\n", sys_pair.Key);
                        System.Console.Write(" ResourceInUseException {0} \r\n", ex.GetErrorDescription());
                    }
                }
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }

            if (sSystemID == "")
            {
                System.Console.Write(" No System found \r\n");
                System.Console.Write(" Input any number to close the program:\r\n");
                Console.Read();
            }
            else
            {
                mSystem = systemList[sSystemID];
            }


            if (sInterfaceID == "")
            {
                System.Console.Write(" No Interface of TLType 'GEV' found \r\n");
                System.Console.Write("\r\nEnd\r\nInput any number to close the program:\r\n");
                Console.Read();
                mSystem.Close();
            }
            else
            {
                mInterface = interfaceList[sInterfaceID];
            }


            System.Console.Write("DEVICE LIST\r\n");
            System.Console.Write("###########\r\n\r\n");

            try
            {
                //COUNTING AVAILABLE CAMERAS
                deviceList = mInterface.Devices;
                deviceList.Refresh(100);
                System.Console.Write("5.1.6   Detected devices:         {0}\r\n", deviceList.Count);

                //DEVICE INFORMATION BEFORE OPENING
                foreach (KeyValuePair <string, BGAPI2.Device> dev_pair in deviceList)
                {
                    System.Console.Write("  5.2.3   Device DeviceID:        {0}\r\n", dev_pair.Key);
                    System.Console.Write("          Device Model:           {0}\r\n", dev_pair.Value.Model);
                    System.Console.Write("          Device SerialNumber:    {0}\r\n", dev_pair.Value.SerialNumber);
                    System.Console.Write("          Device Vendor:          {0}\r\n", dev_pair.Value.Vendor);
                    System.Console.Write("          Device TLType:          {0}\r\n", dev_pair.Value.TLType);
                    System.Console.Write("          Device AccessStatus:    {0}\r\n", dev_pair.Value.AccessStatus);
                    System.Console.Write("          Device UserID:          {0}\r\n\r\n", dev_pair.Value.DisplayName);
                }
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }


            System.Console.Write("DEVICE\r\n");
            System.Console.Write("######\r\n\r\n");

            //OPEN THE FIRST CAMERA IN THE LIST
            try
            {
                foreach (KeyValuePair <string, BGAPI2.Device> dev_pair in deviceList)
                {
                    try
                    {
                        System.Console.Write("5.1.7   Open first device \r\n");
                        System.Console.Write("          Device DeviceID:        {0}\r\n", dev_pair.Value.Id);
                        System.Console.Write("          Device Model:           {0}\r\n", dev_pair.Value.Model);
                        System.Console.Write("          Device SerialNumber:    {0}\r\n", dev_pair.Value.SerialNumber);
                        System.Console.Write("          Device Vendor:          {0}\r\n", dev_pair.Value.Vendor);
                        System.Console.Write("          Device TLType:          {0}\r\n", dev_pair.Value.TLType);
                        System.Console.Write("          Device AccessStatus:    {0}\r\n", dev_pair.Value.AccessStatus);
                        System.Console.Write("          Device UserID:          {0}\r\n\r\n", dev_pair.Value.DisplayName);
                        dev_pair.Value.Open();
                        sDeviceID = dev_pair.Key;
                        System.Console.Write("        Opened device - RemoteNodeList Information \r\n");
                        System.Console.Write("          Device AccessStatus:    {0}\r\n", dev_pair.Value.AccessStatus);

                        //SERIAL NUMBER
                        if (dev_pair.Value.RemoteNodeList.GetNodePresent("DeviceSerialNumber") == true)
                        {
                            System.Console.Write("          DeviceSerialNumber:     {0}\r\n", (string)dev_pair.Value.RemoteNodeList["DeviceSerialNumber"].Value);
                        }
                        else if (dev_pair.Value.RemoteNodeList.GetNodePresent("DeviceID") == true)
                        {
                            System.Console.Write("          DeviceID (SN):          {0}\r\n", (string)dev_pair.Value.RemoteNodeList["DeviceID"].Value);
                        }
                        else
                        {
                            System.Console.Write("          SerialNumber:           Not Available.\r\n");
                        }

                        //DISPLAY DEVICEMANUFACTURERINFO
                        if (dev_pair.Value.RemoteNodeList.GetNodePresent("DeviceManufacturerInfo") == true)
                        {
                            System.Console.Write("          DeviceManufacturerInfo: {0}\r\n", (string)dev_pair.Value.RemoteNodeList["DeviceManufacturerInfo"].Value);
                        }

                        //DISPLAY DEVICEFIRMWAREVERSION OR DEVICEVERSION
                        if (dev_pair.Value.RemoteNodeList.GetNodePresent("DeviceFirmwareVersion") == true)
                        {
                            System.Console.Write("          DeviceFirmwareVersion:  {0}\r\n", (string)dev_pair.Value.RemoteNodeList["DeviceFirmwareVersion"].Value);
                        }
                        else if (dev_pair.Value.RemoteNodeList.GetNodePresent("DeviceVersion") == true)
                        {
                            System.Console.Write("          DeviceVersion:          {0}\r\n", (string)dev_pair.Value.RemoteNodeList["DeviceVersion"].Value);
                        }
                        else
                        {
                            System.Console.Write("          DeviceVersion:          Not Available.\r\n");
                        }

                        if (dev_pair.Value.TLType == "GEV")
                        {
                            System.Console.Write("          GevCCP:                 {0}\r\n", (string)dev_pair.Value.RemoteNodeList["GevCCP"].Value);
                            System.Console.Write("          GevCurrentIPAddress:    {0}.{1}.{2}.{3}\r\n", ((long)dev_pair.Value.RemoteNodeList["GevCurrentIPAddress"].Value & 0xff000000) >> 24, ((long)dev_pair.Value.RemoteNodeList["GevCurrentIPAddress"].Value & 0x00ff0000) >> 16, ((long)dev_pair.Value.RemoteNodeList["GevCurrentIPAddress"].Value & 0x0000ff00) >> 8, ((long)dev_pair.Value.RemoteNodeList["GevCurrentIPAddress"].Value & 0x000000ff));
                            System.Console.Write("          GevCurrentSubnetMask:   {0}.{1}.{2}.{3}\r\n", ((long)dev_pair.Value.RemoteNodeList["GevCurrentSubnetMask"].Value & 0xff000000) >> 24, ((long)dev_pair.Value.RemoteNodeList["GevCurrentSubnetMask"].Value & 0x00ff0000) >> 16, ((long)dev_pair.Value.RemoteNodeList["GevCurrentSubnetMask"].Value & 0x0000ff00) >> 8, ((long)dev_pair.Value.RemoteNodeList["GevCurrentSubnetMask"].Value & 0x000000ff));
                        }
                        System.Console.Write("          \r\n");
                        break;
                    }
                    catch (BGAPI2.Exceptions.ResourceInUseException ex)
                    {
                        returnCode = (0 == returnCode) ? 1 : returnCode;
                        System.Console.Write(" Device {0} already opened \r\n", dev_pair.Key);
                        System.Console.Write(" ResourceInUseException {0} \r\n", ex.GetErrorDescription());
                    }
                    catch (BGAPI2.Exceptions.AccessDeniedException ex)
                    {
                        returnCode = (0 == returnCode) ? 1 : returnCode;
                        System.Console.Write(" Device {0} already opened \r\n", dev_pair.Key);
                        System.Console.Write(" AccessDeniedException {0} \r\n", ex.GetErrorDescription());
                    }
                }
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }

            if (sDeviceID == "")
            {
                System.Console.Write(" No Device found \r\n");
                System.Console.Write("\r\nEnd\r\nInput any number to close the program:\r\n");
                Console.Read();
                mInterface.Close();
                mSystem.Close();
            }
            else
            {
                mDevice = deviceList[sDeviceID];
            }


            System.Console.Write("DEVICE PARAMETER SETUP\r\n");
            System.Console.Write("######################\r\n\r\n");

            try
            {
                //SET TRIGGER MODE OFF (FreeRun)
                mDevice.RemoteNodeList["TriggerMode"].Value = "Off";
                System.Console.Write("         TriggerMode:             {0}\r\n", (string)mDevice.RemoteNodeList["TriggerMode"].Value);
                System.Console.Write("  \r\n");
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }


            System.Console.Write("DATA STREAM LIST\r\n");
            System.Console.Write("################\r\n\r\n");

            try
            {
                //COUNTING AVAILABLE DATASTREAMS
                datastreamList = mDevice.DataStreams;
                datastreamList.Refresh();
                System.Console.Write("5.1.8   Detected datastreams:     {0}\r\n", datastreamList.Count);

                //DATASTREAM INFORMATION BEFORE OPENING
                foreach (KeyValuePair <string, BGAPI2.DataStream> dst_pair in datastreamList)
                {
                    System.Console.Write("  5.2.4   DataStream ID:          {0}\r\n\r\n", dst_pair.Key);
                }
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }


            System.Console.Write("DATA STREAM\r\n");
            System.Console.Write("###########\r\n\r\n");

            //OPEN THE FIRST DATASTREAM IN THE LIST
            try
            {
                foreach (KeyValuePair <string, BGAPI2.DataStream> dst_pair in datastreamList)
                {
                    System.Console.Write("5.1.9   Open first datastream \r\n");
                    System.Console.Write("          DataStream ID:          {0}\r\n\r\n", dst_pair.Key);
                    dst_pair.Value.Open();
                    sDataStreamID = dst_pair.Key;
                    System.Console.Write("        Opened datastream - NodeList Information \r\n");
                    System.Console.Write("          StreamAnnounceBufferMinimum:  {0}\r\n", dst_pair.Value.NodeList["StreamAnnounceBufferMinimum"].Value);
                    if (dst_pair.Value.TLType == "GEV")
                    {
                        System.Console.Write("          StreamDriverModel:            {0}\r\n", dst_pair.Value.NodeList["StreamDriverModel"].Value);
                    }
                    System.Console.Write("  \r\n");
                    break;
                }
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }

            if (sDataStreamID == "")
            {
                System.Console.Write(" No DataStream found \r\n");
                System.Console.Write("\r\nEnd\r\nInput any number to close the program:\r\n");
                Console.Read();
                mDevice.Close();
                mInterface.Close();
                mSystem.Close();
            }
            else
            {
                mDataStream = datastreamList[sDataStreamID];
            }


            System.Console.Write("BUFFER LIST\r\n");
            System.Console.Write("###########\r\n\r\n");

            try
            {
                //BufferList
                bufferList = mDataStream.BufferList;

                // 4 buffers using internal buffer mode
                for (int i = 0; i < 4; i++)
                {
                    mBuffer = new BGAPI2.Buffer();
                    bufferList.Add(mBuffer);
                }
                System.Console.Write("5.1.10   Announced buffers:       {0} using {1} [bytes]\r\n", bufferList.AnnouncedCount, mBuffer.MemSize * bufferList.AnnouncedCount);
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }


            try
            {
                foreach (KeyValuePair <string, BGAPI2.Buffer> buf_pair in bufferList)
                {
                    buf_pair.Value.QueueBuffer();
                }
                System.Console.Write("5.1.11   Queued buffers:          {0}\r\n", bufferList.QueuedCount);
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }
            System.Console.Write("\r\n");


            System.Console.Write("CAMERA START\r\n");
            System.Console.Write("############\r\n\r\n");

            //START DATASTREAM ACQUISITION
            try
            {
                mDataStream.StartAcquisition();
                System.Console.Write("5.1.12   DataStream started \r\n");
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }

            //START CAMERA
            try
            {
                mDevice.RemoteNodeList["AcquisitionStart"].Execute();
                System.Console.Write("5.1.12   {0} started \r\n", mDevice.Model);
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }

            //CAPTURE 12 IMAGES
            System.Console.Write("\r\n");
            System.Console.Write("CAPTURE 12 IMAGES BY IMAGE POLLING\r\n");
            System.Console.Write("##################################\r\n\r\n");

            BGAPI2.Buffer mBufferFilled = null;
            try
            {
                for (int i = 0; i < 12; i++)
                {
                    mBufferFilled = mDataStream.GetFilledBuffer(1000); // image polling timeout 1000 msec
                    if (mBufferFilled == null)
                    {
                        System.Console.Write("Error: Buffer Timeout after 1000 msec\r\n");
                    }
                    else if (mBufferFilled.IsIncomplete == true)
                    {
                        System.Console.Write("Error: Image is incomplete\r\n");
                        // queue buffer again
                        mBufferFilled.QueueBuffer();
                    }
                    else
                    {
                        System.Console.Write(" Image {0, 5:d} received in memory address {1:X}\r\n", mBufferFilled.FrameID, (ulong)mBufferFilled.MemPtr);
                        // queue buffer again
                        mBufferFilled.QueueBuffer();
                    }
                }
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }
            System.Console.Write("\r\n");


            System.Console.Write("CAMERA STOP\r\n");
            System.Console.Write("###########\r\n\r\n");

            //STOP CAMERA
            try
            {
                if (mDevice.RemoteNodeList.GetNodePresent("AcquisitionAbort") == true)
                {
                    mDevice.RemoteNodeList["AcquisitionAbort"].Execute();
                    System.Console.Write("5.1.12   {0} aborted\r\n", mDevice.Model);
                }

                mDevice.RemoteNodeList["AcquisitionStop"].Execute();
                System.Console.Write("5.1.12   {0} stopped \r\n", mDevice.Model);
                System.Console.Write("\r\n");

                string sExposureNodeName = "";
                if (mDevice.GetRemoteNodeList().GetNodePresent("ExposureTime"))
                {
                    sExposureNodeName = "ExposureTime";
                }
                else if (mDevice.GetRemoteNodeList().GetNodePresent("ExposureTimeAbs"))
                {
                    sExposureNodeName = "ExposureTimeAbs";
                }
                System.Console.Write("         ExposureTime:                   {0} [{1}]\r\n", (double)mDevice.RemoteNodeList[sExposureNodeName].Value, (string)mDevice.RemoteNodeList[sExposureNodeName].Unit);
                if (mDevice.TLType == "GEV")
                {
                    if (mDevice.RemoteNodeList.GetNodePresent("DeviceStreamChannelPacketSize") == true)
                    {
                        System.Console.Write("         DeviceStreamChannelPacketSize:  {0} [bytes]\r\n", (long)mDevice.RemoteNodeList["DeviceStreamChannelPacketSize"].Value);
                    }
                    else
                    {
                        System.Console.Write("         GevSCPSPacketSize:              {0} [bytes]\r\n", (long)mDevice.RemoteNodeList["GevSCPSPacketSize"].Value);
                    }
                    System.Console.Write("         GevSCPD (PacketDelay):          {0} [tics]\r\n", (long)mDevice.RemoteNodeList["GevSCPD"].Value);
                }
                System.Console.Write("\r\n");
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }


            //STOP DataStream acquisition & release buffers
            try
            {
                if (mDataStream.TLType == "GEV")
                {
                    //DataStream Statistics
                    System.Console.Write("         DataStream Statistics \r\n");
                    System.Console.Write("           GoodFrames:            {0}\r\n", (long)mDataStream.NodeList["GoodFrames"].Value);
                    System.Console.Write("           CorruptedFrames:       {0}\r\n", (long)mDataStream.NodeList["CorruptedFrames"].Value);
                    System.Console.Write("           LostFrames:            {0}\r\n", (long)mDataStream.NodeList["LostFrames"].Value);
                    System.Console.Write("           ResendRequests:        {0}\r\n", (long)mDataStream.NodeList["ResendRequests"].Value);
                    System.Console.Write("           ResendPackets:         {0}\r\n", (long)mDataStream.NodeList["ResendPackets"].Value);
                    System.Console.Write("           LostPackets:           {0}\r\n", (long)mDataStream.NodeList["LostPackets"].Value);
                    System.Console.Write("           Bandwidth:             {0}\r\n", (long)mDataStream.NodeList["Bandwidth"].Value);
                    System.Console.Write("\r\n");
                }
                if (mDataStream.TLType == "U3V")
                {
                    //DataStream Statistics
                    System.Console.Write("         DataStream Statistics \r\n");
                    System.Console.Write("           GoodFrames:            {0}\r\n", (long)mDataStream.NodeList["GoodFrames"].Value);
                    System.Console.Write("           CorruptedFrames:       {0}\r\n", (long)mDataStream.NodeList["CorruptedFrames"].Value);
                    System.Console.Write("           LostFrames:            {0}\r\n", (long)mDataStream.NodeList["LostFrames"].Value);
                    System.Console.Write("\r\n");
                }
                //BufferList Information
                System.Console.Write("         BufferList Information \r\n");
                System.Console.Write("           DeliveredCount:        {0}\r\n", (long)bufferList.DeliveredCount);
                System.Console.Write("           UnderrunCount:         {0}\r\n", (long)bufferList.UnderrunCount);
                System.Console.Write("\r\n");

                mDataStream.StopAcquisition();
                System.Console.Write("5.1.12   DataStream stopped \r\n");
                bufferList.DiscardAllBuffers();
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }
            System.Console.Write("\r\n");


            System.Console.Write("RELEASE\r\n");
            System.Console.Write("#######\r\n\r\n");

            //Release buffers
            System.Console.Write("5.1.13   Releasing the resources\r\n");
            try
            {
                while (bufferList.Count > 0)
                {
                    mBuffer = (BGAPI2.Buffer)bufferList.Values.First();
                    bufferList.RevokeBuffer(mBuffer);
                }
                System.Console.Write("         buffers after revoke:    {0}\r\n", bufferList.Count);

                mDataStream.Close();
                mDevice.Close();
                mInterface.Close();
                mSystem.Close();
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                returnCode = (0 == returnCode) ? 1 : returnCode;
                System.Console.Write("ExceptionType:    {0} \r\n", ex.GetType());
                System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
                System.Console.Write("in function:      {0} \r\n", ex.GetFunctionName());
            }

            System.Console.Write("\r\nEnd\r\n\r\n");
            System.Console.Write("Input any number to close the program:\r\n");
            Console.Read();
        }