예제 #1
0
        /// <summary>
        /// 读取各个相机的曝光值到ini
        /// </summary>
        public void ReadExposureTime(string strStep, out string strExp)
        {
            int    nExp    = 0;
            string strFile = m_strConfigDir /*+ strStep + "/" + strStep*/ + "param.ini";

            IniTool.GetString(strFile, "ExposureTime", "nExp", nExp.ToString());
            //IniOperation.GetStringValue(strFile, strStep, "ExposureTime", nExp.ToString());
            string strTemp = IniTool.GetString(strFile, strStep, "ExposureTime", null);

            nExp = Convert.ToInt32(strTemp);

            VisionBase vb;

            if (m_dicVision.TryGetValue(strStep, out vb))
            {
                if (nExp == 0)
                {
                    nExp = vb.m_ExposureTime;  //未读到将值设置成初始值
                    WriteExposureTime(strStep, nExp);
                }
                vb.SetExposureTime(nExp);
                strExp = nExp.ToString();
            }
            else
            {
                throw new Exception("系统指定的视觉处理步骤:" + strStep + "未找到");
            }
        }
예제 #2
0
        private static void InitConfig()
        {
            //通讯接受 Tx
            R.Tx.Port = IniTool.GetInt(R.Files.Settings, "Tx", "Port", 52830);
            IniTool.Set(R.Files.Settings, "Tx", "Port", R.Tx.Port);

            R.Tx.ConnectKey = IniTool.GetString(R.Files.Settings, "Tx", "ConnectKey", R.Tx.ConnectKey);
            IniTool.Set(R.Files.Settings, "Tx", "ConnectKey", R.Tx.ConnectKey);

            //通讯转发 TxConvert
            R.TxConvert.IP = IniTool.GetString(R.Files.Settings, "TxConvert", "IP", "vaselee.com");
            IniTool.Set(R.Files.Settings, "TxConvert", "IP", R.TxConvert.IP);

            R.TxConvert.Port = IniTool.GetInt(R.Files.Settings, "TxConvert", "Port", 0);
            IniTool.Set(R.Files.Settings, "TxConvert", "Port", R.TxConvert.Port);

            R.TxConvert.ConnectKey = IniTool.GetString(R.Files.Settings, "TxConvert", "ConnectKey", R.TxConvert.ConnectKey);
            IniTool.Set(R.Files.Settings, "TxConvert", "ConnectKey", R.TxConvert.ConnectKey);
        }
예제 #3
0
        //[Command]
        //IP=127.0.0.1
        //Port=8001
        //Type=40002000
        //Data={"Item1":"127.0.0.1","Item2":8001}

        public static void Start()
        {
            Task.Factory.StartNew(() =>
            {
                while (!R.MainUI.IsDisposed)
                {
                    if (Ls.Ok(R.Tx.Hosts))
                    {
                        List <string> cmd_files = FileTool.GetAllFile(R.Paths.Command, new[] { "*.cmd.ini" });
                        string tuple_string     = Json.Object2String(new Tuple <string, int>("abc", 123));
                        if (Ls.Ok(cmd_files))
                        {
                            foreach (var file in cmd_files)
                            {
                                string ip   = IniTool.GetString(file, "Command", "IP", "");
                                int port    = IniTool.GetInt(file, "Command", "Port", 0);
                                int type    = IniTool.GetInt(file, "Command", "Type", 0);
                                string data = IniTool.GetString(file, "Command", "Data", "");

                                if (Str.Ok(ip) && type > 0)
                                {
                                    List <string> hosts = TxHostMapTool.GetHost($"{ip}");
                                    if (Ls.Ok(hosts))
                                    {
                                        foreach (var host in hosts)
                                        {
                                            Tuple <string, int> info = new Tuple <string, int>(ip, port);
                                            string ss = Json.Object2String(info);
                                            R.Tx.TcppServer.Write(host, type, Json.Object2Byte(ss));
                                        }
                                    }
                                }
                                R.Log.I($"处理指令:{type},IP:{ip},Port:{port},Data:{data}");
                                FileTool.Delete(file);
                            }
                        }
                    }
                    Sleep.S(10);
                }
            });
        }
