liuwf 1 year ago
commit 2ae9d88953

@ -2496,6 +2496,56 @@
是否标识
</summary>
</member>
<member name="T:Admin.Core.Model.RecordSidePanelComplate">
<summary>
完成记录
</summary>
</member>
<member name="P:Admin.Core.Model.RecordSidePanelComplate.ObjId">
<summary>
主键标识
</summary>
</member>
<member name="P:Admin.Core.Model.RecordSidePanelComplate.PlanCode">
<summary>
计划编号
</summary>
</member>
<member name="P:Admin.Core.Model.RecordSidePanelComplate.MaterialCode">
<summary>
物料编号
</summary>
</member>
<member name="P:Admin.Core.Model.RecordSidePanelComplate.ProductlineCode">
<summary>
计划工位
</summary>
</member>
<member name="P:Admin.Core.Model.RecordSidePanelComplate.CompleteAmount">
<summary>
完成数量
</summary>
</member>
<member name="P:Admin.Core.Model.RecordSidePanelComplate.OffLineAmount">
<summary>
下线数量
</summary>
</member>
<member name="P:Admin.Core.Model.RecordSidePanelComplate.OutPutAmount">
<summary>
实际产量
</summary>
</member>
<member name="P:Admin.Core.Model.RecordSidePanelComplate.RecordTime">
<summary>
记录时间
</summary>
</member>
<member name="P:Admin.Core.Model.RecordSidePanelComplate.IsFlag">
<summary>
是否标识
</summary>
</member>
<member name="T:Admin.Core.Model.SMProductionCompletionRecord">
<summary>
钣金每日生产记录表

@ -0,0 +1,14 @@
using Admin.Core.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Admin.Core.IService
{
public interface IRecordSidePanelComplateServices : IBaseServices<RecordSidePanelComplate>
{
Task<bool> InsertSidePanelCimplate(RecordSidePanelComplate sidePanelComplate);
}
}

@ -0,0 +1,71 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Admin.Core.Model
{
/// <summary>
/// 完成记录
///</summary>
[SugarTable("RECORD_SIDEPANEL_COMPLATE", "AUCMA_SCADA")]
public class RecordSidePanelComplate
{
/// <summary>
/// 主键标识
///</summary>
[SugarColumn(ColumnName = "OBJ_ID", IsPrimaryKey = true, OracleSequenceName = "SEQ_RECORD_SIDEPANEL_COMPLATE")]
public decimal ObjId { get; set; }
/// <summary>
/// 计划编号
///</summary>
[SugarColumn(ColumnName = "PLAN_CODE")]
public string PlanCode { get; set; }
/// <summary>
/// 物料编号
///</summary>
[SugarColumn(ColumnName = "MATERIAL_CODE")]
public string MaterialCode { get; set; }
/// <summary>
/// 计划工位
///</summary>
[SugarColumn(ColumnName = "PRODUCTLINE_CODE")]
public string ProductlineCode { get; set; }
/// <summary>
/// 完成数量
///</summary>
[SugarColumn(ColumnName = "COMPLETE_AMOUNT")]
public int CompleteAmount { get; set; }
/// <summary>
/// 下线数量
/// </summary>
[SugarColumn(ColumnName = "OFFLINE_AMOUNT")]
public int OffLineAmount { get; set; }
/// <summary>
/// 实际产量
/// </summary>
[SugarColumn(ColumnName = "OUTPUT_AMOUNT")]
public int OutPutAmount { get; set; }
[SugarColumn(ColumnName = "DEVICE_STATUS")]
public decimal? DeviceStatus { get; set; }
[SugarColumn(ColumnName = "PRODUCTION_BEAT")]
public decimal? ProductionBeat { get; set; }
/// <summary>
/// 记录时间
///</summary>
[SugarColumn(ColumnName = "RECORD_TIME")]
public DateTime? RecordTime { get; set; }
/// <summary>
/// 是否标识
///</summary>
[SugarColumn(ColumnName = "IS_FLAG")]
public decimal? IsFlag { get; set; }
}
}

