Преглед изворни кода

上传

一拖四味魔方配料系统
lyw пре 8 месеци
родитељ
комит
7780f1bc56
5 измењених фајлова са 389 додато и 192 уклоњено
  1. +355
    -180
      DosingSystem/ExcuteControl .cs
  2. +2
    -0
      DosingSystem/Model/DeviceAddress.cs
  3. +27
    -4
      DosingSystem/Model/DeviceInquire.cs
  4. +2
    -6
      DosingSystem/Model/RawMaterialDeviceStatus.cs
  5. +3
    -2
      DosingSystem/ViewModel/MaterialDosageViewModel.cs

+ 355
- 180
DosingSystem/ExcuteControl .cs Прегледај датотеку

@@ -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 (finish_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(() =>


+ 2
- 0
DosingSystem/Model/DeviceAddress.cs Прегледај датотеку

@@ -9,6 +9,8 @@ namespace BPASmartClient.DosingSystem
/// </summary>
public static string DeviceName { get; set; } = "LW0";

public static string Finish_Point { get; set; } = "LW49";

public static string WorkModel { get; set; } = "LW50";
/// <summary>
/// 料仓重量反馈起始地址


+ 27
- 4
DosingSystem/Model/DeviceInquire.cs Прегледај датотеку

@@ -410,7 +410,9 @@ namespace BPASmartClient.DosingSystem
/// </summary>
public class DeviceStatus
{

public int recipeCount { get; set; }
public int mrCount { get; set; }
//public Action<int,int> startAction { get; set; }
#region 对象属性声明
public string DeviceName = String.Empty;
public string IpAddress => modbusTcp.GetConfigPar().IpAddress;
@@ -423,6 +425,13 @@ namespace BPASmartClient.DosingSystem
public ModbusTcp modbusTcp = new ModbusTcp();

public bool IsConnected => modbusTcp.IsConnected();

public void UpdateState(ObservableCollection<RecipeModel> recipeProcesses, int recipecount,Action<int> indexA) {

int re = recipeProcesses.ElementAt(recipecount).RawMaterials.ToList().FindIndex(a => a.RawMaterialName == DeviceName && a.Loc == deviceStatus.PassPail && a.RecipeStatus == 1);
modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 0);
indexA?.Invoke(re);
}
#endregion

public void Init(string DeviceName)
@@ -442,6 +451,10 @@ namespace BPASmartClient.DosingSystem
//获取设备运行状态
var rs = this.modbusTcp.Read<ushort>(DeviceAddress.RunStatus.ToAdd(), 1, BPA.Helper.DataFormat.CDAB);
if (rs.IsSuccess) deviceStatus.RunStatus = rs.Content;
if (deviceStatus.RunStatus ==2&& recipeCount>=0&& mrCount>=0)
{
//startAction?.Invoke(recipeCount, mrCount);
}

////获取设备料仓剩余重量
var wf = this.modbusTcp.Read<uint>(DeviceAddress.WeightFeedback.ToAdd(), 1, BPA.Helper.DataFormat.CDAB);
@@ -464,11 +477,10 @@ namespace BPASmartClient.DosingSystem
deviceStatus.RecipeFinish = SimensSend.GetInstance.SendSimens.Read<bool>($"DB1.DBX70{(int)((dnum.Content - 1) / 8)}.{(dnum.Content - 1) % 8}").Content;
}
}

////获取设备故障编码
var dac = this.modbusTcp.Read<ushort>(DeviceAddress.DeviceAlarmCode.ToAdd(), 1, BPA.Helper.DataFormat.CDAB);
if (dac.IsSuccess) deviceStatus.DeviceAlarmCode = dac.Content;
deviceStatus.StartSend = SimensSend.GetInstance.SendSimens.Read<bool>($"M11.5").Content;
//获取原料类型
var mt = this.modbusTcp.Read<ushort>(DeviceAddress.MaterialDeviceType.ToAdd(), 1, BPA.Helper.DataFormat.CDAB);
if (mt.IsSuccess) deviceStatus.RawMaterialType = mt.Content;
@@ -476,7 +488,6 @@ namespace BPASmartClient.DosingSystem
//获取工作模式
var wm = this.modbusTcp.Read<ushort>(DeviceAddress.WorkModel.ToAdd(),1, BPA.Helper.DataFormat.CDAB);
if (wm.IsSuccess) {
deviceStatus.WorkModel = wm.Content.GetBitValue(1);
deviceStatus.Finish_mt = wm.Content.GetBitValue(6);
}
/* //慢加重量
@@ -558,6 +569,18 @@ namespace BPASmartClient.DosingSystem
TaskManage.GetInstance.StopTask($"{DeviceName} 开始监听");
}



public void StartWeight(float Value) {
if (modbusTcp.IsConnected())
{
modbusTcp.Write<float>(DeviceAddress.WeightSet.ToAdd(), Value);
modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 1);

}
}


public void Start(float Value)
{
if (modbusTcp.IsConnected())


+ 2
- 6
DosingSystem/Model/RawMaterialDeviceStatus.cs Прегледај датотеку

@@ -119,13 +119,9 @@ namespace BPASmartClient.DosingSystem
/// </summary>
public int RecipePail { get;set; }
/// <summary>
/// 进桶总数
/// 配料完成复位监测
/// </summary>
public int InPailAll { get; set; }
/// <summary>
/// 出桶总数
/// </summary>
public int OutPailAll { get; set; }
public bool StartSend { get; set; }
/// <summary>
/// 配料完成,传送带运行
/// </summary>


+ 3
- 2
DosingSystem/ViewModel/MaterialDosageViewModel.cs Прегледај датотеку

@@ -16,10 +16,11 @@ namespace BPASmartClient.DosingSystem.ViewModel
{
public class MaterialDosageViewModel:NotifyBase
{
public MaterialDosageViewModel()
{

InRecipe = SimensSend.GetInstance.SendSimens.Read<int>($"DB1.DBW1000").Content;
OutRecipe = SimensSend.GetInstance.SendSimens.Read<int>($"DB1.DBW1002").Content;
App.Current.Dispatcher.Invoke(() =>
{
ProcessesAllweight.Clear();


Loading…
Откажи
Сачувај