Form1.cs 26.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
using CtuDeviceLib;
using CtuDeviceLib.manager;
using DeviceLibrary;
using Mushiny;
using OnlineStore;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.IO;
using System.Runtime.ExceptionServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TheMachine
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            crc.OpenResourceLog = true;
            InitializeComponent();
            LogUtil.logBox = LogText;
            this.FormClosing += Form1_FormClosing;
            this.Text = Setting_Init.App_Title + " " + Setting_Init.Device_CID;
            t1.Interval = 3000;
            t1.Tick += T1_Tick;
            t1.Tick += UpdatePage_from1;
            t1.Start();
            GC.KeepAlive(t1);
        }

        private void Crc_LanguageChangeEvent(object sender, EventArgs e)
        {
            //if (tabc.TabCount > tabpagecount)
            //    addTablePage();


            LanguageProcess();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;
                this.WindowState = FormWindowState.Minimized;
                return;
            }
            LogUtil.info("系统强制退出应用 step1");
            btn_stop_Click(sender, EventArgs.Empty);
            Thread.Sleep(2000);
            LogUtil.info("系统强制退出应用 step2");
            Application.Exit();
            LogUtil.info("系统强制退出应用 step3");
        }

        SettingControl sc = new SettingControl();

        readonly System.Windows.Forms.Timer t1 = new System.Windows.Forms.Timer();
        private void Form1_Load(object sender, EventArgs e)
        {
            btn_run.Enabled = false;
            //btn_stop.Enabled = false;
            #region 报警信息listview初始化
            listView1.View = View.Details;
            ColumnHeader emptycol = new ColumnHeader();
            emptycol.Text = "";
            emptycol.Width = 0;
            ColumnHeader msgcol = new ColumnHeader();
            msgcol.Text = crc.GetString("Res0047", "信息");
            msgcol.Width = 800;
            ColumnHeader timecol = new ColumnHeader();
            timecol.Text = crc.GetString("Res0048", "时间");
            timecol.Width = 150;
            listView1.Columns.Add(emptycol);
            listView1.Columns.Add(timecol);
            listView1.Columns.Add(msgcol);
            listView1.ColumnWidthChanging += listView_ColumnWidthChanging;
            #endregion

            #region 状态信息listview初始化
            stateView.View = View.Details;
            ColumnHeader c1 = new ColumnHeader();
            c1.Text = "";
            c1.Width = 0;
            ColumnHeader c2 = new ColumnHeader();
            c2.Text = crc.GetString("Res0049", "CTU");
            c2.Width = 90;
            ColumnHeader c3 = new ColumnHeader();
            c3.Text = crc.GetString("Res0050", "位置");
            c3.Width = 80;
            ColumnHeader c4 = new ColumnHeader();
            c4.Text = crc.GetString("table_task", "任务名");
            c4.Width = 150;

            ColumnHeader c7 = new ColumnHeader();
            c7.Text = crc.GetString("table_task", "料箱");
            c7.Width = 100;

            ColumnHeader c6 = new ColumnHeader();
            c6.Text = crc.GetString("table_task", "目的地");
            c6.Width = 250;

            ColumnHeader c5 = new ColumnHeader();
            c5.Text = crc.GetString("Res0047", "信息");
            c5.Width = 800;

            stateView.Columns.Add(c1);
            stateView.Columns.Add(c2);
            stateView.Columns.Add(c3);
            stateView.Columns.Add(c4);
            stateView.Columns.Add(c7);
            stateView.Columns.Add(c6);
            stateView.Columns.Add(c5);
            stateView.ColumnWidthChanging += listView_ColumnWidthChanging;
            #endregion

            LogUtil.info("开始初始化");
            RobotManager.LoadFinishEvent += RobotManage_LoadFinishEvent;
            RobotManager.UserPauseSet += RobotManage_UserPauseSet;

            RobotManager.Init();

            ListViewItem lvi = new ListViewItem(new string[] { "", DateTime.Now.ToString(), crc.GetString("device_initializing", "加载中,请稍后...") });
            lvi.ForeColor = Color.DarkGreen;
            listView1.Items.Add(lvi);
            pnl.Enabled = false;
        }

        void showInitErrMsg(string msg)
        {
            ListViewItem lvi = new ListViewItem(new string[] { "", DateTime.Now.ToString(), crc.GetString("device_initializing", msg) });
            lvi.ForeColor = Color.Red;
            listView1.Items.Add(lvi);
        }
        private void listView_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
        {
            e.NewWidth = (sender as ListView).Columns[e.ColumnIndex].Width;
            e.Cancel = true;
        }
        const int tabpagecount = 1;
        void addTablePage()
        {
            AddForm("tab_setting", crc.GetString("tab_setting", "相关设置"), sc);
            crc.LanguageProcess(this);
        }

        private void T1_Tick(object sender, EventArgs e)
        {
            SetState(CTUManager.CTUs);
        }
        ListViewItem lviInletSplitHead = new ListViewItem(new string[] { "", "", "", "已启用CTU", "", "", "" });
        ListViewItem lviDisabledSplitHead = new ListViewItem(new string[] { "", "", "", "未启用CTU", "", "", "" });

        void SetState(List<CTU> ctus)
        {
            if (RobotManager.mainMachine == null)
                return;
            if (Monitor.TryEnter(stateView, 100))
            {
                try
                {
                    this.SuspendLayout();
                    stateView.Items.Clear();

                    var inLetCtus = ctus?.FindAll(s => s.Enabled);
                    var disableCtus = ctus?.FindAll(s => !s.Enabled);
                    stateView.Items.Add(lviInletSplitHead);
                    showStateMsg(inLetCtus);
                    stateView.Items.Add(lviDisabledSplitHead);
                    showStateMsg(disableCtus);
                }
                catch (Exception ex)
                {

                }
                finally
                {
                    this.ResumeLayout(true);
                    Monitor.Exit(stateView);
                }
            }


        }
        void showStateMsg(List<CTU> ctus)
        {
            if (ctus == null || ctus.Count == 0) return;
            foreach (CTU ctu in ctus)
            {
                var stateinfo = ctu.GetStateStr();
                if (!RobotManager.isRunning)
                    stateinfo = crc.GetString("Res0051", "未启动");
                string dst = "";
                if (ctu.CtuTask != null)
                {
                    if (!string.IsNullOrEmpty(ctu.CtuTask?.DstName))
                        dst = $"{ctu.CtuTask?.DstName}[{ctu.CtuTask?.destination}]";
                }
                ListViewItem lvi = new ListViewItem(new string[] { "", $"{ctu.Name}[{ctu.SOC}%]", ctu.CurLandMark.ToString(), ctu.CtuTask?.Name, ctu.CtuTask?.boxCode, dst, stateinfo });
                if (ctu.Enabled || ctu.IsDebug)
                {
                    if (ctu.RunState == DeviceLibrary.CtuService.RunState.Offline)
                    {
                        lvi.BackColor = Color.Red;
                    }
                    else if (ctu.RunState == DeviceLibrary.CtuService.RunState.Online)
                    {
                        lvi.BackColor = Color.Yellow;
                    }
                    else if (ctu.RunState == DeviceLibrary.CtuService.RunState.Executing)
                    {
                        lvi.BackColor = Color.LightBlue;
                    }
                }
                else
                {
                    lvi.BackColor = Color.Gray;
                }
                stateView.Items.Add(lvi);
            }
        }
        private void AddForm(string id, string text, UserControl form)
        {
            foreach (TabPage tp in tabc.TabPages)
            {
                if (tp.Name == id)
                {
                    tp.Text = text;
                    return;
                }
            }

            TabPage lineTabPage = new TabPage(text);
            lineTabPage.Name = id;
            Panel linePan = new Panel();
            linePan.Dock = DockStyle.Fill;
            linePan.AutoScroll = true;
            lineTabPage.Controls.Add(linePan);
            linePan.Controls.Add(form);
            form.Dock = DockStyle.Fill;
            linePan.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
            form.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
            form.Show();
            tabc.TabPages.Add(lineTabPage);
        }

        private void 启用调试模式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RobotManager.IsConfigMode = RobotManager.IsConfigMode ? false : true;
            (sender as ToolStripMenuItem).Text = !RobotManager.IsConfigMode ? crc.GetString("enable_config_mode", "启用配置模式") : crc.GetString("disable_config_mode", "停用配置模式");
            if (RobotManager.IsConfigMode)
            {
                addTablePage();
            }
            else
            {
                var tc = tabc.TabPages.Count;
                for (int i = 1; i <= tabpagecount; i++)
                {
                    var str = tabc.TabPages[tc - i].Text;
                    var str_1 = crc.GetString("Form1_tabc_tabPage1_Text", "详情信息");
                    if (str != str_1)
                    {
                        tabc.TabPages[tc - i].Parent = null;
                    }
                }
            }
        }

        public delegate void setmsgdelegate(List<Msg> msgs);
        private void MainMachine_ProcessMsgEvent(List<Msg> msgs)
        {
            if (!this.IsHandleCreated) return;
            if (msgs == null)
                return;
            try
            {
                var d = new setmsgdelegate(SetMsg);
                this.Invoke(d, msgs);
            }
            catch (Exception e)
            {
                LogUtil.info("MainMachine_ProcessMsgEvent:" + e.ToString());
            }
        }

        private void RobotManage_LoadFinishEvent(bool state, string msg)
        {
            if (this.InvokeRequired)
            {
                this.Invoke((EventHandler)delegate
                {
                    RobotManage_LoadFinishEvent(state, msg);
                });
                return;
            }
            启用调试模式ToolStripMenuItem.Enabled = true;
            pnl.Enabled = true;
            if (state)
            {

                //btn_stop.Enabled = true;
                if (!btn_run.Enabled)
                {
                    RobotManager.mainMachine.ProcessMsgEvent += MainMachine_ProcessMsgEvent;
                }
                btn_run.Enabled = true;
            }

            var lm = new List<Msg>();
            foreach (string ms in msg.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
            {
                var m = new Msg();
                m.datetime = DateTime.Now;
                m.msgtxt = ms;
                m.msgLevel = state ? MsgLevel.info : MsgLevel.warning;
                lm.Add(m);
            }
            SetMsg(lm);
        }
        object showMsgLoc = new object();
        void SetMsg(List<Msg> msgs)
        {
            if (Monitor.TryEnter(showMsgLoc))
            {
                try
                {
                    this.SuspendLayout();
                    listView1.Items.Clear();
                    foreach (Msg msg in msgs)
                    {
                        if (string.IsNullOrEmpty(msg.msgtxt) || msg.datetime == null)
                            continue;

                        ListViewItem lvi = new ListViewItem(new string[] { "", msg.datetime.ToString(), msg.msgtxt });
                        if (msg.msgLevel == MsgLevel.info)
                            lvi.ForeColor = Color.DarkGreen;
                        else
                            lvi.ForeColor = Color.Red;
                        listView1.Items.Add(lvi);
                        //if (msg.errInfo == ErrInfo.X09_BoxNotDetect)
                        //{
                        //    RobotManage.mainMachine.ShowIgnoreFixtureAlarm = true;
                        //    if (btn_IgnoreX09.Visible) continue;
                        //    btn_IgnoreX09.Invoke(new Action(() =>
                        //    {
                        //        btn_IgnoreX09.Visible = true;
                        //    }));

                        //}
                        //else if (msg.errInfo == ErrInfo.X09_Clear)
                        //{
                        //    RobotManage.mainMachine.ShowIgnoreFixtureAlarm = false;
                        //    if (!btn_IgnoreX09.Visible) continue;
                        //    btn_IgnoreX09.Invoke(new Action(() =>
                        //    {
                        //        btn_IgnoreX09.Visible = false;
                        //    }));
                        //}
                        //else if (msg.errInfo == ErrInfo.RunBtn)// || msg.errInfo == ErrInfo.ResetBtn)
                        //{
                        //    Task.Run(() =>
                        //    {
                        //        Task.Delay(1000).Wait();
                        //        if (!RobotManage.isRunning || RobotManage.IsUserPause)
                        //            btn_run_Click(this, EventArgs.Empty);
                        //    });

                        //}
                        //else if (msg.errInfo == ErrInfo.SuddenStop)
                        //{
                        //    Task.Run(() =>
                        //    {
                        //        if (RobotManage.isRunning)
                        //            btn_stop_Click(this, EventArgs.Empty);
                        //    });

                        //}
                    }
                    this.ResumeLayout(true);
                }
                finally
                { Monitor.Exit(showMsgLoc); }
            }

        }

        bool userpause = false;


        private void btn_run_Click(object sender, EventArgs e)
        {


            if (!RobotManager.isRunning)
            {
                listView1.Items.Clear();
                var enableCtus = CTUManager.GetEnabledCTUs();
                if (enableCtus != null && enableCtus.Count > 0)
                {
                    bool ctuIsInError = false;
                    foreach (var ctu in enableCtus)
                    {
                        if (ctu.CurLandMark == 0)
                        {
                            ctuIsInError = true;
                            showInitErrMsg($"已启用的[{ctu.Name}]未复位,不允许启动");
                        }
                        else if (ctu.CurLandMark == 10001)
                        {
                            ctuIsInError = true;
                            showInitErrMsg($"已启用的[{ctu.Name}]在辅助码,不允许启动");
                        }
                    }
                    if (ctuIsInError)
                    {
                        return;
                    }
                }

                RobotManager.Start();
                userpause = false;
                if (RobotManager.isRunning)
                {
                    btn_stop.Enabled = true;
                    RobotManage_UserPauseSet(this, false);
                    //(sender as Button).Text = "暂停运行";
                }
                LogUtil.info("用户按下启动");
                return;
            }
            //else if (!userpause)
            //{
            //    userpause = true;
            //    RobotManager.UserPause("用户按下暂停1", userpause);
            //}
            //else if (userpause)
            //{
            //    userpause = false;
            //    RobotManager.UserPause("用户取消暂停2", userpause);
            //}
            btn_stop.Enabled = true;
        }
        private void RobotManage_UserPauseSet(object sender, bool e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke((EventHandler<bool>)delegate
                {
                    RobotManage_UserPauseSet(sender, e);
                }, sender, e);
                return;
            }

            if (e)
            {
                userpause = true;
                (btn_run).Text = crc.GetString("device_resume", "恢复运行");
                (btn_run).BackColor = Color.LightGreen;
            }
            else
            {
                userpause = false;
                btn_run.Text = crc.GetString("device_pause", "暂停运行");
                (btn_run).BackColor = Color.Yellow;
            }

        }
        private void btn_stop_Click(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke((EventHandler)delegate
                {
                    btn_stop_Click(sender, e);
                }, sender, e);
                return;
            }
            if (!btn_stop.Enabled)
                return;
            btn_stop.Enabled = false;
            Task.Run(() => { RobotManager.Stop(); });
            RobotManager.UserPause("停止按钮", false);
            userpause = false;
            btn_run.Text = crc.GetString("start", "启动");
            btn_run.BackColor = Color.Transparent;
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (RobotManager.isRunning)
            {
                MessageBox.Show(crc.GetString("device_isrunning_cant_exit", "机器尚在运行,不能退出,请先停止运行."));
            }
            else
            {
                RobotManager.ShutDown();
                System.Diagnostics.Process.GetCurrentProcess().Kill();
                this.Close();
            }
        }
        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutBox1 aboutBox1 = new AboutBox1();
            aboutBox1.ShowDialog();
        }

        private void btn_PauseBuzzer_Click(object sender, EventArgs e)
        {
            // AlarmBuzzer.MuteOnce();
        }

        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            var obj = sender as PictureBox;
            if (obj.Dock == DockStyle.Fill)
                obj.Dock = DockStyle.None;
            else
            {
                obj.BringToFront();
                obj.Dock = DockStyle.Fill;
            }
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            var obj = sender as PictureBox;
            if (obj.Dock == DockStyle.Fill)
                obj.Dock = DockStyle.None;
        }

        [HandleProcessCorruptedStateExceptions]
        public static T DeepClone<T>(T _object)
        {
            try
            {
                T dstobject;
                using (MemoryStream mStream = new MemoryStream())
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(mStream, _object);
                    mStream.Seek(0, SeekOrigin.Begin);//指定当前流的位置为流的开头。
                    dstobject = (T)bf.Deserialize(mStream);
                    mStream.Close();
                }
                return dstobject;
            }
            catch (Exception e)
            {
                LogUtil.info("GetStringCenterA" + e.ToString());
                return default;
            }
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            LanguageProcess();
        }
        void LanguageProcess()
        {
            crc.LanguageProcess(this, this.GetType().Name);
            crc.ProcessListItem(menuStrip1.Items, "menuStrip1");

            listView1.Columns[1].Text = crc.GetString("table_datetime", "时间");
            listView1.Columns[2].Text = crc.GetString("table_info", "信息");

            stateView.Columns[1].Text = crc.GetString("table_module", "CTU");
            stateView.Columns[2].Text = crc.GetString("table_step", "位置");
            stateView.Columns[3].Text = crc.GetString("table_task", "任务名");
            stateView.Columns[4].Text = crc.GetString("table_task", "料箱");
            stateView.Columns[5].Text = crc.GetString("table_task", "目的地");
            stateView.Columns[6].Text = crc.GetString("table_info", "信息");

            启用调试模式ToolStripMenuItem.Text = !RobotManager.IsConfigMode ? crc.GetString("enable_config_mode", "启用配置模式") : crc.GetString("disable_config_mode", "停用配置模式");

            btn_run.Text = crc.GetString("start", "启动");

            if (RobotManager.isRunning)
            {
                if (userpause)
                    (btn_run).Text = crc.GetString("device_resume", "恢复运行");
                else
                    (btn_run).Text = crc.GetString("device_pause", "暂停运行");
            }
        }

        DateTime lastUpdateLimit = DateTime.Now;
        object reFreshMap = new object();

        /// <summary>
        /// 刷新地图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void UpdatePage_from1(object sender, EventArgs e)
        {
            if (Monitor.TryEnter(reFreshMap, 300))
            {
                //bool refreshMap = ConfigAppSettings.GetValue("Enable_RefreshMap", false);
                //if (!refreshMap) return;
                try
                {
                    foreach (var item in CTUManager.GetCTUs())
                    {
                        try
                        {
                            if (item.CurLandMark == 0) continue;
                            if (item.CurLandMark == 10001) continue;
                            if (item.CtuTask == null)
                            {
                                uC_AGVMap1.Update_CTU(item.Name, item.CurLandMark, new List<uint>(), new List<uint>(),
                                    new List<uint>(item.UsedPoint), Color.DarkBlue, Color.DarkGreen, Color.DarkGray, Color.Yellow, item.RobotState.ToString());
                            }
                            else
                            {
                                var planedPoints = new List<uint>();
                                var curPoints = new List<uint>();
                                item.CtuTask.CurRunningPoints?.ForEach(s => curPoints.Add(s.Id));
                                item.CtuTask.planedPoints?.ForEach(s => planedPoints.Add(s.Id));
                                uC_AGVMap1.Update_CTU(item.Name, item.CurLandMark, planedPoints, curPoints,
                                     new List<uint>(item.UsedPoint), Color.DarkBlue, Color.DarkGreen, Color.DarkGray, Color.Yellow, item.RobotState.ToString());
                            }
                        }
                        catch (Exception ex)
                        {

                        }

                    }

                }
                catch (Exception ex)
                {
                    LogUtil.MapLog.Error($"更新地图信息失败:{ex.ToString()}");
                }
                finally
                {
                    Monitor.Exit(reFreshMap);
                }
            }

        }


        private void button8_Click(object sender, EventArgs e)
        {
            LogText.Text = null;
        }

        private void button9_Click(object sender, EventArgs e)
        {
            try
            {
                string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
                string pathNmae = baseDirectory + "NGDetails";
                if (!Directory.Exists(pathNmae))
                {
                    Directory.CreateDirectory(pathNmae);
                }
                string fileName = "NG详情-" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".txt";
                string filePath = Path.Combine(pathNmae, fileName);
                if (string.IsNullOrWhiteSpace(LogText.Text))
                {
                    MessageBox.Show($"无数据保存失败!");
                }
                else
                {
                    ConfigHelper.Config.FileSave(LogText.Text, filePath);
                    MessageBox.Show($"保存成功-{filePath}");
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show($"保存失败,请手动保存NG详情!原因:{ex}");
            }
        }

        private void SetLogText_event(object sender, string e)
        {
            this.Invoke((EventHandler<string>)delegate
            {
                LogText.Text += $"{DateTime.Now.ToString("HH:mm:ss")}  {e}{Environment.NewLine}";
            }, sender, e);
        }

        private void chbReadyUpdate_CheckedChanged(object sender, EventArgs e)
        {
            RobotManager.IsReadyUpdate = chbReadyUpdate.Checked;
        }

        private void 地码维护ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ConveyorLine.FrmPointCode frmPointCode = new ConveyorLine.FrmPointCode();
            frmPointCode.Show();
        }

        private void uC_AGVMap1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                //  if ((DateTime.Now - lastUpdateLimit).TotalMinutes > 1)
                {
                    foreach (var item in CTUManager.localLimitAreas)
                    {
                        uC_AGVMap1.Update_LimitArea(item.PointCodes, Color.LightYellow);
                    }
                    if (HttpManager.GetLimitAreas(out List<LimitAreaInfo> limits))
                    {
                        foreach (var area in limits)
                        {
                            if (area.Enabled)
                                uC_AGVMap1.Update_LimitArea(area.CtuPointCodes, Color.LightYellow);
                        }
                    }
                    lastUpdateLimit = DateTime.Now;
                }
            }
            catch (Exception ex)
            {


            }
        }
    }
}