@@ -381,10 +381,7 @@ namespace BPASmartClient.DosingSystem
MessageNotify.GetInstance.ShowUserLog($"下发工单 {Recipes.ElementAt(index).RecipeName}");
RecipeNames.Enqueue(RecipeName);
var res = Recipes.FirstOrDefault(p => p.RecipeName == RecipeName);
foreach (var item in res.RawMaterials)
{
}
App.Current.Dispatcher.Invoke(() =>
{
var raw = new ObservableCollection<RawMaterialModel>();
@@ -400,6 +397,7 @@ namespace BPASmartClient.DosingSystem
RawMaterialWeight = X.RawMaterialWeight,
RecipeStatus = 1,
TotalWeight = X.TotalWeight,
Status = 0
});
@@ -584,8 +582,8 @@ namespace BPASmartClient.DosingSystem
bool allowStart=false;
public ConcurrentDictionary<string, bool> start_Stop = new ConcurrentDictionary<string, bool>();
bool start_Send = false;
int pas = 2;
private void MatchRun()
{
@@ -611,182 +609,340 @@ namespace BPASmartClient.DosingSystem
//判断IP是否在列表中
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
//只有设备在等待配料状态才能下发数据
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1 )
string ip = DeviceInquire.GetInstance.devices[i].IpAddress;
if (doDeviceCount.ContainsKey(ip) )
{
if (doDeviceCount.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
int index = 0;//配方索引
int maxPail = 0;//最大桶数
List<int> device_Loc = new List<int>();//下发桶号
int recipeNameNum = doDeviceCount[ip];//配方数量
var dnum = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.DeviceNum;//设备编号
int passPail = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PassPail;//当前通过桶数
int passPail_1 = -1;//下一料仓桶数
string nextIp = "";
if (dnum < 18)
{
int index = 0;//配方索引
int maxPail = 0;//最大桶数
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)
nextIp = $"192.168.2.{(dnum + 1) * 10}";
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(nextIp))
{
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum));
if (index >= 0 && dnum > 0)
passPail_1 = DeviceInquire.GetInstance.DeviceLists[nextIp].deviceStatus.PassPail;
}
}
else
{
passPail_1 = passPail - 1;
}
if (recipeNameNum == 0)
{
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum));
if (index >= 0 && dnum > 0)
{
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
{
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
if (rawMaterial.Loc > maxPail )
{
if (rawMaterial.Loc > maxPail)
{
maxPail = rawMaterial.Loc;
}
if (rawMaterial.DeviceIp == DeviceInquire.GetInstance.devices[i].IpAddress)
{
device_Loc.Add(rawMaterial.Loc);
}
maxPail = rawMaterial.Loc;
}
if (passPail == 0 )
if (rawMaterial.DeviceIp == DeviceInquire.GetInstance.devices[i].IpAddress)
{
doDeviceCount.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, recipeNameNum + 1, doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress]);
foreach (var down_Loc in device_Loc)
device_Loc.Add(rawMaterial.Loc);
}
}
if (passPail == 0)
{
doDeviceCount.TryUpdate(ip, recipeNameNum + 1, doDeviceCount[ip]);
foreach (var down_Loc in device_Loc)
{
while (!SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX{710 + 4 * (dnum - 1) + (int)((down_Loc - 1) / 8)}.{(down_Loc - 1) % 8}", true).IsSuccess)
{
while (!SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX{710 + 4 * (dnum - 1) + (int)((down_Loc - 1) / 8)}.{(down_Loc - 1) % 8}", true).IsSuccess)
{
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配方第{down_Loc}桶下发失败");
}
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配方第{down_Loc}桶下发失败");
}
SimensSend.GetInstance.SendSimens.Write<ushort>($"DB1.DBW{106 + 2 * (dnum - 1)}", 500);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配方{RecipeNames.ElementAt(recipeNameNum)}");
if (dnum == 1)
}
SimensSend.GetInstance.SendSimens.Write<ushort>($"DB1.DBW{106 + 2 * (dnum - 1)}", 500);//电机速度
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配方{RecipeNames.ElementAt(recipeNameNum)}");
if (dnum == 1)
{
App.Current.Dispatcher.Invoke(() =>
{
App.Current.Dispatcher.Invoke(() =>
if (recipeNameNum >= 0 && recipeNameNum < RecipeNames.Count)
{
if (recipeNameNum >= 0 && recipeNameNum < RecipeNames.Count)
RecipeModel recipe = UserTreeWait.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum));
if (recipe != null)
{
RecipeModel recipe = UserTreeWait.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum));
if (recipe != null)
recipe.RecipStatus = "正在配料";
recipeProcesses.Insert(0, recipe);
ActionManage.GetInstance.Send("正在配料", recipeProcesses);
/*Json<OnRecipe>.Data.Recipes.Insert(0, recipe);
Json<OnRecipe>.Save();*/
int removeObj = UserTreeWait.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum));
if (removeObj >= 0 && removeObj < UserTreeWait.Count())
{
recipe.RecipStatus = "正在配料";
recipeProcesses.Insert(0, recipe);
ActionManage.GetInstance.Send("正在配料", recipeProcesses);
/*Json<OnRecipe>.Data.Recipes.Insert(0, recipe);
Json<OnRecipe>.Save();*/
int removeObj = UserTreeWait.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum));
if (removeObj >= 0 && removeObj < UserTreeWait.Count())
{
UserTreeWait.RemoveAt(removeObj);
}
UserTreeWait.RemoveAt(removeObj);
}
while (!DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.StartSend)
{
SimensSend.GetInstance.SendSimens.Write<bool>("M11.5", true);
}
start_Send = true;
}
}
});
}
});
}
}
}
if (recipeNameNum > 0 && recipeNameNum <= RecipeNames.Count)
}
if (recipeNameNum > 0 && recipeNameNum <= RecipeNames.Count)
{
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
if (index >= 0 && dnum > 0)
{
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
if (index >= 0 && dnum > 0)
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
{
if (rawMaterial.Loc > maxPail)
{
maxPail = rawMaterial.Loc;
}
}
if (dnum == 18 && maxPail <= passPail)
{
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
App.Current.Dispatcher.Invoke(() =>
{
if (rawMaterial.Loc > maxPail)
RecipeModel recipe = recipeProcesses?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
if (recipe != null)
{
maxPail = rawMaterial.Loc;
int res = recipe.RawMaterials.ToList().FindIndex(a => a.RecipeStatus != 3);
if (res < 0)
{
recipe.RecipStatus = "制作完成";
UserTreeCompelete.Insert(0, recipe);
recipeProcesses.RemoveAt(recipeProcesses.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1)));
Json<OnRecipe>.Data.Recipes = recipeProcesses;
Json<OnRecipe>.Save();
Json<OldRecipe>.Data.Recipes.Insert(0, recipe);
Json<OldRecipe>.Save();
ActionManage.GetInstance.Send("配料完成", UserTreeCompelete);
ActionManage.GetInstance.Send("历史记录", Json<OldRecipe>.Data.Recipes);
}
}
}
});
}
if (dnum == 18 && maxPail <= passPail)
int recipecount = recipeProcesses.Count - (recipeNameNum - UserTreeCompelete.Count);
int re =0;
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 != 3);
}
if (maxPail <= passPail && recipeNameNum < RecipeNames.Count && !DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PailArrive&&re<0)
{
int pPail = 1;
while (pPail != 0)
{
SimensSend.GetInstance.SendSimens.Write<ushort>($"DB1.DBW{810 + 2 * (dnum - 1)}", 0);
Thread.Sleep(10);
pPail = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PassPail;
}
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}桶数已清零");
doDeviceCount.TryUpdate(ip, recipeNameNum + 1, doDeviceCount[ip]);
recipeNameNum = doDeviceCount[ip];
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
if (index >= 0)
{
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
{
if (rawMaterial.DeviceIp == DeviceInquire.GetInstance.devices[i].IpAddress)
{
device_Loc.Add(rawMaterial.Loc);
}
}
}
foreach (var down_Loc in device_Loc)
{
while (!SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX{710 + 4 * (dnum - 1) + (int)((down_Loc - 1) / 8)}.{(down_Loc - 1) % 8}", true).IsSuccess)
{
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配方第{down_Loc}桶下发失败");
}
}
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配方桶下发成功");
SimensSend.GetInstance.SendSimens.Write<ushort>($"DB1.DBW{106 + 2 * (dnum - 1)}", 500);
if (dnum == 1)
{
App.Current.Dispatcher.Invoke(() =>
{
RecipeModel recipe = recipeProcesses?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
RecipeModel recipe = UserTreeWait?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
if (recipe != null)
{
int res = recipe.RawMaterials.ToList().FindIndex(a => a.RecipeStatus !=3);
if (res < 0 )
recipe.RecipStatus = "正在配料";
recipeProcesses.Insert(0, recipe);
ActionManage.GetInstance.Send("正在配料", recipeProcesses);
/* Json<OnRecipe>.Data.Recipes.Insert(0, recipe);
Json<OnRecipe>.Save();*/
UserTreeWait.RemoveAt(UserTreeWait.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1)));
while (!DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.StartSend)
{
recipe.RecipStatus = "制作完成";
UserTreeCompelete.Insert(0, recipe);
recipeProcesses.RemoveAt(recipeProcesses.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1)));
Json<OnRecipe>.Data.Recipes = recipeProcesses;
Json<OnRecipe>.Save();
Json<OldRecipe>.Data.Recipes.Insert(0, recipe);
Json<OldRecipe>.Save();
ActionManage.GetInstance.Send("配料完成", UserTreeCompelete);
ActionManage.GetInstance.Send("历史记录", Json<OldRecipe>.Data.Recipes);
SimensSend.GetInstance.SendSimens.Write<bool>("M11.5", true);
}
start_Send = true;
}
});
}
int recipecount = recipeProcesses.Count - (recipeNameNum - UserTreeCompelete.Count);
int re = -1;
}
}
}
if (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PailArrive)
{
if (recipeNameNum > 0)
{
int recipecount = recipeProcesses.Count - (recipeNameNum - UserTreeCompelete.Count);
#region 下料
int doCount = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
if (doCount >= 0)
{
int finish = UserTreeCompelete.Count;
int re = 0;
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);
}
DeviceInquire.GetInstance.DeviceLists[ip].UpdateState(recipeProcesses, recipecount, (s) => {
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(s).RecipeStatus = 2;
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(s).Status = (Status)1;
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}确认状态:正在配料,物料状态:{recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(s).Status}");
if (maxPail <= passPail && recipeNameNum < RecipeNames.Count && !DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive&&re<0)
{
});
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));
if (index >= 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);
//DeviceInquire.GetInstance.DeviceLists[ip].startAction = ((s,t) =>
//{
// DeviceInquire.GetInstance.DeviceLists[ip].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 0);
// recipeProcesses.ElementAt(s).RawMaterials.ElementAt(t).RecipeStatus = 2;
// recipeProcesses.ElementAt(s).RawMaterials.ElementAt(t).Status = (Status)1;
// MessageNotify.GetInstance.ShowRunLog($"设备{dnum}确认状态:正在配料,物料状态:{recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).Status}");
//});
if (re >= 0)
{
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
MessageNotify.GetInstance.ShowRunLog($"当前设备{dnum}执行:{recipecount},当前配方数:{recipeProcesses.Count},完成配方数{finish},已执行配方数{recipeNameNum}");
MessageNotify.GetInstance.ShowRunLog($"当前设备{dnum},下料重量:{recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).RawMaterialWeight}g");
//DeviceInquire.GetInstance.DeviceLists[ip].modbusTcp.Write<float>(DeviceAddress.WeightSet.ToAdd(), recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).RawMaterialWeight);
//Thread.Sleep(10);
//DeviceInquire.GetInstance.DeviceLists[ip].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 1);
//Thread.Sleep(10);
if (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.RunStatus == 2)
{
if (rawMaterial.DeviceIp == DeviceInquire.GetInstance.devices[i].IpAddress)
{
device_Loc.Add(rawMaterial.Loc);
}
}
}
foreach (var down_Loc in device_Loc)
{
while (!SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX{710 + 4 * (dnum - 1) + (int)((down_Loc - 1) / 8)}.{(down_Loc - 1) % 8}", true).IsSuccess)
Thread.Sleep(200);
bool finish_mt_1 = true;
while (finish_mt_1)
{
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配方第{down_Loc}桶下发失败");
ushort reset = 0;
reset = reset.SetBitValue(1, true);
DeviceInquire.GetInstance.DeviceLists[ip].modbusTcp.Write<ushort>(DeviceAddress.Finish_Point.ToAdd(), reset);
finish_mt_1 = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt;
}
while (!DeviceInquire.GetInstance.DeviceLists[ip].modbusTcp.Write<ushort>(DeviceAddress.Finish_Point.ToAdd(), 0).IsSuccess)
{
Thread.Sleep(10);
}
start_Stop.TryUpdate(ip, true, false);
}
SimensSend.GetInstance.SendSimens.Write<ushort>($"DB1.DBW{106 + 2 * (dnum - 1)}", 500);
if (dnum == 1)
}
}
#endregion
#region 完成计重
bool finish_mt = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt;
bool recipe_fn = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.RecipeFinish;
if (finish_mt && passPail_1 == passPail - 1)
{
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);
if (re_1 >= 0)
{
App.Current.Dispatcher.Invoke(() =>
Thread.Sleep(200);
float xx = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.CutWeightFeedback;
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).TotalWeight = xx;
float t = Math.Abs(recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).TotalWeight - recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).RawMaterialWeight);
if (t > 2)
{
RecipeModel recipe = UserTreeWait?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
if (recipe != null)
SimensSend.GetInstance.SendSimens.Write<bool>("M11.2", true );
while (!MessageNotify.GetInstance.ShowDialog($"设备{dnum}物料下料超出范围报警,请处理后点击确认!", DialogType.Warning) )
{
recipe.RecipStatus = "正在配料";
recipeProcesses.Insert(0, recipe);
ActionManage.GetInstance.Send("正在配料", recipeProcesses);
/* Json<OnRecipe>.Data.Recipes.Insert(0, recipe);
Json<OnRecipe>.Save();*/
UserTreeWait.RemoveAt(UserTreeWait.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1)));
App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"需确认处理后才能继续运行!"); });
}
SimensSend.GetInstance.SendSimens.Write<bool>("M11.2", false);
}
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).RecipeStatus = 3;
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).Status = (Status)2;
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}配料状态:完成配料,物料状态:{recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).Status}");
Json<OnRecipe>.Data.Recipes = recipeProcesses;
Json<OnRecipe>.Save();
while (finish_mt)
{
ushort reset = 0;
reset = reset.SetBitValue(1, true);
DeviceInquire.GetInstance.DeviceLists[ip].modbusTcp.Write<ushort>(DeviceAddress.Finish_Point.ToAdd(), reset);
Thread.Sleep(10);
finish_mt = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt;
}
DeviceInquire.GetInstance.DeviceLists[ip].modbusTcp.Write<ushort>(DeviceAddress.Finish_Point.ToAdd(), 0);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}配料完成已复位");
while (!recipe_fn)
{
SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX70{(int)((dnum - 1) / 8)}.{(dnum - 1) % 8}", true);
Thread.Sleep(10);
recipe_fn = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.RecipeFinish;
}
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}传送带:true");
ActionManage.GetInstance.Send("正在配料", recipeProcesses);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}已下料{recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).TotalWeight}g");
while (recipe_fn)
{
SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX70{(int)((dnum - 1) / 8)}.{(dnum - 1) % 8}", false);
Thread.Sleep(10);
recipe_fn = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.RecipeFinish;
}
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}传送带:false");
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}确认配料完成,输出通过桶数{DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PassPail},输出当前配方数{recipeNameNum},输出总配方数{RecipeNames.Count},输出允许配料状态{DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive}");
});
}
}
}
#endregion
}
}
else
{
doDeviceCount.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, 0);
}
}
else
{
doDeviceCount.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, 0);
}
/*MonitorStatus(DeviceInquire.GetInstance.devices[i].IpAddress);*/
}
@@ -804,32 +960,59 @@ namespace BPASmartClient.DosingSystem
Thread.Sleep(10);
}, "设备下发配方");
MessageNotify.GetInstance.ShowRunLog($"设备下发配方运行");
Raction = ((s, f ) =>
TaskManage.GetInstance.StartLong(( ) =>
{
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(s))
string ip = "192.168.2.10";
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(ip) && doDeviceCount.ContainsKey(ip))
{
while (!DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<float>(DeviceAddress.WeightSet.ToAdd(), f).IsSuccess)
int maxPail = 0;
int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(doDeviceCount[ip] - 1));
if (index >= 0)
{
MessageNotify.GetInstance.ShowRunLog($"设备{s}下发下料重量信号失败");
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
{
if (rawMaterial.Loc > maxPail)
{
maxPail = rawMaterial.Loc;
}
}
}
while (!DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 1).IsSuccess)
int passing = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PassPail;
if (start_Send && passing == 1)
{
MessageNotify.GetInstance.ShowRunLog($"设备{s}下发开始信号失败");
start_Stop.TryUpdate(s,false,true);
while (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.StartSend)
{
SimensSend.GetInstance.SendSimens.Write<bool>("M11.5", false);
}
MessageNotify.GetInstance.ShowRunLog($"状态:配方首桶已到位");
pas = 2;
start_Send = false;
}
start_Stop.TryUpdate(s, true, false);
}
});
if (pas > passing && !DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PailArrive&&pas<=maxPail)
{
while (!DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.StartSend)
{
SimensSend.GetInstance.SendSimens.Write<bool>("M11.5", true);
}
MessageNotify.GetInstance.ShowRunLog($"状态:配方续桶");
}
if (passing == pas && pas <= maxPail)
{
while (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.StartSend)
{
SimensSend.GetInstance.SendSimens.Write<bool>("M11.5", false);
TaskManage.GetInstance.StartLong(() =>
}
MessageNotify.GetInstance.ShowRunLog($"状态:配方停桶");
pas++;
}
}
Thread.Sleep(100);
}, "起始传送带控制");
/*TaskManage.GetInstance.StartLong(() =>
{
for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
{
string ip = DeviceInquire.GetInstance.devices[i].IpAddress;
if (!start_Stop.ContainsKey(ip))
{
@@ -854,40 +1037,15 @@ namespace BPASmartClient.DosingSystem
{
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)
{
bool finish_mt = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt;
bool recipe_fn = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.RecipeFinish;
}
if (DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt&& passPail==0)
if (finish_mt && passPail==0&& DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PailArrive)
{
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);
@@ -906,36 +1064,53 @@ namespace BPASmartClient.DosingSystem
}
SimensSend.GetInstance.SendSimens.Write<bool>("M11.2", false);
}
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).RecipeStatus = 3;
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).Status = (Status)2;
int status = 2;
while (status != 3)
{
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).RecipeStatus = 3;
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).Status = (Status)2;
status = recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).RecipeStatus;
}
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}配料状态:完成配料");
Json<OnRecipe>.Data.Recipes = recipeProcesses;
Json<OnRecipe>.Save();
while(DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt)
while (f inish_mt)
{
DeviceInquire.GetInstance.DeviceLists[ip].modbusTcp.Write<ushort>(DeviceAddress.WorkModel.ToAdd(), 0);
ushort reset = 0;
reset = reset.SetBitValue(1, true);
DeviceInquire.GetInstance.DeviceLists[ip].modbusTcp.Write<ushort>(DeviceAddress.Finish_Point.ToAdd(), reset);
Thread.Sleep(10);
finish_mt = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt;
}
while (!DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.RecipeFinish)
DeviceInquire.GetInstance.DeviceLists[ip].modbusTcp.Write<ushort>(DeviceAddress.Finish_Point.ToAdd(), 0);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}配料完成已复位");
while (!recipe_fn)
{
SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX70{(int)((dnum - 1) / 8)}.{(dnum - 1) % 8}", true);
Thread.Sleep(10);
recipe_fn = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.RecipeFinish;
}
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}传送带置为true");
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 )
while (recipe_fn )
{
SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX70{(int)((dnum - 1) / 8)}.{(dnum - 1) % 8}", false);
Thread.Sleep(10);
recipe_fn = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.RecipeFinish;
}
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}传送带置为false");
/*finish_weight.TryUpdate(ip, true, false);*/
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}确认配料完成,输出通过桶数{DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PassPail},输出当前配方数{recipeNameNum},输出总配方数{RecipeNames.Count},输出允许配料状态{DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive}");
}
}
}
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus != 1 && start_Stop[ip])
{
Thread.Sleep(50);
while (!DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 0).IsSuccess)
{
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发开始配料复位信号失败");
@@ -949,7 +1124,7 @@ namespace BPASmartClient.DosingSystem
Thread.Sleep(10);
}, "下料控制");
MessageNotify.GetInstance.ShowRunLog($"下料控制运行");
MessageNotify.GetInstance.ShowRunLog($"下料控制运行");*/
//弃用
/*TaskManage.GetInstance.StartLong(() =>