using BPASmartClient.Helper; using BPASmartClient.Modbus; using System; using System.Collections.Generic; using System.Linq; using System.Text; using BPASmartClient.CustomResource.Pages.Model; using System.Threading.Tasks; using BPASmartClient.S7Net; using System.Threading; namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC { public class HKDeviceStatus { public SiemensHelper HK_PLC_S7 = new SiemensHelper(); public bool IsConnected => HK_PLC_S7.IsConnected; public DB_Write PlcWrite = new DB_Write(); public DB_Read PlcRead = new DB_Read(); public StockBinName StockBinName = new StockBinName(); public void Init() { if (IsConnected) { ThreadManage.GetInstance().StartLong(new Action(() => { HK_PLC_S7.WriteClass(PlcWrite, 99); var res1 = HK_PLC_S7.ReadClass(98); var res2 = HK_PLC_S7.ReadClass(97); if (res1 != null && res1 is DB_Read data1) { PlcRead = data1; GVL_BigStation.HeartBeatFromPlc = data1.HeartBeat;//读取plc心跳 } if (res2 != null && res2 is StockBinName data2) { StockBinName = data2; } Thread.Sleep(10); }),"信号收发处理"); } } /// /// 下发配方数据 /// public void StockBinPar(RecipeData recipe) { if (IsConnected) { if (recipe != null) { PlcWrite.RecipeCode = Convert.ToInt16(recipe.RecipeCode); PlcWrite.TrayCode = Convert.ToInt16(recipe.TrayCode); for (int barrel = 1; barrel < 6; barrel++) { if (barrel != 3)//桶的编号不为3 只为1,2,4,5号桶 { for (int loc = 1; loc < 15; loc++) { int index = Array.FindIndex(recipe.RawMaterial.ToArray(), p => p.RawMaterialBarrelNum == barrel && p.RawMaterialLocation == loc); if (index == -1) { switch (barrel) { case 1: switch (loc) { case 1: PlcWrite.Bareel1Bin1SetWeight = 0; break; case 2: PlcWrite.Bareel1Bin2SetWeight = 0; break; case 3: PlcWrite.Bareel1Bin3SetWeight = 0; break; case 4: PlcWrite.Bareel1Bin4SetWeight = 0; break; case 5: PlcWrite.Bareel1Bin5SetWeight = 0; break; case 6: PlcWrite.Bareel1Bin6SetWeight = 0; break; case 7: PlcWrite.Bareel1Bin7SetWeight = 0; break; case 8: PlcWrite.Bareel1Bin8SetWeight = 0; break; case 9: PlcWrite.Bareel1Bin9SetWeight = 0; break; case 10: PlcWrite.Bareel1Bin10SetWeight = 0; break; case 11: PlcWrite.Bareel1Bin11SetWeight = 0; break; case 12: PlcWrite.Bareel1Bin12SetWeight = 0; break; case 13: PlcWrite.Bareel1Bin13SetWeight = 0; break; case 14: PlcWrite.Bareel1Bin14SetWeight = 0; break; default: break; } break; case 2: switch (loc) { case 1: PlcWrite.Bareel2Bin1SetWeight = 0; break; case 2: PlcWrite.Bareel2Bin2SetWeight = 0; break; case 3: PlcWrite.Bareel2Bin3SetWeight = 0; break; case 4: PlcWrite.Bareel2Bin4SetWeight = 0; break; case 5: PlcWrite.Bareel2Bin5SetWeight = 0; break; case 6: PlcWrite.Bareel2Bin6SetWeight = 0; break; case 7: PlcWrite.Bareel2Bin7SetWeight = 0; break; case 8: PlcWrite.Bareel2Bin8SetWeight = 0; break; case 9: PlcWrite.Bareel2Bin9SetWeight = 0; break; case 10: PlcWrite.Bareel2Bin10SetWeight = 0; break; case 11: PlcWrite.Bareel2Bin11SetWeight = 0; break; case 12: PlcWrite.Bareel2Bin12SetWeight = 0; break; case 13: PlcWrite.Bareel2Bin13SetWeight = 0; break; case 14: PlcWrite.Bareel2Bin14SetWeight = 0; break; default: break; } break; case 4: switch (loc) { case 1: PlcWrite.Bareel4Bin1SetWeight = 0; break; case 2: PlcWrite.Bareel4Bin2SetWeight = 0; break; case 3: PlcWrite.Bareel4Bin3SetWeight = 0; break; case 4: PlcWrite.Bareel4Bin4SetWeight = 0; break; case 5: PlcWrite.Bareel4Bin5SetWeight = 0; break; case 6: PlcWrite.Bareel4Bin6SetWeight = 0; break; case 7: PlcWrite.Bareel4Bin7SetWeight = 0; break; case 8: PlcWrite.Bareel4Bin8SetWeight = 0; break; case 9: PlcWrite.Bareel4Bin9SetWeight = 0; break; case 10: PlcWrite.Bareel4Bin10SetWeight = 0; break; case 11: PlcWrite.Bareel4Bin11SetWeight = 0; break; case 12: PlcWrite.Bareel4Bin12SetWeight = 0; break; case 13: PlcWrite.Bareel4Bin13SetWeight = 0; break; case 14: PlcWrite.Bareel4Bin14SetWeight = 0; break; default: break; } break; case 5: switch (loc) { case 1: PlcWrite.Bareel5Bin1SetWeight = 0; break; case 2: PlcWrite.Bareel5Bin2SetWeight = 0; break; case 3: PlcWrite.Bareel5Bin3SetWeight = 0; break; case 4: PlcWrite.Bareel5Bin4SetWeight = 0; break; case 5: PlcWrite.Bareel5Bin5SetWeight = 0; break; case 6: PlcWrite.Bareel5Bin6SetWeight = 0; break; case 7: PlcWrite.Bareel5Bin7SetWeight = 0; break; case 8: PlcWrite.Bareel5Bin8SetWeight = 0; break; case 9: PlcWrite.Bareel5Bin9SetWeight = 0; break; case 10: PlcWrite.Bareel5Bin10SetWeight = 0; break; case 11: PlcWrite.Bareel5Bin11SetWeight = 0; break; case 12: PlcWrite.Bareel5Bin12SetWeight = 0; break; case 13: PlcWrite.Bareel5Bin13SetWeight = 0; break; case 14: PlcWrite.Bareel5Bin14SetWeight = 0; break; default: break; } break; default: break; } } else { MessageNotify.GetInstance.ShowRunLog($"配方编号:{recipe.RecipeCode},托盘编号:{recipe.TrayCode},桶号:{barrel},位置:{loc},重量:{recipe.RawMaterial.ElementAt(index).RawMaterialWeight}"); switch (barrel) { case 1: switch (loc) { case 1: PlcWrite.Bareel1Bin1SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 2: PlcWrite.Bareel1Bin2SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 3: PlcWrite.Bareel1Bin3SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 4: PlcWrite.Bareel1Bin4SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 5: PlcWrite.Bareel1Bin5SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 6: PlcWrite.Bareel1Bin6SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 7: PlcWrite.Bareel1Bin7SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 8: PlcWrite.Bareel1Bin8SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 9: PlcWrite.Bareel1Bin9SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 10: PlcWrite.Bareel1Bin10SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 11: PlcWrite.Bareel1Bin11SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 12: PlcWrite.Bareel1Bin12SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 13: PlcWrite.Bareel1Bin13SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 14: PlcWrite.Bareel1Bin14SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; default: break; } break; case 2: switch (loc) { case 1: PlcWrite.Bareel2Bin1SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 2: PlcWrite.Bareel2Bin2SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 3: PlcWrite.Bareel2Bin3SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 4: PlcWrite.Bareel2Bin4SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 5: PlcWrite.Bareel2Bin5SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 6: PlcWrite.Bareel2Bin6SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 7: PlcWrite.Bareel2Bin7SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 8: PlcWrite.Bareel2Bin8SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 9: PlcWrite.Bareel2Bin9SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 10: PlcWrite.Bareel2Bin10SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 11: PlcWrite.Bareel2Bin11SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 12: PlcWrite.Bareel2Bin12SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 13: PlcWrite.Bareel2Bin13SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 14: PlcWrite.Bareel2Bin14SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; default: break; } break; case 4: switch (loc) { case 1: PlcWrite.Bareel4Bin1SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 2: PlcWrite.Bareel4Bin2SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 3: PlcWrite.Bareel4Bin3SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 4: PlcWrite.Bareel4Bin4SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 5: PlcWrite.Bareel4Bin5SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 6: PlcWrite.Bareel4Bin6SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 7: PlcWrite.Bareel4Bin7SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 8: PlcWrite.Bareel4Bin8SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 9: PlcWrite.Bareel4Bin9SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 10: PlcWrite.Bareel4Bin10SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 11: PlcWrite.Bareel4Bin11SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 12: PlcWrite.Bareel4Bin12SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 13: PlcWrite.Bareel4Bin13SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 14: PlcWrite.Bareel4Bin14SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; default: break; } break; case 5: switch (loc) { case 1: PlcWrite.Bareel5Bin1SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 2: PlcWrite.Bareel5Bin2SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 3: PlcWrite.Bareel5Bin3SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 4: PlcWrite.Bareel5Bin4SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 5: PlcWrite.Bareel5Bin5SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 6: PlcWrite.Bareel5Bin6SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 7: PlcWrite.Bareel5Bin7SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 8: PlcWrite.Bareel5Bin8SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 9: PlcWrite.Bareel5Bin9SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 10: PlcWrite.Bareel5Bin10SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 11: PlcWrite.Bareel5Bin11SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 12: PlcWrite.Bareel5Bin12SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 13: PlcWrite.Bareel5Bin13SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; case 14: PlcWrite.Bareel5Bin14SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight; break; default: break; } break; default: break; } } } } } } } } } }