@ -0,0 +1,41 @@
using Admin.Core.IRepository;
using Admin.Core.IService;
using Admin.Core.Model;
using log4net;
using System;
using System.Threading.Tasks;
namespace Admin.Core.Service
{
/// <summary>
/// RecordProductFinishServices
/// </summary>
public class RecordSidePanelComplateServices : BaseServices<RecordSidePanelComplate>, IRecordSidePanelComplateServices
{
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(RecordOutStoreServices));
private readonly IBaseRepository<RecordSidePanelComplate> _dal;
public RecordSidePanelComplateServices(IBaseRepository<RecordSidePanelComplate> dal)
{
this._dal = dal;
base.BaseDal = dal;
}
public async Task<bool> InsertSidePanelCimplate(RecordSidePanelComplate sidePanelComplate)
{
bool result = false;
try
{
int r =await _dal.AddAsync(sidePanelComplate);
if (r > 0) result=true;
}
catch (Exception ex)
{
logHelper.Error("完成记录添加异常", ex);
}
return result;
}
}
}

@ -76,7 +76,7 @@ namespace Aucma.Core.HwPLc
/// <returns></returns>
public bool Connect(string iP, int port)
{
melsecMcNet.IpAddress = iP;//正式环境开启
//melsecMcNet.IpAddress = iP;//正式环境开启
melsecMcNet.Port = port;
// 如果网络不太理想,配置了两个端口,一个有问题,立即切换另一个的话,可以配置如下的代码

@ -21,12 +21,12 @@ namespace Aucma.Core.OldBoxFoam.Business
public List<FixtureStatus> listFixtureStatus = new List<FixtureStatus>();
public List<SpaceDetailModel> spaceDetailModel = new List<SpaceDetailModel>();
public List<int> BoxTypeList = new List<int>();
public List<int> HolderStatusList = new List<int>();
public List<int> HolderOutPutList = new List<int>();
public List<int> SolidifyTimeList = new List<int>();
public List<string> StoreTypeList = new List<string>();
public List<string> StoreAmountList = new List<string>();
public static List<int> BoxTypeList = new List<int>();
public static List<int> HolderStatusList = new List<int>();
public static List<int> HolderOutPutList = new List<int>();
public static List<int> SolidifyTimeList = new List<int>();
public static List<string> StoreTypeList = new List<string>();
public static List<string> StoreAmountList = new List<string>();
public Collection() {
@ -133,9 +133,18 @@ namespace Aucma.Core.OldBoxFoam.Business
/// <summary>
/// 读取夹具箱型
/// </summary>
static void ReadBoxType(HwPLc.PlcModel obj, List<int> BoxTypeList)
static void ReadBoxType(HwPLc.PlcModel obj, List<int> HolderStatusList)
{
if (obj == null) return;
if (obj == null)
{
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
return;
}
if (obj.plc.IsConnected)
{
@ -156,6 +165,15 @@ namespace Aucma.Core.OldBoxFoam.Business
BoxTypeList.Add(temp6);
Console.WriteLine($"读取夹具箱型,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
}
else
{
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
}
}
/// <summary>
@ -163,7 +181,16 @@ namespace Aucma.Core.OldBoxFoam.Business
/// </summary>
static void ReadHolderStatus(PlcModel obj1, List<int> HolderStatusList)
{
if (obj1 == null) return;
if (obj1 == null)
{
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
return;
}
byte[] result = obj1.plc.Read("YF0", 1);
if (result == null) return;
//输出二进制字符串,1#-3#手动、自动数据
@ -271,9 +298,27 @@ namespace Aucma.Core.OldBoxFoam.Business
/// </summary>
static void ReadHolderOutPut(PlcModel obj,List<int> HolderOutPutList)
{
if (obj == null) return;
if (obj == null)
{
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
return;
}
byte[] result = obj.plc.Read("D182", 24);
if (result == null) return;
if (result == null)
{
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
return;
}
byte[] info = result;
int temp1 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(0).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber);
int temp2 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(2).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber);
@ -296,9 +341,27 @@ namespace Aucma.Core.OldBoxFoam.Business
/// </summary>
static void ReadSolidifyTime(PlcModel obj,List<int> SolidifyTimeList)
{
if (obj == null) return;
if (obj == null)
{
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
return;
}
byte[] result = obj.plc.Read("D910", 24);
if (result == null) return;
if (result == null)
{
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
return;
}
byte[] info = result;
int temp1 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(0).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber);
int temp2 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(2).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber);
@ -320,10 +383,28 @@ namespace Aucma.Core.OldBoxFoam.Business
/// </summary>
static void ReadStoreType(PlcModel obj, List<string> storeType)
{
if (obj == null) return;
if (obj == null)
{
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
return;
}
//夹具箱型
byte[] result = obj.plc.Read("D2010", 40);
if (result == null) return;
if (result == null)
{
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
return;
}
byte[] info = result;
int temp1 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(0).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber);
int temp2 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(20).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber);
@ -341,9 +422,27 @@ namespace Aucma.Core.OldBoxFoam.Business
/// </summary>
static void ReadStoreAmount(PlcModel obj, List<string> storeAmount)
{
if (obj == null) return;
if (obj == null)
{
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
return;
}
byte[] result = obj.plc.Read("L101", 1);
if (result == null) return;
if (result == null)
{
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
BoxTypeList.Add(0);
return;
}
string str1 = ByteArrayToBinary(array(result)).Substring(0, 3);
int item1 = Regex.Matches(str1, "1").Count;

@ -231,10 +231,25 @@
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ObjId}" Header="货道号" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding Local}" Header="位置" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding Boxtype}" Header="货道类型" Width="3*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding Storeamount}" Header="库存数量" Width="3*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding Status}" Header="库存状态" Width="3*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding MaterialCode}" Header="物料编号" Width="3*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTemplateColumn Width="*" Header="状态">
<DataGridTemplateColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<DataTrigger Binding="{Binding Status}" Value="1">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
<DataTrigger Binding="{Binding Status}" Value="0">
<Setter Property="Background" Value="LawnGreen"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTemplateColumn.CellStyle>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Boxtype}" Header="货道类型" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding Storeamount}" Header="库存数量" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<!--<DataGridTextColumn Binding="{Binding Status}" Header="库存状态" Width="3*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>-->
<DataGridTextColumn Binding="{Binding MaterialCode}" Header="物料编号" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding MaterialName}" Header="物料名称" Width="3*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<!--<DataGridTextColumn Binding="{Binding QualityResult}" Header="模具数量" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>-->
</DataGrid.Columns>

