From 1d48a26b97f4c1b535c122e24e63128d718ffa11 Mon Sep 17 00:00:00 2001
From: pengliangyang <1406009520@qq.com>
Date: Sat, 20 Aug 2022 13:40:11 +0800
Subject: [PATCH] =?UTF-8?q?=E5=90=89=E9=A6=99=E5=B1=85=E4=BB=A3=E7=A0=81?=
=?UTF-8?q?=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Model/GVL_BigStation.cs | 20 +-
.../Model/ProcessControl.cs | 247 +++++++++---------
.../ViewModel/RecipeReceiveViewModel.cs | 13 +-
.../Model/ProcessControl.cs | 5 +-
4 files changed, 145 insertions(+), 140 deletions(-)
diff --git a/BPASmartClient.JXJFoodBigStation/Model/GVL_BigStation.cs b/BPASmartClient.JXJFoodBigStation/Model/GVL_BigStation.cs
index 91af66e9..49d9601e 100644
--- a/BPASmartClient.JXJFoodBigStation/Model/GVL_BigStation.cs
+++ b/BPASmartClient.JXJFoodBigStation/Model/GVL_BigStation.cs
@@ -11,18 +11,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model
{
public class GVL_BigStation
{
- ///
- /// 配方数据
- ///
- public ObservableCollection RemoteRecipes = new ObservableCollection();
- ///
- /// 配方数据
- ///
- public ObservableCollection IssuedComplete = new ObservableCollection();
- ///
- /// 配方队列
- ///
- public ConcurrentQueue RecipeQueue = new ConcurrentQueue();
+
///
/// 往输送带下发配方完成
///
@@ -38,13 +27,10 @@ namespace BPASmartClient.JXJFoodBigStation.Model
///
/// 记录AGV进站送货的指令顺序
///
- public int[] AgvDeliveryPosition { get; set; }= new int[6];
+ public int AgvDeliveryPosition { get; set; }
///
/// 记录AGV进站取货的指令顺序
///
- public int[] AgvPickUpPosition { get; set; } = new int[6];
-
- public ConcurrentQueue AGVToWorkStationQueue = new ConcurrentQueue();
-
+ public int AgvPickUpPosition { get; set; }
}
}
diff --git a/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs b/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs
index 4ccc3506..7788c885 100644
--- a/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs
+++ b/BPASmartClient.JXJFoodBigStation/Model/ProcessControl.cs
@@ -25,6 +25,23 @@ namespace BPASmartClient.JXJFoodBigStation.Model
public SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
public HKDeviceStatus HKDevice = new HKDeviceStatus();
GVL_BigStation BigStation = new GVL_BigStation();
+
+ ///
+ /// 配方数据
+ ///
+ public ObservableCollection RemoteRecipes = new ObservableCollection();
+ ///
+ /// 配方数据
+ ///
+ public ObservableCollection IssuedComplete = new ObservableCollection();
+ ///
+ /// 配方队列
+ ///
+ public ConcurrentQueue RecipeQueue = new ConcurrentQueue();
+ ///
+ /// AGV到达工站队列
+ ///
+ public ConcurrentQueue AGVToWorkStationQueue = new ConcurrentQueue();
///
/// 接收原料数据
///
@@ -38,9 +55,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model
var res = SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.RecipeName);
var res1 = SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.RecipeID);
int res2 = SiemensDevice.Siemens_PLC_S7.ReadClass(RawMaterial, 0, 0);
- if ((res != null && res is string recipeName) &&
- (res1 != null && res1 is uint recipeID) &&
- (res2 > 0))
+ if ((res != null && res is string recipeName) && (res1 != null && res1 is uint recipeID) && (res2 > 0))
{
int index = Array.FindIndex(Json.Data.Recipes.ToArray(), p => p.RecipeCode == recipeID);
if (index == -1)
@@ -77,12 +92,12 @@ namespace BPASmartClient.JXJFoodBigStation.Model
var res1 = SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.RecipeID);
if (res != null && res is int TrayLocation && res1 != null && res1 is int recipeId)
{
- int index = Array.FindIndex(Json.Data.Recipes.ToArray(), p => p.RecipeCode == recipeId);
- if (index >= 0 && index < Json.Data.Recipes.Count)
+ int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == recipeId);
+ if (index >= 0 && index < RemoteRecipes.Count)
{
- Json.Data.Recipes.ElementAt(index).TrayCode = TrayLocation;
+ RemoteRecipes.ElementAt(index).TrayCode = TrayLocation;
MessageLog.GetInstance.RunLog($"接收到AGV进站信号=>配方编码:{recipeId} 、托盘位置:{TrayLocation}");
- BigStation.AGVToWorkStationQueue.Enqueue(recipeId);
+ AGVToWorkStationQueue.Enqueue(recipeId);
}
}
}
@@ -106,7 +121,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model
{
}
- BigStation.RecipeQueue.Clear();
+ RecipeQueue.Clear();
Json.Data.Recipes = TestData.GetInstance.Recipes;//添加测试数据
ThreadManage.GetInstance().StartLong(new Action(() =>
{
@@ -117,8 +132,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model
ThreadManage.GetInstance().StartLong(new Action(() => {
if (HKDevice.IsConnected && SiemensDevice.IsConnected)
{
- AgvGetInDelivery();
- //AgvGetInPickUp();
+ AgvGetInOut();
}
Thread.Sleep(10);
@@ -126,123 +140,120 @@ namespace BPASmartClient.JXJFoodBigStation.Model
ThreadManage.GetInstance().StartLong(new Action(() => {
ReadSiemensCommData();
ReadHKPLCCommData();
- }), "AGV进站送取货", true);
+ }), "读取西门子和海科PLC的数据", true);
}
///
- /// AGV进站送货
+ /// AGV送货
///
- private void AgvGetInDelivery()
+ ///
+ private void AGV_Delivery(int bitNum)
{
- //检测AGV到站信号
- if (BigStation.AGVToWorkStationQueue.Count > 0)
+ if ((ReadSiemens("M4002."+ bitNum) is bool) && BigStation.AgvDeliveryPosition == 0)
{
- int index = BigStation.AGVToWorkStationQueue.ElementAt(0);
-
+ BigStation.AgvDeliveryPosition = 1;
+ WriteHKPLC("M4002."+ bitNum, true);
+ WriteSiemens("M4002."+ bitNum, false);
}
- for (int i = 0; i < 6; i++)
+ else if (ReadHK("M5002."+ bitNum) is bool && BigStation.AgvDeliveryPosition == 1)
{
- switch (BigStation.AgvDeliveryPosition[i])
- {
- case 0:
- if (true)
- {
- BigStation.AgvDeliveryPosition[i] = 1;
- HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVApply, true);
- SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.DeliveryAGVApply,false);
- }
- break;
- case 1:
- if (HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.DeliveryAGVIsApply) is bool)
- {
- BigStation.AgvDeliveryPosition[i] = 2;
- SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.DeliveryAGVIsApply, true);
- }
- break;
- case 2:
- if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.DeliveryAGVApplyJack) is bool))
- {
- BigStation.AgvDeliveryPosition[i] = 3;
- HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVApplyJack, true);
- }
- break;
- case 3:
- if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.DeliveryAGVIsApplyJack) is bool))
- {
- BigStation.AgvDeliveryPosition[i] = 4;
- SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.DeliveryAGVIsApplyJack, true);
- }
- break;
- case 4:
- if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.DeliveryAGVFinsih) is bool))
- {
- BigStation.AgvDeliveryPosition[i] = 5;
- HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVFinsih, true);
- }
- break;
- case 5:
- if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.StationHaveCargo) is bool))
- {
- BigStation.AgvDeliveryPosition[i] = 0;
- SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.StationHaveCargo, true);
- }
- break;
- default:
- break;
- }
- //获取工位上是否有小车
- SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.StationIsExistCar, (bool)
- HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.StationIsExistCar));
+ BigStation.AgvDeliveryPosition = 2;
+ WriteSiemens("M5002."+ bitNum, true);
+ WriteHKPLC("M5002."+ bitNum, false);
+ }
+ else if (ReadSiemens("M4004."+ bitNum) is bool && BigStation.AgvDeliveryPosition == 2)
+ {
+ BigStation.AgvDeliveryPosition = 3;
+ WriteHKPLC("M4004."+ bitNum, true);
+ WriteSiemens("M4004."+ bitNum, false);
+ }
+ else if (ReadHK("M5004."+ bitNum) is bool && BigStation.AgvDeliveryPosition == 3)
+ {
+ BigStation.AgvDeliveryPosition = 4;
+ WriteSiemens("M5004."+ bitNum, true);
+ WriteHKPLC("M5004."+ bitNum, false);
+ }
+ else if (ReadSiemens("M4005."+ bitNum) is bool && BigStation.AgvDeliveryPosition == 4)
+ {
+ BigStation.AgvDeliveryPosition = 5;
+ WriteHKPLC("M4005."+ bitNum, true);
+ WriteSiemens("M4005."+ bitNum, false);
+ }
+ else if (ReadHK("M5005."+ bitNum) is bool && BigStation.AgvDeliveryPosition == 5)
+ {
+ WriteSiemens("M5005."+ bitNum, true);
+ WriteHKPLC("M5005."+ bitNum, false);
}
-
}
///
- /// AGV进站取货
+ /// AGV取货
///
- private void AgvGetInPickUp()
+ ///
+ private void AGV_Pick(int bitNum)
{
- /*switch (BigStation.AgvPickUpPosition)
+ if (ReadSiemens("M4003"+ bitNum) is bool && BigStation.AgvPickUpPosition == 0)
{
- case 0:
- if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.PickAGVApply) is bool))
- {
- BigStation.AgvPickUpPosition = 1;
- HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.PickAGVApply, true);
- }
- break;
- case 1:
- if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.PickAGVIsApply) is bool))
- {
- BigStation.AgvPickUpPosition = 2;
- SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.PickAGVIsApply, true);
- }
- break;
- case 2:
- if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.PickCargoAGVFinish) is bool))
+ BigStation.AgvPickUpPosition = 1;
+ WriteHKPLC("M4003" + bitNum, true);
+ WriteSiemens("M4003" + bitNum, false);
+ }
+ if (ReadHK("M5003" + bitNum) is bool && BigStation.AgvPickUpPosition == 1)
+ {
+ BigStation.AgvPickUpPosition = 2;
+ WriteSiemens("M5003" + bitNum, true);
+ WriteHKPLC("M5003" + bitNum,false);
+ }
+ if (ReadSiemens("M4006" + bitNum) is bool && BigStation.AgvPickUpPosition == 2)
+ {
+ BigStation.AgvPickUpPosition = 3;
+ WriteHKPLC("M4006" + bitNum, true);
+ WriteSiemens("M4006" + bitNum, false);
+ }
+ if (ReadHK("M5006" + bitNum) is bool && BigStation.AgvPickUpPosition == 3)
+ {
+ WriteSiemens("M5006" + bitNum, true);
+ WriteHKPLC("M5006" + bitNum, false);
+ }
+ }
+ ///
+ /// AGV进站送货
+ ///
+ private void AgvGetInOut()
+ {
+ //获取工位上是否有小车
+ SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.StationIsExistCar, (bool)
+ HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.StationIsExistCar));
+ //检测AGV到站信号
+ if (AGVToWorkStationQueue.Count > 0)
+ {
+ int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == AGVToWorkStationQueue.ElementAt(0));
+ int TrayLocation = RemoteRecipes.ElementAt(index).TrayCode;//根据配方编号,找到托盘的ID 托盘ID1-6
+ int recipe = (int)RemoteRecipes.ElementAt(index).RecipeCode;
+ if (TrayLocation > 0 && TrayLocation < 7)
+ {
+ AGV_Delivery(TrayLocation - 1);
+ if (BigStation.AgvDeliveryPosition == 5)
{
- BigStation.AgvPickUpPosition = 3;
- HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.PickCargoAGVFinish, true);
+ BigStation.AgvDeliveryPosition = 0;
+ AGVToWorkStationQueue.TryDequeue(out recipe);
}
- break;
- case 3:
- if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.PickAGVFinish) is bool))
+ AGV_Pick(TrayLocation - 1);
+ if (BigStation.AgvPickUpPosition == 3)
{
BigStation.AgvPickUpPosition = 0;
- SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.PickAGVFinish, true);
+ AGVToWorkStationQueue.TryDequeue(out recipe);
}
- break;
- default:
- break;
- }*/
+ }
+ }
}
private void ReceviceData()
{
- BigStation.RemoteRecipes = Json.Data.Recipes;
- if (Json.Data.Recipes.Count > 0)
+ RemoteRecipes = Json.Data.Recipes;
+ if (RemoteRecipes.Count > 0)
{
- foreach (var data in Json.Data.Recipes)
+ foreach (var data in RemoteRecipes)
{
- if(!(BigStation.RecipeQueue.Contains(data.RecipeCode)))
- BigStation.RecipeQueue.Enqueue(data.RecipeCode);
+ if(!(RecipeQueue.Contains(data.RecipeCode)))
+ RecipeQueue.Enqueue(data.RecipeCode);
}
}
}
@@ -251,19 +262,19 @@ namespace BPASmartClient.JXJFoodBigStation.Model
ushort[] Weight = new ushort[15];
private void RecipeInfoToHKPLC()
{
- if (BigStation.RecipeQueue.Count > 0)
+ if (RecipeQueue.Count > 0)
{
- int index = Array.FindIndex(BigStation.RemoteRecipes.ToArray(), p => p.RecipeCode == BigStation.RecipeQueue.ElementAt(0));
- if (index >= 0 && index <= BigStation.RemoteRecipes.Count)
+ int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == RecipeQueue.ElementAt(0));
+ if (index >= 0 && index <= RemoteRecipes.Count)
{
- long code = BigStation.RemoteRecipes.ElementAt(index).RecipeCode;
+ long code = RemoteRecipes.ElementAt(index).RecipeCode;
if (HKDevice.HK_PLC_S7.Read("M5001.0") is bool)//配方1是否允许下发配发
{
- for (int i = 0; i < BigStation.RemoteRecipes.ElementAt(index).RawMaterial.Count; i++)
+ for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++)
{
- BarrelNum[i] = (ushort)BigStation.RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
- Location[i] = (ushort)BigStation.RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialLocation;
- Weight[i] = (ushort)BigStation.RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialWeight;
+ BarrelNum[i] = (ushort)RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
+ Location[i] = (ushort)RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialLocation;
+ Weight[i] = (ushort)RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialWeight;
}
HKDevice.StockBinPar(BarrelNum, Location, Weight);
HKDevice.HK_PLC_S7.Write("M4001.0", 1);//配发下发完成,to plc
@@ -273,9 +284,8 @@ namespace BPASmartClient.JXJFoodBigStation.Model
if (RTrig.GetInstance("StockState").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.RecipeDosingFinish) is bool))
{
HKDevice.RecipeDosingFinishReset();
- BigStation.RecipeQueue.TryDequeue(out code);
-
- BigStation.IssuedComplete.Add(BigStation.RemoteRecipes.ElementAt(index));//将该配方添加到下
+ RecipeQueue.TryDequeue(out code);
+ IssuedComplete.Add(RemoteRecipes.ElementAt(index));//将该配方添加到下
Json.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
}
}
@@ -289,8 +299,10 @@ namespace BPASmartClient.JXJFoodBigStation.Model
{
GetSiemensStatus("", new Action