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
using DataRWDAL;
using HxSocket;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using XCommon;
using XCommon.Log;
using XCore;
using XHandler.Controls.Run.Com;
using XHandler.View;
using XImagingXhandler.XDAL;
 
namespace XHandler.Controls
{
    public class HoldingLabwareControl
    {
        #region 变量
        private string m_strCurrentCulture = string.Empty;
        private static MethodHoldingLabware m_beginHoldingLabwareData = null;
 
        #region BLL
        private HoldingLabwareBll m_holdingLabwareBll = new HoldingLabwareBll();
        #endregion
 
        #region 转运参数
        private string m_strMethodName = string.Empty;
        #endregion
 
        public RunWnd LaunchView = null;
        public HxSocketClient SocketTcpListener = null;
        #endregion
 
        /// <summary>
        /// 构造函数
        /// </summary>
        public HoldingLabwareControl(string strCurrentCulture)
        {
            this.m_strCurrentCulture = strCurrentCulture;
        }
 
        #region 执行抓板保持开始
        /// <summary>
        /// 执行抓板保持开始
        /// </summary>
        /// <param name="xmlEnv"></param>
        /// <param name="methodNode"></param>
        /// <param name="isSimulator"></param>
        /// <returns></returns>
        public bool ExecuteBeginHolding(XmlNode xmlEnv, XmlNode methodNode, bool isSimulator)
        {
            bool result = true;
            string methodName = methodNode.SelectSingleNode("name").InnerText;
 
            if (LaunchView._cancelSource.IsCancellationRequested)
            {
                result = false;
                return result;
            }
 
            try
            {
                #region StartLog
                if (m_strCurrentCulture.Equals("zh-CN"))
                {
                    LaunchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strStart.ToString());
                }
                else
                {
                    LaunchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodName + "】start:");
                }
                #endregion
 
                #region 数据准备
                m_beginHoldingLabwareData = m_holdingLabwareBll.GenerateMethodBeginHoldingLabware(methodNode);
                #endregion
 
                // From点位耗材信息
                Labware labwareFrom = LabwareDB.GetLabware(m_beginHoldingLabwareData.gripPickLabwareValue);
                ObservableCollection<Labware> piledFromLabwares = piledFromLabwares = LabwareDB.GetPiledlabwareOfALabware(labwareFrom);   // 被叠放的盖子
 
                #region Del
                //// To点位耗材信息
                //Labware labwareTo = null;
                //// 放空板位:-1:空板位
                //if ("-1".Equals(holdingLabwareData.gripPlaceLabwareValue))
                //{
                //    labwareTo = labwareFrom;
 
                //    // 被抓的耗材位置是顶部,且有盖子:=> labwareTo = 盖子
                //    if (piledFromLabwares.Count() > 0 && holdingLabwareData.gripModelPosValue == 2)
                //    {
                //        labwareTo = LabwareDB.GetLabware(piledFromLabwares[0].labware_id);
                //    }
                //}
                //else
                //{
                //    labwareTo = LabwareDB.GetLabware(holdingLabwareData.gripPlaceLabwareValue);
                //}
                #endregion
 
                if (labwareFrom == null)
                {
                    return result;
                }
 
                // 抓板
                MethodGripTransport gripTransportData = ComUtility.MapperStruct<MethodGripTransport, MethodHoldingLabware>(m_beginHoldingLabwareData);
                LaunchView.startMethodGripTransport = gripTransportData;
                result = ControlCom.ExecuteGripTransportPick(xmlEnv, gripTransportData, labwareFrom, piledFromLabwares, methodName, LaunchView, isSimulator);
                if (m_strCurrentCulture.Equals("zh-CN"))
                {
                    LaunchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.MachineRunResource.strEnd.ToString());
                }
                else
                {
                    LaunchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】progress: complete;");
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
 
                if (m_strCurrentCulture.Equals("zh-CN"))
                {
                    LaunchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strError.ToString() + " 源 " + ex.Source + " 错误信息 " + ex.Message + ";");
                }
                else
                {
                    LaunchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】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;
        }
        #endregion
 