@ -11,8 +11,8 @@ namespace Aucma.Core.RunPlc
/// </summary>
public class RunPlcService : IRunPlcService
{
System.Timers.Timer timer = new System.Timers.Timer(5000);//创建定时器设置间隔时间为1000毫秒
System.Timers.Timer timer = new System.Timers.Timer(3000);//创建定时器设置间隔时间为1000毫秒
System.Timers.Timer timer1 = new System.Timers.Timer(3000);
#region 构造函数
public RunPlcService()
{
@ -29,10 +29,10 @@ namespace Aucma.Core.RunPlc
timer.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它
timer.Start();//timer.Start()的内部原理还是设置timer.Enabled = true;
timer.Elapsed += new System.Timers.ElapsedEventHandler(ExecSiemensHeartTask);
timer.AutoReset = true;//设置是执行一次false还是一直执行(true)
timer.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它
timer.Start();//timer.Start()的内部原理还是设置timer.Enabled = true;
timer1.Elapsed += new System.Timers.ElapsedEventHandler(ExecSiemensHeartTask);
timer1.AutoReset = true;//设置是执行一次false还是一直执行(true)
timer1.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它
timer1.Start();//timer.Start()的内部原理还是设置timer.Enabled = true;
return Task.CompletedTask;
}
@ -87,7 +87,7 @@ namespace Aucma.Core.RunPlc
{
var item = PlcHelper.melsecList.Where(c => c.Id == i).FirstOrDefault();
if (item == null) continue;
if (await item.plc.Read("M100"))
if (item.plc.Read("M100").Result)
{
item.IsConnect = true;
item.plc.IsConnected = true;

@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Documents;
using Admin.Core.Common;
using Admin.Core.IService;
using Admin.Core.Model;
@ -25,127 +27,263 @@ public class SheetMetalPlanTaskHandle
public event RefreshCurrentPlanInfo RefreshCurrentPlanInfoEvent;
protected readonly IExecutePlanInfoServices? _executePlanInfoServices;
protected readonly IRecordSidePanelComplateServices _sidePanelComplateServices;
public HwPLc.PlcModel plc1 = null;
public SheetMetalPlanTaskHandle()
{
_executePlanInfoServices =
App.ServiceProvider.GetService<IExecutePlanInfoServices>();
_sidePanelComplateServices = App.ServiceProvider.GetService<IRecordSidePanelComplateServices>();
}
/// <summary>
/// 箱壳计划任务下发⾄设备PLC
/// 下发围板生产计划
/// </summary>
/// <returns></returns>
public void SendPlanTaskToDevice()
/// <param name="planInfo"></param>
/// <param name="obj"></param>
public void SendPlanTask_WB(ExecutePlanInfo planInfo, PlcModel obj)
{
Thread.Sleep(5000);
try
{
lock (string.Empty)
{
string stationCode = Appsettings.app("StoreInfo", "StationCode");
//获取待执⾏的计划,根据计划序号进⾏排序依次下发
var list = _executePlanInfoServices.Query(d =>
d.ProductLineCode.Equals(stationCode) && d.ExecuteStatus == 1);
if (list != null)
if (obj != null)
{
//计划编号10个字D6000-D6009、物料编号10个字D6010-D6019、计划数量1个字D6020、应答字1个字D6021
obj.plc.WriteString("D6000", planInfo.TaskCode);
string processNumber = GetProcessNumberBy(planInfo.MaterialCode);
obj.plc.WriteString("D6010", "BCD/310NF");
obj.plc.WriteInt32("D6020", planInfo.PlanAmount);
obj.plc.WriteInt32("D6021", 1);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>等待围板设备应答。。。。。。");
//下发完成后读取PLC应答应答后复位应答信号
if (list.Count > 0)
#region PLC反馈信号逻辑处理
//循环读取PLC应答信号PLC应答后复位应答信号、更新计划状态为执行中
bool isFlag = true;
do
{
ExecutePlanInfo task = list.OrderBy(x => x.ExecuteOrder).First();
var obj = PlcHelper.melsecList.FirstOrDefault(d =>
d.EquipName.Equals("OldTypePlc1"));
if (obj != null)
if (obj.plc.ReadInt32("D6021") == 2)
{
//计划编号10个字D6000-D6009、物料编号10个字D6010-D6019、计划数量1个字D6020、应答字1个字D6021
obj.plc.WriteString("D6000", task.TaskCode);
string processNumber = GetProcessNumberBy(task.MaterialCode);
obj.plc.WriteString("D6010", "BCD/310NF");
obj.plc.WriteInt32("D6020", task.PlanAmount);
obj.plc.WriteInt32("D6021", 1);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>等待设备应答。。。。。。");
//下发完成后读取PLC应答应答后复位应答信号
ReadPlcFeedBack(obj);
//更新计划状态为2执行中
task.ExecuteStatus = 2;
_executePlanInfoServices.UpdateExecutePlanInfo(task);
RefreshCurrentPlanInfoEvent?.Invoke(task);
//读取设备进度,完成后再次下发新任务
ReadDeviceComplate(obj);
obj.plc.WriteInt32("D6021", 0);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>收到围板设备应答信号,复位应答地址");
isFlag = false;
}
}
else
{
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>未获取到需要下发的生产计划!");
}
Thread.Sleep(2000);
} while (isFlag);
//更新计划状态为2执行中
planInfo.ExecuteStatus = 2;
//SheetMetalPlanTaskHandle handle = new SheetMetalPlanTaskHandle();
//plc1 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1"));
//handle.SendPlanTask_WB(list, plc1);
_executePlanInfoServices.UpdateExecutePlanInfo(planInfo);
RefreshCurrentPlanInfoEvent?.Invoke(planInfo);
#endregion
//读取设备进度,完成后再次下发新任务
ReadDeviceComplate_WB(obj);
}
}
}
catch (Exception ex)
{
MessageBox.Show($"箱壳⽣产计划下发异常:{ex.Message}", "提示", MessageBoxButton.OK, MessageBoxImage.Error,
MessageBox.Show($"围板⽣产计划下发异常:{ex.Message}", "提示", MessageBoxButton.OK, MessageBoxImage.Error,
MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
}
}
/// <summary>
/// 读取PLC应答反馈PLC反馈后复位应答地址
/// 读取围板生产数据
/// </summary>
private void ReadPlcFeedBack(PlcModel obj)
/// <param name="obj"></param>
public void ReadDeviceComplate_WB(PlcModel obj)
{
bool isFlag = true;
if (obj != null)
try
{
do
{
//D6030
//计划编号D6030-D6039物料编号D6040-D6049计划完成数D6050计划下线数D6051设备状态D6052-D6056,生产节拍D6057-D6058
byte[] info = obj.plc.Read("D6030", 59);
//计划编号
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);
//设备状态
int deviceStatus = short.Parse(bytesToHexStr(info.Skip(43).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
//生产节拍
int productionBeat = short.Parse(bytesToHexStr(info.Skip(51).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
Console.WriteLine($"设备数据读取====>>>>当前计划:{planCode},物料编号:{materialCode},完成数量:{complateAmount},下线数量:{offLineAmount},设备状态:{deviceStatus},生产节拍:{productionBeat}");
//添加完工记录
RecordSidePanelComplate sidePanelComplate = new RecordSidePanelComplate()
{
ProductlineCode = "1001",
PlanCode = planCode,
MaterialCode = materialCode,
CompleteAmount = complateAmount,
OffLineAmount = offLineAmount,
DeviceStatus = deviceStatus,
ProductionBeat = productionBeat,
RecordTime = DateTime.Now
};
if (obj.plc.ReadInt32("D6021") == 1)
//先查询该计划编号下的前一条完工记录如果不存在本条记录产量为0
List<RecordSidePanelComplate> sidePanelComplates = _sidePanelComplateServices.Query(x => x.ProductlineCode == "1001" && x.PlanCode == planCode);
int lastComplateAmount = 0; //前一条完成记录的计划完成数量
int sumComplateAmount = 0; //当前计划总产量
if (sidePanelComplates != null)
{
obj.plc.WriteInt32("D6021", 0);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>收到设备应答信号,复位应答地址");
isFlag = false;
if (sidePanelComplates.Count > 0)
{
sidePanelComplates = sidePanelComplates.OrderByDescending(x => x.RecordTime).ToList();
lastComplateAmount = sidePanelComplates.First().CompleteAmount;
sidePanelComplate.OutPutAmount = complateAmount - lastComplateAmount;
sumComplateAmount = sidePanelComplates.Sum(x => x.OutPutAmount) + sidePanelComplate.OutPutAmount;
if (sidePanelComplate.OutPutAmount == 0)
{
Thread.Sleep(5000);
continue;
}
else
{
if (sumComplateAmount > 0)
{
ExecutePlanInfo planInfo = _executePlanInfoServices.Query(x => x.TaskCode.Equals(planCode.Substring(0, 13)) && x.ExecuteStatus == 2).FirstOrDefault();
if (planInfo != null)
{
if (sumComplateAmount > planInfo.CompleteAmount)
{
if (planInfo.PlanAmount - sumComplateAmount == 0)
{
Console.WriteLine($"计划:{planCode},执行完成!!!");
planInfo.CompleteAmount = sumComplateAmount;
planInfo.ExecuteStatus = 3;
_executePlanInfoServices.UpdateExecutePlanInfo(planInfo);
isFlag = false;
}
else
{
Console.WriteLine(
$"设备当前计划:{planCode},计划数量:{planInfo.PlanAmount},实际完成:{sumComplateAmount},差异:{planInfo.PlanAmount - sumComplateAmount}");
planInfo.CompleteAmount = sumComplateAmount;
_executePlanInfoServices.UpdateExecutePlanInfo(planInfo);
}
RefreshCurrentPlanInfoEvent?.Invoke(planInfo);
}
}
}
}
}
}
Thread.Sleep(2000);
_sidePanelComplateServices.InsertSidePanelCimplate(sidePanelComplate);
Thread.Sleep(5000);
} while (isFlag);
}
catch (Exception e)
{
Console.WriteLine($"读取设备完成数据异常:{e.Message}");
}
}
/// <summary>
/// 读取设备完成数据
/// 下发背板生产计划
/// </summary>
/// <param name="planInfo"></param>
/// <param name="obj"></param>
public void ReadDeviceComplate(PlcModel obj)
public void SendPlanTaskTo_BB(ExecutePlanInfo planInfo, PlcModel obj)
{
bool isFlag = true;
Thread.Sleep(5000);
try
{
if (obj != null)
lock (string.Empty)
{
do
if (obj != null)
{
//计划编号D6030-D6039物料编号D6040-D6049计划完成数D6050计划下线数D6051设备状态D6052-D6056,生产节拍D6057-D6058
#region 单个地址读取
//计划编号10个字D6000-D6009、物料编号10个字D6010-D6019、计划数量1个字D6020、应答字1个字D6021
obj.plc.WriteString("D6000", planInfo.TaskCode);
string processNumber = GetProcessNumberBy(planInfo.MaterialCode);
obj.plc.WriteString("D6010", "BCD/310NF");
obj.plc.WriteInt32("D6020", planInfo.PlanAmount);
obj.plc.WriteInt32("D6021", 1);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>等待背板设备应答。。。。。。");
#region PLC反馈信号逻辑处理
//循环读取PLC应答信号PLC应答后复位应答信号、更新计划状态为执行中
bool isFlag = true;
do
{
/*
string planCode = obj.plc.ReadString("D6030");
string materialCode = obj.plc.ReadString("D6040");
int complateAmount = obj.plc.ReadInt32("D6050");
int offLineAmount = obj.plc.ReadInt32("D6051");
int productionBeat = obj.plc.ReadInt32("D6057");
*/
if (obj.plc.ReadInt32("D6021") == 2)
{
obj.plc.WriteInt32("D6021", 0);
Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>收到背板板设备应答信号,复位应答地址");
isFlag = false;
}
Thread.Sleep(2000);
} while (isFlag);
//更新计划状态为2执行中
planInfo.ExecuteStatus = 2;
_executePlanInfoServices.UpdateExecutePlanInfo(planInfo);
RefreshCurrentPlanInfoEvent?.Invoke(planInfo);
#endregion
//读取设备进度,完成后再次下发新任务
ReadDeviceComplate_BB(obj);
}
else
{
return;
}
}
}
catch (Exception ex)
{
MessageBox.Show($"背板⽣产计划下发异常:{ex.Message}", "提示", MessageBoxButton.OK, MessageBoxImage.Error,
MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
}
}
/// <summary>
/// 读取背板生产数据
/// </summary>
/// <param name="obj"></param>
public void ReadDeviceComplate_BB(PlcModel obj)
{
bool isFlag = true;
try
{
do
{
//计划编号D6030-D6039物料编号D6040-D6049计划完成数D6050计划下线数D6051设备状态D6052-D6056,生产节拍D6057-D6058
byte[] info = obj.plc.Read("D6030", 59);
//计划编号
string planCode = Encoding.ASCII.GetString(info.Skip(0).Take(20).ToArray());
@ -162,44 +300,87 @@ public class SheetMetalPlanTaskHandle
Console.WriteLine($"设备数据读取====>>>>当前计划:{planCode},物料编号:{materialCode},完成数量:{complateAmount},下线数量:{offLineAmount},设备状态:{deviceStatus},生产节拍:{productionBeat}");
//更新执行计划差异值为0后任务结束再次下发新任务
ExecutePlanInfo planInfo = _executePlanInfoServices.Query(x=>x.TaskCode.Equals(planCode.Substring(0,13)) && x.ExecuteStatus == 2).FirstOrDefault();
//添加完工记录
RecordSidePanelComplate sidePanelComplate = new RecordSidePanelComplate()
{
ProductlineCode = "1002",
PlanCode = planCode,
MaterialCode = materialCode,
CompleteAmount = complateAmount,
OffLineAmount = offLineAmount,
DeviceStatus = deviceStatus,
ProductionBeat = productionBeat,
RecordTime = DateTime.Now
};
if (planInfo != null)
//先查询该计划编号下的前一条完工记录如果不存在本条记录产量为0
List<RecordSidePanelComplate> sidePanelComplates = _sidePanelComplateServices.Query(x => x.ProductlineCode == "1002" && x.PlanCode == planCode);
int lastComplateAmount = 0; //前一条完成记录的计划完成数量
int sumComplateAmount = 0; //当前计划总产量
if (sidePanelComplates != null)
{
if (complateAmount > planInfo.CompleteAmount)
if (sidePanelComplates.Count > 0)
{
if (planInfo.PlanAmount - complateAmount == 0)
sidePanelComplates = sidePanelComplates.OrderByDescending(x => x.RecordTime).ToList();
lastComplateAmount = sidePanelComplates.First().CompleteAmount;
sidePanelComplate.OutPutAmount = complateAmount - lastComplateAmount;
sumComplateAmount = sidePanelComplates.Sum(x => x.OutPutAmount) + sidePanelComplate.OutPutAmount;
if (sidePanelComplate.OutPutAmount == 0)
{
Console.WriteLine($"计划:{planCode},执行完成!!!");
planInfo.CompleteAmount = complateAmount;
planInfo.ExecuteStatus = 3;
_executePlanInfoServices.UpdateExecutePlanInfo(planInfo);
isFlag = false;
Thread.Sleep(5000);
continue;
}
else
{
Console.WriteLine(
$"设备当前计划:{planCode},计划数量:{planInfo.PlanAmount},实际完成:{complateAmount},差异:{planInfo.PlanAmount - complateAmount}");
planInfo.CompleteAmount = complateAmount;
_executePlanInfoServices.UpdateExecutePlanInfo(planInfo);
if (sumComplateAmount > 0)
{
ExecutePlanInfo planInfo = _executePlanInfoServices.Query(x=>x.TaskCode.Equals(planCode.Substring(0,13)) && x.ExecuteStatus == 2).FirstOrDefault();
if (planInfo != null)
{
if (sumComplateAmount > planInfo.CompleteAmount)
{
if (planInfo.PlanAmount - sumComplateAmount == 0)
{
Console.WriteLine($"计划:{planCode},执行完成!!!");
planInfo.CompleteAmount = sumComplateAmount;
planInfo.ExecuteStatus = 3;
_executePlanInfoServices.UpdateExecutePlanInfo(planInfo);
isFlag = false;
}
else
{
Console.WriteLine(
$"设备当前计划:{planCode},计划数量:{planInfo.PlanAmount},实际完成:{sumComplateAmount},差异:{planInfo.PlanAmount - sumComplateAmount}");
planInfo.CompleteAmount = sumComplateAmount;
_executePlanInfoServices.UpdateExecutePlanInfo(planInfo);
}
RefreshCurrentPlanInfoEvent?.Invoke(planInfo);
}
}
}
}
RefreshCurrentPlanInfoEvent?.Invoke(planInfo);
}
}
_sidePanelComplateServices.InsertSidePanelCimplate(sidePanelComplate);
Thread.Sleep(5000);
} while (isFlag);
}
}
catch (Exception e)
{
Console.WriteLine($"读取设备完成数据异常:{e.Message}");
}
}
/// <summary>
/// 通过物料编号获取工艺编号

@ -23,6 +23,8 @@ using LiveCharts.Defaults;
using Aucma.Core.SheetMetal.Business;
using static Aucma.Core.SheetMetal.Business.SheetMetalPlanTaskHandle;
using System.Threading;
using NetTaste;
using Aucma.Core.HwPLc;
/*
*
*
@ -46,17 +48,16 @@ namespace Aucma.Core.SheetMetal.ViewModels
TypeName="自动"
}};
public Func<double, string> Formatter { get; set; }
public HwPLc.PlcModel obj = null;
#region 构造函数
public IndexPageViewModel()
{
_taskExecutionPlanInfoServices = App.ServiceProvider.GetService<IExecutePlanInfoServices>();
StationName = Appsettings.app("StoreInfo", "StationName");
_stationName = Appsettings.app("StationInfo", "StationName");
Job_SheetMetalTask_Quartz.SmEverDayDelegateEvent += InitEveryDayMethod;
Job_SheetMetalTask_Quartz.SmTaskDelegateEvent += UpdatePlanSHow;//计划内容展示
WeakReferenceMessenger.Default.Register<string>(this, Recive);
Task.WaitAll(LoadData(), InitExecMethod());
InitEveryDayMethod();
@ -69,7 +70,20 @@ namespace Aucma.Core.SheetMetal.ViewModels
Task.Run(() =>
{
Thread.Sleep(5000);
_taskHandle.SendPlanTaskToDevice();
while (true)
{
obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldTypePlc1"));
if (obj!=null)
{
if (obj.plc.IsConnected)
{
_taskHandle.ReadDeviceComplate_WB(obj);
_taskHandle.ReadDeviceComplate_BB(obj);
}
}
}
});
}
#endregion
@ -189,13 +203,13 @@ namespace Aucma.Core.SheetMetal.ViewModels
#region 加载DataGrid数据
private async Task LoadData()
{
string productLineCode = Appsettings.app("StoreInfo", "ProductLineCode");
var list = await _taskExecutionPlanInfoServices.QueryAsync(d => d.ProductLineCode.Contains(productLineCode));
string productLineCode = Appsettings.app("StationInfo", "ProductLineCode");
string stationCode = Appsettings.app("StationInfo", "StationCode");
var list = await _taskExecutionPlanInfoServices.QueryAsync(d => d.ProductLineCode.Contains(stationCode));
if (list == null) return;
var execList = list.OrderBy(d => d.ExecuteOrder);
int i = 1;
string planType = string.Empty;
foreach (var item in execList)
{
TaskExecModel task = new TaskExecModel();
@ -631,7 +645,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
PlanInfoDataGrid.Clear();
LoadData();
_= LoadData();
}));
}
}

@ -3,6 +3,7 @@ using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Service;
using Aucma.Core.HwPLc;
using Aucma.Core.SheetMetal.Business;
using Aucma.Core.SheetMetal.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@ -13,6 +14,7 @@ using Microsoft.IdentityModel.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@ -102,10 +104,24 @@ namespace Aucma.Core.SheetMetal.ViewModels
if (obj == null) { return; }
if (obj.plc.IsConnected)
{
obj.plc.WriteInt16("D8000", _TransmitAmount);//计划编号
obj.plc.WriteInt16("D8009", _TransmitAmount);//计划编号
obj.plc.WriteInt16("D8050", _TransmitAmount);//计划数量
obj.plc.ReadInt16("D8021");//应答字
//obj.plc.WriteInt16("D8000", _TransmitAmount);//计划编号
//obj.plc.WriteInt16("D8009", _TransmitAmount);//计划编号
//obj.plc.WriteInt16("D8050", _TransmitAmount);//计划数量
//obj.plc.ReadInt16("D8021");//应答字
SheetMetalPlanTaskHandle handle = new SheetMetalPlanTaskHandle();
if (productPlanInfo.PlanType== 1)
{
handle.SendPlanTaskTo_BB(task, obj);
handle.SendPlanTask_WB(task, obj);
}
if (productPlanInfo.PlanType == 2)
{
handle.SendPlanTask_WB(task, obj);
}
if (productPlanInfo.PlanType == 2)
{
handle.SendPlanTaskTo_BB(task, obj);
}
}
MessageBox.Show("计划拆分成功!", "系统提醒");
WeakReferenceMessenger.Default.Send<string>("Refresh");//刷新窗口

@ -19,6 +19,8 @@ using Aucma.Core.SheetMetal.Common;
using System.Windows.Input;
using Admin.Core.Common;
using System.Drawing.Drawing2D;
using Aucma.Core.SheetMetal.Business;
using Aucma.Core.HwPLc;
namespace Aucma.Core.SheetMetal.ViewModels
{
@ -29,7 +31,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
//protected readonly ISmTaskExecutionServices? _smTaskExecutionServices;
protected readonly IExecutePlanInfoServices? _executePlanInfoServices;
private AppConfigHelper appConfig = new AppConfigHelper();
public SplitPlanViewModel()
{
_productPlanInfoServices = App.ServiceProvider.GetService<IProductPlanInfoServices>();
@ -46,7 +48,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
{
MaterialDataGrid.Clear();
int i = 1;
string station = Appsettings.app("StoreInfo", "StationCode");
string station = Appsettings.app("StationInfo", "StationCode");
var planlist = await _productPlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals(station));
var execList = await _executePlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals(station));
foreach (var item in planlist)
@ -141,6 +143,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
MessageBox.Show("请选中需要拆分的计划!", "系统提醒");
return;
}
string productLineCode=Appsettings.app("StationInfo", "ProductLineCode");
string plan_code = SelectedCells.PlanCode;
string order_code = SelectedCells.OrderCode;
string material_code = SelectedCells.MaterialCode;
@ -165,6 +168,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
task.PlanAmount = SelectedCells.SpliteResidueAmount;
task.CompleteAmount = 0;
task.CreatedTime = DateTime.Now;
var result = await _executePlanInfoServices.AddAsync(task);
if (result>0)
{

@ -70,7 +70,7 @@
<Setter Property="Foreground" Value="White"/>
</Trigger>
<DataTrigger Binding="{Binding ExecuteStatus}" Value="2">
<Setter Property="Background" Value="Green" />
<Setter Property="Background" Value="CadetBlue" />
</DataTrigger>
</Style.Triggers>
</Style>
@ -311,7 +311,7 @@
<DataGridTextColumn Binding="{Binding TaskAmount}" Header="计划" Width="0.6*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding CompleteAmount}" Header="完成" Width="0.6*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding PlanType}" Header="计划类型" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding PlanType}" Header="配方" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<!--<DataGridTextColumn Binding="{Binding PlanType}" Header="配方" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>-->
<DataGridTextColumn Binding="{Binding BeginTime ,StringFormat=\{0:MM-dd HH:mm\}}" Header="开始时间" Width="1.2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding ExecuteStatus}" Header="执行状态" Visibility="Collapsed"/>

@ -113,13 +113,13 @@
"Enabled": true
}
},
"StoreInfo": {
"StationInfo": {
"StationName": "箱壳前后板生产",
"StationCode": "1001",
"ShellStoreCode": "XKJCK-001",
"LinerStoreCode": "NDJCK-001",
"FoamBeforeStoreCode": "PBSCK-001",
"ProductLineCode": "1001"
"ProductLineCode": "CX_01"
},
"PLCServer": [
{

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save