Beispiel #1
0
        /// <summary>
        /// 切换运行状态
        /// </summary>
        public void btnRun_Click(object sender, EventArgs e)
        {
            int cameraCount = IniStatus.Instance.CamearCount;
            Dictionary <int, CameraBase> cameraDic = CameraManger.CameraDic;

            try
            {
                if (CommHandle.Instance.IsLink == false)
                {
                    /*StatusManger status = StatusManger.Instance;
                     * if (status.RuningStatus == RuningStatus.系统异常)
                     * {
                     *  MessageBox.Show("系统出现异常,请检查设置", "提示",
                     *  MessageBoxButtons.OK, MessageBoxIcon.Error);
                     *  return;
                     * }*/

                    if (CameraManger.CameraDic.Count > 0)
                    {
                        CameraManger.Close();
                    }

                    if (CameraManger.Open() == false)
                    {
                        MessageBox.Show("没有相机连接,无法启动", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    for (int i = 0; i < cameraCount; i++)
                    {
                        if (cameraDic.ContainsKey(i + 1) == false)
                        {
                            //Util.Notify(string.Format("请注意相机{0}未连接", i+1));
                            MessageHelper.ShowError(string.Format("相机{0}没有找到", i + 1));
                        }
                    }

                    foreach (int key in cameraDic.Keys)
                    {
                        if (key > cameraCount || key < 1)
                        {
                            cameraDic.Remove(key);
                            Util.Notify(Level.Err, $"相机{key}名称ID超出相机个数设定范围,请用相机软件重新设定");
                            return;
                        }
                    }
                    Util.Notify("相机打开完成");

                    foreach (var item in ToolsFactory.ToolsDic.Values)
                    {
                        Tools.CreateImage.CreateImageTool createImageTool = item[0] as Tools.CreateImage.CreateImageTool;
                        createImageTool.OffLineMode = false;
                    }

                    LoadProject(false);
                    CommHandle.Instance.CommunicationParam = UserSetting.Instance.MainDeviceComParam;  //两对象同是CommunicationParam类型。
                    CommHandle.Instance.Open();
                }
                else
                {
                    if (MessageBox.Show("确定中止运行吗?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                        MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        CommHandle.Instance.IsLink = false;
                        foreach (var item in CameraManger.CameraDic.Values)
                        {
                            item.ContinuousShotStop();
                            if (item.IsContinuousShot)
                            {
                                item.ContinuousShotStop();
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #2
0
        /// <summary>
        /// 打开相机,加载工程文件,通信参数设定,打开通讯。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmMain_Load(object sender, EventArgs e)
        {
            //Common.UI.FrmLoad frmLoad = new Common.UI.FrmLoad(Application.StartupPath + @"\Res\Loading\");
            //Common.UI.Parameter.Name = frmAbout.AssemblyProduct;
            //Common.UI.Parameter.Year = DateTime.Now.ToString("yyyy");
            //Common.UI.Parameter.Version = frmAbout.AssemblyVersion;
            //Common.UI.Parameter.CopyRight = frmAbout.AssemblyCopyright;
            //Common.UI.Parameter.CompanyName = frmAbout.AssemblyCompany;
            //Common.UI.Parameter.Status = "初始化中...";
            //Common.UI.Parameter.StatusNum = 0;
            //frmLoad.Show();

            //frmLoad.UpdateProgress("相机加载...", 0, 30, 500);
            //frmWait.AsyncMethod += ((obj, args) =>
            {
                //注册认证
#if !DEBUG
                //string key = "";
                //key = Common.RegisterHelper.getMNum();
                // if (UserSetting.Instance.SoftKey == null || UserSetting.Instance.SoftKey != key)
                //{
                //    if (UserSetting.Instance.SoftKey == null)
                //    {
                //        MessageBox.Show("验证码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

                //        //      Common.Util.Notify("验证码错误");
                //    }
                //    else
                //    {
                //        // MessageBox.Show(str, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //    }
                //    frmRegistered registered = new frmRegistered();
                //    registered.ShowDialog();
                //}
                //if (UserSetting.Instance.SoftKey == null || UserSetting.Instance.SoftKey != key)
                //{
                //    // 终止此进程并为基础操作系统提供指定的退出代码。
                //    System.Environment.Exit(1);
                //}
#endif
                bool isCameraOpenSuccess = false;

                try
                {
                    //打开相机
                    if (CameraManger.Open())
                    {
                        int cameraCount = IniStatus.Instance.CamearCount;
                        Dictionary <int, CameraBase> cameraDic = CameraManger.CameraDic;
                        for (int i = 0; i < cameraCount; i++)
                        {
                            if (cameraDic.ContainsKey(i + 1) == false)
                            {
                                MessageHelper.ShowError(string.Format("相机{0}没有找到", i + 1));
                            }
                        }
                        //查询相机名称是不是超出有效范围,如果超出,将其从字典中清除。
                        foreach (int key in cameraDic.Keys)
                        {
                            if (key > cameraCount || key < 1)
                            {
                                //cameraDic.Remove(key);
                                Util.Notify(Level.Err, $"相机{key}已连接,但其名称ID超出相机个数设定范围,请通过相机软件修改");
                            }
                        }
                        isCameraOpenSuccess = true;
                        Util.Notify("相机打开完成");
                    }
                    else
                    {
                        StatusManger.Instance.RuningStatus = RuningStatus.系统异常;
                        Util.Notify(Level.Err, "相机打开失败");
                    }
                }
                catch (Exception)
                {
                    MessageHelper.ShowError("相机打开出现异常");
                    StatusManger.Instance.RuningStatus = RuningStatus.系统异常;
                    Util.Notify(Level.Err, "相机打开出现异常");
                }
                //加载工程文件
                autoUnit.LoadProject(true);     //放在此位置很重要,不能像以前一样放在最后。

                try
                {
                    //通信参数设定
                    CommHandle.Instance.CommunicationParam = UserSetting.Instance.MainDeviceComParam;  //两对象同是CommunicationParam类型。
                    //打开通讯
                    if (isCameraOpenSuccess)
                    {
                        CommHandle.Instance.Open();
                    }
                }
                catch (Exception)
                {
                    StatusManger.Instance.RuningStatus = RuningStatus.系统异常;
                    Util.Notify(Level.Err, "通信端口打开异常");
                }

                this.WindowState = FormWindowState.Maximized;
            }
        }