예제 #4
0
        /// <summary>
        /// 初始化Ini配置信息
        /// </summary>
        static void InitIni()
        {
            DirTool.Create(R.Paths.Settings);
            DirTool.Create(R.Paths.Projects);
            DirTool.Create(R.Paths.DefaultPublishStorage);
            DirTool.Create(R.Paths.DefaultNewStorage);

            R.Paths.PublishStorage = IniTool.GetString(R.Files.Settings, "Paths", "PublishStorage", R.Paths.DefaultPublishStorage);
            if (string.IsNullOrWhiteSpace(R.Paths.PublishStorage))
            {
                R.Paths.PublishStorage = R.Paths.DefaultPublishStorage;
            }

            R.Paths.NewStorage = IniTool.GetString(R.Files.Settings, "Paths", "NewStorage", R.Paths.DefaultNewStorage);
            if (string.IsNullOrWhiteSpace(R.Paths.NewStorage))
            {
                R.Paths.NewStorage = R.Paths.DefaultNewStorage;
            }

            R.Tx.IP                  = IniTool.GetString(R.Files.Settings, "Console", "IP", "");
            R.Tx.Port                = IniTool.GetInt(R.Files.Settings, "Console", "Port", 0);
            R.Tx.LocalIP             = IniTool.GetString(R.Files.Settings, "Local", "IP", "");
            R.Tx.LocalName           = IniTool.GetString(R.Files.Settings, "Local", "Name", "");
            R.IsAutoDeleteExpiredLog = IniTool.GetBool(R.Files.Settings, "Settings", "AutoDeleteExpiredLog", false);
            R.AppID                  = IniTool.GetString(R.Files.Settings, "App", "ID", "");

            if (!Str.Ok(R.AppID))
            {
                R.AppID = GuidTool.Short();
                IniTool.Set(R.Files.Settings, "App", "ID", R.AppID);
            }

            if (!File.Exists(R.Files.NewStorageReadme))
            {
                TxtTool.Create(R.Files.NewStorageReadme, R.NewStorageReadmeTxt);
            }
        }
