示例#1
0
        /// <summary>
        /// 写文件,编码值清0记录
        /// </summary>
        /// <param name="str"></param>
        public static void WriteClrEncoderLog(int channelNo, string str)
        {
            try
            {
                string path    = SoftwareInfo.getInstance().OriginImagePath + "\\标记异常\\" + DateTime.Now.ToString("yyyy-MM-dd");
                string pathtxt = path + "\\编码值清0记录表.txt";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                using (StreamWriter sw = new StreamWriter(pathtxt, true))
                {
                    if (channelNo == 0)
                    {
                        sw.WriteLine("编码值清0;清0值:" + str + UnitStr + ";时间:" + DateTime.Now.ToString("HH-mm-ss-fff"));
                    }
                    else
                    {
                        sw.WriteLine("编码值清0;清0值:" + str + UnitStr1 + ";时间:" + DateTime.Now.ToString("HH-mm-ss-fff"));
                    }
                    sw.Close();
                }
            }
            catch
            { }
        }
示例#2
0
        //HalconDotNet.HWindowControl hWindControl4 = null;
        #endregion

        public void showHoImage(HObject hoImage)
        {
            try
            {
                if (hoImage != null && hoImage.IsInitialized())
                {
                    HOperatorSet.DispObj(hoImage, hWindControl1.HalconWindow);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(Application.Current.Resources.MergedDictionaries.First()["Error displaying real-time images"].ToString() + e.Message);

                //if (SoftwareInfo.getInstance().Language == "English")
                //{
                //    MessageBox.Show("Error displaying real-time images" + e.Message);
                //}
                //else
                //{
                //    //MessageBox.Show("显示实时图像出错" + e.Message);
                //    Console.WriteLine("显示实时图像出错" + e.Message);
                //}

                SoftwareInfo.getInstance().WriteLog("showHoImage:显示实时图像出错\n" + e.ToString());
            }
        }
示例#3
0
        public LightControlConfig()
        {
            lightControlList = new List <LightControl>();

            string lightcontrolpath = SoftwareInfo.getInstance().IsUserCamParaTips;

            System.Xml.Linq.XElement root = null;

            try
            {
                root = System.Xml.Linq.XDocument.Load(lightcontrolpath).Root;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            System.Xml.Linq.XElement controls = root.Element("LightControls");

            foreach (var item in controls.Elements())
            {
                LightControl lc = new LightControl()
                {
                    lightContolParas = XmlSerializer.Deserialize(item, typeof(LightContolParas)) as LightContolParas
                };
                if (!lightControlList.Contains(lc))
                {
                    lightControlList.Add(lc);
                }
            }
        }
示例#4
0
 /// <summary>
 /// 频闪方式采图开始
 /// </summary>
 public static void IsGrab(bool isStart)
 {
     if (SoftwareInfo.getInstance().IsStrobe&& SoftwareInfo.getInstance().SystemRunMode == 1)
     {
         //   Global.m_alarmIO.Grab(isStart);//////////////////////////////////////////////////zyy
     }
 }
示例#5
0
        //生成单个模板的算法所需参数
        public static string GenerateModelHalconParas(int channelNo, int stationNo, int modelNo)
        {
            string ret = string.Empty;

            try
            {
                ProductChannel channel = ProductChannelArray[channelNo];

                if (!string.IsNullOrEmpty(channel.ProductData.ProductName))
                {
                    Station station = channel.ProductData.StationList[stationNo];
                    Model   model   = station.ModeList[modelNo];

                    if (0 != model.GenerateHalconParas(SoftwareInfo.getInstance().AlgorithmNormalParasNum, SoftwareInfo.getInstance().AlgorithmSeniorParasNum, station))
                    {
                        ret += "通道" + channel.ChannelName + "产品" + channel.ProductData.ProductName + "工位" + station.StationNo + "模版" + model.ModelNo
                               + "生成参数错误\r\n";
                    }
                }
            }
            catch (Exception ex)
            {
                string str = "GenerateModelHalconParas  生成模板参数出错:\n" + ex.ToString();
                SoftwareInfo.getInstance().WriteLog("GenerateModelHalconParas:\n" + str);
                ret += "GenerateModelHalconParas  生成模板参数出错";
            }
            return(ret);
        }
示例#6
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());
            }
        }
