@@ -27,9 +27,9 @@ namespace BPASmartClient.DosingSystem.ViewModel
//StartCommand = new BPARelayCommand<object>(RecipeIssued);
//ChangeRecipeStateCommand = new BPARelayCommand<object>(ChangeRecipeState);
//CancelRecipeCommand = new BPARelayCommand<object>(CancelRecipe);
RecipeRun();
// RecipeRun();
RecipeStatusInquire();
MatchRun();
StartCommand = new BPARelayCommand<object>(new Action<object>((o) => {
if (o != null && o is string recipeName)
{
@@ -122,20 +122,18 @@ namespace BPASmartClient.DosingSystem.ViewModel
//}
int index = 0;
private void MatchRun()
{
string passRecipeName = "";
recipeProcesses.Clear();
TaskManage.GetInstance.StartLong(() =>
{
if (RecipeNames.Count > 0)
{
passRecipeName = recipeProcesses.Last().RecipeName;
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices.Last().IpAddress].deviceStatus.MaxPassPail!=0 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices.Last().IpAddress].deviceStatus.MaxPassPail == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices.Last().IpAddress].deviceStatus.PassPail && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices.Last().IpAddress].deviceStatus.RunStatus == 3)
{
RecipeNames.TryDequeue(out passRecipeName );
recipeProcesses.Remove(recipeProcesses.Last() );
UserTreeCompelete.Insert(0, recipeProcesses.Last());
}
for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
{
@@ -143,10 +141,12 @@ namespace BPASmartClient.DosingSystem.ViewModel
{
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail == 0 || DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3)
{
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail)
{
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(0));
string passName = RecipeNames.ElementAt(0);
RecipeNames.TryDequeue(out passName);
int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(0));
if (index > 0 && index < Recipes.Count)
{
App.Current.Dispatcher.Invoke(new Action(() =>
@@ -170,14 +170,17 @@ namespace BPASmartClient.DosingSystem.ViewModel
}
}
RawMaterialModel res = Recipes.ElementAt(index).RawMaterials?.ToList().Find(a => a.RawMaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
if (res != null && res.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail)
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1)
{
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1)
int doCount = Array.FindIndex(Recipes.ToArray(), p => p.SerialNum == (int)DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DoRecipeCount);
RawMaterialModel res = Recipes.ElementAt(doCount).RawMaterials?.ToList().Find(a => a.RawMaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
if (res != null && res.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail)
{
DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
if (deviceSet!= null)
if (deviceSet != null)
{
//设置启动
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 1);
@@ -198,23 +201,25 @@ namespace BPASmartClient.DosingSystem.ViewModel
//设置搅拌速度
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<int>(DeviceAddress.StirringSpeed.ToAdd(), deviceSet.StirringSpeed);
}
//写入出货量
//下料设定参数
}
}
}
if (i < DeviceInquire.GetInstance.devices.Count - 1)
{
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i + 1].IpAddress].deviceStatus.PailArrive == 0)
{
//出料状态
//传送带运行
DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), deviceSet.SendSp);
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 1);
}
else
{
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
//传送带停止
}
}
@@ -235,195 +240,195 @@ namespace BPASmartClient.DosingSystem.ViewModel
/// <summary>
/// 配方业务执行
/// </summary>
private void RecipeRun()
{
TaskManage.GetInstance.StartLong(new Action(() =>
{
if (RecipeNames.Count > 0)
{
int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(0));
if (index >= 0 && index < Recipes.Count)
{
Recipes.ElementAt(index).Are.Reset();
Recipes.ElementAt(index).IsEnable = false;
StockStatus.Clear();
App.Current.Dispatcher.Invoke(new Action(() =>
{
recipeProcesses.Clear();
if (UserTreeWait.Count > 0) UserTreeWait.RemoveAt(0);
}));
CurrentRecipeName = Recipes.ElementAt(index).RecipeName;
#region 配方下发到PLC操作相关
//配方数据写入到输送机
var res = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeName == CurrentRecipeName);
List<int> BarrelNum = new List<int>();
ConcurrentDictionary<string, int[]> values = new();
if (res != null)
{
var tInfo = res.RawMaterials.GroupBy(p => p.Loc);//获取桶号信息
if (tInfo != null)
{
for (int i = 0; i < tInfo.Count(); i++)
{
int data = 0;
for (int m = 0; m < tInfo.ElementAt(i).Count(); m++)
{
var TempName = tInfo.ElementAt(i).ElementAt(m).RawMaterialName;
var tempDevice = DeviceInquire.GetInstance.devices.FirstOrDefault(p => p.DeviceName == TempName);
if (tempDevice != null)
{
/*data = data.SetBitValue((byte)tempDevice.DeviceNum, true);*/
if (tempDevice.DeviceNum > 0)
{
// //int a = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true);
// //byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC);
// //int item = test1.ToInt();
// int item = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true).ToBytes(BPA.Helper.DataFormat.BADC).ToInt();
// int item1 = SiemensDevice.GetInstance.MySiemens.Read<int>($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}").Content;
////prop1:
// var RE = SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}", item + item1);
// //var values = SiemensDevice.GetInstance.MySiemens.Read<int>($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}");
// //if ((values != null && values.ToString() != (item + item1).ToString()) || values == null)
// // goto prop1;
// if (RE.IsSuccess)
// MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} :{(byte)tInfo.ElementAt(i).ElementAt(m).Loc}-{item + item1}-{(item + item1).ToBinString()}");
// else
// MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} 失败");
int item = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true).ToBytes(BPA.Helper.DataFormat.BADC).ToInt();
string tempAdd = $"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}";
if (!values.ContainsKey(tempAdd)) values.TryAdd(tempAdd, new int[2] { 0, 0 });
values[tempAdd][0] = values[tempAdd][0] + item;
values[tempAdd][1] = tInfo.ElementAt(i).ElementAt(m).Loc;
}
}
if (tInfo.ElementAt(i).ElementAt(m).Loc > 0)
{
if (!BarrelNum.Contains(tInfo.ElementAt(i).ElementAt(m).Loc))
{
BarrelNum.Add(tInfo.ElementAt(i).ElementAt(m).Loc);
}
}
}
}
}
}
// private void RecipeRun()
// {
// TaskManage.GetInstance.StartLong(new Action(() =>
// {
// if (RecipeNames.Count > 0)
// {
// int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(0));
// if (index >= 0 && index < Recipes.Count)
// {
// Recipes.ElementAt(index).Are.Reset();
// Recipes.ElementAt(index).IsEnable = false;
// StockStatus.Clear();
// App.Current.Dispatcher.Invoke(new Action(() =>
// {
// recipeProcesses.Clear();
// if (UserTreeWait.Count > 0) UserTreeWait.RemoveAt(0);
// }));
// CurrentRecipeName = Recipes.ElementAt(index).RecipeName;
// #region 配方下发到PLC操作相关
// //配方数据写入到输送机
// var res = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeName == CurrentRecipeName);
// List<int> BarrelNum = new List<int>();
// ConcurrentDictionary<string, int[]> values = new();
// if (res != null)
// {
// var tInfo = res.RawMaterials.GroupBy(p => p.Loc);//获取桶号信息
// if (tInfo != null)
// {
// for (int i = 0; i < tInfo.Count(); i++)
// {
// int data = 0;
// for (int m = 0; m < tInfo.ElementAt(i).Count(); m++)
// {
// var TempName = tInfo.ElementAt(i).ElementAt(m).RawMaterialName;
// var tempDevice = DeviceInquire.GetInstance.devices.FirstOrDefault(p => p.DeviceName == TempName);
// if (tempDevice != null)
// {
// /*data = data.SetBitValue((byte)tempDevice.DeviceNum, true);*/
// if (tempDevice.DeviceNum > 0)
// {
// // //int a = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true);
// // //byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC);
// // //int item = test1.ToInt();
// // int item = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true).ToBytes(BPA.Helper.DataFormat.BADC).ToInt();
// // int item1 = SiemensDevice.GetInstance.MySiemens.Read<int>($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}").Content;
// ////prop1:
// // var RE = SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}", item + item1);
// // //var values = SiemensDevice.GetInstance.MySiemens.Read<int>($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}");
// // //if ((values != null && values.ToString() != (item + item1).ToString()) || values == null)
// // // goto prop1;
// // if (RE.IsSuccess)
// // MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} :{(byte)tInfo.ElementAt(i).ElementAt(m).Loc}-{item + item1}-{(item + item1).ToBinString()}");
// // else
// // MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} 失败");
// int item = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true).ToBytes(BPA.Helper.DataFormat.BADC).ToInt();
// string tempAdd = $"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}";
// if (!values.ContainsKey(tempAdd)) values.TryAdd(tempAdd, new int[2] { 0, 0 });
// values[tempAdd][0] = values[tempAdd][0] + item;
// values[tempAdd][1] = tInfo.ElementAt(i).ElementAt(m).Loc;
// }
// }
// if (tInfo.ElementAt(i).ElementAt(m).Loc > 0)
// {
// if (!BarrelNum.Contains(tInfo.ElementAt(i).ElementAt(m).Loc))
// {
// BarrelNum.Add(tInfo.ElementAt(i).ElementAt(m).Loc);
// }
// }
// }
// }
// }
// }
values?.ToList().ForEach(x =>
{
SiemensDevice.GetInstance.MySiemens.Write(x.Key, x.Value[0]).OnSuccess(() =>
{
MessageNotify.GetInstance.ShowRunLog($"下发配方-{x.Key} :桶数:[{x.Value[1]}]-{x.Value[0].ToBinString()}");
}).OnFail(s =>
{
MessageNotify.GetInstance.ShowRunLog($"下发配方-{x.Key} 失败");
});
});
// values?.ToList().ForEach(x =>
// {
// SiemensDevice.GetInstance.MySiemens.Write(x.Key, x.Value[0]).OnSuccess(() =>
// {
// MessageNotify.GetInstance.ShowRunLog($"下发配方-{x.Key} :桶数:[{x.Value[1]}]-{x.Value[0].ToBinString()}");
// }).OnFail(s =>
// {
// MessageNotify.GetInstance.ShowRunLog($"下发配方-{x.Key} 失败");
// });
// });
SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD198", BarrelNum.Count);//配方使用桶数写入
// SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD198", BarrelNum.Count);//配方使用桶数写入
SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX0.1", true);//配方执行启动
Stopwatch sw = new Stopwatch();
var recipe = Recipes.ElementAt(index);
ObservableCollection<RawMaterialModel> RawMater = new ObservableCollection<RawMaterialModel>();
foreach (var item in recipe.RawMaterials)
{
RawMater.Add(new RawMaterialModel()
{
RawMaterialName = item.RawMaterialName,
DeviceIp = item.DeviceIp,
DownLimtFeedback = item.DownLimtFeedback,
Loc = item.Loc,
RawMaterialId = item.RawMaterialId,
RawMaterialSource = item.RawMaterialSource,
RawMaterialType = item.RawMaterialType,
RawMaterialWeight = item.RawMaterialWeight,
RecipeStatus = item.RecipeStatus,
SelectIndex = item.SelectIndex,
Status = item.Status,
UpLimtFeedback = item.UpLimtFeedback,
UpLimtWeightFeedback = item.UpLimtWeightFeedback,
WeightFeedback = item.WeightFeedback,
});
}
App.Current.Dispatcher.Invoke(() =>
{
recipeProcesses.Add(new RecipeModel()
{
RawMaterials = RawMater,
IsEnable = recipe.IsEnable,
RecipeName = recipe.RecipeName,
SerialNum = recipe.SerialNum,
RecipCode = recipe.RecipCode,
});
});
sw.Restart();
while (true)
{
if (sw.ElapsedMilliseconds >= 3000 && !GlobalDevice.PlcData.ResComplete)
{
MessageNotify.GetInstance.ShowRunLog("获取配方下发反馈超时");
break;
}
if (GlobalDevice.PlcData.ResComplete)
{
SiemensDevice.GetInstance.MySiemens.Write("DB3.DBX0.1", false);
break;
}
Thread.Sleep(100);
}
#endregion
// SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX0.1", true);//配方执行启动
// Stopwatch sw = new Stopwatch();
// var recipe = Recipes.ElementAt(index);
// ObservableCollection<RawMaterialModel> RawMater = new ObservableCollection<RawMaterialModel>();
// foreach (var item in recipe.RawMaterials)
// {
// RawMater.Add(new RawMaterialModel()
// {
// RawMaterialName = item.RawMaterialName,
// DeviceIp = item.DeviceIp,
// DownLimtFeedback = item.DownLimtFeedback,
// Loc = item.Loc,
// RawMaterialId = item.RawMaterialId,
// RawMaterialSource = item.RawMaterialSource,
// RawMaterialType = item.RawMaterialType,
// RawMaterialWeight = item.RawMaterialWeight,
// RecipeStatus = item.RecipeStatus,
// SelectIndex = item.SelectIndex,
// Status = item.Status,
// UpLimtFeedback = item.UpLimtFeedback,
// UpLimtWeightFeedback = item.UpLimtWeightFeedback,
// WeightFeedback = item.WeightFeedback,
// });
// }
// App.Current.Dispatcher.Invoke(() =>
// {
// recipeProcesses.Add(new RecipeModel()
// {
// RawMaterials = RawMater,
// IsEnable = recipe.IsEnable,
// RecipeName = recipe.RecipeName,
// SerialNum = recipe.SerialNum,
// RecipCode = recipe.RecipCode,
// });
// });
// sw.Restart();
// while (true)
// {
// if (sw.ElapsedMilliseconds >= 3000 && !GlobalDevice.PlcData.ResComplete)
// {
// MessageNotify.GetInstance.ShowRunLog("获取配方下发反馈超时");
// break;
// }
// if (GlobalDevice.PlcData.ResComplete)
// {
// SiemensDevice.GetInstance.MySiemens.Write("DB3.DBX0.1", false);
// break;
// }
// Thread.Sleep(100);
// }
// #endregion
Recipes.ElementAt(index).Are.WaitOne();//阻塞,直到当前配方完成
RecipeNames.TryDequeue(out string deviceName);
var recipeComple = Recipes.ElementAt(index);
ObservableCollection<RawMaterialModel> RawMaterComple = new ObservableCollection<RawMaterialModel>();
foreach (var item in recipeComple.RawMaterials)
{
RawMaterComple.Add(new RawMaterialModel()
{
RawMaterialName = item.RawMaterialName,
DeviceIp = item.DeviceIp,
DownLimtFeedback = item.DownLimtFeedback,
Loc = item.Loc,
RawMaterialId = item.RawMaterialId,
RawMaterialSource = item.RawMaterialSource,
RawMaterialType = item.RawMaterialType,
RawMaterialWeight = item.RawMaterialWeight,
RecipeStatus = item.RecipeStatus,
SelectIndex = item.SelectIndex,
Status = item.Status,
UpLimtFeedback = item.UpLimtFeedback,
UpLimtWeightFeedback = item.UpLimtWeightFeedback,
WeightFeedback = item.WeightFeedback,
});
}
App.Current.Dispatcher.Invoke(() =>
{
UserTreeCompelete.Add(new RecipeModel()
{
RawMaterials = RawMaterComple,
IsEnable = recipeComple.IsEnable,
RecipeName = recipeComple.RecipeName,
SerialNum = UserTreeCompelete.Count + 1,
RecipCode = recipeComple.RecipCode,
RecipStatus = "制作完成"
});
});
App.Current.Dispatcher.Invoke(new Action(() =>
{
recipeProcesses.Clear();
CurrentRecipeName = string.Empty;
}));//完成后清空当前配方
}
}
Thread.Sleep(100);
}), "启动配方下发", true);
}
// Recipes.ElementAt(index).Are.WaitOne();//阻塞,直到当前配方完成
// RecipeNames.TryDequeue(out string deviceName);
// var recipeComple = Recipes.ElementAt(index);
// ObservableCollection<RawMaterialModel> RawMaterComple = new ObservableCollection<RawMaterialModel>();
// foreach (var item in recipeComple.RawMaterials)
// {
// RawMaterComple.Add(new RawMaterialModel()
// {
// RawMaterialName = item.RawMaterialName,
// DeviceIp = item.DeviceIp,
// DownLimtFeedback = item.DownLimtFeedback,
// Loc = item.Loc,
// RawMaterialId = item.RawMaterialId,
// RawMaterialSource = item.RawMaterialSource,
// RawMaterialType = item.RawMaterialType,
// RawMaterialWeight = item.RawMaterialWeight,
// RecipeStatus = item.RecipeStatus,
// SelectIndex = item.SelectIndex,
// Status = item.Status,
// UpLimtFeedback = item.UpLimtFeedback,
// UpLimtWeightFeedback = item.UpLimtWeightFeedback,
// WeightFeedback = item.WeightFeedback,
// });
// }
// App.Current.Dispatcher.Invoke(() =>
// {
// UserTreeCompelete.Add(new RecipeModel()
// {
// RawMaterials = RawMaterComple,
// IsEnable = recipeComple.IsEnable,
// RecipeName = recipeComple.RecipeName,
// SerialNum = UserTreeCompelete.Count + 1,
// RecipCode = recipeComple.RecipCode,
// RecipStatus = "制作完成"
// });
// });
// App.Current.Dispatcher.Invoke(new Action(() =>
// {
// recipeProcesses.Clear();
// CurrentRecipeName = string.Empty;
// }));//完成后清空当前配方
// }
// }
// Thread.Sleep(100);
// }), "启动配方下发", true);
// }
/// <summary>