222
schangxiang@126.com
2024-12-12 9f61c92fe6864d536a0e3a6e041cbd788dcec752
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
using iWareCC.BLL;
using iWareCC.SrmService;
using iWareCommon;
using iWareCommon.Utils;
using iWareModel;
using iWareSql;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace iWareCC.Forms
{
    public partial class SystemCheckForm : Form
    {
        private string strOK = "成功!";
        private string strFail = "失败!";
        Boolean DeviceStats = false;
        public SystemCheckForm()
        {
            InitializeComponent();
 
            this.BtnDection.Enabled = false;
            this.btn_Skip.Enabled = false;
        }
 
        /// <summary>
        /// 显示登陆窗体.(公共静态方法)
        /// </summary>        
        public static bool Frm_SystemCheckResult()
        {
            SystemCheckForm LoadDetectionFM = new SystemCheckForm();
            LoadDetectionFM.StartPosition = FormStartPosition.CenterScreen;
            DialogResult result = LoadDetectionFM.ShowDialog();
            return (result == DialogResult.OK);
        }
 
        private void Bgw1_DoWork(object sender, DoWorkEventArgs e)
        {
            StartDection();
        }
 
        private void StartDection()
        {
            this.BtnDection.Enabled = false;
            this.btn_Skip.Enabled = false;
 
            Boolean result1, result2, result3, result4, result5, result6, result7;
            result1 = result2 = result3 = result4 = result5 = result6 = result7 = false;
 
            int checkAllCount = 7;
            int checkIndex = 0;
 
            var tipsMsg = "";
            //1、通讯检测
            tipsMsg = "正在检测  WCS通讯...(" + (++checkIndex) + "/" + checkAllCount + ")";
            SetLablelMsg(tipsMsg);
            this.Bgw1.ReportProgress(10, tipsMsg);
            result1 = this.DeviceDection(txt_WCS, txt_WCS, "WCS通讯检测", "");
            Thread.Sleep(500);
 
            //2、MES接口反馈
            tipsMsg = "正在检测  MES服务...(" + (++checkIndex) + "/" + checkAllCount + ")";
            SetLablelMsg(tipsMsg);
            this.Bgw1.ReportProgress(20, tipsMsg);
            result2 = this.MesDection();
            Thread.Sleep(500);
 
            //3、堆垛机反馈
            tipsMsg = "正在检测  1号堆垛机连接...(" + (++checkIndex) + "/" + checkAllCount + ")";
            SetLablelMsg(tipsMsg);
            this.Bgw1.ReportProgress(30, tipsMsg);
            result3 = this.SrmDection(EDevice.一号堆垛机, "1号堆垛机");
            Thread.Sleep(500);
 
            tipsMsg = "正在检测  2号堆垛机连接...(" + (++checkIndex) + "/" + checkAllCount + ")";
            SetLablelMsg(tipsMsg);
            this.Bgw1.ReportProgress(40, tipsMsg);
            result4 = this.SrmDection(EDevice.二号堆垛机, "2号堆垛机");
            Thread.Sleep(500);
 
            //4、RGV和输送线反馈
 
 
            tipsMsg = "正在检测  RGV连接...(" + (++checkIndex) + "/" + checkAllCount + ")";
            SetLablelMsg(tipsMsg);
            this.Bgw1.ReportProgress(60, tipsMsg);
            result6 = this.RgvDection();
            Thread.Sleep(500);
 
            tipsMsg = "正在检测  输送线连接...(" + (++checkIndex) + "/" + checkAllCount + ")";
            SetLablelMsg(tipsMsg);
            this.Bgw1.ReportProgress(70, tipsMsg);
            //result7 = this.ConveyorDection();
            Thread.Sleep(500);
 
            tipsMsg = "检测完成...(" + (checkIndex) + "/" + checkAllCount + ")";
            SetLablelMsg(tipsMsg);
            DeviceStats = result1 && result2 && result3 && result4 && result5 && result6 && result7;
            this.Bgw1.ReportProgress(100, "检测完成...(" + checkIndex + "/" + checkAllCount + ")");
 
            Thread.Sleep(2000);
 
            this.BtnDection.Enabled = true;
            this.btn_Skip.Enabled = true;
 
        }
 
        #region MES检测
 
        private bool MesDection()
        {
            try
            {
                ////根据MatId取MES那里获取Mat对象,,这里还没写
                //MesMatInfo matInfo = new MesMatInfo()
                //{
                //    MatID = "DBCWMJS18_B2",
                //    MatName = ""
                //};
                //string resData = new MesWebService.MesWebServiceSoapClient().GetMesMatInfo(JsonConvert.SerializeObject(matInfo));
                //ResEntity re = JsonConvert.DeserializeObject<ResEntity>(resData);
                //if (re.resCode == "1")
                //{
                //    txtMESDec.Invoke(new Action(() => { txtMESDec.BackColor = Color.Salmon; }));
                //    txtMESDec.Invoke(new Action(() => { txtMESDec.Text = "MES服务检测失败!" + re.resMsg; }));
                //    return false;
                //}
 
                //txtMESDec.Invoke(new Action(() => { txtMESDec.BackColor = Color.LimeGreen; }));
                //txtMESDec.Invoke(new Action(() => { txtMESDec.Text = "MES服务检测成功!"; }));
                return true;
            }
            catch (Exception ex)
            {
                txtMESDec.Invoke(new Action(() => { txtMESDec.BackColor = Color.Salmon; }));
                txtMESDec.Invoke(new Action(() => { txtMESDec.Text = "MES服务检测失败!出现异常:" + ex.Message; }));
                return false;
            }
        }
 
        #endregion
 
        #region 堆垛机检测
 
        /// <summary>
        /// 堆垛机检测
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private bool SrmDection(EDevice deviceId, string msg)
        {
            TextBox tb = null;
            switch (deviceId)
            {
                case EDevice.一号堆垛机:
                    tb = txt_Srm1;
                    break;
                case EDevice.二号堆垛机:
                    tb = txt_Srm2;
                    break;
            }
            try
            {
                var result = false;
                string errMsg = "";
                int int_deviceId = (int)deviceId;
                using (var srmService = new SrmService.SrmServiceClient())
                {
 
                    var isHandShare = SrmBLL.IsHandShare(srmService, deviceId);
                    if (!isHandShare)
                    {
                        errMsg = deviceId.ToString() + "没有心跳";
                        tb.Invoke(new Action(() => { tb.BackColor = Color.Salmon; }));
                        tb.Invoke(new Action(() => { tb.Text = msg + "检测失败!" + errMsg; }));
                        return false;
                    }
 
                    SdaResEntity sdaResult = srmService.IsReady(int_deviceId, out errMsg);
                    if (sdaResult.result == false)
                    {
                        Log4NetHelper.WriteErrorLog(iWareCommon.Utils.LogType.DataProcess_BZ39_IssueInboundTask, "验证堆垛机是否可以接受任务出现错误,int_deviceId:" + int_deviceId + ",sdaResultStr:" + JsonConvert.SerializeObject(sdaResult));
                        result = false;
                    }
                    else
                    {
                        result = true;
                    }
 
                    if (result)
                    {
                        tb.Invoke(new Action(() => { tb.BackColor = Color.LimeGreen; }));
                        tb.Invoke(new Action(() => { tb.Text = msg + "检测成功!"; }));
                    }
                    else
                    {
                        if (sdaResult.resMsg == ESrmAlarm.无报警.ToString())
                        {
                            tb.Invoke(new Action(() => { tb.BackColor = Color.LimeGreen; }));
                            tb.Invoke(new Action(() => { tb.Text = msg + "检测成功!"; }));
                            return true;
                        }
                        tb.Invoke(new Action(() => { tb.BackColor = Color.Salmon; }));
                        tb.Invoke(new Action(() => { tb.Text = msg + "检测失败!" + sdaResult.resMsg; }));
                        return false;
                    }
 
                    return true;
                }
            }
            catch (Exception ex)
            {
                tb.Invoke(new Action(() => { tb.BackColor = Color.Salmon; }));
                tb.Invoke(new Action(() => { tb.Text = msg + "检测失败!" + ex.Message; }));
                return false;
            }
        }
 
        #endregion
 
        #region 桁架、RGV、输送线
 
 
        /// <summary>
        /// RGV检测
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private bool RgvDection()
        {
            var msg = "RGV";
            try
            {
                string errMsg = "";
                using (var rgvService = new RgvService.RgvServiceClient())
                {
                    //检测是否有心跳
                    var isRgvHandShare = RgvBLL.IsRgvHandShare(rgvService);
                    if (!isRgvHandShare)
                    {
                        text_RGV.Invoke(new Action(() => { text_RGV.BackColor = Color.Salmon; }));
                        text_RGV.Invoke(new Action(() => { text_RGV.Text = msg + "检测失败!RGV没有心跳"; }));
                        return false;
                    }
 
 
                    iWareCC.RgvService.SdaResEntity sdaResult = rgvService.IsRgvAuto((int)EDevice.RGV, Convert.ToInt32(EDevice.RGV).ToString());
                    if (sdaResult.result == false)
                    {
                        Log4NetHelper.WriteErrorLog(iWareCommon.Utils.LogType.DataProcess_RobotBuffer_ModeChange, "验证RGV是否可以接受任务出现错误,int_deviceId:" + (int)EDevice.RGV + ",sdaResultStr:" + JsonConvert.SerializeObject(sdaResult));
                        text_RGV.Invoke(new Action(() => { text_RGV.BackColor = Color.Salmon; }));
                        text_RGV.Invoke(new Action(() => { text_RGV.Text = msg + "检测失败!" + sdaResult.resMsg; }));
                        return false;
                    }
                    else
                    {
                        text_RGV.Invoke(new Action(() => { text_RGV.BackColor = Color.LimeGreen; }));
                        text_RGV.Invoke(new Action(() => { text_RGV.Text = msg + "检测成功!"; }));
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                text_RGV.Invoke(new Action(() => { text_RGV.BackColor = Color.Salmon; }));
                text_RGV.Invoke(new Action(() => { text_RGV.Text = msg + "检测失败!" + ex.Message; }));
                return false;
            }
        }
 
 
        #endregion
 
        #region 通讯测试
        private bool DeviceDection(TextBox txt1, TextBox txt2, string strMsg1, string strMsg2)
        {
            try
            {
                string _sip = "192.168.1.29";
                Ping ping = new Ping();
 
                PingReply pingReply = ping.Send(IPAddress.Parse(_sip));
                if (pingReply.Status == IPStatus.Success)
                {
 
                    txt1.Invoke(new Action(() => { txt1.BackColor = Color.LimeGreen; }));
                    txt1.Invoke(new Action(() => { txt1.Text = strMsg1 + strOK; }));
                    if (txt2.Name != txt1.Name)
                    {
                        txt2.Invoke(new Action(() => { txt2.BackColor = Color.LimeGreen; }));
                        txt2.Invoke(new Action(() => { txt2.Text = strMsg2 + strOK; }));
                    }
                    return true;
                }
                else
                {
                    //SysLog.saveLog(strMsg1 + strFail);
                    txt1.Invoke(new Action(() => { txt1.BackColor = Color.Salmon; }));
                    txt1.Invoke(new Action(() => { txt1.Text = strMsg1 + strFail; }));
 
                    if (txt2.Name != txt1.Name)
                    {
                        //SysLog.saveLog(strMsg2 + strFail);
                        txt2.Invoke(new Action(() => { txt2.BackColor = Color.Salmon; }));
                        txt2.Invoke(new Action(() => { txt2.Text = strMsg2 + strFail; }));
                    }
                    return false;
                }
            }
            catch (Exception ex)
            {
                //SysLog.saveLog(strMsg1 + strFail + ex);
                txt1.Invoke(new Action(() => { txt1.BackColor = Color.Salmon; }));
                txt1.Invoke(new Action(() => { txt1.Text = strMsg1 + strFail; }));
 
                if (txt2.Name != txt1.Name)
                {
                    //SysLog.saveLog(strMsg2 + strFail + ex);
                    txt2.Invoke(new Action(() => { txt2.BackColor = Color.Salmon; }));
                    txt2.Invoke(new Action(() => { txt2.Text = strMsg2 + strFail; }));
                }
                return false;
            }
        }
        #endregion
 
        #region 消息赋值
        private void SetLablelMsg(string strMsg)
        {
            lbl_Msg.Invoke(new Action(() => { lbl_Msg.Text = strMsg; }));
        }
        #endregion
 
        private void Bgw1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e == null)
            {
                this.DialogResult = DialogResult.OK;
                return;
            }
            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message);
            }
            else if (e.Cancelled)
            {
                MessageBox.Show("任务取消。");
            }
            else if (!DeviceStats)
            {
                //WZ.Useful.Commons.MessageUtil.ShowError("通讯设备检测失败!");
            }
            else
            {
                //MessageBox.Show("检测完成!");
                this.DialogResult = DialogResult.OK;
            }
        }
 
        private void Bgw1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            this.pgbDec.Value = e.ProgressPercentage;
        }
 
        private void SystemCheckForm_Load(object sender, EventArgs e)
        {
            this.Bgw1.RunWorkerAsync(); // 运行 backgroundWorker 组件
        }
 
        private void BtnDection_Click(object sender, EventArgs e)
        {
            this.pgbDec.Value = 0;
            TxtClear();
            this.Bgw1.RunWorkerAsync(); // 运行 backgroundWorker 组件
        }
 
        private void TxtClear()
        {
 
            TextBox[] txts = new TextBox[] { txt_WCS, txtMESDec, txt_Srm1, txt_Srm2, txt_Truss, txt_Conveyor, text_RGV };
 
            foreach (TextBox txt in txts)
            {
                string strTxt = txt.Text.ToString().Trim();
                txt.BackColor = Color.WhiteSmoke;
                txt.Text = strTxt.Contains(strOK) ? strTxt.Substring(0, strTxt.Length - 3) : strTxt;
                txt.Text = strTxt.Contains(strFail) ? strTxt.Substring(0, strTxt.Length - 3) : strTxt;
            }
        }
 
        private void btn_Skip_Click(object sender, EventArgs e)
        {
            this.DeviceStats = true;
            Bgw1_RunWorkerCompleted(null, null);
        }
    }
}