|
|
@@ -1,4 +1,6 @@ |
|
|
|
using BPA.Helper; |
|
|
|
#define test |
|
|
|
|
|
|
|
using BPA.Helper; |
|
|
|
using BPASmartClient.SmallBatchingSystem; |
|
|
|
using System; |
|
|
|
using System.Collections.Concurrent; |
|
|
@@ -36,86 +38,236 @@ namespace BPASmartClient.SmallBatchingSystem |
|
|
|
{ |
|
|
|
if (MakeOrderQueue.TryDequeue(out RecipeInfo recipeInfo)) |
|
|
|
{ |
|
|
|
IsCancel = false; |
|
|
|
List<int> OutletInfo = new List<int>(); |
|
|
|
recipeInfo.SiloInfoModels.ToList()?.ForEach(item => |
|
|
|
{ |
|
|
|
var res = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(item.SiloName)) != null); |
|
|
|
if (res != null) if (!OutletInfo.Contains(res.OutletLoc)) OutletInfo.Add(res.OutletLoc); |
|
|
|
}); |
|
|
|
foreach (var temp in OutletInfo) |
|
|
|
//ProcessOne(recipeInfo); |
|
|
|
ProcessTwo(recipeInfo); |
|
|
|
} |
|
|
|
} |
|
|
|
Thread.Sleep(10); |
|
|
|
}), "配方流程控制"); |
|
|
|
} |
|
|
|
|
|
|
|
private void ProcessOne(RecipeInfo recipeInfo) |
|
|
|
{ |
|
|
|
IsCancel = false; |
|
|
|
List<int> OutletInfo = new List<int>(); |
|
|
|
recipeInfo.SiloInfoModels.ToList()?.ForEach(item => |
|
|
|
{ |
|
|
|
var res = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(item.SiloName)) != null); |
|
|
|
if (res != null) if (!OutletInfo.Contains(res.OutletLoc)) OutletInfo.Add(res.OutletLoc); |
|
|
|
}); |
|
|
|
foreach (var temp in OutletInfo) |
|
|
|
{ |
|
|
|
PlcServer.GetInstance.WriteData("VW302", (ushort)temp);//设置出料口位置 |
|
|
|
PlcServer.GetInstance.WriteData("M10.0", true);//定位启动 |
|
|
|
RunLog($"启动定位,出料口位置:{temp}"); |
|
|
|
int index = temp - 1; |
|
|
|
if (index >= 0) |
|
|
|
{ |
|
|
|
RunLog("等待定位完成"); |
|
|
|
while (!PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1);//等待定位反馈 |
|
|
|
if (IsCancel) break; |
|
|
|
RunLog("定位完成"); |
|
|
|
PlcServer.GetInstance.WriteData("M20.0", false); |
|
|
|
while (PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1); |
|
|
|
if (IsCancel) break; |
|
|
|
RunLog("定位完成,复位成功"); |
|
|
|
foreach (var temp1 in recipeInfo.SiloInfoModels) |
|
|
|
{ |
|
|
|
var rest = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(temp1.SiloName)) != null); |
|
|
|
if (rest != null && rest.OutletLoc == temp) |
|
|
|
{ |
|
|
|
PlcServer.GetInstance.WriteData("VW302", (ushort)temp);//设置出料口位置 |
|
|
|
PlcServer.GetInstance.WriteData("M10.0", true);//定位启动 |
|
|
|
RunLog($"启动定位,出料口位置:{temp}"); |
|
|
|
int index = temp - 1; |
|
|
|
if (index >= 0) |
|
|
|
var res = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == temp1.SiloName); |
|
|
|
if (res != null) |
|
|
|
{ |
|
|
|
RunLog("等待定位完成"); |
|
|
|
while (!PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1);//等待定位反馈 |
|
|
|
StatusNotify(res.SiloName, Status.正在配料); |
|
|
|
RunLog($"写重量地址:{GetWeightAdd(res.SiloLoc)},重量:{temp1.SiloWeight}"); |
|
|
|
PlcServer.GetInstance.WriteData(GetWeightAdd(res.SiloLoc), (ushort)temp1.SiloWeight); |
|
|
|
RunLog($"写启动信号地址:{GetStartSingleAdd(res.SiloLoc)}"); |
|
|
|
PlcServer.GetInstance.WriteData(GetStartSingleAdd(res.SiloLoc), true); |
|
|
|
while (!PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成 |
|
|
|
if (IsCancel) break; |
|
|
|
RunLog("定位完成"); |
|
|
|
PlcServer.GetInstance.WriteData("M20.0", false); |
|
|
|
while (PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1); |
|
|
|
RunLog("出料完成,复位出料完成状态"); |
|
|
|
PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号 |
|
|
|
while (PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成信号复位成功 |
|
|
|
if (IsCancel) break; |
|
|
|
RunLog("定位完成,复位成功"); |
|
|
|
foreach (var temp1 in recipeInfo.SiloInfoModels) |
|
|
|
{ |
|
|
|
var rest = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(temp1.SiloName)) != null); |
|
|
|
if (rest != null && rest.OutletLoc == temp) |
|
|
|
{ |
|
|
|
var res = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == temp1.SiloName); |
|
|
|
if (res != null) |
|
|
|
{ |
|
|
|
StatusNotify(res.SiloName, Status.正在配料); |
|
|
|
RunLog($"写重量地址:{GetWeightAdd(res.SiloLoc)},重量:{temp1.SiloWeight}"); |
|
|
|
PlcServer.GetInstance.WriteData(GetWeightAdd(res.SiloLoc), (ushort)temp1.SiloWeight); |
|
|
|
RunLog($"写启动信号地址:{GetStartSingleAdd(res.SiloLoc)}"); |
|
|
|
PlcServer.GetInstance.WriteData(GetStartSingleAdd(res.SiloLoc), true); |
|
|
|
while (!PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成 |
|
|
|
if (IsCancel) break; |
|
|
|
RunLog("出料完成,复位出料完成状态"); |
|
|
|
PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号 |
|
|
|
while (PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成信号复位成功 |
|
|
|
if (IsCancel) break; |
|
|
|
RunLog("出料完成复位成功"); |
|
|
|
StatusNotify(res.SiloName, Status.配料完成); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (IsCancel) return; |
|
|
|
RunLog("出料完成复位成功"); |
|
|
|
StatusNotify(res.SiloName, Status.配料完成); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (IsCancel) return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!IsCancel) |
|
|
|
{ |
|
|
|
RunLog($"写入配方执行完成信号"); |
|
|
|
PlcServer.GetInstance.WriteData("M10.4", true); |
|
|
|
RunLog("等待配方执行完成"); |
|
|
|
while (!PlcDataModel.RecipeBatchingComplete && !IsCancel) Thread.Sleep(1); |
|
|
|
if (IsCancel) return; |
|
|
|
RunLog($"【{recipeInfo.RecipeName}】配方执行完成"); |
|
|
|
ActionManage.GetInstance.Send("GrindArenaceousCancel"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!IsCancel) |
|
|
|
/// <summary> |
|
|
|
/// 计时配料 |
|
|
|
/// </summary> |
|
|
|
/// <param name="recipeInfo"></param> |
|
|
|
private void ProcessTwo(RecipeInfo recipeInfo) |
|
|
|
{ |
|
|
|
IsCancel = false; |
|
|
|
Dictionary<int, List<int>> DeviceSoilInfo = new Dictionary<int, List<int>>(); |
|
|
|
List<int> OutletInfo = new List<int>(); |
|
|
|
recipeInfo.SiloInfoModels.ToList()?.ForEach(item => |
|
|
|
{ |
|
|
|
var res = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s == item.SiloName) != null); |
|
|
|
if (res != null) |
|
|
|
{ |
|
|
|
var soliInfo = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == item.SiloName); |
|
|
|
if (soliInfo != null) |
|
|
|
{ |
|
|
|
if (!DeviceSoilInfo.ContainsKey(res.OutletLoc)) |
|
|
|
{ |
|
|
|
DeviceSoilInfo.Add(res.OutletLoc, new List<int>()); |
|
|
|
DeviceSoilInfo[res.OutletLoc].Add(soliInfo.SiloLoc); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
RunLog($"写入配方执行完成信号"); |
|
|
|
PlcServer.GetInstance.WriteData("M10.4", true); |
|
|
|
RunLog("等待配方执行完成"); |
|
|
|
while (!PlcDataModel.RecipeBatchingComplete && !IsCancel) Thread.Sleep(1); |
|
|
|
if (IsCancel) break; |
|
|
|
RunLog($"【{recipeInfo.RecipeName}】配方执行完成"); |
|
|
|
ActionManage.GetInstance.Send("GrindArenaceousCancel"); |
|
|
|
DeviceSoilInfo[res.OutletLoc].Add(soliInfo.SiloLoc); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
Thread.Sleep(10); |
|
|
|
}), "配方流程控制"); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
private bool Wait(ref bool Targger, bool IsCancel = false) |
|
|
|
{ |
|
|
|
bool a = Targger; |
|
|
|
while (!IsCancel) |
|
|
|
foreach (var temp in DeviceSoilInfo) |
|
|
|
{ |
|
|
|
if (a) |
|
|
|
Thread.Sleep(1); |
|
|
|
PlcServer.GetInstance.WriteData("VW302", (ushort)temp.Key);//设置出料口位置 |
|
|
|
//PlcServer.GetInstance.WriteData("M10.0", true);//定位启动 |
|
|
|
PlcServer.GetInstance.WriteData("M10.4", true);//定位启动 |
|
|
|
RunLog($"启动定位,出料口位置:{temp}"); |
|
|
|
int index = temp.Key - 1; |
|
|
|
if (index >= 0) |
|
|
|
{ |
|
|
|
RunLog("等待定位完成"); |
|
|
|
while (!PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1);//等待定位反馈 |
|
|
|
if (IsCancel) break; |
|
|
|
RunLog("定位完成"); |
|
|
|
PlcServer.GetInstance.WriteData("M20.0", false); |
|
|
|
while (PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1); |
|
|
|
if (IsCancel) break; |
|
|
|
RunLog("定位完成,复位成功"); |
|
|
|
foreach (var temp1 in temp.Value) |
|
|
|
{ |
|
|
|
//var rest = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(temp1.SiloName)) != null); |
|
|
|
//if (rest != null && rest.OutletLoc == temp) |
|
|
|
//{ |
|
|
|
|
|
|
|
var res = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloLoc == temp1); |
|
|
|
if (res != null) |
|
|
|
{ |
|
|
|
var tempRecipe = recipeInfo.SiloInfoModels.FirstOrDefault(p => p.SiloName == res.SiloName); |
|
|
|
if (tempRecipe != null) |
|
|
|
{ |
|
|
|
StatusNotify(res.SiloName, Status.正在配料); |
|
|
|
RunLog($"写重量地址:{GetWeightAdd(res.SiloLoc)},重量:{tempRecipe.SiloWeight}"); |
|
|
|
PlcServer.GetInstance.WriteData(GetWeightAdd(res.SiloLoc), (ushort)(tempRecipe.SiloWeight * 10)); |
|
|
|
RunLog($"写启动信号地址:{GetStartSingleAdd(res.SiloLoc)}"); |
|
|
|
PlcServer.GetInstance.WriteData(GetStartSingleAdd(res.SiloLoc), true); |
|
|
|
while (!PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成 |
|
|
|
if (IsCancel) break; |
|
|
|
RunLog("出料完成,复位出料完成状态"); |
|
|
|
#if test |
|
|
|
PlcServer.GetInstance.WriteData("M10.0", false);//复位出料完成信号 |
|
|
|
#else |
|
|
|
PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号 |
|
|
|
#endif |
|
|
|
|
|
|
|
while (PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成信号复位成功 |
|
|
|
if (IsCancel) break; |
|
|
|
RunLog("出料完成复位成功"); |
|
|
|
StatusNotify(res.SiloName, Status.配料完成); |
|
|
|
} |
|
|
|
} |
|
|
|
//} |
|
|
|
} |
|
|
|
if (IsCancel) return; |
|
|
|
} |
|
|
|
} |
|
|
|
return !IsCancel; |
|
|
|
} |
|
|
|
|
|
|
|
//IsCancel = false; |
|
|
|
//List<int> OutletInfo = new List<int>(); |
|
|
|
//recipeInfo.SiloInfoModels.ToList()?.ForEach(item => |
|
|
|
//{ |
|
|
|
// var res = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(item.SiloName)) != null); |
|
|
|
// if (res != null) if (!OutletInfo.Contains(res.OutletLoc)) OutletInfo.Add(res.OutletLoc); |
|
|
|
//}); |
|
|
|
//foreach (var temp in OutletInfo) |
|
|
|
//{ |
|
|
|
// PlcServer.GetInstance.WriteData("VW302", (ushort)temp);//设置出料口位置 |
|
|
|
// //PlcServer.GetInstance.WriteData("M10.0", true);//定位启动 |
|
|
|
// PlcServer.GetInstance.WriteData("M10.4", true);//定位启动 |
|
|
|
// RunLog($"启动定位,出料口位置:{temp}"); |
|
|
|
// int index = temp - 1; |
|
|
|
// if (index >= 0) |
|
|
|
// { |
|
|
|
// RunLog("等待定位完成"); |
|
|
|
// while (!PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1);//等待定位反馈 |
|
|
|
// if (IsCancel) break; |
|
|
|
// RunLog("定位完成"); |
|
|
|
// PlcServer.GetInstance.WriteData("M20.0", false); |
|
|
|
// while (PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1); |
|
|
|
// if (IsCancel) break; |
|
|
|
// RunLog("定位完成,复位成功"); |
|
|
|
// foreach (var temp1 in recipeInfo.SiloInfoModels) |
|
|
|
// { |
|
|
|
// var rest = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(temp1.SiloName)) != null); |
|
|
|
// if (rest != null && rest.OutletLoc == temp) |
|
|
|
// { |
|
|
|
// var res = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == temp1.SiloName); |
|
|
|
// if (res != null) |
|
|
|
// { |
|
|
|
// StatusNotify(res.SiloName, Status.正在配料); |
|
|
|
// RunLog($"写重量地址:{GetWeightAdd(res.SiloLoc)},重量:{temp1.SiloWeight}"); |
|
|
|
// PlcServer.GetInstance.WriteData(GetWeightAdd(res.SiloLoc), (ushort)(temp1.SiloWeight * 10)); |
|
|
|
// RunLog($"写启动信号地址:{GetStartSingleAdd(res.SiloLoc)}"); |
|
|
|
// PlcServer.GetInstance.WriteData(GetStartSingleAdd(res.SiloLoc), true); |
|
|
|
// while (!PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成 |
|
|
|
// if (IsCancel) break; |
|
|
|
// RunLog("出料完成,复位出料完成状态"); |
|
|
|
//#if test |
|
|
|
// PlcServer.GetInstance.WriteData("M10.0", false);//复位出料完成信号 |
|
|
|
//#else |
|
|
|
//PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号 |
|
|
|
//#endif |
|
|
|
|
|
|
|
|
|
|
|
// while (PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成信号复位成功 |
|
|
|
// if (IsCancel) break; |
|
|
|
// RunLog("出料完成复位成功"); |
|
|
|
// StatusNotify(res.SiloName, Status.配料完成); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// if (IsCancel) return; |
|
|
|
// } |
|
|
|
//} |
|
|
|
|
|
|
|
if (!IsCancel) |
|
|
|
{ |
|
|
|
RunLog($"写入配方执行完成信号"); |
|
|
|
//PlcServer.GetInstance.WriteData("M10.4", true); |
|
|
|
PlcServer.GetInstance.WriteData("M10.5", true); |
|
|
|
RunLog("等待配方执行完成"); |
|
|
|
while (!PlcDataModel.RecipeBatchingComplete && !IsCancel) Thread.Sleep(1); |
|
|
|
if (IsCancel) return; |
|
|
|
RunLog($"【{recipeInfo.RecipeName}】配方执行完成"); |
|
|
|
ActionManage.GetInstance.Send("GrindArenaceousCancel"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 获取重量设置地址 |
|
|
|
/// </summary> |
|
|
@@ -123,10 +275,22 @@ namespace BPASmartClient.SmallBatchingSystem |
|
|
|
/// <returns></returns> |
|
|
|
private string GetWeightAdd(int num) |
|
|
|
{ |
|
|
|
#if test |
|
|
|
if (num > 0) |
|
|
|
{ |
|
|
|
int add = 0; |
|
|
|
if (num >= 1 && num <= 8) |
|
|
|
if (num >= 1 && num <= 18) |
|
|
|
{ |
|
|
|
add = 200 + (num - 1) * 2; |
|
|
|
} |
|
|
|
return $"VW{add}"; |
|
|
|
} |
|
|
|
return default; |
|
|
|
#else |
|
|
|
if (num > 0) |
|
|
|
{ |
|
|
|
int add = 0; |
|
|
|
if (num >= 1 && num <= 18) |
|
|
|
{ |
|
|
|
add = 100 + (num - 1) * 2; |
|
|
|
} |
|
|
@@ -137,6 +301,8 @@ namespace BPASmartClient.SmallBatchingSystem |
|
|
|
return $"VW{add}"; |
|
|
|
} |
|
|
|
return default; |
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void StatusNotify(string SiloName, Status Status) |
|
|
@@ -176,6 +342,7 @@ namespace BPASmartClient.SmallBatchingSystem |
|
|
|
/// <returns></returns> |
|
|
|
private string GetStartSingleAdd(int num) |
|
|
|
{ |
|
|
|
#if test |
|
|
|
if (num > 0) |
|
|
|
{ |
|
|
|
string Add = string.Empty; |
|
|
@@ -187,10 +354,28 @@ namespace BPASmartClient.SmallBatchingSystem |
|
|
|
c = 7; |
|
|
|
} |
|
|
|
else c--; |
|
|
|
Add = $"M{ t}.{c}"; |
|
|
|
Add = $"M{t + 4}.{c}"; |
|
|
|
return Add; |
|
|
|
} |
|
|
|
return default; |
|
|
|
#else |
|
|
|
if (num > 0) |
|
|
|
{ |
|
|
|
string Add = string.Empty; |
|
|
|
var t = num / 8; |
|
|
|
var c = (num % 8); |
|
|
|
if (c == 0) |
|
|
|
{ |
|
|
|
t--; |
|
|
|
c = 7; |
|
|
|
} |
|
|
|
else c--; |
|
|
|
Add = $"M{t}.{c}"; |
|
|
|
return Add; |
|
|
|
} |
|
|
|
return default; |
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|