Example #1
0
        //双击datagrid的事件
        private void RunningInfoGrid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (RunningInfoGrid.SelectedItem == null || RunningInfoGrid.SelectedItem.GetType() != typeof(RunningStatusInfo))
            {
                return;
            }
            //显示图片

            try
            {
                RunningStatusInfo item     = RunningInfoGrid.SelectedItem as RunningStatusInfo;
                RunningStatusInfo itemTemp = new RunningStatusInfo();
                if (!string.IsNullOrEmpty(item.ImagePath))
                {
                    Tools.ShowImage_shimgvw(item.ImagePath);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(Application.Current.Resources.MergedDictionaries.First()["Error opening picture"].ToString() + ex.Message);
                //if (SoftwareInfo.getInstance().Language == "English")
                //{
                //    MessageBox.Show("Error opening picture " + ex.Message);
                //}
                //else
                //{
                //    MessageBox.Show("打开图片出错" + ex.Message);
                //}

                SoftwareInfo.getInstance().WriteLog("RunningInfoGrid_MouseDoubleClick:打开图片出错\n" + ex.ToString());
            }
        }
Example #2
0
        private void ProcessImage()
        {
            while (!Stop)
            {
                try
                {
                    if (!Pause)
                    {
                        IsReady = false;
                        switch (StationState)
                        {
                        case PublicEnum.StationState.Close:
                        case PublicEnum.StationState.Black:
                            //todo
                            //显示黑屏
                            break;

                        case PublicEnum.StationState.Stay:
                            //todo
                            //不动
                            //Thread.Sleep(200);
                            //if (SoftwareInfo.getInstance().IsShowAlarmImage)
                            //{
                            //    if (m_camera != null &&
                            //        !Pause)
                            //    {
                            //        if (m_camera.queueImage.Count > 0)
                            //        {
                            //            //取出图像
                            //            PackedImage tempPackedImage = m_camera.queueImage[0];

                            //            //处理图像
                            //            ProcessImageFunction(tempPackedImage);

                            //            //图像需要销毁
                            //            if (tempPackedImage != null)
                            //            {
                            //                if (tempPackedImage.Image != null)
                            //                    tempPackedImage.Image.Dispose();
                            //            }

                            //            if (m_camera.queueImage.Count > 0)
                            //            {
                            //                m_camera.queueImage.RemoveAt(0);
                            //            }
                            //        }
                            //    }
                            //}
                            break;

                        case PublicEnum.StationState.Show:

                            if (m_camera != null &&
                                !Pause)
                            {
                                Action action = () =>
                                {
                                    PackedImage tempPackedImage = null;

                                    try
                                    {
                                        if (m_camera.queueImage.TryDequeue(out tempPackedImage))
                                        {
                                            if (tempPackedImage != null && tempPackedImage.Image.IsInitialized())
                                            {
                                                HTuple objNum = 0;
                                                HOperatorSet.CountObj(tempPackedImage.Image, out objNum);
                                                if (objNum.I != 1)
                                                {
                                                    SoftwareInfo.getInstance().WriteLog("ProcessImage出错:tempPackedImage 中图像I的值不等于1");
                                                    throw new Exception("ProcessImage出错:tempPackedImage 中图像I的值不等于1");
                                                }

                                                showHoImage(tempPackedImage.Image);
                                                ImageCount++;
                                                if (false && ImageCount % 10 == 0)
                                                {
                                                    string            path = SaveImage(tempPackedImage.Image, "");
                                                    RunningStatusInfo info = new RunningStatusInfo
                                                    {
                                                        Channel   = tempPackedImage.ChannelNo.ToString(),
                                                        CodeValue = tempPackedImage.CodeValue,
                                                        ImagePath = path,
                                                        State     = "ng",
                                                        Time      = DateTime.Now.ToString(),
                                                        Explain   = "ng测试"
                                                    };

                                                    Dispatcher.Invoke(InsertInfo, info);
                                                }
                                            }
                                            else
                                            {
                                                nullCnt++;
                                                SoftwareInfo.getInstance().WriteLog("ProcessImage出错:\n tempPackedImage == null");
                                                if (SoftwareInfo.getInstance().IsStrobe&& nullCnt > 20)
                                                {
                                                    nullCnt = 0;
                                                    //  Global.m_alarmIO.Stop(0);
                                                    MessageBox.Show("ProcessImage出错:\n取图为空,tempPackedImage");
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        throw;
                                    }
                                };

                                action.Invoke();
                            }
                            break;

                        case PublicEnum.StationState.Measure:

                            if (m_camera != null &&
                                !Pause)
                            {
                                if (m_camera.IsGrabError && SoftwareInfo.getInstance().IsStrobe)
                                {
                                    //  Global.m_alarmIO.Stop(0);/////////////////////////////////////////////zy
                                    MessageBox.Show("ProcessImage出错:\n采图出错,tempPackedImage");
                                }
                                if (m_camera.queueImage.Count > 0)
                                {
                                    //取出图像
                                    mutex.WaitOne();
                                    PackedImage tempPackedImage = null;
                                    m_camera.queueImage.TryDequeue(out tempPackedImage);



                                    if (tempPackedImage != null && tempPackedImage.Image.IsInitialized())
                                    {
                                        HTuple objNum = 0;
                                        HOperatorSet.CountObj(tempPackedImage.Image, out objNum);
                                        if (objNum.I != 1)
                                        {
                                            //销毁本次图像
                                            if (tempPackedImage != null)
                                            {
                                                if (tempPackedImage.Image != null)
                                                {
                                                    tempPackedImage.Image.Dispose();
                                                }
                                            }


                                            SoftwareInfo.getInstance().WriteLog("ProcessImage出错:tempPackedImage 中图像I的值不等于1");
                                            break;
                                        }
                                        //是否启用频场校正


                                        //处理图像
                                    }
                                    else
                                    {
                                        nullCnt++;
                                        SoftwareInfo.getInstance().WriteLog("ProcessImage出错:\n tempPackedImage == null");
                                        if (SoftwareInfo.getInstance().IsStrobe&& nullCnt > 20)
                                        {
                                            nullCnt = 0;
                                            //   Global.m_alarmIO.Stop(0);////////////////////////////////////////////////////zy
                                            MessageBox.Show("ProcessImage出错:\n取图为空,tempPackedImage");
                                        }
                                    }


                                    //图像需要销毁
                                    if (tempPackedImage != null)
                                    {
                                        if (tempPackedImage.Image != null)
                                        {
                                            tempPackedImage.Image.Dispose();
                                        }
                                    }


                                    //    mutex.ReleaseMutex();

                                    //触发缓存图像报警
                                    if (SoftwareInfo.getInstance().IsCacheImageAlarm&& m_camera.queueImage.Count > SoftwareInfo.getInstance().CacheAlarmNumer)
                                    {
                                        if (InsertInfo != null)
                                        {
                                            RunningStatusInfo info = new RunningStatusInfo();
                                            info.Time    = DateTime.Now.ToString("HH:mm:ss");
                                            info.Channel = Global.ProductChannelArray[ChannelNo].ChannelName;
                                            info.Station = (StationNo + 1).ToString();

                                            info.State   = "产品运行速度与检测速度不匹配!";
                                            info.Explain = "请检查产品运行速度是否过快!";
                                            Dispatcher.Invoke(InsertInfo, info);
                                        }

                                        if (alarmFunction != null)
                                        {
                                            Object[] arg = new Object[] { ChannelNo, StationNo, m_camera.AlarmDelayTime, AlarmType.Measure };
                                            Dispatcher.Invoke(alarmFunction, arg);
                                            // Global.m_alarmIO.Stop(ChannelNo);/////////////////////////////////////////////////////////////zy

                                            if (SoftwareInfo.getInstance().IsAlarmDeviceStop)
                                            {
                                                // Global.m_alarmIO.CacheImageAlarmStop(ChannelNo);////////////////////////////////////////////zy
                                            }
                                        }
                                    }
                                }
                            }
                            break;

                        case PublicEnum.StationState.Ajust:
                            //Thread.Sleep(200);
                            //todo
                            break;
                        }


                        IsReady = true;
                    }
                    //刷新数字
                    // Dispatcher.Invoke(new Action(RefreshInformation));///////////////////////////////////////zy
                }
                catch (Exception ex)
                {
                    SoftwareInfo.getInstance().WriteLog("ProcessImage出错:\n" + ex.ToString());
                    Console.WriteLine("ProcessImage出错:" + ex.Message);
                }
                finally
                {
                }
                DispatcherHelper.DoEvents();
                Thread.Sleep(50);
            }
        }
Example #3
0
 //插入一条数据
 public void InsertRunningInfo(RunningStatusInfo info)
 {
     RunningStatusInfoList.Insert(0, info);
 }