示例#7
0
        /// <summary>
        /// 顺德报警记录
        /// </summary>
        //public static string AlarmImagePath = ""  ;
        //public static string AlarmImageType = ""  ;



        /// <summary>
        /// 设置通道编码器值
        /// </summary>
        /// <param name="ChannelNo"></param>
        /// <param name="CodeNum"></param>
        public static void SetChannelCode(int ChannelNo, double CodeNum)
        {
            if (ChannelNo == 0)
            {
                Channel1Code = Convert.ToDouble(CodeNum / SoftwareInfo.getInstance().DistanceToAlarmCode *SoftwareInfo.getInstance().UniteLenth);
            }
            else if (ChannelNo == 1)
            {
                Channel2Code = Convert.ToDouble(CodeNum / SoftwareInfo.getInstance().DistanceToAlarmCode *SoftwareInfo.getInstance().UniteLenth2);
            }
        }
示例#8
0
        /// <summary>
        /// 写文件,异常写入
        /// </summary>
        /// <param name="str"></param>
        public static void WriteLog(string str)
        {
            try
            {
                List <string> ListErrLogFileName = new List <string>()
                {
                };
                List <string> timeList = new List <string>()
                {
                };
                string[] strArray = new string[] { };
                ListErrLogFileName = Directory.GetFiles(SoftwareInfo.getInstance().ErrorLogPath).ToList();
                int count = 0;

                foreach (string ErrLogFileName in ListErrLogFileName)
                {
                    strArray = ErrLogFileName.Split(' ');
                    timeList.Add(strArray[strArray.Length - 1].Split('.')[0]);
                }
                foreach (string time in timeList)
                {
                    //相等:0 小于today:1 大于today:-1
                    DateTime fileTime    = Convert.ToDateTime(time);
                    DateTime fileTimeNew = fileTime.AddDays(SoftwareInfo.getInstance().SaveErrorLogTime);

                    if (DateTime.Today.CompareTo(fileTimeNew) == 1)
                    {
                        File.Delete(ListErrLogFileName[count]);
                    }
                    //dates t = DateTime.Today-fileTime;
                    count++;
                }
                string path    = SoftwareInfo.getInstance().ErrorLogPath;
                string pathtxt = path + "\\ErrLog " + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                using (StreamWriter sw = new StreamWriter(pathtxt, true))
                {
                    sw.WriteLine(DateTime.Now.ToString());
                    sw.WriteLine(str);
                    sw.WriteLine("---------------------------------------------------------");
                    sw.Close();
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex.Message);
            }
        }
示例#9
0
        public static void DoEvents()
        {
            DispatcherFrame frame = new DispatcherFrame();

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
                                                     new DispatcherOperationCallback(ExitFrames), frame);

            try
            {
                Dispatcher.PushFrame(frame);
            }
            catch (InvalidOperationException ex)
            {
                SoftwareInfo.getInstance().WriteLog("DoEvents:\n" + ex.ToString());
            }
        }
示例#10
0
        public static void ShowImage_shimgvw(string imageName)
        {
            //判断图片是否存在
            if (!System.IO.File.Exists(imageName))
            {
                MessageBox.Show(Application.Current.Resources.MergedDictionaries.First()["Picture does not exist!"].ToString());

                //if (SoftwareInfo.getInstance().Language == "English")
                //{
                //    MessageBox.Show("Picture does not exist! ");
                //}
                //else
                //{
                //    MessageBox.Show("图片不存在!");
                //}

                return;
            }

            try
            {
                //路径 window 下是   \
                imageName = imageName.Replace("//", "\\").Replace("/", "\\");
                System.Diagnostics.Process.Start
                (
                    "rundll32.exe",
                    string.Format("{0} {1}", "shimgvw.dll,ImageView_Fullscreen", imageName)
                );
            }
            catch (Exception ex)
            {
                MessageBox.Show(Application.Current.Resources.MergedDictionaries.First()["access denied :"].ToString());

                //if (SoftwareInfo.getInstance().Language == "English")
                //{
                //    MessageBox.Show("Access denied: " + imageName + "");
                //}
                //else
                //{
                //    MessageBox.Show("拒绝访问: " + imageName + "");
                //}
                SoftwareInfo.getInstance().WriteLog("ShowImage_shimgvw拒绝访问:\n " + imageName + "\n" + ex.ToString());
            }
        }
