liulb@mesnac.com 1 year ago
parent f49f181ecb
commit 8e957ff1c6

@ -16,8 +16,9 @@ namespace Admin.Core.Model
/// <summary>
/// 主键标识
///</summary>
[SugarColumn(ColumnName = "OBJ_ID", IsPrimaryKey = true, OracleSequenceName = "SEQ_RECORD_SIDEPANEL_COMPLATE")]
public decimal ObjId { get; set; }
//[SugarColumn(ColumnName = "OBJ_ID", IsPrimaryKey = true, OracleSequenceName = "SEQ_RECORD_SIDEPANEL_COMPLATE")]
[SugarColumn(ColumnName = "OBJ_ID", IsPrimaryKey = true, IsIdentity = true)]
public int ObjId { get; set; }
/// <summary>
/// 计划编号
///</summary>
@ -52,10 +53,10 @@ namespace Admin.Core.Model
public int OutPutAmount { get; set; }
[SugarColumn(ColumnName = "DEVICE_STATUS")]
public decimal? DeviceStatus { get; set; }
public string DeviceStatus { get; set; }
[SugarColumn(ColumnName = "PRODUCTION_BEAT")]
public decimal? ProductionBeat { get; set; }
public string ProductionBeat { get; set; }
/// <summary>
/// 记录时间
@ -66,6 +67,6 @@ namespace Admin.Core.Model
/// 是否标识
///</summary>
[SugarColumn(ColumnName = "IS_FLAG")]
public decimal? IsFlag { get; set; }
public string IsFlag { get; set; }
}
}

@ -37,7 +37,7 @@ namespace Aucma.Core.OldBoxFoam.Business
{
try
{
await ExecTaskMethod();
//await ExecTaskMethod();
return;
}
catch (Exception ex)

@ -67,7 +67,7 @@ namespace Aucma.Core.OldBoxFoam
//services.AddJobSetup();
//PLC
services.AddPlcSetup();
// services.AddAucmaTaskSetup();
services.AddAucmaTaskSetup();
//支持编码大全 例如:支持 System.Text.Encoding.GetEncoding("GB2312") System.Text.Encoding.GetEncoding("GB18030")
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
@ -89,7 +89,7 @@ namespace Aucma.Core.OldBoxFoam
/// <param name="app"></param>
/// <param name="env"></param>
public void Configure(IApplicationBuilder app,
IRunPlcService runPlcService)
IRunPlcService runPlcService, IAucamTaskService aucamTaskService)
{
// 使用静态文件
app.UseStaticFiles();
@ -98,7 +98,7 @@ namespace Aucma.Core.OldBoxFoam
// 开启QuartzNetJob调度服务
// app.UseQuartzJobMildd(tasksQzService, schedulerCenter);
//app.AucmaTaskMildds(aucamTaskService);
app.AucmaTaskMildds(aucamTaskService);
//PLC
app.UsePlcMildd(runPlcService);
}

@ -53,10 +53,10 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
_boxFoamDataRecordServices = App.ServiceProvider.GetService<IBoxFoamDataRecordServices>();
//AucamTaskService.RefreshOldBoxFoamDataDelegateEvent += OldBoxFoamOnLoad3;
timer2.Elapsed += new System.Timers.ElapsedEventHandler(RealTimeFoamingTask); //到达时间的时候执行事件;
timer2.AutoReset = true;//设置是执行一次false还是一直执行(true)
timer2.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它
timer2.Start();//timer.Start()的内部原理还是设置timer.Enabled = true;
//timer2.Elapsed += new System.Timers.ElapsedEventHandler(RealTimeFoamingTask); //到达时间的时候执行事件;
//timer2.AutoReset = true;//设置是执行一次false还是一直执行(true)
//timer2.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它
//timer2.Start();//timer.Start()的内部原理还是设置timer.Enabled = true;
}

@ -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 = "";

@ -3,6 +3,7 @@ using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.Model_New;
using Aucma.Core.HwPLc;
using Aucma.Core.Tasks.Business;
using log4net;
using System.Timers;
@ -22,7 +23,7 @@ namespace Aucma.Core.Tasks
{
}
System.Timers.Timer timer1 = new System.Timers.Timer(1000);
System.Timers.Timer timer1 = new System.Timers.Timer(5000);
bool qFlay=true;//完成
@ -47,8 +48,7 @@ namespace Aucma.Core.Tasks
qFlay = false;
try
{
var plc1 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1"));
Collection.startCollect();
}
catch (Exception)
{

@ -17,12 +17,12 @@ namespace Aucma.Core.Tasks.Business
{
public class Collection
{
public HwPLc.PlcModel plc1 = null;
public HwPLc.PlcModel plc2 = null;
public HwPLc.PlcModel plc3 = null;
public HwPLc.PlcModel plc4 = null;
public List<FixtureStatus> listFixtureStatus = new List<FixtureStatus>();
public List<SpaceDetailModel> spaceDetailModel = new List<SpaceDetailModel>();
public static HwPLc.PlcModel plc1 = null;
public static HwPLc.PlcModel plc2 = null;
public static HwPLc.PlcModel plc3 = null;
public static HwPLc.PlcModel plc4 = null;
public static List<FixtureStatus> listFixtureStatus = new List<FixtureStatus>();
public static List<SpaceDetailModel> spaceDetailModel = new List<SpaceDetailModel>();
public static List<int> BoxTypeList = new List<int>();
public static List<int> HolderStatusList = new List<int>();
@ -34,11 +34,11 @@ namespace Aucma.Core.Tasks.Business
public Collection() {
}
public async void startCollect()
public static void startCollect()
{
try
{
await ExecTaskMethod();
ExecTaskMethod();
return;
}
catch (Exception ex)
@ -47,10 +47,8 @@ namespace Aucma.Core.Tasks.Business
}
}
private Task ExecTaskMethod()
private static void ExecTaskMethod()
{
Task.Run(() =>
{
while (true)
{
Thread.Sleep(3000);
@ -75,7 +73,6 @@ namespace Aucma.Core.Tasks.Business
ReadHolderStatus(plc1, HolderStatusList);
ReadHolderStatus(plc2, HolderStatusList);
ReadHolderStatus(plc3, HolderStatusList);
ReadHolderStatus(plc4, HolderStatusList);
ReadHolderOutPut(plc1, HolderOutPutList);
ReadHolderOutPut(plc2, HolderOutPutList);
@ -143,9 +140,7 @@ namespace Aucma.Core.Tasks.Business
spaceDetailModel.Add(model);
}
}
});
return Task.CompletedTask;
}
/// <summary>

Loading…
Cancel
Save