Esempio n. 1
0
        void connectCam(string _interfacename, string _device)
        {
            _status_connect_cam = false;
            if (Framgraber != null)
            {
                Framgraber.Dispose();
            }

            Framgraber = new HFramegrabber(_interfacename, 0, 0, 0, 0, 0, 0, "progressive",
                                           -1, "default", -1, "default", _interfacename == "File" ? _device : "default", _interfacename == "File" ? "default" : _device, 0, -1);
            if (_interfacename == "GigE")
            {
                HOperatorSet.SetFramegrabberParam(Framgraber, "ExposureTime", 150000);
                HOperatorSet.SetFramegrabberParam(Framgraber, "Gain", 1);
                HOperatorSet.SetFramegrabberParam(Framgraber, "grab_timeout", 60000);
            }
            _status_connect_plc = true;

            Img = Framgraber.GrabImageAsync(1);
            Img.GetImagePointer1(out HTuple typeImg, out HTuple WidthImg, out HTuple HeightImg);
            HTuple a = 0;

            window.SetPart(a, a, HeightImg - 1, WidthImg - 1);
            Img.Dispose();
        }
        public GrabberEventViewModel Connect()
        {
            var viewModel = new GrabberEventViewModel()
            {
                Result = new GrabberEventResult()
                {
                    State = GrabberEventState.Busy,
                    Error = new Exception(),
                    Model = null
                },
                ReportHandler = On_ConnectReport
            };

            try
            {
                setHFramegrabber();

                viewModel.Result.State = GrabberEventState.Done;
            }
            catch (Exception ex)
            {
                viewModel.Result.Error = ex;
                Hanbo.Log.LogManager.Debug("Connect Exception:" + ex.Message);
                Hanbo.Log.LogManager.Debug("Connect StackTrace:" + ex.StackTrace);
            }
            finally
            {
                if (_hFrameGrabber != null)
                {
                    _hFrameGrabber.Dispose();
                }
            }
            return(viewModel);
        }
Esempio n. 3
0
 private void StopBtn_Click(object sender, EventArgs e)
 {
     StopBtn.Enabled      = false;
     shotComboBox.Enabled = true;
     Savebtn.Enabled      = false;
     Framegrabber.Dispose();
 }
Esempio n. 4
0
        /// <summary>
        /// Releases all resources used by the Component.
        /// Stops the grabbing of images, closes the connection
        /// to the device and release the object, that is responsible
        /// for the device connection and image acquisition.
        /// </summary>
        new public void Dispose()
        {
            try
            {
                if (GrabOn)
                {
                    StopGrabThread();
                }

                CloseDevice();

                if (frameGrabber != null)
                {
                    frameGrabber.Dispose();
                }
                if (img != null)
                {
                    img.Dispose();
                }
            }
            finally
            {
                if (frameGrabber != null)
                {
                    frameGrabber.Dispose();
                }
            }
            base.Dispose();
        }
 /// <summary>
 /// 中斷連線
 /// </summary>
 public void DisConnection()
 {
     _bgworker.CancelAsync();
     if (_hFrameGrabber != null)
     {
         _hFrameGrabber.Dispose();
         Status.IsConnection = false;
         statusChangedNotify(null, new GrabImageStatusChangedEventArgs()
         {
             Status = new WorkingManStatus()
             {
                 Instruction = GrabInstruction.DisConnect, Stage = GrabStage.Closed, State = GrabState.Idle
             }
         });
     }
 }
