Beispiel #1
0
        public void Run(ref ICogImage cogImage, int nFlipRotation)
        {
            // 2013.05.03
            try
            {
                m_nAcqCount++;

                if (nFlipRotation == 0)
                {
                    //Acquire(cogDisplay);
                    // 2015.04.08
                    m_bRan = false;

                    m_cogAcqFifoTool.Run();

                    // 2015.04.08
                    WaitRanEvent();

                    if (m_cogAcqFifoTool.OutputImage != null)
                    {
                        cogImage = m_cogAcqFifoTool.OutputImage;

#if !_USE_TRIGGER_ACQ
                        // 2017.11.16 by kdi.
                        m_cogImageTrigger = cogImage;
                        AUtil.PostMessage(m_hMain, _WM_ACQFIFO_COMPLETE, m_nPoint, m_nSection);
#endif
                    }
#if !_USE_TRIGGER_ACQ
                    else
                    {
                        cogImage = null;

                        //var property = m_cogAcqFifoTool.RunStatus.Exception.GetType().GetProperty("HResult", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                        //var value = property.GetValue(m_cogAcqFifoTool.RunStatus.Exception, null);

                        int nHResult = System.Runtime.InteropServices.Marshal.GetHRForException(m_cogAcqFifoTool.RunStatus.Exception);
                        //if (m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE) == true ||
                        //    m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE2) == true ||
                        //    m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE3) == true
                        //    )
                        //** to do:
                        //  1. 네트워크 단절 에러와 일반 예외 값이 동일한지 확인 필요
                        //      동일한 값을 가진다면, 이 조건을 적용할 수 없음
                        if ((UInt32)nHResult == (UInt32)0x80131600)     // Application Exception
                        {
                            // ip address
                            System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse(m_cogAcqFifoTool.Operator.FrameGrabber.OwnedGigEAccess.CurrentIPAddress);
                            int intAddress = BitConverter.ToInt32(ipaddress.GetAddressBytes(), 0);

                            //AUtil.PostMessage(m_hMain, ASDef._WM_CAMERA_IS_DISCONNECTED, m_nPoint, intAddress);
                            AUtil.PostMessage(m_hMain, clsCamera._WM_CAMERA_IS_DISCONNECTED, m_nPoint, intAddress);
                        }

                        string strMsg = "";
                        strMsg     = string.Format("AAcqFifo.Run: Error. {0}", m_cogAcqFifoTool.RunStatus.Message);
                        m_strError = strMsg;
                        AVisionProBuild.WriteLogFile(strMsg, ".AcqFifo.err.txt");
                    }
#endif

                    return;
                }

                // 2015.04.08
                m_bRan = false;
                //DateTime Now = DateTime.Now;

                m_cogAcqFifoTool.Run();

                // 2015.04.08
                WaitRanEvent();

                //TimeSpan span  = DateTime.Now - Now;

                if (m_cogAcqFifoTool.OutputImage != null)
                {
                    // 2011.07.29
                    CogIPOneImageFlipRotate cogIPOneImageFlipRotate = new CogIPOneImageFlipRotate();
                    cogIPOneImageFlipRotate.OperationInPixelSpace = (CogIPOneImageFlipRotateOperationConstants)nFlipRotation;

                    // 2012.04.25
                    ICogImage cogImageFR = cogIPOneImageFlipRotate.Execute(m_cogAcqFifoTool.OutputImage, CogRegionModeConstants.PixelAlignedBoundingBox, null);
                    Bitmap    Bmp        = cogImageFR.ToBitmap();
                    if ((Bmp.Flags & (16 | 32 | 64 | 128 | 256)) != 0)
                    {
                        cogImage = new CogImage24PlanarColor(Bmp);
                    }
                    else
                    {
                        cogImage = new CogImage8Grey(Bmp);
                    }

#if !_USE_TRIGGER_ACQ
                    // 2017.11.16 by kdi.
                    m_cogImageTrigger = cogImage;
                    AUtil.PostMessage(m_hMain, _WM_ACQFIFO_COMPLETE, m_nPoint, m_nSection);
#endif

                    // 2012.06.06
                    if (Bmp != null)
                    {
                        Bmp.Dispose();
                        Bmp = null;
                    }
                }
#if !_USE_TRIGGER_ACQ
                else
                {
                    cogImage = null;

                    int nHResult = System.Runtime.InteropServices.Marshal.GetHRForException(m_cogAcqFifoTool.RunStatus.Exception);
                    //if (m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE) == true ||
                    //       m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE2) == true ||
                    //       m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE3) == true
                    //       )
                    //** to do:
                    //  1. 네트워크 단절 에러와 일반 예외 값이 동일한지 확인 필요
                    //      동일한 값을 가진다면, 이 조건을 적용할 수 없음
                    if ((UInt32)nHResult == (UInt32)0x80131600)    // Application Exception
                    {
                        // 2018.04.09
                        //AUtil.PostMessage(m_hMain, ASDef._WM_CAMERA_IS_DISCONNECTED, m_nPoint, 0);
                        AUtil.PostMessage(m_hMain, clsCamera._WM_CAMERA_IS_DISCONNECTED, m_nPoint, 0);
                    }

                    string strMsg = "";
                    strMsg     = string.Format("AAcqFifo.Run: Error. {0}", m_cogAcqFifoTool.RunStatus.Message);
                    m_strError = strMsg;
                    AVisionProBuild.WriteLogFile(strMsg, ".AcqFifo.err.txt");
                }
#endif


                /*
                 * ICogImage cogImageFR = cogIPOneImageFlipRotate.Execute(m_cogAcqFifoTool.OutputImage, CogRegionModeConstants.PixelAlignedBoundingBox, null);
                 *
                 * lock (m_cogImageFile)
                 * {
                 *  string strFName = "c:\\" + AVisionProBuild.MakeName("Flip", DateTime.Now) + ".bmp";
                 *  m_cogImageFile.Open(strFName, CogImageFileModeConstants.Write);
                 *  m_cogImageFile.Append(cogImageFR);
                 *  m_cogImageFile.Close();
                 *  m_cogImageFile.Open(strFName, CogImageFileModeConstants.Read);
                 *  cogImage = m_cogImageFile[0];
                 *  m_cogImageFile.Close();
                 *  File.Delete(strFName);
                 * }
                 */
            }
            catch (CogException ex)
            {
                cogImage          = null;
                m_cogImageTrigger = cogImage;

#if !_USE_TRIGGER_ACQ
                if (ex.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE) == true ||
                    ex.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE2) == true)
                {
                    // 2018.04.09
                    //AUtil.PostMessage(m_hMain, ASDef._WM_CAMERA_IS_DISCONNECTED, m_nPoint, 0);
                    AUtil.PostMessage(m_hMain, clsCamera._WM_CAMERA_IS_DISCONNECTED, m_nPoint, 0);
                }

                string strMsg = "";
                strMsg     = string.Format("AAcqFifo.Run: CogException. {0}", ex.Message);
                m_strError = strMsg;
                AVisionProBuild.WriteLogFile(strMsg, ".AcqFifo.err.txt");
