Form_Home.cs 579 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. /*
  40. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  41. */
  42. namespace MainForm
  43. {
  44. /// <summary>
  45. /// 记录日志的委托
  46. /// </summary>
  47. /// <param name="logType">日志类型</param>
  48. /// <param name="message">日志信息</param>
  49. public delegate void HomeMessageHandler(LogType logType, string message);
  50. /// <summary>
  51. /// 主页窗体
  52. /// </summary>
  53. public partial class Form_Home : Form
  54. {
  55. #region 常量
  56. //文本常量
  57. private const string Head = "开始采集";
  58. private const string Tail = "采集完成";
  59. private const string Body = "工位出站数据";
  60. private const string BodyCheck = "工位点检数据";
  61. private const string BodyRun = "整线运行数据";
  62. private const string BodyAlarm = "整线报警数据";
  63. #endregion 常量
  64. #region 变量
  65. /// <summary>
  66. /// 委托-记录日志的方法
  67. /// </summary>
  68. public event HomeMessageHandler MessageEvent;
  69. /// <summary>
  70. /// 日志接口
  71. /// </summary>
  72. ILogNet _PLCLogNet;
  73. /// <summary>
  74. /// 用于记录IOT MQTT日志
  75. /// </summary>
  76. ILogNet _IOTMqttLogNet;
  77. /// <summary>
  78. /// 用于记录AGV MQTT日志
  79. /// </summary>
  80. ILogNet _AGVMqttLogNet;
  81. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  82. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  83. // 间隔时间
  84. private int IntervalReadPLC = 300; //ms 读PLC
  85. private int IntervalMonitorMES = 1000; //ms MES心跳
  86. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  87. // 软件状态
  88. private bool IsRun = true;
  89. #region PLC 与 TCP对象
  90. // 定义一个字典,存plc对象(通讯)
  91. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  92. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  93. // 定义TCPClient对象列表
  94. Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  95. // 定义MQTTHelper对象
  96. MQTTHelper _MQTTHelper = new MQTTHelper();
  97. #endregion PLC 与 TCP对象
  98. /// <summary>
  99. /// 上次的设备运行信息
  100. /// </summary>
  101. private string lineWorkingData1_OldStr = string.Empty;
  102. /// <summary>
  103. /// 设备报警字典-当前结果
  104. /// Dictionary<工位代码,List<报警信息>>
  105. /// </summary>
  106. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  107. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  108. #endregion 变量
  109. #region 窗体基础事件
  110. /// <summary>
  111. /// 初始化
  112. /// </summary>
  113. public Form_Home()
  114. {
  115. InitializeComponent();
  116. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  117. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  118. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  119. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  120. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  121. }
  122. /// <summary>
  123. /// 窗体加载事件
  124. /// </summary>
  125. private void Form_Home_Load(object sender, EventArgs e)
  126. {
  127. try
  128. {
  129. AddMessage(LogType.Info, "开始初始化程序");
  130. InitalDicAlarm(); // 实例化报警字典
  131. //组建plc对象字典
  132. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  133. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  134. if (GlobalContext.IsUsePLC1)
  135. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  136. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  137. if (GlobalContext.IsUsePLC2)
  138. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  139. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  140. if (GlobalContext.IsUsePLC3)
  141. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  142. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  143. if (GlobalContext.IsUsePLC4)
  144. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  145. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  146. if (GlobalContext.IsUsePLC5)
  147. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  148. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  149. if (GlobalContext.IsUsePLC6)
  150. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  151. if (GlobalContext.IsUsePLC7)
  152. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  153. if (GlobalContext.IsUsePLC8)
  154. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  155. if (GlobalContext.IsUsePLC9)
  156. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  157. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  158. {
  159. if (plcEIP != null)
  160. {
  161. try
  162. {
  163. (int, string) result = plcEIP.Connect();
  164. }
  165. catch (Exception ex)
  166. {
  167. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  168. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  169. }
  170. }
  171. }
  172. /*
  173. //plc1Alarm.Connect();
  174. foreach (ModbusClientHelper modbusClient in Funs.Values)
  175. {
  176. if (modbusClient != null)
  177. {
  178. try
  179. {
  180. modbusClient.Connect();
  181. }
  182. catch (Exception ex)
  183. {
  184. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  185. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  186. }
  187. }
  188. }
  189. */
  190. // 采集任务
  191. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  192. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  193. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  194. if (GlobalContext.IsUsePLC1)
  195. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  196. if (GlobalContext.IsUsePLC2)
  197. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  198. if (GlobalContext.IsUsePLC3)
  199. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  200. if (GlobalContext.IsUsePLC4)
  201. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  202. if (GlobalContext.IsUsePLC5)
  203. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  204. if (GlobalContext.IsUsePLC6)
  205. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  206. if (GlobalContext.IsUsePLC7)
  207. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  208. if (GlobalContext.IsUsePLC8)
  209. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  210. if (GlobalContext.IsUsePLC9)
  211. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  212. #region 初始化
  213. try
  214. {
  215. // 开启边线MES(绑定/查询数据)
  216. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  217. //if (mesRoute == 0)
  218. //{
  219. // //picMESStatus.Image = imageListState.Images[1];
  220. // //GlobalContext.MESIsConnect = true;
  221. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  222. //}
  223. //else
  224. //{
  225. // //picMESStatus.Image = imageListState.Images[0];
  226. // //GlobalContext.MESIsConnect = false;
  227. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  228. //}
  229. // 开启MES(Http)
  230. if (GlobalContext.IsUseMES)
  231. {
  232. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  233. if (mesret)
  234. {
  235. picMESStatus.Image = imageListState.Images[1];
  236. GlobalContext.MESIsConnect = true;
  237. AddMessage(LogType.Info, "小米MES初始连接成功!");
  238. }
  239. else
  240. {
  241. picMESStatus.Image = imageListState.Images[0];
  242. GlobalContext.MESIsConnect = false;
  243. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  244. }
  245. }
  246. // 开启IOT(MQTT)
  247. if (GlobalContext.IsUseIot)
  248. {
  249. string addr = GlobalContext.MQTTServerHost;
  250. int port = GlobalContext.MQTTServerPort;
  251. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer(addr, port, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  252. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  253. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  254. {
  255. picIot.Image = imageListState.Images[1];
  256. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  257. XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  258. }
  259. else
  260. {
  261. picIot.Image = imageListState.Images[0];
  262. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  263. }
  264. }
  265. // 开启AGV(Http与MQTT)
  266. if (GlobalContext.IsUseAGV)
  267. {
  268. // AGV HTTP
  269. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  270. if (mesret1)
  271. {
  272. picAgvHttp.Image = imageListState.Images[1];
  273. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  274. }
  275. else
  276. {
  277. picAgvHttp.Image = imageListState.Images[0];
  278. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  279. }
  280. string agvMqttIp = GlobalContext.MQTTServerHost;
  281. int agvMqttPort = GlobalContext.MQTTServerPort;
  282. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  283. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  284. // AGV MQTT
  285. if (result_MQTT.ResultCode == 1)
  286. {
  287. picAgvMqtt.Image = imageListState.Images[1];
  288. GlobalContext.AGVMQTTIsConnect = true;
  289. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  290. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  291. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  292. }
  293. else
  294. {
  295. picAgvMqtt.Image = imageListState.Images[0];
  296. GlobalContext.AGVMQTTIsConnect = false;
  297. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  298. }
  299. }
  300. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  301. Task.Run(MonitorMESConnect);
  302. // 查询PLC连接状态
  303. foreach (int plcNo in FunsEip.Keys)
  304. {
  305. bool connected = FunsEip[plcNo].IsConnected;
  306. if (connected)
  307. {
  308. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  309. AddMessage(LogType.Info, msg);
  310. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  311. }
  312. else
  313. {
  314. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  315. AddMessage(LogType.Info, msg);
  316. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  317. }
  318. }
  319. // PLC4时 初始化扫码器TCP
  320. //if (GlobalContext.IsUsePLC4)
  321. // HpTCPClientInit();
  322. // 开启PLC的业务处理线程-监听PLC点位+状态
  323. foreach (Task task in TaskReadProcess)
  324. {
  325. if (task != null)
  326. task.Start();
  327. }
  328. //// 开启“获取线体报警数据”的线程
  329. //TaskReadAlarm.Start();
  330. ////下传MES信息给1工位(先判断下plc对象数量)
  331. //if (Funs.Count > 1)
  332. // DownLoadProductInfo(1);
  333. AddMessage(LogType.Info, "程序初始化完成");
  334. }
  335. catch (Exception ex)
  336. {
  337. string str = ex.StackTrace;
  338. this.BeginInvoke(new Action(() =>
  339. {
  340. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  341. }));
  342. }
  343. #endregion
  344. }
  345. catch (Exception ex)
  346. {
  347. string str = ex.StackTrace;
  348. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  349. if (ex.Message != null && ex.Message.Contains("timed out"))
  350. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  351. else
  352. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  353. }
  354. }
  355. /// <summary>
  356. /// 窗体关闭事件
  357. /// </summary>
  358. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  359. {
  360. Closed2();
  361. }
  362. public void Closed2()
  363. {
  364. try
  365. {
  366. IsRun = false;
  367. Thread.Sleep(IntervalReadPLC);
  368. // 断开TCP
  369. int count = _HPSocket_TcpClients.Count();
  370. for (int i = 0; i < count; i++)
  371. {
  372. try
  373. {
  374. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  375. {
  376. _HPSocket_TcpClients[i].Stop();
  377. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  378. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  379. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  380. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  381. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  382. }
  383. }
  384. catch { }
  385. }
  386. // 关闭Iot
  387. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  388. // 关闭AGV Mqtt
  389. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  390. }
  391. catch { }
  392. }
  393. #endregion 窗体基础事件
  394. #region 监控MES状态
  395. /// <summary>
  396. /// 监控MES连接状态
  397. /// </summary>
  398. private void MonitorMESConnect()
  399. {
  400. while (IsRun) // 运行被控线程
  401. {
  402. try
  403. {
  404. // 开启MES(Http)
  405. if (GlobalContext.IsUseMES)
  406. {
  407. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  408. if (mesret)
  409. {
  410. picMESStatus.Image = imageListState.Images[1];
  411. GlobalContext.MESIsConnect = true;
  412. }
  413. else
  414. {
  415. picMESStatus.Image = imageListState.Images[0];
  416. GlobalContext.MESIsConnect = false;
  417. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  418. }
  419. }
  420. // 开启IOT(MQTT)
  421. if (GlobalContext.IsUseIot)
  422. {
  423. bool iIot = XiaomiMqttClient.IsOpen;
  424. if (iIot)
  425. picIot.Image = imageListState.Images[1];
  426. else
  427. {
  428. picIot.Image = imageListState.Images[0];
  429. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  430. }
  431. }
  432. // 开启AGV(Http与MQTT)
  433. if (GlobalContext.IsUseAGV)
  434. {
  435. // AGV Http
  436. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  437. if (mesret1)
  438. picAgvHttp.Image = imageListState.Images[1];
  439. else
  440. {
  441. picAgvHttp.Image = imageListState.Images[0];
  442. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  443. }
  444. // AGV MQTT
  445. if (GlobalContext.AGVMQTTIsConnect)
  446. picAgvMqtt.Image = imageListState.Images[1];
  447. else
  448. {
  449. picAgvMqtt.Image = imageListState.Images[0];
  450. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  451. }
  452. }
  453. }
  454. catch (Exception ex)
  455. {
  456. string str = ex.StackTrace;
  457. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  458. }
  459. Thread.Sleep(IntervalMonitorMES);
  460. }
  461. }
  462. #endregion 监控MES连接状态
  463. #region 采集设备状态、运行数据、报警数据
  464. /// <summary>
  465. /// 请求设备状态 5000
  466. /// </summary>
  467. /// <param name="no">1</param>
  468. /// <param name="stationNameStr"></param>
  469. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  470. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  471. {
  472. try
  473. {
  474. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  475. {
  476. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  477. return result;
  478. }
  479. else
  480. {
  481. return 0;
  482. }
  483. }
  484. catch (Exception ex)
  485. {
  486. string str = ex.StackTrace;
  487. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  488. return 0;
  489. }
  490. }
  491. /// <summary>
  492. /// 检查是否可采集点检数据 - 不取新值
  493. /// 5000不为1时可点检
  494. /// </summary>
  495. /// <returns></returns>
  496. public bool CheckCanSpotcheck1(int deviceState)
  497. {
  498. //return true;
  499. //D5000 = 1,代表设备控制状态处于运行状态
  500. //D5000 = 2, 代表设备控制状态处于故障状态
  501. //D5000 = 3,代表设备控制状态处于缺料状态
  502. //D5000 = 4, 代表设备控制状态处于待机状态
  503. //D5000 = 5,代表设备控制状态处于维修状态
  504. return deviceState != 1;
  505. }
  506. /// <summary>
  507. /// 检查是否可采集产品数据 - 不取新值
  508. /// </summary>
  509. /// <returns></returns>
  510. public bool CheckCanCollData(int deviceState)
  511. {
  512. return deviceState == 0; // 点检时该值不为0
  513. }
  514. /// <summary>
  515. /// 获取设备报警数据与获取设备运行信息
  516. /// </summary>
  517. private async void ReadAlarmAllPLC()
  518. {
  519. // [S1] Tray盘上料装备(板测)
  520. // [S2] FCT(板测)
  521. // [S3] 值板机
  522. // [S4] 取放桁架
  523. // [S5] Tray盘下料装备
  524. /// 上位机心跳
  525. /// 获取设备报警数据与状态信息
  526. string stationNameStr = "获取设备报警数据与状态信息";
  527. while (IsRun)
  528. {
  529. try
  530. {
  531. if (!GlobalContext._IsCon_plc1Alarm)
  532. {
  533. UpdatePLCMonitor(1, -2, 0);
  534. continue;
  535. }
  536. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  537. {
  538. DateTime dtNow = DateTime.Now;
  539. #region 获取设备运行信息
  540. try
  541. {
  542. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  543. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  544. lineWorkingData1.LineName = GlobalContext.LineCode;
  545. //
  546. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  547. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  548. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  549. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  550. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  551. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  552. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  553. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  554. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  555. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  556. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  557. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  558. lineWorkingData1.CreateTime = DateTime.Now;
  559. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  560. // UI展示-展示到设备状态页
  561. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  562. {
  563. // 查询数据库最新一条数据,确定是不是更新
  564. string qSql = @"SELECT top(1) [GUID]
  565. ,[LineName]
  566. ,[BootTimeLong]
  567. ,[NormalTimeLong]
  568. ,[StandbyTimeLong]
  569. ,[FaultTimeLong]
  570. ,[MaterialShortageTimeLong]
  571. ,[MaintenanceTimeLong]
  572. ,[FaultNumber]
  573. ,[OutputNumber]
  574. ,[QualifiedNumber]
  575. ,[QualifiedRate]
  576. ,[DesignRhythm]
  577. ,[RealityRhythm]
  578. ,[CreateTime]
  579. FROM [LineWorkingData]
  580. where [CreateTime] > '{0}'
  581. and [LineName]='{1}'
  582. order by [CreateTime] desc
  583. ";
  584. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  585. var ds = SQLHelper_New.Query(qSql, null);
  586. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  587. {
  588. var dataDBlast = new LineWorkingData_ThisTime();
  589. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  590. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  591. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  592. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  593. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  594. {
  595. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  596. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  597. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  598. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  599. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  600. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  601. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  602. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  603. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  604. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  605. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  606. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  607. string usql = dataDBlast.ToStringUpdate();
  608. SQLHelper_New.ExecuteSQL(usql, null);
  609. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  610. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  611. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  612. }
  613. }
  614. else
  615. {
  616. // 插入
  617. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  618. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  619. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  620. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  621. }
  622. }
  623. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  624. {
  625. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  626. //// 本次开机设备运行情况
  627. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  628. //Task.Run(() =>
  629. //{
  630. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  631. // {
  632. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  633. // }
  634. //});
  635. // 本日设备运行情况
  636. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  637. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  638. {
  639. // 更新
  640. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  641. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  642. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  643. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  644. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  645. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  646. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  647. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  648. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  649. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  650. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  651. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  652. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  653. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  654. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  655. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  656. }
  657. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  658. {
  659. // 插入
  660. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  661. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  662. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  663. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  664. }
  665. await Task.Run(() =>
  666. {
  667. try
  668. {
  669. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  670. {
  671. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  672. }
  673. }
  674. catch { }
  675. });
  676. }
  677. }
  678. catch (Exception ex)
  679. {
  680. string str = ex.StackTrace;
  681. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  682. }
  683. #endregion 获取设备运行信息
  684. #region 报警数据
  685. try
  686. {
  687. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  688. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  689. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  690. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  691. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  692. {
  693. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  694. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  695. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  696. {
  697. isNeedUpdUI = true; // 需要更新历史报警UI信息
  698. // 记录
  699. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  700. switch (dicAlarms_Cur_PLC1[i].是否报警)
  701. {
  702. case true: // 报警
  703. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  704. {
  705. GUID = Guid.NewGuid().ToString(),
  706. LineName = GlobalContext.LineCode, // 线体
  707. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  708. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  709. StartTime = dtNow // 开始时间
  710. };
  711. // 传输到页面
  712. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  713. {
  714. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  715. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  716. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  717. 开始时间 = dtNow
  718. });
  719. // 新增到数据库
  720. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  721. SaveAlarmDataByDB(stationNameStr, data1, false);
  722. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  723. break;
  724. case false: // 消除报警
  725. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  726. {
  727. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  728. {
  729. GUID = Guid.NewGuid().ToString(),
  730. LineName = GlobalContext.LineCode, // 线体
  731. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  732. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  733. StartTime = dtNow, // 开始时间
  734. EndTime = dtNow, // 开始时间
  735. PersistTime = 1, // 耗时1s
  736. };
  737. // 新增
  738. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  739. SaveAlarmDataByDB(stationNameStr, data2, false);
  740. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  741. }
  742. else
  743. {
  744. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  745. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  746. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  747. // 修改
  748. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  749. SaveAlarmDataByDB(stationNameStr, data3, true);
  750. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  751. }
  752. break;
  753. default:
  754. break;
  755. }
  756. }
  757. }
  758. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  759. // 有新报警则更新
  760. if (isNeedUpdUI)
  761. {
  762. // UI展示 - 展示到设备状态页
  763. await Task.Run(() =>
  764. {
  765. try
  766. {
  767. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  768. {
  769. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  770. if (Form_Main.formDevAlarm.Visible)
  771. {
  772. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  773. }
  774. }
  775. }
  776. catch { }
  777. });
  778. }
  779. }
  780. catch (Exception ex)
  781. {
  782. string str = ex.StackTrace;
  783. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  784. }
  785. #endregion 报警数据
  786. UpdatePLCMonitor(1, -2, 1);
  787. }
  788. else
  789. {
  790. UpdatePLCMonitor(1, -2, 0);
  791. }
  792. }
  793. catch (Exception ex)
  794. {
  795. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  796. }
  797. Thread.Sleep(IntervalAlarm);
  798. }
  799. }
  800. #endregion 轮询PLC
  801. #region 下发订单信息
  802. ///// <summary>
  803. ///// 壳体上料(下发工单)的交互逻辑
  804. ///// </summary>
  805. ///// <param name="no"></param>
  806. ///// <exception cref="NotImplementedException"></exception>
  807. //private void ReadStation_DownOrderInfo(int plcNo)
  808. //{
  809. // // [S1] Tray盘上料装备(板测)
  810. // // [S2] FCT(板测)
  811. // // [S3] 值板机
  812. // // [S4] 取放桁架
  813. // // [S5] Tray盘下料装备
  814. // /// 上位机心跳
  815. // /// 获取设备报警数据与状态信息
  816. // string stationNameStr = "[S0]壳体上料";
  817. // while (IsRun)
  818. // {
  819. // try
  820. // {
  821. // if (!GlobalContext._IsCon_Funs1)
  822. // {
  823. // UpdatePLCMonitor(plcNo, 0);
  824. // continue;
  825. // }
  826. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  827. // {
  828. // #region 壳体上料(下发工单)
  829. // try
  830. // {
  831. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  832. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  833. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  834. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  835. // // 重置数据和信号
  836. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  837. // {
  838. // // 清空写给PLC的数据
  839. // int[] i497 = new int[1] { 0 };
  840. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  841. // // MES_Flag重置为0
  842. // int[] i500 = new int[1] { 0 };
  843. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  844. // }
  845. // }
  846. // catch (Exception ex)
  847. // {
  848. // string str = ex.StackTrace;
  849. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  850. // }
  851. // #endregion 壳体上料(下发工单)
  852. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  853. // }
  854. // else
  855. // {
  856. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  857. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  858. //
  859. // Funs[plcNo].Connect();
  860. // }
  861. // }
  862. // catch (Exception ex)
  863. // {
  864. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  865. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  866. //
  867. // Funs[plcNo].ReConnect();
  868. // }
  869. // Thread.Sleep(IntervalReadPLC);
  870. // }
  871. //}
  872. ///// <summary>
  873. ///// 下发订单信息到PLC
  874. ///// </summary>
  875. ///// <param name="no">PLC编号</param>
  876. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  877. //{
  878. // try
  879. // {
  880. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  881. // {
  882. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  883. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  884. // }
  885. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  886. // }
  887. // catch (Exception ex)
  888. // {
  889. // string str = ex.StackTrace;
  890. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  891. // }
  892. //}
  893. /// <summary>
  894. /// 下发清料信号
  895. /// </summary>
  896. /// <param name="no">PLC编号</param>
  897. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  898. {
  899. try
  900. {
  901. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  902. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  903. return true;
  904. }
  905. catch (Exception ex)
  906. {
  907. string str = ex.StackTrace;
  908. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  909. return false;
  910. }
  911. }
  912. #endregion 下发订单信息
  913. #region Xiaomi 贲流
  914. #region 公共方法
  915. private static bool ProgressState = false;
  916. private static readonly object lockObj = new object(); // 锁对象
  917. private static bool isCollectingFlagLeft;
  918. private static bool isCollectingFlagRight;
  919. /// <summary>
  920. /// float[]转为string
  921. /// </summary>
  922. public string FloatArrayToString(float[] nScrewResults)
  923. {
  924. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  925. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  926. }
  927. /// <summary>
  928. /// short[]转为string
  929. /// </summary>
  930. public string ShortArrayToString(short[] nScrewResults)
  931. {
  932. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  933. return string.Join(",", nScrewResults);
  934. }
  935. /// <summary>
  936. /// 写入PLC重复三次
  937. /// </summary>
  938. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  939. {
  940. int i = 0;
  941. int nRet = 0;
  942. string strRet = "";
  943. try
  944. {
  945. while (i < 3) // 最多上传三次
  946. {
  947. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  948. if (nRet == 0) //成功
  949. {
  950. break;
  951. }
  952. else
  953. {
  954. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  955. i++;
  956. }
  957. }
  958. return (nRet, strRet);
  959. }
  960. catch (Exception ex)
  961. {
  962. return (1, ex.Message);
  963. }
  964. }
  965. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  966. {
  967. try
  968. {
  969. // 获取当前日期
  970. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  971. // 构建保存路径
  972. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  973. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  974. // 确保目录存在
  975. Directory.CreateDirectory(savePath);
  976. // 文件名
  977. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  978. string filePath = Path.Combine(savePath, fileName);
  979. // 确保不会超出数组长度,只取前14个或数组的实际长度
  980. int count = Math.Min(14, fScrewTimes.Length);
  981. using (StreamWriter sw = new StreamWriter(filePath))
  982. {
  983. for (int i = 0; i < count; i++)
  984. {
  985. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  986. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  987. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  988. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  989. sw.WriteLine(); // 空行分隔不同螺丝的信息
  990. }
  991. }
  992. return (0, "");
  993. }
  994. catch (Exception ex)
  995. {
  996. return (1, ex.Message);
  997. }
  998. }
  999. /// <summary>
  1000. /// 调用进站接口并保存进站数据
  1001. /// </summary>
  1002. /// <param name="stationNameStr">工站信息</param>
  1003. /// <param name="workorder_code">工单号</param>
  1004. /// <param name="mtltmrk">型号(物料号)</param>
  1005. /// <param name="sn">产品SN</param>
  1006. /// <param name="items">进站数据</param>
  1007. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1008. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1009. {
  1010. int result = 0;
  1011. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1012. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1013. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1014. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1015. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1016. inRequest_Body.unitSn = sn; // 产品SN
  1017. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1018. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1019. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1020. StationIn stationIn = new StationIn()
  1021. {
  1022. Workorder_code = workorder_code, // 车间订单号
  1023. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1024. Sn = sn, // SN
  1025. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1026. Parameter_values = items, // 进站数据
  1027. Write_user = inRequest_Body.userId, // 员工Id
  1028. Test_time = inRequest_Body.clientTime // 进站时间
  1029. };
  1030. // 本地数据
  1031. string sql = stationIn.ToStringInsert(0);
  1032. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1033. result = ret == "成功" ? 1 : 6;
  1034. //await Task.Delay(200);
  1035. // 上传MES
  1036. if (GlobalContext.IsSendStationIn)
  1037. {
  1038. try
  1039. {
  1040. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1041. string mesRet = string.Empty;
  1042. int i = 0;
  1043. while (i < 2) // 1009会多次尝试上传
  1044. {
  1045. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1046. if (response != null && response.header.code == "200")
  1047. break;
  1048. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1049. i++;
  1050. i++;
  1051. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1052. // 记录失败原因
  1053. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1054. }
  1055. if (response?.header?.code == "200")
  1056. {
  1057. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1058. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1059. result = ret_Upd == "成功" ? 1 : 6;
  1060. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1061. }
  1062. else
  1063. {
  1064. result = 5;
  1065. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1066. }
  1067. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1068. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1069. }
  1070. catch (Exception ex)
  1071. {
  1072. result = 6;
  1073. string str = ex.StackTrace;
  1074. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1075. }
  1076. }
  1077. return result;
  1078. }
  1079. /// <summary>
  1080. /// 选择如何记录出站数据
  1081. /// </summary>
  1082. /// <param name="items">出站数据</param>
  1083. /// <param name="equipmentCode">设备编号</param>
  1084. /// <param name="processItem">测试项目</param>
  1085. /// <param name="workorder_code">车间订单号</param>
  1086. /// <param name="batch_num">批次号</param>
  1087. /// <param name="mtltmrk">型号</param>
  1088. /// <param name="proDate">日期</param>
  1089. /// <param name="supplierCode">供应商代码</param>
  1090. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1091. /// <returns>上传成功时返回1;失败返回0</returns>
  1092. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1093. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1094. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode)
  1095. {
  1096. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1097. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode);
  1098. }
  1099. /// <summary>
  1100. /// 图片存入数据库
  1101. /// </summary>
  1102. /// <param name="stPLC_MesData"></param>
  1103. /// <param name="stationCode"></param>
  1104. /// <param name="stationName"></param>
  1105. private void SaveDBbyFileInfo(OP40_MesData_t stPLC_MesData, string stationCode, string stationName) {
  1106. string path = GlobalContext.FilePath;
  1107. string leftPath = path + "\\Left";
  1108. string rightPath = path + "\\Right";
  1109. string sql = "";
  1110. // 获取所有图片文件
  1111. List<string> imageFiles_L = GetAllImageFiles(leftPath);
  1112. List<string> imageFiles_R = GetAllImageFiles(rightPath);
  1113. foreach (string imageFile in imageFiles_L) {
  1114. sql = "";
  1115. }
  1116. }
  1117. /// <summary>
  1118. /// 获取路径下的所有图片
  1119. /// </summary>
  1120. /// <param name="directoryPath"></param>
  1121. /// <returns></returns>
  1122. private List<string> GetAllImageFiles(string directoryPath)
  1123. {
  1124. var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
  1125. var imageFiles = new List<string>();
  1126. try
  1127. {
  1128. // 遍历目录及子目录中的所有文件
  1129. foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
  1130. {
  1131. // 获取文件扩展名并检查是否为图片格式
  1132. string extension = Path.GetExtension(file);
  1133. if (imageExtensions.Contains(extension))
  1134. {
  1135. imageFiles.Add(file);
  1136. }
  1137. }
  1138. }
  1139. catch (Exception ex)
  1140. {
  1141. OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
  1142. }
  1143. return imageFiles;
  1144. }
  1145. /// <summary>
  1146. /// 添加出站数据(提交到MES+本地保存到数据库)
  1147. /// </summary>
  1148. /// <param name="items">出站数据</param>
  1149. /// <param name="equipmentCode">设备编号</param>
  1150. /// <param name="processItem">测试项目</param>
  1151. /// <param name="workorder_code">车间订单号</param>
  1152. /// <param name="batch_num">批次号</param>
  1153. /// <param name="mtltmrk">型号</param>
  1154. /// <param name="proDate">日期</param>
  1155. /// <param name="supplierCode">供应商代码</param>
  1156. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1157. /// <returns>上传成功时返回1;失败返回0</returns>
  1158. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1159. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1160. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode)
  1161. {
  1162. int upload = 0;
  1163. int result = 0;
  1164. ProcessData processData = new ProcessData()
  1165. {
  1166. Equipment_code = equipmentCode,
  1167. Workorder_code = workorder_code,
  1168. Batch_number = batch_num,
  1169. Sn = sn, // SN
  1170. Testitem = processItem,
  1171. Parameter_values = items,
  1172. Write_user = GlobalContext.CurrentUser,
  1173. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1174. };
  1175. // 本地数据
  1176. string sql = processData.ToStringInsert(upload);
  1177. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1178. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1179. // 上传MES
  1180. if (GlobalContext.IsSendProcessData)
  1181. {
  1182. try
  1183. {
  1184. string id = processData.ID.Copy();
  1185. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1186. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1187. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1188. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1189. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1190. outRequest_Body.unitSn = sn; // 产品SN
  1191. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1192. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1193. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1194. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1195. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1196. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1197. if (!string.IsNullOrEmpty(partBarcode))
  1198. {
  1199. outRequest_Body.unitData.keyMaterial.Add(
  1200. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1201. {
  1202. bindSort = 1,
  1203. materialSn = partBarcode
  1204. }); // 设备数据 - 部件码
  1205. }
  1206. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1207. if (GlobalContext.IsSendProcessData)
  1208. {
  1209. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1210. string mesRet = string.Empty;
  1211. int i = 0;
  1212. while (i < 2) // 1009会多次尝试上传
  1213. {
  1214. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1215. if (response != null && response.header.code == "200")
  1216. break;
  1217. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1218. i++;
  1219. i++;
  1220. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1221. // 记录失败原因
  1222. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1223. }
  1224. if (response?.header?.code == "200")
  1225. {
  1226. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1227. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1228. result = 1;
  1229. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1230. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1231. }
  1232. else
  1233. {
  1234. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1235. }
  1236. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1237. JsonConvert.SerializeObject(response), id);
  1238. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1239. }
  1240. }
  1241. catch (Exception ex)
  1242. {
  1243. string str = ex.StackTrace;
  1244. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1245. }
  1246. }
  1247. return result;
  1248. }
  1249. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1250. //{
  1251. // Stopwatch stopwatch = new Stopwatch();
  1252. // stopwatch.Start();
  1253. // try
  1254. // {
  1255. // // 初始化 AtlasScrew 实例
  1256. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1257. // atlasScrew1.Initial();
  1258. // // 存储结果的列表
  1259. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1260. // // 存储角度和扭力的字符串列表
  1261. // List<string> angleStrs = new List<string>();
  1262. // List<string> torqueStrs = new List<string>();
  1263. // // 上一次获取的数据
  1264. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1265. // while (isExitAtlasLeft) // 检查是否收集数据
  1266. // {
  1267. // // 获取当前数据
  1268. // var currentResult = atlasScrew1.GetResults();
  1269. // // 判断是否为新数据
  1270. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1271. // {
  1272. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1273. // // 更新角度和扭力的字符串列表
  1274. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1275. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1276. // // 计算角度、扭力、起始扭力和最大扭力
  1277. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1278. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1279. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1280. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1281. // // 将新数据添加到结果列表
  1282. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1283. // // 更新上一次获取的数据
  1284. // lastResult = currentResult;
  1285. // }
  1286. // // 等待一段时间后再次检查
  1287. // Thread.Sleep(20); // 轮询间隔时间
  1288. // // 如果触发了出站,则退出循环
  1289. // if (!isExitAtlasLeft)
  1290. // {
  1291. // break;
  1292. // }
  1293. // }
  1294. // // 生成文件名
  1295. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1296. // // 写入数据到文件
  1297. // using (StreamWriter writer = new StreamWriter(fileName))
  1298. // {
  1299. // // 写入标题行
  1300. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1301. // // 写入每一行数据
  1302. // foreach (var result in results)
  1303. // {
  1304. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1305. // }
  1306. // }
  1307. // stopwatch.Stop();
  1308. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1309. // }
  1310. // catch (Exception ex)
  1311. // {
  1312. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1313. // }
  1314. // finally
  1315. // {
  1316. // // 重置标志变量
  1317. // isExitAtlasLeft = false;
  1318. // }
  1319. //}
  1320. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1321. //{
  1322. // Stopwatch stopwatch = new Stopwatch();
  1323. // stopwatch.Start();
  1324. // try
  1325. // {
  1326. // // 初始化 AtlasScrew 实例
  1327. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1328. // atlasScrew2.Initial();
  1329. // // 存储结果的列表
  1330. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1331. // // 上一次获取的数据
  1332. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1333. // while (isExitAtlasRight) // 检查是否收集数据
  1334. // {
  1335. // // 获取当前数据
  1336. // var currentResult = atlasScrew2.GetResults();
  1337. // // 判断是否为新数据
  1338. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1339. // {
  1340. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1341. // // 将新数据写入PLC
  1342. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1343. // // 将新数据添加到结果列表
  1344. // results.Add(currentResult);
  1345. // // 更新上一次获取的数据
  1346. // lastResult = currentResult;
  1347. // }
  1348. // // 等待一段时间后再次检查
  1349. // Thread.Sleep(20); // 轮询间隔时间
  1350. // // 如果触发了出站,则退出循环
  1351. // if (!isExitAtlasRight)
  1352. // {
  1353. // break;
  1354. // }
  1355. // }
  1356. // // 将所有数据写入文件
  1357. // //WriteDataToFile(sn, direction, results);
  1358. // stopwatch.Stop();
  1359. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1360. // }
  1361. // catch (Exception ex)
  1362. // {
  1363. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1364. // }
  1365. // finally
  1366. // {
  1367. // // 重置标志变量
  1368. // isExitAtlasRight = false;
  1369. // }
  1370. //}
  1371. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1372. {
  1373. Stopwatch stopwatch = new Stopwatch();
  1374. stopwatch.Start();
  1375. int nRet = 0;
  1376. string strRet = "";
  1377. try
  1378. {
  1379. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1380. while (isCollectingFlagLeft)
  1381. {
  1382. // 从缓存中获取所有未处理的数据
  1383. var cachedData = atlasScrew.GetCachedDataLeft();
  1384. foreach (var currentResult in cachedData)
  1385. {
  1386. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1387. {
  1388. continue; // 跳过无效数据
  1389. }
  1390. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1391. // 写入PLC
  1392. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1393. {
  1394. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1395. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1396. };
  1397. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1398. if (nRet != 0)
  1399. {
  1400. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1401. }
  1402. else
  1403. {
  1404. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1405. }
  1406. // 构建保存路径
  1407. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1408. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1409. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1410. Directory.CreateDirectory(savePath); // 确保目录存在
  1411. // 构建文件名(以 SN + 序号命名)
  1412. string fileName = $"{sn}_{fileCounter}.txt";
  1413. string filePath = Path.Combine(savePath, fileName);
  1414. // 写入文件
  1415. using (StreamWriter writer = new StreamWriter(filePath))
  1416. {
  1417. writer.WriteLine("精度, 扭力");
  1418. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1419. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1420. {
  1421. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1422. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1423. writer.WriteLine($"{precision}, {torque}");
  1424. }
  1425. }
  1426. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1427. // 增加文件计数器
  1428. fileCounter++;
  1429. }
  1430. // 如果没有更多数据,则短暂休眠以节省资源
  1431. if (!cachedData.Any())
  1432. {
  1433. Thread.Sleep(10); // 根据需要调整休眠时间
  1434. }
  1435. // 如果触发了出站,则退出循环
  1436. if (!isCollectingFlagLeft)
  1437. {
  1438. break;
  1439. }
  1440. }
  1441. stopwatch.Stop();
  1442. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1443. }
  1444. catch (Exception ex)
  1445. {
  1446. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1447. }
  1448. finally
  1449. {
  1450. isCollectingFlagLeft = false;
  1451. }
  1452. }
  1453. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1454. {
  1455. Stopwatch stopwatch = new Stopwatch();
  1456. stopwatch.Start();
  1457. int nRet = 0;
  1458. string strRet = "";
  1459. try
  1460. {
  1461. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1462. while (isCollectingFlagRight)
  1463. {
  1464. // 从缓存中获取所有未处理的数据
  1465. var cachedData = atlasScrew.GetCachedDataLeft();
  1466. foreach (var currentResult in cachedData)
  1467. {
  1468. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1469. {
  1470. continue; // 跳过无效数据
  1471. }
  1472. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1473. // 写入PLC
  1474. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1475. {
  1476. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1477. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1478. };
  1479. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1480. if (nRet != 0)
  1481. {
  1482. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1483. }
  1484. else
  1485. {
  1486. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1487. }
  1488. // 构建保存路径
  1489. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1490. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1491. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1492. Directory.CreateDirectory(savePath); // 确保目录存在
  1493. // 构建文件名(以 SN + 序号命名)
  1494. string fileName = $"{sn}_{fileCounter}.txt";
  1495. string filePath = Path.Combine(savePath, fileName);
  1496. // 写入文件
  1497. using (StreamWriter writer = new StreamWriter(filePath))
  1498. {
  1499. writer.WriteLine("精度, 扭力");
  1500. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1501. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1502. {
  1503. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1504. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1505. writer.WriteLine($"{precision}, {torque}");
  1506. }
  1507. }
  1508. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1509. // 增加文件计数器
  1510. fileCounter++;
  1511. }
  1512. // 如果没有更多数据,则短暂休眠以节省资源
  1513. if (!cachedData.Any())
  1514. {
  1515. Thread.Sleep(10); // 根据需要调整休眠时间
  1516. }
  1517. // 如果触发了出站,则退出循环
  1518. if (!isCollectingFlagRight)
  1519. {
  1520. break;
  1521. }
  1522. }
  1523. stopwatch.Stop();
  1524. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1525. }
  1526. catch (Exception ex)
  1527. {
  1528. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1529. }
  1530. finally
  1531. {
  1532. isCollectingFlagRight = false;
  1533. }
  1534. }
  1535. #endregion
  1536. #region S1
  1537. /// <summary>
  1538. /// [S1] 壳体清洁上料装备
  1539. /// </summary>
  1540. /// <param name="plcNo">PLC编号</param>
  1541. private void ReadStation_S1(int plcNo)
  1542. {
  1543. string stationCode = "[OP10]";
  1544. string stationName = "壳体清洁上料";
  1545. string stationNameStr = stationCode + stationName;
  1546. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1547. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1548. string tagAgvCommName = "agvCommFrmPC";
  1549. string tagBarsetName = "BarcodeSet";
  1550. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1551. (int, string) result;
  1552. while (true)
  1553. {
  1554. try
  1555. {
  1556. if (!GlobalContext._IsCon_Funs1)
  1557. {
  1558. UpdatePLCMonitor(1, plcNo, 0);
  1559. continue;
  1560. }
  1561. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1562. {
  1563. Stopwatch stopwatch1 = new Stopwatch();
  1564. Stopwatch stopwatch2 = new Stopwatch();
  1565. stopwatch1.Start();
  1566. stopwatch2.Start();
  1567. #region 一次性读取所有数据
  1568. // 一次性读取所有数据
  1569. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1570. if (result.Item1 != 0)
  1571. {
  1572. //richTextBox1.AppendText("\n" + strRet);
  1573. }
  1574. else
  1575. {
  1576. //richTextBox1.AppendText("\n" + "读取成功");
  1577. }
  1578. #endregion 一次性读取所有数据
  1579. stopwatch2.Stop();
  1580. #region 进站
  1581. try
  1582. {
  1583. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1584. {
  1585. lock (lockObj)
  1586. {
  1587. if (!ProgressState)
  1588. {
  1589. ProgressState = true;
  1590. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1591. }
  1592. }
  1593. }
  1594. }
  1595. catch (Exception ex)
  1596. {
  1597. ProgressState = false;
  1598. string str = ex.StackTrace;
  1599. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1600. }
  1601. #endregion 进站
  1602. #region 出站
  1603. try
  1604. {
  1605. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1606. {
  1607. lock (lockObj)
  1608. {
  1609. if (!ProgressState)
  1610. {
  1611. ProgressState = true;
  1612. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1613. }
  1614. }
  1615. }
  1616. }
  1617. catch (Exception ex)
  1618. {
  1619. ProgressState = false;
  1620. string str = ex.StackTrace;
  1621. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1622. }
  1623. #endregion 进站
  1624. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1625. stopwatch1.Stop();
  1626. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1627. }
  1628. else
  1629. {
  1630. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1631. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1632. FunsEip[plcNo].Connect(); // 重连
  1633. }
  1634. }
  1635. catch (Exception ex)
  1636. {
  1637. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1638. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1639. }
  1640. Thread.Sleep(IntervalReadPLC);
  1641. }
  1642. }
  1643. /// <summary>
  1644. /// [S1] 壳体清洁上料 - 进站
  1645. /// </summary>
  1646. /// <param name="plcNo">PLC编号</param>
  1647. /// <param name="stationNameStr">工站全称</param>
  1648. /// <param name="stPLC_MesData"></param>
  1649. /// <param name="tagMesCommName"></param>
  1650. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1651. {
  1652. Stopwatch stopwatch1 = new Stopwatch();
  1653. Stopwatch stopwatch2 = new Stopwatch();
  1654. try
  1655. {
  1656. stopwatch1.Start();
  1657. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1658. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1659. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1660. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1661. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1662. if (string.IsNullOrEmpty(sn))
  1663. {
  1664. ProgressState = false;
  1665. return;
  1666. }
  1667. //正式生产就用PLC中取的
  1668. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1669. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1670. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1671. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1672. //绑定载具和产品
  1673. ResponseMessage message = new ResponseMessage();
  1674. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1675. if (message.result == false)
  1676. {
  1677. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1678. }
  1679. // 产品SN进站
  1680. List<TestItem> item = new List<TestItem>();
  1681. stopwatch2.Start();
  1682. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1683. stopwatch2.Stop();
  1684. //指令执行结果 1:OK 110:失败
  1685. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1686. //进站结果写入PLC
  1687. CommandFromPLC resultToPlC = new CommandFromPLC();
  1688. resultToPlC.cmd = 0;
  1689. resultToPlC.cmdParam = 0;
  1690. resultToPlC.cmdResult = mesResultFrmWeb;
  1691. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1692. }
  1693. catch (Exception ex)
  1694. {
  1695. string str = ex.StackTrace;
  1696. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1697. CommandFromPLC resultToPlC = new CommandFromPLC();
  1698. resultToPlC.cmd = 0;
  1699. resultToPlC.cmdParam = 0; //指令参数
  1700. resultToPlC.cmdResult = 110;
  1701. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1702. }
  1703. stopwatch1.Stop();
  1704. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1705. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1706. ProgressState = false;
  1707. }
  1708. /// <summary>
  1709. /// [S1] 壳体清洁上料 - 出站接口
  1710. /// </summary>
  1711. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1712. {
  1713. Stopwatch stopwatch1 = new Stopwatch();
  1714. Stopwatch stopwatch2 = new Stopwatch();
  1715. try
  1716. {
  1717. stopwatch1.Start();
  1718. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1719. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1720. string processItem = stationName; // 项目
  1721. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1722. string supplierCode = ""; // 供应商代码
  1723. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1724. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1725. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1726. string sn = string.Empty;
  1727. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1728. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1729. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1730. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1731. a1Result = 1;
  1732. bool pass = a1Result == 1;
  1733. //根据载具码获取产品码
  1734. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1735. if (string.IsNullOrEmpty(strProductBarcode))
  1736. {
  1737. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1738. }
  1739. sn = strProductBarcode;
  1740. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1741. List<TestItem> items = new List<TestItem>();
  1742. items.Add(new TestItem()
  1743. {
  1744. Parameter_name = "载具码",
  1745. Parameter_value = CarrierBarcode,
  1746. Parameter_unit = ""
  1747. });
  1748. items.Add(new TestItem()
  1749. {
  1750. Parameter_name = "产品码",
  1751. Parameter_value = sn,
  1752. Parameter_unit = ""
  1753. });
  1754. //出站接口
  1755. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1756. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1757. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1758. stopwatch2.Start();
  1759. //进站结果写入PLC
  1760. CommandFromPLC resultToPlC = new CommandFromPLC();
  1761. resultToPlC.cmd = 0;
  1762. resultToPlC.cmdParam = 0; //指令参数
  1763. resultToPlC.cmdResult = mesResultFrmWeb;
  1764. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1765. stopwatch2.Stop();
  1766. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1767. //保存PLC返回MES数据到本地
  1768. ResponseMessage message = new ResponseMessage();
  1769. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1770. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1771. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1772. stPLC_MesData.mesData.nRemainCount);
  1773. if (message.result == false)
  1774. {
  1775. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1776. }
  1777. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1778. }
  1779. catch (Exception ex)
  1780. {
  1781. stopwatch2.Start();
  1782. CommandFromPLC resultToPlC = new CommandFromPLC();
  1783. resultToPlC.cmd = 0;
  1784. resultToPlC.cmdParam = 0; //指令参数
  1785. resultToPlC.cmdResult = 110;
  1786. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1787. stopwatch2.Stop();
  1788. string str = ex.StackTrace;
  1789. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1790. }
  1791. stopwatch1.Stop();
  1792. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1793. ProgressState = false;
  1794. }
  1795. #endregion
  1796. #region S2
  1797. /// <summary>
  1798. /// [S2] 上盖板上料装备
  1799. /// </summary>
  1800. /// <param name="plcNo">PLC编号</param>
  1801. private void ReadStation_S2(int plcNo)
  1802. {
  1803. string stationCode = "[OP20]";
  1804. string stationName = "上盖板上料装备";
  1805. string stationNameStr = stationCode + stationName;
  1806. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1807. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1808. string tagAgvCommName = "agvCommFrmPC";
  1809. string tagBarsetName = "BarcodeSet";
  1810. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1811. (int, string) result;
  1812. while (true)
  1813. {
  1814. try
  1815. {
  1816. if (!GlobalContext._IsCon_Funs2)
  1817. {
  1818. UpdatePLCMonitor(1, plcNo, 0);
  1819. continue;
  1820. }
  1821. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1822. {
  1823. Stopwatch stopwatch1 = new Stopwatch();
  1824. Stopwatch stopwatch2 = new Stopwatch();
  1825. stopwatch1.Start();
  1826. stopwatch2.Start();
  1827. #region 一次性读取所有数据
  1828. // 一次性读取所有数据
  1829. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1830. if (result.Item1 != 0)
  1831. {
  1832. //richTextBox1.AppendText("\n" + strRet);
  1833. }
  1834. else
  1835. {
  1836. //richTextBox1.AppendText("\n" + "读取成功");
  1837. }
  1838. #endregion 一次性读取所有数据
  1839. stopwatch2.Stop();
  1840. #region 进站
  1841. try
  1842. {
  1843. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1844. {
  1845. lock (lockObj)
  1846. {
  1847. if (!ProgressState)
  1848. {
  1849. ProgressState = true;
  1850. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1851. }
  1852. }
  1853. }
  1854. }
  1855. catch (Exception ex)
  1856. {
  1857. ProgressState = false;
  1858. string str = ex.StackTrace;
  1859. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1860. }
  1861. #endregion 进站
  1862. #region 出站
  1863. try
  1864. {
  1865. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1866. {
  1867. lock (lockObj)
  1868. {
  1869. if (!ProgressState)
  1870. {
  1871. ProgressState = true;
  1872. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1873. }
  1874. }
  1875. }
  1876. }
  1877. catch (Exception ex)
  1878. {
  1879. ProgressState = false;
  1880. string str = ex.StackTrace;
  1881. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1882. }
  1883. #endregion 进站
  1884. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1885. stopwatch1.Stop();
  1886. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1887. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1888. }
  1889. else
  1890. {
  1891. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1892. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1893. FunsEip[plcNo].Connect();
  1894. }
  1895. }
  1896. catch (Exception ex)
  1897. {
  1898. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1899. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1900. //Funs[plcNo].ReConnect();
  1901. }
  1902. Thread.Sleep(IntervalReadPLC);
  1903. }
  1904. }
  1905. /// <summary>
  1906. /// [S2] 上盖板上料装备
  1907. /// </summary>
  1908. /// <param name="plcNo">PLC编号</param>
  1909. /// <param name="stationNameStr">工站全称</param>
  1910. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  1911. {
  1912. Stopwatch stopwatch1 = new Stopwatch();
  1913. Stopwatch stopwatch2 = new Stopwatch();
  1914. try
  1915. {
  1916. stopwatch1.Start();
  1917. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1918. //正式生产就用PLC中取的
  1919. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  1920. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1921. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1922. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  1923. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  1924. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  1925. //根据载具码获取产品码
  1926. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  1927. if (string.IsNullOrEmpty(strProductBarcode))
  1928. {
  1929. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1930. }
  1931. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  1932. //sn = strProductBarcode;
  1933. if (sn!= strProductBarcode) {
  1934. AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  1935. }
  1936. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  1937. // 产品SN(物料码)校验
  1938. List<TestItem> item = new List<TestItem>();
  1939. stopwatch2.Start();
  1940. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1941. stopwatch2.Stop();
  1942. //指令执行结果 1:OK 110:失败
  1943. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1944. //进站结果写入PLC
  1945. CommandFromPLC resultToPlC = new CommandFromPLC();
  1946. resultToPlC.cmd = 0;
  1947. resultToPlC.cmdParam = 0; //指令参数
  1948. resultToPlC.cmdResult = mesResultFrmWeb;
  1949. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1950. }
  1951. catch (Exception ex)
  1952. {
  1953. string str = ex.StackTrace;
  1954. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1955. CommandFromPLC resultToPlC = new CommandFromPLC();
  1956. resultToPlC.cmd = 0;
  1957. resultToPlC.cmdParam = 0; //指令参数
  1958. resultToPlC.cmdResult = 110;
  1959. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1960. }
  1961. stopwatch1.Stop();
  1962. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1963. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1964. ProgressState = false;
  1965. }
  1966. /// <summary>
  1967. /// [S2] 上盖板上料装备 - 出站接口
  1968. /// </summary>
  1969. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1970. {
  1971. Stopwatch stopwatch1 = new Stopwatch();
  1972. Stopwatch stopwatch2 = new Stopwatch();
  1973. try
  1974. {
  1975. stopwatch1.Start();
  1976. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1977. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1978. string processItem = stationName; // 测试项目
  1979. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1980. string supplierCode = ""; // 供应商代码
  1981. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  1982. string batch_num = GlobalContext.BatchNumber; // 批次号
  1983. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  1984. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  1985. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1986. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  1987. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  1988. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  1989. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1990. bool pass = a1Result == 1;
  1991. //根据载具码获取产品码
  1992. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1993. if (string.IsNullOrEmpty(strProductBarcode))
  1994. {
  1995. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1996. }
  1997. sn = strProductBarcode;
  1998. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1999. List<TestItem> items = new List<TestItem>();
  2000. items.Add(new TestItem()
  2001. {
  2002. Parameter_name = "载具码",
  2003. Parameter_value = CarrierBarcode,
  2004. Parameter_unit = ""
  2005. });
  2006. items.Add(new TestItem()
  2007. {
  2008. Parameter_name = "产品码",
  2009. Parameter_value = sn,
  2010. Parameter_unit = ""
  2011. });
  2012. items.Add(new TestItem()
  2013. {
  2014. Parameter_name = "部件码",
  2015. Parameter_value = PartBarcode,
  2016. Parameter_unit = ""
  2017. });
  2018. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2019. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2020. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2021. stopwatch2.Start();
  2022. //进站结果写入PLC
  2023. CommandFromPLC resultToPlC = new CommandFromPLC();
  2024. resultToPlC.cmd = 0;
  2025. resultToPlC.cmdParam = 0; //指令参数
  2026. resultToPlC.cmdResult = mesResultFrmWeb;
  2027. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2028. stopwatch2.Stop();
  2029. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2030. //保存PLC返回MES数据到本地
  2031. ResponseMessage message = new ResponseMessage();
  2032. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  2033. if (message.result == false)
  2034. {
  2035. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2036. }
  2037. if (!string.IsNullOrEmpty(PartBarcode))
  2038. {
  2039. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2040. if (message.result == false)
  2041. {
  2042. AddMessage(LogType.Error, message.text);
  2043. }
  2044. }
  2045. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2046. }
  2047. catch (Exception ex)
  2048. {
  2049. stopwatch2.Start();
  2050. CommandFromPLC resultToPlC = new CommandFromPLC();
  2051. resultToPlC.cmd = 0;
  2052. resultToPlC.cmdParam = 0; //指令参数
  2053. resultToPlC.cmdResult = 110;
  2054. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2055. stopwatch2.Stop();
  2056. string str = ex.StackTrace;
  2057. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2058. }
  2059. stopwatch1.Stop();
  2060. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2061. ProgressState = false;
  2062. }
  2063. #endregion
  2064. #region S3
  2065. /// <summary>
  2066. /// [S3] 点散热胶装备
  2067. /// </summary>
  2068. /// <param name="plcNo">PLC编号</param>
  2069. private void ReadStation_S3(int plcNo)
  2070. {
  2071. string stationCode = "[OP30]";
  2072. string stationName = "点散热胶装备";
  2073. string stationNameStr = stationCode + stationName;
  2074. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2075. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2076. string tagAgvCommName = "agvCommFrmPC";
  2077. string tagBarsetName = "BarcodeSet";
  2078. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2079. (int, string) result;
  2080. #region 创建字典
  2081. // 触发信号字典 赋值
  2082. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2083. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2084. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2085. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2086. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2087. // PLC数据字典 赋值
  2088. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2089. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2090. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2091. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2092. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2093. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2094. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2095. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2096. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2097. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2098. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2099. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2100. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2101. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2102. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2103. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2104. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2105. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2106. s3PLCData.Add("c1Result", 0); // 产品结果
  2107. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2108. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2109. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2110. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2111. #endregion 创建字典
  2112. while (true)
  2113. {
  2114. try
  2115. {
  2116. if (!GlobalContext._IsCon_Funs2)
  2117. {
  2118. UpdatePLCMonitor(1, plcNo, 0);
  2119. continue;
  2120. }
  2121. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2122. {
  2123. Stopwatch stopwatch1 = new Stopwatch();
  2124. Stopwatch stopwatch2 = new Stopwatch();
  2125. stopwatch1.Start();
  2126. stopwatch2.Start();
  2127. #region 一次性读取所有数据
  2128. // 一次性读取所有数据
  2129. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2130. if (result.Item1 != 0)
  2131. {
  2132. //richTextBox1.AppendText("\n" + strRet);
  2133. }
  2134. else
  2135. {
  2136. //richTextBox1.AppendText("\n" + "读取成功");
  2137. }
  2138. #endregion 一次性读取所有数据
  2139. stopwatch2.Stop();
  2140. #region 左边进站
  2141. try
  2142. {
  2143. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2144. {
  2145. lock (lockObj)
  2146. {
  2147. if (!ProgressState)
  2148. {
  2149. ProgressState = true;
  2150. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2151. }
  2152. }
  2153. }
  2154. }
  2155. catch (Exception ex)
  2156. {
  2157. ProgressState = false;
  2158. string str = ex.StackTrace;
  2159. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2160. }
  2161. #endregion 左边进站
  2162. #region 左边出站
  2163. try
  2164. {
  2165. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2166. {
  2167. lock (lockObj)
  2168. {
  2169. if (!ProgressState)
  2170. {
  2171. ProgressState = true;
  2172. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2173. }
  2174. }
  2175. }
  2176. }
  2177. catch (Exception ex)
  2178. {
  2179. ProgressState = false;
  2180. string str = ex.StackTrace;
  2181. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2182. }
  2183. #endregion 左边出站
  2184. #region 右边进站
  2185. try
  2186. {
  2187. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2188. {
  2189. lock (lockObj)
  2190. {
  2191. if (!ProgressState)
  2192. {
  2193. ProgressState = true;
  2194. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2195. }
  2196. }
  2197. }
  2198. }
  2199. catch (Exception ex)
  2200. {
  2201. ProgressState = false;
  2202. string str = ex.StackTrace;
  2203. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2204. }
  2205. #endregion 右边进站
  2206. #region 右边出站
  2207. try
  2208. {
  2209. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2210. {
  2211. lock (lockObj)
  2212. {
  2213. if (!ProgressState)
  2214. {
  2215. ProgressState = true;
  2216. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2217. }
  2218. }
  2219. }
  2220. }
  2221. catch (Exception ex)
  2222. {
  2223. string str = ex.StackTrace;
  2224. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2225. }
  2226. #endregion 右边出站
  2227. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2228. stopwatch1.Stop();
  2229. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2230. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2231. }
  2232. else
  2233. {
  2234. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2235. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2236. FunsEip[plcNo].Connect();
  2237. }
  2238. }
  2239. catch (Exception ex)
  2240. {
  2241. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2242. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2243. //Funs[plcNo].ReConnect();
  2244. }
  2245. Thread.Sleep(IntervalReadPLC);
  2246. }
  2247. }
  2248. /// <summary>
  2249. /// [S3] 点散热胶装备 - 进站
  2250. /// </summary>
  2251. /// <param name="plcNo">PLC编号</param>
  2252. /// <param name="stationNameStr">工站全称</param>
  2253. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2254. {
  2255. Stopwatch stopwatch1 = new Stopwatch();
  2256. Stopwatch stopwatch2 = new Stopwatch();
  2257. try
  2258. {
  2259. stopwatch1.Start();
  2260. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2261. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2262. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2263. string StationId=string.Empty;
  2264. if (direction=="Left")
  2265. {
  2266. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2267. }
  2268. if (direction == "Right")
  2269. {
  2270. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2271. }
  2272. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2273. //载具码验证产品码
  2274. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2275. if (string.IsNullOrEmpty(strProductBarcode))
  2276. {
  2277. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2278. }
  2279. sn = strProductBarcode;
  2280. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2281. // 产品SN(物料码)校验
  2282. List<TestItem> item = new List<TestItem>();
  2283. stopwatch2.Start();
  2284. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2285. stopwatch2.Stop();
  2286. //指令执行结果 1:OK 110:失败
  2287. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2288. //进站结果写入PLC
  2289. CommandFromPLC resultToPlC = new CommandFromPLC();
  2290. resultToPlC.cmd = 0;
  2291. resultToPlC.cmdParam = 0; //指令参数
  2292. resultToPlC.cmdResult = mesResultFrmWeb;
  2293. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2294. }
  2295. catch (Exception ex)
  2296. {
  2297. string str = ex.StackTrace;
  2298. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2299. CommandFromPLC resultToPlC = new CommandFromPLC();
  2300. resultToPlC.cmd = 0;
  2301. resultToPlC.cmdParam = 0; //指令参数
  2302. resultToPlC.cmdResult = 110;
  2303. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2304. }
  2305. stopwatch1.Stop();
  2306. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2307. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2308. ProgressState = false;
  2309. }
  2310. /// <summary>
  2311. /// [S3] 点散热胶装备 - 出站
  2312. /// </summary>
  2313. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2314. {
  2315. Stopwatch stopwatch1 = new Stopwatch();
  2316. Stopwatch stopwatch2 = new Stopwatch();
  2317. try
  2318. {
  2319. stopwatch1.Start();
  2320. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2321. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2322. string processItem = stationName; // 测试项目
  2323. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2324. string supplierCode = ""; // 供应商代码
  2325. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2326. string batch_num = GlobalContext.BatchNumber; // 批次号
  2327. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2328. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2329. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2330. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2331. string StationId = string.Empty;
  2332. if (direction == "Left")
  2333. {
  2334. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2335. }
  2336. if (direction == "Right")
  2337. {
  2338. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2339. }
  2340. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2341. bool pass = a1Result == 1;
  2342. //根据载具码获取产品码
  2343. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2344. if (string.IsNullOrEmpty(strProductBarcode))
  2345. {
  2346. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2347. }
  2348. sn = strProductBarcode;
  2349. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2350. List<TestItem> items = new List<TestItem>();
  2351. items.Add(new TestItem()
  2352. {
  2353. Parameter_name = "载具码",
  2354. Parameter_value = CarrierBarcode,
  2355. Parameter_unit = ""
  2356. });
  2357. items.Add(new TestItem()
  2358. {
  2359. Parameter_name = "产品码",
  2360. Parameter_value = sn,
  2361. Parameter_unit = ""
  2362. });
  2363. int result1 = 1;
  2364. if (direction == "Right")
  2365. {
  2366. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2367. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2368. }
  2369. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2370. stopwatch2.Start();
  2371. //进站结果写入PLC
  2372. CommandFromPLC resultToPlC = new CommandFromPLC();
  2373. resultToPlC.cmd = 0;
  2374. resultToPlC.cmdParam = 0; //指令参数
  2375. resultToPlC.cmdResult = mesResultFrmWeb;
  2376. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2377. stopwatch2.Stop();
  2378. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2379. //保存PLC返回MES数据到本地
  2380. ResponseMessage message = new ResponseMessage();
  2381. if (direction == "Left")
  2382. {
  2383. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2384. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2385. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2386. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2387. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2388. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2389. if (message.result == false)
  2390. {
  2391. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2392. }
  2393. }
  2394. if (direction == "Right")
  2395. {
  2396. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2397. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2398. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2399. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2400. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2401. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2402. if (message.result == false)
  2403. {
  2404. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2405. }
  2406. }
  2407. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2408. }
  2409. catch (Exception ex)
  2410. {
  2411. stopwatch2.Start();
  2412. CommandFromPLC resultToPlC = new CommandFromPLC();
  2413. resultToPlC.cmd = 0;
  2414. resultToPlC.cmdParam = 0; //指令参数
  2415. resultToPlC.cmdResult = 110;
  2416. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2417. stopwatch2.Stop();
  2418. string str = ex.StackTrace;
  2419. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2420. }
  2421. stopwatch1.Stop();
  2422. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2423. ProgressState = false;
  2424. }
  2425. #endregion S3
  2426. #region S4
  2427. /// <summary>
  2428. /// [S4] 点胶检测设备
  2429. /// </summary>
  2430. /// <param name="plcNo">PLC编号</param>
  2431. private void ReadStation_S4(int plcNo)
  2432. {
  2433. string stationCode = "[OP40]";
  2434. string stationName = "胶线检测";
  2435. string stationNameStr = stationCode + stationName;
  2436. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2437. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2438. string tagAgvCommName = "agvCommFrmPC";
  2439. string tagBarsetName = "BarcodeSet";
  2440. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2441. (int, string) result;
  2442. while (true)
  2443. {
  2444. try
  2445. {
  2446. if (!GlobalContext._IsCon_Funs1)
  2447. {
  2448. UpdatePLCMonitor(1, plcNo, 0);
  2449. continue;
  2450. }
  2451. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2452. {
  2453. Stopwatch stopwatch1 = new Stopwatch();
  2454. Stopwatch stopwatch2 = new Stopwatch();
  2455. stopwatch1.Start();
  2456. stopwatch2.Start();
  2457. #region 一次性读取所有数据
  2458. // 一次性读取所有数据
  2459. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2460. if (result.Item1 != 0)
  2461. {
  2462. //richTextBox1.AppendText("\n" + strRet);
  2463. }
  2464. else
  2465. {
  2466. //richTextBox1.AppendText("\n" + "读取成功");
  2467. }
  2468. #endregion 一次性读取所有数据
  2469. stopwatch2.Stop();
  2470. #region 进站
  2471. try
  2472. {
  2473. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2474. {
  2475. lock (lockObj)
  2476. {
  2477. if (!ProgressState)
  2478. {
  2479. ProgressState = true;
  2480. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2481. }
  2482. }
  2483. }
  2484. }
  2485. catch (Exception ex)
  2486. {
  2487. ProgressState = false;
  2488. string str = ex.StackTrace;
  2489. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2490. }
  2491. #endregion 进站
  2492. #region 出站
  2493. try
  2494. {
  2495. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2496. {
  2497. lock (lockObj)
  2498. {
  2499. if (!ProgressState)
  2500. {
  2501. ProgressState = true;
  2502. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2503. }
  2504. }
  2505. }
  2506. }
  2507. catch (Exception ex)
  2508. {
  2509. string str = ex.StackTrace;
  2510. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2511. }
  2512. #endregion 进站
  2513. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2514. stopwatch1.Stop();
  2515. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2516. }
  2517. else
  2518. {
  2519. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2520. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2521. FunsEip[plcNo].Connect(); // 重连
  2522. }
  2523. }
  2524. catch (Exception ex)
  2525. {
  2526. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2527. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2528. }
  2529. Thread.Sleep(IntervalReadPLC);
  2530. }
  2531. }
  2532. /// <summary>
  2533. /// [S4] 点胶检测设备 - 进站
  2534. /// </summary>
  2535. /// <param name="plcNo">PLC编号</param>
  2536. /// <param name="stationNameStr">工站全称</param>
  2537. /// <param name="stPLC_MesData"></param>
  2538. /// <param name="tagMesCommName"></param>
  2539. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2540. {
  2541. Stopwatch stopwatch1 = new Stopwatch();
  2542. Stopwatch stopwatch2 = new Stopwatch();
  2543. try
  2544. {
  2545. stopwatch1.Start();
  2546. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2547. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2548. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2549. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2550. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2551. //载具码验证产品码
  2552. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2553. if (string.IsNullOrEmpty(strProductBarcode))
  2554. {
  2555. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2556. }
  2557. sn = strProductBarcode;
  2558. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2559. // 产品SN(物料码)校验
  2560. List<TestItem> item = new List<TestItem>();
  2561. stopwatch2.Start();
  2562. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2563. stopwatch2.Stop();
  2564. //指令执行结果 1:OK 110:失败
  2565. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2566. //进站结果写入PLC
  2567. CommandFromPLC resultToPlC = new CommandFromPLC();
  2568. resultToPlC.cmd = 0;
  2569. resultToPlC.cmdParam = 0; //指令参数
  2570. resultToPlC.cmdResult = mesResultFrmWeb;
  2571. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2572. }
  2573. catch (Exception ex)
  2574. {
  2575. string str = ex.StackTrace;
  2576. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2577. CommandFromPLC resultToPlC = new CommandFromPLC();
  2578. resultToPlC.cmd = 0;
  2579. resultToPlC.cmdParam = 0; //指令参数
  2580. resultToPlC.cmdResult = 110;
  2581. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2582. }
  2583. stopwatch1.Stop();
  2584. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2585. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2586. ProgressState = false;
  2587. }
  2588. /// <summary>
  2589. /// [S4] 点胶检测设备 - 出站接口
  2590. /// </summary>
  2591. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2592. {
  2593. Stopwatch stopwatch1 = new Stopwatch();
  2594. Stopwatch stopwatch2 = new Stopwatch();
  2595. try
  2596. {
  2597. stopwatch1.Start();
  2598. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2599. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2600. string processItem = stationName; // 测试项目
  2601. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2602. string supplierCode = ""; // 供应商代码
  2603. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2604. string batch_num = GlobalContext.BatchNumber; // 批次号
  2605. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2606. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2607. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2608. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2609. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2610. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2611. bool pass = a1Result == 1;
  2612. //根据载具码获取产品码
  2613. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2614. if (string.IsNullOrEmpty(strProductBarcode))
  2615. {
  2616. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2617. }
  2618. sn = strProductBarcode;
  2619. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2620. List<TestItem> items = new List<TestItem>();
  2621. items.Add(new TestItem()
  2622. {
  2623. Parameter_name = "载具码",
  2624. Parameter_value = CarrierBarcode,
  2625. Parameter_unit = ""
  2626. });
  2627. items.Add(new TestItem()
  2628. {
  2629. Parameter_name = "产品码",
  2630. Parameter_value = sn,
  2631. Parameter_unit = ""
  2632. });
  2633. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2634. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2635. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2636. stopwatch2.Start();
  2637. //进站结果写入PLC
  2638. CommandFromPLC resultToPlC = new CommandFromPLC();
  2639. resultToPlC.cmd = 0;
  2640. resultToPlC.cmdParam = 0; //指令参数
  2641. resultToPlC.cmdResult = mesResultFrmWeb;
  2642. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2643. stopwatch2.Stop();
  2644. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2645. //保存PLC返回MES数据到本地
  2646. ResponseMessage message = new ResponseMessage();
  2647. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2648. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2649. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2650. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2651. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2652. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2653. if (message.result == false)
  2654. {
  2655. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2656. }
  2657. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2658. }
  2659. catch (Exception ex)
  2660. {
  2661. stopwatch2.Start();
  2662. CommandFromPLC resultToPlC = new CommandFromPLC();
  2663. resultToPlC.cmd = 0;
  2664. resultToPlC.cmdParam = 0; //指令参数
  2665. resultToPlC.cmdResult = 110;
  2666. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2667. stopwatch2.Stop();
  2668. string str = ex.StackTrace;
  2669. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2670. }
  2671. stopwatch1.Stop();
  2672. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2673. ProgressState = false;
  2674. }
  2675. #endregion
  2676. #region S5
  2677. /// <summary>
  2678. /// [S5] 点胶检测设备
  2679. /// </summary>
  2680. /// <param name="plcNo">PLC编号</param>
  2681. private void ReadStation_S5(int plcNo)
  2682. {
  2683. string stationCode = "[OP50]";
  2684. string stationName = "ADD板上料组装装备";
  2685. string stationNameStr = stationCode + stationName;
  2686. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2687. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2688. string tagAgvCommName = "agvCommFrmPC";
  2689. string tagBarsetName = "BarcodeSet";
  2690. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2691. (int, string) result;
  2692. while (true)
  2693. {
  2694. try
  2695. {
  2696. if (!GlobalContext._IsCon_Funs1)
  2697. {
  2698. UpdatePLCMonitor(1, plcNo, 0);
  2699. continue;
  2700. }
  2701. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2702. {
  2703. Stopwatch stopwatch1 = new Stopwatch();
  2704. Stopwatch stopwatch2 = new Stopwatch();
  2705. stopwatch1.Start();
  2706. stopwatch2.Start();
  2707. #region 一次性读取所有数据
  2708. // 一次性读取所有数据
  2709. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2710. if (result.Item1 != 0)
  2711. {
  2712. //richTextBox1.AppendText("\n" + strRet);
  2713. }
  2714. else
  2715. {
  2716. //richTextBox1.AppendText("\n" + "读取成功");
  2717. }
  2718. #endregion 一次性读取所有数据
  2719. stopwatch2.Stop();
  2720. #region 进站
  2721. try
  2722. {
  2723. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2724. {
  2725. lock (lockObj)
  2726. {
  2727. if (!ProgressState)
  2728. {
  2729. ProgressState = true;
  2730. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2731. }
  2732. }
  2733. }
  2734. }
  2735. catch (Exception ex)
  2736. {
  2737. ProgressState = false;
  2738. string str = ex.StackTrace;
  2739. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2740. }
  2741. #endregion 进站
  2742. #region 出站
  2743. try
  2744. {
  2745. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2746. {
  2747. lock (lockObj)
  2748. {
  2749. if (!ProgressState)
  2750. {
  2751. ProgressState = true;
  2752. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2753. }
  2754. }
  2755. }
  2756. }
  2757. catch (Exception ex)
  2758. {
  2759. ProgressState = false;
  2760. string str = ex.StackTrace;
  2761. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2762. }
  2763. #endregion 进站
  2764. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2765. stopwatch1.Stop();
  2766. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2767. }
  2768. else
  2769. {
  2770. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2771. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2772. FunsEip[plcNo].Connect(); // 重连
  2773. }
  2774. }
  2775. catch (Exception ex)
  2776. {
  2777. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2778. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2779. }
  2780. Thread.Sleep(IntervalReadPLC);
  2781. }
  2782. }
  2783. /// <summary>
  2784. /// [S5] 点胶检测设备 - 进站
  2785. /// </summary>
  2786. /// <param name="plcNo">PLC编号</param>
  2787. /// <param name="stationNameStr">工站全称</param>
  2788. /// <param name="stPLC_MesData"></param>
  2789. /// <param name="tagMesCommName"></param>
  2790. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2791. {
  2792. Stopwatch stopwatch1 = new Stopwatch();
  2793. Stopwatch stopwatch2 = new Stopwatch();
  2794. try
  2795. {
  2796. stopwatch1.Start();
  2797. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2798. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2799. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2800. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2801. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2802. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2803. //载具码验证产品码 //载具码验证产品码
  2804. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2805. if (string.IsNullOrEmpty(strProductBarcode))
  2806. {
  2807. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2808. }
  2809. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2810. if (sn != strProductBarcode)
  2811. {
  2812. AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2813. }
  2814. //sn = strProductBarcode;
  2815. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2816. // 产品SN(物料码)校验
  2817. List<TestItem> item = new List<TestItem>();
  2818. stopwatch2.Start();
  2819. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2820. stopwatch2.Stop();
  2821. //指令执行结果 1:OK 110:失败
  2822. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2823. //进站结果写入PLC
  2824. CommandFromPLC resultToPlC = new CommandFromPLC();
  2825. resultToPlC.cmd = 0;
  2826. resultToPlC.cmdParam = 0; //指令参数
  2827. resultToPlC.cmdResult = mesResultFrmWeb;
  2828. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2829. }
  2830. catch (Exception ex)
  2831. {
  2832. string str = ex.StackTrace;
  2833. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2834. CommandFromPLC resultToPlC = new CommandFromPLC();
  2835. resultToPlC.cmd = 0;
  2836. resultToPlC.cmdParam = 0; //指令参数
  2837. resultToPlC.cmdResult = 110;
  2838. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2839. }
  2840. stopwatch1.Stop();
  2841. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2842. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2843. ProgressState = false;
  2844. }
  2845. /// <summary>
  2846. /// [S5] 点胶检测设备 - 出站接口
  2847. /// </summary>
  2848. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2849. {
  2850. Stopwatch stopwatch1 = new Stopwatch();
  2851. Stopwatch stopwatch2 = new Stopwatch();
  2852. try
  2853. {
  2854. stopwatch1.Start();
  2855. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2856. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2857. string processItem = stationName; // 测试项目
  2858. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2859. string supplierCode = ""; // 供应商代码
  2860. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2861. string batch_num = GlobalContext.BatchNumber; // 批次号
  2862. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2863. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2864. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2865. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2866. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2867. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2868. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2869. bool pass = a1Result == 1;
  2870. //根据载具码获取产品码
  2871. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2872. if (string.IsNullOrEmpty(strProductBarcode))
  2873. {
  2874. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2875. }
  2876. sn = strProductBarcode;
  2877. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2878. List<TestItem> items = new List<TestItem>();
  2879. items.Add(new TestItem()
  2880. {
  2881. Parameter_name = "载具码",
  2882. Parameter_value = CarrierBarcode,
  2883. Parameter_unit = ""
  2884. });
  2885. items.Add(new TestItem()
  2886. {
  2887. Parameter_name = "产品码",
  2888. Parameter_value = sn,
  2889. Parameter_unit = ""
  2890. });
  2891. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2892. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2893. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2894. stopwatch2.Start();
  2895. //进站结果写入PLC
  2896. CommandFromPLC resultToPlC = new CommandFromPLC();
  2897. resultToPlC.cmd = 0;
  2898. resultToPlC.cmdParam = 0; //指令参数
  2899. resultToPlC.cmdResult = mesResultFrmWeb;
  2900. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2901. stopwatch2.Stop();
  2902. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2903. //保存PLC返回MES数据到本地
  2904. ResponseMessage message = new ResponseMessage();
  2905. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  2906. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  2907. if (message.result == false)
  2908. {
  2909. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2910. }
  2911. //保存部件码信息
  2912. if (!string.IsNullOrEmpty(PartBarcode))
  2913. {
  2914. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  2915. if (message.result == false)
  2916. {
  2917. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  2918. }
  2919. }
  2920. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2921. }
  2922. catch (Exception ex)
  2923. {
  2924. stopwatch2.Start();
  2925. CommandFromPLC resultToPlC = new CommandFromPLC();
  2926. resultToPlC.cmd = 0;
  2927. resultToPlC.cmdParam = 0; //指令参数
  2928. resultToPlC.cmdResult = 110;
  2929. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2930. stopwatch2.Stop();
  2931. string str = ex.StackTrace;
  2932. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2933. }
  2934. stopwatch1.Stop();
  2935. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2936. ProgressState = false;
  2937. }
  2938. #endregion
  2939. #region S6
  2940. /// <summary>
  2941. /// [S6] 顶盖装配设备
  2942. /// </summary>
  2943. /// <param name="plcNo">PLC编号</param>
  2944. private void ReadStation_S6(int plcNo)
  2945. {
  2946. string stationCode = "[OP60]";
  2947. string stationName = "组上盖板";
  2948. string stationNameStr = stationCode + stationName;
  2949. string tagBaseName = "g_OP60_MES"; //标签变量名称
  2950. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2951. string tagAgvCommName = "agvCommFrmPC";
  2952. string tagBarsetName = "BarcodeSet";
  2953. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  2954. (int, string) result;
  2955. while (true)
  2956. {
  2957. try
  2958. {
  2959. if (!GlobalContext._IsCon_Funs1)
  2960. {
  2961. UpdatePLCMonitor(1, plcNo, 0);
  2962. continue;
  2963. }
  2964. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2965. {
  2966. Stopwatch stopwatch1 = new Stopwatch();
  2967. Stopwatch stopwatch2 = new Stopwatch();
  2968. stopwatch1.Start();
  2969. stopwatch2.Start();
  2970. #region 一次性读取所有数据
  2971. // 一次性读取所有数据
  2972. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2973. if (result.Item1 != 0)
  2974. {
  2975. //richTextBox1.AppendText("\n" + strRet);
  2976. }
  2977. else
  2978. {
  2979. //richTextBox1.AppendText("\n" + "读取成功");
  2980. }
  2981. #endregion 一次性读取所有数据
  2982. stopwatch2.Stop();
  2983. #region 进站
  2984. try
  2985. {
  2986. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2987. {
  2988. lock (lockObj)
  2989. {
  2990. if (!ProgressState)
  2991. {
  2992. ProgressState = true;
  2993. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2994. }
  2995. }
  2996. }
  2997. }
  2998. catch (Exception ex)
  2999. {
  3000. ProgressState = false;
  3001. string str = ex.StackTrace;
  3002. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3003. }
  3004. #endregion 进站
  3005. #region 出站
  3006. try
  3007. {
  3008. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3009. {
  3010. lock (lockObj)
  3011. {
  3012. if (!ProgressState)
  3013. {
  3014. ProgressState = true; ;
  3015. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3016. }
  3017. }
  3018. }
  3019. }
  3020. catch (Exception ex)
  3021. {
  3022. ProgressState = false;
  3023. string str = ex.StackTrace;
  3024. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3025. }
  3026. #endregion 进站
  3027. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3028. stopwatch1.Stop();
  3029. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3030. }
  3031. else
  3032. {
  3033. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3034. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3035. FunsEip[plcNo].Connect(); // 重连
  3036. }
  3037. }
  3038. catch (Exception ex)
  3039. {
  3040. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3041. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3042. }
  3043. Thread.Sleep(IntervalReadPLC);
  3044. }
  3045. }
  3046. /// <summary>
  3047. /// [S6] 顶盖装配设备 - 进站
  3048. /// </summary>
  3049. /// <param name="plcNo">PLC编号</param>
  3050. /// <param name="stationNameStr">工站全称</param>
  3051. /// <param name="stPLC_MesData"></param>
  3052. /// <param name="tagMesCommName"></param>
  3053. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3054. {
  3055. Stopwatch stopwatch1 = new Stopwatch();
  3056. Stopwatch stopwatch2 = new Stopwatch();
  3057. try
  3058. {
  3059. stopwatch1.Start();
  3060. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3061. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3062. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3063. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3064. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3065. //载具码验证产品码
  3066. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3067. if (string.IsNullOrEmpty(strProductBarcode))
  3068. {
  3069. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3070. }
  3071. sn = strProductBarcode;
  3072. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3073. // 产品SN(物料码)校验
  3074. List<TestItem> item = new List<TestItem>();
  3075. stopwatch2.Start();
  3076. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3077. stopwatch2.Stop();
  3078. //指令执行结果 1:OK 110:失败
  3079. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3080. //进站结果写入PLC
  3081. CommandFromPLC resultToPlC = new CommandFromPLC();
  3082. resultToPlC.cmd = 0;
  3083. resultToPlC.cmdParam = 0; //指令参数
  3084. resultToPlC.cmdResult = mesResultFrmWeb;
  3085. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3086. }
  3087. catch (Exception ex)
  3088. {
  3089. string str = ex.StackTrace;
  3090. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3091. CommandFromPLC resultToPlC = new CommandFromPLC();
  3092. resultToPlC.cmd = 0;
  3093. resultToPlC.cmdParam = 0; //指令参数
  3094. resultToPlC.cmdResult = 110;
  3095. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3096. }
  3097. stopwatch1.Stop();
  3098. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3099. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3100. ProgressState = false;
  3101. }
  3102. /// <summary>
  3103. /// [S6] 顶盖装配设备 - 出站接口
  3104. /// </summary>
  3105. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3106. {
  3107. Stopwatch stopwatch1 = new Stopwatch();
  3108. Stopwatch stopwatch2 = new Stopwatch();
  3109. try
  3110. {
  3111. stopwatch1.Start();
  3112. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3113. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3114. string processItem = stationName; // 测试项目
  3115. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3116. string supplierCode = ""; // 供应商代码
  3117. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3118. string batch_num = GlobalContext.BatchNumber; // 批次号
  3119. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3120. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3121. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3122. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3123. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3124. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3125. bool pass = a1Result == 1;
  3126. //根据载具码获取产品码
  3127. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3128. if (string.IsNullOrEmpty(strProductBarcode))
  3129. {
  3130. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3131. }
  3132. sn = strProductBarcode;
  3133. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3134. List<TestItem> items = new List<TestItem>();
  3135. items.Add(new TestItem()
  3136. {
  3137. Parameter_name = "载具码",
  3138. Parameter_value = CarrierBarcode,
  3139. Parameter_unit = ""
  3140. });
  3141. items.Add(new TestItem()
  3142. {
  3143. Parameter_name = "产品码",
  3144. Parameter_value = sn,
  3145. Parameter_unit = ""
  3146. });
  3147. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3148. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3149. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3150. stopwatch2.Start();
  3151. //进站结果写入PLC
  3152. CommandFromPLC resultToPlC = new CommandFromPLC();
  3153. resultToPlC.cmd = 0;
  3154. resultToPlC.cmdParam = 0; //指令参数
  3155. resultToPlC.cmdResult = mesResultFrmWeb;
  3156. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3157. stopwatch2.Stop();
  3158. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3159. //保存PLC返回MES数据到本地
  3160. ResponseMessage message = new ResponseMessage();
  3161. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3162. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3163. if (message.result == false)
  3164. {
  3165. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3166. }
  3167. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3168. }
  3169. catch (Exception ex)
  3170. {
  3171. stopwatch2.Start();
  3172. CommandFromPLC resultToPlC = new CommandFromPLC();
  3173. resultToPlC.cmd = 0;
  3174. resultToPlC.cmdParam = 0; //指令参数
  3175. resultToPlC.cmdResult = 110;
  3176. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3177. stopwatch2.Stop();
  3178. string str = ex.StackTrace;
  3179. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3180. }
  3181. stopwatch1.Stop();
  3182. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3183. ProgressState = false;
  3184. }
  3185. #endregion
  3186. #region S7
  3187. /// <summary>
  3188. /// [S7] 锁螺丝设备
  3189. /// </summary>
  3190. /// <param name="plcNo">PLC编号</param>
  3191. private void ReadStation_S7(int plcNo)
  3192. {
  3193. string stationCode = "[OP70]";
  3194. string stationName = "上盖板锁螺丝";
  3195. string stationNameStr = stationCode + stationName;
  3196. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3197. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3198. string tagAgvCommName = "agvCommFrmPC";
  3199. string tagBarsetName = "BarcodeSet";
  3200. string tagScrewDataset = "screwDataset";
  3201. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3202. (int, string) result;
  3203. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3204. atlasScrewLeft.Initial();
  3205. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3206. atlasScrewRight.Initial();
  3207. while (true)
  3208. {
  3209. try
  3210. {
  3211. if (!GlobalContext._IsCon_Funs1)
  3212. {
  3213. UpdatePLCMonitor(1, plcNo, 0);
  3214. continue;
  3215. }
  3216. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3217. {
  3218. Stopwatch stopwatch1 = new Stopwatch();
  3219. Stopwatch stopwatch2 = new Stopwatch();
  3220. stopwatch1.Start();
  3221. stopwatch2.Start();
  3222. #region 一次性读取所有数据
  3223. // 一次性读取所有数据
  3224. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3225. if (result.Item1 != 0)
  3226. {
  3227. //richTextBox1.AppendText("\n" + strRet);
  3228. }
  3229. else
  3230. {
  3231. //richTextBox1.AppendText("\n" + "读取成功");
  3232. }
  3233. #endregion 一次性读取所有数据
  3234. stopwatch2.Stop();
  3235. #region 左边进站
  3236. try
  3237. {
  3238. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3239. {
  3240. lock (lockObj)
  3241. {
  3242. if (!ProgressState)
  3243. {
  3244. ProgressState = true;
  3245. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3246. }
  3247. }
  3248. }
  3249. }
  3250. catch (Exception ex)
  3251. {
  3252. ProgressState = false;
  3253. string str = ex.StackTrace;
  3254. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3255. }
  3256. #endregion 左边进站
  3257. #region 左边出站
  3258. try
  3259. {
  3260. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3261. {
  3262. lock (lockObj)
  3263. {
  3264. if (!ProgressState)
  3265. {
  3266. ProgressState = true;
  3267. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3268. }
  3269. }
  3270. }
  3271. }
  3272. catch (Exception ex)
  3273. {
  3274. ProgressState = false;
  3275. string str = ex.StackTrace;
  3276. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3277. }
  3278. #endregion 左边出站
  3279. #region 右边进站
  3280. try
  3281. {
  3282. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3283. {
  3284. lock (lockObj)
  3285. {
  3286. if (!ProgressState)
  3287. {
  3288. ProgressState = true;
  3289. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr}_Right进站:【载具条码】{stPLC_MesData.Right.BarcodeSet.strCarrierBarcode},【产品条码】{stPLC_MesData.Right.BarcodeSet.strProductBarcode}");
  3290. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3291. }
  3292. }
  3293. }
  3294. }
  3295. catch (Exception ex)
  3296. {
  3297. ProgressState = false;
  3298. string str = ex.StackTrace;
  3299. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3300. }
  3301. #endregion 右边进站
  3302. #region 右边出站
  3303. try
  3304. {
  3305. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3306. {
  3307. lock (lockObj)
  3308. {
  3309. if (!ProgressState)
  3310. {
  3311. ProgressState = true;
  3312. OnMessage(LogType.Info,$"PLC{plcNo}_{stationNameStr}_Right出站:【载具条码】{stPLC_MesData.Right.BarcodeSet.strCarrierBarcode},【产品条码】{stPLC_MesData.Right.BarcodeSet.strProductBarcode}");
  3313. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3314. }
  3315. }
  3316. }
  3317. }
  3318. catch (Exception ex)
  3319. {
  3320. ProgressState = false;
  3321. string str = ex.StackTrace;
  3322. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3323. }
  3324. #endregion 右边出站
  3325. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3326. stopwatch1.Stop();
  3327. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3328. }
  3329. else
  3330. {
  3331. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3332. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3333. FunsEip[plcNo].Connect(); // 重连
  3334. }
  3335. }
  3336. catch (Exception ex)
  3337. {
  3338. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3339. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3340. }
  3341. Thread.Sleep(IntervalReadPLC);
  3342. }
  3343. }
  3344. /// <summary>
  3345. /// [S7] 锁螺丝设备 - 进站
  3346. /// </summary>
  3347. /// <param name="plcNo">PLC编号</param>
  3348. /// <param name="stationNameStr">工站全称</param>
  3349. /// <param name="stPLC_MesData"></param>
  3350. /// <param name="tagMesCommName"></param>
  3351. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3352. {
  3353. Stopwatch stopwatch1 = new Stopwatch();
  3354. Stopwatch stopwatch2 = new Stopwatch();
  3355. string atlasSn=string.Empty;
  3356. try
  3357. {
  3358. stopwatch1.Start();
  3359. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3360. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3361. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3362. string StationId = string.Empty; // 工位ID(可配置)
  3363. if (direction == "Left")
  3364. {
  3365. StationId = GlobalContext.S7_StationId_1;
  3366. }
  3367. if (direction == "Right")
  3368. {
  3369. StationId = GlobalContext.S7_StationId_2;
  3370. }
  3371. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3372. //载具码验证产品码
  3373. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3374. if (string.IsNullOrEmpty(strProductBarcode))
  3375. {
  3376. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3377. }
  3378. sn = strProductBarcode;
  3379. atlasSn= strProductBarcode;
  3380. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3381. if (direction == "Left")
  3382. {
  3383. isCollectingFlagLeft = false;//采集螺丝数据结束
  3384. }
  3385. if (direction == "Right")
  3386. {
  3387. isCollectingFlagRight = false;//采集螺丝数据结束
  3388. }
  3389. // 产品SN(物料码)校验
  3390. List<TestItem> item = new List<TestItem>();
  3391. stopwatch2.Start();
  3392. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3393. stopwatch2.Stop();
  3394. //指令执行结果 1:OK 110:失败
  3395. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3396. //进站结果写入PLC
  3397. CommandFromPLC resultToPlC = new CommandFromPLC();
  3398. resultToPlC.cmd = 0;
  3399. resultToPlC.cmdParam = 0; //指令参数
  3400. resultToPlC.cmdResult = mesResultFrmWeb;
  3401. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3402. }
  3403. catch (Exception ex)
  3404. {
  3405. string str = ex.StackTrace;
  3406. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3407. CommandFromPLC resultToPlC = new CommandFromPLC();
  3408. resultToPlC.cmd = 0;
  3409. resultToPlC.cmdParam = 0; //指令参数
  3410. resultToPlC.cmdResult = 110;
  3411. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3412. }
  3413. stopwatch1.Stop();
  3414. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3415. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3416. ProgressState = false;
  3417. //开始采集螺丝数据
  3418. if (direction == "Left")
  3419. {
  3420. isCollectingFlagLeft = true;
  3421. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3422. }
  3423. if (direction == "Right")
  3424. {
  3425. isCollectingFlagRight = true;
  3426. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3427. }
  3428. }
  3429. /// <summary>
  3430. /// [S7] 锁螺丝设备 - 出站
  3431. /// </summary>
  3432. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3433. {
  3434. Stopwatch stopwatch1 = new Stopwatch();
  3435. Stopwatch stopwatch2 = new Stopwatch();
  3436. try
  3437. {
  3438. stopwatch1.Start();
  3439. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3440. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3441. string processItem = stationName; // 测试项目
  3442. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3443. string supplierCode = ""; // 供应商代码
  3444. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3445. string batch_num = GlobalContext.BatchNumber; // 批次号
  3446. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3447. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3448. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3449. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3450. string StationId = string.Empty; // 工位ID(可配置)
  3451. if (direction == "Left")
  3452. {
  3453. StationId = GlobalContext.S7_StationId_1;
  3454. }
  3455. if (direction == "Right")
  3456. {
  3457. StationId = GlobalContext.S7_StationId_2;
  3458. }
  3459. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3460. a1Result = 1;
  3461. bool pass = a1Result == 1;
  3462. //根据载具码获取产品码
  3463. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3464. if (string.IsNullOrEmpty(strProductBarcode))
  3465. {
  3466. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3467. }
  3468. sn = strProductBarcode;
  3469. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3470. List<TestItem> items = new List<TestItem>();
  3471. items.Add(new TestItem()
  3472. {
  3473. Parameter_name = "载具码",
  3474. Parameter_value = CarrierBarcode,
  3475. Parameter_unit = ""
  3476. });
  3477. items.Add(new TestItem()
  3478. {
  3479. Parameter_name = "产品码",
  3480. Parameter_value = sn,
  3481. Parameter_unit = ""
  3482. });
  3483. int result1 = 1;
  3484. if (direction == "Right")
  3485. {
  3486. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3487. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3488. }
  3489. //if (direction == "Left")
  3490. //{
  3491. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3492. //}
  3493. //if (direction == "Right")
  3494. //{
  3495. // isCollectingFlagRight = false;//采集螺丝数据结束
  3496. //}
  3497. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3498. stopwatch2.Start();
  3499. //进站结果写入PLC
  3500. CommandFromPLC resultToPlC = new CommandFromPLC();
  3501. resultToPlC.cmd = 0;
  3502. resultToPlC.cmdParam = 0; //指令参数
  3503. resultToPlC.cmdResult = mesResultFrmWeb;
  3504. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3505. stopwatch2.Stop();
  3506. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3507. //保存PLC返回MES数据到本地
  3508. ResponseMessage message = new ResponseMessage();
  3509. if (direction == "Left")
  3510. {
  3511. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3512. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3513. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3514. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3515. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3516. if (message.result == false)
  3517. {
  3518. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3519. }
  3520. }
  3521. if (direction == "Right")
  3522. {
  3523. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3524. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3525. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3526. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3527. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3528. if (message.result == false)
  3529. {
  3530. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3531. }
  3532. }
  3533. //保存螺丝数据到txt
  3534. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3535. if (result.Item1 != 0)
  3536. {
  3537. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3538. }
  3539. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3540. }
  3541. catch (Exception ex)
  3542. {
  3543. stopwatch2.Start();
  3544. CommandFromPLC resultToPlC = new CommandFromPLC();
  3545. resultToPlC.cmd = 0;
  3546. resultToPlC.cmdParam = 0; //指令参数
  3547. resultToPlC.cmdResult = 110;
  3548. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3549. stopwatch2.Stop();
  3550. string str = ex.StackTrace;
  3551. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3552. }
  3553. stopwatch1.Stop();
  3554. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3555. ProgressState = false;
  3556. }
  3557. #endregion
  3558. #region S8
  3559. /// <summary>
  3560. /// [S8] 3D螺丝高度检测设备
  3561. /// </summary>
  3562. /// <param name="plcNo">PLC编号</param>
  3563. private void ReadStation_S8(int plcNo)
  3564. {
  3565. string stationCode = "[OP80]";
  3566. string stationName = "NG下料";
  3567. string stationNameStr = stationCode + stationName;
  3568. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3569. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3570. string tagAgvCommName = "agvCommFrmPC";
  3571. string tagBarsetName = "BarcodeSet";
  3572. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3573. (int, string) result;
  3574. while (true)
  3575. {
  3576. try
  3577. {
  3578. if (!GlobalContext._IsCon_Funs1)
  3579. {
  3580. UpdatePLCMonitor(1, plcNo, 0);
  3581. continue;
  3582. }
  3583. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3584. {
  3585. Stopwatch stopwatch1 = new Stopwatch();
  3586. Stopwatch stopwatch2 = new Stopwatch();
  3587. stopwatch1.Start();
  3588. stopwatch2.Start();
  3589. #region 一次性读取所有数据
  3590. // 一次性读取所有数据
  3591. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3592. if (result.Item1 != 0)
  3593. {
  3594. //richTextBox1.AppendText("\n" + strRet);
  3595. }
  3596. else
  3597. {
  3598. //richTextBox1.AppendText("\n" + "读取成功");
  3599. }
  3600. #endregion 一次性读取所有数据
  3601. stopwatch2.Stop();
  3602. #region 进站
  3603. try
  3604. {
  3605. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3606. {
  3607. lock (lockObj)
  3608. {
  3609. if (!ProgressState)
  3610. {
  3611. ProgressState = true;
  3612. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3613. }
  3614. }
  3615. }
  3616. }
  3617. catch (Exception ex)
  3618. {
  3619. ProgressState = false;
  3620. string str = ex.StackTrace;
  3621. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3622. }
  3623. #endregion 进站
  3624. #region 出站
  3625. try
  3626. {
  3627. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3628. {
  3629. lock (lockObj)
  3630. {
  3631. if (!ProgressState)
  3632. {
  3633. ProgressState = true;
  3634. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3635. }
  3636. }
  3637. }
  3638. }
  3639. catch (Exception ex)
  3640. {
  3641. ProgressState = false;
  3642. string str = ex.StackTrace;
  3643. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3644. }
  3645. #endregion 进站
  3646. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3647. stopwatch1.Stop();
  3648. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3649. }
  3650. else
  3651. {
  3652. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3653. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3654. FunsEip[plcNo].Connect(); // 重连
  3655. }
  3656. }
  3657. catch (Exception ex)
  3658. {
  3659. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3660. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3661. }
  3662. Thread.Sleep(IntervalReadPLC);
  3663. }
  3664. }
  3665. /// <summary>
  3666. /// [S8] 3D螺丝高度检测设备 - 进站
  3667. /// </summary>
  3668. /// <param name="plcNo">PLC编号</param>
  3669. /// <param name="stationNameStr">工站全称</param>
  3670. /// <param name="stPLC_MesData"></param>
  3671. /// <param name="tagMesCommName"></param>
  3672. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3673. {
  3674. Stopwatch stopwatch1 = new Stopwatch();
  3675. Stopwatch stopwatch2 = new Stopwatch();
  3676. try
  3677. {
  3678. stopwatch1.Start();
  3679. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3680. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3681. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3682. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3683. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3684. //载具码验证产品码
  3685. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3686. if (string.IsNullOrEmpty(strProductBarcode))
  3687. {
  3688. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3689. }
  3690. sn = strProductBarcode;
  3691. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3692. // 产品SN(物料码)校验
  3693. List<TestItem> item = new List<TestItem>();
  3694. stopwatch2.Start();
  3695. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3696. stopwatch2.Stop();
  3697. //指令执行结果 1:OK 110:失败
  3698. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3699. //进站结果写入PLC
  3700. CommandFromPLC resultToPlC = new CommandFromPLC();
  3701. resultToPlC.cmd = 0;
  3702. resultToPlC.cmdParam = 0; //指令参数
  3703. resultToPlC.cmdResult = mesResultFrmWeb;
  3704. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3705. }
  3706. catch (Exception ex)
  3707. {
  3708. string str = ex.StackTrace;
  3709. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3710. CommandFromPLC resultToPlC = new CommandFromPLC();
  3711. resultToPlC.cmd = 0;
  3712. resultToPlC.cmdParam = 0; //指令参数
  3713. resultToPlC.cmdResult = 110;
  3714. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3715. }
  3716. stopwatch1.Stop();
  3717. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3718. ProgressState = false;
  3719. }
  3720. /// <summary>
  3721. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3722. /// </summary>
  3723. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3724. {
  3725. Stopwatch stopwatch1 = new Stopwatch();
  3726. Stopwatch stopwatch2 = new Stopwatch();
  3727. try
  3728. {
  3729. stopwatch1.Start();
  3730. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3731. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3732. string processItem = stationName; // 测试项目
  3733. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3734. string supplierCode = ""; // 供应商代码
  3735. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3736. string batch_num = GlobalContext.BatchNumber; // 批次号
  3737. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3738. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3739. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3740. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3741. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3742. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3743. bool pass = a1Result == 1;
  3744. //根据载具码获取产品码
  3745. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3746. if (string.IsNullOrEmpty(strProductBarcode))
  3747. {
  3748. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3749. }
  3750. sn = strProductBarcode;
  3751. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3752. List<TestItem> items = new List<TestItem>();
  3753. items.Add(new TestItem()
  3754. {
  3755. Parameter_name = "载具码",
  3756. Parameter_value = CarrierBarcode,
  3757. Parameter_unit = ""
  3758. });
  3759. items.Add(new TestItem()
  3760. {
  3761. Parameter_name = "产品码",
  3762. Parameter_value = sn,
  3763. Parameter_unit = ""
  3764. });
  3765. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3766. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3767. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3768. stopwatch2.Start();
  3769. //进站结果写入PLC
  3770. CommandFromPLC resultToPlC = new CommandFromPLC();
  3771. resultToPlC.cmd = 0;
  3772. resultToPlC.cmdParam = 0; //指令参数
  3773. resultToPlC.cmdResult = mesResultFrmWeb;
  3774. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3775. stopwatch2.Stop();
  3776. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3777. //保存PLC返回MES数据到本地
  3778. ResponseMessage message = new ResponseMessage();
  3779. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3780. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3781. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3782. if (message.result == false)
  3783. {
  3784. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3785. }
  3786. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3787. }
  3788. catch (Exception ex)
  3789. {
  3790. stopwatch2.Start();
  3791. CommandFromPLC resultToPlC = new CommandFromPLC();
  3792. resultToPlC.cmd = 0;
  3793. resultToPlC.cmdParam = 0; //指令参数
  3794. resultToPlC.cmdResult = 110;
  3795. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3796. stopwatch2.Stop();
  3797. string str = ex.StackTrace;
  3798. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3799. }
  3800. stopwatch1.Stop();
  3801. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3802. ProgressState = false;
  3803. }
  3804. #endregion
  3805. #region S9
  3806. /// <summary>
  3807. /// [S9] 下料设备
  3808. /// </summary>
  3809. /// <param name="plcNo">PLC编号</param>
  3810. private void ReadStation_S9(int plcNo)
  3811. {
  3812. string stationCode = "[OP90]";
  3813. string stationName = "半成品下料";
  3814. string stationNameStr = stationCode + stationName;
  3815. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3816. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3817. string tagAgvCommName = "agvCommFrmPC";
  3818. string tagBarsetName = "BarcodeSet";
  3819. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3820. (int, string) result;
  3821. while (true)
  3822. {
  3823. try
  3824. {
  3825. if (!GlobalContext._IsCon_Funs1)
  3826. {
  3827. UpdatePLCMonitor(1, plcNo, 0);
  3828. continue;
  3829. }
  3830. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3831. {
  3832. Stopwatch stopwatch1 = new Stopwatch();
  3833. Stopwatch stopwatch2 = new Stopwatch();
  3834. stopwatch1.Start();
  3835. stopwatch2.Start();
  3836. #region 一次性读取所有数据
  3837. // 一次性读取所有数据
  3838. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3839. if (result.Item1 != 0)
  3840. {
  3841. //richTextBox1.AppendText("\n" + strRet);
  3842. }
  3843. else
  3844. {
  3845. //richTextBox1.AppendText("\n" + "读取成功");
  3846. }
  3847. #endregion 一次性读取所有数据
  3848. stopwatch2.Stop();
  3849. #region 进站
  3850. try
  3851. {
  3852. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3853. {
  3854. lock (lockObj)
  3855. {
  3856. if (!ProgressState)
  3857. {
  3858. ProgressState = true;
  3859. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3860. }
  3861. }
  3862. }
  3863. }
  3864. catch (Exception ex)
  3865. {
  3866. ProgressState = false;
  3867. string str = ex.StackTrace;
  3868. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3869. }
  3870. #endregion 进站
  3871. #region 出站
  3872. try
  3873. {
  3874. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3875. {
  3876. lock (lockObj)
  3877. {
  3878. if (!ProgressState)
  3879. {
  3880. ProgressState = true;
  3881. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3882. }
  3883. }
  3884. }
  3885. }
  3886. catch (Exception ex)
  3887. {
  3888. ProgressState = false;
  3889. string str = ex.StackTrace;
  3890. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3891. }
  3892. #endregion 进站
  3893. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3894. stopwatch1.Stop();
  3895. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3896. }
  3897. else
  3898. {
  3899. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3900. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3901. FunsEip[plcNo].Connect(); // 重连
  3902. }
  3903. }
  3904. catch (Exception ex)
  3905. {
  3906. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3907. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3908. }
  3909. Thread.Sleep(IntervalReadPLC);
  3910. }
  3911. }
  3912. /// <summary>
  3913. /// [S9] 下料设备 - 进站
  3914. /// </summary>
  3915. /// <param name="plcNo">PLC编号</param>
  3916. /// <param name="stationNameStr">工站全称</param>
  3917. /// <param name="stPLC_MesData"></param>
  3918. /// <param name="tagMesCommName"></param>
  3919. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3920. {
  3921. Stopwatch stopwatch1 = new Stopwatch();
  3922. Stopwatch stopwatch2 = new Stopwatch();
  3923. try
  3924. {
  3925. stopwatch1.Start();
  3926. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3927. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3928. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  3929. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  3930. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3931. //载具码验证产品码
  3932. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3933. if (string.IsNullOrEmpty(strProductBarcode))
  3934. {
  3935. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3936. }
  3937. sn = strProductBarcode;
  3938. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3939. // 产品SN(物料码)校验
  3940. List<TestItem> item = new List<TestItem>();
  3941. stopwatch2.Start();
  3942. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3943. stopwatch2.Stop();
  3944. //指令执行结果 1:OK 110:失败
  3945. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3946. //进站结果写入PLC
  3947. CommandFromPLC resultToPlC = new CommandFromPLC();
  3948. resultToPlC.cmd = 0;
  3949. resultToPlC.cmdParam = 0; //指令参数
  3950. resultToPlC.cmdResult = mesResultFrmWeb;
  3951. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3952. }
  3953. catch (Exception ex)
  3954. {
  3955. string str = ex.StackTrace;
  3956. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3957. CommandFromPLC resultToPlC = new CommandFromPLC();
  3958. resultToPlC.cmd = 0;
  3959. resultToPlC.cmdParam = 0; //指令参数
  3960. resultToPlC.cmdResult = 110;
  3961. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3962. }
  3963. stopwatch1.Stop();
  3964. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3965. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3966. ProgressState = false;
  3967. }
  3968. /// <summary>
  3969. /// [S9] 下料设备 - 出站接口
  3970. /// </summary>
  3971. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3972. {
  3973. Stopwatch stopwatch1 = new Stopwatch();
  3974. Stopwatch stopwatch2 = new Stopwatch();
  3975. try
  3976. {
  3977. stopwatch1.Start();
  3978. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3979. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3980. string processItem = stationName; // 测试项目
  3981. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3982. string supplierCode = ""; // 供应商代码
  3983. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3984. string batch_num = GlobalContext.BatchNumber; // 批次号
  3985. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3986. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3987. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3988. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  3989. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  3990. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3991. bool pass = a1Result == 1;
  3992. //根据载具码获取产品码
  3993. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3994. if (string.IsNullOrEmpty(strProductBarcode))
  3995. {
  3996. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3997. }
  3998. sn = strProductBarcode;
  3999. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4000. List<TestItem> items = new List<TestItem>();
  4001. items.Add(new TestItem()
  4002. {
  4003. Parameter_name = "载具码",
  4004. Parameter_value = CarrierBarcode,
  4005. Parameter_unit = ""
  4006. });
  4007. items.Add(new TestItem()
  4008. {
  4009. Parameter_name = "产品码",
  4010. Parameter_value = sn,
  4011. Parameter_unit = ""
  4012. });
  4013. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4014. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  4015. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4016. stopwatch2.Start();
  4017. //进站结果写入PLC
  4018. CommandFromPLC resultToPlC = new CommandFromPLC();
  4019. resultToPlC.cmd = 0;
  4020. resultToPlC.cmdParam = 0; //指令参数
  4021. resultToPlC.cmdResult = mesResultFrmWeb;
  4022. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4023. stopwatch2.Stop();
  4024. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4025. //保存PLC返回MES数据到本地
  4026. ResponseMessage message = new ResponseMessage();
  4027. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4028. if (message.result == false)
  4029. {
  4030. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4031. }
  4032. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4033. if (result1 == 1)
  4034. {
  4035. //载具码解除绑定
  4036. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4037. if (message.result == false)
  4038. {
  4039. AddMessage(LogType.Error, message.text);
  4040. }
  4041. }
  4042. }
  4043. catch (Exception ex)
  4044. {
  4045. stopwatch2.Start();
  4046. CommandFromPLC resultToPlC = new CommandFromPLC();
  4047. resultToPlC.cmd = 0;
  4048. resultToPlC.cmdParam = 0; //指令参数
  4049. resultToPlC.cmdResult = 110;
  4050. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4051. stopwatch2.Stop();
  4052. string str = ex.StackTrace;
  4053. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4054. }
  4055. stopwatch1.Stop();
  4056. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4057. ProgressState = false;
  4058. }
  4059. #endregion
  4060. #endregion Xiaomi
  4061. #region PLC1 张超凡
  4062. #region [S1] Tray盘上料装备(板测)
  4063. /// <summary>
  4064. /// S1工位的数据- 触发信号上次的值
  4065. /// </summary>
  4066. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4067. /// <summary>
  4068. /// S1工位的数据(含触发信号)
  4069. /// </summary>
  4070. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4071. /// <summary>
  4072. /// S1工位的数据- 回写点位
  4073. /// </summary>
  4074. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4075. ///// <summary>
  4076. ///// 触发信号
  4077. ///// </summary>
  4078. //private ManualResetEvent[] MreTasks;
  4079. /// <summary>
  4080. /// [S1] Tray盘上料装备(板测)
  4081. /// </summary>
  4082. /// <param name="plcNo">PLC编号</param>
  4083. //private void ReadStation_S1(int plcNo)
  4084. //{
  4085. // // [S1] Tray盘上料装备
  4086. // // [S2] FCT
  4087. // // [S3] 值板机
  4088. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4089. // // [S5] Tray盘下料装备
  4090. // string stationCode = "[S1]";
  4091. // string stationName = "Tray盘上料装备";
  4092. // string stationNameStr = stationCode + stationName;
  4093. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4094. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4095. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4096. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4097. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4098. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4099. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4100. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4101. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4102. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4103. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4104. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4105. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4106. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4107. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4108. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4109. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4110. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4111. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4112. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4113. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4114. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4115. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4116. // s1PLCData.Add("a1Result", 0); // 产品结果
  4117. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4118. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4119. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4120. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4121. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4122. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4123. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4124. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4125. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4126. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4127. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4128. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4129. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4130. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4131. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4132. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4133. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4134. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4135. // while (IsRun)
  4136. // {
  4137. // try
  4138. // {
  4139. // if (!GlobalContext._IsCon_Funs1)
  4140. // {
  4141. // UpdatePLCMonitor(1, plcNo, 0);
  4142. // continue;
  4143. // }
  4144. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4145. // {
  4146. // Stopwatch stopwatch1 = new Stopwatch();
  4147. // Stopwatch stopwatch2 = new Stopwatch();
  4148. // stopwatch1.Start();
  4149. // stopwatch2.Start();
  4150. // #region 一次性读取所有数据
  4151. // // 一次性读取所有数据
  4152. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4153. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4154. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4155. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4156. // int[] datas = data1.Concat(data2).ToArray();
  4157. // datas = datas.Concat(data3).ToArray();
  4158. // datas = datas.Concat(data4).ToArray();
  4159. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4160. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4161. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4162. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4163. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4164. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4165. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4166. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4167. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4168. // s1PLCData["a1MES_FLAG"] = datas[109];
  4169. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4170. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4171. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4172. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4173. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4174. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4175. // s1PLCData["a1Result"] = datas[170];
  4176. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4177. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4178. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4179. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4180. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4181. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4182. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4183. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4184. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4185. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4186. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4187. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4188. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4189. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4190. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4191. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4192. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4193. // s1PLCData["a1AGVUpStart"] = datas[308];
  4194. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4195. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4196. // s1PLCData["a1AGVDownStart"] = datas[321];
  4197. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4198. // #endregion 一次性读取所有数据
  4199. // stopwatch2.Stop();
  4200. // #region 回写操作,写后清空flag
  4201. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4202. // #endregion 回写操作,写后清空flag
  4203. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4204. // try
  4205. // {
  4206. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4207. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4208. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4209. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4210. // {
  4211. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4212. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4213. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4214. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4215. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4216. // }
  4217. // }
  4218. // catch (Exception ex)
  4219. // {
  4220. // // 6代表上位机报警
  4221. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4222. // string str = ex.StackTrace;
  4223. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4224. // }
  4225. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4226. // #region 上料进站校验
  4227. // try
  4228. // {
  4229. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4230. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4231. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4232. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4233. // {
  4234. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4235. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4236. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4237. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4238. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4239. // }
  4240. // }
  4241. // catch (Exception ex)
  4242. // {
  4243. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4244. // string str = ex.StackTrace;
  4245. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4246. // }
  4247. // #endregion 上料进站校验
  4248. // #region Tray盘上料装备-出站接口
  4249. // try
  4250. // {
  4251. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4252. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4253. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4254. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4255. // {
  4256. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4257. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4258. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4259. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4260. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4261. // }
  4262. // }
  4263. // catch (Exception ex)
  4264. // {
  4265. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4266. // string str = ex.StackTrace;
  4267. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4268. // }
  4269. // #endregion Tray盘上料装备-出站接口
  4270. // #region Tray盘上料装备-将SN发给ICT标机
  4271. // try
  4272. // {
  4273. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4274. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4275. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4276. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4277. // {
  4278. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4279. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4280. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4281. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4282. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4283. // }
  4284. // }
  4285. // catch (Exception ex)
  4286. // {
  4287. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4288. // string str = ex.StackTrace;
  4289. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4290. // }
  4291. // #endregion Tray盘上料装备-将SN发给ICT标机
  4292. // #region Tray盘上料装备-点检数据
  4293. // //try
  4294. // //{
  4295. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4296. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4297. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4298. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4299. // // if (pLC_Flag && !mES_Flag) // 1 0
  4300. // // {
  4301. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4302. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4303. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4304. // // }
  4305. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4306. // // {
  4307. // // // 清空写给PLC的数据
  4308. // // // MES_Flag重置为0
  4309. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4310. // // }
  4311. // //}
  4312. // //catch (Exception ex)
  4313. // //{
  4314. // // // MES_Flag 为2上位机报错
  4315. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4316. // // string str = ex.StackTrace;
  4317. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4318. // //}
  4319. // #endregion Tray盘上料装备-点检数据
  4320. // #region 节拍接口
  4321. // try
  4322. // {
  4323. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4324. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4325. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4326. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4327. // {
  4328. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4329. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4330. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4331. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4332. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4333. // }
  4334. // }
  4335. // catch (Exception ex)
  4336. // {
  4337. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4338. // string str = ex.StackTrace;
  4339. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4340. // }
  4341. // #endregion 节拍接口
  4342. // #region AGV上料
  4343. // // AGV上料叫AGV信号
  4344. // try
  4345. // {
  4346. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4347. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4348. // if (a1AGVUpCall != a1AGVUpCallOld)
  4349. // {
  4350. // if (a1AGVUpCall == 1) // 0->1
  4351. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4352. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4353. // }
  4354. // }
  4355. // catch (Exception ex)
  4356. // {
  4357. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4358. // string str = ex.StackTrace;
  4359. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4360. // }
  4361. // // AGV上料完成信号
  4362. // try
  4363. // {
  4364. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4365. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4366. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4367. // {
  4368. // if (a1AGVUpEnd == 1) // 0->1
  4369. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4370. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4371. // }
  4372. // }
  4373. // catch (Exception ex)
  4374. // {
  4375. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4376. // string str = ex.StackTrace;
  4377. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4378. // }
  4379. // #endregion AGV上料
  4380. // #region AGV下料
  4381. // // AGV下料叫agv信号
  4382. // try
  4383. // {
  4384. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4385. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4386. // if (a1AGVDownCall != a1AGVDownCallOld)
  4387. // {
  4388. // if (a1AGVDownCall == 1) // 0->1
  4389. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4390. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4391. // }
  4392. // }
  4393. // catch (Exception ex)
  4394. // {
  4395. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4396. // string str = ex.StackTrace;
  4397. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4398. // }
  4399. // // AGV下料完成信号
  4400. // try
  4401. // {
  4402. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4403. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4404. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4405. // {
  4406. // if (a1AGVDownEnd == 1) // 0->1
  4407. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4408. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4409. // }
  4410. // }
  4411. // catch (Exception ex)
  4412. // {
  4413. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4414. // string str = ex.StackTrace;
  4415. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4416. // }
  4417. // #endregion AGV下料
  4418. // #region 心跳
  4419. // try
  4420. // {
  4421. // short states = 0;
  4422. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4423. // }
  4424. // catch (Exception ex)
  4425. // {
  4426. // string str = ex.StackTrace;
  4427. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4428. // }
  4429. // #endregion 心跳
  4430. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4431. // stopwatch1.Stop();
  4432. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4433. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4434. // }
  4435. // else
  4436. // {
  4437. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4438. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4439. // Funs[plcNo].Connect(); // 重连
  4440. // }
  4441. // }
  4442. // catch (Exception ex)
  4443. // {
  4444. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4445. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4446. // Funs[plcNo].ReConnect();
  4447. // }
  4448. // Thread.Sleep(IntervalReadPLC);
  4449. // }
  4450. //}
  4451. /// <summary>
  4452. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4453. /// </summary>
  4454. /// <param name="plcNo">PLC编号</param>
  4455. /// <param name="stationNameStr">工站全称</param>
  4456. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4457. {
  4458. Stopwatch stopwatch1 = new Stopwatch();
  4459. Stopwatch stopwatch2 = new Stopwatch();
  4460. try
  4461. {
  4462. stopwatch1.Start();
  4463. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4464. sn = sn.Replace("\0", "");
  4465. #region 查询载具上的产品信息
  4466. string cavityData = string.Empty;
  4467. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4468. if (string.IsNullOrEmpty(cavityData))
  4469. cavityData = "";
  4470. if (snResult != 0)
  4471. {
  4472. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4473. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4474. writeToPLC_Flag1.Adress = 2003;
  4475. writeToPLC_Flag1.Value = (short)6;
  4476. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4477. stopwatch1.Stop();
  4478. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4479. return;
  4480. }
  4481. #endregion 查询载具上的产品信息
  4482. string[] cavitySNs = cavityData.Split('.');
  4483. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4484. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4485. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4486. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4487. if (cavitySNs != null && cavitySNs.Length >= 2)
  4488. {
  4489. a1CavitySN1_VehicleStates = cavitySNs[0];
  4490. a1CavitySN2_VehicleStates = cavitySNs[1];
  4491. a1CavityResult1_VehicleStates = 2;
  4492. a1CavityResult2_VehicleStates = 2;
  4493. }
  4494. if (a1CavitySN1_VehicleStates == "假产品")
  4495. a1CavityResult1_VehicleStates = 3;
  4496. if (a1CavitySN2_VehicleStates == "假产品")
  4497. a1CavityResult2_VehicleStates = 3;
  4498. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4499. // 回写
  4500. stopwatch2.Start();
  4501. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4502. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4503. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4504. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4505. //// MES_Flag
  4506. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4507. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4508. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4509. writeToPLC_Flag.Adress = 2003;
  4510. writeToPLC_Flag.Value = mES_Flag;
  4511. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4512. {
  4513. Name = "a1CavitySN1_VehicleStates",
  4514. Adress = 2024,
  4515. ValueType = PLCValueType.String,
  4516. ValueTypeStrLength = 20,
  4517. Value = a1CavitySN1_VehicleStates
  4518. });
  4519. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4520. {
  4521. Name = "a1CavitySN2_VehicleStates",
  4522. Adress = 2044,
  4523. ValueType = PLCValueType.String,
  4524. ValueTypeStrLength = 20,
  4525. Value = a1CavitySN2_VehicleStates
  4526. });
  4527. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4528. {
  4529. Name = "a1CavityResult1_VehicleStates",
  4530. Adress = 2064,
  4531. ValueType = PLCValueType.Short,
  4532. Value = a1CavityResult1_VehicleStates
  4533. });
  4534. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4535. {
  4536. Name = "a1CavityResult2_VehicleStates",
  4537. Adress = 2065,
  4538. ValueType = PLCValueType.Short,
  4539. Value = a1CavityResult2_VehicleStates
  4540. });
  4541. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4542. stopwatch2.Stop();
  4543. }
  4544. catch (Exception ex)
  4545. {
  4546. string str = ex.StackTrace;
  4547. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4548. // MES_Flag
  4549. stopwatch2.Start();
  4550. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4551. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4552. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4553. writeToPLC_Flag.Adress = 2003;
  4554. writeToPLC_Flag.Value = (short)6;
  4555. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4556. stopwatch2.Stop();
  4557. }
  4558. stopwatch1.Stop();
  4559. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4560. }
  4561. /// <summary>
  4562. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4563. /// </summary>
  4564. /// <param name="plcNo">PLC编号</param>
  4565. /// <param name="stationNameStr">工站全称</param>
  4566. private void S1上料进站校验(int plcNo, string stationNameStr)
  4567. {
  4568. Stopwatch stopwatch1 = new Stopwatch();
  4569. Stopwatch stopwatch2 = new Stopwatch();
  4570. try
  4571. {
  4572. stopwatch1.Start();
  4573. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4574. sn = sn.Replace("\0", "");
  4575. // 保存进站数据+调用进站MES接口
  4576. List<TestItem> item = new List<TestItem>();
  4577. stopwatch2.Start();
  4578. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4579. stopwatch2.Stop();
  4580. short a1MES_FLAG_Check = (short)result;
  4581. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4582. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4583. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4584. writeToPLC_Flag.Adress = 2077;
  4585. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4586. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4587. }
  4588. catch (Exception ex)
  4589. {
  4590. string str = ex.StackTrace;
  4591. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4592. // MES_Flag
  4593. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4594. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4595. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4596. writeToPLC_Flag.Adress = 2077;
  4597. writeToPLC_Flag.Value = (short)6;
  4598. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4599. }
  4600. stopwatch1.Stop();
  4601. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4602. }
  4603. /// <summary>
  4604. /// [S1] Tray盘上料装备(板测)- 出站接口
  4605. /// </summary>
  4606. /// <param name="plcNo"></param>
  4607. /// <param name="stationCode"></param>
  4608. /// <param name="stationName"></param>
  4609. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4610. {
  4611. Stopwatch stopwatch1 = new Stopwatch();
  4612. Stopwatch stopwatch2 = new Stopwatch();
  4613. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4614. string stationNameStr = stationCode + stationName;
  4615. string processItem = stationName; // 测试项目
  4616. try
  4617. {
  4618. stopwatch1.Start();
  4619. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4620. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4621. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4622. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4623. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4624. sn = sn.Replace("\0", "");
  4625. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4626. partNo1 = partNo1.Replace("\0", "");
  4627. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4628. partNo2 = partNo2.Replace("\0", "");
  4629. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4630. bool pass = a1Result == 1;
  4631. stopwatch2.Start();
  4632. // 产品1
  4633. List<TestItem> items = new List<TestItem>();
  4634. items.Add(new TestItem()
  4635. {
  4636. Parameter_name = "载具码",
  4637. Parameter_value = sn,
  4638. Parameter_unit = ""
  4639. });
  4640. items.Add(new TestItem()
  4641. {
  4642. Parameter_name = "载具穴号",
  4643. Parameter_value = "1",
  4644. Parameter_unit = ""
  4645. });
  4646. items.Add(new TestItem()
  4647. {
  4648. Parameter_name = "产品结果",
  4649. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4650. Parameter_unit = ""
  4651. });
  4652. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4653. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4654. // 产品2
  4655. items = new List<TestItem>();
  4656. items.Add(new TestItem()
  4657. {
  4658. Parameter_name = "载具码",
  4659. Parameter_value = sn,
  4660. Parameter_unit = ""
  4661. });
  4662. items.Add(new TestItem()
  4663. {
  4664. Parameter_name = "载具穴号",
  4665. Parameter_value = "2",
  4666. Parameter_unit = ""
  4667. });
  4668. items.Add(new TestItem()
  4669. {
  4670. Parameter_name = "产品结果",
  4671. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4672. Parameter_unit = ""
  4673. });
  4674. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4675. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4676. short result = 0;
  4677. List<int> results = new List<int>() { result1, result2 };
  4678. if (result1 == 1 && result2 == 1)
  4679. result = 1;
  4680. else if (results.Contains(3))
  4681. result = 3;
  4682. else if (results.Contains(2))
  4683. result = 2;
  4684. else if (results.Contains(4))
  4685. result = 4;
  4686. else
  4687. result = 4;
  4688. stopwatch2.Stop();
  4689. #region 存储绑定数据到 边线MES系统中
  4690. if (result == 1)
  4691. {
  4692. string data = string.Concat(partNo1, ".", partNo2);
  4693. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4694. if (resultMesR != 0)
  4695. {
  4696. result = 4;
  4697. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4698. }
  4699. }
  4700. #endregion 存储绑定数据到 边线MES系统中
  4701. // MES_Flag 为MES报错
  4702. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4703. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4704. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4705. writeToPLC_Flag.Name = "a1MES_FLAG";
  4706. writeToPLC_Flag.Adress = 2109;
  4707. writeToPLC_Flag.Value = result;
  4708. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4709. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4710. }
  4711. catch (Exception ex)
  4712. {
  4713. stopwatch2.Restart();
  4714. // MES_Flag 为4上位机报错
  4715. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4716. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4717. writeToPLC_Flag.Name = "a1MES_FLAG";
  4718. writeToPLC_Flag.Adress = 2109;
  4719. writeToPLC_Flag.Value = (short)4;
  4720. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4721. stopwatch2.Stop();
  4722. string str = ex.StackTrace;
  4723. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4724. }
  4725. stopwatch1.Stop();
  4726. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4727. }
  4728. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4729. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4730. //{
  4731. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4732. // string stationNameStr = stationCode + stationName;
  4733. // string processItem = stationName; // 测试项目
  4734. // try
  4735. // {
  4736. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4737. // string accno = "1"; // 工序编号
  4738. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4739. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4740. // List<OneCheckItem> items = new List<OneCheckItem>()
  4741. // {
  4742. // new OneCheckItem()
  4743. // {
  4744. // Onecheck_name="胶圈装配行程设定上限",
  4745. // Onecheck_content="上限值",
  4746. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4747. // },
  4748. // };
  4749. // OneCheckData oneCheckData = new OneCheckData()
  4750. // {
  4751. // Line_code = GlobalContext.LineCode,
  4752. // Line_name = GlobalContext.LineName,
  4753. // Equipment_code = equipmentCode,
  4754. // Equipment_name = equipmentCode,
  4755. // Workorder_code = workorder_code,
  4756. // Procedure_code = accno,
  4757. // Procedure_name = processItem,
  4758. // Oneckeck_values = items,
  4759. // Onecheck_empcode = "",
  4760. // Onecheck_empname = "",
  4761. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4762. // };
  4763. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4764. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4765. // short result = result1 == 1 ? (short)1 : (short)2;
  4766. // // MES_Flag 为4MES报错
  4767. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4768. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4769. // }
  4770. // catch (Exception ex)
  4771. // {
  4772. // // MES_Flag 为2上位机报错
  4773. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4774. // string str = ex.StackTrace;
  4775. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4776. // }
  4777. //}
  4778. // ReadStation_S1_2 节拍接口+AGV
  4779. /// <summary>
  4780. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4781. /// </summary>
  4782. /// <param name="plcNo">PLC编号</param>
  4783. /// <param name="stationNameStr">工站全称</param>
  4784. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4785. {
  4786. Stopwatch stopwatch1 = new Stopwatch();
  4787. Stopwatch stopwatch2 = new Stopwatch();
  4788. try
  4789. {
  4790. stopwatch1.Start();
  4791. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4792. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4793. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4794. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4795. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4796. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4797. // ZS 将SN发给ICT标机(串口)
  4798. short a1MES_FLAG_ICT = 1;
  4799. stopwatch2.Start();
  4800. // MES_Flag
  4801. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4802. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4803. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4804. writeToPLC_Flag.Adress = 2182;
  4805. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4806. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4807. stopwatch2.Stop();
  4808. }
  4809. catch (Exception ex)
  4810. {
  4811. string str = ex.StackTrace;
  4812. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4813. stopwatch2.Start();
  4814. // MES_Flag
  4815. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4816. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4817. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4818. writeToPLC_Flag.Adress = 2182;
  4819. writeToPLC_Flag.Value = (short)4;
  4820. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4821. stopwatch2.Stop();
  4822. }
  4823. stopwatch1.Stop();
  4824. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4825. }
  4826. /// <summary>
  4827. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4828. /// </summary>
  4829. /// <param name="plcNo">PLC编号</param>
  4830. /// <param name="stationNameStr">工站全称</param>
  4831. private void S1节拍接口(int plcNo, string stationNameStr)
  4832. {
  4833. Stopwatch stopwatch1 = new Stopwatch();
  4834. Stopwatch stopwatch2 = new Stopwatch();
  4835. string resultStr = string.Empty;
  4836. try
  4837. {
  4838. stopwatch1.Start();
  4839. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4840. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4841. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4842. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4843. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4844. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4845. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  4846. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4847. if (!actionBool)
  4848. {
  4849. stopwatch2.Start();
  4850. // MES_Flag
  4851. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4852. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4853. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  4854. writeToPLC_Flag1.Adress = 2254;
  4855. writeToPLC_Flag1.Value = (short)1;
  4856. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  4857. stopwatch2.Stop();
  4858. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4859. return;
  4860. }
  4861. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  4862. {
  4863. stopwatch2.Start();
  4864. // MES_Flag
  4865. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4866. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  4867. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  4868. writeToPLC_Flag2.Adress = 2254;
  4869. writeToPLC_Flag2.Value = (short)1;
  4870. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  4871. stopwatch2.Stop();
  4872. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4873. return;
  4874. }
  4875. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  4876. { // 查产品SN
  4877. a1OEEPartNo = "Test"; // ZS
  4878. }
  4879. short a1OEEMES_FLAG = 0;
  4880. // 上传OEE
  4881. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  4882. a1OEEMES_FLAG = result.Item1;
  4883. resultStr = result.Item2;
  4884. stopwatch2.Start();
  4885. // MES_Flag
  4886. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4887. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4888. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4889. writeToPLC_Flag.Adress = 2254;
  4890. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  4891. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4892. stopwatch2.Stop();
  4893. }
  4894. catch (Exception ex)
  4895. {
  4896. string str = ex.StackTrace;
  4897. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4898. // MES_Flag
  4899. stopwatch2.Start();
  4900. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4901. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4902. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4903. writeToPLC_Flag.Adress = 2254;
  4904. writeToPLC_Flag.Value = (short)4;
  4905. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4906. stopwatch2.Stop();
  4907. }
  4908. stopwatch1.Stop();
  4909. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4910. }
  4911. /// <summary>
  4912. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  4913. /// </summary>
  4914. /// <param name="plcNo">PLC编号</param>
  4915. /// <param name="stationNameStr">工站全称</param>
  4916. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  4917. {
  4918. Stopwatch stopwatch1 = new Stopwatch();
  4919. Stopwatch stopwatch2 = new Stopwatch();
  4920. try
  4921. {
  4922. stopwatch1.Start();
  4923. // ZS 呼叫AGV
  4924. short a1AGVUpCall = 2;
  4925. stopwatch2.Start();
  4926. // a1AGVUpCall
  4927. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4928. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4929. writeToPLC_Flag.Name = "a1AGVUpCall";
  4930. writeToPLC_Flag.Adress = 2307;
  4931. writeToPLC_Flag.Value = a1AGVUpCall;
  4932. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4933. stopwatch2.Stop();
  4934. }
  4935. catch (Exception ex)
  4936. {
  4937. string str = ex.StackTrace;
  4938. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4939. // a1AGVUpCall
  4940. stopwatch2.Start();
  4941. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4942. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4943. writeToPLC_Flag.Name = "a1AGVUpCall";
  4944. writeToPLC_Flag.Adress = 2307;
  4945. writeToPLC_Flag.Value = (short)4;
  4946. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4947. stopwatch2.Stop();
  4948. }
  4949. stopwatch1.Stop();
  4950. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4951. }
  4952. /// <summary>
  4953. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  4954. /// </summary>
  4955. /// <param name="plcNo">PLC编号</param>
  4956. /// <param name="stationNameStr">工站全称</param>
  4957. private void S1AGV上料完成(int plcNo, string stationNameStr)
  4958. {
  4959. Stopwatch stopwatch1 = new Stopwatch();
  4960. Stopwatch stopwatch2 = new Stopwatch();
  4961. try
  4962. {
  4963. stopwatch1.Start();
  4964. // ZS AGV上料完成,让小车离开
  4965. short a1AGVUpEnd = 2;
  4966. stopwatch2.Start();
  4967. // a1AGVUpEnd
  4968. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4969. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4970. writeToPLC_Flag.Name = "a1AGVUpEnd";
  4971. writeToPLC_Flag.Adress = 2309;
  4972. writeToPLC_Flag.Value = a1AGVUpEnd;
  4973. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  4974. stopwatch2.Stop();
  4975. }
  4976. catch (Exception ex)
  4977. {
  4978. string str = ex.StackTrace;
  4979. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4980. // a1AGVUpEnd
  4981. stopwatch2.Start();
  4982. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4983. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4984. writeToPLC_Flag.Name = "a1AGVUpEnd";
  4985. writeToPLC_Flag.Adress = 2309;
  4986. writeToPLC_Flag.Value = (short)4;
  4987. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  4988. stopwatch2.Stop();
  4989. }
  4990. stopwatch1.Stop();
  4991. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4992. }
  4993. /// <summary>
  4994. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  4995. /// </summary>
  4996. /// <param name="plcNo">PLC编号</param>
  4997. /// <param name="stationNameStr">工站全称</param>
  4998. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  4999. {
  5000. Stopwatch stopwatch1 = new Stopwatch();
  5001. Stopwatch stopwatch2 = new Stopwatch();
  5002. try
  5003. {
  5004. stopwatch1.Start();
  5005. // ZS 呼叫AGV
  5006. short a1AGVDownCall = 2;
  5007. stopwatch2.Start();
  5008. // a1AGVDownCall
  5009. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5010. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5011. writeToPLC_Flag.Name = "a1AGVDownCall";
  5012. writeToPLC_Flag.Adress = 2320;
  5013. writeToPLC_Flag.Value = a1AGVDownCall;
  5014. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5015. stopwatch2.Stop();
  5016. }
  5017. catch (Exception ex)
  5018. {
  5019. string str = ex.StackTrace;
  5020. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5021. // a1AGVDownCall
  5022. stopwatch2.Start();
  5023. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5024. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5025. writeToPLC_Flag.Name = "a1AGVDownCall";
  5026. writeToPLC_Flag.Adress = 2320;
  5027. writeToPLC_Flag.Value = (short)4;
  5028. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5029. stopwatch2.Stop();
  5030. }
  5031. stopwatch1.Stop();
  5032. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5033. }
  5034. /// <summary>
  5035. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5036. /// </summary>
  5037. /// <param name="plcNo">PLC编号</param>
  5038. /// <param name="stationNameStr">工站全称</param>
  5039. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5040. {
  5041. Stopwatch stopwatch1 = new Stopwatch();
  5042. Stopwatch stopwatch2 = new Stopwatch();
  5043. try
  5044. {
  5045. stopwatch1.Start();
  5046. // ZS AGV上料完成,让小车离开
  5047. short a1AGVDownEnd = 2;
  5048. stopwatch2.Start();
  5049. // a1AGVDownEnd
  5050. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5051. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5052. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5053. writeToPLC_Flag.Adress = 2322;
  5054. writeToPLC_Flag.Value = a1AGVDownEnd;
  5055. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5056. stopwatch2.Stop();
  5057. }
  5058. catch (Exception ex)
  5059. {
  5060. string str = ex.StackTrace;
  5061. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5062. // a1AGVDownEnd
  5063. stopwatch2.Start();
  5064. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5065. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5066. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5067. writeToPLC_Flag.Adress = 2322;
  5068. writeToPLC_Flag.Value = (short)4;
  5069. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5070. stopwatch2.Stop();
  5071. }
  5072. stopwatch1.Stop();
  5073. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5074. }
  5075. #endregion [S1] Tray盘上料装备(板测)
  5076. #endregion PLC1 张超凡
  5077. #region PLC2 李晓奇
  5078. #region [S2] FCT(板测)
  5079. /// <summary>
  5080. /// S2工位的数据- 触发信号上次的值
  5081. /// </summary>
  5082. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5083. /// <summary>
  5084. /// S2工位的数据(含触发信号)
  5085. /// </summary>
  5086. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5087. /// <summary>
  5088. /// S2工位的数据- 回写点位
  5089. /// </summary>
  5090. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5091. /// <summary>
  5092. /// [S2] FCT(板测)
  5093. /// </summary>
  5094. /// <param name="plcNo">PLC编号</param>
  5095. //private void ReadStation_S2(int plcNo)
  5096. //{
  5097. // // [S1] Tray盘上料装备
  5098. // // [S2] FCT
  5099. // // [S3] 值板机
  5100. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5101. // // [S5] Tray盘下料装备
  5102. // /// 上位机心跳
  5103. // /// 获取设备报警数据与状态信息
  5104. // string stationCode = "[S2]";
  5105. // string stationName = "FCT";
  5106. // string stationNameStr = stationCode + stationName;
  5107. // #region 创建字典
  5108. // // 触发信号字典 赋值
  5109. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5110. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5111. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5112. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5113. // // PLC数据字典 赋值
  5114. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5115. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5116. // s2PLCData.Add("b1ProductSN_Check", 0);
  5117. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5118. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5119. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5120. // s2PLCData.Add("b1ProductSN_Bind", "");
  5121. // s2PLCData.Add("b1Part1SN_Bind", "");
  5122. // s2PLCData.Add("b1Part2SN_Bind", "");
  5123. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5124. // s2PLCData.Add("b1MES_FLAG", 0);
  5125. // s2PLCData.Add("b1ProductSN", 0);
  5126. // s2PLCData.Add("b1Part1Result", 0);
  5127. // s2PLCData.Add("b1Part2Result", 0);
  5128. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5129. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5130. // s2PLCData.Add("b1OEEProductSN", "");
  5131. // s2PLCData.Add("b1OEEType", 0);
  5132. // #endregion 创建字典
  5133. // while (IsRun)
  5134. // {
  5135. // try
  5136. // {
  5137. // if (!GlobalContext._IsCon_Funs2)
  5138. // {
  5139. // UpdatePLCMonitor(1, plcNo, 0);
  5140. // continue;
  5141. // }
  5142. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5143. // {
  5144. // Stopwatch stopwatch1 = new Stopwatch();
  5145. // Stopwatch stopwatch2 = new Stopwatch();
  5146. // stopwatch1.Start();
  5147. // stopwatch2.Start();
  5148. // #region 一次性读取所有数据
  5149. // // 一次性读取所有数据
  5150. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5151. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5152. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5153. // int[] datas = data1.Concat(data2).ToArray();
  5154. // datas = datas.Concat(data3).ToArray();
  5155. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5156. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5157. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5158. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5159. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5160. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5161. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5162. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5163. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5164. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5165. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5166. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5167. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5168. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5169. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5170. // s2PLCData["b1MES_FLAG"] = datas[169];
  5171. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5172. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5173. // s2PLCData["b1Part1Result"] = datas[190];
  5174. // s2PLCData["b1Part2Result"] = datas[191];
  5175. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5176. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5177. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5178. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5179. // s2PLCData["b1OEEType"] = datas[224];
  5180. // #endregion 一次性读取所有数据
  5181. // stopwatch2.Stop();
  5182. // #region 回写操作,写后清空flag
  5183. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5184. // #endregion 回写操作,写后清空flag
  5185. // #region 进站校验
  5186. // try
  5187. // {
  5188. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5189. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5190. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5191. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5192. // {
  5193. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5194. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5195. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5196. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5197. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5198. // }
  5199. // }
  5200. // catch (Exception ex)
  5201. // {
  5202. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5203. // string str = ex.StackTrace;
  5204. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5205. // }
  5206. // #endregion 进站校验
  5207. // #region 二穴载具解绑/绑定(产品换载具)
  5208. // try
  5209. // {
  5210. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5211. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5212. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5213. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5214. // {
  5215. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5216. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5217. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5218. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5219. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5220. // }
  5221. // }
  5222. // catch (Exception ex)
  5223. // {
  5224. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5225. // string str = ex.StackTrace;
  5226. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5227. // }
  5228. // #endregion 二穴载具解绑/绑定(产品换载具)
  5229. // #region FCT-出站接口
  5230. // try
  5231. // {
  5232. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5233. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5234. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5235. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5236. // {
  5237. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5238. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5239. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5240. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5241. // }
  5242. // }
  5243. // catch (Exception ex)
  5244. // {
  5245. // // MES_Flag 为6上位机报错
  5246. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5247. // string str = ex.StackTrace;
  5248. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5249. // }
  5250. // #endregion FCT-出站接口
  5251. // #region 节拍接口
  5252. // try
  5253. // {
  5254. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5255. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5256. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5257. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5258. // {
  5259. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5260. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5261. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5262. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5263. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5264. // }
  5265. // }
  5266. // catch (Exception ex)
  5267. // {
  5268. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5269. // string str = ex.StackTrace;
  5270. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5271. // }
  5272. // #endregion 节拍接口
  5273. // #region 心跳
  5274. // try
  5275. // {
  5276. // short states = 0;
  5277. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5278. // }
  5279. // catch (Exception ex)
  5280. // {
  5281. // string str = ex.StackTrace;
  5282. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5283. // }
  5284. // #endregion 心跳
  5285. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5286. // stopwatch1.Stop();
  5287. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5288. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5289. // }
  5290. // else
  5291. // {
  5292. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5293. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5294. // Funs[plcNo].Connect();
  5295. // }
  5296. // }
  5297. // catch (Exception ex)
  5298. // {
  5299. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5300. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5301. // Funs[plcNo].ReConnect();
  5302. // }
  5303. // Thread.Sleep(IntervalReadPLC);
  5304. // }
  5305. //}
  5306. /// <summary>
  5307. /// [S2] FCT(板测)- 进站校验
  5308. /// </summary>
  5309. /// <param name="plcNo">PLC编号</param>
  5310. /// <param name="stationNameStr">工站全称</param>
  5311. private void S2进站校验(int plcNo, string stationNameStr)
  5312. {
  5313. Stopwatch stopwatch1 = new Stopwatch();
  5314. Stopwatch stopwatch2 = new Stopwatch();
  5315. try
  5316. {
  5317. stopwatch1.Start();
  5318. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5319. sn = sn.Replace("\0", "");
  5320. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5321. // 查询物料码By载具码 并判断是不是假产品
  5322. string cavityData = string.Empty;
  5323. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5324. if (string.IsNullOrEmpty(cavityData))
  5325. cavityData = "";
  5326. if (snResult != 0)
  5327. {
  5328. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5329. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5330. writeToPLC_Flag1.Adress = 2003;
  5331. writeToPLC_Flag1.Value = (short)6;
  5332. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5333. stopwatch1.Stop();
  5334. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5335. return;
  5336. }
  5337. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5338. string[] cavitySNs = cavityData.Split('.');
  5339. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5340. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5341. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5342. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5343. if (cavitySNs != null && cavitySNs.Length >= 2)
  5344. {
  5345. b1Part1SN_Check = cavitySNs[0];
  5346. b1Part2SN_Check = cavitySNs[1];
  5347. b1Part1Result_Check = 2;
  5348. b1Part2Result_Check = 2;
  5349. }
  5350. if (b1Part1SN_Check == "假产品")
  5351. b1Part1Result_Check = 3;
  5352. if (b1Part2SN_Check == "假产品")
  5353. b1Part2Result_Check = 3;
  5354. // 调用MES进站
  5355. stopwatch2.Start();
  5356. // 调用MES进站 - 产品1
  5357. List<TestItem> item;
  5358. int result1 = b1Part1Result_Check;
  5359. if (result1 != 3)
  5360. {
  5361. item = new List<TestItem>();
  5362. item.Add(new TestItem()
  5363. {
  5364. Parameter_name = "载具码",
  5365. Parameter_value = sn,
  5366. });
  5367. item.Add(new TestItem()
  5368. {
  5369. Parameter_name = "载具穴号",
  5370. Parameter_value = "1",
  5371. });
  5372. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5373. }
  5374. // 调用MES进站 - 产品2
  5375. int result2 = b1Part2Result_Check;
  5376. if (result2 != 3)
  5377. {
  5378. item = new List<TestItem>();
  5379. item.Add(new TestItem()
  5380. {
  5381. Parameter_name = "载具码",
  5382. Parameter_value = sn,
  5383. });
  5384. item.Add(new TestItem()
  5385. {
  5386. Parameter_name = "载具穴号",
  5387. Parameter_value = "2",
  5388. });
  5389. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5390. }
  5391. stopwatch2.Stop();
  5392. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5393. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5394. int result = result1;
  5395. if (result == 1)
  5396. result = result2;
  5397. short b1MES_FLAG_Check = (short)result;
  5398. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5399. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5400. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5401. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5402. //// MES_Flag
  5403. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5404. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5405. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5406. writeToPLC_Flag.Adress = 2003;
  5407. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5408. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5409. {
  5410. Name = "b1Part1SN_Check",
  5411. Adress = 2024,
  5412. ValueType = PLCValueType.String,
  5413. ValueTypeStrLength = 20,
  5414. Value = b1Part1SN_Check
  5415. });
  5416. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5417. {
  5418. Name = "b1Part2SN_Check",
  5419. Adress = 2044,
  5420. ValueType = PLCValueType.String,
  5421. ValueTypeStrLength = 20,
  5422. Value = b1Part2SN_Check
  5423. });
  5424. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5425. {
  5426. Name = "b1Part1Result_Check",
  5427. Adress = 2064,
  5428. ValueType = PLCValueType.Short,
  5429. Value = b1Part1Result_Check
  5430. });
  5431. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5432. {
  5433. Name = "b1Part2Result_Check",
  5434. Adress = 2065,
  5435. ValueType = PLCValueType.Short,
  5436. Value = b1Part2Result_Check
  5437. });
  5438. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5439. }
  5440. catch (Exception ex)
  5441. {
  5442. string str = ex.StackTrace;
  5443. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5444. // MES_Flag
  5445. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5446. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5447. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5448. writeToPLC_Flag.Adress = 2003;
  5449. writeToPLC_Flag.Value = (short)6;
  5450. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5451. }
  5452. stopwatch1.Stop();
  5453. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5454. }
  5455. /// <summary>
  5456. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5457. /// </summary>
  5458. /// <param name="plcNo">PLC编号</param>
  5459. /// <param name="stationNameStr">工站全称</param>
  5460. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5461. {
  5462. Stopwatch stopwatch1 = new Stopwatch();
  5463. Stopwatch stopwatch2 = new Stopwatch();
  5464. try
  5465. {
  5466. stopwatch1.Start();
  5467. // 产品换载具
  5468. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5469. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5470. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5471. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5472. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5473. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5474. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5475. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5476. stopwatch2.Start();
  5477. #region 查询载具上的产品信息
  5478. //string cavityData = string.Empty;
  5479. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5480. //if (string.IsNullOrEmpty(cavityData))
  5481. // cavityData = "";
  5482. //if (snResult != 0)
  5483. //{
  5484. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5485. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5486. // writeToPLC_Flag.Adress = 2077;
  5487. // writeToPLC_Flag.Value = (short)6;
  5488. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5489. // stopwatch1.Stop();
  5490. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5491. // return;
  5492. //}
  5493. #endregion 查询载具上的产品信息
  5494. #region 解绑(边线MES系统)
  5495. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5496. if (snResult != 0)
  5497. {
  5498. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5499. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5500. writeToPLC_Flag1.Adress = 2077;
  5501. writeToPLC_Flag1.Value = (short)6;
  5502. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5503. stopwatch1.Stop();
  5504. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5505. return;
  5506. }
  5507. #endregion 解绑(边线MES系统)
  5508. #region 存储绑定数据到 边线MES系统中
  5509. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5510. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5511. if (snResult != 0)
  5512. {
  5513. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5514. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5515. writeToPLC_Flag1.Adress = 2077;
  5516. writeToPLC_Flag1.Value = (short)6;
  5517. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5518. stopwatch1.Stop();
  5519. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5520. return;
  5521. }
  5522. #endregion 存储绑定数据到 边线MES系统中
  5523. stopwatch2.Stop();
  5524. short b1MES_FLAG_Unbind = 1;
  5525. // MES_Flag
  5526. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5527. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5528. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5529. writeToPLC_Flag.Adress = 2077;
  5530. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5531. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5532. }
  5533. catch (Exception ex)
  5534. {
  5535. string str = ex.StackTrace;
  5536. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5537. // MES_Flag
  5538. stopwatch2.Start();
  5539. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5540. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5541. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5542. writeToPLC_Flag.Adress = 2077;
  5543. writeToPLC_Flag.Value = (short)6;
  5544. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5545. stopwatch2.Stop();
  5546. }
  5547. stopwatch1.Stop();
  5548. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5549. }
  5550. //// 上次采集到的SN
  5551. //private string sn_FCT = string.Empty;
  5552. /// <summary>
  5553. /// [S2] FCT(板测)- 出站数据
  5554. /// </summary>
  5555. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5556. {
  5557. Stopwatch stopwatch1 = new Stopwatch();
  5558. Stopwatch stopwatch2 = new Stopwatch();
  5559. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5560. string stationNameStr = stationCode + stationName;
  5561. string processItem = stationName; // 测试项目
  5562. try
  5563. {
  5564. stopwatch1.Start();
  5565. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5566. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5567. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5568. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5569. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5570. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5571. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5572. bool pass1 = b1Part1Result == 1;
  5573. bool pass2 = b1Part2Result == 1;
  5574. #region 根据 载具SN 查 物料SN
  5575. string cavityData = string.Empty;
  5576. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5577. if (string.IsNullOrEmpty(cavityData))
  5578. cavityData = "";
  5579. if (snResult != 0)
  5580. {
  5581. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5582. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5583. writeToPLC_Flag1.Adress = 2169;
  5584. writeToPLC_Flag1.Value = (short)4;
  5585. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5586. stopwatch1.Stop();
  5587. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5588. return;
  5589. }
  5590. #endregion 根据 载具SN 查 物料SN
  5591. string[] cavitySNs = cavityData.Split('.');
  5592. string b1ProductSN1 = string.Empty;
  5593. string b1ProductSN2 = string.Empty;
  5594. if (cavitySNs != null && cavitySNs.Length >= 2)
  5595. {
  5596. b1ProductSN1 = cavitySNs[0];
  5597. b1ProductSN2 = cavitySNs[1];
  5598. }
  5599. stopwatch2.Start();
  5600. // 产品1
  5601. int result1 = 0;
  5602. if (b1ProductSN1 == "假产品")
  5603. result1 = 1;
  5604. else
  5605. {
  5606. List<TestItem> items1 = new List<TestItem>();
  5607. items1.Add(new TestItem()
  5608. {
  5609. Parameter_name = "载具码",
  5610. Parameter_value = b1ProductSN.ToString(),
  5611. Parameter_unit = ""
  5612. });
  5613. items1.Add(new TestItem()
  5614. {
  5615. Parameter_name = "载具穴号",
  5616. Parameter_value = "1",
  5617. Parameter_unit = ""
  5618. });
  5619. items1.Add(new TestItem()
  5620. {
  5621. Parameter_name = "产品结果",
  5622. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5623. Parameter_unit = ""
  5624. });
  5625. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5626. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5627. }
  5628. // 产品2
  5629. int result2 = 0;
  5630. if (b1ProductSN1 == "假产品")
  5631. result2 = 1;
  5632. else
  5633. {
  5634. List<TestItem> items2 = new List<TestItem>();
  5635. items2.Add(new TestItem()
  5636. {
  5637. Parameter_name = "载具码",
  5638. Parameter_value = b1ProductSN.ToString(),
  5639. Parameter_unit = ""
  5640. });
  5641. items2.Add(new TestItem()
  5642. {
  5643. Parameter_name = "载具穴号",
  5644. Parameter_value = "2",
  5645. Parameter_unit = ""
  5646. });
  5647. items2.Add(new TestItem()
  5648. {
  5649. Parameter_name = "产品结果",
  5650. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5651. Parameter_unit = ""
  5652. });
  5653. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5654. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5655. }
  5656. short result = 0;
  5657. List<int> results = new List<int>() { result1, result2 };
  5658. if (result1 == 1 && result2 == 1)
  5659. result = 1;
  5660. else if (results.Contains(3))
  5661. result = 3;
  5662. else if (results.Contains(2))
  5663. result = 2;
  5664. else if (results.Contains(4))
  5665. result = 4;
  5666. else
  5667. result = 4;
  5668. stopwatch2.Stop();
  5669. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5670. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5671. writeToPLC_Flag.Name = "b1MES_FLAG";
  5672. writeToPLC_Flag.Adress = 2169;
  5673. writeToPLC_Flag.Value = result;
  5674. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5675. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5676. }
  5677. catch (Exception ex)
  5678. {
  5679. stopwatch2.Restart();
  5680. // MES_Flag 为4上位机报错
  5681. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5682. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5683. writeToPLC_Flag.Name = "b1MES_FLAG";
  5684. writeToPLC_Flag.Adress = 2169;
  5685. writeToPLC_Flag.Value = (short)4;
  5686. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5687. stopwatch2.Stop();
  5688. string str = ex.StackTrace;
  5689. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5690. }
  5691. stopwatch1.Stop();
  5692. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5693. }
  5694. /// <summary>
  5695. /// [S2] FCT(板测)- 节拍接口
  5696. /// </summary>
  5697. /// <param name="plcNo">PLC编号</param>
  5698. /// <param name="stationNameStr">工站全称</param>
  5699. private void S2节拍接口(int plcNo, string stationNameStr)
  5700. {
  5701. Stopwatch stopwatch1 = new Stopwatch();
  5702. Stopwatch stopwatch2 = new Stopwatch();
  5703. string resultStr = string.Empty;
  5704. try
  5705. {
  5706. stopwatch1.Start();
  5707. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5708. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5709. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5710. if (!actionBool)
  5711. {
  5712. stopwatch2.Start();
  5713. // MES_Flag
  5714. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5715. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5716. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5717. writeToPLC_Flag1.Adress = 2203;
  5718. writeToPLC_Flag1.Value = (short)4;
  5719. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5720. stopwatch2.Stop();
  5721. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5722. return;
  5723. }
  5724. string b1OEEPartNo = string.Empty; // 物料码
  5725. if (string.IsNullOrEmpty(b1OEEProductSN))
  5726. {
  5727. stopwatch2.Start();
  5728. // MES_Flag
  5729. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5730. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5731. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5732. writeToPLC_Flag1.Adress = 2203;
  5733. writeToPLC_Flag1.Value = (short)1;
  5734. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5735. stopwatch2.Stop();
  5736. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5737. return;
  5738. }
  5739. else
  5740. { // 查产品SN
  5741. b1OEEPartNo = "Test"; // ZS
  5742. }
  5743. short b1OEEMES_FLAG = 0;
  5744. // 上传OEE
  5745. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5746. b1OEEMES_FLAG = result.Item1;
  5747. resultStr = result.Item2;
  5748. stopwatch2.Start();
  5749. // MES_Flag
  5750. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5751. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5752. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5753. writeToPLC_Flag.Adress = 2203;
  5754. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5755. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5756. stopwatch2.Stop();
  5757. }
  5758. catch (Exception ex)
  5759. {
  5760. string str = ex.StackTrace;
  5761. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5762. // MES_Flag
  5763. stopwatch2.Start();
  5764. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5765. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5766. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5767. writeToPLC_Flag.Adress = 2203;
  5768. writeToPLC_Flag.Value = (short)4;
  5769. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5770. stopwatch2.Stop();
  5771. }
  5772. stopwatch1.Stop();
  5773. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5774. }
  5775. #endregion [S2] FCT(板测)
  5776. #endregion PLC2 李晓奇
  5777. #region PLC3 刘永村
  5778. #region [S3] 值板机
  5779. /// <summary>
  5780. /// S3工位的数据- 触发信号上次的值
  5781. /// </summary>
  5782. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5783. /// <summary>
  5784. /// S3工位的数据(含触发信号)
  5785. /// </summary>
  5786. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5787. /// <summary>
  5788. /// S3工位的数据- 回写点位
  5789. /// </summary>
  5790. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5791. /// <summary>
  5792. /// [S3] 值板机
  5793. /// </summary>
  5794. /// <param name="plcNo">PLC编号</param>
  5795. //private void ReadStation_S3(int plcNo)
  5796. //{
  5797. // // [S1] Tray盘上料装备
  5798. // // [S2] FCT
  5799. // // [S3] 值板机
  5800. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5801. // // [S5] Tray盘下料装备
  5802. // /// 上位机心跳
  5803. // /// 获取设备报警数据与状态信息
  5804. // string stationCode = "[S3]";
  5805. // string stationName = "值板机";
  5806. // string stationNameStr = stationCode + stationName;
  5807. // #region 创建字典
  5808. // // 触发信号字典 赋值
  5809. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5810. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5811. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5812. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5813. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5814. // // PLC数据字典 赋值
  5815. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5816. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5817. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5818. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5819. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5820. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5821. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5822. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5823. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5824. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5825. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5826. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5827. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5828. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5829. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5830. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5831. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5832. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5833. // s3PLCData.Add("c1Result", 0); // 产品结果
  5834. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5835. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5836. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5837. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  5838. // #endregion 创建字典
  5839. // while (IsRun)
  5840. // {
  5841. // try
  5842. // {
  5843. // if (!GlobalContext._IsCon_Funs3)
  5844. // {
  5845. // UpdatePLCMonitor(1, plcNo, 0);
  5846. // continue;
  5847. // }
  5848. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5849. // {
  5850. // Stopwatch stopwatch1 = new Stopwatch();
  5851. // Stopwatch stopwatch2 = new Stopwatch();
  5852. // stopwatch1.Start();
  5853. // stopwatch2.Start();
  5854. // #region 一次性读取所有数据
  5855. // // 一次性读取所有数据
  5856. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  5857. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  5858. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  5859. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  5860. // int[] datas = data1.Concat(data2).ToArray();
  5861. // datas = datas.Concat(data3).ToArray();
  5862. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  5863. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  5864. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5865. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  5866. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  5867. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  5868. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5869. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  5870. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  5871. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  5872. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  5873. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5874. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  5875. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  5876. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  5877. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  5878. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5879. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  5880. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  5881. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  5882. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  5883. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  5884. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  5885. // #endregion 一次性读取所有数据
  5886. // stopwatch2.Stop();
  5887. // #region 回写操作,写后清空flag
  5888. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  5889. // #endregion 回写操作,写后清空flag
  5890. // #region S3进站校验
  5891. // try
  5892. // {
  5893. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  5894. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  5895. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  5896. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  5897. // {
  5898. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  5899. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5900. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  5901. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5902. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  5903. // }
  5904. // }
  5905. // catch (Exception ex)
  5906. // {
  5907. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5908. // string str = ex.StackTrace;
  5909. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5910. // }
  5911. // #endregion S3进站校验
  5912. // #region S3二穴载具解绑
  5913. // try
  5914. // {
  5915. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  5916. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  5917. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  5918. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  5919. // {
  5920. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5921. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  5922. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  5923. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  5924. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  5925. // }
  5926. // }
  5927. // catch (Exception ex)
  5928. // {
  5929. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  5930. // string str = ex.StackTrace;
  5931. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5932. // }
  5933. // #endregion S3二穴载具解绑
  5934. // #region S3二穴载具绑定
  5935. // try
  5936. // {
  5937. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  5938. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  5939. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  5940. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  5941. // {
  5942. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5943. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5944. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  5945. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  5946. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  5947. // }
  5948. // }
  5949. // catch (Exception ex)
  5950. // {
  5951. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  5952. // string str = ex.StackTrace;
  5953. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5954. // }
  5955. // #endregion S3二穴载具绑定
  5956. // #region S3出站接口(+一穴载具绑定)
  5957. // try
  5958. // {
  5959. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  5960. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  5961. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  5962. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  5963. // {
  5964. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  5965. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5966. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  5967. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  5968. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  5969. // }
  5970. // }
  5971. // catch (Exception ex)
  5972. // {
  5973. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  5974. // string str = ex.StackTrace;
  5975. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5976. // }
  5977. // #endregion S3出站接口(+一穴载具绑定)
  5978. // #region S3节拍接口
  5979. // try
  5980. // {
  5981. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  5982. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  5983. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  5984. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  5985. // {
  5986. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  5987. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5988. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  5989. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  5990. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  5991. // }
  5992. // }
  5993. // catch (Exception ex)
  5994. // {
  5995. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  5996. // string str = ex.StackTrace;
  5997. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5998. // }
  5999. // #endregion S3节拍接口
  6000. // #region 心跳
  6001. // try
  6002. // {
  6003. // short states = 0;
  6004. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6005. // }
  6006. // catch (Exception ex)
  6007. // {
  6008. // string str = ex.StackTrace;
  6009. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6010. // }
  6011. // #endregion 心跳
  6012. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6013. // stopwatch1.Stop();
  6014. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6015. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6016. // }
  6017. // else
  6018. // {
  6019. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6020. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6021. // Funs[plcNo].Connect();
  6022. // }
  6023. // }
  6024. // catch (Exception ex)
  6025. // {
  6026. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6027. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6028. // Funs[plcNo].ReConnect();
  6029. // }
  6030. // Thread.Sleep(IntervalReadPLC);
  6031. // }
  6032. //}
  6033. /// <summary>
  6034. /// [S3] 值板机- 进站校验
  6035. /// </summary>
  6036. /// <param name="plcNo">PLC编号</param>
  6037. /// <param name="stationNameStr">工站全称</param>
  6038. private void S3进站校验(int plcNo, string stationNameStr)
  6039. {
  6040. Stopwatch stopwatch1 = new Stopwatch();
  6041. Stopwatch stopwatch2 = new Stopwatch();
  6042. try
  6043. {
  6044. stopwatch1.Start();
  6045. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6046. sn = sn.Replace("\0", "");
  6047. #region 查询载具上的产品信息
  6048. string cavityData = string.Empty;
  6049. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6050. if (string.IsNullOrEmpty(cavityData))
  6051. cavityData = "";
  6052. if (snResult != 0)
  6053. {
  6054. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6055. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6056. writeToPLC_Flag1.Adress = 2003;
  6057. writeToPLC_Flag1.Value = (short)6;
  6058. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6059. stopwatch1.Stop();
  6060. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6061. return;
  6062. }
  6063. #endregion 查询载具上的产品信息
  6064. string[] cavitySNs = cavityData.Split('.');
  6065. string part1Str = ""; // 产品1的SN码
  6066. string part2Str = ""; // 产品2的SN码
  6067. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6068. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6069. if (cavitySNs != null && cavitySNs.Length >= 2)
  6070. {
  6071. part1Str = cavitySNs[0];
  6072. part2Str = cavitySNs[1];
  6073. c1Part1Result_Check = 2;
  6074. c1Part2Result_Check = 2;
  6075. }
  6076. if (part1Str == "假产品")
  6077. c1Part1Result_Check = 3;
  6078. if (part2Str == "假产品")
  6079. c1Part2Result_Check = 3;
  6080. // 调用MES进站
  6081. stopwatch2.Start();
  6082. // 调用MES进站 - 产品1
  6083. List<TestItem> item;
  6084. int result1 = c1Part1Result_Check;
  6085. if (result1 != 3)
  6086. {
  6087. item = new List<TestItem>();
  6088. item.Add(new TestItem()
  6089. {
  6090. Parameter_name = "载具码",
  6091. Parameter_value = sn,
  6092. });
  6093. item.Add(new TestItem()
  6094. {
  6095. Parameter_name = "载具穴号",
  6096. Parameter_value = "1",
  6097. });
  6098. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6099. }
  6100. // 调用MES进站 - 产品2
  6101. int result2 = c1Part2Result_Check;
  6102. if (result2 != 3)
  6103. {
  6104. item = new List<TestItem>();
  6105. item.Add(new TestItem()
  6106. {
  6107. Parameter_name = "载具码",
  6108. Parameter_value = sn,
  6109. });
  6110. item.Add(new TestItem()
  6111. {
  6112. Parameter_name = "载具穴号",
  6113. Parameter_value = "2",
  6114. });
  6115. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6116. }
  6117. stopwatch2.Stop();
  6118. if (result1 == 2)
  6119. c1Part1Result_Check = 2;
  6120. if (result2 == 2)
  6121. c1Part2Result_Check = 2;
  6122. int result = result1;
  6123. if (result == 1)
  6124. result = result2;
  6125. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6126. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6127. short c1MES_FLAG_Check = (short)result;
  6128. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6129. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6130. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6131. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6132. //// MES_Flag
  6133. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6134. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6135. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6136. writeToPLC_Flag.Adress = 2003;
  6137. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6138. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6139. {
  6140. Name = "c1Part1Result_Check",
  6141. Adress = 2024,
  6142. ValueType = PLCValueType.Short,
  6143. Value = c1Part1Result_Check
  6144. });
  6145. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6146. {
  6147. Name = "c1Part2Result_Check",
  6148. Adress = 2025,
  6149. ValueType = PLCValueType.Short,
  6150. Value = c1Part2Result_Check
  6151. });
  6152. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6153. {
  6154. Name = "c1Part1Num_Check",
  6155. Adress = 2026,
  6156. ValueType = PLCValueType.Short,
  6157. Value = c1Part1Num_Check
  6158. });
  6159. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6160. {
  6161. Name = "c1Part2Num_Check",
  6162. Adress = 2027,
  6163. ValueType = PLCValueType.Short,
  6164. Value = c1Part2Num_Check
  6165. });
  6166. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6167. }
  6168. catch (Exception ex)
  6169. {
  6170. string str = ex.StackTrace;
  6171. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6172. // MES_Flag
  6173. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6174. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6175. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6176. writeToPLC_Flag.Adress = 2003;
  6177. writeToPLC_Flag.Value = (short)6;
  6178. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6179. }
  6180. stopwatch1.Stop();
  6181. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6182. }
  6183. /// <summary>
  6184. /// [S3] 值板机 - 二穴载具解绑
  6185. /// </summary>
  6186. /// <param name="plcNo">PLC编号</param>
  6187. /// <param name="stationNameStr">工站全称</param>
  6188. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6189. {
  6190. Stopwatch stopwatch1 = new Stopwatch();
  6191. Stopwatch stopwatch2 = new Stopwatch();
  6192. try
  6193. {
  6194. stopwatch1.Start();
  6195. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6196. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6197. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6198. // 解绑
  6199. #region 查询载具上的产品信息
  6200. string cavityData = string.Empty;
  6201. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6202. if (string.IsNullOrEmpty(cavityData))
  6203. cavityData = "";
  6204. if (snResult != 0)
  6205. {
  6206. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6207. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6208. writeToPLC_Flag1.Adress = 2082;
  6209. writeToPLC_Flag1.Value = (short)6;
  6210. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6211. stopwatch1.Stop();
  6212. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6213. return;
  6214. }
  6215. #endregion 查询载具上的产品信息
  6216. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6217. #region 解绑
  6218. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6219. {
  6220. // 删除
  6221. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6222. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6223. }
  6224. else
  6225. {
  6226. string data_new = string.Join(".", cavitySNs);
  6227. // 删除再插入
  6228. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6229. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6230. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6231. }
  6232. #endregion 解绑
  6233. short c1MES_FLAG_Unbind = 1;
  6234. stopwatch2.Start();
  6235. // MES_Flag
  6236. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6237. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6238. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6239. writeToPLC_Flag.Adress = 2082;
  6240. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6241. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6242. stopwatch2.Stop();
  6243. }
  6244. catch (Exception ex)
  6245. {
  6246. string str = ex.StackTrace;
  6247. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6248. // MES_Flag
  6249. stopwatch2.Start();
  6250. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6251. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6252. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6253. writeToPLC_Flag.Adress = 2082;
  6254. writeToPLC_Flag.Value = (short)6;
  6255. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6256. stopwatch2.Stop();
  6257. }
  6258. stopwatch1.Stop();
  6259. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6260. }
  6261. /// <summary>
  6262. /// [S3] 值板机 - 二穴载具绑定
  6263. /// </summary>
  6264. /// <param name="plcNo">PLC编号</param>
  6265. /// <param name="stationNameStr">工站全称</param>
  6266. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6267. {
  6268. Stopwatch stopwatch1 = new Stopwatch();
  6269. Stopwatch stopwatch2 = new Stopwatch();
  6270. try
  6271. {
  6272. stopwatch1.Start();
  6273. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6274. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6275. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6276. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6277. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6278. stopwatch2.Start();
  6279. #region 查询载具上的产品信息
  6280. string cavityData = string.Empty;
  6281. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6282. if (string.IsNullOrEmpty(cavityData))
  6283. cavityData = "";
  6284. if (snResult != 0)
  6285. {
  6286. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6287. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6288. writeToPLC_Flag1.Adress = 2115;
  6289. writeToPLC_Flag1.Value = (short)6;
  6290. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6291. stopwatch1.Stop();
  6292. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6293. return;
  6294. }
  6295. #endregion 查询载具上的产品信息
  6296. // 产品换载具
  6297. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6298. string partSn1 = "";
  6299. string partSn2 = "";
  6300. if (cavitySNs != null && cavitySNs.Length >= 2)
  6301. {
  6302. partSn1 = cavitySNs[0];
  6303. partSn2 = cavitySNs[1];
  6304. }
  6305. string data_new = string.Empty;
  6306. // 是否是两个穴位交换
  6307. if (c1CavityReverse_Bind == 1)
  6308. {
  6309. // 交换
  6310. data_new = string.Concat(partSn2, ".", partSn1);
  6311. }
  6312. else
  6313. { // 不交换
  6314. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6315. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6316. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6317. data_new = string.Join(".", cavitySNs);
  6318. }
  6319. // 删除再插入
  6320. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6321. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6322. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6323. stopwatch2.Stop();
  6324. short c1MES_FLAG_Bind = 1;
  6325. // MES_Flag
  6326. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6327. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6328. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6329. writeToPLC_Flag.Adress = 2115;
  6330. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6331. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6332. }
  6333. catch (Exception ex)
  6334. {
  6335. string str = ex.StackTrace;
  6336. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6337. // MES_Flag
  6338. stopwatch2.Start();
  6339. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6340. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6341. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6342. writeToPLC_Flag.Adress = 2115;
  6343. writeToPLC_Flag.Value = (short)6;
  6344. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6345. stopwatch2.Stop();
  6346. }
  6347. stopwatch1.Stop();
  6348. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6349. }
  6350. //// 上次采集到的SN
  6351. //private string sn_值板机 = string.Empty;
  6352. /// <summary>
  6353. /// [S3] 值板机 - 出站接口
  6354. /// </summary>
  6355. /// <param name="plcNo">PLC编号</param>
  6356. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6357. {
  6358. Stopwatch stopwatch1 = new Stopwatch();
  6359. Stopwatch stopwatch2 = new Stopwatch();
  6360. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6361. string stationNameStr = stationCode + stationName;
  6362. string processItem = stationName; // 测试项目
  6363. try
  6364. {
  6365. stopwatch1.Start();
  6366. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6367. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6368. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6369. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6370. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6371. sn = sn.Replace("\0", "");
  6372. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6373. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6374. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6375. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6376. bool pass = c1Result == 1;
  6377. // 查sn
  6378. #region 查询载具上的产品信息
  6379. string cavityData = string.Empty;
  6380. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6381. if (string.IsNullOrEmpty(cavityData))
  6382. cavityData = "";
  6383. if (snResult != 0)
  6384. {
  6385. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6386. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6387. writeToPLC_Flag1.Adress = 2150;
  6388. writeToPLC_Flag1.Value = (short)4;
  6389. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6390. stopwatch1.Stop();
  6391. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6392. return;
  6393. }
  6394. #endregion 查询载具上的产品信息
  6395. string[] cavitySNs = cavityData.Split('.');
  6396. string productSN = "";
  6397. if (cavitySNs != null && cavitySNs.Length >= 2)
  6398. {
  6399. productSN = cavitySNs[c1VehicleCavity];
  6400. cavitySNs[c1VehicleCavity] = "";
  6401. }
  6402. stopwatch2.Start();
  6403. List<TestItem> items = new List<TestItem>();
  6404. items.Add(new TestItem()
  6405. {
  6406. Parameter_name = "二穴载具码",
  6407. Parameter_value = c1ProductSN_Check,
  6408. Parameter_unit = ""
  6409. });
  6410. items.Add(new TestItem()
  6411. {
  6412. Parameter_name = "二穴载具穴号",
  6413. Parameter_value = c1VehicleCavity.ToString(),
  6414. Parameter_unit = ""
  6415. });
  6416. items.Add(new TestItem()
  6417. {
  6418. Parameter_name = "一穴载具码",
  6419. Parameter_value = sn,
  6420. Parameter_unit = ""
  6421. });
  6422. items.Add(new TestItem()
  6423. {
  6424. Parameter_name = "一穴载具穴号",
  6425. Parameter_value = "1",
  6426. Parameter_unit = ""
  6427. });
  6428. items.Add(new TestItem()
  6429. {
  6430. Parameter_name = "产品结果",
  6431. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6432. Parameter_unit = ""
  6433. });
  6434. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6435. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6436. short result = (short)result1;
  6437. stopwatch2.Stop();
  6438. #region 存储绑定数据到 边线MES系统中
  6439. if (result == 1)
  6440. {
  6441. string data = string.Concat(productSN);
  6442. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6443. if (resultMesR != 0)
  6444. {
  6445. result = 4;
  6446. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6447. }
  6448. }
  6449. #endregion 存储绑定数据到 边线MES系统中
  6450. #region 产品从 来源载具(二穴载具)中删除
  6451. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6452. {
  6453. // 删除
  6454. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6455. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6456. }
  6457. else
  6458. {
  6459. string data_new = string.Join(".", cavitySNs);
  6460. // 删除再插入
  6461. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6462. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6463. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6464. }
  6465. #endregion 产品从 来源载具(二穴载具)中删除
  6466. // MES_Flag 为MES报错
  6467. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6468. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6469. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6470. writeToPLC_Flag.Name = "c1MES_FLAG";
  6471. writeToPLC_Flag.Adress = 2150;
  6472. writeToPLC_Flag.Value = result;
  6473. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6474. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6475. }
  6476. catch (Exception ex)
  6477. {
  6478. stopwatch2.Restart();
  6479. // MES_Flag 为4上位机报错
  6480. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6481. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6482. writeToPLC_Flag.Name = "c1MES_FLAG";
  6483. writeToPLC_Flag.Adress = 2150;
  6484. writeToPLC_Flag.Value = (short)4;
  6485. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6486. stopwatch2.Stop();
  6487. string str = ex.StackTrace;
  6488. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6489. }
  6490. stopwatch1.Stop();
  6491. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6492. }
  6493. /// <summary>
  6494. /// [S3] 值板机- 节拍接口
  6495. /// </summary>
  6496. /// <param name="plcNo">PLC编号</param>
  6497. /// <param name="stationNameStr">工站全称</param>
  6498. private void S3节拍接口(int plcNo, string stationNameStr)
  6499. {
  6500. Stopwatch stopwatch1 = new Stopwatch();
  6501. Stopwatch stopwatch2 = new Stopwatch();
  6502. string resultStr = string.Empty;
  6503. try
  6504. {
  6505. stopwatch1.Start();
  6506. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6507. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6508. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6509. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6510. if (!actionBool)
  6511. {
  6512. stopwatch2.Start();
  6513. // MES_Flag
  6514. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6515. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6516. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6517. writeToPLC_Flag1.Adress = 2204;
  6518. writeToPLC_Flag1.Value = (short)4;
  6519. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6520. stopwatch2.Stop();
  6521. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6522. return;
  6523. }
  6524. string c1OEEPartNo = string.Empty; // 物料码
  6525. if (string.IsNullOrEmpty(c1OEEProductSN))
  6526. {
  6527. stopwatch2.Start();
  6528. // MES_Flag
  6529. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6530. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6531. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6532. writeToPLC_Flag1.Adress = 2204;
  6533. writeToPLC_Flag1.Value = (short)1;
  6534. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6535. stopwatch2.Stop();
  6536. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6537. return;
  6538. }
  6539. else
  6540. { // 查产品SN
  6541. c1OEEPartNo = "Test"; // ZS
  6542. }
  6543. short c1OEEMES_FLAG = 0;
  6544. // 上传OEE
  6545. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6546. c1OEEMES_FLAG = result.Item1;
  6547. resultStr = result.Item2;
  6548. stopwatch2.Start();
  6549. // MES_Flag
  6550. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6551. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6552. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6553. writeToPLC_Flag.Adress = 2204;
  6554. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6555. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6556. stopwatch2.Stop();
  6557. }
  6558. catch (Exception ex)
  6559. {
  6560. string str = ex.StackTrace;
  6561. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6562. // MES_Flag
  6563. stopwatch2.Start();
  6564. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6565. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6566. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6567. writeToPLC_Flag.Adress = 2204;
  6568. writeToPLC_Flag.Value = (short)4;
  6569. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6570. stopwatch2.Stop();
  6571. }
  6572. stopwatch1.Stop();
  6573. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6574. }
  6575. #endregion [S3] 值板机
  6576. #endregion PLC3 刘永村
  6577. #region PLC4 刘果段
  6578. #region [S4] 取放桁架
  6579. /// <summary>
  6580. /// S4工位的数据- 触发信号上次的值
  6581. /// </summary>
  6582. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6583. /// <summary>
  6584. /// S4工位的数据(含触发信号)
  6585. /// </summary>
  6586. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6587. /// <summary>
  6588. /// S4工位的数据- 回写点位
  6589. /// </summary>
  6590. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6591. /// <summary>
  6592. /// [S4] 取放桁架
  6593. /// </summary>
  6594. /// <param name="plcNo">PLC编号</param>
  6595. //private void ReadStation_S4(int plcNo)
  6596. //{
  6597. // // [S1] Tray盘上料装备
  6598. // // [S2] FCT
  6599. // // [S3] 值板机
  6600. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6601. // // [S5] Tray盘下料装备
  6602. // /// 上位机心跳
  6603. // /// 获取设备报警数据与状态信息
  6604. // string stationCode = "[S4_1]";
  6605. // string stationName = "载具下线装备";
  6606. // string stationNameStr = stationCode + stationName;
  6607. // string stationCode2 = "[S4_2]";
  6608. // string stationName2 = "桁架";
  6609. // string stationNameStr2 = stationCode2 + stationName2;
  6610. // string stationCode3 = "[S4_3]";
  6611. // string stationName3 = "提升机1";
  6612. // string stationNameStr3 = stationCode3 + stationName3;
  6613. // string stationCode4 = "[S4_4]";
  6614. // string stationName4 = "提升机2";
  6615. // string stationNameStr4 = stationCode4 + stationName4;
  6616. // string stationCode5 = "[S4_5]";
  6617. // string stationName5 = "载具上线装备";
  6618. // string stationNameStr5 = stationCode5 + stationName5;
  6619. // #region 创建字典
  6620. // // 触发信号字典 赋值
  6621. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6622. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6623. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6624. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6625. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6626. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6627. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6628. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6629. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6630. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6631. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6632. // // PLC数据字典 赋值
  6633. // // 载具下线装备(弹夹上线)
  6634. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6635. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6636. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6637. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6638. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6639. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6640. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6641. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6642. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6643. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6644. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6645. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6646. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6647. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6648. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6649. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6650. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6651. // s4PLCData.Add("d1Result", 0); // 产品结果
  6652. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6653. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6654. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6655. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6656. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6657. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6658. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6659. // // 真空标机(提升机)
  6660. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6661. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6662. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6663. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6664. // s4PLCData.Add("d3Result", 0); // 产品结果
  6665. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6666. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6667. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6668. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6669. // s4PLCData.Add("d4Result", 0); // 产品结果
  6670. // // 载具上线装备(弹夹下线)
  6671. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6672. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6673. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6674. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6675. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6676. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6677. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6678. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6679. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6680. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6681. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6682. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6683. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6684. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6685. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6686. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6687. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6688. // s4PLCData.Add("d5Result", 0); // 产品结果
  6689. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6690. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6691. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6692. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6693. // #endregion 创建字典
  6694. // while (IsRun)
  6695. // {
  6696. // try
  6697. // {
  6698. // if (!GlobalContext._IsCon_Funs4)
  6699. // {
  6700. // UpdatePLCMonitor(1, plcNo, 0);
  6701. // continue;
  6702. // }
  6703. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6704. // {
  6705. // Stopwatch stopwatch1 = new Stopwatch();
  6706. // Stopwatch stopwatch2 = new Stopwatch();
  6707. // stopwatch1.Start();
  6708. // stopwatch2.Start();
  6709. // #region 一次性读取所有数据
  6710. // // 载具下线装备(弹夹上线)
  6711. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6712. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6713. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6714. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6715. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6716. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6717. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6718. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6719. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6720. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6721. // int[] datas = data1.Concat(data2).ToArray();
  6722. // datas = datas.Concat(data3).ToArray();
  6723. // datas = datas.Concat(data4).ToArray();
  6724. // datas = datas.Concat(data5).ToArray();
  6725. // datas = datas.Concat(data6).ToArray();
  6726. // datas = datas.Concat(data7).ToArray();
  6727. // datas = datas.Concat(data8).ToArray();
  6728. // datas = datas.Concat(data9).ToArray();
  6729. // datas = datas.Concat(data10).ToArray();
  6730. // // 载具下线装备(弹夹上线)
  6731. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6732. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6733. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6734. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6735. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6736. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6737. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6738. // s4PLCData["d1MES_FLAG"] = datas[65];
  6739. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6740. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6741. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6742. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6743. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6744. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6745. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6746. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6747. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6748. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6749. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6750. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6751. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6752. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6753. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6754. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6755. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6756. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6757. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6758. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6759. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6760. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6761. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6762. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6763. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6764. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6765. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6766. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6767. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6768. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6769. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6770. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6771. // s4PLCData["d1Result"] = datas[386];
  6772. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6773. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6774. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6775. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6776. // s4PLCData["d1OEEType"] = datas[419];
  6777. // // 桁架(查询标机中弹夹的状态)
  6778. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6779. // s4PLCData["d2BulletclipStates"] = datas[431];
  6780. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6781. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6782. // // 真空标机
  6783. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6784. // s4PLCData["d3MES_FLAG"] = datas[463];
  6785. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6786. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6787. // s4PLCData["d3Result"] = datas[484];
  6788. // s4PLCData["d3Type"] = datas[485];
  6789. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6790. // s4PLCData["d4MES_FLAG"] = datas[496];
  6791. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6792. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6793. // s4PLCData["d4Result"] = datas[517];
  6794. // s4PLCData["d4Type"] = datas[518];
  6795. // // 载具上线装备(弹夹下线)
  6796. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6797. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6798. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6799. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6800. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6801. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6802. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6803. // s4PLCData["d5MES_FLAG"] = datas[591];
  6804. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6805. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6806. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6807. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6808. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6809. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6810. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6811. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6812. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6813. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6814. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6815. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6816. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6817. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6818. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6819. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6820. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6821. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6822. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6823. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6824. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6825. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6826. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6827. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6828. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6829. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6830. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6831. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6832. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6833. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6834. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6835. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6836. // s4PLCData["d5Result"] = datas[912];
  6837. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  6838. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  6839. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  6840. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  6841. // s4PLCData["d5OEEType"] = datas[945];
  6842. // #endregion 一次性读取所有数据
  6843. // stopwatch2.Stop();
  6844. // #region 回写操作,写后清空flag
  6845. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  6846. // #endregion 回写操作,写后清空flag
  6847. // // N801A-S4_1 弹夹扫码
  6848. // #region N801A-S4_1 弹夹扫码
  6849. // try
  6850. // {
  6851. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  6852. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  6853. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  6854. // {
  6855. // if (d1BulletclipScanCode == 1) // 0->1
  6856. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6857. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  6858. // }
  6859. // }
  6860. // catch (Exception ex)
  6861. // {
  6862. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  6863. // string str = ex.StackTrace;
  6864. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6865. // }
  6866. // #endregion N801A-S4_1 弹夹扫码
  6867. // // N801A-S4_1 载具扫码
  6868. // #region N801A-S4_1 载具扫码
  6869. // try
  6870. // {
  6871. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  6872. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  6873. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  6874. // {
  6875. // if (d1VehicleScanCode == 1) // 0->1
  6876. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6877. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  6878. // }
  6879. // }
  6880. // catch (Exception ex)
  6881. // {
  6882. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  6883. // string str = ex.StackTrace;
  6884. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6885. // }
  6886. // #endregion N801A-S4_1 载具扫码
  6887. // // N801A-S4_1 出站接口
  6888. // #region N801A-S4_1 出站接口
  6889. // try
  6890. // {
  6891. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  6892. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  6893. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  6894. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  6895. // {
  6896. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  6897. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6898. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  6899. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  6900. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  6901. // }
  6902. // }
  6903. // catch (Exception ex)
  6904. // {
  6905. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  6906. // string str = ex.StackTrace;
  6907. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6908. // }
  6909. // #endregion N801A-S4_1 出站接口
  6910. // // N801A-S4_1 节拍接口
  6911. // #region N801A-S4_1 节拍接口
  6912. // try
  6913. // {
  6914. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  6915. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  6916. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  6917. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  6918. // {
  6919. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  6920. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6921. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  6922. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  6923. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  6924. // }
  6925. // }
  6926. // catch (Exception ex)
  6927. // {
  6928. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  6929. // string str = ex.StackTrace;
  6930. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6931. // }
  6932. // #endregion N801A-S4_1 节拍接口
  6933. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  6934. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  6935. // try
  6936. // {
  6937. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  6938. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  6939. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  6940. // {
  6941. // if (d2BulletclipScanCode == 1) // 0->1
  6942. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  6943. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  6944. // }
  6945. // }
  6946. // catch (Exception ex)
  6947. // {
  6948. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  6949. // string str = ex.StackTrace;
  6950. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6951. // }
  6952. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  6953. // // N801A-S4_3 真空标机1 数据
  6954. // #region N801A-S4_3 真空标机1
  6955. // try
  6956. // {
  6957. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  6958. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  6959. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  6960. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  6961. // {
  6962. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  6963. // {
  6964. // int stationType = (int)s4PLCData["d3Type"];
  6965. // if (stationType == 1)
  6966. // {
  6967. // // S4_3进站接口
  6968. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  6969. // }
  6970. // else if (stationType == 2)
  6971. // {
  6972. // // S4_3出站接口
  6973. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  6974. // }
  6975. // }
  6976. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  6977. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  6978. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  6979. // }
  6980. // }
  6981. // catch (Exception ex)
  6982. // {
  6983. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  6984. // string str = ex.StackTrace;
  6985. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6986. // }
  6987. // #endregion N801A-S4_3 真空标机1
  6988. // // N801A-S4_4 真空标机2 数据
  6989. // #region N801A-S4_4 真空标机2
  6990. // try
  6991. // {
  6992. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  6993. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  6994. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  6995. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  6996. // {
  6997. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  6998. // {
  6999. // int stationType = (int)s4PLCData["d4Type"];
  7000. // if (stationType == 1)
  7001. // {
  7002. // // S4_4进站接口
  7003. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  7004. // }
  7005. // else if (stationType == 2)
  7006. // {
  7007. // // S4_4出站接口
  7008. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  7009. // }
  7010. // }
  7011. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  7012. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  7013. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  7014. // }
  7015. // }
  7016. // catch (Exception ex)
  7017. // {
  7018. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7019. // string str = ex.StackTrace;
  7020. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7021. // }
  7022. // #endregion N801A-S4_4 真空标机2
  7023. // // N801A-S4_5 弹夹扫码 数据
  7024. // #region N801A-S4_5 弹夹扫码
  7025. // try
  7026. // {
  7027. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7028. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7029. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7030. // {
  7031. // if (d5BulletclipScanCode == 1) // 0->1
  7032. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7033. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7034. // }
  7035. // }
  7036. // catch (Exception ex)
  7037. // {
  7038. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7039. // string str = ex.StackTrace;
  7040. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7041. // }
  7042. // #endregion N801A-S4_5 弹夹扫码
  7043. // // N801A-S4_5 载具扫码 数据
  7044. // #region N801A-S4_5 载具扫码
  7045. // try
  7046. // {
  7047. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7048. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7049. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7050. // {
  7051. // if (d5VehicleScanCode == 1) // 0->1
  7052. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7053. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7054. // }
  7055. // }
  7056. // catch (Exception ex)
  7057. // {
  7058. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7059. // string str = ex.StackTrace;
  7060. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7061. // }
  7062. // #endregion N801A-S4_5 载具扫码
  7063. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7064. // #region N801A-S4_5 出站接口
  7065. // try
  7066. // {
  7067. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7068. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7069. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7070. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7071. // {
  7072. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7073. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7074. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7075. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7076. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7077. // }
  7078. // }
  7079. // catch (Exception ex)
  7080. // {
  7081. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7082. // string str = ex.StackTrace;
  7083. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7084. // }
  7085. // #endregion N801A-S4_5 出站接口
  7086. // // N801A-S4_5 节拍接口 数据
  7087. // #region N801A-S4_5 节拍接口
  7088. // try
  7089. // {
  7090. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7091. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7092. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7093. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7094. // {
  7095. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7096. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7097. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7098. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7099. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7100. // }
  7101. // }
  7102. // catch (Exception ex)
  7103. // {
  7104. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7105. // string str = ex.StackTrace;
  7106. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7107. // }
  7108. // #endregion N801A-S4_5 节拍接口
  7109. // #region 心跳
  7110. // try
  7111. // {
  7112. // short states = 0;
  7113. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7114. // }
  7115. // catch (Exception ex)
  7116. // {
  7117. // string str = ex.StackTrace;
  7118. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7119. // }
  7120. // #endregion 心跳
  7121. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7122. // stopwatch1.Stop();
  7123. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7124. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7125. // }
  7126. // else
  7127. // {
  7128. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7129. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7130. // Funs[plcNo].Connect();
  7131. // }
  7132. // }
  7133. // catch (Exception ex)
  7134. // {
  7135. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7136. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7137. // Funs[plcNo].ReConnect();
  7138. // }
  7139. // Thread.Sleep(IntervalReadPLC);
  7140. // }
  7141. //}
  7142. /// <summary>
  7143. /// [S4] 取放桁架 - S4_1弹夹扫码
  7144. /// </summary>
  7145. /// <param name="plcNo">PLC编号</param>
  7146. /// <param name="stationNameStr">工站全称</param>
  7147. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7148. {
  7149. Stopwatch stopwatch1 = new Stopwatch();
  7150. Stopwatch stopwatch2 = new Stopwatch();
  7151. try
  7152. {
  7153. stopwatch1.Start();
  7154. // ZS 弹夹扫码
  7155. string d1BulletclipCode = " "; // 扫到的码
  7156. short d1BulletclipScanCode = 2;
  7157. stopwatch2.Start();
  7158. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7159. //// MES_Flag
  7160. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7161. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7162. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7163. writeToPLC_Flag.Adress = 2002;
  7164. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7165. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7166. {
  7167. Name = "d1BulletclipCode",
  7168. Adress = 2003,
  7169. ValueType = PLCValueType.String,
  7170. ValueTypeStrLength = 20,
  7171. Value = d1BulletclipCode
  7172. });
  7173. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7174. stopwatch2.Stop();
  7175. }
  7176. catch (Exception ex)
  7177. {
  7178. string str = ex.StackTrace;
  7179. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7180. stopwatch2.Start();
  7181. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7182. //// MES_Flag
  7183. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7184. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7185. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7186. writeToPLC_Flag.Adress = 2002;
  7187. writeToPLC_Flag.Value = (short)6;
  7188. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7189. {
  7190. Name = "d1BulletclipCode",
  7191. Adress = 2003,
  7192. ValueType = PLCValueType.String,
  7193. ValueTypeStrLength = 20,
  7194. Value = " "
  7195. });
  7196. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7197. stopwatch2.Stop();
  7198. }
  7199. stopwatch1.Stop();
  7200. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7201. }
  7202. /// <summary>
  7203. /// [S4] 取放桁架 - S4_1载具扫码
  7204. /// </summary>
  7205. /// <param name="plcNo">PLC编号</param>
  7206. /// <param name="stationNameStr">工站全称</param>
  7207. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7208. {
  7209. Stopwatch stopwatch1 = new Stopwatch();
  7210. Stopwatch stopwatch2 = new Stopwatch();
  7211. try
  7212. {
  7213. stopwatch1.Start();
  7214. // ZS 载具扫码
  7215. string d1VehicleCode = ""; // 扫到的码
  7216. short d1VehicleScanCode = 2;
  7217. #region 进站
  7218. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7219. {
  7220. #region 查询载具上的产品信息
  7221. string cavityData = string.Empty;
  7222. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7223. if (string.IsNullOrEmpty(cavityData))
  7224. cavityData = "";
  7225. if (snResult != 0)
  7226. {
  7227. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7228. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7229. writeToPLC_Flag1.Adress = 2033;
  7230. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7231. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7232. {
  7233. Name = "d1VehicleCode",
  7234. Adress = 2034,
  7235. ValueType = PLCValueType.String,
  7236. ValueTypeStrLength = 20,
  7237. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7238. });
  7239. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7240. stopwatch1.Stop();
  7241. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7242. return;
  7243. }
  7244. string[] cavitySNs = cavityData.Split('.');
  7245. string partNo = "";
  7246. if (cavitySNs != null && cavitySNs.Length >= 1)
  7247. {
  7248. partNo = cavitySNs[0];
  7249. }
  7250. #endregion 查询载具上的产品信息
  7251. List<TestItem> item = new List<TestItem>();
  7252. item.Add(new TestItem()
  7253. {
  7254. Parameter_name = "载具码",
  7255. Parameter_value = d1VehicleCode,
  7256. });
  7257. item.Add(new TestItem()
  7258. {
  7259. Parameter_name = "载具穴号",
  7260. Parameter_value = "1",
  7261. });
  7262. stopwatch2.Start();
  7263. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7264. stopwatch2.Stop();
  7265. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7266. }
  7267. #endregion 进站
  7268. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7269. //// MES_Flag
  7270. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7271. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7272. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7273. writeToPLC_Flag.Adress = 2033;
  7274. writeToPLC_Flag.Value = d1VehicleScanCode;
  7275. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7276. {
  7277. Name = "d1VehicleCode",
  7278. Adress = 2034,
  7279. ValueType = PLCValueType.String,
  7280. ValueTypeStrLength = 20,
  7281. Value = d1VehicleCode
  7282. });
  7283. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7284. }
  7285. catch (Exception ex)
  7286. {
  7287. string str = ex.StackTrace;
  7288. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7289. stopwatch2.Start();
  7290. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7291. //// MES_Flag
  7292. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7293. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7294. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7295. writeToPLC_Flag.Adress = 2033;
  7296. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7297. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7298. {
  7299. Name = "d1VehicleCode",
  7300. Adress = 2034,
  7301. ValueType = PLCValueType.String,
  7302. ValueTypeStrLength = 20,
  7303. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7304. });
  7305. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7306. stopwatch2.Stop();
  7307. }
  7308. stopwatch1.Stop();
  7309. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7310. }
  7311. // 上次采集到的SN
  7312. //private string sn_S4_1出站接口 = string.Empty;
  7313. /// <summary>
  7314. /// [S4] 取放桁架 - S4_1出站接口
  7315. /// </summary>
  7316. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7317. {
  7318. Stopwatch stopwatch1 = new Stopwatch();
  7319. Stopwatch stopwatch2 = new Stopwatch();
  7320. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7321. string stationNameStr = stationCode + stationName;
  7322. string processItem = stationName; // 测试项目
  7323. try
  7324. {
  7325. stopwatch1.Start();
  7326. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7327. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7328. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7329. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7330. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7331. sn = sn.Replace("\0", "");
  7332. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7333. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7334. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7335. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7336. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7337. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7338. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7339. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7340. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7341. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7342. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7343. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7344. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7345. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7346. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7347. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7348. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7349. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7350. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7351. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7352. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7353. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7354. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7355. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7356. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7357. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7358. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7359. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7360. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7361. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7362. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7363. bool pass = d1Result == 1;
  7364. // 存 载具SN列表
  7365. List<string> vehicleCodes = new List<string>()
  7366. {
  7367. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7368. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7369. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7370. };
  7371. // 统一查 产品SN列表
  7372. List<string> partNos = new List<string>();
  7373. foreach (string vehicleCode in vehicleCodes)
  7374. {
  7375. if (string.IsNullOrEmpty(vehicleCode))
  7376. partNos.Add("");
  7377. else
  7378. {
  7379. string partNo = "";
  7380. #region 查询载具上的产品信息
  7381. string cavityData = string.Empty;
  7382. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7383. if (string.IsNullOrEmpty(cavityData))
  7384. cavityData = "";
  7385. if (snResult != 0)
  7386. {
  7387. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7388. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7389. writeToPLC_Flag1.Adress = 2065;
  7390. writeToPLC_Flag1.Value = (short)4;
  7391. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7392. stopwatch1.Stop();
  7393. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7394. return;
  7395. }
  7396. string[] cavitySNs = cavityData.Split('.');
  7397. if (cavitySNs != null && cavitySNs.Length >= 1)
  7398. partNo = cavitySNs[0];
  7399. #endregion 查询载具上的产品信息
  7400. partNos.Add(partNo);
  7401. }
  7402. }
  7403. // 统一上传
  7404. stopwatch2.Start();
  7405. List<int> results = new List<int>();
  7406. for (int i = 0; i < partNos.Count; i++)
  7407. {
  7408. string index = (i + 1).ToString(); // 弹夹穴号
  7409. if (string.IsNullOrEmpty(partNos[i]))
  7410. results.Add(1);
  7411. else
  7412. {
  7413. List<TestItem> items1 = new List<TestItem>();
  7414. items1.Add(new TestItem()
  7415. {
  7416. Parameter_name = "弹夹码",
  7417. Parameter_value = sn,
  7418. Parameter_unit = ""
  7419. });
  7420. items1.Add(new TestItem()
  7421. {
  7422. Parameter_name = "弹夹穴号",
  7423. Parameter_value = index,
  7424. Parameter_unit = ""
  7425. });
  7426. items1.Add(new TestItem()
  7427. {
  7428. Parameter_name = "载具码",
  7429. Parameter_value = vehicleCodes[i],
  7430. Parameter_unit = ""
  7431. });
  7432. items1.Add(new TestItem()
  7433. {
  7434. Parameter_name = "载具穴号",
  7435. Parameter_value = "1",
  7436. Parameter_unit = ""
  7437. });
  7438. items1.Add(new TestItem()
  7439. {
  7440. Parameter_name = "产品结果",
  7441. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7442. Parameter_unit = ""
  7443. });
  7444. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7445. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7446. results.Add(result1);
  7447. }
  7448. }
  7449. short result = 0;
  7450. if (results.All(a => a == 1))
  7451. result = 1;
  7452. else if (results.Contains(3))
  7453. result = 3;
  7454. else if (results.Contains(2))
  7455. result = 2;
  7456. else if (results.Contains(4))
  7457. result = 4;
  7458. else
  7459. result = 4;
  7460. stopwatch2.Stop();
  7461. #region 存储绑定数据到 边线MES系统中
  7462. if (result == 1)
  7463. {
  7464. string data = string.Join(".", vehicleCodes);
  7465. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7466. if (resultMesR != 0)
  7467. {
  7468. result = 4;
  7469. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7470. }
  7471. }
  7472. #endregion 存储绑定数据到 边线MES系统中
  7473. // MES_Flag 为4MES报错
  7474. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7475. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7476. writeToPLC_Flag.Name = "d1MES_FLAG";
  7477. writeToPLC_Flag.Adress = 2065;
  7478. writeToPLC_Flag.Value = result;
  7479. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7480. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7481. }
  7482. catch (Exception ex)
  7483. {
  7484. stopwatch2.Restart();
  7485. // MES_Flag 为4上位机报错
  7486. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7487. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7488. writeToPLC_Flag.Name = "d1MES_FLAG";
  7489. writeToPLC_Flag.Adress = 2065;
  7490. writeToPLC_Flag.Value = (short)4;
  7491. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7492. stopwatch2.Stop();
  7493. string str = ex.StackTrace;
  7494. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7495. }
  7496. stopwatch1.Stop();
  7497. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7498. }
  7499. /// <summary>
  7500. /// [S4] 取放桁架 - S4_1节拍接口
  7501. /// </summary>
  7502. /// <param name="plcNo">PLC编号</param>
  7503. /// <param name="stationNameStr">工站全称</param>
  7504. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7505. {
  7506. Stopwatch stopwatch1 = new Stopwatch();
  7507. Stopwatch stopwatch2 = new Stopwatch();
  7508. string resultStr = string.Empty;
  7509. try
  7510. {
  7511. stopwatch1.Start();
  7512. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7513. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7514. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7515. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7516. if (!actionBool)
  7517. {
  7518. stopwatch2.Start();
  7519. // MES_Flag
  7520. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7521. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7522. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7523. writeToPLC_Flag1.Adress = 2398;
  7524. writeToPLC_Flag1.Value = (short)4;
  7525. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7526. stopwatch2.Stop();
  7527. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7528. return;
  7529. }
  7530. string d1OEEPartNo = string.Empty; // 物料码
  7531. if (string.IsNullOrEmpty(d1OEEProductSN))
  7532. {
  7533. stopwatch2.Start();
  7534. // MES_Flag
  7535. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7536. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7537. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7538. writeToPLC_Flag1.Adress = 2398;
  7539. writeToPLC_Flag1.Value = (short)1;
  7540. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7541. stopwatch2.Stop();
  7542. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7543. return;
  7544. }
  7545. else
  7546. { // 查产品SN ZS
  7547. d1OEEPartNo = "Test";
  7548. }
  7549. short d1OEEMES_FLAG = 0;
  7550. // 上传OEE
  7551. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7552. d1OEEMES_FLAG = result.Item1;
  7553. resultStr = result.Item2;
  7554. stopwatch2.Start();
  7555. // MES_Flag
  7556. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7557. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7558. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7559. writeToPLC_Flag.Adress = 2398;
  7560. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7561. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7562. stopwatch2.Stop();
  7563. }
  7564. catch (Exception ex)
  7565. {
  7566. string str = ex.StackTrace;
  7567. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7568. // MES_Flag
  7569. stopwatch2.Start();
  7570. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7571. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7572. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7573. writeToPLC_Flag.Adress = 2398;
  7574. writeToPLC_Flag.Value = (short)4;
  7575. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7576. stopwatch2.Stop();
  7577. }
  7578. stopwatch1.Stop();
  7579. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7580. }
  7581. /// <summary>
  7582. /// [S4] 取放桁架 - S4_2桁架
  7583. /// </summary>
  7584. /// <param name="plcNo">PLC编号</param>
  7585. /// <param name="stationNameStr">工站全称</param>
  7586. private void S4_2桁架(int plcNo, string stationNameStr)
  7587. {
  7588. Stopwatch stopwatch1 = new Stopwatch();
  7589. Stopwatch stopwatch2 = new Stopwatch();
  7590. try
  7591. {
  7592. stopwatch1.Start();
  7593. // ZS 弹夹扫码
  7594. string d2BulletclipCode = " "; // 扫到的码
  7595. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7596. short d2BulletclipScanCode = 2;
  7597. stopwatch2.Start();
  7598. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7599. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7600. //// MES_Flag
  7601. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7602. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7603. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7604. writeToPLC_Flag.Adress = 2430;
  7605. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7606. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7607. {
  7608. Name = "d2BulletclipCode",
  7609. Adress = 2432,
  7610. ValueType = PLCValueType.String,
  7611. ValueTypeStrLength = 20,
  7612. Value = d2BulletclipCode
  7613. });
  7614. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7615. {
  7616. Name = "d2BulletclipStates",
  7617. Adress = 2431,
  7618. ValueType = PLCValueType.Short,
  7619. Value = d2BulletclipStates
  7620. });
  7621. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7622. stopwatch2.Stop();
  7623. }
  7624. catch (Exception ex)
  7625. {
  7626. string str = ex.StackTrace;
  7627. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7628. stopwatch2.Start();
  7629. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7630. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7631. // MES_Flag
  7632. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7633. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7634. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7635. writeToPLC_Flag.Adress = 2430;
  7636. writeToPLC_Flag.Value = (short)6;
  7637. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7638. {
  7639. Name = "d2BulletclipCode",
  7640. Adress = 2432,
  7641. ValueType = PLCValueType.String,
  7642. ValueTypeStrLength = 20,
  7643. Value = " "
  7644. });
  7645. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7646. {
  7647. Name = "d2BulletclipStates",
  7648. Adress = 2431,
  7649. ValueType = PLCValueType.Short,
  7650. Value = (short)0
  7651. });
  7652. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7653. stopwatch2.Stop();
  7654. }
  7655. stopwatch1.Stop();
  7656. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7657. }
  7658. // 上次采集到的SN
  7659. //private string sn_S4_3进站接口 = string.Empty;
  7660. /// <summary>
  7661. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7662. /// </summary>
  7663. private void S4_3进站接口(int plcNo, string stationNameStr)
  7664. {
  7665. Stopwatch stopwatch1 = new Stopwatch();
  7666. Stopwatch stopwatch2 = new Stopwatch();
  7667. try
  7668. {
  7669. stopwatch1.Start();
  7670. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7671. sn = sn.Replace("\0", "");
  7672. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7673. #region 查询15个载具码
  7674. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7675. string vehicleData = string.Empty;
  7676. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7677. if (string.IsNullOrEmpty(vehicleData))
  7678. vehicleData = "";
  7679. if (snResult != 0)
  7680. {
  7681. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7682. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7683. writeToPLC_Flag1.Adress = 2463;
  7684. writeToPLC_Flag1.Value = (short)4;
  7685. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7686. stopwatch1.Stop();
  7687. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7688. return;
  7689. }
  7690. string[] cavitySNs = vehicleData.Split('.');
  7691. if (cavitySNs != null && cavitySNs.Length > 0)
  7692. {
  7693. for (int i = 0; i < cavitySNs.Length; i++)
  7694. {
  7695. if (string.IsNullOrEmpty(cavitySNs[i]))
  7696. vehicleCodes.Add("");
  7697. else
  7698. vehicleCodes.Add(cavitySNs[i]);
  7699. }
  7700. }
  7701. #endregion 查询15个载具码
  7702. #region 查询15个产品SN
  7703. List<string> portNos = new List<string>(); // 15个产品SN
  7704. foreach (string vehicleCode in vehicleCodes)
  7705. {
  7706. if (string.IsNullOrEmpty(vehicleCode))
  7707. portNos.Add("");
  7708. else
  7709. {
  7710. // 查询
  7711. string cavityData = string.Empty;
  7712. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7713. if (string.IsNullOrEmpty(cavityData))
  7714. cavityData = "";
  7715. if (snResult1 != 0)
  7716. {
  7717. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7718. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7719. writeToPLC_Flag1.Adress = 2463;
  7720. writeToPLC_Flag1.Value = (short)4;
  7721. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7722. stopwatch1.Stop();
  7723. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7724. return;
  7725. }
  7726. string[] partSNs = cavityData.Split('.');
  7727. if (partSNs != null && partSNs.Length >= 1)
  7728. portNos.Add(partSNs[0]);
  7729. else
  7730. portNos.Add("");
  7731. }
  7732. }
  7733. #endregion 查询15个产品SN
  7734. // 调用MES进站(最多15个)
  7735. stopwatch2.Start();
  7736. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7737. for (int i = 0; i < vehicleCodes.Count; i++)
  7738. {
  7739. // 循环进站
  7740. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7741. {
  7742. // 产品SN(物料码)校验
  7743. string portNo = portNos[i];
  7744. List<TestItem> item = new List<TestItem>();
  7745. item.Add(new TestItem()
  7746. {
  7747. Parameter_name = "弹夹码",
  7748. Parameter_value = sn,
  7749. });
  7750. item.Add(new TestItem()
  7751. {
  7752. Parameter_name = "弹夹穴位",
  7753. Parameter_value = (i + 1).ToString(),
  7754. });
  7755. item.Add(new TestItem()
  7756. {
  7757. Parameter_name = "载具码",
  7758. Parameter_value = vehicleCodes[i],
  7759. });
  7760. item.Add(new TestItem()
  7761. {
  7762. Parameter_name = "载具穴号",
  7763. Parameter_value = "1",
  7764. });
  7765. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7766. }
  7767. }
  7768. stopwatch2.Stop();
  7769. short result = 0;
  7770. bool haveMesWarn = results.Contains(5);
  7771. bool havePCWarn = results.Contains(6);
  7772. if (haveMesWarn)
  7773. result = 2; // 5->2
  7774. else if (havePCWarn)
  7775. result = 6; // 6->4
  7776. else
  7777. result = 1;
  7778. // MES_Flag 为4MES报错
  7779. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7780. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7781. writeToPLC_Flag.Name = "d3MES_FLAG";
  7782. writeToPLC_Flag.Adress = 2463;
  7783. writeToPLC_Flag.Value = result;
  7784. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7785. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7786. }
  7787. catch (Exception ex)
  7788. {
  7789. stopwatch2.Stop();
  7790. // MES_Flag 为4上位机报错
  7791. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7792. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7793. writeToPLC_Flag.Name = "d3MES_FLAG";
  7794. writeToPLC_Flag.Adress = 2463;
  7795. writeToPLC_Flag.Value = (short)4;
  7796. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7797. string str = ex.StackTrace;
  7798. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7799. }
  7800. stopwatch1.Stop();
  7801. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7802. }
  7803. // 上次采集到的SN
  7804. //private string sn_S4_3出站接口 = string.Empty;
  7805. /// <summary>
  7806. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7807. /// </summary>
  7808. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7809. {
  7810. Stopwatch stopwatch1 = new Stopwatch();
  7811. Stopwatch stopwatch2 = new Stopwatch();
  7812. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7813. string stationNameStr = stationCode + stationName;
  7814. string processItem = stationName; // 测试项目
  7815. try
  7816. {
  7817. stopwatch1.Start();
  7818. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7819. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7820. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7821. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7822. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7823. sn = sn.Replace("\0", "");
  7824. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7825. bool isPass = d3Result == 1; // 产品结果 bool
  7826. #region 查询15个载具码
  7827. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7828. string vehicleData = string.Empty;
  7829. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7830. if (string.IsNullOrEmpty(vehicleData))
  7831. vehicleData = "";
  7832. if (snResult1 != 0)
  7833. {
  7834. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7835. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7836. writeToPLC_Flag1.Adress = 2463;
  7837. writeToPLC_Flag1.Value = (short)4;
  7838. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7839. stopwatch1.Stop();
  7840. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7841. return;
  7842. }
  7843. string[] cavitySNs = vehicleData.Split('.');
  7844. if (cavitySNs != null && cavitySNs.Length > 0)
  7845. {
  7846. for (int i = 0; i < cavitySNs.Length; i++)
  7847. {
  7848. if (string.IsNullOrEmpty(cavitySNs[i]))
  7849. vehicleCodes.Add("");
  7850. else
  7851. vehicleCodes.Add(cavitySNs[i]);
  7852. }
  7853. }
  7854. #endregion 查询15个载具码
  7855. // 统一查 产品SN列表
  7856. List<string> partNos = new List<string>();
  7857. foreach (string vehicleCode in vehicleCodes)
  7858. {
  7859. if (string.IsNullOrEmpty(vehicleCode))
  7860. partNos.Add("");
  7861. else
  7862. {
  7863. string partNo = "";
  7864. #region 查询载具上的产品信息
  7865. string cavityData = string.Empty;
  7866. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7867. if (string.IsNullOrEmpty(cavityData))
  7868. cavityData = "";
  7869. if (snResult != 0)
  7870. {
  7871. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7872. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7873. writeToPLC_Flag1.Adress = 2463;
  7874. writeToPLC_Flag1.Value = (short)4;
  7875. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7876. stopwatch1.Stop();
  7877. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7878. return;
  7879. }
  7880. string[] partSNs = cavityData.Split('.');
  7881. if (partSNs != null && partSNs.Length >= 1)
  7882. partNo = partSNs[0];
  7883. #endregion 查询载具上的产品信息
  7884. partNos.Add(partNo);
  7885. }
  7886. }
  7887. // 统一上传 - 调用MES出站
  7888. stopwatch2.Start();
  7889. List<int> results = new List<int>();
  7890. for (int i = 0; i < partNos.Count; i++)
  7891. {
  7892. string index = (i + 1).ToString(); // 弹夹穴号
  7893. if (string.IsNullOrEmpty(partNos[i]))
  7894. results.Add(1);
  7895. else
  7896. {
  7897. List<TestItem> items1 = new List<TestItem>();
  7898. items1.Add(new TestItem()
  7899. {
  7900. Parameter_name = "弹夹码",
  7901. Parameter_value = sn,
  7902. Parameter_unit = ""
  7903. });
  7904. items1.Add(new TestItem()
  7905. {
  7906. Parameter_name = "弹夹穴号",
  7907. Parameter_value = index,
  7908. Parameter_unit = ""
  7909. });
  7910. items1.Add(new TestItem()
  7911. {
  7912. Parameter_name = "载具码",
  7913. Parameter_value = vehicleCodes[i],
  7914. Parameter_unit = ""
  7915. });
  7916. items1.Add(new TestItem()
  7917. {
  7918. Parameter_name = "载具穴号",
  7919. Parameter_value = "1",
  7920. Parameter_unit = ""
  7921. });
  7922. items1.Add(new TestItem()
  7923. {
  7924. Parameter_name = "产品结果",
  7925. Parameter_value = d3Result == 1 ? "OK" : "NG",
  7926. Parameter_unit = ""
  7927. });
  7928. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7929. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  7930. results.Add(result1);
  7931. }
  7932. }
  7933. short result = 0;
  7934. if (results.All(a => a == 1))
  7935. result = 1;
  7936. else if (results.Contains(3))
  7937. result = 3;
  7938. else if (results.Contains(2))
  7939. result = 2;
  7940. else if (results.Contains(4))
  7941. result = 4;
  7942. else
  7943. result = 4;
  7944. stopwatch2.Stop();
  7945. // MES_Flag 为4MES报错
  7946. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7947. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7948. writeToPLC_Flag.Name = "d3MES_FLAG";
  7949. writeToPLC_Flag.Adress = 2463;
  7950. writeToPLC_Flag.Value = result;
  7951. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7952. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7953. }
  7954. catch (Exception ex)
  7955. {
  7956. stopwatch2.Restart();
  7957. // MES_Flag 为4上位机报错
  7958. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7959. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7960. writeToPLC_Flag.Name = "d3MES_FLAG";
  7961. writeToPLC_Flag.Adress = 2463;
  7962. writeToPLC_Flag.Value = (short)4;
  7963. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7964. string str = ex.StackTrace;
  7965. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7966. stopwatch2.Stop();
  7967. }
  7968. stopwatch1.Stop();
  7969. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7970. }
  7971. // 上次采集到的SN
  7972. //private string sn_S4_4进站接口 = string.Empty;
  7973. /// <summary>
  7974. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  7975. /// </summary>
  7976. private void S4_4进站接口(int plcNo, string stationNameStr)
  7977. {
  7978. Stopwatch stopwatch1 = new Stopwatch();
  7979. Stopwatch stopwatch2 = new Stopwatch();
  7980. try
  7981. {
  7982. stopwatch1.Start();
  7983. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  7984. sn = sn.Replace("\0", "");
  7985. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  7986. #region 查询15个载具码
  7987. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7988. string vehicleData = string.Empty;
  7989. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7990. if (string.IsNullOrEmpty(vehicleData))
  7991. vehicleData = "";
  7992. if (snResult != 0)
  7993. {
  7994. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7995. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7996. writeToPLC_Flag1.Adress = 2463;
  7997. writeToPLC_Flag1.Value = (short)4;
  7998. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7999. stopwatch1.Stop();
  8000. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8001. return;
  8002. }
  8003. string[] cavitySNs = vehicleData.Split('.');
  8004. if (cavitySNs != null && cavitySNs.Length > 0)
  8005. {
  8006. for (int i = 0; i < cavitySNs.Length; i++)
  8007. {
  8008. if (string.IsNullOrEmpty(cavitySNs[i]))
  8009. vehicleCodes.Add("");
  8010. else
  8011. vehicleCodes.Add(cavitySNs[i]);
  8012. }
  8013. }
  8014. #endregion 查询15个载具码
  8015. #region 查询15个产品SN
  8016. List<string> portNos = new List<string>(); // 15个产品SN
  8017. foreach (string vehicleCode in vehicleCodes)
  8018. {
  8019. if (string.IsNullOrEmpty(vehicleCode))
  8020. portNos.Add("");
  8021. else
  8022. {
  8023. // 查询
  8024. string cavityData = string.Empty;
  8025. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8026. if (string.IsNullOrEmpty(cavityData))
  8027. cavityData = "";
  8028. if (snResult1 != 0)
  8029. {
  8030. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8031. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8032. writeToPLC_Flag1.Adress = 2463;
  8033. writeToPLC_Flag1.Value = (short)4;
  8034. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8035. stopwatch1.Stop();
  8036. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8037. return;
  8038. }
  8039. string[] partSNs = cavityData.Split('.');
  8040. if (partSNs != null && partSNs.Length >= 1)
  8041. portNos.Add(partSNs[0]);
  8042. else
  8043. portNos.Add("");
  8044. }
  8045. }
  8046. #endregion 查询15个产品SN
  8047. // 调用MES进站(最多15个)
  8048. stopwatch2.Start();
  8049. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8050. for (int i = 0; i < vehicleCodes.Count; i++)
  8051. {
  8052. // 循环进站
  8053. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8054. {
  8055. // 产品SN(物料码)校验
  8056. string portNo = portNos[i];
  8057. List<TestItem> item = new List<TestItem>();
  8058. item.Add(new TestItem()
  8059. {
  8060. Parameter_name = "弹夹码",
  8061. Parameter_value = sn,
  8062. });
  8063. item.Add(new TestItem()
  8064. {
  8065. Parameter_name = "弹夹穴位",
  8066. Parameter_value = (i + 1).ToString(),
  8067. });
  8068. item.Add(new TestItem()
  8069. {
  8070. Parameter_name = "载具码",
  8071. Parameter_value = vehicleCodes[i],
  8072. });
  8073. item.Add(new TestItem()
  8074. {
  8075. Parameter_name = "载具穴号",
  8076. Parameter_value = "1",
  8077. });
  8078. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8079. }
  8080. }
  8081. stopwatch2.Stop();
  8082. short result = 0;
  8083. bool haveMesWarn = results.Contains(5);
  8084. bool havePCWarn = results.Contains(6);
  8085. if (haveMesWarn)
  8086. result = 2; // 5->2
  8087. else if (havePCWarn)
  8088. result = 6; // 6->4
  8089. else
  8090. result = 1;
  8091. // MES_Flag 为4MES报错
  8092. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8093. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8094. writeToPLC_Flag.Name = "d4MES_FLAG";
  8095. writeToPLC_Flag.Adress = 2496;
  8096. writeToPLC_Flag.Value = result;
  8097. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8098. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8099. }
  8100. catch (Exception ex)
  8101. {
  8102. stopwatch2.Stop();
  8103. // MES_Flag 为4上位机报错
  8104. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8105. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8106. writeToPLC_Flag.Name = "d4MES_FLAG";
  8107. writeToPLC_Flag.Adress = 2496;
  8108. writeToPLC_Flag.Value = (short)4;
  8109. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8110. string str = ex.StackTrace;
  8111. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8112. }
  8113. stopwatch1.Stop();
  8114. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8115. }
  8116. // 上次采集到的SN
  8117. //private string sn_S4_4出站接口 = string.Empty;
  8118. /// <summary>
  8119. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8120. /// </summary>
  8121. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8122. {
  8123. Stopwatch stopwatch1 = new Stopwatch();
  8124. Stopwatch stopwatch2 = new Stopwatch();
  8125. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8126. string stationNameStr = stationCode + stationName;
  8127. string processItem = stationName; // 测试项目
  8128. try
  8129. {
  8130. stopwatch1.Start();
  8131. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8132. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8133. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8134. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8135. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8136. sn = sn.Replace("\0", "");
  8137. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8138. bool isPass = d4Result == 1; // 产品结果 bool
  8139. #region 查询15个载具码
  8140. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8141. string vehicleData = string.Empty;
  8142. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8143. if (string.IsNullOrEmpty(vehicleData))
  8144. vehicleData = "";
  8145. if (snResult1 != 0)
  8146. {
  8147. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8148. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8149. writeToPLC_Flag1.Adress = 2496;
  8150. writeToPLC_Flag1.Value = (short)4;
  8151. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8152. stopwatch1.Stop();
  8153. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8154. return;
  8155. }
  8156. string[] cavitySNs = vehicleData.Split('.');
  8157. if (cavitySNs != null && cavitySNs.Length > 0)
  8158. {
  8159. for (int i = 0; i < cavitySNs.Length; i++)
  8160. {
  8161. if (string.IsNullOrEmpty(cavitySNs[i]))
  8162. vehicleCodes.Add("");
  8163. else
  8164. vehicleCodes.Add(cavitySNs[i]);
  8165. }
  8166. }
  8167. #endregion 查询15个载具码
  8168. // 统一查 产品SN列表
  8169. List<string> partNos = new List<string>();
  8170. foreach (string vehicleCode in vehicleCodes)
  8171. {
  8172. if (string.IsNullOrEmpty(vehicleCode))
  8173. partNos.Add("");
  8174. else
  8175. {
  8176. string partNo = "";
  8177. #region 查询载具上的产品信息
  8178. string cavityData = string.Empty;
  8179. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8180. if (string.IsNullOrEmpty(cavityData))
  8181. cavityData = "";
  8182. if (snResult != 0)
  8183. {
  8184. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8185. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8186. writeToPLC_Flag1.Adress = 2496;
  8187. writeToPLC_Flag1.Value = (short)4;
  8188. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8189. stopwatch1.Stop();
  8190. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8191. return;
  8192. }
  8193. string[] partSNs = cavityData.Split('.');
  8194. if (partSNs != null && partSNs.Length >= 1)
  8195. partNo = partSNs[0];
  8196. #endregion 查询载具上的产品信息
  8197. partNos.Add(partNo);
  8198. }
  8199. }
  8200. // 调用MES出站
  8201. stopwatch2.Start();
  8202. // 统一上传
  8203. List<int> results = new List<int>();
  8204. for (int i = 0; i < partNos.Count; i++)
  8205. {
  8206. string index = (i + 1).ToString(); // 弹夹穴号
  8207. if (string.IsNullOrEmpty(partNos[i]))
  8208. results.Add(1);
  8209. else
  8210. {
  8211. List<TestItem> items1 = new List<TestItem>();
  8212. items1.Add(new TestItem()
  8213. {
  8214. Parameter_name = "弹夹码",
  8215. Parameter_value = sn,
  8216. Parameter_unit = ""
  8217. });
  8218. items1.Add(new TestItem()
  8219. {
  8220. Parameter_name = "弹夹穴号",
  8221. Parameter_value = index,
  8222. Parameter_unit = ""
  8223. });
  8224. items1.Add(new TestItem()
  8225. {
  8226. Parameter_name = "载具码",
  8227. Parameter_value = vehicleCodes[i],
  8228. Parameter_unit = ""
  8229. });
  8230. items1.Add(new TestItem()
  8231. {
  8232. Parameter_name = "载具穴号",
  8233. Parameter_value = "1",
  8234. Parameter_unit = ""
  8235. });
  8236. items1.Add(new TestItem()
  8237. {
  8238. Parameter_name = "产品结果",
  8239. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8240. Parameter_unit = ""
  8241. });
  8242. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8243. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8244. results.Add(result1);
  8245. }
  8246. }
  8247. short result = 0;
  8248. if (results.All(a => a == 1))
  8249. result = 1;
  8250. else if (results.Contains(3))
  8251. result = 3;
  8252. else if (results.Contains(2))
  8253. result = 2;
  8254. else if (results.Contains(4))
  8255. result = 4;
  8256. else
  8257. result = 4;
  8258. stopwatch2.Stop();
  8259. // MES_Flag 为4MES报错
  8260. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8261. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8262. writeToPLC_Flag.Name = "d4MES_FLAG";
  8263. writeToPLC_Flag.Adress = 2496;
  8264. writeToPLC_Flag.Value = result;
  8265. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8266. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8267. }
  8268. catch (Exception ex)
  8269. {
  8270. stopwatch2.Restart();
  8271. // MES_Flag 为4上位机报错
  8272. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8273. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8274. writeToPLC_Flag.Name = "d4MES_FLAG";
  8275. writeToPLC_Flag.Adress = 2496;
  8276. writeToPLC_Flag.Value = (short)4;
  8277. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8278. string str = ex.StackTrace;
  8279. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8280. stopwatch2.Stop();
  8281. }
  8282. stopwatch1.Stop();
  8283. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8284. }
  8285. /// <summary>
  8286. /// [S4] 取放桁架 - S4_5弹夹扫码
  8287. /// </summary>
  8288. /// <param name="plcNo">PLC编号</param>
  8289. /// <param name="stationNameStr">工站全称</param>
  8290. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8291. {
  8292. Stopwatch stopwatch1 = new Stopwatch();
  8293. Stopwatch stopwatch2 = new Stopwatch();
  8294. try
  8295. {
  8296. stopwatch1.Start();
  8297. // ZS 弹夹扫码
  8298. string d5BulletclipCode = " "; // 扫到的码
  8299. short d5BulletclipScanCode = 2;
  8300. stopwatch2.Start();
  8301. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8302. //// MES_Flag
  8303. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8304. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8305. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8306. writeToPLC_Flag.Adress = 2528;
  8307. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8308. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8309. {
  8310. Name = "d5BulletclipCode",
  8311. Adress = 2529,
  8312. ValueType = PLCValueType.String,
  8313. ValueTypeStrLength = 20,
  8314. Value = d5BulletclipCode
  8315. });
  8316. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8317. stopwatch2.Stop();
  8318. }
  8319. catch (Exception ex)
  8320. {
  8321. string str = ex.StackTrace;
  8322. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8323. stopwatch2.Start();
  8324. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8325. //// MES_Flag
  8326. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8327. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8328. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8329. writeToPLC_Flag.Adress = 2528;
  8330. writeToPLC_Flag.Value = (short)6;
  8331. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8332. {
  8333. Name = "d5BulletclipCode",
  8334. Adress = 2529,
  8335. ValueType = PLCValueType.String,
  8336. ValueTypeStrLength = 20,
  8337. Value = " "
  8338. });
  8339. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8340. stopwatch2.Stop();
  8341. }
  8342. stopwatch1.Stop();
  8343. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8344. }
  8345. /// <summary>
  8346. /// [S4] 取放桁架 - S4_5载具扫码
  8347. /// </summary>
  8348. /// <param name="plcNo">PLC编号</param>
  8349. /// <param name="stationNameStr">工站全称</param>
  8350. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8351. {
  8352. Stopwatch stopwatch1 = new Stopwatch();
  8353. Stopwatch stopwatch2 = new Stopwatch();
  8354. try
  8355. {
  8356. stopwatch1.Start();
  8357. // ZS 载具扫码
  8358. string d5VehicleCode = " "; // 扫到的码
  8359. short d5VehicleScanCode = 2;
  8360. #region 进站
  8361. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8362. {
  8363. // 查产品SN
  8364. #region 查询载具上的产品信息
  8365. string cavityData = string.Empty;
  8366. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8367. if (string.IsNullOrEmpty(cavityData))
  8368. cavityData = "";
  8369. if (snResult != 0)
  8370. {
  8371. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8372. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8373. writeToPLC_Flag1.Adress = 2559;
  8374. writeToPLC_Flag1.Value = (short)6;
  8375. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8376. {
  8377. Name = "d5VehicleCode",
  8378. Adress = 2560,
  8379. ValueType = PLCValueType.String,
  8380. ValueTypeStrLength = 20,
  8381. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8382. });
  8383. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8384. stopwatch1.Stop();
  8385. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8386. return;
  8387. }
  8388. string[] cavitySNs = cavityData.Split('.');
  8389. string partNo = "";
  8390. if (cavitySNs != null && cavitySNs.Length >= 1)
  8391. {
  8392. partNo = cavitySNs[0];
  8393. }
  8394. #endregion 查询载具上的产品信息
  8395. List<TestItem> item = new List<TestItem>();
  8396. item.Add(new TestItem()
  8397. {
  8398. Parameter_name = "载具码",
  8399. Parameter_value = d5VehicleCode,
  8400. });
  8401. item.Add(new TestItem()
  8402. {
  8403. Parameter_name = "载具穴号",
  8404. Parameter_value = "1",
  8405. });
  8406. stopwatch2.Start();
  8407. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8408. stopwatch2.Stop();
  8409. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8410. }
  8411. #endregion 进站
  8412. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8413. //// MES_Flag
  8414. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8415. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8416. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8417. writeToPLC_Flag.Adress = 2559;
  8418. writeToPLC_Flag.Value = d5VehicleScanCode;
  8419. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8420. {
  8421. Name = "d5VehicleCode",
  8422. Adress = 2560,
  8423. ValueType = PLCValueType.String,
  8424. ValueTypeStrLength = 20,
  8425. Value = d5VehicleCode
  8426. });
  8427. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8428. }
  8429. catch (Exception ex)
  8430. {
  8431. string str = ex.StackTrace;
  8432. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8433. stopwatch2.Start();
  8434. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8435. //// MES_Flag
  8436. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8437. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8438. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8439. writeToPLC_Flag.Adress = 2559;
  8440. writeToPLC_Flag.Value = (short)6;
  8441. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8442. {
  8443. Name = "d5VehicleCode",
  8444. Adress = 2560,
  8445. ValueType = PLCValueType.String,
  8446. ValueTypeStrLength = 20,
  8447. Value = " "
  8448. });
  8449. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8450. stopwatch2.Stop();
  8451. }
  8452. stopwatch1.Stop();
  8453. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8454. }
  8455. // 上次采集到的SN
  8456. //private string sn_S4_5出站接口 = string.Empty;
  8457. /// <summary>
  8458. /// [S4] 取放桁架 - S4_5出站接口
  8459. /// </summary>
  8460. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8461. {
  8462. Stopwatch stopwatch1 = new Stopwatch();
  8463. Stopwatch stopwatch2 = new Stopwatch();
  8464. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8465. string stationNameStr = stationCode + stationName;
  8466. string processItem = stationName; // 测试项目
  8467. try
  8468. {
  8469. stopwatch1.Start();
  8470. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8471. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8472. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8473. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8474. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8475. sn = sn.Replace("\0", "");
  8476. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8477. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8478. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8479. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8480. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8481. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8482. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8483. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8484. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8485. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8486. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8487. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8488. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8489. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8490. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8491. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8492. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8493. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8494. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8495. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8496. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8497. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8498. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8499. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8500. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8501. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8502. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8503. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8504. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8505. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8506. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8507. bool pass = d5Result == 1;
  8508. // 存 载具SN列表
  8509. List<string> vehicleCodes = new List<string>()
  8510. {
  8511. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8512. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8513. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8514. };
  8515. // 统一查 产品SN列表
  8516. List<string> partNos = new List<string>();
  8517. foreach (string vehicleCode in vehicleCodes)
  8518. {
  8519. if (string.IsNullOrEmpty(vehicleCode))
  8520. partNos.Add("");
  8521. else
  8522. {
  8523. string partNo = "";
  8524. #region 查询载具上的产品信息
  8525. string cavityData = string.Empty;
  8526. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8527. if (string.IsNullOrEmpty(cavityData))
  8528. cavityData = "";
  8529. if (snResult != 0)
  8530. {
  8531. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8532. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8533. writeToPLC_Flag1.Adress = 2591;
  8534. writeToPLC_Flag1.Value = (short)4;
  8535. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8536. stopwatch1.Stop();
  8537. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8538. return;
  8539. }
  8540. string[] cavitySNs = cavityData.Split('.');
  8541. if (cavitySNs != null && cavitySNs.Length >= 1)
  8542. partNo = cavitySNs[0];
  8543. #endregion 查询载具上的产品信息
  8544. partNos.Add(partNo);
  8545. }
  8546. }
  8547. // 统一上传
  8548. stopwatch2.Start();
  8549. List<int> results = new List<int>();
  8550. for (int i = 0; i < partNos.Count; i++)
  8551. {
  8552. string index = (i + 1).ToString(); // 弹夹穴号
  8553. if (string.IsNullOrEmpty(partNos[i]))
  8554. results.Add(1);
  8555. else
  8556. {
  8557. List<TestItem> items1 = new List<TestItem>();
  8558. items1.Add(new TestItem()
  8559. {
  8560. Parameter_name = "弹夹码",
  8561. Parameter_value = sn,
  8562. Parameter_unit = ""
  8563. });
  8564. items1.Add(new TestItem()
  8565. {
  8566. Parameter_name = "弹夹穴号",
  8567. Parameter_value = index,
  8568. Parameter_unit = ""
  8569. });
  8570. items1.Add(new TestItem()
  8571. {
  8572. Parameter_name = "载具码",
  8573. Parameter_value = vehicleCodes[i],
  8574. Parameter_unit = ""
  8575. });
  8576. items1.Add(new TestItem()
  8577. {
  8578. Parameter_name = "载具穴号",
  8579. Parameter_value = "1",
  8580. Parameter_unit = ""
  8581. });
  8582. items1.Add(new TestItem()
  8583. {
  8584. Parameter_name = "产品结果",
  8585. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8586. Parameter_unit = ""
  8587. });
  8588. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8589. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8590. results.Add(result1);
  8591. }
  8592. }
  8593. short result = 0;
  8594. if (results.All(a => a == 1))
  8595. result = 1;
  8596. else if (results.Contains(3))
  8597. result = 3;
  8598. else if (results.Contains(2))
  8599. result = 2;
  8600. else if (results.Contains(4))
  8601. result = 4;
  8602. else
  8603. result = 4;
  8604. stopwatch2.Stop();
  8605. #region 存储绑定数据到 边线MES系统中
  8606. if (result == 1)
  8607. {
  8608. // 删除绑定信息
  8609. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8610. if (resultMesR != 0)
  8611. {
  8612. result = 4;
  8613. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8614. }
  8615. }
  8616. #endregion 存储绑定数据到 边线MES系统中
  8617. // MES_Flag 为4MES报错
  8618. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8619. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8620. writeToPLC_Flag.Name = "d5MES_FLAG";
  8621. writeToPLC_Flag.Adress = 2591;
  8622. writeToPLC_Flag.Value = result;
  8623. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8624. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8625. }
  8626. catch (Exception ex)
  8627. {
  8628. stopwatch2.Restart();
  8629. // MES_Flag 为4上位机报错
  8630. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8631. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8632. writeToPLC_Flag.Name = "d5MES_FLAG";
  8633. writeToPLC_Flag.Adress = 2591;
  8634. writeToPLC_Flag.Value = (short)4;
  8635. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8636. stopwatch2.Stop();
  8637. string str = ex.StackTrace;
  8638. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8639. }
  8640. stopwatch1.Stop();
  8641. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8642. }
  8643. /// <summary>
  8644. /// [S4] 取放桁架 - S4_5节拍接口
  8645. /// </summary>
  8646. /// <param name="plcNo">PLC编号</param>
  8647. /// <param name="stationNameStr">工站全称</param>
  8648. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8649. {
  8650. Stopwatch stopwatch1 = new Stopwatch();
  8651. Stopwatch stopwatch2 = new Stopwatch();
  8652. string resultStr = string.Empty;
  8653. try
  8654. {
  8655. stopwatch1.Start();
  8656. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8657. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8658. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8659. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8660. if (!actionBool)
  8661. {
  8662. stopwatch2.Start();
  8663. // MES_Flag
  8664. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8665. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8666. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8667. writeToPLC_Flag1.Adress = 2924;
  8668. writeToPLC_Flag1.Value = (short)4;
  8669. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8670. stopwatch2.Stop();
  8671. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8672. return;
  8673. }
  8674. string d5OEEPartNo = string.Empty; // 物料码
  8675. if (string.IsNullOrEmpty(d5OEEProductSN))
  8676. {
  8677. stopwatch2.Start();
  8678. // MES_Flag
  8679. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8680. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8681. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8682. writeToPLC_Flag1.Adress = 2924;
  8683. writeToPLC_Flag1.Value = (short)1;
  8684. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8685. stopwatch2.Stop();
  8686. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8687. return;
  8688. }
  8689. else
  8690. { // 查产品SN
  8691. d5OEEPartNo = "Test"; // ZS
  8692. }
  8693. short d5OEEMES_FLAG = 0;
  8694. // 上传OEE
  8695. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8696. d5OEEMES_FLAG = result.Item1;
  8697. resultStr = result.Item2;
  8698. stopwatch2.Start();
  8699. // MES_Flag
  8700. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8701. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8702. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8703. writeToPLC_Flag.Adress = 2924;
  8704. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8705. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8706. stopwatch2.Stop();
  8707. }
  8708. catch (Exception ex)
  8709. {
  8710. string str = ex.StackTrace;
  8711. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8712. // MES_Flag
  8713. stopwatch2.Start();
  8714. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8715. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8716. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8717. writeToPLC_Flag.Adress = 2924;
  8718. writeToPLC_Flag.Value = (short)4;
  8719. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8720. stopwatch2.Stop();
  8721. }
  8722. stopwatch1.Stop();
  8723. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8724. }
  8725. #endregion [S4] 取放桁架
  8726. #endregion PLC4 刘果段
  8727. #region PLC5 张超凡
  8728. #region [S5] Tray盘下料装备
  8729. /// <summary>
  8730. /// S5工位的数据- 触发信号上次的值
  8731. /// </summary>
  8732. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8733. /// <summary>
  8734. /// S5工位的数据(含触发信号)
  8735. /// </summary>
  8736. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8737. /// <summary>
  8738. /// S5工位的数据- 回写点位
  8739. /// </summary>
  8740. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8741. /// <summary>
  8742. /// [S5] Tray盘下料装备
  8743. /// </summary>
  8744. /// <param name="plcNo">PLC编号</param>
  8745. //private void ReadStation_S5(int plcNo)
  8746. //{
  8747. // // [S1] Tray盘上料装备
  8748. // // [S2] FCT
  8749. // // [S3] 值板机
  8750. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8751. // // [S5] Tray盘下料装备
  8752. // /// 上位机心跳
  8753. // /// 获取设备报警数据与状态信息
  8754. // string stationCode = "[S5]";
  8755. // string stationName = "Tray盘下料装备";
  8756. // string stationNameStr = stationCode + stationName;
  8757. // #region 创建字典
  8758. // // 触发信号字典 赋值
  8759. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8760. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8761. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8762. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8763. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8764. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8765. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8766. // // PLC数据字典 赋值
  8767. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8768. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8769. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8770. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8771. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8772. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8773. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8774. // s5PLCData.Add("e1Result", 0); // 产品结果
  8775. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8776. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8777. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8778. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8779. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8780. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8781. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8782. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8783. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8784. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8785. // #endregion 创建字典
  8786. // while (IsRun)
  8787. // {
  8788. // try
  8789. // {
  8790. // if (!GlobalContext._IsCon_Funs5)
  8791. // {
  8792. // UpdatePLCMonitor(1, plcNo, 0);
  8793. // continue;
  8794. // }
  8795. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8796. // {
  8797. // Stopwatch stopwatch1 = new Stopwatch();
  8798. // Stopwatch stopwatch2 = new Stopwatch();
  8799. // stopwatch1.Start();
  8800. // stopwatch2.Start();
  8801. // #region 一次性读取所有数据
  8802. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8803. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8804. // int[] datas = data1.Concat(data2).ToArray();
  8805. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8806. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8807. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8808. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8809. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8810. // s5PLCData["e1MES_FLAG"] = datas[35];
  8811. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8812. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8813. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8814. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8815. // s5PLCData["e1Result"] = datas[76];
  8816. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8817. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8818. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8819. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8820. // s5PLCData["e1OEEType"] = datas[109];
  8821. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8822. // s5PLCData["e1AGVUpStart"] = datas[121];
  8823. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8824. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8825. // s5PLCData["e1AGVDownStart"] = datas[134];
  8826. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8827. // #endregion 一次性读取所有数据
  8828. // stopwatch2.Stop();
  8829. // #region 回写操作,写后清空flag
  8830. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8831. // #endregion 回写操作,写后清空flag
  8832. // #region 进站校验
  8833. // try
  8834. // {
  8835. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8836. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8837. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  8838. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  8839. // {
  8840. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  8841. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8842. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  8843. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8844. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  8845. // }
  8846. // }
  8847. // catch (Exception ex)
  8848. // {
  8849. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8850. // string str = ex.StackTrace;
  8851. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8852. // }
  8853. // #endregion 进站校验
  8854. // #region 出站接口
  8855. // try
  8856. // {
  8857. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  8858. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  8859. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  8860. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  8861. // {
  8862. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  8863. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8864. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  8865. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  8866. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  8867. // }
  8868. // }
  8869. // catch (Exception ex)
  8870. // {
  8871. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  8872. // string str = ex.StackTrace;
  8873. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8874. // }
  8875. // #endregion 出站接口
  8876. // #region 节拍接口
  8877. // try
  8878. // {
  8879. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  8880. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  8881. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  8882. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  8883. // {
  8884. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  8885. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8886. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  8887. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  8888. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  8889. // }
  8890. // }
  8891. // catch (Exception ex)
  8892. // {
  8893. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  8894. // string str = ex.StackTrace;
  8895. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8896. // }
  8897. // #endregion 节拍接口
  8898. // #region AGV上料
  8899. // // AGV上料叫AGV信号
  8900. // try
  8901. // {
  8902. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  8903. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  8904. // if (e1AGVUpCall != e1AGVUpCallOld)
  8905. // {
  8906. // if (e1AGVUpCall == 1) // 0->1
  8907. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  8908. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  8909. // }
  8910. // }
  8911. // catch (Exception ex)
  8912. // {
  8913. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  8914. // string str = ex.StackTrace;
  8915. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8916. // }
  8917. // // AGV上料完成信号
  8918. // try
  8919. // {
  8920. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  8921. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  8922. // if (e1AGVUpEnd != e1AGVUpEndOld)
  8923. // {
  8924. // if (e1AGVUpEnd == 1) // 0->1
  8925. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  8926. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  8927. // }
  8928. // }
  8929. // catch (Exception ex)
  8930. // {
  8931. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  8932. // string str = ex.StackTrace;
  8933. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8934. // }
  8935. // #endregion AGV上料
  8936. // #region AGV下料
  8937. // // AGV下料叫agv信号
  8938. // try
  8939. // {
  8940. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  8941. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  8942. // if (e1AGVDownCall != e1AGVDownCallOld)
  8943. // {
  8944. // if (e1AGVDownCall == 1) // 0->1
  8945. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  8946. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  8947. // }
  8948. // }
  8949. // catch (Exception ex)
  8950. // {
  8951. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  8952. // string str = ex.StackTrace;
  8953. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8954. // }
  8955. // // AGV下料完成信号
  8956. // try
  8957. // {
  8958. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  8959. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  8960. // if (e1AGVDownEnd != e1AGVDownEndOld)
  8961. // {
  8962. // if (e1AGVDownEnd == 1) // 0->1
  8963. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  8964. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  8965. // }
  8966. // }
  8967. // catch (Exception ex)
  8968. // {
  8969. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  8970. // string str = ex.StackTrace;
  8971. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8972. // }
  8973. // #endregion AGV下料
  8974. // #region 心跳
  8975. // try
  8976. // {
  8977. // short states = 0;
  8978. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8979. // }
  8980. // catch (Exception ex)
  8981. // {
  8982. // string str = ex.StackTrace;
  8983. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8984. // }
  8985. // #endregion 心跳
  8986. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8987. // stopwatch1.Stop();
  8988. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8989. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8990. // }
  8991. // else
  8992. // {
  8993. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8994. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8995. // Funs[plcNo].Connect();
  8996. // }
  8997. // }
  8998. // catch (Exception ex)
  8999. // {
  9000. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9001. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9002. // Funs[plcNo].ReConnect();
  9003. // }
  9004. // Thread.Sleep(IntervalReadPLC);
  9005. // }
  9006. //}
  9007. /// <summary>
  9008. /// [S5] Tray盘下料装备 - 进站校验
  9009. /// </summary>
  9010. /// <param name="plcNo">PLC编号</param>
  9011. /// <param name="stationNameStr">工站全称</param>
  9012. private void S5进站校验(int plcNo, string stationNameStr)
  9013. {
  9014. Stopwatch stopwatch1 = new Stopwatch();
  9015. Stopwatch stopwatch2 = new Stopwatch();
  9016. try
  9017. {
  9018. stopwatch1.Start();
  9019. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9020. sn = sn.Replace("\0", "");
  9021. // 获取产品SN By 载具码
  9022. #region 查询载具上的产品信息
  9023. string cavityData = string.Empty;
  9024. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9025. if (string.IsNullOrEmpty(cavityData))
  9026. cavityData = "";
  9027. if (snResult != 0)
  9028. {
  9029. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9030. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9031. writeToPLC_Flag1.Adress = 2003;
  9032. writeToPLC_Flag1.Value = (short)6;
  9033. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9034. stopwatch1.Stop();
  9035. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9036. return;
  9037. }
  9038. string[] cavitySNs = cavityData.Split('.');
  9039. string partNo = string.Empty;
  9040. if (cavitySNs != null && cavitySNs.Length >= 1)
  9041. partNo = cavitySNs[0];
  9042. #endregion 查询载具上的产品信息
  9043. // 产品SN(物料码)校验
  9044. List<TestItem> item = new List<TestItem>();
  9045. item.Add(new TestItem()
  9046. {
  9047. Parameter_name = "载具码",
  9048. Parameter_value = sn,
  9049. });
  9050. item.Add(new TestItem()
  9051. {
  9052. Parameter_name = "载具穴号",
  9053. Parameter_value = "1",
  9054. });
  9055. stopwatch2.Start();
  9056. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9057. stopwatch2.Stop();
  9058. short e1MES_FLAG_Check = (short)result;
  9059. // MES_Flag
  9060. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9061. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9062. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9063. writeToPLC_Flag.Adress = 2003;
  9064. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9065. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9066. }
  9067. catch (Exception ex)
  9068. {
  9069. string str = ex.StackTrace;
  9070. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9071. // MES_Flag
  9072. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9073. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9074. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9075. writeToPLC_Flag.Adress = 2003;
  9076. writeToPLC_Flag.Value = (short)6;
  9077. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9078. }
  9079. stopwatch1.Stop();
  9080. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9081. }
  9082. /// <summary>
  9083. /// [S5] Tray盘下料装备 - 出站接口
  9084. /// </summary>
  9085. /// <param name="plcNo"></param>
  9086. /// <param name="stationCode"></param>
  9087. /// <param name="stationName"></param>
  9088. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9089. {
  9090. Stopwatch stopwatch1 = new Stopwatch();
  9091. Stopwatch stopwatch2 = new Stopwatch();
  9092. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9093. string stationNameStr = stationCode + stationName;
  9094. string processItem = stationName; // 测试项目
  9095. try
  9096. {
  9097. stopwatch1.Start();
  9098. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9099. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9100. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9101. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9102. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9103. sn = sn.Replace("\0", "");
  9104. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9105. //partNo = partNo.Replace("\0", "");
  9106. #region 查询载具上的产品信息
  9107. string cavityData = string.Empty;
  9108. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9109. if (string.IsNullOrEmpty(cavityData))
  9110. cavityData = "";
  9111. if (snResult != 0)
  9112. {
  9113. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9114. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9115. writeToPLC_Flag1.Adress = 2035;
  9116. writeToPLC_Flag1.Value = (short)4;
  9117. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9118. stopwatch1.Stop();
  9119. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9120. return;
  9121. }
  9122. string[] cavitySNs = cavityData.Split('.');
  9123. string partNo = string.Empty;
  9124. if (cavitySNs != null && cavitySNs.Length >= 1)
  9125. partNo = cavitySNs[0];
  9126. #endregion 查询载具上的产品信息
  9127. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9128. bool pass = e1Result == 1;
  9129. stopwatch2.Start();
  9130. // 上传MES
  9131. List<TestItem> items = new List<TestItem>();
  9132. items.Add(new TestItem()
  9133. {
  9134. Parameter_name = "载具码",
  9135. Parameter_value = sn,
  9136. Parameter_unit = ""
  9137. });
  9138. items.Add(new TestItem()
  9139. {
  9140. Parameter_name = "载具穴号",
  9141. Parameter_value = "1",
  9142. Parameter_unit = ""
  9143. });
  9144. items.Add(new TestItem()
  9145. {
  9146. Parameter_name = "产品结果",
  9147. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9148. Parameter_unit = ""
  9149. });
  9150. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  9151. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9152. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9153. short result = result1 == 1 ? (short)1 : (short)3;
  9154. stopwatch2.Stop();
  9155. #region 存储绑定数据到 边线MES系统中
  9156. if (result == 1)
  9157. {
  9158. // 删除绑定信息
  9159. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9160. if (resultMesR != 0)
  9161. {
  9162. result = 4;
  9163. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9164. }
  9165. }
  9166. #endregion 存储绑定数据到 边线MES系统中
  9167. // MES_Flag 为MES报错
  9168. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9169. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9170. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9171. writeToPLC_Flag.Name = "e1MES_FLAG";
  9172. writeToPLC_Flag.Adress = 2035;
  9173. writeToPLC_Flag.Value = result;
  9174. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9175. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9176. }
  9177. catch (Exception ex)
  9178. {
  9179. stopwatch2.Restart();
  9180. // MES_Flag 为4上位机报错
  9181. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9182. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9183. writeToPLC_Flag.Name = "e1MES_FLAG";
  9184. writeToPLC_Flag.Adress = 2035;
  9185. writeToPLC_Flag.Value = (short)4;
  9186. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9187. stopwatch2.Stop();
  9188. string str = ex.StackTrace;
  9189. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9190. }
  9191. stopwatch1.Stop();
  9192. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9193. }
  9194. /// <summary>
  9195. /// [S5] Tray盘下料装备 - 节拍接口
  9196. /// </summary>
  9197. /// <param name="plcNo">PLC编号</param>
  9198. /// <param name="stationNameStr">工站全称</param>
  9199. private void S5节拍接口(int plcNo, string stationNameStr)
  9200. {
  9201. Stopwatch stopwatch1 = new Stopwatch();
  9202. Stopwatch stopwatch2 = new Stopwatch();
  9203. string resultStr = string.Empty;
  9204. try
  9205. {
  9206. stopwatch1.Start();
  9207. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9208. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9209. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9210. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9211. if (!actionBool)
  9212. {
  9213. stopwatch2.Start();
  9214. // MES_Flag
  9215. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9216. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9217. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9218. writeToPLC_Flag1.Adress = 2088;
  9219. writeToPLC_Flag1.Value = (short)4;
  9220. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9221. stopwatch2.Stop();
  9222. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9223. return;
  9224. }
  9225. string e1OEEPartNo = string.Empty; // 物料码
  9226. if (string.IsNullOrEmpty(e1OEEProductSN))
  9227. {
  9228. stopwatch2.Start();
  9229. // MES_Flag
  9230. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9231. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9232. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9233. writeToPLC_Flag1.Adress = 2088;
  9234. writeToPLC_Flag1.Value = (short)1;
  9235. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9236. stopwatch2.Stop();
  9237. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9238. return;
  9239. }
  9240. else
  9241. { // 查产品SN
  9242. e1OEEPartNo = "Test"; // ZS
  9243. }
  9244. short e1OEEMES_FLAG = 0;
  9245. // 上传OEE
  9246. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9247. e1OEEMES_FLAG = result.Item1;
  9248. resultStr = result.Item2;
  9249. stopwatch2.Start();
  9250. // MES_Flag
  9251. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9252. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9253. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9254. writeToPLC_Flag.Adress = 2088;
  9255. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9256. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9257. stopwatch2.Stop();
  9258. }
  9259. catch (Exception ex)
  9260. {
  9261. string str = ex.StackTrace;
  9262. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9263. // MES_Flag
  9264. stopwatch2.Start();
  9265. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9266. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9267. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9268. writeToPLC_Flag.Adress = 2088;
  9269. writeToPLC_Flag.Value = (short)4;
  9270. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9271. stopwatch2.Stop();
  9272. }
  9273. stopwatch1.Stop();
  9274. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9275. }
  9276. /// <summary>
  9277. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9278. /// </summary>
  9279. /// <param name="plcNo">PLC编号</param>
  9280. /// <param name="stationNameStr">工站全称</param>
  9281. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9282. {
  9283. Stopwatch stopwatch1 = new Stopwatch();
  9284. Stopwatch stopwatch2 = new Stopwatch();
  9285. try
  9286. {
  9287. stopwatch1.Start();
  9288. // ZS 呼叫AGV
  9289. short e1AGVUpCall = 2;
  9290. stopwatch2.Start();
  9291. // e1AGVUpCall
  9292. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9293. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9294. writeToPLC_Flag.Name = "e1AGVUpCall";
  9295. writeToPLC_Flag.Adress = 2120;
  9296. writeToPLC_Flag.Value = e1AGVUpCall;
  9297. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9298. stopwatch2.Stop();
  9299. }
  9300. catch (Exception ex)
  9301. {
  9302. string str = ex.StackTrace;
  9303. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9304. // e1AGVUpCall
  9305. stopwatch2.Start();
  9306. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9307. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9308. writeToPLC_Flag.Name = "e1AGVUpCall";
  9309. writeToPLC_Flag.Adress = 2120;
  9310. writeToPLC_Flag.Value = (short)4;
  9311. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9312. stopwatch2.Stop();
  9313. }
  9314. stopwatch1.Stop();
  9315. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9316. }
  9317. /// <summary>
  9318. /// [S5] Tray盘下料装备 - AGV上料完成
  9319. /// </summary>
  9320. /// <param name="plcNo">PLC编号</param>
  9321. /// <param name="stationNameStr">工站全称</param>
  9322. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9323. {
  9324. Stopwatch stopwatch1 = new Stopwatch();
  9325. Stopwatch stopwatch2 = new Stopwatch();
  9326. try
  9327. {
  9328. stopwatch1.Start();
  9329. // ZS AGV上料完成,让小车离开
  9330. short e1AGVUpEnd = 2;
  9331. stopwatch2.Start();
  9332. // e1AGVUpEnd
  9333. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9334. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9335. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9336. writeToPLC_Flag.Adress = 2122;
  9337. writeToPLC_Flag.Value = e1AGVUpEnd;
  9338. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9339. stopwatch2.Stop();
  9340. }
  9341. catch (Exception ex)
  9342. {
  9343. string str = ex.StackTrace;
  9344. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9345. // e1AGVUpEnd
  9346. stopwatch2.Start();
  9347. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9348. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9349. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9350. writeToPLC_Flag.Adress = 2122;
  9351. writeToPLC_Flag.Value = (short)4;
  9352. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9353. stopwatch2.Stop();
  9354. }
  9355. stopwatch1.Stop();
  9356. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9357. }
  9358. /// <summary>
  9359. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9360. /// </summary>
  9361. /// <param name="plcNo">PLC编号</param>
  9362. /// <param name="stationNameStr">工站全称</param>
  9363. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9364. {
  9365. Stopwatch stopwatch1 = new Stopwatch();
  9366. Stopwatch stopwatch2 = new Stopwatch();
  9367. try
  9368. {
  9369. stopwatch1.Start();
  9370. // ZS 呼叫AGV
  9371. short e1AGVDownCall = 2;
  9372. stopwatch2.Start();
  9373. // e1AGVDownCall
  9374. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9375. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9376. writeToPLC_Flag.Name = "e1AGVDownCall";
  9377. writeToPLC_Flag.Adress = 2133;
  9378. writeToPLC_Flag.Value = e1AGVDownCall;
  9379. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9380. stopwatch2.Stop();
  9381. }
  9382. catch (Exception ex)
  9383. {
  9384. string str = ex.StackTrace;
  9385. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9386. // e1AGVDownCall
  9387. stopwatch2.Start();
  9388. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9389. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9390. writeToPLC_Flag.Name = "e1AGVDownCall";
  9391. writeToPLC_Flag.Adress = 2133;
  9392. writeToPLC_Flag.Value = (short)4;
  9393. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9394. stopwatch2.Stop();
  9395. }
  9396. stopwatch1.Stop();
  9397. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9398. }
  9399. /// <summary>
  9400. /// [S5] Tray盘下料装备 - AGV下料完成
  9401. /// </summary>
  9402. /// <param name="plcNo">PLC编号</param>
  9403. /// <param name="stationNameStr">工站全称</param>
  9404. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9405. {
  9406. Stopwatch stopwatch1 = new Stopwatch();
  9407. Stopwatch stopwatch2 = new Stopwatch();
  9408. try
  9409. {
  9410. stopwatch1.Start();
  9411. // ZS AGV上料完成,让小车离开
  9412. short e1AGVDownEnd = 2;
  9413. stopwatch2.Start();
  9414. // e1AGVDownEnd
  9415. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9416. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9417. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9418. writeToPLC_Flag.Adress = 2135;
  9419. writeToPLC_Flag.Value = e1AGVDownEnd;
  9420. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9421. stopwatch2.Stop();
  9422. }
  9423. catch (Exception ex)
  9424. {
  9425. string str = ex.StackTrace;
  9426. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9427. // e1AGVDownEnd
  9428. stopwatch2.Start();
  9429. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9430. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9431. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9432. writeToPLC_Flag.Adress = 2135;
  9433. writeToPLC_Flag.Value = (short)4;
  9434. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9435. stopwatch2.Stop();
  9436. }
  9437. stopwatch1.Stop();
  9438. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9439. }
  9440. #endregion [S5] Tray盘下料装备
  9441. #endregion PLC5 张超凡
  9442. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9443. /// <summary>
  9444. /// PLC读取到的数据 -添加数据
  9445. /// </summary>
  9446. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9447. {
  9448. if (sxPlcData.ContainsKey(newKey))
  9449. sxPlcData[newKey] = newValue;
  9450. else
  9451. sxPlcData.Add(newKey, newValue);
  9452. }
  9453. /// <summary>
  9454. /// PLC需要写入的数据 -添加数据
  9455. /// </summary>
  9456. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9457. {
  9458. if (sxPLCWriteData.ContainsKey(newKey))
  9459. sxPLCWriteData[newKey] = newValue;
  9460. else
  9461. sxPLCWriteData.Add(newKey, newValue);
  9462. }
  9463. /// <summary>
  9464. /// PLC回写操作,写后清空flag
  9465. /// </summary>
  9466. /// <param name="modbusClient">modbus对象</param>
  9467. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9468. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9469. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9470. {
  9471. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9472. {
  9473. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9474. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9475. {
  9476. string mesFlagName = pLCWriteDatas[i].Name;
  9477. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9478. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9479. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9480. {
  9481. // 先回写数据
  9482. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9483. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9484. {
  9485. int mesDataAdress = writeToPLCDatas[j].Adress;
  9486. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9487. switch (mesDataType)
  9488. {
  9489. case PLCValueType.Short:
  9490. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9491. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9492. break;
  9493. case PLCValueType.String:
  9494. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9495. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9496. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9497. break;
  9498. }
  9499. }
  9500. // 再回写信号
  9501. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9502. // 存储读取数据的字典
  9503. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9504. // 存储写入数据的字典 - 清空写入值
  9505. pLCWriteDatas[i].Value = (short)0;
  9506. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9507. }
  9508. }
  9509. }
  9510. }
  9511. /// <summary>
  9512. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9513. /// </summary>
  9514. /// <param name="no">3</param>
  9515. /// <param name="stationCode">设备编号</param>
  9516. /// <param name="stationNameStr">设备名称</param>
  9517. /// <param name="plcOrder">车间订单号</param>
  9518. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9519. {
  9520. try
  9521. {
  9522. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9523. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9524. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9525. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9526. int result1 = 0;
  9527. switch (stationCode)
  9528. {
  9529. case 2:
  9530. case 3:
  9531. case 4:
  9532. case 6:
  9533. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9534. break;
  9535. case 102:
  9536. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9537. break;
  9538. case 103:
  9539. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9540. break;
  9541. case 104:
  9542. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9543. break;
  9544. case 106:
  9545. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9546. break;
  9547. default:
  9548. // MES_Flag 为“6未找到正确设备编号”
  9549. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9550. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9551. return;
  9552. }
  9553. short result = result1 == 1 ? (short)1 : (short)2;
  9554. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9555. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9556. }
  9557. catch (Exception ex)
  9558. {
  9559. // MES_Flag 为2上位机报错
  9560. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9561. string str = ex.StackTrace;
  9562. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9563. }
  9564. }
  9565. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9566. #region UI刷新
  9567. /// <summary>
  9568. /// 更新商品信息的UI + 下发产品信息(SN)
  9569. /// </summary>
  9570. private void UpdateProductInfo()
  9571. {
  9572. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9573. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9574. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9575. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9576. }
  9577. /// <summary>
  9578. /// 更新PLC连接状态的UI
  9579. /// </summary>
  9580. /// <param name="no">PLC编号</param>
  9581. /// <param name="status">状态</param>
  9582. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9583. {
  9584. if (this != null && !this.IsDisposed)
  9585. {
  9586. switch (imgNo)
  9587. {
  9588. case 1:
  9589. this.BeginInvoke(new Action(() =>
  9590. {
  9591. picPLC.Image = imageListState.Images[status];
  9592. }));
  9593. break;
  9594. case 2:
  9595. this.BeginInvoke(new Action(() =>
  9596. {
  9597. pictureBox2.Image = imageListState.Images[status];
  9598. }));
  9599. break;
  9600. case 3:
  9601. this.BeginInvoke(new Action(() =>
  9602. {
  9603. pictureBox3.Image = imageListState.Images[status];
  9604. }));
  9605. break;
  9606. case 4:
  9607. this.BeginInvoke(new Action(() =>
  9608. {
  9609. pictureBox4.Image = imageListState.Images[status];
  9610. }));
  9611. break;
  9612. case 5:
  9613. this.BeginInvoke(new Action(() =>
  9614. {
  9615. pictureBox5.Image = imageListState.Images[status];
  9616. }));
  9617. break;
  9618. case 6:
  9619. this.BeginInvoke(new Action(() =>
  9620. {
  9621. pictureBox6.Image = imageListState.Images[status];
  9622. }));
  9623. break;
  9624. case 7:
  9625. this.BeginInvoke(new Action(() =>
  9626. {
  9627. pictureBox7.Image = imageListState.Images[status];
  9628. }));
  9629. break;
  9630. case 8:
  9631. this.BeginInvoke(new Action(() =>
  9632. {
  9633. pictureBox8.Image = imageListState.Images[status];
  9634. }));
  9635. break;
  9636. default:
  9637. break;
  9638. }
  9639. }
  9640. Task.Run(() => // 更新PLC交互页的指示灯
  9641. {
  9642. try
  9643. {
  9644. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9645. {
  9646. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9647. }
  9648. }
  9649. catch { }
  9650. });
  9651. }
  9652. #endregion UI刷新
  9653. #region 日志
  9654. /// <summary>
  9655. /// 添加各工位运行日志(同步至PLC交互页面)
  9656. /// </summary>
  9657. /// <param name="stationNameStr">工站名称</param>
  9658. /// <param name="logType">日志类型</param>
  9659. /// <param name="message">日志内容</param>
  9660. /// <param name="snNumber">产品数字SN</param>
  9661. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9662. {
  9663. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9664. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9665. ))
  9666. {
  9667. AddMessage(logType, message); // 首页展示+日志记录
  9668. }
  9669. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9670. {
  9671. StationName = stationNameStr,
  9672. SnNumber = snNumber,
  9673. Message = message,
  9674. CreateTime = DateTime.Now
  9675. };
  9676. // PLC交互页展示
  9677. Task.Run(() =>
  9678. {
  9679. try
  9680. {
  9681. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9682. {
  9683. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9684. }
  9685. }
  9686. catch { }
  9687. });
  9688. }
  9689. /// <summary>
  9690. /// 添加运行日志
  9691. /// </summary>
  9692. /// <param name="logType">日志类型</param>
  9693. /// <param name="message">日志内容</param>
  9694. public void AddMessage(LogType logType, string message)
  9695. {
  9696. OnMessage(logType, message);
  9697. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9698. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9699. string msgShow = time + "--> " + message + "\r\n";
  9700. this.BeginInvoke(new Action(() =>
  9701. {
  9702. systemLog.Rows.Insert(0, date, time, message);
  9703. if (systemLog.Rows.Count >= 100)
  9704. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9705. }));
  9706. }
  9707. /// <summary>
  9708. /// 添加运行日志-保存
  9709. /// </summary>
  9710. /// <param name="logType">日志类型</param>
  9711. /// <param name="message">日志内容</param>
  9712. private void OnMessage(LogType logType, string msg)
  9713. {
  9714. MessageEvent?.Invoke(logType, msg);
  9715. }
  9716. /// <summary>
  9717. /// 保存PLC写入日志
  9718. /// </summary>
  9719. /// <param name="logType"></param>
  9720. /// <param name="logValue"></param>
  9721. private void WritePLCLog(LogType logType, string logValue)
  9722. {
  9723. switch ((int)logType)
  9724. {
  9725. case 0:
  9726. _PLCLogNet.WriteDebug(logValue);
  9727. break;
  9728. case 1:
  9729. _PLCLogNet.WriteInfo(logValue);
  9730. break;
  9731. case 2:
  9732. _PLCLogNet.WriteWarn(logValue);
  9733. break;
  9734. case 3:
  9735. _PLCLogNet.WriteError(logValue);
  9736. break;
  9737. default:
  9738. _PLCLogNet.WriteFatal(logValue);
  9739. break;
  9740. }
  9741. }
  9742. /// <summary>
  9743. /// IOT Mqtt回调方法- With DataId
  9744. /// </summary>
  9745. /// <param name="id"></param>
  9746. /// <param name="v"></param>
  9747. /// <param name="dataId"></param>
  9748. public void CallbackWithDataId(string id, string msg, string dataId)
  9749. {
  9750. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9751. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9752. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9753. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9754. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9755. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9756. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9757. }
  9758. /// <summary>
  9759. /// AGV Mqtt回调方法- 记录Log并处理数据
  9760. /// </summary>
  9761. /// <param name="obj"></param>
  9762. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9763. {
  9764. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9765. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9766. // 接收到的信息
  9767. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9768. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9769. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9770. {
  9771. }
  9772. }
  9773. #endregion 日志
  9774. /// <summary>
  9775. /// 实例化报警字典
  9776. /// </summary>
  9777. private void InitalDicAlarm()
  9778. {
  9779. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9780. List<Alarm> keyValues1 = new List<Alarm>
  9781. {
  9782. #region 第一组报警(电机)
  9783. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9784. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9785. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9786. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9787. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9788. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9789. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9790. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9791. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9792. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9793. #endregion 第一组报警(电机)
  9794. #region 第二组报警(气缸)
  9795. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9796. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9797. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9798. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9799. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9800. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9801. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9802. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9803. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9804. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9805. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9806. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9807. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9808. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9809. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9810. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9811. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9812. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9813. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9814. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9815. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9816. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9817. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9818. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9819. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9820. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9821. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9822. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9823. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9824. #endregion 第二组报警(气缸)
  9825. #region 第三组报警(其他故障)
  9826. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9827. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9828. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9829. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9830. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9831. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9832. #endregion 第三组报警(其他故障)
  9833. };
  9834. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9835. #endregion 第一个工站(这里使用线体代替工位)
  9836. # region 第二个工站-原来的写法(废弃)
  9837. //keyValues = new Dictionary<int, AlarmData[]>();
  9838. ////1
  9839. //dicAlarmName = new Dictionary<int, Alarm>();
  9840. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  9841. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  9842. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  9843. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  9844. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  9845. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9846. //for (int i = 0; i < dicAlarmName.Count; i++)
  9847. //{
  9848. // alarmDatas[i] = new AlarmData();
  9849. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9850. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9851. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9852. // alarmDatas[i].AlarmType = 1;
  9853. //}
  9854. //keyValues.Add(1, alarmDatas);
  9855. ////2
  9856. //dicAlarmName = new Dictionary<int, Alarm>();
  9857. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  9858. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  9859. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  9860. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  9861. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  9862. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  9863. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  9864. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  9865. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9866. //for (int i = 0; i < dicAlarmName.Count; i++)
  9867. //{
  9868. // alarmDatas[i] = new AlarmData();
  9869. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9870. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9871. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9872. // alarmDatas[i].AlarmType = 2;
  9873. //}
  9874. //keyValues.Add(2, alarmDatas);
  9875. ////3
  9876. //dicAlarmName = new Dictionary<int, Alarm>();
  9877. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  9878. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  9879. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  9880. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  9881. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9882. //for (int i = 0; i < dicAlarmName.Count; i++)
  9883. //{
  9884. // alarmDatas[i] = new AlarmData();
  9885. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  9886. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9887. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9888. // alarmDatas[i].AlarmType = 3;
  9889. //}
  9890. //keyValues.Add(3, alarmDatas);
  9891. //DicAlarms.Add(2, keyValues);
  9892. #endregion 第二个工站-原来的写法(废弃)
  9893. }
  9894. }
  9895. }