liulb@mesnac.com 1 year ago
parent b7bca5fe07
commit a988f3a74d

@ -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;
// 如果网络不太理想,配置了两个端口,一个有问题,立即切换另一个的话,可以配置如下的代码

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>

@ -37,7 +37,8 @@ namespace Aucma.Core.OldBoxFoam.Business
try
{
///Task.Run(() =>
//{
//{
// Thread.Sleep(3000);
plc1 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1"));
plc2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc2"));
plc3 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc3"));
@ -83,19 +84,8 @@ namespace Aucma.Core.OldBoxFoam.Business
ReadStoreAmount(plc4, StoreAmountList);
for (int i = 0; i < 24; i++)
{
if (listFixtureStatus.Count > 0)
{
FixtureStatus model = new FixtureStatus();
model.ObjId = i + 1;
if (BoxTypeList.Count > 0) model.FixtureBoxType = BoxTypeList[i].ToString();
if (HolderStatusList.Count > 0) model.Status = HolderStatusList[i];
if (HolderOutPutList.Count > 0) model.Yield = HolderOutPutList[i];
if (SolidifyTimeList.Count > 0) model.PlanCuringTime = SolidifyTimeList[i];
listFixtureStatus.Add(model);
}
else
{
//if (listFixtureStatus.Count > 0)
//{
FixtureStatus model = new FixtureStatus();
model.ObjId = i + 1;
if (BoxTypeList.Count > 0) model.FixtureBoxType = BoxTypeList[i].ToString();
@ -104,7 +94,18 @@ namespace Aucma.Core.OldBoxFoam.Business
if (SolidifyTimeList.Count > 0) model.PlanCuringTime = SolidifyTimeList[i];
listFixtureStatus.Add(model);
}
//}
//else
//{
// FixtureStatus model = new FixtureStatus();
// model.ObjId = i + 1;
// if (BoxTypeList.Count > 0) model.FixtureBoxType = BoxTypeList[i].ToString();
// if (HolderStatusList.Count > 0) model.Status = HolderStatusList[i];
// if (HolderOutPutList.Count > 0) model.Yield = HolderOutPutList[i];
// if (SolidifyTimeList.Count > 0) model.PlanCuringTime = SolidifyTimeList[i];
// listFixtureStatus.Add(model);
//}
}
for (int i = 0; i < 8; i++)
@ -128,6 +129,8 @@ namespace Aucma.Core.OldBoxFoam.Business
/// </summary>
static void ReadBoxType(HwPLc.PlcModel obj, List<int> BoxTypeList)
{
if (obj == null) return;
if (obj.plc.IsConnected)
{
byte[] result = obj.plc.Read("D3140", 48);
@ -154,6 +157,7 @@ namespace Aucma.Core.OldBoxFoam.Business
/// </summary>
static void ReadHolderStatus(PlcModel obj1, List<int> HolderStatusList)
{
if (obj1 == null) return;
byte[] result = obj1.plc.Read("YF0", 1);
if (result == null) return;
//输出二进制字符串,1#-3#手动、自动数据
@ -261,6 +265,7 @@ namespace Aucma.Core.OldBoxFoam.Business
/// </summary>
static void ReadHolderOutPut(PlcModel obj,List<int> HolderOutPutList)
{
if (obj == null) return;
byte[] result = obj.plc.Read("D182", 24);
if (result == null) return;
byte[] info = result;
@ -285,6 +290,7 @@ namespace Aucma.Core.OldBoxFoam.Business
/// </summary>
static void ReadSolidifyTime(PlcModel obj,List<int> SolidifyTimeList)
{
if (obj == null) return;
byte[] result = obj.plc.Read("D910", 24);
if (result == null) return;
byte[] info = result;
@ -308,6 +314,7 @@ namespace Aucma.Core.OldBoxFoam.Business
/// </summary>
static void ReadStoreType(PlcModel obj, List<string> storeType)
{
if (obj == null) return;
//夹具箱型
byte[] result = obj.plc.Read("D2010", 40);
if (result == null) return;
@ -328,6 +335,7 @@ namespace Aucma.Core.OldBoxFoam.Business
/// </summary>
static void ReadStoreAmount(PlcModel obj, List<string> storeAmount)
{
if (obj == null) return;
byte[] result = obj.plc.Read("L101", 1);
if (result == null) return;
string str1 = ByteArrayToBinary(array(result)).Substring(0, 3);

@ -40,51 +40,52 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
private readonly IBoxFoamDataRecordServices _boxFoamDataRecordServices;
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(OldBoxFoamPageViewModel));
Collection collection = new Collection();
System.Timers.Timer timer1 = new System.Timers.Timer(2000);
System.Timers.Timer timer2 = new System.Timers.Timer(10000);
System.Timers.Timer timer1 = new System.Timers.Timer(5000);
System.Timers.Timer timer2 = new System.Timers.Timer(3000);
int totalAmount = 0;
bool flag = true;
public OldBoxFoamPageViewModel() {
_oldBoxFoamDataServices = App.ServiceProvider.GetService<IBoxFoamDataServices>();
_oldBoxFoamTypeServices = App.ServiceProvider.GetService<IOldBoxFoamTypeServices>();
_boxFoamPlanServices = App.ServiceProvider.GetService<IBoxFoamPlanServices>();
_sysUserInfoServices = App.ServiceProvider.GetService<ISysUserInfoServices>();
_currentTeamTimeServices = App.ServiceProvider.GetService<ICurrentTeamTimeServices>();
_currentTeamTimeServices = App.ServiceProvider.GetService<ICurrentTeamTimeServices>();
// _currentTeamTimeServices = App.ServiceProvider.GetService<ICurrentTeamTimeServices>();
_boxFoamDataRecordServices = App.ServiceProvider.GetService<IBoxFoamDataRecordServices>();
//AucamTaskService.RefreshOldBoxFoamDataDelegateEvent += OldBoxFoamOnLoad3;
timer1.Elapsed += new System.Timers.ElapsedEventHandler(OldBoxFoamOnLoad); //到达时间的时候执行事件;
timer1.AutoReset = true;//设置是执行一次false还是一直执行(true)
timer1.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它
timer1.Start();//timer.Start()的内部原理还是设置timer.Enabled = true;
//timer1.Elapsed += new System.Timers.ElapsedEventHandler(OldBoxFoamOnLoad); //到达时间的时候执行事件;
//timer1.AutoReset = true;//设置是执行一次false还是一直执行(true)
//timer1.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它
//timer1.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;
//Task.WaitAll(OldBoxFoamOnLoad3());
}
#region 初始化加载数据
private void OldBoxFoamOnLoad(object? sender, ElapsedEventArgs e)
private void OldBoxFoamOnLoad(List<FixtureStatus> prderList)
{
try
{
//collection.startCollect();
///if (collection.listFixtureStatus == null) return;
//var prderList= collection.listFixtureStatus;
int num = prderList.Sum(d => d.Yield);
if (prderList.Count==0) return;
totalAmount = 0;
_fixtureName.Clear();
_production.Clear();
_beat.Clear();
_statusColor.Clear();
if (collection.listFixtureStatus == null) return;
int i = 0;
var prderList= collection.listFixtureStatus;
int num = prderList.Sum(d => d.Yield);
foreach (var item in prderList)
{
if (item.Status == 1)//生产
if (item.Status == 2)//生产
{
_statusColor.Add("green");
}
@ -112,44 +113,36 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
}
}
}
public async Task OldBoxFoamOnLoad3(List<BoxFoamData> list)
public async Task OldBoxFoamOnLoad3()
{
try
{
if (list == null) return;
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
collection.startCollect();
if (collection.listFixtureStatus == null) return;
var prderList = collection.listFixtureStatus;
int num = prderList.Sum(d => d.Yield);
if (prderList.Count==0) return;
totalAmount = 0;
_fixtureName.Clear();
_production.Clear();
_beat.Clear();
_statusColor.Clear();
foreach (var item in prderList)
{
_fixtureName.Clear();
_production.Clear();
_beat.Clear();
_statusColor.Clear();
OldBoxFoamDataGrid.Clear();
int i = 0;
var prderList = list.OrderBy(d => d.MainId);
foreach (var item in prderList)
if (item.Status == 1)//生产
{
OldBoxFoamDataModel model = new OldBoxFoamDataModel();
model.ObjId = item.ObjId;
model.Fixtureboxtype = item.Fixtureboxtype;
model.Fixturestatus = item.Fixturestatus;
model.Production = item.Production;
model.CuringTimeSettingValue = item.CuringTimeSettingValue;
if (item.Fixturestatus == 1)//停止
{
_statusColor.Add("green");
}
else
{
_statusColor.Add("red");
}
_fixtureName.Add(item.Fixtureboxtype);
_production.Add(item.Production);
_beat.Add(item.BoxBeat);
i = +item.Production;
_statusColor.Add("green");
}
}));
else
{
_statusColor.Add("red");
}
_fixtureName.Add(item.FixtureBoxType);
_production.Add(item.Yield);
//_beat.Add(item.BoxBeat);
totalAmount = totalAmount + item.Yield;
}
Totle = totalAmount.ToString();
}
catch (Exception ex)
{
@ -157,9 +150,10 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
}
finally
{
if (GetStoreTimer != null)
{
GetStoreTimer.Change(10000, Timeout.Infinite);
GetStoreTimer.Change(20000, Timeout.Infinite);
}
}
}
@ -353,8 +347,6 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
private async void ExecHourData(string productLineCode)
{
try
{
List<FixtureStatus> bLis = new List<FixtureStatus>();
@ -362,44 +354,60 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
collection.startCollect();
bLis = collection.listFixtureStatus;
if (bLis.Count == 0) return;
int total = 0;
List<BoxFoamData> bfds = await _oldBoxFoamDataServices.QueryAsync();
List<OldBoxFoamType> spaceList = await _oldBoxFoamTypeServices.QueryAsync();
List < BoxFoamPlan> planList = await _boxFoamPlanServices.QueryAsync();
List<BoxFoamPlan> planList = await _boxFoamPlanServices.QueryAsync();
for (int j = 0; j < bLis.Count; j++)
{
OldBoxFoamType space = spaceList.FirstOrDefault(d => d.Boxtype == bLis[j].FixtureBoxType);
//根据夹具找货道,根据货道找物料
if (space != null)
try
{
BoxFoamPlan plan = planList.FirstOrDefault(d => d.MaterialCode == space.MaterialCode && d.PlanAmount > d.CompleteAmount);
if (plan != null)
OldBoxFoamType space = spaceList.FirstOrDefault(d => d.Boxtype == bLis[j].FixtureBoxType);
//根据夹具找货道,根据货道找物料
if (space != null)
{
int complateAmount = 0;
//更新小时数据
BoxFoamData bfd = bfds.FirstOrDefault(d => d.Fixtureboxtype == bLis[j].FixtureBoxType && d.MainId == bLis[j].ObjId);
if (bfd != null)
BoxFoamPlan plan = planList.FirstOrDefault(d => d.MaterialCode == space.MaterialCode && d.PlanAmount > d.CompleteAmount);
if (plan != null)
{
UpdateBoxData(bLis[j], bfd);
//更新计划数量
complateAmount = bLis[j].Yield - bfd.Production;
int complateAmount = 0;
//更新小时数据
BoxFoamData bfd = bfds.FirstOrDefault(d => d.Fixtureboxtype == bLis[j].FixtureBoxType && d.MainId == bLis[j].ObjId);
if (bfd != null)
{
//更新计划数量
complateAmount = bLis[j].Yield - bfd.Production;
UpdateBoxData(bLis[j], bfd);
}
else
{
SaveBoxData(productLineCode, bLis[j]);
}
plan.CompleteAmount = plan.CompleteAmount + complateAmount;
await _boxFoamPlanServices.UpdateAsync(plan);
}
else
{
SaveBoxData(productLineCode, bLis[j]);
//更新小时数据
BoxFoamData bfd = bfds.FirstOrDefault(d => d.Fixtureboxtype == bLis[j].FixtureBoxType && d.MainId == bLis[j].ObjId);
if (bfd != null)
{
UpdateBoxData(bLis[j], bfd);
}
else
{
SaveBoxData(productLineCode, bLis[j]);
}
}
plan.CompleteAmount = plan.CompleteAmount + complateAmount;
await _boxFoamPlanServices.UpdateAsync(plan);
}
else
{
//更新小时数据
//List<BoxFoamData> bfd = await _oldBoxFoamDataServices.QueryAsync(d => d.Fixtureboxtype == bLis[j].FixtureBoxType && d.MainId == bLis[j].ObjId);
BoxFoamData bfd = bfds.FirstOrDefault(d => d.Fixtureboxtype == bLis[j].FixtureBoxType && d.MainId == bLis[j].ObjId);
if (bfd!=null)
if (bfd != null)
{
UpdateBoxData(bLis[j], bfd);
}
else
{
@ -407,22 +415,11 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
}
}
}
else
{
//更新小时数据
//List<BoxFoamData> bfd = await _oldBoxFoamDataServices.QueryAsync(d => d.Fixtureboxtype == bLis[j].FixtureBoxType && d.MainId == bLis[j].ObjId);
catch { }
BoxFoamData bfd = bfds.FirstOrDefault(d => d.Fixtureboxtype == bLis[j].FixtureBoxType && d.MainId == bLis[j].ObjId);
if (bfd != null)
{
UpdateBoxData(bLis[j], bfd);
}
else
{
SaveBoxData(productLineCode, bLis[j]);
}
}
}
OldBoxFoamOnLoad(bLis);
}
catch (Exception ex)
{

Loading…
Cancel
Save