|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609 |
- using BPA.Message;
- 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.Reflection;
- 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 { get; set; } = new ObservableCollection<RecipeData>();
- /// <summary>
- /// 本地配方数据
- /// </summary>
- public ObservableCollection<RecipeData> LocalRecipes { get; set; } = new ObservableCollection<RecipeData>();
- /// <summary>
- /// 配方等待执行
- /// </summary>
- public ObservableCollection<RecipeData> RecipeWaitExecute { get; set; } = new ObservableCollection<RecipeData>();
- /// <summary>
- /// 配方正在执行
- /// </summary>
- public ObservableCollection<RecipeData> RecipeExecuting { get; set; } = new ObservableCollection<RecipeData>();
- /// <summary>
- /// 配方执行完成
- /// </summary>
- public ObservableCollection<RecipeData> RecipeExecuteComple { get; set; } = new ObservableCollection<RecipeData>();
- /// <summary>
- /// 原料的名称和料仓的位置对应
- /// </summary>
- public ConcurrentDictionary<int, string> RawMaterialsNamePos { get; set; } = new ConcurrentDictionary<int, string>();
- /// <summary>
- /// 硬件料仓的原料信息
- /// </summary>
- public ObservableCollection<RawMaterial> HardWareRawMaterialInfo { get; set; } = new ObservableCollection<RawMaterial>();
- public ObservableCollection<RawMaterial> RawMaterialsInfo { get; set; } = new ObservableCollection<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>();
-
- public ConcurrentDictionary<int, ConcurrentQueue<string>> SiemensRecipeQueue = new ConcurrentDictionary<int, ConcurrentQueue<string>>();
- public ObservableCollection<RecipeDosing> recipe = new ObservableCollection<RecipeDosing>();
- /// <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>();
-
- /// <summary>
- /// 海科PLC的IP
- /// </summary>
- public string HK_PLC_IP = ConfigurationManager.AppSettings["HKPlc_IP"];
- /// <summary>
- /// 西门子PLC的IP
- /// </summary>
- public string Siemens_PLC_IP = ConfigurationManager.AppSettings["Siemens_IP"];
- public void Init()
- {
- 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 (string.IsNullOrEmpty(recipe.Material[i].Material_Name))
- {
-
- }
- else
- {
- int index = RawMaterialsNamePos.Values.ToList().IndexOf(recipe.Material[i].Material_Name);
- if (index >= 0)
- {
- RawMaterials.Add(new RawMaterial()
- {
- RawMaterialName = recipe.Material[i].Material_Name,
- RawMaterialBarrelNum = recipe.Material[i].Material_BarrelNum,
- RawMaterialWeight = recipe.Material[i].Material_Weight,
- RawMaterialLocation = RawMaterialsNamePos.Keys.ToList()[index]
- });
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"本地缺少原料【{recipe.Material[i].Material_Name}】,和西门子下发的原料名称无法对应。");
- }
- }
- }
- 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,
- //OrderType=recipe.Order_Type?"洗桶":"配料",
- RecipesSource=RecipeSource.远程
- });
- });
- }
- }
- }), "SiemensSendRecipe", true);
- DeviceConnectInit();//设备连接初始化
- ThreadInit();//线程初始化
- VarResetInit();//变量初始化
- }
- #region 本地配方--暂时不使用
- 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) && HKDevice.PlcRead.IsAllowIssueRecipe1)
- {
- 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) && HKDevice.PlcRead.IsAllowIssueRecipe2)
- {
- 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) && HKDevice.PlcRead.IsAllowIssueRecipe3)
- {
- 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) && HKDevice.PlcRead.IsAllowIssueRecipe4)
- {
- if (!(LocalRecipeQueue4.Contains(data.RecipeCode)))
- {
- LocalRecipeQueue4.Enqueue(data.RecipeCode);
- }
- }
- }
- }
- else
- {
- LocalRecipeQueue1.Clear();
- LocalRecipeQueue2.Clear();
- LocalRecipeQueue3.Clear();
- LocalRecipeQueue4.Clear();
- GVL_BigStation.BarrelWasherSign = false;
- 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是否允许下发配发
- {
- if (LocalRecipes.ElementAt(index).IsWashingBarrel)
- {
- if (!GVL_BigStation.BarrelWasherSign)
- {
- GVL_BigStation.BarrelWasherSign = true;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
-
- HKDevice.WritePlcRecipeData(LocalRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true);
- GVL_BigStation.Recipe1DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- }
- else
- {
- HKDevice.WritePlcRecipeData(LocalRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true);
- GVL_BigStation.Recipe1DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- }
- if (HKDevice.PlcRead.ReceiveFinishRecipe1 && GVL_BigStation.Recipe1DosingStatus == 1)
- {
- if (LocalRecipes.ElementAt(index).IsWashingBarrel)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶复位
- MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},洗桶信号复位");
- }
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", false);
- StockBinParReset();
- GVL_BigStation.Recipe1DosingStatus = 2;
- MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
- }
- if (GVL_BigStation.Recipe1DosingStatus == 2 && HKDevice.PlcRead.Recipe1DosingFinish)
- {
- if (LocalRecipes.ElementAt(index).IsWashingBarrel)
- {
- GVL_BigStation.BarrelWasherSign = false;
- }
- 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($"配方1,配方编号:{code},托盘编号:{trayCode},配料完成");
- 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);
- //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是否允许下发配发
- {
- if (LocalRecipes.ElementAt(index).IsWashingBarrel)
- {
- if (!GVL_BigStation.BarrelWasherSign)
- {
- GVL_BigStation.BarrelWasherSign = true;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
-
- HKDevice.WritePlcRecipeData(LocalRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", true);
- GVL_BigStation.Recipe2DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
- }
- }
- else
- {
- HKDevice.WritePlcRecipeData(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)
- {
- if (LocalRecipes.ElementAt(index).IsWashingBarrel)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶复位
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},洗桶信号复位");
- }
- 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)
- {
- if (LocalRecipes.ElementAt(index).IsWashingBarrel)
- {
- GVL_BigStation.BarrelWasherSign = false;
- }
- 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);
- 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是否允许下发配发
- {
- if (LocalRecipes.ElementAt(index).IsWashingBarrel)
- {
- if (!GVL_BigStation.BarrelWasherSign)
- {
- GVL_BigStation.BarrelWasherSign = true;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
-
- HKDevice.WritePlcRecipeData(LocalRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", true);
- GVL_BigStation.Recipe3DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
- }
- }
- else
- {
- HKDevice.WritePlcRecipeData(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)
- {
- if (LocalRecipes.ElementAt(index).IsWashingBarrel)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶复位
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},洗桶信号复位");
- }
- 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)
- {
- if (LocalRecipes.ElementAt(index).IsWashingBarrel)
- {
- GVL_BigStation.BarrelWasherSign = false;
- }
- 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);
- 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是否允许下发配发
- {
- if (LocalRecipes.ElementAt(index).IsWashingBarrel)
- {
- if (!GVL_BigStation.BarrelWasherSign)
- {
- GVL_BigStation.BarrelWasherSign = true;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
-
- HKDevice.WritePlcRecipeData(LocalRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", true);
- GVL_BigStation.Recipe4DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
- }
- }
- else
- {
- HKDevice.WritePlcRecipeData(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)
- {
- if (LocalRecipes.ElementAt(index).IsWashingBarrel)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶复位
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},洗桶信号复位");
- }
- 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)
- {
- if (LocalRecipes.ElementAt(index).IsWashingBarrel)
- {
- GVL_BigStation.BarrelWasherSign = false;
- }
- 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);
- LocalRecipes.RemoveAt(index);
- GVL_BigStation.Recipe4DosingStatus = 0;
- }
- }
- }
- }
- #endregion
- /// <summary>
- /// 将西门子配方,添加到队列中
- /// </summary>
- private void ReceviceData()
- {
- SiemensRecipes = Json<RemoteRecipe>.Data.Recipes;
- if (SiemensRecipes.Count > 0)
- {
- foreach (var data in SiemensRecipes)
- {
- if (data.RecipesSource == RecipeSource.远程)
- {
- if (SiemensRecipeQueue1.Count == 0 && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe1 && data.TrayCode == 1)
- {
- if (!(SiemensRecipeQueue1.Contains(data.RecipeCode)))
- {
- if (SiemensDevice.DL_Status is DL_Status_DB status)
- {
- switch (GVL_BigStation.SiemensSendRecipeStatus)
- {
- case 3:
- SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
- MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方:【{data.RecipeCode}】发送配方编号和请求配料标志给西门子");
- GVL_BigStation.SiemensSendRecipeStatus = 4;
- break;
- case 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】,配方:【{data.RecipeCode}】西门子确认开始配料");
- GVL_BigStation.SiemensSendRecipeStatus = 5;
- }
- break;
- case 5:
- if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
- {
- SiemensRecipeQueue1.Enqueue(data.RecipeCode);
- MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方:【{data.RecipeCode}】,加入队列");
- GVL_BigStation.SiemensSendRecipeStatus = 0;
- }
- break;
- default:
- break;
- }
- }
- }
- }
- else if (SiemensRecipeQueue2.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe2 && data.TrayCode == 2)
- {
- 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】,配方:【{data.RecipeCode}】发送配方编号和请求配料标志给西门子");
- 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】,配方:【{data.RecipeCode}】西门子确认开始配料");
- 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) && HKDevice.PlcRead.IsAllowIssueRecipe3 && data.TrayCode == 3)
- {
- 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】,配方:【{data.RecipeCode}】发送配方编号和请求配料标志给西门子");
- 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】,配方:【{data.RecipeCode}】西门子确认开始配料");
- 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) && HKDevice.PlcRead.IsAllowIssueRecipe4 && data.TrayCode == 4)
- {
- 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,配方:【{data.RecipeCode}】发送配方编号和请求配料标志给西门子");
- 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】,配方:【{data.RecipeCode}】西门子确认开始配料");
- 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
- {
- if (SiemensRecipeQueue1.Count == 0 && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe1 && data.TrayCode == 1)
- {
- SiemensRecipeQueue1.Enqueue(data.RecipeCode);
- MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列【1】");
- }
- else if (SiemensRecipeQueue2.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe2 && data.TrayCode == 2)
- {
- SiemensRecipeQueue2.Enqueue(data.RecipeCode);
- MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列【2】");
- }
- else if (SiemensRecipeQueue3.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe3 && data.TrayCode == 3)
- {
- SiemensRecipeQueue3.Enqueue(data.RecipeCode);
- MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列【3】");
- }
- else if (SiemensRecipeQueue4.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe4 && data.TrayCode == 4)
- {
- SiemensRecipeQueue4.Enqueue(data.RecipeCode);
- MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列【4】");
- }
- }
- }
- }
- else
- {
- SiemensRecipeQueue1.Clear();
- SiemensRecipeQueue2.Clear();
- SiemensRecipeQueue3.Clear();
- SiemensRecipeQueue4.Clear();
- GVL_BigStation.BarrelWasherSign = false;
- GVL_BigStation.Recipe1DosingStatus = 0;
- GVL_BigStation.Recipe2DosingStatus = 0;
- GVL_BigStation.Recipe3DosingStatus = 0;
- GVL_BigStation.Recipe4DosingStatus = 0;
- }
- }
- /// <summary>
- /// 订单取消
- /// </summary>
- public void Order_Cancel()
- {
- if (GVL_BigStation.Order_Cancel) //订单取消
- {
- if (!string.IsNullOrEmpty(GVL_BigStation.Order_CancelRecipeCode))
- {
- string code = GVL_BigStation.Order_CancelRecipeCode;
- int index = Array.FindIndex(Json<RemoteRecipe>.Data.Recipes.ToArray(), p => p.RecipeCode == GVL_BigStation.Order_CancelRecipeCode);
- short TrayCode = 0;
- if (index >= 0)
- {
- TrayCode = (short)Json<RemoteRecipe>.Data.Recipes.ElementAt(index).TrayCode;
- }
- switch (GVL_BigStation.Order_CancelStep)
- {
- case 0:
- if (index == -1)
- {
- GVL_BigStation.Order_CancelStep = 10;
- }
- else
- {
- if (SiemensRecipeQueue1.Contains(code) || SiemensRecipeQueue2.Contains(code) || SiemensRecipeQueue3.Contains(code) || SiemensRecipeQueue4.Contains(code))
- {
- GVL_BigStation.Order_CancelStep = 30;
- }
- else
- {
- GVL_BigStation.Order_CancelStep = 20;
- }
- //以下为新增,复位DB99托盘号,配方号,桶重量参数,以及配方下发确认和配料完成。
- StockBinParReset();
-
- }
- break;
- case 10:
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- GVL_BigStation.Order_CancelStep = 11;
- break;
- case 11:
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
- {
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
- GVL_BigStation.Order_CancelStep = 12;
- }
- break;
- case 12:
- MessageNotify.GetInstance.ShowRunLog($"西门子取消订单,但未找到订单:【{GVL_BigStation.Order_CancelRecipeCode}】");
- GVL_BigStation.Order_Cancel = false;
- GVL_BigStation.Order_CancelRecipeCode = "";
- GVL_BigStation.Order_CancelStep = 0;
- break;
-
- case 20:
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- GVL_BigStation.Order_CancelStep = 21;
- break;
- case 21:
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
- {
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
- GVL_BigStation.Order_CancelStep = 22;
- }
- break;
- case 22:
- GVL_BigStation.SiemensSendRecipeStatus = 0;
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
- });
- MessageNotify.GetInstance.ShowRunLog($"正在执行请求取消订单流程,配方还未到PLC,订单号:【{GVL_BigStation.Order_CancelRecipeCode}】");
- GVL_BigStation.Order_Cancel = false;
- GVL_BigStation.Order_CancelRecipeCode = "";
- GVL_BigStation.Order_CancelStep = 0;
- break;
- case 30:
- if (SiemensRecipeQueue1.Contains(code))
- {
- GVL_BigStation.Order_CancelStep = 31;
- }
- else if (SiemensRecipeQueue2.Contains(code))
- {
- GVL_BigStation.Order_CancelStep = 41;
- }
- else if (SiemensRecipeQueue3.Contains(code))
- {
- GVL_BigStation.Order_CancelStep = 51;
- }
- else if (SiemensRecipeQueue4.Contains(code))
- {
- GVL_BigStation.Order_CancelStep = 61;
- }
- break;
- case 31:
- if (GVL_BigStation.Recipe1DosingStatus != 0)
- {
- MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true)}");
- MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode)}");
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", false);
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.4", false);
- GVL_BigStation.Recipe1DosingFinish = false;
- GVL_BigStation.Recipe1DosingStatus = 0;
- GVL_BigStation.Order_CancelStep = 32;
- MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
- }
- else
- {
- GVL_BigStation.Order_CancelStep = 32;
- MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:【{code}】");
- }
- break;
- case 32:
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- GVL_BigStation.Order_CancelStep = 33;
- break;
- case 33:
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
- {
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
- });
- SiemensRecipeQueue1.TryDequeue(out code);
- GVL_BigStation.Order_CancelStep = 0;
- GVL_BigStation.Order_Cancel = false;
- GVL_BigStation.Order_CancelRecipeCode = "";
- MessageNotify.GetInstance.ShowRunLog($"队列1,西门子取消订单完成,订单号:【{code}】");
- }
- break;
- case 41:
- if (GVL_BigStation.Recipe2DosingStatus != 0)
- {
- MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true)}");
- MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode)}");
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", false);
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.5", false);
- GVL_BigStation.Recipe2DosingFinish = false;
- GVL_BigStation.Recipe2DosingStatus = 0;
- GVL_BigStation.Order_CancelStep = 42;
- MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:【{code}】");
- }
- else
- {
- GVL_BigStation.Order_CancelStep = 42;
- MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:【{code}】");
- }
- break;
- case 42:
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- GVL_BigStation.Order_CancelStep = 43;
- break;
- case 43:
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
- {
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
- });
- SiemensRecipeQueue2.TryDequeue(out code);
- GVL_BigStation.Order_CancelStep = 0;
- GVL_BigStation.Order_Cancel = false;
- GVL_BigStation.Order_CancelRecipeCode = "";
- MessageNotify.GetInstance.ShowRunLog($"队列2,西门子取消订单完成,订单号:【{code}】");
- }
- break;
- case 51:
- if (GVL_BigStation.Recipe3DosingStatus != 0)
- {
- MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true)}");
- MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode)}");
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", false);
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.6", false);
- GVL_BigStation.Recipe3DosingFinish = false;
- GVL_BigStation.Recipe3DosingStatus = 0;
- GVL_BigStation.Order_CancelStep = 52;
- MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:【{code}】");
- }
- else
- {
- GVL_BigStation.Order_CancelStep = 52;
- MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:【{code}】");
- }
- break;
- case 52:
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- GVL_BigStation.Order_CancelStep = 53;
- break;
- case 53:
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
- {
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
- });
- SiemensRecipeQueue3.TryDequeue(out code);
- GVL_BigStation.Order_CancelStep = 0;
- GVL_BigStation.Order_Cancel = false;
- GVL_BigStation.Order_CancelRecipeCode = "";
- MessageNotify.GetInstance.ShowRunLog($"队列3,西门子取消订单完成,订单号:【{code}】");
- }
- break;
- case 61:
- if (GVL_BigStation.Recipe4DosingStatus != 0)
- {
- MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true)}");
- MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode)}");
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", false);
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.7", false);
- GVL_BigStation.Recipe4DosingFinish = false;
- GVL_BigStation.Recipe4DosingStatus = 0;
- GVL_BigStation.Order_CancelStep = 62;
- MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:【{code}】");
- }
- else
- {
- GVL_BigStation.Order_CancelStep = 62;
- MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:【{code}】");
- }
- break;
- case 62:
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- GVL_BigStation.Order_CancelStep = 63;
- break;
- case 63:
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
- {
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
- });
- SiemensRecipeQueue4.TryDequeue(out code);
- GVL_BigStation.Order_CancelStep = 0;
- GVL_BigStation.Order_Cancel = false;
- GVL_BigStation.Order_CancelRecipeCode = "";
- MessageNotify.GetInstance.ShowRunLog($"队列4,西门子取消订单完成,订单号:【{code}】");
- }
- break;
- default:
- break;
- }
- }
- }
- }
- /// <summary>
- /// 配方队列,在配料过程中的逻辑处理
- /// </summary>
- 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;//上位机给plc发送AGV到位信号,plc固定托盘后反馈托盘是否到位
- 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】是否允许下发配发
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- if (!GVL_BigStation.BarrelWasherSign)
- {
- GVL_BigStation.BarrelWasherSign = true;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
-
- GVL_BigStation.DosingRecipe1Time = DateTime.Now;
- HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true);
- GVL_BigStation.Recipe1DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- }
- else
- {
- GVL_BigStation.DosingRecipe1Time = DateTime.Now;
- HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true);
- GVL_BigStation.Recipe1DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- }
- if (HKDevice.PlcRead.ReceiveFinishRecipe1 && GVL_BigStation.Recipe1DosingStatus == 1)
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},洗桶复位");
- }
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", false);
- StockBinParReset();
- MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
- GVL_BigStation.Recipe1DosingStatus = 2;
- }
- if (GVL_BigStation.Recipe1DosingStatus == 2 && HKDevice.PlcRead.Recipe1DosingFinish)
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- GVL_BigStation.BarrelWasherSign = false;
- }
- GVL_BigStation.Recipe1DosingFinish = true;
- //GVL_BigStation.Recipe1DosingStatus = 3;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},配料完成");
- ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index));
- //2023-8-21:如果不是MES系统下发的配方,不要返回结束数据。
- if (SiemensRecipes.ElementAt(index).RecipesSource==RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/)
- {
- 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);
- MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg");
- }
- 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);
-
- }
- GVL_BigStation.Recipe1DosingStatus = 30;
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.4", true);
- }
-
- if (GVL_BigStation.Recipe1DosingStatus == 30)
- {
- if (SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程)
- {
- if (SiemensDevice.IsConnected)
- {
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2361.DBX0.0"))
- {
- //SiemensDevice.Siemens_PLC_S7.Write<bool>("DB2361.DBX330.0", false, 5);
- CleanFinishData();
- if (GVL_BigStation.Recipe1DosingFinish)
- GVL_BigStation.Recipe1DosingFinish = false;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,已将完成数据反馈至MES系统。");
- GVL_BigStation.Recipe1DosingStatus = 40;
- }
- else
- {
- SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
- Thread.Sleep(1500);
- }
- }
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,配方为本地下发未将完成数据反馈至MES系统。");
- GVL_BigStation.Recipe1DosingStatus = 40;
- }
- }
- if (GVL_BigStation.Recipe1DosingStatus == 40 && HKDevice.PlcRead.Recipe1DosingFinish == false)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.4", false);
- SiemensRecipeQueue1.TryDequeue(out code);
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- });
- GVL_BigStation.Recipe1DosingStatus = 0;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},复位plc配料完成信号");
- }
- }
- }
- 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】是否允许下发配发
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- if (!GVL_BigStation.BarrelWasherSign)
- {
- GVL_BigStation.BarrelWasherSign = true;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
-
- GVL_BigStation.DosingRecipe2Time = DateTime.Now;
- HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", true);
- GVL_BigStation.Recipe2DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- }
- else
- {
- GVL_BigStation.DosingRecipe2Time = DateTime.Now;
- HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", true);
- GVL_BigStation.Recipe2DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- }
- if (HKDevice.PlcRead.ReceiveFinishRecipe2 && GVL_BigStation.Recipe2DosingStatus == 1)
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},洗桶复位");
- }
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", false);
- StockBinParReset();
- GVL_BigStation.Recipe2DosingStatus = 2;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
- }
- if (GVL_BigStation.Recipe2DosingStatus == 2 && HKDevice.PlcRead.Recipe2DosingFinish)
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- GVL_BigStation.BarrelWasherSign = false;
- }
- GVL_BigStation.Recipe2DosingFinish = true;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},配料完成");
- ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index));
-
- if (SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/)
- {
- 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);
- MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg");
- }
- 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);
-
- }
-
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.5", true);
- GVL_BigStation.Recipe2DosingStatus = 30;
- }
- if (GVL_BigStation.Recipe2DosingStatus == 30)
- {
- if (SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程)
- {
- if (SiemensDevice.IsConnected)
- {
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2361.DBX0.0"))
- {
- // SiemensDevice.Siemens_PLC_S7.Write<bool>("DB2361.DBX330.0", false, 5);
- CleanFinishData();
- if (GVL_BigStation.Recipe2DosingFinish)
- GVL_BigStation.Recipe2DosingFinish = false;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,已将完成数据反馈至MES系统。");
- GVL_BigStation.Recipe2DosingStatus = 40;
- }
- else
- {
- SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
- Thread.Sleep(1500);
- }
- }
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,配方为本地下发未将完成数据反馈至MES系统。");
- GVL_BigStation.Recipe2DosingStatus = 40;
- }
- }
-
- if (GVL_BigStation.Recipe2DosingStatus == 40 && HKDevice.PlcRead.Recipe2DosingFinish == false)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.5", false);
- SiemensRecipeQueue2.TryDequeue(out code);
- RecipeExecuteComple.Add(SiemensRecipes.ElementAt(index));
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- });
- GVL_BigStation.Recipe2DosingStatus = 0;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},,复位plc配料完成信号");
- }
- }
- }
- 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】是否允许下发配发
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- if (!GVL_BigStation.BarrelWasherSign)//其他配方在洗桶时,等待其他配方洗完,在发送数据
- {
- GVL_BigStation.BarrelWasherSign = true;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
- GVL_BigStation.DosingRecipe3Time = DateTime.Now;
- HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", true);
- GVL_BigStation.Recipe3DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- }
- else
- {
- GVL_BigStation.DosingRecipe3Time = DateTime.Now;
- HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", true);
- GVL_BigStation.Recipe3DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- }
- if (HKDevice.PlcRead.ReceiveFinishRecipe3 && GVL_BigStation.Recipe3DosingStatus == 1)
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},洗桶复位");
- }
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", false);
- StockBinParReset();
- GVL_BigStation.Recipe3DosingStatus = 2;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
- }
- if (HKDevice.PlcRead.Recipe3DosingFinish && GVL_BigStation.Recipe3DosingStatus == 2)
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- GVL_BigStation.BarrelWasherSign = false;
- }
- GVL_BigStation.Recipe3DosingFinish = true;
- //GVL_BigStation.Recipe3DosingStatus = 3;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},配料完成");
- ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index));
- if (SiemensDevice.IsConnected && SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/)
- {
- 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);
- MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg");
- }
- 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);
- }
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.6", true);
- GVL_BigStation.Recipe3DosingStatus = 30;
- }
-
- if (GVL_BigStation.Recipe3DosingStatus == 30)
- {
- if (SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程)
- {
- if (SiemensDevice.IsConnected)
- {
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2361.DBX0.0"))
- {
- //SiemensDevice.Siemens_PLC_S7.Write<bool>("DB2361.DBX330.0", false, 5);
- CleanFinishData();
-
- if (GVL_BigStation.Recipe3DosingFinish)
- GVL_BigStation.Recipe3DosingFinish = false;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,已将完成数据反馈至MES系统。");
- GVL_BigStation.Recipe3DosingStatus = 40;
- }
- else
- {
- SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
- Thread.Sleep(1500);
- }
- }
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,配方为本地下发未将完成数据反馈至MES系统。");
- GVL_BigStation.Recipe3DosingStatus = 40;
- }
- }
-
- if (GVL_BigStation.Recipe3DosingStatus == 40 && HKDevice.PlcRead.Recipe3DosingFinish == false)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.6", false);
- SiemensRecipeQueue3.TryDequeue(out code);
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- });
- GVL_BigStation.Recipe3DosingStatus = 0;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},复位plc配料完成信号");
- }
- }
- }
- 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】是否允许下发配发
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- if (!GVL_BigStation.BarrelWasherSign)//其他配方在洗桶时,等待其他配方洗完,在发送数据
- {
- GVL_BigStation.BarrelWasherSign = true;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
- GVL_BigStation.DosingRecipe4Time = DateTime.Now;
- HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", true);
- GVL_BigStation.Recipe4DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- }
- else
- {
- GVL_BigStation.DosingRecipe4Time = DateTime.Now;
- HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", true);
- GVL_BigStation.Recipe4DosingStatus = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- }
- if (HKDevice.PlcRead.ReceiveFinishRecipe4 && GVL_BigStation.Recipe4DosingStatus == 1)
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},洗桶复位");
- }
- GVL_BigStation.Recipe4DosingStatus = 2;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", false);
- StockBinParReset();
- MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
- }
- if (GVL_BigStation.Recipe4DosingStatus == 2 && HKDevice.PlcRead.Recipe4DosingFinish)
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- GVL_BigStation.BarrelWasherSign = false;
- }
- GVL_BigStation.Recipe4DosingFinish = true;
- //GVL_BigStation.Recipe4DosingStatus = 3;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},配料完成");
- ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index));
- if (SiemensDevice.IsConnected && SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/)
- {
- 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);
- MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg");
- }
- 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);
-
- }
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.7", true);
- GVL_BigStation.Recipe4DosingStatus = 30;
- }
-
- if (GVL_BigStation.Recipe4DosingStatus == 30)
- {
- if (SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程)
- {
- if (SiemensDevice.IsConnected)
- {
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2361.DBX0.0"))
- {
- // SiemensDevice.Siemens_PLC_S7.Write<bool>("DB2361.DBX330.0", false, 5);
- CleanFinishData();
- if (GVL_BigStation.Recipe4DosingFinish)
- GVL_BigStation.Recipe4DosingFinish = false;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,已将完成数据反馈至MES系统。");
- GVL_BigStation.Recipe4DosingStatus = 40;
- }
- else
- {
- SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
- Thread.Sleep(1500);
- }
- }
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,配方为本地下发未将完成数据反馈至MES系统。");
- GVL_BigStation.Recipe4DosingStatus = 40;
- }
- }
-
- if (GVL_BigStation.Recipe4DosingStatus == 40 && HKDevice.PlcRead.Recipe4DosingFinish == false)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX1.7", false);
- SiemensRecipeQueue4.TryDequeue(out code);
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- });
- GVL_BigStation.Recipe4DosingStatus = 0;
- MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},复位plc配料完成信号");
- }
- }
- }
- }
- /// <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 = Json<RawMaterialData>.Data.RawMaterial;
- /*foreach (var material in RawMaterialsInfo)
- {
- if (!string.IsNullOrEmpty(material.RawMaterialName))
- {
- if (!RawMaterialsNamePos.ContainsKey(material.RawMaterialName))
- {
- RawMaterialsNamePos.Add(material.RawMaterialName, (short)material.RawMaterialLocation);
- }
- }
- }*/
- if (RawMaterialsNamePos.Count == 14)
- {
- for (int i = 0; i < typeof(StockBinName).GetProperties().Length; i++)
- {
- PropertyInfo pro = GVL_BigStation.stockBinName.GetType().GetProperty(typeof(StockBinName).GetProperties()[i].Name);
- RawMaterialsNamePos[i + 1] = pro.GetValue(GVL_BigStation.stockBinName, null).ToString();
- }
- }
- else
- {
- RawMaterialsNamePos.TryAdd(1, GVL_BigStation.stockBinName.RawMaterialName1);
- RawMaterialsNamePos.TryAdd(2, GVL_BigStation.stockBinName.RawMaterialName2);
- RawMaterialsNamePos.TryAdd(3, GVL_BigStation.stockBinName.RawMaterialName3);
- RawMaterialsNamePos.TryAdd(4, GVL_BigStation.stockBinName.RawMaterialName4);
- RawMaterialsNamePos.TryAdd(5, GVL_BigStation.stockBinName.RawMaterialName5);
- RawMaterialsNamePos.TryAdd(6, GVL_BigStation.stockBinName.RawMaterialName6);
- RawMaterialsNamePos.TryAdd(7, GVL_BigStation.stockBinName.RawMaterialName7);
- RawMaterialsNamePos.TryAdd(8, GVL_BigStation.stockBinName.RawMaterialName8);
- RawMaterialsNamePos.TryAdd(9, GVL_BigStation.stockBinName.RawMaterialName9);
- RawMaterialsNamePos.TryAdd(10, GVL_BigStation.stockBinName.RawMaterialName10);
- RawMaterialsNamePos.TryAdd(11, GVL_BigStation.stockBinName.RawMaterialName11);
- RawMaterialsNamePos.TryAdd(12, GVL_BigStation.stockBinName.RawMaterialName12);
- RawMaterialsNamePos.TryAdd(13, GVL_BigStation.stockBinName.RawMaterialName13);
- RawMaterialsNamePos.TryAdd(14, GVL_BigStation.stockBinName.RawMaterialName14);
- foreach (var item in RawMaterialsNamePos)
- {
- HardWareRawMaterialInfo.Add(new RawMaterial() { RawMaterialCount = HardWareRawMaterialInfo.Count + 1, RawMaterialLocation = item.Key, RawMaterialName = item.Value, RawMaterialChineseName = "" });
- }
- }
- foreach (var item in RawMaterialsNamePos)
- {
- int num = Array.FindIndex(Json<BomMaterial>.Data.RawMaterials.ToArray(), p => p.RawMaterialName == item.Value);
- int index = Array.FindIndex(HardWareRawMaterialInfo.ToArray(), p => p.RawMaterialLocation == item.Key);
- if (index == -1)
- {
- HardWareRawMaterialInfo.Clear();
- }
- else if (num >= 0 && index >= 0)
- {
- string name = Json<BomMaterial>.Data.RawMaterials.ElementAt(num).RawMaterialChineseName;
- HardWareRawMaterialInfo.ElementAt(index).RawMaterialLocation = item.Key;
- HardWareRawMaterialInfo.ElementAt(index).RawMaterialName = item.Value;
- HardWareRawMaterialInfo.ElementAt(index).RawMaterialChineseName = name;
- }
- else if (num == -1)
- {
- HardWareRawMaterialInfo.ElementAt(index).RawMaterialLocation = item.Key;
- HardWareRawMaterialInfo.ElementAt(index).RawMaterialName = "";
- HardWareRawMaterialInfo.ElementAt(index).RawMaterialChineseName = "";
- }
- }
-
- RawMaterialsInfo = HardWareRawMaterialInfo;
- }
- /// <summary>
- /// MES的物料名称和物料编码对应
- /// </summary>
- public void RawMaterialNameWithCode()
- {
- GVL_BigStation.RawMaterialsNameCode.Add("0001", "色拉油");
- GVL_BigStation.RawMaterialsNameCode.Add("0002", "一级菜油");
- GVL_BigStation.RawMaterialsNameCode.Add("0003", "菜籽油");
- GVL_BigStation.RawMaterialsNameCode.Add("0004", "青花椒油");
- GVL_BigStation.RawMaterialsNameCode.Add("0005", "卤牛肉丁");
- GVL_BigStation.RawMaterialsNameCode.Add("0006", "冻鸡肉丁");
- GVL_BigStation.RawMaterialsNameCode.Add("0007", "香菇丁");
- GVL_BigStation.RawMaterialsNameCode.Add("0008", "高水分糍粑海椒");
- GVL_BigStation.RawMaterialsNameCode.Add("0009", "低水分糍粑海椒");
- GVL_BigStation.RawMaterialsNameCode.Add("0010", "辣豆瓣");
- GVL_BigStation.RawMaterialsNameCode.Add("0011", "整豆豉");
- GVL_BigStation.RawMaterialsNameCode.Add("0012", "豆豉细粒");
- GVL_BigStation.RawMaterialsNameCode.Add("0013", "卤黄豆");
- GVL_BigStation.RawMaterialsNameCode.Add("0014", "野山椒粒");
- GVL_BigStation.RawMaterialsNameCode.Add("0015", "竹笋丁");
- GVL_BigStation.RawMaterialsNameCode.Add("0016", "香辣酱辣椒酱");
- GVL_BigStation.RawMaterialsNameCode.Add("0017", "芽菜粒");
- GVL_BigStation.RawMaterialsNameCode.Add("0018", "榨菜丁");
- GVL_BigStation.RawMaterialsNameCode.Add("0019", "盐菜");
- GVL_BigStation.RawMaterialsNameCode.Add("0020", "洋葱丁");
- GVL_BigStation.RawMaterialsNameCode.Add("0021", "番茄酱");
- GVL_BigStation.RawMaterialsNameCode.Add("0022", "甜豆瓣");
- GVL_BigStation.RawMaterialsNameCode.Add("0023", "甜面酱");
- GVL_BigStation.RawMaterialsNameCode.Add("0024", "芝麻酱");
- GVL_BigStation.RawMaterialsNameCode.Add("0025", "炸花生");
- GVL_BigStation.RawMaterialsNameCode.Add("0026", "盐渍青椒丁");
- GVL_BigStation.RawMaterialsNameCode.Add("0027", "备料剁红椒");
- GVL_BigStation.RawMaterialsNameCode.Add("0028", "萝卜丁");
- GVL_BigStation.RawMaterialsNameCode.Add("0029", "油芝麻");
- GVL_BigStation.RawMaterialsNameCode.Add("0030", "生姜");
- GVL_BigStation.RawMaterialsNameCode.Add("0031", "大蒜");
- GVL_BigStation.RawMaterialsNameCode.Add("0032", "榨菜酱");
- GVL_BigStation.RawMaterialsNameCode.Add("0033", "炸碗豆");
- GVL_BigStation.RawMaterialsNameCode.Add("0034", "大头菜丁");
- GVL_BigStation.RawMaterialsNameCode.Add("0035", "酱油");
- GVL_BigStation.RawMaterialsNameCode.Add("0036", "I+G");
- GVL_BigStation.RawMaterialsNameCode.Add("0037", "味精");
- GVL_BigStation.RawMaterialsNameCode.Add("0038", "白糖");
- GVL_BigStation.RawMaterialsNameCode.Add("0039", "食盐");
- GVL_BigStation.RawMaterialsNameCode.Add("0040", "花椒酱");
- GVL_BigStation.RawMaterialsNameCode.Add("0041", "调味膏2");
- GVL_BigStation.RawMaterialsNameCode.Add("0042", "调味膏5");
- GVL_BigStation.RawMaterialsNameCode.Add("0043", "十三香调味膏");
- GVL_BigStation.RawMaterialsNameCode.Add("0044", "酱香膏");
- GVL_BigStation.RawMaterialsNameCode.Add("0045", "芽菜香料粉");
- GVL_BigStation.RawMaterialsNameCode.Add("0046", "香料A");
- GVL_BigStation.RawMaterialsNameCode.Add("0047", "香料D");
- GVL_BigStation.RawMaterialsNameCode.Add("0048", "猪肉精膏");
- GVL_BigStation.RawMaterialsNameCode.Add("0049", "调味膏3");
- GVL_BigStation.RawMaterialsNameCode.Add("0050", "柠檬酸粉");
- GVL_BigStation.RawMaterialsNameCode.Add("0051", "辣椒红");
- GVL_BigStation.RawMaterialsNameCode.Add("0052", "辣椒油树脂");
- GVL_BigStation.RawMaterialsNameCode.Add("0053", "水态混和酸");
- GVL_BigStation.RawMaterialsNameCode.Add("0054", "加水稀释后防腐剂");
- GVL_BigStation.RawMaterialsNameCode.Add("0055", "异维C钠粉");
- GVL_BigStation.RawMaterialsNameCode.Add("0056", "琼脂粉");
- GVL_BigStation.RawMaterialsNameCode.Add("0057", "香葱油");
- GVL_BigStation.RawMaterialsNameCode.Add("0058", "水态甜味剂");
- GVL_BigStation.RawMaterialsNameCode.Add("0059", "孜然粉");
- GVL_BigStation.RawMaterialsNameCode.Add("0060", "孜然油");
- }
- /// <summary>
- /// 设备连接 西门子和海科PLC
- /// </summary>
- public void DeviceConnectInit()
- {
- 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.ShowRunLog("海科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.ShowRunLog("西门子plc连接失败,等待重新连接");
- }
- finally
- {
- SiemensDevice.Init();
- MessageNotify.GetInstance.ShowRunLog("西门子plc初始化");
- if (SiemensDevice.IsConnected && GVL_BigStation.IsAllowSiemensConnect)
- {
- MessageNotify.GetInstance.ShowRunLog("西门子plc连接成功");
- }
- }
- }
-
- public void ThreadInit()
- {
- 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重新连接");
- }
- Thread.Sleep(10);
- }), "西门子和海科PLC重新连接", true);
-
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- 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)GVL_BigStation.TrayEnable);
- }
- Thread.Sleep(10);
- }), "海科plc和西门子数据交互", true);
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- testRawMaterialNameData();//自定义料仓名称
- if (GVL_BigStation.Order_Cancel)
- {
- Order_Cancel();
- }
- else
- {
- /*if (GVL_BigStation.IsUseLocalRecipe)
- {
- LocalRecipeRecevice();
- LocalRecipeDosing();
- }
- else
- {*/
- ReceviceData();
- RecipeInfoToHKPLC();
- /* }*/
- }
- Thread.Sleep(10);
- }), "配方数据执行流程", true);
- }
- /// <summary>
- /// 初始化变量复位
- /// </summary>
- public void VarResetInit()
- {
- LocalRecipeQueue1.Clear();
- LocalRecipeQueue2.Clear();
- LocalRecipeQueue3.Clear();
- LocalRecipeQueue4.Clear();
- SiemensRecipeQueue1.Clear();
- SiemensRecipeQueue2.Clear();
- SiemensRecipeQueue3.Clear();
- SiemensRecipeQueue4.Clear();
- }
- public void RecipeDosing()
- {
- GVL_BigStation.AllowIssueRecipe[0] = HKDevice.PlcRead.IsAllowIssueRecipe1;
- GVL_BigStation.AllowIssueRecipe[1] = HKDevice.PlcRead.IsAllowIssueRecipe2;
- GVL_BigStation.AllowIssueRecipe[2] = HKDevice.PlcRead.IsAllowIssueRecipe3;
- GVL_BigStation.AllowIssueRecipe[3] = HKDevice.PlcRead.IsAllowIssueRecipe4;
- GVL_BigStation.ReceviceFinishRecipe[0] = HKDevice.PlcRead.ReceiveFinishRecipe1;
- GVL_BigStation.ReceviceFinishRecipe[1] = HKDevice.PlcRead.ReceiveFinishRecipe2;
- GVL_BigStation.ReceviceFinishRecipe[2] = HKDevice.PlcRead.ReceiveFinishRecipe3;
- GVL_BigStation.ReceviceFinishRecipe[3] = HKDevice.PlcRead.ReceiveFinishRecipe4;
- GVL_BigStation.DosingFinishRecipe[0] = HKDevice.PlcRead.Recipe1DosingFinish;
- GVL_BigStation.DosingFinishRecipe[1] = HKDevice.PlcRead.Recipe2DosingFinish;
- GVL_BigStation.DosingFinishRecipe[2] = HKDevice.PlcRead.Recipe3DosingFinish;
- GVL_BigStation.DosingFinishRecipe[3] = HKDevice.PlcRead.Recipe4DosingFinish;
- GVL_BigStation.IsTrayArrive[0] = HKDevice.PlcRead.Tray1InPlace;
- GVL_BigStation.IsTrayArrive[1] = HKDevice.PlcRead.Tray2InPlace;
- GVL_BigStation.IsTrayArrive[2] = HKDevice.PlcRead.Tray3InPlace;
- GVL_BigStation.IsTrayArrive[3] = HKDevice.PlcRead.Tray4InPlace;
- GVL_BigStation.IsTrayArrive[4] = HKDevice.PlcRead.Tray5InPlace;
- #region 接收配方
- SiemensRecipes = Json<RemoteRecipe>.Data.Recipes;
- if (SiemensRecipes.Count > 0)
- {
- foreach (var data in SiemensRecipes)
- {
- foreach (var item in SiemensRecipeQueue)
- {
- if (item.Value.Count == 0 && item.Key == data.TrayCode && GVL_BigStation.AllowIssueRecipe[item.Key - 1])
- {
- if (SiemensDevice.DL_Status is DL_Status_DB status)
- {
- switch (GVL_BigStation.SiemensSendRecipeStatus)
- {
- case 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;
- break;
- case 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;
- }
- break;
- case 5:
- if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
- {
- item.Value.Enqueue(data.RecipeCode);
- MessageNotify.GetInstance.ShowRunLog($"配方1,配方:{data.RecipeCode},加入队列");
- GVL_BigStation.SiemensSendRecipeStatus = 0;
- }
- break;
- default:
- break;
- }
- }
- }
- }
- }
- }
- else
- {
- SiemensRecipeQueue.Clear();
- GVL_BigStation.BarrelWasherSign = false;
- for (int i = 0; i < GVL_BigStation.RecipeDosingStatus.Length; i++)
- {
- GVL_BigStation.RecipeDosingStatus[i] = 0;
- }
- }
- #endregion
- #region 取消配方
- if (GVL_BigStation.Order_Cancel) //订单取消
- {
- if (!string.IsNullOrEmpty(GVL_BigStation.Order_CancelRecipeCode))
- {
- string code = GVL_BigStation.Order_CancelRecipeCode;
- int index = Array.FindIndex(Json<RemoteRecipe>.Data.Recipes.ToArray(), p => p.RecipeCode == GVL_BigStation.Order_CancelRecipeCode);
- short TrayCode = 0;
- if (index >= 0)
- {
- TrayCode = (short)Json<RemoteRecipe>.Data.Recipes.ElementAt(index).TrayCode;
- }
- switch (GVL_BigStation.Order_CancelStep)
- {
- case 0:
- if (index == -1)
- {
- GVL_BigStation.Order_CancelStep = 10;
- }
- else
- {
- GVL_BigStation.Order_CancelStep = 20;
- foreach (var item in SiemensRecipeQueue)
- {
- if (item.Value.Contains(code))
- {
- GVL_BigStation.Order_CancelStep = 30;
- }
- }
- }
- break;
- case 10:
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- GVL_BigStation.Order_CancelStep = 11;
- break;
- case 11:
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
- {
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
- GVL_BigStation.Order_CancelStep = 12;
- }
- break;
- case 12:
- MessageNotify.GetInstance.ShowRunLog($"西门子取消订单,但未找到订单:{GVL_BigStation.Order_CancelRecipeCode}");
- GVL_BigStation.Order_Cancel = false;
- GVL_BigStation.Order_CancelRecipeCode = "";
- GVL_BigStation.Order_CancelStep = 0;
- break;
-
- case 20:
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- GVL_BigStation.Order_CancelStep = 21;
- break;
- case 21:
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
- {
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
- GVL_BigStation.Order_CancelStep = 22;
- }
- break;
- case 22:
- GVL_BigStation.SiemensSendRecipeStatus = 0;
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
- });
- MessageNotify.GetInstance.ShowRunLog($"正在执行请求订单流程,配方还未到PLC,订单号:{GVL_BigStation.Order_CancelRecipeCode}");
- GVL_BigStation.Order_Cancel = false;
- GVL_BigStation.Order_CancelRecipeCode = "";
- GVL_BigStation.Order_CancelStep = 0;
- break;
-
- case 30:
- foreach (var item in SiemensRecipeQueue)
- {
- if (item.Value.Contains(code))
- {
- if (GVL_BigStation.RecipeDosingStatus[item.Key - 1] != 0)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true);
- HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode);
- GVL_BigStation.RecipeDosingStatus[item.Key - 1] = 0;
- item.Value.TryDequeue(out code);
- GVL_BigStation.Order_CancelStep = 32;
- MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
- }
- else
- {
- GVL_BigStation.Order_CancelStep = 32;
- MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:{code}");
- }
- }
- }
- break;
- case 32:
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
- GVL_BigStation.Order_CancelStep = 33;
- break;
- case 33:
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
- {
- SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
- });
- GVL_BigStation.Order_CancelStep = 0;
- MessageNotify.GetInstance.ShowRunLog($"队列1,西门子取消订单完成,订单号:{code}");
- }
- break;
- default:
- break;
- }
- }
- }
- #endregion
- #region 配料
- foreach (var data in SiemensRecipeQueue)
- {
- int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == data.Value.ElementAt(0));
- if (index >= 0 && index < SiemensRecipes.Count)
- {
- string code = SiemensRecipes.ElementAt(index).RecipeCode;
- int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
- if (GVL_BigStation.RecipeDosingStatus[data.Key] == 0 && GVL_BigStation.AllowIssueRecipe[data.Key] && GVL_BigStation.IsTrayArrive[trayCode - 1])//配方4是否允许下发配发
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- if (!GVL_BigStation.BarrelWasherSign)//其他配方在洗桶时,等待其他配方洗完,在发送数据
- {
- GVL_BigStation.BarrelWasherSign = true;
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
-
- GVL_BigStation.RecipeDosingTime[data.Key] = DateTime.Now;
- HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write($"DB99.DBX0.{2 + data.Key}", true);
- GVL_BigStation.RecipeDosingStatus[data.Key] = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- }
- else
- {
- GVL_BigStation.RecipeDosingTime[data.Key] = DateTime.Now;
- HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
- HKDevice.HK_PLC_S7.Write($"DB99.DBX0.{2 + data.Key}", true);
- GVL_BigStation.RecipeDosingStatus[data.Key] = 1;
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
- }
- }
- if (GVL_BigStation.RecipeDosingStatus[data.Key] == 1 && GVL_BigStation.ReceviceFinishRecipe[data.Key])
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},洗桶复位");
- }
- GVL_BigStation.RecipeDosingStatus[data.Key] = 2;
- HKDevice.HK_PLC_S7.Write($"DB99.DBX0.{2 + data.Key}", true);
- StockBinParReset();
- MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
- }
- if (GVL_BigStation.RecipeDosingStatus[data.Key] == 2 && GVL_BigStation.DosingFinishRecipe[data.Key])
- {
- if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
- {
- GVL_BigStation.BarrelWasherSign = false;
- }
- MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
- ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index));
- 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);
- MessageNotify.GetInstance.ShowRunLog($"配方{data.Key},配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg");
- }
- FinishData.Ask_For_Finish = true;
- double a = DateTime.Now.Subtract(GVL_BigStation.RecipeDosingTime[data.Key]).TotalSeconds;
- FinishData.ProcessTime = Convert.ToInt16(a);
- SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
- MessageNotify.GetInstance.ShowRunLog($"{code}配方配料完成,将信号反馈给西门子");
- }
- data.Value.TryDequeue(out code);
- 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);//制作完成,移除当前配方
- });
- }
- HKDevice.HK_PLC_S7.Write($"DB99.DBX1.{data.Key + 3}", true);
- GVL_BigStation.RecipeDosingStatus[data.Key] = 3;
- }
- if (GVL_BigStation.RecipeDosingStatus[data.Key] == 3 && GVL_BigStation.DosingFinishRecipe[data.Key] == false)
- {
- HKDevice.HK_PLC_S7.Write($"DB99.DBX1.{data.Key + 3}", false);
- GVL_BigStation.RecipeDosingStatus[data.Key] = 0;
- }
- }
- }
- #endregion
- }
- /// <summary>
- /// 读取配料完成时,每个料仓的配料重量
- /// </summary>
- /// <param name="recipes"></param>
- public void ReadStockBinDosingWeight(RecipeData recipes)
- {
- foreach (var item in recipes.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;
- }
- }
- }
-
-
- /// <summary>
- /// 发送操作,直到收到确认信号
- /// </summary>
- /// <param name="operate"></param>
- /// <param name="ack"></param>
- /// <param name="retrySecond"></param>
- /// <returns></returns>
- /// <exception cref="ArgumentNullException"></exception>
- private bool SendDataOperation(Action operate, Func<bool> ack, int retrySecond = 3)
- {
- if (operate is null)
- {
- throw new ArgumentNullException("operate", "需要执行的操作不可为Null。");
- }
-
- if (ack is null)
- {
- throw new ArgumentNullException("ack", "验证确认的委托不可为Null。");
- }
-
- var isSuccess = false;
- var isConnected = SiemensDevice.IsConnected;
- var retryDelay = TimeSpan.FromSeconds(retrySecond);
-
- operate?.Invoke();
-
- isSuccess = ack.Invoke();
- while (!isSuccess)
- {
- if (isConnected)
- {
- Thread.Sleep(retryDelay);
- operate?.Invoke();
- isSuccess = isSuccess && ack.Invoke();
- }
- }
-
- return isSuccess;
- }
-
- private void CleanFinishData()
- {
- if ((GVL_BigStation.Recipe1DosingFinish || GVL_BigStation.Recipe2DosingFinish || GVL_BigStation.Recipe3DosingFinish || GVL_BigStation.Recipe4DosingFinish))
- {
- FinishData.Order_No = "";
- FinishData.Product_Code = "";
- FinishData.job_No = 0;
- for (int i = 0; i < 20; i++)
- {
- FinishData.Material[i] = new UDT1();
- }
- FinishData.Ask_For_Finish = false;
- FinishData.ProcessTime = 0;
- SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
-
- }
- }
- }
- }
|