/// <summary>
        /// Manual Triggerring
        /// </summary>
        /// <param name="manualLive"></param>
        /// <returns></returns>
        public override object Acquire(bool manualLive)
        {
            if (_cogAcqFifo == null)
            {
                //if (SimFileName !="" && File.Exists(SimFileName))
                //{
                //    return Bitmap.FromFile(SimFileName);
                //}
                return(null);
            }

            ICogImage cogImage = null;

            StopLiveAllCameraWindows();
            if (ExternalTrigger)
            {
                if (!manualLive)
                {
                    TriggerMode = eTriggerMode.Idle;
                }
                _waitForImage.Reset();
                FireTrigger();
                try
                {
                    // Wait for response
                    U.BlockOrDoEvents(_waitForImage, 2000);
                    cogImage = _lastCogImage;
                }
                catch (Exception ex)
                {
                    U.LogError(ex, "Image Acquisition error");
                }
            }
            else
            {
                try
                {
                    System.Threading.Thread.Sleep(1);
                    int ticket = -1;
                    lock (_lockAcqFifo)
                    {
                        ticket = _cogAcqFifo.StartAcquire();
                    }
                    cogImage = WaitForImage(ticket);
                }
                catch (Exception ex)
                {
                    U.LogError(ex, "Cognex Acquisition Error");
                }
                D.ObjectEventHandler delCallback = GetNextCallback();
                if (delCallback != null)
                {
                    delCallback(cogImage);
                }
            }
            AssignImageToWindows(cogImage);

            return(cogImage);
        }
예제 #2
0
        /// <summary>
        /// Manual Grab Image
        /// </summary>
        public bool GrabManual(bool waitComplete)
        {
            bool Status = false;
            int  trigNum, completeTicket;
            int  retry = 0;

            while (retry < 3)// if something wrong during image capturing retry 3 times;
            {
                if (cogAcqFifo != null)
                {
                    if (this.cogAcqTrigger != null)
                    {
                        if (this.cogAcqTrigger.TriggerModel != CogAcqTriggerModelConstants.Manual)
                        {
                            // Select manual trigger mode
                            this.cogAcqTrigger.TriggerEnabled = false;
                            this.cogAcqTrigger.TriggerModel   = CogAcqTriggerModelConstants.Manual;
                            this.cogAcqTrigger.TriggerEnabled = true;
                        }

                        // Acquire an image
                        try
                        {
                            // Acquire an image
                            acqTicket = cogAcqFifo.StartAcquire();

                            if (waitComplete)
                            {
                                grabImage = this.cogAcqFifo.CompleteAcquire(this.acqTicket,
                                                                            out completeTicket,
                                                                            out trigNum) as CogImage8Grey;
                                numGCAcqs++;
                                // do GC every COGFRAMENUM
                                if (this.numGCAcqs >= 4)
                                {
                                    GC.Collect();
                                    numGCAcqs = 0;
                                }
                            }
                            Status = true;
                        }
                        catch (Exception ex)
                        {
                            retry++;
                            Log.Warn(this, "cogAcqFifo Acquire error: {0}, Retry:{1}", ex.Message, retry);
                            Thread.Sleep(2000);
                        }
                    }
                }
                else
                {
                    break;
                }
                if (Status)
                {
                    break;
                }
            }//while loop

            return(Status);
        }