Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Closing a session in NI IMAQ immediately

Dear all,

 

I would like to terminate my prog during image ackquisition.

My problem is that when I try to shut down the grabbing I have to wait many seconds for waiting the timeout set in the camera file.

Is there any way to close a session immediately ?

Reducing the timeout is not good for me.

 

 

 

 

This is an extract of my code (VS2008 C#)

 

        private void Cleanup()
        {
            if (_session != null)
            {
                // Close the session.
                _session.Stop();   // this waits for the frame timeout
                _session.Close();
                _session = null;
            }
        }

 

 

        // image ackquisition thread function

        public void DoWork()
        {
            try
            {
                if (!shouldStop) InitCamera();

                if (!shouldStop && motorOK && !simulateMotor)
                {
                    lock (_motors) _motors._cameraMotor.MoveAbs(_startpos);
                    WaitForMotorStop(30000);
                }

                if (!shouldStop && motorOK && !simulateMotor)
                {
                    lock (_motors)
                    {
                        _motors._cameraMotor.InitMotionTrigger(_trigdir, _trigpos, _trigstep);
                    }
                }

                if (!shouldStop && cameraOK && !simulateCamera)
                {
                    //  Get the latest image.
                    try { _session.Acquisition.AcquireAsync(); }
                    catch { }
                }

                if (!shouldStop && motorOK && !simulateMotor)
                {
                    lock (_motors) _motors._cameraMotor.MoveAbs(_stoppos);
                    WaitForMotorStop(30000);
                }

                if (!shouldStop && cameraOK && !simulateCamera)
                {
                    try
                    {
                        uint last = 0;
                        do
                        {
                            Application.DoEvents();
                            _session.GetStatus(out last);
                        } while (!shouldStop && last != 0);
                        if (!shouldStop)
                        {
                            _imageViewer.DisplayMapping.MapFullDynamicRange();
                            _session.Acquisition.Copy(last, ImaqOverwriteMode.GetNewest, _imageViewer.Image);
                        }
                    }
                    catch (Exception ex) { MessageBox.Show(ex.Message, "Pixel Conversion Error"); }
                }

                // start image processing thread here

                //ImageProcessing.Process(_imageViewer.Image, ref _imageViewer1);


                if (cameraOK && !simulateCamera)
                    Cleanup();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); }
        }

 

0 Kudos
Message 1 of 2
(2,932 Views)
I'm not sure if this will work in C#, but in LabVIEW, all you have to do is close the session from a different, asynchronously running VI. So in C#, you might try closing the session from a different thread.

View my profile on LinkedIn
0 Kudos
Message 2 of 2
(2,909 Views)