예제 #5
0
        private void AutoForm_Load(object sender, EventArgs e)
        {
            //btnSystemConfig.Enabled = false;
            btnSideCamera.Enabled             = false;
            RoundButton_Communication.Enabled = false;
            btnImageFile.Enabled      = false;
            BtnRun.Enabled            = false;
            RoundButton_Login.Enabled = false;
            //BtnRun.BaseColorEnd = BtnRun.BaseColor = Color.FromArgb(230, 216, 216);

            //btnSystemConfig.BaseColor = Color.DarkGray;
            RoundButton_Communication.BaseColor = Color.DarkGray;
            btnImageFile.BaseColor      = Color.DarkGray;
            BtnRun.BaseColor            = Color.DarkGray;
            RoundButton_Login.BaseColor = Color.DarkGray;

            tlbVer.Alignment = ToolStripItemAlignment.Right;
            tlbVer.Text      = $"V2.1:{System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location)}";

            _autoForm = this;

            //获取相机名称
            string fileName = $@"{System.Environment.CurrentDirectory}\Product\CameraName.ini";

            CameraName.MainCamera = IniTool.GetString(fileName, "CameraName", "MainCamera", "MainCam");
            CameraName.SideCamera = IniTool.GetString(fileName, "CameraName", "SideCamera", "HE012A1GM");

#if JAI
            //添加相机并绑定到窗口
            foreach (var cam in CameraJai.FindCamera())
            {
                if (cam.ModelName == CameraName.MainCamera || cam.ModelName == CameraName.SideCamera)
                {
                    VisionMgr.GetInstance().AddCamera(new CameraJai(cam.ModelName, cam));
                }
            }
#else
            //添加相机并绑定到窗口
            //VisionMgr.GetInstance().AddCamera(new CameraGige(CameraName.MainCamera));
            //VisionMgr.GetInstance().AddCamera(new CameraGige(CameraName.SideCamera));
            VisionMgr.GetInstance().AddCamera(new CameraMVision(CameraName.MainCamera));
            VisionMgr.GetInstance().AddCamera(new CameraMVision(CameraName.SideCamera));
#endif

            //添加视觉步骤
            VisionMgr.GetInstance().AddVisionStep(CameraName.MainCamera, new ProcessMainPos(VisionStepName.MainPos));
            VisionMgr.GetInstance().AddVisionStep(CameraName.MainCamera, new ProcessMainMea(VisionStepName.MainMea));
            VisionMgr.GetInstance().AddVisionStep(CameraName.SideCamera, new ProcessSideMea(VisionStepName.SideMea));

            //加载系统参数
            LoadParam();

            //切换产品
            ProductMgr.GetInstance().ProductChangedMethod += ChangeProduct;
            ProductMgr.GetInstance().ChangeProduct(Param.ProductName);

            //关联页面和按钮
            m_dicForm.Add(btnMainCamera, new MainCameraForm());
            //m_dicForm.Add(RoundButton_Login, new LoginForm());
            m_dicForm.Add(RoundButton_Communication, new CommunicationForm());
            m_dicForm.Add(btnSideCamera, new SideCameraForm());
            m_dicForm.Add(btnSystemConfig, new SystemConfigForm());

            //初始化页面属性
            foreach (KeyValuePair <RoundButton, Form> kp in m_dicForm)
            {
                kp.Value.TopLevel = false;
                kp.Value.Parent   = this.panel_main;
                kp.Value.Dock     = DockStyle.Fill;
            }

            btnMainCamera.PerformClick();

            //切换用户
            //((LoginForm)m_dicForm[RoundButton_Login]).UserChangingMethod = ChangeUser;
            //ChangeUser(UserMode.Operator, Param.OperatorPassword);

            //设置日志显示
            Log.Show  = ((MainCameraForm)m_dicForm[btnMainCamera]).ShowLog;
            Data.Show = ((MainCameraForm)m_dicForm[btnMainCamera]).ShowData;

            //连接服务器
            ((SystemConfigForm)m_dicForm[btnSystemConfig]).SetServerMethod = SetServer;
            ConnectServer();
        }
예제 #6
0
        static void Main()
        {
            //taskkill /IM BigBirdDeployer-1.exe /F
            //启动自动运行指定最新版本
            string appoint_name = IniTool.GetString(R.Files.Settings, "Appoint", "Name", "");
            string appoint_md5  = IniTool.GetString(R.Files.Settings, "Appoint", "MD5", "");
            string current_file = Path.GetFileName(R.Files.App);

            if (Str.Ok(appoint_name, appoint_md5))
            {
                string file = DirTool.Combine(R.Paths.App, appoint_name);
                if (File.Exists(file) && FileTool.GetMD5(file) == appoint_md5)
                {
                    R.Log.V($"appoint:{appoint_name}   current:{current_file}");
                    R.Log.V($"appoint:{file}   current:{R.Files.App}");

                    if (appoint_name != current_file)
                    {
                        if (ProcessTool.Start(file))
                        {
                            return;
                        }
                    }
                }
            }

            //var a = FileTool.GetAllFile(@"F:\Temp\logs", new[] { "*.log"});
            //解决进程互斥
            if (!AppUnique.IsUnique(R.AppName))
            {
                return;
            }

            try
            {
                //处理未捕获的异常
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                //处理UI线程异常
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //处理非UI线程异常
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                R.Log.i("========== 程序启动:BigBirdDeployer(正常启动) ==========");
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                R.MainUI = new MainForm();

                InitIni();                           //初始化Ini配置信息
                StatusLog.Instance.Start();          //启动计算机状态日志记录
                R.Log.SetCacheDays(10);              //保存最近10天的普通日志信息
                StatusLog.Instance.SetCacheDays(10); //保存最近10天的状态日志信息
                SystemSleepAPI.PreventSleep(false);  //禁用计算机息屏和待机
                PlanTaskCore.Start();                //启动定时任务

                Application.Run(R.MainUI);           //启动主UI
            }
            catch (Exception ex)
            {
                R.Log.e("应用程序异常 App Main Exception");
                WriteExceptionAndRestart(ex);
            }
        }