@@ -409,7 +409,6 @@ namespace BPASmartClient.DosingSystem
});
}
App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方下发成功!"); });
}
@@ -584,7 +583,9 @@ namespace BPASmartClient.DosingSystem
}
bool allowStart=false;
public ConcurrentDictionary<string, bool> finish_weight = new ConcurrentDictionary<string, bool>();
public ConcurrentDictionary<string, bool> start_Stop = new ConcurrentDictionary<string, bool>();
private void MatchRun()
{
@@ -620,6 +621,7 @@ namespace BPASmartClient.DosingSystem
List<int> device_Loc = new List<int>();//下发桶号
int recipeNameNum = doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress];
var dnum = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DeviceNum;
int passPail = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail;
if (recipeNameNum == 0)
{
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum));
@@ -636,7 +638,7 @@ namespace BPASmartClient.DosingSystem
device_Loc.Add(rawMaterial.Loc);
}
}
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].I pAddress].deviceStatus.P assPail == 0)
if (passPail == 0)
{
doDeviceCount.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, recipeNameNum + 1, doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress]);
foreach (var down_Loc in device_Loc)
@@ -676,6 +678,7 @@ namespace BPASmartClient.DosingSystem
}
}
}
if (recipeNameNum > 0 && recipeNameNum <= RecipeNames.Count)
{
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
@@ -689,14 +692,14 @@ namespace BPASmartClient.DosingSystem
}
}
if (dnum == 18 && maxPail <= DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].I pAddress].deviceStatus.P assPail)
if (dnum == 18 && maxPail <= passPail)
{
App.Current.Dispatcher.Invoke(() =>
{
RecipeModel recipe = recipeProcesses?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
if (recipe != null && recipe.RecipStatus != "制作完成" )
if (recipe != null)
{
int res = recipe.RawMaterials.ToList().FindIndex(a => a.RecipeStatus !=3);
if (res < 0 )
@@ -711,26 +714,27 @@ namespace BPASmartClient.DosingSystem
ActionManage.GetInstance.Send("配料完成", UserTreeCompelete);
ActionManage.GetInstance.Send("历史记录", Json<OldRecipe>.Data.Recipes);
}
/*Json<OnRecipe>.Data.Recipes.RemoveAt(recipeProcesses.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum)));
Json<OnRecipe>.Save();*/
}
});
}
int recipecount = recipeProcesses.Count - (recipeNameNum - UserTreeCompelete.Count);
int re = -1;
if (recipecount < recipeProcesses.Count && recipecount >= 0)
{
re = recipeProcesses.ElementAt(recipecount).RawMaterials.ToList().FindIndex(a => a.RawMaterialName == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].DeviceName && a.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail && a.RecipeStatus != 3);
}
if (maxPail <= DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].I pAddress].deviceStatus.P assPail && recipeNameNum < RecipeNames.Count && !DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive&& re<0)
if (maxPail <= passPail && recipeNameNum < RecipeNames.Count && !DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive&&re<0)
{
SimensSend.GetInstance.SendSimens.Write<ushort>($"DB1.DBW{810 + 2 * (dnum - 1)}", 0);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配方{RecipeNames.ElementAt(recipeNameNum - 1)},桶数已清零");
while (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail!=0)
{
SimensSend.GetInstance.SendSimens.Write<ushort>($"DB1.DBW{810 + 2 * (dnum - 1)}", 0);
}
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}桶数已清零");
doDeviceCount.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, recipeNameNum + 1, doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress]);
recipeNameNum = doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress];
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
@@ -738,10 +742,6 @@ namespace BPASmartClient.DosingSystem
{
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
{
if (rawMaterial.Loc > maxPail)
{
maxPail = rawMaterial.Loc;
}
if (rawMaterial.DeviceIp == DeviceInquire.GetInstance.devices[i].IpAddress)
{
device_Loc.Add(rawMaterial.Loc);
@@ -815,10 +815,9 @@ namespace BPASmartClient.DosingSystem
while (!DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 1).IsSuccess)
{
MessageNotify.GetInstance.ShowRunLog($"设备{s}下发开始信号失败");
stop = false ;
start_Stop.TryUpdate(s,false,true) ;
}
stop = true;
MessageNotify.GetInstance.ShowRunLog($"允许下发复位信号");
start_Stop.TryUpdate(s, true, false);
}
});
@@ -829,16 +828,66 @@ namespace BPASmartClient.DosingSystem
{
for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
{
string ip = DeviceInquire.GetInstance.devices[i].IpAddress;
if (!start_Stop.ContainsKey(ip))
{
start_Stop.TryAdd(ip,false);
}
int dnum = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.DeviceNum;
int passPail = -1;
string nextIp = "";
if (dnum < 18)
{
nextIp = $"192.168.2.{(dnum + 1) * 10}";
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(nextIp))
{
passPail = DeviceInquire.GetInstance.DeviceLists[nextIp].deviceStatus.PassPail;
}
}
else
{
passPail = 0;
}
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(ip) &&doDeviceCount.ContainsKey(ip))
{
int dnum = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.DeviceNum;
int count = doDeviceCount[ip];
int recipeNameNum = doDeviceCount[ip];
if (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PailArrive)
{
if (recipeNameNum >= 0)
{
int doCount = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
if (doCount >= 0)
{
int finish = UserTreeCompelete.Count;
int re = 0;
int recipecount = recipeProcesses.Count - (recipeNameNum - finish);
if (recipecount < recipeProcesses.Count && recipecount >= 0)
{
re = recipeProcesses.ElementAt(recipecount).RawMaterials.ToList().FindIndex(a => a.RawMaterialName == DeviceInquire.GetInstance.DeviceLists[ip].DeviceName && a.Loc == DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PassPail && a.RecipeStatus == 1);
if (re >= 0)
{
MessageNotify.GetInstance.ShowRunLog($"当前设备{dnum}执行位配方数{doCount},开始下{recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).RawMaterialWeight}g料");
Raction?.Invoke(ip, recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).RawMaterialWeight);
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).RecipeStatus = 2;
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).Status = (Status)1;
}
}
}
}
}
if (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PassPail != 0&& DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt&&!DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PailArrive)
{
}
if (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt)
if (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt&& passPail==0 )
{
int recipecount = recipeProcesses.Count - (count - UserTreeCompelete.Count);
int recipecount = recipeProcesses.Count - (recipeNameNum - UserTreeCompelete.Count);
if (recipecount < recipeProcesses.Count && recipecount >= 0)
{
int re_1 = recipeProcesses.ElementAt(recipecount).RawMaterials.ToList().FindIndex(a => a.RawMaterialName == DeviceInquire.GetInstance.DeviceLists[ip].DeviceName && a.Loc == DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PassPail && a.RecipeStatus == 2);
@@ -859,39 +908,41 @@ namespace BPASmartClient.DosingSystem
}
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).RecipeStatus = 3;
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).Status = (Status)2;
while (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt)
Json<OnRecipe>.Data.Recipes = recipeProcesses;
Json<OnRecipe>.Save();
while(DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt)
{
DeviceInquire.GetInstance.DeviceLists[ip].modbusTcp.Write<ushort>(DeviceAddress.WorkModel.ToAdd(), 0);
Thread.Sleep(10);
}
while (!DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.RecipeFinish)
{
SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX70{(int)((dnum - 1) / 8)}.{(dnum - 1) % 8}", true);
Thread.Sleep(10);
}
Json<OnRecipe>.Data.Recipes = recipeProcesses;
Json<OnRecipe>.Save();
ActionManage.GetInstance.Send("正在配料", recipeProcesses);
MessageNotify.GetInstance.ShowRunLog($"设备{ip}已下料{recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).TotalWeight}g");
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发完成信号");
while (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.RecipeFinish)
{
SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX70{(int)((dnum - 1) / 8)}.{(dnum - 1) % 8}", false);
Thread.Sleep(10);
}
/*finish_weight.TryUpdate(ip, true, false);*/
}
}
}
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 2 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3 )
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus != 1 && start_Stop[ip] )
{
if (stop )
while (!DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 0).IsSuccess )
{
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发开始配料复位信号");
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 0);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发开始配料复位信号失败");
}
start_Stop.TryUpdate(ip, false, true);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发开始配料复位信号");
}
}
}