#endif
            }
            catch
            {
                cogImage = null;
            }
        }
Beispiel #2
0
        public string SaveImage(ICogImage Image, string Name = " ")
        {
            this.UseCognex = !this.SaveImageUI.UseCognex;
            string allPath = "";

            if (!this.UseCognex)
            {
                Bitmap    bitmap    = (Bitmap)Image.ToBitmap().Clone();
                Rectangle rectangle = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                Bitmap    bitmap1   = bitmap.Clone(rectangle, PixelFormat.Format8bppIndexed);
                if (this.mySaveImageUI.ImageFormatJPG & this.IsDiskSpaceEnough(this.GetAllPath(Name, "jpg"), (long)500000000))
                {
                    this.AddImageQueue(this.GetAllPath(Name, "jpg"), bitmap1);
                    this.AddImageQueue(this.GetAllPath(Name, "jpg"), bitmap);
                    allPath = this.GetAllPath(Name, "jpg");
                }
                if (this.mySaveImageUI.ImageFormatBMP & this.IsDiskSpaceEnough(this.GetAllPath(Name, "bmp"), (long)500000000))
                {
                    this.AddImageQueue(this.GetAllPath(Name, "bmp"), bitmap1);
                    this.AddImageQueue(this.GetAllPath(Name, "bmp"), bitmap);
                    allPath = this.GetAllPath(Name, "bmp");
                }
            }
            else
            {
                if (this.mySaveImageUI.ImageFormatJPG & this.IsDiskSpaceEnough(this.GetAllPath(Name, "jpg"), (long)500000000))
                {
                    this.AddImageQueue(this.GetAllPath(Name, "jpg"), Image);
                    allPath = this.GetAllPath(Name, "jpg");
                }
                if (this.mySaveImageUI.ImageFormatBMP & this.IsDiskSpaceEnough(this.GetAllPath(Name, "bmp"), (long)500000000))
                {
                    this.AddImageQueue(this.GetAllPath(Name, "bmp"), Image);
                    allPath = this.GetAllPath(Name, "bmp");
                }
            }
            if (!this.IsDiskSpaceEnough(this.GetAllPath(Name, "bmp"), (long)500000000))
            {
                try
                {
                    var deletePath = Path.Combine(mySaveImageUI.ImageSavePathEdit, GetFirstDay(mySaveImageUI.ImageSavePathEdit));
                    if (Directory.Exists(deletePath))
                    {
                        Directory.Delete(deletePath, true);
                    }
                    ;
                }
                catch (Exception ex)
                {
                }
                return("Err!磁盘空间不足,未保存图像 Image save Error,Disk free space is not enough");
            }
            if (deleteMark != DateTime.Now.ToString("yyMMdd"))
            {
                try
                {
                    var dayPaths = GetOverSevernDays(mySaveImageUI.ImageSavePathEdit);
                    dayPaths.ForEach(dayPath =>
                    {
                        var deletePath2 = Path.Combine(mySaveImageUI.ImageSavePathEdit, dayPath.Name);
                        if (Directory.Exists(deletePath2))
                        {
                            Directory.Delete(deletePath2, true);
                        }
                        ;
                    });
                    deleteMark = DateTime.Now.ToString("yyMMdd");
                }
                catch (Exception ex)
                {
                }
            }
            return(allPath);
        }