示例#1
0
        public static bool Save(int channelNo)
        {
            bool ret = true;

            ProductChannel channel = ProductChannelArray[channelNo];

            if (channel.IsEnable)
            {
                //检验model是否真的已经生成
                foreach (var v in channel.ProductData.StationList)
                {
                    foreach (var model in v.ModeList)
                    {
                        if (model.generateModeParas.IsGenerateModel)
                        {
                            model.IsEnable = true;
                        }
                        else
                        {
                            model.IsEnable = false;
                        }
                    }
                }

                string fileName = InfoPath.getInstance().ProductPath + "\\" + channel.ChannelName + "\\" + channel.ProductData.ProductName + "\\product.xml";

                using (Stream fStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    if (File.Exists(fileName))
                    {
                        System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Product));
                        xmlSerializer.Serialize(fStream, channel.ProductData);
                    }
                    else
                    {
                        Console.WriteLine("暂无此文件:" + fileName);
                        //MessageBox.Show("暂无此文件:" + fileName);
                    }
                }
            }

            return(ret);
        }
示例#2
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();
        }
        private void Save()
        {
            GetGlobalSoftwareInfo().Folw1IsSaveOkImage = (bool)checkBox_OK_Flow1.IsChecked;
            GetGlobalSoftwareInfo().Folw1IsSaveNGImage = (bool)checkBox_NG_Flow1.IsChecked;

            GetGlobalSoftwareInfo().Folw2IsSaveOkImage = (bool)checkBox_OK_Flow2.IsChecked;
            GetGlobalSoftwareInfo().Folw2IsSaveNGImage = (bool)checkBox_NG_Flow2.IsChecked;

            GetGlobalSoftwareInfo().Folw3IsSaveOkImage = (bool)checkBox_OK_Flow3.IsChecked;
            GetGlobalSoftwareInfo().Folw3IsSaveNGImage = (bool)checkBox_NG_Flow3.IsChecked;

            string exMessage = string.Empty;

            if (!(0 == (GetGlobalSoftwareInfo().save(InfoPath.getInstance().SoftwareInfo, ref exMessage))))
            {
                MessageBox.Show(Application.Current.Resources.MergedDictionaries.First()["Failed to save software parameters:"].ToString());
                return;
            }
            else
            {
                MessageBox.Show(Application.Current.Resources.MergedDictionaries.First()["SoftwareInfo Save Successfully"].ToString());
            }
        }
示例#4
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);
        }
示例#5
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);
        }