示例#11
0
        /// <summary>
        /// 对话框初始化,
        /// 2020-04-06,zhouyin,加载相机
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string exMessage = "";

            if (0 != SoftwareInfo.getInstance().load(InfoPath.getInstance().SoftwareInfo, ref exMessage))
            {
                MessageBox.Show(messageBoxText: exMessage);
                this.Closing -= Window_Closing;
                //  MyProgressBar.close();
                this.Close();
            }


            //判断程序是否已启动,如果已启动则不再打开 进程优先级提高
            RaiseCurrentProgramPority();


            //打开相机
            GetCamerasInfo();

            SetCameraViewWithCamera();
        }
示例#12
0
        public static void copyFile(string sourceDirectory, string destDirectory)
        {
            //获取所有文件名称
            string[] fileName = Directory.GetFiles(sourceDirectory);

            foreach (string filePath in fileName)
            {
                //根据每个文件名称生成对应的目标文件名称
                string filePathTemp = destDirectory + "\\" + filePath.Substring(sourceDirectory.Length + 1);

                //若不存在,直接复制文件;若存在,覆盖复制
                if (File.Exists(filePathTemp))
                {
                    File.Copy(filePath, filePathTemp, true);
                }
                else
                {
                    try
                    {
                        File.Copy(filePath, filePathTemp);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString(), Application.Current.Resources.MergedDictionaries.First()["System prompt"].ToString());
                        //if (SoftwareInfo.getInstance().Language == "English")
                        //{
                        //    MessageBox.Show(ex.Message.ToString(), "System prompt");
                        //}
                        //else
                        //{
                        //    MessageBox.Show(ex.Message.ToString(), "系统提示");
                        //}

                        SoftwareInfo.getInstance().WriteLog("copyFile:\n" + ex.ToString());
                    }
                }
            }
        }
示例#13
0
        /// <summary>
        /// [0]帮助文件路径 [1]配置文件路径
        /// </summary>
        /// <param name="FilePathList"></param>
        public static void AssistFile(string str)
        {
            string path       = SoftwareInfo.getInstance().AssistFilesInfoPath;
            string pathFinnal = path + "\\" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + "-" + str;

            SoftwareInfo.getInstance().AssistFilesPartInfoPath = pathFinnal;
            SoftwareInfo.getInstance().AssistParasPath         = pathFinnal + "\\参数文件";
            SoftwareInfo.getInstance().AssistInfoPath          = pathFinnal + "\\配置文件";


            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(SoftwareInfo.getInstance().AssistInfoPath);
            }


            //配置文件
            //   Tools.copyDirectory(InfoPath.getInstance().Path + "\\conf", SoftwareInfo.getInstance().AssistInfoPath);//////////////////////////////////////////////////zyy
            //产品文件
            //BasicTool.copyDirectory(productPath + "\\conf", pathFinnal);
            //日志文件
            //BasicTool.copyDirectory(SoftwareInfo.getInstance().LogPath, pathFinnal);
        }
示例#14
0
 //获得系统参数的单例
 private SoftwareInfo GetProgramSoftwareInfo()
 {
     return(SoftwareInfo.getInstance());
 }
