@@ -31,6 +31,10 @@ using System.Text.RegularExpressions;
using static System.Resources.ResXFileRef;
using BPASmartClient.DosingSystem.Model.Dto;
using BPASmartClient.DosingSystem.Model.MQTT;
using Microsoft.VisualBasic.Logging;
using Org.BouncyCastle.Asn1.Utilities;
using Google.Protobuf.WellKnownTypes;
using System.Windows;
namespace BPASmartClient.DosingSystem
{
@@ -48,6 +52,8 @@ namespace BPASmartClient.DosingSystem
public ObservableCollection<RecipeModel> Recipes { get; set; } = Json<LocalRecipe>.Data.Recipes;
public ObservableCollection<StockStatusModel> StockStatus = new ObservableCollection<StockStatusModel>();
public Action<string,float> Raction { get; set; }
public string CurrentRecipeName { get; set; }
/// <summary>
/// 当前正在制作的配方
@@ -367,10 +373,11 @@ namespace BPASmartClient.DosingSystem
Json<LocalRecipe>.Data.Recipes.ElementAt(index).IsEnable = false;
}
MessageNotify.GetInstance.ShowUserLog($"下发工单 {Recipes.ElementAt(index).RecipeName}");
RecipeNames.Enqueue(RecipeName);
RecipeNames.Enqueue( RecipeName);
var res = Recipes.FirstOrDefault(p => p.RecipeName == RecipeName);
App.Current.Dispatcher.Invoke(() => { UserTreeWait.Add(new RecipeModel { RecipStatus = "等待制作", SerialNum = UserTreeWait.Count + 1, RecipeName = RecipeName, RawMaterials = res.RawMaterials }); });
}
App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方下发成功!"); });
MessageNotify.GetInstance.runLogs.Add(new RunLog() { RunLogInfo = $"下发配方:{RecipeNames.Count}", Time = DateTime.Now.ToString() });
@@ -388,27 +395,30 @@ namespace BPASmartClient.DosingSystem
List<Task> tasks = new();
tasks.Add( SimensSend.GetInstance.SendSimens.WriteAsync("M0.0", false));
tasks.Add( SimensSend.GetInstance.SendSimens.WriteAsync("M0.1", false));
foreach (var item in DeviceInquire.GetInstance.DeviceLists.Values)
/* foreach (var item in DeviceInquire.GetInstance.DeviceLists.Values)
{
tasks.Add( item.modbusTcp.WriteAsync<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0));
}
Task.WaitAll(tasks.ToArray(),TimeSpan.FromSeconds(5));
Task.WaitAll(tasks.ToArray(),TimeSpan.FromSeconds(5));*/
}
public void ShutDown()
{
TaskManage.GetInstance.StopTask("设备下发配方");
TaskManage.GetInstance.StopTask("下发设备参数 ");
TaskManage.GetInstance.StopTask("控制传送带 ");
TaskManage.GetInstance.StopTask("监控允许配料点位 ");
TaskManage.GetInstance.StopTask("下料 控制");
List<Task> tasks = new();
tasks.Add(SimensSend.GetInstance.SendSimens.WriteAsync("M0.0", false));
tasks.Add(SimensSend.GetInstance.SendSimens.WriteAsync("M0.1", false));
var writeTasks = DeviceInquire.GetInstance.DeviceLists.Values.Select(async item =>
/* var writeTasks = DeviceInquire.GetInstance.DeviceLists.Values.Select(async item =>
{
bool writeSuccessful = false;
int maxRetries = 3;
int retryCount = 0;
while (item.deviceStatus.TranspportSwitch == (ushort)1)
{
item.modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), (ushort)0);
}
while (!writeSuccessful && retryCount < maxRetries)
{
var result = await item.modbusTcp.WriteAsync<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
@@ -422,21 +432,126 @@ namespace BPASmartClient.DosingSystem
retryCount++;
}
}
});
});*/
tasks.AddRange(writeTasks);
/* tasks.AddRange(writeTasks);*/
Task.WaitAll(tasks.ToArray(), TimeSpan.FromSeconds(5));
}
private void MatchRun()
public ConcurrentDictionary<string, bool> rTrig = new ConcurrentDictionary<string, bool>();
public ConcurrentDictionary<string, bool> tTrig = new ConcurrentDictionary<string, bool>();
bool stop = true;
private void MonitorStatus()
{
TaskManage.GetInstance.StartLong(() =>
{
for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
{
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
if (!rTrig.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
rTrig.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, false);
}
if (!tTrig.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
tTrig.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, 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)
{
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);
}
}
if (rTrig[DeviceInquire.GetInstance.devices[i].IpAddress] || tTrig[DeviceInquire.GetInstance.devices[i].IpAddress])
{
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 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;
if (recipeNameNum - finish<=recipeProcesses.Count)
{
re = recipeProcesses.ElementAt(recipeProcesses.Count-(recipeNameNum-finish)).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(recipeProcesses.Count - (recipeNameNum - finish)).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(recipeNameNum - finish - 1).RawMaterials.ElementAt(re).RecipeStatus = 2;
Raction?.Invoke(DeviceInquire.GetInstance.devices[i].IpAddress, Recipes.ElementAt(doCount).RawMaterials.ElementAt(res).RawMaterialWeight);
rTrig.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress,false,true);
}
if (tTrig[DeviceInquire.GetInstance.devices[i].IpAddress] &&re_1>=0)
{
recipeProcesses.ElementAt(recipeNameNum - finish - 1).RawMaterials.ElementAt(re_1).RecipeStatus = 3;
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);
}
}
}
}
}
}
}
Thread.Sleep(10);
}, "监控允许配料点位");
}
private void MatchRun()
{
MonitorStatus();
recipeProcesses.Clear();
/*recipeProcesses = new ObservableCollection<RecipeModel>(Json<OnRecipe>.Data.Recipes.ToList()?.FindAll(o => o.RecipStatus == "正在制作"));
foreach (var recipe in recipeProcesses)
{
RecipeNames.Enqueue(recipe.RecipeName);
}
App.Current.Dispatcher.Invoke(() => { recipeProcesses.Add(Recipes.ElementAt(0)); });*/
TaskManage.GetInstance.StartLong(() =>
{
if (RecipeNames.Count > 0)
if (RecipeNames.Count > 0 && SimensSend.GetInstance.IsConnect)
{
SimensSend.GetInstance.SendSimens.Write("M0.0", true);
SimensSend.GetInstance.SendSimens.Write("M0.1", true);
//下发设备参数
//遍历每一个味魔方。
for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
{
@@ -446,174 +561,223 @@ namespace BPASmartClient.DosingSystem
//只有设备在等待配料状态才能下发数据
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1)
{
//判断MaxPassPail--配方的最大桶数,小于已经通过的桶数。
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail <= DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 0)
if (doDeviceCount.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
if (doDeviceCount.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
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;
if (recipeNameNum == 0)
{
int index = 0;
// 该味魔方已经完成的配方数目。
int recipeNameNum = doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress];
//设备已执行的配方必须小于已经下发的配方。所以每次开启软件时 必须清零设备上的数据。
if (recipeNameNum == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DoRecipeCount && recipeNameNum < RecipeNames.Count)
MessageNotify.GetInstance.ShowRunLog("执行首个配方");
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum));
if (index >= 0 && dnum > 0)
{
//查找配方。根据名称查找。
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum));
if (index >= 0 && index < Recipes.Count)
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
{
int maxPail = 0;
//查找配方的最大桶号。
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
if (rawMaterial.Loc > maxPail)
{
if (rawMaterial.Loc > maxPail)
{
maxPail = rawMaterial.Loc;
}
maxPail = rawMaterial.Loc;
}
//清除下位设备的最大桶号,下位设备认为配方制作完一个了。
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.DeletePassPail.ToAdd(), 1);
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.MaxPail.ToAdd(), (ushort)maxPail);
if (rawMaterial.DeviceIp == DeviceInquire.GetInstance.devices[i].IpAddress)
{
device_Loc.Add(rawMaterial.Loc);
}
}
MessageNotify.GetInstance.ShowRunLog($"{DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail}/{maxPail}/{device_Loc}");
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail == 0)
{
doDeviceCount.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, recipeNameNum + 1, doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress]);
App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方{RecipeNames.ElementAt(recipeNameNum)}{recipeNameNum}下发到设备{DeviceInquire.GetInstance.devices[i].DeviceName}"); });
//必须等第一台设备下发成功了,才算正在进行。
if (doDeviceCount.ContainsKey("192.168.2.10") && UserTreeWait.Count > 0 && doDeviceCount["192.168.2.10"] > recipeProcesses.Count)
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)}", 500);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配方{RecipeNames.ElementAt(recipeNameNum)}");
if (dnum == 1)
{
App.Current.Dispatcher.Invoke(() =>
{
recipeProcesses.Insert(0, UserTreeWait?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum)));
RecipeModel recipe = UserTreeWait?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum));
recipe.RecipStatus = "正在配料";
recipeProcesses.Insert(0, recipe);
/*Json<OnRecipe>.Data.Recipes.Insert(0, recipe);
Json<OnRecipe>.Save();*/
UserTreeWait.RemoveAt(UserTreeWait.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum)));
});
}
//
if (DeviceInquire.GetInstance.devices[i].IpAddress == "192.168.2.180" && recipeNameNum > 1 && recipeProcesses.Count > 0)
}
}
}
if (recipeNameNum > 0 && recipeNameNum <= RecipeNames.Count)
{
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 (rawMaterial.DeviceIp == DeviceInquire.GetInstance.devices[i].IpAddress)
{
App.Current.Dispatcher.Invoke(() =>
device_Loc.Add(rawMaterial.Loc);
}
}
if (dnum == 18 && maxPail <= DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail)
{
App.Current.Dispatcher.Invoke(() =>
{
RecipeModel recipe = recipeProcesses?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum));
if (recipe.RecipStatus != "制作完成")
{
RecipeModel recipe = recipeProcesses?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum));
/*Json<OnRecipe>.Data.Recipes.RemoveAt(recipeProcesses.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum)));
Json<OnRecipe>.Save();*/
recipe.RecipStatus = "制作完成";
UserTreeCompelete.Insert(0, recipe);
recipeProcesses.RemoveAt(recipeProcesses.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum)));
}
});
}
if (maxPail <= DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail&& recipeNameNum < RecipeNames.Count)
{
MessageNotify.GetInstance.ShowRunLog("下发下一个配方");
doDeviceCount.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, recipeNameNum + 1, doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress]);
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.Loc > maxPail)
{
maxPail = rawMaterial.Loc;
}
if (rawMaterial.DeviceIp == DeviceInquire.GetInstance.devices[i].IpAddress)
{
device_Loc.Add(rawMaterial.Loc);
}
}
}
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)},桶数已清零");
if (dnum == 1)
{
App.Current.Dispatcher.Invoke(() =>
{
RecipeModel recipe = UserTreeWait?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum));
recipe.RecipStatus = "正在配料";
recipeProcesses.Insert(0, recipe);
/* Json<OnRecipe>.Data.Recipes.Insert(0, recipe);
Json<OnRecipe>.Save();*/
UserTreeWait.RemoveAt(UserTreeWait.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum)));
});
}
}
}
}
else
{
doDeviceCount.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, 0);
}
}
else
{
doDeviceCount.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, 0);
}
}
}
}
//if (doDeviceCount.ContainsKey("192.168.2.10")&&doDeviceCount.ContainsKey($"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"))
//{
// if (doDeviceCount[$"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"] > 0 && DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"].deviceStatus.DoRecipeCount == doDeviceCount[$"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"])
// {
// App.Current.Dispatcher.Invoke(new Action(() =>
// {
// UserTreeCompelete.Insert(0, recipeProcesses.Last());
// recipeProcesses.Remove(recipeProcesses.Last());
// }));
// }
// if (DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.DoRecipeCount == doDeviceCount["192.168.2.10"])
// {
// App.Current.Dispatcher.Invoke(new Action(() =>
// {
// if (UserTreeWait.Count > 0)
// {
// recipeProcesses.Insert(0, UserTreeWait[0]);
// UserTreeWait.RemoveAt(0);
// }
// }));
// }
//}
}
Thread.Sleep(10);
}, "设备下发配方");
TaskManage.GetInstance.StartLong(() =>
MessageNotify.GetInstance.ShowRunLog($"设备下发配方运行");
Raction = ((s,f) =>
{
while (!DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<float>(DeviceAddress.WeightSet.ToAdd(), f).IsSuccess)
{
DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<float>(DeviceAddress.WeightSet.ToAdd(), f);
}
while (!DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 1).IsSuccess)
{
DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 1);
stop = false;
}
stop = true;
MessageNotify.GetInstance.ShowRunLog($"允许下发复位信号");
});
TaskManage.GetInstance.StartLong(() =>
{
for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
{
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress) && doDeviceCount.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
//判断桶到位 和 状态为等待配料。
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DoRecipeCount > 0)
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}下发完成信号");
}
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus==2&& DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus==3)
{
int doCount = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DoRecipeCount - 1));
if (doCount >= 0 && doCount < Recipes.Count)
if (stop)
{
//根据物料名称查找
var res = Recipes.ElementAt(doCount).RawMaterials?.ToList().FindAll(a => a.RawMaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
foreach (RawMaterialModel item in res)
MessageNotify.GetInstance.ShowRunLog($"下发复位信号");
while (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 0).IsSuccess)
{
//可能是多个桶都需要下同一种料,根据已通过桶数和当前物料信息的通号做对比。
if (item != null && item.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail)
{
DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
if (deviceSet != null && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].IsConnected == true)
{
var deviceModbus = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp;
//传送带停止
deviceModbus.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
Thread.Sleep(50);
//设置下料重量
deviceModbus.Write<float>(DeviceAddress.WeightSet.ToAdd(), item.RawMaterialWeight);
Thread.Sleep(50);
//设置慢加重量
deviceModbus.Write<float>(DeviceAddress.SlowlyAddWeight.ToAdd(), deviceSet.SlowlyAddWeight);
Thread.Sleep(50);
//设置提前关阀重量
deviceModbus.Write<float>(DeviceAddress.PreCloseValveWeight.ToAdd(), deviceSet.PreCloseValveWeight);
Thread.Sleep(50);
//设置快慢加速度
deviceModbus.Write<int>(DeviceAddress.SlowAcceleration.ToAdd(), (int)deviceSet.SlowAcceleration);
Thread.Sleep(50);
deviceModbus.Write<int>(DeviceAddress.RapidAcceleration.ToAdd(), (int)deviceSet.RapidAcceleration);
Thread.Sleep(50);
//设置伺服手动速度
deviceModbus.Write<int>(DeviceAddress.ServoManualSpeed.ToAdd(), deviceSet.ServoManualSpeed);
Thread.Sleep(50);
//设置料仓上下限重量
deviceModbus.Write<int>(DeviceAddress.SiloUpperLimitWeight.ToAdd(), deviceSet.SiloUpperLimitWeight);
Thread.Sleep(50);
deviceModbus.Write<int>(DeviceAddress.LowerLimitWeightOfSilo.ToAdd(), deviceSet.LowerLimitWeightOfSilo);
Thread.Sleep(50);
//开始配料信号
deviceModbus.Write<ushort>(DeviceAddress.Start.ToAdd(), (ushort)1);
////设置搅拌速度
//DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<int>(DeviceAddress.StirringSpeed.ToAdd(), deviceSet.StirringSpeed);
}
}
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 0);
}
}
}
}
}
Thread.Sleep(10);
}, "下料控制");
MessageNotify.GetInstance.ShowRunLog($"下料控制运行");
//弃用
/*TaskManage.GetInstance.StartLong(() =>
{
for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
{
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress) && doDeviceCount.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive && doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress] >= 0)
{
int recipeNameNum = doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress];
int doCount = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum));
var res = Recipes.ElementAt(doCount).RawMaterials?.ToList().Find(a => a.RawMaterialName == DeviceInquire.GetInstance.devices[i].DeviceName && a.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail);
if (res != null)
{
var deviceModbus = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp;
deviceModbus.Write<float>(DeviceAddress.WeightSet.ToAdd(), res.RawMaterialWeight);
deviceModbus.Write<bool>(DeviceAddress.Start.ToAdd(), true);
}
}
}
}
Thread.Sleep(10);
}, "下发设备参数");
DeviceStatus nextDevice = new DeviceStatus();
}, "下发设备参数");*/
/*DeviceStatus nextDevice = new DeviceStatus();
TaskManage.GetInstance.StartLong(() =>
{
for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
{
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
@@ -621,7 +785,7 @@ namespace BPASmartClient.DosingSystem
if (DeviceInquire.GetInstance.devices[i].IpAddress == "192.168.2.90")
{
if (DeviceInquire.GetInstance.DeviceLists[ DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1)
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1)
{
SimensSend.GetInstance.SendSimens.Write("DB1.DBX702.0", 0);
}
@@ -634,56 +798,56 @@ namespace BPASmartClient.DosingSystem
if (DeviceInquire.GetInstance.devices[i].IpAddress != $"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}")
{
ushort deviceNum = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DeviceNum;
string nextIp = "";
if (DeviceInquire.GetInstance.DeviceLists.TryGetValue($"{Json<DevicePar>.Data.BaseParModel.NetworkSegAddress}{(deviceNum + 1) * 10}", out nextDevice) && deviceNum != 0)
{
nextIp = DeviceInquire.GetInstance.DeviceLists.ToList().Find(q => q.Value == nextDevice).Key;
}
if (nextIp != "")
ushort deviceNum = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DeviceNum;
string nextIp = "";
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey($"{Json<DevicePar>.Data.BaseParModel.NetworkSegAddress}{(deviceNum + 1) * 10}") && deviceNum != 0)
{
nextIp = $"{Json<DevicePar>.Data.BaseParModel.NetworkSegAddress}{(deviceNum + 1) * 10}";
}
if (nextIp != "")
{
//if (DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.RunStatus == 1 || DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.RunStatus == 3)
//{
// DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
// DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), 1000);
// DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 1);
//}
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1 || DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3)
{
//if (DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.RunStatus == 1 || DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.RunStatus == 3)
//{
// DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
// DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), 1000);
// DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 1);
//}
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1 || DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3)
{
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1 && DeviceInquire.GetInstance.DeviceLists[nextIp].deviceStatus.PailArrive == 1)
{
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), (ushort)0);
}
else
{
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), 600);
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), (ushort)1);
}
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1 && DeviceInquire.GetInstance.DeviceLists[nextIp].deviceStatus.PailArrive == 1)
{
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), (ushort)0);
}
else
{
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
//传送带停止
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), 600);
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), (ushort)1);
}
//DeviceInquire.GetInstance.DeviceLists["192.168.2.130"].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), 1000);
//DeviceInquire.GetInstance.DeviceLists["192.168.2.130"].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
//else if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i + 1].IpAddress].deviceStatus.PailArrive == 1)
//{
// //传送带运行
// DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), (ushort)1);
// DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
// DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), deviceSet.SendSp);
// DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 1);
//}
}
else
{
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
//传送带停止
}
//DeviceInquire.GetInstance.DeviceLists["192.168.2.130"].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), 1000);
//DeviceInquire.GetInstance.DeviceLists["192.168.2.130"].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
//else if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i + 1].IpAddress].deviceStatus.PailArrive == 1)
//{
// //传送带运行
// DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), (ushort)1);
// DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
// DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), deviceSet.SendSp);
// DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 1);
//}
}
else
{
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
}
}
else
{
@@ -708,11 +872,13 @@ namespace BPASmartClient.DosingSystem
}
}
}
Thread.Sleep(10);
}, "控制传送带");
}, "控制传送带");*/
#region 弃用配料流程
//弃用配料流程