schangxiang@126.com
2025-11-04 ca398287db3f5ea01f03aac4a85edb13b28100a6
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
using DriverLib.Engine;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using XCore;
using XImagingXhandler.XDAL;
using XHandler.View.MethodProperty;
using XHandler.View;
using XHandler.Class.DataEx;
using HxSocket;
using DataEntity.Share;
using XCommon.Log;
using XHandler.Controls.Run.Com;
using static HxEnum.OperationTypeEnum;
using MySqlX.XDevAPI.Common;
using SqlSugar;
using XImaging.Automation.Service.Interface;
using DataRWDAL;
using DataEntity;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
 
namespace XHandler.Controls
{
    public class UnloadTipsControl
    {
        string strCurrentCulture = "";
        WellCalc wellCalc = new WellCalc();
        LatticeBll latticeBll = new LatticeBll();
        UnloadTipsBll unloadTipsBll = new UnloadTipsBll();
        public RunWnd launchView = null;
        public HxSocketClient socketTcpClientToRemote = null;
 
        public UnloadTipsControl(string strCurrentCulture)
        {
            this.strCurrentCulture = strCurrentCulture;
        }
 
        #region 执行卸载吸头,返回结果字符串
        /// <summary>
        /// 执行卸载吸头,返回结果字符串
        /// </summary>
        /// <param name="platformNodeList"></param>
        /// <param name="methodNode">装载方法属性节点对象</param>
        /// <param name="isSimulator">0:连接谁;1:仿真</param>
        /// <returns></returns>
        public bool ExecuteUnloadTips(XmlNodeList platformNodeList, XmlNode methodNode, bool isSimulator)
        {
            bool result = true;
 
            if (launchView._cancelSource.IsCancellationRequested)
            {
                result = false;
                return result;
            }
 
            try
            {
                #region Start Log
                if (strCurrentCulture.Equals("zh-CN"))
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strStart.ToString());
                }
                else
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】start:");
                }
                #endregion
 
                #region 数据准备 
                string channelNums = methodNode.SelectSingleNode("channels").InnerText;
                string armName = methodNode.SelectSingleNode("arm/text").InnerText;
                string armId = methodNode.SelectSingleNode("arm/value").InnerText;
                string latticeid = methodNode.SelectSingleNode("position/value").InnerText;
                string latticenum = methodNode.SelectSingleNode("position/text").InnerText;
                bool isputToSource = methodNode.SelectSingleNode("isputToSource").InnerText.ToLower() == "true" ? true : false;
                #endregion
 