示例#15
0
        public static string Load(int channelIndex, string path)
        {
            string ret = string.Empty;

            try
            {
                if (File.Exists(path + "\\product.xml"))
                {
                    using (Stream fStream = File.OpenRead(path + "\\product.xml"))
                    {
                        System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Product));
                        ProductChannelArray[channelIndex].ProductData = serializer.Deserialize(fStream) as Product;
                    }
                    ProductChannelArray[channelIndex].IsEnable = true;
                }
                else
                {
                    ProductChannelArray[channelIndex].IsEnable = false;
                }
                if (ProductChannelArray[channelIndex].IsEnable == true)
                {
                    Global.m_dicCameraS.SetCamerasGrabActionMode(0, false);
                    Global.m_dicCameraS.SetCamerasGrabActionMode(1, false);

                    foreach (var v in ProductChannelArray[channelIndex].ProductData.StationList)
                    {
                        foreach (var model in v.ModeList)
                        {
                            if (model.IsEnable)
                            {
                                string stationPath   = InfoPath.getInstance().ProductPath + "\\" + ProductChannelArray[channelIndex].ChannelName + "\\" + ProductChannelArray[channelIndex].ProductData.ProductName + "\\" + v.StationNo + "\\";
                                string modelfilePath = stationPath + "Model" + model.ModelNo + ".shm";
                                string Imagepath     = stationPath + "Model" + model.ModelNo + ".bmp";

                                if (File.Exists(modelfilePath))
                                {
                                    HTuple        ReadError      = new HTuple();//函数执行成功标志位
                                    List <double> CreateParaList = new List <double>();
                                    CreateParaList.Add(model.generateModeParas.LightOrDark);
                                    CreateParaList.Add(v.ImageChannel);
                                    CreateParaList.Add(model.generateModeParas.RangeProduct);
                                    CreateParaList.Add(model.generateModeParas.Angle_Modle);
                                    CreateParaList.Add(model.generateModeParas.Select_MD);
                                    CreateParaList.Add(model.generateModeParas.IsClosedZone);
                                    CreateParaList.Add(model.generateModeParas.MinScore);
                                    CreateParaList.Add(model.generateModeParas.RangeLocation);
                                    //zyh 20190531
                                    foreach (var defect in model.MeasureDefectList)
                                    {
                                        if (defect.DefectAlgorithm.PrecisionLevel != 0 && defect.DefectAlgorithm.PrecisionLevel != 1)
                                        {
                                            defect.DefectAlgorithm.PrecisionLevel = 1;
                                        }
                                    }
                                    CreateParaList.Add(model.generateModeParas.ModelPriority);
                                    CreateParaList.Add(model.generateModeParas.DetectionOver);
                                    CreateParaList.Add(Global.ModelDataManager.generateModeParas.LocationType);
                                    CreateParaList.Add(model.generateModeParas.DirectionY);
                                    CreateParaList.Add(model.generateModeParas.DirectionX);
                                    CreateParaList.Add(model.generateModeParas.StretchY);
                                    CreateParaList.Add(model.generateModeParas.StretchX);
                                    model.hv_Create_Range_Tuple = CreateParaList.ToArray();

                                    if (SoftwareInfo.getInstance().IsAlgorithmUseModel)
                                    {
                                        /*  Halcon_Algorithm.Read_Model_Varmodel(out model.generateModeParas.Region, stationPath + "Model", model.ModelNo, model.hv_Create_Range_Tuple,
                                         *    out model.generateModeParas.ModelID, out model.generateModeParas.ModelID_LH, out model.generateModeParas.VarModelID, out ReadError);
                                         *
                                         * Halcon_Algorithm.Read_Model_New4Region(out model.generateModeParas.Region_BigArea, out model.generateModeParas.Region_Column,
                                         *    out model.generateModeParas.Region_Row, out model.generateModeParas.Region_Remove, stationPath + "Model", model.ModelNo);*///////////////////////////////////////////////////zyy
                                    }
                                    model.Contour = model.generateModeParas.Region;
                                }

                                if (!File.Exists(Imagepath))
                                {
                                    ret += Imagepath + " 图像不存在!\r\n";
                                }
                                else
                                {
                                    HOperatorSet.ReadImage(out model.generateModeParas.ModelImage, Imagepath);
                                    HOperatorSet.ReadImage(out model.generateModeParas.TempImage, Imagepath);
                                }
                            }
                        }
                    }

                    Global.m_dicCameraS.SetCamerasGrabActionMode(0, true);
                    Global.m_dicCameraS.SetCamerasGrabActionMode(1, true);
                }

                savePCImgPath = InfoPath.getInstance().ProductPath + "\\" + ProductChannelArray[DefineChannelIndex].ChannelName
                                + "\\" + ProductChannelArray[DefineChannelIndex].ProductData.ProductName + InfoPath.getInstance().ProductNo;
            }
            catch (System.Exception ex)
            {
                Global.m_dicCameraS.SetCamerasGrabActionMode(0, true);
                Global.m_dicCameraS.SetCamerasGrabActionMode(1, true);

                SoftwareInfo.getInstance().WriteLog("Load:\n" + ex.ToString());
                ret += ex.Message;
            }

            return(ret);
        }
示例#16
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);
            }
        }
 private SoftwareInfo GetGlobalSoftwareInfo()
 {
     return(SoftwareInfo.getInstance());
 }
