222
schangxiang@126.com
2024-11-23 fa8d6d8410a6ec07903cd81f37f0880dabe8ddf4
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
using iWareCC.Common.Helper;
using iWareCC.SrmService;
using iWareCommon.Common.Globle;
using iWareCommon.Utils;
using iWareModel;
using iWareSql;
using iWareSql.DataAccess;
using iWareSql.DBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using XiGang.Core.Model;
 
namespace iWareCC
{
    /// <summary>
    /// 四个入库口扫描检测线程
    /// </summary>
    public static class LineInSacnResult
    {
        /// <summary>
        /// 四个入库口扫描检测线程
        /// </summary>
        public static void HandlerLineInSacnResult(object int_device)
        {
            while (true)
            {
                var errMsg = "";
                var showErrMsg = "";
                try
                {
                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = "";
                    //if (SystemValue.isAllowRuning_LineInScan && SystemValue.isStartedModel)
                    if (true)//注意:不需要启动模式
                    {
                        SingleDo((int)EDevice.一号堆垛机, out errMsg);
                        showErrMsg += errMsg + SysGloble.SPLIT_STR;
 
                        SingleDo((int)EDevice.二号堆垛机, out errMsg);
                        showErrMsg += errMsg + SysGloble.SPLIT_STR;
 
                        SingleDo((int)EDevice.三号堆垛机, out errMsg);
                        showErrMsg += errMsg + SysGloble.SPLIT_STR;
 
                        SingleDo((int)EDevice.四号堆垛机, out errMsg);
                        showErrMsg += errMsg + SysGloble.SPLIT_STR;
                    }
 
                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = showErrMsg;
                }
                catch (Exception ex)
                {
                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound += "HandlerLineInSacnResult 出现异常:" + ex.Message + SysGloble.SPLIT_STR;
                    Log4NetHelper.WriteErrorLog(iWareCommon.Utils.LogType.DataProcess_RobotBuffer_FinishTaskForOutbound, "HandlerLineInSacnResult 出现异常:" + ex.Message, ex);
                }
                Thread.Sleep(1000);//休眠2秒
            }
        }
 
