04-27-2010 03:52 AM
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"); }
}
04-28-2010 08:36 AM