222
schangxiang@126.com
2025-08-23 06b5e669d423ba48fd3f92bbb318b6395e38af1b
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
using iWareCc.Cache.Entity;
using iWareCc.DecomposeTask.Entity;
using iWareCc.Properties;
using iWareCc.Srm.Entity;
using iWareCommon.Common.Entity;
using iWareCommon.Common.EnumType;
using iWareCommon.Utils;
using iWareDataCore.DEV.EnumType;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace iWareCc.FinishStackerTask.Chain
{
    public class 等待堆垛机完成任务 : IHandler
    {
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        private IHandler nextHandler = null;
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
        private StackerEntity Stacker;
 
        /// <summary>
        /// 任务容器
        /// </summary>
        private PartTaskContainer DecompositionTaskContainer;
 
 
        public 等待堆垛机完成任务(StackerEntity stacker, PartTaskContainer decompositionTaskContainer)
        {
            this.Stacker = stacker;
            this.DecompositionTaskContainer = decompositionTaskContainer;
        }
 
 
        public void Handle()
        {
            try
            {
                if (Stacker.WTaskNo != DecompositionTaskContainer.PartTask.Id)
                {
                    LogTextHelper.WriteLine(Resources.LogDir + @"/完成堆垛机任务/" + Stacker.Equipment.EquipName, "等待堆垛机完成任务WCSId={0},STAKERID={1}:{2}", DecompositionTaskContainer.PartTask.Id, Stacker.WTaskNo, "任务号不匹配");
                    return;
                }
 
 
                if (Stacker.TaskFinish < 1)
                {
                    LogTextHelper.WriteLine(Resources.LogDir + @"/完成堆垛机任务/" + Stacker.Equipment.EquipName, "等待堆垛机完成任务:{0}", "任务执行中...");
                    return;
                }
 
                var flag1 = CacheEntity.OpcWcfServiceClient.WriteValue(Stacker.OpcWriteItems.TaskNo, (int)EYesOrNo.否);
 
                while (Stacker.State != (int)ESrmState.堆垛机空闲)
                {
                    Thread.Sleep(1000);
                }
                if (!flag1)
                {
                    LogTextHelper.WriteLine(Resources.LogDir + @"/完成堆垛机任务/" + Stacker.Equipment.EquipName, "等待堆垛机完成任务:{0}", "发送OPC失败");
                    return;
                }
 
                LogTextHelper.WriteLine(Resources.LogDir + @"/完成堆垛机任务/" + Stacker.Equipment.EquipName, "等待堆垛机完成任务:{0}", "任务已完成");
 
                if (nextHandler != null)
                {
                    nextHandler.Handle();
                }
            }
            catch (Exception ex)
            {
                LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
            }
        }
    }
}