|
@@ -19,11 +19,13 @@ using System.Data.SqlClient; |
|
|
using S7.Net.Types; |
|
|
using S7.Net.Types; |
|
|
using BPA.Communication; |
|
|
using BPA.Communication; |
|
|
using BPASmartClient.DosingSystem.Model; |
|
|
using BPASmartClient.DosingSystem.Model; |
|
|
|
|
|
using System.Security.Cryptography; |
|
|
|
|
|
|
|
|
namespace BPASmartClient.DosingSystem.ViewModel |
|
|
namespace BPASmartClient.DosingSystem.ViewModel |
|
|
{ |
|
|
{ |
|
|
public class RecipeControlViewModel : NotifyBase |
|
|
public class RecipeControlViewModel : NotifyBase |
|
|
{ |
|
|
{ |
|
|
|
|
|
int ComCount = 0;//配料完成计数 |
|
|
static ConcurrentQueue<string> RecipeNames = new ConcurrentQueue<string>(); |
|
|
static ConcurrentQueue<string> RecipeNames = new ConcurrentQueue<string>(); |
|
|
static ObservableCollection<StockStatusModel> StockStatus = new ObservableCollection<StockStatusModel>(); |
|
|
static ObservableCollection<StockStatusModel> StockStatus = new ObservableCollection<StockStatusModel>(); |
|
|
public RecipeControlViewModel() |
|
|
public RecipeControlViewModel() |
|
@@ -160,7 +162,7 @@ namespace BPASmartClient.DosingSystem.ViewModel |
|
|
if ((values != null && values.ToString() != (item + item1).ToString()) || values == null) |
|
|
if ((values != null && values.ToString() != (item + item1).ToString()) || values == null) |
|
|
goto prop1; |
|
|
goto prop1; |
|
|
if (RE.IsSuccess) |
|
|
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()}"); |
|
|
|
|
|
|
|
|
MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} :{(byte)tInfo.ElementAt(i).ElementAt(m).Loc}-{item + item1}-{(item + item1).ToBinString()}"); |
|
|
else |
|
|
else |
|
|
MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} 失败"); |
|
|
MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} 失败"); |
|
|
} |
|
|
} |
|
@@ -294,7 +296,8 @@ namespace BPASmartClient.DosingSystem.ViewModel |
|
|
Thread.Sleep(100); |
|
|
Thread.Sleep(100); |
|
|
}), "启动配方下发", true); |
|
|
}), "启动配方下发", true); |
|
|
} |
|
|
} |
|
|
int ComCount = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
/// <summary> |
|
|
/// 配方执行状态监听 |
|
|
/// 配方执行状态监听 |
|
|
/// </summary> |
|
|
/// </summary> |
|
@@ -727,7 +730,7 @@ namespace BPASmartClient.DosingSystem.ViewModel |
|
|
//设备状态显示 |
|
|
//设备状态显示 |
|
|
if (Recipes.ElementAt(i).RecipeName == CurrentRecipeName) |
|
|
if (Recipes.ElementAt(i).RecipeName == CurrentRecipeName) |
|
|
{ |
|
|
{ |
|
|
string tempRawMaterialName = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).DeviceName; |
|
|
|
|
|
|
|
|
string tempRawMaterialName = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).DeviceName; |
|
|
int recIndex = recipeProcesses.ToList().FindIndex(p => p.RecipeName == CurrentRecipeName); |
|
|
int recIndex = recipeProcesses.ToList().FindIndex(p => p.RecipeName == CurrentRecipeName); |
|
|
if (recIndex >= 0 && recIndex < recipeProcesses.Count) |
|
|
if (recIndex >= 0 && recIndex < recipeProcesses.Count) |
|
|
{ |
|
|
{ |
|
@@ -735,9 +738,12 @@ namespace BPASmartClient.DosingSystem.ViewModel |
|
|
|
|
|
|
|
|
if (index >= 0 && index < recipeProcesses.ElementAt(recIndex).RawMaterials.Count) |
|
|
if (index >= 0 && index < recipeProcesses.ElementAt(recIndex).RawMaterials.Count) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
//测试使用 |
|
|
//测试使用 |
|
|
recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; |
|
|
recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++) |
|
|
for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++) |
|
|
{ |
|
|
{ |
|
@@ -778,13 +784,12 @@ namespace BPASmartClient.DosingSystem.ViewModel |
|
|
if (DeviceNum > 0) |
|
|
if (DeviceNum > 0) |
|
|
{ |
|
|
{ |
|
|
float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialWeight; |
|
|
float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialWeight; |
|
|
//测试 |
|
|
|
|
|
// int loc1 = Array.FindIndex(recipeProcesses.ElementAt(recIndex).RawMaterials.ToArray(),p=>p.RawMaterialName==RawName&&p.RecipeStatus==1); |
|
|
|
|
|
|
|
|
|
|
|
int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => (p.RawMaterialName == RawName)); |
|
|
int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => (p.RawMaterialName == RawName)); |
|
|
if (loc >= 0 && RawName != null && weight >= 0) |
|
|
if (loc >= 0 && RawName != null && weight >= 0) |
|
|
{ |
|
|
{ |
|
|
int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); |
|
|
int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); |
|
|
// int materialCount = recipeProcesses.ElementAt(recIndex).RawMaterials.Where(p => p.RawMaterialName == RawName).Count(); |
|
|
|
|
|
|
|
|
// int materialCount = recipeProcesses.ElementAt(recIndex).RawMaterials.Where(p => p.RawMaterialName == RawName).Count(); |
|
|
if (St_index < 0) //|| (StockStatus.Count < materialCount && St_index > 0) |
|
|
if (St_index < 0) //|| (StockStatus.Count < materialCount && St_index > 0) |
|
|
{ |
|
|
{ |
|
|
StockStatus.Add(new StockStatusModel() |
|
|
StockStatus.Add(new StockStatusModel() |
|
@@ -794,16 +799,17 @@ namespace BPASmartClient.DosingSystem.ViewModel |
|
|
IssueStatus = 0, |
|
|
IssueStatus = 0, |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName );//&& p.IssueStatus == 0) |
|
|
|
|
|
|
|
|
St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName);//&& p.IssueStatus == 0) |
|
|
|
|
|
|
|
|
// int St_index1 = Array.FindIndex(StockStatus.ToArray(), p => (p.MaterialName == RawName && p.IssueStatus == 1)); |
|
|
// int St_index1 = Array.FindIndex(StockStatus.ToArray(), p => (p.MaterialName == RawName && p.IssueStatus == 1)); |
|
|
if (St_index >= 0) |
|
|
if (St_index >= 0) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
if (RTrig.GetInstance($"ac{j}-{St_index}").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) |
|
|
if (RTrig.GetInstance($"ac{j}-{St_index}").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) |
|
|
{ |
|
|
{ |
|
|
MessageNotify.GetInstance.ShowRunLog($"{St_index}-{j}--》允许配料"); |
|
|
MessageNotify.GetInstance.ShowRunLog($"{St_index}-{j}--》允许配料"); |
|
|
if (StockStatus.ElementAt(St_index).IssueStatus == 2) |
|
|
if (StockStatus.ElementAt(St_index).IssueStatus == 2) |
|
|
{ |
|
|
|
|
|
|
|
|
{ |
|
|
StockStatus.ElementAt(St_index).IssueStatus = 0; |
|
|
StockStatus.ElementAt(St_index).IssueStatus = 0; |
|
|
MessageNotify.GetInstance.ShowRunLog($"{St_index}-复位"); |
|
|
MessageNotify.GetInstance.ShowRunLog($"{St_index}-复位"); |
|
|
} |
|
|
} |
|
@@ -811,36 +817,51 @@ namespace BPASmartClient.DosingSystem.ViewModel |
|
|
var rrr = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).deviceStatus.RunStatus; |
|
|
var rrr = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).deviceStatus.RunStatus; |
|
|
if ((recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0))// |
|
|
if ((recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0))// |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
StockStatus.ElementAt(St_index).IssueStatus = 1; |
|
|
StockStatus.ElementAt(St_index).IssueStatus = 1; |
|
|
DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); |
|
|
DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); |
|
|
|
|
|
|
|
|
|
|
|
var res = recipeProcesses.ElementAt(recIndex).RawMaterials.FirstOrDefault(p => p.Status !=Status.正在配料 &&p.Status!=Status.配料完成&& p.RawMaterialName == tempRawMaterialName && p.Loc == j + 1); |
|
|
|
|
|
if (res != null) |
|
|
|
|
|
res.Status = Status.正在配料; |
|
|
|
|
|
|
|
|
MessageNotify.GetInstance.ShowRunLog($"设备执行状态:{rrr}"); |
|
|
MessageNotify.GetInstance.ShowRunLog($"设备执行状态:{rrr}"); |
|
|
MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); |
|
|
MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); |
|
|
} |
|
|
} |
|
|
if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) |
|
|
if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) |
|
|
{ |
|
|
{ |
|
|
//GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 |
|
|
//GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ComCount++; |
|
|
ComCount++; |
|
|
StockStatus.ElementAt(St_index).IssueStatus = 2; |
|
|
StockStatus.ElementAt(St_index).IssueStatus = 2; |
|
|
DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); |
|
|
DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); |
|
|
//int a = 0.SetBitValue((byte)(DeviceNum), true); |
|
|
//int a = 0.SetBitValue((byte)(DeviceNum), true); |
|
|
//byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); |
|
|
//byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); |
|
|
//int item = test1.ToInt(); |
|
|
//int item = test1.ToInt(); |
|
|
//prop1: |
|
|
|
|
|
// SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); |
|
|
|
|
|
SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{DeviceNum - 1}", true).OnSuccess(() => |
|
|
|
|
|
|
|
|
//prop1: |
|
|
|
|
|
// SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); |
|
|
|
|
|
SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{DeviceNum - 1}", true); |
|
|
|
|
|
Task.Run(() => |
|
|
{ |
|
|
{ |
|
|
MessageNotify.GetInstance.ShowRunLog($"设备完成信号写入成功!DB4.DBX130.{{DeviceNum - 1}}:true\""); |
|
|
|
|
|
}).OnFail(s => |
|
|
|
|
|
{ |
|
|
|
|
|
MessageNotify.GetInstance.ShowRunLog($"设备完成信号写入失败!{s}"); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
int cout = DeviceNum - 1; |
|
|
|
|
|
while (!SiemensDevice.GetInstance.MySiemens.Read<bool>($"DB3.DBX148.{cout}").Content) //DB3.DBX148.0-31 148.0-148.5代表6个料仓位置 |
|
|
|
|
|
{ |
|
|
|
|
|
SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", true); |
|
|
|
|
|
Thread.Sleep(200); |
|
|
|
|
|
} |
|
|
|
|
|
while (SiemensDevice.GetInstance.MySiemens.Read<bool>($"DB3.DBX148.{cout}").Content) |
|
|
|
|
|
{ |
|
|
|
|
|
SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", false); |
|
|
|
|
|
} |
|
|
|
|
|
MessageNotify.GetInstance.ShowRunLog($"{cout}号气缸复位信号写入成功!"); |
|
|
|
|
|
}); |
|
|
|
|
|
var res = recipeProcesses.ElementAt(recIndex).RawMaterials.FirstOrDefault(p => p.Status != Status.配料完成 && p.RawMaterialName == tempRawMaterialName && p.Loc == j + 1); |
|
|
|
|
|
if (res != null) |
|
|
|
|
|
res.Status = Status.配料完成; |
|
|
//var values = SiemensDevice.GetInstance.MySiemens.Read<int>("DB4.DBD130").Content; |
|
|
//var values = SiemensDevice.GetInstance.MySiemens.Read<int>("DB4.DBD130").Content; |
|
|
//if ((values != null && values.ToString() != item.ToString()) || values == null) |
|
|
//if ((values != null && values.ToString() != item.ToString()) || values == null) |
|
|
// goto prop1; |
|
|
// goto prop1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", true).OnSuccess(() => |
|
|
//SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", true).OnSuccess(() => |
|
|
//{ |
|
|
//{ |
|
|
// MessageNotify.GetInstance.ShowRunLog($"设备完成信号写入成功!"); |
|
|
// MessageNotify.GetInstance.ShowRunLog($"设备完成信号写入成功!"); |
|
@@ -848,11 +869,10 @@ namespace BPASmartClient.DosingSystem.ViewModel |
|
|
//{ |
|
|
//{ |
|
|
// MessageNotify.GetInstance.ShowRunLog($"设备完成信号写入失败!{s}"); |
|
|
// MessageNotify.GetInstance.ShowRunLog($"设备完成信号写入失败!{s}"); |
|
|
//}); |
|
|
//}); |
|
|
//MessageNotify.GetInstance.ShowRunLog($"{res}"); |
|
|
|
|
|
|
|
|
|
|
|
MessageNotify.GetInstance.ShowRunLog($"设备完成执行状态:{rrr}"); |
|
|
MessageNotify.GetInstance.ShowRunLog($"设备完成执行状态:{rrr}"); |
|
|
MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}"); |
|
|
|
|
|
MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); |
|
|
MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//测试 |
|
|
//测试 |
|
@@ -972,7 +992,7 @@ namespace BPASmartClient.DosingSystem.ViewModel |
|
|
// }); |
|
|
// }); |
|
|
// } |
|
|
// } |
|
|
// St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); |
|
|
// St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (St_index >= 0) |
|
|
// if (St_index >= 0) |
|
|
// { |
|
|
// { |
|
|
// if (RTrig.GetInstance($"ac{j}").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) |
|
|
// if (RTrig.GetInstance($"ac{j}").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) |
|
@@ -1146,9 +1166,18 @@ namespace BPASmartClient.DosingSystem.ViewModel |
|
|
} |
|
|
} |
|
|
//int Finish_Count = StockStatus.Where(s => s.IssueStatus == 2).Count(); |
|
|
//int Finish_Count = StockStatus.Where(s => s.IssueStatus == 2).Count(); |
|
|
//int Finish_Count = recipeProcesses.ElementAt(recIndex).RawMaterials.Where(p => p.RecipeStatus == 3).Count(); |
|
|
//int Finish_Count = recipeProcesses.ElementAt(recIndex).RawMaterials.Where(p => p.RecipeStatus == 3).Count(); |
|
|
if ( ComCount >= Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count && |
|
|
|
|
|
|
|
|
if (ComCount >= Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count && |
|
|
{ |
|
|
{ |
|
|
|
|
|
int cc = recipeProcesses.ElementAt(recIndex).RawMaterials.OrderBy(p => p.RawMaterialName).Count(); |
|
|
|
|
|
for (int k = 0; k < 32; k++) |
|
|
|
|
|
{ |
|
|
|
|
|
for (int l = 0; l < cc; l++) |
|
|
|
|
|
{ |
|
|
|
|
|
RTrig.GetInstance($"ac{k}-{l}").Start(false); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
ComCount = 0; |
|
|
ComCount = 0; |
|
|
|
|
|
|
|
|
StockStatus.Clear(); |
|
|
StockStatus.Clear(); |
|
|
MessageNotify.GetInstance.ShowUserLog($"配方:{recipeProcesses.ElementAt(recIndex).RecipeName},配料完成"); |
|
|
MessageNotify.GetInstance.ShowUserLog($"配方:{recipeProcesses.ElementAt(recIndex).RecipeName},配料完成"); |
|
|
foreach (var item in recipeProcesses.ElementAt(recIndex).RawMaterials) |
|
|
foreach (var item in recipeProcesses.ElementAt(recIndex).RawMaterials) |
|
|