        private static void SingleDo(int int_device, out string errMsg)
        {
            errMsg = "";
            EDevice device = (EDevice)Enum.Parse(typeof(EDevice), int_device.ToString());
            var stationCode = "";
            var scanCode = GetScanValueBySrmStationCode(device, ref stationCode);
 
            var srm = FormCC.srmViewDict[(int)device];
            if (srm.R_PickReqForInStore)
            {//必须堆垛机请求了才可以
                //只有当堆垛机有任务执行时,并且是入库任务的时候才判断
                var realSrmSourcePlace = int_device + "-" + srm.SrmSourcePlace;
 
 
                if (string.IsNullOrEmpty(scanCode))
                {
                    errMsg = "设备:" + device.ToString() + ",输送线扫描的值为空";
                    return;
                }
 
                if (srm.R_TaskNo > 0 && (srm.R_State == (int)ESrmState.取货中 || srm.R_State == (int)ESrmState.取货定位中)
                    && SysGloble.Dict_SpecialPlace_IN.ContainsKey(realSrmSourcePlace))
                {
                    if (srm.R_TaskNo > 0 && srm.R_TaskNo <= 100)
                    {//手动
                        MyExtendHelper.WriteScanValidateACK(false, "手动任务", stationCode, srm.R_TaskNo, true, "", scanCode);
                        errMsg = "设备:" + device.ToString() + ",判断是手动任务,验证通过";
                        return;
                    }
                    else
                    {
                        using (DbModel context = new DbModel())
                        {
                            //拿到堆垛机要入库时,应该正确的托盘号
                            var queryState = (int)DeviceTaskStatusEnum.已下发;
                            var queryTaskNo = srm.R_TaskNo.ToString();
                            var queryEDeviceType = (int)EDeviceType.堆垛机;
                            var task = context.Task_Part.Where(x => x.DeviceType == queryEDeviceType && x.PlcTaskId == queryTaskNo && x.TaskState == queryState).FirstOrDefault();
                            if (task == null)
                            {
                                errMsg = "设备:" + device.ToString() + ",获取任务为NULL,PLC任务号:" + queryTaskNo;
                                return;
                                /*
                                //表示是手动进去的?
                                WriteScanFailACK("我认为是手动任务", stationCode, srm.R_TaskNo, true, "", scanCode);
                                errMsg = "设备:" + device.ToString() + ",判断是手动任务(系统),验证通过";
                                return;
                                //*/
                            }
                            else
                            {
                                var sysSalverCode = task.SalverCode;
                                //如果是 托盘入库任务,就不校验
                                if (task.MaterialType == (int)MaterialTypeEnum.托盘)
                                {
                                    MyExtendHelper.WriteScanValidateACK(false, "自动任务,验证托盘", stationCode, Convert.ToInt32(task.PlcTaskId), true, sysSalverCode, scanCode);
                                    errMsg = "设备:" + device.ToString() + ",判断是自动任务,验证通过";
                                    return;
                                }
                                else
                                {
                                    if (scanCode != sysSalverCode)
                                    {//校验不通过
                                        //首先要判断 OK信号是否是true,如果是true,就不需要写验证不通过了,否则会影响wcs手动入库口扫码强制验证通过的节奏
                                        bool isSMQZYZTG = false;
                                        if (ValidateScanSuccessACK(stationCode, ref isSMQZYZTG) == false)
                                        {
                                            //注意:这里停留1秒,继续判断下
                                            Thread.Sleep(2000);
                                            if (ValidateScanSuccessACK(stationCode, ref isSMQZYZTG) == false)
                                            {
                                                MyExtendHelper.WriteScanValidateACK(false, "自动任务,验证发动机", stationCode, Convert.ToInt32(task.PlcTaskId), false, sysSalverCode, scanCode);
                                                errMsg = "设备:" + device.ToString() + ",判断是自动任务,验证不通过,系统托盘号:" + sysSalverCode + ",扫描值:" + scanCode + ",任务号:" + task.PlcTaskId;
                                                return;
                                            }
                                            else
                                            {
                                                if (isSMQZYZTG)
                                                {//强制验证通过
                                                    MyExtendHelper.WriteScanValidateACK(false, "[强制验证通过]自动任务,验证发动机", stationCode, Convert.ToInt32(task.PlcTaskId), true, sysSalverCode, scanCode);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            errMsg = "设备:" + device.ToString() + ",判断是自动任务,本来是验证不通过,但是由于人工手动入库口扫码强制验证通过,所以就不推送验证不通过信号了,系统托盘号:" + sysSalverCode + ",扫描值:" + scanCode + ",任务号:" + task.PlcTaskId;
                                            if (isSMQZYZTG)
                                            {//强制验证通过
                                                MyExtendHelper.WriteScanValidateACK(false, "[强制验证通过]自动任务,验证发动机", stationCode, Convert.ToInt32(task.PlcTaskId), true, sysSalverCode, scanCode);
                                            }
                                            return;
                                        }
                                    }
                                    else
                                    {//校验通过
                                        MyExtendHelper.WriteScanValidateACK(false, "自动任务,验证发动机", stationCode, Convert.ToInt32(task.PlcTaskId), true, sysSalverCode, scanCode);
                                        errMsg = "设备:" + device.ToString() + ",判断是自动任务,验证通过";
                                        return;
                                    }
                                }
                            }
                        }
                    }
 
                }
                else
                {
                    errMsg = "设备:" + device.ToString() + "不满足条件,任务号:" + srm.R_TaskNo + ",状态:" + srm.StateName + ",不是取货中或取货定位中";
                    return;
                }
            }
            else
            {
                MyExtendHelper.SetSrm_IN_SMQZYZTG(device, false);
                ResetACK(stationCode, srm, device);
 
                errMsg = "设备:" + device.ToString() + ",堆垛机没有请求取货";
                return;
            }
        }
 
 
        /// <summary>
        /// 验证OK信号的真假
        /// </summary>
        /// <param name="stationCode"></param>
        /// <returns></returns>
        private static bool ValidateScanSuccessACK(string stationCode, ref bool isSMQZYZTG)
        {
            var isOk = false;
            switch (stationCode)
            {
                case "1002":
                    if (FormCC.rgvView.W_1002_ScanSuccessACK || FormCC.Srm1_IN_SMQZYZTG)
                    {
                        isOk = true;
                    }
                    if (FormCC.Srm1_IN_SMQZYZTG) isSMQZYZTG = true;
                    break;
                case "1004":
                    if (FormCC.rgvView.W_1004_ScanSuccessACK || FormCC.Srm2_IN_SMQZYZTG)
                    {
                        isOk = true;
                    }
                    if (FormCC.Srm2_IN_SMQZYZTG) isSMQZYZTG = true;
                    break;
                case "1006":
                    if (FormCC.rgvView.W_1006_ScanSuccessACK || FormCC.Srm3_IN_SMQZYZTG)
                    {
                        isOk = true;
                    }
                    if (FormCC.Srm3_IN_SMQZYZTG) isSMQZYZTG = true;
                    break;
                case "1007":
                    if (FormCC.rgvView.W_1007_ScanSuccessACK || FormCC.Srm4_IN_SMQZYZTG)
                    {
                        isOk = true;
                    }
                    if (FormCC.Srm4_IN_SMQZYZTG) isSMQZYZTG = true;
                    break;
            }
            return isOk;
        }
 
        private static void ResetACK(string stationCode, SrmView srm, EDevice device)
        {
            var isNeedRest = false;
            switch (stationCode)
            {
                case "1002":
                    if (FormCC.rgvView.W_1002_ScanFailACK || FormCC.rgvView.W_1002_ScanSuccessACK)
                    {
                        isNeedRest = true;
                    }
                    break;
                case "1004":
                    if (FormCC.rgvView.W_1004_ScanFailACK || FormCC.rgvView.W_1004_ScanSuccessACK)
                    {
                        isNeedRest = true;
                    }
                    break;
                case "1006":
                    if (FormCC.rgvView.W_1006_ScanFailACK || FormCC.rgvView.W_1006_ScanSuccessACK)
                    {
                        isNeedRest = true;
                    }
                    break;
                case "1007":
                    if (FormCC.rgvView.W_1007_ScanFailACK || FormCC.rgvView.W_1007_ScanSuccessACK)
                    {
                        isNeedRest = true;
                    }
                    break;
            }
            if (isNeedRest)
            {
                //重置输送线的信号
                MyExtendHelper.WriteScanValidateACK(true, "重置任务", stationCode, srm.R_TaskNo, false, "", "");
            }
        }
 
 
        /// <summary>
        /// 根据堆垛机的入库口获取 扫描值
        /// </summary>
        /// <param name="srmStationCode"></param>
        /// <returns></returns>
        private static string GetScanValueBySrmStationCode(EDevice device, ref string stationCode)
        {
            if (FormCC.rgvView == null)
            {
                return "";
            }
 
            if (device == EDevice.一号堆垛机)
            {
                stationCode = "1002";
                return FormCC.rgvView.R_1002_Scan;
            }
            else if (device == EDevice.二号堆垛机)
            {
                stationCode = "1004";
                return FormCC.rgvView.R_1004_Scan;
            }
            else if (device == EDevice.三号堆垛机)
            {
                stationCode = "1006";
                return FormCC.rgvView.R_1006_Scan;
            }
            else if (device == EDevice.四号堆垛机)
            {
                stationCode = "1007";
                return FormCC.rgvView.R_1007_Scan;
            }
            return "";
        }
 
 
 
 
    }
}