                #region 数据验证
                if (channelNums == "")
                {
                    if (strCurrentCulture.Equals("zh-CN"))
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler:【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strWithoutChannel.ToString());
                    }
                    else
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler:Channel wasn't set, please check!");
                    }
                    if (launchView.isRemotingOper)
                    {
                        launchView.OnError?.Invoke(launchView.remoteObjectCmd, "EC-1019", 5, Properties.MachineRunResource.strWithoutChannel, 2);
                    }
                    result = false;
                    return result;
                }
                #endregion
 
                DataTable dt = null;
                List<TipsTable> dtTipBase = new List<TipsTable>();
                Lattice lattice = new Lattice();
                TabletopTemplate tabletopTemplate = TabletopTemplateDB.GetCurrentAppTabletopTemplateCollectionFromdb();  //增加台面模板判断
                if (tabletopTemplate == null)
                {
                    lattice = LatticeDB.GetLatticeDataByIdFromdb(latticenum, Convert.ToInt32(armId), Shared.SoftwareInformation.software_device_number); // 卸载位
                }
                else
                {
                    string armid = methodNode.SelectSingleNode("arm/value").InnerText;
                    lattice = LatticeDB.GetLatticeDataByLatticeNumAndTempIdFromdb(latticenum, Convert.ToInt32(armid), Shared.SoftwareInformation.software_device_number, tabletopTemplate.tabletopid);
                }
                //Lattice lattice = LatticeDB.GetLatticeDataByIdFromdb(latticenum, Convert.ToInt32(armId), Shared.SoftwareInformation.software_device_number); // 卸载位
                if (isputToSource)      // 原孔位放置
                {
                    //查询板位上是否有空闲的耗材孔
                    foreach (XmlNode x in platformNodeList)
                    {
                        if (launchView.currentWellLatticeId != string.Empty)
                        {
                            string a = x.ChildNodes[0].InnerText;
 
                            
                            int latticeId = 0;
                            if (tabletopTemplate == null)
                            {
                                a = ControlCom.GetLatticeId(Convert.ToInt32(a)).ToString();
                            }
                            else
                            {
                                string latticeNumber = "P" + a;
                                a = LatticeDB.GetLatticeDataByLatticeNumAndTempIdFromdb(latticeNumber, Convert.ToInt32(Shared.DeviceArmList.SingleOrDefault(t => t.arm_type.Equals(1)).device_arm_id), Shared.SoftwareInformation.software_device_number, tabletopTemplate.tabletopid).lattice_id;
                            }
                            
                            if (a == launchView.currentWellLatticeId)
                            {
                                lattice = LatticeDB.GetLatticeDataByIdFromdb(launchView.currentWellLatticeId);
 
                                if (!string.IsNullOrEmpty(launchView.currentInValidWell))
                                {
                                    XmlNodeList xmlNodeList = x.SelectNodes("labware");
                                    Labware labware = LabwareDB.GetLabware(xmlNodeList[xmlNodeList.Count-1].ChildNodes[0].InnerText);
 
                                    string t1 = launchView.currentInValidWell;
                                    string p = lattice.lattice_id;
                                    string[] tWells = t1.Split(',');
                                    for (int i = 0; i < tWells.Length; i++)
                                    {
                                        TipsTable t = new TipsTable();
                                        t.labware_id = labware.labware_id;
                                        t.lattice_id = p;
                                        t.wellname = tWells[i];
                                        t.axis_b_X = 0.0f;
                                        t.axis_b_Y = 0.0f;
                                        t.axis_b_Z = 0.0f;
                                        t.well_top_shape = 0;
                                        t.axis_b_r = 0.0f;
                                        t.isUsed = 0;
                                        t.lattice_num = lattice.lattice_num;
                                        dtTipBase.Add(t);
                                    }
 
                                    List<Lattice> lattices = new List<Lattice>();
                                    lattices.Add(lattice);
                                    dt = ControlCom.GenerateCurrentTablayoutWellCoordinate(labware, lattices);
                                }
                                else
                                {
                                    result = false;
                                    return result;
                                }
                                break;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
 
                    List<TipsTable> dtsTips = new List<TipsTable>();
 
                    if(dt==null)
                    {
                        result = false;
                        return result;
                    }
                    // dt 转化为实体类对象集合
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        //去除未被选中的孔位(即非可用枪头孔位)
                        var a = dtTipBase.FirstOrDefault(x => x.labware_id.Equals(dt.Rows[i]["labware_id"].ToString()) &&
                                                    x.lattice_id.Equals(dt.Rows[i]["lattice_id"].ToString()) &&
                                                    x.lattice_num.Equals(dt.Rows[i]["lattice_num"].ToString()) &&
                                                    x.wellname.Equals(dt.Rows[i]["wellname"].ToString()));
                        if (a != null)
                        {
                            TipsTable tipsTable = new TipsTable();
                            tipsTable.labware_id = dt.Rows[i]["labware_id"].ToString();
                            tipsTable.lattice_id = dt.Rows[i]["lattice_id"].ToString();
                            tipsTable.wellname = dt.Rows[i]["wellname"].ToString();
                            tipsTable.axis_b_X = (float)Convert.ToDouble(dt.Rows[i]["axis_b_X"].ToString());
                            tipsTable.axis_b_Y = (float)Convert.ToDouble(dt.Rows[i]["axis_b_Y"].ToString());
                            tipsTable.axis_b_Z = (float)Convert.ToDouble(dt.Rows[i]["axis_b_Z"].ToString());
                            tipsTable.well_top_shape = Convert.ToInt32(dt.Rows[i]["well_top_shape"].ToString());
                            tipsTable.axis_b_r = (float)Convert.ToDouble(dt.Rows[i]["axis_b_r"].ToString());
                            tipsTable.isUsed = Convert.ToInt32(dt.Rows[i]["isUsed"].ToString());
                            tipsTable.lattice_num = dt.Rows[i]["lattice_num"].ToString();
                            dtsTips.Add(tipsTable);
                        }
                    }
 
                    // 通道号
                    string[] strCh = channelNums.Split(',');
                    UnloadTipsMParam unloadTipsMParam = new UnloadTipsMParam();
                    unloadTipsMParam.basezAxisVal = (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisSafeVal"]);
 
                    TipsTable tipsTableSource = dtsTips.FirstOrDefault(t => t.lattice_num.Equals(lattice.lattice_num));
 
                    string strWell = launchView.currentInValidWell;
                    unloadTipsMParam.xAxisVal = (float)tipsTableSource.axis_b_X;
                    unloadTipsMParam.yAxisVal = (float)tipsTableSource.axis_b_Y;
                    unloadTipsMParam.zAxisVal = (float)tipsTableSource.axis_b_Z - 10f;
                    unloadTipsMParam.armId = Convert.ToInt32(armId);
 
                    launchView.SetWaitOne();    // 暂停
                    HxResult ret = unloadTipsBll.ExecuteUnLoadTips(unloadTipsMParam, isSimulator);
 
                    #region 错误处理
                    result = DoError(platformNodeList, methodNode, isSimulator, ret, tipsTableSource, strWell, latticenum);
                    #endregion
                }
                else//选定垃圾桶板位退枪头
                {
                    if (!string.IsNullOrEmpty(latticenum))
                    {
                        //判断是否是垃圾桶板位
                        if (lattice.is_trash == 1)
                        {
                            if (Shared.ChannelCount == 1)
                            {
                                UnloadTipsMParam unloadTipsMParam = new UnloadTipsMParam();
                                unloadTipsMParam.xAxisVal = (float)lattice.lattice_X+ (float)lattice.lattice_length/2f;
                                unloadTipsMParam.yAxisVal = (float)lattice.lattice_Y + (float)lattice.lattice_width / 2f;
                                unloadTipsMParam.zAxisVal = (float)lattice.lattice_Z - ControlCom.CurrentLengthOfTip - 50 - (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisWasteVal"].ToString());
 
                                unloadTipsMParam.armId = Convert.ToInt32(methodNode.SelectSingleNode("arm/value").InnerText);
                                unloadTipsMParam.basezAxisVal = (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisSafeVal"]);
 
                                launchView.SetWaitOne();//暂停
                                HxResult ret = unloadTipsBll.ExecuteUnLoadTips(unloadTipsMParam, isSimulator);
                                
                                #region 错误处理
                                result = DoError(platformNodeList, methodNode, isSimulator, ret, null, string.Empty, latticenum);
                                #endregion
                            }
                            else if (Shared.ChannelCount > 1&&!Shared.ChannelCount.Equals(96))
                            {
                                UnloadTipsMParamSH unloadTipsMParam = new UnloadTipsMParamSH();
                                unloadTipsMParam.yAxisVal = (float)lattice.lattice_Y + 30f;
                                float[] f = new float[channelNums.Split(',').Length];
                                for (int i = 0; i < f.Length; i++)
                                {
                                    f[i] = (float)lattice.lattice_Z-ControlCom.CurrentLengthOfTip-50- (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisWasteVal"].ToString());
                                }
 
                                unloadTipsMParam.channelCount = f.Length;
                                int[] c = new int[channelNums.Split(',').Length];
                                string[] cn = channelNums.Split(',');
                                for (int j = 0; j < c.Length; j++)
                                {
                                    c[j] = Convert.ToInt32(cn[j]);
                                }
 
                                unloadTipsMParam.channelId = c;
                                unloadTipsMParam.zAxisVal = f;
 
                                unloadTipsMParam.yChannelGapVal = 9;
                                unloadTipsMParam.armId = Convert.ToInt32(methodNode.SelectSingleNode("arm/value").InnerText);
                                unloadTipsMParam.basezAxisVal = (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisSafeVal"]);
 
                                launchView.SetWaitOne();//暂停
                                HxResult ret = unloadTipsBll.ExecuteUnLoadTips(unloadTipsMParam, isSimulator);
 
                                #region 错误处理
                                result = DoError(platformNodeList, methodNode, isSimulator, ret, null, string.Empty, latticenum);
                                #endregion
                            }
                            else if (Shared.ChannelCount.Equals(96))
                            {
                                UnloadTipsMParam unloadTipsMParam = new UnloadTipsMParam();
                                unloadTipsMParam.xAxisVal = (float)lattice.lattice_X;
                                unloadTipsMParam.yAxisVal = (float)lattice.lattice_Y+13;
                                unloadTipsMParam.zAxisVal = (float)lattice.lattice_Z-80;
 
                                unloadTipsMParam.armId = Convert.ToInt32(methodNode.SelectSingleNode("arm/value").InnerText);
                                unloadTipsMParam.basezAxisVal = (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisSafeVal"]);
 
                                launchView.SetWaitOne();//暂停
                                HxResult ret = unloadTipsBll.ExecuteUnLoadTips(unloadTipsMParam, isSimulator);
 
                                #region 错误处理
                                result = DoError(platformNodeList, methodNode, isSimulator, ret, null, string.Empty, latticenum);
                                #endregion
                            }
                        }
                        else
                        {
                            if (strCurrentCulture.Equals("zh-CN"))
                            {
                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.RunUnloadTipsResource.strUnloadTipTargetWrong);
                            }
                            else
                            {
                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】Target lattice isn't trash, please task will stop!");
                            }
                            if (launchView.isRemotingOper)
                            {
                                launchView.OnError?.Invoke(launchView.remoteObjectCmd, "EC-1019", 5, Properties.RunUnloadTipsResource.strWithoutLattice, 2);
                            }
                            result = false;
                            return result;
                        }
                    }
                    else
                    {
                        result = ExecuteUnloadTipsInToTrash(platformNodeList, methodNode, isSimulator);
                    }
                }
            }
            catch (Exception ex)
            {
                if (strCurrentCulture.Equals("zh-CN"))
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strError.ToString() + " 源 " + ex.Source + " 错误信息 " + ex.Message + ";");
                }
                else
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】error:source:" + ex.Source + ";error:" + ex.Message + ";");
                }
                if (launchView.isRemotingOper)
                {
                    launchView.OnError?.Invoke(launchView.remoteObjectCmd, "EC-1001", 5, "error:source:" + ex.Source + ";error:" + ex.Message + ";", 2);
                }
                result = false;
            }
 
 
            return result;
        }
 
        private bool DoError(XmlNodeList labwareNode, XmlNode methodNode, bool isSimulator, HxResult ret, TipsTable tipsTableSource, string strWell, string latticenum)
        {
            bool result = true;
 
            if (ret.Result != ResultType.Success)
            {
                #region 错误处理
                OperateDialog plsConfirmOper = null;
                if (!launchView.isRemotingOper)
                {
                    System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        plsConfirmOper = new OperateDialog(strCurrentCulture.Equals("zh-CN") ? Properties.RunUnloadTipsResource.strFailWhatToDo : "unloadtips are fail! What do you want to do?");
                        plsConfirmOper.ShowDialog();
                    }));
                }
                else
                {
                    launchView.OnError?.Invoke(launchView.remoteObjectCmd, "EC-1043", 5, Properties.RunUnloadTipsResource.strFailWhatToDo, 2);
                    plsConfirmOper = new OperateDialog(strCurrentCulture.Equals("zh-CN") ? Properties.RunUnloadTipsResource.strFailWhatToDo : "unloadtips are fail! What do you want to do?");
                    plsConfirmOper.ShowDialog();
                }
 
                if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Retry)           // 重试
                {
                    result = ExecuteUnloadTips(labwareNode, methodNode, isSimulator);
                    return result;
                }
                else if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Cancel)     // 终止
                {
                    if (strCurrentCulture.Equals("zh-CN"))
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress + Properties.RunUnloadTipsResource.strUnLoadTipWasStopped);
                    }
                    else
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress:unload tip was stopped!");
                    }
                    if (launchView.isRemotingOper)
                    {
                        launchView.OnError?.Invoke(launchView.remoteObjectCmd, "EC-1044", 5, Properties.RunUnloadTipsResource.strUnLoadTipWasStopped, 2);
                    }
                    result = false;
                    return result;
                }
                else if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Continue)   // 跳过
                {
                    if (strCurrentCulture.Equals("zh-CN"))
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress + Properties.RunUnloadTipsResource.strUnLoadTipWasSkipped);
                    }
                    else
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress:unload tip was skipped!");
                    }
                }
                #endregion
            }
            else
            {
                if (tipsTableSource != null)
                {
                    launchView.UpdateLabwaretipsPutIntoSrc(tipsTableSource, strWell);
                }
                launchView.currentIsLoadingTips = false;
                ControlCom.CurrentLengthOfTip = 0f;
                if (strCurrentCulture.Equals("zh-CN"))
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress + Properties.RunUnloadTipsResource.strUnloadTipSuccess + "卸载到板位 " + latticenum);
                }
                else
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress:unload tips are success from " + latticenum + " lattice!");
                }
            }
 
            if (strCurrentCulture.Equals("zh-CN"))
            {
                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strEnd);
            }
            else
            {
                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】complete;");
            }
 
            return result;
        }
        #endregion
 
        #region 执行卸载吸头到垃圾桶板位,返回结果字符串
        /// <summary>
        /// 执行卸载吸头到垃圾桶板位,返回结果字符串
        /// </summary>
        /// <param name="platformNodeList"></param>
        /// <param name="methodNode">装载方法属性节点对象</param>
        /// <param name="isSimulator">0:连接谁;1:仿真</param>
        /// <returns></returns>
        public bool ExecuteUnloadTipsInToTrash(XmlNodeList platformNodeList, XmlNode methodNode, bool isSimulator)
        {
            bool result = true;
            try
            {
                if (launchView._cancelSource.IsCancellationRequested)
                {
                    result = false;
                    return result;
                }
 
                if (strCurrentCulture.Equals("zh-CN"))
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【卸载枪头】" + Properties.MachineRunResource.strStart.ToString());
                }
                else
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【unloadtip method】start:");
                }
 
                #region 数据准备 
                string channelNums = methodNode.SelectSingleNode("channels").InnerText;
                string armName = methodNode.SelectSingleNode("arm/text").InnerText;
                string armId = methodNode.SelectSingleNode("arm/value").InnerText;
                #endregion
 
                #region 数据验证
                if (channelNums == "")
                {
                    //MethodMsg methodMsg = new MethodMsg(Guid.NewGuid().ToString(), "ID202_Choice_machine", 5, "", "ExecuteUnloadTipsInToTrash", "1019",
                    //                                    "卸载枪头方法未指定卸载的通道,卸载枪头方法终止运行。", 6, 0);
                    //if (socketTcpClientToRemote != null)
                    //{
                    //    socketTcpClientToRemote.sendmessageError(socketTcpClientToRemote.CreateSendMsgContent(methodMsg, false), launchView.isRemotingOper);
                    //}
                    if (strCurrentCulture.Equals("zh-CN"))
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler:【卸载枪头】" + Properties.MachineRunResource.strWithoutChannel.ToString());
                    }
                    else
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler:Channel wasn't set, please check!");
                    }
                    if (launchView.isRemotingOper)
                    {
                        launchView.OnError?.Invoke(launchView.remoteObjectCmd, "EC-1019", 5, Properties.MachineRunResource.strWithoutChannel, 2);
                    }
                    result = false;
                    return result;
                }
                #endregion
 
                List<Lattice> lattice = LatticeDB.GetTrashLatticeDataByIdFromdb(armId, Shared.SoftwareInformation.software_device_number);       // 获取当前垃圾桶台面板位信息
 
                Random random = new Random();
                int i = random.Next(0, lattice.Count);
 
                launchView.SetWaitOne();//暂停
                if (Shared.ChannelCount == 1)
                {
                    UnloadTipsMParam unloadTipsMParam = new UnloadTipsMParam();
                    //unloadTipsMParam.xAxisVal = (float)lattice[i].lattice_X;
                    //unloadTipsMParam.yAxisVal = (float)lattice[i].lattice_Y;
                    //unloadTipsMParam.zAxisVal = (float)lattice[i].lattice_Z;
                    unloadTipsMParam.xAxisVal = (float)lattice[i].lattice_X + ((float)lattice[i].lattice_length / (float)2f);
                    unloadTipsMParam.yAxisVal = (float)lattice[i].lattice_Y + ((float)lattice[i].lattice_width / (float)2f);
                    unloadTipsMParam.zAxisVal = (float)lattice[i].lattice_Z - ControlCom.CurrentLengthOfTip - 50 - (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisWasteVal"].ToString());
 
 
                    unloadTipsMParam.armId = Convert.ToInt32(armId);
                    unloadTipsMParam.basezAxisVal = (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisSafeVal"]);
 
                    launchView.SetWaitOne();//暂停
                    HxResult ret = unloadTipsBll.ExecuteUnLoadTips(unloadTipsMParam, isSimulator);
 
                    #region 错误处理
                    result = DoError(platformNodeList, methodNode, isSimulator, ret, null, string.Empty, lattice[i].lattice_num);
                    #endregion
                }
                else if(Shared.ChannelCount > 1)
                {
                    UnloadTipsMParamSH unloadTipsMParam = new UnloadTipsMParamSH();
                    unloadTipsMParam.xAxisVal = (float)lattice[i].lattice_X;
                    unloadTipsMParam.yAxisVal = (float)lattice[i].lattice_Y;
 
                    float[] f = new float[channelNums.Split(',').Length];
                    for (int j = 0; j < f.Length; j++)
                    {
                        f[j] = (float)lattice[i].lattice_Z - ControlCom.CurrentLengthOfTip - 50- (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisWasteVal"].ToString());
                    }
 
                    unloadTipsMParam.channelCount = f.Length;
                    int[] c = new int[channelNums.Split(',').Length];
                    string[] cn = channelNums.Split(',');
                    for (int j = 0; j < c.Length; j++)
                    {
                        c[j] = Convert.ToInt32(cn[j]);
                    }
 
                    unloadTipsMParam.channelId = c;
                    unloadTipsMParam.zAxisVal = f;
 
                    unloadTipsMParam.armId = Convert.ToInt32(armId);
                    unloadTipsMParam.basezAxisVal = (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisSafeVal"]);
                    unloadTipsMParam.yChannelGapVal = (float)9f;
 
                    launchView.SetWaitOne();//暂停
                    HxResult ret = unloadTipsBll.ExecuteUnLoadTips(unloadTipsMParam, isSimulator);
 
                    #region 错误处理
                    result = DoError(platformNodeList, methodNode, isSimulator, ret, null, string.Empty, lattice[i].lattice_num);
                    #endregion
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
                result = false;
            }
 
            return result;
        }
        #endregion
 
        #region 控制面板用
        /// <summary>
        /// 卸载枪头
        /// </summary>
        /// <returns></returns>
        public string UnLoadTip(string armValue="0")
        {
            string strMsg = string.Empty;
            string currentArmValue = string.Empty;
 
            // 获取当前垃圾桶台面板位信息
            List<Lattice> lattice = new List<Lattice>();
            if (armValue != "0" || armValue != Shared.ChanelArmId.ToString())
            {
                currentArmValue = armValue;
                lattice = LatticeDB.GetTrashLatticeDataByIdFromdb(armValue, Shared.SoftwareInformation.software_device_number);
            }
            else
            {
                currentArmValue = Shared.ChanelArmId.ToString();
                lattice = LatticeDB.GetTrashLatticeDataByIdFromdb(Shared.ChanelArmId.ToString(), Shared.SoftwareInformation.software_device_number);
            }
            Random random = new Random();
            int index = random.Next(0, lattice.Count);
            HxResult ret = new HxResult();
 
            if (Shared.ChannelCount == 1)
            {
                UnloadTipsMParam unloadTipsMParam = new UnloadTipsMParam();
                if (Shared.SoftwareInformation.software_device_number == DeviceCategory.DeviceHXFX)
                {
                    unloadTipsMParam.xAxisVal = (float)lattice[index].lattice_X + (float)lattice[index].lattice_length / 2f;
                    unloadTipsMParam.yAxisVal = (float)lattice[index].lattice_Y + (float)lattice[index].lattice_length / 2f;
                }
                else
                {
                    unloadTipsMParam.xAxisVal = (float)lattice[index].lattice_X;
                    unloadTipsMParam.yAxisVal = (float)lattice[index].lattice_Y + 30f;
                }
                unloadTipsMParam.zAxisVal = (float)lattice[index].lattice_Z - ControlCom.CurrentLengthOfTip - 50 - (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisWasteVal"].ToString());
 
                unloadTipsMParam.armId = Convert.ToInt32(currentArmValue);//Shared.ChanelArmId;
                unloadTipsMParam.basezAxisVal = (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisSafeVal"]);
                ret = unloadTipsBll.ExecuteUnLoadTips(unloadTipsMParam, false);
            }
            else if (Shared.ChannelCount > 1)
            {
                UnloadTipsMParamSH unloadTipsMParam = new UnloadTipsMParamSH();
                unloadTipsMParam.yAxisVal = (float)lattice[index].lattice_Y + 30f;
                float[] f = new float[Shared.ChannelsId.Length];
                for (int i = 0; i < f.Length; i++)
                {
                    f[i] = (float)lattice[index].lattice_Z - ControlCom.CurrentLengthOfTip - 50-(float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisWasteVal"].ToString());
                }
 
                unloadTipsMParam.channelCount = f.Length;
                unloadTipsMParam.channelId = Shared.ChannelsId;
                unloadTipsMParam.zAxisVal = f;
                unloadTipsMParam.yChannelGapVal = 9;
                unloadTipsMParam.armId = Convert.ToInt32(currentArmValue);// Shared.ChanelArmId;
                unloadTipsMParam.basezAxisVal = (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisSafeVal"]);
 
                ret = unloadTipsBll.ExecuteUnLoadTips(unloadTipsMParam, false);
            }
 
            if (ret.Result != ResultType.Success)
            {
                strMsg = string.Format("卸载Tip失败:{0}", ret.AlarmInfo);
            }
 
            return strMsg;
        }
 
        #endregion
 
        #region 控制面板用
        /// <summary>
        /// 卸载所有臂通道枪头
        /// </summary>
        /// <returns></returns>
        public string UnLoadTipFromAllArm()
        {
            string strMsg = string.Empty;
            List<DeviceArm> deviceArmList = DeviceArmDB.GetDeviceArmFromdb(Shared.SoftwareInformation.software_information_id);
            Shared.DeviceArmList = deviceArmList;
            List<DeviceArm> deviceArmArray= Shared.DeviceArmList.Where(x => x.software_information_id.Equals(Shared.SoftwareInformation.software_information_id) && x.arm_type.Equals(1)).ToList();
            foreach (DeviceArm decArm in deviceArmArray)
            {
                DeviceArm deviceArm = decArm;
 
                // 获取当前垃圾桶台面板位信息
                List<Lattice> lattice = LatticeDB.GetTrashLatticeDataByIdFromdb(deviceArm.device_arm_id.ToString(), Shared.SoftwareInformation.software_device_number);
                Random random = new Random();
                int index = random.Next(0, lattice.Count);
                HxResult ret = new HxResult();
 
                if (deviceArm.channels == 1)
                {
                    UnloadTipsMParam unloadTipsMParam = new UnloadTipsMParam();
                    unloadTipsMParam.xAxisVal = (float)lattice[index].lattice_X;
                    unloadTipsMParam.yAxisVal = (float)lattice[index].lattice_Y + 30f;
                    unloadTipsMParam.zAxisVal = (float)lattice[index].lattice_Z - ControlCom.CurrentLengthOfTip - 50 - (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisWasteVal"].ToString());
 
                    unloadTipsMParam.armId = deviceArm.device_arm_id;
                    unloadTipsMParam.basezAxisVal = (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisSafeVal"]);
                    ret = unloadTipsBll.ExecuteUnLoadTips(unloadTipsMParam, false);
                }
                else if (deviceArm.channels > 1)
                {
                    UnloadTipsMParamSH unloadTipsMParam = new UnloadTipsMParamSH();
                    unloadTipsMParam.yAxisVal = (float)lattice[index].lattice_X;
                    unloadTipsMParam.yAxisVal = (float)lattice[index].lattice_Y + 30f;
 
                    if (deviceArm.device_arm_property == "")
                    {
                        continue;
                    }
                    string[] strChannels = deviceArm.device_arm_property.Trim().Split(',');
                    int[] iChannels = new int[strChannels.Length];
                    for (int j = 0; j < strChannels.Length; j++)
                    {
                        iChannels[j] = Convert.ToInt32(strChannels[j]);
                    }
 
                    float[] f = new float[iChannels.Length];
                    for (int i = 0; i < f.Length; i++)
                    {
                        f[i] = (float)lattice[index].lattice_Z - ControlCom.CurrentLengthOfTip - 50 - (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisWasteVal"].ToString());
                    }
 
                    unloadTipsMParam.channelCount = f.Length;
                    unloadTipsMParam.channelId = iChannels;
                    unloadTipsMParam.zAxisVal = f;
                    unloadTipsMParam.yChannelGapVal = 9;
                    unloadTipsMParam.armId = deviceArm.device_arm_id;
                    unloadTipsMParam.basezAxisVal = (float)Convert.ToDouble(ConfigurationManager.AppSettings["zAxisSafeVal"]);
 
                    ret = unloadTipsBll.ExecuteUnLoadTips(unloadTipsMParam, false);
                }
 
                if (ret.Result != ResultType.Success)
                {
                    strMsg = string.Format("卸载Tip失败:{0}", ret.AlarmInfo);
                    break;
                }
            }
 
            return strMsg;
        }
 
        #endregion
    }
}