PrintLabelBean.cs 28.2 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
using CodeLibrary;
using JAKA;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Routing;
using System.Windows.Forms;

namespace OnlineStore.DeviceLibrary
{
    public class PrintLabelBean
    {
        public PrinterBean Printer = null;
        InputEquip Robot;
        public DeviceMoveInfo MoveInfo;
        public string WarnMsg = "";
        public string Name = "打标机";

        protected System.Timers.Timer mainTimer;
        public PrintLabelBean(InputEquip equip)
        {
            this.Robot = equip;
            Printer = new PrinterBean();
            MoveInfo = new DeviceMoveInfo(Name);
            if (BufferDataManager.LabelInfo != null)
                LabelInfo = SServerManager.GetFeederInfo(BufferDataManager.LabelInfo.barcode);
            mainTimer = new System.Timers.Timer();
            mainTimer.Enabled = false;
            mainTimer.Interval = 500;
            mainTimer.Elapsed += MainTimer_Elapsed;
            mainTimer.AutoReset = true;
            mainTimer.Enabled = true;
        }
        object locObject = new object();
        private void MainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            PrinteLabelProcess();
        }

        public string GetMoveStr()
        {
            return "【" + (LabelInfo?.ToStr() ?? "") + "】【"
                + (BufferDataManager.LabelInfo == null ? "" : BufferDataManager.LabelInfo.ToStr()) + "】" +
                "【A下" + ((BufferDataManager.AOutStoreInfo?.Labeled ?? false) ? "已" : "未") + "打标】" +
                "【B下" + ((BufferDataManager.BOutStoreInfo?.Labeled ?? false) ? "已" : "未") + "打标】";
        }
        Task scanCode = null;
        void scancodeA()
        {
            scanCode = Task.Factory.StartNew(delegate
            {
                (List<CodeInfo> codeinfos, string filename) tmp = CodeManager.CameraScan(new List<string> { Robot.Config.CameraNameList_FeedA });
                MoveInfo.MoveParam.PosInfo.LabelParam.LabelContent.codeInfos = tmp.codeinfos;
                MoveInfo.MoveParam.PosInfo.LabelParam.BitmapFilename = tmp.filename;
            });
        }
        void scancodeB()
        {
            scanCode = Task.Factory.StartNew(delegate
            {
                (List<CodeInfo> codeinfos, string filename) tmp = CodeManager.CameraScan(new List<string> { Robot.Config.CameraNameList_FeedB });
                MoveInfo.MoveParam.PosInfo.LabelParam.LabelContent.codeInfos = tmp.codeinfos;
                MoveInfo.MoveParam.PosInfo.LabelParam.BitmapFilename = tmp.filename;
            });
        }
        public Label_LZ LabelInfo;
        public void Reset()
        {
            MoveInfo.EndMove();
        }
        public void Start(InOutParam param)
        {
            if (MoveInfo.MoveType.Equals(MoveType.None))
            {
                if (BufferDataManager.LabelInfo == null)
                {
                    LabelInfo = SServerManager.GetFeederInfo(param.PosInfo.barcode);
                    if (LabelInfo == null)
                    {
                        param.PosInfo.outstoreNG = true;
                        BufferDataManager.LabelInfo = param.PosInfo.ToCopy();
                        LogUtil.info($"贴标信息为null,紧急料出库:{param.PosInfo.ToCopy()}");
                        return;
                    }
                    else if (string.IsNullOrEmpty(LabelInfo.line))
                    {
                        param.PosInfo.outstoreNG = true;
                        BufferDataManager.LabelInfo = param.PosInfo.ToCopy();
                        LogUtil.info($"贴标无线体信息,紧急料出库:{param.PosInfo.ToCopy()}");
                        return;
                        //warnMsg = ("料盘贴标无线体信息,出库NG:" + param.PosInfo.ToStr());
                    }
                    else if (string.IsNullOrEmpty(LabelInfo.hSerial))
                    {
                        param.PosInfo.outstoreNG = true;
                        BufferDataManager.LabelInfo = param.PosInfo.ToCopy();
                        LogUtil.info($"贴标无工单信息,紧急料出库:{param.PosInfo.ToCopy()}");
                        return;
                        //warnMsg = ("料盘贴标无需求单信息,出库NG:" + param.PosInfo.ToStr());
                    }
                    MoveInfo.MoveParam = param;
                    MoveInfo.NewMove(MoveType.Working, param);
                    MoveInfo.NextMoveStep(StepEnum.Label00_ScanCode);
                    Label00_ScanCode();
                }

            }

        }
        void CheckAndMove(string IoType, IO_VALUE value)
        {
            if (!IOValue(IoType).Equals(value))
            {
                IOMove(IoType, value);
            }
        }
        void Label00_ScanCode()
        {
            CheckAndMove(IO_Type.CameraLed, IO_VALUE.HIGH);
            int startp = MoveInfo.MoveParam.PosInfo.GetPosType();
            MoveInfo.MoveParam.PosInfo.LabelParam = new LabelParam();
            if (startp.Equals(1))
            {
                MoveInfo.MoveParam.PosInfo.LabelParam.TrayCenterInImg_X = ConfigAppSettings.GetIntValue(Setting_Init.TrayCenterInImg_X_CamA, 2600);
                MoveInfo.MoveParam.PosInfo.LabelParam.TrayCenterInImg_Y = ConfigAppSettings.GetIntValue(Setting_Init.TrayCenterInImg_Y_CamA, 1700);
                MoveInfo.MoveParam.PosInfo.LabelParam.RelativeAngle = ConfigAppSettings.GetIntValue(Setting_Init.RelativeAngle_CamA, 150);
                MoveInfo.MoveParam.PosInfo.LabelParam.LabelInImgAngle = ConfigAppSettings.GetIntValue(Setting_Init.LabelInImgAngle_CamA, 190);
                MoveInfo.MoveParam.PosInfo.LabelParam.LabelContent = new LabelContent();
                MoveInfo.MoveParam.PosInfo.LabelParam.LabelContent.PN = LabelInfo.pn;
                scancodeA();
                MoveLog($"开始A下暂存区物料出库{MoveInfo.SLog}: {getSideName(MoveInfo.MoveParam.ShelfType)},标签气缸后退,等待料盘检测=1");
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LineA_ReelInPlaceCheck, IO_VALUE.HIGH));
            }
            else if (startp.Equals(2))
            {
                MoveInfo.MoveParam.PosInfo.LabelParam.TrayCenterInImg_X = ConfigAppSettings.GetIntValue(Setting_Init.TrayCenterInImg_X_CamB, 2600);
                MoveInfo.MoveParam.PosInfo.LabelParam.TrayCenterInImg_Y = ConfigAppSettings.GetIntValue(Setting_Init.TrayCenterInImg_Y_CamB, 1700);
                MoveInfo.MoveParam.PosInfo.LabelParam.RelativeAngle = ConfigAppSettings.GetIntValue(Setting_Init.RelativeAngle_CamB, 150);
                MoveInfo.MoveParam.PosInfo.LabelParam.LabelInImgAngle = ConfigAppSettings.GetIntValue(Setting_Init.LabelInImgAngle_CamB, 190);
                MoveInfo.MoveParam.PosInfo.LabelParam.LabelContent = new LabelContent();
                MoveInfo.MoveParam.PosInfo.LabelParam.LabelContent.PN = LabelInfo.pn;
                scancodeB();
                MoveLog($"开始B下暂存区物料出库{MoveInfo.SLog}: {getSideName(MoveInfo.MoveParam.ShelfType)},标签气缸后退,等待料盘检测=1");
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LineB_ReelInPlaceCheck, IO_VALUE.HIGH));
            }
            Label_CylinderBack(MoveInfo);
        }
        void Label_CylinderBack(DeviceMoveInfo moveInfo = null)
        {
            IOMove(IO_Type.Printer_CylinderFwd, IO_VALUE.LOW);
            IOMove(IO_Type.Printer_CylinderBack, IO_VALUE.HIGH);
            if (moveInfo != null)
            {
                moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Printer_CylinderFwd, IO_VALUE.LOW));
                moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Printer_CylinderBack, IO_VALUE.HIGH));
                moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Printer_CylinderFwdCheck, IO_VALUE.LOW));
                moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Printer_CylinderBackCheck, IO_VALUE.HIGH));
            }
        }
        void MoveLog(string msg)
        {
            string posId = (MoveInfo.MoveParam != null && MoveInfo.MoveParam.PosInfo != null) ? " [" + MoveInfo.MoveParam.PosInfo.PosId + "]" : "";
            LogUtil.info($"{Name} {MoveInfo?.SLog} {posId} {msg}");
        }
        string getSideName(int shelf)
        {
            if (shelf == 1)
            {
                return "A周转箱内侧【T面】";
            }
            else if (shelf == 2)
            {
                return "A周转箱外侧【B面】";
            }
            else if (shelf == 3)
            {
                return "B周转箱内侧【T面】";
            }
            else if (shelf == 4)
            {
                return "B周转箱外侧【B面】";
            }
            return "周转箱";
        }
        public void PrinteLabelProcess()
        {
            if(Monitor.TryEnter(locObject))
            {
                try
                {
                    if (MoveInfo.IsInWait)
                    {
                        CheckWait(MoveInfo);
                    }
                    if (MoveInfo.IsInWait)
                    {
                        return;
                    }

                    if (MoveInfo.IsStep(StepEnum.Label00_ScanCode))
                    {
                        MoveInfo.NextMoveStep(StepEnum.Label01_ConnectPrinter);
                        if (Printer.Connect(out string msg))
                        {
                            MoveLog($"打标:连接打印机");
                        }
                        else
                        {
                            MoveLog($"打标:连接打印机:{msg}");
                        }
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    }
                    else if (MoveInfo.IsStep(StepEnum.Label01_ConnectPrinter))
                    {
                        if (Printer.IsReadyPrint(out string msg))
                        {
                            MoveInfo.NextMoveStep(StepEnum.Label02_CheckState);
                            SetWarnMsg();
                            MoveLog($"打标:打印机准备就绪");
                            Thread.Sleep(1000);
                        }
                        else
                        {
                            SetWarnMsg($"打印机状态异常:{msg}");
                            Thread.Sleep(2000);
                        }
                    }
                    else if (MoveInfo.IsStep(StepEnum.Label02_CheckState))
                    {

                        if (!CheckLabel())
                        {
                            MoveInfo.NextMoveStep(StepEnum.Label03_HasLabelAtDoor);
                            MoveLog($"打标:出口无标签");
                        }
                        else
                        {
                            SetWarnMsg($"出口有标签,无法打印");
                            Thread.Sleep(2000);
                        }
                    }
                    else if (MoveInfo.IsStep(StepEnum.Label03_HasLabelAtDoor))
                    {
                        MoveInfo.NextMoveStep(StepEnum.Label04_PrintLabel);
                        Printer.Print(new Label_LZ(LabelInfo?.pn, LabelInfo?.side, LabelInfo?.station, LabelInfo?.line, LabelInfo?.slot, LabelInfo?.subslot), out string msg);
                        MoveLog($"打标:开始打印标签【{msg}】:{LabelInfo.ToStr()}");
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    }
                    else if (MoveInfo.IsStep(StepEnum.Label04_PrintLabel))
                    {
                        if (CheckLabel())
                        {
                            MoveInfo.NextMoveStep(StepEnum.Label05_WaitPrintOK);
                            MoveLog($"打标:出标完成");
                        }
                        else if (MoveInfo.IsTimeOut(5))
                        {
                            MoveInfo.NextMoveStep(StepEnum.Label05_WaitPrintOK);
                            MoveLog($"打标:5秒超时,认为出标完成");
                        }
                        Thread.Sleep(1000);
                    }
                    else if (MoveInfo.IsStep(StepEnum.Label05_WaitPrintOK))
                    {
                        MoveInfo.NextMoveStep(StepEnum.Label06_LabelFwd);
                        MoveLog($"打标:标签平台前进");
                        Label_CylinderFwd(MoveInfo);
                    }
                    else if (MoveInfo.IsStep(StepEnum.Label06_LabelFwd))
                    {
                        if (checkLabelInPos())
                        {
                            MoveInfo.NextMoveStep(StepEnum.Label07_CheckLabelInPos);
                            CloseSuckLabel();
                            MoveLog($"打标:标签在平台上");
                        }
                        else
                        {
                            SetWarnMsg("标签未在平台上,请处理");
                            //MoveInfo.NextMoveStep(StepEnum.Label01_ConnectPrinter);
                            //MoveLog($"打标:未检测到标签在平台上,标签平台后退,准备重新打印");
                            //Label_CylinderBack(MoveInfo);
                        }
                    }
                    else if (MoveInfo.IsStep(StepEnum.Label07_CheckLabelInPos))
                    {
                        MoveInfo.NextMoveStep(StepEnum.Label08_CloseConnect);
                        MoveLog($"打标:关闭打印机连接");
                        Printer.Close();
                    }
                    else if (MoveInfo.IsStep(StepEnum.Label08_CloseConnect))
                    {
                        if (scanCode == null || (scanCode.IsCompleted))
                        {
                            MoveInfo.NextMoveStep(StepEnum.Label09_WaitLabelLeave);
                            MoveInfo.MoveParam.PosInfo.relativeAngle = LabelManager.CalcLabelAngle(MoveInfo?.MoveParam?.PosInfo?.LabelParam);
                            int startp = MoveInfo.MoveParam.PosInfo.GetPosType();
                            if (startp.Equals(1))
                            {
                                if (BufferDataManager.AOutStoreInfo != null)
                                    BufferDataManager.AOutStoreInfo.Labeled = true;
                            }
                            else
                            {
                                if (BufferDataManager.BOutStoreInfo != null)
                                    BufferDataManager.BOutStoreInfo.Labeled = true;
                            }
                            MoveLog($"打标:{MoveInfo.MoveParam.PosInfo.barcode}标记为打标,计算的贴标旋转角度:{MoveInfo.MoveParam.PosInfo.relativeAngle}°");
                            BufferDataManager.LabelInfo = MoveInfo.MoveParam.PosInfo.ToCopy();
                            MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
                        }
                        else if (MoveInfo.IsTimeOut(15))
                        {
                            SetWarnMsg("等待相机解析旋转角度超时");
                        }
                    }
                    else if (MoveInfo.IsStep(StepEnum.Label09_WaitLabelLeave))
                    {
                        if (BufferDataManager.LabelInfo == null)
                        {
                            MoveInfo.NextMoveStep(StepEnum.Label10_Finish);
                            //MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(300));
                            Label_CylinderBack(MoveInfo);
                            MoveLog($"打标:标签被取走,流程结束");
                            CodeManager.DelImg(Name,MoveInfo?.MoveParam?.PosInfo?.LabelParam.BitmapFilename);
                        }
                        else if (MoveInfo.IsTimeOut())
                        {
                            SetWarnMsg("等待标签被取走超时");
                        }
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    }
                    else if (MoveInfo.IsStep(StepEnum.Label10_Finish))
                    {
                        MoveInfo.EndMove();
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.error("printlabelprocess", ex);
                }
                finally
                {
                    Monitor.Exit(locObject);
                }
            }

        }
        /// <summary>
        /// 检查标签状态
        /// </summary>
        /// <returns></returns>
        bool CheckLabel()
        {
            bool useLabelCheck = ConfigAppSettings.GetBoolValue(Setting_Init.UseLabelCheck, false);
            if (useLabelCheck)
                return IOValue(IO_Type.Printer_LabelCheck).Equals(IO_VALUE.HIGH);
            else
            {
                return Printer.IsLabelOnPeeler();
            }
        }
        /// <summary>
        /// 检查标签是否在平台上
        /// </summary>
        /// <returns></returns>
        bool checkLabelInPos()
        {
            bool useLabelCheck = ConfigAppSettings.GetBoolValue(Setting_Init.UseLabelCheck, false);
            if (useLabelCheck)
                return IOValue(IO_Type.Printer_LabelCheck).Equals(IO_VALUE.HIGH);
            return true;
        }
        public void SetWarnMsg(string msg = "")
        {
            WarnMsg = msg;
        }
        public void Label_CylinderFwd(DeviceMoveInfo moveInfo = null)
        {
            IOMove(IO_Type.Printer_CylinderBack, IO_VALUE.LOW);
            IOMove(IO_Type.Printer_CylinderFwd, IO_VALUE.HIGH);
            if (moveInfo != null)
            {
                moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Printer_CylinderBack, IO_VALUE.LOW));
                moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Printer_CylinderFwd, IO_VALUE.HIGH));
                moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Printer_CylinderBackCheck, IO_VALUE.LOW));
                moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Printer_CylinderFwdCheck, IO_VALUE.HIGH));
            }
        }
        /// <summary>
        /// 关闭吸标签
        /// </summary>
        /// <param name="moveInfo"></param>
        public void CloseSuckLabel(DeviceMoveInfo moveInfo = null)
        {
            IOMove(IO_Type.Printer_CylinderFwd, IO_VALUE.LOW);
            if (moveInfo != null)
            {
                moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Printer_CylinderFwd, IO_VALUE.LOW));
            }
        }
        private DateTime preCheckAxisTime = DateTime.Now;
        protected DateTime preRWTime = DateTime.Now;
        internal void CheckWait(DeviceMoveInfo moveInfo)
        {
            try
            {
                List<WaitResultInfo> list = moveInfo.WaitList;
                if (list.Count <= 0)
                {
                    moveInfo.EndStepWait();
                    return;
                }

                //当等待超过一分钟时,需要打印提示 
                TimeSpan span = DateTime.Now - moveInfo.LastSetpTime;
                if (span.TotalMilliseconds < 300)
                {
                    return;
                }
                string NotOkMsg = "";
                bool isOk = !moveInfo.OneWaitCanEndStep;
                foreach (WaitResultInfo wait in list)
                {
                    if (wait.IsEnd)
                    {
                        continue;
                    }
                    NotOkMsg = " [" + wait.ToStr() + "] ";
                    if (wait.WaitType.Equals(WaitEnum.W002_IOValue))
                    {
                        NotOkMsg = " [" + IOManager.GetIO(wait.IoType, Robot.DeviceID).DisplayStr + "=" + wait.IoValue + "]";
                        wait.IsEnd = IOValue(wait.IoType).Equals(wait.IoValue);
                        {
                            TimeSpan rwSpan = DateTime.Now - preRWTime;
                            //一分钟还未检测到
                            if (span.TotalSeconds > StoreManager.Config.IOSingle_TimerOut && alarmType <= AlarmType.IoSingleTimeOut)
                            {
                                ConfigIO io = Robot.Config.getWaitIO(wait.IoType);
                                WarnMsg = moveInfo.Name + "[" + moveInfo.MoveType + "][" + moveInfo.MoveStep + "] 等待" + NotOkMsg + " 超时 " + Math.Round(span.TotalSeconds, 1) + "秒";

                                LogUtil.error(WarnMsg, moveInfo.ErrorLogType, moveInfo.logSeconds());
                                if (alarmType.Equals(AlarmType.None))
                                {
                                    Alarm(AlarmType.IoSingleTimeOut);
                                }
                            }
                            else if (rwSpan.TotalSeconds > 5 && span.TotalSeconds > 6 && span.TotalSeconds < StoreManager.Config.IOSingle_TimerOut * 2)
                            {
                                preRWTime = DateTime.Now;
                                string msg = moveInfo.Name + " [" + moveInfo.MoveType + "][" + moveInfo.MoveStep + "] " + NotOkMsg + "已等待 " + Math.Round(span.TotalSeconds, 1) + "秒,重写DO:";
                                bool isLog = false;
                                foreach (WaitResultInfo ww in list)
                                {
                                    if (ww != null && ww.WaitType.Equals(2) && Robot.Config.DOList.ContainsKey(ww.IoType))
                                    {
                                        if (IOManager.DOValue(ww.IoType, Robot.Config.Id).Equals(ww.IoValue).Equals(false))
                                        {
                                            isLog = true;
                                            Robot.IOMove(ww.IoType, ww.IoValue);
                                            msg += ww.ToStr() + ",";
                                        }
                                    }
                                }
                                if (isLog)
                                {
                                    LogUtil.error(msg);
                                }
                            }
                        }
                    }
                    else if (wait.WaitType.Equals(WaitEnum.W003_Time))
                    {
                        wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
                    }
                    else if (wait.WaitType.Equals(WaitEnum.W202_PrintLabel))
                    {
                        if (Printer.IsLabelOnPeeler())
                        {
                            wait.IsEnd = true;
                        }
                    }
                    else
                    {
                        LogUtil.error(Name + "未找到WaitType=" + wait.WaitType + "的处理");
                    }
                    if (wait.IsEnd)
                    {
                        if (moveInfo.OneWaitCanEndStep)
                        {
                            isOk = true;
                            break;
                        }
                    }
                    else
                    {
                        if (!moveInfo.OneWaitCanEndStep)
                        {
                            isOk = false;
                            break;
                        }
                    }
                }
                if (isOk)
                {
                    moveInfo.EndStepWait();
                }
                else if (span.TotalSeconds > moveInfo.TimeOutSeconds)
                {
                    WarnMsg = moveInfo.Name + "[" + moveInfo.MoveType + "][" + moveInfo.MoveStep + "]等待" + NotOkMsg + "超时[" + Math.Round(span.TotalSeconds, 1) + "]秒";
                    //int second = 10;

                    //second = (int)(span.TotalSeconds/ moveInfo.TimeOutSeconds) * 10;
                    //if (second > 120)
                    //{
                    //    second = 120;
                    //}
                    //else if (second < 10)
                    //{
                    //    second = 10;
                    //}
                    LogUtil.error(WarnMsg, moveInfo.ErrorLogType, moveInfo.logSeconds());
                    Alarm(AlarmType.IoSingleTimeOut);
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(moveInfo.Name + " [" + moveInfo.MoveStep + "] CheckWait 出错:", ex);
            }
        }
        public DateTime LastAlarmTime = DateTime.Now;
        public AlarmType alarmType = AlarmType.None;
        internal void Alarm(AlarmType alarmType)
        {
            if (alarmType.Equals(AlarmType.None).Equals(false))
            {
                LastAlarmTime = DateTime.Now;
            }
            if (this.alarmType.Equals(alarmType))
            {
                return;
            }
            this.alarmType = alarmType;
            if (alarmType.Equals(AlarmType.SuddenStop) || alarmType.Equals(AlarmType.NoAirpressure_Check) || alarmType.Equals(AlarmType.AxisAlarm))
            {
                StopMove();
            }
        }
        internal void StopMove()
        {
            LogUtil.info(Name + " Stop Move ");
            MoveInfo.EndMove();
        }
        /// <summary>
        /// 打印信息预览
        /// </summary>
        /// <param name="label_LZ"></param>
        /// <returns></returns>
        public Bitmap PrintView(Label_LZ label_LZ = null)
        {
            if (label_LZ == null)
                label_LZ = new Label_LZ("123456789", "T", "ABCD-10_1  1A", "line 1");
            return Printer.PrintView(label_LZ);
        }
        public void PrintTest()
        {
            try
            {
                string msg = "";
                if (!Printer.Connect(out msg))
                {
                    MessageBox.Show($"连接打印机失败:{msg}");
                }
                if (Printer.IsLabelOnPeeler())
                {
                    MessageBox.Show("剥纸器上有标签,无法打印");
                    return;
                }
                Label_LZ label_LZ = new Label_LZ("123456789", "T", "ABCD-10_1  1A", "line");
                bool rtn = Printer.Print(label_LZ, out msg);
                if (!rtn)
                {
                    MessageBox.Show($"打印失败:{msg}");
                }
            }
            catch (Exception ex)
            {
                LogUtil.error("打印异常", ex);
            }

        }
        /// <summary>
        /// 打印流程测试
        /// </summary>
        public void PrintProcessTest()
        {
            string msg = "";
            if (!Printer.Connect(out msg))
            {
                MessageBox.Show($"连接打印机失败:{msg}");
            }
            if (Printer.IsLabelOnPeeler())
            {
                MessageBox.Show("剥纸器上有标签,无法打印");
                return;
            }
            Task.Factory.StartNew(delegate
            {
                IOMove(IO_Type.Printer_CylinderFwd, IO_VALUE.LOW);
                IOMove(IO_Type.Printer_CylinderBack, IO_VALUE.HIGH);
                while (IOValue(IO_Type.Printer_CylinderBackCheck).Equals(IO_VALUE.LOW))
                {
                    Thread.Sleep(500);
                }
                Label_LZ label_LZ = new Label_LZ("123456789", "T", "ABCD-10_1  1A", "line");
                Printer.Print(label_LZ, out msg);
                while (!Printer.IsLabelOnPeeler())
                {
                    Thread.Sleep(1000);
                }
                IOMove(IO_Type.Printer_CylinderBack, IO_VALUE.LOW);
                IOMove(IO_Type.Printer_CylinderFwd, IO_VALUE.HIGH);
                while (IOValue(IO_Type.Printer_CylinderFwdCheck).Equals(IO_VALUE.LOW))
                {
                    Thread.Sleep(1000);
                }
            });
        }
        public void IOMove(string IoType, IO_VALUE value, int msTime = 0)
        {
            Robot.IOMove(IoType, value, msTime);
        }
        public IO_VALUE IOValue(string IoType)
        {
            return Robot.IOValue(IoType);
        }
    }
}