schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
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
using DataEntity;
using DataEntity.Share;
using DataRWDAL;
using DriverLib.Engine;
using MySqlX.XDevAPI.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Xml;
using XCommon;
using XCommon.Log;
using XCore;
using XCoreBLL;
using XHandler.Controls.Run.Com;
using XHandler.View;
using XHandler.View.MethodProperty;
using XImaging.Automation.Service.Interface;
using XImagingXhandler.XDAL;
using static HxEnum.OperationTypeEnum;
 
namespace XHandler.Controls
{
    /// <summary>
    /// 开关盖
    /// </summary>
    public class SwitchLidControl
    {
        string strCurrentCulture = "";
        WellCalc wellCalc = new WellCalc();
        LatticeBll latticeBll = new LatticeBll();
        SwitchLidBll switchLidBll = new SwitchLidBll();
        public RunWnd launchView = null;
 
        public SwitchLidControl(string strCurrentCulture)
        {
            this.strCurrentCulture = strCurrentCulture;
        }
 
        #region 执行开关盖,返回结果字符串
        /// <summary>
        /// 执行开关盖,返回结果字符串
        /// </summary>
        /// <param name="xmlEnv">板位节点信息</param>
        /// <param name="methodNode">装载方法属性节点对象</param>
        /// <param name="zAxisVal">z轴安全距离</param>
        /// <param name="isSimulator">0:连接谁;1:仿真</param>
        /// <returns></returns>
        public bool ExecuteSwitchLid(XmlNode xmlEnv, XmlNode methodNode, float zAxisVal, bool isSimulator)
        {
            bool result = true;
            HxResult ret = new HxResult();
            if (launchView._cancelSource.IsCancellationRequested)
            {
                result = false;
                return result;
            }
 
            #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 数据准备 
            MethodSwitchLid methodSwitchLid = switchLidBll.GenerateMethodSwitchLidDataByXmlNode(methodNode);
            #endregion
 
            #region 数据验证
            Labware labwares = LabwareDB.GetLabware(methodSwitchLid.labwareValue);
            string strWells = methodSwitchLid.wellarray;
            string[] wells = new string[] { };
            string wellVariable = string.Empty;
            if (!string.IsNullOrEmpty(strWells))
            {
                //判断是否包含等号,如果是包含等号的,则是变量控制孔位
                if (strWells.Contains(","))
                {
                    wells = strWells.Split(',');
                }
                else if (strWells.Contains("="))
                {
                }
            }
 
            else if (strWells.Contains("="))
            {
                wellVariable = strWells.Substring(strWells.LastIndexOf('=') + 1, (strWells.Length - strWells.LastIndexOf('=') - 1));
 
                Variable variable = new Variable();
                Stack<Variable> stackTem = new Stack<Variable>();//临时存储变量过得对象
                int totalLoop = launchView.gloadVariable.Count;
                // 从当前变量字典中取出变量的值
                for (int i = 0; i < totalLoop; i++)
                {
                    Variable v = launchView.gloadVariable.Pop();         //取出最近的一个匹配变量   
                    stackTem.Push(v);
 
                    if (v.variablename == wellVariable)
                    {
                        variable = v;
                        break;
                    }
                }
                int totalLoopTem = stackTem.Count;
                for (int i = 0; i < totalLoopTem; i++)
                {
                    Variable v = stackTem.Pop();
                    launchView.gloadVariable.Push(v);
                }
            }
 
 
            // 给孔位排序
            if (strWells.Contains(','))
            {
                string suffix = wells[0].Substring(1, wells[0].Length - 1);
                List<string> sortWellName = new List<string>();
 
                if (Shared.ChannelCount == 1)
                {
                    for (int i = 0; i < labwares.number_row; i++)
                    {
                        string rowName = ComUtility.GetRowChar(i);
                        string rowWellName = rowName + suffix;
                        if (wells.Contains(rowWellName))
                        {
                            sortWellName.Add(rowWellName);
                        }
                    }
                    wells = sortWellName.ToArray();
                }
                else if (Shared.ChannelCount > 1)
                {
 
                }
            }
            else if (!string.IsNullOrEmpty(strWells) &&
                !strWells.Contains(',') &&
                !strWells.Contains("="))        // 只有一个孔位
            {
                wells = new string[] { strWells };
            }
            else if (strWells.Contains("="))    // 利用循环
            {
                string strvariable = strWells.Substring(strWells.LastIndexOf('=') + 1, (strWells.Length - strWells.LastIndexOf('=') - 1));
                Variable variable = new Variable();
                Stack<Variable> stackTem = new Stack<Variable>();//临时存储变量过得对象
                int totalLoop = launchView.gloadVariable.Count;
                // 从当前变量字典中取出变量的值
                for (int i = 0; i < totalLoop; i++)
                {
                    Variable v = launchView.gloadVariable.Pop();         //取出最近的一个匹配变量   
                    stackTem.Push(v);
 
                    if (v.variablename == strvariable)
                    {
                        variable = v;
                        break;
                    }
                }
                int totalLoopTem = stackTem.Count;
                for (int i = 0; i < totalLoopTem; i++)
                {
                    Variable v = stackTem.Pop();
                    launchView.gloadVariable.Push(v);
                }
 
                if (variable.variablename.Equals(string.Empty) && strvariable.Length >= 1)//没有查找到变量名,看看是不是表达式,并求出表达式值
                {
                    totalLoop = launchView.gloadVariable.Count;
                    List<Variable> variablelist = new List<Variable>();
                    stackTem = new Stack<Variable>();//临时存储变量过得对象
                    for (int i = 0; i < totalLoop; i++) //看看表达式中包不包含变量,如果包含就把变量全部替换成值
                    {
                        Variable v = launchView.gloadVariable.Pop();
                        variablelist.Add(v);
                        stackTem.Push(v);
                    }
                    for(int i=0;i< variablelist.Count;i++)
                    { 
                        if (strvariable.Contains(variablelist[i].variablename))
                        {
                            strvariable = strvariable.Replace(variable.variablename, variable.variablecurval);
                            break;
                        }
                    }
 
                    //恢复全局变量
                    for (int i = 0; i < variablelist.Count; i++)
                    {
                        Variable v = stackTem.Pop();
                        launchView.gloadVariable.Push(v);
                    }
 
                    Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
                    variable.variablecurval = Microsoft.JScript.Eval.JScriptEvaluate(strvariable, ve).ToString();
                }
 
                List<string> sortWellName = new List<string>();
                for (int j = 1; j <= labwares.number_column; j++)
                {
                    for (int i = 0; i < labwares.number_row; i++)
                    {
                        string rowName = ComUtility.GetRowChar(i);
 
                        string rowWellName = rowName + j;
                        sortWellName.Add(rowWellName);
                    }
                }
                wells = new string[1];
                wells[0] = sortWellName[Convert.ToInt32(variable.variablecurval) - 1];
            }
 
            // 判断方法中的板位和板子是否能对应上设置的台面
            Lattice lattice = new Lattice();
 
            string armId = Shared.DeviceArmList.FirstOrDefault(x => x.arm_type.Equals(1)).device_arm_id.ToString();
            string latticenum = methodSwitchLid.positionText.ToString();
            TabletopTemplate tabletopTemplate = TabletopTemplateDB.GetCurrentAppTabletopTemplateCollectionFromdb();  //增加台面模板判断
            if (tabletopTemplate == null)
            {
                lattice = LatticeDB.GetLatticeDataByIdFromdb(latticenum, Convert.ToInt32(armId), Shared.SoftwareInformation.software_device_number);
            }
            else
            {
                lattice = LatticeDB.GetLatticeDataByLatticeNumAndTempIdFromdb(latticenum, Convert.ToInt32(armId), Shared.SoftwareInformation.software_device_number, tabletopTemplate.tabletopid);
            }
            int xmlLatticeId = Convert.ToInt32(latticenum.Substring(1));
 
            var latticeXn = xmlEnv.SelectSingleNode("platform[lattice_id='" + xmlLatticeId.ToString() + "']");
            if (latticeXn != null)
            {
                labwares.labware_sname = latticeXn.SelectNodes("labware")[0].SelectSingleNode("labware_sname").InnerText;
            }
            else
            {
                if (strCurrentCulture.Equals("zh-CN"))
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.RunAspirateResource.strWithoutLattice.ToString());
                }
                else
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: the lattice of aspirate liquid is wrong! please check!");
                }
                result = false;
                return result;
            }
            //}
            #endregion
 
            #region 执行构建
            try
            {
 
                // 获取当前台面的夹爪坐标
                List<GripperCoordinate> gripperCoordinates = DataRWDAL.GripperCoordinateDB.GetAGripperCoordinateFromdb(Shared.SoftwareInformation.software_information_id, Convert.ToInt32(methodSwitchLid.armValue),lattice.lattice_num);
 
                //转化成板位
                Lattice slattice = new Lattice();
                slattice.lattice_X = gripperCoordinates[0].lattice_X;
                slattice.lattice_Y = gripperCoordinates[0].lattice_Y;
                slattice.lattice_Z = gripperCoordinates[0].lattice_Z;
                slattice.lattice_num = gripperCoordinates[0].lattice_num;
                slattice.lattice_id = "";
 
                // 获取板位孔的坐标数据
                List<TipsTable> dtWells = ControlCom.GenerateWellCoordinateForChemistry(labwares, slattice);
 
                //离心管耗材对象
                Labware centrifugalLabware = ControlCom.GetCentrifugalLabwer(labwares.piled_script);
 
                //根据循环处理孔位
                TipsTable tipsTable = null;
                tipsTable = dtWells.SingleOrDefault(t => t.lattice_num.Equals(lattice.lattice_num)
                                                                && t.labware_id.Equals(labwares.labware_id)
                                                                && t.wellname.Equals(wells[0]));
                tipsTable.axis_b_Z = tipsTable.axis_b_Z + ControlCom.CurrentLengthOfTip;//被减的枪头要加回来
 
                if (methodSwitchLid.armText == "夹爪臂")
                {
                    ScrewTubeCapMParam screwTubeCapMParam = new ScrewTubeCapMParam();
                    screwTubeCapMParam.tubeRackNo = Convert.ToInt32(lattice.lattice_num.Substring(1)); //板位号,数字部分
                    screwTubeCapMParam.tubeCol = Convert.ToInt32(wells[0].Substring(1));               //孔所在列号,数字部分
                    screwTubeCapMParam.tubeScrewPitch = (float)centrifugalLabware.well_helical_distance;//螺纹螺距
                    screwTubeCapMParam.tubeDiameter = (float)centrifugalLabware.well_mouth_out_radius*2;  //离心管主管外径
 
                    screwTubeCapMParam.tubeRow = 0;
 
                    screwTubeCapMParam.capDiameter = (float)centrifugalLabware.lid_out_radius*2;
                    screwTubeCapMParam.capExpandDistance = (float)centrifugalLabware.upgripper_spread;
                    screwTubeCapMParam.capPushDistance = (float)centrifugalLabware.upgripper_squeeze;
                    screwTubeCapMParam.capPushForce = (float)centrifugalLabware.upgripper_power;
                    screwTubeCapMParam.capScrewAngle =new float[] { (float)methodSwitchLid.numOfCircle * 360 };
                    screwTubeCapMParam.capScrewSpeed = (float)methodSwitchLid.switchSpeed;
                    screwTubeCapMParam.capScrewDistance =new float[] { (float)centrifugalLabware.well_helical_distance * (float)Math.Ceiling(methodSwitchLid.numOfCircle) };
                    screwTubeCapMParam.slotNo = 1;
                    screwTubeCapMParam.basezAxisVal = 0;
 
                    //下夹爪
                    screwTubeCapMParam.x2AxisVal = 0;
                    screwTubeCapMParam.y2AxisVal = 0;
                    screwTubeCapMParam.tubePushDistance = (float)centrifugalLabware.downgripper_squeeze;
                    screwTubeCapMParam.tubeExpandDistance =(float)centrifugalLabware.downgripper_spread;
                    screwTubeCapMParam.tubePushForce = (float)centrifugalLabware.downgripper_power;
 
                    //上夹爪
                    screwTubeCapMParam.xAxisVal = tipsTable.axis_b_X;
                    screwTubeCapMParam.yAxisVal = tipsTable.axis_b_Y;
 
                    //Labware centrifugalLabware = ControlCom.GetCentrifugalLabwer(labwares.piled_script);
                    screwTubeCapMParam.zAxisVal = tipsTable.axis_b_Z-((float)centrifugalLabware.labware_height+3f)+(float)centrifugalLabware.upgripper_zoffset;//孔口
 
                    
 
                    launchView.SetWaitOne();//暂停
                    ret = switchLidBll.ExecuteSwitchLid(screwTubeCapMParam, methodSwitchLid.switchState, isSimulator);
 
                    if (ret.Result != ResultType.Success)
                    {
                        if (strCurrentCulture.Equals("zh-CN"))
                        {
                            if (methodSwitchLid.switchState == 0)
                            {
                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidOpenFailed.ToString() + ret.AlarmInfo + " 孔 " + tipsTable.wellname + " 板位 " + slattice.lattice_num);
                                LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidOpenFailed.ToString() + ret.AlarmInfo + " 孔 " + tipsTable.wellname + " 板位 " + slattice.lattice_num);
                            }
                            else if (methodSwitchLid.switchState == 1)
                            {
                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidCloseFailed.ToString() + ret.AlarmInfo + " 孔 " + tipsTable.wellname + " 板位 " + slattice.lattice_num);
                                LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidCloseFailed.ToString() + ret.AlarmInfo + " 孔 " + tipsTable.wellname + " 板位 " + slattice.lattice_num);
                            }
                        }
                        else
                        {
                            if (methodSwitchLid.switchState == 0)
                            {
                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: switch to open lid was failed on " + tipsTable.wellname + " of " + slattice.lattice_num + " lattice! Error info:" + ret.AlarmInfo);
                                LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: switch to open lid was failed on " + tipsTable.wellname + " of " + slattice.lattice_num + " lattice! Error info:" + ret.AlarmInfo);
                            }
                            else if (methodSwitchLid.switchState == 1)
                            {
                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: switch to close lid was failed on " + tipsTable.wellname + " of " + slattice.lattice_num + " lattice! Error info:" + ret.AlarmInfo);
                                LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: switch to close lid was failed on " + tipsTable.wellname + " of " + slattice.lattice_num + " lattice! Error info:" + ret.AlarmInfo);
                            }
                        }
                        result = false;
                        OperateDialog plsConfirmOper = null;
                        if (!launchView.isRemotingOper)
                        {
                            Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                plsConfirmOper = new OperateDialog(strCurrentCulture.Equals("zh-CN") ? Properties.GripTransportResource.strPickFailWhatToDo : "The action of pick was fail! What do you want to do?");
                                plsConfirmOper.ShowDialog();
                            }));
                        }
                        else
                        {
                            launchView.OnError?.Invoke(launchView.remoteObjectCmd, "EC-1027", 5, Properties.GripTransportResource.strPickFailWhatToDo, 2);
                            plsConfirmOper = new OperateDialog(strCurrentCulture.Equals("zh-CN") ? Properties.GripTransportResource.strPickFailWhatToDo : "The action of pick was fail! What do you want to do?");
                            plsConfirmOper.ShowDialog();
                        }
 
                        if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Retry)           // 重试
                        {
                            return ExecuteSwitchLidReTry(lattice, wells, centrifugalLabware, methodSwitchLid, isSimulator, tipsTable);
                        }
                        else if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Cancel)     // 终止
                        {
                            if (launchView.isRemotingOper)
                            {
                                launchView.OnError?.Invoke(launchView.remoteObjectCmd, "EC-1045", 5, Properties.GripTransportResource.strPickWasStopped, 2);
                            }
                            result = false;
                            return result;
                        }
                        else if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Continue)   // 跳过
                        {
                            result = true;
                            return result;
                        }
                        return result;
                    }
                    else
                    {
                        if (methodSwitchLid.switchState == 0)
                        {
                            if (strCurrentCulture.Equals("zh-CN"))
                            {
                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidOpenSuccess.ToString() + " 孔 " + tipsTable.wellname + " 板位 " + slattice.lattice_num);
                                LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidOpenSuccess.ToString() + " 孔 " + tipsTable.wellname + " 板位 " + slattice.lattice_num);
                            }
                            else
                            {
                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress:switch to open lid was successful on " + tipsTable.wellname + " of " + slattice.lattice_num + " lattice!");
                                LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress:switch to open lid was successful on " + tipsTable.wellname + " of " + slattice.lattice_num + " lattice!");
                            }
                        }
                        else if (methodSwitchLid.switchState == 1)
                        {
                            if (strCurrentCulture.Equals("zh-CN"))
                            {
                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidCloseSuccess.ToString() + " 孔 " + tipsTable.wellname + " 板位 " + slattice.lattice_num);
                                LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidCloseSuccess.ToString() + " 孔 " + tipsTable.wellname + " 板位 " + slattice.lattice_num);
                            }
                            else
                            {
                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress:switch to closed lid was successful on " + tipsTable.wellname + " of " + slattice.lattice_num + " lattice!");
                                LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress:switch to closed lid was successful on " + tipsTable.wellname + " of " + slattice.lattice_num + " lattice!");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", 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 + ";");
                }
                result = false;
            }
 
            #endregion
 
            return result;
        }
        #endregion
 
        #region 开关盖重试函数
        public bool ExecuteSwitchLidReTry(Lattice lattice,string[] wells, Labware centrifugalLabware,MethodSwitchLid methodSwitchLid,bool isSimulator,TipsTable tipsTable)
        {
            bool result = true;
            ScrewTubeCapMParam screwTubeCapMParam = new ScrewTubeCapMParam();
            screwTubeCapMParam.tubeRackNo = Convert.ToInt32(lattice.lattice_num.Substring(1)); //板位号,数字部分
            screwTubeCapMParam.tubeCol = Convert.ToInt32(wells[0].Substring(1));               //孔所在列号,数字部分
            screwTubeCapMParam.tubeScrewPitch = (float)centrifugalLabware.well_helical_distance;//螺纹螺距
            screwTubeCapMParam.tubeDiameter = (float)centrifugalLabware.well_mouth_out_radius * 2;  //离心管主管外径
 
            screwTubeCapMParam.tubeRow = 0;
 
            screwTubeCapMParam.capDiameter = (float)centrifugalLabware.lid_out_radius * 2;
            screwTubeCapMParam.capExpandDistance = (float)centrifugalLabware.upgripper_spread;
            screwTubeCapMParam.capPushDistance = (float)centrifugalLabware.upgripper_squeeze;
            screwTubeCapMParam.capPushForce = (float)centrifugalLabware.upgripper_power;
            screwTubeCapMParam.capScrewAngle = new float[] { (float)methodSwitchLid.numOfCircle * 360 };
            screwTubeCapMParam.capScrewSpeed = (float)methodSwitchLid.switchSpeed;
            screwTubeCapMParam.capScrewDistance = new float[] { (float)centrifugalLabware.well_helical_distance * (float)Math.Ceiling(methodSwitchLid.numOfCircle) };
            screwTubeCapMParam.slotNo = 1;
            screwTubeCapMParam.basezAxisVal = 0;
 
            //下夹爪
            screwTubeCapMParam.x2AxisVal = 0;
            screwTubeCapMParam.y2AxisVal = 0;
            screwTubeCapMParam.tubePushDistance = (float)centrifugalLabware.downgripper_squeeze;
            screwTubeCapMParam.tubeExpandDistance = (float)centrifugalLabware.downgripper_spread;
            screwTubeCapMParam.tubePushForce = (float)centrifugalLabware.downgripper_power;
 
            //上夹爪
            screwTubeCapMParam.xAxisVal = tipsTable.axis_b_X;
            screwTubeCapMParam.yAxisVal = tipsTable.axis_b_Y;
 
            //Labware centrifugalLabware = ControlCom.GetCentrifugalLabwer(labwares.piled_script);
            screwTubeCapMParam.zAxisVal = tipsTable.axis_b_Z - ((float)centrifugalLabware.labware_height + 3f) + (float)centrifugalLabware.upgripper_zoffset;//孔口
 
 
 
            launchView.SetWaitOne();//暂停
            HxResult  ret = switchLidBll.ExecuteSwitchLid(screwTubeCapMParam, methodSwitchLid.switchState, isSimulator);
 
            if (ret.Result != ResultType.Success)
            {
                if (strCurrentCulture.Equals("zh-CN"))
                {
                    if (methodSwitchLid.switchState == 0)
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidOpenFailed.ToString() + ret.AlarmInfo + " 孔 " + tipsTable.wellname + " 板位 " + lattice.lattice_num);
                        LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidOpenFailed.ToString() + ret.AlarmInfo + " 孔 " + tipsTable.wellname + " 板位 " + lattice.lattice_num);
                    }
                    else if (methodSwitchLid.switchState == 1)
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidCloseFailed.ToString() + ret.AlarmInfo + " 孔 " + tipsTable.wellname + " 板位 " + lattice.lattice_num);
                        LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidCloseFailed.ToString() + ret.AlarmInfo + " 孔 " + tipsTable.wellname + " 板位 " + lattice.lattice_num);
                    }
                }
                else
                {
                    if (methodSwitchLid.switchState == 0)
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】progress: switch to open lid was failed on " + tipsTable.wellname + " of " + lattice.lattice_num + " lattice! Error info:" + ret.AlarmInfo);
                        LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】progress: switch to open lid was failed on " + tipsTable.wellname + " of " + lattice.lattice_num + " lattice! Error info:" + ret.AlarmInfo);
                    }
                    else if (methodSwitchLid.switchState == 1)
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】progress: switch to close lid was failed on " + tipsTable.wellname + " of " + lattice.lattice_num + " lattice! Error info:" + ret.AlarmInfo);
                        LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】progress: switch to close lid was failed on " + tipsTable.wellname + " of " + lattice.lattice_num + " lattice! Error info:" + ret.AlarmInfo);
                    }
                }
                result = false;
                OperateDialog plsConfirmOper = null;
                if (!launchView.isRemotingOper)
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        if (methodSwitchLid.switchState == 0)
                        {
                            plsConfirmOper = new OperateDialog(strCurrentCulture.Equals("zh-CN") ? Properties.SwitchLidResource.strSwitchOpenFailWhatToDo : "The action of switch open was fail! What do you want to do?");
                        }
                        else
                        {
                            plsConfirmOper = new OperateDialog(strCurrentCulture.Equals("zh-CN") ? Properties.SwitchLidResource.strSwitchCloseFailWhatToDo : "The action of switch close was fail! What do you want to do?");
                        }
                        plsConfirmOper.ShowDialog();
                    }));
                }
                else
                {
                    if (methodSwitchLid.switchState == 0)
                    {
                        launchView.OnError?.Invoke(launchView.remoteObjectCmd, "EC-1027", 5, Properties.SwitchLidResource.strSwitchOpenFailWhatToDo, 2);
                        plsConfirmOper = new OperateDialog(strCurrentCulture.Equals("zh-CN") ? Properties.SwitchLidResource.strSwitchOpenFailWhatToDo : "The action of switch open was fail! What do you want to do?");
                    }
                    else
                    {
                        launchView.OnError?.Invoke(launchView.remoteObjectCmd, "EC-1027", 5, Properties.SwitchLidResource.strSwitchCloseFailWhatToDo, 2);
                        plsConfirmOper = new OperateDialog(strCurrentCulture.Equals("zh-CN") ? Properties.SwitchLidResource.strSwitchCloseFailWhatToDo : "The action of switch close was fail! What do you want to do?");
                    }
                    plsConfirmOper.ShowDialog();
                }
 
                if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Retry)           // 重试
                {
                    return ExecuteSwitchLidReTry(lattice, wells, centrifugalLabware, methodSwitchLid, isSimulator, tipsTable);
                }
                else if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Cancel)     // 终止
                {
                    if (launchView.isRemotingOper)
                    {
                        launchView.OnError?.Invoke(launchView.remoteObjectCmd, "EC-1045", 5, Properties.SwitchLidResource.strSwitchWasStopped, 2);
                    }
                    result = false;
                    return result;
                }
                else if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Continue)   // 跳过
                {
                    result = true;
                    return result;
                }
                return result;
            }
            else
            {
                if (methodSwitchLid.switchState == 0)
                {
                    if (strCurrentCulture.Equals("zh-CN"))
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidOpenSuccess.ToString() + " 孔 " + tipsTable.wellname + " 板位 " + lattice.lattice_num);
                        LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidOpenSuccess.ToString() + " 孔 " + tipsTable.wellname + " 板位 " + lattice.lattice_num);
                    }
                    else
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】progress:switch to open lid was successful on " + tipsTable.wellname + " of " + lattice.lattice_num + " lattice!");
                        LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】progress:switch to open lid was successful on " + tipsTable.wellname + " of " + lattice.lattice_num + " lattice!");
                    }
                }
                else if (methodSwitchLid.switchState == 1)
                {
                    if (strCurrentCulture.Equals("zh-CN"))
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidCloseSuccess.ToString() + " 孔 " + tipsTable.wellname + " 板位 " + lattice.lattice_num);
                        LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.SwitchLidResource.strSwitchLidCloseSuccess.ToString() + " 孔 " + tipsTable.wellname + " 板位 " + lattice.lattice_num);
                    }
                    else
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】progress:switch to closed lid was successful on " + tipsTable.wellname + " of " + lattice.lattice_num + " lattice!");
                        LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodSwitchLid.name + "】progress:switch to closed lid was successful on " + tipsTable.wellname + " of " + lattice.lattice_num + " lattice!");
                    }
                }
            }
 
            return result;
        }
        #endregion
    }
}