        #region 执行抓板保持结束
        /// <summary>
        /// 执行抓板保持结束
        /// </summary>
        /// <param name="xmlEnv"></param>
        /// <param name="methodNode"></param>
        /// <param name="isSimulator"></param>
        /// <returns></returns>
        public bool ExecuteEndHolding(XmlNode xmlEnv, XmlNode methodNode, bool isSimulator)
        {
            bool result = true;
            string methodName = methodNode.SelectSingleNode("name").InnerText;
 
            if (LaunchView._cancelSource.IsCancellationRequested)
            {
                result = false;
                return result;
            }
 
            try
            {
                #region StartLog
                if (m_strCurrentCulture.Equals("zh-CN"))
                {
                    LaunchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strStart.ToString());
                }
                else
                {
                    LaunchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodName + "】start:");
                }
                #endregion
 
                #region 数据准备
                MethodHoldingLabware endHoldingLabwareData = m_holdingLabwareBll.GenerateMethodEndHoldingLabware(methodNode);
                endHoldingLabwareData.gripModelPosValue = m_beginHoldingLabwareData.gripModelPosValue;
                #endregion
 
                // From点位耗材信息
                Labware labwareFrom = LabwareDB.GetLabware(m_beginHoldingLabwareData.gripPickLabwareValue);
                // To点位耗材信息
                Labware labwareTo = null;
                ObservableCollection<Labware> piledFromLabwares = piledFromLabwares = LabwareDB.GetPiledlabwareOfALabware(labwareFrom);   // 被叠放的盖子
 
                // 放空板位
                if ("-1".Equals(endHoldingLabwareData.gripPlaceLabwareValue))
                {
                    labwareTo = labwareFrom;
 
                    // 被抓的耗材位置是顶部,且有盖子:=> labwareTo = 盖子
                    if (piledFromLabwares.Count() > 0 && m_beginHoldingLabwareData.gripModelPosValue == 2)
                    {
                        labwareTo = LabwareDB.GetLabware(piledFromLabwares[0].labware_id);
                    }
                }
                else
                {
                    labwareTo = LabwareDB.GetLabware(endHoldingLabwareData.gripPlaceLabwareValue);
                }
 
                if (labwareTo == null)
                {
                    return result;
                }
 
                
                // 放板
                MethodGripTransport gripTransportData = ComUtility.MapperStruct<MethodGripTransport, MethodHoldingLabware>(endHoldingLabwareData);
 
                if (LaunchView.startMethodGripTransport != null)
                {
                    #region 来源点位
                    gripTransportData.srcPositionText = LaunchView.startMethodGripTransport.srcPositionText;
                    gripTransportData.srcPositionValue = LaunchView.startMethodGripTransport.srcPositionValue;
                    gripTransportData.srcPositionType = LaunchView.startMethodGripTransport.srcPositionType;
                    #endregion
 
                    #region 抓板方向
                    gripTransportData.gripModelText = LaunchView.startMethodGripTransport.gripModelText;
                    gripTransportData.gripModelValue = LaunchView.startMethodGripTransport.gripModelValue;
                    #endregion
 
                    #region 抓取耗材
                    gripTransportData.gripPickLabwareText = LaunchView.startMethodGripTransport.gripPickLabwareText;
                    gripTransportData.gripPickLabwareValue = LaunchView.startMethodGripTransport.gripPickLabwareValue;
                    #endregion
 
                    #region 抓板位置
                    gripTransportData.gripModelPosText = LaunchView.startMethodGripTransport.gripModelPosText;
                    gripTransportData.gripModelPosValue = LaunchView.startMethodGripTransport.gripModelPosValue;
                    #endregion
 
                    gripTransportData.transportMode = LaunchView.startMethodGripTransport.transportMode;
                    gripTransportData.transportCount = LaunchView.startMethodGripTransport.transportCount;
 
                    LaunchView.GenerateAnimation(xmlEnv, gripTransportData);
                }
                result = ControlCom.ExecuteGripTransportPlace(xmlEnv, gripTransportData, labwareFrom, labwareTo, piledFromLabwares, methodName, LaunchView, isSimulator);
                if (m_strCurrentCulture.Equals("zh-CN"))
                {
                    LaunchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.MachineRunResource.strEnd.ToString());
                }
                else
                {
                    LaunchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】progress: complete;");
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
 
                if (m_strCurrentCulture.Equals("zh-CN"))
                {
                    LaunchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strError.ToString() + " 源 " + ex.Source + " 错误信息 " + ex.Message + ";");
                }
                else
                {
                    LaunchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】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;
        }
        #endregion
    }
}