示例#18
0
        /// <summary>
        /// 写文件,图片信息
        /// </summary>
        /// <param name="str"></param>
        public static void WritePicLog(int channelNo, List <string> strList)
        {
            try
            {
                //存在多线程访问同一文件占用问题,暂时不启用 wuqh 20200102
                return;

                //DateTime.Now.ToString("HH-mm-ss-fff")
#pragma warning disable CS0162 // 检测到无法访问的代码
                string str = "";
#pragma warning restore CS0162 // 检测到无法访问的代码
                if (strList.Count < 6)
                {
                    return;
                }

                for (int i = strList.Count - 6; i < strList.Count; i++)
                {
                    str += strList[i] + "\t";
                }
                string path = SoftwareInfo.getInstance().OriginImagePath + "\\标记异常\\" + DateTime.Now.ToString("yyyy-MM-dd");
                if (strList.Count > 6)
                {
                    path += "\\" + strList[5] + "\\" + strList[6];
                }
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //SoftwareInfo.getInstance().PicInfoPath = path ;
                if (string.IsNullOrEmpty(pathPictxt))
                {
                    pathPictxt = path + SoftwareInfo.getInstance().PicInfoPath;
                }


                if (File.Exists(pathPictxt))
                {
                    picList.Clear();
                    picList = File.ReadAllLines(pathPictxt).ToList();
                }
                if (picList.Count > 0 && picList.Count < 5000)
                {
                    if (!File.Exists(path + SoftwareInfo.getInstance().PicInfoPath))
                    {
                        timeStr    = DateTime.Now.ToString("HH-mm-ss-fff");
                        pathPictxt = path + "\\缺陷信息_" + timeStr + ".txt";
                        SoftwareInfo.getInstance().PicInfoPath = "\\缺陷信息_" + timeStr + ".txt";
                    }
                    using (StreamWriter sw = new StreamWriter(pathPictxt, true))
                    {
                        sw.WriteLine(str);
                        sw.Close();
                    }
                }
                else
                {
                    timeStr    = DateTime.Now.ToString("HH-mm-ss-fff");
                    pathPictxt = path + "\\缺陷信息_" + timeStr + ".txt";
                    SoftwareInfo.getInstance().PicInfoPath = "\\缺陷信息_" + timeStr + ".txt";

                    using (StreamWriter sw = new StreamWriter(pathPictxt, true))
                    {
                        sw.WriteLine("型号\t批号\t通道\t工位\t缺陷名称\t图片名称\t倍数");
                        if (channelNo == 0)
                        {
                            sw.WriteLine(str + Global.UnitStr);
                        }
                        else
                        {
                            sw.WriteLine(str + Global.UnitStr1);
                        }
                        sw.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("写入图片信息出错!" + ex.Message.ToString());
            }
        }
示例#19
0
        //加载相机信息
        private void GetCamerasInfo()
        {
            Global.IsGrab(true);
            string CameraPath = "";
            string exMessage  = "";

            //#region 获取相机参数集合

            if (SoftwareInfo.getInstance().HasTwoChannels&& SoftwareInfo.getInstance().SoftwareType == SoftwareTypeEnum.Pieces)
            {
                CameraPath = InfoPath.getInstance().CameraS2Ch;
            }
            else
            {
                CameraPath = InfoPath.getInstance().CameraS;
            }
            if (SoftwareInfo.getInstance().SystemRunMode == 1)
            {
                Global.m_dicCameraS.CloseAllCamera();
            }

            if (0 != Global.m_dicCameraS.GetCameraS(CameraPath, ref exMessage))
            {
                exMessage = Application.Current.Resources.MergedDictionaries.First()["Camera configuration loaded error:"].ToString() + exMessage;
                //if (SoftwareInfo.getInstance().Language == "English")
                //{
                //    exMessage = "Camera configuration loaded error : " + exMessage;
                //}
                //else
                //{
                //    exMessage = "相机配置加载出错: " + exMessage;
                //}
                MessageBox.Show(messageBoxText: exMessage);
                this.Closing -= Window_Closing;
                this.Close();
            }

            //设置读取编码器值的方法
            if (SoftwareInfo.getInstance().SoftwareType == SoftwareTypeEnum.Normal)
            {
                Global.m_dicCameraS.SetGetChannelCodeFunc(Global.GetChannelCode);
            }
            else if (SoftwareInfo.getInstance().SoftwareType == SoftwareTypeEnum.ContinueUDP)
            {
                Global.m_dicCameraS.SetGetStationCodeFunc(Global.GetStationImageCode);
            }
            //片式
            else
            {
                Global.m_dicCameraS.SetGetStationCodeFunc(Global.GetStationImageCode);
            }
            if (GetProgramSoftwareInfo().SystemRunMode == 1)
            {
                string openCamera = Global.m_dicCameraS.OpenAllCamera();


                if ("OK" != openCamera)
                {
                    Global.m_dicCameraS.CloseAllCamera();
                    MessageBox.Show(messageBoxText: openCamera);
                    this.Closing -= Window_Closing;
                    this.Close();
                }
            }
            Global.IsGrab(false);
        }