wangxinhui
2024-11-06 8f392cc88b0768b74efca3b68785cf5aa1c38e70
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
using Newtonsoft.Json;
using Quartz;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.Tools;
using WIDESEA_Entity.DomainModels.Equipment;
using WIDESEA_WCS.Jobs;
using WIDESEA_WCS.JobsPart.Public;
using WIDESEA_WCS.WCSClient;
 
namespace WIDESEA_WCS
{
    /// <summary>
    /// 分切机调度【三菱】
    /// </summary>
    [DisallowConcurrentExecution]
    public class SlitterJob : JobBase, IJob
    {
        static List<AGVCenterEqDB> centerEqDBList;
 
        public SlitterJob()
        {
            if (centerEqDBList == null || centerEqDBList.Count == 0)
            {
                string tsjJson = File.ReadAllText(AppContext.BaseDirectory + "/分切机.json", Encoding.UTF8);
                centerEqDBList = JsonConvert.DeserializeObject<List<AGVCenterEqDB>>(tsjJson);
            }
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                //ExecuteJob(context, DoAction);
            }
            catch { }
            return Task.FromResult(string.Empty);
        }
 
 
        //private void DoAction(IJobExecutionContext context)
        //{
        //    var clinet = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient;
 
        //    var stationList = centerEqDBList.FirstOrDefault(t => t.tiShenJiName == clinet.PLCName);
        //    if (stationList != null)
        //    {
        //        foreach (var station in stationList.stationInfos)
        //        {
        //            if (station.stationType == "in")
        //            {
        //                var hreat = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_hreat"]);
        //                var requestIn = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_requestIn"]);
        //                var allowIn = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_allowIn"]);
        //                var allowLeave = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_allowLeave"]);
 
        //                //转换为调度中心地址
        //                byte[] clientData = new byte[100];
        //                clientData[0] = (byte)(hreat ? 1 : 0);
        //                int step = 0;
        //                if (allowIn)
        //                {
        //                    step = 1;
        //                }
        //                if (allowLeave)
        //                {
        //                    step = 2;
        //                }
        //                clientData[90 + 1] = (byte)step;
 
        //                TransferData(station, clinet, clientData);
        //                Create(clinet, station, requestIn);
        //            }
        //            else if (station.stationType.StartsWith("out"))
        //            {
        //                var requestOut = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_requestOut"]);
        //                var allowIn = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_allowIn"]);
        //                var allowLeave = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_allowLeave"]);
 
        //                //转换为调度中心地址
        //                byte[] clientData = new byte[100];
        //                int step = 0;
        //                if (allowIn)
        //                {
        //                    step = 1;
        //                }
        //                if (allowLeave)
        //                {
        //                    step = 2;
        //                }
        //                int data_93 = 0;
        //                if (station.stationType == "outB")
        //                {
        //                    data_93 = 2;
        //                }
        //                clientData[93] = (byte)data_93;
        //                clientData[90 + 1] = (byte)step;
 
        //                TransferData(station, clinet, clientData);
        //                Create(clinet, station, requestOut);
        //            }
        //        }
        //    }
        //}
 
        private void Create(PLCClient clinet, StationInfo station, bool request)
        {
            try
            {
                //入口无料
                if (station.stationType == "in" && request)
                {
                    WCSCommon.CreateTask(station, true);
                }
                //出口有料
                else if (station.stationType.StartsWith("out") && request)
                {
                    WCSCommon.CreateTask(station, false);
                }
            }
            catch (Exception ex)
            {
                WriteLog.GetLog().Write($"【提升机任务请求异常】{clinet.PLCName},{station.stationCode}口。{ex.Message}" + "\n", clinet.PLCName);
            }
        }
 
 
        /// <summary>
        /// 中转AGV对接数据
        /// </summary>
        /// <param name="station"></param>
        /// <param name="eq_Client"></param>
        /// <param name="eq_Data"></param>
        //private void TransferData(StationInfo station, PLCClient eq_Client, byte[] eq_Data)
        //{
        //    var agv_Client = WIDESEA_WCS.WCSService.Clients.FirstOrDefault(t => t.PLCName == station.agvCenterName);
        //    if (agv_Client != null)
        //    {
        //        var agvData = (byte[])agv_Client.ReadDBValue(station.agvDBList[0], 100);
        //        int step = (int)agvData[90 + 1];
 
        //        //物料类型
        //        if (station.stationType == "in")
        //        {
        //            //心跳
        //            int hreat = (int)agvData[0];
        //            eq_Client.MelsecPLCClient.Write(station.dbData["W_hreat"], hreat);
        //            if (step == 0)
        //            {
        //                eq_Client.MelsecPLCClient.Write(station.dbData["W_requestIn"], false);
        //                eq_Client.MelsecPLCClient.Write(station.dbData["W_requestClose"], false);
        //                eq_Client.MelsecPLCClient.Write(station.dbData["W_haveLeave"], false);
        //            }
        //            else if (step == 1)
        //            {
        //                eq_Client.MelsecPLCClient.Write(station.dbData["W_requestIn"], true);
        //            }
        //            else if (step == 2)
        //            {
        //                eq_Client.MelsecPLCClient.Write(station.dbData["W_requestClose"], true);
        //            }
        //            else if (step == 3)
        //            { 
        //                //离开后,辊分机。自复位
        //                eq_Client.MelsecPLCClient.Write(station.dbData["W_haveLeave"], true);
        //            }
        //        }
        //        else if (station.stationType.StartsWith("out"))
        //        {
        //            if (step == 0)
        //            {
        //                eq_Client.MelsecPLCClient.Write(station.dbData["W_requestIn"], false);
        //                eq_Client.MelsecPLCClient.Write(station.dbData["W_requestOpen"], false);
        //                eq_Client.MelsecPLCClient.Write(station.dbData["W_haveLeave"], false);
        //            }
        //            else if (step == 1)
        //            {
        //                eq_Client.MelsecPLCClient.Write(station.dbData["W_requestIn"], true);
        //            }
        //            else if (step == 2)
        //            {
        //                eq_Client.MelsecPLCClient.Write(station.dbData["W_requestOpen"], true);
        //            }
        //            else if (step == 3)
        //            {
        //                eq_Client.MelsecPLCClient.Write(station.dbData["W_haveLeave"], true);
        //            }
        //        }
        //        agv_Client.WriteDBValue(station.agvDBList[1], eq_Data);
        //    }
        //    else
        //    {
        //        WriteLog.GetLog(eq_Client.PLCName).Write($"【异常】{station.agvCenterName},读取调度中心PLC失败" + "\n", eq_Client.PLCName);
        //    }
        //}
    }
}