Form_Home.cs 717 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106
  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. using HslCommunication.Enthernet;
  40. using BZFAStandardLib;
  41. using MainForm.ClassFile;
  42. using NPOI.SS.Formula.Functions;
  43. using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
  44. using System.Net.Http;
  45. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_UpLoadFile;
  46. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
  47. using System.Reflection;
  48. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  49. using FaFrameUI;
  50. using System.Security.Policy;
  51. /*
  52. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  53. */
  54. namespace MainForm
  55. {
  56. /// <summary>
  57. /// 记录日志的委托
  58. /// </summary>
  59. /// <param name="logType">日志类型</param>
  60. /// <param name="message">日志信息</param>
  61. public delegate void HomeMessageHandler(LogType logType, string message);
  62. /// <summary>
  63. /// 主页窗体
  64. /// </summary>
  65. public partial class Form_Home : Form
  66. {
  67. #region 常量
  68. //文本常量
  69. private const string Head = "开始采集";
  70. private const string Tail = "采集完成";
  71. private const string Body = "工位出站数据";
  72. private const string BodyCheck = "工位点检数据";
  73. private const string BodyRun = "整线运行数据";
  74. private const string BodyAlarm = "整线报警数据";
  75. #endregion 常量
  76. #region 变量
  77. /// <summary>
  78. /// 委托-记录日志的方法
  79. /// </summary>
  80. public event HomeMessageHandler MessageEvent;
  81. /// <summary>
  82. /// 日志接口
  83. /// </summary>
  84. ILogNet _PLCLogNet;
  85. /// <summary>
  86. /// 用于记录IOT MQTT日志
  87. /// </summary>
  88. ILogNet _IOTMqttLogNet;
  89. /// <summary>
  90. /// 用于记录AGV MQTT日志
  91. /// </summary>
  92. ILogNet _AGVMqttLogNet;
  93. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  94. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  95. // 间隔时间
  96. private int IntervalReadPLC = 300; //ms 读PLC
  97. private int IntervalMonitorMES = 1000; //ms MES心跳
  98. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  99. /// <summary>
  100. /// 设备报警数据
  101. /// </summary>
  102. uint[] _FaultDatas = { };
  103. uint[] _FaultDatas_Old = { };
  104. // 软件状态
  105. private bool IsRun = true;
  106. #region PLC 与 TCP对象
  107. // 定义一个字典,存plc对象(通讯)
  108. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  109. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  110. // 定义TCPClient对象列表
  111. Dictionary<int, HPSocket_TcpClientHelper>
  112. _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  113. // 定义MQTTHelper对象
  114. MQTTHelper _MQTTHelper = new MQTTHelper();
  115. #endregion PLC 与 TCP对象
  116. /// <summary>
  117. /// 上次的设备运行信息
  118. /// </summary>
  119. private string lineWorkingData1_OldStr = string.Empty;
  120. /// <summary>
  121. /// 设备报警字典-当前结果
  122. /// Dictionary<工位代码,List<报警信息>>
  123. /// </summary>
  124. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  125. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  126. /// <summary>
  127. /// 单机用-设备状态
  128. /// </summary>
  129. //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  130. XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
  131. private int test_item_num = 0;//iot 过站数据序号
  132. private string uuid = "";
  133. private bool inpass = false;//保存进站测试状态
  134. public string _deviceCode="";//装备编码
  135. public string _stationCode="";//工站ID
  136. public string _workstation="";//工位编码
  137. #endregion 变量
  138. #region 窗体基础事件
  139. /// <summary>
  140. /// 初始化
  141. /// </summary>
  142. public Form_Home()
  143. {
  144. InitializeComponent();
  145. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  146. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  147. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  148. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  149. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  150. }
  151. /// <summary>
  152. /// 窗体加载事件
  153. /// </summary>
  154. private void Form_Home_Load(object sender, EventArgs e)
  155. {
  156. try
  157. {
  158. AddMessage(LogType.Info, "开始初始化程序");
  159. //组建plc对象字典
  160. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  161. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  162. //上传操作记录
  163. operateToIot("startup","开启");
  164. if (GlobalContext.IsUsePLC1)
  165. {
  166. GlobalContext.IsUsePLCNow = 1;
  167. GlobalContext.IsUseStationName = "[OP10]壳体清洁上料";
  168. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  169. }
  170. if (GlobalContext.IsUsePLC2)
  171. {
  172. GlobalContext.IsUsePLCNow = 2;
  173. GlobalContext.IsUseStationName = "[OP20]上盖板上料装备";
  174. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  175. }
  176. if (GlobalContext.IsUsePLC3)
  177. {
  178. GlobalContext.IsUsePLCNow = 3;
  179. GlobalContext.IsUseStationName = "[OP30]点散热胶装备";
  180. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  181. }
  182. if (GlobalContext.IsUsePLC4)
  183. {
  184. GlobalContext.IsUsePLCNow = 4;
  185. GlobalContext.IsUseStationName = "[OP40]胶线检测";
  186. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  187. }
  188. if (GlobalContext.IsUsePLC5)
  189. {
  190. GlobalContext.IsUsePLCNow = 5;
  191. GlobalContext.IsUseStationName = "[OP50]ADD板上料组装装备";
  192. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  193. }
  194. if (GlobalContext.IsUsePLC6)
  195. {
  196. GlobalContext.IsUsePLCNow = 6;
  197. GlobalContext.IsUseStationName = "[OP60]组上盖板";
  198. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  199. }
  200. if (GlobalContext.IsUsePLC7)
  201. {
  202. GlobalContext.IsUsePLCNow = 7;
  203. GlobalContext.IsUseStationName = "[OP70]上盖板锁螺丝";
  204. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  205. }
  206. if (GlobalContext.IsUsePLC8)
  207. {
  208. GlobalContext.IsUsePLCNow = 8;
  209. GlobalContext.IsUseStationName = "[OP80]NG下料";
  210. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  211. }
  212. if (GlobalContext.IsUsePLC9)
  213. {
  214. GlobalContext.IsUsePLCNow = 9;
  215. GlobalContext.IsUseStationName = "[OP90]半成品下料";
  216. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  217. }
  218. (bool,string)DicResult=InitalDicAlarm(); // 实例化报警字典
  219. AddMessage(LogType.Info, DicResult.Item2);
  220. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  221. {
  222. if (plcEIP != null)
  223. {
  224. try
  225. {
  226. (int, string) result = plcEIP.Connect();
  227. }
  228. catch (Exception ex)
  229. {
  230. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  231. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
  232. MessageBoxOptions.ServiceNotification);
  233. }
  234. }
  235. }
  236. /*
  237. //plc1Alarm.Connect();
  238. foreach (ModbusClientHelper modbusClient in Funs.Values)
  239. {
  240. if (modbusClient != null)
  241. {
  242. try
  243. {
  244. modbusClient.Connect();
  245. }
  246. catch (Exception ex)
  247. {
  248. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  249. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  250. }
  251. }
  252. }
  253. */
  254. // 采集任务
  255. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  256. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  257. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  258. if (GlobalContext.IsUsePLC1)
  259. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  260. if (GlobalContext.IsUsePLC2)
  261. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  262. if (GlobalContext.IsUsePLC3)
  263. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  264. if (GlobalContext.IsUsePLC4)
  265. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  266. if (GlobalContext.IsUsePLC5)
  267. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  268. if (GlobalContext.IsUsePLC6)
  269. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  270. if (GlobalContext.IsUsePLC7)
  271. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  272. if (GlobalContext.IsUsePLC8)
  273. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  274. if (GlobalContext.IsUsePLC9)
  275. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  276. #region 初始化
  277. try
  278. {
  279. // 开启边线MES(绑定/查询数据)
  280. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  281. //if (mesRoute == 0)
  282. //{
  283. // //picMESStatus.Image = imageListState.Images[1];
  284. // //GlobalContext.MESIsConnect = true;
  285. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  286. //}
  287. //else
  288. //{
  289. // //picMESStatus.Image = imageListState.Images[0];
  290. // //GlobalContext.MESIsConnect = false;
  291. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  292. //}
  293. // 开启MES(Http)
  294. if (GlobalContext.IsUseMES)
  295. {
  296. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  297. if (mesret)
  298. {
  299. picMESStatus.Image = imageListState.Images[1];
  300. GlobalContext.MESIsConnect = true;
  301. AddMessage(LogType.Info, "小米MES初始连接成功!");
  302. }
  303. else
  304. {
  305. picMESStatus.Image = imageListState.Images[0];
  306. GlobalContext.MESIsConnect = false;
  307. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  308. }
  309. }
  310. // 开启IOT(MQTT)
  311. if (GlobalContext.IsUseIot)
  312. {
  313. string addr = GlobalContext.MQTTServerHost;
  314. int port = GlobalContext.MQTTServerPort;
  315. //生产环境需要修改
  316. (int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  317. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
  318. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  319. {
  320. picIot.Image = imageListState.Images[1];
  321. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  322. // 设置回调函数
  323. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  324. // 配置参数
  325. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  326. // fds
  327. param.parameter.fds.address = GlobalContext.address;
  328. param.parameter.fds.appId = GlobalContext.appId;
  329. param.parameter.fds.appKey = GlobalContext.appKey;
  330. // mes
  331. param.parameter.mes.address = GlobalContext.ServerIp;
  332. param.parameter.mes.appId = GlobalContext.MESAppId;
  333. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  334. // mqtt
  335. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  336. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  337. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  338. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  339. // 设备配置
  340. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  341. if (GlobalContext.IsUsePLC1)
  342. {
  343. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  344. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  345. _workstation= GlobalContext.S1_work_station;//工站
  346. }
  347. if (GlobalContext.IsUsePLC2)
  348. {
  349. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  350. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  351. _workstation= GlobalContext.S2_work_station;//工站
  352. }
  353. if (GlobalContext.IsUsePLC3)
  354. {
  355. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  356. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  357. }
  358. if (GlobalContext.IsUsePLC4)
  359. {
  360. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  361. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  362. _workstation= GlobalContext.s4_work_station;//工站
  363. }
  364. if (GlobalContext.IsUsePLC5)
  365. {
  366. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  367. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  368. _workstation= GlobalContext.s5_work_station;//工站
  369. }
  370. if (GlobalContext.IsUsePLC6)
  371. {
  372. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  373. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  374. _workstation= GlobalContext.s6_work_station;//工站
  375. }
  376. if (GlobalContext.IsUsePLC7)
  377. {
  378. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  379. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  380. }
  381. if (GlobalContext.IsUsePLC8)
  382. {
  383. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  384. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  385. _workstation= GlobalContext.s8_work_station;//工站
  386. }
  387. if (GlobalContext.IsUsePLC9)
  388. {
  389. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  390. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  391. _workstation= GlobalContext.s9_work_station;//工站
  392. }
  393. param.parameter.equipment.project = GlobalContext.Project_Code;
  394. param.parameter.equipment.productMode = "debug";
  395. param.parameter.other.logLevel = 0;
  396. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  397. XiaomiMqttClient_Extend.ParameterConfig(param);
  398. //保存全局变量
  399. _stationCode = param.parameter.equipment.deviceCode;
  400. _deviceCode = param.parameter.equipment.stationCode;
  401. }
  402. else
  403. {
  404. picIot.Image = imageListState.Images[0];
  405. AddMessage(LogType.Info,
  406. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  407. }
  408. }
  409. // 开启AGV(Http与MQTT)
  410. if (GlobalContext.IsUseAGV)
  411. {
  412. // AGV HTTP
  413. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  414. if (mesret1)
  415. {
  416. picAgvHttp.Image = imageListState.Images[1];
  417. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  418. }
  419. else
  420. {
  421. picAgvHttp.Image = imageListState.Images[0];
  422. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  423. }
  424. string agvMqttIp = GlobalContext.MQTTServerHost;
  425. int agvMqttPort = GlobalContext.MQTTServerPort;
  426. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  427. ResultData_MQTT result_MQTT = _MQTTHelper
  428. .CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  429. // AGV MQTT
  430. if (result_MQTT.ResultCode == 1)
  431. {
  432. picAgvMqtt.Image = imageListState.Images[1];
  433. GlobalContext.AGVMQTTIsConnect = true;
  434. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  435. ResultData_MQTT result =
  436. XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  437. AddMessage(LogType.Info,
  438. $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  439. }
  440. else
  441. {
  442. picAgvMqtt.Image = imageListState.Images[0];
  443. GlobalContext.AGVMQTTIsConnect = false;
  444. AddMessage(LogType.Info,
  445. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  446. }
  447. }
  448. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  449. Task.Run(MonitorMESConnect);
  450. // 查询PLC连接状态
  451. foreach (int plcNo in FunsEip.Keys)
  452. {
  453. bool connected = FunsEip[plcNo].IsConnected;
  454. if (connected)
  455. {
  456. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  457. AddMessage(LogType.Info, msg);
  458. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  459. }
  460. else
  461. {
  462. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  463. AddMessage(LogType.Info, msg);
  464. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  465. }
  466. }
  467. // PLC4时 初始化扫码器TCP
  468. //if (GlobalContext.IsUsePLC4)
  469. // HpTCPClientInit();
  470. // 开启PLC的业务处理线程-监听PLC点位+状态
  471. foreach (Task task in TaskReadProcess)
  472. {
  473. if (task != null)
  474. task.Start();
  475. }
  476. //// 开启iot的线程
  477. TaskReadAlarm.Start();
  478. ////下传MES信息给1工位(先判断下plc对象数量)
  479. //if (Funs.Count > 1)
  480. // DownLoadProductInfo(1);
  481. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  482. {
  483. state_l.Text = "设备状态(左):";
  484. state_r.Text = "设备状态(右):";
  485. state_r.Visible = true;
  486. lblDeviceStates2.Visible = true;
  487. }
  488. AddMessage(LogType.Info, "程序初始化完成");
  489. }
  490. catch (Exception ex)
  491. {
  492. string str = ex.StackTrace;
  493. this.BeginInvoke(new Action(() =>
  494. {
  495. AddMessage(LogType.Error,
  496. "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  497. str.Length - str.LastIndexOf("\\") - 1));
  498. }));
  499. }
  500. #endregion
  501. }
  502. catch (Exception ex)
  503. {
  504. string str = ex.StackTrace;
  505. OnMessage(LogType.Info,
  506. "主窗体的首页初始化出错!异常位置:" +
  507. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
  508. ex.Message.ToString());
  509. if (ex.Message != null && ex.Message.Contains("timed out"))
  510. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  511. else
  512. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  513. }
  514. }
  515. /// <summary>
  516. /// 窗体关闭事件
  517. /// </summary>
  518. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  519. {
  520. Closed2();
  521. }
  522. public void Closed2()
  523. {
  524. try
  525. {
  526. IsRun = false;
  527. Thread.Sleep(IntervalReadPLC);
  528. // 断开TCP
  529. int count = _HPSocket_TcpClients.Count();
  530. for (int i = 0; i < count; i++)
  531. {
  532. try
  533. {
  534. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  535. {
  536. _HPSocket_TcpClients[i].Stop();
  537. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  538. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  539. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  540. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  541. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  542. }
  543. }
  544. catch
  545. {
  546. }
  547. }
  548. // 关闭Iot
  549. try
  550. {
  551. XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
  552. GlobalContext.MqttServerName);
  553. }
  554. catch
  555. {
  556. }
  557. // 关闭AGV Mqtt
  558. try
  559. {
  560. _MQTTHelper.DisconnectAsync_Client().Wait();
  561. }
  562. catch
  563. {
  564. }
  565. }
  566. catch
  567. {
  568. }
  569. }
  570. #endregion 窗体基础事件
  571. #region 监控MES状态
  572. /// <summary>
  573. /// 监控MES连接状态
  574. /// </summary>
  575. private void MonitorMESConnect()
  576. {
  577. while (IsRun) // 运行被控线程
  578. {
  579. try
  580. {
  581. // 开启MES(Http)
  582. if (GlobalContext.IsUseMES)
  583. {
  584. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  585. if (mesret)
  586. {
  587. picMESStatus.Image = imageListState.Images[1];
  588. GlobalContext.MESIsConnect = true;
  589. }
  590. else
  591. {
  592. picMESStatus.Image = imageListState.Images[0];
  593. GlobalContext.MESIsConnect = false;
  594. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  595. }
  596. }
  597. // 开启IOT(MQTT)
  598. if (GlobalContext.IsUseIot)
  599. {
  600. bool iIot = XiaomiMqttClient.IsOpen;
  601. if (iIot)
  602. picIot.Image = imageListState.Images[1];
  603. else
  604. {
  605. picIot.Image = imageListState.Images[0];
  606. OnMessage(LogType.Info,
  607. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  608. }
  609. }
  610. // 开启AGV(Http与MQTT)
  611. if (GlobalContext.IsUseAGV)
  612. {
  613. // AGV Http
  614. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  615. if (mesret1)
  616. picAgvHttp.Image = imageListState.Images[1];
  617. else
  618. {
  619. picAgvHttp.Image = imageListState.Images[0];
  620. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  621. }
  622. // AGV MQTT
  623. if (GlobalContext.AGVMQTTIsConnect)
  624. picAgvMqtt.Image = imageListState.Images[1];
  625. else
  626. {
  627. picAgvMqtt.Image = imageListState.Images[0];
  628. OnMessage(LogType.Info,
  629. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  630. }
  631. }
  632. }
  633. catch (Exception ex)
  634. {
  635. string str = ex.StackTrace;
  636. AddMessage(LogType.Error,
  637. "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  638. str.Length - str.LastIndexOf("\\") - 1));
  639. }
  640. Thread.Sleep(IntervalMonitorMES);
  641. }
  642. }
  643. #endregion 监控MES连接状态
  644. #region 采集设备状态、运行数据、报警数据
  645. /// <summary>
  646. /// 请求设备状态 5000
  647. /// </summary>
  648. /// <param name="no">1</param>
  649. /// <param name="stationNameStr"></param>
  650. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  651. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  652. {
  653. try
  654. {
  655. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  656. {
  657. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  658. return result;
  659. }
  660. else
  661. {
  662. return 0;
  663. }
  664. }
  665. catch (Exception ex)
  666. {
  667. string str = ex.StackTrace;
  668. AddMessage_Station(stationNameStr, LogType.Error,
  669. "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  670. str.Length - str.LastIndexOf("\\") - 1));
  671. return 0;
  672. }
  673. }
  674. /// <summary>
  675. /// 检查是否可采集点检数据 - 不取新值
  676. /// 5000不为1时可点检
  677. /// </summary>
  678. /// <returns></returns>
  679. public bool CheckCanSpotcheck1(int deviceState)
  680. {
  681. //return true;
  682. //D5000 = 1,代表设备控制状态处于运行状态
  683. //D5000 = 2, 代表设备控制状态处于故障状态
  684. //D5000 = 3,代表设备控制状态处于缺料状态
  685. //D5000 = 4, 代表设备控制状态处于待机状态
  686. //D5000 = 5,代表设备控制状态处于维修状态
  687. return deviceState != 1;
  688. }
  689. /// <summary>
  690. /// 检查是否可采集产品数据 - 不取新值
  691. /// </summary>
  692. /// <returns></returns>
  693. public bool CheckCanCollData(int deviceState)
  694. {
  695. return deviceState == 0; // 点检时该值不为0
  696. }
  697. /// <summary>
  698. /// 采集到的设备状态
  699. /// </summary>
  700. private string _DeviceStates = "未知状态";
  701. private string _DeviceStates_Old = "未知状态";
  702. private string _DeviceStates2 = "未知状态";
  703. private string _DeviceStates_Old2 = "未知状态";
  704. /// <summary>
  705. /// 获取设备报警数据与获取设备运行信息
  706. /// </summary>
  707. private async void ReadAlarmAllPLC()
  708. {
  709. /// 获取设备报警数据与状态信息
  710. string stationNameStr = "获取设备报警数据与状态信息";
  711. // 已连接到PLC
  712. while (IsRun)
  713. {
  714. try
  715. {
  716. #region 报警数据
  717. try
  718. {
  719. //_FaultDatas = new uint[] { 4, 0, 30, 10 };
  720. if (_FaultDatas.Length>0)
  721. {
  722. ReadPLCAlarmToIot(_FaultDatas, stationNameStr);
  723. }
  724. else
  725. {
  726. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!" );
  727. }
  728. }
  729. catch (Exception ex)
  730. {
  731. string str = ex.StackTrace;
  732. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  733. }
  734. #endregion 报警数据
  735. #region 设备状态
  736. //if (!GlobalContext._IsCon_plc1Alarm)
  737. //{
  738. // UpdatePLCMonitor(1, -2, 0);
  739. // continue;
  740. //}
  741. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  742. {
  743. if (plcEIP != null)
  744. {
  745. if (plcEIP.IsConnected)
  746. {
  747. #region 主页展示设备运行状态并上传到IOT中,有双工位left就是左工位,没有双工位left就是单工位
  748. switch (xmDeviceStateData.left)
  749. {
  750. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  751. _DeviceStates = "未初始化状态";
  752. lblDeviceStates.Text = _DeviceStates;
  753. break;
  754. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  755. _DeviceStates = "初始化状态";
  756. lblDeviceStates.Text = _DeviceStates;
  757. break;
  758. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  759. _DeviceStates = "初始化完成状态";
  760. lblDeviceStates.Text = _DeviceStates;
  761. break;
  762. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  763. _DeviceStates = "运行状态";
  764. lblDeviceStates.Text = _DeviceStates;
  765. break;
  766. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  767. _DeviceStates = "暂停状态";
  768. lblDeviceStates.Text = _DeviceStates;
  769. break;
  770. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  771. _DeviceStates = "故障状态";
  772. lblDeviceStates.Text = _DeviceStates;
  773. break;
  774. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  775. _DeviceStates = "警报状态";
  776. lblDeviceStates.Text = _DeviceStates;
  777. break;
  778. }
  779. if (!_DeviceStates.Equals(_DeviceStates_Old))
  780. {
  781. var iotResult =
  782. SaveDeviceStateData(stationNameStr, xmDeviceStateData.left, "left"); // 上传+保存
  783. if (iotResult.Item1 == 1)
  784. {
  785. _DeviceStates_Old = _DeviceStates;
  786. AddMessage_Station(stationNameStr, LogType.Info,
  787. "【设备状态】" + stationNameStr + $"_上传设备状态到Iot成功!");
  788. }
  789. else
  790. AddMessage_Station(stationNameStr, LogType.Info,
  791. "【设备状态】"+stationNameStr +
  792. $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  793. }
  794. #endregion 主页展示设备运行状态并上传到IOT中
  795. #region 右工位
  796. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  797. {
  798. switch (xmDeviceStateData.right)
  799. {
  800. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  801. _DeviceStates2 = "未初始化状态";
  802. lblDeviceStates.Text = _DeviceStates2;
  803. break;
  804. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  805. _DeviceStates2 = "初始化状态";
  806. lblDeviceStates.Text = _DeviceStates2;
  807. break;
  808. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  809. _DeviceStates2 = "初始化完成状态";
  810. lblDeviceStates.Text = _DeviceStates2;
  811. break;
  812. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  813. _DeviceStates2 = "运行状态";
  814. lblDeviceStates.Text = _DeviceStates2;
  815. break;
  816. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  817. _DeviceStates2 = "暂停状态";
  818. lblDeviceStates.Text = _DeviceStates2;
  819. break;
  820. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  821. _DeviceStates2 = "故障状态";
  822. lblDeviceStates.Text = _DeviceStates2;
  823. break;
  824. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  825. _DeviceStates2 = "警报状态";
  826. lblDeviceStates.Text = _DeviceStates2;
  827. break;
  828. }
  829. if (!_DeviceStates2.Equals(_DeviceStates_Old2))
  830. {
  831. var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceStateData.left,
  832. "right"); // 上传+保存
  833. if (iotResult.Item1 == 1)
  834. {
  835. _DeviceStates_Old2 = _DeviceStates2;
  836. AddMessage_Station(stationNameStr, LogType.Info,
  837. "【设备状态】" + stationNameStr + $"_上传Iot成功!");
  838. }
  839. else
  840. AddMessage_Station(stationNameStr, LogType.Info,
  841. "【设备状态】" + stationNameStr +
  842. $"_上传Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  843. }
  844. }
  845. #endregion 右工位
  846. }
  847. }
  848. }
  849. #endregion
  850. //if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  851. //{
  852. // DateTime dtNow = DateTime.Now;
  853. // //#region 获取设备运行信息
  854. // //try
  855. // //{
  856. // // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  857. // // lineWorkingData1.GUID = Guid.NewGuid().ToString();
  858. // // lineWorkingData1.LineName = GlobalContext.LineCode;
  859. // // //
  860. // // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  861. // // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  862. // // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  863. // // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  864. // // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  865. // // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  866. // // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  867. // // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  868. // // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  869. // // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  870. // // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  871. // // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  872. // // lineWorkingData1.CreateTime = DateTime.Now;
  873. // // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  874. // // // UI展示-展示到设备状态页
  875. // // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  876. // // {
  877. // // // 查询数据库最新一条数据,确定是不是更新
  878. // // string qSql = @"SELECT top(1) [GUID]
  879. // // ,[LineName]
  880. // // ,[BootTimeLong]
  881. // // ,[NormalTimeLong]
  882. // // ,[StandbyTimeLong]
  883. // // ,[FaultTimeLong]
  884. // // ,[MaterialShortageTimeLong]
  885. // // ,[MaintenanceTimeLong]
  886. // // ,[FaultNumber]
  887. // // ,[OutputNumber]
  888. // // ,[QualifiedNumber]
  889. // // ,[QualifiedRate]
  890. // // ,[DesignRhythm]
  891. // // ,[RealityRhythm]
  892. // // ,[CreateTime]
  893. // // FROM [LineWorkingData]
  894. // // where [CreateTime] > '{0}'
  895. // // and [LineName]='{1}'
  896. // // order by [CreateTime] desc
  897. // // ";
  898. // // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  899. // // var ds = SQLHelper_New.Query(qSql, null);
  900. // // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  901. // // {
  902. // // var dataDBlast = new LineWorkingData_ThisTime();
  903. // // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  904. // // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  905. // // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  906. // // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  907. // // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  908. // // {
  909. // // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  910. // // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  911. // // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  912. // // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  913. // // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  914. // // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  915. // // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  916. // // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  917. // // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  918. // // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  919. // // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  920. // // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  921. // // string usql = dataDBlast.ToStringUpdate();
  922. // // SQLHelper_New.ExecuteSQL(usql, null);
  923. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  924. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  925. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  926. // // }
  927. // // }
  928. // // else
  929. // // {
  930. // // // 插入
  931. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  932. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  933. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  934. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  935. // // }
  936. // // }
  937. // // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  938. // // {
  939. // // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  940. // // //// 本次开机设备运行情况
  941. // // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  942. // // //Task.Run(() =>
  943. // // //{
  944. // // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  945. // // // {
  946. // // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  947. // // // }
  948. // // //});
  949. // // // 本日设备运行情况
  950. // // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  951. // // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  952. // // {
  953. // // // 更新
  954. // // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  955. // // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  956. // // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  957. // // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  958. // // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  959. // // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  960. // // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  961. // // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  962. // // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  963. // // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  964. // // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  965. // // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  966. // // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  967. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  968. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  969. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  970. // // }
  971. // // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  972. // // {
  973. // // // 插入
  974. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  975. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  976. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  977. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  978. // // }
  979. // // await Task.Run(() =>
  980. // // {
  981. // // try
  982. // // {
  983. // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  984. // // {
  985. // // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  986. // // }
  987. // // }
  988. // // catch { }
  989. // // });
  990. // // }
  991. // //}
  992. // //catch (Exception ex)
  993. // //{
  994. // // string str = ex.StackTrace;
  995. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  996. // //}
  997. // //#endregion 获取设备运行信息
  998. // #region 报警数据
  999. // try
  1000. // {
  1001. // List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  1002. // bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  1003. // // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  1004. // var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  1005. // for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  1006. // {
  1007. // short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  1008. // dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  1009. // if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  1010. // {
  1011. // isNeedUpdUI = true; // 需要更新历史报警UI信息
  1012. // // 记录
  1013. // dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  1014. // switch (dicAlarms_Cur_PLC1[i].是否报警)
  1015. // {
  1016. // case true: // 报警
  1017. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  1018. // {
  1019. // GUID = Guid.NewGuid().ToString(),
  1020. // LineName = GlobalContext.LineCode, // 线体
  1021. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1022. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1023. // StartTime = dtNow // 开始时间
  1024. // };
  1025. // // 传输到页面
  1026. // deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  1027. // {
  1028. // 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  1029. // 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  1030. // 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  1031. // 开始时间 = dtNow
  1032. // });
  1033. // // 新增到数据库
  1034. // var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  1035. // SaveAlarmDataByDB(stationNameStr, data1, false);
  1036. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1037. // break;
  1038. // case false: // 消除报警
  1039. // if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  1040. // {
  1041. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  1042. // {
  1043. // GUID = Guid.NewGuid().ToString(),
  1044. // LineName = GlobalContext.LineCode, // 线体
  1045. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1046. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1047. // StartTime = dtNow, // 开始时间
  1048. // EndTime = dtNow, // 开始时间
  1049. // PersistTime = 1, // 耗时1s
  1050. // };
  1051. // // 新增
  1052. // var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  1053. // SaveAlarmDataByDB(stationNameStr, data2, false);
  1054. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1055. // }
  1056. // else
  1057. // {
  1058. // dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  1059. // dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  1060. // - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  1061. // // 修改
  1062. // var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  1063. // SaveAlarmDataByDB(stationNameStr, data3, true);
  1064. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1065. // }
  1066. // break;
  1067. // default:
  1068. // break;
  1069. // }
  1070. // }
  1071. // }
  1072. // DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  1073. // // 有新报警则更新
  1074. // if (isNeedUpdUI)
  1075. // {
  1076. // // UI展示 - 展示到设备状态页
  1077. // await Task.Run(() =>
  1078. // {
  1079. // try
  1080. // {
  1081. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  1082. // {
  1083. // Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  1084. // if (Form_Main.formDevAlarm.Visible)
  1085. // {
  1086. // Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  1087. // }
  1088. // }
  1089. // }
  1090. // catch { }
  1091. // });
  1092. // }
  1093. // }
  1094. // catch (Exception ex)
  1095. // {
  1096. // string str = ex.StackTrace;
  1097. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1098. // }
  1099. // #endregion 报警数据
  1100. // UpdatePLCMonitor(1, -2, 1);
  1101. //}
  1102. //else
  1103. //{
  1104. // UpdatePLCMonitor(1, -2, 0);
  1105. //}
  1106. }
  1107. catch (Exception ex)
  1108. {
  1109. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1110. AddMessage_Station(stationNameStr, LogType.Error,
  1111. $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  1112. }
  1113. Thread.Sleep(IntervalAlarm);
  1114. }
  1115. }
  1116. #endregion 轮询PLC
  1117. #region 下发订单信息
  1118. ///// <summary>
  1119. ///// 壳体上料(下发工单)的交互逻辑
  1120. ///// </summary>
  1121. ///// <param name="no"></param>
  1122. ///// <exception cref="NotImplementedException"></exception>
  1123. //private void ReadStation_DownOrderInfo(int plcNo)
  1124. //{
  1125. // // [S1] Tray盘上料装备(板测)
  1126. // // [S2] FCT(板测)
  1127. // // [S3] 值板机
  1128. // // [S4] 取放桁架
  1129. // // [S5] Tray盘下料装备
  1130. // /// 上位机心跳
  1131. // /// 获取设备报警数据与状态信息
  1132. // string stationNameStr = "[S0]壳体上料";
  1133. // while (IsRun)
  1134. // {
  1135. // try
  1136. // {
  1137. // if (!GlobalContext._IsCon_Funs1)
  1138. // {
  1139. // UpdatePLCMonitor(plcNo, 0);
  1140. // continue;
  1141. // }
  1142. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  1143. // {
  1144. // #region 壳体上料(下发工单)
  1145. // try
  1146. // {
  1147. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  1148. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  1149. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  1150. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  1151. // // 重置数据和信号
  1152. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  1153. // {
  1154. // // 清空写给PLC的数据
  1155. // int[] i497 = new int[1] { 0 };
  1156. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  1157. // // MES_Flag重置为0
  1158. // int[] i500 = new int[1] { 0 };
  1159. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  1160. // }
  1161. // }
  1162. // catch (Exception ex)
  1163. // {
  1164. // string str = ex.StackTrace;
  1165. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1166. // }
  1167. // #endregion 壳体上料(下发工单)
  1168. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1169. // }
  1170. // else
  1171. // {
  1172. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1173. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1174. //
  1175. // Funs[plcNo].Connect();
  1176. // }
  1177. // }
  1178. // catch (Exception ex)
  1179. // {
  1180. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1181. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1182. //
  1183. // Funs[plcNo].ReConnect();
  1184. // }
  1185. // Thread.Sleep(IntervalReadPLC);
  1186. // }
  1187. //}
  1188. ///// <summary>
  1189. ///// 下发订单信息到PLC
  1190. ///// </summary>
  1191. ///// <param name="no">PLC编号</param>
  1192. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  1193. //{
  1194. // try
  1195. // {
  1196. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  1197. // {
  1198. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  1199. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  1200. // }
  1201. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  1202. // }
  1203. // catch (Exception ex)
  1204. // {
  1205. // string str = ex.StackTrace;
  1206. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1207. // }
  1208. //}
  1209. /// <summary>
  1210. /// 下发清料信号
  1211. /// </summary>
  1212. /// <param name="no">PLC编号</param>
  1213. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  1214. {
  1215. try
  1216. {
  1217. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  1218. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  1219. return true;
  1220. }
  1221. catch (Exception ex)
  1222. {
  1223. string str = ex.StackTrace;
  1224. AddMessage_Station(stationNameStr, LogType.Error,
  1225. "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  1226. str.Length - str.LastIndexOf("\\") - 1));
  1227. return false;
  1228. }
  1229. }
  1230. #endregion 下发订单信息
  1231. #region Xiaomi 贲流
  1232. #region 公共方法
  1233. private static bool ProgressState = false;
  1234. private static readonly object lockObj = new object(); // 锁对象
  1235. private static bool isCollectingFlagLeft;
  1236. private static bool isCollectingFlagRight;
  1237. private bool OpenDailogFalg = true;//是否开启扫码弹窗标识
  1238. /// <summary>
  1239. /// float[]转为string
  1240. /// </summary>
  1241. public string FloatArrayToString(float[] nScrewResults)
  1242. {
  1243. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1244. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1245. }
  1246. /// <summary>
  1247. /// short[]转为string
  1248. /// </summary>
  1249. public string ShortArrayToString(short[] nScrewResults)
  1250. {
  1251. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1252. return string.Join(",", nScrewResults);
  1253. }
  1254. /// <summary>
  1255. /// 写入PLC重复三次
  1256. /// </summary>
  1257. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount,
  1258. T inObj)
  1259. {
  1260. int i = 0;
  1261. int nRet = 0;
  1262. string strRet = "";
  1263. try
  1264. {
  1265. while (i < 3) // 最多上传三次
  1266. {
  1267. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1268. if (nRet == 0) //成功
  1269. {
  1270. break;
  1271. }
  1272. else
  1273. {
  1274. AddMessage_Station(stationNameStr, LogType.Error,
  1275. $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1276. i++;
  1277. }
  1278. }
  1279. return (nRet, strRet);
  1280. }
  1281. catch (Exception ex)
  1282. {
  1283. return (1, ex.Message);
  1284. }
  1285. }
  1286. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
  1287. short[] nScrewOrders, short[] nScrewResults)
  1288. {
  1289. try
  1290. {
  1291. // 获取当前日期
  1292. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1293. // 构建保存路径
  1294. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1295. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
  1296. // 确保目录存在
  1297. Directory.CreateDirectory(savePath);
  1298. // 文件名
  1299. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1300. string filePath = Path.Combine(savePath, fileName);
  1301. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1302. int count = Math.Min(14, fScrewTimes.Length);
  1303. using (StreamWriter sw = new StreamWriter(filePath))
  1304. {
  1305. for (int i = 0; i < count; i++)
  1306. {
  1307. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1308. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1309. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1310. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1311. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1312. }
  1313. }
  1314. return (0, "");
  1315. }
  1316. catch (Exception ex)
  1317. {
  1318. return (1, ex.Message);
  1319. }
  1320. }
  1321. public Dictionary<string, string> GetLastLineCompensation(string path, string direction, string sn)
  1322. {
  1323. // 创建字典存储补偿点及其对应的值
  1324. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1325. try
  1326. {
  1327. //string path = GlobalContext.MESLaserRPath;
  1328. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1329. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1330. string filename = $"Laser-{currentDate}-W0.txt";
  1331. // 拼接完整路径
  1332. string fullPath = Path.Combine(path, filename);
  1333. string lastNonEmptyLine = "";
  1334. // 判断文件是否存在
  1335. if (File.Exists(fullPath))
  1336. {
  1337. //读取文件内容
  1338. string[] lines = File.ReadAllLines(fullPath);
  1339. // 获取最后一行数据(忽略标题行)
  1340. if (lines.Length > 1)
  1341. {
  1342. string lastLine = "";
  1343. for (int i = lines.Length - 1; i > 0; i--)
  1344. {
  1345. if (!string.IsNullOrEmpty(lines[i]))
  1346. {
  1347. lastLine = lines[i];
  1348. break;
  1349. }
  1350. }
  1351. // 将最后一行按逗号分隔
  1352. string[] values = lastLine.Split(',');
  1353. values[1] = sn;
  1354. string key = "三点激光_" + direction; // 构造键名
  1355. string value = string.Join(",", values); // 获取值并去除多余空格
  1356. compensationDict[key] = value;
  1357. //// 提取“1点补偿”到“6点补偿”的值
  1358. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1359. //{
  1360. // string key = $"{i - 1}点补偿"; // 构造键名
  1361. // string value = values[i].Trim(); // 获取值并去除多余空格
  1362. // compensationDict[key] = value;
  1363. //}
  1364. }
  1365. }
  1366. else
  1367. {
  1368. Console.WriteLine($"文件不存在: {fullPath}");
  1369. }
  1370. }
  1371. catch (Exception ex)
  1372. {
  1373. // 捕获异常并输出错误信息
  1374. Console.WriteLine($"发生错误: {ex.Message}");
  1375. }
  1376. return compensationDict;
  1377. }
  1378. /// <summary>
  1379. /// 调用进站接口并保存进站数据
  1380. /// </summary>
  1381. /// <param name="stationNameStr">工站信息</param>
  1382. /// <param name="workorder_code">工单号</param>
  1383. /// <param name="mtltmrk">型号(物料号)</param>
  1384. /// <param name="sn">产品SN</param>
  1385. /// <param name="items">进站数据</param>
  1386. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1387. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
  1388. List<TestItem> items, string MachineId, string StationId,bool pass)
  1389. {
  1390. int result = 0;
  1391. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1392. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1393. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1394. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1395. inRequest_Body.clientTime =
  1396. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1397. inRequest_Body.unitSn = sn; // 产品SN
  1398. inRequest_Body.uuidInspection = uuid;
  1399. inRequest_Body.state = pass ? "PASS" : "FAIL";
  1400. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1401. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1402. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1403. StationIn stationIn = new StationIn()
  1404. {
  1405. Workorder_code = workorder_code, // 车间订单号
  1406. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1407. Sn = sn, // SN
  1408. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1409. Parameter_values = items, // 进站数据
  1410. Write_user = inRequest_Body.userId, // 员工Id
  1411. Test_time = inRequest_Body.clientTime // 进站时间
  1412. };
  1413. // 本地数据
  1414. string sql = stationIn.ToStringInsert(0);
  1415. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1416. result = ret == "成功" ? 1 : 6;
  1417. //await Task.Delay(200);
  1418. // 上传MES
  1419. if (GlobalContext.IsSendStationIn)
  1420. {
  1421. try
  1422. {
  1423. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1424. string resultJson = "";
  1425. string mesRet = string.Empty;
  1426. int i = 0;
  1427. while (i < 2) // 1009会多次尝试上传
  1428. {
  1429. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1430. resultJson = JsonConvert.SerializeObject(response);
  1431. if (response != null && response.header.code == "200")
  1432. break;
  1433. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1434. i++;
  1435. i++;
  1436. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1437. // 记录失败原因
  1438. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!请求参数:{json_Body},接口报错信息:" + mesRet);
  1439. }
  1440. if (response?.header?.code == "200")
  1441. {
  1442. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1443. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1444. result = ret_Upd == "成功" ? 1 : 6;
  1445. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,请求参数:{json_Body},返回参数:{resultJson}");
  1446. }
  1447. else
  1448. {
  1449. result = 5;
  1450. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!请求参数:{json_Body},接口报错信息:" + mesRet);
  1451. }
  1452. string sql_response =
  1453. stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1454. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1455. }
  1456. catch (Exception ex)
  1457. {
  1458. result = 6;
  1459. string str = ex.StackTrace;
  1460. AddMessage_Station(stationNameStr, LogType.Error,
  1461. $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1462. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1463. }
  1464. }
  1465. #region IOT
  1466. string slot = "01-SLOT-01";
  1467. //过站结果
  1468. if (GlobalContext.IsMqttSendProcessData)
  1469. {
  1470. PassStationResultRequest request = new PassStationResultRequest();
  1471. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1472. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1473. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1474. request.line_code = GlobalContext.LineCode; // 线体编码
  1475. request.work_station = _workstation; // ⼯站ID
  1476. request.device_code = _deviceCode; // 装备编码
  1477. request.station = _stationCode;
  1478. request.process_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1479. request.slot = slot; // 槽位编码
  1480. request.sn = sn; // 产品SN
  1481. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1482. request.enter_status = pass ? "PASS" : "FAIL"; // 进站状态
  1483. request.result = ""; // 出站条件 PASS或FAIL; // 过站结果
  1484. request.work_type = "OUT_STATION"; // 作业类型
  1485. // 上传过站结果
  1486. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1487. if (iotResult.Item1 != 0)
  1488. {
  1489. OnMessage(LogType.Info, $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1490. }
  1491. }
  1492. #endregion
  1493. return result;
  1494. }
  1495. /// <summary>
  1496. /// 选择如何记录出站数据
  1497. /// </summary>
  1498. /// <param name="items">出站数据</param>
  1499. /// <param name="equipmentCode">设备编号</param>
  1500. /// <param name="processItem">测试项目</param>
  1501. /// <param name="workorder_code">车间订单号</param>
  1502. /// <param name="batch_num">批次号</param>
  1503. /// <param name="mtltmrk">型号</param>
  1504. /// <param name="proDate">日期</param>
  1505. /// <param name="supplierCode">供应商代码</param>
  1506. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1507. /// <returns>上传成功时返回1;失败返回0</returns>
  1508. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode,
  1509. string processItem,
  1510. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1511. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode,string jsonParm, string direction="")
  1512. {
  1513. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1514. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm, direction);
  1515. }
  1516. /// <summary>
  1517. /// 添加出站数据(提交到MES+本地保存到数据库)
  1518. /// </summary>
  1519. /// <param name="items">出站数据</param>
  1520. /// <param name="equipmentCode">设备编号</param>
  1521. /// <param name="processItem">测试项目</param>
  1522. /// <param name="workorder_code">车间订单号</param>
  1523. /// <param name="batch_num">批次号</param>
  1524. /// <param name="mtltmrk">型号</param>
  1525. /// <param name="proDate">日期</param>
  1526. /// <param name="supplierCode">供应商代码</param>
  1527. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1528. /// <returns>上传成功时返回1;失败返回0</returns>
  1529. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1530. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1531. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode,string jsonParm,string direction="")
  1532. {
  1533. int upload = 0;
  1534. int result = 0;
  1535. ProcessData processData = new ProcessData()
  1536. {
  1537. Equipment_code = equipmentCode,
  1538. Workorder_code = workorder_code,
  1539. Batch_number = batch_num,
  1540. Sn = sn, // SN
  1541. Testitem = processItem,
  1542. Parameter_values = items,
  1543. Write_user = GlobalContext.CurrentUser,
  1544. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1545. };
  1546. // 本地数据
  1547. string sql = processData.ToStringInsert(upload);
  1548. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1549. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1550. #region MES
  1551. if (GlobalContext.IsSendProcessData)
  1552. {
  1553. try
  1554. {
  1555. string id = processData.ID.Copy();
  1556. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1557. outRequest_Body.uuidInspection = uuid;
  1558. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1559. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1560. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1561. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1562. outRequest_Body.unitSn = sn; // 产品SN
  1563. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1564. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1565. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1566. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1567. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1568. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1569. if (!string.IsNullOrEmpty(partBarcode))
  1570. {
  1571. outRequest_Body.unitData.keyMaterial.Add(
  1572. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1573. {
  1574. bindSort = 1,
  1575. materialSn = partBarcode
  1576. }); // 设备数据 - 部件码
  1577. }
  1578. //OP30站读txt数据
  1579. if (stationNameStr.Contains("CPAPHD"))
  1580. {
  1581. string path = "";
  1582. if (direction == "Left")
  1583. path = GlobalContext.MESLaserLPath;
  1584. else
  1585. path = GlobalContext.MESLaserRPath;
  1586. //字典存储数据
  1587. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction, sn);
  1588. foreach (var kvp in compensationDict)
  1589. {
  1590. outRequest_Body.unitData.processData.Add(
  1591. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1592. {
  1593. dataName = kvp.Key.ToString(),
  1594. dataValue = kvp.Value.ToString()
  1595. });
  1596. }
  1597. }
  1598. //过站明细
  1599. if (GlobalContext.IsSendProcessDetail)
  1600. {
  1601. if (jsonParm.Length > 0)
  1602. {
  1603. // 解析JSON字符串为字典
  1604. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1605. foreach (var kvp in dictionary)
  1606. {
  1607. outRequest_Body.unitData.processData.Add(
  1608. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1609. {
  1610. dataName = kvp.Key.ToString(),
  1611. dataValue = kvp.Value.ToString()
  1612. });
  1613. }
  1614. }
  1615. }
  1616. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1617. if (GlobalContext.IsSendProcessData)
  1618. {
  1619. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1620. string mesRet = string.Empty;
  1621. int i = 0;
  1622. while (i < 2) // 1009会多次尝试上传
  1623. {
  1624. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1625. if (response != null && response.header.code == "200")
  1626. {
  1627. OnMessage(LogType.Info,
  1628. $"【出站数据 SN {sn}】上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
  1629. JsonConvert.SerializeObject(response.body));
  1630. break;
  1631. }
  1632. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1633. i++;
  1634. i++;
  1635. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1636. // 记录失败原因
  1637. OnMessage(LogType.Error, $"【出站数据 SN {sn}】上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1638. }
  1639. if (response?.header?.code == "200")
  1640. {
  1641. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1642. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1643. result = 1;
  1644. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1645. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1646. }
  1647. else
  1648. {
  1649. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1650. }
  1651. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
  1652. JsonConvert.SerializeObject(outRequest_Body),
  1653. JsonConvert.SerializeObject(response), id);
  1654. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1655. }
  1656. }
  1657. catch (Exception ex)
  1658. {
  1659. string str = ex.StackTrace;
  1660. AddMessage_Station(stationNameStr, LogType.Error,
  1661. $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1662. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1663. }
  1664. }
  1665. #endregion
  1666. #region IOT
  1667. string slot = "01-SLOT-01";
  1668. //过站明细
  1669. if (GlobalContext.IsMqttSendProcessData)
  1670. {
  1671. test_item_num += 1;
  1672. PassStationDetailRequest request = new PassStationDetailRequest();
  1673. request.pass_station_id = uuid;
  1674. request.sn = sn; // 产品SN
  1675. request.slot = slot; // 槽位编码
  1676. request.test_item_num = test_item_num.ToString();
  1677. request.function_name = "Machine_加⼯模块";
  1678. request.status = "PASS";
  1679. (int, string) iotResult = (0, "");
  1680. if (jsonParm.Length > 0)
  1681. {
  1682. // 解析JSON字符串为字典
  1683. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1684. foreach (var kvp in dictionary)
  1685. {
  1686. request.test_item = kvp.Key.ToString();
  1687. request.result_val = kvp.Value.ToString();
  1688. request.description = request.test_item;
  1689. // 上传过站明细
  1690. iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  1691. if (iotResult.Item1 != 0)
  1692. {
  1693. OnMessage(LogType.Info, $"【IOT过站明细】上传失败!错误原因:{iotResult.Item2},过站明细;产品码[{sn}] 测试项目[{request.test_item}] 测试值[{request.result_val}]");
  1694. }
  1695. }
  1696. }
  1697. }
  1698. //过站结果
  1699. if (GlobalContext.IsMqttSendProcessData)
  1700. {
  1701. PassStationResultRequest request = new PassStationResultRequest();
  1702. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1703. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1704. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1705. request.line_code = GlobalContext.LineCode; // 线体编码
  1706. request.work_station = _workstation; // ⼯站ID
  1707. request.device_code = _deviceCode; // 装备编码
  1708. request.station = _stationCode;
  1709. request.process_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1710. request.slot = slot; // 槽位编码
  1711. request.sn = sn; // 产品SN
  1712. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1713. request.enter_status = ""; // 进站状态
  1714. request.result = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL; // 过站结果
  1715. request.work_type = "OUT_STATION"; // 作业类型
  1716. // 上传过站结果
  1717. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1718. if (iotResult.Item1 != 0)
  1719. {
  1720. OnMessage(LogType.Info, $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1721. }
  1722. }
  1723. #endregion
  1724. return result;
  1725. }
  1726. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1727. //{
  1728. // Stopwatch stopwatch = new Stopwatch();
  1729. // stopwatch.Start();
  1730. // try
  1731. // {
  1732. // // 初始化 AtlasScrew 实例
  1733. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1734. // atlasScrew1.Initial();
  1735. // // 存储结果的列表
  1736. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1737. // // 存储角度和扭力的字符串列表
  1738. // List<string> angleStrs = new List<string>();
  1739. // List<string> torqueStrs = new List<string>();
  1740. // // 上一次获取的数据
  1741. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1742. // while (isExitAtlasLeft) // 检查是否收集数据
  1743. // {
  1744. // // 获取当前数据
  1745. // var currentResult = atlasScrew1.GetResults();
  1746. // // 判断是否为新数据
  1747. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1748. // {
  1749. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1750. // // 更新角度和扭力的字符串列表
  1751. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1752. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1753. // // 计算角度、扭力、起始扭力和最大扭力
  1754. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1755. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1756. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1757. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1758. // // 将新数据添加到结果列表
  1759. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1760. // // 更新上一次获取的数据
  1761. // lastResult = currentResult;
  1762. // }
  1763. // // 等待一段时间后再次检查
  1764. // Thread.Sleep(20); // 轮询间隔时间
  1765. // // 如果触发了出站,则退出循环
  1766. // if (!isExitAtlasLeft)
  1767. // {
  1768. // break;
  1769. // }
  1770. // }
  1771. // // 生成文件名
  1772. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1773. // // 写入数据到文件
  1774. // using (StreamWriter writer = new StreamWriter(fileName))
  1775. // {
  1776. // // 写入标题行
  1777. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1778. // // 写入每一行数据
  1779. // foreach (var result in results)
  1780. // {
  1781. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1782. // }
  1783. // }
  1784. // stopwatch.Stop();
  1785. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1786. // }
  1787. // catch (Exception ex)
  1788. // {
  1789. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1790. // }
  1791. // finally
  1792. // {
  1793. // // 重置标志变量
  1794. // isExitAtlasLeft = false;
  1795. // }
  1796. //}
  1797. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1798. //{
  1799. // Stopwatch stopwatch = new Stopwatch();
  1800. // stopwatch.Start();
  1801. // try
  1802. // {
  1803. // // 初始化 AtlasScrew 实例
  1804. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1805. // atlasScrew2.Initial();
  1806. // // 存储结果的列表
  1807. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1808. // // 上一次获取的数据
  1809. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1810. // while (isExitAtlasRight) // 检查是否收集数据
  1811. // {
  1812. // // 获取当前数据
  1813. // var currentResult = atlasScrew2.GetResults();
  1814. // // 判断是否为新数据
  1815. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1816. // {
  1817. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1818. // // 将新数据写入PLC
  1819. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1820. // // 将新数据添加到结果列表
  1821. // results.Add(currentResult);
  1822. // // 更新上一次获取的数据
  1823. // lastResult = currentResult;
  1824. // }
  1825. // // 等待一段时间后再次检查
  1826. // Thread.Sleep(20); // 轮询间隔时间
  1827. // // 如果触发了出站,则退出循环
  1828. // if (!isExitAtlasRight)
  1829. // {
  1830. // break;
  1831. // }
  1832. // }
  1833. // // 将所有数据写入文件
  1834. // //WriteDataToFile(sn, direction, results);
  1835. // stopwatch.Stop();
  1836. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1837. // }
  1838. // catch (Exception ex)
  1839. // {
  1840. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1841. // }
  1842. // finally
  1843. // {
  1844. // // 重置标志变量
  1845. // isExitAtlasRight = false;
  1846. // }
  1847. //}
  1848. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1849. {
  1850. Stopwatch stopwatch = new Stopwatch();
  1851. stopwatch.Start();
  1852. int nRet = 0;
  1853. string strRet = "";
  1854. try
  1855. {
  1856. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1857. while (isCollectingFlagLeft)
  1858. {
  1859. // 从缓存中获取所有未处理的数据
  1860. var cachedData = atlasScrew.GetCachedDataLeft();
  1861. foreach (var currentResult in cachedData)
  1862. {
  1863. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1864. {
  1865. continue; // 跳过无效数据
  1866. }
  1867. OnMessage(LogType.Info,
  1868. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1869. // 写入PLC
  1870. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1871. {
  1872. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1873. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1874. };
  1875. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1876. if (nRet != 0)
  1877. {
  1878. OnMessage(LogType.Info,
  1879. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1880. }
  1881. else
  1882. {
  1883. OnMessage(LogType.Info,
  1884. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1885. }
  1886. // 构建保存路径
  1887. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1888. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1889. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1890. Directory.CreateDirectory(savePath); // 确保目录存在
  1891. // 构建文件名(以 SN + 序号命名)
  1892. string fileName = $"{sn}_{fileCounter}.txt";
  1893. string filePath = Path.Combine(savePath, fileName);
  1894. // 写入文件
  1895. using (StreamWriter writer = new StreamWriter(filePath))
  1896. {
  1897. writer.WriteLine("精度, 扭力");
  1898. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1899. for (int i = 0;
  1900. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1901. i++)
  1902. {
  1903. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1904. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1905. writer.WriteLine($"{precision}, {torque}");
  1906. }
  1907. }
  1908. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1909. // 增加文件计数器
  1910. fileCounter++;
  1911. }
  1912. // 如果没有更多数据,则短暂休眠以节省资源
  1913. if (!cachedData.Any())
  1914. {
  1915. Thread.Sleep(10); // 根据需要调整休眠时间
  1916. }
  1917. // 如果触发了出站,则退出循环
  1918. if (!isCollectingFlagLeft)
  1919. {
  1920. break;
  1921. }
  1922. }
  1923. stopwatch.Stop();
  1924. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1925. }
  1926. catch (Exception ex)
  1927. {
  1928. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1929. }
  1930. finally
  1931. {
  1932. isCollectingFlagLeft = false;
  1933. }
  1934. }
  1935. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1936. {
  1937. Stopwatch stopwatch = new Stopwatch();
  1938. stopwatch.Start();
  1939. int nRet = 0;
  1940. string strRet = "";
  1941. try
  1942. {
  1943. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1944. while (isCollectingFlagRight)
  1945. {
  1946. // 从缓存中获取所有未处理的数据
  1947. var cachedData = atlasScrew.GetCachedDataLeft();
  1948. foreach (var currentResult in cachedData)
  1949. {
  1950. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1951. {
  1952. continue; // 跳过无效数据
  1953. }
  1954. OnMessage(LogType.Info,
  1955. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1956. // 写入PLC
  1957. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1958. {
  1959. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1960. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1961. };
  1962. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1963. if (nRet != 0)
  1964. {
  1965. OnMessage(LogType.Info,
  1966. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1967. }
  1968. else
  1969. {
  1970. OnMessage(LogType.Info,
  1971. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1972. }
  1973. // 构建保存路径
  1974. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1975. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1976. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1977. Directory.CreateDirectory(savePath); // 确保目录存在
  1978. // 构建文件名(以 SN + 序号命名)
  1979. string fileName = $"{sn}_{fileCounter}.txt";
  1980. string filePath = Path.Combine(savePath, fileName);
  1981. // 写入文件
  1982. using (StreamWriter writer = new StreamWriter(filePath))
  1983. {
  1984. writer.WriteLine("精度, 扭力");
  1985. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1986. for (int i = 0;
  1987. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1988. i++)
  1989. {
  1990. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1991. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1992. writer.WriteLine($"{precision}, {torque}");
  1993. }
  1994. }
  1995. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1996. // 增加文件计数器
  1997. fileCounter++;
  1998. }
  1999. // 如果没有更多数据,则短暂休眠以节省资源
  2000. if (!cachedData.Any())
  2001. {
  2002. Thread.Sleep(10); // 根据需要调整休眠时间
  2003. }
  2004. // 如果触发了出站,则退出循环
  2005. if (!isCollectingFlagRight)
  2006. {
  2007. break;
  2008. }
  2009. }
  2010. stopwatch.Stop();
  2011. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  2012. }
  2013. catch (Exception ex)
  2014. {
  2015. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  2016. }
  2017. finally
  2018. {
  2019. isCollectingFlagRight = false;
  2020. }
  2021. }
  2022. /// <summary>
  2023. /// 上传文件
  2024. /// </summary>
  2025. /// <param name="BarcodeSet_t">条码集合</param>
  2026. /// <param name="stationCode">工站编号</param>
  2027. /// <param name="stationName">工站名称</param>
  2028. /// <param name="path">文件路径</param>
  2029. public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode, string stationName,string path)
  2030. {
  2031. string sql, filename = "";
  2032. Guid guid;
  2033. int result = 0;
  2034. var formData = new MultipartFormDataContent();
  2035. // 获取所有图片文件
  2036. List<string> imageFiles = GetAllImageFiles(path);
  2037. try
  2038. {
  2039. if (imageFiles.Count>0)
  2040. {
  2041. foreach (string imageFile in imageFiles)
  2042. {
  2043. guid = Guid.NewGuid();
  2044. filename = Path.GetFileName(imageFile);
  2045. sql = string.Format("INSERT INTO [dbo].[DataFiles](stationCode,stationName,CarrierBarcode,ProductBarcode,bucket,fileName,fileContext,uuid,fileUrl,status,submitTime,createTime) " +
  2046. "VALUES('{0}','{1}','{2}' ,'{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')"
  2047. , stationCode
  2048. , stationName
  2049. , BarcodeSet.strCarrierBarcode
  2050. , BarcodeSet.strProductBarcode
  2051. , "/mesCommToPC/pic/left"
  2052. , filename
  2053. , ""
  2054. , guid.ToString()
  2055. , ""
  2056. , 0
  2057. , ""
  2058. , DateTime.Now
  2059. );
  2060. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  2061. FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  2062. string bucket = string.Empty;
  2063. //bucket = "IMAGE/IMAGE/N3/debug/online/PASS/M0002PA-0001/P320N000006B/382f55e9-c2bb";
  2064. bucket = "/mesCommToPC/pic/left";
  2065. fileUpload_X5.bucket = bucket;
  2066. fileUpload_X5.name = filename;
  2067. fileUpload_X5.uuid = guid.ToString();
  2068. ///需要上传文件
  2069. FileInfo file = new FileInfo(imageFile);
  2070. string fileMd5Hex = GetMD5Hex(file);
  2071. fileUpload_X5.md5 = fileMd5Hex;
  2072. fileUpload_X5.uploadCloud = true;
  2073. fileUpload_X5.informMqtt = true;
  2074. FileMqttPayload fileMqttPayload = new FileMqttPayload();
  2075. //fileMqttPayload.factory = "";
  2076. //fileMqttPayload.project_name = "";
  2077. //fileMqttPayload.product_mode = "";
  2078. //fileMqttPayload.line_no = "";
  2079. //fileMqttPayload.work_station_no = "";
  2080. //fileMqttPayload.equipment_no = "";
  2081. //fileMqttPayload.station_no = "";
  2082. //fileMqttPayload.file_id = "";
  2083. //fileMqttPayload.file_name = "";
  2084. //fileMqttPayload.sn = "";
  2085. //fileMqttPayload.opt_time = "";
  2086. //fileMqttPayload.file_type = "";
  2087. //fileMqttPayload.file_category = "";
  2088. //fileMqttPayload.tag = "";
  2089. //fileMqttPayload.pass_station_id = "";
  2090. //FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  2091. //FileMqttPayload fileMqttPayload = new FileMqttPayload();
  2092. //fileUpload_X5.bucket = "IMAGE/IMAGE/N3/debug/online/PASS/M0002PA-0001/P320N000006B/382f55e9-c2bb";
  2093. //fileUpload_X5.name = "test";
  2094. //fileUpload_X5.md5 = "";
  2095. //fileUpload_X5.uploadCloud = true;
  2096. //fileUpload_X5.informMqtt = true;
  2097. var fileresult = XiaomiMESHttp_UpLoadFile.FileUoladToMes(imageFile, fileUpload_X5, fileMqttPayload);
  2098. if (fileresult.Result.Item1 == 0)
  2099. {
  2100. return (1, fileresult.Result.Item2);
  2101. }
  2102. sql = string.Format("UPDATE [dbo].[DataFiles] SET status='{0}' WHERE uuid='{1}'", 1, guid);
  2103. string retnew = SQLHelper_New.ExecuteNonQuery(sql, null);
  2104. return fileresult.Result;
  2105. }
  2106. return (1, "程序错误!");
  2107. }
  2108. else
  2109. {
  2110. return (1,"文件不存在!");
  2111. }
  2112. }
  2113. catch (Exception e)
  2114. {
  2115. return (1, filename + $"图片保存失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" + e.Message);
  2116. //AddMessage_Station(stationName, LogType.Error, filename + $"图片保存失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode}");
  2117. }
  2118. }
  2119. /// <summary>
  2120. /// 获取路径下的所有图片
  2121. /// </summary>
  2122. /// <param name="directoryPath"></param>
  2123. /// <returns></returns>
  2124. public List<string> GetAllImageFiles(string directoryPath)
  2125. {
  2126. var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
  2127. var imageFiles = new List<string>();
  2128. try
  2129. {
  2130. // 遍历目录及子目录中的所有文件
  2131. foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
  2132. {
  2133. // 获取文件扩展名并检查是否为图片格式
  2134. string extension = Path.GetExtension(file);
  2135. if (imageExtensions.Contains(extension))
  2136. {
  2137. imageFiles.Add(file);
  2138. }
  2139. }
  2140. }
  2141. catch (Exception ex)
  2142. {
  2143. OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
  2144. }
  2145. return imageFiles;
  2146. }
  2147. /// <summary>
  2148. /// 实例化报警字典
  2149. /// </summary>
  2150. private (bool, string) InitalDicAlarm()
  2151. {
  2152. #region 加载报警表
  2153. string excelPath = "";
  2154. switch (GlobalContext.IsUsePLCNow)
  2155. {
  2156. case 1:
  2157. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_10_壳体清洁上料.xlsx";
  2158. break;
  2159. case 2:
  2160. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_20_上盖板上料装备.xlsx";
  2161. break;
  2162. case 3:
  2163. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_30_点散热胶装备.xlsx";
  2164. break;
  2165. case 4:
  2166. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_40_胶线检测.xlsx";
  2167. break;
  2168. case 5:
  2169. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_50_ADD板上料组装装备.xlsx";
  2170. break;
  2171. case 6:
  2172. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_60_组上盖板.xlsx";
  2173. break;
  2174. case 7:
  2175. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_70_上盖板锁螺丝.xlsx";
  2176. break;
  2177. case 8:
  2178. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_80_NG下料.xlsx";
  2179. break;
  2180. case 9:
  2181. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_90_半成品下料.xlsx";
  2182. break;
  2183. default:
  2184. return (false, $"不支持当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请在设置页切换到正确的plc后重启该软件!");
  2185. }
  2186. if (!File.Exists(excelPath))
  2187. return (false, $"未找到当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请检查文件路径:'{excelPath}'。");
  2188. DataTable DtModel = NPOIHelper.ReadExcel(excelPath);
  2189. if (DtModel == null || DtModel.Rows.Count < 1)
  2190. return (false, $"报警点位表未包含任何报警数据!请检查‘{excelPath}’文件!");
  2191. // 检查列名
  2192. List<string> isNeedParms = new List<string>() {"设备分类名称","设备分类编码","分类层级1","分类层级2","分类层级3" ,"分类层级4","事件名称"
  2193. ,"事件ID","描述","标签","PLC地址","工位"}; // 必须要有的列
  2194. // 指定列名 + 检查列是否完整
  2195. DataRow dtRowName = DtModel.Rows[0];
  2196. int count = DtModel.Columns.Count;
  2197. for (int i = 0; i < count; i++)
  2198. {
  2199. string columeName = dtRowName[i]?.ToString();
  2200. if (!string.IsNullOrEmpty(columeName))
  2201. DtModel.Columns[i].ColumnName = columeName;
  2202. if ((!string.IsNullOrEmpty(columeName)) && isNeedParms.Count > 0 && isNeedParms.Contains(columeName))
  2203. isNeedParms.Remove(columeName);
  2204. }
  2205. DtModel.Rows.RemoveAt(0);
  2206. if (isNeedParms.Count > 0)
  2207. {
  2208. string msg1 = string.Join(",", isNeedParms);
  2209. return (false, $"报警点位表未包含列:{msg1}!请检查‘{excelPath}’文件!");
  2210. }
  2211. #endregion 加载报警表
  2212. List<Alarm> keyValues1 = new List<Alarm>();
  2213. for (int i = 0; i < DtModel.Rows.Count; i++)
  2214. {
  2215. Alarm alarm = new Alarm();
  2216. alarm.plcName = DtModel.Rows[i]["设备分类名称"]?.ToString(); // 设备名;
  2217. string type1Str = DtModel.Rows[i]["分类层级1"]?.ToString(); // 分类层级1;
  2218. alarm.type1CH = type1Str; // 分类层级1 中文
  2219. alarm.type1 = type1Str; // 分类层级1
  2220. if (!string.IsNullOrEmpty(type1Str) && type1Str.Contains("\n"))
  2221. {
  2222. string[] type1Strs = type1Str.Split('\n');
  2223. if (type1Strs.Length >= 2)
  2224. {
  2225. alarm.type1CH = type1Strs[0].Trim(); // 分类层级1 中文
  2226. alarm.type1 = type1Strs[1].Trim(); // 分类层级1
  2227. if (string.IsNullOrEmpty(alarm.type1))
  2228. alarm.type1 = alarm.type1CH;
  2229. }
  2230. }
  2231. string type2Str = DtModel.Rows[i]["分类层级2"]?.ToString(); // 分类层级2;电气控制 electric_control
  2232. alarm.type2CH = type2Str; // 分类层级2 中文
  2233. alarm.type2 = type2Str; // 分类层级2
  2234. if (!string.IsNullOrEmpty(type2Str) && type2Str.Contains("\n"))
  2235. {
  2236. string[] type2Strs = type2Str.Split('\n');
  2237. if (type2Strs.Length >= 2)
  2238. {
  2239. alarm.type2CH = type2Strs[0].Trim(); // 分类层级2 中文
  2240. alarm.type2 = type2Strs[1].Trim(); // 分类层级2
  2241. if (string.IsNullOrEmpty(alarm.type2))
  2242. alarm.type2 = alarm.type2CH;
  2243. }
  2244. }
  2245. string type3Str = DtModel.Rows[i]["分类层级3"]?.ToString(); // 分类层级3;故障 Fault
  2246. alarm.type3CH = type3Str; // 分类层级3 中文
  2247. alarm.type3 = type3Str; // 分类层级3
  2248. if (!string.IsNullOrEmpty(type3Str) && type3Str.Contains("\n"))
  2249. {
  2250. string[] type3Strs = type3Str.Split('\n');
  2251. if (type3Strs.Length >= 2)
  2252. {
  2253. alarm.type3CH = type3Strs[0].Trim(); // 分类层级3 中文
  2254. alarm.type3 = type3Strs[1].Trim(); // 分类层级3
  2255. if (string.IsNullOrEmpty(alarm.type3))
  2256. alarm.type3 = alarm.type3CH;
  2257. }
  2258. }
  2259. string faultStr = DtModel.Rows[i]["分类层级4"]?.ToString(); // 故障部件;overall_module
  2260. alarm.type4 = faultStr; // 分类层级4 中文
  2261. alarm.type4CH = faultStr; // 分类层级4
  2262. if (!string.IsNullOrEmpty(faultStr) && faultStr.Contains("\n"))
  2263. {
  2264. string[] faultStrs = faultStr.Split('\n');
  2265. if (faultStrs.Length >= 2)
  2266. {
  2267. alarm.type4CH = faultStrs[0].Trim(); // 故障部件;overall_module
  2268. alarm.type4 = faultStrs[1].Trim(); // 故障部件
  2269. if (string.IsNullOrEmpty(alarm.type4))
  2270. alarm.type4 = alarm.type4CH;
  2271. }
  2272. }
  2273. alarm.fault_code = DtModel.Rows[i]["事件ID"]?.ToString(); // 故障编码;A40001
  2274. alarm.fault_name = DtModel.Rows[i]["事件名称"]?.ToString(); // 故障名称;AL[1000]_系统_HMI急停故障
  2275. alarm.fault_desc = alarm.fault_name; // 故障描述;AL[1000]_系统_HMI急停故障
  2276. string plcAdress = DtModel.Rows[i]["PLC地址"]?.ToString();
  2277. alarm.PLC地址 = plcAdress;
  2278. plcAdress = plcAdress.Replace("fault_codes[", "");
  2279. plcAdress = plcAdress.Replace("]", "");
  2280. alarm.group_index = Convert.ToInt32(plcAdress.Split(".")[0]);
  2281. keyValues1.Add(alarm);
  2282. }
  2283. DicAlarms_Cur.Add(GlobalContext.IsUseStationName, keyValues1); // 这里使用线体代替工位
  2284. return (true, "报警字典表初始化成功!");
  2285. }
  2286. private async void ReadPLCAlarmToIot(uint[] FaultData,string stationNameStr)
  2287. {
  2288. DateTime dtNow = DateTime.Now;
  2289. try
  2290. {
  2291. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  2292. List<(int, int)> AlarmIndexList = new List<(int, int)>();//收集所有报警信息的位置
  2293. AlarmData alarmData = new AlarmData();
  2294. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  2295. bool isNoAlarm = false;//是否有报警
  2296. string binaryString = "";
  2297. bool isNoNewAlarm = false;//是否有新的报警
  2298. if (FaultData.Length > 0)
  2299. {
  2300. }
  2301. foreach (var item in FaultData)
  2302. {
  2303. isNoAlarm = item > 0 ? true : false;
  2304. }
  2305. if (!FaultData.SequenceEqual(_FaultDatas_Old))
  2306. {
  2307. isNoNewAlarm = true;
  2308. isNeedUpdUI = true;
  2309. }
  2310. if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
  2311. {
  2312. //解析报警信息,分析当前报警在字典中的定位
  2313. for (int i = 0; i <= FaultData.Length - 1; i++)
  2314. {
  2315. var num = 0;
  2316. if (FaultData[i] > 0)
  2317. {
  2318. //转换二进制
  2319. binaryString = Convert.ToString(FaultData[i], 2);
  2320. for (int j = binaryString.Length - 1; j >= 0; j--)
  2321. {
  2322. num++;
  2323. char s = binaryString[j];
  2324. if (binaryString[j] == '1')
  2325. {
  2326. //记录1的位置
  2327. AlarmIndexList.Add((i, num - 1));
  2328. }
  2329. }
  2330. }
  2331. }
  2332. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  2333. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
  2334. foreach ((int index, int row) in AlarmIndexList)
  2335. {
  2336. var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
  2337. for (int i = 0; i < tempDic.Count - 1; i++) // 读取
  2338. {
  2339. //若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
  2340. if (tempDic[i].group_index == index && i == row)
  2341. {
  2342. dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 = new AlarmData()
  2343. {
  2344. GUID = Guid.NewGuid().ToString(),
  2345. LineName = GlobalContext.IsUseStationName, // 工站
  2346. PlcStation = tempDic[i].plcName, // 工站全称;[S1]
  2347. Type1 = tempDic[i].type1, // 故障层级1
  2348. Type2 = tempDic[i].type2, // 故障层级2
  2349. Type3 = tempDic[i].type3, // 故障层级3
  2350. Type4 = tempDic[i].type4, // 故障层级4
  2351. AlarmType = tempDic[i].fault_code, // 报警类型
  2352. AlarmDesc = tempDic[i].fault_name, // 报警内容
  2353. StartTime = dtNow // 开始时间
  2354. };
  2355. // 传输到页面
  2356. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  2357. {
  2358. 线体名称 = tempDic[i].plcName,
  2359. 报警类型 = tempDic[i].fault_code,
  2360. 报警内容 = tempDic[i].fault_name,
  2361. 开始时间 = dtNow
  2362. });
  2363. // 新增到数据库
  2364. //var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
  2365. //SaveAlarmDataByDB(stationNameStr, data1, false);
  2366. //OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
  2367. }
  2368. }
  2369. }
  2370. //筛选含报警数据的字典
  2371. var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
  2372. if (dicAlarms_Cur.Count > 0)
  2373. {
  2374. foreach (var item in dicAlarms_Cur)
  2375. {
  2376. //上传
  2377. SaveAlarmDataByDB(GlobalContext.IsUseStationName, item.报警数据, false);
  2378. }
  2379. }
  2380. // 有新报警则更新
  2381. if (isNeedUpdUI)
  2382. // UI展示 - 展示到设备状态页
  2383. await Task.Run(() =>
  2384. {
  2385. try
  2386. {
  2387. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  2388. {
  2389. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  2390. if (Form_Main.formDevAlarm.Visible)
  2391. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  2392. }
  2393. }
  2394. catch { }
  2395. });
  2396. _FaultDatas_Old = FaultData.ToArray();
  2397. }
  2398. //FaultLogRequest request = new FaultLogRequest();
  2399. //request.station = mesStation; // 工位
  2400. //request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
  2401. //request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
  2402. //request.fault_cmpnt = xmFaultCmpnt; // 故障部件
  2403. //request.fault_desc = xmFaultDesc; // 故障描述
  2404. //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发生时间 2022-06-01 14:27:57.283
  2405. // // 上传
  2406. //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
  2407. }
  2408. catch (Exception ex)
  2409. {
  2410. string str = ex.StackTrace;
  2411. AddMessage_Station(stationNameStr, LogType.Error, $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2412. }
  2413. }
  2414. public void operateToIot(string action, string stationNameStr)
  2415. {
  2416. OperateLogRequest request = new OperateLogRequest();
  2417. request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
  2418. request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
  2419. request.operate_action = action; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
  2420. //request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
  2421. request.current_process = Application.ProductName;
  2422. request.operate_desc = stationNameStr; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
  2423. request.operate_result = "success"; // 操作结果
  2424. request.operator_name = "default"; // 操作账号名;填当前操作⽤⼾,如⽆则填default
  2425. // 上传
  2426. (int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
  2427. if (iotResult.Item1 != 0)
  2428. {
  2429. AddMessage(LogType.Info, "【操作记录】上传失败!错误原因:"+ iotResult.Item2+"操作状态:"+stationNameStr);
  2430. }
  2431. }
  2432. #endregion
  2433. #region S1
  2434. /// <summary>
  2435. /// [S1] 壳体清洁上料装备
  2436. /// </summary>
  2437. /// <param name="plcNo">PLC编号</param>
  2438. private void ReadStation_S1(int plcNo)
  2439. {
  2440. string stationCode = "[OP10]";
  2441. string stationName = "壳体清洁上料";
  2442. string stationNameStr = stationCode + stationName;
  2443. string tagBaseName = "g_OP10_MES"; //标签变量名称
  2444. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2445. string tagAgvCommName = "agvCommFrmPC";
  2446. string tagBarsetName = "BarcodeSet";
  2447. // 触发信号字典
  2448. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2449. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2450. // PLC数据字典 赋值
  2451. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2452. s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  2453. s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  2454. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  2455. (int, string) result;
  2456. while (true)
  2457. {
  2458. try
  2459. {
  2460. if (!GlobalContext._IsCon_Funs1)
  2461. {
  2462. UpdatePLCMonitor(1, plcNo, 0);
  2463. continue;
  2464. }
  2465. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2466. {
  2467. Stopwatch stopwatch1 = new Stopwatch();
  2468. Stopwatch stopwatch2 = new Stopwatch();
  2469. stopwatch1.Start();
  2470. stopwatch2.Start();
  2471. #region 一次性读取所有数据
  2472. // 一次性读取所有数据
  2473. result = FunsEip[plcNo]
  2474. .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2475. if (result.Item1 != 0)
  2476. {
  2477. //richTextBox1.AppendText("\n" + strRet);
  2478. }
  2479. else
  2480. {
  2481. //richTextBox1.AppendText("\n" + "读取成功");
  2482. //设备状态
  2483. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2484. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2485. ? XiaomiDeviceState.Unknown
  2486. : (XiaomiDeviceState)xmDeviceStateInt;
  2487. // 物料码(物料码还未绑定载具SN时必填)
  2488. s1PLCData["a1OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode;
  2489. // 载具SN
  2490. s1PLCData["a1OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode;
  2491. // 节拍
  2492. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.BeatAction;
  2493. //报警信息
  2494. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  2495. }
  2496. #endregion 一次性读取所有数据
  2497. stopwatch2.Stop();
  2498. #region 进站
  2499. try
  2500. {
  2501. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2502. {
  2503. lock (lockObj)
  2504. {
  2505. if (!ProgressState)
  2506. {
  2507. uuid = Guid.NewGuid().ToString();
  2508. ProgressState = true;
  2509. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
  2510. tagBaseName + "." + tagMesCommName, out ProgressState));
  2511. }
  2512. }
  2513. }
  2514. }
  2515. catch (Exception ex)
  2516. {
  2517. ProgressState = false;
  2518. string str = ex.StackTrace;
  2519. AddMessage_Station(stationNameStr, LogType.Error,
  2520. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2521. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2522. }
  2523. #endregion 进站
  2524. #region 出站
  2525. try
  2526. {
  2527. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2528. {
  2529. lock (lockObj)
  2530. {
  2531. if (!ProgressState)
  2532. {
  2533. ProgressState = true;
  2534. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
  2535. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2536. out ProgressState));
  2537. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2538. uuid = "";
  2539. }
  2540. }
  2541. }
  2542. }
  2543. catch (Exception ex)
  2544. {
  2545. ProgressState = false;
  2546. string str = ex.StackTrace;
  2547. AddMessage_Station(stationNameStr, LogType.Error,
  2548. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2549. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2550. }
  2551. #endregion 出站
  2552. #region 节拍接口
  2553. try
  2554. {
  2555. int a10EEType = (int)s1PLCData["a10EEType"];
  2556. int a10EETypeGOld = (int)s1PLCSignal_Old["a10EEType"];
  2557. //若设备紧急复原后节拍重置
  2558. if (a10EEType == 1)
  2559. {
  2560. a10EETypeGOld = 0;
  2561. }
  2562. if (a10EEType != a10EETypeGOld)
  2563. {
  2564. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  2565. if ((a10EETypeGOld == 1 && a10EEType != 2) || (a10EETypeGOld == 3 && a10EEType != 4) ||
  2566. (a10EETypeGOld == 5 && a10EEType != 6))
  2567. {
  2568. //写入PLC
  2569. stPLC_MesData.iotData.beatReturn = 2; //NG
  2570. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  2571. AddMessage(LogType.Info,
  2572. stationNameStr +
  2573. $"_节拍接口-- 设备本次上传节拍[{a10EEType}],未上传节拍[{a10EETypeGOld}]的结束信号,请检查;总用时" +
  2574. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  2575. "ms");
  2576. return;
  2577. }
  2578. else
  2579. {
  2580. Task.Run(() =>
  2581. S1节拍接口(plcNo, stationNameStr, tagBaseName,
  2582. stPLC_MesData.iotData)); // MreTasks[4].Set();
  2583. }
  2584. s1PLCSignal_Old["a10EEType"] = s1PLCData["a10EEType"];
  2585. }
  2586. }
  2587. catch (Exception ex)
  2588. {
  2589. string str = ex.StackTrace;
  2590. AddMessage_Station(stationNameStr, LogType.Error,
  2591. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2592. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2593. }
  2594. #endregion
  2595. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2596. stopwatch1.Stop();
  2597. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2598. }
  2599. else
  2600. {
  2601. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2602. AddMessage_Station(stationNameStr, LogType.Info,
  2603. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2604. FunsEip[plcNo].Connect(); // 重连
  2605. }
  2606. }
  2607. catch (Exception ex)
  2608. {
  2609. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2610. AddMessage_Station(stationNameStr, LogType.Error,
  2611. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2612. }
  2613. Thread.Sleep(IntervalReadPLC);
  2614. }
  2615. }
  2616. /// <summary>
  2617. /// [S1] 壳体清洁上料 - 进站
  2618. /// </summary>
  2619. /// <param name="plcNo">PLC编号</param>
  2620. /// <param name="stationNameStr">工站全称</param>
  2621. /// <param name="stPLC_MesData"></param>
  2622. /// <param name="tagMesCommName"></param>
  2623. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2624. out bool ProgressState)
  2625. {
  2626. Stopwatch stopwatch1 = new Stopwatch();
  2627. Stopwatch stopwatch2 = new Stopwatch();
  2628. try
  2629. {
  2630. stopwatch1.Start();
  2631. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2632. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  2633. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2634. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  2635. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  2636. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2637. bool pass = a1Result == 1;
  2638. if (string.IsNullOrEmpty(sn))
  2639. {
  2640. ProgressState = false;
  2641. return;
  2642. }
  2643. //正式生产就用PLC中取的
  2644. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  2645. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  2646. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2647. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2648. //绑定载具和产品
  2649. ResponseMessage message = new ResponseMessage();
  2650. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  2651. if (message.result == false)
  2652. {
  2653. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  2654. }
  2655. // 产品SN进站
  2656. List<TestItem> item = new List<TestItem>();
  2657. stopwatch2.Start();
  2658. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  2659. item, MachineId, StationId,pass);
  2660. stopwatch2.Stop();
  2661. //指令执行结果 1:OK 110:失败
  2662. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2663. if (mesResultFrmWeb==1)
  2664. {
  2665. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  2666. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  2667. }
  2668. //进站结果写入PLC
  2669. CommandFromPLC resultToPlC = new CommandFromPLC();
  2670. resultToPlC.cmd = 0;
  2671. resultToPlC.cmdParam = 0;
  2672. resultToPlC.cmdResult = mesResultFrmWeb;
  2673. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2674. }
  2675. catch (Exception ex)
  2676. {
  2677. string str = ex.StackTrace;
  2678. AddMessage(LogType.Error,
  2679. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  2680. str.Length - str.LastIndexOf("\\") - 1));
  2681. CommandFromPLC resultToPlC = new CommandFromPLC();
  2682. resultToPlC.cmd = 0;
  2683. resultToPlC.cmdParam = 0; //指令参数
  2684. resultToPlC.cmdResult = 110;
  2685. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2686. }
  2687. stopwatch1.Stop();
  2688. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2689. AddMessage(LogType.Info,
  2690. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  2691. stopwatch2.ElapsedMilliseconds + "ms");
  2692. ProgressState = false;
  2693. }
  2694. /// <summary>
  2695. /// [S1] 壳体清洁上料 - 出站接口
  2696. /// </summary>
  2697. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2698. string stationCode, string stationName, out bool ProgressState)
  2699. {
  2700. Stopwatch stopwatch1 = new Stopwatch();
  2701. Stopwatch stopwatch2 = new Stopwatch();
  2702. test_item_num = 0;//iot 过站明细序号
  2703. try
  2704. {
  2705. stopwatch1.Start();
  2706. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2707. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2708. string processItem = stationName; // 项目
  2709. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2710. string supplierCode = ""; // 供应商代码
  2711. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  2712. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  2713. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  2714. string sn = string.Empty;
  2715. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2716. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  2717. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  2718. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2719. //a1Result = 1;
  2720. bool pass = a1Result == 1;
  2721. //根据载具码获取产品码
  2722. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2723. if (string.IsNullOrEmpty(strProductBarcode))
  2724. {
  2725. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2726. }
  2727. sn = strProductBarcode;
  2728. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2729. List<TestItem> items = new List<TestItem>();
  2730. items.Add(new TestItem()
  2731. {
  2732. Parameter_name = "载具码",
  2733. Parameter_value = CarrierBarcode,
  2734. Parameter_unit = ""
  2735. });
  2736. items.Add(new TestItem()
  2737. {
  2738. Parameter_name = "产品码",
  2739. Parameter_value = sn,
  2740. Parameter_unit = ""
  2741. });
  2742. #region 转换过站明细字符串
  2743. //创建字典
  2744. var dic = new Dictionary<string, string>();
  2745. // 获取结构体类型
  2746. FieldInfo[] fields = typeof(OP10_DataSet_t).GetFields();
  2747. // 遍历变量名转换成字典描述
  2748. foreach (FieldInfo field in fields)
  2749. {
  2750. //获取枚举描述
  2751. string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name, typeof(XiaomiMESEnum_ProcessData.Enum_10_ProcessData));
  2752. //获取过站明细的值
  2753. object valueObj = field.GetValue(stPLC_MesData.mesData);
  2754. dic.Add(name, valueObj.ToString());
  2755. }
  2756. string paramJson = JsonConvert.SerializeObject(dic);
  2757. #endregion
  2758. //出站接口
  2759. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2760. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  2761. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2762. if (mesResultFrmWeb == 1)
  2763. {
  2764. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  2765. AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
  2766. }
  2767. stopwatch2.Start();
  2768. //进站结果写入PLC
  2769. CommandFromPLC resultToPlC = new CommandFromPLC();
  2770. resultToPlC.cmd = 0;
  2771. resultToPlC.cmdParam = 0; //指令参数
  2772. resultToPlC.cmdResult = mesResultFrmWeb;
  2773. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2774. stopwatch2.Stop();
  2775. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2776. //保存PLC返回MES数据到本地
  2777. ResponseMessage message = new ResponseMessage();
  2778. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  2779. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
  2780. stPLC_MesData.mesData.fCleanSpeed,
  2781. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
  2782. stPLC_MesData.mesData.nCleanCount,
  2783. stPLC_MesData.mesData.nRemainCount);
  2784. if (message.result == false)
  2785. {
  2786. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2787. }
  2788. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  2789. }
  2790. catch (Exception ex)
  2791. {
  2792. stopwatch2.Start();
  2793. CommandFromPLC resultToPlC = new CommandFromPLC();
  2794. resultToPlC.cmd = 0;
  2795. resultToPlC.cmdParam = 0; //指令参数
  2796. resultToPlC.cmdResult = 110;
  2797. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2798. stopwatch2.Stop();
  2799. string str = ex.StackTrace;
  2800. AddMessage(LogType.Error,
  2801. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  2802. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2803. }
  2804. stopwatch1.Stop();
  2805. AddMessage(LogType.Info,
  2806. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  2807. stopwatch2.ElapsedMilliseconds + "ms");
  2808. ProgressState = false;
  2809. }
  2810. #endregion
  2811. #region S2
  2812. /// <summary>
  2813. /// [S2] 上盖板上料装备
  2814. /// </summary>
  2815. /// <param name="plcNo">PLC编号</param>
  2816. private void ReadStation_S2(int plcNo)
  2817. {
  2818. string stationCode = "[OP20]";
  2819. string stationName = "上盖板上料装备";
  2820. string stationNameStr = stationCode + stationName;
  2821. string tagBaseName = "g_OP20_MES"; //标签变量名称
  2822. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2823. string tagAgvCommName = "agvCommFrmPC";
  2824. string tagBarsetName = "BarcodeSet";
  2825. // 触发信号字典
  2826. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2827. s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
  2828. // PLC数据字典 赋值
  2829. s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
  2830. s2PLCData.Add("a2OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  2831. s2PLCData.Add("a2OEEVehicleCode", ""); // 载具SN
  2832. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  2833. IoT_DataSet_t iot_data;
  2834. (int, string) result;
  2835. while (true)
  2836. {
  2837. try
  2838. {
  2839. if (!GlobalContext._IsCon_Funs2)
  2840. {
  2841. UpdatePLCMonitor(1, plcNo, 0);
  2842. continue;
  2843. }
  2844. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2845. {
  2846. Stopwatch stopwatch1 = new Stopwatch();
  2847. Stopwatch stopwatch2 = new Stopwatch();
  2848. stopwatch1.Start();
  2849. stopwatch2.Start();
  2850. #region 一次性读取所有数据
  2851. // 一次性读取所有数据
  2852. result = FunsEip[plcNo]
  2853. .Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2854. if (result.Item1 != 0)
  2855. {
  2856. //richTextBox1.AppendText("\n" + strRet);
  2857. }
  2858. else
  2859. {
  2860. //richTextBox1.AppendText("\n" + "读取成功");
  2861. //设备状态
  2862. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2863. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2864. ? XiaomiDeviceState.Unknown
  2865. : (XiaomiDeviceState)xmDeviceStateInt;
  2866. s2PLCData["a2OEEPartNo"] =
  2867. stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  2868. s2PLCData["a2OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  2869. s2PLCData["a2OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  2870. }
  2871. #endregion 一次性读取所有数据
  2872. stopwatch2.Stop();
  2873. #region 进站
  2874. try
  2875. {
  2876. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2877. {
  2878. lock (lockObj)
  2879. {
  2880. if (!ProgressState)
  2881. {
  2882. ProgressState = true;
  2883. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
  2884. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  2885. out ProgressState));
  2886. }
  2887. }
  2888. }
  2889. }
  2890. catch (Exception ex)
  2891. {
  2892. ProgressState = false;
  2893. string str = ex.StackTrace;
  2894. AddMessage_Station(stationNameStr, LogType.Error,
  2895. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2896. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2897. }
  2898. #endregion 进站
  2899. #region 出站
  2900. try
  2901. {
  2902. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2903. {
  2904. lock (lockObj)
  2905. {
  2906. if (!ProgressState)
  2907. {
  2908. ProgressState = true;
  2909. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
  2910. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2911. out ProgressState));
  2912. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2913. }
  2914. }
  2915. }
  2916. }
  2917. catch (Exception ex)
  2918. {
  2919. ProgressState = false;
  2920. string str = ex.StackTrace;
  2921. AddMessage_Station(stationNameStr, LogType.Error,
  2922. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2923. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2924. }
  2925. #endregion 出站
  2926. #region 节拍接口
  2927. try
  2928. {
  2929. int a20EEType = (int)s2PLCData["a20EEType"];
  2930. int a20EETypeGOld = (int)s2PLCSignal_Old["a20EEType"];
  2931. //若设备紧急复原后节拍重置
  2932. if (a20EEType == 1)
  2933. {
  2934. a20EETypeGOld = 0;
  2935. }
  2936. if (a20EEType != a20EETypeGOld)
  2937. {
  2938. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  2939. if ((a20EETypeGOld == 1 && a20EEType != 2) || (a20EETypeGOld == 3 && a20EEType != 4) ||
  2940. (a20EETypeGOld == 5 && a20EEType != 6))
  2941. {
  2942. //写入PLC
  2943. stPLC_MesData.iotData.beatReturn = 2; //NG
  2944. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  2945. AddMessage(LogType.Info,
  2946. stationNameStr +
  2947. $"_节拍接口-- 设备本次上传节拍[{a20EEType}],未上传节拍[{a20EETypeGOld}]的结束信号,请检查;总用时" +
  2948. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  2949. "ms");
  2950. return;
  2951. }
  2952. else
  2953. {
  2954. Task.Run(() =>
  2955. S2节拍接口(plcNo, stationNameStr, tagBaseName,
  2956. stPLC_MesData.iotData)); // MreTasks[4].Set();
  2957. }
  2958. s2PLCSignal_Old["a20EEType"] = s2PLCData["a20EEType"];
  2959. }
  2960. }
  2961. catch (Exception ex)
  2962. {
  2963. string str = ex.StackTrace;
  2964. AddMessage_Station(stationNameStr, LogType.Error,
  2965. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2966. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2967. }
  2968. #endregion
  2969. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2970. stopwatch1.Stop();
  2971. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2972. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2973. }
  2974. else
  2975. {
  2976. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2977. AddMessage_Station(stationNameStr, LogType.Info,
  2978. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2979. FunsEip[plcNo].Connect();
  2980. }
  2981. }
  2982. catch (Exception ex)
  2983. {
  2984. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2985. AddMessage_Station(stationNameStr, LogType.Error,
  2986. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2987. //Funs[plcNo].ReConnect();
  2988. }
  2989. Thread.Sleep(IntervalReadPLC);
  2990. }
  2991. }
  2992. /// <summary>
  2993. /// [S2] 上盖板上料装备
  2994. /// </summary>
  2995. /// <param name="plcNo">PLC编号</param>
  2996. /// <param name="stationNameStr">工站全称</param>
  2997. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  2998. string tagBarsetName, out bool ProgressState)
  2999. {
  3000. Stopwatch stopwatch1 = new Stopwatch();
  3001. Stopwatch stopwatch2 = new Stopwatch();
  3002. try
  3003. {
  3004. stopwatch1.Start();
  3005. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3006. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  3007. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3008. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3009. bool pass = a1Result == 1;
  3010. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  3011. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  3012. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3013. //根据载具码获取产品码
  3014. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3015. if (string.IsNullOrEmpty(strProductBarcode))
  3016. {
  3017. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3018. }
  3019. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  3020. //if (sn != strProductBarcode)
  3021. //{
  3022. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  3023. //}
  3024. sn = strProductBarcode;
  3025. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3026. // 产品SN(物料码)校验
  3027. List<TestItem> item = new List<TestItem>();
  3028. stopwatch2.Start();
  3029. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3030. item, MachineId, StationId,pass);
  3031. stopwatch2.Stop();
  3032. //指令执行结果 1:OK 110:失败
  3033. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3034. if (mesResultFrmWeb == 1)
  3035. {
  3036. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3037. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3038. }
  3039. //进站结果写入PLC
  3040. CommandFromPLC resultToPlC = new CommandFromPLC();
  3041. resultToPlC.cmd = 0;
  3042. resultToPlC.cmdParam = 0; //指令参数
  3043. resultToPlC.cmdResult = mesResultFrmWeb;
  3044. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3045. }
  3046. catch (Exception ex)
  3047. {
  3048. string str = ex.StackTrace;
  3049. AddMessage(LogType.Error,
  3050. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3051. str.Length - str.LastIndexOf("\\") - 1));
  3052. CommandFromPLC resultToPlC = new CommandFromPLC();
  3053. resultToPlC.cmd = 0;
  3054. resultToPlC.cmdParam = 0; //指令参数
  3055. resultToPlC.cmdResult = 110;
  3056. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3057. }
  3058. stopwatch1.Stop();
  3059. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3060. AddMessage(LogType.Info,
  3061. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3062. stopwatch2.ElapsedMilliseconds + "ms");
  3063. ProgressState = false;
  3064. }
  3065. /// <summary>
  3066. /// [S2] 上盖板上料装备 - 出站接口
  3067. /// </summary>
  3068. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3069. string stationCode, string stationName, out bool ProgressState)
  3070. {
  3071. Stopwatch stopwatch1 = new Stopwatch();
  3072. Stopwatch stopwatch2 = new Stopwatch();
  3073. try
  3074. {
  3075. stopwatch1.Start();
  3076. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3077. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3078. string processItem = stationName; // 测试项目
  3079. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3080. string supplierCode = ""; // 供应商代码
  3081. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3082. string batch_num = GlobalContext.BatchNumber; // 批次号
  3083. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3084. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3085. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3086. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  3087. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  3088. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  3089. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3090. bool pass = a1Result == 1;
  3091. //根据载具码获取产品码
  3092. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3093. if (string.IsNullOrEmpty(strProductBarcode))
  3094. {
  3095. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3096. }
  3097. sn = strProductBarcode;
  3098. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3099. List<TestItem> items = new List<TestItem>();
  3100. items.Add(new TestItem()
  3101. {
  3102. Parameter_name = "载具码",
  3103. Parameter_value = CarrierBarcode,
  3104. Parameter_unit = ""
  3105. });
  3106. items.Add(new TestItem()
  3107. {
  3108. Parameter_name = "产品码",
  3109. Parameter_value = sn,
  3110. Parameter_unit = ""
  3111. });
  3112. items.Add(new TestItem()
  3113. {
  3114. Parameter_name = "部件码",
  3115. Parameter_value = PartBarcode,
  3116. Parameter_unit = ""
  3117. });
  3118. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3119. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3120. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
  3121. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3122. if (mesResultFrmWeb == 1)
  3123. {
  3124. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3125. AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
  3126. }
  3127. stopwatch2.Start();
  3128. //进站结果写入PLC
  3129. CommandFromPLC resultToPlC = new CommandFromPLC();
  3130. resultToPlC.cmd = 0;
  3131. resultToPlC.cmdParam = 0; //指令参数
  3132. resultToPlC.cmdResult = mesResultFrmWeb;
  3133. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3134. stopwatch2.Stop();
  3135. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3136. //保存PLC返回MES数据到本地
  3137. ResponseMessage message = new ResponseMessage();
  3138. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  3139. stPLC_MesData.mesData.nRemainCount);
  3140. if (message.result == false)
  3141. {
  3142. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3143. }
  3144. if (!string.IsNullOrEmpty(PartBarcode))
  3145. {
  3146. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  3147. if (message.result == false)
  3148. {
  3149. AddMessage(LogType.Error, message.text);
  3150. }
  3151. }
  3152. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3153. }
  3154. catch (Exception ex)
  3155. {
  3156. stopwatch2.Start();
  3157. CommandFromPLC resultToPlC = new CommandFromPLC();
  3158. resultToPlC.cmd = 0;
  3159. resultToPlC.cmdParam = 0; //指令参数
  3160. resultToPlC.cmdResult = 110;
  3161. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3162. stopwatch2.Stop();
  3163. string str = ex.StackTrace;
  3164. AddMessage(LogType.Error,
  3165. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3166. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3167. }
  3168. stopwatch1.Stop();
  3169. AddMessage(LogType.Info,
  3170. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3171. stopwatch2.ElapsedMilliseconds + "ms");
  3172. ProgressState = false;
  3173. }
  3174. #endregion
  3175. #region S3
  3176. /// <summary>
  3177. /// [S3] 点散热胶装备
  3178. /// </summary>
  3179. /// <param name="plcNo">PLC编号</param>
  3180. private void ReadStation_S3(int plcNo)
  3181. {
  3182. string stationCode = "[OP30]";
  3183. string stationName = "点散热胶装备";
  3184. string stationNameStr = stationCode + stationName;
  3185. string tagBaseName = "g_OP30_MES"; //标签变量名称
  3186. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3187. string tagAgvCommName = "agvCommFrmPC";
  3188. string tagBarsetName = "BarcodeSet";
  3189. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3190. s3PLCSignal_Old.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3191. s3PLCSignal_Old.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3192. // PLC数据字典 赋值
  3193. s3PLCData.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3194. s3PLCData.Add("a3OEEPartNo_left", ""); // 物料码(物料码还未绑定载具SN时必填)
  3195. s3PLCData.Add("a3OEEVehicleCode_left", ""); // 载具SN
  3196. s3PLCData.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3197. s3PLCData.Add("a3OEEPartNo_right", ""); // 物料码(物料码还未绑定载具SN时必填)
  3198. s3PLCData.Add("a3OEEVehicleCode_right", ""); // 载具SN
  3199. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  3200. (int, string) result;
  3201. while (true)
  3202. {
  3203. try
  3204. {
  3205. if (!GlobalContext._IsCon_Funs2)
  3206. {
  3207. UpdatePLCMonitor(1, plcNo, 0);
  3208. continue;
  3209. }
  3210. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3211. {
  3212. Stopwatch stopwatch1 = new Stopwatch();
  3213. Stopwatch stopwatch2 = new Stopwatch();
  3214. stopwatch1.Start();
  3215. stopwatch2.Start();
  3216. #region 一次性读取所有数据
  3217. // 一次性读取所有数据
  3218. result = FunsEip[plcNo]
  3219. .Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3220. if (result.Item1 != 0)
  3221. {
  3222. //richTextBox1.AppendText("\n" + strRet);
  3223. }
  3224. else
  3225. {
  3226. //richTextBox1.AppendText("\n" + "读取成功");
  3227. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  3228. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  3229. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3230. ? XiaomiDeviceState.Unknown
  3231. : (XiaomiDeviceState)xmDeviceStateInt_L;
  3232. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3233. ? XiaomiDeviceState.Unknown
  3234. : (XiaomiDeviceState)xmDeviceStateInt_R;
  3235. s1PLCData["a1OEEPartNo"] =stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  3236. s1PLCData["a1OEEVehicleCode"] = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode; // 载具SN
  3237. s1PLCData["a1OEEType"] = stPLC_MesData.Left.iotData.BeatAction; // 节拍
  3238. s1PLCData["a1OEEVehicleCode_right"] = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode; // 载具SN
  3239. s1PLCData["a1OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction; // 节拍
  3240. }
  3241. #endregion 一次性读取所有数据
  3242. stopwatch2.Stop();
  3243. #region 左边进站
  3244. try
  3245. {
  3246. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3247. {
  3248. lock (lockObj)
  3249. {
  3250. if (!ProgressState)
  3251. {
  3252. ProgressState = true;
  3253. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
  3254. tagBaseName + ".Left." + tagMesCommName,
  3255. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  3256. }
  3257. }
  3258. }
  3259. }
  3260. catch (Exception ex)
  3261. {
  3262. ProgressState = false;
  3263. string str = ex.StackTrace;
  3264. AddMessage_Station(stationNameStr, LogType.Error,
  3265. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3266. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3267. }
  3268. #endregion 左边进站
  3269. #region 左边出站
  3270. try
  3271. {
  3272. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3273. {
  3274. lock (lockObj)
  3275. {
  3276. if (!ProgressState)
  3277. {
  3278. ProgressState = true;
  3279. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
  3280. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  3281. out ProgressState));
  3282. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3283. }
  3284. }
  3285. }
  3286. }
  3287. catch (Exception ex)
  3288. {
  3289. ProgressState = false;
  3290. string str = ex.StackTrace;
  3291. AddMessage_Station(stationNameStr, LogType.Error,
  3292. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3293. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3294. }
  3295. #endregion 左边出站
  3296. #region 右边进站
  3297. try
  3298. {
  3299. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3300. {
  3301. lock (lockObj)
  3302. {
  3303. if (!ProgressState)
  3304. {
  3305. ProgressState = true;
  3306. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
  3307. tagBaseName + ".Right." + tagMesCommName,
  3308. tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
  3309. }
  3310. }
  3311. }
  3312. }
  3313. catch (Exception ex)
  3314. {
  3315. ProgressState = false;
  3316. string str = ex.StackTrace;
  3317. AddMessage_Station(stationNameStr, LogType.Error,
  3318. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3319. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3320. }
  3321. #endregion 右边进站
  3322. #region 右边出站
  3323. try
  3324. {
  3325. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3326. {
  3327. lock (lockObj)
  3328. {
  3329. if (!ProgressState)
  3330. {
  3331. ProgressState = true;
  3332. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
  3333. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  3334. out ProgressState));
  3335. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3336. }
  3337. }
  3338. }
  3339. }
  3340. catch (Exception ex)
  3341. {
  3342. string str = ex.StackTrace;
  3343. AddMessage_Station(stationNameStr, LogType.Error,
  3344. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3345. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3346. }
  3347. #endregion 右边出站
  3348. #region 节拍接口
  3349. try
  3350. {
  3351. #region 左工位 节拍
  3352. int a30EEType_left = (int)s3PLCData["a30EEType_left"];
  3353. int a30EETypeGOld_left = (int)s3PLCSignal_Old["a30EEType_left"];
  3354. //若设备紧急复原后节拍重置
  3355. if (a30EEType_left == 1)
  3356. {
  3357. a30EETypeGOld_left = 0;
  3358. }
  3359. if (a30EEType_left != a30EETypeGOld_left)
  3360. {
  3361. stationNameStr = stationNameStr + "_Left";
  3362. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3363. if ((a30EETypeGOld_left == 1 && a30EEType_left != 2) || (a30EETypeGOld_left == 3 && a30EEType_left != 4) ||
  3364. (a30EETypeGOld_left == 5 && a30EEType_left != 6))
  3365. {
  3366. //写入PLC
  3367. stPLC_MesData.Left.iotData.beatReturn = 2; //NG
  3368. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
  3369. AddMessage(LogType.Info,
  3370. stationNameStr +
  3371. $"_节拍接口-- 设备本次上传节拍[{a30EEType_left}],未上传节拍[{a30EETypeGOld_left}]的结束信号,请检查;总用时" +
  3372. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  3373. "ms");
  3374. return;
  3375. }
  3376. else
  3377. {
  3378. Task.Run(() =>
  3379. S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
  3380. stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
  3381. }
  3382. s3PLCSignal_Old["a30EEType_left"] = s3PLCData["a30EEType_left"];
  3383. }
  3384. #endregion 左工位 节拍
  3385. #region 右工位 节拍
  3386. int a30EEType_right = (int)s3PLCData["a30EEType_right"];
  3387. int a30EETypeGOld_right = (int)s3PLCSignal_Old["a30EEType_right"];
  3388. //若设备紧急复原后节拍重置
  3389. if (a30EEType_right == 1)
  3390. {
  3391. a30EETypeGOld_right = 0;
  3392. }
  3393. if (a30EEType_right != a30EETypeGOld_right)
  3394. {
  3395. stationNameStr = stationNameStr + "_Right";
  3396. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3397. if ((a30EETypeGOld_right == 1 && a30EEType_right != 2) || (a30EETypeGOld_right == 3 && a30EEType_right != 4) ||
  3398. (a30EETypeGOld_right == 5 && a30EEType_right != 6))
  3399. {
  3400. //写入PLC
  3401. stPLC_MesData.Right.iotData.beatReturn = 2; //NG
  3402. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
  3403. AddMessage(LogType.Info,
  3404. stationNameStr +
  3405. $"_节拍接口-- 设备本次上传节拍[{a30EEType_right}],未上传节拍[{a30EETypeGOld_right}]的结束信号,请检查;总用时" +
  3406. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  3407. "ms");
  3408. return;
  3409. }
  3410. else
  3411. {
  3412. Task.Run(() =>
  3413. S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
  3414. stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
  3415. }
  3416. s3PLCSignal_Old["a30EEType_right"] = s3PLCData["a30EEType_right"];
  3417. }
  3418. #endregion 右工位 节拍
  3419. }
  3420. catch (Exception ex)
  3421. {
  3422. string str = ex.StackTrace;
  3423. AddMessage_Station(stationNameStr, LogType.Error,
  3424. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3425. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3426. }
  3427. #endregion
  3428. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3429. stopwatch1.Stop();
  3430. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3431. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3432. }
  3433. else
  3434. {
  3435. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3436. AddMessage_Station(stationNameStr, LogType.Info,
  3437. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3438. FunsEip[plcNo].Connect();
  3439. }
  3440. }
  3441. catch (Exception ex)
  3442. {
  3443. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3444. AddMessage_Station(stationNameStr, LogType.Error,
  3445. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3446. //Funs[plcNo].ReConnect();
  3447. }
  3448. Thread.Sleep(IntervalReadPLC);
  3449. }
  3450. }
  3451. /// <summary>
  3452. /// [S3] 点散热胶装备 - 进站
  3453. /// </summary>
  3454. /// <param name="plcNo">PLC编号</param>
  3455. /// <param name="stationNameStr">工站全称</param>
  3456. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3457. string tagBarsetName, string direction, out bool ProgressState)
  3458. {
  3459. Stopwatch stopwatch1 = new Stopwatch();
  3460. Stopwatch stopwatch2 = new Stopwatch();
  3461. try
  3462. {
  3463. stopwatch1.Start();
  3464. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  3465. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3466. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  3467. string StationId = string.Empty;
  3468. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3469. bool pass = a1Result == 1;
  3470. if (direction == "Left")
  3471. {
  3472. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3473. }
  3474. if (direction == "Right")
  3475. {
  3476. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3477. }
  3478. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3479. //载具码验证产品码
  3480. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3481. if (string.IsNullOrEmpty(strProductBarcode))
  3482. {
  3483. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3484. }
  3485. sn = strProductBarcode;
  3486. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  3487. // 产品SN(物料码)校验
  3488. List<TestItem> item = new List<TestItem>();
  3489. stopwatch2.Start();
  3490. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3491. item, MachineId, StationId,pass);
  3492. stopwatch2.Stop();
  3493. //指令执行结果 1:OK 110:失败
  3494. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3495. if (mesResultFrmWeb == 1)
  3496. {
  3497. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3498. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3499. }
  3500. //进站结果写入PLC
  3501. CommandFromPLC resultToPlC = new CommandFromPLC();
  3502. resultToPlC.cmd = 0;
  3503. resultToPlC.cmdParam = 0; //指令参数
  3504. resultToPlC.cmdResult = mesResultFrmWeb;
  3505. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3506. }
  3507. catch (Exception ex)
  3508. {
  3509. string str = ex.StackTrace;
  3510. AddMessage(LogType.Error,
  3511. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3512. str.Length - str.LastIndexOf("\\") - 1));
  3513. CommandFromPLC resultToPlC = new CommandFromPLC();
  3514. resultToPlC.cmd = 0;
  3515. resultToPlC.cmdParam = 0; //指令参数
  3516. resultToPlC.cmdResult = 110;
  3517. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3518. }
  3519. stopwatch1.Stop();
  3520. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3521. AddMessage(LogType.Info,
  3522. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3523. stopwatch2.ElapsedMilliseconds + "ms");
  3524. ProgressState = false;
  3525. }
  3526. /// <summary>
  3527. /// [S3] 点散热胶装备 - 出站
  3528. /// </summary>
  3529. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3530. string stationCode, string stationName, string direction, out bool ProgressState)
  3531. {
  3532. Stopwatch stopwatch1 = new Stopwatch();
  3533. Stopwatch stopwatch2 = new Stopwatch();
  3534. try
  3535. {
  3536. stopwatch1.Start();
  3537. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  3538. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3539. string processItem = stationName; // 测试项目
  3540. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3541. string supplierCode = ""; // 供应商代码
  3542. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3543. string batch_num = GlobalContext.BatchNumber; // 批次号
  3544. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3545. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3546. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3547. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  3548. string StationId = string.Empty;
  3549. if (direction == "Left")
  3550. {
  3551. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3552. }
  3553. if (direction == "Right")
  3554. {
  3555. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3556. }
  3557. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3558. bool pass = a1Result == 1;
  3559. //根据载具码获取产品码
  3560. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3561. if (string.IsNullOrEmpty(strProductBarcode))
  3562. {
  3563. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3564. }
  3565. sn = strProductBarcode;
  3566. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3567. List<TestItem> items = new List<TestItem>();
  3568. items.Add(new TestItem()
  3569. {
  3570. Parameter_name = "载具码",
  3571. Parameter_value = CarrierBarcode,
  3572. Parameter_unit = ""
  3573. });
  3574. items.Add(new TestItem()
  3575. {
  3576. Parameter_name = "产品码",
  3577. Parameter_value = sn,
  3578. Parameter_unit = ""
  3579. });
  3580. //if (direction == "Right")
  3581. //{
  3582. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3583. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3584. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson, direction);
  3585. //}
  3586. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3587. if (mesResultFrmWeb == 1)
  3588. {
  3589. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3590. AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
  3591. }
  3592. stopwatch2.Start();
  3593. //进站结果写入PLC
  3594. CommandFromPLC resultToPlC = new CommandFromPLC();
  3595. resultToPlC.cmd = 0;
  3596. resultToPlC.cmdParam = 0; //指令参数
  3597. resultToPlC.cmdResult = mesResultFrmWeb;
  3598. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3599. stopwatch2.Stop();
  3600. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3601. //保存PLC返回MES数据到本地
  3602. ResponseMessage message = new ResponseMessage();
  3603. if (direction == "Left")
  3604. {
  3605. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  3606. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  3607. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  3608. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  3609. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  3610. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  3611. if (message.result == false)
  3612. {
  3613. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3614. }
  3615. }
  3616. if (direction == "Right")
  3617. {
  3618. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  3619. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  3620. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  3621. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  3622. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  3623. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  3624. if (message.result == false)
  3625. {
  3626. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3627. }
  3628. }
  3629. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3630. }
  3631. catch (Exception ex)
  3632. {
  3633. stopwatch2.Start();
  3634. CommandFromPLC resultToPlC = new CommandFromPLC();
  3635. resultToPlC.cmd = 0;
  3636. resultToPlC.cmdParam = 0; //指令参数
  3637. resultToPlC.cmdResult = 110;
  3638. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3639. stopwatch2.Stop();
  3640. string str = ex.StackTrace;
  3641. AddMessage(LogType.Error,
  3642. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3643. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3644. }
  3645. stopwatch1.Stop();
  3646. AddMessage(LogType.Info,
  3647. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3648. stopwatch2.ElapsedMilliseconds + "ms");
  3649. ProgressState = false;
  3650. }
  3651. #endregion S3
  3652. #region S4
  3653. /// <summary>
  3654. /// [S4] 点胶检测设备
  3655. /// </summary>
  3656. /// <param name="plcNo">PLC编号</param>
  3657. private void ReadStation_S4(int plcNo)
  3658. {
  3659. string stationCode = "[OP40]";
  3660. string stationName = "胶线检测";
  3661. string stationNameStr = stationCode + stationName;
  3662. string tagBaseName = "g_OP40_MES"; //标签变量名称
  3663. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3664. string tagAgvCommName = "agvCommFrmPC";
  3665. string tagBarsetName = "BarcodeSet";
  3666. // 触发信号字典
  3667. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3668. s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
  3669. // PLC数据字典 赋值
  3670. s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
  3671. s4PLCData.Add("a4OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  3672. s4PLCData.Add("a4OEEVehicleCode", ""); // 载具SN
  3673. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  3674. (int, string) result;
  3675. while (true)
  3676. {
  3677. try
  3678. {
  3679. if (!GlobalContext._IsCon_Funs1)
  3680. {
  3681. UpdatePLCMonitor(1, plcNo, 0);
  3682. continue;
  3683. }
  3684. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3685. {
  3686. Stopwatch stopwatch1 = new Stopwatch();
  3687. Stopwatch stopwatch2 = new Stopwatch();
  3688. stopwatch1.Start();
  3689. stopwatch2.Start();
  3690. #region 一次性读取所有数据
  3691. // 一次性读取所有数据
  3692. result = FunsEip[plcNo]
  3693. .Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3694. if (result.Item1 != 0)
  3695. {
  3696. //richTextBox1.AppendText("\n" + strRet);
  3697. }
  3698. else
  3699. {
  3700. //richTextBox1.AppendText("\n" + "读取成功");
  3701. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3702. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3703. ? XiaomiDeviceState.Unknown
  3704. : (XiaomiDeviceState)xmDeviceStateInt;
  3705. s4PLCData["a4OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  3706. s4PLCData["a4OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3707. s4PLCData["a4OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  3708. }
  3709. #endregion 一次性读取所有数据
  3710. stopwatch2.Stop();
  3711. #region 进站
  3712. try
  3713. {
  3714. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3715. {
  3716. lock (lockObj)
  3717. {
  3718. if (!ProgressState)
  3719. {
  3720. ProgressState = true;
  3721. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
  3722. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3723. out ProgressState));
  3724. }
  3725. }
  3726. }
  3727. }
  3728. catch (Exception ex)
  3729. {
  3730. ProgressState = false;
  3731. string str = ex.StackTrace;
  3732. AddMessage_Station(stationNameStr, LogType.Error,
  3733. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3734. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3735. }
  3736. #endregion 进站
  3737. #region 出站
  3738. try
  3739. {
  3740. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3741. {
  3742. lock (lockObj)
  3743. {
  3744. if (!ProgressState)
  3745. {
  3746. ProgressState = true;
  3747. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
  3748. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3749. out ProgressState));
  3750. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3751. }
  3752. }
  3753. }
  3754. }
  3755. catch (Exception ex)
  3756. {
  3757. string str = ex.StackTrace;
  3758. AddMessage_Station(stationNameStr, LogType.Error,
  3759. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3760. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3761. }
  3762. #endregion 出站
  3763. #region 节拍接口
  3764. try
  3765. {
  3766. int a40EEType = (int)s4PLCData["a40EEType"];
  3767. int a40EETypeGOld = (int)s4PLCSignal_Old["a40EEType"];
  3768. //若设备紧急复原后节拍重置
  3769. if (a40EEType == 1)
  3770. {
  3771. a40EETypeGOld = 0;
  3772. }
  3773. if (a40EEType != a40EETypeGOld)
  3774. {
  3775. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3776. if ((a40EETypeGOld == 1 && a40EEType != 2) || (a40EETypeGOld == 3 && a40EEType != 4) ||
  3777. (a40EETypeGOld == 5 && a40EEType != 6))
  3778. {
  3779. //写入PLC
  3780. stPLC_MesData.iotData.beatReturn = 2; //NG
  3781. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  3782. AddMessage(LogType.Info,
  3783. stationNameStr +
  3784. $"_节拍接口-- 设备本次上传节拍[{a40EEType}],未上传节拍[{a40EETypeGOld}]的结束信号,请检查;总用时" +
  3785. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  3786. "ms");
  3787. return;
  3788. }
  3789. else
  3790. {
  3791. Task.Run(() =>
  3792. S4节拍接口(plcNo, stationNameStr, tagBaseName,
  3793. stPLC_MesData.iotData)); // MreTasks[4].Set();
  3794. }
  3795. s4PLCSignal_Old["a40EEType"] = s4PLCData["a40EEType"];
  3796. }
  3797. }
  3798. catch (Exception ex)
  3799. {
  3800. string str = ex.StackTrace;
  3801. AddMessage_Station(stationNameStr, LogType.Error,
  3802. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3803. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3804. }
  3805. #endregion
  3806. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3807. stopwatch1.Stop();
  3808. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3809. }
  3810. else
  3811. {
  3812. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3813. AddMessage_Station(stationNameStr, LogType.Info,
  3814. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3815. FunsEip[plcNo].Connect(); // 重连
  3816. }
  3817. }
  3818. catch (Exception ex)
  3819. {
  3820. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3821. AddMessage_Station(stationNameStr, LogType.Error,
  3822. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3823. }
  3824. Thread.Sleep(IntervalReadPLC);
  3825. }
  3826. }
  3827. /// <summary>
  3828. /// [S4] 点胶检测设备 - 进站
  3829. /// </summary>
  3830. /// <param name="plcNo">PLC编号</param>
  3831. /// <param name="stationNameStr">工站全称</param>
  3832. /// <param name="stPLC_MesData"></param>
  3833. /// <param name="tagMesCommName"></param>
  3834. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  3835. string tagBarsetName, out bool ProgressState)
  3836. {
  3837. Stopwatch stopwatch1 = new Stopwatch();
  3838. Stopwatch stopwatch2 = new Stopwatch();
  3839. try
  3840. {
  3841. stopwatch1.Start();
  3842. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3843. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3844. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  3845. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  3846. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3847. bool pass = a1Result == 1;
  3848. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3849. //载具码验证产品码
  3850. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3851. if (string.IsNullOrEmpty(strProductBarcode))
  3852. {
  3853. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3854. }
  3855. sn = strProductBarcode;
  3856. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3857. // 产品SN(物料码)校验
  3858. List<TestItem> item = new List<TestItem>();
  3859. stopwatch2.Start();
  3860. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3861. item, MachineId, StationId,pass);
  3862. stopwatch2.Stop();
  3863. //指令执行结果 1:OK 110:失败
  3864. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3865. if (mesResultFrmWeb == 1)
  3866. {
  3867. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3868. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3869. }
  3870. //进站结果写入PLC
  3871. CommandFromPLC resultToPlC = new CommandFromPLC();
  3872. resultToPlC.cmd = 0;
  3873. resultToPlC.cmdParam = 0; //指令参数
  3874. resultToPlC.cmdResult = mesResultFrmWeb;
  3875. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3876. }
  3877. catch (Exception ex)
  3878. {
  3879. string str = ex.StackTrace;
  3880. AddMessage(LogType.Error,
  3881. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3882. str.Length - str.LastIndexOf("\\") - 1));
  3883. CommandFromPLC resultToPlC = new CommandFromPLC();
  3884. resultToPlC.cmd = 0;
  3885. resultToPlC.cmdParam = 0; //指令参数
  3886. resultToPlC.cmdResult = 110;
  3887. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3888. }
  3889. stopwatch1.Stop();
  3890. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3891. AddMessage(LogType.Info,
  3892. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3893. stopwatch2.ElapsedMilliseconds + "ms");
  3894. ProgressState = false;
  3895. }
  3896. /// <summary>
  3897. /// [S4] 点胶检测设备 - 出站接口
  3898. /// </summary>
  3899. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  3900. string stationCode, string stationName, out bool ProgressState)
  3901. {
  3902. Stopwatch stopwatch1 = new Stopwatch();
  3903. Stopwatch stopwatch2 = new Stopwatch();
  3904. try
  3905. {
  3906. stopwatch1.Start();
  3907. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3908. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3909. string processItem = stationName; // 测试项目
  3910. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3911. string supplierCode = ""; // 供应商代码
  3912. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3913. string batch_num = GlobalContext.BatchNumber; // 批次号
  3914. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3915. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3916. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3917. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  3918. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  3919. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3920. bool pass = a1Result == 1;
  3921. //根据载具码获取产品码
  3922. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3923. if (string.IsNullOrEmpty(strProductBarcode))
  3924. {
  3925. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3926. }
  3927. sn = strProductBarcode;
  3928. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3929. List<TestItem> items = new List<TestItem>();
  3930. items.Add(new TestItem()
  3931. {
  3932. Parameter_name = "载具码",
  3933. Parameter_value = CarrierBarcode,
  3934. Parameter_unit = ""
  3935. });
  3936. items.Add(new TestItem()
  3937. {
  3938. Parameter_name = "产品码",
  3939. Parameter_value = sn,
  3940. Parameter_unit = ""
  3941. });
  3942. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3943. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3944. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  3945. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3946. if (mesResultFrmWeb == 1)
  3947. {
  3948. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3949. AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
  3950. }
  3951. stopwatch2.Start();
  3952. //进站结果写入PLC
  3953. CommandFromPLC resultToPlC = new CommandFromPLC();
  3954. resultToPlC.cmd = 0;
  3955. resultToPlC.cmdParam = 0; //指令参数
  3956. resultToPlC.cmdResult = mesResultFrmWeb;
  3957. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3958. stopwatch2.Stop();
  3959. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3960. //保存PLC返回MES数据到本地
  3961. ResponseMessage message = new ResponseMessage();
  3962. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  3963. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  3964. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  3965. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  3966. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  3967. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  3968. if (message.result == false)
  3969. {
  3970. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3971. }
  3972. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3973. }
  3974. catch (Exception ex)
  3975. {
  3976. stopwatch2.Start();
  3977. CommandFromPLC resultToPlC = new CommandFromPLC();
  3978. resultToPlC.cmd = 0;
  3979. resultToPlC.cmdParam = 0; //指令参数
  3980. resultToPlC.cmdResult = 110;
  3981. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3982. stopwatch2.Stop();
  3983. string str = ex.StackTrace;
  3984. AddMessage(LogType.Error,
  3985. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3986. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3987. }
  3988. stopwatch1.Stop();
  3989. AddMessage(LogType.Info,
  3990. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3991. stopwatch2.ElapsedMilliseconds + "ms");
  3992. ProgressState = false;
  3993. }
  3994. private void S4节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  3995. {
  3996. Stopwatch stopwatch1 = new Stopwatch();
  3997. Stopwatch stopwatch2 = new Stopwatch();
  3998. string resultStr = string.Empty;
  3999. try
  4000. {
  4001. stopwatch1.Start();
  4002. string oEEType = ((int)s1PLCData["a4OEEType"]).ToString(); // 节拍类型(plc写入)
  4003. string a40EEPartNo = (string)s1PLCData["a40EEPartNo"]; // 物料码
  4004. a40EEPartNo = a40EEPartNo.Replace("\0", "");
  4005. string a50EEVehicleCode = (string)s1PLCData["a50EEVehicleCode"]; // 载具SN
  4006. a50EEVehicleCode = a50EEVehicleCode.Replace("\0", "");
  4007. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4008. if (!actionBool)
  4009. {
  4010. stopwatch2.Start();
  4011. //写入PLC
  4012. iot_data.beatReturn = 2; //NG
  4013. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4014. stopwatch2.Stop();
  4015. AddMessage(LogType.Info,
  4016. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  4017. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4018. return;
  4019. }
  4020. //作业开始后要有物料和载具信息
  4021. if (string.IsNullOrEmpty(a40EEPartNo) && string.IsNullOrEmpty(a50EEVehicleCode) &&
  4022. Convert.ToInt32(oEEType) > 2)
  4023. {
  4024. stopwatch2.Start();
  4025. //写入PLC
  4026. iot_data.beatReturn = 2; //NG
  4027. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4028. stopwatch2.Stop();
  4029. AddMessage_Station(stationNameStr, LogType.Info,
  4030. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  4031. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4032. return;
  4033. }
  4034. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a40EEPartNo))
  4035. {
  4036. stopwatch2.Start();
  4037. //写入PLC
  4038. iot_data.beatReturn = 2; //NG
  4039. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4040. stopwatch2.Stop();
  4041. AddMessage_Station(stationNameStr, LogType.Info,
  4042. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  4043. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4044. return;
  4045. }
  4046. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a50EEVehicleCode))
  4047. {
  4048. stopwatch2.Start();
  4049. //写入PLC
  4050. iot_data.beatReturn = 2; //NG
  4051. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4052. stopwatch2.Stop();
  4053. AddMessage_Station(stationNameStr, LogType.Info,
  4054. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  4055. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4056. return;
  4057. }
  4058. short _result = 0;
  4059. // 上传OEE
  4060. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a40EEPartNo, a50EEVehicleCode);
  4061. _result = result.Item1;
  4062. resultStr = result.Item2;
  4063. if (_result == 1)
  4064. {
  4065. stopwatch2.Start();
  4066. //写入PLC
  4067. iot_data.beatReturn = 1; //OK
  4068. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4069. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  4070. stopwatch2.Stop();
  4071. }
  4072. else
  4073. {
  4074. stopwatch2.Start();
  4075. //写入PLC
  4076. iot_data.beatReturn = 2; //NG
  4077. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4078. stopwatch2.Stop();
  4079. AddMessage_Station(stationNameStr, LogType.Error,
  4080. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  4081. }
  4082. }
  4083. catch (Exception ex)
  4084. {
  4085. string str = ex.StackTrace;
  4086. AddMessage_Station(stationNameStr, LogType.Error,
  4087. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  4088. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4089. // MES_Flag
  4090. stopwatch2.Start();
  4091. //写入PLC
  4092. iot_data.beatReturn = 2; //NG
  4093. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4094. stopwatch2.Stop();
  4095. }
  4096. stopwatch1.Stop();
  4097. AddMessage(LogType.Info,
  4098. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4099. stopwatch2.ElapsedMilliseconds + "ms");
  4100. }
  4101. #endregion
  4102. #region S5
  4103. /// <summary>
  4104. /// [S5] 点胶检测设备
  4105. /// </summary>
  4106. /// <param name="plcNo">PLC编号</param>
  4107. private void ReadStation_S5(int plcNo)
  4108. {
  4109. string stationCode = "[OP50]";
  4110. string stationName = "ADD板上料组装装备";
  4111. string stationNameStr = stationCode + stationName;
  4112. string tagBaseName = "g_OP50_MES"; //标签变量名称
  4113. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4114. string tagAgvCommName = "agvCommFrmPC";
  4115. string tagBarsetName = "BarcodeSet";
  4116. // 触发信号字典
  4117. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4118. s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4119. // PLC数据字典 赋值
  4120. s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4121. s5PLCData.Add("a5OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4122. s5PLCData.Add("a5OEEVehicleCode", ""); // 载具SN
  4123. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  4124. (int, string) result;
  4125. while (true)
  4126. {
  4127. try
  4128. {
  4129. if (!GlobalContext._IsCon_Funs1)
  4130. {
  4131. UpdatePLCMonitor(1, plcNo, 0);
  4132. continue;
  4133. }
  4134. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4135. {
  4136. Stopwatch stopwatch1 = new Stopwatch();
  4137. Stopwatch stopwatch2 = new Stopwatch();
  4138. stopwatch1.Start();
  4139. stopwatch2.Start();
  4140. #region 一次性读取所有数据
  4141. // 一次性读取所有数据
  4142. result = FunsEip[plcNo]
  4143. .Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4144. if (result.Item1 != 0)
  4145. {
  4146. //richTextBox1.AppendText("\n" + strRet);
  4147. }
  4148. else
  4149. {
  4150. //richTextBox1.AppendText("\n" + "读取成功");
  4151. //richTextBox1.AppendText("\n" + "读取成功");
  4152. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4153. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4154. ? XiaomiDeviceState.Unknown
  4155. : (XiaomiDeviceState)xmDeviceStateInt;
  4156. s5PLCData["a5OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  4157. s5PLCData["a5OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  4158. s5PLCData["a5OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  4159. }
  4160. #endregion 一次性读取所有数据
  4161. stopwatch2.Stop();
  4162. #region 进站
  4163. try
  4164. {
  4165. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4166. {
  4167. lock (lockObj)
  4168. {
  4169. if (!ProgressState)
  4170. {
  4171. ProgressState = true;
  4172. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData,
  4173. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4174. out ProgressState));
  4175. }
  4176. }
  4177. }
  4178. }
  4179. catch (Exception ex)
  4180. {
  4181. ProgressState = false;
  4182. string str = ex.StackTrace;
  4183. AddMessage_Station(stationNameStr, LogType.Error,
  4184. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4185. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4186. }
  4187. #endregion 进站
  4188. #region 出站
  4189. try
  4190. {
  4191. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4192. {
  4193. lock (lockObj)
  4194. {
  4195. if (!ProgressState)
  4196. {
  4197. ProgressState = true;
  4198. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
  4199. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4200. out ProgressState));
  4201. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4202. }
  4203. }
  4204. }
  4205. }
  4206. catch (Exception ex)
  4207. {
  4208. ProgressState = false;
  4209. string str = ex.StackTrace;
  4210. AddMessage_Station(stationNameStr, LogType.Error,
  4211. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4212. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4213. }
  4214. #endregion 出站
  4215. #region 节拍接口
  4216. try
  4217. {
  4218. int a50EEType = (int)s5PLCData["a50EEType"];
  4219. int a50EETypeGOld = (int)s5PLCSignal_Old["a50EEType"];
  4220. //若设备紧急复原后节拍重置
  4221. if (a50EEType == 1)
  4222. {
  4223. a50EETypeGOld = 0;
  4224. }
  4225. if (a50EEType != a50EETypeGOld)
  4226. {
  4227. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  4228. if ((a50EETypeGOld == 1 && a50EEType != 2) || (a50EETypeGOld == 3 && a50EEType != 4) ||
  4229. (a50EETypeGOld == 5 && a50EEType != 6))
  4230. {
  4231. //写入PLC
  4232. stPLC_MesData.iotData.beatReturn = 2; //NG
  4233. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  4234. AddMessage(LogType.Info,
  4235. stationNameStr +
  4236. $"_节拍接口-- 设备本次上传节拍[{a50EEType}],未上传节拍[{a50EETypeGOld}]的结束信号,请检查;总用时" +
  4237. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  4238. "ms");
  4239. return;
  4240. }
  4241. else
  4242. {
  4243. Task.Run(() =>
  4244. S5节拍接口(plcNo, stationNameStr, tagBaseName,
  4245. stPLC_MesData.iotData)); // MreTasks[4].Set();
  4246. }
  4247. s5PLCSignal_Old["a50EEType"] = s5PLCData["a50EEType"];
  4248. }
  4249. }
  4250. catch (Exception ex)
  4251. {
  4252. string str = ex.StackTrace;
  4253. AddMessage_Station(stationNameStr, LogType.Error,
  4254. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4255. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4256. }
  4257. #endregion
  4258. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4259. stopwatch1.Stop();
  4260. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4261. }
  4262. else
  4263. {
  4264. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4265. AddMessage_Station(stationNameStr, LogType.Info,
  4266. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4267. FunsEip[plcNo].Connect(); // 重连
  4268. }
  4269. }
  4270. catch (Exception ex)
  4271. {
  4272. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4273. AddMessage_Station(stationNameStr, LogType.Error,
  4274. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4275. }
  4276. Thread.Sleep(IntervalReadPLC);
  4277. }
  4278. }
  4279. /// <summary>
  4280. /// [S5] 点胶检测设备 - 进站
  4281. /// </summary>
  4282. /// <param name="plcNo">PLC编号</param>
  4283. /// <param name="stationNameStr">工站全称</param>
  4284. /// <param name="stPLC_MesData"></param>
  4285. /// <param name="tagMesCommName"></param>
  4286. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4287. string tagBarsetName, out bool ProgressState)
  4288. {
  4289. Stopwatch stopwatch1 = new Stopwatch();
  4290. Stopwatch stopwatch2 = new Stopwatch();
  4291. try
  4292. {
  4293. stopwatch1.Start();
  4294. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4295. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4296. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  4297. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  4298. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  4299. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  4300. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4301. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4302. bool pass = a1Result == 1;
  4303. //绑定载具和产品
  4304. ResponseMessage message = new ResponseMessage();
  4305. message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
  4306. if (message.result == false)
  4307. {
  4308. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  4309. }
  4310. //载具码验证产品码 //载具码验证产品码
  4311. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4312. if (string.IsNullOrEmpty(strProductBarcode))
  4313. {
  4314. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4315. }
  4316. sn = strProductBarcode;
  4317. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  4318. // 产品SN(物料码)校验
  4319. List<TestItem> item = new List<TestItem>();
  4320. stopwatch2.Start();
  4321. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4322. item, MachineId, StationId, pass);
  4323. stopwatch2.Stop();
  4324. //指令执行结果 1:OK 110:失败
  4325. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4326. if (mesResultFrmWeb == 1)
  4327. {
  4328. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4329. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4330. }
  4331. //进站结果写入PLC
  4332. CommandFromPLC resultToPlC = new CommandFromPLC();
  4333. resultToPlC.cmd = 0;
  4334. resultToPlC.cmdParam = 0; //指令参数
  4335. resultToPlC.cmdResult = mesResultFrmWeb;
  4336. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4337. }
  4338. catch (Exception ex)
  4339. {
  4340. string str = ex.StackTrace;
  4341. AddMessage(LogType.Error,
  4342. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4343. str.Length - str.LastIndexOf("\\") - 1));
  4344. CommandFromPLC resultToPlC = new CommandFromPLC();
  4345. resultToPlC.cmd = 0;
  4346. resultToPlC.cmdParam = 0; //指令参数
  4347. resultToPlC.cmdResult = 110;
  4348. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4349. }
  4350. stopwatch1.Stop();
  4351. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4352. AddMessage(LogType.Info,
  4353. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4354. stopwatch2.ElapsedMilliseconds + "ms");
  4355. ProgressState = false;
  4356. }
  4357. /// <summary>
  4358. /// [S5] 点胶检测设备 - 出站接口
  4359. /// </summary>
  4360. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4361. string stationCode, string stationName, out bool ProgressState)
  4362. {
  4363. Stopwatch stopwatch1 = new Stopwatch();
  4364. Stopwatch stopwatch2 = new Stopwatch();
  4365. try
  4366. {
  4367. stopwatch1.Start();
  4368. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4369. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4370. string processItem = stationName; // 测试项目
  4371. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4372. string supplierCode = ""; // 供应商代码
  4373. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4374. string batch_num = GlobalContext.BatchNumber; // 批次号
  4375. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4376. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4377. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  4378. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4379. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  4380. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  4381. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4382. bool pass = a1Result == 1;
  4383. //根据载具码获取产品码
  4384. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4385. if (string.IsNullOrEmpty(strProductBarcode))
  4386. {
  4387. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4388. }
  4389. sn = strProductBarcode;
  4390. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4391. List<TestItem> items = new List<TestItem>();
  4392. items.Add(new TestItem()
  4393. {
  4394. Parameter_name = "载具码",
  4395. Parameter_value = CarrierBarcode,
  4396. Parameter_unit = ""
  4397. });
  4398. items.Add(new TestItem()
  4399. {
  4400. Parameter_name = "产品码",
  4401. Parameter_value = sn,
  4402. Parameter_unit = ""
  4403. });
  4404. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4405. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4406. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
  4407. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4408. if (mesResultFrmWeb == 1)
  4409. {
  4410. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4411. AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
  4412. }
  4413. stopwatch2.Start();
  4414. //进站结果写入PLC
  4415. CommandFromPLC resultToPlC = new CommandFromPLC();
  4416. resultToPlC.cmd = 0;
  4417. resultToPlC.cmdParam = 0; //指令参数
  4418. resultToPlC.cmdResult = mesResultFrmWeb;
  4419. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4420. stopwatch2.Stop();
  4421. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4422. //保存PLC返回MES数据到本地
  4423. ResponseMessage message = new ResponseMessage();
  4424. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  4425. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB,
  4426. stPLC_MesData.mesData.nRemainCount, "");
  4427. if (message.result == false)
  4428. {
  4429. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4430. }
  4431. //保存部件码信息
  4432. if (!string.IsNullOrEmpty(PartBarcode))
  4433. {
  4434. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  4435. if (message.result == false)
  4436. {
  4437. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  4438. }
  4439. }
  4440. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4441. }
  4442. catch (Exception ex)
  4443. {
  4444. stopwatch2.Start();
  4445. CommandFromPLC resultToPlC = new CommandFromPLC();
  4446. resultToPlC.cmd = 0;
  4447. resultToPlC.cmdParam = 0; //指令参数
  4448. resultToPlC.cmdResult = 110;
  4449. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4450. stopwatch2.Stop();
  4451. string str = ex.StackTrace;
  4452. AddMessage(LogType.Error,
  4453. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4454. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4455. }
  4456. stopwatch1.Stop();
  4457. AddMessage(LogType.Info,
  4458. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4459. stopwatch2.ElapsedMilliseconds + "ms");
  4460. ProgressState = false;
  4461. }
  4462. private void S5节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  4463. {
  4464. Stopwatch stopwatch1 = new Stopwatch();
  4465. Stopwatch stopwatch2 = new Stopwatch();
  4466. string resultStr = string.Empty;
  4467. try
  4468. {
  4469. stopwatch1.Start();
  4470. string oEEType = ((int)s1PLCData["a5OEEType"]).ToString(); // 节拍类型(plc写入)
  4471. string a50EEPartNo = (string)s1PLCData["a50EEPartNo"]; // 物料码
  4472. a50EEPartNo = a50EEPartNo.Replace("\0", "");
  4473. string a40EEVehicleCode = (string)s1PLCData["a40EEVehicleCode"]; // 载具SN
  4474. a40EEVehicleCode = a40EEVehicleCode.Replace("\0", "");
  4475. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4476. if (!actionBool)
  4477. {
  4478. stopwatch2.Start();
  4479. //写入PLC
  4480. iot_data.beatReturn = 2; //NG
  4481. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4482. stopwatch2.Stop();
  4483. AddMessage(LogType.Info,
  4484. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  4485. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4486. return;
  4487. }
  4488. //作业开始后要有物料和载具信息
  4489. if (string.IsNullOrEmpty(a50EEPartNo) && string.IsNullOrEmpty(a40EEVehicleCode) &&
  4490. Convert.ToInt32(oEEType) > 2)
  4491. {
  4492. stopwatch2.Start();
  4493. //写入PLC
  4494. iot_data.beatReturn = 2; //NG
  4495. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4496. stopwatch2.Stop();
  4497. AddMessage_Station(stationNameStr, LogType.Info,
  4498. stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  4499. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4500. return;
  4501. }
  4502. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a50EEPartNo))
  4503. {
  4504. stopwatch2.Start();
  4505. //写入PLC
  4506. iot_data.beatReturn = 2; //NG
  4507. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4508. stopwatch2.Stop();
  4509. AddMessage_Station(stationNameStr, LogType.Info,
  4510. stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  4511. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4512. return;
  4513. }
  4514. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a40EEVehicleCode))
  4515. {
  4516. stopwatch2.Start();
  4517. //写入PLC
  4518. iot_data.beatReturn = 2; //NG
  4519. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4520. stopwatch2.Stop();
  4521. AddMessage_Station(stationNameStr, LogType.Info,
  4522. stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  4523. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4524. return;
  4525. }
  4526. short _result = 0;
  4527. // 上传OEE
  4528. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a50EEPartNo, a40EEVehicleCode);
  4529. _result = result.Item1;
  4530. resultStr = result.Item2;
  4531. if (_result == 1)
  4532. {
  4533. stopwatch2.Start();
  4534. //写入PLC
  4535. iot_data.beatReturn = 1; //OK
  4536. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4537. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  4538. stopwatch2.Stop();
  4539. }
  4540. else
  4541. {
  4542. stopwatch2.Start();
  4543. //写入PLC
  4544. iot_data.beatReturn = 2; //NG
  4545. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4546. stopwatch2.Stop();
  4547. AddMessage_Station(stationNameStr, LogType.Error,
  4548. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  4549. }
  4550. }
  4551. catch (Exception ex)
  4552. {
  4553. string str = ex.StackTrace;
  4554. AddMessage_Station(stationNameStr, LogType.Error,
  4555. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  4556. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4557. // MES_Flag
  4558. stopwatch2.Start();
  4559. //写入PLC
  4560. iot_data.beatReturn = 2; //NG
  4561. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4562. stopwatch2.Stop();
  4563. }
  4564. stopwatch1.Stop();
  4565. AddMessage(LogType.Info,
  4566. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4567. stopwatch2.ElapsedMilliseconds + "ms");
  4568. }
  4569. #endregion
  4570. #region S6
  4571. private Dictionary<string, object> s6PLCData = new Dictionary<string, object>();
  4572. private Dictionary<string, object> s6PLCSignal_Old = new Dictionary<string, object>();
  4573. /// <summary>
  4574. /// [S6] 顶盖装配设备
  4575. /// </summary>
  4576. /// <param name="plcNo">PLC编号</param>
  4577. private void ReadStation_S6(int plcNo)
  4578. {
  4579. string stationCode = "[OP60]";
  4580. string stationName = "组上盖板";
  4581. string stationNameStr = stationCode + stationName;
  4582. string tagBaseName = "g_OP60_MES"; //标签变量名称
  4583. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4584. string tagAgvCommName = "agvCommFrmPC";
  4585. string tagBarsetName = "BarcodeSet";
  4586. // 触发信号字典
  4587. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4588. s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
  4589. // PLC数据字典 赋值
  4590. s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
  4591. s6PLCData.Add("a6OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4592. s6PLCData.Add("a6OEEVehicleCode", ""); // 载具SN
  4593. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  4594. (int, string) result;
  4595. while (true)
  4596. {
  4597. try
  4598. {
  4599. if (!GlobalContext._IsCon_Funs1)
  4600. {
  4601. UpdatePLCMonitor(1, plcNo, 0);
  4602. continue;
  4603. }
  4604. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4605. {
  4606. Stopwatch stopwatch1 = new Stopwatch();
  4607. Stopwatch stopwatch2 = new Stopwatch();
  4608. stopwatch1.Start();
  4609. stopwatch2.Start();
  4610. #region 一次性读取所有数据
  4611. // 一次性读取所有数据
  4612. result = FunsEip[plcNo]
  4613. .Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4614. if (result.Item1 != 0)
  4615. {
  4616. //richTextBox1.AppendText("\n" + strRet);
  4617. }
  4618. else
  4619. {
  4620. //richTextBox1.AppendText("\n" + "读取成功");
  4621. //richTextBox1.AppendText("\n" + "读取成功");
  4622. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4623. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4624. ? XiaomiDeviceState.Unknown
  4625. : (XiaomiDeviceState)xmDeviceStateInt;
  4626. s6PLCData["a6OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  4627. s6PLCData["a6OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  4628. s6PLCData["a6OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  4629. }
  4630. #endregion 一次性读取所有数据
  4631. stopwatch2.Stop();
  4632. #region 进站
  4633. try
  4634. {
  4635. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4636. {
  4637. lock (lockObj)
  4638. {
  4639. if (!ProgressState)
  4640. {
  4641. ProgressState = true;
  4642. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
  4643. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4644. out ProgressState));
  4645. }
  4646. }
  4647. }
  4648. }
  4649. catch (Exception ex)
  4650. {
  4651. ProgressState = false;
  4652. string str = ex.StackTrace;
  4653. AddMessage_Station(stationNameStr, LogType.Error,
  4654. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4655. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4656. }
  4657. #endregion 进站
  4658. #region 出站
  4659. try
  4660. {
  4661. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4662. {
  4663. lock (lockObj)
  4664. {
  4665. if (!ProgressState)
  4666. {
  4667. ProgressState = true;
  4668. ;
  4669. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
  4670. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4671. out ProgressState));
  4672. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4673. }
  4674. }
  4675. }
  4676. }
  4677. catch (Exception ex)
  4678. {
  4679. ProgressState = false;
  4680. string str = ex.StackTrace;
  4681. AddMessage_Station(stationNameStr, LogType.Error,
  4682. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4683. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4684. }
  4685. #endregion 出站
  4686. #region 节拍接口
  4687. try
  4688. {
  4689. int a60EEType = (int)s6PLCData["a60EEType"];
  4690. int a60EETypeGOld = (int)s6PLCSignal_Old["a60EEType"];
  4691. //若设备紧急复原后节拍重置
  4692. if (a60EEType == 1)
  4693. {
  4694. a60EETypeGOld = 0;
  4695. }
  4696. if (a60EEType != a60EETypeGOld)
  4697. {
  4698. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  4699. if ((a60EETypeGOld == 1 && a60EEType != 2) || (a60EETypeGOld == 3 && a60EEType != 4) ||
  4700. (a60EETypeGOld == 5 && a60EEType != 6))
  4701. {
  4702. //写入PLC
  4703. stPLC_MesData.iotData.beatReturn = 2; //NG
  4704. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  4705. AddMessage(LogType.Info,
  4706. stationNameStr +
  4707. $"_节拍接口-- 设备本次上传节拍[{a60EEType}],未上传节拍[{a60EETypeGOld}]的结束信号,请检查;总用时" +
  4708. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  4709. "ms");
  4710. return;
  4711. }
  4712. else
  4713. {
  4714. Task.Run(() =>
  4715. S6节拍接口(plcNo, stationNameStr, tagBaseName,
  4716. stPLC_MesData.iotData)); // MreTasks[4].Set();
  4717. }
  4718. s6PLCSignal_Old["a60EEType"] = s6PLCData["a60EEType"];
  4719. }
  4720. }
  4721. catch (Exception ex)
  4722. {
  4723. string str = ex.StackTrace;
  4724. AddMessage_Station(stationNameStr, LogType.Error,
  4725. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4726. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4727. }
  4728. #endregion
  4729. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4730. stopwatch1.Stop();
  4731. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4732. }
  4733. else
  4734. {
  4735. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4736. AddMessage_Station(stationNameStr, LogType.Info,
  4737. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4738. FunsEip[plcNo].Connect(); // 重连
  4739. }
  4740. }
  4741. catch (Exception ex)
  4742. {
  4743. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4744. AddMessage_Station(stationNameStr, LogType.Error,
  4745. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4746. }
  4747. Thread.Sleep(IntervalReadPLC);
  4748. }
  4749. }
  4750. /// <summary>
  4751. /// [S6] 顶盖装配设备 - 进站
  4752. /// </summary>
  4753. /// <param name="plcNo">PLC编号</param>
  4754. /// <param name="stationNameStr">工站全称</param>
  4755. /// <param name="stPLC_MesData"></param>
  4756. /// <param name="tagMesCommName"></param>
  4757. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  4758. string tagBarsetName, out bool ProgressState)
  4759. {
  4760. Stopwatch stopwatch1 = new Stopwatch();
  4761. Stopwatch stopwatch2 = new Stopwatch();
  4762. try
  4763. {
  4764. stopwatch1.Start();
  4765. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4766. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4767. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  4768. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  4769. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4770. bool pass = a1Result == 1;
  4771. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4772. //strCarrierBarcode = "N801A-003";
  4773. //载具码验证产品码
  4774. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4775. if (string.IsNullOrEmpty(strProductBarcode))
  4776. {
  4777. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4778. }
  4779. sn = strProductBarcode;
  4780. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4781. if (OpenDailogFalg)
  4782. {
  4783. using (var dialog = new BandBarodeDialog())
  4784. {
  4785. dialog._CarrierBarcode = strCarrierBarcode;
  4786. dialog._ProductBarcode = sn;
  4787. var rs = dialog.ShowDialog();
  4788. if (rs == DialogResult.OK)
  4789. {
  4790. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  4791. OpenDailogFalg = false;//关闭扫码
  4792. }
  4793. else {
  4794. ProgressState = false;
  4795. return;
  4796. }
  4797. }
  4798. }
  4799. // 产品SN(物料码)校验
  4800. List<TestItem> item = new List<TestItem>();
  4801. stopwatch2.Start();
  4802. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4803. item, MachineId, StationId, pass);
  4804. stopwatch2.Stop();
  4805. //指令执行结果 1:OK 110:失败
  4806. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4807. if (mesResultFrmWeb == 1)
  4808. {
  4809. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4810. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4811. }
  4812. //进站结果写入PLC
  4813. CommandFromPLC resultToPlC = new CommandFromPLC();
  4814. resultToPlC.cmd = 0;
  4815. resultToPlC.cmdParam = 0; //指令参数
  4816. resultToPlC.cmdResult = mesResultFrmWeb;
  4817. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4818. }
  4819. catch (Exception ex)
  4820. {
  4821. string str = ex.StackTrace;
  4822. AddMessage(LogType.Error,
  4823. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4824. str.Length - str.LastIndexOf("\\") - 1));
  4825. CommandFromPLC resultToPlC = new CommandFromPLC();
  4826. resultToPlC.cmd = 0;
  4827. resultToPlC.cmdParam = 0; //指令参数
  4828. resultToPlC.cmdResult = 110;
  4829. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4830. }
  4831. stopwatch1.Stop();
  4832. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4833. AddMessage(LogType.Info,
  4834. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4835. stopwatch2.ElapsedMilliseconds + "ms");
  4836. ProgressState = false;
  4837. OpenDailogFalg = true; //开启下一个物料的扫码
  4838. }
  4839. /// <summary>
  4840. /// [S6] 顶盖装配设备 - 出站接口
  4841. /// </summary>
  4842. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  4843. string stationCode, string stationName, out bool ProgressState)
  4844. {
  4845. Stopwatch stopwatch1 = new Stopwatch();
  4846. Stopwatch stopwatch2 = new Stopwatch();
  4847. try
  4848. {
  4849. stopwatch1.Start();
  4850. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4851. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4852. string processItem = stationName; // 测试项目
  4853. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4854. string supplierCode = ""; // 供应商代码
  4855. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4856. string batch_num = GlobalContext.BatchNumber; // 批次号
  4857. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4858. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4859. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4860. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  4861. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  4862. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4863. bool pass = a1Result == 1;
  4864. //根据载具码获取产品码
  4865. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4866. if (string.IsNullOrEmpty(strProductBarcode))
  4867. {
  4868. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4869. }
  4870. sn = strProductBarcode;
  4871. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4872. List<TestItem> items = new List<TestItem>();
  4873. items.Add(new TestItem()
  4874. {
  4875. Parameter_name = "载具码",
  4876. Parameter_value = CarrierBarcode,
  4877. Parameter_unit = ""
  4878. });
  4879. items.Add(new TestItem()
  4880. {
  4881. Parameter_name = "产品码",
  4882. Parameter_value = sn,
  4883. Parameter_unit = ""
  4884. });
  4885. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4886. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4887. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  4888. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4889. if (mesResultFrmWeb == 1)
  4890. {
  4891. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4892. AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
  4893. }
  4894. stopwatch2.Start();
  4895. //进站结果写入PLC
  4896. CommandFromPLC resultToPlC = new CommandFromPLC();
  4897. resultToPlC.cmd = 0;
  4898. resultToPlC.cmdParam = 0; //指令参数
  4899. resultToPlC.cmdResult = mesResultFrmWeb;
  4900. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4901. stopwatch2.Stop();
  4902. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4903. //保存PLC返回MES数据到本地
  4904. ResponseMessage message = new ResponseMessage();
  4905. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  4906. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  4907. if (message.result == false)
  4908. {
  4909. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4910. }
  4911. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4912. }
  4913. catch (Exception ex)
  4914. {
  4915. stopwatch2.Start();
  4916. CommandFromPLC resultToPlC = new CommandFromPLC();
  4917. resultToPlC.cmd = 0;
  4918. resultToPlC.cmdParam = 0; //指令参数
  4919. resultToPlC.cmdResult = 110;
  4920. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4921. stopwatch2.Stop();
  4922. string str = ex.StackTrace;
  4923. AddMessage(LogType.Error,
  4924. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4925. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4926. }
  4927. stopwatch1.Stop();
  4928. AddMessage(LogType.Info,
  4929. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4930. stopwatch2.ElapsedMilliseconds + "ms");
  4931. ProgressState = false;
  4932. }
  4933. private void S6节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  4934. {
  4935. Stopwatch stopwatch1 = new Stopwatch();
  4936. Stopwatch stopwatch2 = new Stopwatch();
  4937. string resultStr = string.Empty;
  4938. try
  4939. {
  4940. stopwatch1.Start();
  4941. string oEEType = ((int)s1PLCData["a6OEEType"]).ToString(); // 节拍类型(plc写入)
  4942. string a60EEPartNo = (string)s1PLCData["a60EEPartNo"]; // 物料码
  4943. a60EEPartNo = a60EEPartNo.Replace("\0", "");
  4944. string a60EEVehicleCode = (string)s1PLCData["a60EEVehicleCode"]; // 载具SN
  4945. a60EEVehicleCode = a60EEVehicleCode.Replace("\0", "");
  4946. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4947. if (!actionBool)
  4948. {
  4949. stopwatch2.Start();
  4950. //写入PLC
  4951. iot_data.beatReturn = 2; //NG
  4952. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4953. stopwatch2.Stop();
  4954. AddMessage(LogType.Info,
  4955. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  4956. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4957. return;
  4958. }
  4959. //作业开始后要有物料和载具信息
  4960. if (string.IsNullOrEmpty(a60EEPartNo) && string.IsNullOrEmpty(a60EEVehicleCode) &&
  4961. Convert.ToInt32(oEEType) > 2)
  4962. {
  4963. stopwatch2.Start();
  4964. //写入PLC
  4965. iot_data.beatReturn = 2; //NG
  4966. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4967. stopwatch2.Stop();
  4968. AddMessage_Station(stationNameStr, LogType.Info,
  4969. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  4970. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4971. return;
  4972. }
  4973. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEPartNo))
  4974. {
  4975. stopwatch2.Start();
  4976. //写入PLC
  4977. iot_data.beatReturn = 2; //NG
  4978. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4979. stopwatch2.Stop();
  4980. AddMessage_Station(stationNameStr, LogType.Info,
  4981. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  4982. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4983. return;
  4984. }
  4985. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEVehicleCode))
  4986. {
  4987. stopwatch2.Start();
  4988. //写入PLC
  4989. iot_data.beatReturn = 2; //NG
  4990. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4991. stopwatch2.Stop();
  4992. AddMessage_Station(stationNameStr, LogType.Info,
  4993. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  4994. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4995. return;
  4996. }
  4997. short _result = 0;
  4998. // 上传OEE
  4999. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a60EEPartNo, a60EEVehicleCode);
  5000. _result = result.Item1;
  5001. resultStr = result.Item2;
  5002. if (_result == 1)
  5003. {
  5004. stopwatch2.Start();
  5005. //写入PLC
  5006. iot_data.beatReturn = 1; //OK
  5007. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5008. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  5009. stopwatch2.Stop();
  5010. }
  5011. else
  5012. {
  5013. stopwatch2.Start();
  5014. //写入PLC
  5015. iot_data.beatReturn = 2; //NG
  5016. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5017. stopwatch2.Stop();
  5018. AddMessage_Station(stationNameStr, LogType.Error,
  5019. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  5020. }
  5021. }
  5022. catch (Exception ex)
  5023. {
  5024. string str = ex.StackTrace;
  5025. AddMessage_Station(stationNameStr, LogType.Error,
  5026. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  5027. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5028. // MES_Flag
  5029. stopwatch2.Start();
  5030. //写入PLC
  5031. iot_data.beatReturn = 2; //NG
  5032. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5033. stopwatch2.Stop();
  5034. }
  5035. stopwatch1.Stop();
  5036. AddMessage(LogType.Info,
  5037. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5038. stopwatch2.ElapsedMilliseconds + "ms");
  5039. }
  5040. #endregion
  5041. #region S7
  5042. private Dictionary<string, object> s7PLCSignal_Old = new Dictionary<string, object>();
  5043. private Dictionary<string, object> s7PLCData = new Dictionary<string, object>();
  5044. /// <summary>
  5045. /// [S7] 锁螺丝设备
  5046. /// </summary>
  5047. /// <param name="plcNo">PLC编号</param>
  5048. private void ReadStation_S7(int plcNo)
  5049. {
  5050. string stationCode = "[OP70]";
  5051. string stationName = "上盖板锁螺丝";
  5052. string stationNameStr = stationCode + stationName;
  5053. string tagBaseName = "g_OP70_MES"; //标签变量名称
  5054. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5055. string tagAgvCommName = "agvCommFrmPC";
  5056. string tagBarsetName = "BarcodeSet";
  5057. string tagScrewDataset = "screwDataset";
  5058. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5059. s7PLCSignal_Old.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5060. s7PLCSignal_Old.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5061. // PLC数据字典 赋值
  5062. s7PLCData.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5063. s7PLCData.Add("a7OEEPartNo_left", ""); // 物料码(物料码还未绑定载具SN时必填)
  5064. s7PLCData.Add("a7OEEVehicleCode_left", ""); // 载具SN
  5065. s7PLCData.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5066. s7PLCData.Add("a7OEEPartNo_right", ""); // 物料码(物料码还未绑定载具SN时必填)
  5067. s7PLCData.Add("a7OEEVehicleCode_right", ""); // 载具SN
  5068. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  5069. (int, string) result;
  5070. AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
  5071. 3000, 3000, "Left");
  5072. atlasScrewLeft.Initial();
  5073. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
  5074. 3000, 3000, "Right");
  5075. atlasScrewRight.Initial();
  5076. while (true)
  5077. {
  5078. try
  5079. {
  5080. if (!GlobalContext._IsCon_Funs1)
  5081. {
  5082. UpdatePLCMonitor(1, plcNo, 0);
  5083. continue;
  5084. }
  5085. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5086. {
  5087. Stopwatch stopwatch1 = new Stopwatch();
  5088. Stopwatch stopwatch2 = new Stopwatch();
  5089. stopwatch1.Start();
  5090. stopwatch2.Start();
  5091. #region 一次性读取所有数据
  5092. // 一次性读取所有数据
  5093. result = FunsEip[plcNo]
  5094. .Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5095. if (result.Item1 != 0)
  5096. {
  5097. //richTextBox1.AppendText("\n" + strRet);
  5098. }
  5099. else
  5100. {
  5101. //richTextBox1.AppendText("\n" + "读取成功");
  5102. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  5103. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  5104. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5105. ? XiaomiDeviceState.Unknown
  5106. : (XiaomiDeviceState)xmDeviceStateInt_L;
  5107. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5108. ? XiaomiDeviceState.Unknown
  5109. : (XiaomiDeviceState)xmDeviceStateInt_R;
  5110. s7PLCData["a7OEEPartNo"] =stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5111. s7PLCData["a7OEEVehicleCode"] = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode; // 载具SN
  5112. s7PLCData["a7OEEType"] = stPLC_MesData.Left.iotData.BeatAction; // 节拍
  5113. s7PLCData["a7OEEVehicleCode_right"] = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode; // 载具SN
  5114. s7PLCData["a7OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction; // 节拍
  5115. }
  5116. #endregion 一次性读取所有数据
  5117. stopwatch2.Stop();
  5118. #region 左边进站
  5119. try
  5120. {
  5121. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5122. {
  5123. lock (lockObj)
  5124. {
  5125. if (!ProgressState)
  5126. {
  5127. ProgressState = true;
  5128. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
  5129. tagBaseName + ".Left." + tagMesCommName,
  5130. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
  5131. atlasScrewLeft));
  5132. }
  5133. }
  5134. }
  5135. }
  5136. catch (Exception ex)
  5137. {
  5138. ProgressState = false;
  5139. string str = ex.StackTrace;
  5140. AddMessage_Station(stationNameStr, LogType.Error,
  5141. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5142. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5143. }
  5144. #endregion 左边进站
  5145. #region 左边出站
  5146. try
  5147. {
  5148. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5149. {
  5150. lock (lockObj)
  5151. {
  5152. if (!ProgressState)
  5153. {
  5154. ProgressState = true;
  5155. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
  5156. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  5157. out ProgressState));
  5158. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  5159. }
  5160. }
  5161. }
  5162. }
  5163. catch (Exception ex)
  5164. {
  5165. ProgressState = false;
  5166. string str = ex.StackTrace;
  5167. AddMessage_Station(stationNameStr, LogType.Error,
  5168. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5169. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5170. }
  5171. #endregion 左边出站
  5172. #region 右边进站
  5173. try
  5174. {
  5175. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5176. {
  5177. lock (lockObj)
  5178. {
  5179. if (!ProgressState)
  5180. {
  5181. ProgressState = true;
  5182. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
  5183. tagBaseName + ".Right." + tagMesCommName,
  5184. tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
  5185. atlasScrewRight));
  5186. }
  5187. }
  5188. }
  5189. }
  5190. catch (Exception ex)
  5191. {
  5192. ProgressState = false;
  5193. string str = ex.StackTrace;
  5194. AddMessage_Station(stationNameStr, LogType.Error,
  5195. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5196. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5197. }
  5198. #endregion 右边进站
  5199. #region 右边出站
  5200. try
  5201. {
  5202. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5203. {
  5204. lock (lockObj)
  5205. {
  5206. if (!ProgressState)
  5207. {
  5208. ProgressState = true;
  5209. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
  5210. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  5211. out ProgressState));
  5212. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  5213. }
  5214. }
  5215. }
  5216. }
  5217. catch (Exception ex)
  5218. {
  5219. ProgressState = false;
  5220. string str = ex.StackTrace;
  5221. AddMessage_Station(stationNameStr, LogType.Error,
  5222. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5223. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5224. }
  5225. #endregion 右边出站
  5226. #region 节拍接口
  5227. try
  5228. {
  5229. #region 左工位 节拍
  5230. int a70EEType_left = (int)s7PLCData["a70EEType_left"];
  5231. int a70EETypeGOld_left = (int)s7PLCSignal_Old["a70EEType_left"];
  5232. //若设备紧急复原后节拍重置
  5233. if (a70EEType_left == 1)
  5234. {
  5235. a70EETypeGOld_left = 0;
  5236. }
  5237. if (a70EEType_left != a70EETypeGOld_left)
  5238. {
  5239. stationNameStr = stationNameStr + "_Left";
  5240. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  5241. if ((a70EETypeGOld_left == 1 && a70EEType_left != 2) || (a70EETypeGOld_left == 3 && a70EEType_left != 4) ||
  5242. (a70EETypeGOld_left == 5 && a70EEType_left != 6))
  5243. {
  5244. //写入PLC
  5245. stPLC_MesData.Left.iotData.beatReturn = 2; //NG
  5246. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
  5247. AddMessage(LogType.Info,
  5248. stationNameStr +
  5249. $"_节拍接口-- 设备本次上传节拍[{a70EEType_left}],未上传节拍[{a70EETypeGOld_left}]的结束信号,请检查;总用时" +
  5250. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  5251. "ms");
  5252. return;
  5253. }
  5254. else
  5255. {
  5256. Task.Run(() =>
  5257. S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
  5258. stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
  5259. }
  5260. s7PLCSignal_Old["a70EEType_left"] = s7PLCData["a70EEType_left"];
  5261. }
  5262. #endregion 左工位 节拍
  5263. #region 右工位 节拍
  5264. int a70EEType_right = (int)s7PLCData["a70EEType_right"];
  5265. int a70EETypeGOld_right = (int)s7PLCSignal_Old["a70EEType_right"];
  5266. //若设备紧急复原后节拍重置
  5267. if (a70EEType_right == 1)
  5268. {
  5269. a70EETypeGOld_right = 0;
  5270. }
  5271. if (a70EEType_right != a70EETypeGOld_right)
  5272. {
  5273. stationNameStr = stationNameStr + "_Right";
  5274. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  5275. if ((a70EETypeGOld_right == 1 && a70EEType_right != 2) || (a70EETypeGOld_right == 3 && a70EEType_right != 4) ||
  5276. (a70EETypeGOld_right == 5 && a70EEType_right != 6))
  5277. {
  5278. //写入PLC
  5279. stPLC_MesData.Right.iotData.beatReturn = 2; //NG
  5280. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
  5281. AddMessage(LogType.Info,
  5282. stationNameStr +
  5283. $"_节拍接口-- 设备本次上传节拍[{a70EEType_right}],未上传节拍[{a70EETypeGOld_right}]的结束信号,请检查;总用时" +
  5284. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  5285. "ms");
  5286. return;
  5287. }
  5288. else
  5289. {
  5290. Task.Run(() =>
  5291. S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
  5292. stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
  5293. }
  5294. s7PLCSignal_Old["a70EEType_right"] = s7PLCData["a70EEType_right"];
  5295. }
  5296. #endregion 右工位 节拍
  5297. }
  5298. catch (Exception ex)
  5299. {
  5300. string str = ex.StackTrace;
  5301. AddMessage_Station(stationNameStr, LogType.Error,
  5302. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5303. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5304. }
  5305. #endregion
  5306. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5307. stopwatch1.Stop();
  5308. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5309. }
  5310. else
  5311. {
  5312. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5313. AddMessage_Station(stationNameStr, LogType.Info,
  5314. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5315. FunsEip[plcNo].Connect(); // 重连
  5316. }
  5317. }
  5318. catch (Exception ex)
  5319. {
  5320. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5321. AddMessage_Station(stationNameStr, LogType.Error,
  5322. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5323. }
  5324. Thread.Sleep(IntervalReadPLC);
  5325. }
  5326. }
  5327. /// <summary>
  5328. /// [S7] 锁螺丝设备 - 进站
  5329. /// </summary>
  5330. /// <param name="plcNo">PLC编号</param>
  5331. /// <param name="stationNameStr">工站全称</param>
  5332. /// <param name="stPLC_MesData"></param>
  5333. /// <param name="tagMesCommName"></param>
  5334. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5335. string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
  5336. {
  5337. Stopwatch stopwatch1 = new Stopwatch();
  5338. Stopwatch stopwatch2 = new Stopwatch();
  5339. string atlasSn = string.Empty;
  5340. try
  5341. {
  5342. stopwatch1.Start();
  5343. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  5344. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5345. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  5346. string StationId = string.Empty; // 工位ID(可配置)
  5347. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5348. bool pass = a1Result == 1;
  5349. if (direction == "Left")
  5350. {
  5351. StationId = GlobalContext.S7_StationId_1;
  5352. }
  5353. if (direction == "Right")
  5354. {
  5355. StationId = GlobalContext.S7_StationId_2;
  5356. }
  5357. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5358. //载具码验证产品码
  5359. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5360. if (string.IsNullOrEmpty(strProductBarcode))
  5361. {
  5362. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5363. }
  5364. sn = strProductBarcode;
  5365. atlasSn = strProductBarcode;
  5366. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5367. if (direction == "Left")
  5368. {
  5369. isCollectingFlagLeft = false; //采集螺丝数据结束
  5370. }
  5371. if (direction == "Right")
  5372. {
  5373. isCollectingFlagRight = false; //采集螺丝数据结束
  5374. }
  5375. // 产品SN(物料码)校验
  5376. List<TestItem> item = new List<TestItem>();
  5377. stopwatch2.Start();
  5378. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5379. item, MachineId, StationId, pass);
  5380. stopwatch2.Stop();
  5381. //指令执行结果 1:OK 110:失败
  5382. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5383. if (mesResultFrmWeb == 1)
  5384. {
  5385. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5386. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5387. }
  5388. //进站结果写入PLC
  5389. CommandFromPLC resultToPlC = new CommandFromPLC();
  5390. resultToPlC.cmd = 0;
  5391. resultToPlC.cmdParam = 0; //指令参数
  5392. resultToPlC.cmdResult = mesResultFrmWeb;
  5393. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5394. }
  5395. catch (Exception ex)
  5396. {
  5397. string str = ex.StackTrace;
  5398. AddMessage(LogType.Error,
  5399. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5400. str.Length - str.LastIndexOf("\\") - 1));
  5401. CommandFromPLC resultToPlC = new CommandFromPLC();
  5402. resultToPlC.cmd = 0;
  5403. resultToPlC.cmdParam = 0; //指令参数
  5404. resultToPlC.cmdResult = 110;
  5405. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5406. }
  5407. stopwatch1.Stop();
  5408. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  5409. AddMessage(LogType.Info,
  5410. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5411. stopwatch2.ElapsedMilliseconds + "ms");
  5412. ProgressState = false;
  5413. //开始采集螺丝数据
  5414. if (direction == "Left")
  5415. {
  5416. isCollectingFlagLeft = true;
  5417. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  5418. }
  5419. if (direction == "Right")
  5420. {
  5421. isCollectingFlagRight = true;
  5422. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  5423. }
  5424. }
  5425. /// <summary>
  5426. /// [S7] 锁螺丝设备 - 出站
  5427. /// </summary>
  5428. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5429. string stationCode, string stationName, string direction, out bool ProgressState)
  5430. {
  5431. Stopwatch stopwatch1 = new Stopwatch();
  5432. Stopwatch stopwatch2 = new Stopwatch();
  5433. try
  5434. {
  5435. stopwatch1.Start();
  5436. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  5437. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5438. string processItem = stationName; // 测试项目
  5439. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5440. string supplierCode = ""; // 供应商代码
  5441. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5442. string batch_num = GlobalContext.BatchNumber; // 批次号
  5443. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5444. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5445. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5446. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  5447. string StationId = string.Empty; // 工位ID(可配置)
  5448. if (direction == "Left")
  5449. {
  5450. StationId = GlobalContext.S7_StationId_1;
  5451. }
  5452. if (direction == "Right")
  5453. {
  5454. StationId = GlobalContext.S7_StationId_2;
  5455. }
  5456. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5457. a1Result = 1;
  5458. bool pass = a1Result == 1;
  5459. //根据载具码获取产品码
  5460. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5461. if (string.IsNullOrEmpty(strProductBarcode))
  5462. {
  5463. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5464. }
  5465. sn = strProductBarcode;
  5466. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5467. List<TestItem> items = new List<TestItem>();
  5468. items.Add(new TestItem()
  5469. {
  5470. Parameter_name = "载具码",
  5471. Parameter_value = CarrierBarcode,
  5472. Parameter_unit = ""
  5473. });
  5474. items.Add(new TestItem()
  5475. {
  5476. Parameter_name = "产品码",
  5477. Parameter_value = sn,
  5478. Parameter_unit = ""
  5479. });
  5480. //if (direction == "Right")
  5481. //{
  5482. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5483. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode
  5484. , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  5485. //}
  5486. //if (direction == "Left")
  5487. //{
  5488. // isCollectingFlagLeft = false;//采集螺丝数据结束
  5489. //}
  5490. //if (direction == "Right")
  5491. //{
  5492. // isCollectingFlagRight = false;//采集螺丝数据结束
  5493. //}
  5494. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5495. if (mesResultFrmWeb == 1)
  5496. {
  5497. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5498. AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
  5499. }
  5500. stopwatch2.Start();
  5501. //进站结果写入PLC
  5502. CommandFromPLC resultToPlC = new CommandFromPLC();
  5503. resultToPlC.cmd = 0;
  5504. resultToPlC.cmdParam = 0; //指令参数
  5505. resultToPlC.cmdResult = mesResultFrmWeb;
  5506. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5507. stopwatch2.Stop();
  5508. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  5509. //保存PLC返回MES数据到本地
  5510. ResponseMessage message = new ResponseMessage();
  5511. if (direction == "Left")
  5512. {
  5513. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5514. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5515. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5516. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  5517. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5518. if (message.result == false)
  5519. {
  5520. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  5521. }
  5522. }
  5523. if (direction == "Right")
  5524. {
  5525. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5526. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5527. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5528. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  5529. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5530. if (message.result == false)
  5531. {
  5532. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  5533. }
  5534. }
  5535. //保存螺丝数据到txt
  5536. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
  5537. stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  5538. if (result.Item1 != 0)
  5539. {
  5540. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  5541. }
  5542. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
  5543. }
  5544. catch (Exception ex)
  5545. {
  5546. stopwatch2.Start();
  5547. CommandFromPLC resultToPlC = new CommandFromPLC();
  5548. resultToPlC.cmd = 0;
  5549. resultToPlC.cmdParam = 0; //指令参数
  5550. resultToPlC.cmdResult = 110;
  5551. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5552. stopwatch2.Stop();
  5553. string str = ex.StackTrace;
  5554. AddMessage(LogType.Error,
  5555. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5556. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5557. }
  5558. stopwatch1.Stop();
  5559. AddMessage(LogType.Info,
  5560. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5561. stopwatch2.ElapsedMilliseconds + "ms");
  5562. ProgressState = false;
  5563. }
  5564. private void S7节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  5565. {
  5566. Stopwatch stopwatch1 = new Stopwatch();
  5567. Stopwatch stopwatch2 = new Stopwatch();
  5568. string resultStr = string.Empty;
  5569. try
  5570. {
  5571. stopwatch1.Start();
  5572. string oEEType = ((int)s1PLCData["a7OEEType"]).ToString(); // 节拍类型(plc写入)
  5573. string a7OEEPartNo = (string)s1PLCData["a7OEEPartNo"]; // 物料码
  5574. a7OEEPartNo = a7OEEPartNo.Replace("\0", "");
  5575. string a7OEEVehicleCode = (string)s1PLCData["a7OEEVehicleCode"]; // 载具SN
  5576. a7OEEVehicleCode = a7OEEVehicleCode.Replace("\0", "");
  5577. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5578. if (!actionBool)
  5579. {
  5580. stopwatch2.Start();
  5581. //写入PLC
  5582. iot_data.beatReturn = 2; //NG
  5583. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5584. stopwatch2.Stop();
  5585. AddMessage(LogType.Info,
  5586. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  5587. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5588. return;
  5589. }
  5590. //作业开始后要有物料和载具信息
  5591. if (string.IsNullOrEmpty(a7OEEPartNo) && string.IsNullOrEmpty(a7OEEVehicleCode) &&
  5592. Convert.ToInt32(oEEType) > 2)
  5593. {
  5594. stopwatch2.Start();
  5595. //写入PLC
  5596. iot_data.beatReturn = 2; //NG
  5597. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5598. stopwatch2.Stop();
  5599. AddMessage_Station(stationNameStr, LogType.Info,
  5600. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  5601. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5602. return;
  5603. }
  5604. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEPartNo))
  5605. {
  5606. stopwatch2.Start();
  5607. //写入PLC
  5608. iot_data.beatReturn = 2; //NG
  5609. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5610. stopwatch2.Stop();
  5611. AddMessage_Station(stationNameStr, LogType.Info,
  5612. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  5613. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5614. return;
  5615. }
  5616. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEVehicleCode))
  5617. {
  5618. stopwatch2.Start();
  5619. //写入PLC
  5620. iot_data.beatReturn = 2; //NG
  5621. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5622. stopwatch2.Stop();
  5623. AddMessage_Station(stationNameStr, LogType.Info,
  5624. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  5625. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5626. return;
  5627. }
  5628. short _result = 0;
  5629. // 上传OEE
  5630. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a7OEEPartNo, a7OEEVehicleCode);
  5631. _result = result.Item1;
  5632. resultStr = result.Item2;
  5633. if (_result == 1)
  5634. {
  5635. stopwatch2.Start();
  5636. //写入PLC
  5637. iot_data.beatReturn = 1; //OK
  5638. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5639. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  5640. stopwatch2.Stop();
  5641. }
  5642. else
  5643. {
  5644. stopwatch2.Start();
  5645. //写入PLC
  5646. iot_data.beatReturn = 2; //NG
  5647. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5648. stopwatch2.Stop();
  5649. AddMessage_Station(stationNameStr, LogType.Error,
  5650. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  5651. }
  5652. }
  5653. catch (Exception ex)
  5654. {
  5655. string str = ex.StackTrace;
  5656. AddMessage_Station(stationNameStr, LogType.Error,
  5657. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  5658. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5659. // MES_Flag
  5660. stopwatch2.Start();
  5661. //写入PLC
  5662. iot_data.beatReturn = 2; //NG
  5663. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5664. stopwatch2.Stop();
  5665. }
  5666. stopwatch1.Stop();
  5667. AddMessage(LogType.Info,
  5668. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5669. stopwatch2.ElapsedMilliseconds + "ms");
  5670. }
  5671. #endregion
  5672. #region S8
  5673. private Dictionary<string, object> s8PLCData = new Dictionary<string, object>();
  5674. private Dictionary<string, object> s8PLCSignal_Old = new Dictionary<string, object>();
  5675. /// <summary>
  5676. /// [S8] 3D螺丝高度检测设备
  5677. /// </summary>
  5678. /// <param name="plcNo">PLC编号</param>
  5679. private void ReadStation_S8(int plcNo)
  5680. {
  5681. string stationCode = "[OP80]";
  5682. string stationName = "NG下料";
  5683. string stationNameStr = stationCode + stationName;
  5684. string tagBaseName = "g_OP80_MES"; //标签变量名称
  5685. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5686. string tagAgvCommName = "agvCommFrmPC";
  5687. string tagBarsetName = "BarcodeSet";
  5688. // 触发信号字典
  5689. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5690. s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
  5691. // PLC数据字典 赋值
  5692. s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
  5693. s8PLCData.Add("a8OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  5694. s8PLCData.Add("a8OEEVehicleCode", ""); // 载具SN
  5695. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  5696. (int, string) result;
  5697. while (true)
  5698. {
  5699. try
  5700. {
  5701. if (!GlobalContext._IsCon_Funs1)
  5702. {
  5703. UpdatePLCMonitor(1, plcNo, 0);
  5704. continue;
  5705. }
  5706. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5707. {
  5708. Stopwatch stopwatch1 = new Stopwatch();
  5709. Stopwatch stopwatch2 = new Stopwatch();
  5710. stopwatch1.Start();
  5711. stopwatch2.Start();
  5712. #region 一次性读取所有数据
  5713. // 一次性读取所有数据
  5714. result = FunsEip[plcNo]
  5715. .Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5716. if (result.Item1 != 0)
  5717. {
  5718. //richTextBox1.AppendText("\n" + strRet);
  5719. }
  5720. else
  5721. {
  5722. //richTextBox1.AppendText("\n" + "读取成功");
  5723. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  5724. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  5725. ? XiaomiDeviceState.Unknown
  5726. : (XiaomiDeviceState)xmDeviceStateInt;
  5727. s8PLCData["a8OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5728. s8PLCData["a8OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  5729. s8PLCData["a8OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  5730. }
  5731. #endregion 一次性读取所有数据
  5732. stopwatch2.Stop();
  5733. #region 进站
  5734. try
  5735. {
  5736. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5737. {
  5738. lock (lockObj)
  5739. {
  5740. if (!ProgressState)
  5741. {
  5742. ProgressState = true;
  5743. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
  5744. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  5745. out ProgressState));
  5746. }
  5747. }
  5748. }
  5749. }
  5750. catch (Exception ex)
  5751. {
  5752. ProgressState = false;
  5753. string str = ex.StackTrace;
  5754. AddMessage_Station(stationNameStr, LogType.Error,
  5755. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5756. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5757. }
  5758. #endregion 进站
  5759. #region 出站
  5760. try
  5761. {
  5762. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5763. {
  5764. lock (lockObj)
  5765. {
  5766. if (!ProgressState)
  5767. {
  5768. ProgressState = true;
  5769. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
  5770. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5771. out ProgressState));
  5772. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5773. }
  5774. }
  5775. }
  5776. }
  5777. catch (Exception ex)
  5778. {
  5779. ProgressState = false;
  5780. string str = ex.StackTrace;
  5781. AddMessage_Station(stationNameStr, LogType.Error,
  5782. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5783. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5784. }
  5785. #endregion 出站
  5786. #region 节拍接口
  5787. try
  5788. {
  5789. int a80EEType = (int)s9PLCData["a80EEType"];
  5790. int a80EETypeGOld = (int)s9PLCSignal_Old["a80EEType"];
  5791. //若设备紧急复原后节拍重置
  5792. if (a80EEType == 1)
  5793. {
  5794. a80EETypeGOld = 0;
  5795. }
  5796. if (a80EEType != a80EETypeGOld)
  5797. {
  5798. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  5799. if ((a80EETypeGOld == 1 && a80EEType != 2) || (a80EETypeGOld == 3 && a80EEType != 4) ||
  5800. (a80EETypeGOld == 5 && a80EEType != 6))
  5801. {
  5802. //写入PLC
  5803. stPLC_MesData.iotData.beatReturn = 2; //NG
  5804. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  5805. AddMessage(LogType.Info,
  5806. stationNameStr +
  5807. $"_节拍接口-- 设备本次上传节拍[{a80EEType}],未上传节拍[{a80EETypeGOld}]的结束信号,请检查;总用时" +
  5808. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  5809. "ms");
  5810. return;
  5811. }
  5812. else
  5813. {
  5814. Task.Run(() =>
  5815. S8节拍接口(plcNo, stationNameStr, tagBaseName,
  5816. stPLC_MesData.iotData)); // MreTasks[4].Set();
  5817. }
  5818. s8PLCSignal_Old["a80EEType"] = s8PLCData["a80EEType"];
  5819. }
  5820. }
  5821. catch (Exception ex)
  5822. {
  5823. string str = ex.StackTrace;
  5824. AddMessage_Station(stationNameStr, LogType.Error,
  5825. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5826. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5827. }
  5828. #endregion
  5829. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5830. stopwatch1.Stop();
  5831. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5832. }
  5833. else
  5834. {
  5835. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5836. AddMessage_Station(stationNameStr, LogType.Info,
  5837. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5838. FunsEip[plcNo].Connect(); // 重连
  5839. }
  5840. }
  5841. catch (Exception ex)
  5842. {
  5843. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5844. AddMessage_Station(stationNameStr, LogType.Error,
  5845. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5846. }
  5847. Thread.Sleep(IntervalReadPLC);
  5848. }
  5849. }
  5850. /// <summary>
  5851. /// [S8] 3D螺丝高度检测设备 - 进站
  5852. /// </summary>
  5853. /// <param name="plcNo">PLC编号</param>
  5854. /// <param name="stationNameStr">工站全称</param>
  5855. /// <param name="stPLC_MesData"></param>
  5856. /// <param name="tagMesCommName"></param>
  5857. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  5858. string tagBarsetName, out bool ProgressState)
  5859. {
  5860. Stopwatch stopwatch1 = new Stopwatch();
  5861. Stopwatch stopwatch2 = new Stopwatch();
  5862. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5863. bool pass = a1Result == 1;
  5864. try
  5865. {
  5866. stopwatch1.Start();
  5867. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5868. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5869. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  5870. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  5871. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5872. //载具码验证产品码
  5873. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5874. if (string.IsNullOrEmpty(strProductBarcode))
  5875. {
  5876. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5877. }
  5878. sn = strProductBarcode;
  5879. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5880. // 产品SN(物料码)校验
  5881. List<TestItem> item = new List<TestItem>();
  5882. stopwatch2.Start();
  5883. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5884. item, MachineId, StationId, pass);
  5885. stopwatch2.Stop();
  5886. //指令执行结果 1:OK 110:失败
  5887. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5888. if (mesResultFrmWeb == 1)
  5889. {
  5890. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5891. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5892. }
  5893. //进站结果写入PLC
  5894. CommandFromPLC resultToPlC = new CommandFromPLC();
  5895. resultToPlC.cmd = 0;
  5896. resultToPlC.cmdParam = 0; //指令参数
  5897. resultToPlC.cmdResult = mesResultFrmWeb;
  5898. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5899. }
  5900. catch (Exception ex)
  5901. {
  5902. string str = ex.StackTrace;
  5903. AddMessage(LogType.Error,
  5904. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5905. str.Length - str.LastIndexOf("\\") - 1));
  5906. CommandFromPLC resultToPlC = new CommandFromPLC();
  5907. resultToPlC.cmd = 0;
  5908. resultToPlC.cmdParam = 0; //指令参数
  5909. resultToPlC.cmdResult = 110;
  5910. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5911. }
  5912. stopwatch1.Stop();
  5913. AddMessage(LogType.Info,
  5914. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5915. stopwatch2.ElapsedMilliseconds + "ms");
  5916. ProgressState = false;
  5917. }
  5918. /// <summary>
  5919. /// [S8] 3D螺丝高度检测设备 - 出站接口
  5920. /// </summary>
  5921. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  5922. string stationCode, string stationName, out bool ProgressState)
  5923. {
  5924. Stopwatch stopwatch1 = new Stopwatch();
  5925. Stopwatch stopwatch2 = new Stopwatch();
  5926. try
  5927. {
  5928. stopwatch1.Start();
  5929. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5930. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5931. string processItem = stationName; // 测试项目
  5932. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5933. string supplierCode = ""; // 供应商代码
  5934. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5935. string batch_num = GlobalContext.BatchNumber; // 批次号
  5936. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5937. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5938. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5939. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  5940. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  5941. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5942. bool pass = a1Result == 1;
  5943. //根据载具码获取产品码
  5944. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5945. if (string.IsNullOrEmpty(strProductBarcode))
  5946. {
  5947. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5948. }
  5949. sn = strProductBarcode;
  5950. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5951. List<TestItem> items = new List<TestItem>();
  5952. items.Add(new TestItem()
  5953. {
  5954. Parameter_name = "载具码",
  5955. Parameter_value = CarrierBarcode,
  5956. Parameter_unit = ""
  5957. });
  5958. items.Add(new TestItem()
  5959. {
  5960. Parameter_name = "产品码",
  5961. Parameter_value = sn,
  5962. Parameter_unit = ""
  5963. });
  5964. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5965. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5966. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  5967. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5968. if (mesResultFrmWeb == 1)
  5969. {
  5970. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5971. AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
  5972. }
  5973. stopwatch2.Start();
  5974. //进站结果写入PLC
  5975. CommandFromPLC resultToPlC = new CommandFromPLC();
  5976. resultToPlC.cmd = 0;
  5977. resultToPlC.cmdParam = 0; //指令参数
  5978. resultToPlC.cmdResult = mesResultFrmWeb;
  5979. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5980. stopwatch2.Stop();
  5981. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5982. //保存PLC返回MES数据到本地
  5983. ResponseMessage message = new ResponseMessage();
  5984. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  5985. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5986. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  5987. if (message.result == false)
  5988. {
  5989. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  5990. }
  5991. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  5992. }
  5993. catch (Exception ex)
  5994. {
  5995. stopwatch2.Start();
  5996. CommandFromPLC resultToPlC = new CommandFromPLC();
  5997. resultToPlC.cmd = 0;
  5998. resultToPlC.cmdParam = 0; //指令参数
  5999. resultToPlC.cmdResult = 110;
  6000. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6001. stopwatch2.Stop();
  6002. string str = ex.StackTrace;
  6003. AddMessage(LogType.Error,
  6004. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6005. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6006. }
  6007. stopwatch1.Stop();
  6008. AddMessage(LogType.Info,
  6009. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6010. stopwatch2.ElapsedMilliseconds + "ms");
  6011. ProgressState = false;
  6012. }
  6013. private void S8节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  6014. {
  6015. Stopwatch stopwatch1 = new Stopwatch();
  6016. Stopwatch stopwatch2 = new Stopwatch();
  6017. string resultStr = string.Empty;
  6018. try
  6019. {
  6020. stopwatch1.Start();
  6021. string oEEType = ((int)s1PLCData["a8OEEType"]).ToString(); // 节拍类型(plc写入)
  6022. string a80EEPartNo = (string)s1PLCData["a80EEPartNo"]; // 物料码
  6023. a80EEPartNo = a80EEPartNo.Replace("\0", "");
  6024. string a80EEVehicleCode = (string)s1PLCData["a80EEVehicleCode"]; // 载具SN
  6025. a80EEVehicleCode = a80EEVehicleCode.Replace("\0", "");
  6026. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6027. if (!actionBool)
  6028. {
  6029. stopwatch2.Start();
  6030. //写入PLC
  6031. iot_data.beatReturn = 2; //NG
  6032. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6033. stopwatch2.Stop();
  6034. AddMessage(LogType.Info,
  6035. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  6036. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6037. return;
  6038. }
  6039. //作业开始后要有物料和载具信息
  6040. if (string.IsNullOrEmpty(a80EEPartNo) && string.IsNullOrEmpty(a80EEVehicleCode) &&
  6041. Convert.ToInt32(oEEType) > 2)
  6042. {
  6043. stopwatch2.Start();
  6044. //写入PLC
  6045. iot_data.beatReturn = 2; //NG
  6046. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6047. stopwatch2.Stop();
  6048. AddMessage_Station(stationNameStr, LogType.Info,
  6049. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  6050. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6051. return;
  6052. }
  6053. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEPartNo))
  6054. {
  6055. stopwatch2.Start();
  6056. //写入PLC
  6057. iot_data.beatReturn = 2; //NG
  6058. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6059. stopwatch2.Stop();
  6060. AddMessage_Station(stationNameStr, LogType.Info,
  6061. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  6062. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6063. return;
  6064. }
  6065. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEVehicleCode))
  6066. {
  6067. stopwatch2.Start();
  6068. //写入PLC
  6069. iot_data.beatReturn = 2; //NG
  6070. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6071. stopwatch2.Stop();
  6072. AddMessage_Station(stationNameStr, LogType.Info,
  6073. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  6074. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6075. return;
  6076. }
  6077. short _result = 0;
  6078. // 上传OEE
  6079. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a80EEPartNo, a80EEVehicleCode);
  6080. _result = result.Item1;
  6081. resultStr = result.Item2;
  6082. if (_result == 1)
  6083. {
  6084. stopwatch2.Start();
  6085. //写入PLC
  6086. iot_data.beatReturn = 1; //OK
  6087. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6088. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  6089. stopwatch2.Stop();
  6090. }
  6091. else
  6092. {
  6093. stopwatch2.Start();
  6094. //写入PLC
  6095. iot_data.beatReturn = 2; //NG
  6096. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6097. stopwatch2.Stop();
  6098. AddMessage_Station(stationNameStr, LogType.Error,
  6099. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  6100. }
  6101. }
  6102. catch (Exception ex)
  6103. {
  6104. string str = ex.StackTrace;
  6105. AddMessage_Station(stationNameStr, LogType.Error,
  6106. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  6107. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6108. // MES_Flag
  6109. stopwatch2.Start();
  6110. //写入PLC
  6111. iot_data.beatReturn = 2; //NG
  6112. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6113. stopwatch2.Stop();
  6114. }
  6115. stopwatch1.Stop();
  6116. AddMessage(LogType.Info,
  6117. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6118. stopwatch2.ElapsedMilliseconds + "ms");
  6119. }
  6120. #endregion
  6121. #region S9
  6122. private Dictionary<string, object> s9PLCData = new Dictionary<string, object>();
  6123. private Dictionary<string, object> s9PLCSignal_Old = new Dictionary<string, object>();
  6124. /// <summary>
  6125. /// [S9] 下料设备
  6126. /// </summary>
  6127. /// <param name="plcNo">PLC编号</param>
  6128. private void ReadStation_S9(int plcNo)
  6129. {
  6130. string stationCode = "[OP90]";
  6131. string stationName = "半成品下料";
  6132. string stationNameStr = stationCode + stationName;
  6133. string tagBaseName = "g_OP90_MES"; //标签变量名称
  6134. string tagMesCommName = "mesCommToPC"; //标签变量名称
  6135. string tagAgvCommName = "agvCommFrmPC";
  6136. string tagBarsetName = "BarcodeSet";
  6137. // 触发信号字典
  6138. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6139. s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6140. // PLC数据字典 赋值
  6141. s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6142. s9PLCData.Add("a9OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  6143. s9PLCData.Add("a9OEEVehicleCode", ""); // 载具SN
  6144. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  6145. (int, string) result;
  6146. while (true)
  6147. {
  6148. try
  6149. {
  6150. if (!GlobalContext._IsCon_Funs1)
  6151. {
  6152. UpdatePLCMonitor(1, plcNo, 0);
  6153. continue;
  6154. }
  6155. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  6156. {
  6157. Stopwatch stopwatch1 = new Stopwatch();
  6158. Stopwatch stopwatch2 = new Stopwatch();
  6159. stopwatch1.Start();
  6160. stopwatch2.Start();
  6161. #region 一次性读取所有数据
  6162. // 一次性读取所有数据
  6163. result = FunsEip[plcNo]
  6164. .Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6165. if (result.Item1 != 0)
  6166. {
  6167. //richTextBox1.AppendText("\n" + strRet);
  6168. }
  6169. else
  6170. {
  6171. //richTextBox1.AppendText("\n" + "读取成功");
  6172. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6173. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6174. ? XiaomiDeviceState.Unknown
  6175. : (XiaomiDeviceState)xmDeviceStateInt;
  6176. s9PLCData["a9OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  6177. s9PLCData["a9OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6178. s9PLCData["a9OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  6179. }
  6180. #endregion 一次性读取所有数据
  6181. stopwatch2.Stop();
  6182. #region 进站
  6183. try
  6184. {
  6185. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6186. {
  6187. lock (lockObj)
  6188. {
  6189. if (!ProgressState)
  6190. {
  6191. ProgressState = true;
  6192. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
  6193. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6194. out ProgressState));
  6195. }
  6196. }
  6197. }
  6198. }
  6199. catch (Exception ex)
  6200. {
  6201. ProgressState = false;
  6202. string str = ex.StackTrace;
  6203. AddMessage_Station(stationNameStr, LogType.Error,
  6204. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6205. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6206. }
  6207. #endregion 进站
  6208. #region 出站
  6209. try
  6210. {
  6211. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6212. {
  6213. lock (lockObj)
  6214. {
  6215. if (!ProgressState)
  6216. {
  6217. ProgressState = true;
  6218. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
  6219. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  6220. out ProgressState));
  6221. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  6222. }
  6223. }
  6224. }
  6225. }
  6226. catch (Exception ex)
  6227. {
  6228. ProgressState = false;
  6229. string str = ex.StackTrace;
  6230. AddMessage_Station(stationNameStr, LogType.Error,
  6231. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6232. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6233. }
  6234. #endregion 出站
  6235. #region 节拍接口
  6236. try
  6237. {
  6238. int a90EEType = (int)s9PLCData["a90EEType"];
  6239. int a90EETypeGOld = (int)s9PLCSignal_Old["a90EEType"];
  6240. //若设备紧急复原后节拍重置
  6241. if (a90EEType == 1)
  6242. {
  6243. a90EETypeGOld = 0;
  6244. }
  6245. if (a90EEType != a90EETypeGOld)
  6246. {
  6247. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  6248. if ((a90EETypeGOld == 1 && a90EEType != 2) || (a90EETypeGOld == 3 && a90EEType != 4) ||
  6249. (a90EETypeGOld == 5 && a90EEType != 6))
  6250. {
  6251. //写入PLC
  6252. stPLC_MesData.iotData.beatReturn = 2; //NG
  6253. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  6254. AddMessage(LogType.Info,
  6255. stationNameStr +
  6256. $"_节拍接口-- 设备本次上传节拍[{a90EEType}],未上传节拍[{a90EETypeGOld}]的结束信号,请检查;总用时" +
  6257. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  6258. "ms");
  6259. return;
  6260. }
  6261. else
  6262. {
  6263. Task.Run(() =>
  6264. S9节拍接口(plcNo, stationNameStr, tagBaseName,
  6265. stPLC_MesData.iotData)); // MreTasks[4].Set();
  6266. }
  6267. s9PLCSignal_Old["a90EEType"] = s9PLCData["a90EEType"];
  6268. }
  6269. }
  6270. catch (Exception ex)
  6271. {
  6272. string str = ex.StackTrace;
  6273. AddMessage_Station(stationNameStr, LogType.Error,
  6274. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6275. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6276. }
  6277. #endregion
  6278. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6279. stopwatch1.Stop();
  6280. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6281. }
  6282. else
  6283. {
  6284. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6285. AddMessage_Station(stationNameStr, LogType.Info,
  6286. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6287. FunsEip[plcNo].Connect(); // 重连
  6288. }
  6289. }
  6290. catch (Exception ex)
  6291. {
  6292. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6293. AddMessage_Station(stationNameStr, LogType.Error,
  6294. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6295. }
  6296. Thread.Sleep(IntervalReadPLC);
  6297. }
  6298. }
  6299. /// <summary>
  6300. /// [S9] 下料设备 - 进站
  6301. /// </summary>
  6302. /// <param name="plcNo">PLC编号</param>
  6303. /// <param name="stationNameStr">工站全称</param>
  6304. /// <param name="stPLC_MesData"></param>
  6305. /// <param name="tagMesCommName"></param>
  6306. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6307. string tagBarsetName, out bool ProgressState)
  6308. {
  6309. Stopwatch stopwatch1 = new Stopwatch();
  6310. Stopwatch stopwatch2 = new Stopwatch();
  6311. try
  6312. {
  6313. stopwatch1.Start();
  6314. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6315. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6316. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  6317. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  6318. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6319. bool pass = a1Result == 1;
  6320. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6321. //载具码验证产品码
  6322. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6323. if (string.IsNullOrEmpty(strProductBarcode))
  6324. {
  6325. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  6326. }
  6327. sn = strProductBarcode;
  6328. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6329. // 产品SN(物料码)校验
  6330. List<TestItem> item = new List<TestItem>();
  6331. stopwatch2.Start();
  6332. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6333. item, MachineId, StationId, pass);
  6334. stopwatch2.Stop();
  6335. //指令执行结果 1:OK 110:失败
  6336. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6337. if (mesResultFrmWeb == 1)
  6338. {
  6339. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6340. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6341. }
  6342. //进站结果写入PLC
  6343. CommandFromPLC resultToPlC = new CommandFromPLC();
  6344. resultToPlC.cmd = 0;
  6345. resultToPlC.cmdParam = 0; //指令参数
  6346. resultToPlC.cmdResult = mesResultFrmWeb;
  6347. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6348. }
  6349. catch (Exception ex)
  6350. {
  6351. string str = ex.StackTrace;
  6352. AddMessage(LogType.Error,
  6353. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  6354. str.Length - str.LastIndexOf("\\") - 1));
  6355. CommandFromPLC resultToPlC = new CommandFromPLC();
  6356. resultToPlC.cmd = 0;
  6357. resultToPlC.cmdParam = 0; //指令参数
  6358. resultToPlC.cmdResult = 110;
  6359. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6360. }
  6361. stopwatch1.Stop();
  6362. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  6363. AddMessage(LogType.Info,
  6364. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6365. stopwatch2.ElapsedMilliseconds + "ms");
  6366. ProgressState = false;
  6367. }
  6368. /// <summary>
  6369. /// [S9] 下料设备 - 出站接口
  6370. /// </summary>
  6371. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6372. string stationCode, string stationName, out bool ProgressState)
  6373. {
  6374. Stopwatch stopwatch1 = new Stopwatch();
  6375. Stopwatch stopwatch2 = new Stopwatch();
  6376. try
  6377. {
  6378. stopwatch1.Start();
  6379. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6380. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6381. string processItem = stationName; // 测试项目
  6382. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6383. string supplierCode = ""; // 供应商代码
  6384. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6385. string batch_num = GlobalContext.BatchNumber; // 批次号
  6386. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6387. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6388. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6389. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  6390. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  6391. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6392. bool pass = a1Result == 1;
  6393. //根据载具码获取产品码
  6394. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6395. if (string.IsNullOrEmpty(strProductBarcode))
  6396. {
  6397. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  6398. }
  6399. sn = strProductBarcode;
  6400. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6401. List<TestItem> items = new List<TestItem>();
  6402. items.Add(new TestItem()
  6403. {
  6404. Parameter_name = "载具码",
  6405. Parameter_value = CarrierBarcode,
  6406. Parameter_unit = ""
  6407. });
  6408. items.Add(new TestItem()
  6409. {
  6410. Parameter_name = "产品码",
  6411. Parameter_value = sn,
  6412. Parameter_unit = ""
  6413. });
  6414. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6415. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6416. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  6417. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6418. if (mesResultFrmWeb == 1)
  6419. {
  6420. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6421. AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
  6422. }
  6423. stopwatch2.Start();
  6424. //进站结果写入PLC
  6425. CommandFromPLC resultToPlC = new CommandFromPLC();
  6426. resultToPlC.cmd = 0;
  6427. resultToPlC.cmdParam = 0; //指令参数
  6428. resultToPlC.cmdResult = mesResultFrmWeb;
  6429. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6430. stopwatch2.Stop();
  6431. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6432. //保存PLC返回MES数据到本地
  6433. ResponseMessage message = new ResponseMessage();
  6434. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  6435. stPLC_MesData.mesData.nRemainCount);
  6436. if (message.result == false)
  6437. {
  6438. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6439. }
  6440. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6441. if (result1 == 1)
  6442. {
  6443. //载具码解除绑定
  6444. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  6445. if (message.result == false)
  6446. {
  6447. AddMessage(LogType.Error, message.text);
  6448. }
  6449. }
  6450. }
  6451. catch (Exception ex)
  6452. {
  6453. stopwatch2.Start();
  6454. CommandFromPLC resultToPlC = new CommandFromPLC();
  6455. resultToPlC.cmd = 0;
  6456. resultToPlC.cmdParam = 0; //指令参数
  6457. resultToPlC.cmdResult = 110;
  6458. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6459. stopwatch2.Stop();
  6460. string str = ex.StackTrace;
  6461. AddMessage(LogType.Error,
  6462. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6463. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6464. }
  6465. stopwatch1.Stop();
  6466. AddMessage(LogType.Info,
  6467. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6468. stopwatch2.ElapsedMilliseconds + "ms");
  6469. ProgressState = false;
  6470. }
  6471. private void S9节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  6472. {
  6473. Stopwatch stopwatch1 = new Stopwatch();
  6474. Stopwatch stopwatch2 = new Stopwatch();
  6475. string resultStr = string.Empty;
  6476. try
  6477. {
  6478. stopwatch1.Start();
  6479. string oEEType = ((int)s1PLCData["a9OEEType"]).ToString(); // 节拍类型(plc写入)
  6480. string a90EEPartNo = (string)s1PLCData["a90EEPartNo"]; // 物料码
  6481. a90EEPartNo = a90EEPartNo.Replace("\0", "");
  6482. string a90EEVehicleCode = (string)s1PLCData["a90EEVehicleCode"]; // 载具SN
  6483. a90EEVehicleCode = a90EEVehicleCode.Replace("\0", "");
  6484. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6485. if (!actionBool)
  6486. {
  6487. stopwatch2.Start();
  6488. //写入PLC
  6489. iot_data.beatReturn = 2; //NG
  6490. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6491. stopwatch2.Stop();
  6492. AddMessage(LogType.Info,
  6493. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  6494. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6495. return;
  6496. }
  6497. //作业开始后要有物料和载具信息
  6498. if (string.IsNullOrEmpty(a90EEPartNo) && string.IsNullOrEmpty(a90EEVehicleCode) &&
  6499. Convert.ToInt32(oEEType) > 2)
  6500. {
  6501. stopwatch2.Start();
  6502. //写入PLC
  6503. iot_data.beatReturn = 2; //NG
  6504. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6505. stopwatch2.Stop();
  6506. AddMessage_Station(stationNameStr, LogType.Info,
  6507. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  6508. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6509. return;
  6510. }
  6511. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEPartNo))
  6512. {
  6513. stopwatch2.Start();
  6514. //写入PLC
  6515. iot_data.beatReturn = 2; //NG
  6516. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6517. stopwatch2.Stop();
  6518. AddMessage_Station(stationNameStr, LogType.Info,
  6519. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  6520. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6521. return;
  6522. }
  6523. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEVehicleCode))
  6524. {
  6525. stopwatch2.Start();
  6526. //写入PLC
  6527. iot_data.beatReturn = 2; //NG
  6528. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6529. stopwatch2.Stop();
  6530. AddMessage_Station(stationNameStr, LogType.Info,
  6531. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  6532. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6533. return;
  6534. }
  6535. short _result = 0;
  6536. // 上传OEE
  6537. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a90EEPartNo, a90EEVehicleCode);
  6538. _result = result.Item1;
  6539. resultStr = result.Item2;
  6540. if (_result == 1)
  6541. {
  6542. stopwatch2.Start();
  6543. //写入PLC
  6544. iot_data.beatReturn = 1; //OK
  6545. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6546. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  6547. stopwatch2.Stop();
  6548. }
  6549. else
  6550. {
  6551. stopwatch2.Start();
  6552. //写入PLC
  6553. iot_data.beatReturn = 2; //NG
  6554. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6555. stopwatch2.Stop();
  6556. AddMessage_Station(stationNameStr, LogType.Error,
  6557. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  6558. }
  6559. }
  6560. catch (Exception ex)
  6561. {
  6562. string str = ex.StackTrace;
  6563. AddMessage_Station(stationNameStr, LogType.Error,
  6564. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  6565. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6566. // MES_Flag
  6567. stopwatch2.Start();
  6568. //写入PLC
  6569. iot_data.beatReturn = 2; //NG
  6570. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6571. stopwatch2.Stop();
  6572. }
  6573. stopwatch1.Stop();
  6574. AddMessage(LogType.Info,
  6575. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6576. stopwatch2.ElapsedMilliseconds + "ms");
  6577. }
  6578. #endregion
  6579. #endregion Xiaomi
  6580. #region PLC1 张超凡
  6581. #region [S1] Tray盘上料装备(板测)
  6582. /// <summary>
  6583. /// S1工位的数据- 触发信号上次的值
  6584. /// </summary>
  6585. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  6586. /// <summary>
  6587. /// S1工位的数据(含触发信号)
  6588. /// </summary>
  6589. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  6590. /// <summary>
  6591. /// S1工位的数据- 回写点位
  6592. /// </summary>
  6593. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6594. ///// <summary>
  6595. ///// 触发信号
  6596. ///// </summary>
  6597. //private ManualResetEvent[] MreTasks;
  6598. /// <summary>
  6599. /// [S1] Tray盘上料装备(板测)
  6600. /// </summary>
  6601. /// <param name="plcNo">PLC编号</param>
  6602. //private void ReadStation_S1(int plcNo)
  6603. //{
  6604. // // [S1] Tray盘上料装备
  6605. // // [S2] FCT
  6606. // // [S3] 值板机
  6607. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6608. // // [S5] Tray盘下料装备
  6609. // string stationCode = "[S1]";
  6610. // string stationName = "Tray盘上料装备";
  6611. // string stationNameStr = stationCode + stationName;
  6612. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6613. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6614. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6615. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6616. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6617. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6618. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6619. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6620. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  6621. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6622. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  6623. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6624. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6625. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  6626. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  6627. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6628. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  6629. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  6630. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6631. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  6632. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  6633. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  6634. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  6635. // s1PLCData.Add("a1Result", 0); // 产品结果
  6636. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6637. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  6638. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  6639. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  6640. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  6641. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6642. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  6643. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  6644. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  6645. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  6646. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  6647. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6648. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  6649. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  6650. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6651. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  6652. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  6653. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6654. // while (IsRun)
  6655. // {
  6656. // try
  6657. // {
  6658. // if (!GlobalContext._IsCon_Funs1)
  6659. // {
  6660. // UpdatePLCMonitor(1, plcNo, 0);
  6661. // continue;
  6662. // }
  6663. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6664. // {
  6665. // Stopwatch stopwatch1 = new Stopwatch();
  6666. // Stopwatch stopwatch2 = new Stopwatch();
  6667. // stopwatch1.Start();
  6668. // stopwatch2.Start();
  6669. // #region 一次性读取所有数据
  6670. // // 一次性读取所有数据
  6671. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6672. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6673. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6674. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  6675. // int[] datas = data1.Concat(data2).ToArray();
  6676. // datas = datas.Concat(data3).ToArray();
  6677. // datas = datas.Concat(data4).ToArray();
  6678. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  6679. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  6680. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  6681. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  6682. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  6683. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  6684. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  6685. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  6686. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  6687. // s1PLCData["a1MES_FLAG"] = datas[109];
  6688. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  6689. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  6690. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  6691. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  6692. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  6693. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  6694. // s1PLCData["a1Result"] = datas[170];
  6695. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  6696. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  6697. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  6698. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  6699. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  6700. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  6701. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  6702. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  6703. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  6704. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  6705. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  6706. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  6707. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  6708. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  6709. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  6710. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  6711. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  6712. // s1PLCData["a1AGVUpStart"] = datas[308];
  6713. // s1PLCData["a1AGVUpEnd"] = datas[309];
  6714. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  6715. // s1PLCData["a1AGVDownStart"] = datas[321];
  6716. // s1PLCData["a1AGVDownEnd"] = datas[322];
  6717. // #endregion 一次性读取所有数据
  6718. // stopwatch2.Stop();
  6719. // #region 回写操作,写后清空flag
  6720. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  6721. // #endregion 回写操作,写后清空flag
  6722. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6723. // try
  6724. // {
  6725. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  6726. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  6727. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  6728. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  6729. // {
  6730. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  6731. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  6732. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  6733. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6734. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  6735. // }
  6736. // }
  6737. // catch (Exception ex)
  6738. // {
  6739. // // 6代表上位机报警
  6740. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  6741. // string str = ex.StackTrace;
  6742. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6743. // }
  6744. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6745. // #region 上料进站校验
  6746. // try
  6747. // {
  6748. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  6749. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  6750. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  6751. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  6752. // {
  6753. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  6754. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6755. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  6756. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  6757. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  6758. // }
  6759. // }
  6760. // catch (Exception ex)
  6761. // {
  6762. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  6763. // string str = ex.StackTrace;
  6764. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6765. // }
  6766. // #endregion 上料进站校验
  6767. // #region Tray盘上料装备-出站接口
  6768. // try
  6769. // {
  6770. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  6771. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  6772. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  6773. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  6774. // {
  6775. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  6776. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6777. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  6778. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  6779. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  6780. // }
  6781. // }
  6782. // catch (Exception ex)
  6783. // {
  6784. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  6785. // string str = ex.StackTrace;
  6786. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6787. // }
  6788. // #endregion Tray盘上料装备-出站接口
  6789. // #region Tray盘上料装备-将SN发给ICT标机
  6790. // try
  6791. // {
  6792. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  6793. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  6794. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  6795. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  6796. // {
  6797. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  6798. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  6799. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  6800. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  6801. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  6802. // }
  6803. // }
  6804. // catch (Exception ex)
  6805. // {
  6806. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  6807. // string str = ex.StackTrace;
  6808. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6809. // }
  6810. // #endregion Tray盘上料装备-将SN发给ICT标机
  6811. // #region Tray盘上料装备-点检数据
  6812. // //try
  6813. // //{
  6814. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  6815. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  6816. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  6817. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  6818. // // if (pLC_Flag && !mES_Flag) // 1 0
  6819. // // {
  6820. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  6821. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  6822. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  6823. // // }
  6824. // // else if (!pLC_Flag && mES_Flag) // 0 1
  6825. // // {
  6826. // // // 清空写给PLC的数据
  6827. // // // MES_Flag重置为0
  6828. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  6829. // // }
  6830. // //}
  6831. // //catch (Exception ex)
  6832. // //{
  6833. // // // MES_Flag 为2上位机报错
  6834. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  6835. // // string str = ex.StackTrace;
  6836. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6837. // //}
  6838. // #endregion Tray盘上料装备-点检数据
  6839. // #region 节拍接口
  6840. // try
  6841. // {
  6842. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  6843. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  6844. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  6845. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  6846. // {
  6847. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  6848. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6849. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  6850. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  6851. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  6852. // }
  6853. // }
  6854. // catch (Exception ex)
  6855. // {
  6856. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  6857. // string str = ex.StackTrace;
  6858. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6859. // }
  6860. // #endregion 节拍接口
  6861. // #region AGV上料
  6862. // // AGV上料叫AGV信号
  6863. // try
  6864. // {
  6865. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  6866. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  6867. // if (a1AGVUpCall != a1AGVUpCallOld)
  6868. // {
  6869. // if (a1AGVUpCall == 1) // 0->1
  6870. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  6871. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  6872. // }
  6873. // }
  6874. // catch (Exception ex)
  6875. // {
  6876. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  6877. // string str = ex.StackTrace;
  6878. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6879. // }
  6880. // // AGV上料完成信号
  6881. // try
  6882. // {
  6883. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  6884. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  6885. // if (a1AGVUpEnd != a1AGVUpEndOld)
  6886. // {
  6887. // if (a1AGVUpEnd == 1) // 0->1
  6888. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  6889. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  6890. // }
  6891. // }
  6892. // catch (Exception ex)
  6893. // {
  6894. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  6895. // string str = ex.StackTrace;
  6896. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6897. // }
  6898. // #endregion AGV上料
  6899. // #region AGV下料
  6900. // // AGV下料叫agv信号
  6901. // try
  6902. // {
  6903. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  6904. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  6905. // if (a1AGVDownCall != a1AGVDownCallOld)
  6906. // {
  6907. // if (a1AGVDownCall == 1) // 0->1
  6908. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  6909. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  6910. // }
  6911. // }
  6912. // catch (Exception ex)
  6913. // {
  6914. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  6915. // string str = ex.StackTrace;
  6916. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6917. // }
  6918. // // AGV下料完成信号
  6919. // try
  6920. // {
  6921. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  6922. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  6923. // if (a1AGVDownEnd != a1AGVDownEndOld)
  6924. // {
  6925. // if (a1AGVDownEnd == 1) // 0->1
  6926. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  6927. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  6928. // }
  6929. // }
  6930. // catch (Exception ex)
  6931. // {
  6932. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  6933. // string str = ex.StackTrace;
  6934. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6935. // }
  6936. // #endregion AGV下料
  6937. // #region 心跳
  6938. // try
  6939. // {
  6940. // short states = 0;
  6941. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6942. // }
  6943. // catch (Exception ex)
  6944. // {
  6945. // string str = ex.StackTrace;
  6946. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6947. // }
  6948. // #endregion 心跳
  6949. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6950. // stopwatch1.Stop();
  6951. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6952. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6953. // }
  6954. // else
  6955. // {
  6956. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6957. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6958. // Funs[plcNo].Connect(); // 重连
  6959. // }
  6960. // }
  6961. // catch (Exception ex)
  6962. // {
  6963. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6964. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6965. // Funs[plcNo].ReConnect();
  6966. // }
  6967. // Thread.Sleep(IntervalReadPLC);
  6968. // }
  6969. //}
  6970. /// <summary>
  6971. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  6972. /// </summary>
  6973. /// <param name="plcNo">PLC编号</param>
  6974. /// <param name="stationNameStr">工站全称</param>
  6975. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  6976. {
  6977. Stopwatch stopwatch1 = new Stopwatch();
  6978. Stopwatch stopwatch2 = new Stopwatch();
  6979. try
  6980. {
  6981. stopwatch1.Start();
  6982. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  6983. sn = sn.Replace("\0", "");
  6984. #region 查询载具上的产品信息
  6985. string cavityData = string.Empty;
  6986. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6987. if (string.IsNullOrEmpty(cavityData))
  6988. cavityData = "";
  6989. if (snResult != 0)
  6990. {
  6991. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6992. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  6993. writeToPLC_Flag1.Adress = 2003;
  6994. writeToPLC_Flag1.Value = (short)6;
  6995. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  6996. stopwatch1.Stop();
  6997. AddMessage(LogType.Info,
  6998. stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  6999. "ms");
  7000. return;
  7001. }
  7002. #endregion 查询载具上的产品信息
  7003. string[] cavitySNs = cavityData.Split('.');
  7004. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  7005. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  7006. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  7007. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  7008. if (cavitySNs != null && cavitySNs.Length >= 2)
  7009. {
  7010. a1CavitySN1_VehicleStates = cavitySNs[0];
  7011. a1CavitySN2_VehicleStates = cavitySNs[1];
  7012. a1CavityResult1_VehicleStates = 2;
  7013. a1CavityResult2_VehicleStates = 2;
  7014. }
  7015. if (a1CavitySN1_VehicleStates == "假产品")
  7016. a1CavityResult1_VehicleStates = 3;
  7017. if (a1CavitySN2_VehicleStates == "假产品")
  7018. a1CavityResult2_VehicleStates = 3;
  7019. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7020. // 回写
  7021. stopwatch2.Start();
  7022. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  7023. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  7024. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  7025. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  7026. //// MES_Flag
  7027. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  7028. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7029. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7030. writeToPLC_Flag.Adress = 2003;
  7031. writeToPLC_Flag.Value = mES_Flag;
  7032. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7033. {
  7034. Name = "a1CavitySN1_VehicleStates",
  7035. Adress = 2024,
  7036. ValueType = PLCValueType.String,
  7037. ValueTypeStrLength = 20,
  7038. Value = a1CavitySN1_VehicleStates
  7039. });
  7040. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  7041. {
  7042. Name = "a1CavitySN2_VehicleStates",
  7043. Adress = 2044,
  7044. ValueType = PLCValueType.String,
  7045. ValueTypeStrLength = 20,
  7046. Value = a1CavitySN2_VehicleStates
  7047. });
  7048. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7049. {
  7050. Name = "a1CavityResult1_VehicleStates",
  7051. Adress = 2064,
  7052. ValueType = PLCValueType.Short,
  7053. Value = a1CavityResult1_VehicleStates
  7054. });
  7055. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7056. {
  7057. Name = "a1CavityResult2_VehicleStates",
  7058. Adress = 2065,
  7059. ValueType = PLCValueType.Short,
  7060. Value = a1CavityResult2_VehicleStates
  7061. });
  7062. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7063. stopwatch2.Stop();
  7064. }
  7065. catch (Exception ex)
  7066. {
  7067. string str = ex.StackTrace;
  7068. AddMessage_Station(stationNameStr, LogType.Error,
  7069. $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
  7070. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7071. // MES_Flag
  7072. stopwatch2.Start();
  7073. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7074. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7075. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7076. writeToPLC_Flag.Adress = 2003;
  7077. writeToPLC_Flag.Value = (short)6;
  7078. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7079. stopwatch2.Stop();
  7080. }
  7081. stopwatch1.Stop();
  7082. AddMessage(LogType.Info,
  7083. stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7084. stopwatch2.ElapsedMilliseconds + "ms");
  7085. }
  7086. /// <summary>
  7087. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  7088. /// </summary>
  7089. /// <param name="plcNo">PLC编号</param>
  7090. /// <param name="stationNameStr">工站全称</param>
  7091. private void S1上料进站校验(int plcNo, string stationNameStr)
  7092. {
  7093. Stopwatch stopwatch1 = new Stopwatch();
  7094. Stopwatch stopwatch2 = new Stopwatch();
  7095. try
  7096. {
  7097. stopwatch1.Start();
  7098. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  7099. sn = sn.Replace("\0", "");
  7100. // 保存进站数据+调用进站MES接口
  7101. List<TestItem> item = new List<TestItem>();
  7102. stopwatch2.Start();
  7103. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  7104. item, out string errorMsg);
  7105. stopwatch2.Stop();
  7106. short a1MES_FLAG_Check = (short)result;
  7107. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7108. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7109. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7110. writeToPLC_Flag.Adress = 2077;
  7111. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  7112. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7113. }
  7114. catch (Exception ex)
  7115. {
  7116. string str = ex.StackTrace;
  7117. AddMessage_Station(stationNameStr, LogType.Error,
  7118. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  7119. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7120. // MES_Flag
  7121. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7122. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7123. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7124. writeToPLC_Flag.Adress = 2077;
  7125. writeToPLC_Flag.Value = (short)6;
  7126. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7127. }
  7128. stopwatch1.Stop();
  7129. AddMessage(LogType.Info,
  7130. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7131. stopwatch2.ElapsedMilliseconds + "ms");
  7132. }
  7133. /// <summary>
  7134. /// [S1] Tray盘上料装备(板测)- 出站接口
  7135. /// </summary>
  7136. /// <param name="plcNo"></param>
  7137. /// <param name="stationCode"></param>
  7138. /// <param name="stationName"></param>
  7139. private void S1出站接口(int plcNo, string stationCode, string stationName)
  7140. {
  7141. Stopwatch stopwatch1 = new Stopwatch();
  7142. Stopwatch stopwatch2 = new Stopwatch();
  7143. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7144. string stationNameStr = stationCode + stationName;
  7145. string processItem = stationName; // 测试项目
  7146. try
  7147. {
  7148. stopwatch1.Start();
  7149. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7150. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7151. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7152. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7153. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  7154. sn = sn.Replace("\0", "");
  7155. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  7156. partNo1 = partNo1.Replace("\0", "");
  7157. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  7158. partNo2 = partNo2.Replace("\0", "");
  7159. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  7160. bool pass = a1Result == 1;
  7161. stopwatch2.Start();
  7162. // 产品1
  7163. List<TestItem> items = new List<TestItem>();
  7164. items.Add(new TestItem()
  7165. {
  7166. Parameter_name = "载具码",
  7167. Parameter_value = sn,
  7168. Parameter_unit = ""
  7169. });
  7170. items.Add(new TestItem()
  7171. {
  7172. Parameter_name = "载具穴号",
  7173. Parameter_value = "1",
  7174. Parameter_unit = ""
  7175. });
  7176. items.Add(new TestItem()
  7177. {
  7178. Parameter_name = "产品结果",
  7179. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7180. Parameter_unit = ""
  7181. });
  7182. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7183. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  7184. // 产品2
  7185. items = new List<TestItem>();
  7186. items.Add(new TestItem()
  7187. {
  7188. Parameter_name = "载具码",
  7189. Parameter_value = sn,
  7190. Parameter_unit = ""
  7191. });
  7192. items.Add(new TestItem()
  7193. {
  7194. Parameter_name = "载具穴号",
  7195. Parameter_value = "2",
  7196. Parameter_unit = ""
  7197. });
  7198. items.Add(new TestItem()
  7199. {
  7200. Parameter_name = "产品结果",
  7201. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7202. Parameter_unit = ""
  7203. });
  7204. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7205. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  7206. short result = 0;
  7207. List<int> results = new List<int>() { result1, result2 };
  7208. if (result1 == 1 && result2 == 1)
  7209. result = 1;
  7210. else if (results.Contains(3))
  7211. result = 3;
  7212. else if (results.Contains(2))
  7213. result = 2;
  7214. else if (results.Contains(4))
  7215. result = 4;
  7216. else
  7217. result = 4;
  7218. stopwatch2.Stop();
  7219. #region 存储绑定数据到 边线MES系统中
  7220. if (result == 1)
  7221. {
  7222. string data = string.Concat(partNo1, ".", partNo2);
  7223. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7224. if (resultMesR != 0)
  7225. {
  7226. result = 4;
  7227. AddMessage_Station(stationNameStr, LogType.Error,
  7228. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  7229. }
  7230. }
  7231. #endregion 存储绑定数据到 边线MES系统中
  7232. // MES_Flag 为MES报错
  7233. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7234. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  7235. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7236. writeToPLC_Flag.Name = "a1MES_FLAG";
  7237. writeToPLC_Flag.Adress = 2109;
  7238. writeToPLC_Flag.Value = result;
  7239. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7240. OnMessage(LogType.Debug,
  7241. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7242. }
  7243. catch (Exception ex)
  7244. {
  7245. stopwatch2.Restart();
  7246. // MES_Flag 为4上位机报错
  7247. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  7248. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7249. writeToPLC_Flag.Name = "a1MES_FLAG";
  7250. writeToPLC_Flag.Adress = 2109;
  7251. writeToPLC_Flag.Value = (short)4;
  7252. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7253. stopwatch2.Stop();
  7254. string str = ex.StackTrace;
  7255. AddMessage_Station(stationNameStr, LogType.Error,
  7256. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  7257. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7258. }
  7259. stopwatch1.Stop();
  7260. AddMessage(LogType.Info,
  7261. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  7262. stopwatch2.ElapsedMilliseconds + "ms");
  7263. }
  7264. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  7265. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  7266. //{
  7267. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7268. // string stationNameStr = stationCode + stationName;
  7269. // string processItem = stationName; // 测试项目
  7270. // try
  7271. // {
  7272. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7273. // string accno = "1"; // 工序编号
  7274. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  7275. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  7276. // List<OneCheckItem> items = new List<OneCheckItem>()
  7277. // {
  7278. // new OneCheckItem()
  7279. // {
  7280. // Onecheck_name="胶圈装配行程设定上限",
  7281. // Onecheck_content="上限值",
  7282. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  7283. // },
  7284. // };
  7285. // OneCheckData oneCheckData = new OneCheckData()
  7286. // {
  7287. // Line_code = GlobalContext.LineCode,
  7288. // Line_name = GlobalContext.LineName,
  7289. // Equipment_code = equipmentCode,
  7290. // Equipment_name = equipmentCode,
  7291. // Workorder_code = workorder_code,
  7292. // Procedure_code = accno,
  7293. // Procedure_name = processItem,
  7294. // Oneckeck_values = items,
  7295. // Onecheck_empcode = "",
  7296. // Onecheck_empname = "",
  7297. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  7298. // };
  7299. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  7300. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  7301. // short result = result1 == 1 ? (short)1 : (short)2;
  7302. // // MES_Flag 为4MES报错
  7303. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  7304. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7305. // }
  7306. // catch (Exception ex)
  7307. // {
  7308. // // MES_Flag 为2上位机报错
  7309. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7310. // string str = ex.StackTrace;
  7311. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7312. // }
  7313. //}
  7314. // ReadStation_S1_2 节拍接口+AGV
  7315. /// <summary>
  7316. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  7317. /// </summary>
  7318. /// <param name="plcNo">PLC编号</param>
  7319. /// <param name="stationNameStr">工站全称</param>
  7320. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  7321. {
  7322. Stopwatch stopwatch1 = new Stopwatch();
  7323. Stopwatch stopwatch2 = new Stopwatch();
  7324. try
  7325. {
  7326. stopwatch1.Start();
  7327. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  7328. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  7329. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  7330. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  7331. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  7332. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  7333. // ZS 将SN发给ICT标机(串口)
  7334. short a1MES_FLAG_ICT = 1;
  7335. stopwatch2.Start();
  7336. // MES_Flag
  7337. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  7338. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7339. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7340. writeToPLC_Flag.Adress = 2182;
  7341. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  7342. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7343. stopwatch2.Stop();
  7344. }
  7345. catch (Exception ex)
  7346. {
  7347. string str = ex.StackTrace;
  7348. AddMessage_Station(stationNameStr, LogType.Error,
  7349. $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
  7350. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7351. stopwatch2.Start();
  7352. // MES_Flag
  7353. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  7354. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7355. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7356. writeToPLC_Flag.Adress = 2182;
  7357. writeToPLC_Flag.Value = (short)4;
  7358. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7359. stopwatch2.Stop();
  7360. }
  7361. stopwatch1.Stop();
  7362. AddMessage(LogType.Info,
  7363. stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7364. stopwatch2.ElapsedMilliseconds + "ms");
  7365. }
  7366. /// <summary>
  7367. /// [S1] Tray盘上料装备(板测)- 节拍接口
  7368. /// </summary>
  7369. /// <param name="plcNo">PLC编号</param>
  7370. /// <param name="stationNameStr">工站全称</param>
  7371. private void S1节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  7372. {
  7373. Stopwatch stopwatch1 = new Stopwatch();
  7374. Stopwatch stopwatch2 = new Stopwatch();
  7375. string resultStr = string.Empty;
  7376. try
  7377. {
  7378. stopwatch1.Start();
  7379. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  7380. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  7381. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  7382. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  7383. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  7384. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7385. if (!actionBool)
  7386. {
  7387. stopwatch2.Start();
  7388. //写入PLC
  7389. iot_data.beatReturn = 2; //NG
  7390. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7391. stopwatch2.Stop();
  7392. AddMessage(LogType.Info,
  7393. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  7394. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7395. return;
  7396. }
  7397. //作业开始后要有物料和载具信息
  7398. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode) &&
  7399. Convert.ToInt32(oEEType) > 2)
  7400. {
  7401. stopwatch2.Start();
  7402. //写入PLC
  7403. iot_data.beatReturn = 2; //NG
  7404. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7405. stopwatch2.Stop();
  7406. AddMessage_Station(stationNameStr, LogType.Info,
  7407. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  7408. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7409. return;
  7410. }
  7411. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEPartNo))
  7412. {
  7413. stopwatch2.Start();
  7414. //写入PLC
  7415. iot_data.beatReturn = 2; //NG
  7416. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7417. stopwatch2.Stop();
  7418. AddMessage_Station(stationNameStr, LogType.Info,
  7419. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  7420. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7421. return;
  7422. }
  7423. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEVehicleCode))
  7424. {
  7425. stopwatch2.Start();
  7426. //写入PLC
  7427. iot_data.beatReturn = 2; //NG
  7428. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7429. stopwatch2.Stop();
  7430. AddMessage_Station(stationNameStr, LogType.Info,
  7431. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  7432. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7433. return;
  7434. }
  7435. short _result = 0;
  7436. // 上传OEE
  7437. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  7438. _result = result.Item1;
  7439. resultStr = result.Item2;
  7440. if (_result == 1)
  7441. {
  7442. stopwatch2.Start();
  7443. //写入PLC
  7444. iot_data.beatReturn = 1; //OK
  7445. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7446. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  7447. stopwatch2.Stop();
  7448. }
  7449. else {
  7450. stopwatch2.Start();
  7451. //写入PLC
  7452. iot_data.beatReturn = 2; //NG
  7453. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7454. stopwatch2.Stop();
  7455. AddMessage_Station(stationNameStr, LogType.Error,
  7456. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr );
  7457. }
  7458. }
  7459. catch (Exception ex)
  7460. {
  7461. string str = ex.StackTrace;
  7462. AddMessage_Station(stationNameStr, LogType.Error,
  7463. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  7464. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7465. // MES_Flag
  7466. stopwatch2.Start();
  7467. //写入PLC
  7468. iot_data.beatReturn = 2; //NG
  7469. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7470. stopwatch2.Stop();
  7471. }
  7472. stopwatch1.Stop();
  7473. AddMessage(LogType.Info,
  7474. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7475. stopwatch2.ElapsedMilliseconds + "ms");
  7476. }
  7477. /// <summary>
  7478. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  7479. /// </summary>
  7480. /// <param name="plcNo">PLC编号</param>
  7481. /// <param name="stationNameStr">工站全称</param>
  7482. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  7483. {
  7484. Stopwatch stopwatch1 = new Stopwatch();
  7485. Stopwatch stopwatch2 = new Stopwatch();
  7486. try
  7487. {
  7488. stopwatch1.Start();
  7489. // ZS 呼叫AGV
  7490. short a1AGVUpCall = 2;
  7491. stopwatch2.Start();
  7492. // a1AGVUpCall
  7493. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7494. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7495. writeToPLC_Flag.Name = "a1AGVUpCall";
  7496. writeToPLC_Flag.Adress = 2307;
  7497. writeToPLC_Flag.Value = a1AGVUpCall;
  7498. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7499. stopwatch2.Stop();
  7500. }
  7501. catch (Exception ex)
  7502. {
  7503. string str = ex.StackTrace;
  7504. AddMessage_Station(stationNameStr, LogType.Error,
  7505. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7506. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7507. // a1AGVUpCall
  7508. stopwatch2.Start();
  7509. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7510. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7511. writeToPLC_Flag.Name = "a1AGVUpCall";
  7512. writeToPLC_Flag.Adress = 2307;
  7513. writeToPLC_Flag.Value = (short)4;
  7514. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7515. stopwatch2.Stop();
  7516. }
  7517. stopwatch1.Stop();
  7518. AddMessage(LogType.Info,
  7519. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7520. stopwatch2.ElapsedMilliseconds + "ms");
  7521. }
  7522. /// <summary>
  7523. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  7524. /// </summary>
  7525. /// <param name="plcNo">PLC编号</param>
  7526. /// <param name="stationNameStr">工站全称</param>
  7527. private void S1AGV上料完成(int plcNo, string stationNameStr)
  7528. {
  7529. Stopwatch stopwatch1 = new Stopwatch();
  7530. Stopwatch stopwatch2 = new Stopwatch();
  7531. try
  7532. {
  7533. stopwatch1.Start();
  7534. // ZS AGV上料完成,让小车离开
  7535. short a1AGVUpEnd = 2;
  7536. stopwatch2.Start();
  7537. // a1AGVUpEnd
  7538. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7539. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7540. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7541. writeToPLC_Flag.Adress = 2309;
  7542. writeToPLC_Flag.Value = a1AGVUpEnd;
  7543. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7544. stopwatch2.Stop();
  7545. }
  7546. catch (Exception ex)
  7547. {
  7548. string str = ex.StackTrace;
  7549. AddMessage_Station(stationNameStr, LogType.Error,
  7550. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7551. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7552. // a1AGVUpEnd
  7553. stopwatch2.Start();
  7554. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7555. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7556. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7557. writeToPLC_Flag.Adress = 2309;
  7558. writeToPLC_Flag.Value = (short)4;
  7559. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7560. stopwatch2.Stop();
  7561. }
  7562. stopwatch1.Stop();
  7563. AddMessage(LogType.Info,
  7564. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7565. stopwatch2.ElapsedMilliseconds + "ms");
  7566. }
  7567. /// <summary>
  7568. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  7569. /// </summary>
  7570. /// <param name="plcNo">PLC编号</param>
  7571. /// <param name="stationNameStr">工站全称</param>
  7572. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  7573. {
  7574. Stopwatch stopwatch1 = new Stopwatch();
  7575. Stopwatch stopwatch2 = new Stopwatch();
  7576. try
  7577. {
  7578. stopwatch1.Start();
  7579. // ZS 呼叫AGV
  7580. short a1AGVDownCall = 2;
  7581. stopwatch2.Start();
  7582. // a1AGVDownCall
  7583. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7584. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7585. writeToPLC_Flag.Name = "a1AGVDownCall";
  7586. writeToPLC_Flag.Adress = 2320;
  7587. writeToPLC_Flag.Value = a1AGVDownCall;
  7588. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7589. stopwatch2.Stop();
  7590. }
  7591. catch (Exception ex)
  7592. {
  7593. string str = ex.StackTrace;
  7594. AddMessage_Station(stationNameStr, LogType.Error,
  7595. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7596. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7597. // a1AGVDownCall
  7598. stopwatch2.Start();
  7599. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7600. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7601. writeToPLC_Flag.Name = "a1AGVDownCall";
  7602. writeToPLC_Flag.Adress = 2320;
  7603. writeToPLC_Flag.Value = (short)4;
  7604. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7605. stopwatch2.Stop();
  7606. }
  7607. stopwatch1.Stop();
  7608. AddMessage(LogType.Info,
  7609. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7610. stopwatch2.ElapsedMilliseconds + "ms");
  7611. }
  7612. /// <summary>
  7613. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  7614. /// </summary>
  7615. /// <param name="plcNo">PLC编号</param>
  7616. /// <param name="stationNameStr">工站全称</param>
  7617. private void S1AGV下料完成(int plcNo, string stationNameStr)
  7618. {
  7619. Stopwatch stopwatch1 = new Stopwatch();
  7620. Stopwatch stopwatch2 = new Stopwatch();
  7621. try
  7622. {
  7623. stopwatch1.Start();
  7624. // ZS AGV上料完成,让小车离开
  7625. short a1AGVDownEnd = 2;
  7626. stopwatch2.Start();
  7627. // a1AGVDownEnd
  7628. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7629. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7630. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7631. writeToPLC_Flag.Adress = 2322;
  7632. writeToPLC_Flag.Value = a1AGVDownEnd;
  7633. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7634. stopwatch2.Stop();
  7635. }
  7636. catch (Exception ex)
  7637. {
  7638. string str = ex.StackTrace;
  7639. AddMessage_Station(stationNameStr, LogType.Error,
  7640. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7641. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7642. // a1AGVDownEnd
  7643. stopwatch2.Start();
  7644. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7645. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7646. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7647. writeToPLC_Flag.Adress = 2322;
  7648. writeToPLC_Flag.Value = (short)4;
  7649. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7650. stopwatch2.Stop();
  7651. }
  7652. stopwatch1.Stop();
  7653. AddMessage(LogType.Info,
  7654. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7655. stopwatch2.ElapsedMilliseconds + "ms");
  7656. }
  7657. #endregion [S1] Tray盘上料装备(板测)
  7658. #endregion PLC1 张超凡
  7659. #region PLC2 李晓奇
  7660. #region [S2] FCT(板测)
  7661. /// <summary>
  7662. /// S2工位的数据- 触发信号上次的值
  7663. /// </summary>
  7664. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  7665. /// <summary>
  7666. /// S2工位的数据(含触发信号)
  7667. /// </summary>
  7668. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  7669. /// <summary>
  7670. /// S2工位的数据- 回写点位
  7671. /// </summary>
  7672. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  7673. /// <summary>
  7674. /// [S2] FCT(板测)
  7675. /// </summary>
  7676. /// <param name="plcNo">PLC编号</param>
  7677. //private void ReadStation_S2(int plcNo)
  7678. //{
  7679. // // [S1] Tray盘上料装备
  7680. // // [S2] FCT
  7681. // // [S3] 值板机
  7682. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  7683. // // [S5] Tray盘下料装备
  7684. // /// 上位机心跳
  7685. // /// 获取设备报警数据与状态信息
  7686. // string stationCode = "[S2]";
  7687. // string stationName = "FCT";
  7688. // string stationNameStr = stationCode + stationName;
  7689. // #region 创建字典
  7690. // // 触发信号字典 赋值
  7691. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  7692. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  7693. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7694. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7695. // // PLC数据字典 赋值
  7696. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  7697. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  7698. // s2PLCData.Add("b1ProductSN_Check", 0);
  7699. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  7700. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  7701. // s2PLCData.Add("b1ProductSN_Unbind", "");
  7702. // s2PLCData.Add("b1ProductSN_Bind", "");
  7703. // s2PLCData.Add("b1Part1SN_Bind", "");
  7704. // s2PLCData.Add("b1Part2SN_Bind", "");
  7705. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  7706. // s2PLCData.Add("b1MES_FLAG", 0);
  7707. // s2PLCData.Add("b1ProductSN", 0);
  7708. // s2PLCData.Add("b1Part1Result", 0);
  7709. // s2PLCData.Add("b1Part2Result", 0);
  7710. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  7711. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  7712. // s2PLCData.Add("b1OEEProductSN", "");
  7713. // s2PLCData.Add("b1OEEType", 0);
  7714. // #endregion 创建字典
  7715. // while (IsRun)
  7716. // {
  7717. // try
  7718. // {
  7719. // if (!GlobalContext._IsCon_Funs2)
  7720. // {
  7721. // UpdatePLCMonitor(1, plcNo, 0);
  7722. // continue;
  7723. // }
  7724. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  7725. // {
  7726. // Stopwatch stopwatch1 = new Stopwatch();
  7727. // Stopwatch stopwatch2 = new Stopwatch();
  7728. // stopwatch1.Start();
  7729. // stopwatch2.Start();
  7730. // #region 一次性读取所有数据
  7731. // // 一次性读取所有数据
  7732. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  7733. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  7734. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  7735. // int[] datas = data1.Concat(data2).ToArray();
  7736. // datas = datas.Concat(data3).ToArray();
  7737. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  7738. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  7739. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  7740. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  7741. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  7742. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  7743. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  7744. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  7745. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  7746. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  7747. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  7748. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  7749. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  7750. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  7751. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  7752. // s2PLCData["b1MES_FLAG"] = datas[169];
  7753. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  7754. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  7755. // s2PLCData["b1Part1Result"] = datas[190];
  7756. // s2PLCData["b1Part2Result"] = datas[191];
  7757. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  7758. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  7759. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  7760. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  7761. // s2PLCData["b1OEEType"] = datas[224];
  7762. // #endregion 一次性读取所有数据
  7763. // stopwatch2.Stop();
  7764. // #region 回写操作,写后清空flag
  7765. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  7766. // #endregion 回写操作,写后清空flag
  7767. // #region 进站校验
  7768. // try
  7769. // {
  7770. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  7771. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7772. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  7773. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  7774. // {
  7775. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  7776. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  7777. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  7778. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  7779. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  7780. // }
  7781. // }
  7782. // catch (Exception ex)
  7783. // {
  7784. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7785. // string str = ex.StackTrace;
  7786. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7787. // }
  7788. // #endregion 进站校验
  7789. // #region 二穴载具解绑/绑定(产品换载具)
  7790. // try
  7791. // {
  7792. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  7793. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7794. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  7795. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  7796. // {
  7797. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  7798. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  7799. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  7800. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  7801. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  7802. // }
  7803. // }
  7804. // catch (Exception ex)
  7805. // {
  7806. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7807. // string str = ex.StackTrace;
  7808. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7809. // }
  7810. // #endregion 二穴载具解绑/绑定(产品换载具)
  7811. // #region FCT-出站接口
  7812. // try
  7813. // {
  7814. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  7815. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  7816. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  7817. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  7818. // {
  7819. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  7820. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7821. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  7822. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  7823. // }
  7824. // }
  7825. // catch (Exception ex)
  7826. // {
  7827. // // MES_Flag 为6上位机报错
  7828. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  7829. // string str = ex.StackTrace;
  7830. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7831. // }
  7832. // #endregion FCT-出站接口
  7833. // #region 节拍接口
  7834. // try
  7835. // {
  7836. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  7837. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  7838. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  7839. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  7840. // {
  7841. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  7842. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7843. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  7844. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  7845. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  7846. // }
  7847. // }
  7848. // catch (Exception ex)
  7849. // {
  7850. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  7851. // string str = ex.StackTrace;
  7852. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7853. // }
  7854. // #endregion 节拍接口
  7855. // #region 心跳
  7856. // try
  7857. // {
  7858. // short states = 0;
  7859. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7860. // }
  7861. // catch (Exception ex)
  7862. // {
  7863. // string str = ex.StackTrace;
  7864. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7865. // }
  7866. // #endregion 心跳
  7867. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7868. // stopwatch1.Stop();
  7869. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7870. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7871. // }
  7872. // else
  7873. // {
  7874. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7875. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7876. // Funs[plcNo].Connect();
  7877. // }
  7878. // }
  7879. // catch (Exception ex)
  7880. // {
  7881. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7882. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7883. // Funs[plcNo].ReConnect();
  7884. // }
  7885. // Thread.Sleep(IntervalReadPLC);
  7886. // }
  7887. //}
  7888. /// <summary>
  7889. /// [S2] FCT(板测)- 进站校验
  7890. /// </summary>
  7891. /// <param name="plcNo">PLC编号</param>
  7892. /// <param name="stationNameStr">工站全称</param>
  7893. private void S2进站校验(int plcNo, string stationNameStr)
  7894. {
  7895. Stopwatch stopwatch1 = new Stopwatch();
  7896. Stopwatch stopwatch2 = new Stopwatch();
  7897. try
  7898. {
  7899. stopwatch1.Start();
  7900. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  7901. sn = sn.Replace("\0", "");
  7902. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7903. // 查询物料码By载具码 并判断是不是假产品
  7904. string cavityData = string.Empty;
  7905. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7906. if (string.IsNullOrEmpty(cavityData))
  7907. cavityData = "";
  7908. if (snResult != 0)
  7909. {
  7910. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7911. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  7912. writeToPLC_Flag1.Adress = 2003;
  7913. writeToPLC_Flag1.Value = (short)6;
  7914. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  7915. stopwatch1.Stop();
  7916. AddMessage(LogType.Info,
  7917. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7918. return;
  7919. }
  7920. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7921. string[] cavitySNs = cavityData.Split('.');
  7922. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  7923. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  7924. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7925. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7926. if (cavitySNs != null && cavitySNs.Length >= 2)
  7927. {
  7928. b1Part1SN_Check = cavitySNs[0];
  7929. b1Part2SN_Check = cavitySNs[1];
  7930. b1Part1Result_Check = 2;
  7931. b1Part2Result_Check = 2;
  7932. }
  7933. if (b1Part1SN_Check == "假产品")
  7934. b1Part1Result_Check = 3;
  7935. if (b1Part2SN_Check == "假产品")
  7936. b1Part2Result_Check = 3;
  7937. // 调用MES进站
  7938. stopwatch2.Start();
  7939. // 调用MES进站 - 产品1
  7940. List<TestItem> item;
  7941. int result1 = b1Part1Result_Check;
  7942. if (result1 != 3)
  7943. {
  7944. item = new List<TestItem>();
  7945. item.Add(new TestItem()
  7946. {
  7947. Parameter_name = "载具码",
  7948. Parameter_value = sn,
  7949. });
  7950. item.Add(new TestItem()
  7951. {
  7952. Parameter_name = "载具穴号",
  7953. Parameter_value = "1",
  7954. });
  7955. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7956. b1Part1SN_Check, item, out string errorMsg);
  7957. }
  7958. // 调用MES进站 - 产品2
  7959. int result2 = b1Part2Result_Check;
  7960. if (result2 != 3)
  7961. {
  7962. item = new List<TestItem>();
  7963. item.Add(new TestItem()
  7964. {
  7965. Parameter_name = "载具码",
  7966. Parameter_value = sn,
  7967. });
  7968. item.Add(new TestItem()
  7969. {
  7970. Parameter_name = "载具穴号",
  7971. Parameter_value = "2",
  7972. });
  7973. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7974. b1Part2SN_Check, item, out string errorMsg);
  7975. }
  7976. stopwatch2.Stop();
  7977. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7978. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7979. int result = result1;
  7980. if (result == 1)
  7981. result = result2;
  7982. short b1MES_FLAG_Check = (short)result;
  7983. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  7984. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  7985. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  7986. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  7987. //// MES_Flag
  7988. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7989. WriteToPLC_Flag
  7990. writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7991. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  7992. writeToPLC_Flag.Adress = 2003;
  7993. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  7994. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7995. {
  7996. Name = "b1Part1SN_Check",
  7997. Adress = 2024,
  7998. ValueType = PLCValueType.String,
  7999. ValueTypeStrLength = 20,
  8000. Value = b1Part1SN_Check
  8001. });
  8002. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8003. {
  8004. Name = "b1Part2SN_Check",
  8005. Adress = 2044,
  8006. ValueType = PLCValueType.String,
  8007. ValueTypeStrLength = 20,
  8008. Value = b1Part2SN_Check
  8009. });
  8010. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8011. {
  8012. Name = "b1Part1Result_Check",
  8013. Adress = 2064,
  8014. ValueType = PLCValueType.Short,
  8015. Value = b1Part1Result_Check
  8016. });
  8017. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8018. {
  8019. Name = "b1Part2Result_Check",
  8020. Adress = 2065,
  8021. ValueType = PLCValueType.Short,
  8022. Value = b1Part2Result_Check
  8023. });
  8024. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  8025. }
  8026. catch (Exception ex)
  8027. {
  8028. string str = ex.StackTrace;
  8029. AddMessage_Station(stationNameStr, LogType.Error,
  8030. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8031. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8032. // MES_Flag
  8033. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8034. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8035. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  8036. writeToPLC_Flag.Adress = 2003;
  8037. writeToPLC_Flag.Value = (short)6;
  8038. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  8039. }
  8040. stopwatch1.Stop();
  8041. AddMessage(LogType.Info,
  8042. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8043. stopwatch2.ElapsedMilliseconds + "ms");
  8044. }
  8045. /// <summary>
  8046. /// [S2] FCT(板测)- 二穴载具解绑绑定
  8047. /// </summary>
  8048. /// <param name="plcNo">PLC编号</param>
  8049. /// <param name="stationNameStr">工站全称</param>
  8050. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  8051. {
  8052. Stopwatch stopwatch1 = new Stopwatch();
  8053. Stopwatch stopwatch2 = new Stopwatch();
  8054. try
  8055. {
  8056. stopwatch1.Start();
  8057. // 产品换载具
  8058. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  8059. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  8060. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  8061. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  8062. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  8063. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  8064. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  8065. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  8066. stopwatch2.Start();
  8067. #region 查询载具上的产品信息
  8068. //string cavityData = string.Empty;
  8069. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  8070. //if (string.IsNullOrEmpty(cavityData))
  8071. // cavityData = "";
  8072. //if (snResult != 0)
  8073. //{
  8074. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8075. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8076. // writeToPLC_Flag.Adress = 2077;
  8077. // writeToPLC_Flag.Value = (short)6;
  8078. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8079. // stopwatch1.Stop();
  8080. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8081. // return;
  8082. //}
  8083. #endregion 查询载具上的产品信息
  8084. #region 解绑(边线MES系统)
  8085. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  8086. if (snResult != 0)
  8087. {
  8088. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8089. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  8090. writeToPLC_Flag1.Adress = 2077;
  8091. writeToPLC_Flag1.Value = (short)6;
  8092. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  8093. stopwatch1.Stop();
  8094. AddMessage(LogType.Info,
  8095. stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
  8096. stopwatch1.ElapsedMilliseconds + "ms");
  8097. return;
  8098. }
  8099. #endregion 解绑(边线MES系统)
  8100. #region 存储绑定数据到 边线MES系统中
  8101. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  8102. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  8103. if (snResult != 0)
  8104. {
  8105. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8106. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  8107. writeToPLC_Flag1.Adress = 2077;
  8108. writeToPLC_Flag1.Value = (short)6;
  8109. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  8110. stopwatch1.Stop();
  8111. AddMessage(LogType.Info,
  8112. stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
  8113. stopwatch1.ElapsedMilliseconds + "ms");
  8114. return;
  8115. }
  8116. #endregion 存储绑定数据到 边线MES系统中
  8117. stopwatch2.Stop();
  8118. short b1MES_FLAG_Unbind = 1;
  8119. // MES_Flag
  8120. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8121. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8122. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8123. writeToPLC_Flag.Adress = 2077;
  8124. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  8125. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8126. }
  8127. catch (Exception ex)
  8128. {
  8129. string str = ex.StackTrace;
  8130. AddMessage_Station(stationNameStr, LogType.Error,
  8131. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8132. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8133. // MES_Flag
  8134. stopwatch2.Start();
  8135. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  8136. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8137. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8138. writeToPLC_Flag.Adress = 2077;
  8139. writeToPLC_Flag.Value = (short)6;
  8140. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8141. stopwatch2.Stop();
  8142. }
  8143. stopwatch1.Stop();
  8144. AddMessage(LogType.Info,
  8145. stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8146. stopwatch2.ElapsedMilliseconds + "ms");
  8147. }
  8148. //// 上次采集到的SN
  8149. //private string sn_FCT = string.Empty;
  8150. /// <summary>
  8151. /// [S2] FCT(板测)- 出站数据
  8152. /// </summary>
  8153. private void S2出站接口(int plcNo, string stationCode, string stationName)
  8154. {
  8155. Stopwatch stopwatch1 = new Stopwatch();
  8156. Stopwatch stopwatch2 = new Stopwatch();
  8157. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8158. string stationNameStr = stationCode + stationName;
  8159. string processItem = stationName; // 测试项目
  8160. try
  8161. {
  8162. stopwatch1.Start();
  8163. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8164. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8165. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8166. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8167. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  8168. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  8169. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  8170. bool pass1 = b1Part1Result == 1;
  8171. bool pass2 = b1Part2Result == 1;
  8172. #region 根据 载具SN 查 物料SN
  8173. string cavityData = string.Empty;
  8174. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  8175. if (string.IsNullOrEmpty(cavityData))
  8176. cavityData = "";
  8177. if (snResult != 0)
  8178. {
  8179. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8180. writeToPLC_Flag1.Name = "b1MES_FLAG";
  8181. writeToPLC_Flag1.Adress = 2169;
  8182. writeToPLC_Flag1.Value = (short)4;
  8183. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  8184. stopwatch1.Stop();
  8185. AddMessage(LogType.Info,
  8186. stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8187. "ms");
  8188. return;
  8189. }
  8190. #endregion 根据 载具SN 查 物料SN
  8191. string[] cavitySNs = cavityData.Split('.');
  8192. string b1ProductSN1 = string.Empty;
  8193. string b1ProductSN2 = string.Empty;
  8194. if (cavitySNs != null && cavitySNs.Length >= 2)
  8195. {
  8196. b1ProductSN1 = cavitySNs[0];
  8197. b1ProductSN2 = cavitySNs[1];
  8198. }
  8199. stopwatch2.Start();
  8200. // 产品1
  8201. int result1 = 0;
  8202. if (b1ProductSN1 == "假产品")
  8203. result1 = 1;
  8204. else
  8205. {
  8206. List<TestItem> items1 = new List<TestItem>();
  8207. items1.Add(new TestItem()
  8208. {
  8209. Parameter_name = "载具码",
  8210. Parameter_value = b1ProductSN.ToString(),
  8211. Parameter_unit = ""
  8212. });
  8213. items1.Add(new TestItem()
  8214. {
  8215. Parameter_name = "载具穴号",
  8216. Parameter_value = "1",
  8217. Parameter_unit = ""
  8218. });
  8219. items1.Add(new TestItem()
  8220. {
  8221. Parameter_name = "产品结果",
  8222. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  8223. Parameter_unit = ""
  8224. });
  8225. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8226. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  8227. }
  8228. // 产品2
  8229. int result2 = 0;
  8230. if (b1ProductSN1 == "假产品")
  8231. result2 = 1;
  8232. else
  8233. {
  8234. List<TestItem> items2 = new List<TestItem>();
  8235. items2.Add(new TestItem()
  8236. {
  8237. Parameter_name = "载具码",
  8238. Parameter_value = b1ProductSN.ToString(),
  8239. Parameter_unit = ""
  8240. });
  8241. items2.Add(new TestItem()
  8242. {
  8243. Parameter_name = "载具穴号",
  8244. Parameter_value = "2",
  8245. Parameter_unit = ""
  8246. });
  8247. items2.Add(new TestItem()
  8248. {
  8249. Parameter_name = "产品结果",
  8250. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  8251. Parameter_unit = ""
  8252. });
  8253. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  8254. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  8255. }
  8256. short result = 0;
  8257. List<int> results = new List<int>() { result1, result2 };
  8258. if (result1 == 1 && result2 == 1)
  8259. result = 1;
  8260. else if (results.Contains(3))
  8261. result = 3;
  8262. else if (results.Contains(2))
  8263. result = 2;
  8264. else if (results.Contains(4))
  8265. result = 4;
  8266. else
  8267. result = 4;
  8268. stopwatch2.Stop();
  8269. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8270. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8271. writeToPLC_Flag.Name = "b1MES_FLAG";
  8272. writeToPLC_Flag.Adress = 2169;
  8273. writeToPLC_Flag.Value = result;
  8274. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8275. OnMessage(LogType.Debug,
  8276. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8277. }
  8278. catch (Exception ex)
  8279. {
  8280. stopwatch2.Restart();
  8281. // MES_Flag 为4上位机报错
  8282. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  8283. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8284. writeToPLC_Flag.Name = "b1MES_FLAG";
  8285. writeToPLC_Flag.Adress = 2169;
  8286. writeToPLC_Flag.Value = (short)4;
  8287. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8288. stopwatch2.Stop();
  8289. string str = ex.StackTrace;
  8290. AddMessage_Station(stationNameStr, LogType.Error,
  8291. $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8292. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8293. }
  8294. stopwatch1.Stop();
  8295. AddMessage(LogType.Info,
  8296. stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8297. stopwatch2.ElapsedMilliseconds + "ms");
  8298. }
  8299. /// <summary>
  8300. /// [S2] FCT(板测)- 节拍接口
  8301. /// </summary>
  8302. /// <param name="plcNo">PLC编号</param>
  8303. /// <param name="stationNameStr">工站全称</param>
  8304. private void S2节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  8305. {
  8306. Stopwatch stopwatch1 = new Stopwatch();
  8307. Stopwatch stopwatch2 = new Stopwatch();
  8308. string resultStr = string.Empty;
  8309. try
  8310. {
  8311. stopwatch1.Start();
  8312. string oEEType = ((int)s1PLCData["a2OEEType"]).ToString(); // 节拍类型(plc写入)
  8313. string a2OEEPartNo = (string)s1PLCData["a2OEEPartNo"]; // 物料码
  8314. a2OEEPartNo = a2OEEPartNo.Replace("\0", "");
  8315. string a20EEVehicleCode = (string)s1PLCData["a20EEVehicleCode"]; // 载具SN
  8316. a20EEVehicleCode = a20EEVehicleCode.Replace("\0", "");
  8317. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8318. if (!actionBool)
  8319. {
  8320. stopwatch2.Start();
  8321. //写入PLC
  8322. iot_data.beatReturn = 2; //NG
  8323. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8324. stopwatch2.Stop();
  8325. AddMessage(LogType.Info,
  8326. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  8327. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8328. return;
  8329. }
  8330. //作业开始后要有物料和载具信息
  8331. if (string.IsNullOrEmpty(a2OEEPartNo) && string.IsNullOrEmpty(a20EEVehicleCode) &&
  8332. Convert.ToInt32(oEEType) > 2)
  8333. {
  8334. stopwatch2.Start();
  8335. //写入PLC
  8336. iot_data.beatReturn = 2; //NG
  8337. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8338. stopwatch2.Stop();
  8339. AddMessage_Station(stationNameStr, LogType.Info,
  8340. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  8341. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8342. return;
  8343. }
  8344. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a2OEEPartNo))
  8345. {
  8346. stopwatch2.Start();
  8347. //写入PLC
  8348. iot_data.beatReturn = 2; //NG
  8349. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8350. stopwatch2.Stop();
  8351. AddMessage_Station(stationNameStr, LogType.Info,
  8352. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  8353. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8354. return;
  8355. }
  8356. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a20EEVehicleCode))
  8357. {
  8358. stopwatch2.Start();
  8359. //写入PLC
  8360. iot_data.beatReturn = 2; //NG
  8361. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8362. stopwatch2.Stop();
  8363. AddMessage_Station(stationNameStr, LogType.Info,
  8364. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  8365. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8366. return;
  8367. }
  8368. short _result = 0;
  8369. // 上传OEE
  8370. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a2OEEPartNo, a20EEVehicleCode);
  8371. _result = result.Item1;
  8372. resultStr = result.Item2;
  8373. if (_result == 1)
  8374. {
  8375. stopwatch2.Start();
  8376. //写入PLC
  8377. iot_data.beatReturn = 1; //OK
  8378. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8379. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  8380. stopwatch2.Stop();
  8381. }
  8382. else
  8383. {
  8384. stopwatch2.Start();
  8385. //写入PLC
  8386. iot_data.beatReturn = 2; //NG
  8387. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8388. stopwatch2.Stop();
  8389. AddMessage_Station(stationNameStr, LogType.Error,
  8390. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  8391. }
  8392. }
  8393. catch (Exception ex)
  8394. {
  8395. string str = ex.StackTrace;
  8396. AddMessage_Station(stationNameStr, LogType.Error,
  8397. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  8398. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8399. // MES_Flag
  8400. stopwatch2.Start();
  8401. //写入PLC
  8402. iot_data.beatReturn = 2; //NG
  8403. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8404. stopwatch2.Stop();
  8405. }
  8406. stopwatch1.Stop();
  8407. AddMessage(LogType.Info,
  8408. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8409. stopwatch2.ElapsedMilliseconds + "ms");
  8410. }
  8411. #endregion [S2] FCT(板测)
  8412. #endregion PLC2 李晓奇
  8413. #region PLC3 刘永村
  8414. #region [S3] 值板机
  8415. /// <summary>
  8416. /// S3工位的数据- 触发信号上次的值
  8417. /// </summary>
  8418. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  8419. /// <summary>
  8420. /// S3工位的数据(含触发信号)
  8421. /// </summary>
  8422. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  8423. /// <summary>
  8424. /// S3工位的数据- 回写点位
  8425. /// </summary>
  8426. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8427. /// <summary>
  8428. /// [S3] 值板机
  8429. /// </summary>
  8430. /// <param name="plcNo">PLC编号</param>
  8431. //private void ReadStation_S3(int plcNo)
  8432. //{
  8433. // // [S1] Tray盘上料装备
  8434. // // [S2] FCT
  8435. // // [S3] 值板机
  8436. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8437. // // [S5] Tray盘下料装备
  8438. // /// 上位机心跳
  8439. // /// 获取设备报警数据与状态信息
  8440. // string stationCode = "[S3]";
  8441. // string stationName = "值板机";
  8442. // string stationNameStr = stationCode + stationName;
  8443. // #region 创建字典
  8444. // // 触发信号字典 赋值
  8445. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8446. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8447. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8448. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8449. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8450. // // PLC数据字典 赋值
  8451. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8452. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  8453. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8454. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8455. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  8456. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8457. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8458. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8459. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  8460. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8461. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  8462. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  8463. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8464. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8465. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  8466. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  8467. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  8468. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8469. // s3PLCData.Add("c1Result", 0); // 产品结果
  8470. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8471. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  8472. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  8473. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  8474. // #endregion 创建字典
  8475. // while (IsRun)
  8476. // {
  8477. // try
  8478. // {
  8479. // if (!GlobalContext._IsCon_Funs3)
  8480. // {
  8481. // UpdatePLCMonitor(1, plcNo, 0);
  8482. // continue;
  8483. // }
  8484. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8485. // {
  8486. // Stopwatch stopwatch1 = new Stopwatch();
  8487. // Stopwatch stopwatch2 = new Stopwatch();
  8488. // stopwatch1.Start();
  8489. // stopwatch2.Start();
  8490. // #region 一次性读取所有数据
  8491. // // 一次性读取所有数据
  8492. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  8493. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8494. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  8495. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  8496. // int[] datas = data1.Concat(data2).ToArray();
  8497. // datas = datas.Concat(data3).ToArray();
  8498. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  8499. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  8500. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8501. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  8502. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  8503. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  8504. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8505. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  8506. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  8507. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  8508. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8509. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8510. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  8511. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  8512. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  8513. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  8514. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8515. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  8516. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  8517. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  8518. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  8519. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  8520. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  8521. // #endregion 一次性读取所有数据
  8522. // stopwatch2.Stop();
  8523. // #region 回写操作,写后清空flag
  8524. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  8525. // #endregion 回写操作,写后清空flag
  8526. // #region S3进站校验
  8527. // try
  8528. // {
  8529. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  8530. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  8531. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  8532. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  8533. // {
  8534. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  8535. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8536. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  8537. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8538. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  8539. // }
  8540. // }
  8541. // catch (Exception ex)
  8542. // {
  8543. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8544. // string str = ex.StackTrace;
  8545. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8546. // }
  8547. // #endregion S3进站校验
  8548. // #region S3二穴载具解绑
  8549. // try
  8550. // {
  8551. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  8552. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  8553. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  8554. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  8555. // {
  8556. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8557. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  8558. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  8559. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  8560. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  8561. // }
  8562. // }
  8563. // catch (Exception ex)
  8564. // {
  8565. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  8566. // string str = ex.StackTrace;
  8567. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8568. // }
  8569. // #endregion S3二穴载具解绑
  8570. // #region S3二穴载具绑定
  8571. // try
  8572. // {
  8573. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  8574. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  8575. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  8576. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  8577. // {
  8578. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8579. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  8580. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  8581. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  8582. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  8583. // }
  8584. // }
  8585. // catch (Exception ex)
  8586. // {
  8587. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8588. // string str = ex.StackTrace;
  8589. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8590. // }
  8591. // #endregion S3二穴载具绑定
  8592. // #region S3出站接口(+一穴载具绑定)
  8593. // try
  8594. // {
  8595. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  8596. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  8597. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  8598. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  8599. // {
  8600. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  8601. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8602. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  8603. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  8604. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  8605. // }
  8606. // }
  8607. // catch (Exception ex)
  8608. // {
  8609. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  8610. // string str = ex.StackTrace;
  8611. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8612. // }
  8613. // #endregion S3出站接口(+一穴载具绑定)
  8614. // #region S3节拍接口
  8615. // try
  8616. // {
  8617. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  8618. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  8619. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  8620. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  8621. // {
  8622. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  8623. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8624. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  8625. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  8626. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  8627. // }
  8628. // }
  8629. // catch (Exception ex)
  8630. // {
  8631. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  8632. // string str = ex.StackTrace;
  8633. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8634. // }
  8635. // #endregion S3节拍接口
  8636. // #region 心跳
  8637. // try
  8638. // {
  8639. // short states = 0;
  8640. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8641. // }
  8642. // catch (Exception ex)
  8643. // {
  8644. // string str = ex.StackTrace;
  8645. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8646. // }
  8647. // #endregion 心跳
  8648. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8649. // stopwatch1.Stop();
  8650. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8651. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8652. // }
  8653. // else
  8654. // {
  8655. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8656. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8657. // Funs[plcNo].Connect();
  8658. // }
  8659. // }
  8660. // catch (Exception ex)
  8661. // {
  8662. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8663. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8664. // Funs[plcNo].ReConnect();
  8665. // }
  8666. // Thread.Sleep(IntervalReadPLC);
  8667. // }
  8668. //}
  8669. /// <summary>
  8670. /// [S3] 值板机- 进站校验
  8671. /// </summary>
  8672. /// <param name="plcNo">PLC编号</param>
  8673. /// <param name="stationNameStr">工站全称</param>
  8674. private void S3进站校验(int plcNo, string stationNameStr)
  8675. {
  8676. Stopwatch stopwatch1 = new Stopwatch();
  8677. Stopwatch stopwatch2 = new Stopwatch();
  8678. try
  8679. {
  8680. stopwatch1.Start();
  8681. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  8682. sn = sn.Replace("\0", "");
  8683. #region 查询载具上的产品信息
  8684. string cavityData = string.Empty;
  8685. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8686. if (string.IsNullOrEmpty(cavityData))
  8687. cavityData = "";
  8688. if (snResult != 0)
  8689. {
  8690. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8691. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  8692. writeToPLC_Flag1.Adress = 2003;
  8693. writeToPLC_Flag1.Value = (short)6;
  8694. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  8695. stopwatch1.Stop();
  8696. AddMessage(LogType.Info,
  8697. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8698. return;
  8699. }
  8700. #endregion 查询载具上的产品信息
  8701. string[] cavitySNs = cavityData.Split('.');
  8702. string part1Str = ""; // 产品1的SN码
  8703. string part2Str = ""; // 产品2的SN码
  8704. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8705. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8706. if (cavitySNs != null && cavitySNs.Length >= 2)
  8707. {
  8708. part1Str = cavitySNs[0];
  8709. part2Str = cavitySNs[1];
  8710. c1Part1Result_Check = 2;
  8711. c1Part2Result_Check = 2;
  8712. }
  8713. if (part1Str == "假产品")
  8714. c1Part1Result_Check = 3;
  8715. if (part2Str == "假产品")
  8716. c1Part2Result_Check = 3;
  8717. // 调用MES进站
  8718. stopwatch2.Start();
  8719. // 调用MES进站 - 产品1
  8720. List<TestItem> item;
  8721. int result1 = c1Part1Result_Check;
  8722. if (result1 != 3)
  8723. {
  8724. item = new List<TestItem>();
  8725. item.Add(new TestItem()
  8726. {
  8727. Parameter_name = "载具码",
  8728. Parameter_value = sn,
  8729. });
  8730. item.Add(new TestItem()
  8731. {
  8732. Parameter_name = "载具穴号",
  8733. Parameter_value = "1",
  8734. });
  8735. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8736. part1Str, item, out string errorMsg);
  8737. }
  8738. // 调用MES进站 - 产品2
  8739. int result2 = c1Part2Result_Check;
  8740. if (result2 != 3)
  8741. {
  8742. item = new List<TestItem>();
  8743. item.Add(new TestItem()
  8744. {
  8745. Parameter_name = "载具码",
  8746. Parameter_value = sn,
  8747. });
  8748. item.Add(new TestItem()
  8749. {
  8750. Parameter_name = "载具穴号",
  8751. Parameter_value = "2",
  8752. });
  8753. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8754. part2Str, item, out string errorMsg);
  8755. }
  8756. stopwatch2.Stop();
  8757. if (result1 == 2)
  8758. c1Part1Result_Check = 2;
  8759. if (result2 == 2)
  8760. c1Part2Result_Check = 2;
  8761. int result = result1;
  8762. if (result == 1)
  8763. result = result2;
  8764. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  8765. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  8766. short c1MES_FLAG_Check = (short)result;
  8767. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  8768. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  8769. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  8770. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  8771. //// MES_Flag
  8772. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8773. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8774. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8775. writeToPLC_Flag.Adress = 2003;
  8776. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  8777. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8778. {
  8779. Name = "c1Part1Result_Check",
  8780. Adress = 2024,
  8781. ValueType = PLCValueType.Short,
  8782. Value = c1Part1Result_Check
  8783. });
  8784. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8785. {
  8786. Name = "c1Part2Result_Check",
  8787. Adress = 2025,
  8788. ValueType = PLCValueType.Short,
  8789. Value = c1Part2Result_Check
  8790. });
  8791. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8792. {
  8793. Name = "c1Part1Num_Check",
  8794. Adress = 2026,
  8795. ValueType = PLCValueType.Short,
  8796. Value = c1Part1Num_Check
  8797. });
  8798. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8799. {
  8800. Name = "c1Part2Num_Check",
  8801. Adress = 2027,
  8802. ValueType = PLCValueType.Short,
  8803. Value = c1Part2Num_Check
  8804. });
  8805. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8806. }
  8807. catch (Exception ex)
  8808. {
  8809. string str = ex.StackTrace;
  8810. AddMessage_Station(stationNameStr, LogType.Error,
  8811. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8812. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8813. // MES_Flag
  8814. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8815. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8816. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8817. writeToPLC_Flag.Adress = 2003;
  8818. writeToPLC_Flag.Value = (short)6;
  8819. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8820. }
  8821. stopwatch1.Stop();
  8822. AddMessage(LogType.Info,
  8823. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8824. stopwatch2.ElapsedMilliseconds + "ms");
  8825. }
  8826. /// <summary>
  8827. /// [S3] 值板机 - 二穴载具解绑
  8828. /// </summary>
  8829. /// <param name="plcNo">PLC编号</param>
  8830. /// <param name="stationNameStr">工站全称</param>
  8831. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  8832. {
  8833. Stopwatch stopwatch1 = new Stopwatch();
  8834. Stopwatch stopwatch2 = new Stopwatch();
  8835. try
  8836. {
  8837. stopwatch1.Start();
  8838. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8839. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8840. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8841. // 解绑
  8842. #region 查询载具上的产品信息
  8843. string cavityData = string.Empty;
  8844. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8845. if (string.IsNullOrEmpty(cavityData))
  8846. cavityData = "";
  8847. if (snResult != 0)
  8848. {
  8849. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8850. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  8851. writeToPLC_Flag1.Adress = 2082;
  8852. writeToPLC_Flag1.Value = (short)6;
  8853. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  8854. stopwatch1.Stop();
  8855. AddMessage(LogType.Info,
  8856. stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8857. "ms");
  8858. return;
  8859. }
  8860. #endregion 查询载具上的产品信息
  8861. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8862. #region 解绑
  8863. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  8864. {
  8865. // 删除
  8866. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8867. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  8868. }
  8869. else
  8870. {
  8871. string data_new = string.Join(".", cavitySNs);
  8872. // 删除再插入
  8873. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8874. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8875. OnMessage(LogType.Debug,
  8876. $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  8877. }
  8878. #endregion 解绑
  8879. short c1MES_FLAG_Unbind = 1;
  8880. stopwatch2.Start();
  8881. // MES_Flag
  8882. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8883. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8884. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8885. writeToPLC_Flag.Adress = 2082;
  8886. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  8887. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8888. stopwatch2.Stop();
  8889. }
  8890. catch (Exception ex)
  8891. {
  8892. string str = ex.StackTrace;
  8893. AddMessage_Station(stationNameStr, LogType.Error,
  8894. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
  8895. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8896. // MES_Flag
  8897. stopwatch2.Start();
  8898. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  8899. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8900. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8901. writeToPLC_Flag.Adress = 2082;
  8902. writeToPLC_Flag.Value = (short)6;
  8903. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8904. stopwatch2.Stop();
  8905. }
  8906. stopwatch1.Stop();
  8907. AddMessage(LogType.Info,
  8908. stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8909. stopwatch2.ElapsedMilliseconds + "ms");
  8910. }
  8911. /// <summary>
  8912. /// [S3] 值板机 - 二穴载具绑定
  8913. /// </summary>
  8914. /// <param name="plcNo">PLC编号</param>
  8915. /// <param name="stationNameStr">工站全称</param>
  8916. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  8917. {
  8918. Stopwatch stopwatch1 = new Stopwatch();
  8919. Stopwatch stopwatch2 = new Stopwatch();
  8920. try
  8921. {
  8922. stopwatch1.Start();
  8923. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8924. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8925. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  8926. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8927. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8928. stopwatch2.Start();
  8929. #region 查询载具上的产品信息
  8930. string cavityData = string.Empty;
  8931. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8932. if (string.IsNullOrEmpty(cavityData))
  8933. cavityData = "";
  8934. if (snResult != 0)
  8935. {
  8936. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8937. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  8938. writeToPLC_Flag1.Adress = 2115;
  8939. writeToPLC_Flag1.Value = (short)6;
  8940. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  8941. stopwatch1.Stop();
  8942. AddMessage(LogType.Info,
  8943. stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8944. "ms");
  8945. return;
  8946. }
  8947. #endregion 查询载具上的产品信息
  8948. // 产品换载具
  8949. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8950. string partSn1 = "";
  8951. string partSn2 = "";
  8952. if (cavitySNs != null && cavitySNs.Length >= 2)
  8953. {
  8954. partSn1 = cavitySNs[0];
  8955. partSn2 = cavitySNs[1];
  8956. }
  8957. string data_new = string.Empty;
  8958. // 是否是两个穴位交换
  8959. if (c1CavityReverse_Bind == 1)
  8960. {
  8961. // 交换
  8962. data_new = string.Concat(partSn2, ".", partSn1);
  8963. }
  8964. else
  8965. {
  8966. // 不交换
  8967. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  8968. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  8969. cavitySNs[c1VehicleCavityFr_Bind] = "";
  8970. data_new = string.Join(".", cavitySNs);
  8971. }
  8972. // 删除再插入
  8973. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8974. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8975. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  8976. stopwatch2.Stop();
  8977. short c1MES_FLAG_Bind = 1;
  8978. // MES_Flag
  8979. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8980. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8981. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8982. writeToPLC_Flag.Adress = 2115;
  8983. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  8984. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8985. }
  8986. catch (Exception ex)
  8987. {
  8988. string str = ex.StackTrace;
  8989. AddMessage_Station(stationNameStr, LogType.Error,
  8990. $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8991. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8992. // MES_Flag
  8993. stopwatch2.Start();
  8994. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8995. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8996. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8997. writeToPLC_Flag.Adress = 2115;
  8998. writeToPLC_Flag.Value = (short)6;
  8999. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  9000. stopwatch2.Stop();
  9001. }
  9002. stopwatch1.Stop();
  9003. AddMessage(LogType.Info,
  9004. stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9005. stopwatch2.ElapsedMilliseconds + "ms");
  9006. }
  9007. //// 上次采集到的SN
  9008. //private string sn_值板机 = string.Empty;
  9009. /// <summary>
  9010. /// [S3] 值板机 - 出站接口
  9011. /// </summary>
  9012. /// <param name="plcNo">PLC编号</param>
  9013. private void S3出站接口(int plcNo, string stationCode, string stationName)
  9014. {
  9015. Stopwatch stopwatch1 = new Stopwatch();
  9016. Stopwatch stopwatch2 = new Stopwatch();
  9017. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9018. string stationNameStr = stationCode + stationName;
  9019. string processItem = stationName; // 测试项目
  9020. try
  9021. {
  9022. stopwatch1.Start();
  9023. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9024. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9025. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9026. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9027. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  9028. sn = sn.Replace("\0", "");
  9029. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  9030. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  9031. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9032. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  9033. bool pass = c1Result == 1;
  9034. // 查sn
  9035. #region 查询载具上的产品信息
  9036. string cavityData = string.Empty;
  9037. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  9038. if (string.IsNullOrEmpty(cavityData))
  9039. cavityData = "";
  9040. if (snResult != 0)
  9041. {
  9042. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9043. writeToPLC_Flag1.Name = "c1MES_FLAG";
  9044. writeToPLC_Flag1.Adress = 2150;
  9045. writeToPLC_Flag1.Value = (short)4;
  9046. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  9047. stopwatch1.Stop();
  9048. AddMessage(LogType.Info,
  9049. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9050. return;
  9051. }
  9052. #endregion 查询载具上的产品信息
  9053. string[] cavitySNs = cavityData.Split('.');
  9054. string productSN = "";
  9055. if (cavitySNs != null && cavitySNs.Length >= 2)
  9056. {
  9057. productSN = cavitySNs[c1VehicleCavity];
  9058. cavitySNs[c1VehicleCavity] = "";
  9059. }
  9060. stopwatch2.Start();
  9061. List<TestItem> items = new List<TestItem>();
  9062. items.Add(new TestItem()
  9063. {
  9064. Parameter_name = "二穴载具码",
  9065. Parameter_value = c1ProductSN_Check,
  9066. Parameter_unit = ""
  9067. });
  9068. items.Add(new TestItem()
  9069. {
  9070. Parameter_name = "二穴载具穴号",
  9071. Parameter_value = c1VehicleCavity.ToString(),
  9072. Parameter_unit = ""
  9073. });
  9074. items.Add(new TestItem()
  9075. {
  9076. Parameter_name = "一穴载具码",
  9077. Parameter_value = sn,
  9078. Parameter_unit = ""
  9079. });
  9080. items.Add(new TestItem()
  9081. {
  9082. Parameter_name = "一穴载具穴号",
  9083. Parameter_value = "1",
  9084. Parameter_unit = ""
  9085. });
  9086. items.Add(new TestItem()
  9087. {
  9088. Parameter_name = "产品结果",
  9089. Parameter_value = c1Result == 1 ? "OK" : "NG",
  9090. Parameter_unit = ""
  9091. });
  9092. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  9093. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  9094. short result = (short)result1;
  9095. stopwatch2.Stop();
  9096. #region 存储绑定数据到 边线MES系统中
  9097. if (result == 1)
  9098. {
  9099. string data = string.Concat(productSN);
  9100. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  9101. if (resultMesR != 0)
  9102. {
  9103. result = 4;
  9104. AddMessage_Station(stationNameStr, LogType.Error,
  9105. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  9106. }
  9107. }
  9108. #endregion 存储绑定数据到 边线MES系统中
  9109. #region 产品从 来源载具(二穴载具)中删除
  9110. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  9111. {
  9112. // 删除
  9113. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9114. OnMessage(LogType.Debug,
  9115. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  9116. }
  9117. else
  9118. {
  9119. string data_new = string.Join(".", cavitySNs);
  9120. // 删除再插入
  9121. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9122. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  9123. OnMessage(LogType.Debug,
  9124. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  9125. }
  9126. #endregion 产品从 来源载具(二穴载具)中删除
  9127. // MES_Flag 为MES报错
  9128. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9129. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  9130. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9131. writeToPLC_Flag.Name = "c1MES_FLAG";
  9132. writeToPLC_Flag.Adress = 2150;
  9133. writeToPLC_Flag.Value = result;
  9134. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  9135. OnMessage(LogType.Debug,
  9136. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9137. }
  9138. catch (Exception ex)
  9139. {
  9140. stopwatch2.Restart();
  9141. // MES_Flag 为4上位机报错
  9142. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  9143. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9144. writeToPLC_Flag.Name = "c1MES_FLAG";
  9145. writeToPLC_Flag.Adress = 2150;
  9146. writeToPLC_Flag.Value = (short)4;
  9147. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  9148. stopwatch2.Stop();
  9149. string str = ex.StackTrace;
  9150. AddMessage_Station(stationNameStr, LogType.Error,
  9151. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9152. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9153. }
  9154. stopwatch1.Stop();
  9155. AddMessage(LogType.Info,
  9156. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  9157. stopwatch2.ElapsedMilliseconds + "ms");
  9158. }
  9159. /// <summary>
  9160. /// [S3] 值板机- 节拍接口
  9161. /// </summary>
  9162. /// <param name="plcNo">PLC编号</param>
  9163. /// <param name="stationNameStr">工站全称</param>
  9164. private void S3节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  9165. {
  9166. Stopwatch stopwatch1 = new Stopwatch();
  9167. Stopwatch stopwatch2 = new Stopwatch();
  9168. string resultStr = string.Empty;
  9169. try
  9170. {
  9171. stopwatch1.Start();
  9172. string oEEType = ((int)s1PLCData["a3OEEType"]).ToString(); // 节拍类型(plc写入)
  9173. string a3OEEPartNo = (string)s1PLCData["a3OEEPartNo"]; // 物料码
  9174. a3OEEPartNo = a3OEEPartNo.Replace("\0", "");
  9175. string a3OEEVehicleCode = (string)s1PLCData["a3OEEVehicleCode"]; // 载具SN
  9176. a3OEEVehicleCode = a3OEEVehicleCode.Replace("\0", "");
  9177. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9178. if (!actionBool)
  9179. {
  9180. stopwatch2.Start();
  9181. //写入PLC
  9182. iot_data.beatReturn = 2; //NG
  9183. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9184. stopwatch2.Stop();
  9185. AddMessage(LogType.Info,
  9186. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  9187. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9188. return;
  9189. }
  9190. //作业开始后要有物料和载具信息
  9191. if (string.IsNullOrEmpty(a3OEEPartNo) && string.IsNullOrEmpty(a3OEEVehicleCode) &&
  9192. Convert.ToInt32(oEEType) > 2)
  9193. {
  9194. stopwatch2.Start();
  9195. //写入PLC
  9196. iot_data.beatReturn = 2; //NG
  9197. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9198. stopwatch2.Stop();
  9199. AddMessage_Station(stationNameStr, LogType.Info,
  9200. stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  9201. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9202. return;
  9203. }
  9204. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a3OEEPartNo))
  9205. {
  9206. stopwatch2.Start();
  9207. //写入PLC
  9208. iot_data.beatReturn = 2; //NG
  9209. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9210. stopwatch2.Stop();
  9211. AddMessage_Station(stationNameStr, LogType.Info,
  9212. stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  9213. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9214. return;
  9215. }
  9216. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a3OEEVehicleCode))
  9217. {
  9218. stopwatch2.Start();
  9219. //写入PLC
  9220. iot_data.beatReturn = 2; //NG
  9221. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9222. stopwatch2.Stop();
  9223. AddMessage_Station(stationNameStr, LogType.Info,
  9224. stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  9225. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9226. return;
  9227. }
  9228. short _result = 0;
  9229. // 上传OEE
  9230. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a3OEEPartNo, a3OEEVehicleCode);
  9231. _result = result.Item1;
  9232. resultStr = result.Item2;
  9233. if (_result == 1)
  9234. {
  9235. stopwatch2.Start();
  9236. //写入PLC
  9237. iot_data.beatReturn = 1; //OK
  9238. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9239. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  9240. stopwatch2.Stop();
  9241. }
  9242. else
  9243. {
  9244. stopwatch2.Start();
  9245. //写入PLC
  9246. iot_data.beatReturn = 2; //NG
  9247. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9248. stopwatch2.Stop();
  9249. AddMessage_Station(stationNameStr, LogType.Error,
  9250. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  9251. }
  9252. }
  9253. catch (Exception ex)
  9254. {
  9255. string str = ex.StackTrace;
  9256. AddMessage_Station(stationNameStr, LogType.Error,
  9257. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  9258. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9259. // MES_Flag
  9260. stopwatch2.Start();
  9261. //写入PLC
  9262. iot_data.beatReturn = 2; //NG
  9263. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9264. stopwatch2.Stop();
  9265. }
  9266. stopwatch1.Stop();
  9267. AddMessage(LogType.Info,
  9268. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9269. stopwatch2.ElapsedMilliseconds + "ms");
  9270. }
  9271. #endregion [S3] 值板机
  9272. #endregion PLC3 刘永村
  9273. #region PLC4 刘果段
  9274. #region [S4] 取放桁架
  9275. /// <summary>
  9276. /// S4工位的数据- 触发信号上次的值
  9277. /// </summary>
  9278. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  9279. /// <summary>
  9280. /// S4工位的数据(含触发信号)
  9281. /// </summary>
  9282. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  9283. /// <summary>
  9284. /// S4工位的数据- 回写点位
  9285. /// </summary>
  9286. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  9287. /// <summary>
  9288. /// [S4] 取放桁架
  9289. /// </summary>
  9290. /// <param name="plcNo">PLC编号</param>
  9291. //private void ReadStation_S4(int plcNo)
  9292. //{
  9293. // // [S1] Tray盘上料装备
  9294. // // [S2] FCT
  9295. // // [S3] 值板机
  9296. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  9297. // // [S5] Tray盘下料装备
  9298. // /// 上位机心跳
  9299. // /// 获取设备报警数据与状态信息
  9300. // string stationCode = "[S4_1]";
  9301. // string stationName = "载具下线装备";
  9302. // string stationNameStr = stationCode + stationName;
  9303. // string stationCode2 = "[S4_2]";
  9304. // string stationName2 = "桁架";
  9305. // string stationNameStr2 = stationCode2 + stationName2;
  9306. // string stationCode3 = "[S4_3]";
  9307. // string stationName3 = "提升机1";
  9308. // string stationNameStr3 = stationCode3 + stationName3;
  9309. // string stationCode4 = "[S4_4]";
  9310. // string stationName4 = "提升机2";
  9311. // string stationNameStr4 = stationCode4 + stationName4;
  9312. // string stationCode5 = "[S4_5]";
  9313. // string stationName5 = "载具上线装备";
  9314. // string stationNameStr5 = stationCode5 + stationName5;
  9315. // #region 创建字典
  9316. // // 触发信号字典 赋值
  9317. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9318. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9319. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9320. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9321. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9322. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9323. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9324. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9325. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9326. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9327. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9328. // // PLC数据字典 赋值
  9329. // // 载具下线装备(弹夹上线)
  9330. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9331. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  9332. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9333. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  9334. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9335. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  9336. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  9337. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9338. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9339. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9340. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9341. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9342. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9343. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9344. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9345. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9346. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9347. // s4PLCData.Add("d1Result", 0); // 产品结果
  9348. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9349. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  9350. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  9351. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  9352. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9353. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  9354. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  9355. // // 真空标机(提升机)
  9356. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9357. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  9358. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  9359. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  9360. // s4PLCData.Add("d3Result", 0); // 产品结果
  9361. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9362. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  9363. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  9364. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  9365. // s4PLCData.Add("d4Result", 0); // 产品结果
  9366. // // 载具上线装备(弹夹下线)
  9367. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9368. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  9369. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9370. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  9371. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9372. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  9373. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  9374. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9375. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9376. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9377. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9378. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9379. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9380. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9381. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9382. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9383. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9384. // s4PLCData.Add("d5Result", 0); // 产品结果
  9385. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9386. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  9387. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  9388. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  9389. // #endregion 创建字典
  9390. // while (IsRun)
  9391. // {
  9392. // try
  9393. // {
  9394. // if (!GlobalContext._IsCon_Funs4)
  9395. // {
  9396. // UpdatePLCMonitor(1, plcNo, 0);
  9397. // continue;
  9398. // }
  9399. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9400. // {
  9401. // Stopwatch stopwatch1 = new Stopwatch();
  9402. // Stopwatch stopwatch2 = new Stopwatch();
  9403. // stopwatch1.Start();
  9404. // stopwatch2.Start();
  9405. // #region 一次性读取所有数据
  9406. // // 载具下线装备(弹夹上线)
  9407. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9408. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  9409. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  9410. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  9411. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  9412. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  9413. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  9414. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  9415. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  9416. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  9417. // int[] datas = data1.Concat(data2).ToArray();
  9418. // datas = datas.Concat(data3).ToArray();
  9419. // datas = datas.Concat(data4).ToArray();
  9420. // datas = datas.Concat(data5).ToArray();
  9421. // datas = datas.Concat(data6).ToArray();
  9422. // datas = datas.Concat(data7).ToArray();
  9423. // datas = datas.Concat(data8).ToArray();
  9424. // datas = datas.Concat(data9).ToArray();
  9425. // datas = datas.Concat(data10).ToArray();
  9426. // // 载具下线装备(弹夹上线)
  9427. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  9428. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  9429. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  9430. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  9431. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  9432. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  9433. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  9434. // s4PLCData["d1MES_FLAG"] = datas[65];
  9435. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  9436. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  9437. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  9438. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  9439. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  9440. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  9441. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  9442. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  9443. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  9444. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  9445. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  9446. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  9447. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  9448. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  9449. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  9450. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  9451. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  9452. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  9453. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  9454. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  9455. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  9456. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  9457. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  9458. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  9459. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  9460. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  9461. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  9462. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  9463. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  9464. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  9465. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  9466. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  9467. // s4PLCData["d1Result"] = datas[386];
  9468. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  9469. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  9470. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  9471. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  9472. // s4PLCData["d1OEEType"] = datas[419];
  9473. // // 桁架(查询标机中弹夹的状态)
  9474. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  9475. // s4PLCData["d2BulletclipStates"] = datas[431];
  9476. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  9477. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  9478. // // 真空标机
  9479. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  9480. // s4PLCData["d3MES_FLAG"] = datas[463];
  9481. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  9482. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  9483. // s4PLCData["d3Result"] = datas[484];
  9484. // s4PLCData["d3Type"] = datas[485];
  9485. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  9486. // s4PLCData["d4MES_FLAG"] = datas[496];
  9487. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  9488. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  9489. // s4PLCData["d4Result"] = datas[517];
  9490. // s4PLCData["d4Type"] = datas[518];
  9491. // // 载具上线装备(弹夹下线)
  9492. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  9493. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  9494. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  9495. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  9496. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  9497. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  9498. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  9499. // s4PLCData["d5MES_FLAG"] = datas[591];
  9500. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  9501. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  9502. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  9503. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  9504. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  9505. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  9506. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  9507. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  9508. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  9509. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  9510. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  9511. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  9512. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  9513. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  9514. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  9515. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  9516. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  9517. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  9518. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  9519. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  9520. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  9521. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  9522. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  9523. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  9524. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  9525. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  9526. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  9527. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  9528. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  9529. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  9530. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  9531. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  9532. // s4PLCData["d5Result"] = datas[912];
  9533. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  9534. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  9535. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  9536. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  9537. // s4PLCData["d5OEEType"] = datas[945];
  9538. // #endregion 一次性读取所有数据
  9539. // stopwatch2.Stop();
  9540. // #region 回写操作,写后清空flag
  9541. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  9542. // #endregion 回写操作,写后清空flag
  9543. // // N801A-S4_1 弹夹扫码
  9544. // #region N801A-S4_1 弹夹扫码
  9545. // try
  9546. // {
  9547. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  9548. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  9549. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  9550. // {
  9551. // if (d1BulletclipScanCode == 1) // 0->1
  9552. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9553. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  9554. // }
  9555. // }
  9556. // catch (Exception ex)
  9557. // {
  9558. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9559. // string str = ex.StackTrace;
  9560. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9561. // }
  9562. // #endregion N801A-S4_1 弹夹扫码
  9563. // // N801A-S4_1 载具扫码
  9564. // #region N801A-S4_1 载具扫码
  9565. // try
  9566. // {
  9567. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  9568. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  9569. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  9570. // {
  9571. // if (d1VehicleScanCode == 1) // 0->1
  9572. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9573. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  9574. // }
  9575. // }
  9576. // catch (Exception ex)
  9577. // {
  9578. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9579. // string str = ex.StackTrace;
  9580. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9581. // }
  9582. // #endregion N801A-S4_1 载具扫码
  9583. // // N801A-S4_1 出站接口
  9584. // #region N801A-S4_1 出站接口
  9585. // try
  9586. // {
  9587. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  9588. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  9589. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  9590. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  9591. // {
  9592. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  9593. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9594. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  9595. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  9596. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  9597. // }
  9598. // }
  9599. // catch (Exception ex)
  9600. // {
  9601. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  9602. // string str = ex.StackTrace;
  9603. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9604. // }
  9605. // #endregion N801A-S4_1 出站接口
  9606. // // N801A-S4_1 节拍接口
  9607. // #region N801A-S4_1 节拍接口
  9608. // try
  9609. // {
  9610. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  9611. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  9612. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  9613. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  9614. // {
  9615. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  9616. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9617. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  9618. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  9619. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  9620. // }
  9621. // }
  9622. // catch (Exception ex)
  9623. // {
  9624. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  9625. // string str = ex.StackTrace;
  9626. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9627. // }
  9628. // #endregion N801A-S4_1 节拍接口
  9629. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  9630. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  9631. // try
  9632. // {
  9633. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  9634. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  9635. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  9636. // {
  9637. // if (d2BulletclipScanCode == 1) // 0->1
  9638. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  9639. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  9640. // }
  9641. // }
  9642. // catch (Exception ex)
  9643. // {
  9644. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  9645. // string str = ex.StackTrace;
  9646. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9647. // }
  9648. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  9649. // // N801A-S4_3 真空标机1 数据
  9650. // #region N801A-S4_3 真空标机1
  9651. // try
  9652. // {
  9653. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  9654. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  9655. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  9656. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  9657. // {
  9658. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  9659. // {
  9660. // int stationType = (int)s4PLCData["d3Type"];
  9661. // if (stationType == 1)
  9662. // {
  9663. // // S4_3进站接口
  9664. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  9665. // }
  9666. // else if (stationType == 2)
  9667. // {
  9668. // // S4_3出站接口
  9669. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  9670. // }
  9671. // }
  9672. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  9673. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  9674. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  9675. // }
  9676. // }
  9677. // catch (Exception ex)
  9678. // {
  9679. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  9680. // string str = ex.StackTrace;
  9681. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9682. // }
  9683. // #endregion N801A-S4_3 真空标机1
  9684. // // N801A-S4_4 真空标机2 数据
  9685. // #region N801A-S4_4 真空标机2
  9686. // try
  9687. // {
  9688. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  9689. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  9690. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  9691. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  9692. // {
  9693. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  9694. // {
  9695. // int stationType = (int)s4PLCData["d4Type"];
  9696. // if (stationType == 1)
  9697. // {
  9698. // // S4_4进站接口
  9699. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  9700. // }
  9701. // else if (stationType == 2)
  9702. // {
  9703. // // S4_4出站接口
  9704. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  9705. // }
  9706. // }
  9707. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  9708. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  9709. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  9710. // }
  9711. // }
  9712. // catch (Exception ex)
  9713. // {
  9714. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  9715. // string str = ex.StackTrace;
  9716. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9717. // }
  9718. // #endregion N801A-S4_4 真空标机2
  9719. // // N801A-S4_5 弹夹扫码 数据
  9720. // #region N801A-S4_5 弹夹扫码
  9721. // try
  9722. // {
  9723. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  9724. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  9725. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  9726. // {
  9727. // if (d5BulletclipScanCode == 1) // 0->1
  9728. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9729. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  9730. // }
  9731. // }
  9732. // catch (Exception ex)
  9733. // {
  9734. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  9735. // string str = ex.StackTrace;
  9736. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9737. // }
  9738. // #endregion N801A-S4_5 弹夹扫码
  9739. // // N801A-S4_5 载具扫码 数据
  9740. // #region N801A-S4_5 载具扫码
  9741. // try
  9742. // {
  9743. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  9744. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  9745. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  9746. // {
  9747. // if (d5VehicleScanCode == 1) // 0->1
  9748. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9749. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  9750. // }
  9751. // }
  9752. // catch (Exception ex)
  9753. // {
  9754. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  9755. // string str = ex.StackTrace;
  9756. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9757. // }
  9758. // #endregion N801A-S4_5 载具扫码
  9759. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  9760. // #region N801A-S4_5 出站接口
  9761. // try
  9762. // {
  9763. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  9764. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  9765. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  9766. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  9767. // {
  9768. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  9769. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  9770. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  9771. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  9772. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  9773. // }
  9774. // }
  9775. // catch (Exception ex)
  9776. // {
  9777. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  9778. // string str = ex.StackTrace;
  9779. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9780. // }
  9781. // #endregion N801A-S4_5 出站接口
  9782. // // N801A-S4_5 节拍接口 数据
  9783. // #region N801A-S4_5 节拍接口
  9784. // try
  9785. // {
  9786. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  9787. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  9788. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  9789. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  9790. // {
  9791. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  9792. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  9793. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  9794. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  9795. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  9796. // }
  9797. // }
  9798. // catch (Exception ex)
  9799. // {
  9800. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  9801. // string str = ex.StackTrace;
  9802. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9803. // }
  9804. // #endregion N801A-S4_5 节拍接口
  9805. // #region 心跳
  9806. // try
  9807. // {
  9808. // short states = 0;
  9809. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9810. // }
  9811. // catch (Exception ex)
  9812. // {
  9813. // string str = ex.StackTrace;
  9814. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9815. // }
  9816. // #endregion 心跳
  9817. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9818. // stopwatch1.Stop();
  9819. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9820. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9821. // }
  9822. // else
  9823. // {
  9824. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9825. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  9826. // Funs[plcNo].Connect();
  9827. // }
  9828. // }
  9829. // catch (Exception ex)
  9830. // {
  9831. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9832. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  9833. // Funs[plcNo].ReConnect();
  9834. // }
  9835. // Thread.Sleep(IntervalReadPLC);
  9836. // }
  9837. //}
  9838. /// <summary>
  9839. /// [S4] 取放桁架 - S4_1弹夹扫码
  9840. /// </summary>
  9841. /// <param name="plcNo">PLC编号</param>
  9842. /// <param name="stationNameStr">工站全称</param>
  9843. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  9844. {
  9845. Stopwatch stopwatch1 = new Stopwatch();
  9846. Stopwatch stopwatch2 = new Stopwatch();
  9847. try
  9848. {
  9849. stopwatch1.Start();
  9850. // ZS 弹夹扫码
  9851. string d1BulletclipCode = " "; // 扫到的码
  9852. short d1BulletclipScanCode = 2;
  9853. stopwatch2.Start();
  9854. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  9855. //// MES_Flag
  9856. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9857. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9858. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9859. writeToPLC_Flag.Adress = 2002;
  9860. writeToPLC_Flag.Value = d1BulletclipScanCode;
  9861. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9862. {
  9863. Name = "d1BulletclipCode",
  9864. Adress = 2003,
  9865. ValueType = PLCValueType.String,
  9866. ValueTypeStrLength = 20,
  9867. Value = d1BulletclipCode
  9868. });
  9869. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9870. stopwatch2.Stop();
  9871. }
  9872. catch (Exception ex)
  9873. {
  9874. string str = ex.StackTrace;
  9875. AddMessage_Station(stationNameStr, LogType.Error,
  9876. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9877. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9878. stopwatch2.Start();
  9879. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  9880. //// MES_Flag
  9881. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9882. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9883. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9884. writeToPLC_Flag.Adress = 2002;
  9885. writeToPLC_Flag.Value = (short)6;
  9886. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9887. {
  9888. Name = "d1BulletclipCode",
  9889. Adress = 2003,
  9890. ValueType = PLCValueType.String,
  9891. ValueTypeStrLength = 20,
  9892. Value = " "
  9893. });
  9894. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9895. stopwatch2.Stop();
  9896. }
  9897. stopwatch1.Stop();
  9898. AddMessage(LogType.Info,
  9899. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9900. stopwatch2.ElapsedMilliseconds + "ms");
  9901. }
  9902. /// <summary>
  9903. /// [S4] 取放桁架 - S4_1载具扫码
  9904. /// </summary>
  9905. /// <param name="plcNo">PLC编号</param>
  9906. /// <param name="stationNameStr">工站全称</param>
  9907. private void S4_1载具扫码(int plcNo, string stationNameStr)
  9908. {
  9909. Stopwatch stopwatch1 = new Stopwatch();
  9910. Stopwatch stopwatch2 = new Stopwatch();
  9911. try
  9912. {
  9913. stopwatch1.Start();
  9914. // ZS 载具扫码
  9915. string d1VehicleCode = ""; // 扫到的码
  9916. short d1VehicleScanCode = 2;
  9917. #region 进站
  9918. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  9919. {
  9920. #region 查询载具上的产品信息
  9921. string cavityData = string.Empty;
  9922. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  9923. if (string.IsNullOrEmpty(cavityData))
  9924. cavityData = "";
  9925. if (snResult != 0)
  9926. {
  9927. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9928. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  9929. writeToPLC_Flag1.Adress = 2033;
  9930. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  9931. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9932. {
  9933. Name = "d1VehicleCode",
  9934. Adress = 2034,
  9935. ValueType = PLCValueType.String,
  9936. ValueTypeStrLength = 20,
  9937. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9938. });
  9939. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  9940. stopwatch1.Stop();
  9941. AddMessage(LogType.Info,
  9942. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9943. "ms");
  9944. return;
  9945. }
  9946. string[] cavitySNs = cavityData.Split('.');
  9947. string partNo = "";
  9948. if (cavitySNs != null && cavitySNs.Length >= 1)
  9949. {
  9950. partNo = cavitySNs[0];
  9951. }
  9952. #endregion 查询载具上的产品信息
  9953. List<TestItem> item = new List<TestItem>();
  9954. item.Add(new TestItem()
  9955. {
  9956. Parameter_name = "载具码",
  9957. Parameter_value = d1VehicleCode,
  9958. });
  9959. item.Add(new TestItem()
  9960. {
  9961. Parameter_name = "载具穴号",
  9962. Parameter_value = "1",
  9963. });
  9964. stopwatch2.Start();
  9965. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9966. partNo, item, out string errorMsg);
  9967. stopwatch2.Stop();
  9968. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  9969. }
  9970. #endregion 进站
  9971. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  9972. //// MES_Flag
  9973. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9974. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9975. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9976. writeToPLC_Flag.Adress = 2033;
  9977. writeToPLC_Flag.Value = d1VehicleScanCode;
  9978. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9979. {
  9980. Name = "d1VehicleCode",
  9981. Adress = 2034,
  9982. ValueType = PLCValueType.String,
  9983. ValueTypeStrLength = 20,
  9984. Value = d1VehicleCode
  9985. });
  9986. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9987. }
  9988. catch (Exception ex)
  9989. {
  9990. string str = ex.StackTrace;
  9991. AddMessage_Station(stationNameStr, LogType.Error,
  9992. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9993. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9994. stopwatch2.Start();
  9995. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  9996. //// MES_Flag
  9997. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9998. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9999. writeToPLC_Flag.Name = "d1VehicleScanCode";
  10000. writeToPLC_Flag.Adress = 2033;
  10001. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  10002. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10003. {
  10004. Name = "d1VehicleCode",
  10005. Adress = 2034,
  10006. ValueType = PLCValueType.String,
  10007. ValueTypeStrLength = 20,
  10008. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10009. });
  10010. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  10011. stopwatch2.Stop();
  10012. }
  10013. stopwatch1.Stop();
  10014. AddMessage(LogType.Info,
  10015. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10016. stopwatch2.ElapsedMilliseconds + "ms");
  10017. }
  10018. // 上次采集到的SN
  10019. //private string sn_S4_1出站接口 = string.Empty;
  10020. /// <summary>
  10021. /// [S4] 取放桁架 - S4_1出站接口
  10022. /// </summary>
  10023. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  10024. {
  10025. Stopwatch stopwatch1 = new Stopwatch();
  10026. Stopwatch stopwatch2 = new Stopwatch();
  10027. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10028. string stationNameStr = stationCode + stationName;
  10029. string processItem = stationName; // 测试项目
  10030. try
  10031. {
  10032. stopwatch1.Start();
  10033. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10034. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10035. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10036. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10037. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  10038. sn = sn.Replace("\0", "");
  10039. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  10040. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  10041. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  10042. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  10043. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  10044. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  10045. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  10046. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  10047. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  10048. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  10049. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  10050. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  10051. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  10052. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  10053. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  10054. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  10055. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  10056. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  10057. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  10058. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  10059. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  10060. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  10061. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  10062. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  10063. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  10064. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  10065. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  10066. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  10067. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  10068. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  10069. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  10070. bool pass = d1Result == 1;
  10071. // 存 载具SN列表
  10072. List<string> vehicleCodes = new List<string>()
  10073. {
  10074. d1VehicleCode1, d1VehicleCode2, d1VehicleCode3, d1VehicleCode4, d1VehicleCode5,
  10075. d1VehicleCode6, d1VehicleCode7, d1VehicleCode8, d1VehicleCode9, d1VehicleCode10,
  10076. d1VehicleCode11, d1VehicleCode12, d1VehicleCode13, d1VehicleCode14, d1VehicleCode15
  10077. };
  10078. // 统一查 产品SN列表
  10079. List<string> partNos = new List<string>();
  10080. foreach (string vehicleCode in vehicleCodes)
  10081. {
  10082. if (string.IsNullOrEmpty(vehicleCode))
  10083. partNos.Add("");
  10084. else
  10085. {
  10086. string partNo = "";
  10087. #region 查询载具上的产品信息
  10088. string cavityData = string.Empty;
  10089. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10090. if (string.IsNullOrEmpty(cavityData))
  10091. cavityData = "";
  10092. if (snResult != 0)
  10093. {
  10094. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10095. writeToPLC_Flag1.Name = "d1MES_FLAG";
  10096. writeToPLC_Flag1.Adress = 2065;
  10097. writeToPLC_Flag1.Value = (short)4;
  10098. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  10099. stopwatch1.Stop();
  10100. AddMessage(LogType.Info,
  10101. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10102. "ms");
  10103. return;
  10104. }
  10105. string[] cavitySNs = cavityData.Split('.');
  10106. if (cavitySNs != null && cavitySNs.Length >= 1)
  10107. partNo = cavitySNs[0];
  10108. #endregion 查询载具上的产品信息
  10109. partNos.Add(partNo);
  10110. }
  10111. }
  10112. // 统一上传
  10113. stopwatch2.Start();
  10114. List<int> results = new List<int>();
  10115. for (int i = 0; i < partNos.Count; i++)
  10116. {
  10117. string index = (i + 1).ToString(); // 弹夹穴号
  10118. if (string.IsNullOrEmpty(partNos[i]))
  10119. results.Add(1);
  10120. else
  10121. {
  10122. List<TestItem> items1 = new List<TestItem>();
  10123. items1.Add(new TestItem()
  10124. {
  10125. Parameter_name = "弹夹码",
  10126. Parameter_value = sn,
  10127. Parameter_unit = ""
  10128. });
  10129. items1.Add(new TestItem()
  10130. {
  10131. Parameter_name = "弹夹穴号",
  10132. Parameter_value = index,
  10133. Parameter_unit = ""
  10134. });
  10135. items1.Add(new TestItem()
  10136. {
  10137. Parameter_name = "载具码",
  10138. Parameter_value = vehicleCodes[i],
  10139. Parameter_unit = ""
  10140. });
  10141. items1.Add(new TestItem()
  10142. {
  10143. Parameter_name = "载具穴号",
  10144. Parameter_value = "1",
  10145. Parameter_unit = ""
  10146. });
  10147. items1.Add(new TestItem()
  10148. {
  10149. Parameter_name = "产品结果",
  10150. Parameter_value = d1Result == 1 ? "OK" : "NG",
  10151. Parameter_unit = ""
  10152. });
  10153. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10154. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  10155. results.Add(result1);
  10156. }
  10157. }
  10158. short result = 0;
  10159. if (results.All(a => a == 1))
  10160. result = 1;
  10161. else if (results.Contains(3))
  10162. result = 3;
  10163. else if (results.Contains(2))
  10164. result = 2;
  10165. else if (results.Contains(4))
  10166. result = 4;
  10167. else
  10168. result = 4;
  10169. stopwatch2.Stop();
  10170. #region 存储绑定数据到 边线MES系统中
  10171. if (result == 1)
  10172. {
  10173. string data = string.Join(".", vehicleCodes);
  10174. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  10175. if (resultMesR != 0)
  10176. {
  10177. result = 4;
  10178. AddMessage_Station(stationNameStr, LogType.Error,
  10179. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  10180. }
  10181. }
  10182. #endregion 存储绑定数据到 边线MES系统中
  10183. // MES_Flag 为4MES报错
  10184. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10185. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10186. writeToPLC_Flag.Name = "d1MES_FLAG";
  10187. writeToPLC_Flag.Adress = 2065;
  10188. writeToPLC_Flag.Value = result;
  10189. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  10190. OnMessage(LogType.Debug,
  10191. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  10192. }
  10193. catch (Exception ex)
  10194. {
  10195. stopwatch2.Restart();
  10196. // MES_Flag 为4上位机报错
  10197. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  10198. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10199. writeToPLC_Flag.Name = "d1MES_FLAG";
  10200. writeToPLC_Flag.Adress = 2065;
  10201. writeToPLC_Flag.Value = (short)4;
  10202. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  10203. stopwatch2.Stop();
  10204. string str = ex.StackTrace;
  10205. AddMessage_Station(stationNameStr, LogType.Error,
  10206. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10207. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10208. }
  10209. stopwatch1.Stop();
  10210. AddMessage(LogType.Info,
  10211. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10212. stopwatch2.ElapsedMilliseconds + "ms");
  10213. }
  10214. /// <summary>
  10215. /// [S4] 取放桁架 - S4_1节拍接口
  10216. /// </summary>
  10217. /// <param name="plcNo">PLC编号</param>
  10218. /// <param name="stationNameStr">工站全称</param>
  10219. private void S4_1节拍接口(int plcNo, string stationNameStr)
  10220. {
  10221. Stopwatch stopwatch1 = new Stopwatch();
  10222. Stopwatch stopwatch2 = new Stopwatch();
  10223. string resultStr = string.Empty;
  10224. try
  10225. {
  10226. stopwatch1.Start();
  10227. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  10228. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  10229. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  10230. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  10231. if (!actionBool)
  10232. {
  10233. stopwatch2.Start();
  10234. // MES_Flag
  10235. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10236. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10237. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  10238. writeToPLC_Flag1.Adress = 2398;
  10239. writeToPLC_Flag1.Value = (short)4;
  10240. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  10241. stopwatch2.Stop();
  10242. AddMessage(LogType.Info,
  10243. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  10244. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10245. return;
  10246. }
  10247. string d1OEEPartNo = string.Empty; // 物料码
  10248. if (string.IsNullOrEmpty(d1OEEProductSN))
  10249. {
  10250. stopwatch2.Start();
  10251. // MES_Flag
  10252. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10253. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10254. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  10255. writeToPLC_Flag1.Adress = 2398;
  10256. writeToPLC_Flag1.Value = (short)1;
  10257. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  10258. stopwatch2.Stop();
  10259. AddMessage(LogType.Info,
  10260. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10261. stopwatch2.ElapsedMilliseconds + "ms");
  10262. return;
  10263. }
  10264. else
  10265. {
  10266. // 查产品SN ZS
  10267. d1OEEPartNo = "Test";
  10268. }
  10269. short d1OEEMES_FLAG = 0;
  10270. // 上传OEE
  10271. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  10272. d1OEEMES_FLAG = result.Item1;
  10273. resultStr = result.Item2;
  10274. stopwatch2.Start();
  10275. // MES_Flag
  10276. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10277. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10278. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  10279. writeToPLC_Flag.Adress = 2398;
  10280. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  10281. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  10282. stopwatch2.Stop();
  10283. }
  10284. catch (Exception ex)
  10285. {
  10286. string str = ex.StackTrace;
  10287. AddMessage_Station(stationNameStr, LogType.Error,
  10288. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  10289. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10290. // MES_Flag
  10291. stopwatch2.Start();
  10292. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  10293. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10294. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  10295. writeToPLC_Flag.Adress = 2398;
  10296. writeToPLC_Flag.Value = (short)4;
  10297. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  10298. stopwatch2.Stop();
  10299. }
  10300. stopwatch1.Stop();
  10301. AddMessage(LogType.Info,
  10302. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10303. stopwatch2.ElapsedMilliseconds + "ms");
  10304. }
  10305. /// <summary>
  10306. /// [S4] 取放桁架 - S4_2桁架
  10307. /// </summary>
  10308. /// <param name="plcNo">PLC编号</param>
  10309. /// <param name="stationNameStr">工站全称</param>
  10310. private void S4_2桁架(int plcNo, string stationNameStr)
  10311. {
  10312. Stopwatch stopwatch1 = new Stopwatch();
  10313. Stopwatch stopwatch2 = new Stopwatch();
  10314. try
  10315. {
  10316. stopwatch1.Start();
  10317. // ZS 弹夹扫码
  10318. string d2BulletclipCode = " "; // 扫到的码
  10319. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  10320. short d2BulletclipScanCode = 2;
  10321. stopwatch2.Start();
  10322. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  10323. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  10324. //// MES_Flag
  10325. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10326. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10327. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10328. writeToPLC_Flag.Adress = 2430;
  10329. writeToPLC_Flag.Value = d2BulletclipScanCode;
  10330. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10331. {
  10332. Name = "d2BulletclipCode",
  10333. Adress = 2432,
  10334. ValueType = PLCValueType.String,
  10335. ValueTypeStrLength = 20,
  10336. Value = d2BulletclipCode
  10337. });
  10338. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10339. {
  10340. Name = "d2BulletclipStates",
  10341. Adress = 2431,
  10342. ValueType = PLCValueType.Short,
  10343. Value = d2BulletclipStates
  10344. });
  10345. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10346. stopwatch2.Stop();
  10347. }
  10348. catch (Exception ex)
  10349. {
  10350. string str = ex.StackTrace;
  10351. AddMessage_Station(stationNameStr, LogType.Error,
  10352. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10353. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10354. stopwatch2.Start();
  10355. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  10356. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  10357. // MES_Flag
  10358. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  10359. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10360. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10361. writeToPLC_Flag.Adress = 2430;
  10362. writeToPLC_Flag.Value = (short)6;
  10363. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10364. {
  10365. Name = "d2BulletclipCode",
  10366. Adress = 2432,
  10367. ValueType = PLCValueType.String,
  10368. ValueTypeStrLength = 20,
  10369. Value = " "
  10370. });
  10371. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10372. {
  10373. Name = "d2BulletclipStates",
  10374. Adress = 2431,
  10375. ValueType = PLCValueType.Short,
  10376. Value = (short)0
  10377. });
  10378. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10379. stopwatch2.Stop();
  10380. }
  10381. stopwatch1.Stop();
  10382. AddMessage(LogType.Info,
  10383. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10384. stopwatch2.ElapsedMilliseconds + "ms");
  10385. }
  10386. // 上次采集到的SN
  10387. //private string sn_S4_3进站接口 = string.Empty;
  10388. /// <summary>
  10389. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  10390. /// </summary>
  10391. private void S4_3进站接口(int plcNo, string stationNameStr)
  10392. {
  10393. Stopwatch stopwatch1 = new Stopwatch();
  10394. Stopwatch stopwatch2 = new Stopwatch();
  10395. try
  10396. {
  10397. stopwatch1.Start();
  10398. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10399. sn = sn.Replace("\0", "");
  10400. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10401. #region 查询15个载具码
  10402. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10403. string vehicleData = string.Empty;
  10404. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10405. if (string.IsNullOrEmpty(vehicleData))
  10406. vehicleData = "";
  10407. if (snResult != 0)
  10408. {
  10409. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10410. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10411. writeToPLC_Flag1.Adress = 2463;
  10412. writeToPLC_Flag1.Value = (short)4;
  10413. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10414. stopwatch1.Stop();
  10415. AddMessage(LogType.Info,
  10416. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10417. return;
  10418. }
  10419. string[] cavitySNs = vehicleData.Split('.');
  10420. if (cavitySNs != null && cavitySNs.Length > 0)
  10421. {
  10422. for (int i = 0; i < cavitySNs.Length; i++)
  10423. {
  10424. if (string.IsNullOrEmpty(cavitySNs[i]))
  10425. vehicleCodes.Add("");
  10426. else
  10427. vehicleCodes.Add(cavitySNs[i]);
  10428. }
  10429. }
  10430. #endregion 查询15个载具码
  10431. #region 查询15个产品SN
  10432. List<string> portNos = new List<string>(); // 15个产品SN
  10433. foreach (string vehicleCode in vehicleCodes)
  10434. {
  10435. if (string.IsNullOrEmpty(vehicleCode))
  10436. portNos.Add("");
  10437. else
  10438. {
  10439. // 查询
  10440. string cavityData = string.Empty;
  10441. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10442. if (string.IsNullOrEmpty(cavityData))
  10443. cavityData = "";
  10444. if (snResult1 != 0)
  10445. {
  10446. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10447. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10448. writeToPLC_Flag1.Adress = 2463;
  10449. writeToPLC_Flag1.Value = (short)4;
  10450. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10451. stopwatch1.Stop();
  10452. AddMessage(LogType.Info,
  10453. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10454. stopwatch1.ElapsedMilliseconds + "ms");
  10455. return;
  10456. }
  10457. string[] partSNs = cavityData.Split('.');
  10458. if (partSNs != null && partSNs.Length >= 1)
  10459. portNos.Add(partSNs[0]);
  10460. else
  10461. portNos.Add("");
  10462. }
  10463. }
  10464. #endregion 查询15个产品SN
  10465. // 调用MES进站(最多15个)
  10466. stopwatch2.Start();
  10467. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10468. for (int i = 0; i < vehicleCodes.Count; i++)
  10469. {
  10470. // 循环进站
  10471. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10472. {
  10473. // 产品SN(物料码)校验
  10474. string portNo = portNos[i];
  10475. List<TestItem> item = new List<TestItem>();
  10476. item.Add(new TestItem()
  10477. {
  10478. Parameter_name = "弹夹码",
  10479. Parameter_value = sn,
  10480. });
  10481. item.Add(new TestItem()
  10482. {
  10483. Parameter_name = "弹夹穴位",
  10484. Parameter_value = (i + 1).ToString(),
  10485. });
  10486. item.Add(new TestItem()
  10487. {
  10488. Parameter_name = "载具码",
  10489. Parameter_value = vehicleCodes[i],
  10490. });
  10491. item.Add(new TestItem()
  10492. {
  10493. Parameter_name = "载具穴号",
  10494. Parameter_value = "1",
  10495. });
  10496. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10497. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10498. }
  10499. }
  10500. stopwatch2.Stop();
  10501. short result = 0;
  10502. bool haveMesWarn = results.Contains(5);
  10503. bool havePCWarn = results.Contains(6);
  10504. if (haveMesWarn)
  10505. result = 2; // 5->2
  10506. else if (havePCWarn)
  10507. result = 6; // 6->4
  10508. else
  10509. result = 1;
  10510. // MES_Flag 为4MES报错
  10511. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10512. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10513. writeToPLC_Flag.Name = "d3MES_FLAG";
  10514. writeToPLC_Flag.Adress = 2463;
  10515. writeToPLC_Flag.Value = result;
  10516. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10517. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10518. }
  10519. catch (Exception ex)
  10520. {
  10521. stopwatch2.Stop();
  10522. // MES_Flag 为4上位机报错
  10523. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10524. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10525. writeToPLC_Flag.Name = "d3MES_FLAG";
  10526. writeToPLC_Flag.Adress = 2463;
  10527. writeToPLC_Flag.Value = (short)4;
  10528. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10529. string str = ex.StackTrace;
  10530. AddMessage_Station(stationNameStr, LogType.Error,
  10531. $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10532. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10533. }
  10534. stopwatch1.Stop();
  10535. AddMessage(LogType.Info,
  10536. stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10537. stopwatch2.ElapsedMilliseconds + "ms");
  10538. }
  10539. // 上次采集到的SN
  10540. //private string sn_S4_3出站接口 = string.Empty;
  10541. /// <summary>
  10542. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  10543. /// </summary>
  10544. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  10545. {
  10546. Stopwatch stopwatch1 = new Stopwatch();
  10547. Stopwatch stopwatch2 = new Stopwatch();
  10548. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10549. string stationNameStr = stationCode + stationName;
  10550. string processItem = stationName; // 测试项目
  10551. try
  10552. {
  10553. stopwatch1.Start();
  10554. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10555. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10556. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10557. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10558. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10559. sn = sn.Replace("\0", "");
  10560. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10561. bool isPass = d3Result == 1; // 产品结果 bool
  10562. #region 查询15个载具码
  10563. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10564. string vehicleData = string.Empty;
  10565. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10566. if (string.IsNullOrEmpty(vehicleData))
  10567. vehicleData = "";
  10568. if (snResult1 != 0)
  10569. {
  10570. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10571. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10572. writeToPLC_Flag1.Adress = 2463;
  10573. writeToPLC_Flag1.Value = (short)4;
  10574. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10575. stopwatch1.Stop();
  10576. AddMessage(LogType.Info,
  10577. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10578. return;
  10579. }
  10580. string[] cavitySNs = vehicleData.Split('.');
  10581. if (cavitySNs != null && cavitySNs.Length > 0)
  10582. {
  10583. for (int i = 0; i < cavitySNs.Length; i++)
  10584. {
  10585. if (string.IsNullOrEmpty(cavitySNs[i]))
  10586. vehicleCodes.Add("");
  10587. else
  10588. vehicleCodes.Add(cavitySNs[i]);
  10589. }
  10590. }
  10591. #endregion 查询15个载具码
  10592. // 统一查 产品SN列表
  10593. List<string> partNos = new List<string>();
  10594. foreach (string vehicleCode in vehicleCodes)
  10595. {
  10596. if (string.IsNullOrEmpty(vehicleCode))
  10597. partNos.Add("");
  10598. else
  10599. {
  10600. string partNo = "";
  10601. #region 查询载具上的产品信息
  10602. string cavityData = string.Empty;
  10603. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10604. if (string.IsNullOrEmpty(cavityData))
  10605. cavityData = "";
  10606. if (snResult != 0)
  10607. {
  10608. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10609. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10610. writeToPLC_Flag1.Adress = 2463;
  10611. writeToPLC_Flag1.Value = (short)4;
  10612. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10613. stopwatch1.Stop();
  10614. AddMessage(LogType.Info,
  10615. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10616. "ms");
  10617. return;
  10618. }
  10619. string[] partSNs = cavityData.Split('.');
  10620. if (partSNs != null && partSNs.Length >= 1)
  10621. partNo = partSNs[0];
  10622. #endregion 查询载具上的产品信息
  10623. partNos.Add(partNo);
  10624. }
  10625. }
  10626. // 统一上传 - 调用MES出站
  10627. stopwatch2.Start();
  10628. List<int> results = new List<int>();
  10629. for (int i = 0; i < partNos.Count; i++)
  10630. {
  10631. string index = (i + 1).ToString(); // 弹夹穴号
  10632. if (string.IsNullOrEmpty(partNos[i]))
  10633. results.Add(1);
  10634. else
  10635. {
  10636. List<TestItem> items1 = new List<TestItem>();
  10637. items1.Add(new TestItem()
  10638. {
  10639. Parameter_name = "弹夹码",
  10640. Parameter_value = sn,
  10641. Parameter_unit = ""
  10642. });
  10643. items1.Add(new TestItem()
  10644. {
  10645. Parameter_name = "弹夹穴号",
  10646. Parameter_value = index,
  10647. Parameter_unit = ""
  10648. });
  10649. items1.Add(new TestItem()
  10650. {
  10651. Parameter_name = "载具码",
  10652. Parameter_value = vehicleCodes[i],
  10653. Parameter_unit = ""
  10654. });
  10655. items1.Add(new TestItem()
  10656. {
  10657. Parameter_name = "载具穴号",
  10658. Parameter_value = "1",
  10659. Parameter_unit = ""
  10660. });
  10661. items1.Add(new TestItem()
  10662. {
  10663. Parameter_name = "产品结果",
  10664. Parameter_value = d3Result == 1 ? "OK" : "NG",
  10665. Parameter_unit = ""
  10666. });
  10667. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10668. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10669. results.Add(result1);
  10670. }
  10671. }
  10672. short result = 0;
  10673. if (results.All(a => a == 1))
  10674. result = 1;
  10675. else if (results.Contains(3))
  10676. result = 3;
  10677. else if (results.Contains(2))
  10678. result = 2;
  10679. else if (results.Contains(4))
  10680. result = 4;
  10681. else
  10682. result = 4;
  10683. stopwatch2.Stop();
  10684. // MES_Flag 为4MES报错
  10685. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10686. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10687. writeToPLC_Flag.Name = "d3MES_FLAG";
  10688. writeToPLC_Flag.Adress = 2463;
  10689. writeToPLC_Flag.Value = result;
  10690. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10691. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10692. }
  10693. catch (Exception ex)
  10694. {
  10695. stopwatch2.Restart();
  10696. // MES_Flag 为4上位机报错
  10697. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10698. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10699. writeToPLC_Flag.Name = "d3MES_FLAG";
  10700. writeToPLC_Flag.Adress = 2463;
  10701. writeToPLC_Flag.Value = (short)4;
  10702. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10703. string str = ex.StackTrace;
  10704. AddMessage_Station(stationNameStr, LogType.Error,
  10705. $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10706. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10707. stopwatch2.Stop();
  10708. }
  10709. stopwatch1.Stop();
  10710. AddMessage(LogType.Info,
  10711. stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10712. stopwatch2.ElapsedMilliseconds + "ms");
  10713. }
  10714. // 上次采集到的SN
  10715. //private string sn_S4_4进站接口 = string.Empty;
  10716. /// <summary>
  10717. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  10718. /// </summary>
  10719. private void S4_4进站接口(int plcNo, string stationNameStr)
  10720. {
  10721. Stopwatch stopwatch1 = new Stopwatch();
  10722. Stopwatch stopwatch2 = new Stopwatch();
  10723. try
  10724. {
  10725. stopwatch1.Start();
  10726. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10727. sn = sn.Replace("\0", "");
  10728. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10729. #region 查询15个载具码
  10730. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10731. string vehicleData = string.Empty;
  10732. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10733. if (string.IsNullOrEmpty(vehicleData))
  10734. vehicleData = "";
  10735. if (snResult != 0)
  10736. {
  10737. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10738. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10739. writeToPLC_Flag1.Adress = 2463;
  10740. writeToPLC_Flag1.Value = (short)4;
  10741. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10742. stopwatch1.Stop();
  10743. AddMessage(LogType.Info,
  10744. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10745. return;
  10746. }
  10747. string[] cavitySNs = vehicleData.Split('.');
  10748. if (cavitySNs != null && cavitySNs.Length > 0)
  10749. {
  10750. for (int i = 0; i < cavitySNs.Length; i++)
  10751. {
  10752. if (string.IsNullOrEmpty(cavitySNs[i]))
  10753. vehicleCodes.Add("");
  10754. else
  10755. vehicleCodes.Add(cavitySNs[i]);
  10756. }
  10757. }
  10758. #endregion 查询15个载具码
  10759. #region 查询15个产品SN
  10760. List<string> portNos = new List<string>(); // 15个产品SN
  10761. foreach (string vehicleCode in vehicleCodes)
  10762. {
  10763. if (string.IsNullOrEmpty(vehicleCode))
  10764. portNos.Add("");
  10765. else
  10766. {
  10767. // 查询
  10768. string cavityData = string.Empty;
  10769. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10770. if (string.IsNullOrEmpty(cavityData))
  10771. cavityData = "";
  10772. if (snResult1 != 0)
  10773. {
  10774. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10775. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10776. writeToPLC_Flag1.Adress = 2463;
  10777. writeToPLC_Flag1.Value = (short)4;
  10778. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10779. stopwatch1.Stop();
  10780. AddMessage(LogType.Info,
  10781. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10782. stopwatch1.ElapsedMilliseconds + "ms");
  10783. return;
  10784. }
  10785. string[] partSNs = cavityData.Split('.');
  10786. if (partSNs != null && partSNs.Length >= 1)
  10787. portNos.Add(partSNs[0]);
  10788. else
  10789. portNos.Add("");
  10790. }
  10791. }
  10792. #endregion 查询15个产品SN
  10793. // 调用MES进站(最多15个)
  10794. stopwatch2.Start();
  10795. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10796. for (int i = 0; i < vehicleCodes.Count; i++)
  10797. {
  10798. // 循环进站
  10799. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10800. {
  10801. // 产品SN(物料码)校验
  10802. string portNo = portNos[i];
  10803. List<TestItem> item = new List<TestItem>();
  10804. item.Add(new TestItem()
  10805. {
  10806. Parameter_name = "弹夹码",
  10807. Parameter_value = sn,
  10808. });
  10809. item.Add(new TestItem()
  10810. {
  10811. Parameter_name = "弹夹穴位",
  10812. Parameter_value = (i + 1).ToString(),
  10813. });
  10814. item.Add(new TestItem()
  10815. {
  10816. Parameter_name = "载具码",
  10817. Parameter_value = vehicleCodes[i],
  10818. });
  10819. item.Add(new TestItem()
  10820. {
  10821. Parameter_name = "载具穴号",
  10822. Parameter_value = "1",
  10823. });
  10824. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10825. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10826. }
  10827. }
  10828. stopwatch2.Stop();
  10829. short result = 0;
  10830. bool haveMesWarn = results.Contains(5);
  10831. bool havePCWarn = results.Contains(6);
  10832. if (haveMesWarn)
  10833. result = 2; // 5->2
  10834. else if (havePCWarn)
  10835. result = 6; // 6->4
  10836. else
  10837. result = 1;
  10838. // MES_Flag 为4MES报错
  10839. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10840. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10841. writeToPLC_Flag.Name = "d4MES_FLAG";
  10842. writeToPLC_Flag.Adress = 2496;
  10843. writeToPLC_Flag.Value = result;
  10844. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10845. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10846. }
  10847. catch (Exception ex)
  10848. {
  10849. stopwatch2.Stop();
  10850. // MES_Flag 为4上位机报错
  10851. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10852. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10853. writeToPLC_Flag.Name = "d4MES_FLAG";
  10854. writeToPLC_Flag.Adress = 2496;
  10855. writeToPLC_Flag.Value = (short)4;
  10856. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10857. string str = ex.StackTrace;
  10858. AddMessage_Station(stationNameStr, LogType.Error,
  10859. $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10860. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10861. }
  10862. stopwatch1.Stop();
  10863. AddMessage(LogType.Info,
  10864. stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10865. stopwatch2.ElapsedMilliseconds + "ms");
  10866. }
  10867. // 上次采集到的SN
  10868. //private string sn_S4_4出站接口 = string.Empty;
  10869. /// <summary>
  10870. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  10871. /// </summary>
  10872. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  10873. {
  10874. Stopwatch stopwatch1 = new Stopwatch();
  10875. Stopwatch stopwatch2 = new Stopwatch();
  10876. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10877. string stationNameStr = stationCode + stationName;
  10878. string processItem = stationName; // 测试项目
  10879. try
  10880. {
  10881. stopwatch1.Start();
  10882. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10883. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10884. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10885. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10886. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10887. sn = sn.Replace("\0", "");
  10888. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10889. bool isPass = d4Result == 1; // 产品结果 bool
  10890. #region 查询15个载具码
  10891. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10892. string vehicleData = string.Empty;
  10893. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10894. if (string.IsNullOrEmpty(vehicleData))
  10895. vehicleData = "";
  10896. if (snResult1 != 0)
  10897. {
  10898. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10899. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10900. writeToPLC_Flag1.Adress = 2496;
  10901. writeToPLC_Flag1.Value = (short)4;
  10902. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10903. stopwatch1.Stop();
  10904. AddMessage(LogType.Info,
  10905. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10906. return;
  10907. }
  10908. string[] cavitySNs = vehicleData.Split('.');
  10909. if (cavitySNs != null && cavitySNs.Length > 0)
  10910. {
  10911. for (int i = 0; i < cavitySNs.Length; i++)
  10912. {
  10913. if (string.IsNullOrEmpty(cavitySNs[i]))
  10914. vehicleCodes.Add("");
  10915. else
  10916. vehicleCodes.Add(cavitySNs[i]);
  10917. }
  10918. }
  10919. #endregion 查询15个载具码
  10920. // 统一查 产品SN列表
  10921. List<string> partNos = new List<string>();
  10922. foreach (string vehicleCode in vehicleCodes)
  10923. {
  10924. if (string.IsNullOrEmpty(vehicleCode))
  10925. partNos.Add("");
  10926. else
  10927. {
  10928. string partNo = "";
  10929. #region 查询载具上的产品信息
  10930. string cavityData = string.Empty;
  10931. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10932. if (string.IsNullOrEmpty(cavityData))
  10933. cavityData = "";
  10934. if (snResult != 0)
  10935. {
  10936. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10937. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10938. writeToPLC_Flag1.Adress = 2496;
  10939. writeToPLC_Flag1.Value = (short)4;
  10940. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10941. stopwatch1.Stop();
  10942. AddMessage(LogType.Info,
  10943. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10944. "ms");
  10945. return;
  10946. }
  10947. string[] partSNs = cavityData.Split('.');
  10948. if (partSNs != null && partSNs.Length >= 1)
  10949. partNo = partSNs[0];
  10950. #endregion 查询载具上的产品信息
  10951. partNos.Add(partNo);
  10952. }
  10953. }
  10954. // 调用MES出站
  10955. stopwatch2.Start();
  10956. // 统一上传
  10957. List<int> results = new List<int>();
  10958. for (int i = 0; i < partNos.Count; i++)
  10959. {
  10960. string index = (i + 1).ToString(); // 弹夹穴号
  10961. if (string.IsNullOrEmpty(partNos[i]))
  10962. results.Add(1);
  10963. else
  10964. {
  10965. List<TestItem> items1 = new List<TestItem>();
  10966. items1.Add(new TestItem()
  10967. {
  10968. Parameter_name = "弹夹码",
  10969. Parameter_value = sn,
  10970. Parameter_unit = ""
  10971. });
  10972. items1.Add(new TestItem()
  10973. {
  10974. Parameter_name = "弹夹穴号",
  10975. Parameter_value = index,
  10976. Parameter_unit = ""
  10977. });
  10978. items1.Add(new TestItem()
  10979. {
  10980. Parameter_name = "载具码",
  10981. Parameter_value = vehicleCodes[i],
  10982. Parameter_unit = ""
  10983. });
  10984. items1.Add(new TestItem()
  10985. {
  10986. Parameter_name = "载具穴号",
  10987. Parameter_value = "1",
  10988. Parameter_unit = ""
  10989. });
  10990. items1.Add(new TestItem()
  10991. {
  10992. Parameter_name = "产品结果",
  10993. Parameter_value = d4Result == 1 ? "OK" : "NG",
  10994. Parameter_unit = ""
  10995. });
  10996. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10997. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10998. results.Add(result1);
  10999. }
  11000. }
  11001. short result = 0;
  11002. if (results.All(a => a == 1))
  11003. result = 1;
  11004. else if (results.Contains(3))
  11005. result = 3;
  11006. else if (results.Contains(2))
  11007. result = 2;
  11008. else if (results.Contains(4))
  11009. result = 4;
  11010. else
  11011. result = 4;
  11012. stopwatch2.Stop();
  11013. // MES_Flag 为4MES报错
  11014. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11015. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11016. writeToPLC_Flag.Name = "d4MES_FLAG";
  11017. writeToPLC_Flag.Adress = 2496;
  11018. writeToPLC_Flag.Value = result;
  11019. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  11020. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  11021. }
  11022. catch (Exception ex)
  11023. {
  11024. stopwatch2.Restart();
  11025. // MES_Flag 为4上位机报错
  11026. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  11027. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11028. writeToPLC_Flag.Name = "d4MES_FLAG";
  11029. writeToPLC_Flag.Adress = 2496;
  11030. writeToPLC_Flag.Value = (short)4;
  11031. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  11032. string str = ex.StackTrace;
  11033. AddMessage_Station(stationNameStr, LogType.Error,
  11034. $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11035. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11036. stopwatch2.Stop();
  11037. }
  11038. stopwatch1.Stop();
  11039. AddMessage(LogType.Info,
  11040. stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11041. stopwatch2.ElapsedMilliseconds + "ms");
  11042. }
  11043. /// <summary>
  11044. /// [S4] 取放桁架 - S4_5弹夹扫码
  11045. /// </summary>
  11046. /// <param name="plcNo">PLC编号</param>
  11047. /// <param name="stationNameStr">工站全称</param>
  11048. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  11049. {
  11050. Stopwatch stopwatch1 = new Stopwatch();
  11051. Stopwatch stopwatch2 = new Stopwatch();
  11052. try
  11053. {
  11054. stopwatch1.Start();
  11055. // ZS 弹夹扫码
  11056. string d5BulletclipCode = " "; // 扫到的码
  11057. short d5BulletclipScanCode = 2;
  11058. stopwatch2.Start();
  11059. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  11060. //// MES_Flag
  11061. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  11062. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11063. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  11064. writeToPLC_Flag.Adress = 2528;
  11065. writeToPLC_Flag.Value = d5BulletclipScanCode;
  11066. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11067. {
  11068. Name = "d5BulletclipCode",
  11069. Adress = 2529,
  11070. ValueType = PLCValueType.String,
  11071. ValueTypeStrLength = 20,
  11072. Value = d5BulletclipCode
  11073. });
  11074. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  11075. stopwatch2.Stop();
  11076. }
  11077. catch (Exception ex)
  11078. {
  11079. string str = ex.StackTrace;
  11080. AddMessage_Station(stationNameStr, LogType.Error,
  11081. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  11082. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11083. stopwatch2.Start();
  11084. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  11085. //// MES_Flag
  11086. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  11087. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11088. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  11089. writeToPLC_Flag.Adress = 2528;
  11090. writeToPLC_Flag.Value = (short)6;
  11091. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11092. {
  11093. Name = "d5BulletclipCode",
  11094. Adress = 2529,
  11095. ValueType = PLCValueType.String,
  11096. ValueTypeStrLength = 20,
  11097. Value = " "
  11098. });
  11099. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  11100. stopwatch2.Stop();
  11101. }
  11102. stopwatch1.Stop();
  11103. AddMessage(LogType.Info,
  11104. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11105. stopwatch2.ElapsedMilliseconds + "ms");
  11106. }
  11107. /// <summary>
  11108. /// [S4] 取放桁架 - S4_5载具扫码
  11109. /// </summary>
  11110. /// <param name="plcNo">PLC编号</param>
  11111. /// <param name="stationNameStr">工站全称</param>
  11112. private void S4_5载具扫码(int plcNo, string stationNameStr)
  11113. {
  11114. Stopwatch stopwatch1 = new Stopwatch();
  11115. Stopwatch stopwatch2 = new Stopwatch();
  11116. try
  11117. {
  11118. stopwatch1.Start();
  11119. // ZS 载具扫码
  11120. string d5VehicleCode = " "; // 扫到的码
  11121. short d5VehicleScanCode = 2;
  11122. #region 进站
  11123. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  11124. {
  11125. // 查产品SN
  11126. #region 查询载具上的产品信息
  11127. string cavityData = string.Empty;
  11128. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  11129. if (string.IsNullOrEmpty(cavityData))
  11130. cavityData = "";
  11131. if (snResult != 0)
  11132. {
  11133. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11134. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  11135. writeToPLC_Flag1.Adress = 2559;
  11136. writeToPLC_Flag1.Value = (short)6;
  11137. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11138. {
  11139. Name = "d5VehicleCode",
  11140. Adress = 2560,
  11141. ValueType = PLCValueType.String,
  11142. ValueTypeStrLength = 20,
  11143. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  11144. });
  11145. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  11146. stopwatch1.Stop();
  11147. AddMessage(LogType.Info,
  11148. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11149. "ms");
  11150. return;
  11151. }
  11152. string[] cavitySNs = cavityData.Split('.');
  11153. string partNo = "";
  11154. if (cavitySNs != null && cavitySNs.Length >= 1)
  11155. {
  11156. partNo = cavitySNs[0];
  11157. }
  11158. #endregion 查询载具上的产品信息
  11159. List<TestItem> item = new List<TestItem>();
  11160. item.Add(new TestItem()
  11161. {
  11162. Parameter_name = "载具码",
  11163. Parameter_value = d5VehicleCode,
  11164. });
  11165. item.Add(new TestItem()
  11166. {
  11167. Parameter_name = "载具穴号",
  11168. Parameter_value = "1",
  11169. });
  11170. stopwatch2.Start();
  11171. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11172. partNo, item, out string errorMsg);
  11173. stopwatch2.Stop();
  11174. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  11175. }
  11176. #endregion 进站
  11177. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  11178. //// MES_Flag
  11179. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  11180. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11181. writeToPLC_Flag.Name = "d5VehicleScanCode";
  11182. writeToPLC_Flag.Adress = 2559;
  11183. writeToPLC_Flag.Value = d5VehicleScanCode;
  11184. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11185. {
  11186. Name = "d5VehicleCode",
  11187. Adress = 2560,
  11188. ValueType = PLCValueType.String,
  11189. ValueTypeStrLength = 20,
  11190. Value = d5VehicleCode
  11191. });
  11192. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  11193. }
  11194. catch (Exception ex)
  11195. {
  11196. string str = ex.StackTrace;
  11197. AddMessage_Station(stationNameStr, LogType.Error,
  11198. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  11199. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11200. stopwatch2.Start();
  11201. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  11202. //// MES_Flag
  11203. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  11204. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11205. writeToPLC_Flag.Name = "d5VehicleScanCode";
  11206. writeToPLC_Flag.Adress = 2559;
  11207. writeToPLC_Flag.Value = (short)6;
  11208. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11209. {
  11210. Name = "d5VehicleCode",
  11211. Adress = 2560,
  11212. ValueType = PLCValueType.String,
  11213. ValueTypeStrLength = 20,
  11214. Value = " "
  11215. });
  11216. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  11217. stopwatch2.Stop();
  11218. }
  11219. stopwatch1.Stop();
  11220. AddMessage(LogType.Info,
  11221. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11222. stopwatch2.ElapsedMilliseconds + "ms");
  11223. }
  11224. // 上次采集到的SN
  11225. //private string sn_S4_5出站接口 = string.Empty;
  11226. /// <summary>
  11227. /// [S4] 取放桁架 - S4_5出站接口
  11228. /// </summary>
  11229. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  11230. {
  11231. Stopwatch stopwatch1 = new Stopwatch();
  11232. Stopwatch stopwatch2 = new Stopwatch();
  11233. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11234. string stationNameStr = stationCode + stationName;
  11235. string processItem = stationName; // 测试项目
  11236. try
  11237. {
  11238. stopwatch1.Start();
  11239. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11240. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11241. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11242. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11243. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  11244. sn = sn.Replace("\0", "");
  11245. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  11246. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  11247. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  11248. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  11249. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  11250. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  11251. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  11252. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  11253. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  11254. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  11255. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  11256. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  11257. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  11258. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  11259. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  11260. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  11261. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  11262. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  11263. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  11264. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  11265. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  11266. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  11267. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  11268. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  11269. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  11270. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  11271. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  11272. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  11273. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  11274. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  11275. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  11276. bool pass = d5Result == 1;
  11277. // 存 载具SN列表
  11278. List<string> vehicleCodes = new List<string>()
  11279. {
  11280. d5VehicleCode1, d5VehicleCode2, d5VehicleCode3, d5VehicleCode4, d5VehicleCode5,
  11281. d5VehicleCode6, d5VehicleCode7, d5VehicleCode8, d5VehicleCode9, d5VehicleCode10,
  11282. d5VehicleCode11, d5VehicleCode12, d5VehicleCode13, d5VehicleCode14, d5VehicleCode15
  11283. };
  11284. // 统一查 产品SN列表
  11285. List<string> partNos = new List<string>();
  11286. foreach (string vehicleCode in vehicleCodes)
  11287. {
  11288. if (string.IsNullOrEmpty(vehicleCode))
  11289. partNos.Add("");
  11290. else
  11291. {
  11292. string partNo = "";
  11293. #region 查询载具上的产品信息
  11294. string cavityData = string.Empty;
  11295. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11296. if (string.IsNullOrEmpty(cavityData))
  11297. cavityData = "";
  11298. if (snResult != 0)
  11299. {
  11300. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11301. writeToPLC_Flag1.Name = "d5MES_FLAG";
  11302. writeToPLC_Flag1.Adress = 2591;
  11303. writeToPLC_Flag1.Value = (short)4;
  11304. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  11305. stopwatch1.Stop();
  11306. AddMessage(LogType.Info,
  11307. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11308. "ms");
  11309. return;
  11310. }
  11311. string[] cavitySNs = cavityData.Split('.');
  11312. if (cavitySNs != null && cavitySNs.Length >= 1)
  11313. partNo = cavitySNs[0];
  11314. #endregion 查询载具上的产品信息
  11315. partNos.Add(partNo);
  11316. }
  11317. }
  11318. // 统一上传
  11319. stopwatch2.Start();
  11320. List<int> results = new List<int>();
  11321. for (int i = 0; i < partNos.Count; i++)
  11322. {
  11323. string index = (i + 1).ToString(); // 弹夹穴号
  11324. if (string.IsNullOrEmpty(partNos[i]))
  11325. results.Add(1);
  11326. else
  11327. {
  11328. List<TestItem> items1 = new List<TestItem>();
  11329. items1.Add(new TestItem()
  11330. {
  11331. Parameter_name = "弹夹码",
  11332. Parameter_value = sn,
  11333. Parameter_unit = ""
  11334. });
  11335. items1.Add(new TestItem()
  11336. {
  11337. Parameter_name = "弹夹穴号",
  11338. Parameter_value = index,
  11339. Parameter_unit = ""
  11340. });
  11341. items1.Add(new TestItem()
  11342. {
  11343. Parameter_name = "载具码",
  11344. Parameter_value = vehicleCodes[i],
  11345. Parameter_unit = ""
  11346. });
  11347. items1.Add(new TestItem()
  11348. {
  11349. Parameter_name = "载具穴号",
  11350. Parameter_value = "1",
  11351. Parameter_unit = ""
  11352. });
  11353. items1.Add(new TestItem()
  11354. {
  11355. Parameter_name = "产品结果",
  11356. Parameter_value = d5Result == 1 ? "OK" : "NG",
  11357. Parameter_unit = ""
  11358. });
  11359. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11360. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  11361. results.Add(result1);
  11362. }
  11363. }
  11364. short result = 0;
  11365. if (results.All(a => a == 1))
  11366. result = 1;
  11367. else if (results.Contains(3))
  11368. result = 3;
  11369. else if (results.Contains(2))
  11370. result = 2;
  11371. else if (results.Contains(4))
  11372. result = 4;
  11373. else
  11374. result = 4;
  11375. stopwatch2.Stop();
  11376. #region 存储绑定数据到 边线MES系统中
  11377. if (result == 1)
  11378. {
  11379. // 删除绑定信息
  11380. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11381. if (resultMesR != 0)
  11382. {
  11383. result = 4;
  11384. AddMessage_Station(stationNameStr, LogType.Error,
  11385. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11386. }
  11387. }
  11388. #endregion 存储绑定数据到 边线MES系统中
  11389. // MES_Flag 为4MES报错
  11390. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11391. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11392. writeToPLC_Flag.Name = "d5MES_FLAG";
  11393. writeToPLC_Flag.Adress = 2591;
  11394. writeToPLC_Flag.Value = result;
  11395. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11396. OnMessage(LogType.Debug,
  11397. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11398. }
  11399. catch (Exception ex)
  11400. {
  11401. stopwatch2.Restart();
  11402. // MES_Flag 为4上位机报错
  11403. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  11404. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11405. writeToPLC_Flag.Name = "d5MES_FLAG";
  11406. writeToPLC_Flag.Adress = 2591;
  11407. writeToPLC_Flag.Value = (short)4;
  11408. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11409. stopwatch2.Stop();
  11410. string str = ex.StackTrace;
  11411. AddMessage_Station(stationNameStr, LogType.Error,
  11412. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11413. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11414. }
  11415. stopwatch1.Stop();
  11416. AddMessage(LogType.Info,
  11417. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11418. stopwatch2.ElapsedMilliseconds + "ms");
  11419. }
  11420. /// <summary>
  11421. /// [S4] 取放桁架 - S4_5节拍接口
  11422. /// </summary>
  11423. /// <param name="plcNo">PLC编号</param>
  11424. /// <param name="stationNameStr">工站全称</param>
  11425. private void S4_5节拍接口(int plcNo, string stationNameStr)
  11426. {
  11427. Stopwatch stopwatch1 = new Stopwatch();
  11428. Stopwatch stopwatch2 = new Stopwatch();
  11429. string resultStr = string.Empty;
  11430. try
  11431. {
  11432. stopwatch1.Start();
  11433. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  11434. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  11435. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  11436. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11437. if (!actionBool)
  11438. {
  11439. stopwatch2.Start();
  11440. // MES_Flag
  11441. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  11442. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11443. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11444. writeToPLC_Flag1.Adress = 2924;
  11445. writeToPLC_Flag1.Value = (short)4;
  11446. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11447. stopwatch2.Stop();
  11448. AddMessage(LogType.Info,
  11449. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11450. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11451. return;
  11452. }
  11453. string d5OEEPartNo = string.Empty; // 物料码
  11454. if (string.IsNullOrEmpty(d5OEEProductSN))
  11455. {
  11456. stopwatch2.Start();
  11457. // MES_Flag
  11458. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11459. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11460. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11461. writeToPLC_Flag1.Adress = 2924;
  11462. writeToPLC_Flag1.Value = (short)1;
  11463. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11464. stopwatch2.Stop();
  11465. AddMessage(LogType.Info,
  11466. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11467. stopwatch2.ElapsedMilliseconds + "ms");
  11468. return;
  11469. }
  11470. else
  11471. {
  11472. // 查产品SN
  11473. d5OEEPartNo = "Test"; // ZS
  11474. }
  11475. short d5OEEMES_FLAG = 0;
  11476. // 上传OEE
  11477. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  11478. d5OEEMES_FLAG = result.Item1;
  11479. resultStr = result.Item2;
  11480. stopwatch2.Start();
  11481. // MES_Flag
  11482. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11483. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11484. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11485. writeToPLC_Flag.Adress = 2924;
  11486. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  11487. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11488. stopwatch2.Stop();
  11489. }
  11490. catch (Exception ex)
  11491. {
  11492. string str = ex.StackTrace;
  11493. AddMessage_Station(stationNameStr, LogType.Error,
  11494. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11495. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11496. // MES_Flag
  11497. stopwatch2.Start();
  11498. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  11499. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11500. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11501. writeToPLC_Flag.Adress = 2924;
  11502. writeToPLC_Flag.Value = (short)4;
  11503. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11504. stopwatch2.Stop();
  11505. }
  11506. stopwatch1.Stop();
  11507. AddMessage(LogType.Info,
  11508. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11509. stopwatch2.ElapsedMilliseconds + "ms");
  11510. }
  11511. #endregion [S4] 取放桁架
  11512. #endregion PLC4 刘果段
  11513. #region PLC5 张超凡
  11514. #region [S5] Tray盘下料装备
  11515. /// <summary>
  11516. /// S5工位的数据- 触发信号上次的值
  11517. /// </summary>
  11518. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  11519. /// <summary>
  11520. /// S5工位的数据(含触发信号)
  11521. /// </summary>
  11522. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  11523. /// <summary>
  11524. /// S5工位的数据- 回写点位
  11525. /// </summary>
  11526. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  11527. /// <summary>
  11528. /// [S5] Tray盘下料装备
  11529. /// </summary>
  11530. /// <param name="plcNo">PLC编号</param>
  11531. //private void ReadStation_S5(int plcNo)
  11532. //{
  11533. // // [S1] Tray盘上料装备
  11534. // // [S2] FCT
  11535. // // [S3] 值板机
  11536. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  11537. // // [S5] Tray盘下料装备
  11538. // /// 上位机心跳
  11539. // /// 获取设备报警数据与状态信息
  11540. // string stationCode = "[S5]";
  11541. // string stationName = "Tray盘下料装备";
  11542. // string stationNameStr = stationCode + stationName;
  11543. // #region 创建字典
  11544. // // 触发信号字典 赋值
  11545. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11546. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11547. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11548. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11549. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  11550. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11551. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  11552. // // PLC数据字典 赋值
  11553. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11554. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  11555. // s5PLCData.Add("e1ProductSN_Check", ""); //
  11556. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11557. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  11558. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  11559. // s5PLCData.Add("e1PartNo", ""); // 物料码
  11560. // s5PLCData.Add("e1Result", 0); // 产品结果
  11561. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11562. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  11563. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  11564. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  11565. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11566. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  11567. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  11568. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11569. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  11570. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  11571. // #endregion 创建字典
  11572. // while (IsRun)
  11573. // {
  11574. // try
  11575. // {
  11576. // if (!GlobalContext._IsCon_Funs5)
  11577. // {
  11578. // UpdatePLCMonitor(1, plcNo, 0);
  11579. // continue;
  11580. // }
  11581. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  11582. // {
  11583. // Stopwatch stopwatch1 = new Stopwatch();
  11584. // Stopwatch stopwatch2 = new Stopwatch();
  11585. // stopwatch1.Start();
  11586. // stopwatch2.Start();
  11587. // #region 一次性读取所有数据
  11588. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  11589. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  11590. // int[] datas = data1.Concat(data2).ToArray();
  11591. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  11592. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  11593. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  11594. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  11595. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  11596. // s5PLCData["e1MES_FLAG"] = datas[35];
  11597. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  11598. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  11599. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  11600. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  11601. // s5PLCData["e1Result"] = datas[76];
  11602. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  11603. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  11604. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  11605. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  11606. // s5PLCData["e1OEEType"] = datas[109];
  11607. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  11608. // s5PLCData["e1AGVUpStart"] = datas[121];
  11609. // s5PLCData["e1AGVUpEnd"] = datas[122];
  11610. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  11611. // s5PLCData["e1AGVDownStart"] = datas[134];
  11612. // s5PLCData["e1AGVDownEnd"] = datas[135];
  11613. // #endregion 一次性读取所有数据
  11614. // stopwatch2.Stop();
  11615. // #region 回写操作,写后清空flag
  11616. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  11617. // #endregion 回写操作,写后清空flag
  11618. // #region 进站校验
  11619. // try
  11620. // {
  11621. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  11622. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  11623. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  11624. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  11625. // {
  11626. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  11627. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  11628. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  11629. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  11630. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  11631. // }
  11632. // }
  11633. // catch (Exception ex)
  11634. // {
  11635. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11636. // string str = ex.StackTrace;
  11637. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11638. // }
  11639. // #endregion 进站校验
  11640. // #region 出站接口
  11641. // try
  11642. // {
  11643. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  11644. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  11645. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  11646. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  11647. // {
  11648. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  11649. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  11650. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  11651. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  11652. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  11653. // }
  11654. // }
  11655. // catch (Exception ex)
  11656. // {
  11657. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  11658. // string str = ex.StackTrace;
  11659. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11660. // }
  11661. // #endregion 出站接口
  11662. // #region 节拍接口
  11663. // try
  11664. // {
  11665. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  11666. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  11667. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  11668. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  11669. // {
  11670. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  11671. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  11672. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  11673. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  11674. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  11675. // }
  11676. // }
  11677. // catch (Exception ex)
  11678. // {
  11679. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11680. // string str = ex.StackTrace;
  11681. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11682. // }
  11683. // #endregion 节拍接口
  11684. // #region AGV上料
  11685. // // AGV上料叫AGV信号
  11686. // try
  11687. // {
  11688. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  11689. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  11690. // if (e1AGVUpCall != e1AGVUpCallOld)
  11691. // {
  11692. // if (e1AGVUpCall == 1) // 0->1
  11693. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  11694. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  11695. // }
  11696. // }
  11697. // catch (Exception ex)
  11698. // {
  11699. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11700. // string str = ex.StackTrace;
  11701. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11702. // }
  11703. // // AGV上料完成信号
  11704. // try
  11705. // {
  11706. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  11707. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  11708. // if (e1AGVUpEnd != e1AGVUpEndOld)
  11709. // {
  11710. // if (e1AGVUpEnd == 1) // 0->1
  11711. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  11712. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  11713. // }
  11714. // }
  11715. // catch (Exception ex)
  11716. // {
  11717. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  11718. // string str = ex.StackTrace;
  11719. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11720. // }
  11721. // #endregion AGV上料
  11722. // #region AGV下料
  11723. // // AGV下料叫agv信号
  11724. // try
  11725. // {
  11726. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  11727. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  11728. // if (e1AGVDownCall != e1AGVDownCallOld)
  11729. // {
  11730. // if (e1AGVDownCall == 1) // 0->1
  11731. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  11732. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  11733. // }
  11734. // }
  11735. // catch (Exception ex)
  11736. // {
  11737. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  11738. // string str = ex.StackTrace;
  11739. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11740. // }
  11741. // // AGV下料完成信号
  11742. // try
  11743. // {
  11744. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  11745. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  11746. // if (e1AGVDownEnd != e1AGVDownEndOld)
  11747. // {
  11748. // if (e1AGVDownEnd == 1) // 0->1
  11749. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  11750. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  11751. // }
  11752. // }
  11753. // catch (Exception ex)
  11754. // {
  11755. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  11756. // string str = ex.StackTrace;
  11757. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11758. // }
  11759. // #endregion AGV下料
  11760. // #region 心跳
  11761. // try
  11762. // {
  11763. // short states = 0;
  11764. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  11765. // }
  11766. // catch (Exception ex)
  11767. // {
  11768. // string str = ex.StackTrace;
  11769. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11770. // }
  11771. // #endregion 心跳
  11772. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  11773. // stopwatch1.Stop();
  11774. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  11775. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  11776. // }
  11777. // else
  11778. // {
  11779. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11780. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  11781. // Funs[plcNo].Connect();
  11782. // }
  11783. // }
  11784. // catch (Exception ex)
  11785. // {
  11786. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11787. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  11788. // Funs[plcNo].ReConnect();
  11789. // }
  11790. // Thread.Sleep(IntervalReadPLC);
  11791. // }
  11792. //}
  11793. /// <summary>
  11794. /// [S5] Tray盘下料装备 - 进站校验
  11795. /// </summary>
  11796. /// <param name="plcNo">PLC编号</param>
  11797. /// <param name="stationNameStr">工站全称</param>
  11798. private void S5进站校验(int plcNo, string stationNameStr)
  11799. {
  11800. Stopwatch stopwatch1 = new Stopwatch();
  11801. Stopwatch stopwatch2 = new Stopwatch();
  11802. try
  11803. {
  11804. stopwatch1.Start();
  11805. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  11806. sn = sn.Replace("\0", "");
  11807. // 获取产品SN By 载具码
  11808. #region 查询载具上的产品信息
  11809. string cavityData = string.Empty;
  11810. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11811. if (string.IsNullOrEmpty(cavityData))
  11812. cavityData = "";
  11813. if (snResult != 0)
  11814. {
  11815. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11816. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  11817. writeToPLC_Flag1.Adress = 2003;
  11818. writeToPLC_Flag1.Value = (short)6;
  11819. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  11820. stopwatch1.Stop();
  11821. AddMessage(LogType.Info,
  11822. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11823. return;
  11824. }
  11825. string[] cavitySNs = cavityData.Split('.');
  11826. string partNo = string.Empty;
  11827. if (cavitySNs != null && cavitySNs.Length >= 1)
  11828. partNo = cavitySNs[0];
  11829. #endregion 查询载具上的产品信息
  11830. // 产品SN(物料码)校验
  11831. List<TestItem> item = new List<TestItem>();
  11832. item.Add(new TestItem()
  11833. {
  11834. Parameter_name = "载具码",
  11835. Parameter_value = sn,
  11836. });
  11837. item.Add(new TestItem()
  11838. {
  11839. Parameter_name = "载具穴号",
  11840. Parameter_value = "1",
  11841. });
  11842. stopwatch2.Start();
  11843. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11844. partNo, item, out string errorMsg);
  11845. stopwatch2.Stop();
  11846. short e1MES_FLAG_Check = (short)result;
  11847. // MES_Flag
  11848. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  11849. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11850. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11851. writeToPLC_Flag.Adress = 2003;
  11852. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  11853. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11854. }
  11855. catch (Exception ex)
  11856. {
  11857. string str = ex.StackTrace;
  11858. AddMessage_Station(stationNameStr, LogType.Error,
  11859. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  11860. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11861. // MES_Flag
  11862. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11863. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11864. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11865. writeToPLC_Flag.Adress = 2003;
  11866. writeToPLC_Flag.Value = (short)6;
  11867. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11868. }
  11869. stopwatch1.Stop();
  11870. AddMessage(LogType.Info,
  11871. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  11872. stopwatch2.ElapsedMilliseconds + "ms");
  11873. }
  11874. /// <summary>
  11875. /// [S5] Tray盘下料装备 - 出站接口
  11876. /// </summary>
  11877. /// <param name="plcNo"></param>
  11878. /// <param name="stationCode"></param>
  11879. /// <param name="stationName"></param>
  11880. private void S5出站接口(int plcNo, string stationCode, string stationName)
  11881. {
  11882. Stopwatch stopwatch1 = new Stopwatch();
  11883. Stopwatch stopwatch2 = new Stopwatch();
  11884. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11885. string stationNameStr = stationCode + stationName;
  11886. string processItem = stationName; // 测试项目
  11887. try
  11888. {
  11889. stopwatch1.Start();
  11890. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11891. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11892. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11893. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11894. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  11895. sn = sn.Replace("\0", "");
  11896. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  11897. //partNo = partNo.Replace("\0", "");
  11898. #region 查询载具上的产品信息
  11899. string cavityData = string.Empty;
  11900. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11901. if (string.IsNullOrEmpty(cavityData))
  11902. cavityData = "";
  11903. if (snResult != 0)
  11904. {
  11905. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11906. writeToPLC_Flag1.Name = "e1MES_FLAG";
  11907. writeToPLC_Flag1.Adress = 2035;
  11908. writeToPLC_Flag1.Value = (short)4;
  11909. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  11910. stopwatch1.Stop();
  11911. AddMessage(LogType.Info,
  11912. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11913. return;
  11914. }
  11915. string[] cavitySNs = cavityData.Split('.');
  11916. string partNo = string.Empty;
  11917. if (cavitySNs != null && cavitySNs.Length >= 1)
  11918. partNo = cavitySNs[0];
  11919. #endregion 查询载具上的产品信息
  11920. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  11921. bool pass = e1Result == 1;
  11922. stopwatch2.Start();
  11923. // 上传MES
  11924. List<TestItem> items = new List<TestItem>();
  11925. items.Add(new TestItem()
  11926. {
  11927. Parameter_name = "载具码",
  11928. Parameter_value = sn,
  11929. Parameter_unit = ""
  11930. });
  11931. items.Add(new TestItem()
  11932. {
  11933. Parameter_name = "载具穴号",
  11934. Parameter_value = "1",
  11935. Parameter_unit = ""
  11936. });
  11937. items.Add(new TestItem()
  11938. {
  11939. Parameter_name = "产品结果",
  11940. Parameter_value = e1Result == 1 ? "OK" : "NG",
  11941. Parameter_unit = ""
  11942. });
  11943. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  11944. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  11945. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  11946. short result = result1 == 1 ? (short)1 : (short)3;
  11947. stopwatch2.Stop();
  11948. #region 存储绑定数据到 边线MES系统中
  11949. if (result == 1)
  11950. {
  11951. // 删除绑定信息
  11952. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11953. if (resultMesR != 0)
  11954. {
  11955. result = 4;
  11956. AddMessage_Station(stationNameStr, LogType.Error,
  11957. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11958. }
  11959. }
  11960. #endregion 存储绑定数据到 边线MES系统中
  11961. // MES_Flag 为MES报错
  11962. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11963. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  11964. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11965. writeToPLC_Flag.Name = "e1MES_FLAG";
  11966. writeToPLC_Flag.Adress = 2035;
  11967. writeToPLC_Flag.Value = result;
  11968. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11969. OnMessage(LogType.Debug,
  11970. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11971. }
  11972. catch (Exception ex)
  11973. {
  11974. stopwatch2.Restart();
  11975. // MES_Flag 为4上位机报错
  11976. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  11977. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11978. writeToPLC_Flag.Name = "e1MES_FLAG";
  11979. writeToPLC_Flag.Adress = 2035;
  11980. writeToPLC_Flag.Value = (short)4;
  11981. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11982. stopwatch2.Stop();
  11983. string str = ex.StackTrace;
  11984. AddMessage_Station(stationNameStr, LogType.Error,
  11985. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11986. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11987. }
  11988. stopwatch1.Stop();
  11989. AddMessage(LogType.Info,
  11990. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11991. stopwatch2.ElapsedMilliseconds + "ms");
  11992. }
  11993. /// <summary>
  11994. /// [S5] Tray盘下料装备 - 节拍接口
  11995. /// </summary>
  11996. /// <param name="plcNo">PLC编号</param>
  11997. /// <param name="stationNameStr">工站全称</param>
  11998. //private void S5节拍接口(int plcNo, string stationNameStr)
  11999. //{
  12000. // Stopwatch stopwatch1 = new Stopwatch();
  12001. // Stopwatch stopwatch2 = new Stopwatch();
  12002. // string resultStr = string.Empty;
  12003. // try
  12004. // {
  12005. // stopwatch1.Start();
  12006. // string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  12007. // string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  12008. // e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  12009. // bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  12010. // if (!actionBool)
  12011. // {
  12012. // stopwatch2.Start();
  12013. // // MES_Flag
  12014. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12015. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12016. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  12017. // writeToPLC_Flag1.Adress = 2088;
  12018. // writeToPLC_Flag1.Value = (short)4;
  12019. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  12020. // stopwatch2.Stop();
  12021. // AddMessage(LogType.Info,
  12022. // stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  12023. // "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  12024. // return;
  12025. // }
  12026. // string e1OEEPartNo = string.Empty; // 物料码
  12027. // if (string.IsNullOrEmpty(e1OEEProductSN))
  12028. // {
  12029. // stopwatch2.Start();
  12030. // // MES_Flag
  12031. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12032. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12033. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  12034. // writeToPLC_Flag1.Adress = 2088;
  12035. // writeToPLC_Flag1.Value = (short)1;
  12036. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  12037. // stopwatch2.Stop();
  12038. // AddMessage(LogType.Info,
  12039. // stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12040. // stopwatch2.ElapsedMilliseconds + "ms");
  12041. // return;
  12042. // }
  12043. // else
  12044. // {
  12045. // // 查产品SN
  12046. // e1OEEPartNo = "Test"; // ZS
  12047. // }
  12048. // short e1OEEMES_FLAG = 0;
  12049. // // 上传OEE
  12050. // (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  12051. // e1OEEMES_FLAG = result.Item1;
  12052. // resultStr = result.Item2;
  12053. // stopwatch2.Start();
  12054. // // MES_Flag
  12055. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12056. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12057. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  12058. // writeToPLC_Flag.Adress = 2088;
  12059. // writeToPLC_Flag.Value = e1OEEMES_FLAG;
  12060. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  12061. // stopwatch2.Stop();
  12062. // }
  12063. // catch (Exception ex)
  12064. // {
  12065. // string str = ex.StackTrace;
  12066. // AddMessage_Station(stationNameStr, LogType.Error,
  12067. // $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  12068. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12069. // // MES_Flag
  12070. // stopwatch2.Start();
  12071. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  12072. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12073. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  12074. // writeToPLC_Flag.Adress = 2088;
  12075. // writeToPLC_Flag.Value = (short)4;
  12076. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  12077. // stopwatch2.Stop();
  12078. // }
  12079. // stopwatch1.Stop();
  12080. // AddMessage(LogType.Info,
  12081. // stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12082. // stopwatch2.ElapsedMilliseconds + "ms");
  12083. //}
  12084. /// <summary>
  12085. /// [S5] Tray盘下料装备 - AGV上料叫agv
  12086. /// </summary>
  12087. /// <param name="plcNo">PLC编号</param>
  12088. /// <param name="stationNameStr">工站全称</param>
  12089. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  12090. {
  12091. Stopwatch stopwatch1 = new Stopwatch();
  12092. Stopwatch stopwatch2 = new Stopwatch();
  12093. try
  12094. {
  12095. stopwatch1.Start();
  12096. // ZS 呼叫AGV
  12097. short e1AGVUpCall = 2;
  12098. stopwatch2.Start();
  12099. // e1AGVUpCall
  12100. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12101. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12102. writeToPLC_Flag.Name = "e1AGVUpCall";
  12103. writeToPLC_Flag.Adress = 2120;
  12104. writeToPLC_Flag.Value = e1AGVUpCall;
  12105. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  12106. stopwatch2.Stop();
  12107. }
  12108. catch (Exception ex)
  12109. {
  12110. string str = ex.StackTrace;
  12111. AddMessage_Station(stationNameStr, LogType.Error,
  12112. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  12113. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12114. // e1AGVUpCall
  12115. stopwatch2.Start();
  12116. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  12117. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12118. writeToPLC_Flag.Name = "e1AGVUpCall";
  12119. writeToPLC_Flag.Adress = 2120;
  12120. writeToPLC_Flag.Value = (short)4;
  12121. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  12122. stopwatch2.Stop();
  12123. }
  12124. stopwatch1.Stop();
  12125. AddMessage(LogType.Info,
  12126. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12127. stopwatch2.ElapsedMilliseconds + "ms");
  12128. }
  12129. /// <summary>
  12130. /// [S5] Tray盘下料装备 - AGV上料完成
  12131. /// </summary>
  12132. /// <param name="plcNo">PLC编号</param>
  12133. /// <param name="stationNameStr">工站全称</param>
  12134. private void S5AGV上料完成(int plcNo, string stationNameStr)
  12135. {
  12136. Stopwatch stopwatch1 = new Stopwatch();
  12137. Stopwatch stopwatch2 = new Stopwatch();
  12138. try
  12139. {
  12140. stopwatch1.Start();
  12141. // ZS AGV上料完成,让小车离开
  12142. short e1AGVUpEnd = 2;
  12143. stopwatch2.Start();
  12144. // e1AGVUpEnd
  12145. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12146. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12147. writeToPLC_Flag.Name = "e1AGVUpEnd";
  12148. writeToPLC_Flag.Adress = 2122;
  12149. writeToPLC_Flag.Value = e1AGVUpEnd;
  12150. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  12151. stopwatch2.Stop();
  12152. }
  12153. catch (Exception ex)
  12154. {
  12155. string str = ex.StackTrace;
  12156. AddMessage_Station(stationNameStr, LogType.Error,
  12157. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  12158. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12159. // e1AGVUpEnd
  12160. stopwatch2.Start();
  12161. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  12162. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12163. writeToPLC_Flag.Name = "e1AGVUpEnd";
  12164. writeToPLC_Flag.Adress = 2122;
  12165. writeToPLC_Flag.Value = (short)4;
  12166. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  12167. stopwatch2.Stop();
  12168. }
  12169. stopwatch1.Stop();
  12170. AddMessage(LogType.Info,
  12171. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12172. stopwatch2.ElapsedMilliseconds + "ms");
  12173. }
  12174. /// <summary>
  12175. /// [S5] Tray盘下料装备 - AGV下料叫agv
  12176. /// </summary>
  12177. /// <param name="plcNo">PLC编号</param>
  12178. /// <param name="stationNameStr">工站全称</param>
  12179. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  12180. {
  12181. Stopwatch stopwatch1 = new Stopwatch();
  12182. Stopwatch stopwatch2 = new Stopwatch();
  12183. try
  12184. {
  12185. stopwatch1.Start();
  12186. // ZS 呼叫AGV
  12187. short e1AGVDownCall = 2;
  12188. stopwatch2.Start();
  12189. // e1AGVDownCall
  12190. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12191. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12192. writeToPLC_Flag.Name = "e1AGVDownCall";
  12193. writeToPLC_Flag.Adress = 2133;
  12194. writeToPLC_Flag.Value = e1AGVDownCall;
  12195. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  12196. stopwatch2.Stop();
  12197. }
  12198. catch (Exception ex)
  12199. {
  12200. string str = ex.StackTrace;
  12201. AddMessage_Station(stationNameStr, LogType.Error,
  12202. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  12203. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12204. // e1AGVDownCall
  12205. stopwatch2.Start();
  12206. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  12207. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12208. writeToPLC_Flag.Name = "e1AGVDownCall";
  12209. writeToPLC_Flag.Adress = 2133;
  12210. writeToPLC_Flag.Value = (short)4;
  12211. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  12212. stopwatch2.Stop();
  12213. }
  12214. stopwatch1.Stop();
  12215. AddMessage(LogType.Info,
  12216. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12217. stopwatch2.ElapsedMilliseconds + "ms");
  12218. }
  12219. /// <summary>
  12220. /// [S5] Tray盘下料装备 - AGV下料完成
  12221. /// </summary>
  12222. /// <param name="plcNo">PLC编号</param>
  12223. /// <param name="stationNameStr">工站全称</param>
  12224. private void S5AGV下料完成(int plcNo, string stationNameStr)
  12225. {
  12226. Stopwatch stopwatch1 = new Stopwatch();
  12227. Stopwatch stopwatch2 = new Stopwatch();
  12228. try
  12229. {
  12230. stopwatch1.Start();
  12231. // ZS AGV上料完成,让小车离开
  12232. short e1AGVDownEnd = 2;
  12233. stopwatch2.Start();
  12234. // e1AGVDownEnd
  12235. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12236. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12237. writeToPLC_Flag.Name = "e1AGVDownEnd";
  12238. writeToPLC_Flag.Adress = 2135;
  12239. writeToPLC_Flag.Value = e1AGVDownEnd;
  12240. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  12241. stopwatch2.Stop();
  12242. }
  12243. catch (Exception ex)
  12244. {
  12245. string str = ex.StackTrace;
  12246. AddMessage_Station(stationNameStr, LogType.Error,
  12247. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  12248. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12249. // e1AGVDownEnd
  12250. stopwatch2.Start();
  12251. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  12252. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12253. writeToPLC_Flag.Name = "e1AGVDownEnd";
  12254. writeToPLC_Flag.Adress = 2135;
  12255. writeToPLC_Flag.Value = (short)4;
  12256. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  12257. stopwatch2.Stop();
  12258. }
  12259. stopwatch1.Stop();
  12260. AddMessage(LogType.Info,
  12261. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12262. stopwatch2.ElapsedMilliseconds + "ms");
  12263. }
  12264. #endregion [S5] Tray盘下料装备
  12265. #endregion PLC5 张超凡
  12266. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  12267. /// <summary>
  12268. /// PLC读取到的数据 -添加数据
  12269. /// </summary>
  12270. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  12271. {
  12272. if (sxPlcData.ContainsKey(newKey))
  12273. sxPlcData[newKey] = newValue;
  12274. else
  12275. sxPlcData.Add(newKey, newValue);
  12276. }
  12277. /// <summary>
  12278. /// PLC需要写入的数据 -添加数据
  12279. /// </summary>
  12280. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey,
  12281. WriteToPLC_Flag newValue)
  12282. {
  12283. if (sxPLCWriteData.ContainsKey(newKey))
  12284. sxPLCWriteData[newKey] = newValue;
  12285. else
  12286. sxPLCWriteData.Add(newKey, newValue);
  12287. }
  12288. /// <summary>
  12289. /// PLC回写操作,写后清空flag
  12290. /// </summary>
  12291. /// <param name="modbusClient">modbus对象</param>
  12292. /// <param name="pLCReadDatas">读取到的数据字典</param>
  12293. /// <param name="pLCWriteDatas">需要写入的数据</param>
  12294. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas,
  12295. ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  12296. {
  12297. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  12298. {
  12299. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  12300. for (int i = 0; i < pLCWriteDatas.Count; i++)
  12301. {
  12302. string mesFlagName = pLCWriteDatas[i].Name;
  12303. int mesFlagAdress = pLCWriteDatas[i].Adress;
  12304. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  12305. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  12306. {
  12307. // 先回写数据
  12308. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  12309. for (int j = 0; j < writeToPLCDatas.Count; j++)
  12310. {
  12311. int mesDataAdress = writeToPLCDatas[j].Adress;
  12312. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  12313. switch (mesDataType)
  12314. {
  12315. case PLCValueType.Short:
  12316. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  12317. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  12318. break;
  12319. case PLCValueType.String:
  12320. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  12321. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  12322. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr,
  12323. mesDataValueStrLength);
  12324. break;
  12325. }
  12326. }
  12327. // 再回写信号
  12328. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  12329. // 存储读取数据的字典
  12330. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  12331. // 存储写入数据的字典 - 清空写入值
  12332. pLCWriteDatas[i].Value = (short)0;
  12333. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  12334. }
  12335. }
  12336. }
  12337. }
  12338. /// <summary>
  12339. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  12340. /// </summary>
  12341. /// <param name="no">3</param>
  12342. /// <param name="stationCode">设备编号</param>
  12343. /// <param name="stationNameStr">设备名称</param>
  12344. /// <param name="plcOrder">车间订单号</param>
  12345. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  12346. {
  12347. try
  12348. {
  12349. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  12350. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  12351. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  12352. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  12353. int result1 = 0;
  12354. switch (stationCode)
  12355. {
  12356. case 2:
  12357. case 3:
  12358. case 4:
  12359. case 6:
  12360. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  12361. break;
  12362. case 102:
  12363. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  12364. break;
  12365. case 103:
  12366. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  12367. break;
  12368. case 104:
  12369. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  12370. break;
  12371. case 106:
  12372. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  12373. break;
  12374. default:
  12375. // MES_Flag 为“6未找到正确设备编号”
  12376. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  12377. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  12378. return;
  12379. }
  12380. short result = result1 == 1 ? (short)1 : (short)2;
  12381. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  12382. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  12383. }
  12384. catch (Exception ex)
  12385. {
  12386. // MES_Flag 为2上位机报错
  12387. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  12388. string str = ex.StackTrace;
  12389. AddMessage_Station(stationNameStr, LogType.Error,
  12390. $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  12391. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12392. }
  12393. }
  12394. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  12395. #region UI刷新
  12396. /// <summary>
  12397. /// 更新商品信息的UI + 下发产品信息(SN)
  12398. /// </summary>
  12399. private void UpdateProductInfo()
  12400. {
  12401. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  12402. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  12403. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  12404. //txt_CurSupplierCode.Text = ""; // 供应商代号
  12405. }
  12406. /// <summary>
  12407. /// 更新PLC连接状态的UI
  12408. /// </summary>
  12409. /// <param name="no">PLC编号</param>
  12410. /// <param name="status">状态</param>
  12411. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  12412. {
  12413. if (this != null && !this.IsDisposed)
  12414. {
  12415. switch (imgNo)
  12416. {
  12417. case 1:
  12418. this.BeginInvoke(new Action(() => { picPLC.Image = imageListState.Images[status]; }));
  12419. break;
  12420. case 2:
  12421. this.BeginInvoke(new Action(() => { pictureBox2.Image = imageListState.Images[status]; }));
  12422. break;
  12423. case 3:
  12424. this.BeginInvoke(new Action(() => { pictureBox3.Image = imageListState.Images[status]; }));
  12425. break;
  12426. case 4:
  12427. this.BeginInvoke(new Action(() => { pictureBox4.Image = imageListState.Images[status]; }));
  12428. break;
  12429. case 5:
  12430. this.BeginInvoke(new Action(() => { pictureBox5.Image = imageListState.Images[status]; }));
  12431. break;
  12432. case 6:
  12433. this.BeginInvoke(new Action(() => { pictureBox6.Image = imageListState.Images[status]; }));
  12434. break;
  12435. case 7:
  12436. this.BeginInvoke(new Action(() => { pictureBox7.Image = imageListState.Images[status]; }));
  12437. break;
  12438. case 8:
  12439. this.BeginInvoke(new Action(() => { pictureBox8.Image = imageListState.Images[status]; }));
  12440. break;
  12441. default:
  12442. break;
  12443. }
  12444. }
  12445. Task.Run(() => // 更新PLC交互页的指示灯
  12446. {
  12447. try
  12448. {
  12449. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12450. {
  12451. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  12452. }
  12453. }
  12454. catch
  12455. {
  12456. }
  12457. });
  12458. }
  12459. #endregion UI刷新
  12460. #region 日志
  12461. /// <summary>
  12462. /// 添加各工位运行日志(同步至PLC交互页面)
  12463. /// </summary>
  12464. /// <param name="stationNameStr">工站名称</param>
  12465. /// <param name="logType">日志类型</param>
  12466. /// <param name="message">日志内容</param>
  12467. /// <param name="snNumber">产品数字SN</param>
  12468. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  12469. {
  12470. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")))
  12471. {
  12472. AddMessage(logType, message); // 首页展示+日志记录
  12473. }
  12474. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  12475. {
  12476. StationName = stationNameStr,
  12477. SnNumber = snNumber,
  12478. Message = message,
  12479. CreateTime = DateTime.Now
  12480. };
  12481. // PLC交互页展示
  12482. Task.Run(() =>
  12483. {
  12484. try
  12485. {
  12486. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12487. {
  12488. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  12489. }
  12490. }
  12491. catch
  12492. {
  12493. }
  12494. });
  12495. }
  12496. /// <summary>
  12497. /// 添加运行日志
  12498. /// </summary>
  12499. /// <param name="logType">日志类型</param>
  12500. /// <param name="message">日志内容</param>
  12501. public void AddMessage(LogType logType, string message)
  12502. {
  12503. OnMessage(logType, message);
  12504. string date = DateTime.Now.ToString("yyyy/MM/dd");
  12505. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  12506. string msgShow = time + "--> " + message + "\r\n";
  12507. this.BeginInvoke(new Action(() =>
  12508. {
  12509. systemLog.Rows.Insert(0, date, time, message);
  12510. if (systemLog.Rows.Count >= 100)
  12511. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  12512. }));
  12513. }
  12514. /// <summary>
  12515. /// 添加运行日志-保存
  12516. /// </summary>
  12517. /// <param name="logType">日志类型</param>
  12518. /// <param name="message">日志内容</param>
  12519. private void OnMessage(LogType logType, string msg)
  12520. {
  12521. MessageEvent?.Invoke(logType, msg);
  12522. }
  12523. /// <summary>
  12524. /// 保存PLC写入日志
  12525. /// </summary>
  12526. /// <param name="logType"></param>
  12527. /// <param name="logValue"></param>
  12528. private void WritePLCLog(LogType logType, string logValue)
  12529. {
  12530. switch ((int)logType)
  12531. {
  12532. case 0:
  12533. _PLCLogNet.WriteDebug(logValue);
  12534. break;
  12535. case 1:
  12536. _PLCLogNet.WriteInfo(logValue);
  12537. break;
  12538. case 2:
  12539. _PLCLogNet.WriteWarn(logValue);
  12540. break;
  12541. case 3:
  12542. _PLCLogNet.WriteError(logValue);
  12543. break;
  12544. default:
  12545. _PLCLogNet.WriteFatal(logValue);
  12546. break;
  12547. }
  12548. }
  12549. /// <summary>
  12550. /// IOT Mqtt回调方法- With DataId
  12551. /// </summary>
  12552. /// <param name="id"></param>
  12553. /// <param name="v"></param>
  12554. /// <param name="dataId"></param>
  12555. public void CallbackWithDataId(string id, string msg, string dataId)
  12556. {
  12557. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  12558. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  12559. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  12560. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  12561. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  12562. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12563. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  12564. }
  12565. /// <summary>
  12566. /// AGV Mqtt回调方法- 记录Log并处理数据
  12567. /// </summary>
  12568. /// <param name="obj"></param>
  12569. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  12570. {
  12571. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12572. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  12573. // 接收到的信息
  12574. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  12575. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  12576. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  12577. {
  12578. }
  12579. }
  12580. #endregion 日志
  12581. //private void button1_Click(object sender, EventArgs e)
  12582. //{
  12583. // OpenDailogFalg=true;
  12584. // if (OpenDailogFalg)
  12585. // {
  12586. // using (var dialog = new BandBarodeDialog())
  12587. // {
  12588. // string strCarrierBarcode = "N801A-003";
  12589. // dialog._CarrierBarcode = strCarrierBarcode;
  12590. // string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  12591. // dialog._ProductBarcode = sn;
  12592. // var rs = dialog.ShowDialog();
  12593. // if (rs == DialogResult.OK)
  12594. // {
  12595. // AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  12596. // OpenDailogFalg = false;//关闭扫码
  12597. // }
  12598. // }
  12599. // }
  12600. //}
  12601. }
  12602. }