|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821 |
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.Helper;
- using BPASmartClient.JXJFoodBigStation.Model.HK_PLC;
- using BPASmartClient.JXJFoodBigStation.Model.Siemens;
- using BPASmartClient.Modbus;
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Configuration;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.JXJFoodBigStation.Model
- {
- public class ProcessControl
- {
- private volatile static ProcessControl _Instance;
- public static ProcessControl GetInstance => _Instance ?? (_Instance = new ProcessControl());
- private ProcessControl() { }
- public SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
- public HKDeviceStatus HKDevice = new HKDeviceStatus();
- DL_Finish_DB FinishData = new DL_Finish_DB();
- /// <summary>
- /// 西门子配方数据
- /// </summary>
- public ObservableCollection<RecipeData> SiemensRecipes = new ObservableCollection<RecipeData>();
- /// <summary>
- /// 本地配方数据
- /// </summary>
- public ObservableCollection<RecipeData> LocalRecipes = new ObservableCollection<RecipeData>();
- /// <summary>
- /// 配方等待执行
- /// </summary>
- public ObservableCollection<RecipeData> RecipeWaitExecute = new ObservableCollection<RecipeData>();
- /// <summary>
- /// 配方正在执行
- /// </summary>
- public ObservableCollection<RecipeData> RecipeExecuting = new ObservableCollection<RecipeData>();
- /// <summary>
- /// 配方执行完成
- /// </summary>
- public ObservableCollection<RecipeData> RecipeExecuteComple = new ObservableCollection<RecipeData>();
- /// <summary>
- /// 原料的名称和料仓的位置对应
- /// </summary>
- public Dictionary<string, short> RawMaterialsNamePos = new Dictionary<string, short>();
- public ObservableCollection<RawMaterial> RawMaterialsInfo => Json<RawMaterialData>.Data.RawMaterial;
- /// <summary>
- /// 西门子配方队列
- /// </summary>
- public ConcurrentQueue<string> SiemensRecipeQueue1 = new ConcurrentQueue<string>();
- public ConcurrentQueue<string> SiemensRecipeQueue2 = new ConcurrentQueue<string>();
- public ConcurrentQueue<string> SiemensRecipeQueue3 = new ConcurrentQueue<string>();
- public ConcurrentQueue<string> SiemensRecipeQueue4 = new ConcurrentQueue<string>();
- /// <summary>
- /// 本地配方队列
- /// </summary>
- public ConcurrentQueue<string> LocalRecipeQueue1 = new ConcurrentQueue<string>();
- public ConcurrentQueue<string> LocalRecipeQueue2 = new ConcurrentQueue<string>();
- public ConcurrentQueue<string> LocalRecipeQueue3 = new ConcurrentQueue<string>();
- public ConcurrentQueue<string> LocalRecipeQueue4 = new ConcurrentQueue<string>();
- public void Init()
- {
- testRawMaterialNameData();//自定义料仓名称
- ActionManage.GetInstance.CancelRegister("SiemensSendRecipe");
- ActionManage.GetInstance.Register(new Action<object>((res) =>
- {
- ObservableCollection<RawMaterial> RawMaterials = new ObservableCollection<RawMaterial>();
- if (SiemensDevice.IsConnected)
- {
- if (res != null && res is DL_Start_DB recipe)
- {
- RawMaterials.Clear();
- for (int i = 0; i < GVL_BigStation.Max_DosingSotckBinNum; i++)
- {
- if (RawMaterialsNamePos.ContainsKey(recipe.Material[i].Material_Name))
- {
- RawMaterials.Add(new RawMaterial()
- {
- RawMaterialName = recipe.Material[i].Material_Name,
- RawMaterialBarrelNum = recipe.Material[i].Material_BarrelNum,
- RawMaterialWeight = recipe.Material[i].Material_Weight,
- RawMaterialLocation = (int)RawMaterialsNamePos[recipe.Material[i].Material_Name]
- });
- }
- else
- {
- MessageNotify.GetInstance.ShowAlarmLog($"本地原料名称和西门子下发的原料名称无法对应,原料位置:{i}");
- }
- }
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.Add(new RecipeData()
- {
- RecipeName = recipe.RecipeName,
- RecipeCode = recipe.RecipeCode,
- RawMaterial = RawMaterials,
- TrayCode = recipe.Job_No,
- IsWashingBarrel = recipe.Order_Type
- });
- });
- }
- }
- }), "SiemensSendRecipe", true);
- string HK_PLC_IP = ConfigurationManager.AppSettings["HKPlc_IP"];
- string Siemens_PLC_IP = ConfigurationManager.AppSettings["Siemens_IP"];
- GVL_BigStation.IsAllowHKPlcConnect = ConfigurationManager.AppSettings["HKPlc_Connect"].ToLower() == "true" ? true : false;
- GVL_BigStation.IsAllowSiemensConnect = ConfigurationManager.AppSettings["Siemens_Connect"].ToLower() == "true" ? true : false;
- try
- {
- if (GVL_BigStation.IsAllowHKPlcConnect)
- {
- HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71500, HK_PLC_IP);
- }
- }
- catch (Exception ex)
- {
- MessageNotify.GetInstance.ShowAlarmLog("海科plc连接失败,等待重新连接");
- }
- finally
- {
- HKDevice.Init();
- MessageNotify.GetInstance.ShowRunLog("海科plc初始化");
- if (HKDevice.IsConnected && GVL_BigStation.IsAllowHKPlcConnect)
- {
- MessageNotify.GetInstance.ShowRunLog("海科plc连接成功");
- }
- }
- try
- {
- if (GVL_BigStation.IsAllowSiemensConnect)
- {
- SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
- }
- }
- catch (Exception ex)
- {
- MessageNotify.GetInstance.ShowAlarmLog("西门子plc连接失败,等待重新连接");
- }
- finally
- {
- SiemensDevice.Init();
- MessageNotify.GetInstance.ShowRunLog("西门子plc初始化");
- if (SiemensDevice.IsConnected && GVL_BigStation.IsAllowSiemensConnect)
- {
- MessageNotify.GetInstance.ShowRunLog("西门子plc连接成功");
- }
- }
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- if (!HKDevice.IsConnected && GVL_BigStation.IsAllowHKPlcConnect)
- {
- HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71500, HK_PLC_IP);
- MessageNotify.GetInstance.ShowRunLog("海科plc重新连接成功");
- }
- if (!SiemensDevice.IsConnected && GVL_BigStation.IsAllowSiemensConnect)
- {
- SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
- MessageNotify.GetInstance.ShowRunLog("西门子plc重新连接");
- }
- GVL_BigStation.HeartBeatToPlc = !GVL_BigStation.HeartBeatToPlc;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.0", GVL_BigStation.HeartBeatToPlc);
- GVL_BigStation.HeartBeatFromPlc = HKDevice.PlcRead.HeartBeat;//读取plc心跳
- if (HKDevice.IsConnected)
- {
- if (GVL_BigStation.AGVPutTray.GetBitValue(1))
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", true);
- }
- else
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
- }
- if (GVL_BigStation.AGVPutTray.GetBitValue(2))
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", true);
- }
- else
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
- }
- if (GVL_BigStation.AGVPutTray.GetBitValue(3))
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", true);
- }
- else
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
- }
- if (GVL_BigStation.AGVPutTray.GetBitValue(4))
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", true);
- }
- else
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
- }
- if (GVL_BigStation.AGVPutTray.GetBitValue(5))
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", true);
- }
- else
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
- }
- GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(1, HKDevice.PlcRead.Tray1Sensor);
- GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(2, HKDevice.PlcRead.Tray2Sensor);
- GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(3, HKDevice.PlcRead.Tray3Sensor);
- GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(4, HKDevice.PlcRead.Tray4Sensor);
- GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(5, HKDevice.PlcRead.Tray5Sensor);
- GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(1, !HKDevice.PlcRead.Tray1Cylinder);
- GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(2, !HKDevice.PlcRead.Tray2Cylinder);
- GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(3, !HKDevice.PlcRead.Tray3Cylinder);
- GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(4, !HKDevice.PlcRead.Tray4Cylinder);
- GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(5, !HKDevice.PlcRead.Tray5Cylinder);
- if (HKDevice.PlcRead.IsAllowIssueRecipe1 || HKDevice.PlcRead.IsAllowIssueRecipe2 || HKDevice.PlcRead.IsAllowIssueRecipe3 || HKDevice.PlcRead.IsAllowIssueRecipe4)
- {
- GVL_BigStation.Order_Request = true;
- }
- }
- if (SiemensDevice.IsConnected)
- {
- GVL_BigStation.AGVPutTray = SiemensDevice.DL_Status.AGV_Put_Done;
- GVL_BigStation.AGVGetTray = SiemensDevice.DL_Status.AGV_Get_Done;
- SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBW30", GVL_BigStation.TraySensor);
- SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBW32", GVL_BigStation.TrayCylinder);
- SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBW34", (ushort)15);
- }
- Thread.Sleep(10);
- }),"海科plc和西门子数据交互",true);
- LocalRecipeQueue1.Clear();
- LocalRecipeQueue2.Clear();
- LocalRecipeQueue3.Clear();
- LocalRecipeQueue4.Clear();
- SiemensRecipeQueue1.Clear();
- SiemensRecipeQueue2.Clear();
- SiemensRecipeQueue3.Clear();
- SiemensRecipeQueue4.Clear();
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- testRawMaterialNameData();//自定义料仓名称
- if (GVL_BigStation.IsUseLocalRecipe)
- {
- LocalRecipeRecevice();
- LocalRecipeDosing();
- }
- else
- {
- ReceviceData();
- RecipeInfoToHKPLC();
- }
- Thread.Sleep(10);
- }), "配方数据执行流程", true);
- }
- private void LocalRecipeRecevice()
- {
- if (LocalRecipes.Count > 0)
- {
- foreach (var data in LocalRecipes)
- {
- if (LocalRecipeQueue1.Count == 0 && !LocalRecipeQueue2.Contains(data.RecipeCode) && !LocalRecipeQueue3.Contains(data.RecipeCode) && !LocalRecipeQueue4.Contains(data.RecipeCode))
- {
- if (!(LocalRecipeQueue1.Contains(data.RecipeCode)))
- {
- LocalRecipeQueue1.Enqueue(data.RecipeCode);
- }
- }
- else if (LocalRecipeQueue2.Count == 0 && !LocalRecipeQueue1.Contains(data.RecipeCode) && !LocalRecipeQueue3.Contains(data.RecipeCode) && !LocalRecipeQueue4.Contains(data.RecipeCode))
- {
- if (!(LocalRecipeQueue2.Contains(data.RecipeCode)))
- {
- LocalRecipeQueue2.Enqueue(data.RecipeCode);
- }
- }
- else if (LocalRecipeQueue3.Count == 0 && !LocalRecipeQueue1.Contains(data.RecipeCode) && !LocalRecipeQueue2.Contains(data.RecipeCode) && !LocalRecipeQueue4.Contains(data.RecipeCode))
- {
- if (!(LocalRecipeQueue3.Contains(data.RecipeCode)))
- {
- LocalRecipeQueue3.Enqueue(data.RecipeCode);
- }
- }
- else if (LocalRecipeQueue4.Count == 0 && !LocalRecipeQueue1.Contains(data.RecipeCode) && !LocalRecipeQueue2.Contains(data.RecipeCode) && !LocalRecipeQueue3.Contains(data.RecipeCode))
- {
- if (!(LocalRecipeQueue4.Contains(data.RecipeCode)))
- {
- LocalRecipeQueue4.Enqueue(data.RecipeCode);
- }
- }
- }
- }
- else
- {
- LocalRecipeQueue1.Clear();
- LocalRecipeQueue2.Clear();
- LocalRecipeQueue3.Clear();
- LocalRecipeQueue4.Clear();
- GVL_BigStation.Recipe1DosingStatus = 0;
- GVL_BigStation.Recipe2DosingStatus = 0;
- GVL_BigStation.Recipe3DosingStatus = 0;
- GVL_BigStation.Recipe4DosingStatus = 0;
- }
- }
- private void LocalRecipeDosing()
- {
- if (LocalRecipeQueue1.Count > 0)
- {
- int index = Array.FindIndex(LocalRecipes.ToArray(), p => p.RecipeCode == LocalRecipeQueue1.ElementAt(0));
- if (index >= 0 && index < LocalRecipes.Count)
- {
- string code = LocalRecipes.ElementAt(index).RecipeCode;
- int trayCode = LocalRecipes.ElementAt(index).TrayCode;
- bool Inplace = false;
- switch (trayCode)
- {
- case 1:
- Inplace = HKDevice.PlcRead.Tray1InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", GVL_BigStation.AGVPutTray.GetBitValue(1));
- break;
- case 2:
- Inplace = HKDevice.PlcRead.Tray2InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", GVL_BigStation.AGVPutTray.GetBitValue(2));
- break;
- case 3:
- Inplace = HKDevice.PlcRead.Tray3InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", GVL_BigStation.AGVPutTray.GetBitValue(3));
- break;
- case 4:
- Inplace = HKDevice.PlcRead.Tray4InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", GVL_BigStation.AGVPutTray.GetBitValue(4));
- break;
- case 5:
- Inplace = HKDevice.PlcRead.Tray5InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", GVL_BigStation.AGVPutTray.GetBitValue(5));
- break;
- default:
- break;
- }
- if (HKDevice.PlcRead.IsAllowIssueRecipe1 && GVL_BigStation.Recipe1DosingStatus == 0 && Inplace)//配方1是否允许下发配发
- {
- HKDevice.StockBinPar(LocalRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true);
- GVL_BigStation.Recipe1DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- if (HKDevice.PlcRead.ReceiveFinishRecipe1 && GVL_BigStation.Recipe1DosingStatus == 1)
- {
- GVL_BigStation.Recipe1DosingStatus = 2;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", false);
- StockBinParReset();
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
- }
- if (GVL_BigStation.Recipe1DosingStatus == 2 && HKDevice.PlcRead.Recipe1DosingFinish)
- {
- GVL_BigStation.Recipe1DosingStatus = 3;
- switch (trayCode)
- {
- case 1:
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
- break;
- case 2:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
- break;
- case 3:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
- break;
- case 4:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
- break;
- case 5:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
- break;
- default:
- break;
- }
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
- foreach (var item in LocalRecipes.ElementAt(index).RawMaterial)
- {
- if (item.RawMaterialLocation == 1)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
- }
- else if (item.RawMaterialLocation == 2)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
- }
- else if (item.RawMaterialLocation == 3)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
- }
- else if (item.RawMaterialLocation == 4)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
- }
- else if (item.RawMaterialLocation == 5)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
- }
- else if (item.RawMaterialLocation == 6)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
- }
- else if (item.RawMaterialLocation == 7)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
- }
- else if (item.RawMaterialLocation == 8)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
- }
- else if (item.RawMaterialLocation == 9)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
- }
- else if (item.RawMaterialLocation == 10)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
- }
- else if (item.RawMaterialLocation == 11)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
- }
- else if (item.RawMaterialLocation == 12)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
- }
- else if (item.RawMaterialLocation == 13)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
- }
- else if (item.RawMaterialLocation == 14)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
- }
- }
- LocalRecipeQueue1.TryDequeue(out code);
- RecipeExecuteComple.Add(LocalRecipes.ElementAt(index));//将配方添加到完成列表
- //App.Current.Dispatcher.Invoke(() => {
- // Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- //});
- LocalRecipes.RemoveAt(index);
- GVL_BigStation.Recipe1DosingStatus = 0;
- }
- }
- }
- if (LocalRecipeQueue2.Count > 0)
- {
- int index = Array.FindIndex(LocalRecipes.ToArray(), p => p.RecipeCode == LocalRecipeQueue2.ElementAt(0));
- if (index >= 0 && index < LocalRecipes.Count)
- {
- string code = LocalRecipes.ElementAt(index).RecipeCode;
- int trayCode = LocalRecipes.ElementAt(index).TrayCode;
- bool Inplace = false;
- switch (trayCode)
- {
- case 1:
- Inplace = HKDevice.PlcRead.Tray1InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", GVL_BigStation.AGVPutTray.GetBitValue(1));
- break;
- case 2:
- Inplace = HKDevice.PlcRead.Tray2InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", GVL_BigStation.AGVPutTray.GetBitValue(2));
- break;
- case 3:
- Inplace = HKDevice.PlcRead.Tray3InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", GVL_BigStation.AGVPutTray.GetBitValue(3));
- break;
- case 4:
- Inplace = HKDevice.PlcRead.Tray4InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", GVL_BigStation.AGVPutTray.GetBitValue(4));
- break;
- case 5:
- Inplace = HKDevice.PlcRead.Tray5InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", GVL_BigStation.AGVPutTray.GetBitValue(5));
- break;
- default:
- break;
- }
- if (HKDevice.PlcRead.IsAllowIssueRecipe2 && GVL_BigStation.Recipe2DosingStatus == 0 &&Inplace)//配方2是否允许下发配发
- {
- HKDevice.StockBinPar(LocalRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", true);
- GVL_BigStation.Recipe2DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
- }
- if (HKDevice.PlcRead.ReceiveFinishRecipe2 && GVL_BigStation.Recipe2DosingStatus == 1)
- {
- GVL_BigStation.Recipe2DosingStatus = 2;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", false);
- StockBinParReset();
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配方配料");
- }
- if (GVL_BigStation.Recipe2DosingStatus == 2 && HKDevice.PlcRead.Recipe2DosingFinish)
- {
- switch (trayCode)
- {
- case 1:
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
- break;
- case 2:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
- break;
- case 3:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
- break;
- case 4:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
- break;
- case 5:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
- break;
- default:
- break;
- }
- GVL_BigStation.Recipe2DosingStatus = 3;
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
- foreach (var item in LocalRecipes.ElementAt(index).RawMaterial)
- {
- if (item.RawMaterialLocation == 1)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
- }
- else if (item.RawMaterialLocation == 2)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
- }
- else if (item.RawMaterialLocation == 3)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
- }
- else if (item.RawMaterialLocation == 4)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
- }
- else if (item.RawMaterialLocation == 5)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
- }
- else if (item.RawMaterialLocation == 6)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
- }
- else if (item.RawMaterialLocation == 7)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
- }
- else if (item.RawMaterialLocation == 8)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
- }
- else if (item.RawMaterialLocation == 9)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
- }
- else if (item.RawMaterialLocation == 10)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
- }
- else if (item.RawMaterialLocation == 11)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
- }
- else if (item.RawMaterialLocation == 12)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
- }
- else if (item.RawMaterialLocation == 13)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
- }
- else if (item.RawMaterialLocation == 14)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
- }
- }
- LocalRecipeQueue2.TryDequeue(out code);
- RecipeExecuteComple.Add(LocalRecipes.ElementAt(index));//将该配方添加到下
- //App.Current.Dispatcher.Invoke(() => {
- // Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- //});
- LocalRecipes.RemoveAt(index);
- GVL_BigStation.Recipe2DosingStatus = 0;
- }
- }
- }
- if (LocalRecipeQueue3.Count > 0)
- {
- int index = Array.FindIndex(LocalRecipes.ToArray(), p => p.RecipeCode == LocalRecipeQueue3.ElementAt(0));
- if (index >= 0 && index < LocalRecipes.Count)
- {
- string code = LocalRecipes.ElementAt(index).RecipeCode;
- int trayCode = LocalRecipes.ElementAt(index).TrayCode;
- bool Inplace = false;
- switch (trayCode)
- {
- case 1:
- Inplace = HKDevice.PlcRead.Tray1InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", GVL_BigStation.AGVPutTray.GetBitValue(1));
- break;
- case 2:
- Inplace = HKDevice.PlcRead.Tray2InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", GVL_BigStation.AGVPutTray.GetBitValue(2));
- break;
- case 3:
- Inplace = HKDevice.PlcRead.Tray3InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", GVL_BigStation.AGVPutTray.GetBitValue(3));
- break;
- case 4:
- Inplace = HKDevice.PlcRead.Tray4InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", GVL_BigStation.AGVPutTray.GetBitValue(4));
- break;
- case 5:
- Inplace = HKDevice.PlcRead.Tray5InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", GVL_BigStation.AGVPutTray.GetBitValue(5));
- break;
- default:
- break;
- }
- if (HKDevice.PlcRead.IsAllowIssueRecipe3 && GVL_BigStation.Recipe3DosingStatus == 0 && Inplace)//配方3是否允许下发配发
- {
- HKDevice.StockBinPar(LocalRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", true);
- GVL_BigStation.Recipe3DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
- }
- if (HKDevice.PlcRead.ReceiveFinishRecipe3 && GVL_BigStation.Recipe3DosingStatus == 1)
- {
- GVL_BigStation.Recipe3DosingStatus = 2;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", false);
- StockBinParReset();
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配方配料");
- }
- if (HKDevice.PlcRead.Recipe3DosingFinish && GVL_BigStation.Recipe3DosingStatus == 2)
- {
- switch (trayCode)
- {
- case 1:
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
- break;
- case 2:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
- break;
- case 3:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
- break;
- case 4:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
- break;
- case 5:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
- break;
- default:
- break;
- }
- GVL_BigStation.Recipe3DosingStatus = 3;
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
- foreach (var item in LocalRecipes.ElementAt(index).RawMaterial)
- {
- if (item.RawMaterialLocation == 1)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
- }
- else if (item.RawMaterialLocation == 2)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
- }
- else if (item.RawMaterialLocation == 3)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
- }
- else if (item.RawMaterialLocation == 4)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
- }
- else if (item.RawMaterialLocation == 5)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
- }
- else if (item.RawMaterialLocation == 6)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
- }
- else if (item.RawMaterialLocation == 7)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
- }
- else if (item.RawMaterialLocation == 8)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
- }
- else if (item.RawMaterialLocation == 9)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
- }
- else if (item.RawMaterialLocation == 10)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
- }
- else if (item.RawMaterialLocation == 11)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
- }
- else if (item.RawMaterialLocation == 12)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
- }
- else if (item.RawMaterialLocation == 13)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
- }
- else if (item.RawMaterialLocation == 14)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
- }
- }
- HKDevice.HK_PLC_S7.Write<bool>("DB98.DBX1.1", false);
- LocalRecipeQueue3.TryDequeue(out code);
- RecipeExecuteComple.Add(LocalRecipes.ElementAt(index));//将该配方添加到下
- //App.Current.Dispatcher.Invoke(() => {
- // Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- //});
- LocalRecipes.RemoveAt(index);
- GVL_BigStation.Recipe3DosingStatus = 0;
- }
- }
- }
- if (LocalRecipeQueue4.Count > 0)
- {
- int index = Array.FindIndex(LocalRecipes.ToArray(), p => p.RecipeCode == LocalRecipeQueue4.ElementAt(0));
- if (index >= 0 && index < LocalRecipes.Count)
- {
- string code = LocalRecipes.ElementAt(index).RecipeCode;
- int trayCode = LocalRecipes.ElementAt(index).TrayCode;
- bool Inplace = false;
- switch (trayCode)
- {
- case 1:
- Inplace = HKDevice.PlcRead.Tray1InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", GVL_BigStation.AGVPutTray.GetBitValue(1));
- break;
- case 2:
- Inplace = HKDevice.PlcRead.Tray2InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", GVL_BigStation.AGVPutTray.GetBitValue(2));
- break;
- case 3:
- Inplace = HKDevice.PlcRead.Tray3InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", GVL_BigStation.AGVPutTray.GetBitValue(3));
- break;
- case 4:
- Inplace = HKDevice.PlcRead.Tray4InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", GVL_BigStation.AGVPutTray.GetBitValue(4));
- break;
- case 5:
- Inplace = HKDevice.PlcRead.Tray5InPlace;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", GVL_BigStation.AGVPutTray.GetBitValue(5));
- break;
- default:
- break;
- }
- if (HKDevice.PlcRead.IsAllowIssueRecipe4 && GVL_BigStation.Recipe4DosingStatus == 0 && Inplace)//配方4是否允许下发配发
- {
- HKDevice.StockBinPar(LocalRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", true);
- GVL_BigStation.Recipe4DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
- }
- if (HKDevice.PlcRead.ReceiveFinishRecipe4 && GVL_BigStation.Recipe4DosingStatus == 1)
- {
- GVL_BigStation.Recipe4DosingStatus = 2;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", false);
- StockBinParReset();
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配方配料");
- }
- if (GVL_BigStation.Recipe4DosingStatus == 2 && HKDevice.PlcRead.Recipe4DosingFinish)
- {
- switch (trayCode)
- {
- case 1:
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
- break;
- case 2:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
- break;
- case 3:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
- break;
- case 4:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
- break;
- case 5:
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
- break;
- default:
- break;
- }
- GVL_BigStation.Recipe4DosingStatus = 3;
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
- foreach (var item in LocalRecipes.ElementAt(index).RawMaterial)
- {
- if (item.RawMaterialLocation == 1)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
- }
- else if (item.RawMaterialLocation == 2)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
- }
- else if (item.RawMaterialLocation == 3)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
- }
- else if (item.RawMaterialLocation == 4)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
- }
- else if (item.RawMaterialLocation == 5)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
- }
- else if (item.RawMaterialLocation == 6)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
- }
- else if (item.RawMaterialLocation == 7)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
- }
- else if (item.RawMaterialLocation == 8)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
- }
- else if (item.RawMaterialLocation == 9)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
- }
- else if (item.RawMaterialLocation == 10)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
- }
- else if (item.RawMaterialLocation == 11)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
- }
- else if (item.RawMaterialLocation == 12)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
- }
- else if (item.RawMaterialLocation == 13)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
- }
- else if (item.RawMaterialLocation == 14)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
- }
- }
- HKDevice.HK_PLC_S7.Write<bool>("DB98.DBX1.3", false);
- LocalRecipeQueue4.TryDequeue(out code);
- RecipeExecuteComple.Add(LocalRecipes.ElementAt(index));//将该配方添加到下
- //App.Current.Dispatcher.Invoke(() => {
- // Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- //});
- LocalRecipes.RemoveAt(index);
- GVL_BigStation.Recipe4DosingStatus = 0;
- }
- }
- }
- }
- private void ReceviceData()
- {
- SiemensRecipes = Json<RemoteRecipe>.Data.Recipes;
- if (SiemensRecipes.Count > 0)
- {
- foreach (var data in SiemensRecipes)
- {
- if (SiemensRecipeQueue1.Count == 0 && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode))
- {
- if (!(SiemensRecipeQueue1.Contains(data.RecipeCode)))
- {
- if (SiemensDevice.DL_Status is DL_Status_DB status)
- {
- if (GVL_BigStation.SiemensSendRecipeStatus == 3)
- {
- SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
- MessageNotify.GetInstance.ShowRunLog($"配方1,发送配方编号和请求配料标志给西门子");
- GVL_BigStation.SiemensSendRecipeStatus = 4;
- }
- if (GVL_BigStation.SiemensSendRecipeStatus == 4)
- {
- if (SiemensDevice.DL_Status.Dosing_Start_ACK)
- {
- SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false);
- MessageNotify.GetInstance.ShowRunLog($"配方1,西门子确认开始配料");
- GVL_BigStation.SiemensSendRecipeStatus = 5;
- }
- }
- if (GVL_BigStation.SiemensSendRecipeStatus == 5)
- {
- if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
- {
- SiemensRecipeQueue1.Enqueue(data.RecipeCode);
- MessageNotify.GetInstance.ShowRunLog($"配方1,配方:{data.RecipeCode},加入队列");
- GVL_BigStation.SiemensSendRecipeStatus = 0;
- }
- }
- }
- }
- }
- else if (SiemensRecipeQueue2.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode))
- {
- if (!(SiemensRecipeQueue2.Contains(data.RecipeCode)))
- {
- if (SiemensDevice.DL_Status is DL_Status_DB status)
- {
- if (GVL_BigStation.SiemensSendRecipeStatus == 3)
- {
- SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
- MessageNotify.GetInstance.ShowRunLog($"配方2,发送配方编号和请求配料标志给西门子");
- GVL_BigStation.SiemensSendRecipeStatus = 4;
- }
- if (GVL_BigStation.SiemensSendRecipeStatus == 4)
- {
- if (SiemensDevice.DL_Status.Dosing_Start_ACK)
- {
- SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false);
- MessageNotify.GetInstance.ShowRunLog($"配方2,西门子确认开始配料");
- GVL_BigStation.SiemensSendRecipeStatus = 5;
- }
- }
- if (GVL_BigStation.SiemensSendRecipeStatus == 5)
- {
- if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
- {
- SiemensRecipeQueue2.Enqueue(data.RecipeCode);
- MessageNotify.GetInstance.ShowRunLog($"配方2,配方:{data.RecipeCode},加入队列");
- GVL_BigStation.SiemensSendRecipeStatus = 0;
- }
- }
- }
- }
- }
- else if (SiemensRecipeQueue3.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode))
- {
- if (!(SiemensRecipeQueue3.Contains(data.RecipeCode)))
- {
- if (SiemensDevice.DL_Status is DL_Status_DB status)
- {
- if (GVL_BigStation.SiemensSendRecipeStatus == 3)
- {
- SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
- MessageNotify.GetInstance.ShowRunLog($"配方3,发送配方编号和请求配料标志给西门子");
- GVL_BigStation.SiemensSendRecipeStatus = 4;
- }
- if (GVL_BigStation.SiemensSendRecipeStatus == 4)
- {
- if (SiemensDevice.DL_Status.Dosing_Start_ACK)
- {
- SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false);
- MessageNotify.GetInstance.ShowRunLog($"配方3,西门子确认开始配料");
- GVL_BigStation.SiemensSendRecipeStatus = 5;
- }
- }
- if (GVL_BigStation.SiemensSendRecipeStatus == 5)
- {
- if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
- {
- SiemensRecipeQueue3.Enqueue(data.RecipeCode);
- MessageNotify.GetInstance.ShowRunLog($"配方3,配方:{data.RecipeCode},加入队列");
- GVL_BigStation.SiemensSendRecipeStatus = 0;
- }
- }
- }
- }
- }
- else if (SiemensRecipeQueue4.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode))
- {
- if (!(SiemensRecipeQueue4.Contains(data.RecipeCode)))
- {
- if (SiemensDevice.DL_Status is DL_Status_DB status)
- {
- if (GVL_BigStation.SiemensSendRecipeStatus == 3)
- {
- SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
- MessageNotify.GetInstance.ShowRunLog($"配方4,发送配方编号和请求配料标志给西门子");
- GVL_BigStation.SiemensSendRecipeStatus = 4;
- }
- if (GVL_BigStation.SiemensSendRecipeStatus == 4)
- {
- if (SiemensDevice.DL_Status.Dosing_Start_ACK)
- {
- SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false);
- MessageNotify.GetInstance.ShowRunLog($"配方4,西门子确认开始配料");
- GVL_BigStation.SiemensSendRecipeStatus = 5;
- }
- }
- if (GVL_BigStation.SiemensSendRecipeStatus == 5)
- {
- if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
- {
- SiemensRecipeQueue4.Enqueue(data.RecipeCode);
- MessageNotify.GetInstance.ShowRunLog($"配方4,配方:{data.RecipeCode},加入队列");
- GVL_BigStation.SiemensSendRecipeStatus = 0;
- }
- }
- }
- }
- }
- }
- }
- else
- {
- SiemensRecipeQueue1.Clear();
- SiemensRecipeQueue2.Clear();
- SiemensRecipeQueue3.Clear();
- SiemensRecipeQueue4.Clear();
- GVL_BigStation.Recipe1DosingStatus = 0;
- GVL_BigStation.Recipe2DosingStatus = 0;
- GVL_BigStation.Recipe3DosingStatus = 0;
- GVL_BigStation.Recipe4DosingStatus = 0;
- }
-
- if (GVL_BigStation.Order_Cancel) //订单取消
- {
- if (!string.IsNullOrEmpty(GVL_BigStation.Order_CancelRecipeCode))
- {
- int index = Array.FindIndex(Json<RemoteRecipe>.Data.Recipes.ToArray(), p => p.RecipeCode == GVL_BigStation.Order_CancelRecipeCode);
- if (index >= 0)
- {
- string code = GVL_BigStation.Order_CancelRecipeCode;
- short TrayCode = (short)Json<RemoteRecipe>.Data.Recipes.ElementAt(index).TrayCode;
- if (SiemensRecipeQueue1.Contains(code) || SiemensRecipeQueue2.Contains(code) || SiemensRecipeQueue3.Contains(code) || SiemensRecipeQueue4.Contains(code))
- {
- if (SiemensRecipeQueue1.Contains(code))
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
- });
- if (GVL_BigStation.Recipe1DosingStatus != 0)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true);
- HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode);
- MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:{code}");
- }
- GVL_BigStation.Recipe1DosingStatus = 0;
- SiemensRecipeQueue1.TryDequeue(out code);
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX320.2", false);
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- MessageNotify.GetInstance.ShowRunLog($"队列1,西门子取消订单完成,订单号:{code}");
- }
- if (SiemensRecipeQueue2.Contains(code))
- {
- GVL_BigStation.Recipe2DosingStatus = 0;
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
- });
- if (GVL_BigStation.Recipe2DosingStatus != 0)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true);
- HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode);
- MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:{code}");
- }
- GVL_BigStation.Recipe2DosingStatus = 0;
- SiemensRecipeQueue2.TryDequeue(out code);
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX320.2", false);
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- MessageNotify.GetInstance.ShowRunLog($"队列2,西门子取消订单完成,订单号:{code}");
- }
- if (SiemensRecipeQueue3.Contains(code))
- {
- GVL_BigStation.Recipe3DosingStatus = 0;
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
- });
- if (GVL_BigStation.Recipe3DosingStatus != 0)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true);
- HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode);
- MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:{code}");
- }
- GVL_BigStation.Recipe3DosingStatus = 0;
- SiemensRecipeQueue3.TryDequeue(out code);
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX320.2", false);
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- MessageNotify.GetInstance.ShowRunLog($"队列3,西门子取消订单完成,订单号:{code}");
- }
- if (SiemensRecipeQueue4.Contains(code))
- {
- GVL_BigStation.Recipe4DosingStatus = 0;
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
- });
- if (GVL_BigStation.Recipe4DosingStatus != 0)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true);
- HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode);
- MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:{code}");
- }
- GVL_BigStation.Recipe4DosingStatus = 0;
- SiemensRecipeQueue4.TryDequeue(out code);
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX320.2", false);
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- MessageNotify.GetInstance.ShowRunLog($"队列4,西门子取消订单完成,订单号:{code}");
- }
- GVL_BigStation.Order_Cancel = false;
- GVL_BigStation.Order_CancelRecipeCode = "";
- }
- else
- {
- if (GVL_BigStation.SiemensSendRecipeStatus != 0 || GVL_BigStation.SiemensSendRecipeStatus != 1)
- {
- GVL_BigStation.SiemensSendRecipeStatus = 0;
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
- });
- MessageNotify.GetInstance.ShowRunLog($"正在执行请求订单流程,配方还未到PLC,订单号:{GVL_BigStation.Order_CancelRecipeCode}");
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"订单取消异常,订单号:{GVL_BigStation.Order_CancelRecipeCode}");
- }
-
- GVL_BigStation.Order_Cancel = false;
- GVL_BigStation.Order_CancelRecipeCode = "";
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX320.2", false);
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- }
- }
- else
- {
- GVL_BigStation.Order_Cancel = false;
- GVL_BigStation.Order_CancelRecipeCode = "";
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX320.2", false);
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- MessageNotify.GetInstance.ShowRunLog($"西门子取消订单,但未找到订单:{GVL_BigStation.Order_CancelRecipeCode}");
- }
- }
- }
- }
- private void RecipeInfoToHKPLC()
- {
- if (SiemensRecipeQueue1.Count > 0)
- {
- int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == SiemensRecipeQueue1.ElementAt(0));
- if (index >= 0 && index < SiemensRecipes.Count)
- {
- string code = SiemensRecipes.ElementAt(index).RecipeCode;
- int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
- bool Inplace = false;
- switch (trayCode)
- {
- case 1:
- Inplace = HKDevice.PlcRead.Tray1InPlace;
- break;
- case 2:
- Inplace = HKDevice.PlcRead.Tray2InPlace;
- break;
- case 3:
- Inplace = HKDevice.PlcRead.Tray3InPlace;
- break;
- case 4:
- Inplace = HKDevice.PlcRead.Tray4InPlace;
- break;
- case 5:
- Inplace = HKDevice.PlcRead.Tray5InPlace;
- break;
- default:
- break;
- }
- if (HKDevice.PlcRead.IsAllowIssueRecipe1 && GVL_BigStation.Recipe1DosingStatus == 0 && Inplace)//配方1是否允许下发配发
- {
- GVL_BigStation.DosingRecipe1Time = DateTime.Now;
- HKDevice.StockBinPar(SiemensRecipes.ElementAt(index));
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
- }
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true);
- GVL_BigStation.Recipe1DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- if (HKDevice.PlcRead.ReceiveFinishRecipe1 && GVL_BigStation.Recipe1DosingStatus == 1)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", false);
- StockBinParReset();
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
- GVL_BigStation.Recipe1DosingStatus = 2;
- }
- if (GVL_BigStation.Recipe1DosingStatus == 2 && HKDevice.PlcRead.Recipe1DosingFinish)
- {
- GVL_BigStation.Recipe1DosingFinish = true;
- GVL_BigStation.Recipe1DosingStatus = 3;
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
- foreach (var item in SiemensRecipes.ElementAt(index).RawMaterial)
- {
- if (item.RawMaterialLocation == 1)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
- }
- else if (item.RawMaterialLocation == 2)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
- }
- else if (item.RawMaterialLocation == 3)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
- }
- else if (item.RawMaterialLocation == 4)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
- }
- else if (item.RawMaterialLocation == 5)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
- }
- else if (item.RawMaterialLocation == 6)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
- }
- else if (item.RawMaterialLocation == 7)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
- }
- else if (item.RawMaterialLocation == 8)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
- }
- else if (item.RawMaterialLocation == 9)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
- }
- else if (item.RawMaterialLocation == 10)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
- }
- else if (item.RawMaterialLocation == 11)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
- }
- else if (item.RawMaterialLocation == 12)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
- }
- else if (item.RawMaterialLocation == 13)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
- }
- else if (item.RawMaterialLocation == 14)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
- }
- }
- if (SiemensDevice.IsConnected)
- {
- FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode;
- FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName;
- FinishData.job_No = (short)SiemensRecipes.ElementAt(index).TrayCode;
- for (int i = 0; i < FinishData.Material.Length; i++)
- {
- FinishData.Material[i] = new UDT1();
- }
- for (int i = 0; i < SiemensRecipes.ElementAt(index).RawMaterial.Count; i++)
- {
- FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
- FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
- FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight);
- }
- FinishData.Ask_For_Finish = true;
- double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe1Time).TotalSeconds;
- FinishData.ProcessTime = Convert.ToInt16(a);
- SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
- MessageNotify.GetInstance.ShowRunLog($"配方配料完成,将信号反馈给西门子");
- }
- SiemensRecipeQueue1.TryDequeue(out code);
- RecipeExecuteComple.Add(SiemensRecipes.ElementAt(index));//将配方添加到完成列表
- if (!GVL_BigStation.IsUseLocalRecipe)
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- });
- }
- else
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- });
- }
- GVL_BigStation.Recipe1DosingStatus = 0;
- }
- }
- }
- if (SiemensRecipeQueue2.Count > 0)
- {
- int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == SiemensRecipeQueue2.ElementAt(0));
- if (index >= 0 && index < SiemensRecipes.Count)
- {
- string code = SiemensRecipes.ElementAt(index).RecipeCode;
- int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
- bool Inplace = false;
- switch (trayCode)
- {
- case 1:
- Inplace = HKDevice.PlcRead.Tray1InPlace;
- break;
- case 2:
- Inplace = HKDevice.PlcRead.Tray2InPlace;
- break;
- case 3:
- Inplace = HKDevice.PlcRead.Tray3InPlace;
- break;
- case 4:
- Inplace = HKDevice.PlcRead.Tray4InPlace;
- break;
- case 5:
- Inplace = HKDevice.PlcRead.Tray5InPlace;
- break;
- default:
- break;
- }
- if (HKDevice.PlcRead.IsAllowIssueRecipe2 && GVL_BigStation.Recipe2DosingStatus == 0 && Inplace)//配方2是否允许下发配发
- {
- GVL_BigStation.DosingRecipe2Time = DateTime.Now;
- HKDevice.StockBinPar(SiemensRecipes.ElementAt(index));
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
- }
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", true);
- GVL_BigStation.Recipe2DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- if (HKDevice.PlcRead.ReceiveFinishRecipe2 && GVL_BigStation.Recipe2DosingStatus == 1)
- {
- GVL_BigStation.Recipe2DosingStatus = 2;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", false);
- StockBinParReset();
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
- }
- if (GVL_BigStation.Recipe2DosingStatus == 2 && HKDevice.PlcRead.Recipe2DosingFinish)
- {
- GVL_BigStation.Recipe2DosingFinish = true;
- GVL_BigStation.Recipe2DosingStatus = 3;
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
- foreach (var item in SiemensRecipes.ElementAt(index).RawMaterial)
- {
- if (item.RawMaterialLocation == 1)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
- }
- else if (item.RawMaterialLocation == 2)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
- }
- else if (item.RawMaterialLocation == 3)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
- }
- else if (item.RawMaterialLocation == 4)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
- }
- else if (item.RawMaterialLocation == 5)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
- }
- else if (item.RawMaterialLocation == 6)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
- }
- else if (item.RawMaterialLocation == 7)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
- }
- else if (item.RawMaterialLocation == 8)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
- }
- else if (item.RawMaterialLocation == 9)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
- }
- else if (item.RawMaterialLocation == 10)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
- }
- else if (item.RawMaterialLocation == 11)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
- }
- else if (item.RawMaterialLocation == 12)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
- }
- else if (item.RawMaterialLocation == 13)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
- }
- else if (item.RawMaterialLocation == 14)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
- }
- }
- if (SiemensDevice.IsConnected)
- {
- FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode;
- FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName;
- FinishData.job_No = (short)SiemensRecipes.ElementAt(index).TrayCode;
- for (int i = 0; i < FinishData.Material.Length; i++)
- {
- FinishData.Material[i] = new UDT1();
- }
- for (int i = 0; i < SiemensRecipes.ElementAt(index).RawMaterial.Count; i++)
- {
- FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
- FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
- FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight);
- }
- FinishData.Ask_For_Finish = true;
- double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe2Time).TotalSeconds;
- FinishData.ProcessTime = Convert.ToInt16(a);
- SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
- MessageNotify.GetInstance.ShowRunLog($"配方配料完成,将信号反馈给西门子");
- }
- SiemensRecipeQueue2.TryDequeue(out code);
- RecipeExecuteComple.Add(SiemensRecipes.ElementAt(index));
- if (!GVL_BigStation.IsUseLocalRecipe)
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- });
- }
- else
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- });
- }
- GVL_BigStation.Recipe2DosingStatus = 0;
- }
- }
- }
- if (SiemensRecipeQueue3.Count > 0)
- {
- int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == SiemensRecipeQueue3.ElementAt(0));
- if (index >= 0 && index < SiemensRecipes.Count)
- {
- string code = SiemensRecipes.ElementAt(index).RecipeCode;
- int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
- bool Inplace = false;
- switch (trayCode)
- {
- case 1:
- Inplace = HKDevice.PlcRead.Tray1InPlace;
- break;
- case 2:
- Inplace = HKDevice.PlcRead.Tray2InPlace;
- break;
- case 3:
- Inplace = HKDevice.PlcRead.Tray3InPlace;
- break;
- case 4:
- Inplace = HKDevice.PlcRead.Tray4InPlace;
- break;
- case 5:
- Inplace = HKDevice.PlcRead.Tray5InPlace;
- break;
- default:
- break;
- }
- if (HKDevice.PlcRead.IsAllowIssueRecipe3 && GVL_BigStation.Recipe3DosingStatus == 0 && Inplace)//配方3是否允许下发配发
- {
- GVL_BigStation.DosingRecipe3Time = DateTime.Now;
- HKDevice.StockBinPar(SiemensRecipes.ElementAt(index));
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
- }
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", true);
- GVL_BigStation.Recipe3DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- if (HKDevice.PlcRead.ReceiveFinishRecipe3 && GVL_BigStation.Recipe3DosingStatus == 1)
- {
- GVL_BigStation.Recipe3DosingStatus = 2;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", false);
- StockBinParReset();
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
- }
- if (HKDevice.PlcRead.Recipe3DosingFinish && GVL_BigStation.Recipe3DosingStatus == 2)
- {
- GVL_BigStation.Recipe3DosingFinish = true;
- GVL_BigStation.Recipe3DosingStatus = 3;
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
- foreach (var item in SiemensRecipes.ElementAt(index).RawMaterial)
- {
- if (item.RawMaterialLocation == 1)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
- }
- else if (item.RawMaterialLocation == 2)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
- }
- else if (item.RawMaterialLocation == 3)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
- }
- else if (item.RawMaterialLocation == 4)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
- }
- else if (item.RawMaterialLocation == 5)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
- }
- else if (item.RawMaterialLocation == 6)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
- }
- else if (item.RawMaterialLocation == 7)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
- }
- else if (item.RawMaterialLocation == 8)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
- }
- else if (item.RawMaterialLocation == 9)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
- }
- else if (item.RawMaterialLocation == 10)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
- }
- else if (item.RawMaterialLocation == 11)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
- }
- else if (item.RawMaterialLocation == 12)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
- }
- else if (item.RawMaterialLocation == 13)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
- }
- else if (item.RawMaterialLocation == 14)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
- }
- }
- if (SiemensDevice.IsConnected)
- {
- FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode;
- FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName;
- FinishData.job_No = (short)SiemensRecipes.ElementAt(index).TrayCode;
- for (int i = 0; i < FinishData.Material.Length; i++)
- {
- FinishData.Material[i] = new UDT1();
- }
- for (int i = 0; i < SiemensRecipes.ElementAt(index).RawMaterial.Count; i++)
- {
- FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
- FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
- FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight);
- }
- FinishData.Ask_For_Finish = true;
- double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe3Time).TotalSeconds;
- FinishData.ProcessTime = Convert.ToInt16(a);
- SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
- MessageNotify.GetInstance.ShowRunLog($"配方配料完成,将信号反馈给西门子");
- }
- SiemensRecipeQueue3.TryDequeue(out code);
- RecipeExecuteComple.Add(SiemensRecipes.ElementAt(index));//将该配方添加到下
- if (!GVL_BigStation.IsUseLocalRecipe)
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- });
- }
- else
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- });
- }
- GVL_BigStation.Recipe3DosingStatus = 0;
- }
- }
- }
- if (SiemensRecipeQueue4.Count > 0)
- {
- int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == SiemensRecipeQueue4.ElementAt(0));
- if (index >= 0 && index < SiemensRecipes.Count)
- {
- string code = SiemensRecipes.ElementAt(index).RecipeCode;
- int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
- bool Inplace = false;
- switch (trayCode)
- {
- case 1:
- Inplace = HKDevice.PlcRead.Tray1InPlace;
- break;
- case 2:
- Inplace = HKDevice.PlcRead.Tray2InPlace;
- break;
- case 3:
- Inplace = HKDevice.PlcRead.Tray3InPlace;
- break;
- case 4:
- Inplace = HKDevice.PlcRead.Tray4InPlace;
- break;
- case 5:
- Inplace = HKDevice.PlcRead.Tray5InPlace;
- break;
- default:
- break;
- }
- if (HKDevice.PlcRead.IsAllowIssueRecipe4 && GVL_BigStation.Recipe4DosingStatus == 0 && Inplace)//配方4是否允许下发配发
- {
- GVL_BigStation.DosingRecipe4Time = DateTime.Now;
- HKDevice.StockBinPar(SiemensRecipes.ElementAt(index));
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
- }
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", true);
- GVL_BigStation.Recipe4DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- if (HKDevice.PlcRead.ReceiveFinishRecipe4 && GVL_BigStation.Recipe4DosingStatus == 1)
- {
- GVL_BigStation.Recipe4DosingStatus = 2;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", false);
- StockBinParReset();
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
- }
- if (GVL_BigStation.Recipe4DosingStatus == 2 && HKDevice.PlcRead.Recipe4DosingFinish)
- {
- GVL_BigStation.Recipe1DosingFinish = true;
- GVL_BigStation.Recipe4DosingStatus = 3;
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
- foreach (var item in SiemensRecipes.ElementAt(index).RawMaterial)
- {
- if (item.RawMaterialLocation == 1)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
- }
- else if (item.RawMaterialLocation == 2)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
- }
- else if (item.RawMaterialLocation == 3)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
- }
- else if (item.RawMaterialLocation == 4)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
- }
- else if (item.RawMaterialLocation == 5)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
- }
- else if (item.RawMaterialLocation == 6)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
- }
- else if (item.RawMaterialLocation == 7)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
- }
- else if (item.RawMaterialLocation == 8)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
- }
- else if (item.RawMaterialLocation == 9)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
- }
- else if (item.RawMaterialLocation == 10)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
- }
- else if (item.RawMaterialLocation == 11)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
- }
- else if (item.RawMaterialLocation == 12)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
- }
- else if (item.RawMaterialLocation == 13)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
- }
- else if (item.RawMaterialLocation == 14)
- {
- item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
- }
- }
- if (SiemensDevice.IsConnected)
- {
- FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode;
- FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName;
- FinishData.job_No = (short)SiemensRecipes.ElementAt(index).TrayCode;
- for (int i = 0; i < FinishData.Material.Length; i++)
- {
- FinishData.Material[i] = new UDT1();
- }
- for (int i = 0; i < SiemensRecipes.ElementAt(index).RawMaterial.Count; i++)
- {
- FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
- FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
- FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight);
- }
- FinishData.Ask_For_Finish = true;
- double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe4Time).TotalSeconds;
- FinishData.ProcessTime = Convert.ToInt16(a);
- SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
- MessageNotify.GetInstance.ShowRunLog($"配方配料完成,将信号反馈给西门子");
- }
- SiemensRecipeQueue4.TryDequeue(out code);
- RecipeExecuteComple.Add(SiemensRecipes.ElementAt(index));//将该配方添加到下
- if (!GVL_BigStation.IsUseLocalRecipe)
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- });
- }
- else
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- });
- }
- GVL_BigStation.Recipe4DosingStatus = 0;
- }
- }
- }
- }
- /// <summary>
- /// 下发plc的配方数据复位
- /// </summary>
- private void StockBinParReset()
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBW2.0", 0);//
- HKDevice.HK_PLC_S7.Write("DB99.DBW4.0", 0);
- for (int i = 0; i < 56; i++)
- {
- string address2 = "DB99.DBD" + (6 + 4 * i);
- HKDevice.HK_PLC_S7.Write(address2, 0);
- }
- }
- private void testRawMaterialNameData()
- {
- /* RawMaterialsInfo.Clear();
- RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0007", RawMaterialLocation = 1 });//备料大蒜
- RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0015", RawMaterialLocation = 2 });//花椒酱
- RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0005", RawMaterialLocation = 3 });//榨菜丁
- RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0018", RawMaterialLocation = 4 });//炸豌豆
- RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0019", RawMaterialLocation = 5 });//高水分糍粑海椒
- RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0033", RawMaterialLocation = 6 });//辣豆瓣*/
- /*RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0030", RawMaterialLocation = 11 });//备用生姜
- RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0012", RawMaterialLocation = 12 });//豆豉细粒*/
- foreach (var material in RawMaterialsInfo)
- {
- if (!string.IsNullOrEmpty(material.RawMaterialName))
- {
- if (!RawMaterialsNamePos.ContainsKey(material.RawMaterialName))
- {
- RawMaterialsNamePos.Add(material.RawMaterialName, (short)material.RawMaterialLocation);
- }
- }
- }
- }
- }
- }
|