Esempio n. 6
0
 void connectCam(string _interfacename, string _device)
 {
     if (Framgraber != null)
     {
         Framgraber.Dispose();
     }
     try
     {
         Framgraber = new HFramegrabber(_interfacename, 0, 0, 0, 0, 0, 0, "progressive",
                                        -1, "default", -1, "default", _interfacename == "File" ? _device : "default", _interfacename == "File" ? "default" : _device, 0, -1);
         if (_interfacename == "GigE")
         {
             HOperatorSet.SetFramegrabberParam(Framgraber, "ExposureTime", 150000);
             HOperatorSet.SetFramegrabberParam(Framgraber, "Gain", 1);
             HOperatorSet.SetFramegrabberParam(Framgraber, "grab_timeout", 60000);
         }
         _Img = Framgraber.GrabImageAsync(1);
         _Img.GetImagePointer1(out HTuple typeImg, out HTuple WidthImg, out HTuple HeightImg);
         HTuple a = 0;
         _window.SetPart(a, a, HeightImg - 1, WidthImg - 1);
         _Img.Dispose();
     }
     catch (Exception ex)
     {
         MessageBox.Show(" Connnection Camera Error: " + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         dataerror = true;
     }
 }
Esempio n. 7
0
        private void ExecuteBtn_Click(object sender, System.EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            HFramegrabber Framegrabber = new HFramegrabber();

            // read images and process them
            try
            {
                Framegrabber.OpenFramegrabber("File", 1, 1, 0, 0, 0, 0, "default",
                                              -1, "default", -1, "default", "fin.seq", "default", -1, -1);

                HImage  Image = new HImage();
                HRegion FinRegion;
                HTuple  FinArea;

                for (int i = 0; i <= 2; i++)
                {
                    Image.GrabImage(Framegrabber);
                    Image.DispObj(Window);

                    // execute procedure
                    ProcCall.SetInputIconicParamObject("Image", Image);
                    ProcCall.Execute();
                    // get output parameters from procedure call
                    FinRegion = ProcCall.GetOutputIconicParamRegion("FinRegion");
                    FinArea   = ProcCall.GetOutputCtrlParamTuple("FinArea");

                    // display results
                    Image.DispObj(Window);
                    Window.SetColor("red");
                    Window.DispObj(FinRegion);
                    Window.SetColor("white");
                    Window.SetTposition(150, 20);
                    Window.WriteString("FinArea: " + FinArea.D);
                    HSystem.WaitSeconds(2);

                    FinRegion.Dispose();
                    Image.Dispose();
                }
            }
            catch (HOperatorException Ex)
            {
                MessageBox.Show(Ex.Message, "HALCON Exception");
            }
            catch (HDevEngineException Ex)
            {
                MessageBox.Show(Ex.Message, "HDevEngine Exception");
            }

            Framegrabber.Dispose();

            this.Cursor = Cursors.Default;
        }
Esempio n. 8
0
 private void setCamera()
 {
     if (topView != null)
     {
         topView.Dispose();
         topView = new HFramegrabber();
     }
     if (bottomView != null)
     {
         bottomView.Dispose();
         bottomView = new HFramegrabber();
     }
     if (engMode == true)
     {
         topView.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb", -1, "false", "default", "[0] Integrated Webcam", 0, -1);
     }
     else
     {
         bottomView.OpenFramegrabber("GigEVision2", 0, 0, 0, 0, 0, 0, "progressive", -1, "default", -1, "false", "default", "licenseCam", 0, -1);
         //topView.OpenFramegrabber("GigEVision2", 0, 0, 0, 0, 0, 0, "progressive", -1, "default", -1, "false", "default", "containerCam", 0, -1);
     }
 }
        public override void Close()
        {
            try
            {
                IsLink = false;


                // Reset the stopwatch.
                stopWatch.Reset();
                framegrabber.Dispose();
            }
            catch (Exception ex)
            {
                Util.WriteLog(this.GetType(), ex);
                Util.Notify("相机关闭异常");
            }
        }
 public override void Close()
 {
     try
     {
         IsLink = false;
         threadRunSignal.Set();
         // Reset the stopwatch.
         //stopWatch.Reset();
         if (framegrabber != null)
         {
             framegrabber.Dispose();
             framegrabber = null;
         }
     }
     catch (Exception ex)
     {
         Util.WriteLog(this.GetType(), ex);
         Util.Notify("相机关闭异常");
     }
 }
Esempio n. 11
0
        //////////////////////////////////////////////////////////////////////////////
        // FGRun() - The thread functionFGRun is in charge of the asynchronous
        //           grabbing. To pass the images to the  other threads, we use
        //           a list. In case  the list exceeds a certain length, because
        //           the processing thread is slower then the grabbing thread,
        //           we omit new images until the list decreases again.
        //           To prevent data races, weuse a mutex to assure mutual
        //           access to the image list.
        //////////////////////////////////////////////////////////////////////////////
        public void ImgAcqRun()
        {
            // -------------------  INIT ----------------

            string sequenceName = "datacode/ecc200/ecc200.seq";

            HFramegrabber acquisition = new HFramegrabber("File", 1, 1, 0, 0, 0, 0,
                                                          "default", -1, "default", -1, "default", sequenceName, "default", -1, -1);

            // -----------  WAIT FOR EVENTS  ---------------

            while (true)
            {
                HImage grabbedImage = acquisition.GrabImageAsync(-1);

                newImgMutex.WaitOne();           // CriticalSect
                if (imgList.Count < MAX_BUFFERS) // CriticalSect
                {                                // CriticalSect
                    imgList.Add(grabbedImage);
                }
                else
                {
                    grabbedImage.Dispose();
                }                             // CriticalSect
                newImgMutex.ReleaseMutex();   // CriticalSect

                newImgEvent.Set();

                if (delegatedStopEvent.WaitOne(0, true))
                {
                    break;
                }
            }

            // --------  RESET/CLOSE ALL HANDLES  ---------

            acquisition.Dispose();
            newImgEvent.Reset();

            return;
        }
Esempio n. 12
0
        private void btnConectaCam_Click(object sender, EventArgs e)
        {
            if (Framgraber != null)
            {
                Framgraber.Dispose();
            }
            _interfacename = cbxInterface.SelectedItem.ToString();
            _device        = cbxCamera.SelectedItem.ToString();
            Framgraber     = new HFramegrabber(_interfacename, 0, 0, 0, 0, 0, 0, "progressive",
                                               -1, "default", -1, "default", _interfacename == "File" ? _device : "default", _interfacename == "File" ? "default" : _device, 0, -1);


            //Framgraber = new HFramegrabber(_interfacename, 0, 0, 0, 0, 0, 0, "progressive", -1, "default", -1, "default",
            //   _interfacename == "file" ? "default" : _device, _interfacename == "file" ? _device : "default", 0, -1);

            Img = Framgraber.GrabImageAsync(1);
            Img.GetImagePointer1(out HTuple typeImg, out HTuple WidthImg, out HTuple HeightImg);
            HTuple a = 0;

            //Window.SetPart(a , a, WidthImg - 1, HeightImg - 1);
            window.SetPart(a, a, WidthImg - 1, HeightImg - 1);
            Img.Dispose();
        }
Esempio n. 13
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            //------------------------------------------------------------
            // Kiểm tra lệnh kết nối hay ngắt kết nối
            //------------------------------------------------------------
            if (CameraConnected)
            {
                MainFrameGrabber.Dispose();
                btnConnect.Text = "  Connect";
                CameraConnected = false;
                return;
            }
            //------------------------------------------------------------
            // Lấy giá trị device và generic cho hàm kết nối camera
            //------------------------------------------------------------
            bool   isFileInterface     = false;
            string regexDevicePattern  = @"(device:)(.+?)(\s\|)";
            string regexGenericPattern = @"(suggestion:)(.+)(\s\|)";
            string deviceInfo          = cbDevices.SelectedItem.ToString();
            string device = Regex.Match(deviceInfo, regexDevicePattern).Groups[2].Value;

            if (device.Length < 3)
            {
                device = "default";
            }
            HTuple generic;

            if (deviceInfo.Contains("misconfigured"))
            {
                generic = Regex.Match(deviceInfo, regexGenericPattern).Groups[2].Value;
            }
            else
            {
                generic = new HTuple(-1);
            }
            //------------------------------------------------------------
            // Check if is File Interface
            //------------------------------------------------------------
            string interfaceName = cbInterfaces.SelectedItem.ToString();

            if (interfaceName == "File")
            {
                isFileInterface = true;
            }
            if (!isFileInterface)
            {
                try
                {
                    MainFrameGrabber = new HFramegrabber(interfaceName, 1, 1, 0, 0, 0, 0, "default",
                                                         new HTuple(-1), new HTuple("default"), generic,
                                                         "default", new HTuple("default"), new HTuple(device),
                                                         new HTuple(-1), new HTuple(-1));
                }
                catch
                {
                    return;
                }
                try
                {
                    //------------------------------------------------------------
                    // Lấy giá trị Gain, Exposure từ Camera
                    //------------------------------------------------------------
                    HTuple gain         = MainFrameGrabber.GetFramegrabberParam("Gain");
                    HTuple exposureTime = MainFrameGrabber.GetFramegrabberParam("ExposureTime");
                    //------------------------------------------------------------
                    // Hiển thị lên ô cài đặt
                    //------------------------------------------------------------
                    txtGainValue.Text     = gain.D.ToString();
                    txtExposureValue.Text = exposureTime.D.ToString();
                    //------------------------------------------------------------
                    // Thay đổi trạng thái kết nối
                    //------------------------------------------------------------
                    btnConnect.Text = "  Connected";
                    CameraConnected = true;
                    //------------------------------------------------------------
                    // Cập nhật CameraSet
                    //------------------------------------------------------------
                    CurrentCameraSet.Device  = device;
                    CurrentCameraSet.Generic = generic;
                }
                catch (Exception ex) { }
            }
            else
            {
                MainFrameGrabber = null;
            }
            //------------------------------------------------------------
            // Set Window display image
            //------------------------------------------------------------
            string ImgType;
            int    ImgWidth, ImgHeight;
            HImage Img;

            Img = MainFrameGrabber.GrabImageAsync(1);
            Img.GetImagePointer1(out ImgType, out ImgWidth, out ImgHeight);
            MainWindow.SetPart(0, 0, ImgHeight - 1, ImgWidth - 1);
            Img.DispObj(MainWindow);
            Img.Dispose();
        }
