|
|
|
@ -21,22 +21,21 @@ namespace Aucma.Core.SheetMetal.Business;
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class SheetMetalPlanTaskHandle
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 刷新当前正在执行的计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
public delegate void RefreshCurrentPlanInfo(ExecutePlanInfo planInfo);
|
|
|
|
|
public event RefreshCurrentPlanInfo RefreshCurrentPlanInfoEvent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected readonly IExecutePlanInfoServices? _executePlanInfoServices;
|
|
|
|
|
protected readonly IRecordSidePanelComplateServices _sidePanelComplateServices;
|
|
|
|
|
protected readonly IRecordBackPanelComplateServices _backPanelComplateServices;
|
|
|
|
|
public HwPLc.PlcModel plc1 = null;
|
|
|
|
|
int completeAmount = 0;
|
|
|
|
|
string planCodeTask = string.Empty;
|
|
|
|
|
|
|
|
|
|
public SheetMetalPlanTaskHandle()
|
|
|
|
|
{
|
|
|
|
|
_executePlanInfoServices =
|
|
|
|
|
_executePlanInfoServices =
|
|
|
|
|
App.ServiceProvider.GetService<IExecutePlanInfoServices>();
|
|
|
|
|
_sidePanelComplateServices = App.ServiceProvider.GetService<IRecordSidePanelComplateServices>();
|
|
|
|
|
_backPanelComplateServices = App.ServiceProvider.GetService<IRecordBackPanelComplateServices>();
|
|
|
|
@ -50,18 +49,14 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
var obj_sidePanel = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("SidePanelPlc"));
|
|
|
|
|
var obj_backPanel = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("BackPanelPLC"));
|
|
|
|
|
var productLineCode = Appsettings.app("StationInfo", "StationCode");
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
var planInfos = _executePlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals(productLineCode) ).Result;
|
|
|
|
|
if (planInfos == null) return;
|
|
|
|
|
var planWait = planInfos.FirstOrDefault(d => d.ExecuteStatus == 2);
|
|
|
|
|
var planInfos = _executePlanInfoServices.Query(d => d.ProductLineCode.Equals("1001") && d.ExecuteStatus == 1);
|
|
|
|
|
|
|
|
|
|
if (planWait == null)
|
|
|
|
|
if (planInfos != null)
|
|
|
|
|
{
|
|
|
|
|
var planWaite1 = planInfos.Where(d => d.ExecuteStatus == 1);
|
|
|
|
|
if (planWaite1 == null) return;
|
|
|
|
|
if (planWaite1.Count() > 0)
|
|
|
|
|
if (planInfos.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
ExecutePlanInfo planInfo = planInfos.First();
|
|
|
|
|
if (planInfo.PlanType == 1) //联合下发
|
|
|
|
@ -90,43 +85,6 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
Console.WriteLine("未获取到需要下发的任务");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//获取上料数据,与计划书匹配任务结束
|
|
|
|
|
//再次判断当前完工数和计划数是否一样,一样结束任务
|
|
|
|
|
//List<RecordSidePanelComplate> sidePanelComplates2 = _sidePanelComplateServices.Query(x => x.ProductlineCode == "1001" && x.PlanCode == planWait.TaskCode);
|
|
|
|
|
|
|
|
|
|
if (planWait.PlanType == 2)
|
|
|
|
|
{
|
|
|
|
|
ReadDeviceComplate_SidePanel(obj_sidePanel);
|
|
|
|
|
|
|
|
|
|
#region 测试
|
|
|
|
|
//byte[] info = obj_sidePanel.plc.Read("D6030", 59);
|
|
|
|
|
|
|
|
|
|
//if (info == null)
|
|
|
|
|
//{
|
|
|
|
|
// Thread.Sleep(1000);
|
|
|
|
|
// continue;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
////计划编号
|
|
|
|
|
//string planCode = Encoding.ASCII.GetString(info.Skip(0).Take(20).ToArray());
|
|
|
|
|
|
|
|
|
|
////物料编号
|
|
|
|
|
//string materialCode = Encoding.ASCII.GetString(info.Skip(20).Take(20).ToArray());
|
|
|
|
|
////完成数量
|
|
|
|
|
//int complateAmount = short.Parse(bytesToHexStr(info.Skip(40).Take(1).ToArray(), 1), System.Globalization.NumberStyles.HexNumber);
|
|
|
|
|
|
|
|
|
|
//if (complateAmount == planWait.PlanAmount && "2023122900001" == planCode.Replace("\0", "").Trim())
|
|
|
|
|
//{
|
|
|
|
|
// //数据计划
|
|
|
|
|
// planWait.ExecuteStatus = 3;
|
|
|
|
|
// planWait.CompleteAmount = planWait.PlanAmount;
|
|
|
|
|
// _ = _executePlanInfoServices.UpdateAsync(planWait).Result;
|
|
|
|
|
//}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(3000);
|
|
|
|
|
}
|
|
|
|
@ -140,7 +98,6 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var productLineCode = Appsettings.app("StationInfo", "ProductLineCode");
|
|
|
|
|
lock (string.Empty)
|
|
|
|
|
{
|
|
|
|
|
bool isComplate = true;
|
|
|
|
@ -148,17 +105,17 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
//等待计划执行完成
|
|
|
|
|
List<RecordSidePanelComplate> sidePanelComplates = _sidePanelComplateServices.Query(x => x.ProductlineCode == productLineCode && x.PlanCode == planInfo.TaskCode);
|
|
|
|
|
List<RecordSidePanelComplate> sidePanelComplates = _sidePanelComplateServices.Query(x => x.ProductlineCode == "1001" && x.PlanCode == planInfo.TaskCode);
|
|
|
|
|
int sumSidePanelAmount = sidePanelComplates.Sum(x => x.OutPutAmount);
|
|
|
|
|
|
|
|
|
|
List<RecordBackPanelComplate> backPanelComplates = _backPanelComplateServices.Query(x => x.ProductlineCode == productLineCode && x.PlanCode == planInfo.TaskCode);
|
|
|
|
|
List<RecordBackPanelComplate> backPanelComplates = _backPanelComplateServices.Query(x => x.ProductlineCode == "1001" && x.PlanCode == planInfo.TaskCode);
|
|
|
|
|
int sumBackPanelAmount = backPanelComplates.Sum(x => x.OutPutAmount);
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"当前计划:{planInfo.TaskCode};计划产量:{planInfo.PlanAmount};围板完成:{sumSidePanelAmount};背板完成:{sumBackPanelAmount}");
|
|
|
|
|
|
|
|
|
|
int sumAmount = 0;
|
|
|
|
|
|
|
|
|
|
if(planInfo.PlanType == 1)
|
|
|
|
|
if (planInfo.PlanType == 1)
|
|
|
|
|
{
|
|
|
|
|
if (sumSidePanelAmount >= sumBackPanelAmount)
|
|
|
|
|
{
|
|
|
|
@ -168,7 +125,8 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
{
|
|
|
|
|
sumAmount = sumSidePanelAmount;
|
|
|
|
|
}
|
|
|
|
|
}else if(planInfo.PlanType == 2)
|
|
|
|
|
}
|
|
|
|
|
else if (planInfo.PlanType == 2)
|
|
|
|
|
{
|
|
|
|
|
sumAmount = sumSidePanelAmount;
|
|
|
|
|
}
|
|
|
|
@ -191,7 +149,8 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
|
|
|
|
|
} while (isComplate);
|
|
|
|
|
}
|
|
|
|
|
}catch(Exception ex)
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"计划任务信息更新异常:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
@ -203,7 +162,7 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
/// <param name="planInfo"></param>
|
|
|
|
|
/// <param name="obj_sidePanel"></param>
|
|
|
|
|
/// <param name="obj_backPanel"></param>
|
|
|
|
|
private void SendPlanTask(ExecutePlanInfo planInfo, PlcModel obj_sidePanel,PlcModel obj_backPanel)
|
|
|
|
|
private void SendPlanTask(ExecutePlanInfo planInfo, PlcModel obj_sidePanel, PlcModel obj_backPanel)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
@ -212,7 +171,7 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
if (obj_sidePanel != null)
|
|
|
|
|
{
|
|
|
|
|
//计划编号10个字:D6000-D6009、物料编号10个字:D6010-D6019、计划数量1个字:D6020、应答字1个字D6021
|
|
|
|
|
obj_sidePanel.plc.WriteString("D6030", planInfo.TaskCode.Substring(0, 16));
|
|
|
|
|
obj_sidePanel.plc.WriteString("D6030", planInfo.TaskCode);
|
|
|
|
|
string processNumber = GetProcessNumberBy(planInfo.MaterialCode);
|
|
|
|
|
obj_sidePanel.plc.WriteString("D6010", "BCD/310NF");
|
|
|
|
|
obj_sidePanel.plc.WriteInt32("D6020", planInfo.PlanAmount);
|
|
|
|
@ -342,7 +301,7 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"围板⽣产计划下发异常:{ex.Message}", "提示", MessageBoxButton.OK, MessageBoxImage.Error,
|
|
|
|
|
MessageBox.Show($"围板⽣产计划下发异常:{ex.Message}", "提示", MessageBoxButton.OK, MessageBoxImage.Error,
|
|
|
|
|
MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -354,6 +313,7 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
public void ReadDeviceComplate_SidePanel(PlcModel obj)
|
|
|
|
|
{
|
|
|
|
|
bool isFlag = true;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
@ -370,12 +330,10 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
|
|
|
|
|
//计划编号
|
|
|
|
|
string planCode = Encoding.ASCII.GetString(info.Skip(0).Take(20).ToArray());
|
|
|
|
|
|
|
|
|
|
//物料编号
|
|
|
|
|
string materialCode = Encoding.ASCII.GetString(info.Skip(20).Take(20).ToArray());
|
|
|
|
|
//完成数量
|
|
|
|
|
int complateAmount = short.Parse(bytesToHexStr(info.Skip(40).Take(1).ToArray(), 1), System.Globalization.NumberStyles.HexNumber);
|
|
|
|
|
|
|
|
|
|
//下线数量
|
|
|
|
|
int offLineAmount = short.Parse(bytesToHexStr(info.Skip(41).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
|
|
|
|
|
//设备状态
|
|
|
|
@ -385,7 +343,6 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"围板设备数据读取====>>>>当前计划:{planCode},物料编号:{materialCode},完成数量:{complateAmount},下线数量:{offLineAmount},设备状态:{deviceStatus},生产节拍:{productionBeat}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//添加完工记录
|
|
|
|
|
RecordSidePanelComplate sidePanelComplate = new RecordSidePanelComplate()
|
|
|
|
|
{
|
|
|
|
@ -439,16 +396,11 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
if (planInfo.PlanAmount - sumComplateAmount == 0)
|
|
|
|
|
{
|
|
|
|
|
isFlag = false;
|
|
|
|
|
|
|
|
|
|
//结束执行数据计划
|
|
|
|
|
planInfo.ExecuteStatus = 3;
|
|
|
|
|
planInfo.CompleteAmount = sumComplateAmount;
|
|
|
|
|
_ = _executePlanInfoServices.UpdateAsync(planInfo).Result;
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"围板计划执行完成,计划数量:{planInfo.PlanAmount};实际产量:{sumComplateAmount};差异值:{planInfo.PlanAmount - sumComplateAmount}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -465,6 +417,8 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下发背板生产计划
|
|
|
|
|
/// </summary>
|
|
|
|
@ -515,11 +469,11 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"背板⽣产计划下发异常:{ex.Message}", "提示", MessageBoxButton.OK, MessageBoxImage.Error,
|
|
|
|
|
MessageBox.Show($"背板⽣产计划下发异常:{ex.Message}", "提示", MessageBoxButton.OK, MessageBoxImage.Error,
|
|
|
|
|
MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取背板生产数据
|
|
|
|
|
/// </summary>
|
|
|
|
@ -531,7 +485,7 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
//计划编号:D6030-D6039,物料编号:D6040-D6049,计划完成数:D6050,计划下线数:D6051,设备状态:D6052-D6056,生产节拍:D6057-D6058
|
|
|
|
|
byte[] info = obj.plc.Read("D6030", 59);
|
|
|
|
|
|
|
|
|
@ -600,7 +554,7 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
List<ExecutePlanInfo> planInfos = _executePlanInfoServices.Query(x => x.TaskCode == planCode.Substring(0, 16) && x.ExecuteStatus == 2);
|
|
|
|
|
if (planInfos != null)
|
|
|
|
|
{
|
|
|
|
|
if(planInfos.Count > 0)
|
|
|
|
|
if (planInfos.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
ExecutePlanInfo planInfo = planInfos.First();
|
|
|
|
|
if (planInfo != null)
|
|
|
|
@ -620,15 +574,15 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
_backPanelComplateServices.InsertBackPanelCimplate(backPanelComplate);
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
} while (isFlag);
|
|
|
|
|
} while (isFlag);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"读取背板设备完成数据异常:{e.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通过物料编号获取工艺编号
|
|
|
|
@ -637,9 +591,9 @@ public class SheetMetalPlanTaskHandle
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private string GetProcessNumberBy(string materialCode)
|
|
|
|
|
{
|
|
|
|
|
return System.Guid.NewGuid().ToString("N").Substring(0,20);
|
|
|
|
|
return System.Guid.NewGuid().ToString("N").Substring(0, 20);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static string bytesToHexStr(byte[] bytes, int iLen)//e.g. { 0x01, 0x01} ---> " 01 01"
|
|
|
|
|
{
|
|
|
|
|
string returnStr = "";
|
|
|
|
|