分支自 SuZhouGuanHong/TaiYuanTaiZhong

PCS
dengjunjie
2023-12-13 113d1d4262d8f9e78a9d92123713c41669ad6c87
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
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm.LogInfo;
using WIDESEA_WCS.WCSClient;
 
namespace WIDESEA_WCS
{
    [DisallowConcurrentExecution]
    public class ChilderCarJob : IJob
    {
        public Task Execute(IJobExecutionContext context)
        {
            var client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient;
            if (client != null && client.IsConnected)
            {
                RunChilder(client);
            }
            return Task.CompletedTask;
        }
 
        private static string currentState { get; set; }
 
        /// <summary>
        /// 当前运行状态
        /// </summary>
        public static string CurrentState
        {
            get { return currentState; }
            set
            {
                WriteLog.Write_Log("自动运行", "currentState", value);
                currentState = value;
            }
        }
 
        /// <summary>
        /// 子车目的地址
        /// </summary>
        public static int childerPoint { get; set; }
        /// <summary>
        /// 龙门目的地址
        /// </summary>
        public static int gantryPoint { get; set; }
 
        /// <summary>
        /// 升降取料的目的地址
        /// </summary>
        public const int liftingPoint1 = 100;
 
        /// <summary>
        /// 升降提起的目的地址
        /// </summary>
        public const int liftingPoint2 = 200;
 
        /// <summary>
        /// 子车完整取料流程
        /// </summary>
        /// <param name="client"></param>
        public void RunChilder(PLCClient client)
        {
            if (CurrentState == "子车开始")
            {
                //起始条件
 
                int startPoint = childerPoint / 1000;
                int endPoint = childerPoint % 1000;
                client.Write("1010", startPoint);
                client.Write("1011", endPoint); //写入目的地址
                client.Write("64", true);//写入启动命令
 
                CurrentState = "子车前往目的地址";
            }
            else if (CurrentState == "子车前往目的地址")
            {
                var arrive = client.Read<bool>("216");   //子车执行到位
                if (arrive)
                {
                    CurrentState = "龙门开始";
                }
            }
            else if (CurrentState == "龙门开始")
            {
                //起始条件
 
                int startPoint = gantryPoint / 1000;
                int endPoint = gantryPoint % 1000;
                client.Write("1028", startPoint);
                client.Write("1029", endPoint); //写入目的地址
                client.Write("208", true);//写入启动命令
 
                CurrentState = "龙门前往目的地址";
            }
            else if (CurrentState == "龙门前往目的地址")
            {
                var arrive = client.Read<bool>("217"); //龙门执行到位
                if (arrive)
                {
                    CurrentState = "升降开始";
                }
            }
            else if (CurrentState == "升降开始")
            {
                //起始条件
 
                int startPoint = liftingPoint1 / 1000;
                int endPoint = liftingPoint1 % 1000;
                client.Write("1032", startPoint);
                client.Write("1033", endPoint); //写入目的地址
                client.Write("211", true);//写入启动命令
 
                CurrentState = "升降前往目的地址";
            }
            else if (CurrentState == "升降前往目的地址")
            {
                var arrive = client.Read<bool>("218"); //升降到位
                if (arrive)
                {
                    CurrentState = "夹紧开始";
                }
            }
            else if (CurrentState == "夹紧开始")
            {
                client.Write("213", true);//请求夹紧
                var arrive = client.Read<bool>("219"); //夹紧完成
                if (arrive)
                {
                    CurrentState = "升降提起开始";
                }
            }
            else if (CurrentState == "升降提起开始")
            {
                int startPoint = liftingPoint2 / 1000;
                int endPoint = liftingPoint2 % 1000;
                client.Write("1032", startPoint);
                client.Write("1033", endPoint); //写入目的地址
                client.Write("211", true);//写入启动命令
 
                CurrentState = "升降提起前往目的地址";
            }
            else if (CurrentState == "升降提起前往目的地址")
            {
                var arrive = client.Read<bool>("218"); //升降到位
                if (arrive)
                {
                    CurrentState = "子车任务完成";
                }
            }
        }
    }
}