Esempio n. 14
0
        private void StartBtn_Click(object sender, System.EventArgs e)
        {
            Framegrabber = new HFramegrabber();
            // read images and process them
            try
            {
                //Framegrabber.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb", -1, "false", "default", "[0] USB2.0 HD UVC WebCam", 0, -1);


                Framegrabber.OpenFramegrabber("GigEVision", 0, 0, 0, 0, 0, 0, "default", -1, "default", -1,
                                              "false", "default", "003053231ec3_basler_aca250014gm", 0, -1);
                Framegrabber.SetFramegrabberParam("AcquisitionMode", "SingleFrame");
                HImage  Image = new HImage();
                HRegion CirclesRegion;

                int shot;
                shot = Int32.Parse(shotComboBox.SelectedItem + "");

                // execute procedure
                ProcCall.SetInputCtrlParamTuple("shot", shot);
                ProcCall.Execute();
                // get output parameters from procedure call
                CirclesRegion = ProcCall.GetOutputIconicParamRegion("RegionOfInterest");
                //LightCheck = ProcCall.GetOutputIconicParamRegion("RegionOfInterest");



                StartBtn.Enabled     = false;
                shotComboBox.Enabled = false;
                Savebtn.Enabled      = true;
                StopBtn.Enabled      = true;
                while (true)
                {
                    if (!StopBtn.Enabled)
                    {
                        StartBtn.Enabled = true;
                        StopBtn.Enabled  = false;
                        Framegrabber.Dispose();
                        Image.Dispose();
                        return;
                    }
                    //Framegrabber.GrabImageStart(-1);
                    Image = Framegrabber.GrabImageAsync(-1);

                    // display results
                    Image.DispObj(Window);
                    Window.SetColor("red");
                    Window.DispObj(CirclesRegion);
                    Window.SetPart(0, 0, -2, -2);

                    HSystem.WaitSeconds(0.108);
                }
            }
            catch (HOperatorException Ex)
            {
                MessageBox.Show(Ex.Message, "HALCON Exception");
            }
            catch (HDevEngineException Ex)
            {
                MessageBox.Show(Ex.Message, "HDevEngine Exception");
            }

            Framegrabber.Dispose();
        }
