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
///
/// 构造函数
///
public HoldingLabwareControl(string strCurrentCulture)
{
this.m_strCurrentCulture = strCurrentCulture;
}
#region 执行抓板保持开始
///
/// 执行抓板保持开始
///
///
///
///
///
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 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(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 执行抓板保持结束
///
/// 执行抓板保持结束
///
///
///
///
///
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 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(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
}
}