@@ -35,6 +35,7 @@ using Microsoft.VisualBasic.Logging;
using Org.BouncyCastle.Asn1.Utilities;
using Google.Protobuf.WellKnownTypes;
using System.Windows;
using System.Windows.Media.Converters;
namespace BPASmartClient.DosingSystem
{
@@ -464,104 +465,99 @@ namespace BPASmartClient.DosingSystem
}
public ConcurrentDictionary<string, bool> rTrig = new ConcurrentDictionary<string, bool>();
public ConcurrentDictionary<string, bool> tTrig = new ConcurrentDictionary<string, bool>();
public ConcurrentDictionary<string, bool> templock = new ConcurrentDictionary<string, bool>();
bool stop = true;
private void MonitorStatus()
private void MonitorStatus(string ip )
{
for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(ip))
{
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
if (!rTrig.ContainsKey(ip))
{
rTrig.TryAdd(ip, false);
}
if (!tTrig.ContainsKey(ip))
{
if (!templock.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
tTrig.TryAdd(ip, false);
}
RTrig.GetInstance(ip).Start(DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.PailArrive);
TTrig.GetInstance(ip).Start(DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.Finish_mt);
if (RTrig.GetInstance(ip).Q)
{
MessageNotify.GetInstance.ShowRunLog($"检测到设备{DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.DeviceNum}上升源");
if (rTrig.ContainsKey(ip))
{
templock.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, false);
rTrig.TryUpdate(ip, true , false);
}
if (!rTrig.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
else
{
rTrig.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, false);
rTrig.TryAdd(ip, tru e);
}
if (!tTrig.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
}
if (TTrig.GetInstance(ip).Q)
{
MessageNotify.GetInstance.ShowRunLog($"检测到设备{DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.DeviceNum}下降源");
if (tTrig.ContainsKey(ip))
{
tTrig.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, false);
tTrig.TryUpdate(ip, true , false);
}
RTrig.GetInstance(DeviceInquire.GetInstance.devices[i].IpAddress).Start(DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive);
TTrig.GetInstance(DeviceInquire.GetInstance.devices[i].IpAddress).Start(DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.Finish_mt);
if (RTrig.GetInstance(DeviceInquire.GetInstance.devices[i].IpAddress).Q)
{
MessageNotify.GetInstance.ShowRunLog($"检测到上升源");
if (rTrig.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
rTrig.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, true, false);
}
else
{
rTrig.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, true);
}
}
if (TTrig.GetInstance(DeviceInquire.GetInstance.devices[i].IpAddress).Q)
else
{
MessageNotify.GetInstance.ShowRunLog($"检测到下降源");
if (tTrig.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
tTrig.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, true, false);
}
else
{
tTrig.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, true);
}
tTrig.TryAdd(ip, true);
}
}
if (rTrig[DeviceInquire.GetInstance.devices[i].IpAddress] || tTrig[DeviceInquire.GetInstance.devices[i].IpAddress])
if (rTrig[ip] || tTrig[ip])
{
int recipeNameNum = doDeviceCount[ip];
int dnum = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.DeviceNum;
if (recipeNameNum >= 0)
{
int recipeNameNum = doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress];
if (recipeNameNum >= 0)
int doCount = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
if (doCount >= 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 re_1 = 0;
int recipecount = recipeProcesses.Count - (recipeNameNum - finish);
if (recipecount < recipeProcesses.Count && recipecount >= 0)
{
int res = Recipes.ElementAt(doCount).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);
if (res >= 0)
{
int finish = UserTreeCompelete.Count;
int re = 0;
int re_1 = 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[DeviceInquire.GetInstance.devices[i].IpAddress].DeviceName && a.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail && a.RecipeStatus == 1);
re_1 = 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 == 2);
if (rTrig[DeviceInquire.GetInstance.devices[i].IpAddress] && re >= 0)
{
MessageNotify.GetInstance.ShowRunLog($"找到配方桶,开始下{Recipes.ElementAt(doCount).RawMaterials.ElementAt(res).RawMaterialWeight}g料");
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).RecipeStatus = 2;
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).Status = (Status)1;
Raction?.Invoke(DeviceInquire.GetInstance.devices[i].IpAddress, Recipes.ElementAt(doCount).RawMaterials.ElementAt(res).RawMaterialWeight);
rTrig.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, false, true);
templock[DeviceInquire.GetInstance.devices[i].IpAddress] = true;
}
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);
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 (tTrig[DeviceInquire.GetInstance.devices[i].IpAddress] && re_1 >= 0 && templock[DeviceInquire.GetInstance.devices[i].IpAddress])
{
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).RecipeStatus = 3;
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).Status = (Status)2;
Recipes.ElementAt(doCount).RawMaterials.ElementAt(res).TotalWeight = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.CutWeightFeedback;
MessageNotify.GetInstance.ShowRunLog($"设备{DeviceInquire.GetInstance.devices[i].IpAddress}已下料{Recipes.ElementAt(doCount).RawMaterials.ElementAt(res).TotalWeight}g");
tTrig.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, false, true);
templock[DeviceInquire.GetInstance.devices[i].IpAddress] = false;
}
}
if (rTrig[ip] && re >= 0)
{
MessageNotify.GetInstance.ShowRunLog($"当前执行位配方数{recipeProcesses.Count},找到配方{recipecount}桶,开始下{recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).RawMaterialWeight}g料");
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).RecipeStatus = 2;
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).Status = (Status)1;
Raction?.Invoke(ip, recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re).RawMaterialWeight);
rTrig.TryUpdate(ip, false, true);
}
if (tTrig[ip] && re_1 >= 0)
{
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).RecipeStatus = 3;
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).Status = (Status)2;
recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).TotalWeight = DeviceInquire.GetInstance.DeviceLists[ip].deviceStatus.CutWeightFeedback;
MessageNotify.GetInstance.ShowRunLog($"设备{ip}已下料{recipeProcesses.ElementAt(recipecount).RawMaterials.ElementAt(re_1).TotalWeight}g");
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发完成信号");
SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX70{(int)((dnum - 1) / 8)}.{(dnum - 1) % 8}", true);
tTrig.TryUpdate(ip, false, true);
}
}
}
}
}
}
}
private void MatchRun()
{
@@ -661,6 +657,7 @@ namespace BPASmartClient.DosingSystem
maxPail = rawMaterial.Loc;
}
}
if (dnum == 18 && maxPail <= DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail)
{
App.Current.Dispatcher.Invoke(() =>
@@ -683,8 +680,20 @@ namespace BPASmartClient.DosingSystem
}
});
}
if (maxPail <= DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail && recipeNameNum < RecipeNames.Count && !DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive)
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].IpAddress].deviceStatus.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)},桶数已清零");
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));
@@ -702,14 +711,11 @@ namespace BPASmartClient.DosingSystem
}
}
}
SimensSend.GetInstance.SendSimens.Write<int>($"DB1.DBD{710 + 4 * (dnum - 1)}", 0);
foreach (var down_Loc in device_Loc)
{
SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX{710 + 4 * (dnum - 1) + (int)((down_Loc - 1) / 8)}.{(down_Loc - 1) % 8}", true);
}
SimensSend.GetInstance.SendSimens.Write<ushort>($"DB1.DBW{106 + 2 * (dnum - 1)}", 600);
SimensSend.GetInstance.SendSimens.Write<ushort>($"DB1.DBW{810 + 2 * (dnum - 1)}", 0);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配方{RecipeNames.ElementAt(recipeNameNum - 1)},桶数已清零");
SimensSend.GetInstance.SendSimens.Write<ushort>($"DB1.DBW{106 + 2 * (dnum - 1)}", 500);
if (dnum == 1)
{
App.Current.Dispatcher.Invoke(() =>
@@ -738,13 +744,13 @@ namespace BPASmartClient.DosingSystem
}
MonitorStatus(DeviceInquire.GetInstance.devices[i].IpAddress);
}
}
MonitorStatus();
}
Thread.Sleep(10);
@@ -756,11 +762,11 @@ namespace BPASmartClient.DosingSystem
{
while (!DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<float>(DeviceAddress.WeightSet.ToAdd(), f).IsSuccess)
{
DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<float>(DeviceAddress.WeightSet.ToAdd(), f );
MessageNotify.GetInstance.ShowRunLog($"设备{s}下发下料重量信号失败" );
}
while (!DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 1).IsSuccess)
{
DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 1 );
MessageNotify.GetInstance.ShowRunLog($"设备{s}下发开始信号失败" );
stop = false;
}
stop = true;
@@ -777,21 +783,21 @@ namespace BPASmartClient.DosingSystem
{
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
int dnum = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DeviceNum;
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.Finish_mt)
{
int dnum = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DeviceNum;
SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX70{(int)((dnum - 1) / 8)}.{(dnum - 1) % 8}", true);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发完成信号");
Thread.Sleep(1000);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配料完成复位信号");
ushort finish = 0;
finish.SetBitValue(1, true);
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.WorkModel.ToAdd(), finish);
}
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 2 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3)
{
if (stop)
{
MessageNotify.GetInstance.ShowRunLog($"下发复位信号");
while (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 0).IsSuccess)
{
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 0);
}
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发开始配料复位信号");
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 0);
}
}
}