|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486 |
- 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<DB_Write>(PlcWrite, 99);
- var res1 = HK_PLC_S7.ReadClass<DB_Read>(98);
- var res2 = HK_PLC_S7.ReadClass<StockBinName>(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);
- }),"信号收发处理");
- }
- }
- /// <summary>
- /// 下发配方数据
- /// </summary>
- 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;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
|