Esempio n. 15
0
        /**
         * Clean up an exit the program.
         *
         * @param acq Acquisition handle.
         * @param callbackTpye Registered callback.
         * @param waiting Activate waiting for user interaction.
         */
        static void exitProgram(ref HFramegrabber acq, string callbackType,
                                bool waiting)
        {
            if (waiting)
            {
                waitUserInteraction();
            }

            if (null == acq)
            {
                System.Environment.Exit(1);
            }

            // Unregister the callback.
            if (null != callbackType)
            {
                try
                {
                    IntPtr currentCallback, context;
                    currentCallback =
                        acq.GetFramegrabberCallback(callbackType, out context);
                    // Already unregistered?
                    if (IntPtr.Zero != currentCallback)
                    {
                        acq.SetFramegrabberCallback(callbackType, IntPtr.Zero, IntPtr.Zero);
                    }
                }
                catch (HalconException exc)
                {
                    Console.WriteLine(exc.GetErrorMessage());
                }
            }

            // Abort the workerThread.
            if (gThreadRunning)
            {
                try
                {
                    // abort the current grab.
                    acq.SetFramegrabberParam("do_abort_grab", 1);
                }
                catch (HalconException exc)
                {
                    Console.WriteLine(exc.GetErrorMessage());
                }
                gAcqMutex.LockMutex();
                gThreadRunning = false;
                gAcqCondition.SignalCondition();
                gAcqMutex.UnlockMutex();
                gThreadHandle.Join();
            }

            try
            {
                // Close the framegrabber.
                acq.Dispose();
                // Clean up.
                gAcqMutex.Dispose();
                gAcqCondition.Dispose();
            }
            catch (HalconException exc)
            {
                Console.WriteLine(exc.GetErrorMessage());
            }

            System.Environment.Exit(1);
        }