Form_Home.cs 701 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052
  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. using static MainForm.ClassFile.XiaomiClass.MesHelper;
  52. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  53. using System.Drawing.Imaging;
  54. using System.Drawing;
  55. using ICSharpCode.SharpZipLib.Zip;
  56. using System.Text.RegularExpressions;
  57. using System.Text;
  58. /*
  59. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  60. */
  61. namespace MainForm
  62. {
  63. /// <summary>
  64. /// 记录日志的委托
  65. /// </summary>
  66. /// <param name="logType">日志类型</param>
  67. /// <param name="message">日志信息</param>
  68. public delegate void HomeMessageHandler(LogType logType, string message);
  69. /// <summary>
  70. /// 主页窗体
  71. /// </summary>
  72. public partial class Form_Home : Form
  73. {
  74. #region 常量
  75. //文本常量
  76. private const string Head = "开始采集";
  77. private const string Tail = "采集完成";
  78. private const string Body = "工位出站数据";
  79. private const string BodyCheck = "工位点检数据";
  80. private const string BodyRun = "整线运行数据";
  81. private const string BodyAlarm = "整线报警数据";
  82. #endregion 常量
  83. #region 变量
  84. /// <summary>
  85. /// 委托-记录日志的方法
  86. /// </summary>
  87. public event HomeMessageHandler MessageEvent;
  88. /// <summary>
  89. /// 日志接口
  90. /// </summary>
  91. ILogNet _PLCLogNet;
  92. /// <summary>
  93. /// 用于记录IOT MQTT日志
  94. /// </summary>
  95. ILogNet _IOTMqttLogNet;
  96. /// <summary>
  97. /// 用于记录AGV MQTT日志
  98. /// </summary>
  99. ILogNet _AGVMqttLogNet;
  100. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  101. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  102. // 间隔时间
  103. private int IntervalReadPLC = 300; //ms 读PLC
  104. private int IntervalMonitorMES = 1000; //ms MES心跳
  105. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  106. /// <summary>
  107. /// 设备报警数据
  108. /// </summary>
  109. uint[] _FaultDatas = { };
  110. uint[] _FaultDatas_Old = { };
  111. uint[] _FaultDatas2 = { };
  112. uint[] _FaultDatas_Old2 = { };
  113. // 软件状态
  114. private bool IsRun = true;
  115. #region PLC 与 TCP对象
  116. // 定义一个字典,存plc对象(通讯)
  117. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  118. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  119. // 定义TCPClient对象列表
  120. Dictionary<int, HPSocket_TcpClientHelper>
  121. _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  122. // 定义MQTTHelper对象
  123. MQTTHelper _MQTTHelper = new MQTTHelper();
  124. #endregion PLC 与 TCP对象
  125. /// <summary>
  126. /// 上次的设备运行信息
  127. /// </summary>
  128. private string lineWorkingData1_OldStr = string.Empty;
  129. /// <summary>
  130. /// 设备报警字典-当前结果
  131. /// Dictionary<工位代码,List<报警信息>>
  132. /// </summary>
  133. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  134. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  135. /// <summary>
  136. /// 单机用-设备状态
  137. /// </summary>
  138. //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  139. XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
  140. private int test_item_num = 0; //iot 过站数据序号
  141. public static string uuid = ""; //单工位或左工位
  142. public static string uuid2 = ""; //右工位
  143. private bool inpass = false; //保存进站测试状态
  144. public static XiaoMiParm xiaomiParm = new XiaoMiParm();
  145. //记录上传附件的信息
  146. public static FileUpload_FileData fileUploadData = new FileUpload_FileData();
  147. #endregion 变量
  148. #region 窗体基础事件
  149. /// <summary>
  150. /// 初始化
  151. /// </summary>
  152. public Form_Home()
  153. {
  154. InitializeComponent();
  155. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  156. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  157. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  158. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  159. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  160. }
  161. /// <summary>
  162. /// 窗体加载事件
  163. /// </summary>
  164. public void Form_Home_Load(object sender, EventArgs e)
  165. {
  166. try
  167. {
  168. AddMessage(LogType.Info, "开始初始化程序");
  169. //组建plc对象字典
  170. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  171. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  172. if (GlobalContext.IsUsePLC1)
  173. {
  174. GlobalContext.IsUsePLCNow = 1;
  175. GlobalContext.IsUseStationName = "[OP10]壳体清洁上料";
  176. FunsEip.Add(GlobalContext.IsUsePLCNow,
  177. new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  178. }
  179. if (GlobalContext.IsUsePLC2)
  180. {
  181. GlobalContext.IsUsePLCNow = 2;
  182. GlobalContext.IsUseStationName = "[OP20]上盖板上料装备";
  183. FunsEip.Add(GlobalContext.IsUsePLCNow,
  184. new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  185. }
  186. if (GlobalContext.IsUsePLC3)
  187. {
  188. GlobalContext.IsUsePLCNow = 3;
  189. GlobalContext.IsUseStationName = "[OP30]点散热胶装备";
  190. FunsEip.Add(GlobalContext.IsUsePLCNow,
  191. new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  192. }
  193. if (GlobalContext.IsUsePLC4)
  194. {
  195. GlobalContext.IsUsePLCNow = 4;
  196. GlobalContext.IsUseStationName = "[OP40]胶线检测";
  197. FunsEip.Add(GlobalContext.IsUsePLCNow,
  198. new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  199. }
  200. if (GlobalContext.IsUsePLC5)
  201. {
  202. GlobalContext.IsUsePLCNow = 5;
  203. GlobalContext.IsUseStationName = "[OP50]ADD板上料组装装备";
  204. FunsEip.Add(GlobalContext.IsUsePLCNow,
  205. new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  206. }
  207. if (GlobalContext.IsUsePLC6)
  208. {
  209. GlobalContext.IsUsePLCNow = 6;
  210. GlobalContext.IsUseStationName = "[OP70]组上盖板";
  211. FunsEip.Add(GlobalContext.IsUsePLCNow,
  212. new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  213. }
  214. if (GlobalContext.IsUsePLC7)
  215. {
  216. GlobalContext.IsUsePLCNow = 7;
  217. GlobalContext.IsUseStationName = "[OP80]上盖板锁螺丝";
  218. FunsEip.Add(GlobalContext.IsUsePLCNow,
  219. new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  220. }
  221. if (GlobalContext.IsUsePLC8)
  222. {
  223. GlobalContext.IsUsePLCNow = 8;
  224. GlobalContext.IsUseStationName = "[OP90]NG下料";
  225. FunsEip.Add(GlobalContext.IsUsePLCNow,
  226. new Inovance_EIP(GlobalContext.PC8Address,
  227. GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  228. }
  229. if (GlobalContext.IsUsePLC9)
  230. {
  231. GlobalContext.IsUsePLCNow = 9;
  232. GlobalContext.IsUseStationName = "[OP100]半成品下料";
  233. FunsEip.Add(GlobalContext.IsUsePLCNow,
  234. new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  235. }
  236. (bool, string) DicResult = InitalDicAlarm(); // 实例化报警字典
  237. AddMessage(LogType.Info, DicResult.Item2);
  238. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  239. {
  240. if (plcEIP != null)
  241. {
  242. try
  243. {
  244. (int, string) result = plcEIP.Connect();
  245. }
  246. catch (Exception ex)
  247. {
  248. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  249. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
  250. MessageBoxOptions.ServiceNotification);
  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(Http)
  280. if (GlobalContext.IsUseMES)
  281. {
  282. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  283. if (mesret)
  284. {
  285. picMESStatus.Image = imageListState.Images[1];
  286. GlobalContext.MESIsConnect = true;
  287. AddMessage(LogType.Info, "小米MES初始连接成功!");
  288. }
  289. else
  290. {
  291. picMESStatus.Image = imageListState.Images[0];
  292. GlobalContext.MESIsConnect = false;
  293. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  294. }
  295. }
  296. // 开启IOT(MQTT)
  297. if (GlobalContext.IsUseIot)
  298. {
  299. string addr = GlobalContext.MQTTServerHost;
  300. int port = GlobalContext.MQTTServerPort;
  301. //生产环境需要修改
  302. (int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666,
  303. GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  304. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
  305. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  306. {
  307. picIot.Image = imageListState.Images[1];
  308. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  309. // 设置回调函数
  310. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  311. // 配置参数
  312. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  313. // fds
  314. param.parameter.fds.address = GlobalContext.address;
  315. param.parameter.fds.appId = GlobalContext.appId;
  316. param.parameter.fds.appKey = GlobalContext.appKey;
  317. // mes
  318. param.parameter.mes.address = GlobalContext.ServerIp;
  319. param.parameter.mes.appId = GlobalContext.MESAppId;
  320. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  321. // mqtt
  322. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  323. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  324. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  325. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  326. // 设备配置
  327. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  328. if (GlobalContext.IsUsePLC1)
  329. {
  330. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  331. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  332. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  333. }
  334. if (GlobalContext.IsUsePLC2)
  335. {
  336. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  337. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  338. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  339. }
  340. if (GlobalContext.IsUsePLC3)
  341. {
  342. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  343. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  344. }
  345. if (GlobalContext.IsUsePLC4)
  346. {
  347. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  348. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  349. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  350. }
  351. if (GlobalContext.IsUsePLC5)
  352. {
  353. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  354. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  355. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  356. }
  357. if (GlobalContext.IsUsePLC6)
  358. {
  359. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  360. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  361. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  362. }
  363. if (GlobalContext.IsUsePLC7)
  364. {
  365. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  366. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  367. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  368. }
  369. if (GlobalContext.IsUsePLC8)
  370. {
  371. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  372. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  373. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  374. }
  375. if (GlobalContext.IsUsePLC9)
  376. {
  377. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  378. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  379. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  380. }
  381. param.parameter.equipment.project = GlobalContext.Project_Code;
  382. param.parameter.equipment.productMode = "debug";
  383. param.parameter.other.logLevel = 0;
  384. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  385. XiaomiMqttClient_Extend.ParameterConfig(param);
  386. //保存全局变量
  387. xiaomiParm.stationCode = param.parameter.equipment.stationCode;
  388. xiaomiParm.deviceCode = param.parameter.equipment.deviceCode;
  389. }
  390. else
  391. {
  392. picIot.Image = imageListState.Images[0];
  393. AddMessage(LogType.Info,
  394. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  395. }
  396. }
  397. // 开启AGV(Http与MQTT)
  398. if (GlobalContext.IsUseAGV)
  399. {
  400. // AGV HTTP
  401. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  402. if (mesret1)
  403. {
  404. picAgvHttp.Image = imageListState.Images[1];
  405. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  406. }
  407. else
  408. {
  409. picAgvHttp.Image = imageListState.Images[0];
  410. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  411. }
  412. string agvMqttIp = GlobalContext.MQTTServerHost;
  413. int agvMqttPort = GlobalContext.MQTTServerPort;
  414. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  415. ResultData_MQTT result_MQTT = _MQTTHelper
  416. .CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  417. // AGV MQTT
  418. if (result_MQTT.ResultCode == 1)
  419. {
  420. picAgvMqtt.Image = imageListState.Images[1];
  421. GlobalContext.AGVMQTTIsConnect = true;
  422. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  423. ResultData_MQTT result =
  424. XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  425. AddMessage(LogType.Info,
  426. $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  427. }
  428. else
  429. {
  430. picAgvMqtt.Image = imageListState.Images[0];
  431. GlobalContext.AGVMQTTIsConnect = false;
  432. AddMessage(LogType.Info,
  433. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  434. }
  435. }
  436. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  437. Task.Run(MonitorMESConnect);
  438. // 查询PLC连接状态
  439. foreach (int plcNo in FunsEip.Keys)
  440. {
  441. bool connected = FunsEip[plcNo].IsConnected;
  442. if (connected)
  443. {
  444. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  445. AddMessage(LogType.Info, msg);
  446. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  447. }
  448. else
  449. {
  450. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  451. AddMessage(LogType.Info, msg);
  452. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  453. }
  454. }
  455. // PLC4时 初始化扫码器TCP
  456. //if (GlobalContext.IsUsePLC4)
  457. // HpTCPClientInit();
  458. // 开启PLC的业务处理线程-监听PLC点位+状态
  459. foreach (Task task in TaskReadProcess)
  460. {
  461. if (task != null)
  462. task.Start();
  463. }
  464. //// 开启iot的线程
  465. TaskReadAlarm.Start();
  466. ////下传MES信息给1工位(先判断下plc对象数量)
  467. //if (Funs.Count > 1)
  468. // DownLoadProductInfo(1);
  469. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  470. {
  471. state_l.Text = "设备状态(左):";
  472. state_r.Text = "设备状态(右):";
  473. state_r.Visible = true;
  474. lblDeviceStates2.Visible = true;
  475. }
  476. //上传操作记录
  477. operateToIot("startup", "开启");
  478. AddMessage(LogType.Info, "程序初始化完成");
  479. }
  480. catch (Exception ex)
  481. {
  482. string str = ex.StackTrace;
  483. this.BeginInvoke(new Action(() =>
  484. {
  485. AddMessage(LogType.Error,
  486. "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  487. str.Length - str.LastIndexOf("\\") - 1));
  488. }));
  489. }
  490. #endregion
  491. }
  492. catch (Exception ex)
  493. {
  494. string str = ex.StackTrace;
  495. OnMessage(LogType.Info,
  496. "主窗体的首页初始化出错!异常位置:" +
  497. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
  498. ex.Message.ToString());
  499. if (ex.Message != null && ex.Message.Contains("timed out"))
  500. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  501. else
  502. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  503. }
  504. }
  505. /// <summary>
  506. /// 窗体关闭事件
  507. /// </summary>
  508. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  509. {
  510. Closed2();
  511. }
  512. public void Closed2()
  513. {
  514. try
  515. {
  516. IsRun = false;
  517. Thread.Sleep(IntervalReadPLC);
  518. // 断开TCP
  519. int count = _HPSocket_TcpClients.Count();
  520. for (int i = 0; i < count; i++)
  521. {
  522. try
  523. {
  524. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  525. {
  526. _HPSocket_TcpClients[i].Stop();
  527. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  528. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  529. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  530. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  531. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  532. }
  533. }
  534. catch
  535. {
  536. }
  537. }
  538. // 关闭Iot
  539. try
  540. {
  541. XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
  542. GlobalContext.MqttServerName);
  543. }
  544. catch
  545. {
  546. }
  547. // 关闭AGV Mqtt
  548. try
  549. {
  550. _MQTTHelper.DisconnectAsync_Client().Wait();
  551. }
  552. catch
  553. {
  554. }
  555. }
  556. catch
  557. {
  558. }
  559. }
  560. #endregion 窗体基础事件
  561. #region 监控MES状态
  562. /// <summary>
  563. /// 监控MES连接状态
  564. /// </summary>
  565. private void MonitorMESConnect()
  566. {
  567. while (IsRun) // 运行被控线程
  568. {
  569. try
  570. {
  571. // 开启MES(Http)
  572. if (GlobalContext.IsUseMES)
  573. {
  574. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  575. if (mesret)
  576. {
  577. picMESStatus.Image = imageListState.Images[1];
  578. GlobalContext.MESIsConnect = true;
  579. }
  580. else
  581. {
  582. picMESStatus.Image = imageListState.Images[0];
  583. GlobalContext.MESIsConnect = false;
  584. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  585. }
  586. }
  587. // 开启IOT(MQTT)
  588. if (GlobalContext.IsUseIot)
  589. {
  590. bool iIot = XiaomiMqttClient.IsOpen;
  591. if (iIot)
  592. picIot.Image = imageListState.Images[1];
  593. else
  594. {
  595. picIot.Image = imageListState.Images[0];
  596. OnMessage(LogType.Info,
  597. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  598. }
  599. }
  600. // 开启AGV(Http与MQTT)
  601. if (GlobalContext.IsUseAGV)
  602. {
  603. // AGV Http
  604. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  605. if (mesret1)
  606. picAgvHttp.Image = imageListState.Images[1];
  607. else
  608. {
  609. picAgvHttp.Image = imageListState.Images[0];
  610. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  611. }
  612. // AGV MQTT
  613. if (GlobalContext.AGVMQTTIsConnect)
  614. picAgvMqtt.Image = imageListState.Images[1];
  615. else
  616. {
  617. picAgvMqtt.Image = imageListState.Images[0];
  618. OnMessage(LogType.Info,
  619. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  620. }
  621. }
  622. }
  623. catch (Exception ex)
  624. {
  625. string str = ex.StackTrace;
  626. AddMessage(LogType.Error,
  627. "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  628. str.Length - str.LastIndexOf("\\") - 1));
  629. }
  630. Thread.Sleep(IntervalMonitorMES);
  631. }
  632. }
  633. #endregion 监控MES连接状态
  634. #region 采集设备状态、运行数据、报警数据
  635. /// <summary>
  636. /// 请求设备状态 5000
  637. /// </summary>
  638. /// <param name="no">1</param>
  639. /// <param name="stationNameStr"></param>
  640. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  641. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  642. {
  643. try
  644. {
  645. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  646. {
  647. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  648. return result;
  649. }
  650. else
  651. {
  652. return 0;
  653. }
  654. }
  655. catch (Exception ex)
  656. {
  657. string str = ex.StackTrace;
  658. AddMessage_Station(stationNameStr, LogType.Error,
  659. "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  660. str.Length - str.LastIndexOf("\\") - 1));
  661. return 0;
  662. }
  663. }
  664. /// <summary>
  665. /// 检查是否可采集点检数据 - 不取新值
  666. /// 5000不为1时可点检
  667. /// </summary>
  668. /// <returns></returns>
  669. public bool CheckCanSpotcheck1(int deviceState)
  670. {
  671. //return true;
  672. //D5000 = 1,代表设备控制状态处于运行状态
  673. //D5000 = 2, 代表设备控制状态处于故障状态
  674. //D5000 = 3,代表设备控制状态处于缺料状态
  675. //D5000 = 4, 代表设备控制状态处于待机状态
  676. //D5000 = 5,代表设备控制状态处于维修状态
  677. return deviceState != 1;
  678. }
  679. /// <summary>
  680. /// 检查是否可采集产品数据 - 不取新值
  681. /// </summary>
  682. /// <returns></returns>
  683. public bool CheckCanCollData(int deviceState)
  684. {
  685. return deviceState == 0; // 点检时该值不为0
  686. }
  687. /// <summary>
  688. /// 采集到的设备状态
  689. /// </summary>
  690. private string _DeviceStates = "未知状态";
  691. private string _DeviceStates_Old = "未知状态";
  692. private string _DeviceStates2 = "未知状态";
  693. private string _DeviceStates_Old2 = "未知状态";
  694. /// <summary>
  695. /// 获取设备报警数据与获取设备运行信息
  696. /// </summary>
  697. private async void ReadAlarmAllPLC()
  698. {
  699. /// 获取设备报警数据与状态信息
  700. string stationNameStr = "获取设备报警数据与状态信息";
  701. // 已连接到PLC
  702. while (IsRun)
  703. {
  704. try
  705. {
  706. #region 报警数据
  707. try
  708. {
  709. //_FaultDatas = new uint[] { 4, 0, 30, 10 };
  710. if (_FaultDatas.Length > 0)
  711. {
  712. ReadPLCAlarmToIot(_FaultDatas, _FaultDatas_Old, stationNameStr,"left");
  713. }
  714. else
  715. {
  716. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  717. }
  718. if (_FaultDatas2.Length > 0)
  719. {
  720. ReadPLCAlarmToIot(_FaultDatas2, _FaultDatas_Old2, stationNameStr,"right");
  721. }
  722. else
  723. {
  724. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  725. }
  726. }
  727. catch (Exception ex)
  728. {
  729. string str = ex.StackTrace;
  730. AddMessage_Station(stationNameStr, LogType.Error,
  731. $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  732. 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. lblDeviceStates2.Text = _DeviceStates2;
  803. break;
  804. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  805. _DeviceStates2 = "初始化状态";
  806. lblDeviceStates2.Text = _DeviceStates2;
  807. break;
  808. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  809. _DeviceStates2 = "初始化完成状态";
  810. lblDeviceStates2.Text = _DeviceStates2;
  811. break;
  812. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  813. _DeviceStates2 = "运行状态";
  814. lblDeviceStates2.Text = _DeviceStates2;
  815. break;
  816. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  817. _DeviceStates2 = "暂停状态";
  818. lblDeviceStates2.Text = _DeviceStates2;
  819. break;
  820. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  821. _DeviceStates2 = "故障状态";
  822. lblDeviceStates2.Text = _DeviceStates2;
  823. break;
  824. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  825. _DeviceStates2 = "警报状态";
  826. lblDeviceStates2.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. private static int res = 0;
  1239. public static bool StopWhile =false;
  1240. public void ConnectToIOT()
  1241. {
  1242. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  1243. // fds
  1244. param.parameter.fds.address = GlobalContext.address;
  1245. param.parameter.fds.appId = GlobalContext.appId;
  1246. param.parameter.fds.appKey = GlobalContext.appKey;
  1247. // mes
  1248. param.parameter.mes.address = GlobalContext.ServerIp;
  1249. param.parameter.mes.appId = GlobalContext.MESAppId;
  1250. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  1251. // mqtt
  1252. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  1253. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  1254. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  1255. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  1256. // 设备配置
  1257. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  1258. if (GlobalContext.IsUsePLC1)
  1259. {
  1260. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  1261. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  1262. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  1263. }
  1264. if (GlobalContext.IsUsePLC2)
  1265. {
  1266. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  1267. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  1268. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  1269. }
  1270. if (GlobalContext.IsUsePLC3)
  1271. {
  1272. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  1273. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  1274. }
  1275. if (GlobalContext.IsUsePLC4)
  1276. {
  1277. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  1278. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  1279. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  1280. }
  1281. if (GlobalContext.IsUsePLC5)
  1282. {
  1283. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  1284. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  1285. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  1286. }
  1287. if (GlobalContext.IsUsePLC6)
  1288. {
  1289. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  1290. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  1291. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  1292. }
  1293. if (GlobalContext.IsUsePLC7)
  1294. {
  1295. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  1296. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  1297. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  1298. }
  1299. if (GlobalContext.IsUsePLC8)
  1300. {
  1301. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  1302. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  1303. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  1304. }
  1305. if (GlobalContext.IsUsePLC9)
  1306. {
  1307. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  1308. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  1309. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  1310. }
  1311. param.parameter.equipment.project = GlobalContext.Project_Code;
  1312. param.parameter.equipment.productMode = "debug";
  1313. param.parameter.other.logLevel = 0;
  1314. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  1315. XiaomiMqttClient_Extend.ParameterConfig(param);
  1316. }
  1317. /// <summary>
  1318. /// float[]转为string
  1319. /// </summary>
  1320. public string FloatArrayToString(float[] nScrewResults)
  1321. {
  1322. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1323. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1324. }
  1325. /// <summary>
  1326. /// short[]转为string
  1327. /// </summary>
  1328. public string ShortArrayToString(short[] nScrewResults)
  1329. {
  1330. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1331. return string.Join(",", nScrewResults);
  1332. }
  1333. /// <summary>
  1334. /// 写入PLC重复三次
  1335. /// </summary>
  1336. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount,
  1337. T inObj)
  1338. {
  1339. int i = 0;
  1340. int nRet = 0;
  1341. string strRet = "";
  1342. try
  1343. {
  1344. while (i < 3) // 最多上传三次
  1345. {
  1346. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1347. if (nRet == 0) //成功
  1348. {
  1349. break;
  1350. }
  1351. else
  1352. {
  1353. AddMessage_Station(stationNameStr, LogType.Error,
  1354. $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1355. i++;
  1356. }
  1357. }
  1358. return (nRet, strRet);
  1359. }
  1360. catch (Exception ex)
  1361. {
  1362. return (1, ex.Message);
  1363. }
  1364. }
  1365. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
  1366. short[] nScrewOrders, short[] nScrewResults)
  1367. {
  1368. try
  1369. {
  1370. // 获取当前日期
  1371. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1372. // 构建保存路径
  1373. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1374. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
  1375. // 确保目录存在
  1376. Directory.CreateDirectory(savePath);
  1377. // 文件名
  1378. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1379. string filePath = Path.Combine(savePath, fileName);
  1380. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1381. int count = Math.Min(14, fScrewTimes.Length);
  1382. using (StreamWriter sw = new StreamWriter(filePath))
  1383. {
  1384. for (int i = 0; i < count; i++)
  1385. {
  1386. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1387. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1388. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1389. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1390. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1391. }
  1392. }
  1393. return (0, "");
  1394. }
  1395. catch (Exception ex)
  1396. {
  1397. return (1, ex.Message);
  1398. }
  1399. }
  1400. public Dictionary<string, string> GetLastLineCompensation(string path, string direction, string sn)
  1401. {
  1402. // 创建字典存储补偿点及其对应的值
  1403. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1404. try
  1405. {
  1406. //string path = GlobalContext.MESLaserRPath;
  1407. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1408. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1409. string filename = $"Laser-{currentDate}-W0.txt";
  1410. // 拼接完整路径
  1411. string fullPath = Path.Combine(path, filename);
  1412. string lastNonEmptyLine = "";
  1413. // 判断文件是否存在
  1414. if (File.Exists(fullPath))
  1415. {
  1416. //读取文件内容
  1417. string[] lines = File.ReadAllLines(fullPath);
  1418. // 获取最后一行数据(忽略标题行)
  1419. if (lines.Length > 1)
  1420. {
  1421. string lastLine = "";
  1422. for (int i = lines.Length - 1; i > 0; i--)
  1423. {
  1424. if (!string.IsNullOrEmpty(lines[i]))
  1425. {
  1426. lastLine = lines[i];
  1427. break;
  1428. }
  1429. }
  1430. // 将最后一行按逗号分隔
  1431. string[] values = lastLine.Split(',');
  1432. values[1] = sn;
  1433. string key = "三点激光_" + direction; // 构造键名
  1434. string value = string.Join(",", values); // 获取值并去除多余空格
  1435. compensationDict[key] = value;
  1436. //// 提取“1点补偿”到“6点补偿”的值
  1437. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1438. //{
  1439. // string key = $"{i - 1}点补偿"; // 构造键名
  1440. // string value = values[i].Trim(); // 获取值并去除多余空格
  1441. // compensationDict[key] = value;
  1442. //}
  1443. }
  1444. }
  1445. else
  1446. {
  1447. Console.WriteLine($"文件不存在: {fullPath}");
  1448. }
  1449. }
  1450. catch (Exception ex)
  1451. {
  1452. // 捕获异常并输出错误信息
  1453. Console.WriteLine($"发生错误: {ex.Message}");
  1454. }
  1455. return compensationDict;
  1456. }
  1457. public int PCBStationOutData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1458. {
  1459. int res = 0;
  1460. string jsonstr1 = "";
  1461. try
  1462. {
  1463. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1464. outRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备id(可配置)
  1465. outRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1466. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1467. outRequest_Body.clientTime =
  1468. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1469. outRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1470. int a1Result = (int)iotData.testStatus;
  1471. //bool pass = a1Result == 1;
  1472. //outRequest_Body.state = pass ? "PASS" : "FAIL"; ; // 出站条件 PASS或FAIL
  1473. outRequest_Body.state = "PASS";
  1474. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1475. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1476. XmStationOut_KeyMaterial keyMaterial = new XmStationOut_KeyMaterial();
  1477. keyMaterial.bindSort = 1;
  1478. keyMaterial.materialSn = Barcode.strProductBarcode;
  1479. outRequest_Body.unitData.keyMaterial.Add(keyMaterial); // 产品码
  1480. jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1481. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1482. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1483. if (response != null && response.header.code == "200")
  1484. {
  1485. res = 1;
  1486. AddMessage(LogType.Info,
  1487. "上传PCB出站数据到MES服务器---成功!请求信息:" + jsonstr1 + ",返回信息:" +
  1488. JsonConvert.SerializeObject(response.body));
  1489. }
  1490. else
  1491. {
  1492. res = 0;
  1493. AddMessage(LogType.Error,
  1494. "上传PCB出站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + jsonstr1 + ",返回信息:" +
  1495. JsonConvert.SerializeObject(response.body));
  1496. }
  1497. }
  1498. catch (Exception e)
  1499. {
  1500. res = 0;
  1501. AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---失败!请求信息:" + jsonstr1 + ",返回信息:" + e.Message);
  1502. }
  1503. return res;
  1504. }
  1505. public int PCBStationInData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1506. {
  1507. int res = 0;
  1508. string json_Body = "";
  1509. try
  1510. {
  1511. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1512. inRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  1513. inRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1514. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1515. inRequest_Body.clientTime =
  1516. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1517. inRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1518. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1519. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1520. json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1521. var response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1522. string resultJson = JsonConvert.SerializeObject(response);
  1523. if (response != null && response.header.code == "200")
  1524. {
  1525. res = 1;
  1526. AddMessage(LogType.Info,
  1527. "上传PCB进站数据到MES服务器---成功!请求信息:" + json_Body + ",返回信息:" +
  1528. JsonConvert.SerializeObject(response.body));
  1529. }
  1530. else
  1531. {
  1532. res = 0;
  1533. AddMessage(LogType.Error,
  1534. "上传PCB进站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + json_Body + ",返回信息:" +
  1535. JsonConvert.SerializeObject(response.body));
  1536. }
  1537. }
  1538. catch (Exception e)
  1539. {
  1540. res = 0;
  1541. AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---失败!请求信息:" + json_Body + ",返回信息:" + e.Message);
  1542. }
  1543. return res;
  1544. }
  1545. /// <summary>
  1546. /// 调用进站接口并保存进站数据
  1547. /// </summary>
  1548. /// <param name="stationNameStr">工站信息</param>
  1549. /// <param name="workorder_code">工单号</param>
  1550. /// <param name="mtltmrk">型号(物料号)</param>
  1551. /// <param name="sn">产品SN</param>
  1552. /// <param name="items">进站数据</param>
  1553. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1554. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
  1555. List<TestItem> items, string MachineId, string StationId, bool pass, string slot)
  1556. {
  1557. int result = 0;
  1558. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1559. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1560. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1561. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1562. inRequest_Body.clientTime =
  1563. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1564. inRequest_Body.unitSn = sn; // 产品SN
  1565. inRequest_Body.uuidInspection = uuid;
  1566. inRequest_Body.state = pass ? "PASS" : "FAIL";
  1567. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1568. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1569. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1570. StationIn stationIn = new StationIn()
  1571. {
  1572. Workorder_code = workorder_code, // 车间订单号
  1573. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1574. Sn = sn, // SN
  1575. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1576. Parameter_values = items, // 进站数据
  1577. Write_user = inRequest_Body.userId, // 员工Id
  1578. Test_time = inRequest_Body.clientTime // 进站时间
  1579. };
  1580. // 本地数据
  1581. string sql = stationIn.ToStringInsert(0);
  1582. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1583. result = ret == "成功" ? 1 : 6;
  1584. #region MES
  1585. if (GlobalContext.IsSendStationIn)
  1586. {
  1587. try
  1588. {
  1589. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1590. string resultJson = "";
  1591. string mesRet = string.Empty;
  1592. int i = 0;
  1593. while (i < 2) // 1009会多次尝试上传
  1594. {
  1595. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1596. resultJson = JsonConvert.SerializeObject(response);
  1597. if (response != null && response.header.code == "200")
  1598. break;
  1599. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1600. i++;
  1601. i++;
  1602. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1603. // 记录失败原因
  1604. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:{mesRet},请求参数:{json_Body}");
  1605. }
  1606. if (response?.header?.code == "200")
  1607. {
  1608. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1609. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1610. result = ret_Upd == "成功" ? 1 : 6;
  1611. AddMessage(LogType.Info,
  1612. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,返回参数:{resultJson},请求参数:{json_Body}");
  1613. }
  1614. else
  1615. {
  1616. result = 5;
  1617. AddMessage(LogType.Info,
  1618. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息: {mesRet},请求参数:{json_Body}");
  1619. }
  1620. string sql_response =
  1621. stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1622. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1623. }
  1624. catch (Exception ex)
  1625. {
  1626. result = 6;
  1627. string str = ex.StackTrace;
  1628. AddMessage_Station(stationNameStr, LogType.Error,
  1629. $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1630. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1631. }
  1632. }
  1633. #endregion
  1634. #region IOT
  1635. //过站结果
  1636. if (GlobalContext.IsMqttSendProcessData)
  1637. {
  1638. PassStationResultRequest request = new PassStationResultRequest();
  1639. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1640. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1641. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1642. request.line_code = GlobalContext.LineCode; // 线体编码
  1643. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1644. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1645. request.station = xiaomiParm.stationCode;
  1646. request.process_time =
  1647. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1648. request.slot = slot; // 槽位编码
  1649. request.sn = sn; // 产品SN
  1650. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1651. request.enter_status = pass ? "PASS" : "FAIL"; // 进站状态
  1652. request.result = ""; // 出站条件 PASS或FAIL; // 过站结果
  1653. request.work_type = "OUT_STATION"; // 作业类型
  1654. // 上传过站结果
  1655. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1656. if (iotResult.Item1 != 0)
  1657. {
  1658. OnMessage(LogType.Info,
  1659. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1660. }
  1661. }
  1662. #endregion
  1663. return result;
  1664. }
  1665. /// <summary>
  1666. /// 选择如何记录出站数据
  1667. /// </summary>
  1668. /// <param name="items">出站数据</param>
  1669. /// <param name="equipmentCode">设备编号</param>
  1670. /// <param name="processItem">测试项目</param>
  1671. /// <param name="workorder_code">车间订单号</param>
  1672. /// <param name="batch_num">批次号</param>
  1673. /// <param name="mtltmrk">型号</param>
  1674. /// <param name="proDate">日期</param>
  1675. /// <param name="supplierCode">供应商代码</param>
  1676. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1677. /// <returns>上传成功时返回1;失败返回0</returns>
  1678. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode,
  1679. string processItem,
  1680. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1681. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId,
  1682. string StationId, string PartBarcode, string jsonParm, string direction = "")
  1683. {
  1684. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num,
  1685. mtltmrk,
  1686. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm,
  1687. direction);
  1688. }
  1689. /// <summary>
  1690. /// 添加出站数据(提交到MES+本地保存到数据库)
  1691. /// </summary>
  1692. /// <param name="items">出站数据</param>
  1693. /// <param name="equipmentCode">设备编号</param>
  1694. /// <param name="processItem">测试项目</param>
  1695. /// <param name="workorder_code">车间订单号</param>
  1696. /// <param name="batch_num">批次号</param>
  1697. /// <param name="mtltmrk">型号</param>
  1698. /// <param name="proDate">日期</param>
  1699. /// <param name="supplierCode">供应商代码</param>
  1700. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1701. /// <returns>上传成功时返回1;失败返回0</returns>
  1702. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1703. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1704. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot,
  1705. string machineId, string stationId, string partBarcode, string jsonParm, string direction = "")
  1706. {
  1707. int upload = 0;
  1708. int result = 0;
  1709. ProcessData processData = new ProcessData()
  1710. {
  1711. Equipment_code = equipmentCode,
  1712. Workorder_code = workorder_code,
  1713. Batch_number = batch_num,
  1714. Sn = sn, // SN
  1715. Testitem = processItem,
  1716. Parameter_values = items,
  1717. Write_user = GlobalContext.CurrentUser,
  1718. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1719. };
  1720. // 本地数据
  1721. string sql = processData.ToStringInsert(upload);
  1722. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1723. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1724. #region MES
  1725. if (GlobalContext.IsSendProcessData)
  1726. {
  1727. try
  1728. {
  1729. string id = processData.ID.Copy();
  1730. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1731. if (direction == "Right")
  1732. outRequest_Body.uuidInspection = uuid2;
  1733. else
  1734. outRequest_Body.uuidInspection = uuid;
  1735. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1736. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1737. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1738. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1739. outRequest_Body.unitSn = sn; // 产品SN
  1740. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1741. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1742. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1743. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1744. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1745. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1746. if (!string.IsNullOrEmpty(partBarcode))
  1747. {
  1748. outRequest_Body.unitData.keyMaterial.Add(
  1749. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1750. {
  1751. bindSort = 1,
  1752. materialSn = partBarcode
  1753. }); // 设备数据 - 部件码
  1754. }
  1755. //OP30站读txt数据
  1756. if (stationNameStr.Contains("OP31") || stationNameStr.Contains("OP32"))
  1757. {
  1758. string path = "";
  1759. if (direction == "Left")
  1760. {
  1761. string pathStr = GlobalContext.MESLaserLPath;
  1762. path = DecFileName(pathStr);
  1763. }
  1764. else {
  1765. string pathStr = GlobalContext.MESLaserRPath;
  1766. path = DecFileName(pathStr);
  1767. }
  1768. //字典存储数据
  1769. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction, sn);
  1770. foreach (var kvp in compensationDict)
  1771. {
  1772. outRequest_Body.unitData.processData.Add(
  1773. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1774. {
  1775. dataName = kvp.Key.ToString(),
  1776. dataValue = kvp.Value.ToString()
  1777. });
  1778. }
  1779. }
  1780. //过站明细
  1781. if (GlobalContext.IsSendProcessDetail)
  1782. {
  1783. if (jsonParm.Length > 0)
  1784. {
  1785. //jsonParm = "{\"fGlueSupplySpeed\":0.63,\"fAB_AirPress\":0.0,\"fAB_AirPressDiff\":0.0,\"fMesHeightInfos\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],\"fIntervalWeights\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],\"fRemainGlues\":[600.0,600.0]}";
  1786. // 解析JSON字符串为字典
  1787. jsonParm = jsonParm.Replace("[", "\"[");
  1788. jsonParm = jsonParm.Replace("]", "]\"");
  1789. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1790. foreach (var kvp in dictionary)
  1791. {
  1792. outRequest_Body.unitData.processData.Add(
  1793. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1794. {
  1795. dataName = kvp.Key.ToString(),
  1796. dataValue = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString()
  1797. });
  1798. }
  1799. }
  1800. }
  1801. if (GlobalContext.MESIsSendUpFile)
  1802. {
  1803. foreach (var item in fileUploadData.fileData)
  1804. {
  1805. if (!string.IsNullOrEmpty(item.FileName))
  1806. {
  1807. outRequest_Body.unitData.fileData.Add(
  1808. new XmStationOut_FileData()
  1809. {
  1810. fileName = item.FileName,
  1811. fileId = item.FileId,
  1812. bucket = item.Bucket
  1813. });
  1814. }
  1815. }
  1816. }
  1817. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1818. if (GlobalContext.IsSendProcessData)
  1819. {
  1820. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1821. string mesRet = string.Empty;
  1822. int i = 0;
  1823. while (i < 2) // 1009会多次尝试上传
  1824. {
  1825. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1826. if (response != null && response.header.code == "200")
  1827. {
  1828. OnMessage(LogType.Info,
  1829. $"【出站数据 SN {sn}】上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
  1830. JsonConvert.SerializeObject(response.body));
  1831. break;
  1832. }
  1833. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1834. i++;
  1835. i++;
  1836. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1837. // 记录失败原因
  1838. OnMessage(LogType.Error,
  1839. $"【出站数据 SN {sn}】上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1840. }
  1841. if (response?.header?.code == "200")
  1842. {
  1843. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1844. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1845. result = 1;
  1846. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1847. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1848. }
  1849. else
  1850. {
  1851. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1852. }
  1853. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
  1854. JsonConvert.SerializeObject(outRequest_Body),
  1855. JsonConvert.SerializeObject(response), id);
  1856. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1857. }
  1858. }
  1859. catch (Exception ex)
  1860. {
  1861. string str = ex.StackTrace;
  1862. AddMessage_Station(stationNameStr, LogType.Error,
  1863. $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1864. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1865. }
  1866. }
  1867. #endregion
  1868. #region IOT
  1869. //过站明细
  1870. if (GlobalContext.IsMqttSendProcessData)
  1871. {
  1872. PassStationDetailRequest request = new PassStationDetailRequest();
  1873. if (direction == "Right")
  1874. request.pass_station_id = uuid2;
  1875. else
  1876. request.pass_station_id = uuid;
  1877. request.sn = sn; // 产品SN
  1878. request.slot = vehicleSlot; // 槽位编码
  1879. request.function_name = "Machine_加⼯模块";
  1880. request.status = "PASS";
  1881. (int, string) iotResult = (0, "");
  1882. if (jsonParm.Length > 0)
  1883. {
  1884. // 解析JSON字符串为字典
  1885. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1886. foreach (var kvp in dictionary)
  1887. {
  1888. test_item_num += 1;
  1889. request.test_item_num = test_item_num.ToString();
  1890. request.test_item = kvp.Key.ToString();
  1891. request.result_val = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString();
  1892. request.description = request.test_item;
  1893. // 上传过站明细
  1894. iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  1895. if (iotResult.Item1 != 0)
  1896. {
  1897. OnMessage(LogType.Info,
  1898. $"【IOT过站明细】上传失败!错误原因:{iotResult.Item2},过站明细;产品码[{sn}] 测试项目[{request.test_item}] 测试值[{request.result_val}]");
  1899. }
  1900. }
  1901. }
  1902. }
  1903. //过站结果
  1904. if (GlobalContext.IsMqttSendProcessData)
  1905. {
  1906. PassStationResultRequest request = new PassStationResultRequest();
  1907. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1908. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1909. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1910. request.line_code = GlobalContext.LineCode; // 线体编码
  1911. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1912. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1913. request.station = xiaomiParm.stationCode;
  1914. request.process_time =
  1915. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1916. request.slot = vehicleSlot; // 槽位编码
  1917. request.sn = sn; // 产品SN
  1918. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1919. request.enter_status = ""; // 进站状态
  1920. request.result = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL; // 过站结果
  1921. request.work_type = "OUT_STATION"; // 作业类型
  1922. // 上传过站结果
  1923. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1924. if (iotResult.Item1 != 0)
  1925. {
  1926. OnMessage(LogType.Info,
  1927. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1928. }
  1929. }
  1930. #endregion
  1931. return result;
  1932. }
  1933. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1934. //{
  1935. // Stopwatch stopwatch = new Stopwatch();
  1936. // stopwatch.Start();
  1937. // try
  1938. // {
  1939. // // 初始化 AtlasScrew 实例
  1940. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1941. // atlasScrew1.Initial();
  1942. // // 存储结果的列表
  1943. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1944. // // 存储角度和扭力的字符串列表
  1945. // List<string> angleStrs = new List<string>();
  1946. // List<string> torqueStrs = new List<string>();
  1947. // // 上一次获取的数据
  1948. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1949. // while (isExitAtlasLeft) // 检查是否收集数据
  1950. // {
  1951. // // 获取当前数据
  1952. // var currentResult = atlasScrew1.GetResults();
  1953. // // 判断是否为新数据
  1954. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1955. // {
  1956. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1957. // // 更新角度和扭力的字符串列表
  1958. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1959. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1960. // // 计算角度、扭力、起始扭力和最大扭力
  1961. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1962. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1963. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1964. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1965. // // 将新数据添加到结果列表
  1966. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1967. // // 更新上一次获取的数据
  1968. // lastResult = currentResult;
  1969. // }
  1970. // // 等待一段时间后再次检查
  1971. // Thread.Sleep(20); // 轮询间隔时间
  1972. // // 如果触发了出站,则退出循环
  1973. // if (!isExitAtlasLeft)
  1974. // {
  1975. // break;
  1976. // }
  1977. // }
  1978. // // 生成文件名
  1979. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1980. // // 写入数据到文件
  1981. // using (StreamWriter writer = new StreamWriter(fileName))
  1982. // {
  1983. // // 写入标题行
  1984. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1985. // // 写入每一行数据
  1986. // foreach (var result in results)
  1987. // {
  1988. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1989. // }
  1990. // }
  1991. // stopwatch.Stop();
  1992. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1993. // }
  1994. // catch (Exception ex)
  1995. // {
  1996. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1997. // }
  1998. // finally
  1999. // {
  2000. // // 重置标志变量
  2001. // isExitAtlasLeft = false;
  2002. // }
  2003. //}
  2004. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  2005. //{
  2006. // Stopwatch stopwatch = new Stopwatch();
  2007. // stopwatch.Start();
  2008. // try
  2009. // {
  2010. // // 初始化 AtlasScrew 实例
  2011. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  2012. // atlasScrew2.Initial();
  2013. // // 存储结果的列表
  2014. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  2015. // // 上一次获取的数据
  2016. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  2017. // while (isExitAtlasRight) // 检查是否收集数据
  2018. // {
  2019. // // 获取当前数据
  2020. // var currentResult = atlasScrew2.GetResults();
  2021. // // 判断是否为新数据
  2022. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  2023. // {
  2024. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2025. // // 将新数据写入PLC
  2026. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  2027. // // 将新数据添加到结果列表
  2028. // results.Add(currentResult);
  2029. // // 更新上一次获取的数据
  2030. // lastResult = currentResult;
  2031. // }
  2032. // // 等待一段时间后再次检查
  2033. // Thread.Sleep(20); // 轮询间隔时间
  2034. // // 如果触发了出站,则退出循环
  2035. // if (!isExitAtlasRight)
  2036. // {
  2037. // break;
  2038. // }
  2039. // }
  2040. // // 将所有数据写入文件
  2041. // //WriteDataToFile(sn, direction, results);
  2042. // stopwatch.Stop();
  2043. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  2044. // }
  2045. // catch (Exception ex)
  2046. // {
  2047. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  2048. // }
  2049. // finally
  2050. // {
  2051. // // 重置标志变量
  2052. // isExitAtlasRight = false;
  2053. // }
  2054. //}
  2055. /// <summary>
  2056. ///字符串中文乱码解决
  2057. /// </summary>
  2058. /// <param name="str"></param>
  2059. /// <returns></returns>
  2060. public static string DecFileName(string str)
  2061. {
  2062. Encoding utf8 = Encoding.GetEncoding("gbk");
  2063. byte[] btArr = utf8.GetBytes(str);
  2064. return Encoding.UTF8.GetString(btArr);
  2065. }
  2066. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  2067. {
  2068. Stopwatch stopwatch = new Stopwatch();
  2069. stopwatch.Start();
  2070. int nRet = 0;
  2071. string strRet = "";
  2072. try
  2073. {
  2074. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  2075. while (isCollectingFlagLeft)
  2076. {
  2077. // 从缓存中获取所有未处理的数据
  2078. var cachedData = atlasScrew.GetCachedDataLeft();
  2079. foreach (var currentResult in cachedData)
  2080. {
  2081. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  2082. {
  2083. continue; // 跳过无效数据
  2084. }
  2085. OnMessage(LogType.Info,
  2086. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2087. // 写入PLC
  2088. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  2089. {
  2090. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  2091. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  2092. };
  2093. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  2094. if (nRet != 0)
  2095. {
  2096. OnMessage(LogType.Info,
  2097. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  2098. }
  2099. else
  2100. {
  2101. OnMessage(LogType.Info,
  2102. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  2103. }
  2104. // 构建保存路径
  2105. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  2106. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  2107. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  2108. Directory.CreateDirectory(savePath); // 确保目录存在
  2109. // 构建文件名(以 SN + 序号命名)
  2110. string fileName = $"{sn}_{fileCounter}.txt";
  2111. string filePath = Path.Combine(savePath, fileName);
  2112. // 写入文件
  2113. using (StreamWriter writer = new StreamWriter(filePath))
  2114. {
  2115. writer.WriteLine("精度, 扭力");
  2116. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  2117. for (int i = 0;
  2118. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  2119. i++)
  2120. {
  2121. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  2122. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  2123. writer.WriteLine($"{precision}, {torque}");
  2124. }
  2125. }
  2126. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  2127. // 增加文件计数器
  2128. fileCounter++;
  2129. }
  2130. // 如果没有更多数据,则短暂休眠以节省资源
  2131. if (!cachedData.Any())
  2132. {
  2133. Thread.Sleep(10); // 根据需要调整休眠时间
  2134. }
  2135. // 如果触发了出站,则退出循环
  2136. if (!isCollectingFlagLeft)
  2137. {
  2138. break;
  2139. }
  2140. }
  2141. stopwatch.Stop();
  2142. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  2143. }
  2144. catch (Exception ex)
  2145. {
  2146. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  2147. }
  2148. finally
  2149. {
  2150. isCollectingFlagLeft = false;
  2151. }
  2152. }
  2153. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  2154. {
  2155. Stopwatch stopwatch = new Stopwatch();
  2156. stopwatch.Start();
  2157. int nRet = 0;
  2158. string strRet = "";
  2159. try
  2160. {
  2161. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  2162. while (isCollectingFlagRight)
  2163. {
  2164. // 从缓存中获取所有未处理的数据
  2165. var cachedData = atlasScrew.GetCachedDataLeft();
  2166. foreach (var currentResult in cachedData)
  2167. {
  2168. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  2169. {
  2170. continue; // 跳过无效数据
  2171. }
  2172. OnMessage(LogType.Info,
  2173. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2174. // 写入PLC
  2175. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  2176. {
  2177. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  2178. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  2179. };
  2180. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  2181. if (nRet != 0)
  2182. {
  2183. OnMessage(LogType.Info,
  2184. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  2185. }
  2186. else
  2187. {
  2188. OnMessage(LogType.Info,
  2189. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  2190. }
  2191. // 构建保存路径
  2192. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  2193. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  2194. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  2195. Directory.CreateDirectory(savePath); // 确保目录存在
  2196. // 构建文件名(以 SN + 序号命名)
  2197. string fileName = $"{sn}_{fileCounter}.txt";
  2198. string filePath = Path.Combine(savePath, fileName);
  2199. // 写入文件
  2200. using (StreamWriter writer = new StreamWriter(filePath))
  2201. {
  2202. writer.WriteLine("精度, 扭力");
  2203. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  2204. for (int i = 0;
  2205. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  2206. i++)
  2207. {
  2208. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  2209. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  2210. writer.WriteLine($"{precision}, {torque}");
  2211. }
  2212. }
  2213. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  2214. // 增加文件计数器
  2215. fileCounter++;
  2216. }
  2217. // 如果没有更多数据,则短暂休眠以节省资源
  2218. if (!cachedData.Any())
  2219. {
  2220. Thread.Sleep(10); // 根据需要调整休眠时间
  2221. }
  2222. // 如果触发了出站,则退出循环
  2223. if (!isCollectingFlagRight)
  2224. {
  2225. break;
  2226. }
  2227. }
  2228. stopwatch.Stop();
  2229. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  2230. }
  2231. catch (Exception ex)
  2232. {
  2233. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  2234. }
  2235. finally
  2236. {
  2237. isCollectingFlagRight = false;
  2238. }
  2239. }
  2240. public static (int, string) CompressFolder(string folderPath, string zipFilePath)
  2241. {
  2242. try
  2243. {
  2244. // 创建zip文件,将指定文件夹内的所有内容压缩到这个zip文件中
  2245. System.IO.Compression.ZipFile.CreateFromDirectory(folderPath, zipFilePath);
  2246. return (1, "文件夹已成功压缩!");
  2247. }
  2248. catch (Exception ex)
  2249. {
  2250. return (0, "文件压缩出错!" + ex.Message);
  2251. }
  2252. }
  2253. /// <summary>
  2254. /// 上传文件
  2255. /// </summary>
  2256. /// <param name="BarcodeSet_t">条码集合</param>
  2257. /// <param name="stationCode">工站编号</param>
  2258. /// <param name="stationName">工站名称</param>
  2259. /// <param name="path">文件路径</param>
  2260. public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode,
  2261. string stationName, int pass, string path, string guid = "")
  2262. {
  2263. string sql, filename = "";
  2264. int result = 0;
  2265. var formData = new MultipartFormDataContent();
  2266. string msg = "";
  2267. string file_category = "IMAGE"; //IMAGE 、TEXT 、UNKNOWN
  2268. string file_type = "IMAGE";
  2269. string project = GlobalContext.ProgramName;
  2270. string run_mode = GlobalContext.run_mode;
  2271. string product_mode = GlobalContext.product_mode;
  2272. string pass_result = (pass == 1 ? "PASS" : "Fail");
  2273. string device_code = xiaomiParm.deviceCode;
  2274. string sn = BarcodeSet.strProductBarcode;
  2275. string staion_id = xiaomiParm.stationCode;
  2276. string bucket =
  2277. $"{file_category}/{file_type}/{project}/{product_mode}/{run_mode}/{pass_result}/{device_code}/{sn}/{staion_id}";
  2278. // 获取所有图片文件
  2279. if (guid == "")
  2280. {
  2281. guid = Guid.NewGuid().ToString();
  2282. }
  2283. try
  2284. {
  2285. if (GlobalContext.MESIsSendUpFile)
  2286. {
  2287. List<string> imageFiles = GetAllImageFiles(path);
  2288. string toPath = GlobalContext.MqttFileBackupLogDir;
  2289. filename =
  2290. $"{xiaomiParm.workstation}_{file_type}_{sn}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  2291. //string directoryPath = Path.GetDirectoryName(path);
  2292. string strFilePath = toPath + "\\" + filename;
  2293. if (imageFiles.Count > 0)
  2294. {
  2295. var r = CompressFolder(path, strFilePath);
  2296. if (r.Item1 == 0)
  2297. {
  2298. return (0, r.Item2);
  2299. }
  2300. else
  2301. {
  2302. msg = r.Item2 + "\r\n";
  2303. }
  2304. }
  2305. else
  2306. {
  2307. return (0, "文件不存在!");
  2308. }
  2309. FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  2310. fileUpload_X5.bucket = bucket;
  2311. fileUpload_X5.name = filename;
  2312. fileUpload_X5.uuid = guid.ToString();
  2313. ///需要上传文件
  2314. FileInfo file = new FileInfo(strFilePath);
  2315. string fileMd5Hex = GetMD5Hex(file);
  2316. fileUpload_X5.md5 = fileMd5Hex;
  2317. fileUpload_X5.uploadCloud = true;
  2318. fileUpload_X5.informMqtt = true;
  2319. FileMqttPayload fileMqttPayload = new FileMqttPayload();
  2320. fileMqttPayload.factory = GlobalContext.Factory_Code;
  2321. fileMqttPayload.project_name = GlobalContext.Project_Code;
  2322. fileMqttPayload.product_mode = GlobalContext.product_mode;
  2323. fileMqttPayload.line_no = GlobalContext.LineCode;
  2324. fileMqttPayload.work_station_no = xiaomiParm.workstation;
  2325. fileMqttPayload.equipment_no = xiaomiParm.deviceCode;
  2326. fileMqttPayload.station_no = xiaomiParm.stationCode;
  2327. fileMqttPayload.file_id = guid;
  2328. fileMqttPayload.file_name = filename;
  2329. fileMqttPayload.sn = BarcodeSet.strProductBarcode;
  2330. //fileMqttPayload.opt_time = "";
  2331. //fileMqttPayload.file_type = "";
  2332. //fileMqttPayload.file_category = "";
  2333. //fileMqttPayload.tag = "";
  2334. fileMqttPayload.reference_info.pass_station_id = uuid;
  2335. var fileresult = await
  2336. XiaomiMESHttp_UpLoadFile.FileUoladToMes(strFilePath, fileUpload_X5, fileMqttPayload);
  2337. if (fileresult.Item1 != 1)
  2338. {
  2339. return (0, msg + fileresult.Item2 + "\r\n");
  2340. }
  2341. else
  2342. {
  2343. msg = msg + fileresult.Item2 + "\r\n";
  2344. }
  2345. foreach (var imageFile in imageFiles)
  2346. {
  2347. if (File.Exists(imageFile))
  2348. {
  2349. //删除文件
  2350. (bool, string) newResult = DeleteFile(imageFile);
  2351. if (!newResult.Item1)
  2352. {
  2353. return (0, Path.GetFileName(imageFile) + newResult.Item2);
  2354. }
  2355. }
  2356. }
  2357. }
  2358. return (1, msg);
  2359. }
  2360. catch (Exception e)
  2361. {
  2362. return (0,
  2363. filename + $"文件上传错误!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" +
  2364. e.Message);
  2365. }
  2366. }
  2367. /// <summary>
  2368. /// 获取路径下的所有图片
  2369. /// </summary>
  2370. /// <param name="directoryPath"></param>
  2371. /// <returns></returns>
  2372. public List<string> GetAllImageFiles(string directoryPath)
  2373. {
  2374. var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
  2375. { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
  2376. var imageFiles = new List<string>();
  2377. try
  2378. {
  2379. // 遍历目录及子目录中的所有文件
  2380. foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
  2381. {
  2382. // 获取文件扩展名并检查是否为图片格式
  2383. string extension = Path.GetExtension(file);
  2384. if (imageExtensions.Contains(extension))
  2385. {
  2386. imageFiles.Add(file);
  2387. }
  2388. }
  2389. }
  2390. catch (Exception ex)
  2391. {
  2392. OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
  2393. }
  2394. return imageFiles;
  2395. }
  2396. /// <summary>
  2397. /// 实例化报警字典
  2398. /// </summary>
  2399. private (bool, string) InitalDicAlarm()
  2400. {
  2401. #region 加载报警表
  2402. string excelPath = "";
  2403. switch (GlobalContext.IsUsePLCNow)
  2404. {
  2405. case 1:
  2406. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_10_壳体清洁上料.xlsx";
  2407. break;
  2408. case 2:
  2409. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_20_上盖板上料装备.xlsx";
  2410. break;
  2411. case 3:
  2412. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_30_点散热胶装备.xlsx";
  2413. break;
  2414. case 4:
  2415. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_40_胶线检测.xlsx";
  2416. break;
  2417. case 5:
  2418. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_50_ADD板上料组装装备.xlsx";
  2419. break;
  2420. case 6:
  2421. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_60_组上盖板.xlsx";
  2422. break;
  2423. case 7:
  2424. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_70_上盖板锁螺丝.xlsx";
  2425. break;
  2426. case 8:
  2427. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_80_NG下料.xlsx";
  2428. break;
  2429. case 9:
  2430. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_90_半成品下料.xlsx";
  2431. break;
  2432. default:
  2433. return (false, $"不支持当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请在设置页切换到正确的plc后重启该软件!");
  2434. }
  2435. if (!File.Exists(excelPath))
  2436. return (false, $"未找到当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请检查文件路径:'{excelPath}'。");
  2437. DataTable DtModel = NPOIHelper.ReadExcel(excelPath);
  2438. if (DtModel == null || DtModel.Rows.Count < 1)
  2439. return (false, $"报警点位表未包含任何报警数据!请检查‘{excelPath}’文件!");
  2440. // 检查列名
  2441. List<string> isNeedParms = new List<string>()
  2442. {
  2443. "设备分类名称", "设备分类编码", "分类层级1", "分类层级2", "分类层级3", "分类层级4", "事件名称", "事件ID", "描述", "标签", "PLC地址", "工位"
  2444. }; // 必须要有的列
  2445. // 指定列名 + 检查列是否完整
  2446. DataRow dtRowName = DtModel.Rows[0];
  2447. int count = DtModel.Columns.Count;
  2448. for (int i = 0; i < count; i++)
  2449. {
  2450. string columeName = dtRowName[i]?.ToString();
  2451. if (!string.IsNullOrEmpty(columeName))
  2452. DtModel.Columns[i].ColumnName = columeName;
  2453. if ((!string.IsNullOrEmpty(columeName)) && isNeedParms.Count > 0 && isNeedParms.Contains(columeName))
  2454. isNeedParms.Remove(columeName);
  2455. }
  2456. DtModel.Rows.RemoveAt(0);
  2457. if (isNeedParms.Count > 0)
  2458. {
  2459. string msg1 = string.Join(",", isNeedParms);
  2460. return (false, $"报警点位表未包含列:{msg1}!请检查‘{excelPath}’文件!");
  2461. }
  2462. #endregion 加载报警表
  2463. List<Alarm> keyValues1 = new List<Alarm>();
  2464. for (int i = 0; i < DtModel.Rows.Count; i++)
  2465. {
  2466. Alarm alarm = new Alarm();
  2467. alarm.plcName = DtModel.Rows[i]["设备分类名称"]?.ToString(); // 设备名;
  2468. string type1Str = DtModel.Rows[i]["分类层级1"]?.ToString(); // 分类层级1;
  2469. alarm.type1CH = type1Str; // 分类层级1 中文
  2470. alarm.type1 = type1Str; // 分类层级1
  2471. if (!string.IsNullOrEmpty(type1Str) && type1Str.Contains("\n"))
  2472. {
  2473. string[] type1Strs = type1Str.Split('\n');
  2474. if (type1Strs.Length >= 2)
  2475. {
  2476. alarm.type1CH = type1Strs[0].Trim(); // 分类层级1 中文
  2477. alarm.type1 = type1Strs[1].Trim(); // 分类层级1
  2478. if (string.IsNullOrEmpty(alarm.type1))
  2479. alarm.type1 = alarm.type1CH;
  2480. }
  2481. }
  2482. string type2Str = DtModel.Rows[i]["分类层级2"]?.ToString(); // 分类层级2;电气控制 electric_control
  2483. alarm.type2CH = type2Str; // 分类层级2 中文
  2484. alarm.type2 = type2Str; // 分类层级2
  2485. if (!string.IsNullOrEmpty(type2Str) && type2Str.Contains("\n"))
  2486. {
  2487. string[] type2Strs = type2Str.Split('\n');
  2488. if (type2Strs.Length >= 2)
  2489. {
  2490. alarm.type2CH = type2Strs[0].Trim(); // 分类层级2 中文
  2491. alarm.type2 = type2Strs[1].Trim(); // 分类层级2
  2492. if (string.IsNullOrEmpty(alarm.type2))
  2493. alarm.type2 = alarm.type2CH;
  2494. }
  2495. }
  2496. string type3Str = DtModel.Rows[i]["分类层级3"]?.ToString(); // 分类层级3;故障 Fault
  2497. alarm.type3CH = type3Str; // 分类层级3 中文
  2498. alarm.type3 = type3Str; // 分类层级3
  2499. if (!string.IsNullOrEmpty(type3Str) && type3Str.Contains("\n"))
  2500. {
  2501. string[] type3Strs = type3Str.Split('\n');
  2502. if (type3Strs.Length >= 2)
  2503. {
  2504. alarm.type3CH = type3Strs[0].Trim(); // 分类层级3 中文
  2505. alarm.type3 = type3Strs[1].Trim(); // 分类层级3
  2506. if (string.IsNullOrEmpty(alarm.type3))
  2507. alarm.type3 = alarm.type3CH;
  2508. }
  2509. }
  2510. string faultStr = DtModel.Rows[i]["分类层级4"]?.ToString(); // 故障部件;overall_module
  2511. alarm.type4 = faultStr; // 分类层级4 中文
  2512. alarm.type4CH = faultStr; // 分类层级4
  2513. if (!string.IsNullOrEmpty(faultStr) && faultStr.Contains("\n"))
  2514. {
  2515. string[] faultStrs = faultStr.Split('\n');
  2516. if (faultStrs.Length >= 2)
  2517. {
  2518. alarm.type4CH = faultStrs[0].Trim(); // 故障部件;overall_module
  2519. alarm.type4 = faultStrs[1].Trim(); // 故障部件
  2520. if (string.IsNullOrEmpty(alarm.type4))
  2521. alarm.type4 = alarm.type4CH;
  2522. }
  2523. }
  2524. alarm.fault_code = DtModel.Rows[i]["事件ID"]?.ToString(); // 故障编码;A40001
  2525. alarm.fault_name = DtModel.Rows[i]["事件名称"]?.ToString(); // 故障名称;AL[1000]_系统_HMI急停故障
  2526. alarm.fault_desc = alarm.fault_name; // 故障描述;AL[1000]_系统_HMI急停故障
  2527. string plcAdress = DtModel.Rows[i]["PLC地址"]?.ToString();
  2528. alarm.PLC地址 = plcAdress;
  2529. plcAdress = plcAdress.Replace("fault_codes[", "");
  2530. plcAdress = plcAdress.Replace("]", "");
  2531. alarm.group_index = Convert.ToInt32(plcAdress.Split(".")[0]);
  2532. keyValues1.Add(alarm);
  2533. }
  2534. DicAlarms_Cur.Add(GlobalContext.IsUseStationName, keyValues1); // 这里使用线体代替工位
  2535. return (true, "报警字典表初始化成功!");
  2536. }
  2537. private async void ReadPLCAlarmToIot(uint[] FaultData, uint[] FaultDataOld, string stationNameStr,string flag)
  2538. {
  2539. DateTime dtNow = DateTime.Now;
  2540. try
  2541. {
  2542. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  2543. List<(int, int)> AlarmIndexList = new List<(int, int)>(); //收集所有报警信息的位置
  2544. AlarmData alarmData = new AlarmData();
  2545. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  2546. bool isNoAlarm = false; //是否有报警
  2547. string binaryString = "";
  2548. bool isNoNewAlarm = false; //是否有新的报警
  2549. if (FaultData.Length > 0)
  2550. {
  2551. foreach (var item in FaultData)
  2552. {
  2553. if (item > 0)
  2554. {
  2555. isNoAlarm = true;
  2556. break;
  2557. }
  2558. else {
  2559. isNoAlarm = false;
  2560. }
  2561. }
  2562. if (!FaultData.SequenceEqual(FaultDataOld))
  2563. {
  2564. isNoNewAlarm = true;
  2565. isNeedUpdUI = true;
  2566. }
  2567. if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
  2568. {
  2569. //解析报警信息,分析当前报警在字典中的定位
  2570. for (int i = 0; i <= FaultData.Length - 1; i++)
  2571. {
  2572. var num = 0;
  2573. if (FaultData[i] > 0)
  2574. {
  2575. //转换二进制
  2576. binaryString = Convert.ToString(FaultData[i], 2);
  2577. for (int j = binaryString.Length - 1; j >= 0; j--)
  2578. {
  2579. num++;
  2580. char s = binaryString[j];
  2581. if (binaryString[j] == '1')
  2582. {
  2583. //记录1的位置
  2584. AlarmIndexList.Add((i, num - 1));
  2585. }
  2586. }
  2587. }
  2588. }
  2589. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  2590. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
  2591. foreach ((int index, int row) in AlarmIndexList)
  2592. {
  2593. var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
  2594. for (int i = 0; i < tempDic.Count - 1; i++) // 读取
  2595. {
  2596. //若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
  2597. if (tempDic[i].group_index == index && i == row)
  2598. {
  2599. dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 =
  2600. new AlarmData()
  2601. {
  2602. GUID = Guid.NewGuid().ToString(),
  2603. LineName = GlobalContext.IsUseStationName, // 工站
  2604. PlcStation = tempDic[i].plcName, // 工站全称;[S1]
  2605. Type1 = tempDic[i].type1, // 故障层级1
  2606. Type2 = tempDic[i].type2, // 故障层级2
  2607. Type3 = tempDic[i].type3, // 故障层级3
  2608. Type4 = tempDic[i].type4, // 故障层级4
  2609. AlarmType = tempDic[i].fault_code, // 报警类型
  2610. AlarmDesc = tempDic[i].fault_name, // 报警内容
  2611. StartTime = dtNow // 开始时间
  2612. };
  2613. // 传输到页面
  2614. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  2615. {
  2616. 线体名称 = tempDic[i].plcName,
  2617. 报警类型 = tempDic[i].fault_code,
  2618. 报警内容 = tempDic[i].fault_name,
  2619. 开始时间 = dtNow
  2620. });
  2621. // 新增到数据库
  2622. //var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
  2623. //SaveAlarmDataByDB(stationNameStr, data1, false);
  2624. //OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
  2625. }
  2626. }
  2627. }
  2628. //筛选含报警数据的字典
  2629. var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
  2630. if (dicAlarms_Cur.Count > 0)
  2631. {
  2632. string stationId = "";
  2633. foreach (var item in dicAlarms_Cur)
  2634. {
  2635. if (!string.IsNullOrEmpty(xiaomiParm.stationCode))
  2636. {
  2637. stationId = xiaomiParm.stationCode;
  2638. //上传
  2639. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2640. }
  2641. else {
  2642. if (flag == "left")
  2643. {
  2644. if (GlobalContext.IsUsePLC3)
  2645. stationId = GlobalContext.s3_1_station;
  2646. if (GlobalContext.IsUsePLC7)
  2647. stationId = GlobalContext.s7_1_station;
  2648. //上传
  2649. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2650. }
  2651. else {
  2652. if (GlobalContext.IsUsePLC3)
  2653. stationId = GlobalContext.s3_2_station;
  2654. if (GlobalContext.IsUsePLC7)
  2655. stationId = GlobalContext.s7_2_station;
  2656. //上传
  2657. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2658. }
  2659. }
  2660. }
  2661. }
  2662. // 有新报警则更新
  2663. if (isNeedUpdUI)
  2664. // UI展示 - 展示到设备状态页
  2665. await Task.Run(() =>
  2666. {
  2667. try
  2668. {
  2669. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  2670. {
  2671. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  2672. if (Form_Main.formDevAlarm.Visible)
  2673. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  2674. }
  2675. }
  2676. catch
  2677. {
  2678. }
  2679. });
  2680. if (flag == "left")
  2681. {
  2682. _FaultDatas_Old = FaultData.ToArray();
  2683. }
  2684. else {
  2685. _FaultDatas_Old2 = FaultData.ToArray();
  2686. }
  2687. }
  2688. }
  2689. //FaultLogRequest request = new FaultLogRequest();
  2690. //request.station = mesStation; // 工位
  2691. //request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
  2692. //request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
  2693. //request.fault_cmpnt = xmFaultCmpnt; // 故障部件
  2694. //request.fault_desc = xmFaultDesc; // 故障描述
  2695. //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发生时间 2022-06-01 14:27:57.283
  2696. // // 上传
  2697. //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
  2698. }
  2699. catch (Exception ex)
  2700. {
  2701. string str = ex.StackTrace;
  2702. AddMessage_Station(stationNameStr, LogType.Error,
  2703. $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  2704. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2705. }
  2706. }
  2707. public void operateToIot(string action, string stationNameStr)
  2708. {
  2709. OperateLogRequest request = new OperateLogRequest();
  2710. request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
  2711. request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
  2712. request.operate_action = action; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
  2713. //request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
  2714. request.current_process = Application.ProductName;
  2715. request.operate_desc = stationNameStr; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
  2716. request.operate_result = "success"; // 操作结果
  2717. request.operator_name = "default"; // 操作账号名;填当前操作⽤⼾,如⽆则填default
  2718. // 上传
  2719. (int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
  2720. if (iotResult.Item1 != 0)
  2721. {
  2722. AddMessage(LogType.Info, "【操作记录】上传失败!错误原因:" + iotResult.Item2 + "操作状态:" + stationNameStr);
  2723. }
  2724. }
  2725. private void 通用节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
  2726. IoT_DataSet_t iot_data, out int res)
  2727. {
  2728. Stopwatch stopwatch1 = new Stopwatch();
  2729. Stopwatch stopwatch2 = new Stopwatch();
  2730. string resultStr = string.Empty;
  2731. try
  2732. {
  2733. string oEEType = iot_data.beatAction.ToString(); // 节拍类型(plc写入)
  2734. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
  2735. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  2736. (short, string) result = (0, "");
  2737. // 上传开始节拍
  2738. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2739. //上传结束节拍
  2740. switch (oEEType)
  2741. {
  2742. case "1":
  2743. Enum.TryParse("2", out deviceOEE);
  2744. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2745. break;
  2746. case "5":
  2747. Enum.TryParse("6", out deviceOEE);
  2748. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2749. break;
  2750. }
  2751. if (result.Item1 == 1)
  2752. {
  2753. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]上传成功!");
  2754. //写入PLC
  2755. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2756. iotData.machineState = iot_data.machineState;
  2757. iotData.work_type = iot_data.work_type;
  2758. iotData.testStatus = iot_data.testStatus;
  2759. iotData.beatAction = iot_data.beatAction;
  2760. iotData.beatReturn = 1; //OK
  2761. iotData.fault_codes = iot_data.fault_codes;
  2762. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2763. if (PLCresult.Item1 == 0)
  2764. {
  2765. res = 1;
  2766. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]写入成功!");
  2767. }
  2768. else
  2769. {
  2770. res = 0;
  2771. }
  2772. }
  2773. else
  2774. {
  2775. res = 0;
  2776. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]接口出错!错误信息:" + result.Item2);
  2777. //写入PLC
  2778. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2779. iotData.machineState = iot_data.machineState;
  2780. iotData.work_type = iot_data.work_type;
  2781. iotData.testStatus = iot_data.testStatus;
  2782. iotData.beatAction = iot_data.beatAction;
  2783. iotData.beatReturn = 2; //NG
  2784. iotData.fault_codes = iot_data.fault_codes;
  2785. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2786. }
  2787. }
  2788. catch (Exception ex)
  2789. {
  2790. res = 0;
  2791. string str = ex.StackTrace;
  2792. AddMessage_Station(stationNameStr, LogType.Error,
  2793. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  2794. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2795. //写入PLC
  2796. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2797. iotData.machineState = iot_data.machineState;
  2798. iotData.work_type = iot_data.work_type;
  2799. iotData.testStatus = iot_data.testStatus;
  2800. iotData.beatAction = iot_data.beatAction;
  2801. iotData.beatReturn = 2; //NG
  2802. iotData.fault_codes = iot_data.fault_codes;
  2803. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2804. }
  2805. }
  2806. /// <summary>
  2807. /// 去除常见特殊字符,如 \r, \n, \t 等
  2808. /// </summary>
  2809. /// <param name="format"></param>
  2810. /// <returns></returns>
  2811. private static string FormatStrbyPLC(string format)
  2812. {
  2813. string cleanedString = "";
  2814. if (!string.IsNullOrEmpty(format))
  2815. {
  2816. cleanedString = Regex.Replace(format, @"[\r\n\t]", "");
  2817. }
  2818. return cleanedString;
  2819. }
  2820. #endregion
  2821. #region S1
  2822. /// <summary>
  2823. /// [S1] 壳体清洁上料装备
  2824. /// </summary>
  2825. /// <param name="plcNo">PLC编号</param>
  2826. private void ReadStation_S1(int plcNo)
  2827. {
  2828. string stationCode = "[OP10]";
  2829. string stationName = "壳体清洁上料";
  2830. string stationNameStr = stationCode + stationName;
  2831. string tagBaseName = "g_OP10_MES"; //标签变量名称
  2832. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2833. string tagAgvCommName = "agvCommFrmPC";
  2834. string tagiotComnName = "iotData";
  2835. string tagBarsetName = "BarcodeSet";
  2836. string CarrierBarcode = "";
  2837. string ProductBarcode = "";
  2838. // 触发信号字典
  2839. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2840. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2841. // PLC数据字典 赋值
  2842. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2843. s1PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  2844. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  2845. (int, string) result;
  2846. while (true)
  2847. {
  2848. try
  2849. {
  2850. if (!GlobalContext._IsCon_Funs1)
  2851. {
  2852. UpdatePLCMonitor(1, plcNo, 0);
  2853. continue;
  2854. }
  2855. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2856. {
  2857. Stopwatch stopwatch1 = new Stopwatch();
  2858. Stopwatch stopwatch2 = new Stopwatch();
  2859. stopwatch1.Start();
  2860. stopwatch2.Start();
  2861. #region 一次性读取所有数据
  2862. // 一次性读取所有数据
  2863. result = FunsEip[plcNo]
  2864. .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2865. if (result.Item1 != 0)
  2866. {
  2867. //richTextBox1.AppendText("\n" + strRet);
  2868. }
  2869. else
  2870. {
  2871. //richTextBox1.AppendText("\n" + "读取成功");
  2872. stPLC_MesData.BarcodeSet.strProductBarcode =
  2873. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  2874. stPLC_MesData.BarcodeSet.strPartBarcode =
  2875. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  2876. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  2877. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  2878. stPLC_MesData.BarcodeSet.strPCBBarcode =
  2879. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  2880. //设备状态
  2881. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2882. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2883. ? XiaomiDeviceState.Unknown
  2884. : (XiaomiDeviceState)xmDeviceStateInt;
  2885. // 载具SN
  2886. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  2887. // 物料码(物料码还未绑定载具SN时必填)
  2888. ProductBarcode = stPLC_MesData.BarcodeSet.strProductBarcode;
  2889. // 节拍
  2890. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.beatAction;
  2891. //报警信息
  2892. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  2893. }
  2894. #endregion 一次性读取所有数据
  2895. stopwatch2.Stop();
  2896. #region 进站
  2897. try
  2898. {
  2899. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2900. {
  2901. lock (lockObj)
  2902. {
  2903. if (!ProgressState)
  2904. {
  2905. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  2906. ProgressState = true;
  2907. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
  2908. tagBaseName + "." + tagMesCommName, out ProgressState));
  2909. }
  2910. }
  2911. }
  2912. }
  2913. catch (Exception ex)
  2914. {
  2915. ProgressState = false;
  2916. string str = ex.StackTrace;
  2917. AddMessage_Station(stationNameStr, LogType.Error,
  2918. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2919. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2920. }
  2921. #endregion 进站
  2922. #region 出站
  2923. try
  2924. {
  2925. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2926. {
  2927. lock (lockObj)
  2928. {
  2929. if (!ProgressState)
  2930. {
  2931. ProgressState = true;
  2932. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
  2933. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2934. out ProgressState));
  2935. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2936. }
  2937. }
  2938. }
  2939. }
  2940. catch (Exception ex)
  2941. {
  2942. ProgressState = false;
  2943. string str = ex.StackTrace;
  2944. AddMessage_Station(stationNameStr, LogType.Error,
  2945. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2946. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2947. }
  2948. #endregion 出站
  2949. #region 节拍接口
  2950. try
  2951. {
  2952. if (stPLC_MesData.iotData.beatAction > 0)
  2953. {
  2954. int a1OEEType = Convert.ToInt32(s1PLCData["a1OEEType"]);
  2955. int a1OEETypeGOld = Convert.ToInt32(s1PLCSignal_Old["a1OEEType"]);
  2956. if (a1OEEType != a1OEETypeGOld)
  2957. {
  2958. s1PLCData["OEETypeFlag"] = "1";
  2959. }
  2960. else
  2961. {
  2962. s1PLCData["OEETypeFlag"] = "0";
  2963. }
  2964. if (s1PLCData["OEETypeFlag"].ToString() == "1" && (a1OEEType == 1 || a1OEEType == 3 || a1OEEType == 4 || a1OEEType == 5))
  2965. {
  2966. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  2967. if (res == 1)
  2968. {
  2969. s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
  2970. }
  2971. else {
  2972. s1PLCSignal_Old["a1OEEType"] = 0;
  2973. }
  2974. }
  2975. }
  2976. else {
  2977. s1PLCSignal_Old["a1OEEType"] = 0;
  2978. }
  2979. }
  2980. catch (Exception ex)
  2981. {
  2982. string str = ex.StackTrace;
  2983. AddMessage_Station(stationNameStr, LogType.Error,
  2984. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2985. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2986. }
  2987. #endregion
  2988. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2989. stopwatch1.Stop();
  2990. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2991. }
  2992. else
  2993. {
  2994. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2995. AddMessage_Station(stationNameStr, LogType.Info,
  2996. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2997. FunsEip[plcNo].Connect(); // 重连
  2998. }
  2999. }
  3000. catch (Exception ex)
  3001. {
  3002. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3003. AddMessage_Station(stationNameStr, LogType.Error,
  3004. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3005. }
  3006. Thread.Sleep(IntervalReadPLC);
  3007. }
  3008. }
  3009. /// <summary>
  3010. /// [S1] 壳体清洁上料 - 进站
  3011. /// </summary>
  3012. /// <param name="plcNo">PLC编号</param>
  3013. /// <param name="stationNameStr">工站全称</param>
  3014. /// <param name="stPLC_MesData"></param>
  3015. /// <param name="tagMesCommName"></param>
  3016. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  3017. out bool ProgressState)
  3018. {
  3019. Stopwatch stopwatch1 = new Stopwatch();
  3020. Stopwatch stopwatch2 = new Stopwatch();
  3021. try
  3022. {
  3023. stopwatch1.Start();
  3024. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3025. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  3026. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3027. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  3028. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  3029. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3030. bool pass = a1Result == 1;
  3031. if (string.IsNullOrEmpty(sn))
  3032. {
  3033. ProgressState = false;
  3034. AddMessage(LogType.Error, $"{stationNameStr}_未能查到产品码");
  3035. Thread.Sleep(10000);
  3036. return;
  3037. }
  3038. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  3039. // sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3040. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3041. //绑定载具和产品
  3042. ResponseMessage message = new ResponseMessage();
  3043. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  3044. if (message.result == false)
  3045. {
  3046. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  3047. ProgressState = false;
  3048. Thread.Sleep(10000);
  3049. return;
  3050. }
  3051. // 产品SN进站
  3052. List<TestItem> item = new List<TestItem>();
  3053. stopwatch2.Start();
  3054. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3055. item, MachineId, StationId, pass, "01-SLOT-01");
  3056. stopwatch2.Stop();
  3057. //指令执行结果 1:OK 110:失败
  3058. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3059. if (mesResultFrmWeb == 1)
  3060. {
  3061. if (a1Result == 1)
  3062. {
  3063. mesResultFrmWeb = 1;
  3064. }
  3065. else
  3066. {
  3067. mesResultFrmWeb = 110;
  3068. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3069. }
  3070. }
  3071. //进站结果写入PLC
  3072. CommandFromPLC resultToPlC = new CommandFromPLC();
  3073. resultToPlC.cmd = 0;
  3074. resultToPlC.cmdParam = 0;
  3075. resultToPlC.cmdResult = mesResultFrmWeb;
  3076. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3077. }
  3078. catch (Exception ex)
  3079. {
  3080. string str = ex.StackTrace;
  3081. AddMessage(LogType.Error,
  3082. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3083. str.Length - str.LastIndexOf("\\") - 1));
  3084. CommandFromPLC resultToPlC = new CommandFromPLC();
  3085. resultToPlC.cmd = 0;
  3086. resultToPlC.cmdParam = 0; //指令参数
  3087. resultToPlC.cmdResult = 110;
  3088. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3089. }
  3090. stopwatch1.Stop();
  3091. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3092. AddMessage(LogType.Info,
  3093. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3094. stopwatch2.ElapsedMilliseconds + "ms");
  3095. ProgressState = false;
  3096. }
  3097. /// <summary>
  3098. /// [S1] 壳体清洁上料 - 出站接口
  3099. /// </summary>
  3100. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  3101. string stationCode, string stationName, out bool ProgressState)
  3102. {
  3103. Stopwatch stopwatch1 = new Stopwatch();
  3104. Stopwatch stopwatch2 = new Stopwatch();
  3105. try
  3106. {
  3107. stopwatch1.Start();
  3108. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3109. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3110. string processItem = stationName; // 项目
  3111. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3112. string supplierCode = ""; // 供应商代码
  3113. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  3114. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  3115. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  3116. string sn = string.Empty;
  3117. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3118. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  3119. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  3120. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3121. //a1Result = 1;
  3122. bool pass = a1Result == 1;
  3123. //根据载具码获取产品码
  3124. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3125. if (string.IsNullOrEmpty(strProductBarcode))
  3126. {
  3127. ProgressState = false;
  3128. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3129. Thread.Sleep(10000);
  3130. return;
  3131. }
  3132. sn = strProductBarcode;
  3133. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3134. List<TestItem> items = new List<TestItem>();
  3135. items.Add(new TestItem()
  3136. {
  3137. Parameter_name = "载具码",
  3138. Parameter_value = CarrierBarcode,
  3139. Parameter_unit = ""
  3140. });
  3141. items.Add(new TestItem()
  3142. {
  3143. Parameter_name = "产品码",
  3144. Parameter_value = sn,
  3145. Parameter_unit = ""
  3146. });
  3147. #region 转换过站明细字符串
  3148. //创建字典
  3149. var dic = new Dictionary<string, string>();
  3150. // 获取结构体类型
  3151. FieldInfo[] fields = typeof(OP10_DataSet_t).GetFields();
  3152. // 遍历变量名转换成字典描述
  3153. foreach (FieldInfo field in fields)
  3154. {
  3155. //获取枚举描述
  3156. string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  3157. typeof(XiaomiMESEnum_ProcessData.Enum_10_ProcessData));
  3158. //获取过站明细的值
  3159. object valueObj = field.GetValue(stPLC_MesData.mesData);
  3160. dic.Add(name, valueObj.ToString());
  3161. }
  3162. string paramJson = JsonConvert.SerializeObject(dic);
  3163. #endregion
  3164. //出站接口
  3165. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3166. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3167. MachineId, StationId, "", paramJson);
  3168. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3169. if (mesResultFrmWeb == 1)
  3170. {
  3171. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3172. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3173. }
  3174. stopwatch2.Start();
  3175. //进站结果写入PLC
  3176. CommandFromPLC resultToPlC = new CommandFromPLC();
  3177. resultToPlC.cmd = 0;
  3178. resultToPlC.cmdParam = 0; //指令参数
  3179. resultToPlC.cmdResult = mesResultFrmWeb;
  3180. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3181. stopwatch2.Stop();
  3182. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3183. //保存PLC返回MES数据到本地
  3184. ResponseMessage message = new ResponseMessage();
  3185. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  3186. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
  3187. stPLC_MesData.mesData.fCleanSpeed,
  3188. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
  3189. stPLC_MesData.mesData.nCleanCount,
  3190. stPLC_MesData.mesData.nRemainCount);
  3191. if (message.result == false)
  3192. {
  3193. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3194. }
  3195. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  3196. }
  3197. catch (Exception ex)
  3198. {
  3199. stopwatch2.Start();
  3200. CommandFromPLC resultToPlC = new CommandFromPLC();
  3201. resultToPlC.cmd = 0;
  3202. resultToPlC.cmdParam = 0; //指令参数
  3203. resultToPlC.cmdResult = 110;
  3204. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3205. stopwatch2.Stop();
  3206. string str = ex.StackTrace;
  3207. AddMessage(LogType.Error,
  3208. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3209. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3210. }
  3211. stopwatch1.Stop();
  3212. AddMessage(LogType.Info,
  3213. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3214. stopwatch2.ElapsedMilliseconds + "ms");
  3215. ProgressState = false;
  3216. uuid = "";
  3217. }
  3218. #endregion
  3219. #region S2
  3220. /// <summary>
  3221. /// [S2] 上盖板上料装备
  3222. /// </summary>
  3223. /// <param name="plcNo">PLC编号</param>
  3224. private void ReadStation_S2(int plcNo)
  3225. {
  3226. string stationCode = "[OP20]";
  3227. string stationName = "上盖板上料装备";
  3228. string stationNameStr = stationCode + stationName;
  3229. string tagBaseName = "g_OP20_MES"; //标签变量名称
  3230. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3231. string tagAgvCommName = "agvCommFrmPC";
  3232. string tagiotComnName = "iotData";
  3233. string tagBarsetName = "BarcodeSet";
  3234. string CarrierBarcode = "";
  3235. // 触发信号字典
  3236. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3237. s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
  3238. // PLC数据字典 赋值
  3239. s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
  3240. s2PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  3241. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  3242. (int, string) result;
  3243. while (true)
  3244. {
  3245. try
  3246. {
  3247. if (!GlobalContext._IsCon_Funs2)
  3248. {
  3249. UpdatePLCMonitor(1, plcNo, 0);
  3250. continue;
  3251. }
  3252. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3253. {
  3254. Stopwatch stopwatch1 = new Stopwatch();
  3255. Stopwatch stopwatch2 = new Stopwatch();
  3256. stopwatch1.Start();
  3257. stopwatch2.Start();
  3258. #region 一次性读取所有数据
  3259. // 一次性读取所有数据
  3260. result = FunsEip[plcNo]
  3261. .Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3262. if (result.Item1 != 0)
  3263. {
  3264. //richTextBox1.AppendText("\n" + strRet);
  3265. }
  3266. else
  3267. {
  3268. //richTextBox1.AppendText("\n" + "读取成功");
  3269. stPLC_MesData.BarcodeSet.strProductBarcode =
  3270. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  3271. stPLC_MesData.BarcodeSet.strPartBarcode =
  3272. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  3273. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  3274. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  3275. stPLC_MesData.BarcodeSet.strPCBBarcode =
  3276. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  3277. //设备状态
  3278. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3279. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3280. ? XiaomiDeviceState.Unknown
  3281. : (XiaomiDeviceState)xmDeviceStateInt;
  3282. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3283. s2PLCData["a2OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  3284. //报警信息
  3285. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  3286. }
  3287. #endregion 一次性读取所有数据
  3288. stopwatch2.Stop();
  3289. #region 进站
  3290. try
  3291. {
  3292. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3293. {
  3294. lock (lockObj)
  3295. {
  3296. if (!ProgressState)
  3297. {
  3298. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3299. ProgressState = true;
  3300. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
  3301. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3302. out ProgressState));
  3303. }
  3304. }
  3305. }
  3306. }
  3307. catch (Exception ex)
  3308. {
  3309. ProgressState = false;
  3310. string str = ex.StackTrace;
  3311. AddMessage_Station(stationNameStr, LogType.Error,
  3312. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3313. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3314. }
  3315. #endregion 进站
  3316. #region 出站
  3317. try
  3318. {
  3319. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3320. {
  3321. lock (lockObj)
  3322. {
  3323. if (!ProgressState)
  3324. {
  3325. ProgressState = true;
  3326. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
  3327. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3328. out ProgressState));
  3329. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  3330. }
  3331. }
  3332. }
  3333. }
  3334. catch (Exception ex)
  3335. {
  3336. ProgressState = false;
  3337. string str = ex.StackTrace;
  3338. AddMessage_Station(stationNameStr, LogType.Error,
  3339. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3340. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3341. }
  3342. #endregion 出站
  3343. #region 节拍接口
  3344. try
  3345. {
  3346. if (stPLC_MesData.iotData.beatAction > 0)
  3347. {
  3348. int a2OEEType = Convert.ToInt32(s2PLCData["a2OEEType"]);
  3349. int a2OEETypeGOld = Convert.ToInt32(s2PLCSignal_Old["a2OEEType"]);
  3350. if (a2OEEType != a2OEETypeGOld)
  3351. {
  3352. s2PLCData["OEETypeFlag"] = "1";
  3353. }
  3354. else
  3355. {
  3356. s2PLCData["OEETypeFlag"] = "0";
  3357. }
  3358. if (s2PLCData["OEETypeFlag"].ToString() == "1" && (a2OEEType == 1 || a2OEEType == 3 || a2OEEType == 4 || a2OEEType == 5))
  3359. {
  3360. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  3361. if (res == 1)
  3362. {
  3363. s2PLCSignal_Old["a2OEEType"] = s2PLCData["a2OEEType"];
  3364. }
  3365. else
  3366. {
  3367. s2PLCSignal_Old["a2OEEType"] = 0;
  3368. }
  3369. }
  3370. }
  3371. else {
  3372. s2PLCSignal_Old["a2OEEType"] = 0;
  3373. }
  3374. }
  3375. catch (Exception ex)
  3376. {
  3377. string str = ex.StackTrace;
  3378. AddMessage_Station(stationNameStr, LogType.Error,
  3379. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3380. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3381. }
  3382. #endregion
  3383. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3384. stopwatch1.Stop();
  3385. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3386. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3387. }
  3388. else
  3389. {
  3390. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3391. AddMessage_Station(stationNameStr, LogType.Info,
  3392. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3393. FunsEip[plcNo].Connect();
  3394. }
  3395. }
  3396. catch (Exception ex)
  3397. {
  3398. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3399. AddMessage_Station(stationNameStr, LogType.Error,
  3400. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3401. //Funs[plcNo].ReConnect();
  3402. }
  3403. Thread.Sleep(IntervalReadPLC);
  3404. }
  3405. }
  3406. /// <summary>
  3407. /// [S2] 上盖板上料装备
  3408. /// </summary>
  3409. /// <param name="plcNo">PLC编号</param>
  3410. /// <param name="stationNameStr">工站全称</param>
  3411. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3412. string tagBarsetName, out bool ProgressState)
  3413. {
  3414. Stopwatch stopwatch1 = new Stopwatch();
  3415. Stopwatch stopwatch2 = new Stopwatch();
  3416. try
  3417. {
  3418. stopwatch1.Start();
  3419. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3420. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  3421. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3422. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3423. bool pass = a1Result == 1;
  3424. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  3425. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  3426. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3427. //根据载具码获取产品码
  3428. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3429. if (string.IsNullOrEmpty(strProductBarcode))
  3430. {
  3431. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3432. ProgressState = false;
  3433. Thread.Sleep(10000);
  3434. return;
  3435. }
  3436. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  3437. //if (sn != strProductBarcode)
  3438. //{
  3439. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  3440. //}
  3441. sn = strProductBarcode;
  3442. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3443. // 产品SN(物料码)校验
  3444. List<TestItem> item = new List<TestItem>();
  3445. stopwatch2.Start();
  3446. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3447. item, MachineId, StationId, pass, "01-SLOT-01");
  3448. stopwatch2.Stop();
  3449. //指令执行结果 1:OK 110:失败
  3450. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3451. if (mesResultFrmWeb == 1)
  3452. {
  3453. if (a1Result == 1)
  3454. {
  3455. mesResultFrmWeb = 1;
  3456. }
  3457. else
  3458. {
  3459. mesResultFrmWeb = 110;
  3460. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3461. }
  3462. }
  3463. //进站结果写入PLC
  3464. CommandFromPLC resultToPlC = new CommandFromPLC();
  3465. resultToPlC.cmd = 0;
  3466. resultToPlC.cmdParam = 0; //指令参数
  3467. resultToPlC.cmdResult = mesResultFrmWeb;
  3468. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3469. }
  3470. catch (Exception ex)
  3471. {
  3472. string str = ex.StackTrace;
  3473. AddMessage(LogType.Error,
  3474. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3475. str.Length - str.LastIndexOf("\\") - 1));
  3476. CommandFromPLC resultToPlC = new CommandFromPLC();
  3477. resultToPlC.cmd = 0;
  3478. resultToPlC.cmdParam = 0; //指令参数
  3479. resultToPlC.cmdResult = 110;
  3480. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3481. }
  3482. stopwatch1.Stop();
  3483. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3484. AddMessage(LogType.Info,
  3485. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3486. stopwatch2.ElapsedMilliseconds + "ms");
  3487. ProgressState = false;
  3488. }
  3489. /// <summary>
  3490. /// [S2] 上盖板上料装备 - 出站接口
  3491. /// </summary>
  3492. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3493. string stationCode, string stationName, out bool ProgressState)
  3494. {
  3495. Stopwatch stopwatch1 = new Stopwatch();
  3496. Stopwatch stopwatch2 = new Stopwatch();
  3497. try
  3498. {
  3499. stopwatch1.Start();
  3500. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3501. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3502. string processItem = stationName; // 测试项目
  3503. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3504. string supplierCode = ""; // 供应商代码
  3505. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3506. string batch_num = GlobalContext.BatchNumber; // 批次号
  3507. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3508. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3509. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3510. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  3511. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  3512. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  3513. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3514. bool pass = a1Result == 1;
  3515. //根据载具码获取产品码
  3516. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3517. if (string.IsNullOrEmpty(strProductBarcode))
  3518. {
  3519. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3520. ProgressState = false;
  3521. Thread.Sleep(10000);
  3522. return;
  3523. }
  3524. sn = strProductBarcode;
  3525. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3526. List<TestItem> items = new List<TestItem>();
  3527. items.Add(new TestItem()
  3528. {
  3529. Parameter_name = "载具码",
  3530. Parameter_value = CarrierBarcode,
  3531. Parameter_unit = ""
  3532. });
  3533. items.Add(new TestItem()
  3534. {
  3535. Parameter_name = "产品码",
  3536. Parameter_value = sn,
  3537. Parameter_unit = ""
  3538. });
  3539. items.Add(new TestItem()
  3540. {
  3541. Parameter_name = "部件码",
  3542. Parameter_value = PartBarcode,
  3543. Parameter_unit = ""
  3544. });
  3545. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3546. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3547. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3548. MachineId, StationId, PartBarcode, paramJson);
  3549. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3550. if (mesResultFrmWeb == 1)
  3551. {
  3552. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3553. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3554. }
  3555. stopwatch2.Start();
  3556. //进站结果写入PLC
  3557. CommandFromPLC resultToPlC = new CommandFromPLC();
  3558. resultToPlC.cmd = 0;
  3559. resultToPlC.cmdParam = 0; //指令参数
  3560. resultToPlC.cmdResult = mesResultFrmWeb;
  3561. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3562. stopwatch2.Stop();
  3563. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3564. //保存PLC返回MES数据到本地
  3565. ResponseMessage message = new ResponseMessage();
  3566. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  3567. stPLC_MesData.mesData.nRemainCount);
  3568. if (message.result == false)
  3569. {
  3570. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3571. }
  3572. if (!string.IsNullOrEmpty(PartBarcode))
  3573. {
  3574. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  3575. if (message.result == false)
  3576. {
  3577. AddMessage(LogType.Error, message.text);
  3578. }
  3579. }
  3580. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3581. }
  3582. catch (Exception ex)
  3583. {
  3584. stopwatch2.Start();
  3585. CommandFromPLC resultToPlC = new CommandFromPLC();
  3586. resultToPlC.cmd = 0;
  3587. resultToPlC.cmdParam = 0; //指令参数
  3588. resultToPlC.cmdResult = 110;
  3589. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3590. stopwatch2.Stop();
  3591. string str = ex.StackTrace;
  3592. AddMessage(LogType.Error,
  3593. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3594. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3595. }
  3596. stopwatch1.Stop();
  3597. AddMessage(LogType.Info,
  3598. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3599. stopwatch2.ElapsedMilliseconds + "ms");
  3600. ProgressState = false;
  3601. uuid = "";
  3602. }
  3603. #endregion
  3604. #region S3
  3605. /// <summary>
  3606. /// [S3] 点散热胶装备
  3607. /// </summary>
  3608. /// <param name="plcNo">PLC编号</param>
  3609. private void ReadStation_S3(int plcNo)
  3610. {
  3611. string stationCode = "[OP30]";
  3612. string stationName = "点散热胶装备";
  3613. string stationNameStr = stationCode + stationName;
  3614. string tagBaseName = "g_OP30_MES"; //标签变量名称
  3615. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3616. string tagAgvCommName = "agvCommFrmPC";
  3617. string tagiotComnName = "iotData";
  3618. string tagBarsetName = "BarcodeSet";
  3619. string CarrierBarcode_Left = "";
  3620. string CarrierBarcode_Right = "";
  3621. s3PLCSignal_Old.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3622. s3PLCSignal_Old.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3623. // PLC数据字典 赋值
  3624. s3PLCData.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3625. s3PLCData.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3626. s5PLCData.Add("OEETypeFlag_left", 0); // 节拍标识 0 不上传 ,1 上传
  3627. s5PLCData.Add("OEETypeFlag_right", 0); // 节拍标识 0 不上传 ,1 上传
  3628. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  3629. (int, string) result;
  3630. while (true)
  3631. {
  3632. try
  3633. {
  3634. if (!GlobalContext._IsCon_Funs2)
  3635. {
  3636. UpdatePLCMonitor(1, plcNo, 0);
  3637. continue;
  3638. }
  3639. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3640. {
  3641. Stopwatch stopwatch1 = new Stopwatch();
  3642. Stopwatch stopwatch2 = new Stopwatch();
  3643. stopwatch1.Start();
  3644. stopwatch2.Start();
  3645. #region 一次性读取所有数据
  3646. // 一次性读取所有数据
  3647. result = FunsEip[plcNo]
  3648. .Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3649. if (result.Item1 != 0)
  3650. {
  3651. //richTextBox1.AppendText("\n" + strRet);
  3652. }
  3653. else
  3654. {
  3655. //测试数据
  3656. //stPLC_MesData.Left.mesCommFrmPLC.cmd = 2;
  3657. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3658. //stPLC_MesData.Left.BarcodeSet.strPCBBarcode = "A1507V000239";
  3659. //stPLC_MesData.Left.iotData.beatAction = 1;
  3660. //stPLC_MesData.Left.iotData.beatAction = 2;
  3661. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3662. #region 去除扫码产生的特殊字符
  3663. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  3664. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  3665. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  3666. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  3667. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  3668. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  3669. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  3670. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  3671. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  3672. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  3673. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  3674. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  3675. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  3676. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  3677. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  3678. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  3679. #endregion
  3680. //richTextBox1.AppendText("\n" + "读取成功");
  3681. //设备状态
  3682. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  3683. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  3684. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3685. ? XiaomiDeviceState.Unknown
  3686. : (XiaomiDeviceState)xmDeviceStateInt_L;
  3687. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3688. ? XiaomiDeviceState.Unknown
  3689. : (XiaomiDeviceState)xmDeviceStateInt_R;
  3690. //载具SN
  3691. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  3692. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  3693. // 节拍
  3694. s3PLCData["a3OEEType_left"] = stPLC_MesData.Left.iotData.beatAction;
  3695. s3PLCData["a3OEEType_right"] = stPLC_MesData.Right.iotData.beatAction;
  3696. //报警信息
  3697. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  3698. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  3699. //_FaultDatas = new uint[] { 2, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
  3700. //_FaultDatas2 = new uint[] { 2, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
  3701. }
  3702. #endregion 一次性读取所有数据
  3703. stopwatch2.Stop();
  3704. #region 左边进站
  3705. try
  3706. {
  3707. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3708. {
  3709. lock (lockObj)
  3710. {
  3711. if (!ProgressState)
  3712. {
  3713. stationCode = "[OP31]";
  3714. stationName = "点散热胶装备1";
  3715. stationNameStr = stationCode + stationName;
  3716. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3717. ProgressState = true;
  3718. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
  3719. tagBaseName + ".Left." + tagMesCommName,
  3720. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  3721. }
  3722. }
  3723. }
  3724. }
  3725. catch (Exception ex)
  3726. {
  3727. ProgressState = false;
  3728. string str = ex.StackTrace;
  3729. AddMessage_Station(stationNameStr, LogType.Error,
  3730. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3731. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3732. }
  3733. #endregion 左边进站
  3734. #region 左边出站
  3735. try
  3736. {
  3737. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3738. {
  3739. lock (lockObj)
  3740. {
  3741. if (!ProgressState)
  3742. {
  3743. stationCode = "[OP31]";
  3744. stationName = "点散热胶装备1";
  3745. stationNameStr = stationCode + stationName;
  3746. ProgressState = true;
  3747. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
  3748. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  3749. out ProgressState));
  3750. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3751. }
  3752. }
  3753. }
  3754. }
  3755. catch (Exception ex)
  3756. {
  3757. ProgressState = false;
  3758. string str = ex.StackTrace;
  3759. AddMessage_Station(stationNameStr, LogType.Error,
  3760. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3761. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3762. }
  3763. #endregion 左边出站
  3764. #region 右边进站
  3765. try
  3766. {
  3767. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3768. {
  3769. lock (lockObj)
  3770. {
  3771. if (!ProgressState)
  3772. {
  3773. uuid2 = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3774. stationCode = "[OP32]";
  3775. stationName = "点散热胶装备2";
  3776. stationNameStr = stationCode + stationName;
  3777. ProgressState = true;
  3778. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
  3779. tagBaseName + ".Right." + tagMesCommName,
  3780. tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
  3781. }
  3782. }
  3783. }
  3784. }
  3785. catch (Exception ex)
  3786. {
  3787. ProgressState = false;
  3788. string str = ex.StackTrace;
  3789. AddMessage_Station(stationNameStr, LogType.Error,
  3790. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3791. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3792. }
  3793. #endregion 右边进站
  3794. #region 右边出站
  3795. try
  3796. {
  3797. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3798. {
  3799. lock (lockObj)
  3800. {
  3801. if (!ProgressState)
  3802. {
  3803. stationCode = "[OP32]";
  3804. stationName = "点散热胶装备2";
  3805. stationNameStr = stationCode + stationName;
  3806. ProgressState = true;
  3807. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
  3808. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  3809. out ProgressState));
  3810. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3811. }
  3812. }
  3813. }
  3814. }
  3815. catch (Exception ex)
  3816. {
  3817. string str = ex.StackTrace;
  3818. AddMessage_Station(stationNameStr, LogType.Error,
  3819. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3820. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3821. }
  3822. #endregion 右边出站
  3823. #region 节拍接口
  3824. try
  3825. {
  3826. #region 左工位 节拍
  3827. if (stPLC_MesData.Left.iotData.beatAction > 0)
  3828. {
  3829. stationCode = "[OP31]";
  3830. stationName = "点散热胶装备1";
  3831. stationNameStr = stationCode + stationName;
  3832. int a3OEEType_left = Convert.ToInt32(s3PLCData["a3OEEType_left"]);
  3833. int a3OEETypeGOld_left = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_left"]);
  3834. if (a3OEEType_left != a3OEETypeGOld_left)
  3835. {
  3836. s3PLCData["OEETypeFlag_left"] = "1";
  3837. }
  3838. else
  3839. {
  3840. s3PLCData["OEETypeFlag_left"] = "0";
  3841. }
  3842. if (s3PLCData["OEETypeFlag_left"].ToString() == "1" && (a3OEEType_left == 1 || a3OEEType_left == 3 || a3OEEType_left == 4 || a3OEEType_left == 5))
  3843. {
  3844. 通用节拍接口(plcNo, stationNameStr,
  3845. tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  3846. stPLC_MesData.Left.iotData, out res);
  3847. if (res == 1)
  3848. {
  3849. s3PLCSignal_Old["a3OEEType_left"] = a3OEEType_left;
  3850. }
  3851. else {
  3852. s3PLCSignal_Old["a3OEEType_left"] = 0;
  3853. }
  3854. }
  3855. }
  3856. else
  3857. {
  3858. s3PLCSignal_Old["a3OEEType_left"] = 0;
  3859. }
  3860. #endregion 左工位 节拍
  3861. #region 右工位 节拍
  3862. if (stPLC_MesData.Right.iotData.beatAction > 0)
  3863. {
  3864. stationCode = "[OP32]";
  3865. stationName = "点散热胶装备2";
  3866. stationNameStr = stationCode + stationName;
  3867. int a3OEEType_right = Convert.ToInt32(s3PLCData["a3OEEType_right"]);
  3868. int a3OEETypeGOld_right = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_right"]);
  3869. if (a3OEEType_right != a3OEETypeGOld_right)
  3870. {
  3871. s3PLCData["OEETypeFlag_right"] = "1";
  3872. }
  3873. else
  3874. {
  3875. s3PLCData["OEETypeFlag_right"] = "0";
  3876. }
  3877. if (s3PLCData["OEETypeFlag_right"].ToString() == "1" && (a3OEEType_right == 1 || a3OEEType_right == 3 || a3OEEType_right == 4 || a3OEEType_right == 5))
  3878. {
  3879. 通用节拍接口(plcNo, stationNameStr,
  3880. tagBaseName + ".Right." + tagiotComnName, CarrierBarcode_Right,
  3881. stPLC_MesData.Right.iotData, out res);
  3882. if (res == 1)
  3883. {
  3884. s3PLCSignal_Old["a3OEEType_right"] = a3OEEType_right;
  3885. }
  3886. else {
  3887. s3PLCSignal_Old["a3OEEType_right"] = 0;
  3888. }
  3889. }
  3890. }
  3891. else
  3892. {
  3893. s3PLCSignal_Old["a3OEEType_right"] = 0;
  3894. }
  3895. #endregion 右工位 节拍
  3896. }
  3897. catch (Exception ex)
  3898. {
  3899. string str = ex.StackTrace;
  3900. AddMessage_Station(stationNameStr, LogType.Error,
  3901. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3902. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3903. }
  3904. #endregion
  3905. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3906. stopwatch1.Stop();
  3907. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3908. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3909. }
  3910. else
  3911. {
  3912. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3913. AddMessage_Station(stationNameStr, LogType.Info,
  3914. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3915. FunsEip[plcNo].Connect();
  3916. }
  3917. }
  3918. catch (Exception ex)
  3919. {
  3920. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3921. AddMessage_Station(stationNameStr, LogType.Error,
  3922. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3923. //Funs[plcNo].ReConnect();
  3924. }
  3925. Thread.Sleep(IntervalReadPLC);
  3926. }
  3927. }
  3928. /// <summary>
  3929. /// [S3] 点散热胶装备 - 进站
  3930. /// </summary>
  3931. /// <param name="plcNo">PLC编号</param>
  3932. /// <param name="stationNameStr">工站全称</param>
  3933. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3934. string tagBarsetName, string direction, out bool ProgressState)
  3935. {
  3936. Stopwatch stopwatch1 = new Stopwatch();
  3937. Stopwatch stopwatch2 = new Stopwatch();
  3938. try
  3939. {
  3940. stopwatch1.Start();
  3941. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  3942. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3943. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  3944. string StationId = string.Empty;
  3945. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3946. bool pass = a1Result == 1;
  3947. string slot = "";
  3948. if (direction == "Left")
  3949. {
  3950. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3951. slot = "01-SLOT-01";
  3952. }
  3953. if (direction == "Right")
  3954. {
  3955. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3956. slot = "01-SLOT-02";
  3957. }
  3958. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3959. //载具码验证产品码
  3960. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3961. if (string.IsNullOrEmpty(strProductBarcode))
  3962. {
  3963. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3964. ProgressState = false;
  3965. Thread.Sleep(10000);
  3966. return;
  3967. }
  3968. sn = strProductBarcode;
  3969. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  3970. // 产品SN(物料码)校验
  3971. List<TestItem> item = new List<TestItem>();
  3972. stopwatch2.Start();
  3973. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3974. item, MachineId, StationId, pass, slot);
  3975. stopwatch2.Stop();
  3976. //指令执行结果 1:OK 110:失败
  3977. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3978. if (mesResultFrmWeb == 1)
  3979. {
  3980. if (a1Result == 1)
  3981. {
  3982. mesResultFrmWeb = 1;
  3983. }
  3984. else
  3985. {
  3986. mesResultFrmWeb = 110;
  3987. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3988. }
  3989. }
  3990. //进站结果写入PLC
  3991. CommandFromPLC resultToPlC = new CommandFromPLC();
  3992. resultToPlC.cmd = 0;
  3993. resultToPlC.cmdParam = 0; //指令参数
  3994. resultToPlC.cmdResult = mesResultFrmWeb;
  3995. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3996. }
  3997. catch (Exception ex)
  3998. {
  3999. string str = ex.StackTrace;
  4000. AddMessage(LogType.Error,
  4001. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4002. str.Length - str.LastIndexOf("\\") - 1));
  4003. CommandFromPLC resultToPlC = new CommandFromPLC();
  4004. resultToPlC.cmd = 0;
  4005. resultToPlC.cmdParam = 0; //指令参数
  4006. resultToPlC.cmdResult = 110;
  4007. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4008. }
  4009. stopwatch1.Stop();
  4010. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  4011. AddMessage(LogType.Info,
  4012. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4013. stopwatch2.ElapsedMilliseconds + "ms");
  4014. ProgressState = false;
  4015. }
  4016. /// <summary>
  4017. /// [S3] 点散热胶装备 - 出站
  4018. /// </summary>
  4019. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  4020. string stationCode, string stationName, string direction, out bool ProgressState)
  4021. {
  4022. Stopwatch stopwatch1 = new Stopwatch();
  4023. Stopwatch stopwatch2 = new Stopwatch();
  4024. try
  4025. {
  4026. stopwatch1.Start();
  4027. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  4028. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4029. string processItem = stationName; // 测试项目
  4030. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4031. string supplierCode = ""; // 供应商代码
  4032. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4033. string batch_num = GlobalContext.BatchNumber; // 批次号
  4034. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4035. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4036. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4037. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  4038. string StationId = string.Empty;
  4039. if (direction == "Left")
  4040. {
  4041. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  4042. }
  4043. if (direction == "Right")
  4044. {
  4045. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  4046. }
  4047. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4048. bool pass = a1Result == 1;
  4049. //根据载具码获取产品码
  4050. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4051. if (string.IsNullOrEmpty(strProductBarcode))
  4052. {
  4053. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4054. ProgressState = false;
  4055. Thread.Sleep(10000);
  4056. return;
  4057. }
  4058. Console.WriteLine($"异常1:{strProductBarcode}");
  4059. sn = strProductBarcode;
  4060. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4061. List<TestItem> items = new List<TestItem>();
  4062. items.Add(new TestItem()
  4063. {
  4064. Parameter_name = "载具码",
  4065. Parameter_value = CarrierBarcode,
  4066. Parameter_unit = ""
  4067. });
  4068. items.Add(new TestItem()
  4069. {
  4070. Parameter_name = "产品码",
  4071. Parameter_value = sn,
  4072. Parameter_unit = ""
  4073. });
  4074. //if (direction == "Right")
  4075. //{
  4076. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData).Replace("null","0");
  4077. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4078. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  4079. MachineId, StationId, "", paramJson, direction);
  4080. //}
  4081. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4082. if (mesResultFrmWeb == 1)
  4083. {
  4084. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4085. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4086. }
  4087. stopwatch2.Start();
  4088. //进站结果写入PLC
  4089. CommandFromPLC resultToPlC = new CommandFromPLC();
  4090. resultToPlC.cmd = 0;
  4091. resultToPlC.cmdParam = 0; //指令参数
  4092. resultToPlC.cmdResult = mesResultFrmWeb;
  4093. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4094. stopwatch2.Stop();
  4095. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  4096. //保存PLC返回MES数据到本地
  4097. ResponseMessage message = new ResponseMessage();
  4098. if (direction == "Left")
  4099. {
  4100. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  4101. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  4102. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  4103. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  4104. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  4105. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  4106. if (message.result == false)
  4107. {
  4108. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4109. }
  4110. }
  4111. if (direction == "Right")
  4112. {
  4113. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  4114. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  4115. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  4116. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  4117. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  4118. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  4119. if (message.result == false)
  4120. {
  4121. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4122. }
  4123. }
  4124. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4125. }
  4126. catch (Exception ex)
  4127. {
  4128. stopwatch2.Start();
  4129. CommandFromPLC resultToPlC = new CommandFromPLC();
  4130. resultToPlC.cmd = 0;
  4131. resultToPlC.cmdParam = 0; //指令参数
  4132. resultToPlC.cmdResult = 110;
  4133. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4134. stopwatch2.Stop();
  4135. string str = ex.StackTrace;
  4136. AddMessage(LogType.Error,
  4137. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4138. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4139. }
  4140. stopwatch1.Stop();
  4141. AddMessage(LogType.Info,
  4142. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4143. stopwatch2.ElapsedMilliseconds + "ms");
  4144. ProgressState = false;
  4145. if (direction == "Left") uuid = "";
  4146. if (direction == "Right") uuid2 = "";
  4147. }
  4148. #endregion S3
  4149. #region S4
  4150. /// <summary>
  4151. /// [S4] 点胶检测设备
  4152. /// </summary>
  4153. /// <param name="plcNo">PLC编号</param>
  4154. private void ReadStation_S4(int plcNo)
  4155. {
  4156. string stationCode = "[OP40]";
  4157. string stationName = "胶线检测";
  4158. string stationNameStr = stationCode + stationName;
  4159. string tagBaseName = "g_OP40_MES"; //标签变量名称
  4160. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4161. string tagAgvCommName = "agvCommFrmPC";
  4162. string tagiotComnName = "iotData";
  4163. string tagBarsetName = "BarcodeSet";
  4164. string CarrierBarcode = "";
  4165. // 触发信号字典
  4166. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4167. s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
  4168. // PLC数据字典 赋值
  4169. s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
  4170. s4PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  4171. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  4172. (int, string) result;
  4173. while (true)
  4174. {
  4175. try
  4176. {
  4177. if (!GlobalContext._IsCon_Funs1)
  4178. {
  4179. UpdatePLCMonitor(1, plcNo, 0);
  4180. continue;
  4181. }
  4182. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4183. {
  4184. Stopwatch stopwatch1 = new Stopwatch();
  4185. Stopwatch stopwatch2 = new Stopwatch();
  4186. stopwatch1.Start();
  4187. stopwatch2.Start();
  4188. #region 一次性读取所有数据
  4189. // 一次性读取所有数据
  4190. result = FunsEip[plcNo]
  4191. .Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4192. if (result.Item1 != 0)
  4193. {
  4194. //richTextBox1.AppendText("\n" + strRet);
  4195. }
  4196. else
  4197. {
  4198. //去除扫码产生的特殊字符
  4199. stPLC_MesData.BarcodeSet.strProductBarcode =
  4200. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4201. stPLC_MesData.BarcodeSet.strPartBarcode =
  4202. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4203. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4204. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4205. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4206. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4207. //richTextBox1.AppendText("\n" + "读取成功");
  4208. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4209. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4210. ? XiaomiDeviceState.Unknown
  4211. : (XiaomiDeviceState)xmDeviceStateInt;
  4212. // 载具SN
  4213. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode;
  4214. // 节拍
  4215. s4PLCData["a4OEEType"] = stPLC_MesData.iotData.beatAction;
  4216. //报警信息
  4217. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4218. }
  4219. #endregion 一次性读取所有数据
  4220. stopwatch2.Stop();
  4221. #region 进站
  4222. try
  4223. {
  4224. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4225. {
  4226. lock (lockObj)
  4227. {
  4228. if (!ProgressState)
  4229. {
  4230. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4231. ProgressState = true;
  4232. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
  4233. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4234. out ProgressState));
  4235. }
  4236. }
  4237. }
  4238. }
  4239. catch (Exception ex)
  4240. {
  4241. ProgressState = false;
  4242. string str = ex.StackTrace;
  4243. AddMessage_Station(stationNameStr, LogType.Error,
  4244. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4245. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4246. }
  4247. #endregion 进站
  4248. #region 出站
  4249. try
  4250. {
  4251. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4252. {
  4253. lock (lockObj)
  4254. {
  4255. if (!ProgressState)
  4256. {
  4257. ProgressState = true;
  4258. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
  4259. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4260. out ProgressState));
  4261. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4262. }
  4263. }
  4264. }
  4265. }
  4266. catch (Exception ex)
  4267. {
  4268. string str = ex.StackTrace;
  4269. AddMessage_Station(stationNameStr, LogType.Error,
  4270. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4271. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4272. }
  4273. #endregion 出站
  4274. #region 节拍接口
  4275. try
  4276. {
  4277. if (stPLC_MesData.iotData.beatAction > 0)
  4278. {
  4279. int a4OEEType = Convert.ToInt32(s4PLCData["a4OEEType"]);
  4280. int a4OEETypeGOld = Convert.ToInt32(s4PLCSignal_Old["a4OEEType"]);
  4281. //若设备紧急复原后节拍重置
  4282. if (a4OEEType == 1)
  4283. {
  4284. a4OEETypeGOld = 0;
  4285. }
  4286. if (a4OEEType != a4OEETypeGOld)
  4287. {
  4288. s4PLCData["OEETypeFlag"] = "1";
  4289. }
  4290. else
  4291. {
  4292. s4PLCData["OEETypeFlag"] = "0";
  4293. }
  4294. if (s4PLCData["OEETypeFlag"].ToString() == "1" && (a4OEEType == 1 || a4OEEType == 3 || a4OEEType == 4 || a4OEEType == 5))
  4295. {
  4296. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  4297. if (res == 1)
  4298. {
  4299. s4PLCSignal_Old["a4OEEType"] = s4PLCData["a4OEEType"];
  4300. }
  4301. else
  4302. {
  4303. s4PLCSignal_Old["a4OEEType"] = 0;
  4304. }
  4305. }
  4306. }
  4307. else {
  4308. s4PLCSignal_Old["a4OEEType"] = 0;
  4309. }
  4310. }
  4311. catch (Exception ex)
  4312. {
  4313. string str = ex.StackTrace;
  4314. AddMessage_Station(stationNameStr, LogType.Error,
  4315. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4316. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4317. }
  4318. #endregion
  4319. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4320. stopwatch1.Stop();
  4321. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4322. }
  4323. else
  4324. {
  4325. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4326. AddMessage_Station(stationNameStr, LogType.Info,
  4327. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4328. FunsEip[plcNo].Connect(); // 重连
  4329. }
  4330. }
  4331. catch (Exception ex)
  4332. {
  4333. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4334. AddMessage_Station(stationNameStr, LogType.Error,
  4335. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4336. }
  4337. Thread.Sleep(IntervalReadPLC);
  4338. }
  4339. }
  4340. /// <summary>
  4341. /// [S4] 点胶检测设备 - 进站
  4342. /// </summary>
  4343. /// <param name="plcNo">PLC编号</param>
  4344. /// <param name="stationNameStr">工站全称</param>
  4345. /// <param name="stPLC_MesData"></param>
  4346. /// <param name="tagMesCommName"></param>
  4347. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4348. string tagBarsetName, out bool ProgressState)
  4349. {
  4350. Stopwatch stopwatch1 = new Stopwatch();
  4351. Stopwatch stopwatch2 = new Stopwatch();
  4352. try
  4353. {
  4354. stopwatch1.Start();
  4355. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4356. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4357. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  4358. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  4359. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4360. bool pass = a1Result == 1;
  4361. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4362. //载具码验证产品码
  4363. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4364. if (string.IsNullOrEmpty(strProductBarcode))
  4365. {
  4366. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4367. ProgressState = false;
  4368. Thread.Sleep(10000);
  4369. return;
  4370. }
  4371. sn = strProductBarcode;
  4372. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4373. // 产品SN(物料码)校验
  4374. List<TestItem> item = new List<TestItem>();
  4375. stopwatch2.Start();
  4376. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4377. item, MachineId, StationId, pass, "01-SLOT-01");
  4378. stopwatch2.Stop();
  4379. //指令执行结果 1:OK 110:失败
  4380. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4381. if (mesResultFrmWeb == 1)
  4382. {
  4383. if (a1Result == 1)
  4384. {
  4385. mesResultFrmWeb = 1;
  4386. }
  4387. else
  4388. {
  4389. mesResultFrmWeb = 110;
  4390. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4391. }
  4392. }
  4393. //进站结果写入PLC
  4394. CommandFromPLC resultToPlC = new CommandFromPLC();
  4395. resultToPlC.cmd = 0;
  4396. resultToPlC.cmdParam = 0; //指令参数
  4397. resultToPlC.cmdResult = mesResultFrmWeb;
  4398. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4399. }
  4400. catch (Exception ex)
  4401. {
  4402. string str = ex.StackTrace;
  4403. AddMessage(LogType.Error,
  4404. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4405. str.Length - str.LastIndexOf("\\") - 1));
  4406. CommandFromPLC resultToPlC = new CommandFromPLC();
  4407. resultToPlC.cmd = 0;
  4408. resultToPlC.cmdParam = 0; //指令参数
  4409. resultToPlC.cmdResult = 110;
  4410. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4411. }
  4412. stopwatch1.Stop();
  4413. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4414. AddMessage(LogType.Info,
  4415. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4416. stopwatch2.ElapsedMilliseconds + "ms");
  4417. ProgressState = false;
  4418. }
  4419. /// <summary>
  4420. /// [S4] 点胶检测设备 - 出站接口
  4421. /// </summary>
  4422. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4423. string stationCode, string stationName, out bool ProgressState)
  4424. {
  4425. Stopwatch stopwatch1 = new Stopwatch();
  4426. Stopwatch stopwatch2 = new Stopwatch();
  4427. try
  4428. {
  4429. stopwatch1.Start();
  4430. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4431. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4432. string processItem = stationName; // 测试项目
  4433. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4434. string supplierCode = ""; // 供应商代码
  4435. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4436. string batch_num = GlobalContext.BatchNumber; // 批次号
  4437. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4438. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4439. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4440. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  4441. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  4442. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4443. bool pass = a1Result == 1;
  4444. //根据载具码获取产品码
  4445. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4446. if (string.IsNullOrEmpty(strProductBarcode))
  4447. {
  4448. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4449. ProgressState = false;
  4450. Thread.Sleep(10000);
  4451. return;
  4452. }
  4453. sn = strProductBarcode;
  4454. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4455. List<TestItem> items = new List<TestItem>();
  4456. items.Add(new TestItem()
  4457. {
  4458. Parameter_name = "载具码",
  4459. Parameter_value = CarrierBarcode,
  4460. Parameter_unit = ""
  4461. });
  4462. items.Add(new TestItem()
  4463. {
  4464. Parameter_name = "产品码",
  4465. Parameter_value = sn,
  4466. Parameter_unit = ""
  4467. });
  4468. #region 上传图片
  4469. if (GlobalContext.MQTTIsSendUpFile)
  4470. {
  4471. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4472. fileUploadData.fileData.Clear();
  4473. foreach (var item in urlarry)
  4474. {
  4475. if (!string.IsNullOrEmpty(item))
  4476. {
  4477. //上传图片
  4478. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4479. item, uuid).Result;
  4480. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4481. }
  4482. }
  4483. }
  4484. #endregion
  4485. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4486. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4487. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode,
  4488. "01-SLOT-01", MachineId, StationId, "", paramJson);
  4489. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4490. if (mesResultFrmWeb == 1)
  4491. {
  4492. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4493. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4494. }
  4495. stopwatch2.Start();
  4496. //进站结果写入PLC
  4497. CommandFromPLC resultToPlC = new CommandFromPLC();
  4498. resultToPlC.cmd = 0;
  4499. resultToPlC.cmdParam = 0; //指令参数
  4500. resultToPlC.cmdResult = mesResultFrmWeb;
  4501. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4502. stopwatch2.Stop();
  4503. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4504. //保存PLC返回MES数据到本地
  4505. ResponseMessage message = new ResponseMessage();
  4506. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  4507. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  4508. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  4509. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  4510. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  4511. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  4512. if (message.result == false)
  4513. {
  4514. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4515. }
  4516. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4517. }
  4518. catch (Exception ex)
  4519. {
  4520. stopwatch2.Start();
  4521. CommandFromPLC resultToPlC = new CommandFromPLC();
  4522. resultToPlC.cmd = 0;
  4523. resultToPlC.cmdParam = 0; //指令参数
  4524. resultToPlC.cmdResult = 110;
  4525. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4526. stopwatch2.Stop();
  4527. string str = ex.StackTrace;
  4528. AddMessage(LogType.Error,
  4529. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4530. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4531. }
  4532. stopwatch1.Stop();
  4533. AddMessage(LogType.Info,
  4534. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4535. stopwatch2.ElapsedMilliseconds + "ms");
  4536. ProgressState = false;
  4537. uuid = "";
  4538. }
  4539. #endregion
  4540. #region S5
  4541. private static bool isPCBStation = false; //控制PCB是否进出站的标识
  4542. /// <summary>
  4543. /// [S5] 点胶检测设备
  4544. /// </summary>
  4545. /// <param name="plcNo">PLC编号</param>
  4546. private void ReadStation_S5(int plcNo)
  4547. {
  4548. string stationCode = "[OP50]";
  4549. string stationName = "ADD板上料组装装备";
  4550. string stationNameStr = stationCode + stationName;
  4551. string tagBaseName = "g_OP50_MES"; //标签变量名称
  4552. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4553. string tagAgvCommName = "agvCommFrmPC";
  4554. string tagiotComnName = "iotData";
  4555. string tagBarsetName = "BarcodeSet";
  4556. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  4557. string CarrierBarcode = "";
  4558. // 触发信号字典
  4559. s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4560. // PLC数据字典 赋值
  4561. s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4562. s5PLCData.Add("OEETypeFlag", 0); // 节拍标识 0 不上传 ,1 上传
  4563. (int, string) result;
  4564. while (true)
  4565. {
  4566. try
  4567. {
  4568. if (!GlobalContext._IsCon_Funs1)
  4569. {
  4570. UpdatePLCMonitor(1, plcNo, 0);
  4571. continue;
  4572. }
  4573. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4574. {
  4575. Stopwatch stopwatch1 = new Stopwatch();
  4576. Stopwatch stopwatch2 = new Stopwatch();
  4577. stopwatch1.Start();
  4578. stopwatch2.Start();
  4579. #region 一次性读取所有数据
  4580. // 一次性读取所有数据
  4581. result = FunsEip[plcNo]
  4582. .Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4583. if (result.Item1 != 0)
  4584. {
  4585. }
  4586. else
  4587. {
  4588. //测试数据
  4589. //stPLC_MesData.mesCommFrmPLC.cmd = 2;
  4590. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A235461";
  4591. //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
  4592. //stPLC_MesData.iotData.beatAction = 1;
  4593. //stPLC_MesData.iotData.beatAction = 2;
  4594. //stPLC_MesData.iotData.beatAction = 3;
  4595. //stPLC_MesData.iotData.beatAction = 4;
  4596. //stPLC_MesData.iotData.beatAction = 5;
  4597. //stPLC_MesData.iotData.beatAction = 6;
  4598. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  4599. #region 去除扫码产生的特殊字符
  4600. stPLC_MesData.BarcodeSet.strProductBarcode =
  4601. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4602. stPLC_MesData.BarcodeSet.strPartBarcode =
  4603. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4604. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4605. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4606. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4607. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4608. #endregion
  4609. //richTextBox1.AppendText("\n" + "读取成功");
  4610. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4611. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4612. ? XiaomiDeviceState.Unknown
  4613. : (XiaomiDeviceState)xmDeviceStateInt;
  4614. // 节拍
  4615. s5PLCData["a5OEEType"] = stPLC_MesData.iotData.beatAction;
  4616. //载具码
  4617. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  4618. //报警信息
  4619. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4620. }
  4621. #endregion 一次性读取所有数据
  4622. stopwatch2.Stop();
  4623. #region 进站
  4624. try
  4625. {
  4626. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4627. {
  4628. lock (lockObj)
  4629. {
  4630. if (!ProgressState)
  4631. {
  4632. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4633. ProgressState = true;
  4634. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  4635. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  4636. {
  4637. ProgressState = true;
  4638. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData,
  4639. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4640. out ProgressState));
  4641. }
  4642. }
  4643. }
  4644. }
  4645. }
  4646. catch (Exception ex)
  4647. {
  4648. ProgressState = false;
  4649. string str = ex.StackTrace;
  4650. AddMessage_Station(stationNameStr, LogType.Error,
  4651. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4652. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4653. }
  4654. #endregion 进站
  4655. #region 出站
  4656. try
  4657. {
  4658. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4659. {
  4660. lock (lockObj)
  4661. {
  4662. if (!ProgressState)
  4663. {
  4664. ProgressState = true;
  4665. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
  4666. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4667. out ProgressState));
  4668. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4669. }
  4670. }
  4671. }
  4672. }
  4673. catch (Exception ex)
  4674. {
  4675. ProgressState = false;
  4676. string str = ex.StackTrace;
  4677. AddMessage_Station(stationNameStr, LogType.Error,
  4678. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4679. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4680. }
  4681. #endregion 出站
  4682. #region 节拍接口
  4683. try
  4684. {
  4685. if (stPLC_MesData.iotData.beatAction > 0)
  4686. {
  4687. int a5OEEType = Convert.ToInt32(s5PLCData["a5OEEType"]);
  4688. int a5OEETypeGOld = Convert.ToInt32(s5PLCSignal_Old["a5OEEType"]);
  4689. if (a5OEEType != a5OEETypeGOld)
  4690. {
  4691. s5PLCData["OEETypeFlag"] = "1";
  4692. }
  4693. else
  4694. {
  4695. s5PLCData["OEETypeFlag"] = "0";
  4696. }
  4697. if (s5PLCData["OEETypeFlag"].ToString() == "1" && (a5OEEType == 1 || a5OEEType == 3 || a5OEEType == 4 || a5OEEType == 5))
  4698. {
  4699. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  4700. if (res == 1)
  4701. {
  4702. s5PLCSignal_Old["a5OEEType"] = s5PLCData["a5OEEType"];
  4703. }
  4704. else {
  4705. s5PLCSignal_Old["a5OEEType"] = 0;
  4706. }
  4707. }
  4708. }
  4709. else {
  4710. s5PLCSignal_Old["a5OEEType"] = 0;
  4711. }
  4712. }
  4713. catch (Exception ex)
  4714. {
  4715. string str = ex.StackTrace;
  4716. AddMessage_Station(stationNameStr, LogType.Error,
  4717. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4718. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4719. }
  4720. #endregion
  4721. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4722. stopwatch1.Stop();
  4723. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4724. }
  4725. else
  4726. {
  4727. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4728. AddMessage_Station(stationNameStr, LogType.Info,
  4729. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4730. FunsEip[plcNo].Connect(); // 重连
  4731. }
  4732. }
  4733. catch (Exception ex)
  4734. {
  4735. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4736. AddMessage_Station(stationNameStr, LogType.Error,
  4737. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4738. }
  4739. Thread.Sleep(IntervalReadPLC);
  4740. }
  4741. }
  4742. /// <summary>
  4743. /// [S5] 点胶检测设备 - 进站
  4744. /// </summary>
  4745. /// <param name="plcNo">PLC编号</param>
  4746. /// <param name="stationNameStr">工站全称</param>
  4747. /// <param name="stPLC_MesData"></param>
  4748. /// <param name="tagMesCommName"></param>
  4749. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4750. string tagBarsetName, out bool ProgressState)
  4751. {
  4752. Stopwatch stopwatch1 = new Stopwatch();
  4753. Stopwatch stopwatch2 = new Stopwatch();
  4754. try
  4755. {
  4756. stopwatch1.Start();
  4757. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4758. //string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4759. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  4760. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  4761. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  4762. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  4763. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4764. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4765. bool pass = a1Result == 1;
  4766. AddMessage(LogType.Info, $"ADD板编码(PCB码):{pcbBarcode}");
  4767. //绑定载具和产品
  4768. //ResponseMessage message = new ResponseMessage();
  4769. //message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
  4770. //if (message.result == false)
  4771. //{
  4772. // AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  4773. // ProgressState = false;
  4774. // Thread.Sleep(10000);
  4775. // return;
  4776. //}
  4777. //载具码验证产品码 //载具码验证产品码
  4778. //string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4779. //if (string.IsNullOrEmpty(strProductBarcode))
  4780. //{
  4781. // AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4782. //}
  4783. //sn = strProductBarcode;
  4784. //AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4785. // 产品SN(物料码)校验
  4786. List<TestItem> item = new List<TestItem>();
  4787. stopwatch2.Start();
  4788. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  4789. pcbBarcode,
  4790. item, MachineId, StationId, pass, "01-SLOT-01");
  4791. stopwatch2.Stop();
  4792. //指令执行结果 1:OK 110:失败
  4793. byte mesResultFrmWeb = (byte)(result == 1 ? 2 : 120);
  4794. if (mesResultFrmWeb == 1)
  4795. {
  4796. if (a1Result == 1)
  4797. {
  4798. mesResultFrmWeb = 2;
  4799. }
  4800. else
  4801. {
  4802. mesResultFrmWeb = 120;
  4803. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4804. }
  4805. }
  4806. //进站结果写入PLC
  4807. CommandFromPLC resultToPlC = new CommandFromPLC();
  4808. resultToPlC.cmd = 0;
  4809. resultToPlC.cmdParam = 0; //指令参数
  4810. resultToPlC.cmdResult = mesResultFrmWeb;
  4811. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4812. }
  4813. catch (Exception ex)
  4814. {
  4815. string str = ex.StackTrace;
  4816. AddMessage(LogType.Error,
  4817. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4818. str.Length - str.LastIndexOf("\\") - 1));
  4819. CommandFromPLC resultToPlC = new CommandFromPLC();
  4820. resultToPlC.cmd = 0;
  4821. resultToPlC.cmdParam = 0; //指令参数
  4822. resultToPlC.cmdResult = 120;
  4823. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4824. }
  4825. stopwatch1.Stop();
  4826. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4827. AddMessage(LogType.Info,
  4828. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4829. stopwatch2.ElapsedMilliseconds + "ms");
  4830. ProgressState = false;
  4831. }
  4832. /// <summary>
  4833. /// [S5] 点胶检测设备 - 出站接口
  4834. /// </summary>
  4835. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4836. string stationCode, string stationName, out bool ProgressState)
  4837. {
  4838. Stopwatch stopwatch1 = new Stopwatch();
  4839. Stopwatch stopwatch2 = new Stopwatch();
  4840. try
  4841. {
  4842. stopwatch1.Start();
  4843. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4844. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4845. string processItem = stationName; // 测试项目
  4846. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4847. string supplierCode = ""; // 供应商代码
  4848. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4849. string batch_num = GlobalContext.BatchNumber; // 批次号
  4850. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4851. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4852. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 部件条码;
  4853. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4854. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4855. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  4856. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  4857. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4858. bool pass = a1Result == 1;
  4859. CommandFromPLC resultToPlC = new CommandFromPLC();
  4860. //根据载具码获取产品码
  4861. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4862. if (string.IsNullOrEmpty(strProductBarcode))
  4863. {
  4864. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4865. ProgressState = false;
  4866. Thread.Sleep(10000);
  4867. return;
  4868. }
  4869. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  4870. sn = strProductBarcode;
  4871. //数据库绑定载具和PCB
  4872. ResponseMessage message = new ResponseMessage();
  4873. message = SQLHelper.PCBCarrierBind(CarrierBarcode, pcbBarcode);
  4874. if (message.result == false)
  4875. {
  4876. AddMessage(LogType.Error, stationNameStr + "_PCB码数据库绑定失败,错误:" + message.text);
  4877. ProgressState = true; //防止循环报错
  4878. return;
  4879. }
  4880. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  4881. List<TestItem> items = new List<TestItem>();
  4882. items.Add(new TestItem()
  4883. {
  4884. Parameter_name = "载具码",
  4885. Parameter_value = CarrierBarcode,
  4886. Parameter_unit = ""
  4887. });
  4888. items.Add(new TestItem()
  4889. {
  4890. Parameter_name = "产品码",
  4891. Parameter_value = sn,
  4892. Parameter_unit = ""
  4893. });
  4894. items.Add(new TestItem()
  4895. {
  4896. Parameter_name = "PCB码",
  4897. Parameter_value = pcbBarcode,
  4898. Parameter_unit = ""
  4899. });
  4900. #region 上传图片
  4901. if (GlobalContext.MQTTIsSendUpFile)
  4902. {
  4903. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4904. fileUploadData.fileData.Clear();
  4905. foreach (var item in urlarry)
  4906. {
  4907. if (!string.IsNullOrEmpty(item))
  4908. {
  4909. //上传图片
  4910. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4911. item, uuid).Result;
  4912. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4913. }
  4914. }
  4915. }
  4916. #endregion
  4917. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4918. int result1 = 0;
  4919. byte mesResultFrmWeb = 0;
  4920. if (stPLC_MesData.mesCommFrmPLC.cmdParam == 2)
  4921. {
  4922. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  4923. batch_num
  4924. , mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId,
  4925. PartBarcode, paramJson);
  4926. }
  4927. else if (stPLC_MesData.mesCommFrmPLC.cmdParam == 1)
  4928. {
  4929. result1 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4930. }
  4931. mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4932. //进站结果写入PLC
  4933. resultToPlC.cmd = 0;
  4934. resultToPlC.cmdParam = 0; //指令参数
  4935. resultToPlC.cmdResult = mesResultFrmWeb;
  4936. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4937. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4938. //保存PLC返回MES数据到本地
  4939. //ResponseMessage message = new ResponseMessage();
  4940. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  4941. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB,
  4942. stPLC_MesData.mesData.nRemainCount, "");
  4943. if (message.result == false)
  4944. {
  4945. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4946. }
  4947. //保存部件码信息
  4948. if (!string.IsNullOrEmpty(PartBarcode))
  4949. {
  4950. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  4951. if (message.result == false)
  4952. {
  4953. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  4954. }
  4955. }
  4956. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4957. }
  4958. catch (Exception ex)
  4959. {
  4960. stopwatch2.Start();
  4961. CommandFromPLC resultToPlC = new CommandFromPLC();
  4962. resultToPlC.cmd = 0;
  4963. resultToPlC.cmdParam = 0; //指令参数
  4964. resultToPlC.cmdResult = 110;
  4965. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4966. stopwatch2.Stop();
  4967. string str = ex.StackTrace;
  4968. AddMessage(LogType.Error,
  4969. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4970. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4971. }
  4972. stopwatch1.Stop();
  4973. AddMessage(LogType.Info,
  4974. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4975. stopwatch2.ElapsedMilliseconds + "ms");
  4976. ProgressState = false;
  4977. uuid = "";
  4978. }
  4979. private int S5_PCB进出站(OP50_MesData_t stPLC_MesData, int plcNo, string stationNameStr, string tagBaseName,
  4980. string tagMesCommName)
  4981. {
  4982. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  4983. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  4984. {
  4985. string strProductBarcode =
  4986. SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4987. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  4988. CommandFromPLC resultToPlC = new CommandFromPLC();
  4989. resultToPlC.cmd = 0;
  4990. resultToPlC.cmdParam = 0; //指令参数
  4991. if (GlobalContext.IsSendStationIn)
  4992. {
  4993. #region 进站
  4994. //int res1 = PCBStationInData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4995. //if (res1 == 1)
  4996. //{
  4997. // resultToPlC.cmdResult = 2;//OK
  4998. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4999. //}
  5000. //else
  5001. //{
  5002. // resultToPlC.cmdResult = 120;
  5003. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5004. // return 2;
  5005. //}
  5006. #endregion
  5007. #region 出站
  5008. int res2 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  5009. if (res2 == 1)
  5010. {
  5011. resultToPlC.cmdResult = 2; //OK
  5012. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5013. return 1;
  5014. }
  5015. else
  5016. {
  5017. resultToPlC.cmdResult = 120;
  5018. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5019. return 2;
  5020. }
  5021. #endregion
  5022. }
  5023. else
  5024. {
  5025. return 2;
  5026. }
  5027. }
  5028. else
  5029. {
  5030. return 2;
  5031. }
  5032. }
  5033. #endregion
  5034. #region S6
  5035. private Dictionary<string, object> s6PLCData = new Dictionary<string, object>();
  5036. private Dictionary<string, object> s6PLCSignal_Old = new Dictionary<string, object>();
  5037. /// <summary>
  5038. /// [S6] 顶盖装配设备
  5039. /// </summary>
  5040. /// <param name="plcNo">PLC编号</param>
  5041. public void ReadStation_S6(int plcNo)
  5042. {
  5043. string stationCode = "[OP70]";
  5044. string stationName = "组上盖板";
  5045. string stationNameStr = stationCode + stationName;
  5046. string tagBaseName = "g_OP60_MES"; //标签变量名称
  5047. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5048. string tagAgvCommName = "agvCommFrmPC";
  5049. string tagiotComnName = "iotData";
  5050. string tagBarsetName = "BarcodeSet";
  5051. string CarrierBarcode = "";
  5052. // 触发信号字典
  5053. s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
  5054. // PLC数据字典 赋值
  5055. s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
  5056. s6PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  5057. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  5058. (int, string) result;
  5059. while (true)
  5060. {
  5061. try
  5062. {
  5063. if (!GlobalContext._IsCon_Funs1)
  5064. {
  5065. UpdatePLCMonitor(1, plcNo, 0);
  5066. continue;
  5067. }
  5068. if (StopWhile)
  5069. {
  5070. continue;
  5071. }
  5072. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5073. {
  5074. Stopwatch stopwatch1 = new Stopwatch();
  5075. Stopwatch stopwatch2 = new Stopwatch();
  5076. stopwatch1.Start();
  5077. stopwatch2.Start();
  5078. #region 一次性读取所有数据
  5079. // 一次性读取所有数据
  5080. result = FunsEip[plcNo]
  5081. .Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5082. if (result.Item1 != 0)
  5083. {
  5084. //richTextBox1.AppendText("\n" + strRet);
  5085. }
  5086. else
  5087. {
  5088. //测试
  5089. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  5090. //stPLC_MesData.mesCommFrmPLC.cmd = 1;
  5091. //去除扫码产生的特殊字符
  5092. stPLC_MesData.BarcodeSet.strProductBarcode =
  5093. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  5094. stPLC_MesData.BarcodeSet.strPartBarcode =
  5095. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  5096. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  5097. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  5098. stPLC_MesData.BarcodeSet.strPCBBarcode =
  5099. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  5100. //richTextBox1.AppendText("\n" + "读取成功");
  5101. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  5102. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  5103. ? XiaomiDeviceState.Unknown
  5104. : (XiaomiDeviceState)xmDeviceStateInt;
  5105. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  5106. s6PLCData["a6OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  5107. //报警信息
  5108. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  5109. }
  5110. #endregion 一次性读取所有数据
  5111. stopwatch2.Stop();
  5112. #region 进站
  5113. try
  5114. {
  5115. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5116. {
  5117. lock (lockObj)
  5118. {
  5119. if (!ProgressState)
  5120. {
  5121. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5122. ProgressState = true;
  5123. //载具码验证产品码
  5124. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
  5125. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  5126. out ProgressState));
  5127. }
  5128. }
  5129. }
  5130. }
  5131. catch (Exception ex)
  5132. {
  5133. ProgressState = false;
  5134. string str = ex.StackTrace;
  5135. AddMessage_Station(stationNameStr, LogType.Error,
  5136. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5137. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5138. }
  5139. #endregion 进站
  5140. #region 出站
  5141. try
  5142. {
  5143. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5144. {
  5145. lock (lockObj)
  5146. {
  5147. if (!ProgressState)
  5148. {
  5149. ProgressState = true;
  5150. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
  5151. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5152. out ProgressState));
  5153. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5154. }
  5155. }
  5156. }
  5157. }
  5158. catch (Exception ex)
  5159. {
  5160. ProgressState = false;
  5161. string str = ex.StackTrace;
  5162. AddMessage_Station(stationNameStr, LogType.Error,
  5163. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5164. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5165. }
  5166. #endregion 出站
  5167. #region 节拍接口
  5168. try
  5169. {
  5170. if (stPLC_MesData.iotData.beatAction > 0)
  5171. {
  5172. int a6OEEType = Convert.ToInt32(s6PLCData["a6OEEType"]);
  5173. int a6OEETypeGOld = Convert.ToInt32(s6PLCSignal_Old["a6OEEType"]);
  5174. if (a6OEEType != a6OEETypeGOld)
  5175. {
  5176. s6PLCData["OEETypeFlag"] = "1";
  5177. }
  5178. else
  5179. {
  5180. s6PLCData["OEETypeFlag"] = "0";
  5181. }
  5182. if (s6PLCData["OEETypeFlag"].ToString() == "1" && (a6OEEType == 1 || a6OEEType == 3 || a6OEEType == 4 || a6OEEType == 5))
  5183. {
  5184. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  5185. if (res == 1)
  5186. {
  5187. s6PLCSignal_Old["a6OEEType"] = s6PLCData["a6OEEType"];
  5188. }
  5189. else
  5190. {
  5191. s6PLCSignal_Old["a6OEEType"] = 0;
  5192. }
  5193. }
  5194. }
  5195. else {
  5196. s6PLCSignal_Old["a6OEEType"] = 0;
  5197. }
  5198. }
  5199. catch (Exception ex)
  5200. {
  5201. string str = ex.StackTrace;
  5202. AddMessage_Station(stationNameStr, LogType.Error,
  5203. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5204. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5205. }
  5206. #endregion
  5207. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5208. stopwatch1.Stop();
  5209. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5210. }
  5211. else
  5212. {
  5213. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5214. AddMessage_Station(stationNameStr, LogType.Info,
  5215. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5216. FunsEip[plcNo].Connect(); // 重连
  5217. }
  5218. }
  5219. catch (Exception ex)
  5220. {
  5221. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5222. AddMessage_Station(stationNameStr, LogType.Error,
  5223. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5224. }
  5225. Thread.Sleep(IntervalReadPLC);
  5226. }
  5227. }
  5228. /// <summary>
  5229. /// [S6] 顶盖装配设备 - 进站
  5230. /// </summary>
  5231. /// <param name="plcNo">PLC编号</param>
  5232. /// <param name="stationNameStr">工站全称</param>
  5233. /// <param name="stPLC_MesData"></param>
  5234. /// <param name="tagMesCommName"></param>
  5235. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5236. string tagBarsetName, out bool ProgressState)
  5237. {
  5238. Stopwatch stopwatch1 = new Stopwatch();
  5239. Stopwatch stopwatch2 = new Stopwatch();
  5240. try
  5241. {
  5242. stopwatch1.Start();
  5243. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5244. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5245. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  5246. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  5247. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5248. bool pass = a1Result == 1;
  5249. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5250. string ProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5251. string PCBBarcode = SQLHelper.GetPCBBarcodeByCarrierCode(strCarrierBarcode);
  5252. //strCarrierBarcode = "N801A-003";
  5253. //载具码验证产品码
  5254. if (string.IsNullOrEmpty(ProductBarcode))
  5255. {
  5256. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5257. ProgressState = false;
  5258. Thread.Sleep(10000);
  5259. return;
  5260. }
  5261. sn = ProductBarcode;
  5262. if (OpenDailogFalg)
  5263. {
  5264. using (var dialog = new BandBarodeDialog(strCarrierBarcode, ProductBarcode, PCBBarcode))
  5265. {
  5266. var rs = dialog.ShowDialog();
  5267. if (rs == DialogResult.OK)
  5268. {
  5269. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode}");
  5270. OpenDailogFalg = false; //关闭扫码
  5271. StopWhile = false;//开启while循环
  5272. }
  5273. else
  5274. {
  5275. ProgressState = false;
  5276. return;
  5277. }
  5278. }
  5279. }
  5280. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5281. // 产品SN(物料码)校验
  5282. List<TestItem> item = new List<TestItem>();
  5283. stopwatch2.Start();
  5284. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5285. item, MachineId, StationId, pass, "01-SLOT-01");
  5286. stopwatch2.Stop();
  5287. //指令执行结果 1:OK 110:失败
  5288. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5289. if (mesResultFrmWeb == 1)
  5290. {
  5291. if (a1Result == 1)
  5292. {
  5293. mesResultFrmWeb = 1;
  5294. }
  5295. else
  5296. {
  5297. mesResultFrmWeb = 110;
  5298. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5299. }
  5300. }
  5301. //进站结果写入PLC
  5302. CommandFromPLC resultToPlC = new CommandFromPLC();
  5303. resultToPlC.cmd = 0;
  5304. resultToPlC.cmdParam = 0; //指令参数
  5305. resultToPlC.cmdResult = mesResultFrmWeb;
  5306. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5307. }
  5308. catch (Exception ex)
  5309. {
  5310. string str = ex.StackTrace;
  5311. AddMessage(LogType.Error,
  5312. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5313. str.Length - str.LastIndexOf("\\") - 1));
  5314. CommandFromPLC resultToPlC = new CommandFromPLC();
  5315. resultToPlC.cmd = 0;
  5316. resultToPlC.cmdParam = 0; //指令参数
  5317. resultToPlC.cmdResult = 110;
  5318. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5319. }
  5320. stopwatch1.Stop();
  5321. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  5322. AddMessage(LogType.Info,
  5323. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5324. stopwatch2.ElapsedMilliseconds + "ms");
  5325. ProgressState = false;
  5326. }
  5327. /// <summary>
  5328. /// [S6] 顶盖装配设备 - 出站接口
  5329. /// </summary>
  5330. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5331. string stationCode, string stationName, out bool ProgressState)
  5332. {
  5333. Stopwatch stopwatch1 = new Stopwatch();
  5334. Stopwatch stopwatch2 = new Stopwatch();
  5335. try
  5336. {
  5337. stopwatch1.Start();
  5338. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5339. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5340. string processItem = stationName; // 测试项目
  5341. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5342. string supplierCode = ""; // 供应商代码
  5343. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5344. string batch_num = GlobalContext.BatchNumber; // 批次号
  5345. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5346. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5347. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5348. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  5349. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  5350. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5351. bool pass = a1Result == 1;
  5352. //根据载具码获取产品码
  5353. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5354. if (string.IsNullOrEmpty(strProductBarcode))
  5355. {
  5356. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5357. ProgressState = false;
  5358. Thread.Sleep(10000);
  5359. return;
  5360. }
  5361. sn = strProductBarcode;
  5362. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5363. List<TestItem> items = new List<TestItem>();
  5364. items.Add(new TestItem()
  5365. {
  5366. Parameter_name = "载具码",
  5367. Parameter_value = CarrierBarcode,
  5368. Parameter_unit = ""
  5369. });
  5370. items.Add(new TestItem()
  5371. {
  5372. Parameter_name = "产品码",
  5373. Parameter_value = sn,
  5374. Parameter_unit = ""
  5375. });
  5376. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5377. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5378. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  5379. MachineId, StationId, "", paramJson);
  5380. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5381. if (mesResultFrmWeb == 1)
  5382. {
  5383. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5384. if (mesResultFrmWeb==110)
  5385. {
  5386. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  5387. }
  5388. }
  5389. stopwatch2.Start();
  5390. //进站结果写入PLC
  5391. CommandFromPLC resultToPlC = new CommandFromPLC();
  5392. resultToPlC.cmd = 0;
  5393. resultToPlC.cmdParam = 0; //指令参数
  5394. resultToPlC.cmdResult = mesResultFrmWeb;
  5395. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5396. stopwatch2.Stop();
  5397. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5398. //保存PLC返回MES数据到本地
  5399. ResponseMessage message = new ResponseMessage();
  5400. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  5401. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  5402. }
  5403. catch (Exception ex)
  5404. {
  5405. stopwatch2.Start();
  5406. CommandFromPLC resultToPlC = new CommandFromPLC();
  5407. resultToPlC.cmd = 0;
  5408. resultToPlC.cmdParam = 0; //指令参数
  5409. resultToPlC.cmdResult = 110;
  5410. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5411. stopwatch2.Stop();
  5412. string str = ex.StackTrace;
  5413. AddMessage(LogType.Error,
  5414. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5415. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5416. }
  5417. stopwatch1.Stop();
  5418. AddMessage(LogType.Info,
  5419. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5420. stopwatch2.ElapsedMilliseconds + "ms");
  5421. ProgressState = false;
  5422. uuid = "";
  5423. OpenDailogFalg = true; //开启下一个物料的扫码
  5424. }
  5425. #endregion
  5426. #region S7
  5427. private Dictionary<string, object> s7PLCSignal_Old = new Dictionary<string, object>();
  5428. private Dictionary<string, object> s7PLCData = new Dictionary<string, object>();
  5429. /// <summary>
  5430. /// [S7] 锁螺丝设备
  5431. /// </summary>
  5432. /// <param name="plcNo">PLC编号</param>
  5433. private void ReadStation_S7(int plcNo)
  5434. {
  5435. string stationCode = "[OP80]";
  5436. string stationName = "上盖板锁螺丝";
  5437. string stationNameStr = stationCode + stationName;
  5438. string tagBaseName = "g_OP70_MES"; //标签变量名称
  5439. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5440. string tagAgvCommName = "agvCommFrmPC";
  5441. string tagBarsetName = "BarcodeSet";
  5442. string tagiotComnName = "iotData";
  5443. string tagScrewDataset = "screwDataset";
  5444. string CarrierBarcode_Left = "";
  5445. string CarrierBarcode_Right = "";
  5446. s7PLCSignal_Old.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5447. s7PLCSignal_Old.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5448. // PLC数据字典 赋值
  5449. s7PLCData.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5450. s7PLCData.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5451. s5PLCData.Add("OEETypeFlag_left", 0); // 节拍标识 0 不上传 ,1 上传
  5452. s5PLCData.Add("OEETypeFlag_right", 0); // 节拍标识 0 不上传 ,1 上传
  5453. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  5454. (int, string) result;
  5455. AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
  5456. 3000, 3000, "Left");
  5457. atlasScrewLeft.Initial();
  5458. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
  5459. 3000, 3000, "Right");
  5460. atlasScrewRight.Initial();
  5461. while (true)
  5462. {
  5463. try
  5464. {
  5465. if (!GlobalContext._IsCon_Funs1)
  5466. {
  5467. UpdatePLCMonitor(1, plcNo, 0);
  5468. continue;
  5469. }
  5470. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5471. {
  5472. Stopwatch stopwatch1 = new Stopwatch();
  5473. Stopwatch stopwatch2 = new Stopwatch();
  5474. stopwatch1.Start();
  5475. stopwatch2.Start();
  5476. #region 一次性读取所有数据
  5477. // 一次性读取所有数据
  5478. result = FunsEip[plcNo]
  5479. .Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5480. if (result.Item1 != 0)
  5481. {
  5482. //richTextBox1.AppendText("\n" + strRet);
  5483. }
  5484. else
  5485. {
  5486. #region 去除扫码产生的特殊字符
  5487. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  5488. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  5489. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  5490. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  5491. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  5492. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  5493. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  5494. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  5495. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  5496. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  5497. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  5498. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  5499. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  5500. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  5501. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  5502. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  5503. #endregion
  5504. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  5505. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  5506. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5507. ? XiaomiDeviceState.Unknown
  5508. : (XiaomiDeviceState)xmDeviceStateInt_L;
  5509. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5510. ? XiaomiDeviceState.Unknown
  5511. : (XiaomiDeviceState)xmDeviceStateInt_R;
  5512. s7PLCData["a7OEEPartNo"] =
  5513. stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5514. // 载具SN
  5515. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  5516. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  5517. // 节拍
  5518. s7PLCData["a7OEEType"] = stPLC_MesData.Left.iotData.beatAction;
  5519. s7PLCData["a7OEEType_left"] = stPLC_MesData.Left .iotData.beatAction;
  5520. s7PLCData["a7OEEType_right"] = stPLC_MesData.Right.iotData.beatAction;
  5521. //报警信息
  5522. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  5523. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  5524. }
  5525. #endregion 一次性读取所有数据
  5526. stopwatch2.Stop();
  5527. #region 左边进站
  5528. try
  5529. {
  5530. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5531. {
  5532. lock (lockObj)
  5533. {
  5534. if (!ProgressState)
  5535. {
  5536. stationCode = "[OP81]";
  5537. stationName = "上盖板锁螺丝1";
  5538. stationNameStr = stationCode + stationName;
  5539. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5540. ProgressState = true;
  5541. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
  5542. tagBaseName + ".Left." + tagMesCommName,
  5543. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
  5544. atlasScrewLeft));
  5545. }
  5546. }
  5547. }
  5548. }
  5549. catch (Exception ex)
  5550. {
  5551. ProgressState = false;
  5552. string str = ex.StackTrace;
  5553. AddMessage_Station(stationNameStr, LogType.Error,
  5554. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5555. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5556. }
  5557. #endregion 左边进站
  5558. #region 左边出站
  5559. try
  5560. {
  5561. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5562. {
  5563. lock (lockObj)
  5564. {
  5565. if (!ProgressState)
  5566. {
  5567. stationCode = "[OP81]";
  5568. stationName = "上盖板锁螺丝1";
  5569. stationNameStr = stationCode + stationName;
  5570. ProgressState = true;
  5571. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
  5572. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  5573. out ProgressState));
  5574. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  5575. }
  5576. }
  5577. }
  5578. }
  5579. catch (Exception ex)
  5580. {
  5581. ProgressState = false;
  5582. string str = ex.StackTrace;
  5583. AddMessage_Station(stationNameStr, LogType.Error,
  5584. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5585. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5586. }
  5587. #endregion 左边出站
  5588. #region 右边进站
  5589. try
  5590. {
  5591. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5592. {
  5593. lock (lockObj)
  5594. {
  5595. if (!ProgressState)
  5596. {
  5597. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5598. stationCode = "[OP82]";
  5599. stationName = "上盖板锁螺丝2";
  5600. stationNameStr = stationCode + stationName;
  5601. ProgressState = true;
  5602. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
  5603. tagBaseName + ".Right." + tagMesCommName,
  5604. tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
  5605. atlasScrewRight));
  5606. }
  5607. }
  5608. }
  5609. }
  5610. catch (Exception ex)
  5611. {
  5612. ProgressState = false;
  5613. string str = ex.StackTrace;
  5614. AddMessage_Station(stationNameStr, LogType.Error,
  5615. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5616. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5617. }
  5618. #endregion 右边进站
  5619. #region 右边出站
  5620. try
  5621. {
  5622. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5623. {
  5624. lock (lockObj)
  5625. {
  5626. if (!ProgressState)
  5627. {
  5628. stationCode = "[OP82]";
  5629. stationName = "上盖板锁螺丝2";
  5630. stationNameStr = stationCode + stationName;
  5631. ProgressState = true;
  5632. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
  5633. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  5634. out ProgressState));
  5635. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  5636. }
  5637. }
  5638. }
  5639. }
  5640. catch (Exception ex)
  5641. {
  5642. ProgressState = false;
  5643. string str = ex.StackTrace;
  5644. AddMessage_Station(stationNameStr, LogType.Error,
  5645. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5646. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5647. }
  5648. #endregion 右边出站
  5649. #region 节拍接口
  5650. try
  5651. {
  5652. #region 左工位 节拍
  5653. if (stPLC_MesData.Left.iotData.beatAction > 0)
  5654. {
  5655. stationCode = "[OP81]";
  5656. stationName = "上盖板锁螺丝1";
  5657. stationNameStr = stationCode + stationName;
  5658. int a7OEEType_left = Convert.ToInt32(s7PLCData["a7OEEType_left"]);
  5659. int a7OEETypeGOld_left = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_left"]);
  5660. if (a7OEEType_left != a7OEETypeGOld_left)
  5661. {
  5662. if (a7OEEType_left != a7OEETypeGOld_left)
  5663. s7PLCData["OEETypeFlag_left"] = "1";
  5664. else
  5665. s7PLCData["OEETypeFlag_left"] = "0";
  5666. if (s7PLCData["OEETypeFlag_left"].ToString() == "1" && (a7OEEType_left == 1 || a7OEEType_left == 3 || a7OEEType_left == 4 || a7OEEType_left == 5))
  5667. {
  5668. int res = 0;
  5669. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  5670. stPLC_MesData.Left.iotData, out res);
  5671. if (res == 1)
  5672. {
  5673. s7PLCSignal_Old["a7OEEType_left"] = s7PLCData["a7OEEType_left"];
  5674. }
  5675. else {
  5676. s7PLCSignal_Old["a7OEEType_left"] = 0;
  5677. }
  5678. }
  5679. }
  5680. }
  5681. else
  5682. {
  5683. s7PLCSignal_Old["a7OEEType_left"] = 0;
  5684. }
  5685. #endregion 左工位 节拍
  5686. #region 右工位 节拍
  5687. if (stPLC_MesData.Right.iotData.beatAction > 0)
  5688. {
  5689. stationCode = "[OP82]";
  5690. stationName = "上盖板锁螺丝2";
  5691. stationNameStr = stationCode + stationName;
  5692. int a7OEEType_right = Convert.ToInt32(s7PLCData["a7OEEType_right"]);
  5693. int a7OEETypeGOld_right = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_right"]);
  5694. if (a7OEEType_right != a7OEETypeGOld_right)
  5695. {
  5696. if (a7OEEType_right != a7OEETypeGOld_right)
  5697. s7PLCData["a7OEEType_right"] = "1";
  5698. else
  5699. s7PLCData["a7OEEType_right"] = "0";
  5700. if (s7PLCData["a7OEEType_right"].ToString() == "1" && (a7OEEType_right == 1 || a7OEEType_right == 3 || a7OEEType_right == 4 || a7OEEType_right == 5))
  5701. {
  5702. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagiotComnName, CarrierBarcode_Left,
  5703. stPLC_MesData.Right.iotData, out res);
  5704. if (res == 1)
  5705. {
  5706. s7PLCSignal_Old["a7OEEType_right"] = s7PLCData["a7OEEType_right"];
  5707. }
  5708. else {
  5709. s7PLCSignal_Old["a7OEEType_right"] = 0;
  5710. }
  5711. }
  5712. }
  5713. }
  5714. else
  5715. {
  5716. s7PLCSignal_Old["a7OEEType_right"] = 0;
  5717. }
  5718. #endregion 右工位 节拍
  5719. }
  5720. catch (Exception ex)
  5721. {
  5722. string str = ex.StackTrace;
  5723. AddMessage_Station(stationNameStr, LogType.Error,
  5724. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5725. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5726. }
  5727. #endregion
  5728. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5729. stopwatch1.Stop();
  5730. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5731. }
  5732. else
  5733. {
  5734. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5735. AddMessage_Station(stationNameStr, LogType.Info,
  5736. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5737. FunsEip[plcNo].Connect(); // 重连
  5738. }
  5739. }
  5740. catch (Exception ex)
  5741. {
  5742. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5743. AddMessage_Station(stationNameStr, LogType.Error,
  5744. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5745. }
  5746. Thread.Sleep(IntervalReadPLC);
  5747. }
  5748. }
  5749. /// <summary>
  5750. /// [S7] 锁螺丝设备 - 进站
  5751. /// </summary>
  5752. /// <param name="plcNo">PLC编号</param>
  5753. /// <param name="stationNameStr">工站全称</param>
  5754. /// <param name="stPLC_MesData"></param>
  5755. /// <param name="tagMesCommName"></param>
  5756. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5757. string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
  5758. {
  5759. Stopwatch stopwatch1 = new Stopwatch();
  5760. Stopwatch stopwatch2 = new Stopwatch();
  5761. string atlasSn = string.Empty;
  5762. try
  5763. {
  5764. stopwatch1.Start();
  5765. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  5766. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5767. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  5768. string StationId = string.Empty; // 工位ID(可配置)
  5769. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5770. bool pass = a1Result == 1;
  5771. if (direction == "Left")
  5772. {
  5773. StationId = GlobalContext.S7_StationId_1;
  5774. }
  5775. if (direction == "Right")
  5776. {
  5777. StationId = GlobalContext.S7_StationId_2;
  5778. }
  5779. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5780. //载具码验证产品码
  5781. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5782. if (string.IsNullOrEmpty(strProductBarcode))
  5783. {
  5784. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5785. ProgressState = false;
  5786. Thread.Sleep(10000);
  5787. return;
  5788. }
  5789. sn = strProductBarcode;
  5790. atlasSn = strProductBarcode;
  5791. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5792. string slot = "";
  5793. if (direction == "Left")
  5794. {
  5795. isCollectingFlagLeft = false; //采集螺丝数据结束
  5796. slot = "01-SLOT-01";
  5797. }
  5798. if (direction == "Right")
  5799. {
  5800. isCollectingFlagRight = false; //采集螺丝数据结束
  5801. slot = "01-SLOT-02";
  5802. }
  5803. // 产品SN(物料码)校验
  5804. List<TestItem> item = new List<TestItem>();
  5805. stopwatch2.Start();
  5806. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5807. item, MachineId, StationId, pass, slot);
  5808. stopwatch2.Stop();
  5809. //指令执行结果 1:OK 110:失败
  5810. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5811. if (mesResultFrmWeb == 1)
  5812. {
  5813. if (a1Result == 1)
  5814. {
  5815. mesResultFrmWeb = 1;
  5816. }
  5817. else
  5818. {
  5819. mesResultFrmWeb = 110;
  5820. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5821. }
  5822. }
  5823. //进站结果写入PLC
  5824. CommandFromPLC resultToPlC = new CommandFromPLC();
  5825. resultToPlC.cmd = 0;
  5826. resultToPlC.cmdParam = 0; //指令参数
  5827. resultToPlC.cmdResult = mesResultFrmWeb;
  5828. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5829. }
  5830. catch (Exception ex)
  5831. {
  5832. string str = ex.StackTrace;
  5833. AddMessage(LogType.Error,
  5834. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5835. str.Length - str.LastIndexOf("\\") - 1));
  5836. CommandFromPLC resultToPlC = new CommandFromPLC();
  5837. resultToPlC.cmd = 0;
  5838. resultToPlC.cmdParam = 0; //指令参数
  5839. resultToPlC.cmdResult = 110;
  5840. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5841. }
  5842. stopwatch1.Stop();
  5843. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  5844. AddMessage(LogType.Info,
  5845. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5846. stopwatch2.ElapsedMilliseconds + "ms");
  5847. ProgressState = false;
  5848. //开始采集螺丝数据
  5849. if (direction == "Left")
  5850. {
  5851. isCollectingFlagLeft = true;
  5852. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  5853. }
  5854. if (direction == "Right")
  5855. {
  5856. isCollectingFlagRight = true;
  5857. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  5858. }
  5859. }
  5860. /// <summary>
  5861. /// [S7] 锁螺丝设备 - 出站
  5862. /// </summary>
  5863. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5864. string stationCode, string stationName, string direction, out bool ProgressState)
  5865. {
  5866. Stopwatch stopwatch1 = new Stopwatch();
  5867. Stopwatch stopwatch2 = new Stopwatch();
  5868. try
  5869. {
  5870. stopwatch1.Start();
  5871. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  5872. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5873. string processItem = stationName; // 测试项目
  5874. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5875. string supplierCode = ""; // 供应商代码
  5876. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5877. string batch_num = GlobalContext.BatchNumber; // 批次号
  5878. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5879. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5880. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5881. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  5882. string StationId = string.Empty; // 工位ID(可配置)
  5883. if (direction == "Left")
  5884. {
  5885. StationId = GlobalContext.S7_StationId_1;
  5886. }
  5887. if (direction == "Right")
  5888. {
  5889. StationId = GlobalContext.S7_StationId_2;
  5890. }
  5891. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5892. //a1Result = 1;
  5893. bool pass = a1Result == 1;
  5894. //根据载具码获取产品码
  5895. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5896. if (string.IsNullOrEmpty(strProductBarcode))
  5897. {
  5898. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5899. ProgressState = false;
  5900. Thread.Sleep(10000);
  5901. return;
  5902. }
  5903. sn = strProductBarcode;
  5904. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5905. List<TestItem> items = new List<TestItem>();
  5906. items.Add(new TestItem()
  5907. {
  5908. Parameter_name = "载具码",
  5909. Parameter_value = CarrierBarcode,
  5910. Parameter_unit = ""
  5911. });
  5912. items.Add(new TestItem()
  5913. {
  5914. Parameter_name = "产品码",
  5915. Parameter_value = sn,
  5916. Parameter_unit = ""
  5917. });
  5918. //if (direction == "Right")
  5919. //{
  5920. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5921. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  5922. batch_num, mtltmrk, plcDate_YMD, supplierCode
  5923. , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  5924. //}
  5925. //if (direction == "Left")
  5926. //{
  5927. // isCollectingFlagLeft = false;//采集螺丝数据结束
  5928. //}
  5929. //if (direction == "Right")
  5930. //{
  5931. // isCollectingFlagRight = false;//采集螺丝数据结束
  5932. //}
  5933. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5934. if (mesResultFrmWeb == 1)
  5935. {
  5936. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5937. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  5938. }
  5939. stopwatch2.Start();
  5940. //进站结果写入PLC
  5941. CommandFromPLC resultToPlC = new CommandFromPLC();
  5942. resultToPlC.cmd = 0;
  5943. resultToPlC.cmdParam = 0; //指令参数
  5944. resultToPlC.cmdResult = mesResultFrmWeb;
  5945. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5946. stopwatch2.Stop();
  5947. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  5948. //保存PLC返回MES数据到本地
  5949. ResponseMessage message = new ResponseMessage();
  5950. if (direction == "Left")
  5951. {
  5952. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5953. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5954. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5955. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  5956. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5957. //if (message.result == false)
  5958. //{
  5959. // AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  5960. //}
  5961. }
  5962. if (direction == "Right")
  5963. {
  5964. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5965. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5966. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5967. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  5968. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5969. //if (message.result == false)
  5970. //{
  5971. // AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  5972. //}
  5973. }
  5974. //保存螺丝数据到txt
  5975. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
  5976. stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  5977. if (result.Item1 != 0)
  5978. {
  5979. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  5980. }
  5981. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
  5982. }
  5983. catch (Exception ex)
  5984. {
  5985. stopwatch2.Start();
  5986. CommandFromPLC resultToPlC = new CommandFromPLC();
  5987. resultToPlC.cmd = 0;
  5988. resultToPlC.cmdParam = 0; //指令参数
  5989. resultToPlC.cmdResult = 110;
  5990. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5991. stopwatch2.Stop();
  5992. string str = ex.StackTrace;
  5993. AddMessage(LogType.Error,
  5994. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5995. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5996. }
  5997. stopwatch1.Stop();
  5998. AddMessage(LogType.Info,
  5999. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6000. stopwatch2.ElapsedMilliseconds + "ms");
  6001. ProgressState = false;
  6002. if (direction == "Left") uuid = "";
  6003. if (direction == "Right") uuid2 = "";
  6004. }
  6005. #endregion
  6006. #region S8
  6007. private Dictionary<string, object> s8PLCData = new Dictionary<string, object>();
  6008. private Dictionary<string, object> s8PLCSignal_Old = new Dictionary<string, object>();
  6009. /// <summary>
  6010. /// [S8] 3D螺丝高度检测设备
  6011. /// </summary>
  6012. /// <param name="plcNo">PLC编号</param>
  6013. private void ReadStation_S8(int plcNo)
  6014. {
  6015. string stationCode = "[OP90]";
  6016. string stationName = "NG下料";
  6017. string stationNameStr = stationCode + stationName;
  6018. string tagBaseName = "g_OP80_MES"; //标签变量名称
  6019. string tagMesCommName = "mesCommToPC"; //标签变量名称
  6020. string tagAgvCommName = "agvCommFrmPC";
  6021. string tagiotComnName = "iotData";
  6022. string tagBarsetName = "BarcodeSet";
  6023. string CarrierBarcode = "";
  6024. // 触发信号字典
  6025. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6026. s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
  6027. // PLC数据字典 赋值
  6028. s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
  6029. s8PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  6030. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  6031. (int, string) result;
  6032. while (true)
  6033. {
  6034. try
  6035. {
  6036. if (!GlobalContext._IsCon_Funs1)
  6037. {
  6038. UpdatePLCMonitor(1, plcNo, 0);
  6039. continue;
  6040. }
  6041. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  6042. {
  6043. Stopwatch stopwatch1 = new Stopwatch();
  6044. Stopwatch stopwatch2 = new Stopwatch();
  6045. stopwatch1.Start();
  6046. stopwatch2.Start();
  6047. #region 一次性读取所有数据
  6048. // 一次性读取所有数据
  6049. result = FunsEip[plcNo]
  6050. .Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6051. if (result.Item1 != 0)
  6052. {
  6053. //richTextBox1.AppendText("\n" + strRet);
  6054. }
  6055. else
  6056. {
  6057. //去除扫码产生的特殊字符
  6058. stPLC_MesData.BarcodeSet.strProductBarcode =
  6059. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  6060. stPLC_MesData.BarcodeSet.strPartBarcode =
  6061. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  6062. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  6063. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  6064. stPLC_MesData.BarcodeSet.strPCBBarcode =
  6065. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  6066. }
  6067. #endregion 一次性读取所有数据
  6068. stopwatch2.Stop();
  6069. //richTextBox1.AppendText("\n" + "读取成功");
  6070. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6071. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6072. ? XiaomiDeviceState.Unknown
  6073. : (XiaomiDeviceState)xmDeviceStateInt;
  6074. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6075. s8PLCData["a8OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  6076. //报警信息
  6077. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  6078. stopwatch2.Stop();
  6079. #region 进站
  6080. try
  6081. {
  6082. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6083. {
  6084. lock (lockObj)
  6085. {
  6086. if (!ProgressState)
  6087. {
  6088. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6089. ProgressState = true;
  6090. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
  6091. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6092. out ProgressState));
  6093. }
  6094. }
  6095. }
  6096. }
  6097. catch (Exception ex)
  6098. {
  6099. ProgressState = false;
  6100. string str = ex.StackTrace;
  6101. AddMessage_Station(stationNameStr, LogType.Error,
  6102. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6103. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6104. }
  6105. #endregion 进站
  6106. #region 出站
  6107. try
  6108. {
  6109. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6110. {
  6111. lock (lockObj)
  6112. {
  6113. if (!ProgressState)
  6114. {
  6115. ProgressState = true;
  6116. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
  6117. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  6118. out ProgressState));
  6119. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  6120. uuid = "";
  6121. }
  6122. }
  6123. }
  6124. }
  6125. catch (Exception ex)
  6126. {
  6127. ProgressState = false;
  6128. string str = ex.StackTrace;
  6129. AddMessage_Station(stationNameStr, LogType.Error,
  6130. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6131. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6132. }
  6133. #endregion 出站
  6134. #region 节拍接口
  6135. try
  6136. {
  6137. int a8OEEType = Convert.ToInt32(s8PLCData["a8OEEType"]);
  6138. int a8OEETypeGOld = Convert.ToInt32(s8PLCSignal_Old["a8OEEType"]);
  6139. if (stPLC_MesData.iotData.beatAction > 0)
  6140. {
  6141. if (a8OEEType != a8OEETypeGOld)
  6142. {
  6143. s8PLCData["OEETypeFlag"] = "1";
  6144. }
  6145. else
  6146. {
  6147. s8PLCData["OEETypeFlag"] = "0";
  6148. }
  6149. if (s8PLCData["OEETypeFlag"].ToString() == "1" && (a8OEEType == 1 || a8OEEType == 3 || a8OEEType == 4 || a8OEEType == 5))
  6150. {
  6151. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6152. CarrierBarcode, stPLC_MesData.iotData, out res);
  6153. if (res == 1)
  6154. {
  6155. s8PLCSignal_Old["a8OEEType"] = s8PLCData["a8OEEType"];
  6156. }
  6157. else
  6158. {
  6159. s8PLCSignal_Old["a8OEEType"] = 0;
  6160. }
  6161. }
  6162. }
  6163. else {
  6164. s8PLCSignal_Old["a8OEEType"] = 0;
  6165. }
  6166. }
  6167. catch (Exception ex)
  6168. {
  6169. string str = ex.StackTrace;
  6170. AddMessage_Station(stationNameStr, LogType.Error,
  6171. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6172. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6173. }
  6174. #endregion
  6175. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6176. stopwatch1.Stop();
  6177. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6178. }
  6179. else
  6180. {
  6181. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6182. AddMessage_Station(stationNameStr, LogType.Info,
  6183. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6184. FunsEip[plcNo].Connect(); // 重连
  6185. }
  6186. }
  6187. catch (Exception ex)
  6188. {
  6189. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6190. AddMessage_Station(stationNameStr, LogType.Error,
  6191. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6192. }
  6193. Thread.Sleep(IntervalReadPLC);
  6194. }
  6195. }
  6196. /// <summary>
  6197. /// [S8] 3D螺丝高度检测设备 - 进站
  6198. /// </summary>
  6199. /// <param name="plcNo">PLC编号</param>
  6200. /// <param name="stationNameStr">工站全称</param>
  6201. /// <param name="stPLC_MesData"></param>
  6202. /// <param name="tagMesCommName"></param>
  6203. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6204. string tagBarsetName, out bool ProgressState)
  6205. {
  6206. Stopwatch stopwatch1 = new Stopwatch();
  6207. Stopwatch stopwatch2 = new Stopwatch();
  6208. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6209. bool pass = a1Result == 1;
  6210. try
  6211. {
  6212. stopwatch1.Start();
  6213. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6214. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6215. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  6216. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  6217. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6218. //载具码验证产品码
  6219. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6220. if (string.IsNullOrEmpty(strProductBarcode))
  6221. {
  6222. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6223. ProgressState = false;
  6224. Thread.Sleep(10000);
  6225. return;
  6226. }
  6227. sn = strProductBarcode;
  6228. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6229. // 产品SN(物料码)校验
  6230. List<TestItem> item = new List<TestItem>();
  6231. stopwatch2.Start();
  6232. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  6233. sn,
  6234. item, MachineId, StationId, pass, "01-SLOT-01");
  6235. stopwatch2.Stop();
  6236. //指令执行结果 1:OK 110:失败
  6237. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6238. if (mesResultFrmWeb == 1)
  6239. {
  6240. if (a1Result == 1)
  6241. {
  6242. mesResultFrmWeb = 1;
  6243. }
  6244. else
  6245. {
  6246. mesResultFrmWeb = 110;
  6247. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6248. }
  6249. }
  6250. //进站结果写入PLC
  6251. CommandFromPLC resultToPlC = new CommandFromPLC();
  6252. resultToPlC.cmd = 0;
  6253. resultToPlC.cmdParam = 0; //指令参数
  6254. resultToPlC.cmdResult = mesResultFrmWeb;
  6255. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6256. }
  6257. catch (Exception ex)
  6258. {
  6259. string str = ex.StackTrace;
  6260. AddMessage(LogType.Error,
  6261. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(
  6262. str.LastIndexOf("\\") + 1,
  6263. str.Length - str.LastIndexOf("\\") - 1));
  6264. CommandFromPLC resultToPlC = new CommandFromPLC();
  6265. resultToPlC.cmd = 0;
  6266. resultToPlC.cmdParam = 0; //指令参数
  6267. resultToPlC.cmdResult = 110;
  6268. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6269. }
  6270. stopwatch1.Stop();
  6271. AddMessage(LogType.Info,
  6272. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6273. stopwatch2.ElapsedMilliseconds + "ms");
  6274. ProgressState = false;
  6275. }
  6276. /// <summary>
  6277. /// [S8] 3D螺丝高度检测设备 - 出站接口
  6278. /// </summary>
  6279. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6280. string stationCode, string stationName, out bool ProgressState)
  6281. {
  6282. Stopwatch stopwatch1 = new Stopwatch();
  6283. Stopwatch stopwatch2 = new Stopwatch();
  6284. try
  6285. {
  6286. stopwatch1.Start();
  6287. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6288. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6289. string processItem = stationName; // 测试项目
  6290. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6291. string supplierCode = ""; // 供应商代码
  6292. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6293. string batch_num = GlobalContext.BatchNumber; // 批次号
  6294. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6295. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6296. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6297. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  6298. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  6299. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6300. bool pass = a1Result == 1;
  6301. //根据载具码获取产品码
  6302. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6303. if (string.IsNullOrEmpty(strProductBarcode))
  6304. {
  6305. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6306. ProgressState = false;
  6307. Thread.Sleep(10000);
  6308. return;
  6309. }
  6310. sn = strProductBarcode;
  6311. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6312. List<TestItem> items = new List<TestItem>();
  6313. items.Add(new TestItem()
  6314. {
  6315. Parameter_name = "载具码",
  6316. Parameter_value = CarrierBarcode,
  6317. Parameter_unit = ""
  6318. });
  6319. items.Add(new TestItem()
  6320. {
  6321. Parameter_name = "产品码",
  6322. Parameter_value = sn,
  6323. Parameter_unit = ""
  6324. });
  6325. #region 上传图片
  6326. if (GlobalContext.MQTTIsSendUpFile)
  6327. {
  6328. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  6329. fileUploadData.fileData.Clear();
  6330. foreach (var item in urlarry)
  6331. {
  6332. if (!string.IsNullOrEmpty(item))
  6333. {
  6334. //上传图片
  6335. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName,
  6336. a1Result, item, uuid).Result;
  6337. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  6338. }
  6339. }
  6340. }
  6341. #endregion
  6342. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6343. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6344. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  6345. MachineId, StationId, "", paramJson);
  6346. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6347. if (mesResultFrmWeb == 1)
  6348. {
  6349. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6350. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6351. }
  6352. stopwatch2.Start();
  6353. //进站结果写入PLC
  6354. CommandFromPLC resultToPlC = new CommandFromPLC();
  6355. resultToPlC.cmd = 0;
  6356. resultToPlC.cmdParam = 0; //指令参数
  6357. resultToPlC.cmdResult = mesResultFrmWeb;
  6358. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6359. stopwatch2.Stop();
  6360. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6361. //保存PLC返回MES数据到本地
  6362. ResponseMessage message = new ResponseMessage();
  6363. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  6364. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6365. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  6366. if (message.result == false)
  6367. {
  6368. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6369. }
  6370. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6371. }
  6372. catch (Exception ex)
  6373. {
  6374. stopwatch2.Start();
  6375. CommandFromPLC resultToPlC = new CommandFromPLC();
  6376. resultToPlC.cmd = 0;
  6377. resultToPlC.cmdParam = 0; //指令参数
  6378. resultToPlC.cmdResult = 110;
  6379. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6380. stopwatch2.Stop();
  6381. string str = ex.StackTrace;
  6382. AddMessage(LogType.Error,
  6383. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6384. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6385. }
  6386. stopwatch1.Stop();
  6387. AddMessage(LogType.Info,
  6388. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6389. stopwatch2.ElapsedMilliseconds + "ms");
  6390. ProgressState = false;
  6391. }
  6392. #endregion
  6393. #region S9
  6394. private Dictionary<string, object> s9PLCData = new Dictionary<string, object>();
  6395. private Dictionary<string, object> s9PLCSignal_Old = new Dictionary<string, object>();
  6396. /// <summary>
  6397. /// [S9] 下料设备
  6398. /// </summary>
  6399. /// <param name="plcNo">PLC编号</param>
  6400. private void ReadStation_S9(int plcNo)
  6401. {
  6402. string stationCode = "[OP100]";
  6403. string stationName = "半成品下料";
  6404. string stationNameStr = stationCode + stationName;
  6405. string tagBaseName = "g_OP90_MES"; //标签变量名称
  6406. string tagMesCommName = "mesCommToPC"; //标签变量名称
  6407. string tagAgvCommName = "agvCommFrmPC";
  6408. string tagiotComnName = "iotData";
  6409. string tagBarsetName = "BarcodeSet";
  6410. string CarrierBarcode = "";
  6411. // 触发信号字典
  6412. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6413. s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6414. // PLC数据字典 赋值
  6415. s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6416. s9PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  6417. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  6418. (int, string) result;
  6419. while (true)
  6420. {
  6421. try
  6422. {
  6423. if (!GlobalContext._IsCon_Funs1)
  6424. {
  6425. UpdatePLCMonitor(1, plcNo, 0);
  6426. continue;
  6427. }
  6428. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  6429. {
  6430. Stopwatch stopwatch1 = new Stopwatch();
  6431. Stopwatch stopwatch2 = new Stopwatch();
  6432. stopwatch1.Start();
  6433. stopwatch2.Start();
  6434. #region 一次性读取所有数据
  6435. // 一次性读取所有数据
  6436. result = FunsEip[plcNo]
  6437. .Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6438. if (result.Item1 != 0)
  6439. {
  6440. //richTextBox1.AppendText("\n" + strRet);
  6441. }
  6442. else
  6443. {
  6444. //去除扫码产生的特殊字符
  6445. stPLC_MesData.BarcodeSet.strProductBarcode =
  6446. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  6447. stPLC_MesData.BarcodeSet.strPartBarcode =
  6448. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  6449. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  6450. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  6451. stPLC_MesData.BarcodeSet.strPCBBarcode =
  6452. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  6453. //richTextBox1.AppendText("\n" + "读取成功");
  6454. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6455. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6456. ? XiaomiDeviceState.Unknown
  6457. : (XiaomiDeviceState)xmDeviceStateInt;
  6458. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6459. s9PLCData["a9OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  6460. //报警信息
  6461. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  6462. }
  6463. #endregion 一次性读取所有数据
  6464. stopwatch2.Stop();
  6465. #region 进站
  6466. try
  6467. {
  6468. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6469. {
  6470. lock (lockObj)
  6471. {
  6472. if (!ProgressState)
  6473. {
  6474. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6475. ProgressState = true;
  6476. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
  6477. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6478. out ProgressState));
  6479. }
  6480. }
  6481. }
  6482. }
  6483. catch (Exception ex)
  6484. {
  6485. ProgressState = false;
  6486. string str = ex.StackTrace;
  6487. AddMessage_Station(stationNameStr, LogType.Error,
  6488. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6489. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6490. }
  6491. #endregion 进站
  6492. #region 出站
  6493. try
  6494. {
  6495. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6496. {
  6497. lock (lockObj)
  6498. {
  6499. if (!ProgressState)
  6500. {
  6501. ProgressState = true;
  6502. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
  6503. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  6504. out ProgressState));
  6505. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  6506. }
  6507. }
  6508. }
  6509. }
  6510. catch (Exception ex)
  6511. {
  6512. ProgressState = false;
  6513. string str = ex.StackTrace;
  6514. AddMessage_Station(stationNameStr, LogType.Error,
  6515. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6516. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6517. }
  6518. #endregion 出站
  6519. #region 节拍接口
  6520. try
  6521. {
  6522. if (stPLC_MesData.iotData.beatAction > 0)
  6523. {
  6524. int a9OEEType = Convert.ToInt32(s9PLCData["a9OEEType"]);
  6525. int a9OEETypeGOld = Convert.ToInt32(s9PLCSignal_Old["a9OEEType"]);
  6526. if (a9OEEType != a9OEETypeGOld)
  6527. {
  6528. s9PLCData["OEETypeFlag"] = "1";
  6529. }
  6530. else
  6531. {
  6532. s9PLCData["OEETypeFlag"] = "0";
  6533. }
  6534. if (s9PLCData["OEETypeFlag"].ToString() == "1" && (a9OEEType == 1 || a9OEEType == 3 || a9OEEType == 4 || a9OEEType == 5))
  6535. {
  6536. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6537. CarrierBarcode, stPLC_MesData.iotData, out res);
  6538. if (res == 1)
  6539. {
  6540. s9PLCSignal_Old["a9OEEType"] = s9PLCData["a9OEEType"];
  6541. }
  6542. else
  6543. {
  6544. s9PLCSignal_Old["a9OEEType"] = 0;
  6545. }
  6546. }
  6547. }
  6548. else {
  6549. s9PLCSignal_Old["a9OEEType"] = 0;
  6550. }
  6551. }
  6552. catch (Exception ex)
  6553. {
  6554. string str = ex.StackTrace;
  6555. AddMessage_Station(stationNameStr, LogType.Error,
  6556. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6557. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6558. }
  6559. #endregion
  6560. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6561. stopwatch1.Stop();
  6562. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6563. }
  6564. else
  6565. {
  6566. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6567. AddMessage_Station(stationNameStr, LogType.Info,
  6568. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6569. FunsEip[plcNo].Connect(); // 重连
  6570. }
  6571. }
  6572. catch (Exception ex)
  6573. {
  6574. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6575. AddMessage_Station(stationNameStr, LogType.Error,
  6576. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6577. }
  6578. Thread.Sleep(IntervalReadPLC);
  6579. }
  6580. }
  6581. /// <summary>
  6582. /// [S9] 下料设备 - 进站
  6583. /// </summary>
  6584. /// <param name="plcNo">PLC编号</param>
  6585. /// <param name="stationNameStr">工站全称</param>
  6586. /// <param name="stPLC_MesData"></param>
  6587. /// <param name="tagMesCommName"></param>
  6588. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6589. string tagBarsetName, out bool ProgressState)
  6590. {
  6591. Stopwatch stopwatch1 = new Stopwatch();
  6592. Stopwatch stopwatch2 = new Stopwatch();
  6593. try
  6594. {
  6595. stopwatch1.Start();
  6596. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6597. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6598. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  6599. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  6600. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6601. bool pass = a1Result == 1;
  6602. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6603. //载具码验证产品码
  6604. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6605. if (string.IsNullOrEmpty(strProductBarcode))
  6606. {
  6607. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6608. ProgressState = false;
  6609. Thread.Sleep(10000);
  6610. return;
  6611. }
  6612. sn = strProductBarcode;
  6613. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6614. // 产品SN(物料码)校验
  6615. List<TestItem> item = new List<TestItem>();
  6616. stopwatch2.Start();
  6617. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6618. item, MachineId, StationId, pass, "01-SLOT-01");
  6619. stopwatch2.Stop();
  6620. //指令执行结果 1:OK 110:失败
  6621. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6622. if (mesResultFrmWeb == 1)
  6623. {
  6624. if (a1Result == 1)
  6625. {
  6626. mesResultFrmWeb = 1;
  6627. }
  6628. else
  6629. {
  6630. mesResultFrmWeb = 110;
  6631. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6632. }
  6633. }
  6634. //进站结果写入PLC
  6635. CommandFromPLC resultToPlC = new CommandFromPLC();
  6636. resultToPlC.cmd = 0;
  6637. resultToPlC.cmdParam = 0; //指令参数
  6638. resultToPlC.cmdResult = mesResultFrmWeb;
  6639. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6640. }
  6641. catch (Exception ex)
  6642. {
  6643. string str = ex.StackTrace;
  6644. AddMessage(LogType.Error,
  6645. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  6646. str.Length - str.LastIndexOf("\\") - 1));
  6647. CommandFromPLC resultToPlC = new CommandFromPLC();
  6648. resultToPlC.cmd = 0;
  6649. resultToPlC.cmdParam = 0; //指令参数
  6650. resultToPlC.cmdResult = 110;
  6651. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6652. }
  6653. stopwatch1.Stop();
  6654. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  6655. AddMessage(LogType.Info,
  6656. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6657. stopwatch2.ElapsedMilliseconds + "ms");
  6658. ProgressState = false;
  6659. }
  6660. /// <summary>
  6661. /// [S9] 下料设备 - 出站接口
  6662. /// </summary>
  6663. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6664. string stationCode, string stationName, out bool ProgressState)
  6665. {
  6666. Stopwatch stopwatch1 = new Stopwatch();
  6667. Stopwatch stopwatch2 = new Stopwatch();
  6668. try
  6669. {
  6670. stopwatch1.Start();
  6671. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6672. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6673. string processItem = stationName; // 测试项目
  6674. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6675. string supplierCode = ""; // 供应商代码
  6676. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6677. string batch_num = GlobalContext.BatchNumber; // 批次号
  6678. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6679. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6680. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6681. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  6682. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  6683. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6684. bool pass = a1Result == 1;
  6685. //根据载具码获取产品码
  6686. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6687. if (string.IsNullOrEmpty(strProductBarcode))
  6688. {
  6689. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6690. ProgressState = false;
  6691. Thread.Sleep(10000);
  6692. return;
  6693. }
  6694. sn = strProductBarcode;
  6695. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6696. List<TestItem> items = new List<TestItem>();
  6697. items.Add(new TestItem()
  6698. {
  6699. Parameter_name = "载具码",
  6700. Parameter_value = CarrierBarcode,
  6701. Parameter_unit = ""
  6702. });
  6703. items.Add(new TestItem()
  6704. {
  6705. Parameter_name = "产品码",
  6706. Parameter_value = sn,
  6707. Parameter_unit = ""
  6708. });
  6709. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6710. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6711. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  6712. MachineId, StationId, "", paramJson);
  6713. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6714. if (mesResultFrmWeb == 1)
  6715. {
  6716. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6717. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6718. }
  6719. stopwatch2.Start();
  6720. //进站结果写入PLC
  6721. CommandFromPLC resultToPlC = new CommandFromPLC();
  6722. resultToPlC.cmd = 0;
  6723. resultToPlC.cmdParam = 0; //指令参数
  6724. resultToPlC.cmdResult = mesResultFrmWeb;
  6725. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6726. stopwatch2.Stop();
  6727. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6728. //保存PLC返回MES数据到本地
  6729. ResponseMessage message = new ResponseMessage();
  6730. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  6731. stPLC_MesData.mesData.nRemainCount);
  6732. if (message.result == false)
  6733. {
  6734. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6735. }
  6736. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6737. if (result1 == 1)
  6738. {
  6739. //载具码解除绑定
  6740. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  6741. if (message.result == false)
  6742. {
  6743. AddMessage(LogType.Error, message.text);
  6744. }
  6745. }
  6746. }
  6747. catch (Exception ex)
  6748. {
  6749. stopwatch2.Start();
  6750. CommandFromPLC resultToPlC = new CommandFromPLC();
  6751. resultToPlC.cmd = 0;
  6752. resultToPlC.cmdParam = 0; //指令参数
  6753. resultToPlC.cmdResult = 110;
  6754. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6755. stopwatch2.Stop();
  6756. string str = ex.StackTrace;
  6757. AddMessage(LogType.Error,
  6758. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6759. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6760. }
  6761. stopwatch1.Stop();
  6762. AddMessage(LogType.Info,
  6763. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6764. stopwatch2.ElapsedMilliseconds + "ms");
  6765. ProgressState = false;
  6766. uuid = "";
  6767. }
  6768. #endregion
  6769. #endregion Xiaomi
  6770. #region PLC1 张超凡
  6771. #region [S1] Tray盘上料装备(板测)
  6772. /// <summary>
  6773. /// S1工位的数据- 触发信号上次的值
  6774. /// </summary>
  6775. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  6776. /// <summary>
  6777. /// S1工位的数据(含触发信号)
  6778. /// </summary>
  6779. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  6780. /// <summary>
  6781. /// S1工位的数据- 回写点位
  6782. /// </summary>
  6783. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6784. ///// <summary>
  6785. ///// 触发信号
  6786. ///// </summary>
  6787. //private ManualResetEvent[] MreTasks;
  6788. /// <summary>
  6789. /// [S1] Tray盘上料装备(板测)
  6790. /// </summary>
  6791. /// <param name="plcNo">PLC编号</param>
  6792. //private void ReadStation_S1(int plcNo)
  6793. //{
  6794. // // [S1] Tray盘上料装备
  6795. // // [S2] FCT
  6796. // // [S3] 值板机
  6797. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6798. // // [S5] Tray盘下料装备
  6799. // string stationCode = "[S1]";
  6800. // string stationName = "Tray盘上料装备";
  6801. // string stationNameStr = stationCode + stationName;
  6802. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6803. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6804. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6805. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6806. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6807. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6808. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6809. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6810. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  6811. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6812. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  6813. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6814. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6815. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  6816. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  6817. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6818. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  6819. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  6820. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6821. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  6822. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  6823. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  6824. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  6825. // s1PLCData.Add("a1Result", 0); // 产品结果
  6826. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6827. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  6828. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  6829. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  6830. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  6831. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6832. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  6833. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  6834. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  6835. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  6836. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  6837. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6838. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  6839. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  6840. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6841. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  6842. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  6843. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6844. // while (IsRun)
  6845. // {
  6846. // try
  6847. // {
  6848. // if (!GlobalContext._IsCon_Funs1)
  6849. // {
  6850. // UpdatePLCMonitor(1, plcNo, 0);
  6851. // continue;
  6852. // }
  6853. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6854. // {
  6855. // Stopwatch stopwatch1 = new Stopwatch();
  6856. // Stopwatch stopwatch2 = new Stopwatch();
  6857. // stopwatch1.Start();
  6858. // stopwatch2.Start();
  6859. // #region 一次性读取所有数据
  6860. // // 一次性读取所有数据
  6861. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6862. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6863. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6864. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  6865. // int[] datas = data1.Concat(data2).ToArray();
  6866. // datas = datas.Concat(data3).ToArray();
  6867. // datas = datas.Concat(data4).ToArray();
  6868. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  6869. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  6870. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  6871. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  6872. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  6873. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  6874. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  6875. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  6876. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  6877. // s1PLCData["a1MES_FLAG"] = datas[109];
  6878. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  6879. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  6880. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  6881. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  6882. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  6883. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  6884. // s1PLCData["a1Result"] = datas[170];
  6885. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  6886. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  6887. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  6888. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  6889. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  6890. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  6891. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  6892. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  6893. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  6894. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  6895. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  6896. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  6897. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  6898. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  6899. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  6900. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  6901. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  6902. // s1PLCData["a1AGVUpStart"] = datas[308];
  6903. // s1PLCData["a1AGVUpEnd"] = datas[309];
  6904. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  6905. // s1PLCData["a1AGVDownStart"] = datas[321];
  6906. // s1PLCData["a1AGVDownEnd"] = datas[322];
  6907. // #endregion 一次性读取所有数据
  6908. // stopwatch2.Stop();
  6909. // #region 回写操作,写后清空flag
  6910. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  6911. // #endregion 回写操作,写后清空flag
  6912. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6913. // try
  6914. // {
  6915. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  6916. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  6917. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  6918. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  6919. // {
  6920. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  6921. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  6922. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  6923. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6924. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  6925. // }
  6926. // }
  6927. // catch (Exception ex)
  6928. // {
  6929. // // 6代表上位机报警
  6930. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  6931. // string str = ex.StackTrace;
  6932. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6933. // }
  6934. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6935. // #region 上料进站校验
  6936. // try
  6937. // {
  6938. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  6939. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  6940. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  6941. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  6942. // {
  6943. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  6944. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6945. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  6946. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  6947. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  6948. // }
  6949. // }
  6950. // catch (Exception ex)
  6951. // {
  6952. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  6953. // string str = ex.StackTrace;
  6954. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6955. // }
  6956. // #endregion 上料进站校验
  6957. // #region Tray盘上料装备-出站接口
  6958. // try
  6959. // {
  6960. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  6961. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  6962. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  6963. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  6964. // {
  6965. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  6966. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6967. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  6968. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  6969. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  6970. // }
  6971. // }
  6972. // catch (Exception ex)
  6973. // {
  6974. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  6975. // string str = ex.StackTrace;
  6976. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6977. // }
  6978. // #endregion Tray盘上料装备-出站接口
  6979. // #region Tray盘上料装备-将SN发给ICT标机
  6980. // try
  6981. // {
  6982. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  6983. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  6984. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  6985. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  6986. // {
  6987. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  6988. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  6989. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  6990. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  6991. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  6992. // }
  6993. // }
  6994. // catch (Exception ex)
  6995. // {
  6996. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  6997. // string str = ex.StackTrace;
  6998. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6999. // }
  7000. // #endregion Tray盘上料装备-将SN发给ICT标机
  7001. // #region Tray盘上料装备-点检数据
  7002. // //try
  7003. // //{
  7004. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  7005. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  7006. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  7007. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  7008. // // if (pLC_Flag && !mES_Flag) // 1 0
  7009. // // {
  7010. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  7011. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  7012. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  7013. // // }
  7014. // // else if (!pLC_Flag && mES_Flag) // 0 1
  7015. // // {
  7016. // // // 清空写给PLC的数据
  7017. // // // MES_Flag重置为0
  7018. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  7019. // // }
  7020. // //}
  7021. // //catch (Exception ex)
  7022. // //{
  7023. // // // MES_Flag 为2上位机报错
  7024. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7025. // // string str = ex.StackTrace;
  7026. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7027. // //}
  7028. // #endregion Tray盘上料装备-点检数据
  7029. // #region 节拍接口
  7030. // try
  7031. // {
  7032. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  7033. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  7034. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  7035. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  7036. // {
  7037. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  7038. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7039. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  7040. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  7041. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  7042. // }
  7043. // }
  7044. // catch (Exception ex)
  7045. // {
  7046. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  7047. // string str = ex.StackTrace;
  7048. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7049. // }
  7050. // #endregion 节拍接口
  7051. // #region AGV上料
  7052. // // AGV上料叫AGV信号
  7053. // try
  7054. // {
  7055. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  7056. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  7057. // if (a1AGVUpCall != a1AGVUpCallOld)
  7058. // {
  7059. // if (a1AGVUpCall == 1) // 0->1
  7060. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  7061. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  7062. // }
  7063. // }
  7064. // catch (Exception ex)
  7065. // {
  7066. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7067. // string str = ex.StackTrace;
  7068. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7069. // }
  7070. // // AGV上料完成信号
  7071. // try
  7072. // {
  7073. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  7074. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  7075. // if (a1AGVUpEnd != a1AGVUpEndOld)
  7076. // {
  7077. // if (a1AGVUpEnd == 1) // 0->1
  7078. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  7079. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  7080. // }
  7081. // }
  7082. // catch (Exception ex)
  7083. // {
  7084. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7085. // string str = ex.StackTrace;
  7086. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7087. // }
  7088. // #endregion AGV上料
  7089. // #region AGV下料
  7090. // // AGV下料叫agv信号
  7091. // try
  7092. // {
  7093. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  7094. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  7095. // if (a1AGVDownCall != a1AGVDownCallOld)
  7096. // {
  7097. // if (a1AGVDownCall == 1) // 0->1
  7098. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  7099. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  7100. // }
  7101. // }
  7102. // catch (Exception ex)
  7103. // {
  7104. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7105. // string str = ex.StackTrace;
  7106. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7107. // }
  7108. // // AGV下料完成信号
  7109. // try
  7110. // {
  7111. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  7112. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  7113. // if (a1AGVDownEnd != a1AGVDownEndOld)
  7114. // {
  7115. // if (a1AGVDownEnd == 1) // 0->1
  7116. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  7117. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  7118. // }
  7119. // }
  7120. // catch (Exception ex)
  7121. // {
  7122. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7123. // string str = ex.StackTrace;
  7124. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7125. // }
  7126. // #endregion AGV下料
  7127. // #region 心跳
  7128. // try
  7129. // {
  7130. // short states = 0;
  7131. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7132. // }
  7133. // catch (Exception ex)
  7134. // {
  7135. // string str = ex.StackTrace;
  7136. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7137. // }
  7138. // #endregion 心跳
  7139. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7140. // stopwatch1.Stop();
  7141. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7142. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7143. // }
  7144. // else
  7145. // {
  7146. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7147. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7148. // Funs[plcNo].Connect(); // 重连
  7149. // }
  7150. // }
  7151. // catch (Exception ex)
  7152. // {
  7153. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7154. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7155. // Funs[plcNo].ReConnect();
  7156. // }
  7157. // Thread.Sleep(IntervalReadPLC);
  7158. // }
  7159. //}
  7160. /// <summary>
  7161. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  7162. /// </summary>
  7163. /// <param name="plcNo">PLC编号</param>
  7164. /// <param name="stationNameStr">工站全称</param>
  7165. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  7166. {
  7167. Stopwatch stopwatch1 = new Stopwatch();
  7168. Stopwatch stopwatch2 = new Stopwatch();
  7169. try
  7170. {
  7171. stopwatch1.Start();
  7172. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  7173. sn = sn.Replace("\0", "");
  7174. #region 查询载具上的产品信息
  7175. string cavityData = string.Empty;
  7176. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7177. if (string.IsNullOrEmpty(cavityData))
  7178. cavityData = "";
  7179. if (snResult != 0)
  7180. {
  7181. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7182. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  7183. writeToPLC_Flag1.Adress = 2003;
  7184. writeToPLC_Flag1.Value = (short)6;
  7185. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  7186. stopwatch1.Stop();
  7187. AddMessage(LogType.Info,
  7188. stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  7189. "ms");
  7190. return;
  7191. }
  7192. #endregion 查询载具上的产品信息
  7193. string[] cavitySNs = cavityData.Split('.');
  7194. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  7195. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  7196. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  7197. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  7198. if (cavitySNs != null && cavitySNs.Length >= 2)
  7199. {
  7200. a1CavitySN1_VehicleStates = cavitySNs[0];
  7201. a1CavitySN2_VehicleStates = cavitySNs[1];
  7202. a1CavityResult1_VehicleStates = 2;
  7203. a1CavityResult2_VehicleStates = 2;
  7204. }
  7205. if (a1CavitySN1_VehicleStates == "假产品")
  7206. a1CavityResult1_VehicleStates = 3;
  7207. if (a1CavitySN2_VehicleStates == "假产品")
  7208. a1CavityResult2_VehicleStates = 3;
  7209. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7210. // 回写
  7211. stopwatch2.Start();
  7212. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  7213. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  7214. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  7215. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  7216. //// MES_Flag
  7217. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  7218. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7219. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7220. writeToPLC_Flag.Adress = 2003;
  7221. writeToPLC_Flag.Value = mES_Flag;
  7222. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7223. {
  7224. Name = "a1CavitySN1_VehicleStates",
  7225. Adress = 2024,
  7226. ValueType = PLCValueType.String,
  7227. ValueTypeStrLength = 20,
  7228. Value = a1CavitySN1_VehicleStates
  7229. });
  7230. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  7231. {
  7232. Name = "a1CavitySN2_VehicleStates",
  7233. Adress = 2044,
  7234. ValueType = PLCValueType.String,
  7235. ValueTypeStrLength = 20,
  7236. Value = a1CavitySN2_VehicleStates
  7237. });
  7238. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7239. {
  7240. Name = "a1CavityResult1_VehicleStates",
  7241. Adress = 2064,
  7242. ValueType = PLCValueType.Short,
  7243. Value = a1CavityResult1_VehicleStates
  7244. });
  7245. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7246. {
  7247. Name = "a1CavityResult2_VehicleStates",
  7248. Adress = 2065,
  7249. ValueType = PLCValueType.Short,
  7250. Value = a1CavityResult2_VehicleStates
  7251. });
  7252. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7253. stopwatch2.Stop();
  7254. }
  7255. catch (Exception ex)
  7256. {
  7257. string str = ex.StackTrace;
  7258. AddMessage_Station(stationNameStr, LogType.Error,
  7259. $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
  7260. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7261. // MES_Flag
  7262. stopwatch2.Start();
  7263. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7264. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7265. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7266. writeToPLC_Flag.Adress = 2003;
  7267. writeToPLC_Flag.Value = (short)6;
  7268. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7269. stopwatch2.Stop();
  7270. }
  7271. stopwatch1.Stop();
  7272. AddMessage(LogType.Info,
  7273. stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7274. stopwatch2.ElapsedMilliseconds + "ms");
  7275. }
  7276. /// <summary>
  7277. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  7278. /// </summary>
  7279. /// <param name="plcNo">PLC编号</param>
  7280. /// <param name="stationNameStr">工站全称</param>
  7281. private void S1上料进站校验(int plcNo, string stationNameStr)
  7282. {
  7283. Stopwatch stopwatch1 = new Stopwatch();
  7284. Stopwatch stopwatch2 = new Stopwatch();
  7285. try
  7286. {
  7287. stopwatch1.Start();
  7288. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  7289. sn = sn.Replace("\0", "");
  7290. // 保存进站数据+调用进站MES接口
  7291. List<TestItem> item = new List<TestItem>();
  7292. stopwatch2.Start();
  7293. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  7294. item, out string errorMsg);
  7295. stopwatch2.Stop();
  7296. short a1MES_FLAG_Check = (short)result;
  7297. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7298. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7299. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7300. writeToPLC_Flag.Adress = 2077;
  7301. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  7302. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7303. }
  7304. catch (Exception ex)
  7305. {
  7306. string str = ex.StackTrace;
  7307. AddMessage_Station(stationNameStr, LogType.Error,
  7308. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  7309. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7310. // MES_Flag
  7311. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7312. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7313. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7314. writeToPLC_Flag.Adress = 2077;
  7315. writeToPLC_Flag.Value = (short)6;
  7316. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7317. }
  7318. stopwatch1.Stop();
  7319. AddMessage(LogType.Info,
  7320. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7321. stopwatch2.ElapsedMilliseconds + "ms");
  7322. }
  7323. /// <summary>
  7324. /// [S1] Tray盘上料装备(板测)- 出站接口
  7325. /// </summary>
  7326. /// <param name="plcNo"></param>
  7327. /// <param name="stationCode"></param>
  7328. /// <param name="stationName"></param>
  7329. private void S1出站接口(int plcNo, string stationCode, string stationName)
  7330. {
  7331. Stopwatch stopwatch1 = new Stopwatch();
  7332. Stopwatch stopwatch2 = new Stopwatch();
  7333. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7334. string stationNameStr = stationCode + stationName;
  7335. string processItem = stationName; // 测试项目
  7336. try
  7337. {
  7338. stopwatch1.Start();
  7339. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7340. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7341. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7342. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7343. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  7344. sn = sn.Replace("\0", "");
  7345. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  7346. partNo1 = partNo1.Replace("\0", "");
  7347. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  7348. partNo2 = partNo2.Replace("\0", "");
  7349. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  7350. bool pass = a1Result == 1;
  7351. stopwatch2.Start();
  7352. // 产品1
  7353. List<TestItem> items = new List<TestItem>();
  7354. items.Add(new TestItem()
  7355. {
  7356. Parameter_name = "载具码",
  7357. Parameter_value = sn,
  7358. Parameter_unit = ""
  7359. });
  7360. items.Add(new TestItem()
  7361. {
  7362. Parameter_name = "载具穴号",
  7363. Parameter_value = "1",
  7364. Parameter_unit = ""
  7365. });
  7366. items.Add(new TestItem()
  7367. {
  7368. Parameter_name = "产品结果",
  7369. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7370. Parameter_unit = ""
  7371. });
  7372. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7373. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  7374. // 产品2
  7375. items = new List<TestItem>();
  7376. items.Add(new TestItem()
  7377. {
  7378. Parameter_name = "载具码",
  7379. Parameter_value = sn,
  7380. Parameter_unit = ""
  7381. });
  7382. items.Add(new TestItem()
  7383. {
  7384. Parameter_name = "载具穴号",
  7385. Parameter_value = "2",
  7386. Parameter_unit = ""
  7387. });
  7388. items.Add(new TestItem()
  7389. {
  7390. Parameter_name = "产品结果",
  7391. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7392. Parameter_unit = ""
  7393. });
  7394. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7395. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  7396. short result = 0;
  7397. List<int> results = new List<int>() { result1, result2 };
  7398. if (result1 == 1 && result2 == 1)
  7399. result = 1;
  7400. else if (results.Contains(3))
  7401. result = 3;
  7402. else if (results.Contains(2))
  7403. result = 2;
  7404. else if (results.Contains(4))
  7405. result = 4;
  7406. else
  7407. result = 4;
  7408. stopwatch2.Stop();
  7409. #region 存储绑定数据到 边线MES系统中
  7410. if (result == 1)
  7411. {
  7412. string data = string.Concat(partNo1, ".", partNo2);
  7413. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7414. if (resultMesR != 0)
  7415. {
  7416. result = 4;
  7417. AddMessage_Station(stationNameStr, LogType.Error,
  7418. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  7419. }
  7420. }
  7421. #endregion 存储绑定数据到 边线MES系统中
  7422. // MES_Flag 为MES报错
  7423. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7424. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  7425. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7426. writeToPLC_Flag.Name = "a1MES_FLAG";
  7427. writeToPLC_Flag.Adress = 2109;
  7428. writeToPLC_Flag.Value = result;
  7429. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7430. OnMessage(LogType.Debug,
  7431. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7432. }
  7433. catch (Exception ex)
  7434. {
  7435. stopwatch2.Restart();
  7436. // MES_Flag 为4上位机报错
  7437. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  7438. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7439. writeToPLC_Flag.Name = "a1MES_FLAG";
  7440. writeToPLC_Flag.Adress = 2109;
  7441. writeToPLC_Flag.Value = (short)4;
  7442. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7443. stopwatch2.Stop();
  7444. string str = ex.StackTrace;
  7445. AddMessage_Station(stationNameStr, LogType.Error,
  7446. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  7447. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7448. }
  7449. stopwatch1.Stop();
  7450. AddMessage(LogType.Info,
  7451. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  7452. stopwatch2.ElapsedMilliseconds + "ms");
  7453. }
  7454. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  7455. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  7456. //{
  7457. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7458. // string stationNameStr = stationCode + stationName;
  7459. // string processItem = stationName; // 测试项目
  7460. // try
  7461. // {
  7462. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7463. // string accno = "1"; // 工序编号
  7464. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  7465. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  7466. // List<OneCheckItem> items = new List<OneCheckItem>()
  7467. // {
  7468. // new OneCheckItem()
  7469. // {
  7470. // Onecheck_name="胶圈装配行程设定上限",
  7471. // Onecheck_content="上限值",
  7472. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  7473. // },
  7474. // };
  7475. // OneCheckData oneCheckData = new OneCheckData()
  7476. // {
  7477. // Line_code = GlobalContext.LineCode,
  7478. // Line_name = GlobalContext.LineName,
  7479. // Equipment_code = equipmentCode,
  7480. // Equipment_name = equipmentCode,
  7481. // Workorder_code = workorder_code,
  7482. // Procedure_code = accno,
  7483. // Procedure_name = processItem,
  7484. // Oneckeck_values = items,
  7485. // Onecheck_empcode = "",
  7486. // Onecheck_empname = "",
  7487. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  7488. // };
  7489. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  7490. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  7491. // short result = result1 == 1 ? (short)1 : (short)2;
  7492. // // MES_Flag 为4MES报错
  7493. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  7494. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7495. // }
  7496. // catch (Exception ex)
  7497. // {
  7498. // // MES_Flag 为2上位机报错
  7499. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7500. // string str = ex.StackTrace;
  7501. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7502. // }
  7503. //}
  7504. // ReadStation_S1_2 节拍接口+AGV
  7505. /// <summary>
  7506. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  7507. /// </summary>
  7508. /// <param name="plcNo">PLC编号</param>
  7509. /// <param name="stationNameStr">工站全称</param>
  7510. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  7511. {
  7512. Stopwatch stopwatch1 = new Stopwatch();
  7513. Stopwatch stopwatch2 = new Stopwatch();
  7514. try
  7515. {
  7516. stopwatch1.Start();
  7517. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  7518. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  7519. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  7520. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  7521. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  7522. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  7523. // ZS 将SN发给ICT标机(串口)
  7524. short a1MES_FLAG_ICT = 1;
  7525. stopwatch2.Start();
  7526. // MES_Flag
  7527. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  7528. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7529. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7530. writeToPLC_Flag.Adress = 2182;
  7531. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  7532. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7533. stopwatch2.Stop();
  7534. }
  7535. catch (Exception ex)
  7536. {
  7537. string str = ex.StackTrace;
  7538. AddMessage_Station(stationNameStr, LogType.Error,
  7539. $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
  7540. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7541. stopwatch2.Start();
  7542. // MES_Flag
  7543. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  7544. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7545. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7546. writeToPLC_Flag.Adress = 2182;
  7547. writeToPLC_Flag.Value = (short)4;
  7548. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7549. stopwatch2.Stop();
  7550. }
  7551. stopwatch1.Stop();
  7552. AddMessage(LogType.Info,
  7553. stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7554. stopwatch2.ElapsedMilliseconds + "ms");
  7555. }
  7556. /// <summary>
  7557. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  7558. /// </summary>
  7559. /// <param name="plcNo">PLC编号</param>
  7560. /// <param name="stationNameStr">工站全称</param>
  7561. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  7562. {
  7563. Stopwatch stopwatch1 = new Stopwatch();
  7564. Stopwatch stopwatch2 = new Stopwatch();
  7565. try
  7566. {
  7567. stopwatch1.Start();
  7568. // ZS 呼叫AGV
  7569. short a1AGVUpCall = 2;
  7570. stopwatch2.Start();
  7571. // a1AGVUpCall
  7572. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7573. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7574. writeToPLC_Flag.Name = "a1AGVUpCall";
  7575. writeToPLC_Flag.Adress = 2307;
  7576. writeToPLC_Flag.Value = a1AGVUpCall;
  7577. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7578. stopwatch2.Stop();
  7579. }
  7580. catch (Exception ex)
  7581. {
  7582. string str = ex.StackTrace;
  7583. AddMessage_Station(stationNameStr, LogType.Error,
  7584. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7585. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7586. // a1AGVUpCall
  7587. stopwatch2.Start();
  7588. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7589. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7590. writeToPLC_Flag.Name = "a1AGVUpCall";
  7591. writeToPLC_Flag.Adress = 2307;
  7592. writeToPLC_Flag.Value = (short)4;
  7593. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7594. stopwatch2.Stop();
  7595. }
  7596. stopwatch1.Stop();
  7597. AddMessage(LogType.Info,
  7598. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7599. stopwatch2.ElapsedMilliseconds + "ms");
  7600. }
  7601. /// <summary>
  7602. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  7603. /// </summary>
  7604. /// <param name="plcNo">PLC编号</param>
  7605. /// <param name="stationNameStr">工站全称</param>
  7606. private void S1AGV上料完成(int plcNo, string stationNameStr)
  7607. {
  7608. Stopwatch stopwatch1 = new Stopwatch();
  7609. Stopwatch stopwatch2 = new Stopwatch();
  7610. try
  7611. {
  7612. stopwatch1.Start();
  7613. // ZS AGV上料完成,让小车离开
  7614. short a1AGVUpEnd = 2;
  7615. stopwatch2.Start();
  7616. // a1AGVUpEnd
  7617. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7618. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7619. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7620. writeToPLC_Flag.Adress = 2309;
  7621. writeToPLC_Flag.Value = a1AGVUpEnd;
  7622. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7623. stopwatch2.Stop();
  7624. }
  7625. catch (Exception ex)
  7626. {
  7627. string str = ex.StackTrace;
  7628. AddMessage_Station(stationNameStr, LogType.Error,
  7629. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7630. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7631. // a1AGVUpEnd
  7632. stopwatch2.Start();
  7633. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7634. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7635. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7636. writeToPLC_Flag.Adress = 2309;
  7637. writeToPLC_Flag.Value = (short)4;
  7638. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7639. stopwatch2.Stop();
  7640. }
  7641. stopwatch1.Stop();
  7642. AddMessage(LogType.Info,
  7643. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7644. stopwatch2.ElapsedMilliseconds + "ms");
  7645. }
  7646. /// <summary>
  7647. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  7648. /// </summary>
  7649. /// <param name="plcNo">PLC编号</param>
  7650. /// <param name="stationNameStr">工站全称</param>
  7651. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  7652. {
  7653. Stopwatch stopwatch1 = new Stopwatch();
  7654. Stopwatch stopwatch2 = new Stopwatch();
  7655. try
  7656. {
  7657. stopwatch1.Start();
  7658. // ZS 呼叫AGV
  7659. short a1AGVDownCall = 2;
  7660. stopwatch2.Start();
  7661. // a1AGVDownCall
  7662. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7663. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7664. writeToPLC_Flag.Name = "a1AGVDownCall";
  7665. writeToPLC_Flag.Adress = 2320;
  7666. writeToPLC_Flag.Value = a1AGVDownCall;
  7667. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7668. stopwatch2.Stop();
  7669. }
  7670. catch (Exception ex)
  7671. {
  7672. string str = ex.StackTrace;
  7673. AddMessage_Station(stationNameStr, LogType.Error,
  7674. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7675. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7676. // a1AGVDownCall
  7677. stopwatch2.Start();
  7678. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7679. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7680. writeToPLC_Flag.Name = "a1AGVDownCall";
  7681. writeToPLC_Flag.Adress = 2320;
  7682. writeToPLC_Flag.Value = (short)4;
  7683. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7684. stopwatch2.Stop();
  7685. }
  7686. stopwatch1.Stop();
  7687. AddMessage(LogType.Info,
  7688. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7689. stopwatch2.ElapsedMilliseconds + "ms");
  7690. }
  7691. /// <summary>
  7692. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  7693. /// </summary>
  7694. /// <param name="plcNo">PLC编号</param>
  7695. /// <param name="stationNameStr">工站全称</param>
  7696. private void S1AGV下料完成(int plcNo, string stationNameStr)
  7697. {
  7698. Stopwatch stopwatch1 = new Stopwatch();
  7699. Stopwatch stopwatch2 = new Stopwatch();
  7700. try
  7701. {
  7702. stopwatch1.Start();
  7703. // ZS AGV上料完成,让小车离开
  7704. short a1AGVDownEnd = 2;
  7705. stopwatch2.Start();
  7706. // a1AGVDownEnd
  7707. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7708. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7709. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7710. writeToPLC_Flag.Adress = 2322;
  7711. writeToPLC_Flag.Value = a1AGVDownEnd;
  7712. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7713. stopwatch2.Stop();
  7714. }
  7715. catch (Exception ex)
  7716. {
  7717. string str = ex.StackTrace;
  7718. AddMessage_Station(stationNameStr, LogType.Error,
  7719. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7720. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7721. // a1AGVDownEnd
  7722. stopwatch2.Start();
  7723. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7724. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7725. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7726. writeToPLC_Flag.Adress = 2322;
  7727. writeToPLC_Flag.Value = (short)4;
  7728. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7729. stopwatch2.Stop();
  7730. }
  7731. stopwatch1.Stop();
  7732. AddMessage(LogType.Info,
  7733. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7734. stopwatch2.ElapsedMilliseconds + "ms");
  7735. }
  7736. #endregion [S1] Tray盘上料装备(板测)
  7737. #endregion PLC1 张超凡
  7738. #region PLC2 李晓奇
  7739. #region [S2] FCT(板测)
  7740. /// <summary>
  7741. /// S2工位的数据- 触发信号上次的值
  7742. /// </summary>
  7743. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  7744. /// <summary>
  7745. /// S2工位的数据(含触发信号)
  7746. /// </summary>
  7747. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  7748. /// <summary>
  7749. /// S2工位的数据- 回写点位
  7750. /// </summary>
  7751. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  7752. /// <summary>
  7753. /// [S2] FCT(板测)
  7754. /// </summary>
  7755. /// <param name="plcNo">PLC编号</param>
  7756. //private void ReadStation_S2(int plcNo)
  7757. //{
  7758. // // [S1] Tray盘上料装备
  7759. // // [S2] FCT
  7760. // // [S3] 值板机
  7761. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  7762. // // [S5] Tray盘下料装备
  7763. // /// 上位机心跳
  7764. // /// 获取设备报警数据与状态信息
  7765. // string stationCode = "[S2]";
  7766. // string stationName = "FCT";
  7767. // string stationNameStr = stationCode + stationName;
  7768. // #region 创建字典
  7769. // // 触发信号字典 赋值
  7770. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  7771. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  7772. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7773. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7774. // // PLC数据字典 赋值
  7775. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  7776. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  7777. // s2PLCData.Add("b1ProductSN_Check", 0);
  7778. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  7779. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  7780. // s2PLCData.Add("b1ProductSN_Unbind", "");
  7781. // s2PLCData.Add("b1ProductSN_Bind", "");
  7782. // s2PLCData.Add("b1Part1SN_Bind", "");
  7783. // s2PLCData.Add("b1Part2SN_Bind", "");
  7784. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  7785. // s2PLCData.Add("b1MES_FLAG", 0);
  7786. // s2PLCData.Add("b1ProductSN", 0);
  7787. // s2PLCData.Add("b1Part1Result", 0);
  7788. // s2PLCData.Add("b1Part2Result", 0);
  7789. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  7790. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  7791. // s2PLCData.Add("b1OEEProductSN", "");
  7792. // s2PLCData.Add("b1OEEType", 0);
  7793. // #endregion 创建字典
  7794. // while (IsRun)
  7795. // {
  7796. // try
  7797. // {
  7798. // if (!GlobalContext._IsCon_Funs2)
  7799. // {
  7800. // UpdatePLCMonitor(1, plcNo, 0);
  7801. // continue;
  7802. // }
  7803. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  7804. // {
  7805. // Stopwatch stopwatch1 = new Stopwatch();
  7806. // Stopwatch stopwatch2 = new Stopwatch();
  7807. // stopwatch1.Start();
  7808. // stopwatch2.Start();
  7809. // #region 一次性读取所有数据
  7810. // // 一次性读取所有数据
  7811. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  7812. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  7813. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  7814. // int[] datas = data1.Concat(data2).ToArray();
  7815. // datas = datas.Concat(data3).ToArray();
  7816. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  7817. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  7818. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  7819. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  7820. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  7821. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  7822. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  7823. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  7824. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  7825. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  7826. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  7827. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  7828. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  7829. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  7830. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  7831. // s2PLCData["b1MES_FLAG"] = datas[169];
  7832. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  7833. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  7834. // s2PLCData["b1Part1Result"] = datas[190];
  7835. // s2PLCData["b1Part2Result"] = datas[191];
  7836. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  7837. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  7838. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  7839. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  7840. // s2PLCData["b1OEEType"] = datas[224];
  7841. // #endregion 一次性读取所有数据
  7842. // stopwatch2.Stop();
  7843. // #region 回写操作,写后清空flag
  7844. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  7845. // #endregion 回写操作,写后清空flag
  7846. // #region 进站校验
  7847. // try
  7848. // {
  7849. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  7850. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7851. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  7852. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  7853. // {
  7854. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  7855. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  7856. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  7857. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  7858. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  7859. // }
  7860. // }
  7861. // catch (Exception ex)
  7862. // {
  7863. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7864. // string str = ex.StackTrace;
  7865. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7866. // }
  7867. // #endregion 进站校验
  7868. // #region 二穴载具解绑/绑定(产品换载具)
  7869. // try
  7870. // {
  7871. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  7872. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7873. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  7874. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  7875. // {
  7876. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  7877. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  7878. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  7879. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  7880. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  7881. // }
  7882. // }
  7883. // catch (Exception ex)
  7884. // {
  7885. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7886. // string str = ex.StackTrace;
  7887. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7888. // }
  7889. // #endregion 二穴载具解绑/绑定(产品换载具)
  7890. // #region FCT-出站接口
  7891. // try
  7892. // {
  7893. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  7894. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  7895. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  7896. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  7897. // {
  7898. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  7899. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7900. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  7901. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  7902. // }
  7903. // }
  7904. // catch (Exception ex)
  7905. // {
  7906. // // MES_Flag 为6上位机报错
  7907. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  7908. // string str = ex.StackTrace;
  7909. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7910. // }
  7911. // #endregion FCT-出站接口
  7912. // #region 节拍接口
  7913. // try
  7914. // {
  7915. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  7916. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  7917. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  7918. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  7919. // {
  7920. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  7921. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7922. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  7923. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  7924. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  7925. // }
  7926. // }
  7927. // catch (Exception ex)
  7928. // {
  7929. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  7930. // string str = ex.StackTrace;
  7931. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7932. // }
  7933. // #endregion 节拍接口
  7934. // #region 心跳
  7935. // try
  7936. // {
  7937. // short states = 0;
  7938. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7939. // }
  7940. // catch (Exception ex)
  7941. // {
  7942. // string str = ex.StackTrace;
  7943. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7944. // }
  7945. // #endregion 心跳
  7946. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7947. // stopwatch1.Stop();
  7948. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7949. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7950. // }
  7951. // else
  7952. // {
  7953. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7954. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7955. // Funs[plcNo].Connect();
  7956. // }
  7957. // }
  7958. // catch (Exception ex)
  7959. // {
  7960. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7961. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7962. // Funs[plcNo].ReConnect();
  7963. // }
  7964. // Thread.Sleep(IntervalReadPLC);
  7965. // }
  7966. //}
  7967. /// <summary>
  7968. /// [S2] FCT(板测)- 进站校验
  7969. /// </summary>
  7970. /// <param name="plcNo">PLC编号</param>
  7971. /// <param name="stationNameStr">工站全称</param>
  7972. private void S2进站校验(int plcNo, string stationNameStr)
  7973. {
  7974. Stopwatch stopwatch1 = new Stopwatch();
  7975. Stopwatch stopwatch2 = new Stopwatch();
  7976. try
  7977. {
  7978. stopwatch1.Start();
  7979. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  7980. sn = sn.Replace("\0", "");
  7981. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7982. // 查询物料码By载具码 并判断是不是假产品
  7983. string cavityData = string.Empty;
  7984. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7985. if (string.IsNullOrEmpty(cavityData))
  7986. cavityData = "";
  7987. if (snResult != 0)
  7988. {
  7989. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7990. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  7991. writeToPLC_Flag1.Adress = 2003;
  7992. writeToPLC_Flag1.Value = (short)6;
  7993. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  7994. stopwatch1.Stop();
  7995. AddMessage(LogType.Info,
  7996. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7997. return;
  7998. }
  7999. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  8000. string[] cavitySNs = cavityData.Split('.');
  8001. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  8002. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  8003. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8004. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8005. if (cavitySNs != null && cavitySNs.Length >= 2)
  8006. {
  8007. b1Part1SN_Check = cavitySNs[0];
  8008. b1Part2SN_Check = cavitySNs[1];
  8009. b1Part1Result_Check = 2;
  8010. b1Part2Result_Check = 2;
  8011. }
  8012. if (b1Part1SN_Check == "假产品")
  8013. b1Part1Result_Check = 3;
  8014. if (b1Part2SN_Check == "假产品")
  8015. b1Part2Result_Check = 3;
  8016. // 调用MES进站
  8017. stopwatch2.Start();
  8018. // 调用MES进站 - 产品1
  8019. List<TestItem> item;
  8020. int result1 = b1Part1Result_Check;
  8021. if (result1 != 3)
  8022. {
  8023. item = new List<TestItem>();
  8024. item.Add(new TestItem()
  8025. {
  8026. Parameter_name = "载具码",
  8027. Parameter_value = sn,
  8028. });
  8029. item.Add(new TestItem()
  8030. {
  8031. Parameter_name = "载具穴号",
  8032. Parameter_value = "1",
  8033. });
  8034. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8035. b1Part1SN_Check, item, out string errorMsg);
  8036. }
  8037. // 调用MES进站 - 产品2
  8038. int result2 = b1Part2Result_Check;
  8039. if (result2 != 3)
  8040. {
  8041. item = new List<TestItem>();
  8042. item.Add(new TestItem()
  8043. {
  8044. Parameter_name = "载具码",
  8045. Parameter_value = sn,
  8046. });
  8047. item.Add(new TestItem()
  8048. {
  8049. Parameter_name = "载具穴号",
  8050. Parameter_value = "2",
  8051. });
  8052. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8053. b1Part2SN_Check, item, out string errorMsg);
  8054. }
  8055. stopwatch2.Stop();
  8056. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8057. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8058. int result = result1;
  8059. if (result == 1)
  8060. result = result2;
  8061. short b1MES_FLAG_Check = (short)result;
  8062. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  8063. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  8064. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  8065. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  8066. //// MES_Flag
  8067. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8068. WriteToPLC_Flag
  8069. writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8070. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  8071. writeToPLC_Flag.Adress = 2003;
  8072. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  8073. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8074. {
  8075. Name = "b1Part1SN_Check",
  8076. Adress = 2024,
  8077. ValueType = PLCValueType.String,
  8078. ValueTypeStrLength = 20,
  8079. Value = b1Part1SN_Check
  8080. });
  8081. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8082. {
  8083. Name = "b1Part2SN_Check",
  8084. Adress = 2044,
  8085. ValueType = PLCValueType.String,
  8086. ValueTypeStrLength = 20,
  8087. Value = b1Part2SN_Check
  8088. });
  8089. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8090. {
  8091. Name = "b1Part1Result_Check",
  8092. Adress = 2064,
  8093. ValueType = PLCValueType.Short,
  8094. Value = b1Part1Result_Check
  8095. });
  8096. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8097. {
  8098. Name = "b1Part2Result_Check",
  8099. Adress = 2065,
  8100. ValueType = PLCValueType.Short,
  8101. Value = b1Part2Result_Check
  8102. });
  8103. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  8104. }
  8105. catch (Exception ex)
  8106. {
  8107. string str = ex.StackTrace;
  8108. AddMessage_Station(stationNameStr, LogType.Error,
  8109. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8110. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8111. // MES_Flag
  8112. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8113. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8114. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  8115. writeToPLC_Flag.Adress = 2003;
  8116. writeToPLC_Flag.Value = (short)6;
  8117. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  8118. }
  8119. stopwatch1.Stop();
  8120. AddMessage(LogType.Info,
  8121. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8122. stopwatch2.ElapsedMilliseconds + "ms");
  8123. }
  8124. /// <summary>
  8125. /// [S2] FCT(板测)- 二穴载具解绑绑定
  8126. /// </summary>
  8127. /// <param name="plcNo">PLC编号</param>
  8128. /// <param name="stationNameStr">工站全称</param>
  8129. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  8130. {
  8131. Stopwatch stopwatch1 = new Stopwatch();
  8132. Stopwatch stopwatch2 = new Stopwatch();
  8133. try
  8134. {
  8135. stopwatch1.Start();
  8136. // 产品换载具
  8137. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  8138. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  8139. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  8140. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  8141. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  8142. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  8143. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  8144. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  8145. stopwatch2.Start();
  8146. #region 查询载具上的产品信息
  8147. //string cavityData = string.Empty;
  8148. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  8149. //if (string.IsNullOrEmpty(cavityData))
  8150. // cavityData = "";
  8151. //if (snResult != 0)
  8152. //{
  8153. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8154. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8155. // writeToPLC_Flag.Adress = 2077;
  8156. // writeToPLC_Flag.Value = (short)6;
  8157. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8158. // stopwatch1.Stop();
  8159. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8160. // return;
  8161. //}
  8162. #endregion 查询载具上的产品信息
  8163. #region 解绑(边线MES系统)
  8164. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  8165. if (snResult != 0)
  8166. {
  8167. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8168. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  8169. writeToPLC_Flag1.Adress = 2077;
  8170. writeToPLC_Flag1.Value = (short)6;
  8171. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  8172. stopwatch1.Stop();
  8173. AddMessage(LogType.Info,
  8174. stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
  8175. stopwatch1.ElapsedMilliseconds + "ms");
  8176. return;
  8177. }
  8178. #endregion 解绑(边线MES系统)
  8179. #region 存储绑定数据到 边线MES系统中
  8180. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  8181. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  8182. if (snResult != 0)
  8183. {
  8184. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8185. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  8186. writeToPLC_Flag1.Adress = 2077;
  8187. writeToPLC_Flag1.Value = (short)6;
  8188. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  8189. stopwatch1.Stop();
  8190. AddMessage(LogType.Info,
  8191. stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
  8192. stopwatch1.ElapsedMilliseconds + "ms");
  8193. return;
  8194. }
  8195. #endregion 存储绑定数据到 边线MES系统中
  8196. stopwatch2.Stop();
  8197. short b1MES_FLAG_Unbind = 1;
  8198. // MES_Flag
  8199. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8200. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8201. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8202. writeToPLC_Flag.Adress = 2077;
  8203. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  8204. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8205. }
  8206. catch (Exception ex)
  8207. {
  8208. string str = ex.StackTrace;
  8209. AddMessage_Station(stationNameStr, LogType.Error,
  8210. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8211. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8212. // MES_Flag
  8213. stopwatch2.Start();
  8214. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  8215. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8216. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8217. writeToPLC_Flag.Adress = 2077;
  8218. writeToPLC_Flag.Value = (short)6;
  8219. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8220. stopwatch2.Stop();
  8221. }
  8222. stopwatch1.Stop();
  8223. AddMessage(LogType.Info,
  8224. stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8225. stopwatch2.ElapsedMilliseconds + "ms");
  8226. }
  8227. //// 上次采集到的SN
  8228. //private string sn_FCT = string.Empty;
  8229. /// <summary>
  8230. /// [S2] FCT(板测)- 出站数据
  8231. /// </summary>
  8232. private void S2出站接口(int plcNo, string stationCode, string stationName)
  8233. {
  8234. Stopwatch stopwatch1 = new Stopwatch();
  8235. Stopwatch stopwatch2 = new Stopwatch();
  8236. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8237. string stationNameStr = stationCode + stationName;
  8238. string processItem = stationName; // 测试项目
  8239. try
  8240. {
  8241. stopwatch1.Start();
  8242. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8243. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8244. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8245. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8246. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  8247. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  8248. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  8249. bool pass1 = b1Part1Result == 1;
  8250. bool pass2 = b1Part2Result == 1;
  8251. #region 根据 载具SN 查 物料SN
  8252. string cavityData = string.Empty;
  8253. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  8254. if (string.IsNullOrEmpty(cavityData))
  8255. cavityData = "";
  8256. if (snResult != 0)
  8257. {
  8258. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8259. writeToPLC_Flag1.Name = "b1MES_FLAG";
  8260. writeToPLC_Flag1.Adress = 2169;
  8261. writeToPLC_Flag1.Value = (short)4;
  8262. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  8263. stopwatch1.Stop();
  8264. AddMessage(LogType.Info,
  8265. stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8266. "ms");
  8267. return;
  8268. }
  8269. #endregion 根据 载具SN 查 物料SN
  8270. string[] cavitySNs = cavityData.Split('.');
  8271. string b1ProductSN1 = string.Empty;
  8272. string b1ProductSN2 = string.Empty;
  8273. if (cavitySNs != null && cavitySNs.Length >= 2)
  8274. {
  8275. b1ProductSN1 = cavitySNs[0];
  8276. b1ProductSN2 = cavitySNs[1];
  8277. }
  8278. stopwatch2.Start();
  8279. // 产品1
  8280. int result1 = 0;
  8281. if (b1ProductSN1 == "假产品")
  8282. result1 = 1;
  8283. else
  8284. {
  8285. List<TestItem> items1 = new List<TestItem>();
  8286. items1.Add(new TestItem()
  8287. {
  8288. Parameter_name = "载具码",
  8289. Parameter_value = b1ProductSN.ToString(),
  8290. Parameter_unit = ""
  8291. });
  8292. items1.Add(new TestItem()
  8293. {
  8294. Parameter_name = "载具穴号",
  8295. Parameter_value = "1",
  8296. Parameter_unit = ""
  8297. });
  8298. items1.Add(new TestItem()
  8299. {
  8300. Parameter_name = "产品结果",
  8301. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  8302. Parameter_unit = ""
  8303. });
  8304. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8305. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  8306. }
  8307. // 产品2
  8308. int result2 = 0;
  8309. if (b1ProductSN1 == "假产品")
  8310. result2 = 1;
  8311. else
  8312. {
  8313. List<TestItem> items2 = new List<TestItem>();
  8314. items2.Add(new TestItem()
  8315. {
  8316. Parameter_name = "载具码",
  8317. Parameter_value = b1ProductSN.ToString(),
  8318. Parameter_unit = ""
  8319. });
  8320. items2.Add(new TestItem()
  8321. {
  8322. Parameter_name = "载具穴号",
  8323. Parameter_value = "2",
  8324. Parameter_unit = ""
  8325. });
  8326. items2.Add(new TestItem()
  8327. {
  8328. Parameter_name = "产品结果",
  8329. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  8330. Parameter_unit = ""
  8331. });
  8332. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  8333. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  8334. }
  8335. short result = 0;
  8336. List<int> results = new List<int>() { result1, result2 };
  8337. if (result1 == 1 && result2 == 1)
  8338. result = 1;
  8339. else if (results.Contains(3))
  8340. result = 3;
  8341. else if (results.Contains(2))
  8342. result = 2;
  8343. else if (results.Contains(4))
  8344. result = 4;
  8345. else
  8346. result = 4;
  8347. stopwatch2.Stop();
  8348. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8349. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8350. writeToPLC_Flag.Name = "b1MES_FLAG";
  8351. writeToPLC_Flag.Adress = 2169;
  8352. writeToPLC_Flag.Value = result;
  8353. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8354. OnMessage(LogType.Debug,
  8355. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8356. }
  8357. catch (Exception ex)
  8358. {
  8359. stopwatch2.Restart();
  8360. // MES_Flag 为4上位机报错
  8361. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  8362. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8363. writeToPLC_Flag.Name = "b1MES_FLAG";
  8364. writeToPLC_Flag.Adress = 2169;
  8365. writeToPLC_Flag.Value = (short)4;
  8366. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8367. stopwatch2.Stop();
  8368. string str = ex.StackTrace;
  8369. AddMessage_Station(stationNameStr, LogType.Error,
  8370. $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8371. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8372. }
  8373. stopwatch1.Stop();
  8374. AddMessage(LogType.Info,
  8375. stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8376. stopwatch2.ElapsedMilliseconds + "ms");
  8377. }
  8378. #endregion [S2] FCT(板测)
  8379. #endregion PLC2 李晓奇
  8380. #region PLC3 刘永村
  8381. #region [S3] 值板机
  8382. /// <summary>
  8383. /// S3工位的数据- 触发信号上次的值
  8384. /// </summary>
  8385. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  8386. /// <summary>
  8387. /// S3工位的数据(含触发信号)
  8388. /// </summary>
  8389. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  8390. /// <summary>
  8391. /// S3工位的数据- 回写点位
  8392. /// </summary>
  8393. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8394. /// <summary>
  8395. /// [S3] 值板机
  8396. /// </summary>
  8397. /// <param name="plcNo">PLC编号</param>
  8398. //private void ReadStation_S3(int plcNo)
  8399. //{
  8400. // // [S1] Tray盘上料装备
  8401. // // [S2] FCT
  8402. // // [S3] 值板机
  8403. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8404. // // [S5] Tray盘下料装备
  8405. // /// 上位机心跳
  8406. // /// 获取设备报警数据与状态信息
  8407. // string stationCode = "[S3]";
  8408. // string stationName = "值板机";
  8409. // string stationNameStr = stationCode + stationName;
  8410. // #region 创建字典
  8411. // // 触发信号字典 赋值
  8412. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8413. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8414. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8415. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8416. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8417. // // PLC数据字典 赋值
  8418. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8419. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  8420. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8421. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8422. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  8423. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8424. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8425. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8426. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  8427. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8428. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  8429. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  8430. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8431. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8432. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  8433. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  8434. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  8435. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8436. // s3PLCData.Add("c1Result", 0); // 产品结果
  8437. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8438. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  8439. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  8440. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  8441. // #endregion 创建字典
  8442. // while (IsRun)
  8443. // {
  8444. // try
  8445. // {
  8446. // if (!GlobalContext._IsCon_Funs3)
  8447. // {
  8448. // UpdatePLCMonitor(1, plcNo, 0);
  8449. // continue;
  8450. // }
  8451. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8452. // {
  8453. // Stopwatch stopwatch1 = new Stopwatch();
  8454. // Stopwatch stopwatch2 = new Stopwatch();
  8455. // stopwatch1.Start();
  8456. // stopwatch2.Start();
  8457. // #region 一次性读取所有数据
  8458. // // 一次性读取所有数据
  8459. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  8460. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8461. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  8462. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  8463. // int[] datas = data1.Concat(data2).ToArray();
  8464. // datas = datas.Concat(data3).ToArray();
  8465. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  8466. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  8467. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8468. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  8469. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  8470. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  8471. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8472. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  8473. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  8474. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  8475. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8476. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8477. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  8478. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  8479. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  8480. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  8481. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8482. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  8483. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  8484. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  8485. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  8486. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  8487. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  8488. // #endregion 一次性读取所有数据
  8489. // stopwatch2.Stop();
  8490. // #region 回写操作,写后清空flag
  8491. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  8492. // #endregion 回写操作,写后清空flag
  8493. // #region S3进站校验
  8494. // try
  8495. // {
  8496. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  8497. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  8498. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  8499. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  8500. // {
  8501. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  8502. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8503. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  8504. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8505. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  8506. // }
  8507. // }
  8508. // catch (Exception ex)
  8509. // {
  8510. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8511. // string str = ex.StackTrace;
  8512. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8513. // }
  8514. // #endregion S3进站校验
  8515. // #region S3二穴载具解绑
  8516. // try
  8517. // {
  8518. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  8519. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  8520. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  8521. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  8522. // {
  8523. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8524. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  8525. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  8526. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  8527. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  8528. // }
  8529. // }
  8530. // catch (Exception ex)
  8531. // {
  8532. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  8533. // string str = ex.StackTrace;
  8534. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8535. // }
  8536. // #endregion S3二穴载具解绑
  8537. // #region S3二穴载具绑定
  8538. // try
  8539. // {
  8540. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  8541. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  8542. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  8543. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  8544. // {
  8545. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8546. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  8547. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  8548. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  8549. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  8550. // }
  8551. // }
  8552. // catch (Exception ex)
  8553. // {
  8554. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8555. // string str = ex.StackTrace;
  8556. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8557. // }
  8558. // #endregion S3二穴载具绑定
  8559. // #region S3出站接口(+一穴载具绑定)
  8560. // try
  8561. // {
  8562. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  8563. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  8564. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  8565. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  8566. // {
  8567. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  8568. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8569. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  8570. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  8571. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  8572. // }
  8573. // }
  8574. // catch (Exception ex)
  8575. // {
  8576. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  8577. // string str = ex.StackTrace;
  8578. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8579. // }
  8580. // #endregion S3出站接口(+一穴载具绑定)
  8581. // #region S3节拍接口
  8582. // try
  8583. // {
  8584. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  8585. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  8586. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  8587. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  8588. // {
  8589. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  8590. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8591. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  8592. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  8593. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  8594. // }
  8595. // }
  8596. // catch (Exception ex)
  8597. // {
  8598. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  8599. // string str = ex.StackTrace;
  8600. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8601. // }
  8602. // #endregion S3节拍接口
  8603. // #region 心跳
  8604. // try
  8605. // {
  8606. // short states = 0;
  8607. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8608. // }
  8609. // catch (Exception ex)
  8610. // {
  8611. // string str = ex.StackTrace;
  8612. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8613. // }
  8614. // #endregion 心跳
  8615. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8616. // stopwatch1.Stop();
  8617. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8618. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8619. // }
  8620. // else
  8621. // {
  8622. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8623. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8624. // Funs[plcNo].Connect();
  8625. // }
  8626. // }
  8627. // catch (Exception ex)
  8628. // {
  8629. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8630. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8631. // Funs[plcNo].ReConnect();
  8632. // }
  8633. // Thread.Sleep(IntervalReadPLC);
  8634. // }
  8635. //}
  8636. /// <summary>
  8637. /// [S3] 值板机- 进站校验
  8638. /// </summary>
  8639. /// <param name="plcNo">PLC编号</param>
  8640. /// <param name="stationNameStr">工站全称</param>
  8641. private void S3进站校验(int plcNo, string stationNameStr)
  8642. {
  8643. Stopwatch stopwatch1 = new Stopwatch();
  8644. Stopwatch stopwatch2 = new Stopwatch();
  8645. try
  8646. {
  8647. stopwatch1.Start();
  8648. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  8649. sn = sn.Replace("\0", "");
  8650. #region 查询载具上的产品信息
  8651. string cavityData = string.Empty;
  8652. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8653. if (string.IsNullOrEmpty(cavityData))
  8654. cavityData = "";
  8655. if (snResult != 0)
  8656. {
  8657. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8658. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  8659. writeToPLC_Flag1.Adress = 2003;
  8660. writeToPLC_Flag1.Value = (short)6;
  8661. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  8662. stopwatch1.Stop();
  8663. AddMessage(LogType.Info,
  8664. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8665. return;
  8666. }
  8667. #endregion 查询载具上的产品信息
  8668. string[] cavitySNs = cavityData.Split('.');
  8669. string part1Str = ""; // 产品1的SN码
  8670. string part2Str = ""; // 产品2的SN码
  8671. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8672. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8673. if (cavitySNs != null && cavitySNs.Length >= 2)
  8674. {
  8675. part1Str = cavitySNs[0];
  8676. part2Str = cavitySNs[1];
  8677. c1Part1Result_Check = 2;
  8678. c1Part2Result_Check = 2;
  8679. }
  8680. if (part1Str == "假产品")
  8681. c1Part1Result_Check = 3;
  8682. if (part2Str == "假产品")
  8683. c1Part2Result_Check = 3;
  8684. // 调用MES进站
  8685. stopwatch2.Start();
  8686. // 调用MES进站 - 产品1
  8687. List<TestItem> item;
  8688. int result1 = c1Part1Result_Check;
  8689. if (result1 != 3)
  8690. {
  8691. item = new List<TestItem>();
  8692. item.Add(new TestItem()
  8693. {
  8694. Parameter_name = "载具码",
  8695. Parameter_value = sn,
  8696. });
  8697. item.Add(new TestItem()
  8698. {
  8699. Parameter_name = "载具穴号",
  8700. Parameter_value = "1",
  8701. });
  8702. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8703. part1Str, item, out string errorMsg);
  8704. }
  8705. // 调用MES进站 - 产品2
  8706. int result2 = c1Part2Result_Check;
  8707. if (result2 != 3)
  8708. {
  8709. item = new List<TestItem>();
  8710. item.Add(new TestItem()
  8711. {
  8712. Parameter_name = "载具码",
  8713. Parameter_value = sn,
  8714. });
  8715. item.Add(new TestItem()
  8716. {
  8717. Parameter_name = "载具穴号",
  8718. Parameter_value = "2",
  8719. });
  8720. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8721. part2Str, item, out string errorMsg);
  8722. }
  8723. stopwatch2.Stop();
  8724. if (result1 == 2)
  8725. c1Part1Result_Check = 2;
  8726. if (result2 == 2)
  8727. c1Part2Result_Check = 2;
  8728. int result = result1;
  8729. if (result == 1)
  8730. result = result2;
  8731. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  8732. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  8733. short c1MES_FLAG_Check = (short)result;
  8734. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  8735. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  8736. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  8737. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  8738. //// MES_Flag
  8739. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8740. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8741. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8742. writeToPLC_Flag.Adress = 2003;
  8743. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  8744. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8745. {
  8746. Name = "c1Part1Result_Check",
  8747. Adress = 2024,
  8748. ValueType = PLCValueType.Short,
  8749. Value = c1Part1Result_Check
  8750. });
  8751. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8752. {
  8753. Name = "c1Part2Result_Check",
  8754. Adress = 2025,
  8755. ValueType = PLCValueType.Short,
  8756. Value = c1Part2Result_Check
  8757. });
  8758. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8759. {
  8760. Name = "c1Part1Num_Check",
  8761. Adress = 2026,
  8762. ValueType = PLCValueType.Short,
  8763. Value = c1Part1Num_Check
  8764. });
  8765. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8766. {
  8767. Name = "c1Part2Num_Check",
  8768. Adress = 2027,
  8769. ValueType = PLCValueType.Short,
  8770. Value = c1Part2Num_Check
  8771. });
  8772. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8773. }
  8774. catch (Exception ex)
  8775. {
  8776. string str = ex.StackTrace;
  8777. AddMessage_Station(stationNameStr, LogType.Error,
  8778. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8779. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8780. // MES_Flag
  8781. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8782. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8783. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8784. writeToPLC_Flag.Adress = 2003;
  8785. writeToPLC_Flag.Value = (short)6;
  8786. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8787. }
  8788. stopwatch1.Stop();
  8789. AddMessage(LogType.Info,
  8790. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8791. stopwatch2.ElapsedMilliseconds + "ms");
  8792. }
  8793. /// <summary>
  8794. /// [S3] 值板机 - 二穴载具解绑
  8795. /// </summary>
  8796. /// <param name="plcNo">PLC编号</param>
  8797. /// <param name="stationNameStr">工站全称</param>
  8798. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  8799. {
  8800. Stopwatch stopwatch1 = new Stopwatch();
  8801. Stopwatch stopwatch2 = new Stopwatch();
  8802. try
  8803. {
  8804. stopwatch1.Start();
  8805. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8806. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8807. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8808. // 解绑
  8809. #region 查询载具上的产品信息
  8810. string cavityData = string.Empty;
  8811. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8812. if (string.IsNullOrEmpty(cavityData))
  8813. cavityData = "";
  8814. if (snResult != 0)
  8815. {
  8816. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8817. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  8818. writeToPLC_Flag1.Adress = 2082;
  8819. writeToPLC_Flag1.Value = (short)6;
  8820. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  8821. stopwatch1.Stop();
  8822. AddMessage(LogType.Info,
  8823. stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8824. "ms");
  8825. return;
  8826. }
  8827. #endregion 查询载具上的产品信息
  8828. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8829. #region 解绑
  8830. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  8831. {
  8832. // 删除
  8833. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8834. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  8835. }
  8836. else
  8837. {
  8838. string data_new = string.Join(".", cavitySNs);
  8839. // 删除再插入
  8840. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8841. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8842. OnMessage(LogType.Debug,
  8843. $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  8844. }
  8845. #endregion 解绑
  8846. short c1MES_FLAG_Unbind = 1;
  8847. stopwatch2.Start();
  8848. // MES_Flag
  8849. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8850. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8851. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8852. writeToPLC_Flag.Adress = 2082;
  8853. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  8854. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8855. stopwatch2.Stop();
  8856. }
  8857. catch (Exception ex)
  8858. {
  8859. string str = ex.StackTrace;
  8860. AddMessage_Station(stationNameStr, LogType.Error,
  8861. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
  8862. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8863. // MES_Flag
  8864. stopwatch2.Start();
  8865. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  8866. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8867. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8868. writeToPLC_Flag.Adress = 2082;
  8869. writeToPLC_Flag.Value = (short)6;
  8870. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8871. stopwatch2.Stop();
  8872. }
  8873. stopwatch1.Stop();
  8874. AddMessage(LogType.Info,
  8875. stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8876. stopwatch2.ElapsedMilliseconds + "ms");
  8877. }
  8878. /// <summary>
  8879. /// [S3] 值板机 - 二穴载具绑定
  8880. /// </summary>
  8881. /// <param name="plcNo">PLC编号</param>
  8882. /// <param name="stationNameStr">工站全称</param>
  8883. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  8884. {
  8885. Stopwatch stopwatch1 = new Stopwatch();
  8886. Stopwatch stopwatch2 = new Stopwatch();
  8887. try
  8888. {
  8889. stopwatch1.Start();
  8890. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8891. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8892. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  8893. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8894. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8895. stopwatch2.Start();
  8896. #region 查询载具上的产品信息
  8897. string cavityData = string.Empty;
  8898. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8899. if (string.IsNullOrEmpty(cavityData))
  8900. cavityData = "";
  8901. if (snResult != 0)
  8902. {
  8903. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8904. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  8905. writeToPLC_Flag1.Adress = 2115;
  8906. writeToPLC_Flag1.Value = (short)6;
  8907. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  8908. stopwatch1.Stop();
  8909. AddMessage(LogType.Info,
  8910. stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8911. "ms");
  8912. return;
  8913. }
  8914. #endregion 查询载具上的产品信息
  8915. // 产品换载具
  8916. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8917. string partSn1 = "";
  8918. string partSn2 = "";
  8919. if (cavitySNs != null && cavitySNs.Length >= 2)
  8920. {
  8921. partSn1 = cavitySNs[0];
  8922. partSn2 = cavitySNs[1];
  8923. }
  8924. string data_new = string.Empty;
  8925. // 是否是两个穴位交换
  8926. if (c1CavityReverse_Bind == 1)
  8927. {
  8928. // 交换
  8929. data_new = string.Concat(partSn2, ".", partSn1);
  8930. }
  8931. else
  8932. {
  8933. // 不交换
  8934. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  8935. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  8936. cavitySNs[c1VehicleCavityFr_Bind] = "";
  8937. data_new = string.Join(".", cavitySNs);
  8938. }
  8939. // 删除再插入
  8940. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8941. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8942. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  8943. stopwatch2.Stop();
  8944. short c1MES_FLAG_Bind = 1;
  8945. // MES_Flag
  8946. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8947. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8948. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8949. writeToPLC_Flag.Adress = 2115;
  8950. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  8951. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8952. }
  8953. catch (Exception ex)
  8954. {
  8955. string str = ex.StackTrace;
  8956. AddMessage_Station(stationNameStr, LogType.Error,
  8957. $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8958. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8959. // MES_Flag
  8960. stopwatch2.Start();
  8961. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8962. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8963. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8964. writeToPLC_Flag.Adress = 2115;
  8965. writeToPLC_Flag.Value = (short)6;
  8966. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8967. stopwatch2.Stop();
  8968. }
  8969. stopwatch1.Stop();
  8970. AddMessage(LogType.Info,
  8971. stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8972. stopwatch2.ElapsedMilliseconds + "ms");
  8973. }
  8974. //// 上次采集到的SN
  8975. //private string sn_值板机 = string.Empty;
  8976. /// <summary>
  8977. /// [S3] 值板机 - 出站接口
  8978. /// </summary>
  8979. /// <param name="plcNo">PLC编号</param>
  8980. private void S3出站接口(int plcNo, string stationCode, string stationName)
  8981. {
  8982. Stopwatch stopwatch1 = new Stopwatch();
  8983. Stopwatch stopwatch2 = new Stopwatch();
  8984. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8985. string stationNameStr = stationCode + stationName;
  8986. string processItem = stationName; // 测试项目
  8987. try
  8988. {
  8989. stopwatch1.Start();
  8990. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8991. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8992. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8993. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8994. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  8995. sn = sn.Replace("\0", "");
  8996. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  8997. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8998. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8999. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  9000. bool pass = c1Result == 1;
  9001. // 查sn
  9002. #region 查询载具上的产品信息
  9003. string cavityData = string.Empty;
  9004. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  9005. if (string.IsNullOrEmpty(cavityData))
  9006. cavityData = "";
  9007. if (snResult != 0)
  9008. {
  9009. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9010. writeToPLC_Flag1.Name = "c1MES_FLAG";
  9011. writeToPLC_Flag1.Adress = 2150;
  9012. writeToPLC_Flag1.Value = (short)4;
  9013. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  9014. stopwatch1.Stop();
  9015. AddMessage(LogType.Info,
  9016. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9017. return;
  9018. }
  9019. #endregion 查询载具上的产品信息
  9020. string[] cavitySNs = cavityData.Split('.');
  9021. string productSN = "";
  9022. if (cavitySNs != null && cavitySNs.Length >= 2)
  9023. {
  9024. productSN = cavitySNs[c1VehicleCavity];
  9025. cavitySNs[c1VehicleCavity] = "";
  9026. }
  9027. stopwatch2.Start();
  9028. List<TestItem> items = new List<TestItem>();
  9029. items.Add(new TestItem()
  9030. {
  9031. Parameter_name = "二穴载具码",
  9032. Parameter_value = c1ProductSN_Check,
  9033. Parameter_unit = ""
  9034. });
  9035. items.Add(new TestItem()
  9036. {
  9037. Parameter_name = "二穴载具穴号",
  9038. Parameter_value = c1VehicleCavity.ToString(),
  9039. Parameter_unit = ""
  9040. });
  9041. items.Add(new TestItem()
  9042. {
  9043. Parameter_name = "一穴载具码",
  9044. Parameter_value = sn,
  9045. Parameter_unit = ""
  9046. });
  9047. items.Add(new TestItem()
  9048. {
  9049. Parameter_name = "一穴载具穴号",
  9050. Parameter_value = "1",
  9051. Parameter_unit = ""
  9052. });
  9053. items.Add(new TestItem()
  9054. {
  9055. Parameter_name = "产品结果",
  9056. Parameter_value = c1Result == 1 ? "OK" : "NG",
  9057. Parameter_unit = ""
  9058. });
  9059. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  9060. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  9061. short result = (short)result1;
  9062. stopwatch2.Stop();
  9063. #region 存储绑定数据到 边线MES系统中
  9064. if (result == 1)
  9065. {
  9066. string data = string.Concat(productSN);
  9067. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  9068. if (resultMesR != 0)
  9069. {
  9070. result = 4;
  9071. AddMessage_Station(stationNameStr, LogType.Error,
  9072. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  9073. }
  9074. }
  9075. #endregion 存储绑定数据到 边线MES系统中
  9076. #region 产品从 来源载具(二穴载具)中删除
  9077. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  9078. {
  9079. // 删除
  9080. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9081. OnMessage(LogType.Debug,
  9082. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  9083. }
  9084. else
  9085. {
  9086. string data_new = string.Join(".", cavitySNs);
  9087. // 删除再插入
  9088. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9089. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  9090. OnMessage(LogType.Debug,
  9091. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  9092. }
  9093. #endregion 产品从 来源载具(二穴载具)中删除
  9094. // MES_Flag 为MES报错
  9095. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9096. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  9097. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9098. writeToPLC_Flag.Name = "c1MES_FLAG";
  9099. writeToPLC_Flag.Adress = 2150;
  9100. writeToPLC_Flag.Value = result;
  9101. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  9102. OnMessage(LogType.Debug,
  9103. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9104. }
  9105. catch (Exception ex)
  9106. {
  9107. stopwatch2.Restart();
  9108. // MES_Flag 为4上位机报错
  9109. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  9110. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9111. writeToPLC_Flag.Name = "c1MES_FLAG";
  9112. writeToPLC_Flag.Adress = 2150;
  9113. writeToPLC_Flag.Value = (short)4;
  9114. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  9115. stopwatch2.Stop();
  9116. string str = ex.StackTrace;
  9117. AddMessage_Station(stationNameStr, LogType.Error,
  9118. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9119. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9120. }
  9121. stopwatch1.Stop();
  9122. AddMessage(LogType.Info,
  9123. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  9124. stopwatch2.ElapsedMilliseconds + "ms");
  9125. }
  9126. #endregion [S3] 值板机
  9127. #endregion PLC3 刘永村
  9128. #region PLC4 刘果段
  9129. #region [S4] 取放桁架
  9130. /// <summary>
  9131. /// S4工位的数据- 触发信号上次的值
  9132. /// </summary>
  9133. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  9134. /// <summary>
  9135. /// S4工位的数据(含触发信号)
  9136. /// </summary>
  9137. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  9138. /// <summary>
  9139. /// S4工位的数据- 回写点位
  9140. /// </summary>
  9141. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  9142. /// <summary>
  9143. /// [S4] 取放桁架
  9144. /// </summary>
  9145. /// <param name="plcNo">PLC编号</param>
  9146. //private void ReadStation_S4(int plcNo)
  9147. //{
  9148. // // [S1] Tray盘上料装备
  9149. // // [S2] FCT
  9150. // // [S3] 值板机
  9151. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  9152. // // [S5] Tray盘下料装备
  9153. // /// 上位机心跳
  9154. // /// 获取设备报警数据与状态信息
  9155. // string stationCode = "[S4_1]";
  9156. // string stationName = "载具下线装备";
  9157. // string stationNameStr = stationCode + stationName;
  9158. // string stationCode2 = "[S4_2]";
  9159. // string stationName2 = "桁架";
  9160. // string stationNameStr2 = stationCode2 + stationName2;
  9161. // string stationCode3 = "[S4_3]";
  9162. // string stationName3 = "提升机1";
  9163. // string stationNameStr3 = stationCode3 + stationName3;
  9164. // string stationCode4 = "[S4_4]";
  9165. // string stationName4 = "提升机2";
  9166. // string stationNameStr4 = stationCode4 + stationName4;
  9167. // string stationCode5 = "[S4_5]";
  9168. // string stationName5 = "载具上线装备";
  9169. // string stationNameStr5 = stationCode5 + stationName5;
  9170. // #region 创建字典
  9171. // // 触发信号字典 赋值
  9172. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9173. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9174. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9175. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9176. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9177. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9178. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9179. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9180. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9181. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9182. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9183. // // PLC数据字典 赋值
  9184. // // 载具下线装备(弹夹上线)
  9185. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9186. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  9187. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9188. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  9189. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9190. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  9191. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  9192. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9193. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9194. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9195. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9196. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9197. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9198. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9199. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9200. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9201. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9202. // s4PLCData.Add("d1Result", 0); // 产品结果
  9203. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9204. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  9205. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  9206. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  9207. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9208. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  9209. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  9210. // // 真空标机(提升机)
  9211. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9212. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  9213. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  9214. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  9215. // s4PLCData.Add("d3Result", 0); // 产品结果
  9216. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9217. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  9218. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  9219. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  9220. // s4PLCData.Add("d4Result", 0); // 产品结果
  9221. // // 载具上线装备(弹夹下线)
  9222. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9223. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  9224. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9225. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  9226. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9227. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  9228. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  9229. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9230. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9231. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9232. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9233. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9234. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9235. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9236. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9237. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9238. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9239. // s4PLCData.Add("d5Result", 0); // 产品结果
  9240. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9241. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  9242. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  9243. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  9244. // #endregion 创建字典
  9245. // while (IsRun)
  9246. // {
  9247. // try
  9248. // {
  9249. // if (!GlobalContext._IsCon_Funs4)
  9250. // {
  9251. // UpdatePLCMonitor(1, plcNo, 0);
  9252. // continue;
  9253. // }
  9254. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9255. // {
  9256. // Stopwatch stopwatch1 = new Stopwatch();
  9257. // Stopwatch stopwatch2 = new Stopwatch();
  9258. // stopwatch1.Start();
  9259. // stopwatch2.Start();
  9260. // #region 一次性读取所有数据
  9261. // // 载具下线装备(弹夹上线)
  9262. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9263. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  9264. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  9265. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  9266. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  9267. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  9268. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  9269. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  9270. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  9271. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  9272. // int[] datas = data1.Concat(data2).ToArray();
  9273. // datas = datas.Concat(data3).ToArray();
  9274. // datas = datas.Concat(data4).ToArray();
  9275. // datas = datas.Concat(data5).ToArray();
  9276. // datas = datas.Concat(data6).ToArray();
  9277. // datas = datas.Concat(data7).ToArray();
  9278. // datas = datas.Concat(data8).ToArray();
  9279. // datas = datas.Concat(data9).ToArray();
  9280. // datas = datas.Concat(data10).ToArray();
  9281. // // 载具下线装备(弹夹上线)
  9282. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  9283. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  9284. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  9285. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  9286. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  9287. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  9288. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  9289. // s4PLCData["d1MES_FLAG"] = datas[65];
  9290. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  9291. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  9292. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  9293. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  9294. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  9295. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  9296. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  9297. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  9298. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  9299. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  9300. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  9301. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  9302. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  9303. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  9304. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  9305. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  9306. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  9307. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  9308. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  9309. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  9310. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  9311. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  9312. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  9313. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  9314. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  9315. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  9316. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  9317. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  9318. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  9319. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  9320. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  9321. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  9322. // s4PLCData["d1Result"] = datas[386];
  9323. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  9324. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  9325. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  9326. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  9327. // s4PLCData["d1OEEType"] = datas[419];
  9328. // // 桁架(查询标机中弹夹的状态)
  9329. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  9330. // s4PLCData["d2BulletclipStates"] = datas[431];
  9331. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  9332. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  9333. // // 真空标机
  9334. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  9335. // s4PLCData["d3MES_FLAG"] = datas[463];
  9336. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  9337. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  9338. // s4PLCData["d3Result"] = datas[484];
  9339. // s4PLCData["d3Type"] = datas[485];
  9340. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  9341. // s4PLCData["d4MES_FLAG"] = datas[496];
  9342. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  9343. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  9344. // s4PLCData["d4Result"] = datas[517];
  9345. // s4PLCData["d4Type"] = datas[518];
  9346. // // 载具上线装备(弹夹下线)
  9347. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  9348. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  9349. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  9350. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  9351. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  9352. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  9353. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  9354. // s4PLCData["d5MES_FLAG"] = datas[591];
  9355. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  9356. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  9357. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  9358. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  9359. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  9360. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  9361. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  9362. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  9363. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  9364. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  9365. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  9366. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  9367. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  9368. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  9369. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  9370. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  9371. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  9372. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  9373. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  9374. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  9375. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  9376. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  9377. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  9378. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  9379. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  9380. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  9381. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  9382. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  9383. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  9384. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  9385. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  9386. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  9387. // s4PLCData["d5Result"] = datas[912];
  9388. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  9389. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  9390. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  9391. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  9392. // s4PLCData["d5OEEType"] = datas[945];
  9393. // #endregion 一次性读取所有数据
  9394. // stopwatch2.Stop();
  9395. // #region 回写操作,写后清空flag
  9396. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  9397. // #endregion 回写操作,写后清空flag
  9398. // // N801A-S4_1 弹夹扫码
  9399. // #region N801A-S4_1 弹夹扫码
  9400. // try
  9401. // {
  9402. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  9403. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  9404. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  9405. // {
  9406. // if (d1BulletclipScanCode == 1) // 0->1
  9407. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9408. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  9409. // }
  9410. // }
  9411. // catch (Exception ex)
  9412. // {
  9413. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9414. // string str = ex.StackTrace;
  9415. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9416. // }
  9417. // #endregion N801A-S4_1 弹夹扫码
  9418. // // N801A-S4_1 载具扫码
  9419. // #region N801A-S4_1 载具扫码
  9420. // try
  9421. // {
  9422. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  9423. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  9424. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  9425. // {
  9426. // if (d1VehicleScanCode == 1) // 0->1
  9427. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9428. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  9429. // }
  9430. // }
  9431. // catch (Exception ex)
  9432. // {
  9433. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9434. // string str = ex.StackTrace;
  9435. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9436. // }
  9437. // #endregion N801A-S4_1 载具扫码
  9438. // // N801A-S4_1 出站接口
  9439. // #region N801A-S4_1 出站接口
  9440. // try
  9441. // {
  9442. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  9443. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  9444. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  9445. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  9446. // {
  9447. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  9448. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9449. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  9450. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  9451. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  9452. // }
  9453. // }
  9454. // catch (Exception ex)
  9455. // {
  9456. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  9457. // string str = ex.StackTrace;
  9458. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9459. // }
  9460. // #endregion N801A-S4_1 出站接口
  9461. // // N801A-S4_1 节拍接口
  9462. // #region N801A-S4_1 节拍接口
  9463. // try
  9464. // {
  9465. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  9466. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  9467. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  9468. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  9469. // {
  9470. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  9471. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9472. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  9473. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  9474. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  9475. // }
  9476. // }
  9477. // catch (Exception ex)
  9478. // {
  9479. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  9480. // string str = ex.StackTrace;
  9481. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9482. // }
  9483. // #endregion N801A-S4_1 节拍接口
  9484. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  9485. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  9486. // try
  9487. // {
  9488. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  9489. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  9490. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  9491. // {
  9492. // if (d2BulletclipScanCode == 1) // 0->1
  9493. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  9494. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  9495. // }
  9496. // }
  9497. // catch (Exception ex)
  9498. // {
  9499. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  9500. // string str = ex.StackTrace;
  9501. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9502. // }
  9503. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  9504. // // N801A-S4_3 真空标机1 数据
  9505. // #region N801A-S4_3 真空标机1
  9506. // try
  9507. // {
  9508. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  9509. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  9510. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  9511. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  9512. // {
  9513. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  9514. // {
  9515. // int stationType = (int)s4PLCData["d3Type"];
  9516. // if (stationType == 1)
  9517. // {
  9518. // // S4_3进站接口
  9519. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  9520. // }
  9521. // else if (stationType == 2)
  9522. // {
  9523. // // S4_3出站接口
  9524. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  9525. // }
  9526. // }
  9527. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  9528. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  9529. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  9530. // }
  9531. // }
  9532. // catch (Exception ex)
  9533. // {
  9534. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  9535. // string str = ex.StackTrace;
  9536. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9537. // }
  9538. // #endregion N801A-S4_3 真空标机1
  9539. // // N801A-S4_4 真空标机2 数据
  9540. // #region N801A-S4_4 真空标机2
  9541. // try
  9542. // {
  9543. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  9544. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  9545. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  9546. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  9547. // {
  9548. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  9549. // {
  9550. // int stationType = (int)s4PLCData["d4Type"];
  9551. // if (stationType == 1)
  9552. // {
  9553. // // S4_4进站接口
  9554. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  9555. // }
  9556. // else if (stationType == 2)
  9557. // {
  9558. // // S4_4出站接口
  9559. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  9560. // }
  9561. // }
  9562. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  9563. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  9564. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  9565. // }
  9566. // }
  9567. // catch (Exception ex)
  9568. // {
  9569. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  9570. // string str = ex.StackTrace;
  9571. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9572. // }
  9573. // #endregion N801A-S4_4 真空标机2
  9574. // // N801A-S4_5 弹夹扫码 数据
  9575. // #region N801A-S4_5 弹夹扫码
  9576. // try
  9577. // {
  9578. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  9579. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  9580. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  9581. // {
  9582. // if (d5BulletclipScanCode == 1) // 0->1
  9583. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9584. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  9585. // }
  9586. // }
  9587. // catch (Exception ex)
  9588. // {
  9589. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  9590. // string str = ex.StackTrace;
  9591. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9592. // }
  9593. // #endregion N801A-S4_5 弹夹扫码
  9594. // // N801A-S4_5 载具扫码 数据
  9595. // #region N801A-S4_5 载具扫码
  9596. // try
  9597. // {
  9598. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  9599. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  9600. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  9601. // {
  9602. // if (d5VehicleScanCode == 1) // 0->1
  9603. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9604. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  9605. // }
  9606. // }
  9607. // catch (Exception ex)
  9608. // {
  9609. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  9610. // string str = ex.StackTrace;
  9611. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9612. // }
  9613. // #endregion N801A-S4_5 载具扫码
  9614. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  9615. // #region N801A-S4_5 出站接口
  9616. // try
  9617. // {
  9618. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  9619. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  9620. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  9621. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  9622. // {
  9623. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  9624. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  9625. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  9626. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  9627. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  9628. // }
  9629. // }
  9630. // catch (Exception ex)
  9631. // {
  9632. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  9633. // string str = ex.StackTrace;
  9634. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9635. // }
  9636. // #endregion N801A-S4_5 出站接口
  9637. // // N801A-S4_5 节拍接口 数据
  9638. // #region N801A-S4_5 节拍接口
  9639. // try
  9640. // {
  9641. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  9642. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  9643. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  9644. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  9645. // {
  9646. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  9647. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  9648. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  9649. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  9650. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  9651. // }
  9652. // }
  9653. // catch (Exception ex)
  9654. // {
  9655. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  9656. // string str = ex.StackTrace;
  9657. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9658. // }
  9659. // #endregion N801A-S4_5 节拍接口
  9660. // #region 心跳
  9661. // try
  9662. // {
  9663. // short states = 0;
  9664. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9665. // }
  9666. // catch (Exception ex)
  9667. // {
  9668. // string str = ex.StackTrace;
  9669. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9670. // }
  9671. // #endregion 心跳
  9672. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9673. // stopwatch1.Stop();
  9674. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9675. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9676. // }
  9677. // else
  9678. // {
  9679. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9680. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  9681. // Funs[plcNo].Connect();
  9682. // }
  9683. // }
  9684. // catch (Exception ex)
  9685. // {
  9686. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9687. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  9688. // Funs[plcNo].ReConnect();
  9689. // }
  9690. // Thread.Sleep(IntervalReadPLC);
  9691. // }
  9692. //}
  9693. /// <summary>
  9694. /// [S4] 取放桁架 - S4_1弹夹扫码
  9695. /// </summary>
  9696. /// <param name="plcNo">PLC编号</param>
  9697. /// <param name="stationNameStr">工站全称</param>
  9698. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  9699. {
  9700. Stopwatch stopwatch1 = new Stopwatch();
  9701. Stopwatch stopwatch2 = new Stopwatch();
  9702. try
  9703. {
  9704. stopwatch1.Start();
  9705. // ZS 弹夹扫码
  9706. string d1BulletclipCode = " "; // 扫到的码
  9707. short d1BulletclipScanCode = 2;
  9708. stopwatch2.Start();
  9709. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  9710. //// MES_Flag
  9711. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9712. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9713. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9714. writeToPLC_Flag.Adress = 2002;
  9715. writeToPLC_Flag.Value = d1BulletclipScanCode;
  9716. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9717. {
  9718. Name = "d1BulletclipCode",
  9719. Adress = 2003,
  9720. ValueType = PLCValueType.String,
  9721. ValueTypeStrLength = 20,
  9722. Value = d1BulletclipCode
  9723. });
  9724. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9725. stopwatch2.Stop();
  9726. }
  9727. catch (Exception ex)
  9728. {
  9729. string str = ex.StackTrace;
  9730. AddMessage_Station(stationNameStr, LogType.Error,
  9731. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9732. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9733. stopwatch2.Start();
  9734. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  9735. //// MES_Flag
  9736. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9737. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9738. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9739. writeToPLC_Flag.Adress = 2002;
  9740. writeToPLC_Flag.Value = (short)6;
  9741. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9742. {
  9743. Name = "d1BulletclipCode",
  9744. Adress = 2003,
  9745. ValueType = PLCValueType.String,
  9746. ValueTypeStrLength = 20,
  9747. Value = " "
  9748. });
  9749. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9750. stopwatch2.Stop();
  9751. }
  9752. stopwatch1.Stop();
  9753. AddMessage(LogType.Info,
  9754. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9755. stopwatch2.ElapsedMilliseconds + "ms");
  9756. }
  9757. /// <summary>
  9758. /// [S4] 取放桁架 - S4_1载具扫码
  9759. /// </summary>
  9760. /// <param name="plcNo">PLC编号</param>
  9761. /// <param name="stationNameStr">工站全称</param>
  9762. private void S4_1载具扫码(int plcNo, string stationNameStr)
  9763. {
  9764. Stopwatch stopwatch1 = new Stopwatch();
  9765. Stopwatch stopwatch2 = new Stopwatch();
  9766. try
  9767. {
  9768. stopwatch1.Start();
  9769. // ZS 载具扫码
  9770. string d1VehicleCode = ""; // 扫到的码
  9771. short d1VehicleScanCode = 2;
  9772. #region 进站
  9773. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  9774. {
  9775. #region 查询载具上的产品信息
  9776. string cavityData = string.Empty;
  9777. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  9778. if (string.IsNullOrEmpty(cavityData))
  9779. cavityData = "";
  9780. if (snResult != 0)
  9781. {
  9782. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9783. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  9784. writeToPLC_Flag1.Adress = 2033;
  9785. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  9786. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9787. {
  9788. Name = "d1VehicleCode",
  9789. Adress = 2034,
  9790. ValueType = PLCValueType.String,
  9791. ValueTypeStrLength = 20,
  9792. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9793. });
  9794. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  9795. stopwatch1.Stop();
  9796. AddMessage(LogType.Info,
  9797. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9798. "ms");
  9799. return;
  9800. }
  9801. string[] cavitySNs = cavityData.Split('.');
  9802. string partNo = "";
  9803. if (cavitySNs != null && cavitySNs.Length >= 1)
  9804. {
  9805. partNo = cavitySNs[0];
  9806. }
  9807. #endregion 查询载具上的产品信息
  9808. List<TestItem> item = new List<TestItem>();
  9809. item.Add(new TestItem()
  9810. {
  9811. Parameter_name = "载具码",
  9812. Parameter_value = d1VehicleCode,
  9813. });
  9814. item.Add(new TestItem()
  9815. {
  9816. Parameter_name = "载具穴号",
  9817. Parameter_value = "1",
  9818. });
  9819. stopwatch2.Start();
  9820. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9821. partNo, item, out string errorMsg);
  9822. stopwatch2.Stop();
  9823. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  9824. }
  9825. #endregion 进站
  9826. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  9827. //// MES_Flag
  9828. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9829. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9830. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9831. writeToPLC_Flag.Adress = 2033;
  9832. writeToPLC_Flag.Value = d1VehicleScanCode;
  9833. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9834. {
  9835. Name = "d1VehicleCode",
  9836. Adress = 2034,
  9837. ValueType = PLCValueType.String,
  9838. ValueTypeStrLength = 20,
  9839. Value = d1VehicleCode
  9840. });
  9841. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9842. }
  9843. catch (Exception ex)
  9844. {
  9845. string str = ex.StackTrace;
  9846. AddMessage_Station(stationNameStr, LogType.Error,
  9847. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9848. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9849. stopwatch2.Start();
  9850. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  9851. //// MES_Flag
  9852. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9853. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9854. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9855. writeToPLC_Flag.Adress = 2033;
  9856. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  9857. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9858. {
  9859. Name = "d1VehicleCode",
  9860. Adress = 2034,
  9861. ValueType = PLCValueType.String,
  9862. ValueTypeStrLength = 20,
  9863. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9864. });
  9865. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9866. stopwatch2.Stop();
  9867. }
  9868. stopwatch1.Stop();
  9869. AddMessage(LogType.Info,
  9870. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9871. stopwatch2.ElapsedMilliseconds + "ms");
  9872. }
  9873. // 上次采集到的SN
  9874. //private string sn_S4_1出站接口 = string.Empty;
  9875. /// <summary>
  9876. /// [S4] 取放桁架 - S4_1出站接口
  9877. /// </summary>
  9878. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  9879. {
  9880. Stopwatch stopwatch1 = new Stopwatch();
  9881. Stopwatch stopwatch2 = new Stopwatch();
  9882. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9883. string stationNameStr = stationCode + stationName;
  9884. string processItem = stationName; // 测试项目
  9885. try
  9886. {
  9887. stopwatch1.Start();
  9888. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9889. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9890. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9891. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9892. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  9893. sn = sn.Replace("\0", "");
  9894. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  9895. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  9896. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  9897. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  9898. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  9899. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  9900. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  9901. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  9902. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  9903. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  9904. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  9905. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  9906. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  9907. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  9908. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  9909. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  9910. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  9911. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  9912. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  9913. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  9914. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  9915. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  9916. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  9917. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  9918. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  9919. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  9920. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  9921. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  9922. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  9923. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  9924. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  9925. bool pass = d1Result == 1;
  9926. // 存 载具SN列表
  9927. List<string> vehicleCodes = new List<string>()
  9928. {
  9929. d1VehicleCode1, d1VehicleCode2, d1VehicleCode3, d1VehicleCode4, d1VehicleCode5,
  9930. d1VehicleCode6, d1VehicleCode7, d1VehicleCode8, d1VehicleCode9, d1VehicleCode10,
  9931. d1VehicleCode11, d1VehicleCode12, d1VehicleCode13, d1VehicleCode14, d1VehicleCode15
  9932. };
  9933. // 统一查 产品SN列表
  9934. List<string> partNos = new List<string>();
  9935. foreach (string vehicleCode in vehicleCodes)
  9936. {
  9937. if (string.IsNullOrEmpty(vehicleCode))
  9938. partNos.Add("");
  9939. else
  9940. {
  9941. string partNo = "";
  9942. #region 查询载具上的产品信息
  9943. string cavityData = string.Empty;
  9944. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  9945. if (string.IsNullOrEmpty(cavityData))
  9946. cavityData = "";
  9947. if (snResult != 0)
  9948. {
  9949. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9950. writeToPLC_Flag1.Name = "d1MES_FLAG";
  9951. writeToPLC_Flag1.Adress = 2065;
  9952. writeToPLC_Flag1.Value = (short)4;
  9953. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  9954. stopwatch1.Stop();
  9955. AddMessage(LogType.Info,
  9956. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9957. "ms");
  9958. return;
  9959. }
  9960. string[] cavitySNs = cavityData.Split('.');
  9961. if (cavitySNs != null && cavitySNs.Length >= 1)
  9962. partNo = cavitySNs[0];
  9963. #endregion 查询载具上的产品信息
  9964. partNos.Add(partNo);
  9965. }
  9966. }
  9967. // 统一上传
  9968. stopwatch2.Start();
  9969. List<int> results = new List<int>();
  9970. for (int i = 0; i < partNos.Count; i++)
  9971. {
  9972. string index = (i + 1).ToString(); // 弹夹穴号
  9973. if (string.IsNullOrEmpty(partNos[i]))
  9974. results.Add(1);
  9975. else
  9976. {
  9977. List<TestItem> items1 = new List<TestItem>();
  9978. items1.Add(new TestItem()
  9979. {
  9980. Parameter_name = "弹夹码",
  9981. Parameter_value = sn,
  9982. Parameter_unit = ""
  9983. });
  9984. items1.Add(new TestItem()
  9985. {
  9986. Parameter_name = "弹夹穴号",
  9987. Parameter_value = index,
  9988. Parameter_unit = ""
  9989. });
  9990. items1.Add(new TestItem()
  9991. {
  9992. Parameter_name = "载具码",
  9993. Parameter_value = vehicleCodes[i],
  9994. Parameter_unit = ""
  9995. });
  9996. items1.Add(new TestItem()
  9997. {
  9998. Parameter_name = "载具穴号",
  9999. Parameter_value = "1",
  10000. Parameter_unit = ""
  10001. });
  10002. items1.Add(new TestItem()
  10003. {
  10004. Parameter_name = "产品结果",
  10005. Parameter_value = d1Result == 1 ? "OK" : "NG",
  10006. Parameter_unit = ""
  10007. });
  10008. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10009. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  10010. results.Add(result1);
  10011. }
  10012. }
  10013. short result = 0;
  10014. if (results.All(a => a == 1))
  10015. result = 1;
  10016. else if (results.Contains(3))
  10017. result = 3;
  10018. else if (results.Contains(2))
  10019. result = 2;
  10020. else if (results.Contains(4))
  10021. result = 4;
  10022. else
  10023. result = 4;
  10024. stopwatch2.Stop();
  10025. #region 存储绑定数据到 边线MES系统中
  10026. if (result == 1)
  10027. {
  10028. string data = string.Join(".", vehicleCodes);
  10029. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  10030. if (resultMesR != 0)
  10031. {
  10032. result = 4;
  10033. AddMessage_Station(stationNameStr, LogType.Error,
  10034. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  10035. }
  10036. }
  10037. #endregion 存储绑定数据到 边线MES系统中
  10038. // MES_Flag 为4MES报错
  10039. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10040. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10041. writeToPLC_Flag.Name = "d1MES_FLAG";
  10042. writeToPLC_Flag.Adress = 2065;
  10043. writeToPLC_Flag.Value = result;
  10044. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  10045. OnMessage(LogType.Debug,
  10046. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  10047. }
  10048. catch (Exception ex)
  10049. {
  10050. stopwatch2.Restart();
  10051. // MES_Flag 为4上位机报错
  10052. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  10053. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10054. writeToPLC_Flag.Name = "d1MES_FLAG";
  10055. writeToPLC_Flag.Adress = 2065;
  10056. writeToPLC_Flag.Value = (short)4;
  10057. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  10058. stopwatch2.Stop();
  10059. string str = ex.StackTrace;
  10060. AddMessage_Station(stationNameStr, LogType.Error,
  10061. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10062. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10063. }
  10064. stopwatch1.Stop();
  10065. AddMessage(LogType.Info,
  10066. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10067. stopwatch2.ElapsedMilliseconds + "ms");
  10068. }
  10069. /// <summary>
  10070. /// [S4] 取放桁架 - S4_1节拍接口
  10071. /// </summary>
  10072. /// <param name="plcNo">PLC编号</param>
  10073. /// <param name="stationNameStr">工站全称</param>
  10074. private void S4_1节拍接口(int plcNo, string stationNameStr)
  10075. {
  10076. Stopwatch stopwatch1 = new Stopwatch();
  10077. Stopwatch stopwatch2 = new Stopwatch();
  10078. string resultStr = string.Empty;
  10079. try
  10080. {
  10081. stopwatch1.Start();
  10082. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  10083. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  10084. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  10085. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  10086. if (!actionBool)
  10087. {
  10088. stopwatch2.Start();
  10089. // MES_Flag
  10090. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10091. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10092. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  10093. writeToPLC_Flag1.Adress = 2398;
  10094. writeToPLC_Flag1.Value = (short)4;
  10095. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  10096. stopwatch2.Stop();
  10097. AddMessage(LogType.Info,
  10098. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  10099. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10100. return;
  10101. }
  10102. string d1OEEPartNo = string.Empty; // 物料码
  10103. if (string.IsNullOrEmpty(d1OEEProductSN))
  10104. {
  10105. stopwatch2.Start();
  10106. // MES_Flag
  10107. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10108. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10109. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  10110. writeToPLC_Flag1.Adress = 2398;
  10111. writeToPLC_Flag1.Value = (short)1;
  10112. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  10113. stopwatch2.Stop();
  10114. AddMessage(LogType.Info,
  10115. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10116. stopwatch2.ElapsedMilliseconds + "ms");
  10117. return;
  10118. }
  10119. else
  10120. {
  10121. // 查产品SN ZS
  10122. d1OEEPartNo = "Test";
  10123. }
  10124. short d1OEEMES_FLAG = 0;
  10125. // 上传OEE
  10126. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  10127. d1OEEMES_FLAG = result.Item1;
  10128. resultStr = result.Item2;
  10129. stopwatch2.Start();
  10130. // MES_Flag
  10131. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10132. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10133. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  10134. writeToPLC_Flag.Adress = 2398;
  10135. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  10136. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  10137. stopwatch2.Stop();
  10138. }
  10139. catch (Exception ex)
  10140. {
  10141. string str = ex.StackTrace;
  10142. AddMessage_Station(stationNameStr, LogType.Error,
  10143. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  10144. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10145. // MES_Flag
  10146. stopwatch2.Start();
  10147. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  10148. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10149. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  10150. writeToPLC_Flag.Adress = 2398;
  10151. writeToPLC_Flag.Value = (short)4;
  10152. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  10153. stopwatch2.Stop();
  10154. }
  10155. stopwatch1.Stop();
  10156. AddMessage(LogType.Info,
  10157. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10158. stopwatch2.ElapsedMilliseconds + "ms");
  10159. }
  10160. /// <summary>
  10161. /// [S4] 取放桁架 - S4_2桁架
  10162. /// </summary>
  10163. /// <param name="plcNo">PLC编号</param>
  10164. /// <param name="stationNameStr">工站全称</param>
  10165. private void S4_2桁架(int plcNo, string stationNameStr)
  10166. {
  10167. Stopwatch stopwatch1 = new Stopwatch();
  10168. Stopwatch stopwatch2 = new Stopwatch();
  10169. try
  10170. {
  10171. stopwatch1.Start();
  10172. // ZS 弹夹扫码
  10173. string d2BulletclipCode = " "; // 扫到的码
  10174. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  10175. short d2BulletclipScanCode = 2;
  10176. stopwatch2.Start();
  10177. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  10178. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  10179. //// MES_Flag
  10180. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10181. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10182. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10183. writeToPLC_Flag.Adress = 2430;
  10184. writeToPLC_Flag.Value = d2BulletclipScanCode;
  10185. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10186. {
  10187. Name = "d2BulletclipCode",
  10188. Adress = 2432,
  10189. ValueType = PLCValueType.String,
  10190. ValueTypeStrLength = 20,
  10191. Value = d2BulletclipCode
  10192. });
  10193. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10194. {
  10195. Name = "d2BulletclipStates",
  10196. Adress = 2431,
  10197. ValueType = PLCValueType.Short,
  10198. Value = d2BulletclipStates
  10199. });
  10200. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10201. stopwatch2.Stop();
  10202. }
  10203. catch (Exception ex)
  10204. {
  10205. string str = ex.StackTrace;
  10206. AddMessage_Station(stationNameStr, LogType.Error,
  10207. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10208. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10209. stopwatch2.Start();
  10210. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  10211. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  10212. // MES_Flag
  10213. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  10214. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10215. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10216. writeToPLC_Flag.Adress = 2430;
  10217. writeToPLC_Flag.Value = (short)6;
  10218. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10219. {
  10220. Name = "d2BulletclipCode",
  10221. Adress = 2432,
  10222. ValueType = PLCValueType.String,
  10223. ValueTypeStrLength = 20,
  10224. Value = " "
  10225. });
  10226. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10227. {
  10228. Name = "d2BulletclipStates",
  10229. Adress = 2431,
  10230. ValueType = PLCValueType.Short,
  10231. Value = (short)0
  10232. });
  10233. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10234. stopwatch2.Stop();
  10235. }
  10236. stopwatch1.Stop();
  10237. AddMessage(LogType.Info,
  10238. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10239. stopwatch2.ElapsedMilliseconds + "ms");
  10240. }
  10241. // 上次采集到的SN
  10242. //private string sn_S4_3进站接口 = string.Empty;
  10243. /// <summary>
  10244. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  10245. /// </summary>
  10246. private void S4_3进站接口(int plcNo, string stationNameStr)
  10247. {
  10248. Stopwatch stopwatch1 = new Stopwatch();
  10249. Stopwatch stopwatch2 = new Stopwatch();
  10250. try
  10251. {
  10252. stopwatch1.Start();
  10253. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10254. sn = sn.Replace("\0", "");
  10255. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10256. #region 查询15个载具码
  10257. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10258. string vehicleData = string.Empty;
  10259. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10260. if (string.IsNullOrEmpty(vehicleData))
  10261. vehicleData = "";
  10262. if (snResult != 0)
  10263. {
  10264. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10265. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10266. writeToPLC_Flag1.Adress = 2463;
  10267. writeToPLC_Flag1.Value = (short)4;
  10268. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10269. stopwatch1.Stop();
  10270. AddMessage(LogType.Info,
  10271. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10272. return;
  10273. }
  10274. string[] cavitySNs = vehicleData.Split('.');
  10275. if (cavitySNs != null && cavitySNs.Length > 0)
  10276. {
  10277. for (int i = 0; i < cavitySNs.Length; i++)
  10278. {
  10279. if (string.IsNullOrEmpty(cavitySNs[i]))
  10280. vehicleCodes.Add("");
  10281. else
  10282. vehicleCodes.Add(cavitySNs[i]);
  10283. }
  10284. }
  10285. #endregion 查询15个载具码
  10286. #region 查询15个产品SN
  10287. List<string> portNos = new List<string>(); // 15个产品SN
  10288. foreach (string vehicleCode in vehicleCodes)
  10289. {
  10290. if (string.IsNullOrEmpty(vehicleCode))
  10291. portNos.Add("");
  10292. else
  10293. {
  10294. // 查询
  10295. string cavityData = string.Empty;
  10296. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10297. if (string.IsNullOrEmpty(cavityData))
  10298. cavityData = "";
  10299. if (snResult1 != 0)
  10300. {
  10301. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10302. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10303. writeToPLC_Flag1.Adress = 2463;
  10304. writeToPLC_Flag1.Value = (short)4;
  10305. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10306. stopwatch1.Stop();
  10307. AddMessage(LogType.Info,
  10308. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10309. stopwatch1.ElapsedMilliseconds + "ms");
  10310. return;
  10311. }
  10312. string[] partSNs = cavityData.Split('.');
  10313. if (partSNs != null && partSNs.Length >= 1)
  10314. portNos.Add(partSNs[0]);
  10315. else
  10316. portNos.Add("");
  10317. }
  10318. }
  10319. #endregion 查询15个产品SN
  10320. // 调用MES进站(最多15个)
  10321. stopwatch2.Start();
  10322. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10323. for (int i = 0; i < vehicleCodes.Count; i++)
  10324. {
  10325. // 循环进站
  10326. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10327. {
  10328. // 产品SN(物料码)校验
  10329. string portNo = portNos[i];
  10330. List<TestItem> item = new List<TestItem>();
  10331. item.Add(new TestItem()
  10332. {
  10333. Parameter_name = "弹夹码",
  10334. Parameter_value = sn,
  10335. });
  10336. item.Add(new TestItem()
  10337. {
  10338. Parameter_name = "弹夹穴位",
  10339. Parameter_value = (i + 1).ToString(),
  10340. });
  10341. item.Add(new TestItem()
  10342. {
  10343. Parameter_name = "载具码",
  10344. Parameter_value = vehicleCodes[i],
  10345. });
  10346. item.Add(new TestItem()
  10347. {
  10348. Parameter_name = "载具穴号",
  10349. Parameter_value = "1",
  10350. });
  10351. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10352. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10353. }
  10354. }
  10355. stopwatch2.Stop();
  10356. short result = 0;
  10357. bool haveMesWarn = results.Contains(5);
  10358. bool havePCWarn = results.Contains(6);
  10359. if (haveMesWarn)
  10360. result = 2; // 5->2
  10361. else if (havePCWarn)
  10362. result = 6; // 6->4
  10363. else
  10364. result = 1;
  10365. // MES_Flag 为4MES报错
  10366. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10367. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10368. writeToPLC_Flag.Name = "d3MES_FLAG";
  10369. writeToPLC_Flag.Adress = 2463;
  10370. writeToPLC_Flag.Value = result;
  10371. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10372. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10373. }
  10374. catch (Exception ex)
  10375. {
  10376. stopwatch2.Stop();
  10377. // MES_Flag 为4上位机报错
  10378. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10379. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10380. writeToPLC_Flag.Name = "d3MES_FLAG";
  10381. writeToPLC_Flag.Adress = 2463;
  10382. writeToPLC_Flag.Value = (short)4;
  10383. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10384. string str = ex.StackTrace;
  10385. AddMessage_Station(stationNameStr, LogType.Error,
  10386. $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10387. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10388. }
  10389. stopwatch1.Stop();
  10390. AddMessage(LogType.Info,
  10391. stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10392. stopwatch2.ElapsedMilliseconds + "ms");
  10393. }
  10394. // 上次采集到的SN
  10395. //private string sn_S4_3出站接口 = string.Empty;
  10396. /// <summary>
  10397. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  10398. /// </summary>
  10399. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  10400. {
  10401. Stopwatch stopwatch1 = new Stopwatch();
  10402. Stopwatch stopwatch2 = new Stopwatch();
  10403. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10404. string stationNameStr = stationCode + stationName;
  10405. string processItem = stationName; // 测试项目
  10406. try
  10407. {
  10408. stopwatch1.Start();
  10409. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10410. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10411. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10412. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10413. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10414. sn = sn.Replace("\0", "");
  10415. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10416. bool isPass = d3Result == 1; // 产品结果 bool
  10417. #region 查询15个载具码
  10418. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10419. string vehicleData = string.Empty;
  10420. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10421. if (string.IsNullOrEmpty(vehicleData))
  10422. vehicleData = "";
  10423. if (snResult1 != 0)
  10424. {
  10425. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10426. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10427. writeToPLC_Flag1.Adress = 2463;
  10428. writeToPLC_Flag1.Value = (short)4;
  10429. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10430. stopwatch1.Stop();
  10431. AddMessage(LogType.Info,
  10432. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10433. return;
  10434. }
  10435. string[] cavitySNs = vehicleData.Split('.');
  10436. if (cavitySNs != null && cavitySNs.Length > 0)
  10437. {
  10438. for (int i = 0; i < cavitySNs.Length; i++)
  10439. {
  10440. if (string.IsNullOrEmpty(cavitySNs[i]))
  10441. vehicleCodes.Add("");
  10442. else
  10443. vehicleCodes.Add(cavitySNs[i]);
  10444. }
  10445. }
  10446. #endregion 查询15个载具码
  10447. // 统一查 产品SN列表
  10448. List<string> partNos = new List<string>();
  10449. foreach (string vehicleCode in vehicleCodes)
  10450. {
  10451. if (string.IsNullOrEmpty(vehicleCode))
  10452. partNos.Add("");
  10453. else
  10454. {
  10455. string partNo = "";
  10456. #region 查询载具上的产品信息
  10457. string cavityData = string.Empty;
  10458. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10459. if (string.IsNullOrEmpty(cavityData))
  10460. cavityData = "";
  10461. if (snResult != 0)
  10462. {
  10463. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10464. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10465. writeToPLC_Flag1.Adress = 2463;
  10466. writeToPLC_Flag1.Value = (short)4;
  10467. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10468. stopwatch1.Stop();
  10469. AddMessage(LogType.Info,
  10470. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10471. "ms");
  10472. return;
  10473. }
  10474. string[] partSNs = cavityData.Split('.');
  10475. if (partSNs != null && partSNs.Length >= 1)
  10476. partNo = partSNs[0];
  10477. #endregion 查询载具上的产品信息
  10478. partNos.Add(partNo);
  10479. }
  10480. }
  10481. // 统一上传 - 调用MES出站
  10482. stopwatch2.Start();
  10483. List<int> results = new List<int>();
  10484. for (int i = 0; i < partNos.Count; i++)
  10485. {
  10486. string index = (i + 1).ToString(); // 弹夹穴号
  10487. if (string.IsNullOrEmpty(partNos[i]))
  10488. results.Add(1);
  10489. else
  10490. {
  10491. List<TestItem> items1 = new List<TestItem>();
  10492. items1.Add(new TestItem()
  10493. {
  10494. Parameter_name = "弹夹码",
  10495. Parameter_value = sn,
  10496. Parameter_unit = ""
  10497. });
  10498. items1.Add(new TestItem()
  10499. {
  10500. Parameter_name = "弹夹穴号",
  10501. Parameter_value = index,
  10502. Parameter_unit = ""
  10503. });
  10504. items1.Add(new TestItem()
  10505. {
  10506. Parameter_name = "载具码",
  10507. Parameter_value = vehicleCodes[i],
  10508. Parameter_unit = ""
  10509. });
  10510. items1.Add(new TestItem()
  10511. {
  10512. Parameter_name = "载具穴号",
  10513. Parameter_value = "1",
  10514. Parameter_unit = ""
  10515. });
  10516. items1.Add(new TestItem()
  10517. {
  10518. Parameter_name = "产品结果",
  10519. Parameter_value = d3Result == 1 ? "OK" : "NG",
  10520. Parameter_unit = ""
  10521. });
  10522. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10523. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10524. results.Add(result1);
  10525. }
  10526. }
  10527. short result = 0;
  10528. if (results.All(a => a == 1))
  10529. result = 1;
  10530. else if (results.Contains(3))
  10531. result = 3;
  10532. else if (results.Contains(2))
  10533. result = 2;
  10534. else if (results.Contains(4))
  10535. result = 4;
  10536. else
  10537. result = 4;
  10538. stopwatch2.Stop();
  10539. // MES_Flag 为4MES报错
  10540. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10541. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10542. writeToPLC_Flag.Name = "d3MES_FLAG";
  10543. writeToPLC_Flag.Adress = 2463;
  10544. writeToPLC_Flag.Value = result;
  10545. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10546. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10547. }
  10548. catch (Exception ex)
  10549. {
  10550. stopwatch2.Restart();
  10551. // MES_Flag 为4上位机报错
  10552. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10553. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10554. writeToPLC_Flag.Name = "d3MES_FLAG";
  10555. writeToPLC_Flag.Adress = 2463;
  10556. writeToPLC_Flag.Value = (short)4;
  10557. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10558. string str = ex.StackTrace;
  10559. AddMessage_Station(stationNameStr, LogType.Error,
  10560. $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10561. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10562. stopwatch2.Stop();
  10563. }
  10564. stopwatch1.Stop();
  10565. AddMessage(LogType.Info,
  10566. stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10567. stopwatch2.ElapsedMilliseconds + "ms");
  10568. }
  10569. // 上次采集到的SN
  10570. //private string sn_S4_4进站接口 = string.Empty;
  10571. /// <summary>
  10572. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  10573. /// </summary>
  10574. private void S4_4进站接口(int plcNo, string stationNameStr)
  10575. {
  10576. Stopwatch stopwatch1 = new Stopwatch();
  10577. Stopwatch stopwatch2 = new Stopwatch();
  10578. try
  10579. {
  10580. stopwatch1.Start();
  10581. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10582. sn = sn.Replace("\0", "");
  10583. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10584. #region 查询15个载具码
  10585. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10586. string vehicleData = string.Empty;
  10587. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10588. if (string.IsNullOrEmpty(vehicleData))
  10589. vehicleData = "";
  10590. if (snResult != 0)
  10591. {
  10592. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10593. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10594. writeToPLC_Flag1.Adress = 2463;
  10595. writeToPLC_Flag1.Value = (short)4;
  10596. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10597. stopwatch1.Stop();
  10598. AddMessage(LogType.Info,
  10599. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10600. return;
  10601. }
  10602. string[] cavitySNs = vehicleData.Split('.');
  10603. if (cavitySNs != null && cavitySNs.Length > 0)
  10604. {
  10605. for (int i = 0; i < cavitySNs.Length; i++)
  10606. {
  10607. if (string.IsNullOrEmpty(cavitySNs[i]))
  10608. vehicleCodes.Add("");
  10609. else
  10610. vehicleCodes.Add(cavitySNs[i]);
  10611. }
  10612. }
  10613. #endregion 查询15个载具码
  10614. #region 查询15个产品SN
  10615. List<string> portNos = new List<string>(); // 15个产品SN
  10616. foreach (string vehicleCode in vehicleCodes)
  10617. {
  10618. if (string.IsNullOrEmpty(vehicleCode))
  10619. portNos.Add("");
  10620. else
  10621. {
  10622. // 查询
  10623. string cavityData = string.Empty;
  10624. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10625. if (string.IsNullOrEmpty(cavityData))
  10626. cavityData = "";
  10627. if (snResult1 != 0)
  10628. {
  10629. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10630. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10631. writeToPLC_Flag1.Adress = 2463;
  10632. writeToPLC_Flag1.Value = (short)4;
  10633. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10634. stopwatch1.Stop();
  10635. AddMessage(LogType.Info,
  10636. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10637. stopwatch1.ElapsedMilliseconds + "ms");
  10638. return;
  10639. }
  10640. string[] partSNs = cavityData.Split('.');
  10641. if (partSNs != null && partSNs.Length >= 1)
  10642. portNos.Add(partSNs[0]);
  10643. else
  10644. portNos.Add("");
  10645. }
  10646. }
  10647. #endregion 查询15个产品SN
  10648. // 调用MES进站(最多15个)
  10649. stopwatch2.Start();
  10650. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10651. for (int i = 0; i < vehicleCodes.Count; i++)
  10652. {
  10653. // 循环进站
  10654. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10655. {
  10656. // 产品SN(物料码)校验
  10657. string portNo = portNos[i];
  10658. List<TestItem> item = new List<TestItem>();
  10659. item.Add(new TestItem()
  10660. {
  10661. Parameter_name = "弹夹码",
  10662. Parameter_value = sn,
  10663. });
  10664. item.Add(new TestItem()
  10665. {
  10666. Parameter_name = "弹夹穴位",
  10667. Parameter_value = (i + 1).ToString(),
  10668. });
  10669. item.Add(new TestItem()
  10670. {
  10671. Parameter_name = "载具码",
  10672. Parameter_value = vehicleCodes[i],
  10673. });
  10674. item.Add(new TestItem()
  10675. {
  10676. Parameter_name = "载具穴号",
  10677. Parameter_value = "1",
  10678. });
  10679. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10680. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10681. }
  10682. }
  10683. stopwatch2.Stop();
  10684. short result = 0;
  10685. bool haveMesWarn = results.Contains(5);
  10686. bool havePCWarn = results.Contains(6);
  10687. if (haveMesWarn)
  10688. result = 2; // 5->2
  10689. else if (havePCWarn)
  10690. result = 6; // 6->4
  10691. else
  10692. result = 1;
  10693. // MES_Flag 为4MES报错
  10694. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10695. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10696. writeToPLC_Flag.Name = "d4MES_FLAG";
  10697. writeToPLC_Flag.Adress = 2496;
  10698. writeToPLC_Flag.Value = result;
  10699. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10700. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10701. }
  10702. catch (Exception ex)
  10703. {
  10704. stopwatch2.Stop();
  10705. // MES_Flag 为4上位机报错
  10706. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10707. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10708. writeToPLC_Flag.Name = "d4MES_FLAG";
  10709. writeToPLC_Flag.Adress = 2496;
  10710. writeToPLC_Flag.Value = (short)4;
  10711. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10712. string str = ex.StackTrace;
  10713. AddMessage_Station(stationNameStr, LogType.Error,
  10714. $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10715. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10716. }
  10717. stopwatch1.Stop();
  10718. AddMessage(LogType.Info,
  10719. stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10720. stopwatch2.ElapsedMilliseconds + "ms");
  10721. }
  10722. // 上次采集到的SN
  10723. //private string sn_S4_4出站接口 = string.Empty;
  10724. /// <summary>
  10725. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  10726. /// </summary>
  10727. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  10728. {
  10729. Stopwatch stopwatch1 = new Stopwatch();
  10730. Stopwatch stopwatch2 = new Stopwatch();
  10731. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10732. string stationNameStr = stationCode + stationName;
  10733. string processItem = stationName; // 测试项目
  10734. try
  10735. {
  10736. stopwatch1.Start();
  10737. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10738. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10739. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10740. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10741. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10742. sn = sn.Replace("\0", "");
  10743. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10744. bool isPass = d4Result == 1; // 产品结果 bool
  10745. #region 查询15个载具码
  10746. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10747. string vehicleData = string.Empty;
  10748. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10749. if (string.IsNullOrEmpty(vehicleData))
  10750. vehicleData = "";
  10751. if (snResult1 != 0)
  10752. {
  10753. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10754. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10755. writeToPLC_Flag1.Adress = 2496;
  10756. writeToPLC_Flag1.Value = (short)4;
  10757. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10758. stopwatch1.Stop();
  10759. AddMessage(LogType.Info,
  10760. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10761. return;
  10762. }
  10763. string[] cavitySNs = vehicleData.Split('.');
  10764. if (cavitySNs != null && cavitySNs.Length > 0)
  10765. {
  10766. for (int i = 0; i < cavitySNs.Length; i++)
  10767. {
  10768. if (string.IsNullOrEmpty(cavitySNs[i]))
  10769. vehicleCodes.Add("");
  10770. else
  10771. vehicleCodes.Add(cavitySNs[i]);
  10772. }
  10773. }
  10774. #endregion 查询15个载具码
  10775. // 统一查 产品SN列表
  10776. List<string> partNos = new List<string>();
  10777. foreach (string vehicleCode in vehicleCodes)
  10778. {
  10779. if (string.IsNullOrEmpty(vehicleCode))
  10780. partNos.Add("");
  10781. else
  10782. {
  10783. string partNo = "";
  10784. #region 查询载具上的产品信息
  10785. string cavityData = string.Empty;
  10786. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10787. if (string.IsNullOrEmpty(cavityData))
  10788. cavityData = "";
  10789. if (snResult != 0)
  10790. {
  10791. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10792. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10793. writeToPLC_Flag1.Adress = 2496;
  10794. writeToPLC_Flag1.Value = (short)4;
  10795. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10796. stopwatch1.Stop();
  10797. AddMessage(LogType.Info,
  10798. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10799. "ms");
  10800. return;
  10801. }
  10802. string[] partSNs = cavityData.Split('.');
  10803. if (partSNs != null && partSNs.Length >= 1)
  10804. partNo = partSNs[0];
  10805. #endregion 查询载具上的产品信息
  10806. partNos.Add(partNo);
  10807. }
  10808. }
  10809. // 调用MES出站
  10810. stopwatch2.Start();
  10811. // 统一上传
  10812. List<int> results = new List<int>();
  10813. for (int i = 0; i < partNos.Count; i++)
  10814. {
  10815. string index = (i + 1).ToString(); // 弹夹穴号
  10816. if (string.IsNullOrEmpty(partNos[i]))
  10817. results.Add(1);
  10818. else
  10819. {
  10820. List<TestItem> items1 = new List<TestItem>();
  10821. items1.Add(new TestItem()
  10822. {
  10823. Parameter_name = "弹夹码",
  10824. Parameter_value = sn,
  10825. Parameter_unit = ""
  10826. });
  10827. items1.Add(new TestItem()
  10828. {
  10829. Parameter_name = "弹夹穴号",
  10830. Parameter_value = index,
  10831. Parameter_unit = ""
  10832. });
  10833. items1.Add(new TestItem()
  10834. {
  10835. Parameter_name = "载具码",
  10836. Parameter_value = vehicleCodes[i],
  10837. Parameter_unit = ""
  10838. });
  10839. items1.Add(new TestItem()
  10840. {
  10841. Parameter_name = "载具穴号",
  10842. Parameter_value = "1",
  10843. Parameter_unit = ""
  10844. });
  10845. items1.Add(new TestItem()
  10846. {
  10847. Parameter_name = "产品结果",
  10848. Parameter_value = d4Result == 1 ? "OK" : "NG",
  10849. Parameter_unit = ""
  10850. });
  10851. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10852. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10853. results.Add(result1);
  10854. }
  10855. }
  10856. short result = 0;
  10857. if (results.All(a => a == 1))
  10858. result = 1;
  10859. else if (results.Contains(3))
  10860. result = 3;
  10861. else if (results.Contains(2))
  10862. result = 2;
  10863. else if (results.Contains(4))
  10864. result = 4;
  10865. else
  10866. result = 4;
  10867. stopwatch2.Stop();
  10868. // MES_Flag 为4MES报错
  10869. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10870. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10871. writeToPLC_Flag.Name = "d4MES_FLAG";
  10872. writeToPLC_Flag.Adress = 2496;
  10873. writeToPLC_Flag.Value = result;
  10874. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10875. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10876. }
  10877. catch (Exception ex)
  10878. {
  10879. stopwatch2.Restart();
  10880. // MES_Flag 为4上位机报错
  10881. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10882. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10883. writeToPLC_Flag.Name = "d4MES_FLAG";
  10884. writeToPLC_Flag.Adress = 2496;
  10885. writeToPLC_Flag.Value = (short)4;
  10886. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10887. string str = ex.StackTrace;
  10888. AddMessage_Station(stationNameStr, LogType.Error,
  10889. $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10890. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10891. stopwatch2.Stop();
  10892. }
  10893. stopwatch1.Stop();
  10894. AddMessage(LogType.Info,
  10895. stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10896. stopwatch2.ElapsedMilliseconds + "ms");
  10897. }
  10898. /// <summary>
  10899. /// [S4] 取放桁架 - S4_5弹夹扫码
  10900. /// </summary>
  10901. /// <param name="plcNo">PLC编号</param>
  10902. /// <param name="stationNameStr">工站全称</param>
  10903. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  10904. {
  10905. Stopwatch stopwatch1 = new Stopwatch();
  10906. Stopwatch stopwatch2 = new Stopwatch();
  10907. try
  10908. {
  10909. stopwatch1.Start();
  10910. // ZS 弹夹扫码
  10911. string d5BulletclipCode = " "; // 扫到的码
  10912. short d5BulletclipScanCode = 2;
  10913. stopwatch2.Start();
  10914. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  10915. //// MES_Flag
  10916. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10917. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10918. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10919. writeToPLC_Flag.Adress = 2528;
  10920. writeToPLC_Flag.Value = d5BulletclipScanCode;
  10921. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10922. {
  10923. Name = "d5BulletclipCode",
  10924. Adress = 2529,
  10925. ValueType = PLCValueType.String,
  10926. ValueTypeStrLength = 20,
  10927. Value = d5BulletclipCode
  10928. });
  10929. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10930. stopwatch2.Stop();
  10931. }
  10932. catch (Exception ex)
  10933. {
  10934. string str = ex.StackTrace;
  10935. AddMessage_Station(stationNameStr, LogType.Error,
  10936. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10937. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10938. stopwatch2.Start();
  10939. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  10940. //// MES_Flag
  10941. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  10942. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10943. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10944. writeToPLC_Flag.Adress = 2528;
  10945. writeToPLC_Flag.Value = (short)6;
  10946. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10947. {
  10948. Name = "d5BulletclipCode",
  10949. Adress = 2529,
  10950. ValueType = PLCValueType.String,
  10951. ValueTypeStrLength = 20,
  10952. Value = " "
  10953. });
  10954. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10955. stopwatch2.Stop();
  10956. }
  10957. stopwatch1.Stop();
  10958. AddMessage(LogType.Info,
  10959. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10960. stopwatch2.ElapsedMilliseconds + "ms");
  10961. }
  10962. /// <summary>
  10963. /// [S4] 取放桁架 - S4_5载具扫码
  10964. /// </summary>
  10965. /// <param name="plcNo">PLC编号</param>
  10966. /// <param name="stationNameStr">工站全称</param>
  10967. private void S4_5载具扫码(int plcNo, string stationNameStr)
  10968. {
  10969. Stopwatch stopwatch1 = new Stopwatch();
  10970. Stopwatch stopwatch2 = new Stopwatch();
  10971. try
  10972. {
  10973. stopwatch1.Start();
  10974. // ZS 载具扫码
  10975. string d5VehicleCode = " "; // 扫到的码
  10976. short d5VehicleScanCode = 2;
  10977. #region 进站
  10978. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  10979. {
  10980. // 查产品SN
  10981. #region 查询载具上的产品信息
  10982. string cavityData = string.Empty;
  10983. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  10984. if (string.IsNullOrEmpty(cavityData))
  10985. cavityData = "";
  10986. if (snResult != 0)
  10987. {
  10988. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10989. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  10990. writeToPLC_Flag1.Adress = 2559;
  10991. writeToPLC_Flag1.Value = (short)6;
  10992. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10993. {
  10994. Name = "d5VehicleCode",
  10995. Adress = 2560,
  10996. ValueType = PLCValueType.String,
  10997. ValueTypeStrLength = 20,
  10998. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10999. });
  11000. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  11001. stopwatch1.Stop();
  11002. AddMessage(LogType.Info,
  11003. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11004. "ms");
  11005. return;
  11006. }
  11007. string[] cavitySNs = cavityData.Split('.');
  11008. string partNo = "";
  11009. if (cavitySNs != null && cavitySNs.Length >= 1)
  11010. {
  11011. partNo = cavitySNs[0];
  11012. }
  11013. #endregion 查询载具上的产品信息
  11014. List<TestItem> item = new List<TestItem>();
  11015. item.Add(new TestItem()
  11016. {
  11017. Parameter_name = "载具码",
  11018. Parameter_value = d5VehicleCode,
  11019. });
  11020. item.Add(new TestItem()
  11021. {
  11022. Parameter_name = "载具穴号",
  11023. Parameter_value = "1",
  11024. });
  11025. stopwatch2.Start();
  11026. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11027. partNo, item, out string errorMsg);
  11028. stopwatch2.Stop();
  11029. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  11030. }
  11031. #endregion 进站
  11032. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  11033. //// MES_Flag
  11034. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  11035. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11036. writeToPLC_Flag.Name = "d5VehicleScanCode";
  11037. writeToPLC_Flag.Adress = 2559;
  11038. writeToPLC_Flag.Value = d5VehicleScanCode;
  11039. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11040. {
  11041. Name = "d5VehicleCode",
  11042. Adress = 2560,
  11043. ValueType = PLCValueType.String,
  11044. ValueTypeStrLength = 20,
  11045. Value = d5VehicleCode
  11046. });
  11047. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  11048. }
  11049. catch (Exception ex)
  11050. {
  11051. string str = ex.StackTrace;
  11052. AddMessage_Station(stationNameStr, LogType.Error,
  11053. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  11054. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11055. stopwatch2.Start();
  11056. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  11057. //// MES_Flag
  11058. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  11059. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11060. writeToPLC_Flag.Name = "d5VehicleScanCode";
  11061. writeToPLC_Flag.Adress = 2559;
  11062. writeToPLC_Flag.Value = (short)6;
  11063. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11064. {
  11065. Name = "d5VehicleCode",
  11066. Adress = 2560,
  11067. ValueType = PLCValueType.String,
  11068. ValueTypeStrLength = 20,
  11069. Value = " "
  11070. });
  11071. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  11072. stopwatch2.Stop();
  11073. }
  11074. stopwatch1.Stop();
  11075. AddMessage(LogType.Info,
  11076. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11077. stopwatch2.ElapsedMilliseconds + "ms");
  11078. }
  11079. // 上次采集到的SN
  11080. //private string sn_S4_5出站接口 = string.Empty;
  11081. /// <summary>
  11082. /// [S4] 取放桁架 - S4_5出站接口
  11083. /// </summary>
  11084. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  11085. {
  11086. Stopwatch stopwatch1 = new Stopwatch();
  11087. Stopwatch stopwatch2 = new Stopwatch();
  11088. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11089. string stationNameStr = stationCode + stationName;
  11090. string processItem = stationName; // 测试项目
  11091. try
  11092. {
  11093. stopwatch1.Start();
  11094. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11095. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11096. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11097. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11098. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  11099. sn = sn.Replace("\0", "");
  11100. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  11101. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  11102. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  11103. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  11104. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  11105. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  11106. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  11107. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  11108. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  11109. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  11110. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  11111. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  11112. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  11113. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  11114. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  11115. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  11116. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  11117. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  11118. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  11119. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  11120. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  11121. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  11122. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  11123. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  11124. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  11125. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  11126. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  11127. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  11128. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  11129. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  11130. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  11131. bool pass = d5Result == 1;
  11132. // 存 载具SN列表
  11133. List<string> vehicleCodes = new List<string>()
  11134. {
  11135. d5VehicleCode1, d5VehicleCode2, d5VehicleCode3, d5VehicleCode4, d5VehicleCode5,
  11136. d5VehicleCode6, d5VehicleCode7, d5VehicleCode8, d5VehicleCode9, d5VehicleCode10,
  11137. d5VehicleCode11, d5VehicleCode12, d5VehicleCode13, d5VehicleCode14, d5VehicleCode15
  11138. };
  11139. // 统一查 产品SN列表
  11140. List<string> partNos = new List<string>();
  11141. foreach (string vehicleCode in vehicleCodes)
  11142. {
  11143. if (string.IsNullOrEmpty(vehicleCode))
  11144. partNos.Add("");
  11145. else
  11146. {
  11147. string partNo = "";
  11148. #region 查询载具上的产品信息
  11149. string cavityData = string.Empty;
  11150. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11151. if (string.IsNullOrEmpty(cavityData))
  11152. cavityData = "";
  11153. if (snResult != 0)
  11154. {
  11155. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11156. writeToPLC_Flag1.Name = "d5MES_FLAG";
  11157. writeToPLC_Flag1.Adress = 2591;
  11158. writeToPLC_Flag1.Value = (short)4;
  11159. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  11160. stopwatch1.Stop();
  11161. AddMessage(LogType.Info,
  11162. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11163. "ms");
  11164. return;
  11165. }
  11166. string[] cavitySNs = cavityData.Split('.');
  11167. if (cavitySNs != null && cavitySNs.Length >= 1)
  11168. partNo = cavitySNs[0];
  11169. #endregion 查询载具上的产品信息
  11170. partNos.Add(partNo);
  11171. }
  11172. }
  11173. // 统一上传
  11174. stopwatch2.Start();
  11175. List<int> results = new List<int>();
  11176. for (int i = 0; i < partNos.Count; i++)
  11177. {
  11178. string index = (i + 1).ToString(); // 弹夹穴号
  11179. if (string.IsNullOrEmpty(partNos[i]))
  11180. results.Add(1);
  11181. else
  11182. {
  11183. List<TestItem> items1 = new List<TestItem>();
  11184. items1.Add(new TestItem()
  11185. {
  11186. Parameter_name = "弹夹码",
  11187. Parameter_value = sn,
  11188. Parameter_unit = ""
  11189. });
  11190. items1.Add(new TestItem()
  11191. {
  11192. Parameter_name = "弹夹穴号",
  11193. Parameter_value = index,
  11194. Parameter_unit = ""
  11195. });
  11196. items1.Add(new TestItem()
  11197. {
  11198. Parameter_name = "载具码",
  11199. Parameter_value = vehicleCodes[i],
  11200. Parameter_unit = ""
  11201. });
  11202. items1.Add(new TestItem()
  11203. {
  11204. Parameter_name = "载具穴号",
  11205. Parameter_value = "1",
  11206. Parameter_unit = ""
  11207. });
  11208. items1.Add(new TestItem()
  11209. {
  11210. Parameter_name = "产品结果",
  11211. Parameter_value = d5Result == 1 ? "OK" : "NG",
  11212. Parameter_unit = ""
  11213. });
  11214. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11215. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  11216. results.Add(result1);
  11217. }
  11218. }
  11219. short result = 0;
  11220. if (results.All(a => a == 1))
  11221. result = 1;
  11222. else if (results.Contains(3))
  11223. result = 3;
  11224. else if (results.Contains(2))
  11225. result = 2;
  11226. else if (results.Contains(4))
  11227. result = 4;
  11228. else
  11229. result = 4;
  11230. stopwatch2.Stop();
  11231. #region 存储绑定数据到 边线MES系统中
  11232. if (result == 1)
  11233. {
  11234. // 删除绑定信息
  11235. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11236. if (resultMesR != 0)
  11237. {
  11238. result = 4;
  11239. AddMessage_Station(stationNameStr, LogType.Error,
  11240. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11241. }
  11242. }
  11243. #endregion 存储绑定数据到 边线MES系统中
  11244. // MES_Flag 为4MES报错
  11245. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11246. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11247. writeToPLC_Flag.Name = "d5MES_FLAG";
  11248. writeToPLC_Flag.Adress = 2591;
  11249. writeToPLC_Flag.Value = result;
  11250. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11251. OnMessage(LogType.Debug,
  11252. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11253. }
  11254. catch (Exception ex)
  11255. {
  11256. stopwatch2.Restart();
  11257. // MES_Flag 为4上位机报错
  11258. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  11259. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11260. writeToPLC_Flag.Name = "d5MES_FLAG";
  11261. writeToPLC_Flag.Adress = 2591;
  11262. writeToPLC_Flag.Value = (short)4;
  11263. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11264. stopwatch2.Stop();
  11265. string str = ex.StackTrace;
  11266. AddMessage_Station(stationNameStr, LogType.Error,
  11267. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11268. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11269. }
  11270. stopwatch1.Stop();
  11271. AddMessage(LogType.Info,
  11272. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11273. stopwatch2.ElapsedMilliseconds + "ms");
  11274. }
  11275. /// <summary>
  11276. /// [S4] 取放桁架 - S4_5节拍接口
  11277. /// </summary>
  11278. /// <param name="plcNo">PLC编号</param>
  11279. /// <param name="stationNameStr">工站全称</param>
  11280. private void S4_5节拍接口(int plcNo, string stationNameStr)
  11281. {
  11282. Stopwatch stopwatch1 = new Stopwatch();
  11283. Stopwatch stopwatch2 = new Stopwatch();
  11284. string resultStr = string.Empty;
  11285. try
  11286. {
  11287. stopwatch1.Start();
  11288. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  11289. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  11290. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  11291. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11292. if (!actionBool)
  11293. {
  11294. stopwatch2.Start();
  11295. // MES_Flag
  11296. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  11297. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11298. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11299. writeToPLC_Flag1.Adress = 2924;
  11300. writeToPLC_Flag1.Value = (short)4;
  11301. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11302. stopwatch2.Stop();
  11303. AddMessage(LogType.Info,
  11304. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11305. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11306. return;
  11307. }
  11308. string d5OEEPartNo = string.Empty; // 物料码
  11309. if (string.IsNullOrEmpty(d5OEEProductSN))
  11310. {
  11311. stopwatch2.Start();
  11312. // MES_Flag
  11313. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11314. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11315. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11316. writeToPLC_Flag1.Adress = 2924;
  11317. writeToPLC_Flag1.Value = (short)1;
  11318. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11319. stopwatch2.Stop();
  11320. AddMessage(LogType.Info,
  11321. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11322. stopwatch2.ElapsedMilliseconds + "ms");
  11323. return;
  11324. }
  11325. else
  11326. {
  11327. // 查产品SN
  11328. d5OEEPartNo = "Test"; // ZS
  11329. }
  11330. short d5OEEMES_FLAG = 0;
  11331. // 上传OEE
  11332. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  11333. d5OEEMES_FLAG = result.Item1;
  11334. resultStr = result.Item2;
  11335. stopwatch2.Start();
  11336. // MES_Flag
  11337. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11338. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11339. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11340. writeToPLC_Flag.Adress = 2924;
  11341. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  11342. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11343. stopwatch2.Stop();
  11344. }
  11345. catch (Exception ex)
  11346. {
  11347. string str = ex.StackTrace;
  11348. AddMessage_Station(stationNameStr, LogType.Error,
  11349. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11350. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11351. // MES_Flag
  11352. stopwatch2.Start();
  11353. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  11354. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11355. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11356. writeToPLC_Flag.Adress = 2924;
  11357. writeToPLC_Flag.Value = (short)4;
  11358. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11359. stopwatch2.Stop();
  11360. }
  11361. stopwatch1.Stop();
  11362. AddMessage(LogType.Info,
  11363. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11364. stopwatch2.ElapsedMilliseconds + "ms");
  11365. }
  11366. #endregion [S4] 取放桁架
  11367. #endregion PLC4 刘果段
  11368. #region PLC5 张超凡
  11369. #region [S5] Tray盘下料装备
  11370. /// <summary>
  11371. /// S5工位的数据- 触发信号上次的值
  11372. /// </summary>
  11373. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  11374. /// <summary>
  11375. /// S5工位的数据(含触发信号)
  11376. /// </summary>
  11377. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  11378. /// <summary>
  11379. /// S5工位的数据- 回写点位
  11380. /// </summary>
  11381. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  11382. /// <summary>
  11383. /// [S5] Tray盘下料装备
  11384. /// </summary>
  11385. /// <param name="plcNo">PLC编号</param>
  11386. //private void ReadStation_S5(int plcNo)
  11387. //{
  11388. // // [S1] Tray盘上料装备
  11389. // // [S2] FCT
  11390. // // [S3] 值板机
  11391. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  11392. // // [S5] Tray盘下料装备
  11393. // /// 上位机心跳
  11394. // /// 获取设备报警数据与状态信息
  11395. // string stationCode = "[S5]";
  11396. // string stationName = "Tray盘下料装备";
  11397. // string stationNameStr = stationCode + stationName;
  11398. // #region 创建字典
  11399. // // 触发信号字典 赋值
  11400. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11401. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11402. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11403. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11404. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  11405. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11406. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  11407. // // PLC数据字典 赋值
  11408. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11409. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  11410. // s5PLCData.Add("e1ProductSN_Check", ""); //
  11411. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11412. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  11413. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  11414. // s5PLCData.Add("e1PartNo", ""); // 物料码
  11415. // s5PLCData.Add("e1Result", 0); // 产品结果
  11416. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11417. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  11418. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  11419. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  11420. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11421. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  11422. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  11423. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11424. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  11425. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  11426. // #endregion 创建字典
  11427. // while (IsRun)
  11428. // {
  11429. // try
  11430. // {
  11431. // if (!GlobalContext._IsCon_Funs5)
  11432. // {
  11433. // UpdatePLCMonitor(1, plcNo, 0);
  11434. // continue;
  11435. // }
  11436. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  11437. // {
  11438. // Stopwatch stopwatch1 = new Stopwatch();
  11439. // Stopwatch stopwatch2 = new Stopwatch();
  11440. // stopwatch1.Start();
  11441. // stopwatch2.Start();
  11442. // #region 一次性读取所有数据
  11443. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  11444. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  11445. // int[] datas = data1.Concat(data2).ToArray();
  11446. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  11447. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  11448. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  11449. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  11450. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  11451. // s5PLCData["e1MES_FLAG"] = datas[35];
  11452. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  11453. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  11454. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  11455. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  11456. // s5PLCData["e1Result"] = datas[76];
  11457. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  11458. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  11459. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  11460. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  11461. // s5PLCData["e1OEEType"] = datas[109];
  11462. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  11463. // s5PLCData["e1AGVUpStart"] = datas[121];
  11464. // s5PLCData["e1AGVUpEnd"] = datas[122];
  11465. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  11466. // s5PLCData["e1AGVDownStart"] = datas[134];
  11467. // s5PLCData["e1AGVDownEnd"] = datas[135];
  11468. // #endregion 一次性读取所有数据
  11469. // stopwatch2.Stop();
  11470. // #region 回写操作,写后清空flag
  11471. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  11472. // #endregion 回写操作,写后清空flag
  11473. // #region 进站校验
  11474. // try
  11475. // {
  11476. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  11477. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  11478. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  11479. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  11480. // {
  11481. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  11482. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  11483. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  11484. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  11485. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  11486. // }
  11487. // }
  11488. // catch (Exception ex)
  11489. // {
  11490. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11491. // string str = ex.StackTrace;
  11492. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11493. // }
  11494. // #endregion 进站校验
  11495. // #region 出站接口
  11496. // try
  11497. // {
  11498. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  11499. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  11500. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  11501. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  11502. // {
  11503. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  11504. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  11505. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  11506. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  11507. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  11508. // }
  11509. // }
  11510. // catch (Exception ex)
  11511. // {
  11512. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  11513. // string str = ex.StackTrace;
  11514. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11515. // }
  11516. // #endregion 出站接口
  11517. // #region 节拍接口
  11518. // try
  11519. // {
  11520. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  11521. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  11522. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  11523. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  11524. // {
  11525. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  11526. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  11527. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  11528. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  11529. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  11530. // }
  11531. // }
  11532. // catch (Exception ex)
  11533. // {
  11534. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11535. // string str = ex.StackTrace;
  11536. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11537. // }
  11538. // #endregion 节拍接口
  11539. // #region AGV上料
  11540. // // AGV上料叫AGV信号
  11541. // try
  11542. // {
  11543. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  11544. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  11545. // if (e1AGVUpCall != e1AGVUpCallOld)
  11546. // {
  11547. // if (e1AGVUpCall == 1) // 0->1
  11548. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  11549. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  11550. // }
  11551. // }
  11552. // catch (Exception ex)
  11553. // {
  11554. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11555. // string str = ex.StackTrace;
  11556. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11557. // }
  11558. // // AGV上料完成信号
  11559. // try
  11560. // {
  11561. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  11562. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  11563. // if (e1AGVUpEnd != e1AGVUpEndOld)
  11564. // {
  11565. // if (e1AGVUpEnd == 1) // 0->1
  11566. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  11567. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  11568. // }
  11569. // }
  11570. // catch (Exception ex)
  11571. // {
  11572. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  11573. // string str = ex.StackTrace;
  11574. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11575. // }
  11576. // #endregion AGV上料
  11577. // #region AGV下料
  11578. // // AGV下料叫agv信号
  11579. // try
  11580. // {
  11581. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  11582. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  11583. // if (e1AGVDownCall != e1AGVDownCallOld)
  11584. // {
  11585. // if (e1AGVDownCall == 1) // 0->1
  11586. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  11587. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  11588. // }
  11589. // }
  11590. // catch (Exception ex)
  11591. // {
  11592. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  11593. // string str = ex.StackTrace;
  11594. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11595. // }
  11596. // // AGV下料完成信号
  11597. // try
  11598. // {
  11599. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  11600. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  11601. // if (e1AGVDownEnd != e1AGVDownEndOld)
  11602. // {
  11603. // if (e1AGVDownEnd == 1) // 0->1
  11604. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  11605. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  11606. // }
  11607. // }
  11608. // catch (Exception ex)
  11609. // {
  11610. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  11611. // string str = ex.StackTrace;
  11612. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11613. // }
  11614. // #endregion AGV下料
  11615. // #region 心跳
  11616. // try
  11617. // {
  11618. // short states = 0;
  11619. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  11620. // }
  11621. // catch (Exception ex)
  11622. // {
  11623. // string str = ex.StackTrace;
  11624. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11625. // }
  11626. // #endregion 心跳
  11627. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  11628. // stopwatch1.Stop();
  11629. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  11630. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  11631. // }
  11632. // else
  11633. // {
  11634. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11635. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  11636. // Funs[plcNo].Connect();
  11637. // }
  11638. // }
  11639. // catch (Exception ex)
  11640. // {
  11641. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11642. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  11643. // Funs[plcNo].ReConnect();
  11644. // }
  11645. // Thread.Sleep(IntervalReadPLC);
  11646. // }
  11647. //}
  11648. /// <summary>
  11649. /// [S5] Tray盘下料装备 - 进站校验
  11650. /// </summary>
  11651. /// <param name="plcNo">PLC编号</param>
  11652. /// <param name="stationNameStr">工站全称</param>
  11653. private void S5进站校验(int plcNo, string stationNameStr)
  11654. {
  11655. Stopwatch stopwatch1 = new Stopwatch();
  11656. Stopwatch stopwatch2 = new Stopwatch();
  11657. try
  11658. {
  11659. stopwatch1.Start();
  11660. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  11661. sn = sn.Replace("\0", "");
  11662. // 获取产品SN By 载具码
  11663. #region 查询载具上的产品信息
  11664. string cavityData = string.Empty;
  11665. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11666. if (string.IsNullOrEmpty(cavityData))
  11667. cavityData = "";
  11668. if (snResult != 0)
  11669. {
  11670. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11671. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  11672. writeToPLC_Flag1.Adress = 2003;
  11673. writeToPLC_Flag1.Value = (short)6;
  11674. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  11675. stopwatch1.Stop();
  11676. AddMessage(LogType.Info,
  11677. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11678. return;
  11679. }
  11680. string[] cavitySNs = cavityData.Split('.');
  11681. string partNo = string.Empty;
  11682. if (cavitySNs != null && cavitySNs.Length >= 1)
  11683. partNo = cavitySNs[0];
  11684. #endregion 查询载具上的产品信息
  11685. // 产品SN(物料码)校验
  11686. List<TestItem> item = new List<TestItem>();
  11687. item.Add(new TestItem()
  11688. {
  11689. Parameter_name = "载具码",
  11690. Parameter_value = sn,
  11691. });
  11692. item.Add(new TestItem()
  11693. {
  11694. Parameter_name = "载具穴号",
  11695. Parameter_value = "1",
  11696. });
  11697. stopwatch2.Start();
  11698. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11699. partNo, item, out string errorMsg);
  11700. stopwatch2.Stop();
  11701. short e1MES_FLAG_Check = (short)result;
  11702. // MES_Flag
  11703. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  11704. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11705. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11706. writeToPLC_Flag.Adress = 2003;
  11707. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  11708. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11709. }
  11710. catch (Exception ex)
  11711. {
  11712. string str = ex.StackTrace;
  11713. AddMessage_Station(stationNameStr, LogType.Error,
  11714. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  11715. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11716. // MES_Flag
  11717. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11718. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11719. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11720. writeToPLC_Flag.Adress = 2003;
  11721. writeToPLC_Flag.Value = (short)6;
  11722. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11723. }
  11724. stopwatch1.Stop();
  11725. AddMessage(LogType.Info,
  11726. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  11727. stopwatch2.ElapsedMilliseconds + "ms");
  11728. }
  11729. /// <summary>
  11730. /// [S5] Tray盘下料装备 - 出站接口
  11731. /// </summary>
  11732. /// <param name="plcNo"></param>
  11733. /// <param name="stationCode"></param>
  11734. /// <param name="stationName"></param>
  11735. private void S5出站接口(int plcNo, string stationCode, string stationName)
  11736. {
  11737. Stopwatch stopwatch1 = new Stopwatch();
  11738. Stopwatch stopwatch2 = new Stopwatch();
  11739. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11740. string stationNameStr = stationCode + stationName;
  11741. string processItem = stationName; // 测试项目
  11742. try
  11743. {
  11744. stopwatch1.Start();
  11745. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11746. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11747. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11748. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11749. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  11750. sn = sn.Replace("\0", "");
  11751. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  11752. //partNo = partNo.Replace("\0", "");
  11753. #region 查询载具上的产品信息
  11754. string cavityData = string.Empty;
  11755. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11756. if (string.IsNullOrEmpty(cavityData))
  11757. cavityData = "";
  11758. if (snResult != 0)
  11759. {
  11760. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11761. writeToPLC_Flag1.Name = "e1MES_FLAG";
  11762. writeToPLC_Flag1.Adress = 2035;
  11763. writeToPLC_Flag1.Value = (short)4;
  11764. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  11765. stopwatch1.Stop();
  11766. AddMessage(LogType.Info,
  11767. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11768. return;
  11769. }
  11770. string[] cavitySNs = cavityData.Split('.');
  11771. string partNo = string.Empty;
  11772. if (cavitySNs != null && cavitySNs.Length >= 1)
  11773. partNo = cavitySNs[0];
  11774. #endregion 查询载具上的产品信息
  11775. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  11776. bool pass = e1Result == 1;
  11777. stopwatch2.Start();
  11778. // 上传MES
  11779. List<TestItem> items = new List<TestItem>();
  11780. items.Add(new TestItem()
  11781. {
  11782. Parameter_name = "载具码",
  11783. Parameter_value = sn,
  11784. Parameter_unit = ""
  11785. });
  11786. items.Add(new TestItem()
  11787. {
  11788. Parameter_name = "载具穴号",
  11789. Parameter_value = "1",
  11790. Parameter_unit = ""
  11791. });
  11792. items.Add(new TestItem()
  11793. {
  11794. Parameter_name = "产品结果",
  11795. Parameter_value = e1Result == 1 ? "OK" : "NG",
  11796. Parameter_unit = ""
  11797. });
  11798. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  11799. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  11800. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  11801. short result = result1 == 1 ? (short)1 : (short)3;
  11802. stopwatch2.Stop();
  11803. #region 存储绑定数据到 边线MES系统中
  11804. if (result == 1)
  11805. {
  11806. // 删除绑定信息
  11807. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11808. if (resultMesR != 0)
  11809. {
  11810. result = 4;
  11811. AddMessage_Station(stationNameStr, LogType.Error,
  11812. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11813. }
  11814. }
  11815. #endregion 存储绑定数据到 边线MES系统中
  11816. // MES_Flag 为MES报错
  11817. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11818. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  11819. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11820. writeToPLC_Flag.Name = "e1MES_FLAG";
  11821. writeToPLC_Flag.Adress = 2035;
  11822. writeToPLC_Flag.Value = result;
  11823. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11824. OnMessage(LogType.Debug,
  11825. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11826. }
  11827. catch (Exception ex)
  11828. {
  11829. stopwatch2.Restart();
  11830. // MES_Flag 为4上位机报错
  11831. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  11832. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11833. writeToPLC_Flag.Name = "e1MES_FLAG";
  11834. writeToPLC_Flag.Adress = 2035;
  11835. writeToPLC_Flag.Value = (short)4;
  11836. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11837. stopwatch2.Stop();
  11838. string str = ex.StackTrace;
  11839. AddMessage_Station(stationNameStr, LogType.Error,
  11840. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11841. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11842. }
  11843. stopwatch1.Stop();
  11844. AddMessage(LogType.Info,
  11845. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11846. stopwatch2.ElapsedMilliseconds + "ms");
  11847. }
  11848. /// <summary>
  11849. /// [S5] Tray盘下料装备 - 节拍接口
  11850. /// </summary>
  11851. /// <param name="plcNo">PLC编号</param>
  11852. /// <param name="stationNameStr">工站全称</param>
  11853. //private void S5节拍接口(int plcNo, string stationNameStr)
  11854. //{
  11855. // Stopwatch stopwatch1 = new Stopwatch();
  11856. // Stopwatch stopwatch2 = new Stopwatch();
  11857. // string resultStr = string.Empty;
  11858. // try
  11859. // {
  11860. // stopwatch1.Start();
  11861. // string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  11862. // string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  11863. // e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  11864. // bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11865. // if (!actionBool)
  11866. // {
  11867. // stopwatch2.Start();
  11868. // // MES_Flag
  11869. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11870. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11871. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11872. // writeToPLC_Flag1.Adress = 2088;
  11873. // writeToPLC_Flag1.Value = (short)4;
  11874. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11875. // stopwatch2.Stop();
  11876. // AddMessage(LogType.Info,
  11877. // stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11878. // "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11879. // return;
  11880. // }
  11881. // string e1OEEPartNo = string.Empty; // 物料码
  11882. // if (string.IsNullOrEmpty(e1OEEProductSN))
  11883. // {
  11884. // stopwatch2.Start();
  11885. // // MES_Flag
  11886. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11887. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11888. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11889. // writeToPLC_Flag1.Adress = 2088;
  11890. // writeToPLC_Flag1.Value = (short)1;
  11891. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11892. // stopwatch2.Stop();
  11893. // AddMessage(LogType.Info,
  11894. // stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11895. // stopwatch2.ElapsedMilliseconds + "ms");
  11896. // return;
  11897. // }
  11898. // else
  11899. // {
  11900. // // 查产品SN
  11901. // e1OEEPartNo = "Test"; // ZS
  11902. // }
  11903. // short e1OEEMES_FLAG = 0;
  11904. // // 上传OEE
  11905. // (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  11906. // e1OEEMES_FLAG = result.Item1;
  11907. // resultStr = result.Item2;
  11908. // stopwatch2.Start();
  11909. // // MES_Flag
  11910. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11911. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11912. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11913. // writeToPLC_Flag.Adress = 2088;
  11914. // writeToPLC_Flag.Value = e1OEEMES_FLAG;
  11915. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11916. // stopwatch2.Stop();
  11917. // }
  11918. // catch (Exception ex)
  11919. // {
  11920. // string str = ex.StackTrace;
  11921. // AddMessage_Station(stationNameStr, LogType.Error,
  11922. // $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11923. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11924. // // MES_Flag
  11925. // stopwatch2.Start();
  11926. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11927. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11928. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11929. // writeToPLC_Flag.Adress = 2088;
  11930. // writeToPLC_Flag.Value = (short)4;
  11931. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11932. // stopwatch2.Stop();
  11933. // }
  11934. // stopwatch1.Stop();
  11935. // AddMessage(LogType.Info,
  11936. // stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11937. // stopwatch2.ElapsedMilliseconds + "ms");
  11938. //}
  11939. /// <summary>
  11940. /// [S5] Tray盘下料装备 - AGV上料叫agv
  11941. /// </summary>
  11942. /// <param name="plcNo">PLC编号</param>
  11943. /// <param name="stationNameStr">工站全称</param>
  11944. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  11945. {
  11946. Stopwatch stopwatch1 = new Stopwatch();
  11947. Stopwatch stopwatch2 = new Stopwatch();
  11948. try
  11949. {
  11950. stopwatch1.Start();
  11951. // ZS 呼叫AGV
  11952. short e1AGVUpCall = 2;
  11953. stopwatch2.Start();
  11954. // e1AGVUpCall
  11955. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11956. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11957. writeToPLC_Flag.Name = "e1AGVUpCall";
  11958. writeToPLC_Flag.Adress = 2120;
  11959. writeToPLC_Flag.Value = e1AGVUpCall;
  11960. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11961. stopwatch2.Stop();
  11962. }
  11963. catch (Exception ex)
  11964. {
  11965. string str = ex.StackTrace;
  11966. AddMessage_Station(stationNameStr, LogType.Error,
  11967. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  11968. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11969. // e1AGVUpCall
  11970. stopwatch2.Start();
  11971. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11972. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11973. writeToPLC_Flag.Name = "e1AGVUpCall";
  11974. writeToPLC_Flag.Adress = 2120;
  11975. writeToPLC_Flag.Value = (short)4;
  11976. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11977. stopwatch2.Stop();
  11978. }
  11979. stopwatch1.Stop();
  11980. AddMessage(LogType.Info,
  11981. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11982. stopwatch2.ElapsedMilliseconds + "ms");
  11983. }
  11984. /// <summary>
  11985. /// [S5] Tray盘下料装备 - AGV上料完成
  11986. /// </summary>
  11987. /// <param name="plcNo">PLC编号</param>
  11988. /// <param name="stationNameStr">工站全称</param>
  11989. private void S5AGV上料完成(int plcNo, string stationNameStr)
  11990. {
  11991. Stopwatch stopwatch1 = new Stopwatch();
  11992. Stopwatch stopwatch2 = new Stopwatch();
  11993. try
  11994. {
  11995. stopwatch1.Start();
  11996. // ZS AGV上料完成,让小车离开
  11997. short e1AGVUpEnd = 2;
  11998. stopwatch2.Start();
  11999. // e1AGVUpEnd
  12000. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12001. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12002. writeToPLC_Flag.Name = "e1AGVUpEnd";
  12003. writeToPLC_Flag.Adress = 2122;
  12004. writeToPLC_Flag.Value = e1AGVUpEnd;
  12005. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  12006. stopwatch2.Stop();
  12007. }
  12008. catch (Exception ex)
  12009. {
  12010. string str = ex.StackTrace;
  12011. AddMessage_Station(stationNameStr, LogType.Error,
  12012. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  12013. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12014. // e1AGVUpEnd
  12015. stopwatch2.Start();
  12016. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  12017. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12018. writeToPLC_Flag.Name = "e1AGVUpEnd";
  12019. writeToPLC_Flag.Adress = 2122;
  12020. writeToPLC_Flag.Value = (short)4;
  12021. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  12022. stopwatch2.Stop();
  12023. }
  12024. stopwatch1.Stop();
  12025. AddMessage(LogType.Info,
  12026. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12027. stopwatch2.ElapsedMilliseconds + "ms");
  12028. }
  12029. /// <summary>
  12030. /// [S5] Tray盘下料装备 - AGV下料叫agv
  12031. /// </summary>
  12032. /// <param name="plcNo">PLC编号</param>
  12033. /// <param name="stationNameStr">工站全称</param>
  12034. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  12035. {
  12036. Stopwatch stopwatch1 = new Stopwatch();
  12037. Stopwatch stopwatch2 = new Stopwatch();
  12038. try
  12039. {
  12040. stopwatch1.Start();
  12041. // ZS 呼叫AGV
  12042. short e1AGVDownCall = 2;
  12043. stopwatch2.Start();
  12044. // e1AGVDownCall
  12045. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12046. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12047. writeToPLC_Flag.Name = "e1AGVDownCall";
  12048. writeToPLC_Flag.Adress = 2133;
  12049. writeToPLC_Flag.Value = e1AGVDownCall;
  12050. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  12051. stopwatch2.Stop();
  12052. }
  12053. catch (Exception ex)
  12054. {
  12055. string str = ex.StackTrace;
  12056. AddMessage_Station(stationNameStr, LogType.Error,
  12057. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  12058. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12059. // e1AGVDownCall
  12060. stopwatch2.Start();
  12061. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  12062. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12063. writeToPLC_Flag.Name = "e1AGVDownCall";
  12064. writeToPLC_Flag.Adress = 2133;
  12065. writeToPLC_Flag.Value = (short)4;
  12066. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  12067. stopwatch2.Stop();
  12068. }
  12069. stopwatch1.Stop();
  12070. AddMessage(LogType.Info,
  12071. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12072. stopwatch2.ElapsedMilliseconds + "ms");
  12073. }
  12074. /// <summary>
  12075. /// [S5] Tray盘下料装备 - AGV下料完成
  12076. /// </summary>
  12077. /// <param name="plcNo">PLC编号</param>
  12078. /// <param name="stationNameStr">工站全称</param>
  12079. private void S5AGV下料完成(int plcNo, string stationNameStr)
  12080. {
  12081. Stopwatch stopwatch1 = new Stopwatch();
  12082. Stopwatch stopwatch2 = new Stopwatch();
  12083. try
  12084. {
  12085. stopwatch1.Start();
  12086. // ZS AGV上料完成,让小车离开
  12087. short e1AGVDownEnd = 2;
  12088. stopwatch2.Start();
  12089. // e1AGVDownEnd
  12090. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12091. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12092. writeToPLC_Flag.Name = "e1AGVDownEnd";
  12093. writeToPLC_Flag.Adress = 2135;
  12094. writeToPLC_Flag.Value = e1AGVDownEnd;
  12095. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  12096. stopwatch2.Stop();
  12097. }
  12098. catch (Exception ex)
  12099. {
  12100. string str = ex.StackTrace;
  12101. AddMessage_Station(stationNameStr, LogType.Error,
  12102. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  12103. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12104. // e1AGVDownEnd
  12105. stopwatch2.Start();
  12106. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  12107. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12108. writeToPLC_Flag.Name = "e1AGVDownEnd";
  12109. writeToPLC_Flag.Adress = 2135;
  12110. writeToPLC_Flag.Value = (short)4;
  12111. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  12112. stopwatch2.Stop();
  12113. }
  12114. stopwatch1.Stop();
  12115. AddMessage(LogType.Info,
  12116. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12117. stopwatch2.ElapsedMilliseconds + "ms");
  12118. }
  12119. #endregion [S5] Tray盘下料装备
  12120. #endregion PLC5 张超凡
  12121. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  12122. /// <summary>
  12123. /// PLC读取到的数据 -添加数据
  12124. /// </summary>
  12125. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  12126. {
  12127. if (sxPlcData.ContainsKey(newKey))
  12128. sxPlcData[newKey] = newValue;
  12129. else
  12130. sxPlcData.Add(newKey, newValue);
  12131. }
  12132. /// <summary>
  12133. /// PLC需要写入的数据 -添加数据
  12134. /// </summary>
  12135. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey,
  12136. WriteToPLC_Flag newValue)
  12137. {
  12138. if (sxPLCWriteData.ContainsKey(newKey))
  12139. sxPLCWriteData[newKey] = newValue;
  12140. else
  12141. sxPLCWriteData.Add(newKey, newValue);
  12142. }
  12143. /// <summary>
  12144. /// PLC回写操作,写后清空flag
  12145. /// </summary>
  12146. /// <param name="modbusClient">modbus对象</param>
  12147. /// <param name="pLCReadDatas">读取到的数据字典</param>
  12148. /// <param name="pLCWriteDatas">需要写入的数据</param>
  12149. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas,
  12150. ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  12151. {
  12152. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  12153. {
  12154. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  12155. for (int i = 0; i < pLCWriteDatas.Count; i++)
  12156. {
  12157. string mesFlagName = pLCWriteDatas[i].Name;
  12158. int mesFlagAdress = pLCWriteDatas[i].Adress;
  12159. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  12160. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  12161. {
  12162. // 先回写数据
  12163. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  12164. for (int j = 0; j < writeToPLCDatas.Count; j++)
  12165. {
  12166. int mesDataAdress = writeToPLCDatas[j].Adress;
  12167. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  12168. switch (mesDataType)
  12169. {
  12170. case PLCValueType.Short:
  12171. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  12172. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  12173. break;
  12174. case PLCValueType.String:
  12175. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  12176. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  12177. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr,
  12178. mesDataValueStrLength);
  12179. break;
  12180. }
  12181. }
  12182. // 再回写信号
  12183. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  12184. // 存储读取数据的字典
  12185. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  12186. // 存储写入数据的字典 - 清空写入值
  12187. pLCWriteDatas[i].Value = (short)0;
  12188. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  12189. }
  12190. }
  12191. }
  12192. }
  12193. /// <summary>
  12194. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  12195. /// </summary>
  12196. /// <param name="no">3</param>
  12197. /// <param name="stationCode">设备编号</param>
  12198. /// <param name="stationNameStr">设备名称</param>
  12199. /// <param name="plcOrder">车间订单号</param>
  12200. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  12201. {
  12202. try
  12203. {
  12204. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  12205. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  12206. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  12207. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  12208. int result1 = 0;
  12209. switch (stationCode)
  12210. {
  12211. case 2:
  12212. case 3:
  12213. case 4:
  12214. case 6:
  12215. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  12216. break;
  12217. case 102:
  12218. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  12219. break;
  12220. case 103:
  12221. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  12222. break;
  12223. case 104:
  12224. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  12225. break;
  12226. case 106:
  12227. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  12228. break;
  12229. default:
  12230. // MES_Flag 为“6未找到正确设备编号”
  12231. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  12232. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  12233. return;
  12234. }
  12235. short result = result1 == 1 ? (short)1 : (short)2;
  12236. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  12237. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  12238. }
  12239. catch (Exception ex)
  12240. {
  12241. // MES_Flag 为2上位机报错
  12242. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  12243. string str = ex.StackTrace;
  12244. AddMessage_Station(stationNameStr, LogType.Error,
  12245. $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  12246. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12247. }
  12248. }
  12249. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  12250. #region UI刷新
  12251. /// <summary>
  12252. /// 更新商品信息的UI + 下发产品信息(SN)
  12253. /// </summary>
  12254. private void UpdateProductInfo()
  12255. {
  12256. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  12257. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  12258. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  12259. //txt_CurSupplierCode.Text = ""; // 供应商代号
  12260. }
  12261. /// <summary>
  12262. /// 更新PLC连接状态的UI
  12263. /// </summary>
  12264. /// <param name="no">PLC编号</param>
  12265. /// <param name="status">状态</param>
  12266. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  12267. {
  12268. if (this != null && !this.IsDisposed)
  12269. {
  12270. switch (imgNo)
  12271. {
  12272. case 1:
  12273. this.BeginInvoke(new Action(() => { picPLC.Image = imageListState.Images[status]; }));
  12274. break;
  12275. case 2:
  12276. this.BeginInvoke(new Action(() => { pictureBox2.Image = imageListState.Images[status]; }));
  12277. break;
  12278. case 3:
  12279. this.BeginInvoke(new Action(() => { pictureBox3.Image = imageListState.Images[status]; }));
  12280. break;
  12281. case 4:
  12282. this.BeginInvoke(new Action(() => { pictureBox4.Image = imageListState.Images[status]; }));
  12283. break;
  12284. case 5:
  12285. this.BeginInvoke(new Action(() => { pictureBox5.Image = imageListState.Images[status]; }));
  12286. break;
  12287. case 6:
  12288. this.BeginInvoke(new Action(() => { pictureBox6.Image = imageListState.Images[status]; }));
  12289. break;
  12290. case 7:
  12291. this.BeginInvoke(new Action(() => { pictureBox7.Image = imageListState.Images[status]; }));
  12292. break;
  12293. case 8:
  12294. this.BeginInvoke(new Action(() => { pictureBox8.Image = imageListState.Images[status]; }));
  12295. break;
  12296. default:
  12297. break;
  12298. }
  12299. }
  12300. Task.Run(() => // 更新PLC交互页的指示灯
  12301. {
  12302. try
  12303. {
  12304. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12305. {
  12306. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  12307. }
  12308. }
  12309. catch
  12310. {
  12311. }
  12312. });
  12313. }
  12314. #endregion UI刷新
  12315. #region 日志
  12316. /// <summary>
  12317. /// 添加各工位运行日志(同步至PLC交互页面)
  12318. /// </summary>
  12319. /// <param name="stationNameStr">工站名称</param>
  12320. /// <param name="logType">日志类型</param>
  12321. /// <param name="message">日志内容</param>
  12322. /// <param name="snNumber">产品数字SN</param>
  12323. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  12324. {
  12325. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")))
  12326. {
  12327. AddMessage(logType, message); // 首页展示+日志记录
  12328. }
  12329. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  12330. {
  12331. StationName = stationNameStr,
  12332. SnNumber = snNumber,
  12333. Message = message,
  12334. CreateTime = DateTime.Now
  12335. };
  12336. // PLC交互页展示
  12337. Task.Run(() =>
  12338. {
  12339. try
  12340. {
  12341. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12342. {
  12343. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  12344. }
  12345. }
  12346. catch
  12347. {
  12348. }
  12349. });
  12350. }
  12351. /// <summary>
  12352. /// 添加运行日志
  12353. /// </summary>
  12354. /// <param name="logType">日志类型</param>
  12355. /// <param name="message">日志内容</param>
  12356. public void AddMessage(LogType logType, string message)
  12357. {
  12358. OnMessage(logType, message);
  12359. string date = DateTime.Now.ToString("yyyy/MM/dd");
  12360. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  12361. string msgShow = time + "--> " + message + "\r\n";
  12362. try
  12363. {
  12364. this.BeginInvoke(new Action(() =>
  12365. {
  12366. systemLog.Rows.Insert(0, date, time, message);
  12367. if (systemLog.Rows.Count >= 100)
  12368. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  12369. }));
  12370. }
  12371. catch (Exception ex) { }
  12372. }
  12373. /// <summary>
  12374. /// 添加运行日志-保存
  12375. /// </summary>
  12376. /// <param name="logType">日志类型</param>
  12377. /// <param name="message">日志内容</param>
  12378. private void OnMessage(LogType logType, string msg)
  12379. {
  12380. MessageEvent?.Invoke(logType, msg);
  12381. }
  12382. /// <summary>
  12383. /// 保存PLC写入日志
  12384. /// </summary>
  12385. /// <param name="logType"></param>
  12386. /// <param name="logValue"></param>
  12387. private void WritePLCLog(LogType logType, string logValue)
  12388. {
  12389. switch ((int)logType)
  12390. {
  12391. case 0:
  12392. _PLCLogNet.WriteDebug(logValue);
  12393. break;
  12394. case 1:
  12395. _PLCLogNet.WriteInfo(logValue);
  12396. break;
  12397. case 2:
  12398. _PLCLogNet.WriteWarn(logValue);
  12399. break;
  12400. case 3:
  12401. _PLCLogNet.WriteError(logValue);
  12402. break;
  12403. default:
  12404. _PLCLogNet.WriteFatal(logValue);
  12405. break;
  12406. }
  12407. }
  12408. /// <summary>
  12409. /// IOT Mqtt回调方法- With DataId
  12410. /// </summary>
  12411. /// <param name="id"></param>
  12412. /// <param name="v"></param>
  12413. /// <param name="dataId"></param>
  12414. public void CallbackWithDataId(string id, string msg, string dataId)
  12415. {
  12416. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  12417. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  12418. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  12419. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  12420. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  12421. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12422. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  12423. }
  12424. /// <summary>
  12425. /// AGV Mqtt回调方法- 记录Log并处理数据
  12426. /// </summary>
  12427. /// <param name="obj"></param>
  12428. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  12429. {
  12430. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12431. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  12432. // 接收到的信息
  12433. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  12434. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  12435. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  12436. {
  12437. }
  12438. }
  12439. #endregion 日志
  12440. //private void button1_Click(object sender, EventArgs e)
  12441. //{
  12442. // OpenDailogFalg=true;
  12443. // if (OpenDailogFalg)
  12444. // {
  12445. // using (var dialog = new BandBarodeDialog())
  12446. // {
  12447. // string strCarrierBarcode = "N801A-003";
  12448. // dialog._CarrierBarcode = strCarrierBarcode;
  12449. // string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  12450. // dialog._ProductBarcode = sn;
  12451. // var rs = dialog.ShowDialog();
  12452. // if (rs == DialogResult.OK)
  12453. // {
  12454. // AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  12455. // OpenDailogFalg = false;//关闭扫码
  12456. // }
  12457. // }
  12458. // }
  12459. //}
  12460. }
  12461. }