|
|
@@ -25,6 +25,23 @@ namespace BPASmartClient.JXJFoodBigStation.Model |
|
|
|
public SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus(); |
|
|
|
public HKDeviceStatus HKDevice = new HKDeviceStatus(); |
|
|
|
GVL_BigStation BigStation = new GVL_BigStation(); |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 配方数据 |
|
|
|
/// </summary> |
|
|
|
public ObservableCollection<RemoteRecipeData> RemoteRecipes = new ObservableCollection<RemoteRecipeData>(); |
|
|
|
/// <summary> |
|
|
|
/// 配方数据 |
|
|
|
/// </summary> |
|
|
|
public ObservableCollection<RemoteRecipeData> IssuedComplete = new ObservableCollection<RemoteRecipeData>(); |
|
|
|
/// <summary> |
|
|
|
/// 配方队列 |
|
|
|
/// </summary> |
|
|
|
public ConcurrentQueue<long> RecipeQueue = new ConcurrentQueue<long>(); |
|
|
|
/// <summary> |
|
|
|
/// AGV到达工站队列 |
|
|
|
/// </summary> |
|
|
|
public ConcurrentQueue<int> AGVToWorkStationQueue = new ConcurrentQueue<int>(); |
|
|
|
/// <summary> |
|
|
|
/// 接收原料数据 |
|
|
|
/// </summary> |
|
|
@@ -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<RemoteRecipeDataColl>.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<RemoteRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == recipeId); |
|
|
|
if (index >= 0 && index < Json<RemoteRecipeDataColl>.Data.Recipes.Count) |
|
|
|
int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == recipeId); |
|
|
|
if (index >= 0 && index < RemoteRecipes.Count) |
|
|
|
{ |
|
|
|
Json<RemoteRecipeDataColl>.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<RemoteRecipeDataColl>.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); |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// AGV进站送货 |
|
|
|
/// AGV送货 |
|
|
|
/// </summary> |
|
|
|
private void AgvGetInDelivery() |
|
|
|
/// <param name="bitNum"></param> |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// AGV进站取货 |
|
|
|
/// AGV取货 |
|
|
|
/// </summary> |
|
|
|
private void AgvGetInPickUp() |
|
|
|
/// <param name="bitNum"></param> |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// AGV进站送货 |
|
|
|
/// </summary> |
|
|
|
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<RemoteRecipeDataColl>.Data.Recipes; |
|
|
|
if (Json<RemoteRecipeDataColl>.Data.Recipes.Count > 0) |
|
|
|
RemoteRecipes = Json<RemoteRecipeDataColl>.Data.Recipes; |
|
|
|
if (RemoteRecipes.Count > 0) |
|
|
|
{ |
|
|
|
foreach (var data in Json<RemoteRecipeDataColl>.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<RemoteRecipeDataColl>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方 |
|
|
|
} |
|
|
|
} |
|
|
@@ -289,8 +299,10 @@ namespace BPASmartClient.JXJFoodBigStation.Model |
|
|
|
{ |
|
|
|
GetSiemensStatus("", new Action<object>((obj) => |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
if (obj is bool[] bools && bools.Length > 0) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
@@ -298,6 +310,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model |
|
|
|
{ |
|
|
|
if (HKDevice.IsConnected) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
private void GetHKStatus(string key,Action<object> action) |
|
|
|