Form_Home.cs 577 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. /*
  40. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  41. */
  42. namespace MainForm
  43. {
  44. /// <summary>
  45. /// 记录日志的委托
  46. /// </summary>
  47. /// <param name="logType">日志类型</param>
  48. /// <param name="message">日志信息</param>
  49. public delegate void HomeMessageHandler(LogType logType, string message);
  50. /// <summary>
  51. /// 主页窗体
  52. /// </summary>
  53. public partial class Form_Home : Form
  54. {
  55. #region 常量
  56. //文本常量
  57. private const string Head = "开始采集";
  58. private const string Tail = "采集完成";
  59. private const string Body = "工位出站数据";
  60. private const string BodyCheck = "工位点检数据";
  61. private const string BodyRun = "整线运行数据";
  62. private const string BodyAlarm = "整线报警数据";
  63. #endregion 常量
  64. #region 变量
  65. /// <summary>
  66. /// 委托-记录日志的方法
  67. /// </summary>
  68. public event HomeMessageHandler MessageEvent;
  69. /// <summary>
  70. /// 日志接口
  71. /// </summary>
  72. ILogNet _PLCLogNet;
  73. /// <summary>
  74. /// 用于记录IOT MQTT日志
  75. /// </summary>
  76. ILogNet _IOTMqttLogNet;
  77. /// <summary>
  78. /// 用于记录AGV MQTT日志
  79. /// </summary>
  80. ILogNet _AGVMqttLogNet;
  81. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  82. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  83. // 间隔时间
  84. private int IntervalReadPLC = 300; //ms 读PLC
  85. private int IntervalMonitorMES = 1000; //ms MES心跳
  86. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  87. // 软件状态
  88. private bool IsRun = true;
  89. #region PLC 与 TCP对象
  90. // 定义一个字典,存plc对象(通讯)
  91. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  92. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  93. // 定义TCPClient对象列表
  94. Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  95. // 定义MQTTHelper对象
  96. MQTTHelper _MQTTHelper = new MQTTHelper();
  97. #endregion PLC 与 TCP对象
  98. /// <summary>
  99. /// 上次的设备运行信息
  100. /// </summary>
  101. private string lineWorkingData1_OldStr = string.Empty;
  102. /// <summary>
  103. /// 设备报警字典-当前结果
  104. /// Dictionary<工位代码,List<报警信息>>
  105. /// </summary>
  106. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  107. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  108. #endregion 变量
  109. #region 窗体基础事件
  110. /// <summary>
  111. /// 初始化
  112. /// </summary>
  113. public Form_Home()
  114. {
  115. InitializeComponent();
  116. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  117. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  118. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  119. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  120. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  121. }
  122. /// <summary>
  123. /// 窗体加载事件
  124. /// </summary>
  125. private void Form_Home_Load(object sender, EventArgs e)
  126. {
  127. try
  128. {
  129. AddMessage(LogType.Info, "开始初始化程序");
  130. InitalDicAlarm(); // 实例化报警字典
  131. //组建plc对象字典
  132. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  133. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  134. if (GlobalContext.IsUsePLC1)
  135. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  136. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  137. if (GlobalContext.IsUsePLC2)
  138. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  139. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  140. if (GlobalContext.IsUsePLC3)
  141. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  142. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  143. if (GlobalContext.IsUsePLC4)
  144. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  145. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  146. if (GlobalContext.IsUsePLC5)
  147. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  148. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  149. if (GlobalContext.IsUsePLC6)
  150. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  151. if (GlobalContext.IsUsePLC7)
  152. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  153. if (GlobalContext.IsUsePLC8)
  154. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  155. if (GlobalContext.IsUsePLC9)
  156. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  157. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  158. {
  159. if (plcEIP != null)
  160. {
  161. try
  162. {
  163. (int, string) result = plcEIP.Connect();
  164. }
  165. catch (Exception ex)
  166. {
  167. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  168. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  169. }
  170. }
  171. }
  172. /*
  173. //plc1Alarm.Connect();
  174. foreach (ModbusClientHelper modbusClient in Funs.Values)
  175. {
  176. if (modbusClient != null)
  177. {
  178. try
  179. {
  180. modbusClient.Connect();
  181. }
  182. catch (Exception ex)
  183. {
  184. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  185. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  186. }
  187. }
  188. }
  189. */
  190. // 采集任务
  191. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  192. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  193. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  194. if (GlobalContext.IsUsePLC1)
  195. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  196. if (GlobalContext.IsUsePLC2)
  197. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  198. if (GlobalContext.IsUsePLC3)
  199. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  200. if (GlobalContext.IsUsePLC4)
  201. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  202. if (GlobalContext.IsUsePLC5)
  203. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  204. if (GlobalContext.IsUsePLC6)
  205. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  206. if (GlobalContext.IsUsePLC7)
  207. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  208. if (GlobalContext.IsUsePLC8)
  209. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  210. if (GlobalContext.IsUsePLC9)
  211. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  212. #region 初始化
  213. try
  214. {
  215. // 开启边线MES(绑定/查询数据)
  216. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  217. //if (mesRoute == 0)
  218. //{
  219. // //picMESStatus.Image = imageListState.Images[1];
  220. // //GlobalContext.MESIsConnect = true;
  221. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  222. //}
  223. //else
  224. //{
  225. // //picMESStatus.Image = imageListState.Images[0];
  226. // //GlobalContext.MESIsConnect = false;
  227. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  228. //}
  229. // 开启MES(Http)
  230. if (GlobalContext.IsUseMES)
  231. {
  232. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  233. if (mesret)
  234. {
  235. picMESStatus.Image = imageListState.Images[1];
  236. GlobalContext.MESIsConnect = true;
  237. AddMessage(LogType.Info, "小米MES初始连接成功!");
  238. }
  239. else
  240. {
  241. picMESStatus.Image = imageListState.Images[0];
  242. GlobalContext.MESIsConnect = false;
  243. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  244. }
  245. }
  246. // 开启IOT(MQTT)
  247. if (GlobalContext.IsUseIot)
  248. {
  249. string addr = GlobalContext.MQTTServerHost;
  250. int port = GlobalContext.MQTTServerPort;
  251. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer(addr, port, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  252. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  253. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  254. {
  255. picIot.Image = imageListState.Images[1];
  256. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  257. XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  258. }
  259. else
  260. {
  261. picIot.Image = imageListState.Images[0];
  262. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  263. }
  264. }
  265. // 开启AGV(Http与MQTT)
  266. if (GlobalContext.IsUseAGV)
  267. {
  268. // AGV HTTP
  269. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  270. if (mesret1)
  271. {
  272. picAgvHttp.Image = imageListState.Images[1];
  273. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  274. }
  275. else
  276. {
  277. picAgvHttp.Image = imageListState.Images[0];
  278. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  279. }
  280. string agvMqttIp = GlobalContext.MQTTServerHost;
  281. int agvMqttPort = GlobalContext.MQTTServerPort;
  282. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  283. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  284. // AGV MQTT
  285. if (result_MQTT.ResultCode == 1)
  286. {
  287. picAgvMqtt.Image = imageListState.Images[1];
  288. GlobalContext.AGVMQTTIsConnect = true;
  289. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  290. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  291. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  292. }
  293. else
  294. {
  295. picAgvMqtt.Image = imageListState.Images[0];
  296. GlobalContext.AGVMQTTIsConnect = false;
  297. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  298. }
  299. }
  300. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  301. Task.Run(MonitorMESConnect);
  302. // 查询PLC连接状态
  303. foreach (int plcNo in FunsEip.Keys)
  304. {
  305. bool connected = FunsEip[plcNo].IsConnected;
  306. if (connected)
  307. {
  308. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  309. AddMessage(LogType.Info, msg);
  310. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  311. }
  312. else
  313. {
  314. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  315. AddMessage(LogType.Info, msg);
  316. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  317. }
  318. }
  319. // PLC4时 初始化扫码器TCP
  320. //if (GlobalContext.IsUsePLC4)
  321. // HpTCPClientInit();
  322. // 开启PLC的业务处理线程-监听PLC点位+状态
  323. foreach (Task task in TaskReadProcess)
  324. {
  325. if (task != null)
  326. task.Start();
  327. }
  328. //// 开启“获取线体报警数据”的线程
  329. //TaskReadAlarm.Start();
  330. ////下传MES信息给1工位(先判断下plc对象数量)
  331. //if (Funs.Count > 1)
  332. // DownLoadProductInfo(1);
  333. AddMessage(LogType.Info, "程序初始化完成");
  334. }
  335. catch (Exception ex)
  336. {
  337. string str = ex.StackTrace;
  338. this.BeginInvoke(new Action(() =>
  339. {
  340. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  341. }));
  342. }
  343. #endregion
  344. }
  345. catch (Exception ex)
  346. {
  347. string str = ex.StackTrace;
  348. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  349. if (ex.Message != null && ex.Message.Contains("timed out"))
  350. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  351. else
  352. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  353. }
  354. }
  355. /// <summary>
  356. /// 窗体关闭事件
  357. /// </summary>
  358. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  359. {
  360. Closed2();
  361. }
  362. public void Closed2()
  363. {
  364. try
  365. {
  366. IsRun = false;
  367. Thread.Sleep(IntervalReadPLC);
  368. // 断开TCP
  369. int count = _HPSocket_TcpClients.Count();
  370. for (int i = 0; i < count; i++)
  371. {
  372. try
  373. {
  374. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  375. {
  376. _HPSocket_TcpClients[i].Stop();
  377. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  378. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  379. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  380. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  381. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  382. }
  383. }
  384. catch { }
  385. }
  386. // 关闭Iot
  387. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  388. // 关闭AGV Mqtt
  389. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  390. }
  391. catch { }
  392. }
  393. #endregion 窗体基础事件
  394. #region 监控MES状态
  395. /// <summary>
  396. /// 监控MES连接状态
  397. /// </summary>
  398. private void MonitorMESConnect()
  399. {
  400. while (IsRun) // 运行被控线程
  401. {
  402. try
  403. {
  404. // 开启MES(Http)
  405. if (GlobalContext.IsUseMES)
  406. {
  407. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  408. if (mesret)
  409. {
  410. picMESStatus.Image = imageListState.Images[1];
  411. GlobalContext.MESIsConnect = true;
  412. }
  413. else
  414. {
  415. picMESStatus.Image = imageListState.Images[0];
  416. GlobalContext.MESIsConnect = false;
  417. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  418. }
  419. }
  420. // 开启IOT(MQTT)
  421. if (GlobalContext.IsUseIot)
  422. {
  423. bool iIot = XiaomiMqttClient.IsOpen;
  424. if (iIot)
  425. picIot.Image = imageListState.Images[1];
  426. else
  427. {
  428. picIot.Image = imageListState.Images[0];
  429. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  430. }
  431. }
  432. // 开启AGV(Http与MQTT)
  433. if (GlobalContext.IsUseAGV)
  434. {
  435. // AGV Http
  436. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  437. if (mesret1)
  438. picAgvHttp.Image = imageListState.Images[1];
  439. else
  440. {
  441. picAgvHttp.Image = imageListState.Images[0];
  442. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  443. }
  444. // AGV MQTT
  445. if (GlobalContext.AGVMQTTIsConnect)
  446. picAgvMqtt.Image = imageListState.Images[1];
  447. else
  448. {
  449. picAgvMqtt.Image = imageListState.Images[0];
  450. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  451. }
  452. }
  453. }
  454. catch (Exception ex)
  455. {
  456. string str = ex.StackTrace;
  457. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  458. }
  459. Thread.Sleep(IntervalMonitorMES);
  460. }
  461. }
  462. #endregion 监控MES连接状态
  463. #region 采集设备状态、运行数据、报警数据
  464. /// <summary>
  465. /// 请求设备状态 5000
  466. /// </summary>
  467. /// <param name="no">1</param>
  468. /// <param name="stationNameStr"></param>
  469. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  470. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  471. {
  472. try
  473. {
  474. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  475. {
  476. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  477. return result;
  478. }
  479. else
  480. {
  481. return 0;
  482. }
  483. }
  484. catch (Exception ex)
  485. {
  486. string str = ex.StackTrace;
  487. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  488. return 0;
  489. }
  490. }
  491. /// <summary>
  492. /// 检查是否可采集点检数据 - 不取新值
  493. /// 5000不为1时可点检
  494. /// </summary>
  495. /// <returns></returns>
  496. public bool CheckCanSpotcheck1(int deviceState)
  497. {
  498. //return true;
  499. //D5000 = 1,代表设备控制状态处于运行状态
  500. //D5000 = 2, 代表设备控制状态处于故障状态
  501. //D5000 = 3,代表设备控制状态处于缺料状态
  502. //D5000 = 4, 代表设备控制状态处于待机状态
  503. //D5000 = 5,代表设备控制状态处于维修状态
  504. return deviceState != 1;
  505. }
  506. /// <summary>
  507. /// 检查是否可采集产品数据 - 不取新值
  508. /// </summary>
  509. /// <returns></returns>
  510. public bool CheckCanCollData(int deviceState)
  511. {
  512. return deviceState == 0; // 点检时该值不为0
  513. }
  514. /// <summary>
  515. /// 获取设备报警数据与获取设备运行信息
  516. /// </summary>
  517. private async void ReadAlarmAllPLC()
  518. {
  519. // [S1] Tray盘上料装备(板测)
  520. // [S2] FCT(板测)
  521. // [S3] 值板机
  522. // [S4] 取放桁架
  523. // [S5] Tray盘下料装备
  524. /// 上位机心跳
  525. /// 获取设备报警数据与状态信息
  526. string stationNameStr = "获取设备报警数据与状态信息";
  527. while (IsRun)
  528. {
  529. try
  530. {
  531. if (!GlobalContext._IsCon_plc1Alarm)
  532. {
  533. UpdatePLCMonitor(1, -2, 0);
  534. continue;
  535. }
  536. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  537. {
  538. DateTime dtNow = DateTime.Now;
  539. #region 获取设备运行信息
  540. try
  541. {
  542. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  543. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  544. lineWorkingData1.LineName = GlobalContext.LineCode;
  545. //
  546. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  547. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  548. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  549. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  550. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  551. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  552. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  553. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  554. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  555. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  556. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  557. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  558. lineWorkingData1.CreateTime = DateTime.Now;
  559. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  560. // UI展示-展示到设备状态页
  561. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  562. {
  563. // 查询数据库最新一条数据,确定是不是更新
  564. string qSql = @"SELECT top(1) [GUID]
  565. ,[LineName]
  566. ,[BootTimeLong]
  567. ,[NormalTimeLong]
  568. ,[StandbyTimeLong]
  569. ,[FaultTimeLong]
  570. ,[MaterialShortageTimeLong]
  571. ,[MaintenanceTimeLong]
  572. ,[FaultNumber]
  573. ,[OutputNumber]
  574. ,[QualifiedNumber]
  575. ,[QualifiedRate]
  576. ,[DesignRhythm]
  577. ,[RealityRhythm]
  578. ,[CreateTime]
  579. FROM [LineWorkingData]
  580. where [CreateTime] > '{0}'
  581. and [LineName]='{1}'
  582. order by [CreateTime] desc
  583. ";
  584. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  585. var ds = SQLHelper_New.Query(qSql, null);
  586. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  587. {
  588. var dataDBlast = new LineWorkingData_ThisTime();
  589. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  590. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  591. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  592. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  593. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  594. {
  595. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  596. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  597. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  598. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  599. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  600. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  601. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  602. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  603. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  604. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  605. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  606. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  607. string usql = dataDBlast.ToStringUpdate();
  608. SQLHelper_New.ExecuteSQL(usql, null);
  609. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  610. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  611. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  612. }
  613. }
  614. else
  615. {
  616. // 插入
  617. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  618. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  619. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  620. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  621. }
  622. }
  623. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  624. {
  625. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  626. //// 本次开机设备运行情况
  627. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  628. //Task.Run(() =>
  629. //{
  630. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  631. // {
  632. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  633. // }
  634. //});
  635. // 本日设备运行情况
  636. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  637. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  638. {
  639. // 更新
  640. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  641. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  642. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  643. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  644. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  645. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  646. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  647. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  648. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  649. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  650. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  651. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  652. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  653. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  654. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  655. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  656. }
  657. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  658. {
  659. // 插入
  660. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  661. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  662. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  663. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  664. }
  665. await Task.Run(() =>
  666. {
  667. try
  668. {
  669. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  670. {
  671. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  672. }
  673. }
  674. catch { }
  675. });
  676. }
  677. }
  678. catch (Exception ex)
  679. {
  680. string str = ex.StackTrace;
  681. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  682. }
  683. #endregion 获取设备运行信息
  684. #region 报警数据
  685. try
  686. {
  687. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  688. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  689. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  690. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  691. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  692. {
  693. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  694. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  695. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  696. {
  697. isNeedUpdUI = true; // 需要更新历史报警UI信息
  698. // 记录
  699. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  700. switch (dicAlarms_Cur_PLC1[i].是否报警)
  701. {
  702. case true: // 报警
  703. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  704. {
  705. GUID = Guid.NewGuid().ToString(),
  706. LineName = GlobalContext.LineCode, // 线体
  707. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  708. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  709. StartTime = dtNow // 开始时间
  710. };
  711. // 传输到页面
  712. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  713. {
  714. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  715. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  716. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  717. 开始时间 = dtNow
  718. });
  719. // 新增到数据库
  720. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  721. SaveAlarmDataByDB(stationNameStr, data1, false);
  722. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  723. break;
  724. case false: // 消除报警
  725. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  726. {
  727. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  728. {
  729. GUID = Guid.NewGuid().ToString(),
  730. LineName = GlobalContext.LineCode, // 线体
  731. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  732. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  733. StartTime = dtNow, // 开始时间
  734. EndTime = dtNow, // 开始时间
  735. PersistTime = 1, // 耗时1s
  736. };
  737. // 新增
  738. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  739. SaveAlarmDataByDB(stationNameStr, data2, false);
  740. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  741. }
  742. else
  743. {
  744. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  745. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  746. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  747. // 修改
  748. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  749. SaveAlarmDataByDB(stationNameStr, data3, true);
  750. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  751. }
  752. break;
  753. default:
  754. break;
  755. }
  756. }
  757. }
  758. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  759. // 有新报警则更新
  760. if (isNeedUpdUI)
  761. {
  762. // UI展示 - 展示到设备状态页
  763. await Task.Run(() =>
  764. {
  765. try
  766. {
  767. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  768. {
  769. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  770. if (Form_Main.formDevAlarm.Visible)
  771. {
  772. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  773. }
  774. }
  775. }
  776. catch { }
  777. });
  778. }
  779. }
  780. catch (Exception ex)
  781. {
  782. string str = ex.StackTrace;
  783. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  784. }
  785. #endregion 报警数据
  786. UpdatePLCMonitor(1, -2, 1);
  787. }
  788. else
  789. {
  790. UpdatePLCMonitor(1, -2, 0);
  791. }
  792. }
  793. catch (Exception ex)
  794. {
  795. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  796. }
  797. Thread.Sleep(IntervalAlarm);
  798. }
  799. }
  800. #endregion 轮询PLC
  801. #region 下发订单信息
  802. ///// <summary>
  803. ///// 壳体上料(下发工单)的交互逻辑
  804. ///// </summary>
  805. ///// <param name="no"></param>
  806. ///// <exception cref="NotImplementedException"></exception>
  807. //private void ReadStation_DownOrderInfo(int plcNo)
  808. //{
  809. // // [S1] Tray盘上料装备(板测)
  810. // // [S2] FCT(板测)
  811. // // [S3] 值板机
  812. // // [S4] 取放桁架
  813. // // [S5] Tray盘下料装备
  814. // /// 上位机心跳
  815. // /// 获取设备报警数据与状态信息
  816. // string stationNameStr = "[S0]壳体上料";
  817. // while (IsRun)
  818. // {
  819. // try
  820. // {
  821. // if (!GlobalContext._IsCon_Funs1)
  822. // {
  823. // UpdatePLCMonitor(plcNo, 0);
  824. // continue;
  825. // }
  826. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  827. // {
  828. // #region 壳体上料(下发工单)
  829. // try
  830. // {
  831. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  832. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  833. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  834. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  835. // // 重置数据和信号
  836. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  837. // {
  838. // // 清空写给PLC的数据
  839. // int[] i497 = new int[1] { 0 };
  840. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  841. // // MES_Flag重置为0
  842. // int[] i500 = new int[1] { 0 };
  843. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  844. // }
  845. // }
  846. // catch (Exception ex)
  847. // {
  848. // string str = ex.StackTrace;
  849. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  850. // }
  851. // #endregion 壳体上料(下发工单)
  852. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  853. // }
  854. // else
  855. // {
  856. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  857. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  858. //
  859. // Funs[plcNo].Connect();
  860. // }
  861. // }
  862. // catch (Exception ex)
  863. // {
  864. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  865. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  866. //
  867. // Funs[plcNo].ReConnect();
  868. // }
  869. // Thread.Sleep(IntervalReadPLC);
  870. // }
  871. //}
  872. ///// <summary>
  873. ///// 下发订单信息到PLC
  874. ///// </summary>
  875. ///// <param name="no">PLC编号</param>
  876. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  877. //{
  878. // try
  879. // {
  880. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  881. // {
  882. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  883. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  884. // }
  885. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  886. // }
  887. // catch (Exception ex)
  888. // {
  889. // string str = ex.StackTrace;
  890. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  891. // }
  892. //}
  893. /// <summary>
  894. /// 下发清料信号
  895. /// </summary>
  896. /// <param name="no">PLC编号</param>
  897. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  898. {
  899. try
  900. {
  901. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  902. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  903. return true;
  904. }
  905. catch (Exception ex)
  906. {
  907. string str = ex.StackTrace;
  908. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  909. return false;
  910. }
  911. }
  912. #endregion 下发订单信息
  913. #region Xiaomi 贲流
  914. #region 公共方法
  915. private static bool ProgressState = false;
  916. private static readonly object lockObj = new object(); // 锁对象
  917. private static bool isCollectingFlagLeft;
  918. private static bool isCollectingFlagRight;
  919. /// <summary>
  920. /// float[]转为string
  921. /// </summary>
  922. public string FloatArrayToString(float[] nScrewResults)
  923. {
  924. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  925. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  926. }
  927. /// <summary>
  928. /// short[]转为string
  929. /// </summary>
  930. public string ShortArrayToString(short[] nScrewResults)
  931. {
  932. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  933. return string.Join(",", nScrewResults);
  934. }
  935. /// <summary>
  936. /// 写入PLC重复三次
  937. /// </summary>
  938. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  939. {
  940. int i = 0;
  941. int nRet = 0;
  942. string strRet = "";
  943. try
  944. {
  945. while (i < 3) // 最多上传三次
  946. {
  947. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  948. if (nRet == 0) //成功
  949. {
  950. break;
  951. }
  952. else
  953. {
  954. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  955. i++;
  956. }
  957. }
  958. return (nRet, strRet);
  959. }
  960. catch (Exception ex)
  961. {
  962. return (1, ex.Message);
  963. }
  964. }
  965. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  966. {
  967. try
  968. {
  969. // 获取当前日期
  970. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  971. // 构建保存路径
  972. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  973. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  974. // 确保目录存在
  975. Directory.CreateDirectory(savePath);
  976. // 文件名
  977. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  978. string filePath = Path.Combine(savePath, fileName);
  979. // 确保不会超出数组长度,只取前14个或数组的实际长度
  980. int count = Math.Min(14, fScrewTimes.Length);
  981. using (StreamWriter sw = new StreamWriter(filePath))
  982. {
  983. for (int i = 0; i < count; i++)
  984. {
  985. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  986. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  987. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  988. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  989. sw.WriteLine(); // 空行分隔不同螺丝的信息
  990. }
  991. }
  992. return (0, "");
  993. }
  994. catch (Exception ex)
  995. {
  996. return (1, ex.Message);
  997. }
  998. }
  999. /// <summary>
  1000. /// 调用进站接口并保存进站数据
  1001. /// </summary>
  1002. /// <param name="stationNameStr">工站信息</param>
  1003. /// <param name="workorder_code">工单号</param>
  1004. /// <param name="mtltmrk">型号(物料号)</param>
  1005. /// <param name="sn">产品SN</param>
  1006. /// <param name="items">进站数据</param>
  1007. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1008. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1009. {
  1010. int result = 0;
  1011. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1012. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1013. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1014. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1015. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1016. inRequest_Body.unitSn = sn; // 产品SN
  1017. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1018. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1019. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1020. StationIn stationIn = new StationIn()
  1021. {
  1022. Workorder_code = workorder_code, // 车间订单号
  1023. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1024. Sn = sn, // SN
  1025. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1026. Parameter_values = items, // 进站数据
  1027. Write_user = inRequest_Body.userId, // 员工Id
  1028. Test_time = inRequest_Body.clientTime // 进站时间
  1029. };
  1030. // 本地数据
  1031. string sql = stationIn.ToStringInsert(0);
  1032. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1033. result = ret == "成功" ? 1 : 6;
  1034. //await Task.Delay(200);
  1035. // 上传MES
  1036. if (GlobalContext.IsSendStationIn)
  1037. {
  1038. try
  1039. {
  1040. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1041. string mesRet = string.Empty;
  1042. int i = 0;
  1043. while (i < 2) // 1009会多次尝试上传
  1044. {
  1045. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1046. if (response != null && response.header.code == "200")
  1047. break;
  1048. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1049. i++;
  1050. i++;
  1051. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1052. // 记录失败原因
  1053. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1054. }
  1055. if (response?.header?.code == "200")
  1056. {
  1057. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1058. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1059. result = ret_Upd == "成功" ? 1 : 6;
  1060. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1061. }
  1062. else
  1063. {
  1064. result = 5;
  1065. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1066. }
  1067. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1068. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1069. }
  1070. catch (Exception ex)
  1071. {
  1072. result = 6;
  1073. string str = ex.StackTrace;
  1074. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1075. }
  1076. }
  1077. return result;
  1078. }
  1079. /// <summary>
  1080. /// 选择如何记录出站数据
  1081. /// </summary>
  1082. /// <param name="items">出站数据</param>
  1083. /// <param name="equipmentCode">设备编号</param>
  1084. /// <param name="processItem">测试项目</param>
  1085. /// <param name="workorder_code">车间订单号</param>
  1086. /// <param name="batch_num">批次号</param>
  1087. /// <param name="mtltmrk">型号</param>
  1088. /// <param name="proDate">日期</param>
  1089. /// <param name="supplierCode">供应商代码</param>
  1090. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1091. /// <returns>上传成功时返回1;失败返回0</returns>
  1092. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1093. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1094. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode)
  1095. {
  1096. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1097. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode);
  1098. }
  1099. /// <summary>
  1100. /// 添加出站数据(提交到MES+本地保存到数据库)
  1101. /// </summary>
  1102. /// <param name="items">出站数据</param>
  1103. /// <param name="equipmentCode">设备编号</param>
  1104. /// <param name="processItem">测试项目</param>
  1105. /// <param name="workorder_code">车间订单号</param>
  1106. /// <param name="batch_num">批次号</param>
  1107. /// <param name="mtltmrk">型号</param>
  1108. /// <param name="proDate">日期</param>
  1109. /// <param name="supplierCode">供应商代码</param>
  1110. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1111. /// <returns>上传成功时返回1;失败返回0</returns>
  1112. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1113. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1114. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode)
  1115. {
  1116. int upload = 0;
  1117. int result = 0;
  1118. ProcessData processData = new ProcessData()
  1119. {
  1120. Equipment_code = equipmentCode,
  1121. Workorder_code = workorder_code,
  1122. Batch_number = batch_num,
  1123. Sn = sn, // SN
  1124. Testitem = processItem,
  1125. Parameter_values = items,
  1126. Write_user = GlobalContext.CurrentUser,
  1127. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1128. };
  1129. // 本地数据
  1130. string sql = processData.ToStringInsert(upload);
  1131. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1132. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1133. // 上传MES
  1134. if (GlobalContext.IsSendProcessData)
  1135. {
  1136. try
  1137. {
  1138. string id = processData.ID.Copy();
  1139. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1140. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1141. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1142. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1143. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1144. outRequest_Body.unitSn = sn; // 产品SN
  1145. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1146. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1147. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1148. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1149. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1150. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1151. if (!string.IsNullOrEmpty(partBarcode))
  1152. {
  1153. outRequest_Body.unitData.keyMaterial.Add(
  1154. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1155. {
  1156. bindSort = 1,
  1157. materialSn = partBarcode
  1158. }); // 设备数据 - 部件码
  1159. }
  1160. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1161. if (GlobalContext.IsSendProcessData)
  1162. {
  1163. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1164. string mesRet = string.Empty;
  1165. int i = 0;
  1166. while (i < 2) // 1009会多次尝试上传
  1167. {
  1168. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1169. if (response != null && response.header.code == "200")
  1170. break;
  1171. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1172. i++;
  1173. i++;
  1174. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1175. // 记录失败原因
  1176. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1177. }
  1178. if (response?.header?.code == "200")
  1179. {
  1180. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1181. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1182. result = 1;
  1183. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1184. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1185. }
  1186. else
  1187. {
  1188. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1189. }
  1190. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1191. JsonConvert.SerializeObject(response), id);
  1192. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1193. }
  1194. }
  1195. catch (Exception ex)
  1196. {
  1197. string str = ex.StackTrace;
  1198. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1199. }
  1200. }
  1201. return result;
  1202. }
  1203. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1204. //{
  1205. // Stopwatch stopwatch = new Stopwatch();
  1206. // stopwatch.Start();
  1207. // try
  1208. // {
  1209. // // 初始化 AtlasScrew 实例
  1210. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1211. // atlasScrew1.Initial();
  1212. // // 存储结果的列表
  1213. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1214. // // 存储角度和扭力的字符串列表
  1215. // List<string> angleStrs = new List<string>();
  1216. // List<string> torqueStrs = new List<string>();
  1217. // // 上一次获取的数据
  1218. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1219. // while (isExitAtlasLeft) // 检查是否收集数据
  1220. // {
  1221. // // 获取当前数据
  1222. // var currentResult = atlasScrew1.GetResults();
  1223. // // 判断是否为新数据
  1224. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1225. // {
  1226. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1227. // // 更新角度和扭力的字符串列表
  1228. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1229. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1230. // // 计算角度、扭力、起始扭力和最大扭力
  1231. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1232. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1233. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1234. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1235. // // 将新数据添加到结果列表
  1236. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1237. // // 更新上一次获取的数据
  1238. // lastResult = currentResult;
  1239. // }
  1240. // // 等待一段时间后再次检查
  1241. // Thread.Sleep(20); // 轮询间隔时间
  1242. // // 如果触发了出站,则退出循环
  1243. // if (!isExitAtlasLeft)
  1244. // {
  1245. // break;
  1246. // }
  1247. // }
  1248. // // 生成文件名
  1249. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1250. // // 写入数据到文件
  1251. // using (StreamWriter writer = new StreamWriter(fileName))
  1252. // {
  1253. // // 写入标题行
  1254. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1255. // // 写入每一行数据
  1256. // foreach (var result in results)
  1257. // {
  1258. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1259. // }
  1260. // }
  1261. // stopwatch.Stop();
  1262. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1263. // }
  1264. // catch (Exception ex)
  1265. // {
  1266. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1267. // }
  1268. // finally
  1269. // {
  1270. // // 重置标志变量
  1271. // isExitAtlasLeft = false;
  1272. // }
  1273. //}
  1274. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1275. //{
  1276. // Stopwatch stopwatch = new Stopwatch();
  1277. // stopwatch.Start();
  1278. // try
  1279. // {
  1280. // // 初始化 AtlasScrew 实例
  1281. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1282. // atlasScrew2.Initial();
  1283. // // 存储结果的列表
  1284. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1285. // // 上一次获取的数据
  1286. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1287. // while (isExitAtlasRight) // 检查是否收集数据
  1288. // {
  1289. // // 获取当前数据
  1290. // var currentResult = atlasScrew2.GetResults();
  1291. // // 判断是否为新数据
  1292. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1293. // {
  1294. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1295. // // 将新数据写入PLC
  1296. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1297. // // 将新数据添加到结果列表
  1298. // results.Add(currentResult);
  1299. // // 更新上一次获取的数据
  1300. // lastResult = currentResult;
  1301. // }
  1302. // // 等待一段时间后再次检查
  1303. // Thread.Sleep(20); // 轮询间隔时间
  1304. // // 如果触发了出站,则退出循环
  1305. // if (!isExitAtlasRight)
  1306. // {
  1307. // break;
  1308. // }
  1309. // }
  1310. // // 将所有数据写入文件
  1311. // //WriteDataToFile(sn, direction, results);
  1312. // stopwatch.Stop();
  1313. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1314. // }
  1315. // catch (Exception ex)
  1316. // {
  1317. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1318. // }
  1319. // finally
  1320. // {
  1321. // // 重置标志变量
  1322. // isExitAtlasRight = false;
  1323. // }
  1324. //}
  1325. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1326. {
  1327. Stopwatch stopwatch = new Stopwatch();
  1328. stopwatch.Start();
  1329. int nRet = 0;
  1330. string strRet = "";
  1331. try
  1332. {
  1333. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1334. while (isCollectingFlagLeft)
  1335. {
  1336. // 从缓存中获取所有未处理的数据
  1337. var cachedData = atlasScrew.GetCachedDataLeft();
  1338. foreach (var currentResult in cachedData)
  1339. {
  1340. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1341. {
  1342. continue; // 跳过无效数据
  1343. }
  1344. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1345. // 写入PLC
  1346. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1347. {
  1348. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1349. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1350. };
  1351. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1352. if (nRet != 0)
  1353. {
  1354. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1355. }
  1356. else
  1357. {
  1358. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1359. }
  1360. // 构建保存路径
  1361. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1362. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1363. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1364. Directory.CreateDirectory(savePath); // 确保目录存在
  1365. // 构建文件名(以 SN + 序号命名)
  1366. string fileName = $"{sn}_{fileCounter}.txt";
  1367. string filePath = Path.Combine(savePath, fileName);
  1368. // 写入文件
  1369. using (StreamWriter writer = new StreamWriter(filePath))
  1370. {
  1371. writer.WriteLine("精度, 扭力");
  1372. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1373. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1374. {
  1375. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1376. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1377. writer.WriteLine($"{precision}, {torque}");
  1378. }
  1379. }
  1380. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1381. // 增加文件计数器
  1382. fileCounter++;
  1383. }
  1384. // 如果没有更多数据,则短暂休眠以节省资源
  1385. if (!cachedData.Any())
  1386. {
  1387. Thread.Sleep(10); // 根据需要调整休眠时间
  1388. }
  1389. // 如果触发了出站,则退出循环
  1390. if (!isCollectingFlagLeft)
  1391. {
  1392. break;
  1393. }
  1394. }
  1395. stopwatch.Stop();
  1396. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1397. }
  1398. catch (Exception ex)
  1399. {
  1400. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1401. }
  1402. finally
  1403. {
  1404. isCollectingFlagLeft = false;
  1405. }
  1406. }
  1407. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1408. {
  1409. Stopwatch stopwatch = new Stopwatch();
  1410. stopwatch.Start();
  1411. int nRet = 0;
  1412. string strRet = "";
  1413. try
  1414. {
  1415. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1416. while (isCollectingFlagRight)
  1417. {
  1418. // 从缓存中获取所有未处理的数据
  1419. var cachedData = atlasScrew.GetCachedDataLeft();
  1420. foreach (var currentResult in cachedData)
  1421. {
  1422. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1423. {
  1424. continue; // 跳过无效数据
  1425. }
  1426. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1427. // 写入PLC
  1428. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1429. {
  1430. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1431. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1432. };
  1433. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1434. if (nRet != 0)
  1435. {
  1436. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1437. }
  1438. else
  1439. {
  1440. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1441. }
  1442. // 构建保存路径
  1443. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1444. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1445. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1446. Directory.CreateDirectory(savePath); // 确保目录存在
  1447. // 构建文件名(以 SN + 序号命名)
  1448. string fileName = $"{sn}_{fileCounter}.txt";
  1449. string filePath = Path.Combine(savePath, fileName);
  1450. // 写入文件
  1451. using (StreamWriter writer = new StreamWriter(filePath))
  1452. {
  1453. writer.WriteLine("精度, 扭力");
  1454. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1455. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1456. {
  1457. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1458. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1459. writer.WriteLine($"{precision}, {torque}");
  1460. }
  1461. }
  1462. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1463. // 增加文件计数器
  1464. fileCounter++;
  1465. }
  1466. // 如果没有更多数据,则短暂休眠以节省资源
  1467. if (!cachedData.Any())
  1468. {
  1469. Thread.Sleep(10); // 根据需要调整休眠时间
  1470. }
  1471. // 如果触发了出站,则退出循环
  1472. if (!isCollectingFlagRight)
  1473. {
  1474. break;
  1475. }
  1476. }
  1477. stopwatch.Stop();
  1478. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1479. }
  1480. catch (Exception ex)
  1481. {
  1482. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1483. }
  1484. finally
  1485. {
  1486. isCollectingFlagRight = false;
  1487. }
  1488. }
  1489. #endregion
  1490. #region S1
  1491. /// <summary>
  1492. /// [S1] 壳体清洁上料装备
  1493. /// </summary>
  1494. /// <param name="plcNo">PLC编号</param>
  1495. private void ReadStation_S1(int plcNo)
  1496. {
  1497. string stationCode = "[OP10]";
  1498. string stationName = "壳体清洁上料";
  1499. string stationNameStr = stationCode + stationName;
  1500. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1501. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1502. string tagAgvCommName = "agvCommFrmPC";
  1503. string tagBarsetName = "BarcodeSet";
  1504. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1505. (int, string) result;
  1506. while (true)
  1507. {
  1508. try
  1509. {
  1510. if (!GlobalContext._IsCon_Funs1)
  1511. {
  1512. UpdatePLCMonitor(1, plcNo, 0);
  1513. continue;
  1514. }
  1515. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1516. {
  1517. Stopwatch stopwatch1 = new Stopwatch();
  1518. Stopwatch stopwatch2 = new Stopwatch();
  1519. stopwatch1.Start();
  1520. stopwatch2.Start();
  1521. #region 一次性读取所有数据
  1522. // 一次性读取所有数据
  1523. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1524. if (result.Item1 != 0)
  1525. {
  1526. //richTextBox1.AppendText("\n" + strRet);
  1527. }
  1528. else
  1529. {
  1530. //richTextBox1.AppendText("\n" + "读取成功");
  1531. }
  1532. #endregion 一次性读取所有数据
  1533. stopwatch2.Stop();
  1534. #region 进站
  1535. try
  1536. {
  1537. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1538. {
  1539. lock (lockObj)
  1540. {
  1541. if (!ProgressState)
  1542. {
  1543. ProgressState = true;
  1544. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1545. }
  1546. }
  1547. }
  1548. }
  1549. catch (Exception ex)
  1550. {
  1551. ProgressState = false;
  1552. string str = ex.StackTrace;
  1553. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1554. }
  1555. #endregion 进站
  1556. #region 出站
  1557. try
  1558. {
  1559. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1560. {
  1561. lock (lockObj)
  1562. {
  1563. if (!ProgressState)
  1564. {
  1565. ProgressState = true;
  1566. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1567. }
  1568. }
  1569. }
  1570. }
  1571. catch (Exception ex)
  1572. {
  1573. ProgressState = false;
  1574. string str = ex.StackTrace;
  1575. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1576. }
  1577. #endregion 进站
  1578. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1579. stopwatch1.Stop();
  1580. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1581. }
  1582. else
  1583. {
  1584. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1585. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1586. FunsEip[plcNo].Connect(); // 重连
  1587. }
  1588. }
  1589. catch (Exception ex)
  1590. {
  1591. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1592. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1593. }
  1594. Thread.Sleep(IntervalReadPLC);
  1595. }
  1596. }
  1597. /// <summary>
  1598. /// [S1] 壳体清洁上料 - 进站
  1599. /// </summary>
  1600. /// <param name="plcNo">PLC编号</param>
  1601. /// <param name="stationNameStr">工站全称</param>
  1602. /// <param name="stPLC_MesData"></param>
  1603. /// <param name="tagMesCommName"></param>
  1604. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1605. {
  1606. Stopwatch stopwatch1 = new Stopwatch();
  1607. Stopwatch stopwatch2 = new Stopwatch();
  1608. try
  1609. {
  1610. stopwatch1.Start();
  1611. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1612. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1613. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1614. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1615. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1616. if (string.IsNullOrEmpty(sn))
  1617. {
  1618. ProgressState = false;
  1619. return;
  1620. }
  1621. //正式生产就用PLC中取的
  1622. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1623. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1624. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1625. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1626. //绑定载具和产品
  1627. ResponseMessage message = new ResponseMessage();
  1628. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1629. if (message.result == false)
  1630. {
  1631. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1632. }
  1633. // 产品SN进站
  1634. List<TestItem> item = new List<TestItem>();
  1635. stopwatch2.Start();
  1636. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1637. stopwatch2.Stop();
  1638. //指令执行结果 1:OK 110:失败
  1639. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1640. //进站结果写入PLC
  1641. CommandFromPLC resultToPlC = new CommandFromPLC();
  1642. resultToPlC.cmd = 0;
  1643. resultToPlC.cmdParam = 0;
  1644. resultToPlC.cmdResult = mesResultFrmWeb;
  1645. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1646. }
  1647. catch (Exception ex)
  1648. {
  1649. string str = ex.StackTrace;
  1650. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1651. CommandFromPLC resultToPlC = new CommandFromPLC();
  1652. resultToPlC.cmd = 0;
  1653. resultToPlC.cmdParam = 0; //指令参数
  1654. resultToPlC.cmdResult = 110;
  1655. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1656. }
  1657. stopwatch1.Stop();
  1658. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1659. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1660. ProgressState = false;
  1661. }
  1662. /// <summary>
  1663. /// [S1] 壳体清洁上料 - 出站接口
  1664. /// </summary>
  1665. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1666. {
  1667. Stopwatch stopwatch1 = new Stopwatch();
  1668. Stopwatch stopwatch2 = new Stopwatch();
  1669. try
  1670. {
  1671. stopwatch1.Start();
  1672. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1673. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1674. string processItem = stationName; // 项目
  1675. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1676. string supplierCode = ""; // 供应商代码
  1677. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1678. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1679. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1680. string sn = string.Empty;
  1681. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1682. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1683. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1684. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1685. a1Result = 1;
  1686. bool pass = a1Result == 1;
  1687. //根据载具码获取产品码
  1688. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1689. if (string.IsNullOrEmpty(strProductBarcode))
  1690. {
  1691. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1692. }
  1693. sn = strProductBarcode;
  1694. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1695. List<TestItem> items = new List<TestItem>();
  1696. items.Add(new TestItem()
  1697. {
  1698. Parameter_name = "载具码",
  1699. Parameter_value = CarrierBarcode,
  1700. Parameter_unit = ""
  1701. });
  1702. items.Add(new TestItem()
  1703. {
  1704. Parameter_name = "产品码",
  1705. Parameter_value = sn,
  1706. Parameter_unit = ""
  1707. });
  1708. //出站接口
  1709. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1710. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1711. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1712. stopwatch2.Start();
  1713. //进站结果写入PLC
  1714. CommandFromPLC resultToPlC = new CommandFromPLC();
  1715. resultToPlC.cmd = 0;
  1716. resultToPlC.cmdParam = 0; //指令参数
  1717. resultToPlC.cmdResult = mesResultFrmWeb;
  1718. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1719. stopwatch2.Stop();
  1720. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1721. //保存PLC返回MES数据到本地
  1722. ResponseMessage message = new ResponseMessage();
  1723. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1724. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1725. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1726. stPLC_MesData.mesData.nRemainCount);
  1727. if (message.result == false)
  1728. {
  1729. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1730. }
  1731. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1732. }
  1733. catch (Exception ex)
  1734. {
  1735. stopwatch2.Start();
  1736. CommandFromPLC resultToPlC = new CommandFromPLC();
  1737. resultToPlC.cmd = 0;
  1738. resultToPlC.cmdParam = 0; //指令参数
  1739. resultToPlC.cmdResult = 110;
  1740. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1741. stopwatch2.Stop();
  1742. string str = ex.StackTrace;
  1743. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1744. }
  1745. stopwatch1.Stop();
  1746. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1747. ProgressState = false;
  1748. }
  1749. #endregion
  1750. #region S2
  1751. /// <summary>
  1752. /// [S2] 上盖板上料装备
  1753. /// </summary>
  1754. /// <param name="plcNo">PLC编号</param>
  1755. private void ReadStation_S2(int plcNo)
  1756. {
  1757. string stationCode = "[OP20]";
  1758. string stationName = "上盖板上料装备";
  1759. string stationNameStr = stationCode + stationName;
  1760. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1761. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1762. string tagAgvCommName = "agvCommFrmPC";
  1763. string tagBarsetName = "BarcodeSet";
  1764. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1765. (int, string) result;
  1766. while (true)
  1767. {
  1768. try
  1769. {
  1770. if (!GlobalContext._IsCon_Funs2)
  1771. {
  1772. UpdatePLCMonitor(1, plcNo, 0);
  1773. continue;
  1774. }
  1775. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1776. {
  1777. Stopwatch stopwatch1 = new Stopwatch();
  1778. Stopwatch stopwatch2 = new Stopwatch();
  1779. stopwatch1.Start();
  1780. stopwatch2.Start();
  1781. #region 一次性读取所有数据
  1782. // 一次性读取所有数据
  1783. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1784. if (result.Item1 != 0)
  1785. {
  1786. //richTextBox1.AppendText("\n" + strRet);
  1787. }
  1788. else
  1789. {
  1790. //richTextBox1.AppendText("\n" + "读取成功");
  1791. }
  1792. #endregion 一次性读取所有数据
  1793. stopwatch2.Stop();
  1794. #region 进站
  1795. try
  1796. {
  1797. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1798. {
  1799. lock (lockObj)
  1800. {
  1801. if (!ProgressState)
  1802. {
  1803. ProgressState = true;
  1804. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1805. }
  1806. }
  1807. }
  1808. }
  1809. catch (Exception ex)
  1810. {
  1811. ProgressState = false;
  1812. string str = ex.StackTrace;
  1813. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1814. }
  1815. #endregion 进站
  1816. #region 出站
  1817. try
  1818. {
  1819. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1820. {
  1821. lock (lockObj)
  1822. {
  1823. if (!ProgressState)
  1824. {
  1825. ProgressState = true;
  1826. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1827. }
  1828. }
  1829. }
  1830. }
  1831. catch (Exception ex)
  1832. {
  1833. ProgressState = false;
  1834. string str = ex.StackTrace;
  1835. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1836. }
  1837. #endregion 进站
  1838. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1839. stopwatch1.Stop();
  1840. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1841. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1842. }
  1843. else
  1844. {
  1845. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1846. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1847. FunsEip[plcNo].Connect();
  1848. }
  1849. }
  1850. catch (Exception ex)
  1851. {
  1852. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1853. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1854. //Funs[plcNo].ReConnect();
  1855. }
  1856. Thread.Sleep(IntervalReadPLC);
  1857. }
  1858. }
  1859. /// <summary>
  1860. /// [S2] 上盖板上料装备
  1861. /// </summary>
  1862. /// <param name="plcNo">PLC编号</param>
  1863. /// <param name="stationNameStr">工站全称</param>
  1864. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  1865. {
  1866. Stopwatch stopwatch1 = new Stopwatch();
  1867. Stopwatch stopwatch2 = new Stopwatch();
  1868. try
  1869. {
  1870. stopwatch1.Start();
  1871. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1872. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  1873. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1874. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  1875. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  1876. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  1877. //根据载具码获取产品码
  1878. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  1879. if (string.IsNullOrEmpty(strProductBarcode))
  1880. {
  1881. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1882. }
  1883. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  1884. //if (sn != strProductBarcode)
  1885. //{
  1886. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  1887. //}
  1888. sn = strProductBarcode;
  1889. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  1890. // 产品SN(物料码)校验
  1891. List<TestItem> item = new List<TestItem>();
  1892. stopwatch2.Start();
  1893. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1894. stopwatch2.Stop();
  1895. //指令执行结果 1:OK 110:失败
  1896. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1897. //进站结果写入PLC
  1898. CommandFromPLC resultToPlC = new CommandFromPLC();
  1899. resultToPlC.cmd = 0;
  1900. resultToPlC.cmdParam = 0; //指令参数
  1901. resultToPlC.cmdResult = mesResultFrmWeb;
  1902. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1903. }
  1904. catch (Exception ex)
  1905. {
  1906. string str = ex.StackTrace;
  1907. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1908. CommandFromPLC resultToPlC = new CommandFromPLC();
  1909. resultToPlC.cmd = 0;
  1910. resultToPlC.cmdParam = 0; //指令参数
  1911. resultToPlC.cmdResult = 110;
  1912. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1913. }
  1914. stopwatch1.Stop();
  1915. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1916. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1917. ProgressState = false;
  1918. }
  1919. /// <summary>
  1920. /// [S2] 上盖板上料装备 - 出站接口
  1921. /// </summary>
  1922. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1923. {
  1924. Stopwatch stopwatch1 = new Stopwatch();
  1925. Stopwatch stopwatch2 = new Stopwatch();
  1926. try
  1927. {
  1928. stopwatch1.Start();
  1929. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1930. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1931. string processItem = stationName; // 测试项目
  1932. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1933. string supplierCode = ""; // 供应商代码
  1934. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  1935. string batch_num = GlobalContext.BatchNumber; // 批次号
  1936. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  1937. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  1938. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1939. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  1940. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  1941. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  1942. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1943. bool pass = a1Result == 1;
  1944. //根据载具码获取产品码
  1945. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1946. if (string.IsNullOrEmpty(strProductBarcode))
  1947. {
  1948. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1949. }
  1950. sn = strProductBarcode;
  1951. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1952. List<TestItem> items = new List<TestItem>();
  1953. items.Add(new TestItem()
  1954. {
  1955. Parameter_name = "载具码",
  1956. Parameter_value = CarrierBarcode,
  1957. Parameter_unit = ""
  1958. });
  1959. items.Add(new TestItem()
  1960. {
  1961. Parameter_name = "产品码",
  1962. Parameter_value = sn,
  1963. Parameter_unit = ""
  1964. });
  1965. items.Add(new TestItem()
  1966. {
  1967. Parameter_name = "部件码",
  1968. Parameter_value = PartBarcode,
  1969. Parameter_unit = ""
  1970. });
  1971. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1972. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  1973. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1974. stopwatch2.Start();
  1975. //进站结果写入PLC
  1976. CommandFromPLC resultToPlC = new CommandFromPLC();
  1977. resultToPlC.cmd = 0;
  1978. resultToPlC.cmdParam = 0; //指令参数
  1979. resultToPlC.cmdResult = mesResultFrmWeb;
  1980. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1981. stopwatch2.Stop();
  1982. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1983. //保存PLC返回MES数据到本地
  1984. ResponseMessage message = new ResponseMessage();
  1985. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  1986. if (message.result == false)
  1987. {
  1988. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1989. }
  1990. if (!string.IsNullOrEmpty(PartBarcode))
  1991. {
  1992. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  1993. if (message.result == false)
  1994. {
  1995. AddMessage(LogType.Error, message.text);
  1996. }
  1997. }
  1998. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  1999. }
  2000. catch (Exception ex)
  2001. {
  2002. stopwatch2.Start();
  2003. CommandFromPLC resultToPlC = new CommandFromPLC();
  2004. resultToPlC.cmd = 0;
  2005. resultToPlC.cmdParam = 0; //指令参数
  2006. resultToPlC.cmdResult = 110;
  2007. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2008. stopwatch2.Stop();
  2009. string str = ex.StackTrace;
  2010. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2011. }
  2012. stopwatch1.Stop();
  2013. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2014. ProgressState = false;
  2015. }
  2016. #endregion
  2017. #region S3
  2018. /// <summary>
  2019. /// [S3] 点散热胶装备
  2020. /// </summary>
  2021. /// <param name="plcNo">PLC编号</param>
  2022. private void ReadStation_S3(int plcNo)
  2023. {
  2024. string stationCode = "[OP30]";
  2025. string stationName = "点散热胶装备";
  2026. string stationNameStr = stationCode + stationName;
  2027. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2028. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2029. string tagAgvCommName = "agvCommFrmPC";
  2030. string tagBarsetName = "BarcodeSet";
  2031. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2032. (int, string) result;
  2033. #region 创建字典
  2034. // 触发信号字典 赋值
  2035. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2036. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2037. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2038. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2039. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2040. // PLC数据字典 赋值
  2041. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2042. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2043. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2044. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2045. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2046. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2047. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2048. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2049. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2050. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2051. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2052. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2053. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2054. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2055. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2056. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2057. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2058. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2059. s3PLCData.Add("c1Result", 0); // 产品结果
  2060. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2061. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2062. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2063. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2064. #endregion 创建字典
  2065. while (true)
  2066. {
  2067. try
  2068. {
  2069. if (!GlobalContext._IsCon_Funs2)
  2070. {
  2071. UpdatePLCMonitor(1, plcNo, 0);
  2072. continue;
  2073. }
  2074. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2075. {
  2076. Stopwatch stopwatch1 = new Stopwatch();
  2077. Stopwatch stopwatch2 = new Stopwatch();
  2078. stopwatch1.Start();
  2079. stopwatch2.Start();
  2080. #region 一次性读取所有数据
  2081. // 一次性读取所有数据
  2082. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2083. if (result.Item1 != 0)
  2084. {
  2085. //richTextBox1.AppendText("\n" + strRet);
  2086. }
  2087. else
  2088. {
  2089. //richTextBox1.AppendText("\n" + "读取成功");
  2090. }
  2091. #endregion 一次性读取所有数据
  2092. stopwatch2.Stop();
  2093. #region 左边进站
  2094. try
  2095. {
  2096. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2097. {
  2098. lock (lockObj)
  2099. {
  2100. if (!ProgressState)
  2101. {
  2102. ProgressState = true;
  2103. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2104. }
  2105. }
  2106. }
  2107. }
  2108. catch (Exception ex)
  2109. {
  2110. ProgressState = false;
  2111. string str = ex.StackTrace;
  2112. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2113. }
  2114. #endregion 左边进站
  2115. #region 左边出站
  2116. try
  2117. {
  2118. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2119. {
  2120. lock (lockObj)
  2121. {
  2122. if (!ProgressState)
  2123. {
  2124. ProgressState = true;
  2125. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2126. }
  2127. }
  2128. }
  2129. }
  2130. catch (Exception ex)
  2131. {
  2132. ProgressState = false;
  2133. string str = ex.StackTrace;
  2134. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2135. }
  2136. #endregion 左边出站
  2137. #region 右边进站
  2138. try
  2139. {
  2140. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2141. {
  2142. lock (lockObj)
  2143. {
  2144. if (!ProgressState)
  2145. {
  2146. ProgressState = true;
  2147. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2148. }
  2149. }
  2150. }
  2151. }
  2152. catch (Exception ex)
  2153. {
  2154. ProgressState = false;
  2155. string str = ex.StackTrace;
  2156. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2157. }
  2158. #endregion 右边进站
  2159. #region 右边出站
  2160. try
  2161. {
  2162. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2163. {
  2164. lock (lockObj)
  2165. {
  2166. if (!ProgressState)
  2167. {
  2168. ProgressState = true;
  2169. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2170. }
  2171. }
  2172. }
  2173. }
  2174. catch (Exception ex)
  2175. {
  2176. string str = ex.StackTrace;
  2177. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2178. }
  2179. #endregion 右边出站
  2180. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2181. stopwatch1.Stop();
  2182. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2183. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2184. }
  2185. else
  2186. {
  2187. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2188. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2189. FunsEip[plcNo].Connect();
  2190. }
  2191. }
  2192. catch (Exception ex)
  2193. {
  2194. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2195. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2196. //Funs[plcNo].ReConnect();
  2197. }
  2198. Thread.Sleep(IntervalReadPLC);
  2199. }
  2200. }
  2201. /// <summary>
  2202. /// [S3] 点散热胶装备 - 进站
  2203. /// </summary>
  2204. /// <param name="plcNo">PLC编号</param>
  2205. /// <param name="stationNameStr">工站全称</param>
  2206. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2207. {
  2208. Stopwatch stopwatch1 = new Stopwatch();
  2209. Stopwatch stopwatch2 = new Stopwatch();
  2210. try
  2211. {
  2212. stopwatch1.Start();
  2213. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2214. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2215. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2216. string StationId=string.Empty;
  2217. if (direction=="Left")
  2218. {
  2219. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2220. }
  2221. if (direction == "Right")
  2222. {
  2223. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2224. }
  2225. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2226. //载具码验证产品码
  2227. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2228. if (string.IsNullOrEmpty(strProductBarcode))
  2229. {
  2230. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2231. }
  2232. sn = strProductBarcode;
  2233. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2234. // 产品SN(物料码)校验
  2235. List<TestItem> item = new List<TestItem>();
  2236. stopwatch2.Start();
  2237. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2238. stopwatch2.Stop();
  2239. //指令执行结果 1:OK 110:失败
  2240. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2241. //进站结果写入PLC
  2242. CommandFromPLC resultToPlC = new CommandFromPLC();
  2243. resultToPlC.cmd = 0;
  2244. resultToPlC.cmdParam = 0; //指令参数
  2245. resultToPlC.cmdResult = mesResultFrmWeb;
  2246. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2247. }
  2248. catch (Exception ex)
  2249. {
  2250. string str = ex.StackTrace;
  2251. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2252. CommandFromPLC resultToPlC = new CommandFromPLC();
  2253. resultToPlC.cmd = 0;
  2254. resultToPlC.cmdParam = 0; //指令参数
  2255. resultToPlC.cmdResult = 110;
  2256. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2257. }
  2258. stopwatch1.Stop();
  2259. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2260. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2261. ProgressState = false;
  2262. }
  2263. /// <summary>
  2264. /// [S3] 点散热胶装备 - 出站
  2265. /// </summary>
  2266. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2267. {
  2268. Stopwatch stopwatch1 = new Stopwatch();
  2269. Stopwatch stopwatch2 = new Stopwatch();
  2270. try
  2271. {
  2272. stopwatch1.Start();
  2273. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2274. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2275. string processItem = stationName; // 测试项目
  2276. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2277. string supplierCode = ""; // 供应商代码
  2278. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2279. string batch_num = GlobalContext.BatchNumber; // 批次号
  2280. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2281. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2282. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2283. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2284. string StationId = string.Empty;
  2285. if (direction == "Left")
  2286. {
  2287. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2288. }
  2289. if (direction == "Right")
  2290. {
  2291. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2292. }
  2293. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2294. bool pass = a1Result == 1;
  2295. //根据载具码获取产品码
  2296. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2297. if (string.IsNullOrEmpty(strProductBarcode))
  2298. {
  2299. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2300. }
  2301. sn = strProductBarcode;
  2302. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2303. List<TestItem> items = new List<TestItem>();
  2304. items.Add(new TestItem()
  2305. {
  2306. Parameter_name = "载具码",
  2307. Parameter_value = CarrierBarcode,
  2308. Parameter_unit = ""
  2309. });
  2310. items.Add(new TestItem()
  2311. {
  2312. Parameter_name = "产品码",
  2313. Parameter_value = sn,
  2314. Parameter_unit = ""
  2315. });
  2316. int result1 = 1;
  2317. if (direction == "Right")
  2318. {
  2319. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2320. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2321. }
  2322. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2323. stopwatch2.Start();
  2324. //进站结果写入PLC
  2325. CommandFromPLC resultToPlC = new CommandFromPLC();
  2326. resultToPlC.cmd = 0;
  2327. resultToPlC.cmdParam = 0; //指令参数
  2328. resultToPlC.cmdResult = mesResultFrmWeb;
  2329. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2330. stopwatch2.Stop();
  2331. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2332. //保存PLC返回MES数据到本地
  2333. ResponseMessage message = new ResponseMessage();
  2334. if (direction == "Left")
  2335. {
  2336. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2337. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2338. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2339. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2340. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2341. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2342. if (message.result == false)
  2343. {
  2344. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2345. }
  2346. }
  2347. if (direction == "Right")
  2348. {
  2349. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2350. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2351. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2352. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2353. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2354. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2355. if (message.result == false)
  2356. {
  2357. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2358. }
  2359. }
  2360. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2361. }
  2362. catch (Exception ex)
  2363. {
  2364. stopwatch2.Start();
  2365. CommandFromPLC resultToPlC = new CommandFromPLC();
  2366. resultToPlC.cmd = 0;
  2367. resultToPlC.cmdParam = 0; //指令参数
  2368. resultToPlC.cmdResult = 110;
  2369. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2370. stopwatch2.Stop();
  2371. string str = ex.StackTrace;
  2372. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2373. }
  2374. stopwatch1.Stop();
  2375. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2376. ProgressState = false;
  2377. }
  2378. #endregion S3
  2379. #region S4
  2380. /// <summary>
  2381. /// [S4] 点胶检测设备
  2382. /// </summary>
  2383. /// <param name="plcNo">PLC编号</param>
  2384. private void ReadStation_S4(int plcNo)
  2385. {
  2386. string stationCode = "[OP40]";
  2387. string stationName = "胶线检测";
  2388. string stationNameStr = stationCode + stationName;
  2389. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2390. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2391. string tagAgvCommName = "agvCommFrmPC";
  2392. string tagBarsetName = "BarcodeSet";
  2393. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2394. (int, string) result;
  2395. while (true)
  2396. {
  2397. try
  2398. {
  2399. if (!GlobalContext._IsCon_Funs1)
  2400. {
  2401. UpdatePLCMonitor(1, plcNo, 0);
  2402. continue;
  2403. }
  2404. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2405. {
  2406. Stopwatch stopwatch1 = new Stopwatch();
  2407. Stopwatch stopwatch2 = new Stopwatch();
  2408. stopwatch1.Start();
  2409. stopwatch2.Start();
  2410. #region 一次性读取所有数据
  2411. // 一次性读取所有数据
  2412. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2413. if (result.Item1 != 0)
  2414. {
  2415. //richTextBox1.AppendText("\n" + strRet);
  2416. }
  2417. else
  2418. {
  2419. //richTextBox1.AppendText("\n" + "读取成功");
  2420. }
  2421. #endregion 一次性读取所有数据
  2422. stopwatch2.Stop();
  2423. #region 进站
  2424. try
  2425. {
  2426. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2427. {
  2428. lock (lockObj)
  2429. {
  2430. if (!ProgressState)
  2431. {
  2432. ProgressState = true;
  2433. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2434. }
  2435. }
  2436. }
  2437. }
  2438. catch (Exception ex)
  2439. {
  2440. ProgressState = false;
  2441. string str = ex.StackTrace;
  2442. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2443. }
  2444. #endregion 进站
  2445. #region 出站
  2446. try
  2447. {
  2448. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2449. {
  2450. lock (lockObj)
  2451. {
  2452. if (!ProgressState)
  2453. {
  2454. ProgressState = true;
  2455. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2456. }
  2457. }
  2458. }
  2459. }
  2460. catch (Exception ex)
  2461. {
  2462. string str = ex.StackTrace;
  2463. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2464. }
  2465. #endregion 进站
  2466. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2467. stopwatch1.Stop();
  2468. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2469. }
  2470. else
  2471. {
  2472. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2473. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2474. FunsEip[plcNo].Connect(); // 重连
  2475. }
  2476. }
  2477. catch (Exception ex)
  2478. {
  2479. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2480. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2481. }
  2482. Thread.Sleep(IntervalReadPLC);
  2483. }
  2484. }
  2485. /// <summary>
  2486. /// [S4] 点胶检测设备 - 进站
  2487. /// </summary>
  2488. /// <param name="plcNo">PLC编号</param>
  2489. /// <param name="stationNameStr">工站全称</param>
  2490. /// <param name="stPLC_MesData"></param>
  2491. /// <param name="tagMesCommName"></param>
  2492. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2493. {
  2494. Stopwatch stopwatch1 = new Stopwatch();
  2495. Stopwatch stopwatch2 = new Stopwatch();
  2496. try
  2497. {
  2498. stopwatch1.Start();
  2499. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2500. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2501. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2502. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2503. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2504. //载具码验证产品码
  2505. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2506. if (string.IsNullOrEmpty(strProductBarcode))
  2507. {
  2508. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2509. }
  2510. sn = strProductBarcode;
  2511. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2512. // 产品SN(物料码)校验
  2513. List<TestItem> item = new List<TestItem>();
  2514. stopwatch2.Start();
  2515. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2516. stopwatch2.Stop();
  2517. //指令执行结果 1:OK 110:失败
  2518. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2519. //进站结果写入PLC
  2520. CommandFromPLC resultToPlC = new CommandFromPLC();
  2521. resultToPlC.cmd = 0;
  2522. resultToPlC.cmdParam = 0; //指令参数
  2523. resultToPlC.cmdResult = mesResultFrmWeb;
  2524. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2525. }
  2526. catch (Exception ex)
  2527. {
  2528. string str = ex.StackTrace;
  2529. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2530. CommandFromPLC resultToPlC = new CommandFromPLC();
  2531. resultToPlC.cmd = 0;
  2532. resultToPlC.cmdParam = 0; //指令参数
  2533. resultToPlC.cmdResult = 110;
  2534. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2535. }
  2536. stopwatch1.Stop();
  2537. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2538. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2539. ProgressState = false;
  2540. }
  2541. /// <summary>
  2542. /// [S4] 点胶检测设备 - 出站接口
  2543. /// </summary>
  2544. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2545. {
  2546. Stopwatch stopwatch1 = new Stopwatch();
  2547. Stopwatch stopwatch2 = new Stopwatch();
  2548. try
  2549. {
  2550. stopwatch1.Start();
  2551. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2552. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2553. string processItem = stationName; // 测试项目
  2554. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2555. string supplierCode = ""; // 供应商代码
  2556. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2557. string batch_num = GlobalContext.BatchNumber; // 批次号
  2558. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2559. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2560. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2561. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2562. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2563. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2564. bool pass = a1Result == 1;
  2565. //根据载具码获取产品码
  2566. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2567. if (string.IsNullOrEmpty(strProductBarcode))
  2568. {
  2569. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2570. }
  2571. sn = strProductBarcode;
  2572. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2573. List<TestItem> items = new List<TestItem>();
  2574. items.Add(new TestItem()
  2575. {
  2576. Parameter_name = "载具码",
  2577. Parameter_value = CarrierBarcode,
  2578. Parameter_unit = ""
  2579. });
  2580. items.Add(new TestItem()
  2581. {
  2582. Parameter_name = "产品码",
  2583. Parameter_value = sn,
  2584. Parameter_unit = ""
  2585. });
  2586. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2587. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2588. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2589. stopwatch2.Start();
  2590. //进站结果写入PLC
  2591. CommandFromPLC resultToPlC = new CommandFromPLC();
  2592. resultToPlC.cmd = 0;
  2593. resultToPlC.cmdParam = 0; //指令参数
  2594. resultToPlC.cmdResult = mesResultFrmWeb;
  2595. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2596. stopwatch2.Stop();
  2597. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2598. //保存PLC返回MES数据到本地
  2599. ResponseMessage message = new ResponseMessage();
  2600. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2601. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2602. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2603. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2604. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2605. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2606. if (message.result == false)
  2607. {
  2608. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2609. }
  2610. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2611. }
  2612. catch (Exception ex)
  2613. {
  2614. stopwatch2.Start();
  2615. CommandFromPLC resultToPlC = new CommandFromPLC();
  2616. resultToPlC.cmd = 0;
  2617. resultToPlC.cmdParam = 0; //指令参数
  2618. resultToPlC.cmdResult = 110;
  2619. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2620. stopwatch2.Stop();
  2621. string str = ex.StackTrace;
  2622. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2623. }
  2624. stopwatch1.Stop();
  2625. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2626. ProgressState = false;
  2627. }
  2628. #endregion
  2629. #region S5
  2630. /// <summary>
  2631. /// [S5] 点胶检测设备
  2632. /// </summary>
  2633. /// <param name="plcNo">PLC编号</param>
  2634. private void ReadStation_S5(int plcNo)
  2635. {
  2636. string stationCode = "[OP50]";
  2637. string stationName = "ADD板上料组装装备";
  2638. string stationNameStr = stationCode + stationName;
  2639. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2640. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2641. string tagAgvCommName = "agvCommFrmPC";
  2642. string tagBarsetName = "BarcodeSet";
  2643. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2644. (int, string) result;
  2645. while (true)
  2646. {
  2647. try
  2648. {
  2649. if (!GlobalContext._IsCon_Funs1)
  2650. {
  2651. UpdatePLCMonitor(1, plcNo, 0);
  2652. continue;
  2653. }
  2654. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2655. {
  2656. Stopwatch stopwatch1 = new Stopwatch();
  2657. Stopwatch stopwatch2 = new Stopwatch();
  2658. stopwatch1.Start();
  2659. stopwatch2.Start();
  2660. #region 一次性读取所有数据
  2661. // 一次性读取所有数据
  2662. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2663. if (result.Item1 != 0)
  2664. {
  2665. //richTextBox1.AppendText("\n" + strRet);
  2666. }
  2667. else
  2668. {
  2669. //richTextBox1.AppendText("\n" + "读取成功");
  2670. }
  2671. #endregion 一次性读取所有数据
  2672. stopwatch2.Stop();
  2673. #region 进站
  2674. try
  2675. {
  2676. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2677. {
  2678. lock (lockObj)
  2679. {
  2680. if (!ProgressState)
  2681. {
  2682. ProgressState = true;
  2683. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2684. }
  2685. }
  2686. }
  2687. }
  2688. catch (Exception ex)
  2689. {
  2690. ProgressState = false;
  2691. string str = ex.StackTrace;
  2692. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2693. }
  2694. #endregion 进站
  2695. #region 出站
  2696. try
  2697. {
  2698. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2699. {
  2700. lock (lockObj)
  2701. {
  2702. if (!ProgressState)
  2703. {
  2704. ProgressState = true;
  2705. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2706. }
  2707. }
  2708. }
  2709. }
  2710. catch (Exception ex)
  2711. {
  2712. ProgressState = false;
  2713. string str = ex.StackTrace;
  2714. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2715. }
  2716. #endregion 进站
  2717. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2718. stopwatch1.Stop();
  2719. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2720. }
  2721. else
  2722. {
  2723. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2724. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2725. FunsEip[plcNo].Connect(); // 重连
  2726. }
  2727. }
  2728. catch (Exception ex)
  2729. {
  2730. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2731. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2732. }
  2733. Thread.Sleep(IntervalReadPLC);
  2734. }
  2735. }
  2736. /// <summary>
  2737. /// [S5] 点胶检测设备 - 进站
  2738. /// </summary>
  2739. /// <param name="plcNo">PLC编号</param>
  2740. /// <param name="stationNameStr">工站全称</param>
  2741. /// <param name="stPLC_MesData"></param>
  2742. /// <param name="tagMesCommName"></param>
  2743. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2744. {
  2745. Stopwatch stopwatch1 = new Stopwatch();
  2746. Stopwatch stopwatch2 = new Stopwatch();
  2747. try
  2748. {
  2749. stopwatch1.Start();
  2750. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2751. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2752. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2753. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2754. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2755. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2756. //载具码验证产品码 //载具码验证产品码
  2757. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2758. if (string.IsNullOrEmpty(strProductBarcode))
  2759. {
  2760. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2761. }
  2762. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2763. //if (sn != strProductBarcode)
  2764. //{
  2765. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2766. //}
  2767. sn = strProductBarcode;
  2768. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2769. // 产品SN(物料码)校验
  2770. List<TestItem> item = new List<TestItem>();
  2771. stopwatch2.Start();
  2772. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2773. stopwatch2.Stop();
  2774. //指令执行结果 1:OK 110:失败
  2775. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2776. //进站结果写入PLC
  2777. CommandFromPLC resultToPlC = new CommandFromPLC();
  2778. resultToPlC.cmd = 0;
  2779. resultToPlC.cmdParam = 0; //指令参数
  2780. resultToPlC.cmdResult = mesResultFrmWeb;
  2781. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2782. }
  2783. catch (Exception ex)
  2784. {
  2785. string str = ex.StackTrace;
  2786. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2787. CommandFromPLC resultToPlC = new CommandFromPLC();
  2788. resultToPlC.cmd = 0;
  2789. resultToPlC.cmdParam = 0; //指令参数
  2790. resultToPlC.cmdResult = 110;
  2791. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2792. }
  2793. stopwatch1.Stop();
  2794. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2795. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2796. ProgressState = false;
  2797. }
  2798. /// <summary>
  2799. /// [S5] 点胶检测设备 - 出站接口
  2800. /// </summary>
  2801. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2802. {
  2803. Stopwatch stopwatch1 = new Stopwatch();
  2804. Stopwatch stopwatch2 = new Stopwatch();
  2805. try
  2806. {
  2807. stopwatch1.Start();
  2808. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2809. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2810. string processItem = stationName; // 测试项目
  2811. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2812. string supplierCode = ""; // 供应商代码
  2813. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2814. string batch_num = GlobalContext.BatchNumber; // 批次号
  2815. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2816. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2817. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2818. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2819. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2820. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2821. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2822. bool pass = a1Result == 1;
  2823. //根据载具码获取产品码
  2824. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2825. if (string.IsNullOrEmpty(strProductBarcode))
  2826. {
  2827. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2828. }
  2829. sn = strProductBarcode;
  2830. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2831. List<TestItem> items = new List<TestItem>();
  2832. items.Add(new TestItem()
  2833. {
  2834. Parameter_name = "载具码",
  2835. Parameter_value = CarrierBarcode,
  2836. Parameter_unit = ""
  2837. });
  2838. items.Add(new TestItem()
  2839. {
  2840. Parameter_name = "产品码",
  2841. Parameter_value = sn,
  2842. Parameter_unit = ""
  2843. });
  2844. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2845. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2846. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2847. stopwatch2.Start();
  2848. //进站结果写入PLC
  2849. CommandFromPLC resultToPlC = new CommandFromPLC();
  2850. resultToPlC.cmd = 0;
  2851. resultToPlC.cmdParam = 0; //指令参数
  2852. resultToPlC.cmdResult = mesResultFrmWeb;
  2853. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2854. stopwatch2.Stop();
  2855. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2856. //保存PLC返回MES数据到本地
  2857. ResponseMessage message = new ResponseMessage();
  2858. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  2859. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  2860. if (message.result == false)
  2861. {
  2862. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2863. }
  2864. //保存部件码信息
  2865. if (!string.IsNullOrEmpty(PartBarcode))
  2866. {
  2867. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  2868. if (message.result == false)
  2869. {
  2870. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  2871. }
  2872. }
  2873. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2874. }
  2875. catch (Exception ex)
  2876. {
  2877. stopwatch2.Start();
  2878. CommandFromPLC resultToPlC = new CommandFromPLC();
  2879. resultToPlC.cmd = 0;
  2880. resultToPlC.cmdParam = 0; //指令参数
  2881. resultToPlC.cmdResult = 110;
  2882. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2883. stopwatch2.Stop();
  2884. string str = ex.StackTrace;
  2885. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2886. }
  2887. stopwatch1.Stop();
  2888. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2889. ProgressState = false;
  2890. }
  2891. #endregion
  2892. #region S6
  2893. /// <summary>
  2894. /// [S6] 顶盖装配设备
  2895. /// </summary>
  2896. /// <param name="plcNo">PLC编号</param>
  2897. private void ReadStation_S6(int plcNo)
  2898. {
  2899. string stationCode = "[OP60]";
  2900. string stationName = "组上盖板";
  2901. string stationNameStr = stationCode + stationName;
  2902. string tagBaseName = "g_OP60_MES"; //标签变量名称
  2903. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2904. string tagAgvCommName = "agvCommFrmPC";
  2905. string tagBarsetName = "BarcodeSet";
  2906. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  2907. (int, string) result;
  2908. while (true)
  2909. {
  2910. try
  2911. {
  2912. if (!GlobalContext._IsCon_Funs1)
  2913. {
  2914. UpdatePLCMonitor(1, plcNo, 0);
  2915. continue;
  2916. }
  2917. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2918. {
  2919. Stopwatch stopwatch1 = new Stopwatch();
  2920. Stopwatch stopwatch2 = new Stopwatch();
  2921. stopwatch1.Start();
  2922. stopwatch2.Start();
  2923. #region 一次性读取所有数据
  2924. // 一次性读取所有数据
  2925. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2926. if (result.Item1 != 0)
  2927. {
  2928. //richTextBox1.AppendText("\n" + strRet);
  2929. }
  2930. else
  2931. {
  2932. //richTextBox1.AppendText("\n" + "读取成功");
  2933. }
  2934. #endregion 一次性读取所有数据
  2935. stopwatch2.Stop();
  2936. #region 进站
  2937. try
  2938. {
  2939. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2940. {
  2941. lock (lockObj)
  2942. {
  2943. if (!ProgressState)
  2944. {
  2945. ProgressState = true;
  2946. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2947. }
  2948. }
  2949. }
  2950. }
  2951. catch (Exception ex)
  2952. {
  2953. ProgressState = false;
  2954. string str = ex.StackTrace;
  2955. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2956. }
  2957. #endregion 进站
  2958. #region 出站
  2959. try
  2960. {
  2961. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2962. {
  2963. lock (lockObj)
  2964. {
  2965. if (!ProgressState)
  2966. {
  2967. ProgressState = true; ;
  2968. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2969. }
  2970. }
  2971. }
  2972. }
  2973. catch (Exception ex)
  2974. {
  2975. ProgressState = false;
  2976. string str = ex.StackTrace;
  2977. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2978. }
  2979. #endregion 进站
  2980. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2981. stopwatch1.Stop();
  2982. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2983. }
  2984. else
  2985. {
  2986. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2987. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2988. FunsEip[plcNo].Connect(); // 重连
  2989. }
  2990. }
  2991. catch (Exception ex)
  2992. {
  2993. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2994. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2995. }
  2996. Thread.Sleep(IntervalReadPLC);
  2997. }
  2998. }
  2999. /// <summary>
  3000. /// [S6] 顶盖装配设备 - 进站
  3001. /// </summary>
  3002. /// <param name="plcNo">PLC编号</param>
  3003. /// <param name="stationNameStr">工站全称</param>
  3004. /// <param name="stPLC_MesData"></param>
  3005. /// <param name="tagMesCommName"></param>
  3006. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3007. {
  3008. Stopwatch stopwatch1 = new Stopwatch();
  3009. Stopwatch stopwatch2 = new Stopwatch();
  3010. try
  3011. {
  3012. stopwatch1.Start();
  3013. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3014. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3015. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3016. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3017. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3018. //载具码验证产品码
  3019. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3020. if (string.IsNullOrEmpty(strProductBarcode))
  3021. {
  3022. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3023. }
  3024. sn = strProductBarcode;
  3025. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3026. // 产品SN(物料码)校验
  3027. List<TestItem> item = new List<TestItem>();
  3028. stopwatch2.Start();
  3029. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3030. stopwatch2.Stop();
  3031. //指令执行结果 1:OK 110:失败
  3032. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3033. //进站结果写入PLC
  3034. CommandFromPLC resultToPlC = new CommandFromPLC();
  3035. resultToPlC.cmd = 0;
  3036. resultToPlC.cmdParam = 0; //指令参数
  3037. resultToPlC.cmdResult = mesResultFrmWeb;
  3038. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3039. }
  3040. catch (Exception ex)
  3041. {
  3042. string str = ex.StackTrace;
  3043. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3044. CommandFromPLC resultToPlC = new CommandFromPLC();
  3045. resultToPlC.cmd = 0;
  3046. resultToPlC.cmdParam = 0; //指令参数
  3047. resultToPlC.cmdResult = 110;
  3048. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3049. }
  3050. stopwatch1.Stop();
  3051. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3052. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3053. ProgressState = false;
  3054. }
  3055. /// <summary>
  3056. /// [S6] 顶盖装配设备 - 出站接口
  3057. /// </summary>
  3058. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3059. {
  3060. Stopwatch stopwatch1 = new Stopwatch();
  3061. Stopwatch stopwatch2 = new Stopwatch();
  3062. try
  3063. {
  3064. stopwatch1.Start();
  3065. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3066. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3067. string processItem = stationName; // 测试项目
  3068. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3069. string supplierCode = ""; // 供应商代码
  3070. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3071. string batch_num = GlobalContext.BatchNumber; // 批次号
  3072. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3073. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3074. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3075. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3076. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3077. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3078. bool pass = a1Result == 1;
  3079. //根据载具码获取产品码
  3080. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3081. if (string.IsNullOrEmpty(strProductBarcode))
  3082. {
  3083. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3084. }
  3085. sn = strProductBarcode;
  3086. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3087. List<TestItem> items = new List<TestItem>();
  3088. items.Add(new TestItem()
  3089. {
  3090. Parameter_name = "载具码",
  3091. Parameter_value = CarrierBarcode,
  3092. Parameter_unit = ""
  3093. });
  3094. items.Add(new TestItem()
  3095. {
  3096. Parameter_name = "产品码",
  3097. Parameter_value = sn,
  3098. Parameter_unit = ""
  3099. });
  3100. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3101. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3102. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3103. stopwatch2.Start();
  3104. //进站结果写入PLC
  3105. CommandFromPLC resultToPlC = new CommandFromPLC();
  3106. resultToPlC.cmd = 0;
  3107. resultToPlC.cmdParam = 0; //指令参数
  3108. resultToPlC.cmdResult = mesResultFrmWeb;
  3109. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3110. stopwatch2.Stop();
  3111. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3112. //保存PLC返回MES数据到本地
  3113. ResponseMessage message = new ResponseMessage();
  3114. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3115. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3116. if (message.result == false)
  3117. {
  3118. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3119. }
  3120. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3121. }
  3122. catch (Exception ex)
  3123. {
  3124. stopwatch2.Start();
  3125. CommandFromPLC resultToPlC = new CommandFromPLC();
  3126. resultToPlC.cmd = 0;
  3127. resultToPlC.cmdParam = 0; //指令参数
  3128. resultToPlC.cmdResult = 110;
  3129. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3130. stopwatch2.Stop();
  3131. string str = ex.StackTrace;
  3132. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3133. }
  3134. stopwatch1.Stop();
  3135. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3136. ProgressState = false;
  3137. }
  3138. #endregion
  3139. #region S7
  3140. /// <summary>
  3141. /// [S7] 锁螺丝设备
  3142. /// </summary>
  3143. /// <param name="plcNo">PLC编号</param>
  3144. private void ReadStation_S7(int plcNo)
  3145. {
  3146. string stationCode = "[OP70]";
  3147. string stationName = "上盖板锁螺丝";
  3148. string stationNameStr = stationCode + stationName;
  3149. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3150. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3151. string tagAgvCommName = "agvCommFrmPC";
  3152. string tagBarsetName = "BarcodeSet";
  3153. string tagScrewDataset = "screwDataset";
  3154. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3155. (int, string) result;
  3156. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3157. atlasScrewLeft.Initial();
  3158. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3159. atlasScrewRight.Initial();
  3160. while (true)
  3161. {
  3162. try
  3163. {
  3164. if (!GlobalContext._IsCon_Funs1)
  3165. {
  3166. UpdatePLCMonitor(1, plcNo, 0);
  3167. continue;
  3168. }
  3169. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3170. {
  3171. Stopwatch stopwatch1 = new Stopwatch();
  3172. Stopwatch stopwatch2 = new Stopwatch();
  3173. stopwatch1.Start();
  3174. stopwatch2.Start();
  3175. #region 一次性读取所有数据
  3176. // 一次性读取所有数据
  3177. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3178. if (result.Item1 != 0)
  3179. {
  3180. //richTextBox1.AppendText("\n" + strRet);
  3181. }
  3182. else
  3183. {
  3184. //richTextBox1.AppendText("\n" + "读取成功");
  3185. }
  3186. #endregion 一次性读取所有数据
  3187. stopwatch2.Stop();
  3188. #region 左边进站
  3189. try
  3190. {
  3191. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3192. {
  3193. lock (lockObj)
  3194. {
  3195. if (!ProgressState)
  3196. {
  3197. ProgressState = true;
  3198. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3199. }
  3200. }
  3201. }
  3202. }
  3203. catch (Exception ex)
  3204. {
  3205. ProgressState = false;
  3206. string str = ex.StackTrace;
  3207. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3208. }
  3209. #endregion 左边进站
  3210. #region 左边出站
  3211. try
  3212. {
  3213. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3214. {
  3215. lock (lockObj)
  3216. {
  3217. if (!ProgressState)
  3218. {
  3219. ProgressState = true;
  3220. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3221. }
  3222. }
  3223. }
  3224. }
  3225. catch (Exception ex)
  3226. {
  3227. ProgressState = false;
  3228. string str = ex.StackTrace;
  3229. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3230. }
  3231. #endregion 左边出站
  3232. #region 右边进站
  3233. try
  3234. {
  3235. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3236. {
  3237. lock (lockObj)
  3238. {
  3239. if (!ProgressState)
  3240. {
  3241. ProgressState = true;
  3242. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3243. }
  3244. }
  3245. }
  3246. }
  3247. catch (Exception ex)
  3248. {
  3249. ProgressState = false;
  3250. string str = ex.StackTrace;
  3251. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3252. }
  3253. #endregion 右边进站
  3254. #region 右边出站
  3255. try
  3256. {
  3257. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3258. {
  3259. lock (lockObj)
  3260. {
  3261. if (!ProgressState)
  3262. {
  3263. ProgressState = true;
  3264. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3265. }
  3266. }
  3267. }
  3268. }
  3269. catch (Exception ex)
  3270. {
  3271. ProgressState = false;
  3272. string str = ex.StackTrace;
  3273. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3274. }
  3275. #endregion 右边出站
  3276. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3277. stopwatch1.Stop();
  3278. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3279. }
  3280. else
  3281. {
  3282. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3283. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3284. FunsEip[plcNo].Connect(); // 重连
  3285. }
  3286. }
  3287. catch (Exception ex)
  3288. {
  3289. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3290. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3291. }
  3292. Thread.Sleep(IntervalReadPLC);
  3293. }
  3294. }
  3295. /// <summary>
  3296. /// [S7] 锁螺丝设备 - 进站
  3297. /// </summary>
  3298. /// <param name="plcNo">PLC编号</param>
  3299. /// <param name="stationNameStr">工站全称</param>
  3300. /// <param name="stPLC_MesData"></param>
  3301. /// <param name="tagMesCommName"></param>
  3302. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3303. {
  3304. Stopwatch stopwatch1 = new Stopwatch();
  3305. Stopwatch stopwatch2 = new Stopwatch();
  3306. string atlasSn=string.Empty;
  3307. try
  3308. {
  3309. stopwatch1.Start();
  3310. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3311. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3312. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3313. string StationId = string.Empty; // 工位ID(可配置)
  3314. if (direction == "Left")
  3315. {
  3316. StationId = GlobalContext.S7_StationId_1;
  3317. }
  3318. if (direction == "Right")
  3319. {
  3320. StationId = GlobalContext.S7_StationId_2;
  3321. }
  3322. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3323. //载具码验证产品码
  3324. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3325. if (string.IsNullOrEmpty(strProductBarcode))
  3326. {
  3327. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3328. }
  3329. sn = strProductBarcode;
  3330. atlasSn= strProductBarcode;
  3331. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3332. if (direction == "Left")
  3333. {
  3334. isCollectingFlagLeft = false;//采集螺丝数据结束
  3335. }
  3336. if (direction == "Right")
  3337. {
  3338. isCollectingFlagRight = false;//采集螺丝数据结束
  3339. }
  3340. // 产品SN(物料码)校验
  3341. List<TestItem> item = new List<TestItem>();
  3342. stopwatch2.Start();
  3343. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3344. stopwatch2.Stop();
  3345. //指令执行结果 1:OK 110:失败
  3346. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3347. //进站结果写入PLC
  3348. CommandFromPLC resultToPlC = new CommandFromPLC();
  3349. resultToPlC.cmd = 0;
  3350. resultToPlC.cmdParam = 0; //指令参数
  3351. resultToPlC.cmdResult = mesResultFrmWeb;
  3352. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3353. }
  3354. catch (Exception ex)
  3355. {
  3356. string str = ex.StackTrace;
  3357. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3358. CommandFromPLC resultToPlC = new CommandFromPLC();
  3359. resultToPlC.cmd = 0;
  3360. resultToPlC.cmdParam = 0; //指令参数
  3361. resultToPlC.cmdResult = 110;
  3362. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3363. }
  3364. stopwatch1.Stop();
  3365. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3366. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3367. ProgressState = false;
  3368. //开始采集螺丝数据
  3369. if (direction == "Left")
  3370. {
  3371. isCollectingFlagLeft = true;
  3372. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3373. }
  3374. if (direction == "Right")
  3375. {
  3376. isCollectingFlagRight = true;
  3377. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3378. }
  3379. }
  3380. /// <summary>
  3381. /// [S7] 锁螺丝设备 - 出站
  3382. /// </summary>
  3383. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3384. {
  3385. Stopwatch stopwatch1 = new Stopwatch();
  3386. Stopwatch stopwatch2 = new Stopwatch();
  3387. try
  3388. {
  3389. stopwatch1.Start();
  3390. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3391. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3392. string processItem = stationName; // 测试项目
  3393. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3394. string supplierCode = ""; // 供应商代码
  3395. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3396. string batch_num = GlobalContext.BatchNumber; // 批次号
  3397. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3398. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3399. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3400. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3401. string StationId = string.Empty; // 工位ID(可配置)
  3402. if (direction == "Left")
  3403. {
  3404. StationId = GlobalContext.S7_StationId_1;
  3405. }
  3406. if (direction == "Right")
  3407. {
  3408. StationId = GlobalContext.S7_StationId_2;
  3409. }
  3410. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3411. a1Result = 1;
  3412. bool pass = a1Result == 1;
  3413. //根据载具码获取产品码
  3414. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3415. if (string.IsNullOrEmpty(strProductBarcode))
  3416. {
  3417. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3418. }
  3419. sn = strProductBarcode;
  3420. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3421. List<TestItem> items = new List<TestItem>();
  3422. items.Add(new TestItem()
  3423. {
  3424. Parameter_name = "载具码",
  3425. Parameter_value = CarrierBarcode,
  3426. Parameter_unit = ""
  3427. });
  3428. items.Add(new TestItem()
  3429. {
  3430. Parameter_name = "产品码",
  3431. Parameter_value = sn,
  3432. Parameter_unit = ""
  3433. });
  3434. int result1 = 1;
  3435. if (direction == "Right")
  3436. {
  3437. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3438. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3439. }
  3440. //if (direction == "Left")
  3441. //{
  3442. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3443. //}
  3444. //if (direction == "Right")
  3445. //{
  3446. // isCollectingFlagRight = false;//采集螺丝数据结束
  3447. //}
  3448. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3449. stopwatch2.Start();
  3450. //进站结果写入PLC
  3451. CommandFromPLC resultToPlC = new CommandFromPLC();
  3452. resultToPlC.cmd = 0;
  3453. resultToPlC.cmdParam = 0; //指令参数
  3454. resultToPlC.cmdResult = mesResultFrmWeb;
  3455. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3456. stopwatch2.Stop();
  3457. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3458. //保存PLC返回MES数据到本地
  3459. ResponseMessage message = new ResponseMessage();
  3460. if (direction == "Left")
  3461. {
  3462. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3463. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3464. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3465. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3466. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3467. if (message.result == false)
  3468. {
  3469. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3470. }
  3471. }
  3472. if (direction == "Right")
  3473. {
  3474. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3475. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3476. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3477. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3478. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3479. if (message.result == false)
  3480. {
  3481. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3482. }
  3483. }
  3484. //保存螺丝数据到txt
  3485. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3486. if (result.Item1 != 0)
  3487. {
  3488. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3489. }
  3490. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3491. }
  3492. catch (Exception ex)
  3493. {
  3494. stopwatch2.Start();
  3495. CommandFromPLC resultToPlC = new CommandFromPLC();
  3496. resultToPlC.cmd = 0;
  3497. resultToPlC.cmdParam = 0; //指令参数
  3498. resultToPlC.cmdResult = 110;
  3499. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3500. stopwatch2.Stop();
  3501. string str = ex.StackTrace;
  3502. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3503. }
  3504. stopwatch1.Stop();
  3505. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3506. ProgressState = false;
  3507. }
  3508. #endregion
  3509. #region S8
  3510. /// <summary>
  3511. /// [S8] 3D螺丝高度检测设备
  3512. /// </summary>
  3513. /// <param name="plcNo">PLC编号</param>
  3514. private void ReadStation_S8(int plcNo)
  3515. {
  3516. string stationCode = "[OP80]";
  3517. string stationName = "NG下料";
  3518. string stationNameStr = stationCode + stationName;
  3519. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3520. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3521. string tagAgvCommName = "agvCommFrmPC";
  3522. string tagBarsetName = "BarcodeSet";
  3523. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3524. (int, string) result;
  3525. while (true)
  3526. {
  3527. try
  3528. {
  3529. if (!GlobalContext._IsCon_Funs1)
  3530. {
  3531. UpdatePLCMonitor(1, plcNo, 0);
  3532. continue;
  3533. }
  3534. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3535. {
  3536. Stopwatch stopwatch1 = new Stopwatch();
  3537. Stopwatch stopwatch2 = new Stopwatch();
  3538. stopwatch1.Start();
  3539. stopwatch2.Start();
  3540. #region 一次性读取所有数据
  3541. // 一次性读取所有数据
  3542. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3543. if (result.Item1 != 0)
  3544. {
  3545. //richTextBox1.AppendText("\n" + strRet);
  3546. }
  3547. else
  3548. {
  3549. //richTextBox1.AppendText("\n" + "读取成功");
  3550. }
  3551. #endregion 一次性读取所有数据
  3552. stopwatch2.Stop();
  3553. #region 进站
  3554. try
  3555. {
  3556. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3557. {
  3558. lock (lockObj)
  3559. {
  3560. if (!ProgressState)
  3561. {
  3562. ProgressState = true;
  3563. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3564. }
  3565. }
  3566. }
  3567. }
  3568. catch (Exception ex)
  3569. {
  3570. ProgressState = false;
  3571. string str = ex.StackTrace;
  3572. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3573. }
  3574. #endregion 进站
  3575. #region 出站
  3576. try
  3577. {
  3578. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3579. {
  3580. lock (lockObj)
  3581. {
  3582. if (!ProgressState)
  3583. {
  3584. ProgressState = true;
  3585. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3586. }
  3587. }
  3588. }
  3589. }
  3590. catch (Exception ex)
  3591. {
  3592. ProgressState = false;
  3593. string str = ex.StackTrace;
  3594. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3595. }
  3596. #endregion 进站
  3597. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3598. stopwatch1.Stop();
  3599. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3600. }
  3601. else
  3602. {
  3603. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3604. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3605. FunsEip[plcNo].Connect(); // 重连
  3606. }
  3607. }
  3608. catch (Exception ex)
  3609. {
  3610. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3611. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3612. }
  3613. Thread.Sleep(IntervalReadPLC);
  3614. }
  3615. }
  3616. /// <summary>
  3617. /// [S8] 3D螺丝高度检测设备 - 进站
  3618. /// </summary>
  3619. /// <param name="plcNo">PLC编号</param>
  3620. /// <param name="stationNameStr">工站全称</param>
  3621. /// <param name="stPLC_MesData"></param>
  3622. /// <param name="tagMesCommName"></param>
  3623. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3624. {
  3625. Stopwatch stopwatch1 = new Stopwatch();
  3626. Stopwatch stopwatch2 = new Stopwatch();
  3627. try
  3628. {
  3629. stopwatch1.Start();
  3630. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3631. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3632. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3633. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3634. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3635. //载具码验证产品码
  3636. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3637. if (string.IsNullOrEmpty(strProductBarcode))
  3638. {
  3639. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3640. }
  3641. sn = strProductBarcode;
  3642. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3643. // 产品SN(物料码)校验
  3644. List<TestItem> item = new List<TestItem>();
  3645. stopwatch2.Start();
  3646. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3647. stopwatch2.Stop();
  3648. //指令执行结果 1:OK 110:失败
  3649. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3650. //进站结果写入PLC
  3651. CommandFromPLC resultToPlC = new CommandFromPLC();
  3652. resultToPlC.cmd = 0;
  3653. resultToPlC.cmdParam = 0; //指令参数
  3654. resultToPlC.cmdResult = mesResultFrmWeb;
  3655. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3656. }
  3657. catch (Exception ex)
  3658. {
  3659. string str = ex.StackTrace;
  3660. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3661. CommandFromPLC resultToPlC = new CommandFromPLC();
  3662. resultToPlC.cmd = 0;
  3663. resultToPlC.cmdParam = 0; //指令参数
  3664. resultToPlC.cmdResult = 110;
  3665. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3666. }
  3667. stopwatch1.Stop();
  3668. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3669. ProgressState = false;
  3670. }
  3671. /// <summary>
  3672. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3673. /// </summary>
  3674. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3675. {
  3676. Stopwatch stopwatch1 = new Stopwatch();
  3677. Stopwatch stopwatch2 = new Stopwatch();
  3678. try
  3679. {
  3680. stopwatch1.Start();
  3681. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3682. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3683. string processItem = stationName; // 测试项目
  3684. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3685. string supplierCode = ""; // 供应商代码
  3686. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3687. string batch_num = GlobalContext.BatchNumber; // 批次号
  3688. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3689. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3690. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3691. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3692. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3693. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3694. bool pass = a1Result == 1;
  3695. //根据载具码获取产品码
  3696. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3697. if (string.IsNullOrEmpty(strProductBarcode))
  3698. {
  3699. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3700. }
  3701. sn = strProductBarcode;
  3702. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3703. List<TestItem> items = new List<TestItem>();
  3704. items.Add(new TestItem()
  3705. {
  3706. Parameter_name = "载具码",
  3707. Parameter_value = CarrierBarcode,
  3708. Parameter_unit = ""
  3709. });
  3710. items.Add(new TestItem()
  3711. {
  3712. Parameter_name = "产品码",
  3713. Parameter_value = sn,
  3714. Parameter_unit = ""
  3715. });
  3716. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3717. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3718. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3719. stopwatch2.Start();
  3720. //进站结果写入PLC
  3721. CommandFromPLC resultToPlC = new CommandFromPLC();
  3722. resultToPlC.cmd = 0;
  3723. resultToPlC.cmdParam = 0; //指令参数
  3724. resultToPlC.cmdResult = mesResultFrmWeb;
  3725. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3726. stopwatch2.Stop();
  3727. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3728. //保存PLC返回MES数据到本地
  3729. ResponseMessage message = new ResponseMessage();
  3730. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3731. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3732. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3733. if (message.result == false)
  3734. {
  3735. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3736. }
  3737. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3738. }
  3739. catch (Exception ex)
  3740. {
  3741. stopwatch2.Start();
  3742. CommandFromPLC resultToPlC = new CommandFromPLC();
  3743. resultToPlC.cmd = 0;
  3744. resultToPlC.cmdParam = 0; //指令参数
  3745. resultToPlC.cmdResult = 110;
  3746. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3747. stopwatch2.Stop();
  3748. string str = ex.StackTrace;
  3749. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3750. }
  3751. stopwatch1.Stop();
  3752. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3753. ProgressState = false;
  3754. }
  3755. #endregion
  3756. #region S9
  3757. /// <summary>
  3758. /// [S9] 下料设备
  3759. /// </summary>
  3760. /// <param name="plcNo">PLC编号</param>
  3761. private void ReadStation_S9(int plcNo)
  3762. {
  3763. string stationCode = "[OP90]";
  3764. string stationName = "半成品下料";
  3765. string stationNameStr = stationCode + stationName;
  3766. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3767. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3768. string tagAgvCommName = "agvCommFrmPC";
  3769. string tagBarsetName = "BarcodeSet";
  3770. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3771. (int, string) result;
  3772. while (true)
  3773. {
  3774. try
  3775. {
  3776. if (!GlobalContext._IsCon_Funs1)
  3777. {
  3778. UpdatePLCMonitor(1, plcNo, 0);
  3779. continue;
  3780. }
  3781. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3782. {
  3783. Stopwatch stopwatch1 = new Stopwatch();
  3784. Stopwatch stopwatch2 = new Stopwatch();
  3785. stopwatch1.Start();
  3786. stopwatch2.Start();
  3787. #region 一次性读取所有数据
  3788. // 一次性读取所有数据
  3789. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3790. if (result.Item1 != 0)
  3791. {
  3792. //richTextBox1.AppendText("\n" + strRet);
  3793. }
  3794. else
  3795. {
  3796. //richTextBox1.AppendText("\n" + "读取成功");
  3797. }
  3798. #endregion 一次性读取所有数据
  3799. stopwatch2.Stop();
  3800. #region 进站
  3801. try
  3802. {
  3803. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3804. {
  3805. lock (lockObj)
  3806. {
  3807. if (!ProgressState)
  3808. {
  3809. ProgressState = true;
  3810. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3811. }
  3812. }
  3813. }
  3814. }
  3815. catch (Exception ex)
  3816. {
  3817. ProgressState = false;
  3818. string str = ex.StackTrace;
  3819. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3820. }
  3821. #endregion 进站
  3822. #region 出站
  3823. try
  3824. {
  3825. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3826. {
  3827. lock (lockObj)
  3828. {
  3829. if (!ProgressState)
  3830. {
  3831. ProgressState = true;
  3832. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3833. }
  3834. }
  3835. }
  3836. }
  3837. catch (Exception ex)
  3838. {
  3839. ProgressState = false;
  3840. string str = ex.StackTrace;
  3841. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3842. }
  3843. #endregion 进站
  3844. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3845. stopwatch1.Stop();
  3846. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3847. }
  3848. else
  3849. {
  3850. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3851. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3852. FunsEip[plcNo].Connect(); // 重连
  3853. }
  3854. }
  3855. catch (Exception ex)
  3856. {
  3857. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3858. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3859. }
  3860. Thread.Sleep(IntervalReadPLC);
  3861. }
  3862. }
  3863. /// <summary>
  3864. /// [S9] 下料设备 - 进站
  3865. /// </summary>
  3866. /// <param name="plcNo">PLC编号</param>
  3867. /// <param name="stationNameStr">工站全称</param>
  3868. /// <param name="stPLC_MesData"></param>
  3869. /// <param name="tagMesCommName"></param>
  3870. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3871. {
  3872. Stopwatch stopwatch1 = new Stopwatch();
  3873. Stopwatch stopwatch2 = new Stopwatch();
  3874. try
  3875. {
  3876. stopwatch1.Start();
  3877. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3878. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3879. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  3880. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  3881. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3882. //载具码验证产品码
  3883. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3884. if (string.IsNullOrEmpty(strProductBarcode))
  3885. {
  3886. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3887. }
  3888. sn = strProductBarcode;
  3889. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3890. // 产品SN(物料码)校验
  3891. List<TestItem> item = new List<TestItem>();
  3892. stopwatch2.Start();
  3893. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3894. stopwatch2.Stop();
  3895. //指令执行结果 1:OK 110:失败
  3896. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3897. //进站结果写入PLC
  3898. CommandFromPLC resultToPlC = new CommandFromPLC();
  3899. resultToPlC.cmd = 0;
  3900. resultToPlC.cmdParam = 0; //指令参数
  3901. resultToPlC.cmdResult = mesResultFrmWeb;
  3902. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3903. }
  3904. catch (Exception ex)
  3905. {
  3906. string str = ex.StackTrace;
  3907. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3908. CommandFromPLC resultToPlC = new CommandFromPLC();
  3909. resultToPlC.cmd = 0;
  3910. resultToPlC.cmdParam = 0; //指令参数
  3911. resultToPlC.cmdResult = 110;
  3912. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3913. }
  3914. stopwatch1.Stop();
  3915. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3916. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3917. ProgressState = false;
  3918. }
  3919. /// <summary>
  3920. /// [S9] 下料设备 - 出站接口
  3921. /// </summary>
  3922. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3923. {
  3924. Stopwatch stopwatch1 = new Stopwatch();
  3925. Stopwatch stopwatch2 = new Stopwatch();
  3926. try
  3927. {
  3928. stopwatch1.Start();
  3929. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3930. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3931. string processItem = stationName; // 测试项目
  3932. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3933. string supplierCode = ""; // 供应商代码
  3934. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3935. string batch_num = GlobalContext.BatchNumber; // 批次号
  3936. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3937. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3938. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3939. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  3940. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  3941. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3942. bool pass = a1Result == 1;
  3943. //根据载具码获取产品码
  3944. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3945. if (string.IsNullOrEmpty(strProductBarcode))
  3946. {
  3947. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3948. }
  3949. sn = strProductBarcode;
  3950. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3951. List<TestItem> items = new List<TestItem>();
  3952. items.Add(new TestItem()
  3953. {
  3954. Parameter_name = "载具码",
  3955. Parameter_value = CarrierBarcode,
  3956. Parameter_unit = ""
  3957. });
  3958. items.Add(new TestItem()
  3959. {
  3960. Parameter_name = "产品码",
  3961. Parameter_value = sn,
  3962. Parameter_unit = ""
  3963. });
  3964. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3965. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3966. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3967. stopwatch2.Start();
  3968. //进站结果写入PLC
  3969. CommandFromPLC resultToPlC = new CommandFromPLC();
  3970. resultToPlC.cmd = 0;
  3971. resultToPlC.cmdParam = 0; //指令参数
  3972. resultToPlC.cmdResult = mesResultFrmWeb;
  3973. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3974. stopwatch2.Stop();
  3975. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3976. //保存PLC返回MES数据到本地
  3977. ResponseMessage message = new ResponseMessage();
  3978. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  3979. if (message.result == false)
  3980. {
  3981. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3982. }
  3983. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3984. if (result1 == 1)
  3985. {
  3986. //载具码解除绑定
  3987. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  3988. if (message.result == false)
  3989. {
  3990. AddMessage(LogType.Error, message.text);
  3991. }
  3992. }
  3993. }
  3994. catch (Exception ex)
  3995. {
  3996. stopwatch2.Start();
  3997. CommandFromPLC resultToPlC = new CommandFromPLC();
  3998. resultToPlC.cmd = 0;
  3999. resultToPlC.cmdParam = 0; //指令参数
  4000. resultToPlC.cmdResult = 110;
  4001. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4002. stopwatch2.Stop();
  4003. string str = ex.StackTrace;
  4004. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4005. }
  4006. stopwatch1.Stop();
  4007. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4008. ProgressState = false;
  4009. }
  4010. #endregion
  4011. #endregion Xiaomi
  4012. #region PLC1 张超凡
  4013. #region [S1] Tray盘上料装备(板测)
  4014. /// <summary>
  4015. /// S1工位的数据- 触发信号上次的值
  4016. /// </summary>
  4017. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4018. /// <summary>
  4019. /// S1工位的数据(含触发信号)
  4020. /// </summary>
  4021. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4022. /// <summary>
  4023. /// S1工位的数据- 回写点位
  4024. /// </summary>
  4025. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4026. ///// <summary>
  4027. ///// 触发信号
  4028. ///// </summary>
  4029. //private ManualResetEvent[] MreTasks;
  4030. /// <summary>
  4031. /// [S1] Tray盘上料装备(板测)
  4032. /// </summary>
  4033. /// <param name="plcNo">PLC编号</param>
  4034. //private void ReadStation_S1(int plcNo)
  4035. //{
  4036. // // [S1] Tray盘上料装备
  4037. // // [S2] FCT
  4038. // // [S3] 值板机
  4039. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4040. // // [S5] Tray盘下料装备
  4041. // string stationCode = "[S1]";
  4042. // string stationName = "Tray盘上料装备";
  4043. // string stationNameStr = stationCode + stationName;
  4044. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4045. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4046. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4047. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4048. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4049. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4050. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4051. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4052. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4053. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4054. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4055. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4056. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4057. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4058. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4059. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4060. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4061. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4062. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4063. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4064. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4065. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4066. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4067. // s1PLCData.Add("a1Result", 0); // 产品结果
  4068. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4069. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4070. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4071. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4072. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4073. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4074. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4075. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4076. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4077. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4078. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4079. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4080. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4081. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4082. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4083. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4084. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4085. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4086. // while (IsRun)
  4087. // {
  4088. // try
  4089. // {
  4090. // if (!GlobalContext._IsCon_Funs1)
  4091. // {
  4092. // UpdatePLCMonitor(1, plcNo, 0);
  4093. // continue;
  4094. // }
  4095. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4096. // {
  4097. // Stopwatch stopwatch1 = new Stopwatch();
  4098. // Stopwatch stopwatch2 = new Stopwatch();
  4099. // stopwatch1.Start();
  4100. // stopwatch2.Start();
  4101. // #region 一次性读取所有数据
  4102. // // 一次性读取所有数据
  4103. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4104. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4105. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4106. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4107. // int[] datas = data1.Concat(data2).ToArray();
  4108. // datas = datas.Concat(data3).ToArray();
  4109. // datas = datas.Concat(data4).ToArray();
  4110. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4111. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4112. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4113. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4114. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4115. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4116. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4117. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4118. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4119. // s1PLCData["a1MES_FLAG"] = datas[109];
  4120. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4121. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4122. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4123. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4124. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4125. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4126. // s1PLCData["a1Result"] = datas[170];
  4127. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4128. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4129. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4130. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4131. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4132. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4133. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4134. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4135. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4136. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4137. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4138. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4139. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4140. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4141. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4142. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4143. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4144. // s1PLCData["a1AGVUpStart"] = datas[308];
  4145. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4146. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4147. // s1PLCData["a1AGVDownStart"] = datas[321];
  4148. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4149. // #endregion 一次性读取所有数据
  4150. // stopwatch2.Stop();
  4151. // #region 回写操作,写后清空flag
  4152. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4153. // #endregion 回写操作,写后清空flag
  4154. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4155. // try
  4156. // {
  4157. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4158. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4159. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4160. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4161. // {
  4162. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4163. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4164. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4165. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4166. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4167. // }
  4168. // }
  4169. // catch (Exception ex)
  4170. // {
  4171. // // 6代表上位机报警
  4172. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4173. // string str = ex.StackTrace;
  4174. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4175. // }
  4176. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4177. // #region 上料进站校验
  4178. // try
  4179. // {
  4180. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4181. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4182. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4183. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4184. // {
  4185. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4186. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4187. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4188. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4189. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4190. // }
  4191. // }
  4192. // catch (Exception ex)
  4193. // {
  4194. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4195. // string str = ex.StackTrace;
  4196. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4197. // }
  4198. // #endregion 上料进站校验
  4199. // #region Tray盘上料装备-出站接口
  4200. // try
  4201. // {
  4202. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4203. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4204. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4205. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4206. // {
  4207. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4208. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4209. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4210. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4211. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4212. // }
  4213. // }
  4214. // catch (Exception ex)
  4215. // {
  4216. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4217. // string str = ex.StackTrace;
  4218. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4219. // }
  4220. // #endregion Tray盘上料装备-出站接口
  4221. // #region Tray盘上料装备-将SN发给ICT标机
  4222. // try
  4223. // {
  4224. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4225. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4226. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4227. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4228. // {
  4229. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4230. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4231. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4232. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4233. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4234. // }
  4235. // }
  4236. // catch (Exception ex)
  4237. // {
  4238. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4239. // string str = ex.StackTrace;
  4240. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4241. // }
  4242. // #endregion Tray盘上料装备-将SN发给ICT标机
  4243. // #region Tray盘上料装备-点检数据
  4244. // //try
  4245. // //{
  4246. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4247. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4248. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4249. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4250. // // if (pLC_Flag && !mES_Flag) // 1 0
  4251. // // {
  4252. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4253. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4254. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4255. // // }
  4256. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4257. // // {
  4258. // // // 清空写给PLC的数据
  4259. // // // MES_Flag重置为0
  4260. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4261. // // }
  4262. // //}
  4263. // //catch (Exception ex)
  4264. // //{
  4265. // // // MES_Flag 为2上位机报错
  4266. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4267. // // string str = ex.StackTrace;
  4268. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4269. // //}
  4270. // #endregion Tray盘上料装备-点检数据
  4271. // #region 节拍接口
  4272. // try
  4273. // {
  4274. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4275. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4276. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4277. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4278. // {
  4279. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4280. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4281. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4282. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4283. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4284. // }
  4285. // }
  4286. // catch (Exception ex)
  4287. // {
  4288. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4289. // string str = ex.StackTrace;
  4290. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4291. // }
  4292. // #endregion 节拍接口
  4293. // #region AGV上料
  4294. // // AGV上料叫AGV信号
  4295. // try
  4296. // {
  4297. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4298. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4299. // if (a1AGVUpCall != a1AGVUpCallOld)
  4300. // {
  4301. // if (a1AGVUpCall == 1) // 0->1
  4302. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4303. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4304. // }
  4305. // }
  4306. // catch (Exception ex)
  4307. // {
  4308. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4309. // string str = ex.StackTrace;
  4310. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4311. // }
  4312. // // AGV上料完成信号
  4313. // try
  4314. // {
  4315. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4316. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4317. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4318. // {
  4319. // if (a1AGVUpEnd == 1) // 0->1
  4320. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4321. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4322. // }
  4323. // }
  4324. // catch (Exception ex)
  4325. // {
  4326. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4327. // string str = ex.StackTrace;
  4328. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4329. // }
  4330. // #endregion AGV上料
  4331. // #region AGV下料
  4332. // // AGV下料叫agv信号
  4333. // try
  4334. // {
  4335. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4336. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4337. // if (a1AGVDownCall != a1AGVDownCallOld)
  4338. // {
  4339. // if (a1AGVDownCall == 1) // 0->1
  4340. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4341. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4342. // }
  4343. // }
  4344. // catch (Exception ex)
  4345. // {
  4346. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4347. // string str = ex.StackTrace;
  4348. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4349. // }
  4350. // // AGV下料完成信号
  4351. // try
  4352. // {
  4353. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4354. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4355. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4356. // {
  4357. // if (a1AGVDownEnd == 1) // 0->1
  4358. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4359. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4360. // }
  4361. // }
  4362. // catch (Exception ex)
  4363. // {
  4364. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4365. // string str = ex.StackTrace;
  4366. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4367. // }
  4368. // #endregion AGV下料
  4369. // #region 心跳
  4370. // try
  4371. // {
  4372. // short states = 0;
  4373. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4374. // }
  4375. // catch (Exception ex)
  4376. // {
  4377. // string str = ex.StackTrace;
  4378. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4379. // }
  4380. // #endregion 心跳
  4381. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4382. // stopwatch1.Stop();
  4383. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4384. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4385. // }
  4386. // else
  4387. // {
  4388. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4389. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4390. // Funs[plcNo].Connect(); // 重连
  4391. // }
  4392. // }
  4393. // catch (Exception ex)
  4394. // {
  4395. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4396. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4397. // Funs[plcNo].ReConnect();
  4398. // }
  4399. // Thread.Sleep(IntervalReadPLC);
  4400. // }
  4401. //}
  4402. /// <summary>
  4403. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4404. /// </summary>
  4405. /// <param name="plcNo">PLC编号</param>
  4406. /// <param name="stationNameStr">工站全称</param>
  4407. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4408. {
  4409. Stopwatch stopwatch1 = new Stopwatch();
  4410. Stopwatch stopwatch2 = new Stopwatch();
  4411. try
  4412. {
  4413. stopwatch1.Start();
  4414. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4415. sn = sn.Replace("\0", "");
  4416. #region 查询载具上的产品信息
  4417. string cavityData = string.Empty;
  4418. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4419. if (string.IsNullOrEmpty(cavityData))
  4420. cavityData = "";
  4421. if (snResult != 0)
  4422. {
  4423. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4424. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4425. writeToPLC_Flag1.Adress = 2003;
  4426. writeToPLC_Flag1.Value = (short)6;
  4427. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4428. stopwatch1.Stop();
  4429. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4430. return;
  4431. }
  4432. #endregion 查询载具上的产品信息
  4433. string[] cavitySNs = cavityData.Split('.');
  4434. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4435. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4436. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4437. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4438. if (cavitySNs != null && cavitySNs.Length >= 2)
  4439. {
  4440. a1CavitySN1_VehicleStates = cavitySNs[0];
  4441. a1CavitySN2_VehicleStates = cavitySNs[1];
  4442. a1CavityResult1_VehicleStates = 2;
  4443. a1CavityResult2_VehicleStates = 2;
  4444. }
  4445. if (a1CavitySN1_VehicleStates == "假产品")
  4446. a1CavityResult1_VehicleStates = 3;
  4447. if (a1CavitySN2_VehicleStates == "假产品")
  4448. a1CavityResult2_VehicleStates = 3;
  4449. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4450. // 回写
  4451. stopwatch2.Start();
  4452. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4453. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4454. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4455. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4456. //// MES_Flag
  4457. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4458. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4459. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4460. writeToPLC_Flag.Adress = 2003;
  4461. writeToPLC_Flag.Value = mES_Flag;
  4462. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4463. {
  4464. Name = "a1CavitySN1_VehicleStates",
  4465. Adress = 2024,
  4466. ValueType = PLCValueType.String,
  4467. ValueTypeStrLength = 20,
  4468. Value = a1CavitySN1_VehicleStates
  4469. });
  4470. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4471. {
  4472. Name = "a1CavitySN2_VehicleStates",
  4473. Adress = 2044,
  4474. ValueType = PLCValueType.String,
  4475. ValueTypeStrLength = 20,
  4476. Value = a1CavitySN2_VehicleStates
  4477. });
  4478. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4479. {
  4480. Name = "a1CavityResult1_VehicleStates",
  4481. Adress = 2064,
  4482. ValueType = PLCValueType.Short,
  4483. Value = a1CavityResult1_VehicleStates
  4484. });
  4485. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4486. {
  4487. Name = "a1CavityResult2_VehicleStates",
  4488. Adress = 2065,
  4489. ValueType = PLCValueType.Short,
  4490. Value = a1CavityResult2_VehicleStates
  4491. });
  4492. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4493. stopwatch2.Stop();
  4494. }
  4495. catch (Exception ex)
  4496. {
  4497. string str = ex.StackTrace;
  4498. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4499. // MES_Flag
  4500. stopwatch2.Start();
  4501. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4502. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4503. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4504. writeToPLC_Flag.Adress = 2003;
  4505. writeToPLC_Flag.Value = (short)6;
  4506. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4507. stopwatch2.Stop();
  4508. }
  4509. stopwatch1.Stop();
  4510. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4511. }
  4512. /// <summary>
  4513. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4514. /// </summary>
  4515. /// <param name="plcNo">PLC编号</param>
  4516. /// <param name="stationNameStr">工站全称</param>
  4517. private void S1上料进站校验(int plcNo, string stationNameStr)
  4518. {
  4519. Stopwatch stopwatch1 = new Stopwatch();
  4520. Stopwatch stopwatch2 = new Stopwatch();
  4521. try
  4522. {
  4523. stopwatch1.Start();
  4524. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4525. sn = sn.Replace("\0", "");
  4526. // 保存进站数据+调用进站MES接口
  4527. List<TestItem> item = new List<TestItem>();
  4528. stopwatch2.Start();
  4529. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4530. stopwatch2.Stop();
  4531. short a1MES_FLAG_Check = (short)result;
  4532. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4533. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4534. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4535. writeToPLC_Flag.Adress = 2077;
  4536. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4537. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4538. }
  4539. catch (Exception ex)
  4540. {
  4541. string str = ex.StackTrace;
  4542. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4543. // MES_Flag
  4544. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4545. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4546. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4547. writeToPLC_Flag.Adress = 2077;
  4548. writeToPLC_Flag.Value = (short)6;
  4549. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4550. }
  4551. stopwatch1.Stop();
  4552. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4553. }
  4554. /// <summary>
  4555. /// [S1] Tray盘上料装备(板测)- 出站接口
  4556. /// </summary>
  4557. /// <param name="plcNo"></param>
  4558. /// <param name="stationCode"></param>
  4559. /// <param name="stationName"></param>
  4560. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4561. {
  4562. Stopwatch stopwatch1 = new Stopwatch();
  4563. Stopwatch stopwatch2 = new Stopwatch();
  4564. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4565. string stationNameStr = stationCode + stationName;
  4566. string processItem = stationName; // 测试项目
  4567. try
  4568. {
  4569. stopwatch1.Start();
  4570. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4571. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4572. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4573. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4574. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4575. sn = sn.Replace("\0", "");
  4576. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4577. partNo1 = partNo1.Replace("\0", "");
  4578. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4579. partNo2 = partNo2.Replace("\0", "");
  4580. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4581. bool pass = a1Result == 1;
  4582. stopwatch2.Start();
  4583. // 产品1
  4584. List<TestItem> items = new List<TestItem>();
  4585. items.Add(new TestItem()
  4586. {
  4587. Parameter_name = "载具码",
  4588. Parameter_value = sn,
  4589. Parameter_unit = ""
  4590. });
  4591. items.Add(new TestItem()
  4592. {
  4593. Parameter_name = "载具穴号",
  4594. Parameter_value = "1",
  4595. Parameter_unit = ""
  4596. });
  4597. items.Add(new TestItem()
  4598. {
  4599. Parameter_name = "产品结果",
  4600. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4601. Parameter_unit = ""
  4602. });
  4603. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4604. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4605. // 产品2
  4606. items = new List<TestItem>();
  4607. items.Add(new TestItem()
  4608. {
  4609. Parameter_name = "载具码",
  4610. Parameter_value = sn,
  4611. Parameter_unit = ""
  4612. });
  4613. items.Add(new TestItem()
  4614. {
  4615. Parameter_name = "载具穴号",
  4616. Parameter_value = "2",
  4617. Parameter_unit = ""
  4618. });
  4619. items.Add(new TestItem()
  4620. {
  4621. Parameter_name = "产品结果",
  4622. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4623. Parameter_unit = ""
  4624. });
  4625. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4626. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4627. short result = 0;
  4628. List<int> results = new List<int>() { result1, result2 };
  4629. if (result1 == 1 && result2 == 1)
  4630. result = 1;
  4631. else if (results.Contains(3))
  4632. result = 3;
  4633. else if (results.Contains(2))
  4634. result = 2;
  4635. else if (results.Contains(4))
  4636. result = 4;
  4637. else
  4638. result = 4;
  4639. stopwatch2.Stop();
  4640. #region 存储绑定数据到 边线MES系统中
  4641. if (result == 1)
  4642. {
  4643. string data = string.Concat(partNo1, ".", partNo2);
  4644. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4645. if (resultMesR != 0)
  4646. {
  4647. result = 4;
  4648. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4649. }
  4650. }
  4651. #endregion 存储绑定数据到 边线MES系统中
  4652. // MES_Flag 为MES报错
  4653. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4654. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4655. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4656. writeToPLC_Flag.Name = "a1MES_FLAG";
  4657. writeToPLC_Flag.Adress = 2109;
  4658. writeToPLC_Flag.Value = result;
  4659. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4660. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4661. }
  4662. catch (Exception ex)
  4663. {
  4664. stopwatch2.Restart();
  4665. // MES_Flag 为4上位机报错
  4666. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4667. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4668. writeToPLC_Flag.Name = "a1MES_FLAG";
  4669. writeToPLC_Flag.Adress = 2109;
  4670. writeToPLC_Flag.Value = (short)4;
  4671. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4672. stopwatch2.Stop();
  4673. string str = ex.StackTrace;
  4674. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4675. }
  4676. stopwatch1.Stop();
  4677. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4678. }
  4679. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4680. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4681. //{
  4682. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4683. // string stationNameStr = stationCode + stationName;
  4684. // string processItem = stationName; // 测试项目
  4685. // try
  4686. // {
  4687. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4688. // string accno = "1"; // 工序编号
  4689. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4690. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4691. // List<OneCheckItem> items = new List<OneCheckItem>()
  4692. // {
  4693. // new OneCheckItem()
  4694. // {
  4695. // Onecheck_name="胶圈装配行程设定上限",
  4696. // Onecheck_content="上限值",
  4697. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4698. // },
  4699. // };
  4700. // OneCheckData oneCheckData = new OneCheckData()
  4701. // {
  4702. // Line_code = GlobalContext.LineCode,
  4703. // Line_name = GlobalContext.LineName,
  4704. // Equipment_code = equipmentCode,
  4705. // Equipment_name = equipmentCode,
  4706. // Workorder_code = workorder_code,
  4707. // Procedure_code = accno,
  4708. // Procedure_name = processItem,
  4709. // Oneckeck_values = items,
  4710. // Onecheck_empcode = "",
  4711. // Onecheck_empname = "",
  4712. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4713. // };
  4714. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4715. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4716. // short result = result1 == 1 ? (short)1 : (short)2;
  4717. // // MES_Flag 为4MES报错
  4718. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4719. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4720. // }
  4721. // catch (Exception ex)
  4722. // {
  4723. // // MES_Flag 为2上位机报错
  4724. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4725. // string str = ex.StackTrace;
  4726. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4727. // }
  4728. //}
  4729. // ReadStation_S1_2 节拍接口+AGV
  4730. /// <summary>
  4731. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4732. /// </summary>
  4733. /// <param name="plcNo">PLC编号</param>
  4734. /// <param name="stationNameStr">工站全称</param>
  4735. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4736. {
  4737. Stopwatch stopwatch1 = new Stopwatch();
  4738. Stopwatch stopwatch2 = new Stopwatch();
  4739. try
  4740. {
  4741. stopwatch1.Start();
  4742. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4743. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4744. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4745. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4746. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4747. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4748. // ZS 将SN发给ICT标机(串口)
  4749. short a1MES_FLAG_ICT = 1;
  4750. stopwatch2.Start();
  4751. // MES_Flag
  4752. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4753. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4754. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4755. writeToPLC_Flag.Adress = 2182;
  4756. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4757. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4758. stopwatch2.Stop();
  4759. }
  4760. catch (Exception ex)
  4761. {
  4762. string str = ex.StackTrace;
  4763. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4764. stopwatch2.Start();
  4765. // MES_Flag
  4766. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4767. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4768. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4769. writeToPLC_Flag.Adress = 2182;
  4770. writeToPLC_Flag.Value = (short)4;
  4771. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4772. stopwatch2.Stop();
  4773. }
  4774. stopwatch1.Stop();
  4775. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4776. }
  4777. /// <summary>
  4778. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4779. /// </summary>
  4780. /// <param name="plcNo">PLC编号</param>
  4781. /// <param name="stationNameStr">工站全称</param>
  4782. private void S1节拍接口(int plcNo, string stationNameStr)
  4783. {
  4784. Stopwatch stopwatch1 = new Stopwatch();
  4785. Stopwatch stopwatch2 = new Stopwatch();
  4786. string resultStr = string.Empty;
  4787. try
  4788. {
  4789. stopwatch1.Start();
  4790. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4791. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4792. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4793. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4794. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4795. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4796. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  4797. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4798. if (!actionBool)
  4799. {
  4800. stopwatch2.Start();
  4801. // MES_Flag
  4802. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4803. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4804. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  4805. writeToPLC_Flag1.Adress = 2254;
  4806. writeToPLC_Flag1.Value = (short)1;
  4807. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  4808. stopwatch2.Stop();
  4809. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4810. return;
  4811. }
  4812. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  4813. {
  4814. stopwatch2.Start();
  4815. // MES_Flag
  4816. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4817. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  4818. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  4819. writeToPLC_Flag2.Adress = 2254;
  4820. writeToPLC_Flag2.Value = (short)1;
  4821. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  4822. stopwatch2.Stop();
  4823. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4824. return;
  4825. }
  4826. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  4827. { // 查产品SN
  4828. a1OEEPartNo = "Test"; // ZS
  4829. }
  4830. short a1OEEMES_FLAG = 0;
  4831. // 上传OEE
  4832. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  4833. a1OEEMES_FLAG = result.Item1;
  4834. resultStr = result.Item2;
  4835. stopwatch2.Start();
  4836. // MES_Flag
  4837. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4838. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4839. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4840. writeToPLC_Flag.Adress = 2254;
  4841. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  4842. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4843. stopwatch2.Stop();
  4844. }
  4845. catch (Exception ex)
  4846. {
  4847. string str = ex.StackTrace;
  4848. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4849. // MES_Flag
  4850. stopwatch2.Start();
  4851. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4852. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4853. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4854. writeToPLC_Flag.Adress = 2254;
  4855. writeToPLC_Flag.Value = (short)4;
  4856. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4857. stopwatch2.Stop();
  4858. }
  4859. stopwatch1.Stop();
  4860. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4861. }
  4862. /// <summary>
  4863. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  4864. /// </summary>
  4865. /// <param name="plcNo">PLC编号</param>
  4866. /// <param name="stationNameStr">工站全称</param>
  4867. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  4868. {
  4869. Stopwatch stopwatch1 = new Stopwatch();
  4870. Stopwatch stopwatch2 = new Stopwatch();
  4871. try
  4872. {
  4873. stopwatch1.Start();
  4874. // ZS 呼叫AGV
  4875. short a1AGVUpCall = 2;
  4876. stopwatch2.Start();
  4877. // a1AGVUpCall
  4878. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4879. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4880. writeToPLC_Flag.Name = "a1AGVUpCall";
  4881. writeToPLC_Flag.Adress = 2307;
  4882. writeToPLC_Flag.Value = a1AGVUpCall;
  4883. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4884. stopwatch2.Stop();
  4885. }
  4886. catch (Exception ex)
  4887. {
  4888. string str = ex.StackTrace;
  4889. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4890. // a1AGVUpCall
  4891. stopwatch2.Start();
  4892. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4893. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4894. writeToPLC_Flag.Name = "a1AGVUpCall";
  4895. writeToPLC_Flag.Adress = 2307;
  4896. writeToPLC_Flag.Value = (short)4;
  4897. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4898. stopwatch2.Stop();
  4899. }
  4900. stopwatch1.Stop();
  4901. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4902. }
  4903. /// <summary>
  4904. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  4905. /// </summary>
  4906. /// <param name="plcNo">PLC编号</param>
  4907. /// <param name="stationNameStr">工站全称</param>
  4908. private void S1AGV上料完成(int plcNo, string stationNameStr)
  4909. {
  4910. Stopwatch stopwatch1 = new Stopwatch();
  4911. Stopwatch stopwatch2 = new Stopwatch();
  4912. try
  4913. {
  4914. stopwatch1.Start();
  4915. // ZS AGV上料完成,让小车离开
  4916. short a1AGVUpEnd = 2;
  4917. stopwatch2.Start();
  4918. // a1AGVUpEnd
  4919. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4920. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4921. writeToPLC_Flag.Name = "a1AGVUpEnd";
  4922. writeToPLC_Flag.Adress = 2309;
  4923. writeToPLC_Flag.Value = a1AGVUpEnd;
  4924. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  4925. stopwatch2.Stop();
  4926. }
  4927. catch (Exception ex)
  4928. {
  4929. string str = ex.StackTrace;
  4930. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4931. // a1AGVUpEnd
  4932. stopwatch2.Start();
  4933. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4934. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4935. writeToPLC_Flag.Name = "a1AGVUpEnd";
  4936. writeToPLC_Flag.Adress = 2309;
  4937. writeToPLC_Flag.Value = (short)4;
  4938. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  4939. stopwatch2.Stop();
  4940. }
  4941. stopwatch1.Stop();
  4942. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4943. }
  4944. /// <summary>
  4945. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  4946. /// </summary>
  4947. /// <param name="plcNo">PLC编号</param>
  4948. /// <param name="stationNameStr">工站全称</param>
  4949. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  4950. {
  4951. Stopwatch stopwatch1 = new Stopwatch();
  4952. Stopwatch stopwatch2 = new Stopwatch();
  4953. try
  4954. {
  4955. stopwatch1.Start();
  4956. // ZS 呼叫AGV
  4957. short a1AGVDownCall = 2;
  4958. stopwatch2.Start();
  4959. // a1AGVDownCall
  4960. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4961. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4962. writeToPLC_Flag.Name = "a1AGVDownCall";
  4963. writeToPLC_Flag.Adress = 2320;
  4964. writeToPLC_Flag.Value = a1AGVDownCall;
  4965. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  4966. stopwatch2.Stop();
  4967. }
  4968. catch (Exception ex)
  4969. {
  4970. string str = ex.StackTrace;
  4971. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4972. // a1AGVDownCall
  4973. stopwatch2.Start();
  4974. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4975. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4976. writeToPLC_Flag.Name = "a1AGVDownCall";
  4977. writeToPLC_Flag.Adress = 2320;
  4978. writeToPLC_Flag.Value = (short)4;
  4979. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  4980. stopwatch2.Stop();
  4981. }
  4982. stopwatch1.Stop();
  4983. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4984. }
  4985. /// <summary>
  4986. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  4987. /// </summary>
  4988. /// <param name="plcNo">PLC编号</param>
  4989. /// <param name="stationNameStr">工站全称</param>
  4990. private void S1AGV下料完成(int plcNo, string stationNameStr)
  4991. {
  4992. Stopwatch stopwatch1 = new Stopwatch();
  4993. Stopwatch stopwatch2 = new Stopwatch();
  4994. try
  4995. {
  4996. stopwatch1.Start();
  4997. // ZS AGV上料完成,让小车离开
  4998. short a1AGVDownEnd = 2;
  4999. stopwatch2.Start();
  5000. // a1AGVDownEnd
  5001. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5002. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5003. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5004. writeToPLC_Flag.Adress = 2322;
  5005. writeToPLC_Flag.Value = a1AGVDownEnd;
  5006. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5007. stopwatch2.Stop();
  5008. }
  5009. catch (Exception ex)
  5010. {
  5011. string str = ex.StackTrace;
  5012. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5013. // a1AGVDownEnd
  5014. stopwatch2.Start();
  5015. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5016. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5017. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5018. writeToPLC_Flag.Adress = 2322;
  5019. writeToPLC_Flag.Value = (short)4;
  5020. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5021. stopwatch2.Stop();
  5022. }
  5023. stopwatch1.Stop();
  5024. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5025. }
  5026. #endregion [S1] Tray盘上料装备(板测)
  5027. #endregion PLC1 张超凡
  5028. #region PLC2 李晓奇
  5029. #region [S2] FCT(板测)
  5030. /// <summary>
  5031. /// S2工位的数据- 触发信号上次的值
  5032. /// </summary>
  5033. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5034. /// <summary>
  5035. /// S2工位的数据(含触发信号)
  5036. /// </summary>
  5037. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5038. /// <summary>
  5039. /// S2工位的数据- 回写点位
  5040. /// </summary>
  5041. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5042. /// <summary>
  5043. /// [S2] FCT(板测)
  5044. /// </summary>
  5045. /// <param name="plcNo">PLC编号</param>
  5046. //private void ReadStation_S2(int plcNo)
  5047. //{
  5048. // // [S1] Tray盘上料装备
  5049. // // [S2] FCT
  5050. // // [S3] 值板机
  5051. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5052. // // [S5] Tray盘下料装备
  5053. // /// 上位机心跳
  5054. // /// 获取设备报警数据与状态信息
  5055. // string stationCode = "[S2]";
  5056. // string stationName = "FCT";
  5057. // string stationNameStr = stationCode + stationName;
  5058. // #region 创建字典
  5059. // // 触发信号字典 赋值
  5060. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5061. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5062. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5063. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5064. // // PLC数据字典 赋值
  5065. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5066. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5067. // s2PLCData.Add("b1ProductSN_Check", 0);
  5068. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5069. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5070. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5071. // s2PLCData.Add("b1ProductSN_Bind", "");
  5072. // s2PLCData.Add("b1Part1SN_Bind", "");
  5073. // s2PLCData.Add("b1Part2SN_Bind", "");
  5074. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5075. // s2PLCData.Add("b1MES_FLAG", 0);
  5076. // s2PLCData.Add("b1ProductSN", 0);
  5077. // s2PLCData.Add("b1Part1Result", 0);
  5078. // s2PLCData.Add("b1Part2Result", 0);
  5079. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5080. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5081. // s2PLCData.Add("b1OEEProductSN", "");
  5082. // s2PLCData.Add("b1OEEType", 0);
  5083. // #endregion 创建字典
  5084. // while (IsRun)
  5085. // {
  5086. // try
  5087. // {
  5088. // if (!GlobalContext._IsCon_Funs2)
  5089. // {
  5090. // UpdatePLCMonitor(1, plcNo, 0);
  5091. // continue;
  5092. // }
  5093. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5094. // {
  5095. // Stopwatch stopwatch1 = new Stopwatch();
  5096. // Stopwatch stopwatch2 = new Stopwatch();
  5097. // stopwatch1.Start();
  5098. // stopwatch2.Start();
  5099. // #region 一次性读取所有数据
  5100. // // 一次性读取所有数据
  5101. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5102. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5103. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5104. // int[] datas = data1.Concat(data2).ToArray();
  5105. // datas = datas.Concat(data3).ToArray();
  5106. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5107. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5108. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5109. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5110. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5111. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5112. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5113. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5114. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5115. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5116. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5117. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5118. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5119. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5120. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5121. // s2PLCData["b1MES_FLAG"] = datas[169];
  5122. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5123. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5124. // s2PLCData["b1Part1Result"] = datas[190];
  5125. // s2PLCData["b1Part2Result"] = datas[191];
  5126. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5127. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5128. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5129. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5130. // s2PLCData["b1OEEType"] = datas[224];
  5131. // #endregion 一次性读取所有数据
  5132. // stopwatch2.Stop();
  5133. // #region 回写操作,写后清空flag
  5134. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5135. // #endregion 回写操作,写后清空flag
  5136. // #region 进站校验
  5137. // try
  5138. // {
  5139. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5140. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5141. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5142. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5143. // {
  5144. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5145. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5146. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5147. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5148. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5149. // }
  5150. // }
  5151. // catch (Exception ex)
  5152. // {
  5153. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5154. // string str = ex.StackTrace;
  5155. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5156. // }
  5157. // #endregion 进站校验
  5158. // #region 二穴载具解绑/绑定(产品换载具)
  5159. // try
  5160. // {
  5161. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5162. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5163. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5164. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5165. // {
  5166. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5167. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5168. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5169. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5170. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5171. // }
  5172. // }
  5173. // catch (Exception ex)
  5174. // {
  5175. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5176. // string str = ex.StackTrace;
  5177. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5178. // }
  5179. // #endregion 二穴载具解绑/绑定(产品换载具)
  5180. // #region FCT-出站接口
  5181. // try
  5182. // {
  5183. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5184. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5185. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5186. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5187. // {
  5188. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5189. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5190. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5191. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5192. // }
  5193. // }
  5194. // catch (Exception ex)
  5195. // {
  5196. // // MES_Flag 为6上位机报错
  5197. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5198. // string str = ex.StackTrace;
  5199. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5200. // }
  5201. // #endregion FCT-出站接口
  5202. // #region 节拍接口
  5203. // try
  5204. // {
  5205. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5206. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5207. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5208. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5209. // {
  5210. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5211. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5212. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5213. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5214. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5215. // }
  5216. // }
  5217. // catch (Exception ex)
  5218. // {
  5219. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5220. // string str = ex.StackTrace;
  5221. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5222. // }
  5223. // #endregion 节拍接口
  5224. // #region 心跳
  5225. // try
  5226. // {
  5227. // short states = 0;
  5228. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5229. // }
  5230. // catch (Exception ex)
  5231. // {
  5232. // string str = ex.StackTrace;
  5233. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5234. // }
  5235. // #endregion 心跳
  5236. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5237. // stopwatch1.Stop();
  5238. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5239. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5240. // }
  5241. // else
  5242. // {
  5243. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5244. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5245. // Funs[plcNo].Connect();
  5246. // }
  5247. // }
  5248. // catch (Exception ex)
  5249. // {
  5250. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5251. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5252. // Funs[plcNo].ReConnect();
  5253. // }
  5254. // Thread.Sleep(IntervalReadPLC);
  5255. // }
  5256. //}
  5257. /// <summary>
  5258. /// [S2] FCT(板测)- 进站校验
  5259. /// </summary>
  5260. /// <param name="plcNo">PLC编号</param>
  5261. /// <param name="stationNameStr">工站全称</param>
  5262. private void S2进站校验(int plcNo, string stationNameStr)
  5263. {
  5264. Stopwatch stopwatch1 = new Stopwatch();
  5265. Stopwatch stopwatch2 = new Stopwatch();
  5266. try
  5267. {
  5268. stopwatch1.Start();
  5269. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5270. sn = sn.Replace("\0", "");
  5271. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5272. // 查询物料码By载具码 并判断是不是假产品
  5273. string cavityData = string.Empty;
  5274. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5275. if (string.IsNullOrEmpty(cavityData))
  5276. cavityData = "";
  5277. if (snResult != 0)
  5278. {
  5279. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5280. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5281. writeToPLC_Flag1.Adress = 2003;
  5282. writeToPLC_Flag1.Value = (short)6;
  5283. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5284. stopwatch1.Stop();
  5285. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5286. return;
  5287. }
  5288. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5289. string[] cavitySNs = cavityData.Split('.');
  5290. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5291. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5292. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5293. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5294. if (cavitySNs != null && cavitySNs.Length >= 2)
  5295. {
  5296. b1Part1SN_Check = cavitySNs[0];
  5297. b1Part2SN_Check = cavitySNs[1];
  5298. b1Part1Result_Check = 2;
  5299. b1Part2Result_Check = 2;
  5300. }
  5301. if (b1Part1SN_Check == "假产品")
  5302. b1Part1Result_Check = 3;
  5303. if (b1Part2SN_Check == "假产品")
  5304. b1Part2Result_Check = 3;
  5305. // 调用MES进站
  5306. stopwatch2.Start();
  5307. // 调用MES进站 - 产品1
  5308. List<TestItem> item;
  5309. int result1 = b1Part1Result_Check;
  5310. if (result1 != 3)
  5311. {
  5312. item = new List<TestItem>();
  5313. item.Add(new TestItem()
  5314. {
  5315. Parameter_name = "载具码",
  5316. Parameter_value = sn,
  5317. });
  5318. item.Add(new TestItem()
  5319. {
  5320. Parameter_name = "载具穴号",
  5321. Parameter_value = "1",
  5322. });
  5323. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5324. }
  5325. // 调用MES进站 - 产品2
  5326. int result2 = b1Part2Result_Check;
  5327. if (result2 != 3)
  5328. {
  5329. item = new List<TestItem>();
  5330. item.Add(new TestItem()
  5331. {
  5332. Parameter_name = "载具码",
  5333. Parameter_value = sn,
  5334. });
  5335. item.Add(new TestItem()
  5336. {
  5337. Parameter_name = "载具穴号",
  5338. Parameter_value = "2",
  5339. });
  5340. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5341. }
  5342. stopwatch2.Stop();
  5343. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5344. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5345. int result = result1;
  5346. if (result == 1)
  5347. result = result2;
  5348. short b1MES_FLAG_Check = (short)result;
  5349. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5350. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5351. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5352. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5353. //// MES_Flag
  5354. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5355. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5356. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5357. writeToPLC_Flag.Adress = 2003;
  5358. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5359. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5360. {
  5361. Name = "b1Part1SN_Check",
  5362. Adress = 2024,
  5363. ValueType = PLCValueType.String,
  5364. ValueTypeStrLength = 20,
  5365. Value = b1Part1SN_Check
  5366. });
  5367. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5368. {
  5369. Name = "b1Part2SN_Check",
  5370. Adress = 2044,
  5371. ValueType = PLCValueType.String,
  5372. ValueTypeStrLength = 20,
  5373. Value = b1Part2SN_Check
  5374. });
  5375. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5376. {
  5377. Name = "b1Part1Result_Check",
  5378. Adress = 2064,
  5379. ValueType = PLCValueType.Short,
  5380. Value = b1Part1Result_Check
  5381. });
  5382. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5383. {
  5384. Name = "b1Part2Result_Check",
  5385. Adress = 2065,
  5386. ValueType = PLCValueType.Short,
  5387. Value = b1Part2Result_Check
  5388. });
  5389. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5390. }
  5391. catch (Exception ex)
  5392. {
  5393. string str = ex.StackTrace;
  5394. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5395. // MES_Flag
  5396. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5397. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5398. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5399. writeToPLC_Flag.Adress = 2003;
  5400. writeToPLC_Flag.Value = (short)6;
  5401. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5402. }
  5403. stopwatch1.Stop();
  5404. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5405. }
  5406. /// <summary>
  5407. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5408. /// </summary>
  5409. /// <param name="plcNo">PLC编号</param>
  5410. /// <param name="stationNameStr">工站全称</param>
  5411. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5412. {
  5413. Stopwatch stopwatch1 = new Stopwatch();
  5414. Stopwatch stopwatch2 = new Stopwatch();
  5415. try
  5416. {
  5417. stopwatch1.Start();
  5418. // 产品换载具
  5419. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5420. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5421. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5422. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5423. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5424. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5425. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5426. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5427. stopwatch2.Start();
  5428. #region 查询载具上的产品信息
  5429. //string cavityData = string.Empty;
  5430. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5431. //if (string.IsNullOrEmpty(cavityData))
  5432. // cavityData = "";
  5433. //if (snResult != 0)
  5434. //{
  5435. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5436. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5437. // writeToPLC_Flag.Adress = 2077;
  5438. // writeToPLC_Flag.Value = (short)6;
  5439. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5440. // stopwatch1.Stop();
  5441. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5442. // return;
  5443. //}
  5444. #endregion 查询载具上的产品信息
  5445. #region 解绑(边线MES系统)
  5446. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5447. if (snResult != 0)
  5448. {
  5449. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5450. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5451. writeToPLC_Flag1.Adress = 2077;
  5452. writeToPLC_Flag1.Value = (short)6;
  5453. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5454. stopwatch1.Stop();
  5455. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5456. return;
  5457. }
  5458. #endregion 解绑(边线MES系统)
  5459. #region 存储绑定数据到 边线MES系统中
  5460. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5461. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5462. if (snResult != 0)
  5463. {
  5464. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5465. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5466. writeToPLC_Flag1.Adress = 2077;
  5467. writeToPLC_Flag1.Value = (short)6;
  5468. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5469. stopwatch1.Stop();
  5470. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5471. return;
  5472. }
  5473. #endregion 存储绑定数据到 边线MES系统中
  5474. stopwatch2.Stop();
  5475. short b1MES_FLAG_Unbind = 1;
  5476. // MES_Flag
  5477. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5478. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5479. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5480. writeToPLC_Flag.Adress = 2077;
  5481. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5482. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5483. }
  5484. catch (Exception ex)
  5485. {
  5486. string str = ex.StackTrace;
  5487. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5488. // MES_Flag
  5489. stopwatch2.Start();
  5490. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5491. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5492. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5493. writeToPLC_Flag.Adress = 2077;
  5494. writeToPLC_Flag.Value = (short)6;
  5495. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5496. stopwatch2.Stop();
  5497. }
  5498. stopwatch1.Stop();
  5499. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5500. }
  5501. //// 上次采集到的SN
  5502. //private string sn_FCT = string.Empty;
  5503. /// <summary>
  5504. /// [S2] FCT(板测)- 出站数据
  5505. /// </summary>
  5506. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5507. {
  5508. Stopwatch stopwatch1 = new Stopwatch();
  5509. Stopwatch stopwatch2 = new Stopwatch();
  5510. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5511. string stationNameStr = stationCode + stationName;
  5512. string processItem = stationName; // 测试项目
  5513. try
  5514. {
  5515. stopwatch1.Start();
  5516. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5517. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5518. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5519. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5520. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5521. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5522. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5523. bool pass1 = b1Part1Result == 1;
  5524. bool pass2 = b1Part2Result == 1;
  5525. #region 根据 载具SN 查 物料SN
  5526. string cavityData = string.Empty;
  5527. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5528. if (string.IsNullOrEmpty(cavityData))
  5529. cavityData = "";
  5530. if (snResult != 0)
  5531. {
  5532. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5533. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5534. writeToPLC_Flag1.Adress = 2169;
  5535. writeToPLC_Flag1.Value = (short)4;
  5536. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5537. stopwatch1.Stop();
  5538. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5539. return;
  5540. }
  5541. #endregion 根据 载具SN 查 物料SN
  5542. string[] cavitySNs = cavityData.Split('.');
  5543. string b1ProductSN1 = string.Empty;
  5544. string b1ProductSN2 = string.Empty;
  5545. if (cavitySNs != null && cavitySNs.Length >= 2)
  5546. {
  5547. b1ProductSN1 = cavitySNs[0];
  5548. b1ProductSN2 = cavitySNs[1];
  5549. }
  5550. stopwatch2.Start();
  5551. // 产品1
  5552. int result1 = 0;
  5553. if (b1ProductSN1 == "假产品")
  5554. result1 = 1;
  5555. else
  5556. {
  5557. List<TestItem> items1 = new List<TestItem>();
  5558. items1.Add(new TestItem()
  5559. {
  5560. Parameter_name = "载具码",
  5561. Parameter_value = b1ProductSN.ToString(),
  5562. Parameter_unit = ""
  5563. });
  5564. items1.Add(new TestItem()
  5565. {
  5566. Parameter_name = "载具穴号",
  5567. Parameter_value = "1",
  5568. Parameter_unit = ""
  5569. });
  5570. items1.Add(new TestItem()
  5571. {
  5572. Parameter_name = "产品结果",
  5573. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5574. Parameter_unit = ""
  5575. });
  5576. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5577. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5578. }
  5579. // 产品2
  5580. int result2 = 0;
  5581. if (b1ProductSN1 == "假产品")
  5582. result2 = 1;
  5583. else
  5584. {
  5585. List<TestItem> items2 = new List<TestItem>();
  5586. items2.Add(new TestItem()
  5587. {
  5588. Parameter_name = "载具码",
  5589. Parameter_value = b1ProductSN.ToString(),
  5590. Parameter_unit = ""
  5591. });
  5592. items2.Add(new TestItem()
  5593. {
  5594. Parameter_name = "载具穴号",
  5595. Parameter_value = "2",
  5596. Parameter_unit = ""
  5597. });
  5598. items2.Add(new TestItem()
  5599. {
  5600. Parameter_name = "产品结果",
  5601. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5602. Parameter_unit = ""
  5603. });
  5604. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5605. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5606. }
  5607. short result = 0;
  5608. List<int> results = new List<int>() { result1, result2 };
  5609. if (result1 == 1 && result2 == 1)
  5610. result = 1;
  5611. else if (results.Contains(3))
  5612. result = 3;
  5613. else if (results.Contains(2))
  5614. result = 2;
  5615. else if (results.Contains(4))
  5616. result = 4;
  5617. else
  5618. result = 4;
  5619. stopwatch2.Stop();
  5620. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5621. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5622. writeToPLC_Flag.Name = "b1MES_FLAG";
  5623. writeToPLC_Flag.Adress = 2169;
  5624. writeToPLC_Flag.Value = result;
  5625. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5626. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5627. }
  5628. catch (Exception ex)
  5629. {
  5630. stopwatch2.Restart();
  5631. // MES_Flag 为4上位机报错
  5632. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5633. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5634. writeToPLC_Flag.Name = "b1MES_FLAG";
  5635. writeToPLC_Flag.Adress = 2169;
  5636. writeToPLC_Flag.Value = (short)4;
  5637. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5638. stopwatch2.Stop();
  5639. string str = ex.StackTrace;
  5640. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5641. }
  5642. stopwatch1.Stop();
  5643. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5644. }
  5645. /// <summary>
  5646. /// [S2] FCT(板测)- 节拍接口
  5647. /// </summary>
  5648. /// <param name="plcNo">PLC编号</param>
  5649. /// <param name="stationNameStr">工站全称</param>
  5650. private void S2节拍接口(int plcNo, string stationNameStr)
  5651. {
  5652. Stopwatch stopwatch1 = new Stopwatch();
  5653. Stopwatch stopwatch2 = new Stopwatch();
  5654. string resultStr = string.Empty;
  5655. try
  5656. {
  5657. stopwatch1.Start();
  5658. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5659. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5660. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5661. if (!actionBool)
  5662. {
  5663. stopwatch2.Start();
  5664. // MES_Flag
  5665. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5666. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5667. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5668. writeToPLC_Flag1.Adress = 2203;
  5669. writeToPLC_Flag1.Value = (short)4;
  5670. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5671. stopwatch2.Stop();
  5672. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5673. return;
  5674. }
  5675. string b1OEEPartNo = string.Empty; // 物料码
  5676. if (string.IsNullOrEmpty(b1OEEProductSN))
  5677. {
  5678. stopwatch2.Start();
  5679. // MES_Flag
  5680. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5681. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5682. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5683. writeToPLC_Flag1.Adress = 2203;
  5684. writeToPLC_Flag1.Value = (short)1;
  5685. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5686. stopwatch2.Stop();
  5687. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5688. return;
  5689. }
  5690. else
  5691. { // 查产品SN
  5692. b1OEEPartNo = "Test"; // ZS
  5693. }
  5694. short b1OEEMES_FLAG = 0;
  5695. // 上传OEE
  5696. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5697. b1OEEMES_FLAG = result.Item1;
  5698. resultStr = result.Item2;
  5699. stopwatch2.Start();
  5700. // MES_Flag
  5701. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5702. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5703. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5704. writeToPLC_Flag.Adress = 2203;
  5705. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5706. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5707. stopwatch2.Stop();
  5708. }
  5709. catch (Exception ex)
  5710. {
  5711. string str = ex.StackTrace;
  5712. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5713. // MES_Flag
  5714. stopwatch2.Start();
  5715. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5716. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5717. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5718. writeToPLC_Flag.Adress = 2203;
  5719. writeToPLC_Flag.Value = (short)4;
  5720. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5721. stopwatch2.Stop();
  5722. }
  5723. stopwatch1.Stop();
  5724. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5725. }
  5726. #endregion [S2] FCT(板测)
  5727. #endregion PLC2 李晓奇
  5728. #region PLC3 刘永村
  5729. #region [S3] 值板机
  5730. /// <summary>
  5731. /// S3工位的数据- 触发信号上次的值
  5732. /// </summary>
  5733. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5734. /// <summary>
  5735. /// S3工位的数据(含触发信号)
  5736. /// </summary>
  5737. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5738. /// <summary>
  5739. /// S3工位的数据- 回写点位
  5740. /// </summary>
  5741. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5742. /// <summary>
  5743. /// [S3] 值板机
  5744. /// </summary>
  5745. /// <param name="plcNo">PLC编号</param>
  5746. //private void ReadStation_S3(int plcNo)
  5747. //{
  5748. // // [S1] Tray盘上料装备
  5749. // // [S2] FCT
  5750. // // [S3] 值板机
  5751. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5752. // // [S5] Tray盘下料装备
  5753. // /// 上位机心跳
  5754. // /// 获取设备报警数据与状态信息
  5755. // string stationCode = "[S3]";
  5756. // string stationName = "值板机";
  5757. // string stationNameStr = stationCode + stationName;
  5758. // #region 创建字典
  5759. // // 触发信号字典 赋值
  5760. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5761. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5762. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5763. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5764. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5765. // // PLC数据字典 赋值
  5766. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5767. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5768. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5769. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5770. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5771. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5772. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5773. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5774. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5775. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5776. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5777. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5778. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5779. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5780. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5781. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5782. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5783. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5784. // s3PLCData.Add("c1Result", 0); // 产品结果
  5785. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5786. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5787. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5788. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  5789. // #endregion 创建字典
  5790. // while (IsRun)
  5791. // {
  5792. // try
  5793. // {
  5794. // if (!GlobalContext._IsCon_Funs3)
  5795. // {
  5796. // UpdatePLCMonitor(1, plcNo, 0);
  5797. // continue;
  5798. // }
  5799. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5800. // {
  5801. // Stopwatch stopwatch1 = new Stopwatch();
  5802. // Stopwatch stopwatch2 = new Stopwatch();
  5803. // stopwatch1.Start();
  5804. // stopwatch2.Start();
  5805. // #region 一次性读取所有数据
  5806. // // 一次性读取所有数据
  5807. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  5808. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  5809. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  5810. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  5811. // int[] datas = data1.Concat(data2).ToArray();
  5812. // datas = datas.Concat(data3).ToArray();
  5813. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  5814. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  5815. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5816. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  5817. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  5818. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  5819. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5820. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  5821. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  5822. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  5823. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  5824. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5825. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  5826. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  5827. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  5828. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  5829. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5830. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  5831. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  5832. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  5833. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  5834. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  5835. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  5836. // #endregion 一次性读取所有数据
  5837. // stopwatch2.Stop();
  5838. // #region 回写操作,写后清空flag
  5839. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  5840. // #endregion 回写操作,写后清空flag
  5841. // #region S3进站校验
  5842. // try
  5843. // {
  5844. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  5845. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  5846. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  5847. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  5848. // {
  5849. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  5850. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5851. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  5852. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5853. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  5854. // }
  5855. // }
  5856. // catch (Exception ex)
  5857. // {
  5858. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5859. // string str = ex.StackTrace;
  5860. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5861. // }
  5862. // #endregion S3进站校验
  5863. // #region S3二穴载具解绑
  5864. // try
  5865. // {
  5866. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  5867. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  5868. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  5869. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  5870. // {
  5871. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5872. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  5873. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  5874. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  5875. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  5876. // }
  5877. // }
  5878. // catch (Exception ex)
  5879. // {
  5880. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  5881. // string str = ex.StackTrace;
  5882. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5883. // }
  5884. // #endregion S3二穴载具解绑
  5885. // #region S3二穴载具绑定
  5886. // try
  5887. // {
  5888. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  5889. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  5890. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  5891. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  5892. // {
  5893. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5894. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5895. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  5896. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  5897. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  5898. // }
  5899. // }
  5900. // catch (Exception ex)
  5901. // {
  5902. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  5903. // string str = ex.StackTrace;
  5904. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5905. // }
  5906. // #endregion S3二穴载具绑定
  5907. // #region S3出站接口(+一穴载具绑定)
  5908. // try
  5909. // {
  5910. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  5911. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  5912. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  5913. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  5914. // {
  5915. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  5916. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5917. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  5918. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  5919. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  5920. // }
  5921. // }
  5922. // catch (Exception ex)
  5923. // {
  5924. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  5925. // string str = ex.StackTrace;
  5926. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5927. // }
  5928. // #endregion S3出站接口(+一穴载具绑定)
  5929. // #region S3节拍接口
  5930. // try
  5931. // {
  5932. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  5933. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  5934. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  5935. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  5936. // {
  5937. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  5938. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5939. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  5940. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  5941. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  5942. // }
  5943. // }
  5944. // catch (Exception ex)
  5945. // {
  5946. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  5947. // string str = ex.StackTrace;
  5948. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5949. // }
  5950. // #endregion S3节拍接口
  5951. // #region 心跳
  5952. // try
  5953. // {
  5954. // short states = 0;
  5955. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5956. // }
  5957. // catch (Exception ex)
  5958. // {
  5959. // string str = ex.StackTrace;
  5960. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5961. // }
  5962. // #endregion 心跳
  5963. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5964. // stopwatch1.Stop();
  5965. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5966. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5967. // }
  5968. // else
  5969. // {
  5970. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5971. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5972. // Funs[plcNo].Connect();
  5973. // }
  5974. // }
  5975. // catch (Exception ex)
  5976. // {
  5977. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5978. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5979. // Funs[plcNo].ReConnect();
  5980. // }
  5981. // Thread.Sleep(IntervalReadPLC);
  5982. // }
  5983. //}
  5984. /// <summary>
  5985. /// [S3] 值板机- 进站校验
  5986. /// </summary>
  5987. /// <param name="plcNo">PLC编号</param>
  5988. /// <param name="stationNameStr">工站全称</param>
  5989. private void S3进站校验(int plcNo, string stationNameStr)
  5990. {
  5991. Stopwatch stopwatch1 = new Stopwatch();
  5992. Stopwatch stopwatch2 = new Stopwatch();
  5993. try
  5994. {
  5995. stopwatch1.Start();
  5996. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  5997. sn = sn.Replace("\0", "");
  5998. #region 查询载具上的产品信息
  5999. string cavityData = string.Empty;
  6000. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6001. if (string.IsNullOrEmpty(cavityData))
  6002. cavityData = "";
  6003. if (snResult != 0)
  6004. {
  6005. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6006. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6007. writeToPLC_Flag1.Adress = 2003;
  6008. writeToPLC_Flag1.Value = (short)6;
  6009. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6010. stopwatch1.Stop();
  6011. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6012. return;
  6013. }
  6014. #endregion 查询载具上的产品信息
  6015. string[] cavitySNs = cavityData.Split('.');
  6016. string part1Str = ""; // 产品1的SN码
  6017. string part2Str = ""; // 产品2的SN码
  6018. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6019. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6020. if (cavitySNs != null && cavitySNs.Length >= 2)
  6021. {
  6022. part1Str = cavitySNs[0];
  6023. part2Str = cavitySNs[1];
  6024. c1Part1Result_Check = 2;
  6025. c1Part2Result_Check = 2;
  6026. }
  6027. if (part1Str == "假产品")
  6028. c1Part1Result_Check = 3;
  6029. if (part2Str == "假产品")
  6030. c1Part2Result_Check = 3;
  6031. // 调用MES进站
  6032. stopwatch2.Start();
  6033. // 调用MES进站 - 产品1
  6034. List<TestItem> item;
  6035. int result1 = c1Part1Result_Check;
  6036. if (result1 != 3)
  6037. {
  6038. item = new List<TestItem>();
  6039. item.Add(new TestItem()
  6040. {
  6041. Parameter_name = "载具码",
  6042. Parameter_value = sn,
  6043. });
  6044. item.Add(new TestItem()
  6045. {
  6046. Parameter_name = "载具穴号",
  6047. Parameter_value = "1",
  6048. });
  6049. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6050. }
  6051. // 调用MES进站 - 产品2
  6052. int result2 = c1Part2Result_Check;
  6053. if (result2 != 3)
  6054. {
  6055. item = new List<TestItem>();
  6056. item.Add(new TestItem()
  6057. {
  6058. Parameter_name = "载具码",
  6059. Parameter_value = sn,
  6060. });
  6061. item.Add(new TestItem()
  6062. {
  6063. Parameter_name = "载具穴号",
  6064. Parameter_value = "2",
  6065. });
  6066. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6067. }
  6068. stopwatch2.Stop();
  6069. if (result1 == 2)
  6070. c1Part1Result_Check = 2;
  6071. if (result2 == 2)
  6072. c1Part2Result_Check = 2;
  6073. int result = result1;
  6074. if (result == 1)
  6075. result = result2;
  6076. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6077. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6078. short c1MES_FLAG_Check = (short)result;
  6079. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6080. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6081. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6082. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6083. //// MES_Flag
  6084. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6085. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6086. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6087. writeToPLC_Flag.Adress = 2003;
  6088. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6089. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6090. {
  6091. Name = "c1Part1Result_Check",
  6092. Adress = 2024,
  6093. ValueType = PLCValueType.Short,
  6094. Value = c1Part1Result_Check
  6095. });
  6096. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6097. {
  6098. Name = "c1Part2Result_Check",
  6099. Adress = 2025,
  6100. ValueType = PLCValueType.Short,
  6101. Value = c1Part2Result_Check
  6102. });
  6103. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6104. {
  6105. Name = "c1Part1Num_Check",
  6106. Adress = 2026,
  6107. ValueType = PLCValueType.Short,
  6108. Value = c1Part1Num_Check
  6109. });
  6110. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6111. {
  6112. Name = "c1Part2Num_Check",
  6113. Adress = 2027,
  6114. ValueType = PLCValueType.Short,
  6115. Value = c1Part2Num_Check
  6116. });
  6117. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6118. }
  6119. catch (Exception ex)
  6120. {
  6121. string str = ex.StackTrace;
  6122. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6123. // MES_Flag
  6124. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6125. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6126. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6127. writeToPLC_Flag.Adress = 2003;
  6128. writeToPLC_Flag.Value = (short)6;
  6129. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6130. }
  6131. stopwatch1.Stop();
  6132. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6133. }
  6134. /// <summary>
  6135. /// [S3] 值板机 - 二穴载具解绑
  6136. /// </summary>
  6137. /// <param name="plcNo">PLC编号</param>
  6138. /// <param name="stationNameStr">工站全称</param>
  6139. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6140. {
  6141. Stopwatch stopwatch1 = new Stopwatch();
  6142. Stopwatch stopwatch2 = new Stopwatch();
  6143. try
  6144. {
  6145. stopwatch1.Start();
  6146. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6147. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6148. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6149. // 解绑
  6150. #region 查询载具上的产品信息
  6151. string cavityData = string.Empty;
  6152. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6153. if (string.IsNullOrEmpty(cavityData))
  6154. cavityData = "";
  6155. if (snResult != 0)
  6156. {
  6157. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6158. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6159. writeToPLC_Flag1.Adress = 2082;
  6160. writeToPLC_Flag1.Value = (short)6;
  6161. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6162. stopwatch1.Stop();
  6163. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6164. return;
  6165. }
  6166. #endregion 查询载具上的产品信息
  6167. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6168. #region 解绑
  6169. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6170. {
  6171. // 删除
  6172. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6173. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6174. }
  6175. else
  6176. {
  6177. string data_new = string.Join(".", cavitySNs);
  6178. // 删除再插入
  6179. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6180. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6181. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6182. }
  6183. #endregion 解绑
  6184. short c1MES_FLAG_Unbind = 1;
  6185. stopwatch2.Start();
  6186. // MES_Flag
  6187. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6188. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6189. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6190. writeToPLC_Flag.Adress = 2082;
  6191. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6192. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6193. stopwatch2.Stop();
  6194. }
  6195. catch (Exception ex)
  6196. {
  6197. string str = ex.StackTrace;
  6198. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6199. // MES_Flag
  6200. stopwatch2.Start();
  6201. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6202. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6203. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6204. writeToPLC_Flag.Adress = 2082;
  6205. writeToPLC_Flag.Value = (short)6;
  6206. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6207. stopwatch2.Stop();
  6208. }
  6209. stopwatch1.Stop();
  6210. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6211. }
  6212. /// <summary>
  6213. /// [S3] 值板机 - 二穴载具绑定
  6214. /// </summary>
  6215. /// <param name="plcNo">PLC编号</param>
  6216. /// <param name="stationNameStr">工站全称</param>
  6217. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6218. {
  6219. Stopwatch stopwatch1 = new Stopwatch();
  6220. Stopwatch stopwatch2 = new Stopwatch();
  6221. try
  6222. {
  6223. stopwatch1.Start();
  6224. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6225. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6226. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6227. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6228. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6229. stopwatch2.Start();
  6230. #region 查询载具上的产品信息
  6231. string cavityData = string.Empty;
  6232. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6233. if (string.IsNullOrEmpty(cavityData))
  6234. cavityData = "";
  6235. if (snResult != 0)
  6236. {
  6237. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6238. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6239. writeToPLC_Flag1.Adress = 2115;
  6240. writeToPLC_Flag1.Value = (short)6;
  6241. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6242. stopwatch1.Stop();
  6243. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6244. return;
  6245. }
  6246. #endregion 查询载具上的产品信息
  6247. // 产品换载具
  6248. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6249. string partSn1 = "";
  6250. string partSn2 = "";
  6251. if (cavitySNs != null && cavitySNs.Length >= 2)
  6252. {
  6253. partSn1 = cavitySNs[0];
  6254. partSn2 = cavitySNs[1];
  6255. }
  6256. string data_new = string.Empty;
  6257. // 是否是两个穴位交换
  6258. if (c1CavityReverse_Bind == 1)
  6259. {
  6260. // 交换
  6261. data_new = string.Concat(partSn2, ".", partSn1);
  6262. }
  6263. else
  6264. { // 不交换
  6265. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6266. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6267. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6268. data_new = string.Join(".", cavitySNs);
  6269. }
  6270. // 删除再插入
  6271. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6272. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6273. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6274. stopwatch2.Stop();
  6275. short c1MES_FLAG_Bind = 1;
  6276. // MES_Flag
  6277. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6278. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6279. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6280. writeToPLC_Flag.Adress = 2115;
  6281. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6282. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6283. }
  6284. catch (Exception ex)
  6285. {
  6286. string str = ex.StackTrace;
  6287. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6288. // MES_Flag
  6289. stopwatch2.Start();
  6290. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6291. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6292. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6293. writeToPLC_Flag.Adress = 2115;
  6294. writeToPLC_Flag.Value = (short)6;
  6295. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6296. stopwatch2.Stop();
  6297. }
  6298. stopwatch1.Stop();
  6299. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6300. }
  6301. //// 上次采集到的SN
  6302. //private string sn_值板机 = string.Empty;
  6303. /// <summary>
  6304. /// [S3] 值板机 - 出站接口
  6305. /// </summary>
  6306. /// <param name="plcNo">PLC编号</param>
  6307. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6308. {
  6309. Stopwatch stopwatch1 = new Stopwatch();
  6310. Stopwatch stopwatch2 = new Stopwatch();
  6311. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6312. string stationNameStr = stationCode + stationName;
  6313. string processItem = stationName; // 测试项目
  6314. try
  6315. {
  6316. stopwatch1.Start();
  6317. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6318. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6319. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6320. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6321. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6322. sn = sn.Replace("\0", "");
  6323. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6324. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6325. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6326. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6327. bool pass = c1Result == 1;
  6328. // 查sn
  6329. #region 查询载具上的产品信息
  6330. string cavityData = string.Empty;
  6331. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6332. if (string.IsNullOrEmpty(cavityData))
  6333. cavityData = "";
  6334. if (snResult != 0)
  6335. {
  6336. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6337. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6338. writeToPLC_Flag1.Adress = 2150;
  6339. writeToPLC_Flag1.Value = (short)4;
  6340. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6341. stopwatch1.Stop();
  6342. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6343. return;
  6344. }
  6345. #endregion 查询载具上的产品信息
  6346. string[] cavitySNs = cavityData.Split('.');
  6347. string productSN = "";
  6348. if (cavitySNs != null && cavitySNs.Length >= 2)
  6349. {
  6350. productSN = cavitySNs[c1VehicleCavity];
  6351. cavitySNs[c1VehicleCavity] = "";
  6352. }
  6353. stopwatch2.Start();
  6354. List<TestItem> items = new List<TestItem>();
  6355. items.Add(new TestItem()
  6356. {
  6357. Parameter_name = "二穴载具码",
  6358. Parameter_value = c1ProductSN_Check,
  6359. Parameter_unit = ""
  6360. });
  6361. items.Add(new TestItem()
  6362. {
  6363. Parameter_name = "二穴载具穴号",
  6364. Parameter_value = c1VehicleCavity.ToString(),
  6365. Parameter_unit = ""
  6366. });
  6367. items.Add(new TestItem()
  6368. {
  6369. Parameter_name = "一穴载具码",
  6370. Parameter_value = sn,
  6371. Parameter_unit = ""
  6372. });
  6373. items.Add(new TestItem()
  6374. {
  6375. Parameter_name = "一穴载具穴号",
  6376. Parameter_value = "1",
  6377. Parameter_unit = ""
  6378. });
  6379. items.Add(new TestItem()
  6380. {
  6381. Parameter_name = "产品结果",
  6382. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6383. Parameter_unit = ""
  6384. });
  6385. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6386. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6387. short result = (short)result1;
  6388. stopwatch2.Stop();
  6389. #region 存储绑定数据到 边线MES系统中
  6390. if (result == 1)
  6391. {
  6392. string data = string.Concat(productSN);
  6393. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6394. if (resultMesR != 0)
  6395. {
  6396. result = 4;
  6397. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6398. }
  6399. }
  6400. #endregion 存储绑定数据到 边线MES系统中
  6401. #region 产品从 来源载具(二穴载具)中删除
  6402. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6403. {
  6404. // 删除
  6405. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6406. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6407. }
  6408. else
  6409. {
  6410. string data_new = string.Join(".", cavitySNs);
  6411. // 删除再插入
  6412. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6413. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6414. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6415. }
  6416. #endregion 产品从 来源载具(二穴载具)中删除
  6417. // MES_Flag 为MES报错
  6418. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6419. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6420. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6421. writeToPLC_Flag.Name = "c1MES_FLAG";
  6422. writeToPLC_Flag.Adress = 2150;
  6423. writeToPLC_Flag.Value = result;
  6424. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6425. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6426. }
  6427. catch (Exception ex)
  6428. {
  6429. stopwatch2.Restart();
  6430. // MES_Flag 为4上位机报错
  6431. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6432. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6433. writeToPLC_Flag.Name = "c1MES_FLAG";
  6434. writeToPLC_Flag.Adress = 2150;
  6435. writeToPLC_Flag.Value = (short)4;
  6436. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6437. stopwatch2.Stop();
  6438. string str = ex.StackTrace;
  6439. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6440. }
  6441. stopwatch1.Stop();
  6442. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6443. }
  6444. /// <summary>
  6445. /// [S3] 值板机- 节拍接口
  6446. /// </summary>
  6447. /// <param name="plcNo">PLC编号</param>
  6448. /// <param name="stationNameStr">工站全称</param>
  6449. private void S3节拍接口(int plcNo, string stationNameStr)
  6450. {
  6451. Stopwatch stopwatch1 = new Stopwatch();
  6452. Stopwatch stopwatch2 = new Stopwatch();
  6453. string resultStr = string.Empty;
  6454. try
  6455. {
  6456. stopwatch1.Start();
  6457. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6458. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6459. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6460. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6461. if (!actionBool)
  6462. {
  6463. stopwatch2.Start();
  6464. // MES_Flag
  6465. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6466. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6467. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6468. writeToPLC_Flag1.Adress = 2204;
  6469. writeToPLC_Flag1.Value = (short)4;
  6470. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6471. stopwatch2.Stop();
  6472. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6473. return;
  6474. }
  6475. string c1OEEPartNo = string.Empty; // 物料码
  6476. if (string.IsNullOrEmpty(c1OEEProductSN))
  6477. {
  6478. stopwatch2.Start();
  6479. // MES_Flag
  6480. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6481. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6482. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6483. writeToPLC_Flag1.Adress = 2204;
  6484. writeToPLC_Flag1.Value = (short)1;
  6485. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6486. stopwatch2.Stop();
  6487. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6488. return;
  6489. }
  6490. else
  6491. { // 查产品SN
  6492. c1OEEPartNo = "Test"; // ZS
  6493. }
  6494. short c1OEEMES_FLAG = 0;
  6495. // 上传OEE
  6496. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6497. c1OEEMES_FLAG = result.Item1;
  6498. resultStr = result.Item2;
  6499. stopwatch2.Start();
  6500. // MES_Flag
  6501. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6502. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6503. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6504. writeToPLC_Flag.Adress = 2204;
  6505. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6506. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6507. stopwatch2.Stop();
  6508. }
  6509. catch (Exception ex)
  6510. {
  6511. string str = ex.StackTrace;
  6512. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6513. // MES_Flag
  6514. stopwatch2.Start();
  6515. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6516. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6517. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6518. writeToPLC_Flag.Adress = 2204;
  6519. writeToPLC_Flag.Value = (short)4;
  6520. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6521. stopwatch2.Stop();
  6522. }
  6523. stopwatch1.Stop();
  6524. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6525. }
  6526. #endregion [S3] 值板机
  6527. #endregion PLC3 刘永村
  6528. #region PLC4 刘果段
  6529. #region [S4] 取放桁架
  6530. /// <summary>
  6531. /// S4工位的数据- 触发信号上次的值
  6532. /// </summary>
  6533. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6534. /// <summary>
  6535. /// S4工位的数据(含触发信号)
  6536. /// </summary>
  6537. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6538. /// <summary>
  6539. /// S4工位的数据- 回写点位
  6540. /// </summary>
  6541. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6542. /// <summary>
  6543. /// [S4] 取放桁架
  6544. /// </summary>
  6545. /// <param name="plcNo">PLC编号</param>
  6546. //private void ReadStation_S4(int plcNo)
  6547. //{
  6548. // // [S1] Tray盘上料装备
  6549. // // [S2] FCT
  6550. // // [S3] 值板机
  6551. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6552. // // [S5] Tray盘下料装备
  6553. // /// 上位机心跳
  6554. // /// 获取设备报警数据与状态信息
  6555. // string stationCode = "[S4_1]";
  6556. // string stationName = "载具下线装备";
  6557. // string stationNameStr = stationCode + stationName;
  6558. // string stationCode2 = "[S4_2]";
  6559. // string stationName2 = "桁架";
  6560. // string stationNameStr2 = stationCode2 + stationName2;
  6561. // string stationCode3 = "[S4_3]";
  6562. // string stationName3 = "提升机1";
  6563. // string stationNameStr3 = stationCode3 + stationName3;
  6564. // string stationCode4 = "[S4_4]";
  6565. // string stationName4 = "提升机2";
  6566. // string stationNameStr4 = stationCode4 + stationName4;
  6567. // string stationCode5 = "[S4_5]";
  6568. // string stationName5 = "载具上线装备";
  6569. // string stationNameStr5 = stationCode5 + stationName5;
  6570. // #region 创建字典
  6571. // // 触发信号字典 赋值
  6572. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6573. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6574. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6575. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6576. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6577. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6578. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6579. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6580. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6581. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6582. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6583. // // PLC数据字典 赋值
  6584. // // 载具下线装备(弹夹上线)
  6585. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6586. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6587. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6588. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6589. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6590. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6591. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6592. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6593. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6594. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6595. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6596. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6597. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6598. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6599. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6600. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6601. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6602. // s4PLCData.Add("d1Result", 0); // 产品结果
  6603. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6604. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6605. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6606. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6607. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6608. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6609. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6610. // // 真空标机(提升机)
  6611. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6612. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6613. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6614. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6615. // s4PLCData.Add("d3Result", 0); // 产品结果
  6616. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6617. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6618. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6619. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6620. // s4PLCData.Add("d4Result", 0); // 产品结果
  6621. // // 载具上线装备(弹夹下线)
  6622. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6623. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6624. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6625. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6626. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6627. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6628. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6629. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6630. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6631. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6632. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6633. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6634. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6635. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6636. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6637. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6638. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6639. // s4PLCData.Add("d5Result", 0); // 产品结果
  6640. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6641. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6642. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6643. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6644. // #endregion 创建字典
  6645. // while (IsRun)
  6646. // {
  6647. // try
  6648. // {
  6649. // if (!GlobalContext._IsCon_Funs4)
  6650. // {
  6651. // UpdatePLCMonitor(1, plcNo, 0);
  6652. // continue;
  6653. // }
  6654. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6655. // {
  6656. // Stopwatch stopwatch1 = new Stopwatch();
  6657. // Stopwatch stopwatch2 = new Stopwatch();
  6658. // stopwatch1.Start();
  6659. // stopwatch2.Start();
  6660. // #region 一次性读取所有数据
  6661. // // 载具下线装备(弹夹上线)
  6662. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6663. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6664. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6665. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6666. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6667. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6668. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6669. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6670. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6671. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6672. // int[] datas = data1.Concat(data2).ToArray();
  6673. // datas = datas.Concat(data3).ToArray();
  6674. // datas = datas.Concat(data4).ToArray();
  6675. // datas = datas.Concat(data5).ToArray();
  6676. // datas = datas.Concat(data6).ToArray();
  6677. // datas = datas.Concat(data7).ToArray();
  6678. // datas = datas.Concat(data8).ToArray();
  6679. // datas = datas.Concat(data9).ToArray();
  6680. // datas = datas.Concat(data10).ToArray();
  6681. // // 载具下线装备(弹夹上线)
  6682. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6683. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6684. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6685. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6686. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6687. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6688. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6689. // s4PLCData["d1MES_FLAG"] = datas[65];
  6690. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6691. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6692. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6693. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6694. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6695. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6696. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6697. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6698. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6699. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6700. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6701. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6702. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6703. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6704. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6705. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6706. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6707. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6708. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6709. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6710. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6711. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6712. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6713. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6714. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6715. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6716. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6717. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6718. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6719. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6720. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6721. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6722. // s4PLCData["d1Result"] = datas[386];
  6723. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6724. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6725. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6726. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6727. // s4PLCData["d1OEEType"] = datas[419];
  6728. // // 桁架(查询标机中弹夹的状态)
  6729. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6730. // s4PLCData["d2BulletclipStates"] = datas[431];
  6731. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6732. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6733. // // 真空标机
  6734. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6735. // s4PLCData["d3MES_FLAG"] = datas[463];
  6736. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6737. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6738. // s4PLCData["d3Result"] = datas[484];
  6739. // s4PLCData["d3Type"] = datas[485];
  6740. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6741. // s4PLCData["d4MES_FLAG"] = datas[496];
  6742. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6743. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6744. // s4PLCData["d4Result"] = datas[517];
  6745. // s4PLCData["d4Type"] = datas[518];
  6746. // // 载具上线装备(弹夹下线)
  6747. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6748. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6749. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6750. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6751. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6752. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6753. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6754. // s4PLCData["d5MES_FLAG"] = datas[591];
  6755. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6756. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6757. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6758. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6759. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6760. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6761. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6762. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6763. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6764. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6765. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6766. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6767. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6768. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6769. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6770. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6771. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6772. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6773. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6774. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6775. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6776. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6777. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6778. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6779. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6780. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6781. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6782. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6783. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6784. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6785. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6786. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6787. // s4PLCData["d5Result"] = datas[912];
  6788. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  6789. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  6790. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  6791. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  6792. // s4PLCData["d5OEEType"] = datas[945];
  6793. // #endregion 一次性读取所有数据
  6794. // stopwatch2.Stop();
  6795. // #region 回写操作,写后清空flag
  6796. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  6797. // #endregion 回写操作,写后清空flag
  6798. // // N801A-S4_1 弹夹扫码
  6799. // #region N801A-S4_1 弹夹扫码
  6800. // try
  6801. // {
  6802. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  6803. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  6804. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  6805. // {
  6806. // if (d1BulletclipScanCode == 1) // 0->1
  6807. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6808. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  6809. // }
  6810. // }
  6811. // catch (Exception ex)
  6812. // {
  6813. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  6814. // string str = ex.StackTrace;
  6815. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6816. // }
  6817. // #endregion N801A-S4_1 弹夹扫码
  6818. // // N801A-S4_1 载具扫码
  6819. // #region N801A-S4_1 载具扫码
  6820. // try
  6821. // {
  6822. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  6823. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  6824. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  6825. // {
  6826. // if (d1VehicleScanCode == 1) // 0->1
  6827. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6828. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  6829. // }
  6830. // }
  6831. // catch (Exception ex)
  6832. // {
  6833. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  6834. // string str = ex.StackTrace;
  6835. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6836. // }
  6837. // #endregion N801A-S4_1 载具扫码
  6838. // // N801A-S4_1 出站接口
  6839. // #region N801A-S4_1 出站接口
  6840. // try
  6841. // {
  6842. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  6843. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  6844. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  6845. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  6846. // {
  6847. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  6848. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6849. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  6850. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  6851. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  6852. // }
  6853. // }
  6854. // catch (Exception ex)
  6855. // {
  6856. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  6857. // string str = ex.StackTrace;
  6858. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6859. // }
  6860. // #endregion N801A-S4_1 出站接口
  6861. // // N801A-S4_1 节拍接口
  6862. // #region N801A-S4_1 节拍接口
  6863. // try
  6864. // {
  6865. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  6866. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  6867. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  6868. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  6869. // {
  6870. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  6871. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6872. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  6873. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  6874. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  6875. // }
  6876. // }
  6877. // catch (Exception ex)
  6878. // {
  6879. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  6880. // string str = ex.StackTrace;
  6881. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6882. // }
  6883. // #endregion N801A-S4_1 节拍接口
  6884. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  6885. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  6886. // try
  6887. // {
  6888. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  6889. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  6890. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  6891. // {
  6892. // if (d2BulletclipScanCode == 1) // 0->1
  6893. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  6894. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  6895. // }
  6896. // }
  6897. // catch (Exception ex)
  6898. // {
  6899. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  6900. // string str = ex.StackTrace;
  6901. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6902. // }
  6903. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  6904. // // N801A-S4_3 真空标机1 数据
  6905. // #region N801A-S4_3 真空标机1
  6906. // try
  6907. // {
  6908. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  6909. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  6910. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  6911. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  6912. // {
  6913. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  6914. // {
  6915. // int stationType = (int)s4PLCData["d3Type"];
  6916. // if (stationType == 1)
  6917. // {
  6918. // // S4_3进站接口
  6919. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  6920. // }
  6921. // else if (stationType == 2)
  6922. // {
  6923. // // S4_3出站接口
  6924. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  6925. // }
  6926. // }
  6927. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  6928. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  6929. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  6930. // }
  6931. // }
  6932. // catch (Exception ex)
  6933. // {
  6934. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  6935. // string str = ex.StackTrace;
  6936. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6937. // }
  6938. // #endregion N801A-S4_3 真空标机1
  6939. // // N801A-S4_4 真空标机2 数据
  6940. // #region N801A-S4_4 真空标机2
  6941. // try
  6942. // {
  6943. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  6944. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  6945. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  6946. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  6947. // {
  6948. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  6949. // {
  6950. // int stationType = (int)s4PLCData["d4Type"];
  6951. // if (stationType == 1)
  6952. // {
  6953. // // S4_4进站接口
  6954. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  6955. // }
  6956. // else if (stationType == 2)
  6957. // {
  6958. // // S4_4出站接口
  6959. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  6960. // }
  6961. // }
  6962. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  6963. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  6964. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  6965. // }
  6966. // }
  6967. // catch (Exception ex)
  6968. // {
  6969. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  6970. // string str = ex.StackTrace;
  6971. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6972. // }
  6973. // #endregion N801A-S4_4 真空标机2
  6974. // // N801A-S4_5 弹夹扫码 数据
  6975. // #region N801A-S4_5 弹夹扫码
  6976. // try
  6977. // {
  6978. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  6979. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  6980. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  6981. // {
  6982. // if (d5BulletclipScanCode == 1) // 0->1
  6983. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  6984. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  6985. // }
  6986. // }
  6987. // catch (Exception ex)
  6988. // {
  6989. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  6990. // string str = ex.StackTrace;
  6991. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6992. // }
  6993. // #endregion N801A-S4_5 弹夹扫码
  6994. // // N801A-S4_5 载具扫码 数据
  6995. // #region N801A-S4_5 载具扫码
  6996. // try
  6997. // {
  6998. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  6999. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7000. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7001. // {
  7002. // if (d5VehicleScanCode == 1) // 0->1
  7003. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7004. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7005. // }
  7006. // }
  7007. // catch (Exception ex)
  7008. // {
  7009. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7010. // string str = ex.StackTrace;
  7011. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7012. // }
  7013. // #endregion N801A-S4_5 载具扫码
  7014. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7015. // #region N801A-S4_5 出站接口
  7016. // try
  7017. // {
  7018. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7019. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7020. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7021. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7022. // {
  7023. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7024. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7025. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7026. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7027. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7028. // }
  7029. // }
  7030. // catch (Exception ex)
  7031. // {
  7032. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7033. // string str = ex.StackTrace;
  7034. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7035. // }
  7036. // #endregion N801A-S4_5 出站接口
  7037. // // N801A-S4_5 节拍接口 数据
  7038. // #region N801A-S4_5 节拍接口
  7039. // try
  7040. // {
  7041. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7042. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7043. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7044. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7045. // {
  7046. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7047. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7048. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7049. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7050. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7051. // }
  7052. // }
  7053. // catch (Exception ex)
  7054. // {
  7055. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7056. // string str = ex.StackTrace;
  7057. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7058. // }
  7059. // #endregion N801A-S4_5 节拍接口
  7060. // #region 心跳
  7061. // try
  7062. // {
  7063. // short states = 0;
  7064. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7065. // }
  7066. // catch (Exception ex)
  7067. // {
  7068. // string str = ex.StackTrace;
  7069. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7070. // }
  7071. // #endregion 心跳
  7072. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7073. // stopwatch1.Stop();
  7074. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7075. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7076. // }
  7077. // else
  7078. // {
  7079. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7080. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7081. // Funs[plcNo].Connect();
  7082. // }
  7083. // }
  7084. // catch (Exception ex)
  7085. // {
  7086. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7087. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7088. // Funs[plcNo].ReConnect();
  7089. // }
  7090. // Thread.Sleep(IntervalReadPLC);
  7091. // }
  7092. //}
  7093. /// <summary>
  7094. /// [S4] 取放桁架 - S4_1弹夹扫码
  7095. /// </summary>
  7096. /// <param name="plcNo">PLC编号</param>
  7097. /// <param name="stationNameStr">工站全称</param>
  7098. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7099. {
  7100. Stopwatch stopwatch1 = new Stopwatch();
  7101. Stopwatch stopwatch2 = new Stopwatch();
  7102. try
  7103. {
  7104. stopwatch1.Start();
  7105. // ZS 弹夹扫码
  7106. string d1BulletclipCode = " "; // 扫到的码
  7107. short d1BulletclipScanCode = 2;
  7108. stopwatch2.Start();
  7109. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7110. //// MES_Flag
  7111. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7112. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7113. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7114. writeToPLC_Flag.Adress = 2002;
  7115. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7116. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7117. {
  7118. Name = "d1BulletclipCode",
  7119. Adress = 2003,
  7120. ValueType = PLCValueType.String,
  7121. ValueTypeStrLength = 20,
  7122. Value = d1BulletclipCode
  7123. });
  7124. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7125. stopwatch2.Stop();
  7126. }
  7127. catch (Exception ex)
  7128. {
  7129. string str = ex.StackTrace;
  7130. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7131. stopwatch2.Start();
  7132. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7133. //// MES_Flag
  7134. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7135. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7136. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7137. writeToPLC_Flag.Adress = 2002;
  7138. writeToPLC_Flag.Value = (short)6;
  7139. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7140. {
  7141. Name = "d1BulletclipCode",
  7142. Adress = 2003,
  7143. ValueType = PLCValueType.String,
  7144. ValueTypeStrLength = 20,
  7145. Value = " "
  7146. });
  7147. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7148. stopwatch2.Stop();
  7149. }
  7150. stopwatch1.Stop();
  7151. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7152. }
  7153. /// <summary>
  7154. /// [S4] 取放桁架 - S4_1载具扫码
  7155. /// </summary>
  7156. /// <param name="plcNo">PLC编号</param>
  7157. /// <param name="stationNameStr">工站全称</param>
  7158. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7159. {
  7160. Stopwatch stopwatch1 = new Stopwatch();
  7161. Stopwatch stopwatch2 = new Stopwatch();
  7162. try
  7163. {
  7164. stopwatch1.Start();
  7165. // ZS 载具扫码
  7166. string d1VehicleCode = ""; // 扫到的码
  7167. short d1VehicleScanCode = 2;
  7168. #region 进站
  7169. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7170. {
  7171. #region 查询载具上的产品信息
  7172. string cavityData = string.Empty;
  7173. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7174. if (string.IsNullOrEmpty(cavityData))
  7175. cavityData = "";
  7176. if (snResult != 0)
  7177. {
  7178. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7179. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7180. writeToPLC_Flag1.Adress = 2033;
  7181. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7182. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7183. {
  7184. Name = "d1VehicleCode",
  7185. Adress = 2034,
  7186. ValueType = PLCValueType.String,
  7187. ValueTypeStrLength = 20,
  7188. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7189. });
  7190. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7191. stopwatch1.Stop();
  7192. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7193. return;
  7194. }
  7195. string[] cavitySNs = cavityData.Split('.');
  7196. string partNo = "";
  7197. if (cavitySNs != null && cavitySNs.Length >= 1)
  7198. {
  7199. partNo = cavitySNs[0];
  7200. }
  7201. #endregion 查询载具上的产品信息
  7202. List<TestItem> item = new List<TestItem>();
  7203. item.Add(new TestItem()
  7204. {
  7205. Parameter_name = "载具码",
  7206. Parameter_value = d1VehicleCode,
  7207. });
  7208. item.Add(new TestItem()
  7209. {
  7210. Parameter_name = "载具穴号",
  7211. Parameter_value = "1",
  7212. });
  7213. stopwatch2.Start();
  7214. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7215. stopwatch2.Stop();
  7216. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7217. }
  7218. #endregion 进站
  7219. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7220. //// MES_Flag
  7221. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7222. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7223. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7224. writeToPLC_Flag.Adress = 2033;
  7225. writeToPLC_Flag.Value = d1VehicleScanCode;
  7226. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7227. {
  7228. Name = "d1VehicleCode",
  7229. Adress = 2034,
  7230. ValueType = PLCValueType.String,
  7231. ValueTypeStrLength = 20,
  7232. Value = d1VehicleCode
  7233. });
  7234. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7235. }
  7236. catch (Exception ex)
  7237. {
  7238. string str = ex.StackTrace;
  7239. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7240. stopwatch2.Start();
  7241. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7242. //// MES_Flag
  7243. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7244. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7245. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7246. writeToPLC_Flag.Adress = 2033;
  7247. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7248. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7249. {
  7250. Name = "d1VehicleCode",
  7251. Adress = 2034,
  7252. ValueType = PLCValueType.String,
  7253. ValueTypeStrLength = 20,
  7254. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7255. });
  7256. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7257. stopwatch2.Stop();
  7258. }
  7259. stopwatch1.Stop();
  7260. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7261. }
  7262. // 上次采集到的SN
  7263. //private string sn_S4_1出站接口 = string.Empty;
  7264. /// <summary>
  7265. /// [S4] 取放桁架 - S4_1出站接口
  7266. /// </summary>
  7267. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7268. {
  7269. Stopwatch stopwatch1 = new Stopwatch();
  7270. Stopwatch stopwatch2 = new Stopwatch();
  7271. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7272. string stationNameStr = stationCode + stationName;
  7273. string processItem = stationName; // 测试项目
  7274. try
  7275. {
  7276. stopwatch1.Start();
  7277. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7278. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7279. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7280. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7281. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7282. sn = sn.Replace("\0", "");
  7283. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7284. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7285. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7286. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7287. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7288. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7289. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7290. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7291. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7292. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7293. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7294. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7295. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7296. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7297. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7298. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7299. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7300. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7301. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7302. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7303. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7304. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7305. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7306. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7307. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7308. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7309. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7310. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7311. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7312. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7313. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7314. bool pass = d1Result == 1;
  7315. // 存 载具SN列表
  7316. List<string> vehicleCodes = new List<string>()
  7317. {
  7318. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7319. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7320. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7321. };
  7322. // 统一查 产品SN列表
  7323. List<string> partNos = new List<string>();
  7324. foreach (string vehicleCode in vehicleCodes)
  7325. {
  7326. if (string.IsNullOrEmpty(vehicleCode))
  7327. partNos.Add("");
  7328. else
  7329. {
  7330. string partNo = "";
  7331. #region 查询载具上的产品信息
  7332. string cavityData = string.Empty;
  7333. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7334. if (string.IsNullOrEmpty(cavityData))
  7335. cavityData = "";
  7336. if (snResult != 0)
  7337. {
  7338. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7339. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7340. writeToPLC_Flag1.Adress = 2065;
  7341. writeToPLC_Flag1.Value = (short)4;
  7342. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7343. stopwatch1.Stop();
  7344. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7345. return;
  7346. }
  7347. string[] cavitySNs = cavityData.Split('.');
  7348. if (cavitySNs != null && cavitySNs.Length >= 1)
  7349. partNo = cavitySNs[0];
  7350. #endregion 查询载具上的产品信息
  7351. partNos.Add(partNo);
  7352. }
  7353. }
  7354. // 统一上传
  7355. stopwatch2.Start();
  7356. List<int> results = new List<int>();
  7357. for (int i = 0; i < partNos.Count; i++)
  7358. {
  7359. string index = (i + 1).ToString(); // 弹夹穴号
  7360. if (string.IsNullOrEmpty(partNos[i]))
  7361. results.Add(1);
  7362. else
  7363. {
  7364. List<TestItem> items1 = new List<TestItem>();
  7365. items1.Add(new TestItem()
  7366. {
  7367. Parameter_name = "弹夹码",
  7368. Parameter_value = sn,
  7369. Parameter_unit = ""
  7370. });
  7371. items1.Add(new TestItem()
  7372. {
  7373. Parameter_name = "弹夹穴号",
  7374. Parameter_value = index,
  7375. Parameter_unit = ""
  7376. });
  7377. items1.Add(new TestItem()
  7378. {
  7379. Parameter_name = "载具码",
  7380. Parameter_value = vehicleCodes[i],
  7381. Parameter_unit = ""
  7382. });
  7383. items1.Add(new TestItem()
  7384. {
  7385. Parameter_name = "载具穴号",
  7386. Parameter_value = "1",
  7387. Parameter_unit = ""
  7388. });
  7389. items1.Add(new TestItem()
  7390. {
  7391. Parameter_name = "产品结果",
  7392. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7393. Parameter_unit = ""
  7394. });
  7395. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7396. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7397. results.Add(result1);
  7398. }
  7399. }
  7400. short result = 0;
  7401. if (results.All(a => a == 1))
  7402. result = 1;
  7403. else if (results.Contains(3))
  7404. result = 3;
  7405. else if (results.Contains(2))
  7406. result = 2;
  7407. else if (results.Contains(4))
  7408. result = 4;
  7409. else
  7410. result = 4;
  7411. stopwatch2.Stop();
  7412. #region 存储绑定数据到 边线MES系统中
  7413. if (result == 1)
  7414. {
  7415. string data = string.Join(".", vehicleCodes);
  7416. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7417. if (resultMesR != 0)
  7418. {
  7419. result = 4;
  7420. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7421. }
  7422. }
  7423. #endregion 存储绑定数据到 边线MES系统中
  7424. // MES_Flag 为4MES报错
  7425. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7426. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7427. writeToPLC_Flag.Name = "d1MES_FLAG";
  7428. writeToPLC_Flag.Adress = 2065;
  7429. writeToPLC_Flag.Value = result;
  7430. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7431. OnMessage(LogType.Debug, $"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>(2065, (short)4); // 4代表上位机报警
  7438. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7439. writeToPLC_Flag.Name = "d1MES_FLAG";
  7440. writeToPLC_Flag.Adress = 2065;
  7441. writeToPLC_Flag.Value = (short)4;
  7442. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7443. stopwatch2.Stop();
  7444. string str = ex.StackTrace;
  7445. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7446. }
  7447. stopwatch1.Stop();
  7448. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7449. }
  7450. /// <summary>
  7451. /// [S4] 取放桁架 - S4_1节拍接口
  7452. /// </summary>
  7453. /// <param name="plcNo">PLC编号</param>
  7454. /// <param name="stationNameStr">工站全称</param>
  7455. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7456. {
  7457. Stopwatch stopwatch1 = new Stopwatch();
  7458. Stopwatch stopwatch2 = new Stopwatch();
  7459. string resultStr = string.Empty;
  7460. try
  7461. {
  7462. stopwatch1.Start();
  7463. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7464. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7465. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7466. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7467. if (!actionBool)
  7468. {
  7469. stopwatch2.Start();
  7470. // MES_Flag
  7471. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7472. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7473. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7474. writeToPLC_Flag1.Adress = 2398;
  7475. writeToPLC_Flag1.Value = (short)4;
  7476. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7477. stopwatch2.Stop();
  7478. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7479. return;
  7480. }
  7481. string d1OEEPartNo = string.Empty; // 物料码
  7482. if (string.IsNullOrEmpty(d1OEEProductSN))
  7483. {
  7484. stopwatch2.Start();
  7485. // MES_Flag
  7486. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7487. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7488. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7489. writeToPLC_Flag1.Adress = 2398;
  7490. writeToPLC_Flag1.Value = (short)1;
  7491. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7492. stopwatch2.Stop();
  7493. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7494. return;
  7495. }
  7496. else
  7497. { // 查产品SN ZS
  7498. d1OEEPartNo = "Test";
  7499. }
  7500. short d1OEEMES_FLAG = 0;
  7501. // 上传OEE
  7502. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7503. d1OEEMES_FLAG = result.Item1;
  7504. resultStr = result.Item2;
  7505. stopwatch2.Start();
  7506. // MES_Flag
  7507. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7508. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7509. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7510. writeToPLC_Flag.Adress = 2398;
  7511. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7512. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7513. stopwatch2.Stop();
  7514. }
  7515. catch (Exception ex)
  7516. {
  7517. string str = ex.StackTrace;
  7518. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7519. // MES_Flag
  7520. stopwatch2.Start();
  7521. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7522. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7523. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7524. writeToPLC_Flag.Adress = 2398;
  7525. writeToPLC_Flag.Value = (short)4;
  7526. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7527. stopwatch2.Stop();
  7528. }
  7529. stopwatch1.Stop();
  7530. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7531. }
  7532. /// <summary>
  7533. /// [S4] 取放桁架 - S4_2桁架
  7534. /// </summary>
  7535. /// <param name="plcNo">PLC编号</param>
  7536. /// <param name="stationNameStr">工站全称</param>
  7537. private void S4_2桁架(int plcNo, string stationNameStr)
  7538. {
  7539. Stopwatch stopwatch1 = new Stopwatch();
  7540. Stopwatch stopwatch2 = new Stopwatch();
  7541. try
  7542. {
  7543. stopwatch1.Start();
  7544. // ZS 弹夹扫码
  7545. string d2BulletclipCode = " "; // 扫到的码
  7546. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7547. short d2BulletclipScanCode = 2;
  7548. stopwatch2.Start();
  7549. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7550. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7551. //// MES_Flag
  7552. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7553. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7554. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7555. writeToPLC_Flag.Adress = 2430;
  7556. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7557. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7558. {
  7559. Name = "d2BulletclipCode",
  7560. Adress = 2432,
  7561. ValueType = PLCValueType.String,
  7562. ValueTypeStrLength = 20,
  7563. Value = d2BulletclipCode
  7564. });
  7565. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7566. {
  7567. Name = "d2BulletclipStates",
  7568. Adress = 2431,
  7569. ValueType = PLCValueType.Short,
  7570. Value = d2BulletclipStates
  7571. });
  7572. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7573. stopwatch2.Stop();
  7574. }
  7575. catch (Exception ex)
  7576. {
  7577. string str = ex.StackTrace;
  7578. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7579. stopwatch2.Start();
  7580. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7581. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7582. // MES_Flag
  7583. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7584. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7585. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7586. writeToPLC_Flag.Adress = 2430;
  7587. writeToPLC_Flag.Value = (short)6;
  7588. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7589. {
  7590. Name = "d2BulletclipCode",
  7591. Adress = 2432,
  7592. ValueType = PLCValueType.String,
  7593. ValueTypeStrLength = 20,
  7594. Value = " "
  7595. });
  7596. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7597. {
  7598. Name = "d2BulletclipStates",
  7599. Adress = 2431,
  7600. ValueType = PLCValueType.Short,
  7601. Value = (short)0
  7602. });
  7603. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7604. stopwatch2.Stop();
  7605. }
  7606. stopwatch1.Stop();
  7607. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7608. }
  7609. // 上次采集到的SN
  7610. //private string sn_S4_3进站接口 = string.Empty;
  7611. /// <summary>
  7612. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7613. /// </summary>
  7614. private void S4_3进站接口(int plcNo, string stationNameStr)
  7615. {
  7616. Stopwatch stopwatch1 = new Stopwatch();
  7617. Stopwatch stopwatch2 = new Stopwatch();
  7618. try
  7619. {
  7620. stopwatch1.Start();
  7621. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7622. sn = sn.Replace("\0", "");
  7623. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7624. #region 查询15个载具码
  7625. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7626. string vehicleData = string.Empty;
  7627. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7628. if (string.IsNullOrEmpty(vehicleData))
  7629. vehicleData = "";
  7630. if (snResult != 0)
  7631. {
  7632. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7633. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7634. writeToPLC_Flag1.Adress = 2463;
  7635. writeToPLC_Flag1.Value = (short)4;
  7636. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7637. stopwatch1.Stop();
  7638. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7639. return;
  7640. }
  7641. string[] cavitySNs = vehicleData.Split('.');
  7642. if (cavitySNs != null && cavitySNs.Length > 0)
  7643. {
  7644. for (int i = 0; i < cavitySNs.Length; i++)
  7645. {
  7646. if (string.IsNullOrEmpty(cavitySNs[i]))
  7647. vehicleCodes.Add("");
  7648. else
  7649. vehicleCodes.Add(cavitySNs[i]);
  7650. }
  7651. }
  7652. #endregion 查询15个载具码
  7653. #region 查询15个产品SN
  7654. List<string> portNos = new List<string>(); // 15个产品SN
  7655. foreach (string vehicleCode in vehicleCodes)
  7656. {
  7657. if (string.IsNullOrEmpty(vehicleCode))
  7658. portNos.Add("");
  7659. else
  7660. {
  7661. // 查询
  7662. string cavityData = string.Empty;
  7663. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7664. if (string.IsNullOrEmpty(cavityData))
  7665. cavityData = "";
  7666. if (snResult1 != 0)
  7667. {
  7668. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7669. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7670. writeToPLC_Flag1.Adress = 2463;
  7671. writeToPLC_Flag1.Value = (short)4;
  7672. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7673. stopwatch1.Stop();
  7674. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7675. return;
  7676. }
  7677. string[] partSNs = cavityData.Split('.');
  7678. if (partSNs != null && partSNs.Length >= 1)
  7679. portNos.Add(partSNs[0]);
  7680. else
  7681. portNos.Add("");
  7682. }
  7683. }
  7684. #endregion 查询15个产品SN
  7685. // 调用MES进站(最多15个)
  7686. stopwatch2.Start();
  7687. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7688. for (int i = 0; i < vehicleCodes.Count; i++)
  7689. {
  7690. // 循环进站
  7691. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7692. {
  7693. // 产品SN(物料码)校验
  7694. string portNo = portNos[i];
  7695. List<TestItem> item = new List<TestItem>();
  7696. item.Add(new TestItem()
  7697. {
  7698. Parameter_name = "弹夹码",
  7699. Parameter_value = sn,
  7700. });
  7701. item.Add(new TestItem()
  7702. {
  7703. Parameter_name = "弹夹穴位",
  7704. Parameter_value = (i + 1).ToString(),
  7705. });
  7706. item.Add(new TestItem()
  7707. {
  7708. Parameter_name = "载具码",
  7709. Parameter_value = vehicleCodes[i],
  7710. });
  7711. item.Add(new TestItem()
  7712. {
  7713. Parameter_name = "载具穴号",
  7714. Parameter_value = "1",
  7715. });
  7716. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7717. }
  7718. }
  7719. stopwatch2.Stop();
  7720. short result = 0;
  7721. bool haveMesWarn = results.Contains(5);
  7722. bool havePCWarn = results.Contains(6);
  7723. if (haveMesWarn)
  7724. result = 2; // 5->2
  7725. else if (havePCWarn)
  7726. result = 6; // 6->4
  7727. else
  7728. result = 1;
  7729. // MES_Flag 为4MES报错
  7730. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7731. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7732. writeToPLC_Flag.Name = "d3MES_FLAG";
  7733. writeToPLC_Flag.Adress = 2463;
  7734. writeToPLC_Flag.Value = result;
  7735. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7736. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7737. }
  7738. catch (Exception ex)
  7739. {
  7740. stopwatch2.Stop();
  7741. // MES_Flag 为4上位机报错
  7742. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7743. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7744. writeToPLC_Flag.Name = "d3MES_FLAG";
  7745. writeToPLC_Flag.Adress = 2463;
  7746. writeToPLC_Flag.Value = (short)4;
  7747. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7748. string str = ex.StackTrace;
  7749. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7750. }
  7751. stopwatch1.Stop();
  7752. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7753. }
  7754. // 上次采集到的SN
  7755. //private string sn_S4_3出站接口 = string.Empty;
  7756. /// <summary>
  7757. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7758. /// </summary>
  7759. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7760. {
  7761. Stopwatch stopwatch1 = new Stopwatch();
  7762. Stopwatch stopwatch2 = new Stopwatch();
  7763. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7764. string stationNameStr = stationCode + stationName;
  7765. string processItem = stationName; // 测试项目
  7766. try
  7767. {
  7768. stopwatch1.Start();
  7769. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7770. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7771. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7772. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7773. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7774. sn = sn.Replace("\0", "");
  7775. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7776. bool isPass = d3Result == 1; // 产品结果 bool
  7777. #region 查询15个载具码
  7778. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7779. string vehicleData = string.Empty;
  7780. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7781. if (string.IsNullOrEmpty(vehicleData))
  7782. vehicleData = "";
  7783. if (snResult1 != 0)
  7784. {
  7785. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7786. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7787. writeToPLC_Flag1.Adress = 2463;
  7788. writeToPLC_Flag1.Value = (short)4;
  7789. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7790. stopwatch1.Stop();
  7791. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7792. return;
  7793. }
  7794. string[] cavitySNs = vehicleData.Split('.');
  7795. if (cavitySNs != null && cavitySNs.Length > 0)
  7796. {
  7797. for (int i = 0; i < cavitySNs.Length; i++)
  7798. {
  7799. if (string.IsNullOrEmpty(cavitySNs[i]))
  7800. vehicleCodes.Add("");
  7801. else
  7802. vehicleCodes.Add(cavitySNs[i]);
  7803. }
  7804. }
  7805. #endregion 查询15个载具码
  7806. // 统一查 产品SN列表
  7807. List<string> partNos = new List<string>();
  7808. foreach (string vehicleCode in vehicleCodes)
  7809. {
  7810. if (string.IsNullOrEmpty(vehicleCode))
  7811. partNos.Add("");
  7812. else
  7813. {
  7814. string partNo = "";
  7815. #region 查询载具上的产品信息
  7816. string cavityData = string.Empty;
  7817. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7818. if (string.IsNullOrEmpty(cavityData))
  7819. cavityData = "";
  7820. if (snResult != 0)
  7821. {
  7822. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7823. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7824. writeToPLC_Flag1.Adress = 2463;
  7825. writeToPLC_Flag1.Value = (short)4;
  7826. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7827. stopwatch1.Stop();
  7828. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7829. return;
  7830. }
  7831. string[] partSNs = cavityData.Split('.');
  7832. if (partSNs != null && partSNs.Length >= 1)
  7833. partNo = partSNs[0];
  7834. #endregion 查询载具上的产品信息
  7835. partNos.Add(partNo);
  7836. }
  7837. }
  7838. // 统一上传 - 调用MES出站
  7839. stopwatch2.Start();
  7840. List<int> results = new List<int>();
  7841. for (int i = 0; i < partNos.Count; i++)
  7842. {
  7843. string index = (i + 1).ToString(); // 弹夹穴号
  7844. if (string.IsNullOrEmpty(partNos[i]))
  7845. results.Add(1);
  7846. else
  7847. {
  7848. List<TestItem> items1 = new List<TestItem>();
  7849. items1.Add(new TestItem()
  7850. {
  7851. Parameter_name = "弹夹码",
  7852. Parameter_value = sn,
  7853. Parameter_unit = ""
  7854. });
  7855. items1.Add(new TestItem()
  7856. {
  7857. Parameter_name = "弹夹穴号",
  7858. Parameter_value = index,
  7859. Parameter_unit = ""
  7860. });
  7861. items1.Add(new TestItem()
  7862. {
  7863. Parameter_name = "载具码",
  7864. Parameter_value = vehicleCodes[i],
  7865. Parameter_unit = ""
  7866. });
  7867. items1.Add(new TestItem()
  7868. {
  7869. Parameter_name = "载具穴号",
  7870. Parameter_value = "1",
  7871. Parameter_unit = ""
  7872. });
  7873. items1.Add(new TestItem()
  7874. {
  7875. Parameter_name = "产品结果",
  7876. Parameter_value = d3Result == 1 ? "OK" : "NG",
  7877. Parameter_unit = ""
  7878. });
  7879. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7880. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  7881. results.Add(result1);
  7882. }
  7883. }
  7884. short result = 0;
  7885. if (results.All(a => a == 1))
  7886. result = 1;
  7887. else if (results.Contains(3))
  7888. result = 3;
  7889. else if (results.Contains(2))
  7890. result = 2;
  7891. else if (results.Contains(4))
  7892. result = 4;
  7893. else
  7894. result = 4;
  7895. stopwatch2.Stop();
  7896. // MES_Flag 为4MES报错
  7897. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7898. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7899. writeToPLC_Flag.Name = "d3MES_FLAG";
  7900. writeToPLC_Flag.Adress = 2463;
  7901. writeToPLC_Flag.Value = result;
  7902. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7903. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7904. }
  7905. catch (Exception ex)
  7906. {
  7907. stopwatch2.Restart();
  7908. // MES_Flag 为4上位机报错
  7909. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7910. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7911. writeToPLC_Flag.Name = "d3MES_FLAG";
  7912. writeToPLC_Flag.Adress = 2463;
  7913. writeToPLC_Flag.Value = (short)4;
  7914. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7915. string str = ex.StackTrace;
  7916. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7917. stopwatch2.Stop();
  7918. }
  7919. stopwatch1.Stop();
  7920. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7921. }
  7922. // 上次采集到的SN
  7923. //private string sn_S4_4进站接口 = string.Empty;
  7924. /// <summary>
  7925. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  7926. /// </summary>
  7927. private void S4_4进站接口(int plcNo, string stationNameStr)
  7928. {
  7929. Stopwatch stopwatch1 = new Stopwatch();
  7930. Stopwatch stopwatch2 = new Stopwatch();
  7931. try
  7932. {
  7933. stopwatch1.Start();
  7934. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  7935. sn = sn.Replace("\0", "");
  7936. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  7937. #region 查询15个载具码
  7938. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7939. string vehicleData = string.Empty;
  7940. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7941. if (string.IsNullOrEmpty(vehicleData))
  7942. vehicleData = "";
  7943. if (snResult != 0)
  7944. {
  7945. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7946. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7947. writeToPLC_Flag1.Adress = 2463;
  7948. writeToPLC_Flag1.Value = (short)4;
  7949. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7950. stopwatch1.Stop();
  7951. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7952. return;
  7953. }
  7954. string[] cavitySNs = vehicleData.Split('.');
  7955. if (cavitySNs != null && cavitySNs.Length > 0)
  7956. {
  7957. for (int i = 0; i < cavitySNs.Length; i++)
  7958. {
  7959. if (string.IsNullOrEmpty(cavitySNs[i]))
  7960. vehicleCodes.Add("");
  7961. else
  7962. vehicleCodes.Add(cavitySNs[i]);
  7963. }
  7964. }
  7965. #endregion 查询15个载具码
  7966. #region 查询15个产品SN
  7967. List<string> portNos = new List<string>(); // 15个产品SN
  7968. foreach (string vehicleCode in vehicleCodes)
  7969. {
  7970. if (string.IsNullOrEmpty(vehicleCode))
  7971. portNos.Add("");
  7972. else
  7973. {
  7974. // 查询
  7975. string cavityData = string.Empty;
  7976. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7977. if (string.IsNullOrEmpty(cavityData))
  7978. cavityData = "";
  7979. if (snResult1 != 0)
  7980. {
  7981. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7982. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7983. writeToPLC_Flag1.Adress = 2463;
  7984. writeToPLC_Flag1.Value = (short)4;
  7985. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7986. stopwatch1.Stop();
  7987. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7988. return;
  7989. }
  7990. string[] partSNs = cavityData.Split('.');
  7991. if (partSNs != null && partSNs.Length >= 1)
  7992. portNos.Add(partSNs[0]);
  7993. else
  7994. portNos.Add("");
  7995. }
  7996. }
  7997. #endregion 查询15个产品SN
  7998. // 调用MES进站(最多15个)
  7999. stopwatch2.Start();
  8000. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8001. for (int i = 0; i < vehicleCodes.Count; i++)
  8002. {
  8003. // 循环进站
  8004. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8005. {
  8006. // 产品SN(物料码)校验
  8007. string portNo = portNos[i];
  8008. List<TestItem> item = new List<TestItem>();
  8009. item.Add(new TestItem()
  8010. {
  8011. Parameter_name = "弹夹码",
  8012. Parameter_value = sn,
  8013. });
  8014. item.Add(new TestItem()
  8015. {
  8016. Parameter_name = "弹夹穴位",
  8017. Parameter_value = (i + 1).ToString(),
  8018. });
  8019. item.Add(new TestItem()
  8020. {
  8021. Parameter_name = "载具码",
  8022. Parameter_value = vehicleCodes[i],
  8023. });
  8024. item.Add(new TestItem()
  8025. {
  8026. Parameter_name = "载具穴号",
  8027. Parameter_value = "1",
  8028. });
  8029. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8030. }
  8031. }
  8032. stopwatch2.Stop();
  8033. short result = 0;
  8034. bool haveMesWarn = results.Contains(5);
  8035. bool havePCWarn = results.Contains(6);
  8036. if (haveMesWarn)
  8037. result = 2; // 5->2
  8038. else if (havePCWarn)
  8039. result = 6; // 6->4
  8040. else
  8041. result = 1;
  8042. // MES_Flag 为4MES报错
  8043. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8044. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8045. writeToPLC_Flag.Name = "d4MES_FLAG";
  8046. writeToPLC_Flag.Adress = 2496;
  8047. writeToPLC_Flag.Value = result;
  8048. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8049. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8050. }
  8051. catch (Exception ex)
  8052. {
  8053. stopwatch2.Stop();
  8054. // MES_Flag 为4上位机报错
  8055. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8056. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8057. writeToPLC_Flag.Name = "d4MES_FLAG";
  8058. writeToPLC_Flag.Adress = 2496;
  8059. writeToPLC_Flag.Value = (short)4;
  8060. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8061. string str = ex.StackTrace;
  8062. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8063. }
  8064. stopwatch1.Stop();
  8065. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8066. }
  8067. // 上次采集到的SN
  8068. //private string sn_S4_4出站接口 = string.Empty;
  8069. /// <summary>
  8070. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8071. /// </summary>
  8072. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8073. {
  8074. Stopwatch stopwatch1 = new Stopwatch();
  8075. Stopwatch stopwatch2 = new Stopwatch();
  8076. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8077. string stationNameStr = stationCode + stationName;
  8078. string processItem = stationName; // 测试项目
  8079. try
  8080. {
  8081. stopwatch1.Start();
  8082. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8083. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8084. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8085. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8086. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8087. sn = sn.Replace("\0", "");
  8088. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8089. bool isPass = d4Result == 1; // 产品结果 bool
  8090. #region 查询15个载具码
  8091. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8092. string vehicleData = string.Empty;
  8093. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8094. if (string.IsNullOrEmpty(vehicleData))
  8095. vehicleData = "";
  8096. if (snResult1 != 0)
  8097. {
  8098. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8099. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8100. writeToPLC_Flag1.Adress = 2496;
  8101. writeToPLC_Flag1.Value = (short)4;
  8102. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8103. stopwatch1.Stop();
  8104. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8105. return;
  8106. }
  8107. string[] cavitySNs = vehicleData.Split('.');
  8108. if (cavitySNs != null && cavitySNs.Length > 0)
  8109. {
  8110. for (int i = 0; i < cavitySNs.Length; i++)
  8111. {
  8112. if (string.IsNullOrEmpty(cavitySNs[i]))
  8113. vehicleCodes.Add("");
  8114. else
  8115. vehicleCodes.Add(cavitySNs[i]);
  8116. }
  8117. }
  8118. #endregion 查询15个载具码
  8119. // 统一查 产品SN列表
  8120. List<string> partNos = new List<string>();
  8121. foreach (string vehicleCode in vehicleCodes)
  8122. {
  8123. if (string.IsNullOrEmpty(vehicleCode))
  8124. partNos.Add("");
  8125. else
  8126. {
  8127. string partNo = "";
  8128. #region 查询载具上的产品信息
  8129. string cavityData = string.Empty;
  8130. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8131. if (string.IsNullOrEmpty(cavityData))
  8132. cavityData = "";
  8133. if (snResult != 0)
  8134. {
  8135. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8136. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8137. writeToPLC_Flag1.Adress = 2496;
  8138. writeToPLC_Flag1.Value = (short)4;
  8139. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8140. stopwatch1.Stop();
  8141. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8142. return;
  8143. }
  8144. string[] partSNs = cavityData.Split('.');
  8145. if (partSNs != null && partSNs.Length >= 1)
  8146. partNo = partSNs[0];
  8147. #endregion 查询载具上的产品信息
  8148. partNos.Add(partNo);
  8149. }
  8150. }
  8151. // 调用MES出站
  8152. stopwatch2.Start();
  8153. // 统一上传
  8154. List<int> results = new List<int>();
  8155. for (int i = 0; i < partNos.Count; i++)
  8156. {
  8157. string index = (i + 1).ToString(); // 弹夹穴号
  8158. if (string.IsNullOrEmpty(partNos[i]))
  8159. results.Add(1);
  8160. else
  8161. {
  8162. List<TestItem> items1 = new List<TestItem>();
  8163. items1.Add(new TestItem()
  8164. {
  8165. Parameter_name = "弹夹码",
  8166. Parameter_value = sn,
  8167. Parameter_unit = ""
  8168. });
  8169. items1.Add(new TestItem()
  8170. {
  8171. Parameter_name = "弹夹穴号",
  8172. Parameter_value = index,
  8173. Parameter_unit = ""
  8174. });
  8175. items1.Add(new TestItem()
  8176. {
  8177. Parameter_name = "载具码",
  8178. Parameter_value = vehicleCodes[i],
  8179. Parameter_unit = ""
  8180. });
  8181. items1.Add(new TestItem()
  8182. {
  8183. Parameter_name = "载具穴号",
  8184. Parameter_value = "1",
  8185. Parameter_unit = ""
  8186. });
  8187. items1.Add(new TestItem()
  8188. {
  8189. Parameter_name = "产品结果",
  8190. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8191. Parameter_unit = ""
  8192. });
  8193. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8194. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8195. results.Add(result1);
  8196. }
  8197. }
  8198. short result = 0;
  8199. if (results.All(a => a == 1))
  8200. result = 1;
  8201. else if (results.Contains(3))
  8202. result = 3;
  8203. else if (results.Contains(2))
  8204. result = 2;
  8205. else if (results.Contains(4))
  8206. result = 4;
  8207. else
  8208. result = 4;
  8209. stopwatch2.Stop();
  8210. // MES_Flag 为4MES报错
  8211. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8212. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8213. writeToPLC_Flag.Name = "d4MES_FLAG";
  8214. writeToPLC_Flag.Adress = 2496;
  8215. writeToPLC_Flag.Value = result;
  8216. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8217. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8218. }
  8219. catch (Exception ex)
  8220. {
  8221. stopwatch2.Restart();
  8222. // MES_Flag 为4上位机报错
  8223. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8224. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8225. writeToPLC_Flag.Name = "d4MES_FLAG";
  8226. writeToPLC_Flag.Adress = 2496;
  8227. writeToPLC_Flag.Value = (short)4;
  8228. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8229. string str = ex.StackTrace;
  8230. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8231. stopwatch2.Stop();
  8232. }
  8233. stopwatch1.Stop();
  8234. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8235. }
  8236. /// <summary>
  8237. /// [S4] 取放桁架 - S4_5弹夹扫码
  8238. /// </summary>
  8239. /// <param name="plcNo">PLC编号</param>
  8240. /// <param name="stationNameStr">工站全称</param>
  8241. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8242. {
  8243. Stopwatch stopwatch1 = new Stopwatch();
  8244. Stopwatch stopwatch2 = new Stopwatch();
  8245. try
  8246. {
  8247. stopwatch1.Start();
  8248. // ZS 弹夹扫码
  8249. string d5BulletclipCode = " "; // 扫到的码
  8250. short d5BulletclipScanCode = 2;
  8251. stopwatch2.Start();
  8252. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8253. //// MES_Flag
  8254. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8255. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8256. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8257. writeToPLC_Flag.Adress = 2528;
  8258. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8259. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8260. {
  8261. Name = "d5BulletclipCode",
  8262. Adress = 2529,
  8263. ValueType = PLCValueType.String,
  8264. ValueTypeStrLength = 20,
  8265. Value = d5BulletclipCode
  8266. });
  8267. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8268. stopwatch2.Stop();
  8269. }
  8270. catch (Exception ex)
  8271. {
  8272. string str = ex.StackTrace;
  8273. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8274. stopwatch2.Start();
  8275. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8276. //// MES_Flag
  8277. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8278. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8279. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8280. writeToPLC_Flag.Adress = 2528;
  8281. writeToPLC_Flag.Value = (short)6;
  8282. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8283. {
  8284. Name = "d5BulletclipCode",
  8285. Adress = 2529,
  8286. ValueType = PLCValueType.String,
  8287. ValueTypeStrLength = 20,
  8288. Value = " "
  8289. });
  8290. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8291. stopwatch2.Stop();
  8292. }
  8293. stopwatch1.Stop();
  8294. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8295. }
  8296. /// <summary>
  8297. /// [S4] 取放桁架 - S4_5载具扫码
  8298. /// </summary>
  8299. /// <param name="plcNo">PLC编号</param>
  8300. /// <param name="stationNameStr">工站全称</param>
  8301. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8302. {
  8303. Stopwatch stopwatch1 = new Stopwatch();
  8304. Stopwatch stopwatch2 = new Stopwatch();
  8305. try
  8306. {
  8307. stopwatch1.Start();
  8308. // ZS 载具扫码
  8309. string d5VehicleCode = " "; // 扫到的码
  8310. short d5VehicleScanCode = 2;
  8311. #region 进站
  8312. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8313. {
  8314. // 查产品SN
  8315. #region 查询载具上的产品信息
  8316. string cavityData = string.Empty;
  8317. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8318. if (string.IsNullOrEmpty(cavityData))
  8319. cavityData = "";
  8320. if (snResult != 0)
  8321. {
  8322. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8323. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8324. writeToPLC_Flag1.Adress = 2559;
  8325. writeToPLC_Flag1.Value = (short)6;
  8326. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8327. {
  8328. Name = "d5VehicleCode",
  8329. Adress = 2560,
  8330. ValueType = PLCValueType.String,
  8331. ValueTypeStrLength = 20,
  8332. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8333. });
  8334. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8335. stopwatch1.Stop();
  8336. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8337. return;
  8338. }
  8339. string[] cavitySNs = cavityData.Split('.');
  8340. string partNo = "";
  8341. if (cavitySNs != null && cavitySNs.Length >= 1)
  8342. {
  8343. partNo = cavitySNs[0];
  8344. }
  8345. #endregion 查询载具上的产品信息
  8346. List<TestItem> item = new List<TestItem>();
  8347. item.Add(new TestItem()
  8348. {
  8349. Parameter_name = "载具码",
  8350. Parameter_value = d5VehicleCode,
  8351. });
  8352. item.Add(new TestItem()
  8353. {
  8354. Parameter_name = "载具穴号",
  8355. Parameter_value = "1",
  8356. });
  8357. stopwatch2.Start();
  8358. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8359. stopwatch2.Stop();
  8360. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8361. }
  8362. #endregion 进站
  8363. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8364. //// MES_Flag
  8365. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8366. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8367. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8368. writeToPLC_Flag.Adress = 2559;
  8369. writeToPLC_Flag.Value = d5VehicleScanCode;
  8370. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8371. {
  8372. Name = "d5VehicleCode",
  8373. Adress = 2560,
  8374. ValueType = PLCValueType.String,
  8375. ValueTypeStrLength = 20,
  8376. Value = d5VehicleCode
  8377. });
  8378. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8379. }
  8380. catch (Exception ex)
  8381. {
  8382. string str = ex.StackTrace;
  8383. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8384. stopwatch2.Start();
  8385. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8386. //// MES_Flag
  8387. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8388. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8389. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8390. writeToPLC_Flag.Adress = 2559;
  8391. writeToPLC_Flag.Value = (short)6;
  8392. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8393. {
  8394. Name = "d5VehicleCode",
  8395. Adress = 2560,
  8396. ValueType = PLCValueType.String,
  8397. ValueTypeStrLength = 20,
  8398. Value = " "
  8399. });
  8400. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8401. stopwatch2.Stop();
  8402. }
  8403. stopwatch1.Stop();
  8404. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8405. }
  8406. // 上次采集到的SN
  8407. //private string sn_S4_5出站接口 = string.Empty;
  8408. /// <summary>
  8409. /// [S4] 取放桁架 - S4_5出站接口
  8410. /// </summary>
  8411. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8412. {
  8413. Stopwatch stopwatch1 = new Stopwatch();
  8414. Stopwatch stopwatch2 = new Stopwatch();
  8415. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8416. string stationNameStr = stationCode + stationName;
  8417. string processItem = stationName; // 测试项目
  8418. try
  8419. {
  8420. stopwatch1.Start();
  8421. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8422. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8423. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8424. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8425. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8426. sn = sn.Replace("\0", "");
  8427. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8428. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8429. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8430. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8431. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8432. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8433. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8434. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8435. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8436. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8437. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8438. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8439. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8440. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8441. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8442. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8443. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8444. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8445. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8446. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8447. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8448. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8449. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8450. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8451. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8452. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8453. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8454. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8455. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8456. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8457. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8458. bool pass = d5Result == 1;
  8459. // 存 载具SN列表
  8460. List<string> vehicleCodes = new List<string>()
  8461. {
  8462. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8463. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8464. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8465. };
  8466. // 统一查 产品SN列表
  8467. List<string> partNos = new List<string>();
  8468. foreach (string vehicleCode in vehicleCodes)
  8469. {
  8470. if (string.IsNullOrEmpty(vehicleCode))
  8471. partNos.Add("");
  8472. else
  8473. {
  8474. string partNo = "";
  8475. #region 查询载具上的产品信息
  8476. string cavityData = string.Empty;
  8477. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8478. if (string.IsNullOrEmpty(cavityData))
  8479. cavityData = "";
  8480. if (snResult != 0)
  8481. {
  8482. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8483. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8484. writeToPLC_Flag1.Adress = 2591;
  8485. writeToPLC_Flag1.Value = (short)4;
  8486. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8487. stopwatch1.Stop();
  8488. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8489. return;
  8490. }
  8491. string[] cavitySNs = cavityData.Split('.');
  8492. if (cavitySNs != null && cavitySNs.Length >= 1)
  8493. partNo = cavitySNs[0];
  8494. #endregion 查询载具上的产品信息
  8495. partNos.Add(partNo);
  8496. }
  8497. }
  8498. // 统一上传
  8499. stopwatch2.Start();
  8500. List<int> results = new List<int>();
  8501. for (int i = 0; i < partNos.Count; i++)
  8502. {
  8503. string index = (i + 1).ToString(); // 弹夹穴号
  8504. if (string.IsNullOrEmpty(partNos[i]))
  8505. results.Add(1);
  8506. else
  8507. {
  8508. List<TestItem> items1 = new List<TestItem>();
  8509. items1.Add(new TestItem()
  8510. {
  8511. Parameter_name = "弹夹码",
  8512. Parameter_value = sn,
  8513. Parameter_unit = ""
  8514. });
  8515. items1.Add(new TestItem()
  8516. {
  8517. Parameter_name = "弹夹穴号",
  8518. Parameter_value = index,
  8519. Parameter_unit = ""
  8520. });
  8521. items1.Add(new TestItem()
  8522. {
  8523. Parameter_name = "载具码",
  8524. Parameter_value = vehicleCodes[i],
  8525. Parameter_unit = ""
  8526. });
  8527. items1.Add(new TestItem()
  8528. {
  8529. Parameter_name = "载具穴号",
  8530. Parameter_value = "1",
  8531. Parameter_unit = ""
  8532. });
  8533. items1.Add(new TestItem()
  8534. {
  8535. Parameter_name = "产品结果",
  8536. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8537. Parameter_unit = ""
  8538. });
  8539. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8540. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8541. results.Add(result1);
  8542. }
  8543. }
  8544. short result = 0;
  8545. if (results.All(a => a == 1))
  8546. result = 1;
  8547. else if (results.Contains(3))
  8548. result = 3;
  8549. else if (results.Contains(2))
  8550. result = 2;
  8551. else if (results.Contains(4))
  8552. result = 4;
  8553. else
  8554. result = 4;
  8555. stopwatch2.Stop();
  8556. #region 存储绑定数据到 边线MES系统中
  8557. if (result == 1)
  8558. {
  8559. // 删除绑定信息
  8560. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8561. if (resultMesR != 0)
  8562. {
  8563. result = 4;
  8564. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8565. }
  8566. }
  8567. #endregion 存储绑定数据到 边线MES系统中
  8568. // MES_Flag 为4MES报错
  8569. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8570. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8571. writeToPLC_Flag.Name = "d5MES_FLAG";
  8572. writeToPLC_Flag.Adress = 2591;
  8573. writeToPLC_Flag.Value = result;
  8574. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8575. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8576. }
  8577. catch (Exception ex)
  8578. {
  8579. stopwatch2.Restart();
  8580. // MES_Flag 为4上位机报错
  8581. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8582. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8583. writeToPLC_Flag.Name = "d5MES_FLAG";
  8584. writeToPLC_Flag.Adress = 2591;
  8585. writeToPLC_Flag.Value = (short)4;
  8586. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8587. stopwatch2.Stop();
  8588. string str = ex.StackTrace;
  8589. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8590. }
  8591. stopwatch1.Stop();
  8592. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8593. }
  8594. /// <summary>
  8595. /// [S4] 取放桁架 - S4_5节拍接口
  8596. /// </summary>
  8597. /// <param name="plcNo">PLC编号</param>
  8598. /// <param name="stationNameStr">工站全称</param>
  8599. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8600. {
  8601. Stopwatch stopwatch1 = new Stopwatch();
  8602. Stopwatch stopwatch2 = new Stopwatch();
  8603. string resultStr = string.Empty;
  8604. try
  8605. {
  8606. stopwatch1.Start();
  8607. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8608. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8609. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8610. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8611. if (!actionBool)
  8612. {
  8613. stopwatch2.Start();
  8614. // MES_Flag
  8615. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8616. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8617. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8618. writeToPLC_Flag1.Adress = 2924;
  8619. writeToPLC_Flag1.Value = (short)4;
  8620. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8621. stopwatch2.Stop();
  8622. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8623. return;
  8624. }
  8625. string d5OEEPartNo = string.Empty; // 物料码
  8626. if (string.IsNullOrEmpty(d5OEEProductSN))
  8627. {
  8628. stopwatch2.Start();
  8629. // MES_Flag
  8630. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8631. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8632. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8633. writeToPLC_Flag1.Adress = 2924;
  8634. writeToPLC_Flag1.Value = (short)1;
  8635. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8636. stopwatch2.Stop();
  8637. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8638. return;
  8639. }
  8640. else
  8641. { // 查产品SN
  8642. d5OEEPartNo = "Test"; // ZS
  8643. }
  8644. short d5OEEMES_FLAG = 0;
  8645. // 上传OEE
  8646. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8647. d5OEEMES_FLAG = result.Item1;
  8648. resultStr = result.Item2;
  8649. stopwatch2.Start();
  8650. // MES_Flag
  8651. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8652. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8653. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8654. writeToPLC_Flag.Adress = 2924;
  8655. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8656. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8657. stopwatch2.Stop();
  8658. }
  8659. catch (Exception ex)
  8660. {
  8661. string str = ex.StackTrace;
  8662. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8663. // MES_Flag
  8664. stopwatch2.Start();
  8665. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8666. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8667. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8668. writeToPLC_Flag.Adress = 2924;
  8669. writeToPLC_Flag.Value = (short)4;
  8670. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8671. stopwatch2.Stop();
  8672. }
  8673. stopwatch1.Stop();
  8674. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8675. }
  8676. #endregion [S4] 取放桁架
  8677. #endregion PLC4 刘果段
  8678. #region PLC5 张超凡
  8679. #region [S5] Tray盘下料装备
  8680. /// <summary>
  8681. /// S5工位的数据- 触发信号上次的值
  8682. /// </summary>
  8683. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8684. /// <summary>
  8685. /// S5工位的数据(含触发信号)
  8686. /// </summary>
  8687. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8688. /// <summary>
  8689. /// S5工位的数据- 回写点位
  8690. /// </summary>
  8691. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8692. /// <summary>
  8693. /// [S5] Tray盘下料装备
  8694. /// </summary>
  8695. /// <param name="plcNo">PLC编号</param>
  8696. //private void ReadStation_S5(int plcNo)
  8697. //{
  8698. // // [S1] Tray盘上料装备
  8699. // // [S2] FCT
  8700. // // [S3] 值板机
  8701. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8702. // // [S5] Tray盘下料装备
  8703. // /// 上位机心跳
  8704. // /// 获取设备报警数据与状态信息
  8705. // string stationCode = "[S5]";
  8706. // string stationName = "Tray盘下料装备";
  8707. // string stationNameStr = stationCode + stationName;
  8708. // #region 创建字典
  8709. // // 触发信号字典 赋值
  8710. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8711. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8712. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8713. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8714. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8715. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8716. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8717. // // PLC数据字典 赋值
  8718. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8719. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8720. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8721. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8722. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8723. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8724. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8725. // s5PLCData.Add("e1Result", 0); // 产品结果
  8726. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8727. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8728. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8729. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8730. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8731. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8732. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8733. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8734. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8735. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8736. // #endregion 创建字典
  8737. // while (IsRun)
  8738. // {
  8739. // try
  8740. // {
  8741. // if (!GlobalContext._IsCon_Funs5)
  8742. // {
  8743. // UpdatePLCMonitor(1, plcNo, 0);
  8744. // continue;
  8745. // }
  8746. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8747. // {
  8748. // Stopwatch stopwatch1 = new Stopwatch();
  8749. // Stopwatch stopwatch2 = new Stopwatch();
  8750. // stopwatch1.Start();
  8751. // stopwatch2.Start();
  8752. // #region 一次性读取所有数据
  8753. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8754. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8755. // int[] datas = data1.Concat(data2).ToArray();
  8756. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8757. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8758. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8759. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8760. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8761. // s5PLCData["e1MES_FLAG"] = datas[35];
  8762. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8763. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8764. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8765. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8766. // s5PLCData["e1Result"] = datas[76];
  8767. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8768. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8769. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8770. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8771. // s5PLCData["e1OEEType"] = datas[109];
  8772. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8773. // s5PLCData["e1AGVUpStart"] = datas[121];
  8774. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8775. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8776. // s5PLCData["e1AGVDownStart"] = datas[134];
  8777. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8778. // #endregion 一次性读取所有数据
  8779. // stopwatch2.Stop();
  8780. // #region 回写操作,写后清空flag
  8781. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8782. // #endregion 回写操作,写后清空flag
  8783. // #region 进站校验
  8784. // try
  8785. // {
  8786. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8787. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8788. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  8789. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  8790. // {
  8791. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  8792. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8793. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  8794. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8795. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  8796. // }
  8797. // }
  8798. // catch (Exception ex)
  8799. // {
  8800. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8801. // string str = ex.StackTrace;
  8802. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8803. // }
  8804. // #endregion 进站校验
  8805. // #region 出站接口
  8806. // try
  8807. // {
  8808. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  8809. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  8810. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  8811. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  8812. // {
  8813. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  8814. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8815. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  8816. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  8817. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  8818. // }
  8819. // }
  8820. // catch (Exception ex)
  8821. // {
  8822. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  8823. // string str = ex.StackTrace;
  8824. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8825. // }
  8826. // #endregion 出站接口
  8827. // #region 节拍接口
  8828. // try
  8829. // {
  8830. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  8831. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  8832. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  8833. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  8834. // {
  8835. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  8836. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8837. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  8838. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  8839. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  8840. // }
  8841. // }
  8842. // catch (Exception ex)
  8843. // {
  8844. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  8845. // string str = ex.StackTrace;
  8846. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8847. // }
  8848. // #endregion 节拍接口
  8849. // #region AGV上料
  8850. // // AGV上料叫AGV信号
  8851. // try
  8852. // {
  8853. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  8854. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  8855. // if (e1AGVUpCall != e1AGVUpCallOld)
  8856. // {
  8857. // if (e1AGVUpCall == 1) // 0->1
  8858. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  8859. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  8860. // }
  8861. // }
  8862. // catch (Exception ex)
  8863. // {
  8864. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  8865. // string str = ex.StackTrace;
  8866. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8867. // }
  8868. // // AGV上料完成信号
  8869. // try
  8870. // {
  8871. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  8872. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  8873. // if (e1AGVUpEnd != e1AGVUpEndOld)
  8874. // {
  8875. // if (e1AGVUpEnd == 1) // 0->1
  8876. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  8877. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  8878. // }
  8879. // }
  8880. // catch (Exception ex)
  8881. // {
  8882. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  8883. // string str = ex.StackTrace;
  8884. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8885. // }
  8886. // #endregion AGV上料
  8887. // #region AGV下料
  8888. // // AGV下料叫agv信号
  8889. // try
  8890. // {
  8891. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  8892. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  8893. // if (e1AGVDownCall != e1AGVDownCallOld)
  8894. // {
  8895. // if (e1AGVDownCall == 1) // 0->1
  8896. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  8897. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  8898. // }
  8899. // }
  8900. // catch (Exception ex)
  8901. // {
  8902. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  8903. // string str = ex.StackTrace;
  8904. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8905. // }
  8906. // // AGV下料完成信号
  8907. // try
  8908. // {
  8909. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  8910. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  8911. // if (e1AGVDownEnd != e1AGVDownEndOld)
  8912. // {
  8913. // if (e1AGVDownEnd == 1) // 0->1
  8914. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  8915. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  8916. // }
  8917. // }
  8918. // catch (Exception ex)
  8919. // {
  8920. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  8921. // string str = ex.StackTrace;
  8922. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8923. // }
  8924. // #endregion AGV下料
  8925. // #region 心跳
  8926. // try
  8927. // {
  8928. // short states = 0;
  8929. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8930. // }
  8931. // catch (Exception ex)
  8932. // {
  8933. // string str = ex.StackTrace;
  8934. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8935. // }
  8936. // #endregion 心跳
  8937. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8938. // stopwatch1.Stop();
  8939. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8940. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8941. // }
  8942. // else
  8943. // {
  8944. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8945. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8946. // Funs[plcNo].Connect();
  8947. // }
  8948. // }
  8949. // catch (Exception ex)
  8950. // {
  8951. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8952. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8953. // Funs[plcNo].ReConnect();
  8954. // }
  8955. // Thread.Sleep(IntervalReadPLC);
  8956. // }
  8957. //}
  8958. /// <summary>
  8959. /// [S5] Tray盘下料装备 - 进站校验
  8960. /// </summary>
  8961. /// <param name="plcNo">PLC编号</param>
  8962. /// <param name="stationNameStr">工站全称</param>
  8963. private void S5进站校验(int plcNo, string stationNameStr)
  8964. {
  8965. Stopwatch stopwatch1 = new Stopwatch();
  8966. Stopwatch stopwatch2 = new Stopwatch();
  8967. try
  8968. {
  8969. stopwatch1.Start();
  8970. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  8971. sn = sn.Replace("\0", "");
  8972. // 获取产品SN By 载具码
  8973. #region 查询载具上的产品信息
  8974. string cavityData = string.Empty;
  8975. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8976. if (string.IsNullOrEmpty(cavityData))
  8977. cavityData = "";
  8978. if (snResult != 0)
  8979. {
  8980. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8981. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  8982. writeToPLC_Flag1.Adress = 2003;
  8983. writeToPLC_Flag1.Value = (short)6;
  8984. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  8985. stopwatch1.Stop();
  8986. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8987. return;
  8988. }
  8989. string[] cavitySNs = cavityData.Split('.');
  8990. string partNo = string.Empty;
  8991. if (cavitySNs != null && cavitySNs.Length >= 1)
  8992. partNo = cavitySNs[0];
  8993. #endregion 查询载具上的产品信息
  8994. // 产品SN(物料码)校验
  8995. List<TestItem> item = new List<TestItem>();
  8996. item.Add(new TestItem()
  8997. {
  8998. Parameter_name = "载具码",
  8999. Parameter_value = sn,
  9000. });
  9001. item.Add(new TestItem()
  9002. {
  9003. Parameter_name = "载具穴号",
  9004. Parameter_value = "1",
  9005. });
  9006. stopwatch2.Start();
  9007. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9008. stopwatch2.Stop();
  9009. short e1MES_FLAG_Check = (short)result;
  9010. // MES_Flag
  9011. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9012. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9013. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9014. writeToPLC_Flag.Adress = 2003;
  9015. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9016. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9017. }
  9018. catch (Exception ex)
  9019. {
  9020. string str = ex.StackTrace;
  9021. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9022. // MES_Flag
  9023. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9024. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9025. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9026. writeToPLC_Flag.Adress = 2003;
  9027. writeToPLC_Flag.Value = (short)6;
  9028. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9029. }
  9030. stopwatch1.Stop();
  9031. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9032. }
  9033. /// <summary>
  9034. /// [S5] Tray盘下料装备 - 出站接口
  9035. /// </summary>
  9036. /// <param name="plcNo"></param>
  9037. /// <param name="stationCode"></param>
  9038. /// <param name="stationName"></param>
  9039. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9040. {
  9041. Stopwatch stopwatch1 = new Stopwatch();
  9042. Stopwatch stopwatch2 = new Stopwatch();
  9043. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9044. string stationNameStr = stationCode + stationName;
  9045. string processItem = stationName; // 测试项目
  9046. try
  9047. {
  9048. stopwatch1.Start();
  9049. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9050. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9051. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9052. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9053. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9054. sn = sn.Replace("\0", "");
  9055. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9056. //partNo = partNo.Replace("\0", "");
  9057. #region 查询载具上的产品信息
  9058. string cavityData = string.Empty;
  9059. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9060. if (string.IsNullOrEmpty(cavityData))
  9061. cavityData = "";
  9062. if (snResult != 0)
  9063. {
  9064. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9065. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9066. writeToPLC_Flag1.Adress = 2035;
  9067. writeToPLC_Flag1.Value = (short)4;
  9068. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9069. stopwatch1.Stop();
  9070. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9071. return;
  9072. }
  9073. string[] cavitySNs = cavityData.Split('.');
  9074. string partNo = string.Empty;
  9075. if (cavitySNs != null && cavitySNs.Length >= 1)
  9076. partNo = cavitySNs[0];
  9077. #endregion 查询载具上的产品信息
  9078. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9079. bool pass = e1Result == 1;
  9080. stopwatch2.Start();
  9081. // 上传MES
  9082. List<TestItem> items = new List<TestItem>();
  9083. items.Add(new TestItem()
  9084. {
  9085. Parameter_name = "载具码",
  9086. Parameter_value = sn,
  9087. Parameter_unit = ""
  9088. });
  9089. items.Add(new TestItem()
  9090. {
  9091. Parameter_name = "载具穴号",
  9092. Parameter_value = "1",
  9093. Parameter_unit = ""
  9094. });
  9095. items.Add(new TestItem()
  9096. {
  9097. Parameter_name = "产品结果",
  9098. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9099. Parameter_unit = ""
  9100. });
  9101. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  9102. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9103. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9104. short result = result1 == 1 ? (short)1 : (short)3;
  9105. stopwatch2.Stop();
  9106. #region 存储绑定数据到 边线MES系统中
  9107. if (result == 1)
  9108. {
  9109. // 删除绑定信息
  9110. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9111. if (resultMesR != 0)
  9112. {
  9113. result = 4;
  9114. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9115. }
  9116. }
  9117. #endregion 存储绑定数据到 边线MES系统中
  9118. // MES_Flag 为MES报错
  9119. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9120. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9121. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9122. writeToPLC_Flag.Name = "e1MES_FLAG";
  9123. writeToPLC_Flag.Adress = 2035;
  9124. writeToPLC_Flag.Value = result;
  9125. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9126. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9127. }
  9128. catch (Exception ex)
  9129. {
  9130. stopwatch2.Restart();
  9131. // MES_Flag 为4上位机报错
  9132. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9133. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9134. writeToPLC_Flag.Name = "e1MES_FLAG";
  9135. writeToPLC_Flag.Adress = 2035;
  9136. writeToPLC_Flag.Value = (short)4;
  9137. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9138. stopwatch2.Stop();
  9139. string str = ex.StackTrace;
  9140. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9141. }
  9142. stopwatch1.Stop();
  9143. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9144. }
  9145. /// <summary>
  9146. /// [S5] Tray盘下料装备 - 节拍接口
  9147. /// </summary>
  9148. /// <param name="plcNo">PLC编号</param>
  9149. /// <param name="stationNameStr">工站全称</param>
  9150. private void S5节拍接口(int plcNo, string stationNameStr)
  9151. {
  9152. Stopwatch stopwatch1 = new Stopwatch();
  9153. Stopwatch stopwatch2 = new Stopwatch();
  9154. string resultStr = string.Empty;
  9155. try
  9156. {
  9157. stopwatch1.Start();
  9158. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9159. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9160. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9161. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9162. if (!actionBool)
  9163. {
  9164. stopwatch2.Start();
  9165. // MES_Flag
  9166. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9167. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9168. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9169. writeToPLC_Flag1.Adress = 2088;
  9170. writeToPLC_Flag1.Value = (short)4;
  9171. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9172. stopwatch2.Stop();
  9173. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9174. return;
  9175. }
  9176. string e1OEEPartNo = string.Empty; // 物料码
  9177. if (string.IsNullOrEmpty(e1OEEProductSN))
  9178. {
  9179. stopwatch2.Start();
  9180. // MES_Flag
  9181. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9182. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9183. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9184. writeToPLC_Flag1.Adress = 2088;
  9185. writeToPLC_Flag1.Value = (short)1;
  9186. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9187. stopwatch2.Stop();
  9188. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9189. return;
  9190. }
  9191. else
  9192. { // 查产品SN
  9193. e1OEEPartNo = "Test"; // ZS
  9194. }
  9195. short e1OEEMES_FLAG = 0;
  9196. // 上传OEE
  9197. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9198. e1OEEMES_FLAG = result.Item1;
  9199. resultStr = result.Item2;
  9200. stopwatch2.Start();
  9201. // MES_Flag
  9202. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9203. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9204. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9205. writeToPLC_Flag.Adress = 2088;
  9206. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9207. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9208. stopwatch2.Stop();
  9209. }
  9210. catch (Exception ex)
  9211. {
  9212. string str = ex.StackTrace;
  9213. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9214. // MES_Flag
  9215. stopwatch2.Start();
  9216. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9217. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9218. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9219. writeToPLC_Flag.Adress = 2088;
  9220. writeToPLC_Flag.Value = (short)4;
  9221. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9222. stopwatch2.Stop();
  9223. }
  9224. stopwatch1.Stop();
  9225. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9226. }
  9227. /// <summary>
  9228. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9229. /// </summary>
  9230. /// <param name="plcNo">PLC编号</param>
  9231. /// <param name="stationNameStr">工站全称</param>
  9232. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9233. {
  9234. Stopwatch stopwatch1 = new Stopwatch();
  9235. Stopwatch stopwatch2 = new Stopwatch();
  9236. try
  9237. {
  9238. stopwatch1.Start();
  9239. // ZS 呼叫AGV
  9240. short e1AGVUpCall = 2;
  9241. stopwatch2.Start();
  9242. // e1AGVUpCall
  9243. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9244. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9245. writeToPLC_Flag.Name = "e1AGVUpCall";
  9246. writeToPLC_Flag.Adress = 2120;
  9247. writeToPLC_Flag.Value = e1AGVUpCall;
  9248. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9249. stopwatch2.Stop();
  9250. }
  9251. catch (Exception ex)
  9252. {
  9253. string str = ex.StackTrace;
  9254. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9255. // e1AGVUpCall
  9256. stopwatch2.Start();
  9257. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9258. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9259. writeToPLC_Flag.Name = "e1AGVUpCall";
  9260. writeToPLC_Flag.Adress = 2120;
  9261. writeToPLC_Flag.Value = (short)4;
  9262. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9263. stopwatch2.Stop();
  9264. }
  9265. stopwatch1.Stop();
  9266. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9267. }
  9268. /// <summary>
  9269. /// [S5] Tray盘下料装备 - AGV上料完成
  9270. /// </summary>
  9271. /// <param name="plcNo">PLC编号</param>
  9272. /// <param name="stationNameStr">工站全称</param>
  9273. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9274. {
  9275. Stopwatch stopwatch1 = new Stopwatch();
  9276. Stopwatch stopwatch2 = new Stopwatch();
  9277. try
  9278. {
  9279. stopwatch1.Start();
  9280. // ZS AGV上料完成,让小车离开
  9281. short e1AGVUpEnd = 2;
  9282. stopwatch2.Start();
  9283. // e1AGVUpEnd
  9284. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9285. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9286. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9287. writeToPLC_Flag.Adress = 2122;
  9288. writeToPLC_Flag.Value = e1AGVUpEnd;
  9289. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9290. stopwatch2.Stop();
  9291. }
  9292. catch (Exception ex)
  9293. {
  9294. string str = ex.StackTrace;
  9295. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9296. // e1AGVUpEnd
  9297. stopwatch2.Start();
  9298. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9299. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9300. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9301. writeToPLC_Flag.Adress = 2122;
  9302. writeToPLC_Flag.Value = (short)4;
  9303. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9304. stopwatch2.Stop();
  9305. }
  9306. stopwatch1.Stop();
  9307. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9308. }
  9309. /// <summary>
  9310. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9311. /// </summary>
  9312. /// <param name="plcNo">PLC编号</param>
  9313. /// <param name="stationNameStr">工站全称</param>
  9314. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9315. {
  9316. Stopwatch stopwatch1 = new Stopwatch();
  9317. Stopwatch stopwatch2 = new Stopwatch();
  9318. try
  9319. {
  9320. stopwatch1.Start();
  9321. // ZS 呼叫AGV
  9322. short e1AGVDownCall = 2;
  9323. stopwatch2.Start();
  9324. // e1AGVDownCall
  9325. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9326. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9327. writeToPLC_Flag.Name = "e1AGVDownCall";
  9328. writeToPLC_Flag.Adress = 2133;
  9329. writeToPLC_Flag.Value = e1AGVDownCall;
  9330. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9331. stopwatch2.Stop();
  9332. }
  9333. catch (Exception ex)
  9334. {
  9335. string str = ex.StackTrace;
  9336. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9337. // e1AGVDownCall
  9338. stopwatch2.Start();
  9339. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9340. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9341. writeToPLC_Flag.Name = "e1AGVDownCall";
  9342. writeToPLC_Flag.Adress = 2133;
  9343. writeToPLC_Flag.Value = (short)4;
  9344. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9345. stopwatch2.Stop();
  9346. }
  9347. stopwatch1.Stop();
  9348. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9349. }
  9350. /// <summary>
  9351. /// [S5] Tray盘下料装备 - AGV下料完成
  9352. /// </summary>
  9353. /// <param name="plcNo">PLC编号</param>
  9354. /// <param name="stationNameStr">工站全称</param>
  9355. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9356. {
  9357. Stopwatch stopwatch1 = new Stopwatch();
  9358. Stopwatch stopwatch2 = new Stopwatch();
  9359. try
  9360. {
  9361. stopwatch1.Start();
  9362. // ZS AGV上料完成,让小车离开
  9363. short e1AGVDownEnd = 2;
  9364. stopwatch2.Start();
  9365. // e1AGVDownEnd
  9366. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9367. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9368. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9369. writeToPLC_Flag.Adress = 2135;
  9370. writeToPLC_Flag.Value = e1AGVDownEnd;
  9371. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9372. stopwatch2.Stop();
  9373. }
  9374. catch (Exception ex)
  9375. {
  9376. string str = ex.StackTrace;
  9377. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9378. // e1AGVDownEnd
  9379. stopwatch2.Start();
  9380. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9381. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9382. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9383. writeToPLC_Flag.Adress = 2135;
  9384. writeToPLC_Flag.Value = (short)4;
  9385. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9386. stopwatch2.Stop();
  9387. }
  9388. stopwatch1.Stop();
  9389. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9390. }
  9391. #endregion [S5] Tray盘下料装备
  9392. #endregion PLC5 张超凡
  9393. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9394. /// <summary>
  9395. /// PLC读取到的数据 -添加数据
  9396. /// </summary>
  9397. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9398. {
  9399. if (sxPlcData.ContainsKey(newKey))
  9400. sxPlcData[newKey] = newValue;
  9401. else
  9402. sxPlcData.Add(newKey, newValue);
  9403. }
  9404. /// <summary>
  9405. /// PLC需要写入的数据 -添加数据
  9406. /// </summary>
  9407. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9408. {
  9409. if (sxPLCWriteData.ContainsKey(newKey))
  9410. sxPLCWriteData[newKey] = newValue;
  9411. else
  9412. sxPLCWriteData.Add(newKey, newValue);
  9413. }
  9414. /// <summary>
  9415. /// PLC回写操作,写后清空flag
  9416. /// </summary>
  9417. /// <param name="modbusClient">modbus对象</param>
  9418. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9419. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9420. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9421. {
  9422. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9423. {
  9424. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9425. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9426. {
  9427. string mesFlagName = pLCWriteDatas[i].Name;
  9428. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9429. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9430. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9431. {
  9432. // 先回写数据
  9433. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9434. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9435. {
  9436. int mesDataAdress = writeToPLCDatas[j].Adress;
  9437. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9438. switch (mesDataType)
  9439. {
  9440. case PLCValueType.Short:
  9441. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9442. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9443. break;
  9444. case PLCValueType.String:
  9445. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9446. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9447. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9448. break;
  9449. }
  9450. }
  9451. // 再回写信号
  9452. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9453. // 存储读取数据的字典
  9454. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9455. // 存储写入数据的字典 - 清空写入值
  9456. pLCWriteDatas[i].Value = (short)0;
  9457. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9458. }
  9459. }
  9460. }
  9461. }
  9462. /// <summary>
  9463. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9464. /// </summary>
  9465. /// <param name="no">3</param>
  9466. /// <param name="stationCode">设备编号</param>
  9467. /// <param name="stationNameStr">设备名称</param>
  9468. /// <param name="plcOrder">车间订单号</param>
  9469. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9470. {
  9471. try
  9472. {
  9473. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9474. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9475. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9476. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9477. int result1 = 0;
  9478. switch (stationCode)
  9479. {
  9480. case 2:
  9481. case 3:
  9482. case 4:
  9483. case 6:
  9484. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9485. break;
  9486. case 102:
  9487. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9488. break;
  9489. case 103:
  9490. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9491. break;
  9492. case 104:
  9493. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9494. break;
  9495. case 106:
  9496. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9497. break;
  9498. default:
  9499. // MES_Flag 为“6未找到正确设备编号”
  9500. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9501. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9502. return;
  9503. }
  9504. short result = result1 == 1 ? (short)1 : (short)2;
  9505. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9506. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9507. }
  9508. catch (Exception ex)
  9509. {
  9510. // MES_Flag 为2上位机报错
  9511. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9512. string str = ex.StackTrace;
  9513. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9514. }
  9515. }
  9516. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9517. #region UI刷新
  9518. /// <summary>
  9519. /// 更新商品信息的UI + 下发产品信息(SN)
  9520. /// </summary>
  9521. private void UpdateProductInfo()
  9522. {
  9523. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9524. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9525. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9526. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9527. }
  9528. /// <summary>
  9529. /// 更新PLC连接状态的UI
  9530. /// </summary>
  9531. /// <param name="no">PLC编号</param>
  9532. /// <param name="status">状态</param>
  9533. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9534. {
  9535. if (this != null && !this.IsDisposed)
  9536. {
  9537. switch (imgNo)
  9538. {
  9539. case 1:
  9540. this.BeginInvoke(new Action(() =>
  9541. {
  9542. picPLC.Image = imageListState.Images[status];
  9543. }));
  9544. break;
  9545. case 2:
  9546. this.BeginInvoke(new Action(() =>
  9547. {
  9548. pictureBox2.Image = imageListState.Images[status];
  9549. }));
  9550. break;
  9551. case 3:
  9552. this.BeginInvoke(new Action(() =>
  9553. {
  9554. pictureBox3.Image = imageListState.Images[status];
  9555. }));
  9556. break;
  9557. case 4:
  9558. this.BeginInvoke(new Action(() =>
  9559. {
  9560. pictureBox4.Image = imageListState.Images[status];
  9561. }));
  9562. break;
  9563. case 5:
  9564. this.BeginInvoke(new Action(() =>
  9565. {
  9566. pictureBox5.Image = imageListState.Images[status];
  9567. }));
  9568. break;
  9569. case 6:
  9570. this.BeginInvoke(new Action(() =>
  9571. {
  9572. pictureBox6.Image = imageListState.Images[status];
  9573. }));
  9574. break;
  9575. case 7:
  9576. this.BeginInvoke(new Action(() =>
  9577. {
  9578. pictureBox7.Image = imageListState.Images[status];
  9579. }));
  9580. break;
  9581. case 8:
  9582. this.BeginInvoke(new Action(() =>
  9583. {
  9584. pictureBox8.Image = imageListState.Images[status];
  9585. }));
  9586. break;
  9587. default:
  9588. break;
  9589. }
  9590. }
  9591. Task.Run(() => // 更新PLC交互页的指示灯
  9592. {
  9593. try
  9594. {
  9595. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9596. {
  9597. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9598. }
  9599. }
  9600. catch { }
  9601. });
  9602. }
  9603. #endregion UI刷新
  9604. #region 日志
  9605. /// <summary>
  9606. /// 添加各工位运行日志(同步至PLC交互页面)
  9607. /// </summary>
  9608. /// <param name="stationNameStr">工站名称</param>
  9609. /// <param name="logType">日志类型</param>
  9610. /// <param name="message">日志内容</param>
  9611. /// <param name="snNumber">产品数字SN</param>
  9612. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9613. {
  9614. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9615. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9616. ))
  9617. {
  9618. AddMessage(logType, message); // 首页展示+日志记录
  9619. }
  9620. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9621. {
  9622. StationName = stationNameStr,
  9623. SnNumber = snNumber,
  9624. Message = message,
  9625. CreateTime = DateTime.Now
  9626. };
  9627. // PLC交互页展示
  9628. Task.Run(() =>
  9629. {
  9630. try
  9631. {
  9632. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9633. {
  9634. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9635. }
  9636. }
  9637. catch { }
  9638. });
  9639. }
  9640. /// <summary>
  9641. /// 添加运行日志
  9642. /// </summary>
  9643. /// <param name="logType">日志类型</param>
  9644. /// <param name="message">日志内容</param>
  9645. public void AddMessage(LogType logType, string message)
  9646. {
  9647. OnMessage(logType, message);
  9648. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9649. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9650. string msgShow = time + "--> " + message + "\r\n";
  9651. this.BeginInvoke(new Action(() =>
  9652. {
  9653. systemLog.Rows.Insert(0, date, time, message);
  9654. if (systemLog.Rows.Count >= 100)
  9655. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9656. }));
  9657. }
  9658. /// <summary>
  9659. /// 添加运行日志-保存
  9660. /// </summary>
  9661. /// <param name="logType">日志类型</param>
  9662. /// <param name="message">日志内容</param>
  9663. private void OnMessage(LogType logType, string msg)
  9664. {
  9665. MessageEvent?.Invoke(logType, msg);
  9666. }
  9667. /// <summary>
  9668. /// 保存PLC写入日志
  9669. /// </summary>
  9670. /// <param name="logType"></param>
  9671. /// <param name="logValue"></param>
  9672. private void WritePLCLog(LogType logType, string logValue)
  9673. {
  9674. switch ((int)logType)
  9675. {
  9676. case 0:
  9677. _PLCLogNet.WriteDebug(logValue);
  9678. break;
  9679. case 1:
  9680. _PLCLogNet.WriteInfo(logValue);
  9681. break;
  9682. case 2:
  9683. _PLCLogNet.WriteWarn(logValue);
  9684. break;
  9685. case 3:
  9686. _PLCLogNet.WriteError(logValue);
  9687. break;
  9688. default:
  9689. _PLCLogNet.WriteFatal(logValue);
  9690. break;
  9691. }
  9692. }
  9693. /// <summary>
  9694. /// IOT Mqtt回调方法- With DataId
  9695. /// </summary>
  9696. /// <param name="id"></param>
  9697. /// <param name="v"></param>
  9698. /// <param name="dataId"></param>
  9699. public void CallbackWithDataId(string id, string msg, string dataId)
  9700. {
  9701. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9702. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9703. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9704. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9705. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9706. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9707. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9708. }
  9709. /// <summary>
  9710. /// AGV Mqtt回调方法- 记录Log并处理数据
  9711. /// </summary>
  9712. /// <param name="obj"></param>
  9713. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9714. {
  9715. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9716. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9717. // 接收到的信息
  9718. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9719. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9720. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9721. {
  9722. }
  9723. }
  9724. #endregion 日志
  9725. /// <summary>
  9726. /// 实例化报警字典
  9727. /// </summary>
  9728. private void InitalDicAlarm()
  9729. {
  9730. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9731. List<Alarm> keyValues1 = new List<Alarm>
  9732. {
  9733. #region 第一组报警(电机)
  9734. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9735. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9736. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9737. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9738. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9739. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9740. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9741. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9742. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9743. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9744. #endregion 第一组报警(电机)
  9745. #region 第二组报警(气缸)
  9746. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9747. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9748. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9749. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9750. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9751. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9752. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9753. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9754. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9755. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9756. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9757. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9758. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9759. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9760. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9761. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9762. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9763. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9764. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9765. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9766. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9767. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9768. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9769. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9770. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9771. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9772. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9773. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9774. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9775. #endregion 第二组报警(气缸)
  9776. #region 第三组报警(其他故障)
  9777. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9778. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9779. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9780. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9781. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9782. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9783. #endregion 第三组报警(其他故障)
  9784. };
  9785. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9786. #endregion 第一个工站(这里使用线体代替工位)
  9787. # region 第二个工站-原来的写法(废弃)
  9788. //keyValues = new Dictionary<int, AlarmData[]>();
  9789. ////1
  9790. //dicAlarmName = new Dictionary<int, Alarm>();
  9791. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  9792. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  9793. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  9794. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  9795. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  9796. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9797. //for (int i = 0; i < dicAlarmName.Count; i++)
  9798. //{
  9799. // alarmDatas[i] = new AlarmData();
  9800. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9801. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9802. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9803. // alarmDatas[i].AlarmType = 1;
  9804. //}
  9805. //keyValues.Add(1, alarmDatas);
  9806. ////2
  9807. //dicAlarmName = new Dictionary<int, Alarm>();
  9808. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  9809. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  9810. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  9811. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  9812. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  9813. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  9814. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  9815. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  9816. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9817. //for (int i = 0; i < dicAlarmName.Count; i++)
  9818. //{
  9819. // alarmDatas[i] = new AlarmData();
  9820. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9821. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9822. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9823. // alarmDatas[i].AlarmType = 2;
  9824. //}
  9825. //keyValues.Add(2, alarmDatas);
  9826. ////3
  9827. //dicAlarmName = new Dictionary<int, Alarm>();
  9828. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  9829. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  9830. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  9831. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  9832. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9833. //for (int i = 0; i < dicAlarmName.Count; i++)
  9834. //{
  9835. // alarmDatas[i] = new AlarmData();
  9836. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  9837. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9838. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9839. // alarmDatas[i].AlarmType = 3;
  9840. //}
  9841. //keyValues.Add(3, alarmDatas);
  9842. //DicAlarms.Add(2, keyValues);
  9843. #endregion 第二个工站-原来的写法(废弃)
  9844. }
  9845. }
  9846. }