Form_Home.cs 582 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using System.Net.Http;
  40. /*
  41. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  42. */
  43. namespace MainForm
  44. {
  45. /// <summary>
  46. /// 记录日志的委托
  47. /// </summary>
  48. /// <param name="logType">日志类型</param>
  49. /// <param name="message">日志信息</param>
  50. public delegate void HomeMessageHandler(LogType logType, string message);
  51. /// <summary>
  52. /// 主页窗体
  53. /// </summary>
  54. public partial class Form_Home : Form
  55. {
  56. #region 常量
  57. //文本常量
  58. private const string Head = "开始采集";
  59. private const string Tail = "采集完成";
  60. private const string Body = "工位出站数据";
  61. private const string BodyCheck = "工位点检数据";
  62. private const string BodyRun = "整线运行数据";
  63. private const string BodyAlarm = "整线报警数据";
  64. #endregion 常量
  65. #region 变量
  66. /// <summary>
  67. /// 委托-记录日志的方法
  68. /// </summary>
  69. public event HomeMessageHandler MessageEvent;
  70. /// <summary>
  71. /// 日志接口
  72. /// </summary>
  73. ILogNet _PLCLogNet;
  74. /// <summary>
  75. /// 用于记录IOT MQTT日志
  76. /// </summary>
  77. ILogNet _IOTMqttLogNet;
  78. /// <summary>
  79. /// 用于记录AGV MQTT日志
  80. /// </summary>
  81. ILogNet _AGVMqttLogNet;
  82. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  83. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  84. // 间隔时间
  85. private int IntervalReadPLC = 300; //ms 读PLC
  86. private int IntervalMonitorMES = 1000; //ms MES心跳
  87. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  88. // 软件状态
  89. private bool IsRun = true;
  90. #region PLC 与 TCP对象
  91. // 定义一个字典,存plc对象(通讯)
  92. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  93. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  94. // 定义TCPClient对象列表
  95. Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  96. // 定义MQTTHelper对象
  97. MQTTHelper _MQTTHelper = new MQTTHelper();
  98. #endregion PLC 与 TCP对象
  99. /// <summary>
  100. /// 上次的设备运行信息
  101. /// </summary>
  102. private string lineWorkingData1_OldStr = string.Empty;
  103. /// <summary>
  104. /// 设备报警字典-当前结果
  105. /// Dictionary<工位代码,List<报警信息>>
  106. /// </summary>
  107. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  108. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  109. #endregion 变量
  110. #region 窗体基础事件
  111. /// <summary>
  112. /// 初始化
  113. /// </summary>
  114. public Form_Home()
  115. {
  116. InitializeComponent();
  117. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  118. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  119. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  120. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  121. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  122. }
  123. /// <summary>
  124. /// 窗体加载事件
  125. /// </summary>
  126. private void Form_Home_Load(object sender, EventArgs e)
  127. {
  128. try
  129. {
  130. AddMessage(LogType.Info, "开始初始化程序");
  131. InitalDicAlarm(); // 实例化报警字典
  132. //组建plc对象字典
  133. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  134. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  135. if (GlobalContext.IsUsePLC1)
  136. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  137. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  138. if (GlobalContext.IsUsePLC2)
  139. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  140. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  141. if (GlobalContext.IsUsePLC3)
  142. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  143. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  144. if (GlobalContext.IsUsePLC4)
  145. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  146. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  147. if (GlobalContext.IsUsePLC5)
  148. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  149. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  150. if (GlobalContext.IsUsePLC6)
  151. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  152. if (GlobalContext.IsUsePLC7)
  153. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  154. if (GlobalContext.IsUsePLC8)
  155. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  156. if (GlobalContext.IsUsePLC9)
  157. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  158. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  159. {
  160. if (plcEIP != null)
  161. {
  162. try
  163. {
  164. (int, string) result = plcEIP.Connect();
  165. }
  166. catch (Exception ex)
  167. {
  168. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  169. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  170. }
  171. }
  172. }
  173. /*
  174. //plc1Alarm.Connect();
  175. foreach (ModbusClientHelper modbusClient in Funs.Values)
  176. {
  177. if (modbusClient != null)
  178. {
  179. try
  180. {
  181. modbusClient.Connect();
  182. }
  183. catch (Exception ex)
  184. {
  185. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  186. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  187. }
  188. }
  189. }
  190. */
  191. // 采集任务
  192. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  193. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  194. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  195. if (GlobalContext.IsUsePLC1)
  196. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  197. if (GlobalContext.IsUsePLC2)
  198. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  199. if (GlobalContext.IsUsePLC3)
  200. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  201. if (GlobalContext.IsUsePLC4)
  202. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  203. if (GlobalContext.IsUsePLC5)
  204. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  205. if (GlobalContext.IsUsePLC6)
  206. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  207. if (GlobalContext.IsUsePLC7)
  208. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  209. if (GlobalContext.IsUsePLC8)
  210. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  211. if (GlobalContext.IsUsePLC9)
  212. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  213. #region 初始化
  214. try
  215. {
  216. // 开启边线MES(绑定/查询数据)
  217. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  218. //if (mesRoute == 0)
  219. //{
  220. // //picMESStatus.Image = imageListState.Images[1];
  221. // //GlobalContext.MESIsConnect = true;
  222. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  223. //}
  224. //else
  225. //{
  226. // //picMESStatus.Image = imageListState.Images[0];
  227. // //GlobalContext.MESIsConnect = false;
  228. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  229. //}
  230. // 开启MES(Http)
  231. if (GlobalContext.IsUseMES)
  232. {
  233. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  234. if (mesret)
  235. {
  236. picMESStatus.Image = imageListState.Images[1];
  237. GlobalContext.MESIsConnect = true;
  238. AddMessage(LogType.Info, "小米MES初始连接成功!");
  239. }
  240. else
  241. {
  242. picMESStatus.Image = imageListState.Images[0];
  243. GlobalContext.MESIsConnect = false;
  244. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  245. }
  246. }
  247. // 开启IOT(MQTT)
  248. if (GlobalContext.IsUseIot)
  249. {
  250. string addr = GlobalContext.MQTTServerHost;
  251. int port = GlobalContext.MQTTServerPort;
  252. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer(addr, port, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  253. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  254. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  255. {
  256. picIot.Image = imageListState.Images[1];
  257. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  258. XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  259. }
  260. else
  261. {
  262. picIot.Image = imageListState.Images[0];
  263. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  264. }
  265. }
  266. // 开启AGV(Http与MQTT)
  267. if (GlobalContext.IsUseAGV)
  268. {
  269. // AGV HTTP
  270. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  271. if (mesret1)
  272. {
  273. picAgvHttp.Image = imageListState.Images[1];
  274. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  275. }
  276. else
  277. {
  278. picAgvHttp.Image = imageListState.Images[0];
  279. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  280. }
  281. string agvMqttIp = GlobalContext.MQTTServerHost;
  282. int agvMqttPort = GlobalContext.MQTTServerPort;
  283. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  284. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  285. // AGV MQTT
  286. if (result_MQTT.ResultCode == 1)
  287. {
  288. picAgvMqtt.Image = imageListState.Images[1];
  289. GlobalContext.AGVMQTTIsConnect = true;
  290. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  291. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  292. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  293. }
  294. else
  295. {
  296. picAgvMqtt.Image = imageListState.Images[0];
  297. GlobalContext.AGVMQTTIsConnect = false;
  298. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  299. }
  300. }
  301. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  302. Task.Run(MonitorMESConnect);
  303. // 查询PLC连接状态
  304. foreach (int plcNo in FunsEip.Keys)
  305. {
  306. bool connected = FunsEip[plcNo].IsConnected;
  307. if (connected)
  308. {
  309. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  310. AddMessage(LogType.Info, msg);
  311. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  312. }
  313. else
  314. {
  315. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  316. AddMessage(LogType.Info, msg);
  317. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  318. }
  319. }
  320. // PLC4时 初始化扫码器TCP
  321. //if (GlobalContext.IsUsePLC4)
  322. // HpTCPClientInit();
  323. // 开启PLC的业务处理线程-监听PLC点位+状态
  324. foreach (Task task in TaskReadProcess)
  325. {
  326. if (task != null)
  327. task.Start();
  328. }
  329. //// 开启“获取线体报警数据”的线程
  330. //TaskReadAlarm.Start();
  331. ////下传MES信息给1工位(先判断下plc对象数量)
  332. //if (Funs.Count > 1)
  333. // DownLoadProductInfo(1);
  334. AddMessage(LogType.Info, "程序初始化完成");
  335. }
  336. catch (Exception ex)
  337. {
  338. string str = ex.StackTrace;
  339. this.BeginInvoke(new Action(() =>
  340. {
  341. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  342. }));
  343. }
  344. #endregion
  345. }
  346. catch (Exception ex)
  347. {
  348. string str = ex.StackTrace;
  349. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  350. if (ex.Message != null && ex.Message.Contains("timed out"))
  351. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  352. else
  353. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  354. }
  355. }
  356. /// <summary>
  357. /// 窗体关闭事件
  358. /// </summary>
  359. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  360. {
  361. Closed2();
  362. }
  363. public void Closed2()
  364. {
  365. try
  366. {
  367. IsRun = false;
  368. Thread.Sleep(IntervalReadPLC);
  369. // 断开TCP
  370. int count = _HPSocket_TcpClients.Count();
  371. for (int i = 0; i < count; i++)
  372. {
  373. try
  374. {
  375. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  376. {
  377. _HPSocket_TcpClients[i].Stop();
  378. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  379. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  380. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  381. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  382. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  383. }
  384. }
  385. catch { }
  386. }
  387. // 关闭Iot
  388. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  389. // 关闭AGV Mqtt
  390. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  391. }
  392. catch { }
  393. }
  394. #endregion 窗体基础事件
  395. #region 监控MES状态
  396. /// <summary>
  397. /// 监控MES连接状态
  398. /// </summary>
  399. private void MonitorMESConnect()
  400. {
  401. while (IsRun) // 运行被控线程
  402. {
  403. try
  404. {
  405. // 开启MES(Http)
  406. if (GlobalContext.IsUseMES)
  407. {
  408. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  409. if (mesret)
  410. {
  411. picMESStatus.Image = imageListState.Images[1];
  412. GlobalContext.MESIsConnect = true;
  413. }
  414. else
  415. {
  416. picMESStatus.Image = imageListState.Images[0];
  417. GlobalContext.MESIsConnect = false;
  418. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  419. }
  420. }
  421. // 开启IOT(MQTT)
  422. if (GlobalContext.IsUseIot)
  423. {
  424. bool iIot = XiaomiMqttClient.IsOpen;
  425. if (iIot)
  426. picIot.Image = imageListState.Images[1];
  427. else
  428. {
  429. picIot.Image = imageListState.Images[0];
  430. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  431. }
  432. }
  433. // 开启AGV(Http与MQTT)
  434. if (GlobalContext.IsUseAGV)
  435. {
  436. // AGV Http
  437. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  438. if (mesret1)
  439. picAgvHttp.Image = imageListState.Images[1];
  440. else
  441. {
  442. picAgvHttp.Image = imageListState.Images[0];
  443. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  444. }
  445. // AGV MQTT
  446. if (GlobalContext.AGVMQTTIsConnect)
  447. picAgvMqtt.Image = imageListState.Images[1];
  448. else
  449. {
  450. picAgvMqtt.Image = imageListState.Images[0];
  451. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  452. }
  453. }
  454. }
  455. catch (Exception ex)
  456. {
  457. string str = ex.StackTrace;
  458. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  459. }
  460. Thread.Sleep(IntervalMonitorMES);
  461. }
  462. }
  463. #endregion 监控MES连接状态
  464. #region 采集设备状态、运行数据、报警数据
  465. /// <summary>
  466. /// 请求设备状态 5000
  467. /// </summary>
  468. /// <param name="no">1</param>
  469. /// <param name="stationNameStr"></param>
  470. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  471. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  472. {
  473. try
  474. {
  475. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  476. {
  477. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  478. return result;
  479. }
  480. else
  481. {
  482. return 0;
  483. }
  484. }
  485. catch (Exception ex)
  486. {
  487. string str = ex.StackTrace;
  488. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  489. return 0;
  490. }
  491. }
  492. /// <summary>
  493. /// 检查是否可采集点检数据 - 不取新值
  494. /// 5000不为1时可点检
  495. /// </summary>
  496. /// <returns></returns>
  497. public bool CheckCanSpotcheck1(int deviceState)
  498. {
  499. //return true;
  500. //D5000 = 1,代表设备控制状态处于运行状态
  501. //D5000 = 2, 代表设备控制状态处于故障状态
  502. //D5000 = 3,代表设备控制状态处于缺料状态
  503. //D5000 = 4, 代表设备控制状态处于待机状态
  504. //D5000 = 5,代表设备控制状态处于维修状态
  505. return deviceState != 1;
  506. }
  507. /// <summary>
  508. /// 检查是否可采集产品数据 - 不取新值
  509. /// </summary>
  510. /// <returns></returns>
  511. public bool CheckCanCollData(int deviceState)
  512. {
  513. return deviceState == 0; // 点检时该值不为0
  514. }
  515. /// <summary>
  516. /// 获取设备报警数据与获取设备运行信息
  517. /// </summary>
  518. private async void ReadAlarmAllPLC()
  519. {
  520. // [S1] Tray盘上料装备(板测)
  521. // [S2] FCT(板测)
  522. // [S3] 值板机
  523. // [S4] 取放桁架
  524. // [S5] Tray盘下料装备
  525. /// 上位机心跳
  526. /// 获取设备报警数据与状态信息
  527. string stationNameStr = "获取设备报警数据与状态信息";
  528. while (IsRun)
  529. {
  530. try
  531. {
  532. if (!GlobalContext._IsCon_plc1Alarm)
  533. {
  534. UpdatePLCMonitor(1, -2, 0);
  535. continue;
  536. }
  537. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  538. {
  539. DateTime dtNow = DateTime.Now;
  540. #region 获取设备运行信息
  541. try
  542. {
  543. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  544. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  545. lineWorkingData1.LineName = GlobalContext.LineCode;
  546. //
  547. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  548. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  549. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  550. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  551. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  552. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  553. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  554. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  555. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  556. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  557. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  558. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  559. lineWorkingData1.CreateTime = DateTime.Now;
  560. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  561. // UI展示-展示到设备状态页
  562. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  563. {
  564. // 查询数据库最新一条数据,确定是不是更新
  565. string qSql = @"SELECT top(1) [GUID]
  566. ,[LineName]
  567. ,[BootTimeLong]
  568. ,[NormalTimeLong]
  569. ,[StandbyTimeLong]
  570. ,[FaultTimeLong]
  571. ,[MaterialShortageTimeLong]
  572. ,[MaintenanceTimeLong]
  573. ,[FaultNumber]
  574. ,[OutputNumber]
  575. ,[QualifiedNumber]
  576. ,[QualifiedRate]
  577. ,[DesignRhythm]
  578. ,[RealityRhythm]
  579. ,[CreateTime]
  580. FROM [LineWorkingData]
  581. where [CreateTime] > '{0}'
  582. and [LineName]='{1}'
  583. order by [CreateTime] desc
  584. ";
  585. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  586. var ds = SQLHelper_New.Query(qSql, null);
  587. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  588. {
  589. var dataDBlast = new LineWorkingData_ThisTime();
  590. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  591. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  592. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  593. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  594. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  595. {
  596. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  597. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  598. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  599. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  600. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  601. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  602. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  603. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  604. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  605. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  606. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  607. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  608. string usql = dataDBlast.ToStringUpdate();
  609. SQLHelper_New.ExecuteSQL(usql, null);
  610. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  611. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  612. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  613. }
  614. }
  615. else
  616. {
  617. // 插入
  618. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  619. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  620. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  621. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  622. }
  623. }
  624. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  625. {
  626. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  627. //// 本次开机设备运行情况
  628. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  629. //Task.Run(() =>
  630. //{
  631. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  632. // {
  633. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  634. // }
  635. //});
  636. // 本日设备运行情况
  637. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  638. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  639. {
  640. // 更新
  641. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  642. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  643. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  644. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  645. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  646. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  647. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  648. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  649. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  650. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  651. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  652. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  653. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  654. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  655. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  656. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  657. }
  658. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  659. {
  660. // 插入
  661. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  662. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  663. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  664. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  665. }
  666. await Task.Run(() =>
  667. {
  668. try
  669. {
  670. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  671. {
  672. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  673. }
  674. }
  675. catch { }
  676. });
  677. }
  678. }
  679. catch (Exception ex)
  680. {
  681. string str = ex.StackTrace;
  682. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  683. }
  684. #endregion 获取设备运行信息
  685. #region 报警数据
  686. try
  687. {
  688. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  689. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  690. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  691. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  692. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  693. {
  694. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  695. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  696. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  697. {
  698. isNeedUpdUI = true; // 需要更新历史报警UI信息
  699. // 记录
  700. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  701. switch (dicAlarms_Cur_PLC1[i].是否报警)
  702. {
  703. case true: // 报警
  704. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  705. {
  706. GUID = Guid.NewGuid().ToString(),
  707. LineName = GlobalContext.LineCode, // 线体
  708. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  709. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  710. StartTime = dtNow // 开始时间
  711. };
  712. // 传输到页面
  713. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  714. {
  715. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  716. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  717. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  718. 开始时间 = dtNow
  719. });
  720. // 新增到数据库
  721. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  722. SaveAlarmDataByDB(stationNameStr, data1, false);
  723. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  724. break;
  725. case false: // 消除报警
  726. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  727. {
  728. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  729. {
  730. GUID = Guid.NewGuid().ToString(),
  731. LineName = GlobalContext.LineCode, // 线体
  732. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  733. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  734. StartTime = dtNow, // 开始时间
  735. EndTime = dtNow, // 开始时间
  736. PersistTime = 1, // 耗时1s
  737. };
  738. // 新增
  739. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  740. SaveAlarmDataByDB(stationNameStr, data2, false);
  741. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  742. }
  743. else
  744. {
  745. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  746. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  747. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  748. // 修改
  749. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  750. SaveAlarmDataByDB(stationNameStr, data3, true);
  751. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  752. }
  753. break;
  754. default:
  755. break;
  756. }
  757. }
  758. }
  759. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  760. // 有新报警则更新
  761. if (isNeedUpdUI)
  762. {
  763. // UI展示 - 展示到设备状态页
  764. await Task.Run(() =>
  765. {
  766. try
  767. {
  768. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  769. {
  770. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  771. if (Form_Main.formDevAlarm.Visible)
  772. {
  773. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  774. }
  775. }
  776. }
  777. catch { }
  778. });
  779. }
  780. }
  781. catch (Exception ex)
  782. {
  783. string str = ex.StackTrace;
  784. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  785. }
  786. #endregion 报警数据
  787. UpdatePLCMonitor(1, -2, 1);
  788. }
  789. else
  790. {
  791. UpdatePLCMonitor(1, -2, 0);
  792. }
  793. }
  794. catch (Exception ex)
  795. {
  796. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  797. }
  798. Thread.Sleep(IntervalAlarm);
  799. }
  800. }
  801. #endregion 轮询PLC
  802. #region 下发订单信息
  803. ///// <summary>
  804. ///// 壳体上料(下发工单)的交互逻辑
  805. ///// </summary>
  806. ///// <param name="no"></param>
  807. ///// <exception cref="NotImplementedException"></exception>
  808. //private void ReadStation_DownOrderInfo(int plcNo)
  809. //{
  810. // // [S1] Tray盘上料装备(板测)
  811. // // [S2] FCT(板测)
  812. // // [S3] 值板机
  813. // // [S4] 取放桁架
  814. // // [S5] Tray盘下料装备
  815. // /// 上位机心跳
  816. // /// 获取设备报警数据与状态信息
  817. // string stationNameStr = "[S0]壳体上料";
  818. // while (IsRun)
  819. // {
  820. // try
  821. // {
  822. // if (!GlobalContext._IsCon_Funs1)
  823. // {
  824. // UpdatePLCMonitor(plcNo, 0);
  825. // continue;
  826. // }
  827. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  828. // {
  829. // #region 壳体上料(下发工单)
  830. // try
  831. // {
  832. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  833. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  834. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  835. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  836. // // 重置数据和信号
  837. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  838. // {
  839. // // 清空写给PLC的数据
  840. // int[] i497 = new int[1] { 0 };
  841. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  842. // // MES_Flag重置为0
  843. // int[] i500 = new int[1] { 0 };
  844. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  845. // }
  846. // }
  847. // catch (Exception ex)
  848. // {
  849. // string str = ex.StackTrace;
  850. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  851. // }
  852. // #endregion 壳体上料(下发工单)
  853. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  854. // }
  855. // else
  856. // {
  857. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  858. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  859. //
  860. // Funs[plcNo].Connect();
  861. // }
  862. // }
  863. // catch (Exception ex)
  864. // {
  865. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  866. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  867. //
  868. // Funs[plcNo].ReConnect();
  869. // }
  870. // Thread.Sleep(IntervalReadPLC);
  871. // }
  872. //}
  873. ///// <summary>
  874. ///// 下发订单信息到PLC
  875. ///// </summary>
  876. ///// <param name="no">PLC编号</param>
  877. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  878. //{
  879. // try
  880. // {
  881. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  882. // {
  883. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  884. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  885. // }
  886. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  887. // }
  888. // catch (Exception ex)
  889. // {
  890. // string str = ex.StackTrace;
  891. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  892. // }
  893. //}
  894. /// <summary>
  895. /// 下发清料信号
  896. /// </summary>
  897. /// <param name="no">PLC编号</param>
  898. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  899. {
  900. try
  901. {
  902. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  903. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  904. return true;
  905. }
  906. catch (Exception ex)
  907. {
  908. string str = ex.StackTrace;
  909. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  910. return false;
  911. }
  912. }
  913. #endregion 下发订单信息
  914. #region Xiaomi 贲流
  915. #region 公共方法
  916. private static bool ProgressState = false;
  917. private static readonly object lockObj = new object(); // 锁对象
  918. private static bool isCollectingFlagLeft;
  919. private static bool isCollectingFlagRight;
  920. /// <summary>
  921. /// float[]转为string
  922. /// </summary>
  923. public string FloatArrayToString(float[] nScrewResults)
  924. {
  925. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  926. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  927. }
  928. /// <summary>
  929. /// short[]转为string
  930. /// </summary>
  931. public string ShortArrayToString(short[] nScrewResults)
  932. {
  933. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  934. return string.Join(",", nScrewResults);
  935. }
  936. /// <summary>
  937. /// 写入PLC重复三次
  938. /// </summary>
  939. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  940. {
  941. int i = 0;
  942. int nRet = 0;
  943. string strRet = "";
  944. try
  945. {
  946. while (i < 3) // 最多上传三次
  947. {
  948. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  949. if (nRet == 0) //成功
  950. {
  951. break;
  952. }
  953. else
  954. {
  955. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  956. i++;
  957. }
  958. }
  959. return (nRet, strRet);
  960. }
  961. catch (Exception ex)
  962. {
  963. return (1, ex.Message);
  964. }
  965. }
  966. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  967. {
  968. try
  969. {
  970. // 获取当前日期
  971. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  972. // 构建保存路径
  973. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  974. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  975. // 确保目录存在
  976. Directory.CreateDirectory(savePath);
  977. // 文件名
  978. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  979. string filePath = Path.Combine(savePath, fileName);
  980. // 确保不会超出数组长度,只取前14个或数组的实际长度
  981. int count = Math.Min(14, fScrewTimes.Length);
  982. using (StreamWriter sw = new StreamWriter(filePath))
  983. {
  984. for (int i = 0; i < count; i++)
  985. {
  986. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  987. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  988. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  989. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  990. sw.WriteLine(); // 空行分隔不同螺丝的信息
  991. }
  992. }
  993. return (0, "");
  994. }
  995. catch (Exception ex)
  996. {
  997. return (1, ex.Message);
  998. }
  999. }
  1000. /// <summary>
  1001. /// 调用进站接口并保存进站数据
  1002. /// </summary>
  1003. /// <param name="stationNameStr">工站信息</param>
  1004. /// <param name="workorder_code">工单号</param>
  1005. /// <param name="mtltmrk">型号(物料号)</param>
  1006. /// <param name="sn">产品SN</param>
  1007. /// <param name="items">进站数据</param>
  1008. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1009. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1010. {
  1011. int result = 0;
  1012. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1013. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1014. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1015. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1016. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1017. inRequest_Body.unitSn = sn; // 产品SN
  1018. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1019. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1020. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1021. StationIn stationIn = new StationIn()
  1022. {
  1023. Workorder_code = workorder_code, // 车间订单号
  1024. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1025. Sn = sn, // SN
  1026. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1027. Parameter_values = items, // 进站数据
  1028. Write_user = inRequest_Body.userId, // 员工Id
  1029. Test_time = inRequest_Body.clientTime // 进站时间
  1030. };
  1031. // 本地数据
  1032. string sql = stationIn.ToStringInsert(0);
  1033. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1034. result = ret == "成功" ? 1 : 6;
  1035. //await Task.Delay(200);
  1036. // 上传MES
  1037. if (GlobalContext.IsSendStationIn)
  1038. {
  1039. try
  1040. {
  1041. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1042. string mesRet = string.Empty;
  1043. int i = 0;
  1044. while (i < 2) // 1009会多次尝试上传
  1045. {
  1046. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1047. if (response != null && response.header.code == "200")
  1048. break;
  1049. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1050. i++;
  1051. i++;
  1052. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1053. // 记录失败原因
  1054. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1055. }
  1056. if (response?.header?.code == "200")
  1057. {
  1058. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1059. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1060. result = ret_Upd == "成功" ? 1 : 6;
  1061. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1062. }
  1063. else
  1064. {
  1065. result = 5;
  1066. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1067. }
  1068. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1069. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1070. }
  1071. catch (Exception ex)
  1072. {
  1073. result = 6;
  1074. string str = ex.StackTrace;
  1075. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1076. }
  1077. }
  1078. return result;
  1079. }
  1080. /// <summary>
  1081. /// 选择如何记录出站数据
  1082. /// </summary>
  1083. /// <param name="items">出站数据</param>
  1084. /// <param name="equipmentCode">设备编号</param>
  1085. /// <param name="processItem">测试项目</param>
  1086. /// <param name="workorder_code">车间订单号</param>
  1087. /// <param name="batch_num">批次号</param>
  1088. /// <param name="mtltmrk">型号</param>
  1089. /// <param name="proDate">日期</param>
  1090. /// <param name="supplierCode">供应商代码</param>
  1091. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1092. /// <returns>上传成功时返回1;失败返回0</returns>
  1093. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1094. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1095. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode)
  1096. {
  1097. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1098. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode);
  1099. }
  1100. /// <summary>
  1101. /// 添加出站数据(提交到MES+本地保存到数据库)
  1102. /// </summary>
  1103. /// <param name="items">出站数据</param>
  1104. /// <param name="equipmentCode">设备编号</param>
  1105. /// <param name="processItem">测试项目</param>
  1106. /// <param name="workorder_code">车间订单号</param>
  1107. /// <param name="batch_num">批次号</param>
  1108. /// <param name="mtltmrk">型号</param>
  1109. /// <param name="proDate">日期</param>
  1110. /// <param name="supplierCode">供应商代码</param>
  1111. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1112. /// <returns>上传成功时返回1;失败返回0</returns>
  1113. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1114. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1115. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode)
  1116. {
  1117. int upload = 0;
  1118. int result = 0;
  1119. ProcessData processData = new ProcessData()
  1120. {
  1121. Equipment_code = equipmentCode,
  1122. Workorder_code = workorder_code,
  1123. Batch_number = batch_num,
  1124. Sn = sn, // SN
  1125. Testitem = processItem,
  1126. Parameter_values = items,
  1127. Write_user = GlobalContext.CurrentUser,
  1128. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1129. };
  1130. // 本地数据
  1131. string sql = processData.ToStringInsert(upload);
  1132. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1133. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1134. // 上传MES
  1135. if (GlobalContext.IsSendProcessData)
  1136. {
  1137. try
  1138. {
  1139. string id = processData.ID.Copy();
  1140. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1141. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1142. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1143. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1144. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1145. outRequest_Body.unitSn = sn; // 产品SN
  1146. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1147. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1148. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1149. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1150. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1151. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1152. if (!string.IsNullOrEmpty(partBarcode))
  1153. {
  1154. outRequest_Body.unitData.keyMaterial.Add(
  1155. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1156. {
  1157. bindSort = 1,
  1158. materialSn = partBarcode
  1159. }); // 设备数据 - 部件码
  1160. }
  1161. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1162. if (GlobalContext.IsSendProcessData)
  1163. {
  1164. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1165. string mesRet = string.Empty;
  1166. int i = 0;
  1167. while (i < 2) // 1009会多次尝试上传
  1168. {
  1169. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1170. if (response != null && response.header.code == "200")
  1171. break;
  1172. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1173. i++;
  1174. i++;
  1175. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1176. // 记录失败原因
  1177. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1178. }
  1179. if (response?.header?.code == "200")
  1180. {
  1181. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1182. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1183. result = 1;
  1184. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1185. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1186. }
  1187. else
  1188. {
  1189. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1190. }
  1191. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1192. JsonConvert.SerializeObject(response), id);
  1193. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1194. }
  1195. }
  1196. catch (Exception ex)
  1197. {
  1198. string str = ex.StackTrace;
  1199. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1200. }
  1201. }
  1202. return result;
  1203. }
  1204. /// <summary>
  1205. /// 图片存入数据库
  1206. /// </summary>
  1207. /// <param name="stPLC_MesData"></param>
  1208. /// <param name="stationCode"></param>
  1209. /// <param name="stationName"></param>
  1210. private void SaveDBbyFileInfo(OP40_MesData_t stPLC_MesData, string stationCode, string stationName)
  1211. {
  1212. string path = GlobalContext.UpFilePath;
  1213. string leftPath = path + "\\Left";
  1214. string rightPath = path + "\\Right";
  1215. string sql = "";
  1216. var formData = new MultipartFormDataContent();
  1217. // 获取所有图片文件
  1218. List<string> imageFiles_L = GetAllImageFiles(leftPath);
  1219. List<string> imageFiles_R = GetAllImageFiles(rightPath);
  1220. try
  1221. {
  1222. foreach (string imageFile in imageFiles_L)
  1223. {
  1224. //formData = MultipartbyFile(imageFile);
  1225. sql = string.Format("INSERT INTO [dbo].[DataFiles](stationCode,stationName,CarrierBarcode,ProductBarcode,bucket,fileName,fileContext,uuid,fileUrl,status,submitTime,createTime) " +
  1226. "VALUES('{0}','{1}','{2}' ,'{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')"
  1227. , stationCode
  1228. , stationName
  1229. , stPLC_MesData.BarcodeSet.strCarrierBarcode
  1230. , stPLC_MesData.BarcodeSet.strProductBarcode
  1231. , "/mesCommToPC/pic/left"
  1232. , Path.GetFileName(imageFile)
  1233. , ""
  1234. , ""
  1235. , ""
  1236. , 0
  1237. , ""
  1238. , DateTime.Now
  1239. );
  1240. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1241. }
  1242. foreach (string imageFile in imageFiles_R)
  1243. {
  1244. //formData = MultipartbyFile(imageFile);
  1245. sql = string.Format("INSERT INTO [dbo].[DataFiles](stationCode,stationName,CarrierBarcode,ProductBarcode,bucket,fileName,fileContext,uuid,fileUrl,status,submitTime,createTime) " +
  1246. "VALUES('{0}','{1}','{2}' ,'{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')"
  1247. , stationCode
  1248. , stationName
  1249. , stPLC_MesData.BarcodeSet.strCarrierBarcode
  1250. , stPLC_MesData.BarcodeSet.strProductBarcode
  1251. , "/mesCommToPC/pic/right"
  1252. , Path.GetFileName(imageFile)
  1253. , ""
  1254. , ""
  1255. , ""
  1256. , 0
  1257. , ""
  1258. , DateTime.Now
  1259. );
  1260. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1261. }
  1262. }
  1263. catch (Exception)
  1264. {
  1265. AddMessage_Station(stationName, LogType.Error, $"图片保存失败!载具码:{stPLC_MesData.BarcodeSet.strCarrierBarcode}产品码{stPLC_MesData.BarcodeSet.strProductBarcode}");
  1266. }
  1267. }
  1268. /// <summary>
  1269. /// 获取路径下的所有图片
  1270. /// </summary>
  1271. /// <param name="directoryPath"></param>
  1272. /// <returns></returns>
  1273. private List<string> GetAllImageFiles(string directoryPath)
  1274. {
  1275. var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
  1276. var imageFiles = new List<string>();
  1277. try
  1278. {
  1279. // 遍历目录及子目录中的所有文件
  1280. foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
  1281. {
  1282. // 获取文件扩展名并检查是否为图片格式
  1283. string extension = Path.GetExtension(file);
  1284. if (imageExtensions.Contains(extension))
  1285. {
  1286. imageFiles.Add(file);
  1287. }
  1288. }
  1289. }
  1290. catch (Exception ex)
  1291. {
  1292. OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
  1293. }
  1294. return imageFiles;
  1295. }
  1296. public MultipartFormDataContent MultipartbyFile(string filePath)
  1297. {
  1298. using (var formData = new MultipartFormDataContent())
  1299. {
  1300. // 读取文件并转换为ByteArrayContent
  1301. byte[] fileBytes = File.ReadAllBytes(filePath);
  1302. var fileContent = new ByteArrayContent(fileBytes);
  1303. // 将ByteArrayContent添加到MultipartFormDataContent,并指定名称
  1304. formData.Add(fileContent, "file", Path.GetFileName(filePath));
  1305. return formData;
  1306. }
  1307. }
  1308. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1309. //{
  1310. // Stopwatch stopwatch = new Stopwatch();
  1311. // stopwatch.Start();
  1312. // try
  1313. // {
  1314. // // 初始化 AtlasScrew 实例
  1315. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1316. // atlasScrew1.Initial();
  1317. // // 存储结果的列表
  1318. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1319. // // 存储角度和扭力的字符串列表
  1320. // List<string> angleStrs = new List<string>();
  1321. // List<string> torqueStrs = new List<string>();
  1322. // // 上一次获取的数据
  1323. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1324. // while (isExitAtlasLeft) // 检查是否收集数据
  1325. // {
  1326. // // 获取当前数据
  1327. // var currentResult = atlasScrew1.GetResults();
  1328. // // 判断是否为新数据
  1329. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1330. // {
  1331. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1332. // // 更新角度和扭力的字符串列表
  1333. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1334. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1335. // // 计算角度、扭力、起始扭力和最大扭力
  1336. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1337. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1338. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1339. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1340. // // 将新数据添加到结果列表
  1341. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1342. // // 更新上一次获取的数据
  1343. // lastResult = currentResult;
  1344. // }
  1345. // // 等待一段时间后再次检查
  1346. // Thread.Sleep(20); // 轮询间隔时间
  1347. // // 如果触发了出站,则退出循环
  1348. // if (!isExitAtlasLeft)
  1349. // {
  1350. // break;
  1351. // }
  1352. // }
  1353. // // 生成文件名
  1354. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1355. // // 写入数据到文件
  1356. // using (StreamWriter writer = new StreamWriter(fileName))
  1357. // {
  1358. // // 写入标题行
  1359. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1360. // // 写入每一行数据
  1361. // foreach (var result in results)
  1362. // {
  1363. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1364. // }
  1365. // }
  1366. // stopwatch.Stop();
  1367. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1368. // }
  1369. // catch (Exception ex)
  1370. // {
  1371. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1372. // }
  1373. // finally
  1374. // {
  1375. // // 重置标志变量
  1376. // isExitAtlasLeft = false;
  1377. // }
  1378. //}
  1379. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1380. //{
  1381. // Stopwatch stopwatch = new Stopwatch();
  1382. // stopwatch.Start();
  1383. // try
  1384. // {
  1385. // // 初始化 AtlasScrew 实例
  1386. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1387. // atlasScrew2.Initial();
  1388. // // 存储结果的列表
  1389. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1390. // // 上一次获取的数据
  1391. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1392. // while (isExitAtlasRight) // 检查是否收集数据
  1393. // {
  1394. // // 获取当前数据
  1395. // var currentResult = atlasScrew2.GetResults();
  1396. // // 判断是否为新数据
  1397. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1398. // {
  1399. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1400. // // 将新数据写入PLC
  1401. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1402. // // 将新数据添加到结果列表
  1403. // results.Add(currentResult);
  1404. // // 更新上一次获取的数据
  1405. // lastResult = currentResult;
  1406. // }
  1407. // // 等待一段时间后再次检查
  1408. // Thread.Sleep(20); // 轮询间隔时间
  1409. // // 如果触发了出站,则退出循环
  1410. // if (!isExitAtlasRight)
  1411. // {
  1412. // break;
  1413. // }
  1414. // }
  1415. // // 将所有数据写入文件
  1416. // //WriteDataToFile(sn, direction, results);
  1417. // stopwatch.Stop();
  1418. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1419. // }
  1420. // catch (Exception ex)
  1421. // {
  1422. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1423. // }
  1424. // finally
  1425. // {
  1426. // // 重置标志变量
  1427. // isExitAtlasRight = false;
  1428. // }
  1429. //}
  1430. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1431. {
  1432. Stopwatch stopwatch = new Stopwatch();
  1433. stopwatch.Start();
  1434. int nRet = 0;
  1435. string strRet = "";
  1436. try
  1437. {
  1438. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1439. while (isCollectingFlagLeft)
  1440. {
  1441. // 从缓存中获取所有未处理的数据
  1442. var cachedData = atlasScrew.GetCachedDataLeft();
  1443. foreach (var currentResult in cachedData)
  1444. {
  1445. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1446. {
  1447. continue; // 跳过无效数据
  1448. }
  1449. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1450. // 写入PLC
  1451. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1452. {
  1453. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1454. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1455. };
  1456. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1457. if (nRet != 0)
  1458. {
  1459. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1460. }
  1461. else
  1462. {
  1463. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1464. }
  1465. // 构建保存路径
  1466. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1467. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1468. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1469. Directory.CreateDirectory(savePath); // 确保目录存在
  1470. // 构建文件名(以 SN + 序号命名)
  1471. string fileName = $"{sn}_{fileCounter}.txt";
  1472. string filePath = Path.Combine(savePath, fileName);
  1473. // 写入文件
  1474. using (StreamWriter writer = new StreamWriter(filePath))
  1475. {
  1476. writer.WriteLine("精度, 扭力");
  1477. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1478. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1479. {
  1480. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1481. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1482. writer.WriteLine($"{precision}, {torque}");
  1483. }
  1484. }
  1485. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1486. // 增加文件计数器
  1487. fileCounter++;
  1488. }
  1489. // 如果没有更多数据,则短暂休眠以节省资源
  1490. if (!cachedData.Any())
  1491. {
  1492. Thread.Sleep(10); // 根据需要调整休眠时间
  1493. }
  1494. // 如果触发了出站,则退出循环
  1495. if (!isCollectingFlagLeft)
  1496. {
  1497. break;
  1498. }
  1499. }
  1500. stopwatch.Stop();
  1501. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1502. }
  1503. catch (Exception ex)
  1504. {
  1505. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1506. }
  1507. finally
  1508. {
  1509. isCollectingFlagLeft = false;
  1510. }
  1511. }
  1512. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1513. {
  1514. Stopwatch stopwatch = new Stopwatch();
  1515. stopwatch.Start();
  1516. int nRet = 0;
  1517. string strRet = "";
  1518. try
  1519. {
  1520. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1521. while (isCollectingFlagRight)
  1522. {
  1523. // 从缓存中获取所有未处理的数据
  1524. var cachedData = atlasScrew.GetCachedDataLeft();
  1525. foreach (var currentResult in cachedData)
  1526. {
  1527. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1528. {
  1529. continue; // 跳过无效数据
  1530. }
  1531. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1532. // 写入PLC
  1533. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1534. {
  1535. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1536. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1537. };
  1538. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1539. if (nRet != 0)
  1540. {
  1541. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1542. }
  1543. else
  1544. {
  1545. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1546. }
  1547. // 构建保存路径
  1548. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1549. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1550. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1551. Directory.CreateDirectory(savePath); // 确保目录存在
  1552. // 构建文件名(以 SN + 序号命名)
  1553. string fileName = $"{sn}_{fileCounter}.txt";
  1554. string filePath = Path.Combine(savePath, fileName);
  1555. // 写入文件
  1556. using (StreamWriter writer = new StreamWriter(filePath))
  1557. {
  1558. writer.WriteLine("精度, 扭力");
  1559. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1560. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1561. {
  1562. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1563. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1564. writer.WriteLine($"{precision}, {torque}");
  1565. }
  1566. }
  1567. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1568. // 增加文件计数器
  1569. fileCounter++;
  1570. }
  1571. // 如果没有更多数据,则短暂休眠以节省资源
  1572. if (!cachedData.Any())
  1573. {
  1574. Thread.Sleep(10); // 根据需要调整休眠时间
  1575. }
  1576. // 如果触发了出站,则退出循环
  1577. if (!isCollectingFlagRight)
  1578. {
  1579. break;
  1580. }
  1581. }
  1582. stopwatch.Stop();
  1583. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1584. }
  1585. catch (Exception ex)
  1586. {
  1587. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1588. }
  1589. finally
  1590. {
  1591. isCollectingFlagRight = false;
  1592. }
  1593. }
  1594. #endregion
  1595. #region S1
  1596. /// <summary>
  1597. /// [S1] 壳体清洁上料装备
  1598. /// </summary>
  1599. /// <param name="plcNo">PLC编号</param>
  1600. private void ReadStation_S1(int plcNo)
  1601. {
  1602. string stationCode = "[OP10]";
  1603. string stationName = "壳体清洁上料";
  1604. string stationNameStr = stationCode + stationName;
  1605. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1606. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1607. string tagAgvCommName = "agvCommFrmPC";
  1608. string tagBarsetName = "BarcodeSet";
  1609. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1610. (int, string) result;
  1611. while (true)
  1612. {
  1613. try
  1614. {
  1615. if (!GlobalContext._IsCon_Funs1)
  1616. {
  1617. UpdatePLCMonitor(1, plcNo, 0);
  1618. continue;
  1619. }
  1620. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1621. {
  1622. Stopwatch stopwatch1 = new Stopwatch();
  1623. Stopwatch stopwatch2 = new Stopwatch();
  1624. stopwatch1.Start();
  1625. stopwatch2.Start();
  1626. #region 一次性读取所有数据
  1627. // 一次性读取所有数据
  1628. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1629. if (result.Item1 != 0)
  1630. {
  1631. //richTextBox1.AppendText("\n" + strRet);
  1632. }
  1633. else
  1634. {
  1635. //richTextBox1.AppendText("\n" + "读取成功");
  1636. }
  1637. #endregion 一次性读取所有数据
  1638. stopwatch2.Stop();
  1639. #region 进站
  1640. try
  1641. {
  1642. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1643. {
  1644. lock (lockObj)
  1645. {
  1646. if (!ProgressState)
  1647. {
  1648. ProgressState = true;
  1649. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1650. }
  1651. }
  1652. }
  1653. }
  1654. catch (Exception ex)
  1655. {
  1656. ProgressState = false;
  1657. string str = ex.StackTrace;
  1658. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1659. }
  1660. #endregion 进站
  1661. #region 出站
  1662. try
  1663. {
  1664. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1665. {
  1666. lock (lockObj)
  1667. {
  1668. if (!ProgressState)
  1669. {
  1670. ProgressState = true;
  1671. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1672. }
  1673. }
  1674. }
  1675. }
  1676. catch (Exception ex)
  1677. {
  1678. ProgressState = false;
  1679. string str = ex.StackTrace;
  1680. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1681. }
  1682. #endregion 进站
  1683. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1684. stopwatch1.Stop();
  1685. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1686. }
  1687. else
  1688. {
  1689. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1690. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1691. FunsEip[plcNo].Connect(); // 重连
  1692. }
  1693. }
  1694. catch (Exception ex)
  1695. {
  1696. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1697. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1698. }
  1699. Thread.Sleep(IntervalReadPLC);
  1700. }
  1701. }
  1702. /// <summary>
  1703. /// [S1] 壳体清洁上料 - 进站
  1704. /// </summary>
  1705. /// <param name="plcNo">PLC编号</param>
  1706. /// <param name="stationNameStr">工站全称</param>
  1707. /// <param name="stPLC_MesData"></param>
  1708. /// <param name="tagMesCommName"></param>
  1709. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1710. {
  1711. Stopwatch stopwatch1 = new Stopwatch();
  1712. Stopwatch stopwatch2 = new Stopwatch();
  1713. try
  1714. {
  1715. stopwatch1.Start();
  1716. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1717. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1718. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1719. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1720. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1721. if (string.IsNullOrEmpty(sn))
  1722. {
  1723. ProgressState = false;
  1724. return;
  1725. }
  1726. //正式生产就用PLC中取的
  1727. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1728. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1729. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1730. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1731. //绑定载具和产品
  1732. ResponseMessage message = new ResponseMessage();
  1733. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1734. if (message.result == false)
  1735. {
  1736. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1737. }
  1738. // 产品SN进站
  1739. List<TestItem> item = new List<TestItem>();
  1740. stopwatch2.Start();
  1741. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1742. stopwatch2.Stop();
  1743. //指令执行结果 1:OK 110:失败
  1744. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1745. //进站结果写入PLC
  1746. CommandFromPLC resultToPlC = new CommandFromPLC();
  1747. resultToPlC.cmd = 0;
  1748. resultToPlC.cmdParam = 0;
  1749. resultToPlC.cmdResult = mesResultFrmWeb;
  1750. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1751. }
  1752. catch (Exception ex)
  1753. {
  1754. string str = ex.StackTrace;
  1755. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1756. CommandFromPLC resultToPlC = new CommandFromPLC();
  1757. resultToPlC.cmd = 0;
  1758. resultToPlC.cmdParam = 0; //指令参数
  1759. resultToPlC.cmdResult = 110;
  1760. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1761. }
  1762. stopwatch1.Stop();
  1763. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1764. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1765. ProgressState = false;
  1766. }
  1767. /// <summary>
  1768. /// [S1] 壳体清洁上料 - 出站接口
  1769. /// </summary>
  1770. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1771. {
  1772. Stopwatch stopwatch1 = new Stopwatch();
  1773. Stopwatch stopwatch2 = new Stopwatch();
  1774. try
  1775. {
  1776. stopwatch1.Start();
  1777. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1778. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1779. string processItem = stationName; // 项目
  1780. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1781. string supplierCode = ""; // 供应商代码
  1782. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1783. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1784. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1785. string sn = string.Empty;
  1786. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1787. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1788. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1789. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1790. a1Result = 1;
  1791. bool pass = a1Result == 1;
  1792. //根据载具码获取产品码
  1793. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1794. if (string.IsNullOrEmpty(strProductBarcode))
  1795. {
  1796. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1797. }
  1798. sn = strProductBarcode;
  1799. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1800. List<TestItem> items = new List<TestItem>();
  1801. items.Add(new TestItem()
  1802. {
  1803. Parameter_name = "载具码",
  1804. Parameter_value = CarrierBarcode,
  1805. Parameter_unit = ""
  1806. });
  1807. items.Add(new TestItem()
  1808. {
  1809. Parameter_name = "产品码",
  1810. Parameter_value = sn,
  1811. Parameter_unit = ""
  1812. });
  1813. //出站接口
  1814. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1815. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1816. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1817. stopwatch2.Start();
  1818. //进站结果写入PLC
  1819. CommandFromPLC resultToPlC = new CommandFromPLC();
  1820. resultToPlC.cmd = 0;
  1821. resultToPlC.cmdParam = 0; //指令参数
  1822. resultToPlC.cmdResult = mesResultFrmWeb;
  1823. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1824. stopwatch2.Stop();
  1825. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1826. //保存PLC返回MES数据到本地
  1827. ResponseMessage message = new ResponseMessage();
  1828. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1829. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1830. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1831. stPLC_MesData.mesData.nRemainCount);
  1832. if (message.result == false)
  1833. {
  1834. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1835. }
  1836. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1837. }
  1838. catch (Exception ex)
  1839. {
  1840. stopwatch2.Start();
  1841. CommandFromPLC resultToPlC = new CommandFromPLC();
  1842. resultToPlC.cmd = 0;
  1843. resultToPlC.cmdParam = 0; //指令参数
  1844. resultToPlC.cmdResult = 110;
  1845. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1846. stopwatch2.Stop();
  1847. string str = ex.StackTrace;
  1848. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1849. }
  1850. stopwatch1.Stop();
  1851. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1852. ProgressState = false;
  1853. }
  1854. #endregion
  1855. #region S2
  1856. /// <summary>
  1857. /// [S2] 上盖板上料装备
  1858. /// </summary>
  1859. /// <param name="plcNo">PLC编号</param>
  1860. private void ReadStation_S2(int plcNo)
  1861. {
  1862. string stationCode = "[OP20]";
  1863. string stationName = "上盖板上料装备";
  1864. string stationNameStr = stationCode + stationName;
  1865. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1866. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1867. string tagAgvCommName = "agvCommFrmPC";
  1868. string tagBarsetName = "BarcodeSet";
  1869. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1870. (int, string) result;
  1871. while (true)
  1872. {
  1873. try
  1874. {
  1875. if (!GlobalContext._IsCon_Funs2)
  1876. {
  1877. UpdatePLCMonitor(1, plcNo, 0);
  1878. continue;
  1879. }
  1880. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1881. {
  1882. Stopwatch stopwatch1 = new Stopwatch();
  1883. Stopwatch stopwatch2 = new Stopwatch();
  1884. stopwatch1.Start();
  1885. stopwatch2.Start();
  1886. #region 一次性读取所有数据
  1887. // 一次性读取所有数据
  1888. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1889. if (result.Item1 != 0)
  1890. {
  1891. //richTextBox1.AppendText("\n" + strRet);
  1892. }
  1893. else
  1894. {
  1895. //richTextBox1.AppendText("\n" + "读取成功");
  1896. }
  1897. #endregion 一次性读取所有数据
  1898. stopwatch2.Stop();
  1899. #region 进站
  1900. try
  1901. {
  1902. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1903. {
  1904. lock (lockObj)
  1905. {
  1906. if (!ProgressState)
  1907. {
  1908. ProgressState = true;
  1909. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1910. }
  1911. }
  1912. }
  1913. }
  1914. catch (Exception ex)
  1915. {
  1916. ProgressState = false;
  1917. string str = ex.StackTrace;
  1918. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1919. }
  1920. #endregion 进站
  1921. #region 出站
  1922. try
  1923. {
  1924. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1925. {
  1926. lock (lockObj)
  1927. {
  1928. if (!ProgressState)
  1929. {
  1930. ProgressState = true;
  1931. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1932. }
  1933. }
  1934. }
  1935. }
  1936. catch (Exception ex)
  1937. {
  1938. ProgressState = false;
  1939. string str = ex.StackTrace;
  1940. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1941. }
  1942. #endregion 进站
  1943. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1944. stopwatch1.Stop();
  1945. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1946. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1947. }
  1948. else
  1949. {
  1950. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1951. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1952. FunsEip[plcNo].Connect();
  1953. }
  1954. }
  1955. catch (Exception ex)
  1956. {
  1957. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1958. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1959. //Funs[plcNo].ReConnect();
  1960. }
  1961. Thread.Sleep(IntervalReadPLC);
  1962. }
  1963. }
  1964. /// <summary>
  1965. /// [S2] 上盖板上料装备
  1966. /// </summary>
  1967. /// <param name="plcNo">PLC编号</param>
  1968. /// <param name="stationNameStr">工站全称</param>
  1969. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  1970. {
  1971. Stopwatch stopwatch1 = new Stopwatch();
  1972. Stopwatch stopwatch2 = new Stopwatch();
  1973. try
  1974. {
  1975. stopwatch1.Start();
  1976. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1977. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  1978. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1979. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  1980. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  1981. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  1982. //根据载具码获取产品码
  1983. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  1984. if (string.IsNullOrEmpty(strProductBarcode))
  1985. {
  1986. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1987. }
  1988. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  1989. //if (sn != strProductBarcode)
  1990. //{
  1991. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  1992. //}
  1993. sn = strProductBarcode;
  1994. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  1995. // 产品SN(物料码)校验
  1996. List<TestItem> item = new List<TestItem>();
  1997. stopwatch2.Start();
  1998. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1999. stopwatch2.Stop();
  2000. //指令执行结果 1:OK 110:失败
  2001. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2002. //进站结果写入PLC
  2003. CommandFromPLC resultToPlC = new CommandFromPLC();
  2004. resultToPlC.cmd = 0;
  2005. resultToPlC.cmdParam = 0; //指令参数
  2006. resultToPlC.cmdResult = mesResultFrmWeb;
  2007. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2008. }
  2009. catch (Exception ex)
  2010. {
  2011. string str = ex.StackTrace;
  2012. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2013. CommandFromPLC resultToPlC = new CommandFromPLC();
  2014. resultToPlC.cmd = 0;
  2015. resultToPlC.cmdParam = 0; //指令参数
  2016. resultToPlC.cmdResult = 110;
  2017. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2018. }
  2019. stopwatch1.Stop();
  2020. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2021. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2022. ProgressState = false;
  2023. }
  2024. /// <summary>
  2025. /// [S2] 上盖板上料装备 - 出站接口
  2026. /// </summary>
  2027. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2028. {
  2029. Stopwatch stopwatch1 = new Stopwatch();
  2030. Stopwatch stopwatch2 = new Stopwatch();
  2031. try
  2032. {
  2033. stopwatch1.Start();
  2034. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2035. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2036. string processItem = stationName; // 测试项目
  2037. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2038. string supplierCode = ""; // 供应商代码
  2039. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2040. string batch_num = GlobalContext.BatchNumber; // 批次号
  2041. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2042. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2043. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2044. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2045. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2046. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  2047. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2048. bool pass = a1Result == 1;
  2049. //根据载具码获取产品码
  2050. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2051. if (string.IsNullOrEmpty(strProductBarcode))
  2052. {
  2053. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2054. }
  2055. sn = strProductBarcode;
  2056. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2057. List<TestItem> items = new List<TestItem>();
  2058. items.Add(new TestItem()
  2059. {
  2060. Parameter_name = "载具码",
  2061. Parameter_value = CarrierBarcode,
  2062. Parameter_unit = ""
  2063. });
  2064. items.Add(new TestItem()
  2065. {
  2066. Parameter_name = "产品码",
  2067. Parameter_value = sn,
  2068. Parameter_unit = ""
  2069. });
  2070. items.Add(new TestItem()
  2071. {
  2072. Parameter_name = "部件码",
  2073. Parameter_value = PartBarcode,
  2074. Parameter_unit = ""
  2075. });
  2076. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2077. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2078. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2079. stopwatch2.Start();
  2080. //进站结果写入PLC
  2081. CommandFromPLC resultToPlC = new CommandFromPLC();
  2082. resultToPlC.cmd = 0;
  2083. resultToPlC.cmdParam = 0; //指令参数
  2084. resultToPlC.cmdResult = mesResultFrmWeb;
  2085. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2086. stopwatch2.Stop();
  2087. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2088. //保存PLC返回MES数据到本地
  2089. ResponseMessage message = new ResponseMessage();
  2090. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  2091. if (message.result == false)
  2092. {
  2093. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2094. }
  2095. if (!string.IsNullOrEmpty(PartBarcode))
  2096. {
  2097. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2098. if (message.result == false)
  2099. {
  2100. AddMessage(LogType.Error, message.text);
  2101. }
  2102. }
  2103. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2104. }
  2105. catch (Exception ex)
  2106. {
  2107. stopwatch2.Start();
  2108. CommandFromPLC resultToPlC = new CommandFromPLC();
  2109. resultToPlC.cmd = 0;
  2110. resultToPlC.cmdParam = 0; //指令参数
  2111. resultToPlC.cmdResult = 110;
  2112. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2113. stopwatch2.Stop();
  2114. string str = ex.StackTrace;
  2115. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2116. }
  2117. stopwatch1.Stop();
  2118. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2119. ProgressState = false;
  2120. }
  2121. #endregion
  2122. #region S3
  2123. /// <summary>
  2124. /// [S3] 点散热胶装备
  2125. /// </summary>
  2126. /// <param name="plcNo">PLC编号</param>
  2127. private void ReadStation_S3(int plcNo)
  2128. {
  2129. string stationCode = "[OP30]";
  2130. string stationName = "点散热胶装备";
  2131. string stationNameStr = stationCode + stationName;
  2132. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2133. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2134. string tagAgvCommName = "agvCommFrmPC";
  2135. string tagBarsetName = "BarcodeSet";
  2136. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2137. (int, string) result;
  2138. #region 创建字典
  2139. // 触发信号字典 赋值
  2140. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2141. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2142. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2143. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2144. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2145. // PLC数据字典 赋值
  2146. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2147. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2148. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2149. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2150. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2151. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2152. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2153. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2154. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2155. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2156. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2157. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2158. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2159. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2160. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2161. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2162. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2163. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2164. s3PLCData.Add("c1Result", 0); // 产品结果
  2165. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2166. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2167. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2168. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2169. #endregion 创建字典
  2170. while (true)
  2171. {
  2172. try
  2173. {
  2174. if (!GlobalContext._IsCon_Funs2)
  2175. {
  2176. UpdatePLCMonitor(1, plcNo, 0);
  2177. continue;
  2178. }
  2179. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2180. {
  2181. Stopwatch stopwatch1 = new Stopwatch();
  2182. Stopwatch stopwatch2 = new Stopwatch();
  2183. stopwatch1.Start();
  2184. stopwatch2.Start();
  2185. #region 一次性读取所有数据
  2186. // 一次性读取所有数据
  2187. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2188. if (result.Item1 != 0)
  2189. {
  2190. //richTextBox1.AppendText("\n" + strRet);
  2191. }
  2192. else
  2193. {
  2194. //richTextBox1.AppendText("\n" + "读取成功");
  2195. }
  2196. #endregion 一次性读取所有数据
  2197. stopwatch2.Stop();
  2198. #region 左边进站
  2199. try
  2200. {
  2201. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2202. {
  2203. lock (lockObj)
  2204. {
  2205. if (!ProgressState)
  2206. {
  2207. ProgressState = true;
  2208. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2209. }
  2210. }
  2211. }
  2212. }
  2213. catch (Exception ex)
  2214. {
  2215. ProgressState = false;
  2216. string str = ex.StackTrace;
  2217. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2218. }
  2219. #endregion 左边进站
  2220. #region 左边出站
  2221. try
  2222. {
  2223. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2224. {
  2225. lock (lockObj)
  2226. {
  2227. if (!ProgressState)
  2228. {
  2229. ProgressState = true;
  2230. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2231. }
  2232. }
  2233. }
  2234. }
  2235. catch (Exception ex)
  2236. {
  2237. ProgressState = false;
  2238. string str = ex.StackTrace;
  2239. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2240. }
  2241. #endregion 左边出站
  2242. #region 右边进站
  2243. try
  2244. {
  2245. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2246. {
  2247. lock (lockObj)
  2248. {
  2249. if (!ProgressState)
  2250. {
  2251. ProgressState = true;
  2252. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2253. }
  2254. }
  2255. }
  2256. }
  2257. catch (Exception ex)
  2258. {
  2259. ProgressState = false;
  2260. string str = ex.StackTrace;
  2261. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2262. }
  2263. #endregion 右边进站
  2264. #region 右边出站
  2265. try
  2266. {
  2267. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2268. {
  2269. lock (lockObj)
  2270. {
  2271. if (!ProgressState)
  2272. {
  2273. ProgressState = true;
  2274. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2275. }
  2276. }
  2277. }
  2278. }
  2279. catch (Exception ex)
  2280. {
  2281. string str = ex.StackTrace;
  2282. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2283. }
  2284. #endregion 右边出站
  2285. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2286. stopwatch1.Stop();
  2287. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2288. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2289. }
  2290. else
  2291. {
  2292. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2293. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2294. FunsEip[plcNo].Connect();
  2295. }
  2296. }
  2297. catch (Exception ex)
  2298. {
  2299. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2300. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2301. //Funs[plcNo].ReConnect();
  2302. }
  2303. Thread.Sleep(IntervalReadPLC);
  2304. }
  2305. }
  2306. /// <summary>
  2307. /// [S3] 点散热胶装备 - 进站
  2308. /// </summary>
  2309. /// <param name="plcNo">PLC编号</param>
  2310. /// <param name="stationNameStr">工站全称</param>
  2311. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2312. {
  2313. Stopwatch stopwatch1 = new Stopwatch();
  2314. Stopwatch stopwatch2 = new Stopwatch();
  2315. try
  2316. {
  2317. stopwatch1.Start();
  2318. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2319. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2320. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2321. string StationId=string.Empty;
  2322. if (direction=="Left")
  2323. {
  2324. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2325. }
  2326. if (direction == "Right")
  2327. {
  2328. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2329. }
  2330. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2331. //载具码验证产品码
  2332. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2333. if (string.IsNullOrEmpty(strProductBarcode))
  2334. {
  2335. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2336. }
  2337. sn = strProductBarcode;
  2338. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2339. // 产品SN(物料码)校验
  2340. List<TestItem> item = new List<TestItem>();
  2341. stopwatch2.Start();
  2342. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2343. stopwatch2.Stop();
  2344. //指令执行结果 1:OK 110:失败
  2345. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2346. //进站结果写入PLC
  2347. CommandFromPLC resultToPlC = new CommandFromPLC();
  2348. resultToPlC.cmd = 0;
  2349. resultToPlC.cmdParam = 0; //指令参数
  2350. resultToPlC.cmdResult = mesResultFrmWeb;
  2351. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2352. }
  2353. catch (Exception ex)
  2354. {
  2355. string str = ex.StackTrace;
  2356. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2357. CommandFromPLC resultToPlC = new CommandFromPLC();
  2358. resultToPlC.cmd = 0;
  2359. resultToPlC.cmdParam = 0; //指令参数
  2360. resultToPlC.cmdResult = 110;
  2361. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2362. }
  2363. stopwatch1.Stop();
  2364. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2365. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2366. ProgressState = false;
  2367. }
  2368. /// <summary>
  2369. /// [S3] 点散热胶装备 - 出站
  2370. /// </summary>
  2371. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2372. {
  2373. Stopwatch stopwatch1 = new Stopwatch();
  2374. Stopwatch stopwatch2 = new Stopwatch();
  2375. try
  2376. {
  2377. stopwatch1.Start();
  2378. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2379. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2380. string processItem = stationName; // 测试项目
  2381. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2382. string supplierCode = ""; // 供应商代码
  2383. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2384. string batch_num = GlobalContext.BatchNumber; // 批次号
  2385. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2386. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2387. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2388. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2389. string StationId = string.Empty;
  2390. if (direction == "Left")
  2391. {
  2392. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2393. }
  2394. if (direction == "Right")
  2395. {
  2396. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2397. }
  2398. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2399. bool pass = a1Result == 1;
  2400. //根据载具码获取产品码
  2401. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2402. if (string.IsNullOrEmpty(strProductBarcode))
  2403. {
  2404. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2405. }
  2406. sn = strProductBarcode;
  2407. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2408. List<TestItem> items = new List<TestItem>();
  2409. items.Add(new TestItem()
  2410. {
  2411. Parameter_name = "载具码",
  2412. Parameter_value = CarrierBarcode,
  2413. Parameter_unit = ""
  2414. });
  2415. items.Add(new TestItem()
  2416. {
  2417. Parameter_name = "产品码",
  2418. Parameter_value = sn,
  2419. Parameter_unit = ""
  2420. });
  2421. int result1 = 1;
  2422. if (direction == "Right")
  2423. {
  2424. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2425. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2426. }
  2427. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2428. stopwatch2.Start();
  2429. //进站结果写入PLC
  2430. CommandFromPLC resultToPlC = new CommandFromPLC();
  2431. resultToPlC.cmd = 0;
  2432. resultToPlC.cmdParam = 0; //指令参数
  2433. resultToPlC.cmdResult = mesResultFrmWeb;
  2434. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2435. stopwatch2.Stop();
  2436. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2437. //保存PLC返回MES数据到本地
  2438. ResponseMessage message = new ResponseMessage();
  2439. if (direction == "Left")
  2440. {
  2441. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2442. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2443. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2444. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2445. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2446. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2447. if (message.result == false)
  2448. {
  2449. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2450. }
  2451. }
  2452. if (direction == "Right")
  2453. {
  2454. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2455. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2456. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2457. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2458. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2459. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2460. if (message.result == false)
  2461. {
  2462. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2463. }
  2464. }
  2465. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2466. }
  2467. catch (Exception ex)
  2468. {
  2469. stopwatch2.Start();
  2470. CommandFromPLC resultToPlC = new CommandFromPLC();
  2471. resultToPlC.cmd = 0;
  2472. resultToPlC.cmdParam = 0; //指令参数
  2473. resultToPlC.cmdResult = 110;
  2474. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2475. stopwatch2.Stop();
  2476. string str = ex.StackTrace;
  2477. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2478. }
  2479. stopwatch1.Stop();
  2480. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2481. ProgressState = false;
  2482. }
  2483. #endregion S3
  2484. #region S4
  2485. /// <summary>
  2486. /// [S4] 点胶检测设备
  2487. /// </summary>
  2488. /// <param name="plcNo">PLC编号</param>
  2489. private void ReadStation_S4(int plcNo)
  2490. {
  2491. string stationCode = "[OP40]";
  2492. string stationName = "胶线检测";
  2493. string stationNameStr = stationCode + stationName;
  2494. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2495. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2496. string tagAgvCommName = "agvCommFrmPC";
  2497. string tagBarsetName = "BarcodeSet";
  2498. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2499. (int, string) result;
  2500. while (true)
  2501. {
  2502. try
  2503. {
  2504. if (!GlobalContext._IsCon_Funs1)
  2505. {
  2506. UpdatePLCMonitor(1, plcNo, 0);
  2507. continue;
  2508. }
  2509. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2510. {
  2511. Stopwatch stopwatch1 = new Stopwatch();
  2512. Stopwatch stopwatch2 = new Stopwatch();
  2513. stopwatch1.Start();
  2514. stopwatch2.Start();
  2515. #region 一次性读取所有数据
  2516. // 一次性读取所有数据
  2517. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2518. if (result.Item1 != 0)
  2519. {
  2520. //richTextBox1.AppendText("\n" + strRet);
  2521. }
  2522. else
  2523. {
  2524. //richTextBox1.AppendText("\n" + "读取成功");
  2525. }
  2526. #endregion 一次性读取所有数据
  2527. stopwatch2.Stop();
  2528. #region 进站
  2529. try
  2530. {
  2531. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2532. {
  2533. lock (lockObj)
  2534. {
  2535. if (!ProgressState)
  2536. {
  2537. ProgressState = true;
  2538. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2539. }
  2540. }
  2541. }
  2542. }
  2543. catch (Exception ex)
  2544. {
  2545. ProgressState = false;
  2546. string str = ex.StackTrace;
  2547. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2548. }
  2549. #endregion 进站
  2550. #region 出站
  2551. try
  2552. {
  2553. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2554. {
  2555. lock (lockObj)
  2556. {
  2557. if (!ProgressState)
  2558. {
  2559. ProgressState = true;
  2560. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2561. }
  2562. }
  2563. }
  2564. }
  2565. catch (Exception ex)
  2566. {
  2567. string str = ex.StackTrace;
  2568. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2569. }
  2570. #endregion 进站
  2571. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2572. stopwatch1.Stop();
  2573. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2574. }
  2575. else
  2576. {
  2577. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2578. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2579. FunsEip[plcNo].Connect(); // 重连
  2580. }
  2581. }
  2582. catch (Exception ex)
  2583. {
  2584. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2585. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2586. }
  2587. Thread.Sleep(IntervalReadPLC);
  2588. }
  2589. }
  2590. /// <summary>
  2591. /// [S4] 点胶检测设备 - 进站
  2592. /// </summary>
  2593. /// <param name="plcNo">PLC编号</param>
  2594. /// <param name="stationNameStr">工站全称</param>
  2595. /// <param name="stPLC_MesData"></param>
  2596. /// <param name="tagMesCommName"></param>
  2597. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2598. {
  2599. Stopwatch stopwatch1 = new Stopwatch();
  2600. Stopwatch stopwatch2 = new Stopwatch();
  2601. try
  2602. {
  2603. stopwatch1.Start();
  2604. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2605. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2606. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2607. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2608. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2609. //载具码验证产品码
  2610. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2611. if (string.IsNullOrEmpty(strProductBarcode))
  2612. {
  2613. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2614. }
  2615. sn = strProductBarcode;
  2616. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2617. // 产品SN(物料码)校验
  2618. List<TestItem> item = new List<TestItem>();
  2619. stopwatch2.Start();
  2620. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2621. stopwatch2.Stop();
  2622. //指令执行结果 1:OK 110:失败
  2623. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2624. //进站结果写入PLC
  2625. CommandFromPLC resultToPlC = new CommandFromPLC();
  2626. resultToPlC.cmd = 0;
  2627. resultToPlC.cmdParam = 0; //指令参数
  2628. resultToPlC.cmdResult = mesResultFrmWeb;
  2629. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2630. }
  2631. catch (Exception ex)
  2632. {
  2633. string str = ex.StackTrace;
  2634. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2635. CommandFromPLC resultToPlC = new CommandFromPLC();
  2636. resultToPlC.cmd = 0;
  2637. resultToPlC.cmdParam = 0; //指令参数
  2638. resultToPlC.cmdResult = 110;
  2639. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2640. }
  2641. stopwatch1.Stop();
  2642. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2643. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2644. ProgressState = false;
  2645. }
  2646. /// <summary>
  2647. /// [S4] 点胶检测设备 - 出站接口
  2648. /// </summary>
  2649. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2650. {
  2651. Stopwatch stopwatch1 = new Stopwatch();
  2652. Stopwatch stopwatch2 = new Stopwatch();
  2653. try
  2654. {
  2655. stopwatch1.Start();
  2656. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2657. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2658. string processItem = stationName; // 测试项目
  2659. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2660. string supplierCode = ""; // 供应商代码
  2661. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2662. string batch_num = GlobalContext.BatchNumber; // 批次号
  2663. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2664. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2665. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2666. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2667. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2668. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2669. bool pass = a1Result == 1;
  2670. //根据载具码获取产品码
  2671. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2672. if (string.IsNullOrEmpty(strProductBarcode))
  2673. {
  2674. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2675. }
  2676. sn = strProductBarcode;
  2677. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2678. List<TestItem> items = new List<TestItem>();
  2679. items.Add(new TestItem()
  2680. {
  2681. Parameter_name = "载具码",
  2682. Parameter_value = CarrierBarcode,
  2683. Parameter_unit = ""
  2684. });
  2685. items.Add(new TestItem()
  2686. {
  2687. Parameter_name = "产品码",
  2688. Parameter_value = sn,
  2689. Parameter_unit = ""
  2690. });
  2691. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2692. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2693. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2694. stopwatch2.Start();
  2695. //进站结果写入PLC
  2696. CommandFromPLC resultToPlC = new CommandFromPLC();
  2697. resultToPlC.cmd = 0;
  2698. resultToPlC.cmdParam = 0; //指令参数
  2699. resultToPlC.cmdResult = mesResultFrmWeb;
  2700. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2701. stopwatch2.Stop();
  2702. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2703. //保存PLC返回MES数据到本地
  2704. ResponseMessage message = new ResponseMessage();
  2705. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2706. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2707. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2708. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2709. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2710. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2711. if (message.result == false)
  2712. {
  2713. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2714. }
  2715. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2716. }
  2717. catch (Exception ex)
  2718. {
  2719. stopwatch2.Start();
  2720. CommandFromPLC resultToPlC = new CommandFromPLC();
  2721. resultToPlC.cmd = 0;
  2722. resultToPlC.cmdParam = 0; //指令参数
  2723. resultToPlC.cmdResult = 110;
  2724. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2725. stopwatch2.Stop();
  2726. string str = ex.StackTrace;
  2727. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2728. }
  2729. stopwatch1.Stop();
  2730. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2731. ProgressState = false;
  2732. }
  2733. #endregion
  2734. #region S5
  2735. /// <summary>
  2736. /// [S5] 点胶检测设备
  2737. /// </summary>
  2738. /// <param name="plcNo">PLC编号</param>
  2739. private void ReadStation_S5(int plcNo)
  2740. {
  2741. string stationCode = "[OP50]";
  2742. string stationName = "ADD板上料组装装备";
  2743. string stationNameStr = stationCode + stationName;
  2744. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2745. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2746. string tagAgvCommName = "agvCommFrmPC";
  2747. string tagBarsetName = "BarcodeSet";
  2748. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2749. (int, string) result;
  2750. while (true)
  2751. {
  2752. try
  2753. {
  2754. if (!GlobalContext._IsCon_Funs1)
  2755. {
  2756. UpdatePLCMonitor(1, plcNo, 0);
  2757. continue;
  2758. }
  2759. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2760. {
  2761. Stopwatch stopwatch1 = new Stopwatch();
  2762. Stopwatch stopwatch2 = new Stopwatch();
  2763. stopwatch1.Start();
  2764. stopwatch2.Start();
  2765. #region 一次性读取所有数据
  2766. // 一次性读取所有数据
  2767. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2768. if (result.Item1 != 0)
  2769. {
  2770. //richTextBox1.AppendText("\n" + strRet);
  2771. }
  2772. else
  2773. {
  2774. //richTextBox1.AppendText("\n" + "读取成功");
  2775. }
  2776. #endregion 一次性读取所有数据
  2777. stopwatch2.Stop();
  2778. #region 进站
  2779. try
  2780. {
  2781. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2782. {
  2783. lock (lockObj)
  2784. {
  2785. if (!ProgressState)
  2786. {
  2787. ProgressState = true;
  2788. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2789. }
  2790. }
  2791. }
  2792. }
  2793. catch (Exception ex)
  2794. {
  2795. ProgressState = false;
  2796. string str = ex.StackTrace;
  2797. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2798. }
  2799. #endregion 进站
  2800. #region 出站
  2801. try
  2802. {
  2803. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2804. {
  2805. lock (lockObj)
  2806. {
  2807. if (!ProgressState)
  2808. {
  2809. ProgressState = true;
  2810. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2811. }
  2812. }
  2813. }
  2814. }
  2815. catch (Exception ex)
  2816. {
  2817. ProgressState = false;
  2818. string str = ex.StackTrace;
  2819. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2820. }
  2821. #endregion 进站
  2822. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2823. stopwatch1.Stop();
  2824. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2825. }
  2826. else
  2827. {
  2828. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2829. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2830. FunsEip[plcNo].Connect(); // 重连
  2831. }
  2832. }
  2833. catch (Exception ex)
  2834. {
  2835. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2836. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2837. }
  2838. Thread.Sleep(IntervalReadPLC);
  2839. }
  2840. }
  2841. /// <summary>
  2842. /// [S5] 点胶检测设备 - 进站
  2843. /// </summary>
  2844. /// <param name="plcNo">PLC编号</param>
  2845. /// <param name="stationNameStr">工站全称</param>
  2846. /// <param name="stPLC_MesData"></param>
  2847. /// <param name="tagMesCommName"></param>
  2848. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2849. {
  2850. Stopwatch stopwatch1 = new Stopwatch();
  2851. Stopwatch stopwatch2 = new Stopwatch();
  2852. try
  2853. {
  2854. stopwatch1.Start();
  2855. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2856. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2857. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2858. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2859. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2860. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2861. //载具码验证产品码 //载具码验证产品码
  2862. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2863. if (string.IsNullOrEmpty(strProductBarcode))
  2864. {
  2865. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2866. }
  2867. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2868. //if (sn != strProductBarcode)
  2869. //{
  2870. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2871. //}
  2872. sn = strProductBarcode;
  2873. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2874. // 产品SN(物料码)校验
  2875. List<TestItem> item = new List<TestItem>();
  2876. stopwatch2.Start();
  2877. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2878. stopwatch2.Stop();
  2879. //指令执行结果 1:OK 110:失败
  2880. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2881. //进站结果写入PLC
  2882. CommandFromPLC resultToPlC = new CommandFromPLC();
  2883. resultToPlC.cmd = 0;
  2884. resultToPlC.cmdParam = 0; //指令参数
  2885. resultToPlC.cmdResult = mesResultFrmWeb;
  2886. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2887. }
  2888. catch (Exception ex)
  2889. {
  2890. string str = ex.StackTrace;
  2891. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2892. CommandFromPLC resultToPlC = new CommandFromPLC();
  2893. resultToPlC.cmd = 0;
  2894. resultToPlC.cmdParam = 0; //指令参数
  2895. resultToPlC.cmdResult = 110;
  2896. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2897. }
  2898. stopwatch1.Stop();
  2899. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2900. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2901. ProgressState = false;
  2902. }
  2903. /// <summary>
  2904. /// [S5] 点胶检测设备 - 出站接口
  2905. /// </summary>
  2906. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2907. {
  2908. Stopwatch stopwatch1 = new Stopwatch();
  2909. Stopwatch stopwatch2 = new Stopwatch();
  2910. try
  2911. {
  2912. stopwatch1.Start();
  2913. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2914. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2915. string processItem = stationName; // 测试项目
  2916. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2917. string supplierCode = ""; // 供应商代码
  2918. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2919. string batch_num = GlobalContext.BatchNumber; // 批次号
  2920. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2921. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2922. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2923. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2924. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2925. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2926. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2927. bool pass = a1Result == 1;
  2928. //根据载具码获取产品码
  2929. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2930. if (string.IsNullOrEmpty(strProductBarcode))
  2931. {
  2932. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2933. }
  2934. sn = strProductBarcode;
  2935. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2936. List<TestItem> items = new List<TestItem>();
  2937. items.Add(new TestItem()
  2938. {
  2939. Parameter_name = "载具码",
  2940. Parameter_value = CarrierBarcode,
  2941. Parameter_unit = ""
  2942. });
  2943. items.Add(new TestItem()
  2944. {
  2945. Parameter_name = "产品码",
  2946. Parameter_value = sn,
  2947. Parameter_unit = ""
  2948. });
  2949. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2950. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2951. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2952. stopwatch2.Start();
  2953. //进站结果写入PLC
  2954. CommandFromPLC resultToPlC = new CommandFromPLC();
  2955. resultToPlC.cmd = 0;
  2956. resultToPlC.cmdParam = 0; //指令参数
  2957. resultToPlC.cmdResult = mesResultFrmWeb;
  2958. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2959. stopwatch2.Stop();
  2960. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2961. //保存PLC返回MES数据到本地
  2962. ResponseMessage message = new ResponseMessage();
  2963. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  2964. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  2965. if (message.result == false)
  2966. {
  2967. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2968. }
  2969. //保存部件码信息
  2970. if (!string.IsNullOrEmpty(PartBarcode))
  2971. {
  2972. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  2973. if (message.result == false)
  2974. {
  2975. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  2976. }
  2977. }
  2978. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2979. }
  2980. catch (Exception ex)
  2981. {
  2982. stopwatch2.Start();
  2983. CommandFromPLC resultToPlC = new CommandFromPLC();
  2984. resultToPlC.cmd = 0;
  2985. resultToPlC.cmdParam = 0; //指令参数
  2986. resultToPlC.cmdResult = 110;
  2987. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2988. stopwatch2.Stop();
  2989. string str = ex.StackTrace;
  2990. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2991. }
  2992. stopwatch1.Stop();
  2993. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2994. ProgressState = false;
  2995. }
  2996. #endregion
  2997. #region S6
  2998. /// <summary>
  2999. /// [S6] 顶盖装配设备
  3000. /// </summary>
  3001. /// <param name="plcNo">PLC编号</param>
  3002. private void ReadStation_S6(int plcNo)
  3003. {
  3004. string stationCode = "[OP60]";
  3005. string stationName = "组上盖板";
  3006. string stationNameStr = stationCode + stationName;
  3007. string tagBaseName = "g_OP60_MES"; //标签变量名称
  3008. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3009. string tagAgvCommName = "agvCommFrmPC";
  3010. string tagBarsetName = "BarcodeSet";
  3011. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  3012. (int, string) result;
  3013. while (true)
  3014. {
  3015. try
  3016. {
  3017. if (!GlobalContext._IsCon_Funs1)
  3018. {
  3019. UpdatePLCMonitor(1, plcNo, 0);
  3020. continue;
  3021. }
  3022. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3023. {
  3024. Stopwatch stopwatch1 = new Stopwatch();
  3025. Stopwatch stopwatch2 = new Stopwatch();
  3026. stopwatch1.Start();
  3027. stopwatch2.Start();
  3028. #region 一次性读取所有数据
  3029. // 一次性读取所有数据
  3030. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3031. if (result.Item1 != 0)
  3032. {
  3033. //richTextBox1.AppendText("\n" + strRet);
  3034. }
  3035. else
  3036. {
  3037. //richTextBox1.AppendText("\n" + "读取成功");
  3038. }
  3039. #endregion 一次性读取所有数据
  3040. stopwatch2.Stop();
  3041. #region 进站
  3042. try
  3043. {
  3044. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3045. {
  3046. lock (lockObj)
  3047. {
  3048. if (!ProgressState)
  3049. {
  3050. ProgressState = true;
  3051. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3052. }
  3053. }
  3054. }
  3055. }
  3056. catch (Exception ex)
  3057. {
  3058. ProgressState = false;
  3059. string str = ex.StackTrace;
  3060. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3061. }
  3062. #endregion 进站
  3063. #region 出站
  3064. try
  3065. {
  3066. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3067. {
  3068. lock (lockObj)
  3069. {
  3070. if (!ProgressState)
  3071. {
  3072. ProgressState = true; ;
  3073. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3074. }
  3075. }
  3076. }
  3077. }
  3078. catch (Exception ex)
  3079. {
  3080. ProgressState = false;
  3081. string str = ex.StackTrace;
  3082. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3083. }
  3084. #endregion 进站
  3085. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3086. stopwatch1.Stop();
  3087. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3088. }
  3089. else
  3090. {
  3091. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3092. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3093. FunsEip[plcNo].Connect(); // 重连
  3094. }
  3095. }
  3096. catch (Exception ex)
  3097. {
  3098. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3099. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3100. }
  3101. Thread.Sleep(IntervalReadPLC);
  3102. }
  3103. }
  3104. /// <summary>
  3105. /// [S6] 顶盖装配设备 - 进站
  3106. /// </summary>
  3107. /// <param name="plcNo">PLC编号</param>
  3108. /// <param name="stationNameStr">工站全称</param>
  3109. /// <param name="stPLC_MesData"></param>
  3110. /// <param name="tagMesCommName"></param>
  3111. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3112. {
  3113. Stopwatch stopwatch1 = new Stopwatch();
  3114. Stopwatch stopwatch2 = new Stopwatch();
  3115. try
  3116. {
  3117. stopwatch1.Start();
  3118. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3119. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3120. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3121. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3122. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3123. //载具码验证产品码
  3124. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3125. if (string.IsNullOrEmpty(strProductBarcode))
  3126. {
  3127. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3128. }
  3129. sn = strProductBarcode;
  3130. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3131. // 产品SN(物料码)校验
  3132. List<TestItem> item = new List<TestItem>();
  3133. stopwatch2.Start();
  3134. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3135. stopwatch2.Stop();
  3136. //指令执行结果 1:OK 110:失败
  3137. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3138. //进站结果写入PLC
  3139. CommandFromPLC resultToPlC = new CommandFromPLC();
  3140. resultToPlC.cmd = 0;
  3141. resultToPlC.cmdParam = 0; //指令参数
  3142. resultToPlC.cmdResult = mesResultFrmWeb;
  3143. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3144. }
  3145. catch (Exception ex)
  3146. {
  3147. string str = ex.StackTrace;
  3148. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3149. CommandFromPLC resultToPlC = new CommandFromPLC();
  3150. resultToPlC.cmd = 0;
  3151. resultToPlC.cmdParam = 0; //指令参数
  3152. resultToPlC.cmdResult = 110;
  3153. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3154. }
  3155. stopwatch1.Stop();
  3156. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3157. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3158. ProgressState = false;
  3159. }
  3160. /// <summary>
  3161. /// [S6] 顶盖装配设备 - 出站接口
  3162. /// </summary>
  3163. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3164. {
  3165. Stopwatch stopwatch1 = new Stopwatch();
  3166. Stopwatch stopwatch2 = new Stopwatch();
  3167. try
  3168. {
  3169. stopwatch1.Start();
  3170. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3171. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3172. string processItem = stationName; // 测试项目
  3173. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3174. string supplierCode = ""; // 供应商代码
  3175. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3176. string batch_num = GlobalContext.BatchNumber; // 批次号
  3177. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3178. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3179. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3180. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3181. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3182. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3183. bool pass = a1Result == 1;
  3184. //根据载具码获取产品码
  3185. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3186. if (string.IsNullOrEmpty(strProductBarcode))
  3187. {
  3188. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3189. }
  3190. sn = strProductBarcode;
  3191. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3192. List<TestItem> items = new List<TestItem>();
  3193. items.Add(new TestItem()
  3194. {
  3195. Parameter_name = "载具码",
  3196. Parameter_value = CarrierBarcode,
  3197. Parameter_unit = ""
  3198. });
  3199. items.Add(new TestItem()
  3200. {
  3201. Parameter_name = "产品码",
  3202. Parameter_value = sn,
  3203. Parameter_unit = ""
  3204. });
  3205. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3206. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3207. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3208. stopwatch2.Start();
  3209. //进站结果写入PLC
  3210. CommandFromPLC resultToPlC = new CommandFromPLC();
  3211. resultToPlC.cmd = 0;
  3212. resultToPlC.cmdParam = 0; //指令参数
  3213. resultToPlC.cmdResult = mesResultFrmWeb;
  3214. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3215. stopwatch2.Stop();
  3216. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3217. //保存PLC返回MES数据到本地
  3218. ResponseMessage message = new ResponseMessage();
  3219. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3220. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3221. if (message.result == false)
  3222. {
  3223. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3224. }
  3225. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3226. }
  3227. catch (Exception ex)
  3228. {
  3229. stopwatch2.Start();
  3230. CommandFromPLC resultToPlC = new CommandFromPLC();
  3231. resultToPlC.cmd = 0;
  3232. resultToPlC.cmdParam = 0; //指令参数
  3233. resultToPlC.cmdResult = 110;
  3234. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3235. stopwatch2.Stop();
  3236. string str = ex.StackTrace;
  3237. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3238. }
  3239. stopwatch1.Stop();
  3240. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3241. ProgressState = false;
  3242. }
  3243. #endregion
  3244. #region S7
  3245. /// <summary>
  3246. /// [S7] 锁螺丝设备
  3247. /// </summary>
  3248. /// <param name="plcNo">PLC编号</param>
  3249. private void ReadStation_S7(int plcNo)
  3250. {
  3251. string stationCode = "[OP70]";
  3252. string stationName = "上盖板锁螺丝";
  3253. string stationNameStr = stationCode + stationName;
  3254. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3255. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3256. string tagAgvCommName = "agvCommFrmPC";
  3257. string tagBarsetName = "BarcodeSet";
  3258. string tagScrewDataset = "screwDataset";
  3259. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3260. (int, string) result;
  3261. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3262. atlasScrewLeft.Initial();
  3263. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3264. atlasScrewRight.Initial();
  3265. while (true)
  3266. {
  3267. try
  3268. {
  3269. if (!GlobalContext._IsCon_Funs1)
  3270. {
  3271. UpdatePLCMonitor(1, plcNo, 0);
  3272. continue;
  3273. }
  3274. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3275. {
  3276. Stopwatch stopwatch1 = new Stopwatch();
  3277. Stopwatch stopwatch2 = new Stopwatch();
  3278. stopwatch1.Start();
  3279. stopwatch2.Start();
  3280. #region 一次性读取所有数据
  3281. // 一次性读取所有数据
  3282. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3283. if (result.Item1 != 0)
  3284. {
  3285. //richTextBox1.AppendText("\n" + strRet);
  3286. }
  3287. else
  3288. {
  3289. //richTextBox1.AppendText("\n" + "读取成功");
  3290. }
  3291. #endregion 一次性读取所有数据
  3292. stopwatch2.Stop();
  3293. #region 左边进站
  3294. try
  3295. {
  3296. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3297. {
  3298. lock (lockObj)
  3299. {
  3300. if (!ProgressState)
  3301. {
  3302. ProgressState = true;
  3303. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3304. }
  3305. }
  3306. }
  3307. }
  3308. catch (Exception ex)
  3309. {
  3310. ProgressState = false;
  3311. string str = ex.StackTrace;
  3312. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3313. }
  3314. #endregion 左边进站
  3315. #region 左边出站
  3316. try
  3317. {
  3318. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3319. {
  3320. lock (lockObj)
  3321. {
  3322. if (!ProgressState)
  3323. {
  3324. ProgressState = true;
  3325. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3326. }
  3327. }
  3328. }
  3329. }
  3330. catch (Exception ex)
  3331. {
  3332. ProgressState = false;
  3333. string str = ex.StackTrace;
  3334. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3335. }
  3336. #endregion 左边出站
  3337. #region 右边进站
  3338. try
  3339. {
  3340. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3341. {
  3342. lock (lockObj)
  3343. {
  3344. if (!ProgressState)
  3345. {
  3346. ProgressState = true;
  3347. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3348. }
  3349. }
  3350. }
  3351. }
  3352. catch (Exception ex)
  3353. {
  3354. ProgressState = false;
  3355. string str = ex.StackTrace;
  3356. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3357. }
  3358. #endregion 右边进站
  3359. #region 右边出站
  3360. try
  3361. {
  3362. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3363. {
  3364. lock (lockObj)
  3365. {
  3366. if (!ProgressState)
  3367. {
  3368. ProgressState = true;
  3369. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3370. }
  3371. }
  3372. }
  3373. }
  3374. catch (Exception ex)
  3375. {
  3376. ProgressState = false;
  3377. string str = ex.StackTrace;
  3378. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3379. }
  3380. #endregion 右边出站
  3381. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3382. stopwatch1.Stop();
  3383. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3384. }
  3385. else
  3386. {
  3387. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3388. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3389. FunsEip[plcNo].Connect(); // 重连
  3390. }
  3391. }
  3392. catch (Exception ex)
  3393. {
  3394. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3395. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3396. }
  3397. Thread.Sleep(IntervalReadPLC);
  3398. }
  3399. }
  3400. /// <summary>
  3401. /// [S7] 锁螺丝设备 - 进站
  3402. /// </summary>
  3403. /// <param name="plcNo">PLC编号</param>
  3404. /// <param name="stationNameStr">工站全称</param>
  3405. /// <param name="stPLC_MesData"></param>
  3406. /// <param name="tagMesCommName"></param>
  3407. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3408. {
  3409. Stopwatch stopwatch1 = new Stopwatch();
  3410. Stopwatch stopwatch2 = new Stopwatch();
  3411. string atlasSn=string.Empty;
  3412. try
  3413. {
  3414. stopwatch1.Start();
  3415. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3416. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3417. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3418. string StationId = string.Empty; // 工位ID(可配置)
  3419. if (direction == "Left")
  3420. {
  3421. StationId = GlobalContext.S7_StationId_1;
  3422. }
  3423. if (direction == "Right")
  3424. {
  3425. StationId = GlobalContext.S7_StationId_2;
  3426. }
  3427. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3428. //载具码验证产品码
  3429. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3430. if (string.IsNullOrEmpty(strProductBarcode))
  3431. {
  3432. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3433. }
  3434. sn = strProductBarcode;
  3435. atlasSn= strProductBarcode;
  3436. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3437. if (direction == "Left")
  3438. {
  3439. isCollectingFlagLeft = false;//采集螺丝数据结束
  3440. }
  3441. if (direction == "Right")
  3442. {
  3443. isCollectingFlagRight = false;//采集螺丝数据结束
  3444. }
  3445. // 产品SN(物料码)校验
  3446. List<TestItem> item = new List<TestItem>();
  3447. stopwatch2.Start();
  3448. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3449. stopwatch2.Stop();
  3450. //指令执行结果 1:OK 110:失败
  3451. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3452. //进站结果写入PLC
  3453. CommandFromPLC resultToPlC = new CommandFromPLC();
  3454. resultToPlC.cmd = 0;
  3455. resultToPlC.cmdParam = 0; //指令参数
  3456. resultToPlC.cmdResult = mesResultFrmWeb;
  3457. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3458. }
  3459. catch (Exception ex)
  3460. {
  3461. string str = ex.StackTrace;
  3462. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3463. CommandFromPLC resultToPlC = new CommandFromPLC();
  3464. resultToPlC.cmd = 0;
  3465. resultToPlC.cmdParam = 0; //指令参数
  3466. resultToPlC.cmdResult = 110;
  3467. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3468. }
  3469. stopwatch1.Stop();
  3470. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3471. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3472. ProgressState = false;
  3473. //开始采集螺丝数据
  3474. if (direction == "Left")
  3475. {
  3476. isCollectingFlagLeft = true;
  3477. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3478. }
  3479. if (direction == "Right")
  3480. {
  3481. isCollectingFlagRight = true;
  3482. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3483. }
  3484. }
  3485. /// <summary>
  3486. /// [S7] 锁螺丝设备 - 出站
  3487. /// </summary>
  3488. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3489. {
  3490. Stopwatch stopwatch1 = new Stopwatch();
  3491. Stopwatch stopwatch2 = new Stopwatch();
  3492. try
  3493. {
  3494. stopwatch1.Start();
  3495. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3496. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3497. string processItem = stationName; // 测试项目
  3498. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3499. string supplierCode = ""; // 供应商代码
  3500. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3501. string batch_num = GlobalContext.BatchNumber; // 批次号
  3502. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3503. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3504. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3505. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3506. string StationId = string.Empty; // 工位ID(可配置)
  3507. if (direction == "Left")
  3508. {
  3509. StationId = GlobalContext.S7_StationId_1;
  3510. }
  3511. if (direction == "Right")
  3512. {
  3513. StationId = GlobalContext.S7_StationId_2;
  3514. }
  3515. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3516. a1Result = 1;
  3517. bool pass = a1Result == 1;
  3518. //根据载具码获取产品码
  3519. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3520. if (string.IsNullOrEmpty(strProductBarcode))
  3521. {
  3522. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3523. }
  3524. sn = strProductBarcode;
  3525. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3526. List<TestItem> items = new List<TestItem>();
  3527. items.Add(new TestItem()
  3528. {
  3529. Parameter_name = "载具码",
  3530. Parameter_value = CarrierBarcode,
  3531. Parameter_unit = ""
  3532. });
  3533. items.Add(new TestItem()
  3534. {
  3535. Parameter_name = "产品码",
  3536. Parameter_value = sn,
  3537. Parameter_unit = ""
  3538. });
  3539. int result1 = 1;
  3540. if (direction == "Right")
  3541. {
  3542. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3543. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3544. }
  3545. //if (direction == "Left")
  3546. //{
  3547. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3548. //}
  3549. //if (direction == "Right")
  3550. //{
  3551. // isCollectingFlagRight = false;//采集螺丝数据结束
  3552. //}
  3553. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3554. stopwatch2.Start();
  3555. //进站结果写入PLC
  3556. CommandFromPLC resultToPlC = new CommandFromPLC();
  3557. resultToPlC.cmd = 0;
  3558. resultToPlC.cmdParam = 0; //指令参数
  3559. resultToPlC.cmdResult = mesResultFrmWeb;
  3560. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3561. stopwatch2.Stop();
  3562. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3563. //保存PLC返回MES数据到本地
  3564. ResponseMessage message = new ResponseMessage();
  3565. if (direction == "Left")
  3566. {
  3567. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3568. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3569. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3570. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3571. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3572. if (message.result == false)
  3573. {
  3574. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3575. }
  3576. }
  3577. if (direction == "Right")
  3578. {
  3579. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3580. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3581. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3582. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3583. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3584. if (message.result == false)
  3585. {
  3586. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3587. }
  3588. }
  3589. //保存螺丝数据到txt
  3590. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3591. if (result.Item1 != 0)
  3592. {
  3593. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3594. }
  3595. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3596. }
  3597. catch (Exception ex)
  3598. {
  3599. stopwatch2.Start();
  3600. CommandFromPLC resultToPlC = new CommandFromPLC();
  3601. resultToPlC.cmd = 0;
  3602. resultToPlC.cmdParam = 0; //指令参数
  3603. resultToPlC.cmdResult = 110;
  3604. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3605. stopwatch2.Stop();
  3606. string str = ex.StackTrace;
  3607. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3608. }
  3609. stopwatch1.Stop();
  3610. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3611. ProgressState = false;
  3612. }
  3613. #endregion
  3614. #region S8
  3615. /// <summary>
  3616. /// [S8] 3D螺丝高度检测设备
  3617. /// </summary>
  3618. /// <param name="plcNo">PLC编号</param>
  3619. private void ReadStation_S8(int plcNo)
  3620. {
  3621. string stationCode = "[OP80]";
  3622. string stationName = "NG下料";
  3623. string stationNameStr = stationCode + stationName;
  3624. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3625. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3626. string tagAgvCommName = "agvCommFrmPC";
  3627. string tagBarsetName = "BarcodeSet";
  3628. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3629. (int, string) result;
  3630. while (true)
  3631. {
  3632. try
  3633. {
  3634. if (!GlobalContext._IsCon_Funs1)
  3635. {
  3636. UpdatePLCMonitor(1, plcNo, 0);
  3637. continue;
  3638. }
  3639. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3640. {
  3641. Stopwatch stopwatch1 = new Stopwatch();
  3642. Stopwatch stopwatch2 = new Stopwatch();
  3643. stopwatch1.Start();
  3644. stopwatch2.Start();
  3645. #region 一次性读取所有数据
  3646. // 一次性读取所有数据
  3647. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3648. if (result.Item1 != 0)
  3649. {
  3650. //richTextBox1.AppendText("\n" + strRet);
  3651. }
  3652. else
  3653. {
  3654. //richTextBox1.AppendText("\n" + "读取成功");
  3655. }
  3656. #endregion 一次性读取所有数据
  3657. stopwatch2.Stop();
  3658. #region 进站
  3659. try
  3660. {
  3661. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3662. {
  3663. lock (lockObj)
  3664. {
  3665. if (!ProgressState)
  3666. {
  3667. ProgressState = true;
  3668. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3669. }
  3670. }
  3671. }
  3672. }
  3673. catch (Exception ex)
  3674. {
  3675. ProgressState = false;
  3676. string str = ex.StackTrace;
  3677. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3678. }
  3679. #endregion 进站
  3680. #region 出站
  3681. try
  3682. {
  3683. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3684. {
  3685. lock (lockObj)
  3686. {
  3687. if (!ProgressState)
  3688. {
  3689. ProgressState = true;
  3690. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3691. }
  3692. }
  3693. }
  3694. }
  3695. catch (Exception ex)
  3696. {
  3697. ProgressState = false;
  3698. string str = ex.StackTrace;
  3699. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3700. }
  3701. #endregion 进站
  3702. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3703. stopwatch1.Stop();
  3704. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3705. }
  3706. else
  3707. {
  3708. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3709. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3710. FunsEip[plcNo].Connect(); // 重连
  3711. }
  3712. }
  3713. catch (Exception ex)
  3714. {
  3715. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3716. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3717. }
  3718. Thread.Sleep(IntervalReadPLC);
  3719. }
  3720. }
  3721. /// <summary>
  3722. /// [S8] 3D螺丝高度检测设备 - 进站
  3723. /// </summary>
  3724. /// <param name="plcNo">PLC编号</param>
  3725. /// <param name="stationNameStr">工站全称</param>
  3726. /// <param name="stPLC_MesData"></param>
  3727. /// <param name="tagMesCommName"></param>
  3728. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3729. {
  3730. Stopwatch stopwatch1 = new Stopwatch();
  3731. Stopwatch stopwatch2 = new Stopwatch();
  3732. try
  3733. {
  3734. stopwatch1.Start();
  3735. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3736. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3737. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3738. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3739. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3740. //载具码验证产品码
  3741. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3742. if (string.IsNullOrEmpty(strProductBarcode))
  3743. {
  3744. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3745. }
  3746. sn = strProductBarcode;
  3747. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3748. // 产品SN(物料码)校验
  3749. List<TestItem> item = new List<TestItem>();
  3750. stopwatch2.Start();
  3751. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3752. stopwatch2.Stop();
  3753. //指令执行结果 1:OK 110:失败
  3754. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3755. //进站结果写入PLC
  3756. CommandFromPLC resultToPlC = new CommandFromPLC();
  3757. resultToPlC.cmd = 0;
  3758. resultToPlC.cmdParam = 0; //指令参数
  3759. resultToPlC.cmdResult = mesResultFrmWeb;
  3760. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3761. }
  3762. catch (Exception ex)
  3763. {
  3764. string str = ex.StackTrace;
  3765. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3766. CommandFromPLC resultToPlC = new CommandFromPLC();
  3767. resultToPlC.cmd = 0;
  3768. resultToPlC.cmdParam = 0; //指令参数
  3769. resultToPlC.cmdResult = 110;
  3770. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3771. }
  3772. stopwatch1.Stop();
  3773. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3774. ProgressState = false;
  3775. }
  3776. /// <summary>
  3777. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3778. /// </summary>
  3779. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3780. {
  3781. Stopwatch stopwatch1 = new Stopwatch();
  3782. Stopwatch stopwatch2 = new Stopwatch();
  3783. try
  3784. {
  3785. stopwatch1.Start();
  3786. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3787. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3788. string processItem = stationName; // 测试项目
  3789. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3790. string supplierCode = ""; // 供应商代码
  3791. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3792. string batch_num = GlobalContext.BatchNumber; // 批次号
  3793. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3794. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3795. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3796. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3797. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3798. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3799. bool pass = a1Result == 1;
  3800. //根据载具码获取产品码
  3801. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3802. if (string.IsNullOrEmpty(strProductBarcode))
  3803. {
  3804. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3805. }
  3806. sn = strProductBarcode;
  3807. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3808. List<TestItem> items = new List<TestItem>();
  3809. items.Add(new TestItem()
  3810. {
  3811. Parameter_name = "载具码",
  3812. Parameter_value = CarrierBarcode,
  3813. Parameter_unit = ""
  3814. });
  3815. items.Add(new TestItem()
  3816. {
  3817. Parameter_name = "产品码",
  3818. Parameter_value = sn,
  3819. Parameter_unit = ""
  3820. });
  3821. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3822. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3823. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3824. stopwatch2.Start();
  3825. //进站结果写入PLC
  3826. CommandFromPLC resultToPlC = new CommandFromPLC();
  3827. resultToPlC.cmd = 0;
  3828. resultToPlC.cmdParam = 0; //指令参数
  3829. resultToPlC.cmdResult = mesResultFrmWeb;
  3830. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3831. stopwatch2.Stop();
  3832. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3833. //保存PLC返回MES数据到本地
  3834. ResponseMessage message = new ResponseMessage();
  3835. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3836. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3837. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3838. if (message.result == false)
  3839. {
  3840. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3841. }
  3842. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3843. }
  3844. catch (Exception ex)
  3845. {
  3846. stopwatch2.Start();
  3847. CommandFromPLC resultToPlC = new CommandFromPLC();
  3848. resultToPlC.cmd = 0;
  3849. resultToPlC.cmdParam = 0; //指令参数
  3850. resultToPlC.cmdResult = 110;
  3851. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3852. stopwatch2.Stop();
  3853. string str = ex.StackTrace;
  3854. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3855. }
  3856. stopwatch1.Stop();
  3857. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3858. ProgressState = false;
  3859. }
  3860. #endregion
  3861. #region S9
  3862. /// <summary>
  3863. /// [S9] 下料设备
  3864. /// </summary>
  3865. /// <param name="plcNo">PLC编号</param>
  3866. private void ReadStation_S9(int plcNo)
  3867. {
  3868. string stationCode = "[OP90]";
  3869. string stationName = "半成品下料";
  3870. string stationNameStr = stationCode + stationName;
  3871. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3872. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3873. string tagAgvCommName = "agvCommFrmPC";
  3874. string tagBarsetName = "BarcodeSet";
  3875. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3876. (int, string) result;
  3877. while (true)
  3878. {
  3879. try
  3880. {
  3881. if (!GlobalContext._IsCon_Funs1)
  3882. {
  3883. UpdatePLCMonitor(1, plcNo, 0);
  3884. continue;
  3885. }
  3886. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3887. {
  3888. Stopwatch stopwatch1 = new Stopwatch();
  3889. Stopwatch stopwatch2 = new Stopwatch();
  3890. stopwatch1.Start();
  3891. stopwatch2.Start();
  3892. #region 一次性读取所有数据
  3893. // 一次性读取所有数据
  3894. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3895. if (result.Item1 != 0)
  3896. {
  3897. //richTextBox1.AppendText("\n" + strRet);
  3898. }
  3899. else
  3900. {
  3901. //richTextBox1.AppendText("\n" + "读取成功");
  3902. }
  3903. #endregion 一次性读取所有数据
  3904. stopwatch2.Stop();
  3905. #region 进站
  3906. try
  3907. {
  3908. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3909. {
  3910. lock (lockObj)
  3911. {
  3912. if (!ProgressState)
  3913. {
  3914. ProgressState = true;
  3915. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3916. }
  3917. }
  3918. }
  3919. }
  3920. catch (Exception ex)
  3921. {
  3922. ProgressState = false;
  3923. string str = ex.StackTrace;
  3924. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3925. }
  3926. #endregion 进站
  3927. #region 出站
  3928. try
  3929. {
  3930. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3931. {
  3932. lock (lockObj)
  3933. {
  3934. if (!ProgressState)
  3935. {
  3936. ProgressState = true;
  3937. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3938. }
  3939. }
  3940. }
  3941. }
  3942. catch (Exception ex)
  3943. {
  3944. ProgressState = false;
  3945. string str = ex.StackTrace;
  3946. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3947. }
  3948. #endregion 进站
  3949. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3950. stopwatch1.Stop();
  3951. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3952. }
  3953. else
  3954. {
  3955. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3956. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3957. FunsEip[plcNo].Connect(); // 重连
  3958. }
  3959. }
  3960. catch (Exception ex)
  3961. {
  3962. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3963. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3964. }
  3965. Thread.Sleep(IntervalReadPLC);
  3966. }
  3967. }
  3968. /// <summary>
  3969. /// [S9] 下料设备 - 进站
  3970. /// </summary>
  3971. /// <param name="plcNo">PLC编号</param>
  3972. /// <param name="stationNameStr">工站全称</param>
  3973. /// <param name="stPLC_MesData"></param>
  3974. /// <param name="tagMesCommName"></param>
  3975. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3976. {
  3977. Stopwatch stopwatch1 = new Stopwatch();
  3978. Stopwatch stopwatch2 = new Stopwatch();
  3979. try
  3980. {
  3981. stopwatch1.Start();
  3982. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3983. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3984. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  3985. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  3986. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3987. //载具码验证产品码
  3988. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3989. if (string.IsNullOrEmpty(strProductBarcode))
  3990. {
  3991. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3992. }
  3993. sn = strProductBarcode;
  3994. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3995. // 产品SN(物料码)校验
  3996. List<TestItem> item = new List<TestItem>();
  3997. stopwatch2.Start();
  3998. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3999. stopwatch2.Stop();
  4000. //指令执行结果 1:OK 110:失败
  4001. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4002. //进站结果写入PLC
  4003. CommandFromPLC resultToPlC = new CommandFromPLC();
  4004. resultToPlC.cmd = 0;
  4005. resultToPlC.cmdParam = 0; //指令参数
  4006. resultToPlC.cmdResult = mesResultFrmWeb;
  4007. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4008. }
  4009. catch (Exception ex)
  4010. {
  4011. string str = ex.StackTrace;
  4012. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4013. CommandFromPLC resultToPlC = new CommandFromPLC();
  4014. resultToPlC.cmd = 0;
  4015. resultToPlC.cmdParam = 0; //指令参数
  4016. resultToPlC.cmdResult = 110;
  4017. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4018. }
  4019. stopwatch1.Stop();
  4020. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4021. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4022. ProgressState = false;
  4023. }
  4024. /// <summary>
  4025. /// [S9] 下料设备 - 出站接口
  4026. /// </summary>
  4027. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  4028. {
  4029. Stopwatch stopwatch1 = new Stopwatch();
  4030. Stopwatch stopwatch2 = new Stopwatch();
  4031. try
  4032. {
  4033. stopwatch1.Start();
  4034. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4035. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4036. string processItem = stationName; // 测试项目
  4037. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4038. string supplierCode = ""; // 供应商代码
  4039. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4040. string batch_num = GlobalContext.BatchNumber; // 批次号
  4041. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4042. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4043. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4044. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  4045. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  4046. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4047. bool pass = a1Result == 1;
  4048. //根据载具码获取产品码
  4049. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4050. if (string.IsNullOrEmpty(strProductBarcode))
  4051. {
  4052. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4053. }
  4054. sn = strProductBarcode;
  4055. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4056. List<TestItem> items = new List<TestItem>();
  4057. items.Add(new TestItem()
  4058. {
  4059. Parameter_name = "载具码",
  4060. Parameter_value = CarrierBarcode,
  4061. Parameter_unit = ""
  4062. });
  4063. items.Add(new TestItem()
  4064. {
  4065. Parameter_name = "产品码",
  4066. Parameter_value = sn,
  4067. Parameter_unit = ""
  4068. });
  4069. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4070. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  4071. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4072. stopwatch2.Start();
  4073. //进站结果写入PLC
  4074. CommandFromPLC resultToPlC = new CommandFromPLC();
  4075. resultToPlC.cmd = 0;
  4076. resultToPlC.cmdParam = 0; //指令参数
  4077. resultToPlC.cmdResult = mesResultFrmWeb;
  4078. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4079. stopwatch2.Stop();
  4080. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4081. //保存PLC返回MES数据到本地
  4082. ResponseMessage message = new ResponseMessage();
  4083. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4084. if (message.result == false)
  4085. {
  4086. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4087. }
  4088. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4089. if (result1 == 1)
  4090. {
  4091. //载具码解除绑定
  4092. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4093. if (message.result == false)
  4094. {
  4095. AddMessage(LogType.Error, message.text);
  4096. }
  4097. }
  4098. }
  4099. catch (Exception ex)
  4100. {
  4101. stopwatch2.Start();
  4102. CommandFromPLC resultToPlC = new CommandFromPLC();
  4103. resultToPlC.cmd = 0;
  4104. resultToPlC.cmdParam = 0; //指令参数
  4105. resultToPlC.cmdResult = 110;
  4106. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4107. stopwatch2.Stop();
  4108. string str = ex.StackTrace;
  4109. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4110. }
  4111. stopwatch1.Stop();
  4112. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4113. ProgressState = false;
  4114. }
  4115. #endregion
  4116. #endregion Xiaomi
  4117. #region PLC1 张超凡
  4118. #region [S1] Tray盘上料装备(板测)
  4119. /// <summary>
  4120. /// S1工位的数据- 触发信号上次的值
  4121. /// </summary>
  4122. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4123. /// <summary>
  4124. /// S1工位的数据(含触发信号)
  4125. /// </summary>
  4126. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4127. /// <summary>
  4128. /// S1工位的数据- 回写点位
  4129. /// </summary>
  4130. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4131. ///// <summary>
  4132. ///// 触发信号
  4133. ///// </summary>
  4134. //private ManualResetEvent[] MreTasks;
  4135. /// <summary>
  4136. /// [S1] Tray盘上料装备(板测)
  4137. /// </summary>
  4138. /// <param name="plcNo">PLC编号</param>
  4139. //private void ReadStation_S1(int plcNo)
  4140. //{
  4141. // // [S1] Tray盘上料装备
  4142. // // [S2] FCT
  4143. // // [S3] 值板机
  4144. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4145. // // [S5] Tray盘下料装备
  4146. // string stationCode = "[S1]";
  4147. // string stationName = "Tray盘上料装备";
  4148. // string stationNameStr = stationCode + stationName;
  4149. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4150. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4151. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4152. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4153. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4154. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4155. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4156. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4157. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4158. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4159. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4160. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4161. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4162. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4163. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4164. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4165. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4166. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4167. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4168. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4169. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4170. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4171. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4172. // s1PLCData.Add("a1Result", 0); // 产品结果
  4173. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4174. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4175. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4176. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4177. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4178. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4179. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4180. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4181. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4182. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4183. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4184. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4185. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4186. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4187. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4188. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4189. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4190. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4191. // while (IsRun)
  4192. // {
  4193. // try
  4194. // {
  4195. // if (!GlobalContext._IsCon_Funs1)
  4196. // {
  4197. // UpdatePLCMonitor(1, plcNo, 0);
  4198. // continue;
  4199. // }
  4200. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4201. // {
  4202. // Stopwatch stopwatch1 = new Stopwatch();
  4203. // Stopwatch stopwatch2 = new Stopwatch();
  4204. // stopwatch1.Start();
  4205. // stopwatch2.Start();
  4206. // #region 一次性读取所有数据
  4207. // // 一次性读取所有数据
  4208. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4209. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4210. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4211. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4212. // int[] datas = data1.Concat(data2).ToArray();
  4213. // datas = datas.Concat(data3).ToArray();
  4214. // datas = datas.Concat(data4).ToArray();
  4215. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4216. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4217. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4218. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4219. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4220. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4221. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4222. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4223. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4224. // s1PLCData["a1MES_FLAG"] = datas[109];
  4225. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4226. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4227. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4228. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4229. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4230. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4231. // s1PLCData["a1Result"] = datas[170];
  4232. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4233. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4234. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4235. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4236. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4237. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4238. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4239. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4240. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4241. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4242. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4243. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4244. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4245. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4246. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4247. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4248. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4249. // s1PLCData["a1AGVUpStart"] = datas[308];
  4250. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4251. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4252. // s1PLCData["a1AGVDownStart"] = datas[321];
  4253. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4254. // #endregion 一次性读取所有数据
  4255. // stopwatch2.Stop();
  4256. // #region 回写操作,写后清空flag
  4257. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4258. // #endregion 回写操作,写后清空flag
  4259. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4260. // try
  4261. // {
  4262. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4263. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4264. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4265. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4266. // {
  4267. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4268. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4269. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4270. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4271. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4272. // }
  4273. // }
  4274. // catch (Exception ex)
  4275. // {
  4276. // // 6代表上位机报警
  4277. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4278. // string str = ex.StackTrace;
  4279. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4280. // }
  4281. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4282. // #region 上料进站校验
  4283. // try
  4284. // {
  4285. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4286. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4287. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4288. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4289. // {
  4290. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4291. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4292. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4293. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4294. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4295. // }
  4296. // }
  4297. // catch (Exception ex)
  4298. // {
  4299. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4300. // string str = ex.StackTrace;
  4301. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4302. // }
  4303. // #endregion 上料进站校验
  4304. // #region Tray盘上料装备-出站接口
  4305. // try
  4306. // {
  4307. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4308. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4309. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4310. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4311. // {
  4312. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4313. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4314. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4315. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4316. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4317. // }
  4318. // }
  4319. // catch (Exception ex)
  4320. // {
  4321. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4322. // string str = ex.StackTrace;
  4323. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4324. // }
  4325. // #endregion Tray盘上料装备-出站接口
  4326. // #region Tray盘上料装备-将SN发给ICT标机
  4327. // try
  4328. // {
  4329. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4330. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4331. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4332. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4333. // {
  4334. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4335. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4336. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4337. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4338. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4339. // }
  4340. // }
  4341. // catch (Exception ex)
  4342. // {
  4343. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4344. // string str = ex.StackTrace;
  4345. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4346. // }
  4347. // #endregion Tray盘上料装备-将SN发给ICT标机
  4348. // #region Tray盘上料装备-点检数据
  4349. // //try
  4350. // //{
  4351. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4352. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4353. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4354. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4355. // // if (pLC_Flag && !mES_Flag) // 1 0
  4356. // // {
  4357. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4358. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4359. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4360. // // }
  4361. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4362. // // {
  4363. // // // 清空写给PLC的数据
  4364. // // // MES_Flag重置为0
  4365. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4366. // // }
  4367. // //}
  4368. // //catch (Exception ex)
  4369. // //{
  4370. // // // MES_Flag 为2上位机报错
  4371. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4372. // // string str = ex.StackTrace;
  4373. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4374. // //}
  4375. // #endregion Tray盘上料装备-点检数据
  4376. // #region 节拍接口
  4377. // try
  4378. // {
  4379. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4380. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4381. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4382. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4383. // {
  4384. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4385. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4386. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4387. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4388. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4389. // }
  4390. // }
  4391. // catch (Exception ex)
  4392. // {
  4393. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4394. // string str = ex.StackTrace;
  4395. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4396. // }
  4397. // #endregion 节拍接口
  4398. // #region AGV上料
  4399. // // AGV上料叫AGV信号
  4400. // try
  4401. // {
  4402. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4403. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4404. // if (a1AGVUpCall != a1AGVUpCallOld)
  4405. // {
  4406. // if (a1AGVUpCall == 1) // 0->1
  4407. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4408. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4409. // }
  4410. // }
  4411. // catch (Exception ex)
  4412. // {
  4413. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4414. // string str = ex.StackTrace;
  4415. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4416. // }
  4417. // // AGV上料完成信号
  4418. // try
  4419. // {
  4420. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4421. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4422. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4423. // {
  4424. // if (a1AGVUpEnd == 1) // 0->1
  4425. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4426. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4427. // }
  4428. // }
  4429. // catch (Exception ex)
  4430. // {
  4431. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4432. // string str = ex.StackTrace;
  4433. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4434. // }
  4435. // #endregion AGV上料
  4436. // #region AGV下料
  4437. // // AGV下料叫agv信号
  4438. // try
  4439. // {
  4440. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4441. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4442. // if (a1AGVDownCall != a1AGVDownCallOld)
  4443. // {
  4444. // if (a1AGVDownCall == 1) // 0->1
  4445. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4446. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4447. // }
  4448. // }
  4449. // catch (Exception ex)
  4450. // {
  4451. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4452. // string str = ex.StackTrace;
  4453. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4454. // }
  4455. // // AGV下料完成信号
  4456. // try
  4457. // {
  4458. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4459. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4460. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4461. // {
  4462. // if (a1AGVDownEnd == 1) // 0->1
  4463. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4464. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4465. // }
  4466. // }
  4467. // catch (Exception ex)
  4468. // {
  4469. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4470. // string str = ex.StackTrace;
  4471. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4472. // }
  4473. // #endregion AGV下料
  4474. // #region 心跳
  4475. // try
  4476. // {
  4477. // short states = 0;
  4478. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4479. // }
  4480. // catch (Exception ex)
  4481. // {
  4482. // string str = ex.StackTrace;
  4483. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4484. // }
  4485. // #endregion 心跳
  4486. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4487. // stopwatch1.Stop();
  4488. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4489. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4490. // }
  4491. // else
  4492. // {
  4493. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4494. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4495. // Funs[plcNo].Connect(); // 重连
  4496. // }
  4497. // }
  4498. // catch (Exception ex)
  4499. // {
  4500. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4501. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4502. // Funs[plcNo].ReConnect();
  4503. // }
  4504. // Thread.Sleep(IntervalReadPLC);
  4505. // }
  4506. //}
  4507. /// <summary>
  4508. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4509. /// </summary>
  4510. /// <param name="plcNo">PLC编号</param>
  4511. /// <param name="stationNameStr">工站全称</param>
  4512. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4513. {
  4514. Stopwatch stopwatch1 = new Stopwatch();
  4515. Stopwatch stopwatch2 = new Stopwatch();
  4516. try
  4517. {
  4518. stopwatch1.Start();
  4519. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4520. sn = sn.Replace("\0", "");
  4521. #region 查询载具上的产品信息
  4522. string cavityData = string.Empty;
  4523. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4524. if (string.IsNullOrEmpty(cavityData))
  4525. cavityData = "";
  4526. if (snResult != 0)
  4527. {
  4528. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4529. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4530. writeToPLC_Flag1.Adress = 2003;
  4531. writeToPLC_Flag1.Value = (short)6;
  4532. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4533. stopwatch1.Stop();
  4534. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4535. return;
  4536. }
  4537. #endregion 查询载具上的产品信息
  4538. string[] cavitySNs = cavityData.Split('.');
  4539. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4540. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4541. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4542. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4543. if (cavitySNs != null && cavitySNs.Length >= 2)
  4544. {
  4545. a1CavitySN1_VehicleStates = cavitySNs[0];
  4546. a1CavitySN2_VehicleStates = cavitySNs[1];
  4547. a1CavityResult1_VehicleStates = 2;
  4548. a1CavityResult2_VehicleStates = 2;
  4549. }
  4550. if (a1CavitySN1_VehicleStates == "假产品")
  4551. a1CavityResult1_VehicleStates = 3;
  4552. if (a1CavitySN2_VehicleStates == "假产品")
  4553. a1CavityResult2_VehicleStates = 3;
  4554. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4555. // 回写
  4556. stopwatch2.Start();
  4557. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4558. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4559. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4560. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4561. //// MES_Flag
  4562. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4563. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4564. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4565. writeToPLC_Flag.Adress = 2003;
  4566. writeToPLC_Flag.Value = mES_Flag;
  4567. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4568. {
  4569. Name = "a1CavitySN1_VehicleStates",
  4570. Adress = 2024,
  4571. ValueType = PLCValueType.String,
  4572. ValueTypeStrLength = 20,
  4573. Value = a1CavitySN1_VehicleStates
  4574. });
  4575. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4576. {
  4577. Name = "a1CavitySN2_VehicleStates",
  4578. Adress = 2044,
  4579. ValueType = PLCValueType.String,
  4580. ValueTypeStrLength = 20,
  4581. Value = a1CavitySN2_VehicleStates
  4582. });
  4583. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4584. {
  4585. Name = "a1CavityResult1_VehicleStates",
  4586. Adress = 2064,
  4587. ValueType = PLCValueType.Short,
  4588. Value = a1CavityResult1_VehicleStates
  4589. });
  4590. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4591. {
  4592. Name = "a1CavityResult2_VehicleStates",
  4593. Adress = 2065,
  4594. ValueType = PLCValueType.Short,
  4595. Value = a1CavityResult2_VehicleStates
  4596. });
  4597. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4598. stopwatch2.Stop();
  4599. }
  4600. catch (Exception ex)
  4601. {
  4602. string str = ex.StackTrace;
  4603. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4604. // MES_Flag
  4605. stopwatch2.Start();
  4606. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4607. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4608. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4609. writeToPLC_Flag.Adress = 2003;
  4610. writeToPLC_Flag.Value = (short)6;
  4611. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4612. stopwatch2.Stop();
  4613. }
  4614. stopwatch1.Stop();
  4615. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4616. }
  4617. /// <summary>
  4618. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4619. /// </summary>
  4620. /// <param name="plcNo">PLC编号</param>
  4621. /// <param name="stationNameStr">工站全称</param>
  4622. private void S1上料进站校验(int plcNo, string stationNameStr)
  4623. {
  4624. Stopwatch stopwatch1 = new Stopwatch();
  4625. Stopwatch stopwatch2 = new Stopwatch();
  4626. try
  4627. {
  4628. stopwatch1.Start();
  4629. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4630. sn = sn.Replace("\0", "");
  4631. // 保存进站数据+调用进站MES接口
  4632. List<TestItem> item = new List<TestItem>();
  4633. stopwatch2.Start();
  4634. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4635. stopwatch2.Stop();
  4636. short a1MES_FLAG_Check = (short)result;
  4637. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4638. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4639. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4640. writeToPLC_Flag.Adress = 2077;
  4641. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4642. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4643. }
  4644. catch (Exception ex)
  4645. {
  4646. string str = ex.StackTrace;
  4647. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4648. // MES_Flag
  4649. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4650. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4651. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4652. writeToPLC_Flag.Adress = 2077;
  4653. writeToPLC_Flag.Value = (short)6;
  4654. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4655. }
  4656. stopwatch1.Stop();
  4657. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4658. }
  4659. /// <summary>
  4660. /// [S1] Tray盘上料装备(板测)- 出站接口
  4661. /// </summary>
  4662. /// <param name="plcNo"></param>
  4663. /// <param name="stationCode"></param>
  4664. /// <param name="stationName"></param>
  4665. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4666. {
  4667. Stopwatch stopwatch1 = new Stopwatch();
  4668. Stopwatch stopwatch2 = new Stopwatch();
  4669. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4670. string stationNameStr = stationCode + stationName;
  4671. string processItem = stationName; // 测试项目
  4672. try
  4673. {
  4674. stopwatch1.Start();
  4675. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4676. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4677. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4678. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4679. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4680. sn = sn.Replace("\0", "");
  4681. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4682. partNo1 = partNo1.Replace("\0", "");
  4683. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4684. partNo2 = partNo2.Replace("\0", "");
  4685. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4686. bool pass = a1Result == 1;
  4687. stopwatch2.Start();
  4688. // 产品1
  4689. List<TestItem> items = new List<TestItem>();
  4690. items.Add(new TestItem()
  4691. {
  4692. Parameter_name = "载具码",
  4693. Parameter_value = sn,
  4694. Parameter_unit = ""
  4695. });
  4696. items.Add(new TestItem()
  4697. {
  4698. Parameter_name = "载具穴号",
  4699. Parameter_value = "1",
  4700. Parameter_unit = ""
  4701. });
  4702. items.Add(new TestItem()
  4703. {
  4704. Parameter_name = "产品结果",
  4705. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4706. Parameter_unit = ""
  4707. });
  4708. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4709. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4710. // 产品2
  4711. items = new List<TestItem>();
  4712. items.Add(new TestItem()
  4713. {
  4714. Parameter_name = "载具码",
  4715. Parameter_value = sn,
  4716. Parameter_unit = ""
  4717. });
  4718. items.Add(new TestItem()
  4719. {
  4720. Parameter_name = "载具穴号",
  4721. Parameter_value = "2",
  4722. Parameter_unit = ""
  4723. });
  4724. items.Add(new TestItem()
  4725. {
  4726. Parameter_name = "产品结果",
  4727. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4728. Parameter_unit = ""
  4729. });
  4730. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4731. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4732. short result = 0;
  4733. List<int> results = new List<int>() { result1, result2 };
  4734. if (result1 == 1 && result2 == 1)
  4735. result = 1;
  4736. else if (results.Contains(3))
  4737. result = 3;
  4738. else if (results.Contains(2))
  4739. result = 2;
  4740. else if (results.Contains(4))
  4741. result = 4;
  4742. else
  4743. result = 4;
  4744. stopwatch2.Stop();
  4745. #region 存储绑定数据到 边线MES系统中
  4746. if (result == 1)
  4747. {
  4748. string data = string.Concat(partNo1, ".", partNo2);
  4749. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4750. if (resultMesR != 0)
  4751. {
  4752. result = 4;
  4753. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4754. }
  4755. }
  4756. #endregion 存储绑定数据到 边线MES系统中
  4757. // MES_Flag 为MES报错
  4758. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4759. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4760. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4761. writeToPLC_Flag.Name = "a1MES_FLAG";
  4762. writeToPLC_Flag.Adress = 2109;
  4763. writeToPLC_Flag.Value = result;
  4764. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4765. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4766. }
  4767. catch (Exception ex)
  4768. {
  4769. stopwatch2.Restart();
  4770. // MES_Flag 为4上位机报错
  4771. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4772. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4773. writeToPLC_Flag.Name = "a1MES_FLAG";
  4774. writeToPLC_Flag.Adress = 2109;
  4775. writeToPLC_Flag.Value = (short)4;
  4776. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4777. stopwatch2.Stop();
  4778. string str = ex.StackTrace;
  4779. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4780. }
  4781. stopwatch1.Stop();
  4782. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4783. }
  4784. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4785. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4786. //{
  4787. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4788. // string stationNameStr = stationCode + stationName;
  4789. // string processItem = stationName; // 测试项目
  4790. // try
  4791. // {
  4792. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4793. // string accno = "1"; // 工序编号
  4794. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4795. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4796. // List<OneCheckItem> items = new List<OneCheckItem>()
  4797. // {
  4798. // new OneCheckItem()
  4799. // {
  4800. // Onecheck_name="胶圈装配行程设定上限",
  4801. // Onecheck_content="上限值",
  4802. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4803. // },
  4804. // };
  4805. // OneCheckData oneCheckData = new OneCheckData()
  4806. // {
  4807. // Line_code = GlobalContext.LineCode,
  4808. // Line_name = GlobalContext.LineName,
  4809. // Equipment_code = equipmentCode,
  4810. // Equipment_name = equipmentCode,
  4811. // Workorder_code = workorder_code,
  4812. // Procedure_code = accno,
  4813. // Procedure_name = processItem,
  4814. // Oneckeck_values = items,
  4815. // Onecheck_empcode = "",
  4816. // Onecheck_empname = "",
  4817. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4818. // };
  4819. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4820. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4821. // short result = result1 == 1 ? (short)1 : (short)2;
  4822. // // MES_Flag 为4MES报错
  4823. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4824. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4825. // }
  4826. // catch (Exception ex)
  4827. // {
  4828. // // MES_Flag 为2上位机报错
  4829. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4830. // string str = ex.StackTrace;
  4831. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4832. // }
  4833. //}
  4834. // ReadStation_S1_2 节拍接口+AGV
  4835. /// <summary>
  4836. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4837. /// </summary>
  4838. /// <param name="plcNo">PLC编号</param>
  4839. /// <param name="stationNameStr">工站全称</param>
  4840. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4841. {
  4842. Stopwatch stopwatch1 = new Stopwatch();
  4843. Stopwatch stopwatch2 = new Stopwatch();
  4844. try
  4845. {
  4846. stopwatch1.Start();
  4847. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4848. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4849. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4850. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4851. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4852. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4853. // ZS 将SN发给ICT标机(串口)
  4854. short a1MES_FLAG_ICT = 1;
  4855. stopwatch2.Start();
  4856. // MES_Flag
  4857. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4858. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4859. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4860. writeToPLC_Flag.Adress = 2182;
  4861. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4862. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4863. stopwatch2.Stop();
  4864. }
  4865. catch (Exception ex)
  4866. {
  4867. string str = ex.StackTrace;
  4868. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4869. stopwatch2.Start();
  4870. // MES_Flag
  4871. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4872. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4873. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4874. writeToPLC_Flag.Adress = 2182;
  4875. writeToPLC_Flag.Value = (short)4;
  4876. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4877. stopwatch2.Stop();
  4878. }
  4879. stopwatch1.Stop();
  4880. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4881. }
  4882. /// <summary>
  4883. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4884. /// </summary>
  4885. /// <param name="plcNo">PLC编号</param>
  4886. /// <param name="stationNameStr">工站全称</param>
  4887. private void S1节拍接口(int plcNo, string stationNameStr)
  4888. {
  4889. Stopwatch stopwatch1 = new Stopwatch();
  4890. Stopwatch stopwatch2 = new Stopwatch();
  4891. string resultStr = string.Empty;
  4892. try
  4893. {
  4894. stopwatch1.Start();
  4895. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4896. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4897. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4898. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4899. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4900. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4901. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  4902. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4903. if (!actionBool)
  4904. {
  4905. stopwatch2.Start();
  4906. // MES_Flag
  4907. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4908. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4909. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  4910. writeToPLC_Flag1.Adress = 2254;
  4911. writeToPLC_Flag1.Value = (short)1;
  4912. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  4913. stopwatch2.Stop();
  4914. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4915. return;
  4916. }
  4917. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  4918. {
  4919. stopwatch2.Start();
  4920. // MES_Flag
  4921. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4922. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  4923. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  4924. writeToPLC_Flag2.Adress = 2254;
  4925. writeToPLC_Flag2.Value = (short)1;
  4926. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  4927. stopwatch2.Stop();
  4928. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4929. return;
  4930. }
  4931. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  4932. { // 查产品SN
  4933. a1OEEPartNo = "Test"; // ZS
  4934. }
  4935. short a1OEEMES_FLAG = 0;
  4936. // 上传OEE
  4937. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  4938. a1OEEMES_FLAG = result.Item1;
  4939. resultStr = result.Item2;
  4940. stopwatch2.Start();
  4941. // MES_Flag
  4942. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4943. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4944. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4945. writeToPLC_Flag.Adress = 2254;
  4946. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  4947. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4948. stopwatch2.Stop();
  4949. }
  4950. catch (Exception ex)
  4951. {
  4952. string str = ex.StackTrace;
  4953. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4954. // MES_Flag
  4955. stopwatch2.Start();
  4956. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4957. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4958. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4959. writeToPLC_Flag.Adress = 2254;
  4960. writeToPLC_Flag.Value = (short)4;
  4961. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4962. stopwatch2.Stop();
  4963. }
  4964. stopwatch1.Stop();
  4965. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4966. }
  4967. /// <summary>
  4968. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  4969. /// </summary>
  4970. /// <param name="plcNo">PLC编号</param>
  4971. /// <param name="stationNameStr">工站全称</param>
  4972. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  4973. {
  4974. Stopwatch stopwatch1 = new Stopwatch();
  4975. Stopwatch stopwatch2 = new Stopwatch();
  4976. try
  4977. {
  4978. stopwatch1.Start();
  4979. // ZS 呼叫AGV
  4980. short a1AGVUpCall = 2;
  4981. stopwatch2.Start();
  4982. // a1AGVUpCall
  4983. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4984. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4985. writeToPLC_Flag.Name = "a1AGVUpCall";
  4986. writeToPLC_Flag.Adress = 2307;
  4987. writeToPLC_Flag.Value = a1AGVUpCall;
  4988. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4989. stopwatch2.Stop();
  4990. }
  4991. catch (Exception ex)
  4992. {
  4993. string str = ex.StackTrace;
  4994. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4995. // a1AGVUpCall
  4996. stopwatch2.Start();
  4997. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4998. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4999. writeToPLC_Flag.Name = "a1AGVUpCall";
  5000. writeToPLC_Flag.Adress = 2307;
  5001. writeToPLC_Flag.Value = (short)4;
  5002. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5003. stopwatch2.Stop();
  5004. }
  5005. stopwatch1.Stop();
  5006. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5007. }
  5008. /// <summary>
  5009. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  5010. /// </summary>
  5011. /// <param name="plcNo">PLC编号</param>
  5012. /// <param name="stationNameStr">工站全称</param>
  5013. private void S1AGV上料完成(int plcNo, string stationNameStr)
  5014. {
  5015. Stopwatch stopwatch1 = new Stopwatch();
  5016. Stopwatch stopwatch2 = new Stopwatch();
  5017. try
  5018. {
  5019. stopwatch1.Start();
  5020. // ZS AGV上料完成,让小车离开
  5021. short a1AGVUpEnd = 2;
  5022. stopwatch2.Start();
  5023. // a1AGVUpEnd
  5024. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5025. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5026. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5027. writeToPLC_Flag.Adress = 2309;
  5028. writeToPLC_Flag.Value = a1AGVUpEnd;
  5029. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5030. stopwatch2.Stop();
  5031. }
  5032. catch (Exception ex)
  5033. {
  5034. string str = ex.StackTrace;
  5035. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5036. // a1AGVUpEnd
  5037. stopwatch2.Start();
  5038. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  5039. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5040. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5041. writeToPLC_Flag.Adress = 2309;
  5042. writeToPLC_Flag.Value = (short)4;
  5043. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5044. stopwatch2.Stop();
  5045. }
  5046. stopwatch1.Stop();
  5047. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5048. }
  5049. /// <summary>
  5050. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  5051. /// </summary>
  5052. /// <param name="plcNo">PLC编号</param>
  5053. /// <param name="stationNameStr">工站全称</param>
  5054. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  5055. {
  5056. Stopwatch stopwatch1 = new Stopwatch();
  5057. Stopwatch stopwatch2 = new Stopwatch();
  5058. try
  5059. {
  5060. stopwatch1.Start();
  5061. // ZS 呼叫AGV
  5062. short a1AGVDownCall = 2;
  5063. stopwatch2.Start();
  5064. // a1AGVDownCall
  5065. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5066. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5067. writeToPLC_Flag.Name = "a1AGVDownCall";
  5068. writeToPLC_Flag.Adress = 2320;
  5069. writeToPLC_Flag.Value = a1AGVDownCall;
  5070. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5071. stopwatch2.Stop();
  5072. }
  5073. catch (Exception ex)
  5074. {
  5075. string str = ex.StackTrace;
  5076. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5077. // a1AGVDownCall
  5078. stopwatch2.Start();
  5079. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5080. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5081. writeToPLC_Flag.Name = "a1AGVDownCall";
  5082. writeToPLC_Flag.Adress = 2320;
  5083. writeToPLC_Flag.Value = (short)4;
  5084. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5085. stopwatch2.Stop();
  5086. }
  5087. stopwatch1.Stop();
  5088. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5089. }
  5090. /// <summary>
  5091. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5092. /// </summary>
  5093. /// <param name="plcNo">PLC编号</param>
  5094. /// <param name="stationNameStr">工站全称</param>
  5095. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5096. {
  5097. Stopwatch stopwatch1 = new Stopwatch();
  5098. Stopwatch stopwatch2 = new Stopwatch();
  5099. try
  5100. {
  5101. stopwatch1.Start();
  5102. // ZS AGV上料完成,让小车离开
  5103. short a1AGVDownEnd = 2;
  5104. stopwatch2.Start();
  5105. // a1AGVDownEnd
  5106. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5107. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5108. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5109. writeToPLC_Flag.Adress = 2322;
  5110. writeToPLC_Flag.Value = a1AGVDownEnd;
  5111. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5112. stopwatch2.Stop();
  5113. }
  5114. catch (Exception ex)
  5115. {
  5116. string str = ex.StackTrace;
  5117. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5118. // a1AGVDownEnd
  5119. stopwatch2.Start();
  5120. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5121. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5122. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5123. writeToPLC_Flag.Adress = 2322;
  5124. writeToPLC_Flag.Value = (short)4;
  5125. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5126. stopwatch2.Stop();
  5127. }
  5128. stopwatch1.Stop();
  5129. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5130. }
  5131. #endregion [S1] Tray盘上料装备(板测)
  5132. #endregion PLC1 张超凡
  5133. #region PLC2 李晓奇
  5134. #region [S2] FCT(板测)
  5135. /// <summary>
  5136. /// S2工位的数据- 触发信号上次的值
  5137. /// </summary>
  5138. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5139. /// <summary>
  5140. /// S2工位的数据(含触发信号)
  5141. /// </summary>
  5142. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5143. /// <summary>
  5144. /// S2工位的数据- 回写点位
  5145. /// </summary>
  5146. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5147. /// <summary>
  5148. /// [S2] FCT(板测)
  5149. /// </summary>
  5150. /// <param name="plcNo">PLC编号</param>
  5151. //private void ReadStation_S2(int plcNo)
  5152. //{
  5153. // // [S1] Tray盘上料装备
  5154. // // [S2] FCT
  5155. // // [S3] 值板机
  5156. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5157. // // [S5] Tray盘下料装备
  5158. // /// 上位机心跳
  5159. // /// 获取设备报警数据与状态信息
  5160. // string stationCode = "[S2]";
  5161. // string stationName = "FCT";
  5162. // string stationNameStr = stationCode + stationName;
  5163. // #region 创建字典
  5164. // // 触发信号字典 赋值
  5165. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5166. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5167. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5168. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5169. // // PLC数据字典 赋值
  5170. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5171. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5172. // s2PLCData.Add("b1ProductSN_Check", 0);
  5173. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5174. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5175. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5176. // s2PLCData.Add("b1ProductSN_Bind", "");
  5177. // s2PLCData.Add("b1Part1SN_Bind", "");
  5178. // s2PLCData.Add("b1Part2SN_Bind", "");
  5179. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5180. // s2PLCData.Add("b1MES_FLAG", 0);
  5181. // s2PLCData.Add("b1ProductSN", 0);
  5182. // s2PLCData.Add("b1Part1Result", 0);
  5183. // s2PLCData.Add("b1Part2Result", 0);
  5184. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5185. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5186. // s2PLCData.Add("b1OEEProductSN", "");
  5187. // s2PLCData.Add("b1OEEType", 0);
  5188. // #endregion 创建字典
  5189. // while (IsRun)
  5190. // {
  5191. // try
  5192. // {
  5193. // if (!GlobalContext._IsCon_Funs2)
  5194. // {
  5195. // UpdatePLCMonitor(1, plcNo, 0);
  5196. // continue;
  5197. // }
  5198. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5199. // {
  5200. // Stopwatch stopwatch1 = new Stopwatch();
  5201. // Stopwatch stopwatch2 = new Stopwatch();
  5202. // stopwatch1.Start();
  5203. // stopwatch2.Start();
  5204. // #region 一次性读取所有数据
  5205. // // 一次性读取所有数据
  5206. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5207. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5208. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5209. // int[] datas = data1.Concat(data2).ToArray();
  5210. // datas = datas.Concat(data3).ToArray();
  5211. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5212. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5213. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5214. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5215. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5216. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5217. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5218. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5219. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5220. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5221. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5222. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5223. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5224. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5225. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5226. // s2PLCData["b1MES_FLAG"] = datas[169];
  5227. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5228. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5229. // s2PLCData["b1Part1Result"] = datas[190];
  5230. // s2PLCData["b1Part2Result"] = datas[191];
  5231. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5232. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5233. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5234. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5235. // s2PLCData["b1OEEType"] = datas[224];
  5236. // #endregion 一次性读取所有数据
  5237. // stopwatch2.Stop();
  5238. // #region 回写操作,写后清空flag
  5239. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5240. // #endregion 回写操作,写后清空flag
  5241. // #region 进站校验
  5242. // try
  5243. // {
  5244. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5245. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5246. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5247. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5248. // {
  5249. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5250. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5251. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5252. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5253. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5254. // }
  5255. // }
  5256. // catch (Exception ex)
  5257. // {
  5258. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5259. // string str = ex.StackTrace;
  5260. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5261. // }
  5262. // #endregion 进站校验
  5263. // #region 二穴载具解绑/绑定(产品换载具)
  5264. // try
  5265. // {
  5266. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5267. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5268. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5269. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5270. // {
  5271. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5272. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5273. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5274. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5275. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5276. // }
  5277. // }
  5278. // catch (Exception ex)
  5279. // {
  5280. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5281. // string str = ex.StackTrace;
  5282. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5283. // }
  5284. // #endregion 二穴载具解绑/绑定(产品换载具)
  5285. // #region FCT-出站接口
  5286. // try
  5287. // {
  5288. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5289. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5290. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5291. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5292. // {
  5293. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5294. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5295. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5296. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5297. // }
  5298. // }
  5299. // catch (Exception ex)
  5300. // {
  5301. // // MES_Flag 为6上位机报错
  5302. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5303. // string str = ex.StackTrace;
  5304. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5305. // }
  5306. // #endregion FCT-出站接口
  5307. // #region 节拍接口
  5308. // try
  5309. // {
  5310. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5311. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5312. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5313. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5314. // {
  5315. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5316. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5317. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5318. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5319. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5320. // }
  5321. // }
  5322. // catch (Exception ex)
  5323. // {
  5324. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5325. // string str = ex.StackTrace;
  5326. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5327. // }
  5328. // #endregion 节拍接口
  5329. // #region 心跳
  5330. // try
  5331. // {
  5332. // short states = 0;
  5333. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5334. // }
  5335. // catch (Exception ex)
  5336. // {
  5337. // string str = ex.StackTrace;
  5338. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5339. // }
  5340. // #endregion 心跳
  5341. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5342. // stopwatch1.Stop();
  5343. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5344. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5345. // }
  5346. // else
  5347. // {
  5348. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5349. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5350. // Funs[plcNo].Connect();
  5351. // }
  5352. // }
  5353. // catch (Exception ex)
  5354. // {
  5355. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5356. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5357. // Funs[plcNo].ReConnect();
  5358. // }
  5359. // Thread.Sleep(IntervalReadPLC);
  5360. // }
  5361. //}
  5362. /// <summary>
  5363. /// [S2] FCT(板测)- 进站校验
  5364. /// </summary>
  5365. /// <param name="plcNo">PLC编号</param>
  5366. /// <param name="stationNameStr">工站全称</param>
  5367. private void S2进站校验(int plcNo, string stationNameStr)
  5368. {
  5369. Stopwatch stopwatch1 = new Stopwatch();
  5370. Stopwatch stopwatch2 = new Stopwatch();
  5371. try
  5372. {
  5373. stopwatch1.Start();
  5374. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5375. sn = sn.Replace("\0", "");
  5376. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5377. // 查询物料码By载具码 并判断是不是假产品
  5378. string cavityData = string.Empty;
  5379. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5380. if (string.IsNullOrEmpty(cavityData))
  5381. cavityData = "";
  5382. if (snResult != 0)
  5383. {
  5384. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5385. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5386. writeToPLC_Flag1.Adress = 2003;
  5387. writeToPLC_Flag1.Value = (short)6;
  5388. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5389. stopwatch1.Stop();
  5390. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5391. return;
  5392. }
  5393. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5394. string[] cavitySNs = cavityData.Split('.');
  5395. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5396. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5397. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5398. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5399. if (cavitySNs != null && cavitySNs.Length >= 2)
  5400. {
  5401. b1Part1SN_Check = cavitySNs[0];
  5402. b1Part2SN_Check = cavitySNs[1];
  5403. b1Part1Result_Check = 2;
  5404. b1Part2Result_Check = 2;
  5405. }
  5406. if (b1Part1SN_Check == "假产品")
  5407. b1Part1Result_Check = 3;
  5408. if (b1Part2SN_Check == "假产品")
  5409. b1Part2Result_Check = 3;
  5410. // 调用MES进站
  5411. stopwatch2.Start();
  5412. // 调用MES进站 - 产品1
  5413. List<TestItem> item;
  5414. int result1 = b1Part1Result_Check;
  5415. if (result1 != 3)
  5416. {
  5417. item = new List<TestItem>();
  5418. item.Add(new TestItem()
  5419. {
  5420. Parameter_name = "载具码",
  5421. Parameter_value = sn,
  5422. });
  5423. item.Add(new TestItem()
  5424. {
  5425. Parameter_name = "载具穴号",
  5426. Parameter_value = "1",
  5427. });
  5428. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5429. }
  5430. // 调用MES进站 - 产品2
  5431. int result2 = b1Part2Result_Check;
  5432. if (result2 != 3)
  5433. {
  5434. item = new List<TestItem>();
  5435. item.Add(new TestItem()
  5436. {
  5437. Parameter_name = "载具码",
  5438. Parameter_value = sn,
  5439. });
  5440. item.Add(new TestItem()
  5441. {
  5442. Parameter_name = "载具穴号",
  5443. Parameter_value = "2",
  5444. });
  5445. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5446. }
  5447. stopwatch2.Stop();
  5448. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5449. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5450. int result = result1;
  5451. if (result == 1)
  5452. result = result2;
  5453. short b1MES_FLAG_Check = (short)result;
  5454. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5455. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5456. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5457. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5458. //// MES_Flag
  5459. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5460. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5461. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5462. writeToPLC_Flag.Adress = 2003;
  5463. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5464. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5465. {
  5466. Name = "b1Part1SN_Check",
  5467. Adress = 2024,
  5468. ValueType = PLCValueType.String,
  5469. ValueTypeStrLength = 20,
  5470. Value = b1Part1SN_Check
  5471. });
  5472. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5473. {
  5474. Name = "b1Part2SN_Check",
  5475. Adress = 2044,
  5476. ValueType = PLCValueType.String,
  5477. ValueTypeStrLength = 20,
  5478. Value = b1Part2SN_Check
  5479. });
  5480. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5481. {
  5482. Name = "b1Part1Result_Check",
  5483. Adress = 2064,
  5484. ValueType = PLCValueType.Short,
  5485. Value = b1Part1Result_Check
  5486. });
  5487. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5488. {
  5489. Name = "b1Part2Result_Check",
  5490. Adress = 2065,
  5491. ValueType = PLCValueType.Short,
  5492. Value = b1Part2Result_Check
  5493. });
  5494. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5495. }
  5496. catch (Exception ex)
  5497. {
  5498. string str = ex.StackTrace;
  5499. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5500. // MES_Flag
  5501. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5502. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5503. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5504. writeToPLC_Flag.Adress = 2003;
  5505. writeToPLC_Flag.Value = (short)6;
  5506. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5507. }
  5508. stopwatch1.Stop();
  5509. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5510. }
  5511. /// <summary>
  5512. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5513. /// </summary>
  5514. /// <param name="plcNo">PLC编号</param>
  5515. /// <param name="stationNameStr">工站全称</param>
  5516. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5517. {
  5518. Stopwatch stopwatch1 = new Stopwatch();
  5519. Stopwatch stopwatch2 = new Stopwatch();
  5520. try
  5521. {
  5522. stopwatch1.Start();
  5523. // 产品换载具
  5524. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5525. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5526. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5527. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5528. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5529. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5530. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5531. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5532. stopwatch2.Start();
  5533. #region 查询载具上的产品信息
  5534. //string cavityData = string.Empty;
  5535. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5536. //if (string.IsNullOrEmpty(cavityData))
  5537. // cavityData = "";
  5538. //if (snResult != 0)
  5539. //{
  5540. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5541. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5542. // writeToPLC_Flag.Adress = 2077;
  5543. // writeToPLC_Flag.Value = (short)6;
  5544. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5545. // stopwatch1.Stop();
  5546. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5547. // return;
  5548. //}
  5549. #endregion 查询载具上的产品信息
  5550. #region 解绑(边线MES系统)
  5551. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5552. if (snResult != 0)
  5553. {
  5554. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5555. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5556. writeToPLC_Flag1.Adress = 2077;
  5557. writeToPLC_Flag1.Value = (short)6;
  5558. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5559. stopwatch1.Stop();
  5560. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5561. return;
  5562. }
  5563. #endregion 解绑(边线MES系统)
  5564. #region 存储绑定数据到 边线MES系统中
  5565. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5566. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5567. if (snResult != 0)
  5568. {
  5569. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5570. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5571. writeToPLC_Flag1.Adress = 2077;
  5572. writeToPLC_Flag1.Value = (short)6;
  5573. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5574. stopwatch1.Stop();
  5575. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5576. return;
  5577. }
  5578. #endregion 存储绑定数据到 边线MES系统中
  5579. stopwatch2.Stop();
  5580. short b1MES_FLAG_Unbind = 1;
  5581. // MES_Flag
  5582. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5583. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5584. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5585. writeToPLC_Flag.Adress = 2077;
  5586. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5587. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5588. }
  5589. catch (Exception ex)
  5590. {
  5591. string str = ex.StackTrace;
  5592. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5593. // MES_Flag
  5594. stopwatch2.Start();
  5595. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5596. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5597. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5598. writeToPLC_Flag.Adress = 2077;
  5599. writeToPLC_Flag.Value = (short)6;
  5600. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5601. stopwatch2.Stop();
  5602. }
  5603. stopwatch1.Stop();
  5604. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5605. }
  5606. //// 上次采集到的SN
  5607. //private string sn_FCT = string.Empty;
  5608. /// <summary>
  5609. /// [S2] FCT(板测)- 出站数据
  5610. /// </summary>
  5611. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5612. {
  5613. Stopwatch stopwatch1 = new Stopwatch();
  5614. Stopwatch stopwatch2 = new Stopwatch();
  5615. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5616. string stationNameStr = stationCode + stationName;
  5617. string processItem = stationName; // 测试项目
  5618. try
  5619. {
  5620. stopwatch1.Start();
  5621. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5622. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5623. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5624. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5625. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5626. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5627. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5628. bool pass1 = b1Part1Result == 1;
  5629. bool pass2 = b1Part2Result == 1;
  5630. #region 根据 载具SN 查 物料SN
  5631. string cavityData = string.Empty;
  5632. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5633. if (string.IsNullOrEmpty(cavityData))
  5634. cavityData = "";
  5635. if (snResult != 0)
  5636. {
  5637. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5638. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5639. writeToPLC_Flag1.Adress = 2169;
  5640. writeToPLC_Flag1.Value = (short)4;
  5641. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5642. stopwatch1.Stop();
  5643. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5644. return;
  5645. }
  5646. #endregion 根据 载具SN 查 物料SN
  5647. string[] cavitySNs = cavityData.Split('.');
  5648. string b1ProductSN1 = string.Empty;
  5649. string b1ProductSN2 = string.Empty;
  5650. if (cavitySNs != null && cavitySNs.Length >= 2)
  5651. {
  5652. b1ProductSN1 = cavitySNs[0];
  5653. b1ProductSN2 = cavitySNs[1];
  5654. }
  5655. stopwatch2.Start();
  5656. // 产品1
  5657. int result1 = 0;
  5658. if (b1ProductSN1 == "假产品")
  5659. result1 = 1;
  5660. else
  5661. {
  5662. List<TestItem> items1 = new List<TestItem>();
  5663. items1.Add(new TestItem()
  5664. {
  5665. Parameter_name = "载具码",
  5666. Parameter_value = b1ProductSN.ToString(),
  5667. Parameter_unit = ""
  5668. });
  5669. items1.Add(new TestItem()
  5670. {
  5671. Parameter_name = "载具穴号",
  5672. Parameter_value = "1",
  5673. Parameter_unit = ""
  5674. });
  5675. items1.Add(new TestItem()
  5676. {
  5677. Parameter_name = "产品结果",
  5678. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5679. Parameter_unit = ""
  5680. });
  5681. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5682. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5683. }
  5684. // 产品2
  5685. int result2 = 0;
  5686. if (b1ProductSN1 == "假产品")
  5687. result2 = 1;
  5688. else
  5689. {
  5690. List<TestItem> items2 = new List<TestItem>();
  5691. items2.Add(new TestItem()
  5692. {
  5693. Parameter_name = "载具码",
  5694. Parameter_value = b1ProductSN.ToString(),
  5695. Parameter_unit = ""
  5696. });
  5697. items2.Add(new TestItem()
  5698. {
  5699. Parameter_name = "载具穴号",
  5700. Parameter_value = "2",
  5701. Parameter_unit = ""
  5702. });
  5703. items2.Add(new TestItem()
  5704. {
  5705. Parameter_name = "产品结果",
  5706. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5707. Parameter_unit = ""
  5708. });
  5709. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5710. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5711. }
  5712. short result = 0;
  5713. List<int> results = new List<int>() { result1, result2 };
  5714. if (result1 == 1 && result2 == 1)
  5715. result = 1;
  5716. else if (results.Contains(3))
  5717. result = 3;
  5718. else if (results.Contains(2))
  5719. result = 2;
  5720. else if (results.Contains(4))
  5721. result = 4;
  5722. else
  5723. result = 4;
  5724. stopwatch2.Stop();
  5725. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5726. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5727. writeToPLC_Flag.Name = "b1MES_FLAG";
  5728. writeToPLC_Flag.Adress = 2169;
  5729. writeToPLC_Flag.Value = result;
  5730. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5731. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5732. }
  5733. catch (Exception ex)
  5734. {
  5735. stopwatch2.Restart();
  5736. // MES_Flag 为4上位机报错
  5737. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5738. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5739. writeToPLC_Flag.Name = "b1MES_FLAG";
  5740. writeToPLC_Flag.Adress = 2169;
  5741. writeToPLC_Flag.Value = (short)4;
  5742. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5743. stopwatch2.Stop();
  5744. string str = ex.StackTrace;
  5745. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5746. }
  5747. stopwatch1.Stop();
  5748. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5749. }
  5750. /// <summary>
  5751. /// [S2] FCT(板测)- 节拍接口
  5752. /// </summary>
  5753. /// <param name="plcNo">PLC编号</param>
  5754. /// <param name="stationNameStr">工站全称</param>
  5755. private void S2节拍接口(int plcNo, string stationNameStr)
  5756. {
  5757. Stopwatch stopwatch1 = new Stopwatch();
  5758. Stopwatch stopwatch2 = new Stopwatch();
  5759. string resultStr = string.Empty;
  5760. try
  5761. {
  5762. stopwatch1.Start();
  5763. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5764. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5765. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5766. if (!actionBool)
  5767. {
  5768. stopwatch2.Start();
  5769. // MES_Flag
  5770. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5771. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5772. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5773. writeToPLC_Flag1.Adress = 2203;
  5774. writeToPLC_Flag1.Value = (short)4;
  5775. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5776. stopwatch2.Stop();
  5777. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5778. return;
  5779. }
  5780. string b1OEEPartNo = string.Empty; // 物料码
  5781. if (string.IsNullOrEmpty(b1OEEProductSN))
  5782. {
  5783. stopwatch2.Start();
  5784. // MES_Flag
  5785. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5786. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5787. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5788. writeToPLC_Flag1.Adress = 2203;
  5789. writeToPLC_Flag1.Value = (short)1;
  5790. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5791. stopwatch2.Stop();
  5792. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5793. return;
  5794. }
  5795. else
  5796. { // 查产品SN
  5797. b1OEEPartNo = "Test"; // ZS
  5798. }
  5799. short b1OEEMES_FLAG = 0;
  5800. // 上传OEE
  5801. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5802. b1OEEMES_FLAG = result.Item1;
  5803. resultStr = result.Item2;
  5804. stopwatch2.Start();
  5805. // MES_Flag
  5806. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5807. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5808. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5809. writeToPLC_Flag.Adress = 2203;
  5810. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5811. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5812. stopwatch2.Stop();
  5813. }
  5814. catch (Exception ex)
  5815. {
  5816. string str = ex.StackTrace;
  5817. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5818. // MES_Flag
  5819. stopwatch2.Start();
  5820. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5821. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5822. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5823. writeToPLC_Flag.Adress = 2203;
  5824. writeToPLC_Flag.Value = (short)4;
  5825. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5826. stopwatch2.Stop();
  5827. }
  5828. stopwatch1.Stop();
  5829. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5830. }
  5831. #endregion [S2] FCT(板测)
  5832. #endregion PLC2 李晓奇
  5833. #region PLC3 刘永村
  5834. #region [S3] 值板机
  5835. /// <summary>
  5836. /// S3工位的数据- 触发信号上次的值
  5837. /// </summary>
  5838. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5839. /// <summary>
  5840. /// S3工位的数据(含触发信号)
  5841. /// </summary>
  5842. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5843. /// <summary>
  5844. /// S3工位的数据- 回写点位
  5845. /// </summary>
  5846. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5847. /// <summary>
  5848. /// [S3] 值板机
  5849. /// </summary>
  5850. /// <param name="plcNo">PLC编号</param>
  5851. //private void ReadStation_S3(int plcNo)
  5852. //{
  5853. // // [S1] Tray盘上料装备
  5854. // // [S2] FCT
  5855. // // [S3] 值板机
  5856. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5857. // // [S5] Tray盘下料装备
  5858. // /// 上位机心跳
  5859. // /// 获取设备报警数据与状态信息
  5860. // string stationCode = "[S3]";
  5861. // string stationName = "值板机";
  5862. // string stationNameStr = stationCode + stationName;
  5863. // #region 创建字典
  5864. // // 触发信号字典 赋值
  5865. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5866. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5867. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5868. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5869. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5870. // // PLC数据字典 赋值
  5871. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5872. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5873. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5874. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5875. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5876. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5877. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5878. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5879. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5880. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5881. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5882. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5883. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5884. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5885. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5886. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5887. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5888. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5889. // s3PLCData.Add("c1Result", 0); // 产品结果
  5890. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5891. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5892. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5893. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  5894. // #endregion 创建字典
  5895. // while (IsRun)
  5896. // {
  5897. // try
  5898. // {
  5899. // if (!GlobalContext._IsCon_Funs3)
  5900. // {
  5901. // UpdatePLCMonitor(1, plcNo, 0);
  5902. // continue;
  5903. // }
  5904. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5905. // {
  5906. // Stopwatch stopwatch1 = new Stopwatch();
  5907. // Stopwatch stopwatch2 = new Stopwatch();
  5908. // stopwatch1.Start();
  5909. // stopwatch2.Start();
  5910. // #region 一次性读取所有数据
  5911. // // 一次性读取所有数据
  5912. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  5913. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  5914. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  5915. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  5916. // int[] datas = data1.Concat(data2).ToArray();
  5917. // datas = datas.Concat(data3).ToArray();
  5918. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  5919. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  5920. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5921. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  5922. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  5923. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  5924. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5925. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  5926. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  5927. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  5928. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  5929. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5930. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  5931. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  5932. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  5933. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  5934. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5935. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  5936. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  5937. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  5938. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  5939. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  5940. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  5941. // #endregion 一次性读取所有数据
  5942. // stopwatch2.Stop();
  5943. // #region 回写操作,写后清空flag
  5944. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  5945. // #endregion 回写操作,写后清空flag
  5946. // #region S3进站校验
  5947. // try
  5948. // {
  5949. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  5950. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  5951. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  5952. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  5953. // {
  5954. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  5955. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5956. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  5957. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5958. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  5959. // }
  5960. // }
  5961. // catch (Exception ex)
  5962. // {
  5963. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5964. // string str = ex.StackTrace;
  5965. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5966. // }
  5967. // #endregion S3进站校验
  5968. // #region S3二穴载具解绑
  5969. // try
  5970. // {
  5971. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  5972. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  5973. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  5974. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  5975. // {
  5976. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5977. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  5978. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  5979. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  5980. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  5981. // }
  5982. // }
  5983. // catch (Exception ex)
  5984. // {
  5985. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  5986. // string str = ex.StackTrace;
  5987. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5988. // }
  5989. // #endregion S3二穴载具解绑
  5990. // #region S3二穴载具绑定
  5991. // try
  5992. // {
  5993. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  5994. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  5995. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  5996. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  5997. // {
  5998. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5999. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  6000. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  6001. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  6002. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  6003. // }
  6004. // }
  6005. // catch (Exception ex)
  6006. // {
  6007. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6008. // string str = ex.StackTrace;
  6009. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6010. // }
  6011. // #endregion S3二穴载具绑定
  6012. // #region S3出站接口(+一穴载具绑定)
  6013. // try
  6014. // {
  6015. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  6016. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  6017. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  6018. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  6019. // {
  6020. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  6021. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6022. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  6023. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  6024. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  6025. // }
  6026. // }
  6027. // catch (Exception ex)
  6028. // {
  6029. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  6030. // string str = ex.StackTrace;
  6031. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6032. // }
  6033. // #endregion S3出站接口(+一穴载具绑定)
  6034. // #region S3节拍接口
  6035. // try
  6036. // {
  6037. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  6038. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  6039. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  6040. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  6041. // {
  6042. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  6043. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6044. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  6045. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  6046. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  6047. // }
  6048. // }
  6049. // catch (Exception ex)
  6050. // {
  6051. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6052. // string str = ex.StackTrace;
  6053. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6054. // }
  6055. // #endregion S3节拍接口
  6056. // #region 心跳
  6057. // try
  6058. // {
  6059. // short states = 0;
  6060. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6061. // }
  6062. // catch (Exception ex)
  6063. // {
  6064. // string str = ex.StackTrace;
  6065. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6066. // }
  6067. // #endregion 心跳
  6068. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6069. // stopwatch1.Stop();
  6070. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6071. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6072. // }
  6073. // else
  6074. // {
  6075. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6076. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6077. // Funs[plcNo].Connect();
  6078. // }
  6079. // }
  6080. // catch (Exception ex)
  6081. // {
  6082. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6083. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6084. // Funs[plcNo].ReConnect();
  6085. // }
  6086. // Thread.Sleep(IntervalReadPLC);
  6087. // }
  6088. //}
  6089. /// <summary>
  6090. /// [S3] 值板机- 进站校验
  6091. /// </summary>
  6092. /// <param name="plcNo">PLC编号</param>
  6093. /// <param name="stationNameStr">工站全称</param>
  6094. private void S3进站校验(int plcNo, string stationNameStr)
  6095. {
  6096. Stopwatch stopwatch1 = new Stopwatch();
  6097. Stopwatch stopwatch2 = new Stopwatch();
  6098. try
  6099. {
  6100. stopwatch1.Start();
  6101. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6102. sn = sn.Replace("\0", "");
  6103. #region 查询载具上的产品信息
  6104. string cavityData = string.Empty;
  6105. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6106. if (string.IsNullOrEmpty(cavityData))
  6107. cavityData = "";
  6108. if (snResult != 0)
  6109. {
  6110. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6111. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6112. writeToPLC_Flag1.Adress = 2003;
  6113. writeToPLC_Flag1.Value = (short)6;
  6114. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6115. stopwatch1.Stop();
  6116. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6117. return;
  6118. }
  6119. #endregion 查询载具上的产品信息
  6120. string[] cavitySNs = cavityData.Split('.');
  6121. string part1Str = ""; // 产品1的SN码
  6122. string part2Str = ""; // 产品2的SN码
  6123. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6124. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6125. if (cavitySNs != null && cavitySNs.Length >= 2)
  6126. {
  6127. part1Str = cavitySNs[0];
  6128. part2Str = cavitySNs[1];
  6129. c1Part1Result_Check = 2;
  6130. c1Part2Result_Check = 2;
  6131. }
  6132. if (part1Str == "假产品")
  6133. c1Part1Result_Check = 3;
  6134. if (part2Str == "假产品")
  6135. c1Part2Result_Check = 3;
  6136. // 调用MES进站
  6137. stopwatch2.Start();
  6138. // 调用MES进站 - 产品1
  6139. List<TestItem> item;
  6140. int result1 = c1Part1Result_Check;
  6141. if (result1 != 3)
  6142. {
  6143. item = new List<TestItem>();
  6144. item.Add(new TestItem()
  6145. {
  6146. Parameter_name = "载具码",
  6147. Parameter_value = sn,
  6148. });
  6149. item.Add(new TestItem()
  6150. {
  6151. Parameter_name = "载具穴号",
  6152. Parameter_value = "1",
  6153. });
  6154. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6155. }
  6156. // 调用MES进站 - 产品2
  6157. int result2 = c1Part2Result_Check;
  6158. if (result2 != 3)
  6159. {
  6160. item = new List<TestItem>();
  6161. item.Add(new TestItem()
  6162. {
  6163. Parameter_name = "载具码",
  6164. Parameter_value = sn,
  6165. });
  6166. item.Add(new TestItem()
  6167. {
  6168. Parameter_name = "载具穴号",
  6169. Parameter_value = "2",
  6170. });
  6171. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6172. }
  6173. stopwatch2.Stop();
  6174. if (result1 == 2)
  6175. c1Part1Result_Check = 2;
  6176. if (result2 == 2)
  6177. c1Part2Result_Check = 2;
  6178. int result = result1;
  6179. if (result == 1)
  6180. result = result2;
  6181. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6182. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6183. short c1MES_FLAG_Check = (short)result;
  6184. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6185. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6186. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6187. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6188. //// MES_Flag
  6189. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6190. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6191. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6192. writeToPLC_Flag.Adress = 2003;
  6193. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6194. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6195. {
  6196. Name = "c1Part1Result_Check",
  6197. Adress = 2024,
  6198. ValueType = PLCValueType.Short,
  6199. Value = c1Part1Result_Check
  6200. });
  6201. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6202. {
  6203. Name = "c1Part2Result_Check",
  6204. Adress = 2025,
  6205. ValueType = PLCValueType.Short,
  6206. Value = c1Part2Result_Check
  6207. });
  6208. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6209. {
  6210. Name = "c1Part1Num_Check",
  6211. Adress = 2026,
  6212. ValueType = PLCValueType.Short,
  6213. Value = c1Part1Num_Check
  6214. });
  6215. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6216. {
  6217. Name = "c1Part2Num_Check",
  6218. Adress = 2027,
  6219. ValueType = PLCValueType.Short,
  6220. Value = c1Part2Num_Check
  6221. });
  6222. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6223. }
  6224. catch (Exception ex)
  6225. {
  6226. string str = ex.StackTrace;
  6227. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6228. // MES_Flag
  6229. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6230. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6231. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6232. writeToPLC_Flag.Adress = 2003;
  6233. writeToPLC_Flag.Value = (short)6;
  6234. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6235. }
  6236. stopwatch1.Stop();
  6237. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6238. }
  6239. /// <summary>
  6240. /// [S3] 值板机 - 二穴载具解绑
  6241. /// </summary>
  6242. /// <param name="plcNo">PLC编号</param>
  6243. /// <param name="stationNameStr">工站全称</param>
  6244. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6245. {
  6246. Stopwatch stopwatch1 = new Stopwatch();
  6247. Stopwatch stopwatch2 = new Stopwatch();
  6248. try
  6249. {
  6250. stopwatch1.Start();
  6251. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6252. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6253. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6254. // 解绑
  6255. #region 查询载具上的产品信息
  6256. string cavityData = string.Empty;
  6257. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6258. if (string.IsNullOrEmpty(cavityData))
  6259. cavityData = "";
  6260. if (snResult != 0)
  6261. {
  6262. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6263. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6264. writeToPLC_Flag1.Adress = 2082;
  6265. writeToPLC_Flag1.Value = (short)6;
  6266. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6267. stopwatch1.Stop();
  6268. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6269. return;
  6270. }
  6271. #endregion 查询载具上的产品信息
  6272. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6273. #region 解绑
  6274. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6275. {
  6276. // 删除
  6277. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6278. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6279. }
  6280. else
  6281. {
  6282. string data_new = string.Join(".", cavitySNs);
  6283. // 删除再插入
  6284. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6285. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6286. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6287. }
  6288. #endregion 解绑
  6289. short c1MES_FLAG_Unbind = 1;
  6290. stopwatch2.Start();
  6291. // MES_Flag
  6292. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6293. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6294. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6295. writeToPLC_Flag.Adress = 2082;
  6296. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6297. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6298. stopwatch2.Stop();
  6299. }
  6300. catch (Exception ex)
  6301. {
  6302. string str = ex.StackTrace;
  6303. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6304. // MES_Flag
  6305. stopwatch2.Start();
  6306. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6307. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6308. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6309. writeToPLC_Flag.Adress = 2082;
  6310. writeToPLC_Flag.Value = (short)6;
  6311. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6312. stopwatch2.Stop();
  6313. }
  6314. stopwatch1.Stop();
  6315. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6316. }
  6317. /// <summary>
  6318. /// [S3] 值板机 - 二穴载具绑定
  6319. /// </summary>
  6320. /// <param name="plcNo">PLC编号</param>
  6321. /// <param name="stationNameStr">工站全称</param>
  6322. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6323. {
  6324. Stopwatch stopwatch1 = new Stopwatch();
  6325. Stopwatch stopwatch2 = new Stopwatch();
  6326. try
  6327. {
  6328. stopwatch1.Start();
  6329. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6330. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6331. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6332. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6333. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6334. stopwatch2.Start();
  6335. #region 查询载具上的产品信息
  6336. string cavityData = string.Empty;
  6337. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6338. if (string.IsNullOrEmpty(cavityData))
  6339. cavityData = "";
  6340. if (snResult != 0)
  6341. {
  6342. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6343. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6344. writeToPLC_Flag1.Adress = 2115;
  6345. writeToPLC_Flag1.Value = (short)6;
  6346. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6347. stopwatch1.Stop();
  6348. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6349. return;
  6350. }
  6351. #endregion 查询载具上的产品信息
  6352. // 产品换载具
  6353. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6354. string partSn1 = "";
  6355. string partSn2 = "";
  6356. if (cavitySNs != null && cavitySNs.Length >= 2)
  6357. {
  6358. partSn1 = cavitySNs[0];
  6359. partSn2 = cavitySNs[1];
  6360. }
  6361. string data_new = string.Empty;
  6362. // 是否是两个穴位交换
  6363. if (c1CavityReverse_Bind == 1)
  6364. {
  6365. // 交换
  6366. data_new = string.Concat(partSn2, ".", partSn1);
  6367. }
  6368. else
  6369. { // 不交换
  6370. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6371. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6372. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6373. data_new = string.Join(".", cavitySNs);
  6374. }
  6375. // 删除再插入
  6376. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6377. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6378. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6379. stopwatch2.Stop();
  6380. short c1MES_FLAG_Bind = 1;
  6381. // MES_Flag
  6382. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6383. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6384. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6385. writeToPLC_Flag.Adress = 2115;
  6386. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6387. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6388. }
  6389. catch (Exception ex)
  6390. {
  6391. string str = ex.StackTrace;
  6392. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6393. // MES_Flag
  6394. stopwatch2.Start();
  6395. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6396. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6397. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6398. writeToPLC_Flag.Adress = 2115;
  6399. writeToPLC_Flag.Value = (short)6;
  6400. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6401. stopwatch2.Stop();
  6402. }
  6403. stopwatch1.Stop();
  6404. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6405. }
  6406. //// 上次采集到的SN
  6407. //private string sn_值板机 = string.Empty;
  6408. /// <summary>
  6409. /// [S3] 值板机 - 出站接口
  6410. /// </summary>
  6411. /// <param name="plcNo">PLC编号</param>
  6412. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6413. {
  6414. Stopwatch stopwatch1 = new Stopwatch();
  6415. Stopwatch stopwatch2 = new Stopwatch();
  6416. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6417. string stationNameStr = stationCode + stationName;
  6418. string processItem = stationName; // 测试项目
  6419. try
  6420. {
  6421. stopwatch1.Start();
  6422. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6423. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6424. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6425. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6426. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6427. sn = sn.Replace("\0", "");
  6428. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6429. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6430. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6431. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6432. bool pass = c1Result == 1;
  6433. // 查sn
  6434. #region 查询载具上的产品信息
  6435. string cavityData = string.Empty;
  6436. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6437. if (string.IsNullOrEmpty(cavityData))
  6438. cavityData = "";
  6439. if (snResult != 0)
  6440. {
  6441. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6442. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6443. writeToPLC_Flag1.Adress = 2150;
  6444. writeToPLC_Flag1.Value = (short)4;
  6445. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6446. stopwatch1.Stop();
  6447. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6448. return;
  6449. }
  6450. #endregion 查询载具上的产品信息
  6451. string[] cavitySNs = cavityData.Split('.');
  6452. string productSN = "";
  6453. if (cavitySNs != null && cavitySNs.Length >= 2)
  6454. {
  6455. productSN = cavitySNs[c1VehicleCavity];
  6456. cavitySNs[c1VehicleCavity] = "";
  6457. }
  6458. stopwatch2.Start();
  6459. List<TestItem> items = new List<TestItem>();
  6460. items.Add(new TestItem()
  6461. {
  6462. Parameter_name = "二穴载具码",
  6463. Parameter_value = c1ProductSN_Check,
  6464. Parameter_unit = ""
  6465. });
  6466. items.Add(new TestItem()
  6467. {
  6468. Parameter_name = "二穴载具穴号",
  6469. Parameter_value = c1VehicleCavity.ToString(),
  6470. Parameter_unit = ""
  6471. });
  6472. items.Add(new TestItem()
  6473. {
  6474. Parameter_name = "一穴载具码",
  6475. Parameter_value = sn,
  6476. Parameter_unit = ""
  6477. });
  6478. items.Add(new TestItem()
  6479. {
  6480. Parameter_name = "一穴载具穴号",
  6481. Parameter_value = "1",
  6482. Parameter_unit = ""
  6483. });
  6484. items.Add(new TestItem()
  6485. {
  6486. Parameter_name = "产品结果",
  6487. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6488. Parameter_unit = ""
  6489. });
  6490. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6491. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6492. short result = (short)result1;
  6493. stopwatch2.Stop();
  6494. #region 存储绑定数据到 边线MES系统中
  6495. if (result == 1)
  6496. {
  6497. string data = string.Concat(productSN);
  6498. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6499. if (resultMesR != 0)
  6500. {
  6501. result = 4;
  6502. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6503. }
  6504. }
  6505. #endregion 存储绑定数据到 边线MES系统中
  6506. #region 产品从 来源载具(二穴载具)中删除
  6507. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6508. {
  6509. // 删除
  6510. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6511. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6512. }
  6513. else
  6514. {
  6515. string data_new = string.Join(".", cavitySNs);
  6516. // 删除再插入
  6517. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6518. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6519. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6520. }
  6521. #endregion 产品从 来源载具(二穴载具)中删除
  6522. // MES_Flag 为MES报错
  6523. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6524. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6525. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6526. writeToPLC_Flag.Name = "c1MES_FLAG";
  6527. writeToPLC_Flag.Adress = 2150;
  6528. writeToPLC_Flag.Value = result;
  6529. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6530. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6531. }
  6532. catch (Exception ex)
  6533. {
  6534. stopwatch2.Restart();
  6535. // MES_Flag 为4上位机报错
  6536. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6537. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6538. writeToPLC_Flag.Name = "c1MES_FLAG";
  6539. writeToPLC_Flag.Adress = 2150;
  6540. writeToPLC_Flag.Value = (short)4;
  6541. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6542. stopwatch2.Stop();
  6543. string str = ex.StackTrace;
  6544. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6545. }
  6546. stopwatch1.Stop();
  6547. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6548. }
  6549. /// <summary>
  6550. /// [S3] 值板机- 节拍接口
  6551. /// </summary>
  6552. /// <param name="plcNo">PLC编号</param>
  6553. /// <param name="stationNameStr">工站全称</param>
  6554. private void S3节拍接口(int plcNo, string stationNameStr)
  6555. {
  6556. Stopwatch stopwatch1 = new Stopwatch();
  6557. Stopwatch stopwatch2 = new Stopwatch();
  6558. string resultStr = string.Empty;
  6559. try
  6560. {
  6561. stopwatch1.Start();
  6562. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6563. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6564. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6565. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6566. if (!actionBool)
  6567. {
  6568. stopwatch2.Start();
  6569. // MES_Flag
  6570. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6571. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6572. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6573. writeToPLC_Flag1.Adress = 2204;
  6574. writeToPLC_Flag1.Value = (short)4;
  6575. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6576. stopwatch2.Stop();
  6577. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6578. return;
  6579. }
  6580. string c1OEEPartNo = string.Empty; // 物料码
  6581. if (string.IsNullOrEmpty(c1OEEProductSN))
  6582. {
  6583. stopwatch2.Start();
  6584. // MES_Flag
  6585. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6586. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6587. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6588. writeToPLC_Flag1.Adress = 2204;
  6589. writeToPLC_Flag1.Value = (short)1;
  6590. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6591. stopwatch2.Stop();
  6592. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6593. return;
  6594. }
  6595. else
  6596. { // 查产品SN
  6597. c1OEEPartNo = "Test"; // ZS
  6598. }
  6599. short c1OEEMES_FLAG = 0;
  6600. // 上传OEE
  6601. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6602. c1OEEMES_FLAG = result.Item1;
  6603. resultStr = result.Item2;
  6604. stopwatch2.Start();
  6605. // MES_Flag
  6606. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6607. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6608. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6609. writeToPLC_Flag.Adress = 2204;
  6610. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6611. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6612. stopwatch2.Stop();
  6613. }
  6614. catch (Exception ex)
  6615. {
  6616. string str = ex.StackTrace;
  6617. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6618. // MES_Flag
  6619. stopwatch2.Start();
  6620. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6621. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6622. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6623. writeToPLC_Flag.Adress = 2204;
  6624. writeToPLC_Flag.Value = (short)4;
  6625. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6626. stopwatch2.Stop();
  6627. }
  6628. stopwatch1.Stop();
  6629. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6630. }
  6631. #endregion [S3] 值板机
  6632. #endregion PLC3 刘永村
  6633. #region PLC4 刘果段
  6634. #region [S4] 取放桁架
  6635. /// <summary>
  6636. /// S4工位的数据- 触发信号上次的值
  6637. /// </summary>
  6638. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6639. /// <summary>
  6640. /// S4工位的数据(含触发信号)
  6641. /// </summary>
  6642. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6643. /// <summary>
  6644. /// S4工位的数据- 回写点位
  6645. /// </summary>
  6646. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6647. /// <summary>
  6648. /// [S4] 取放桁架
  6649. /// </summary>
  6650. /// <param name="plcNo">PLC编号</param>
  6651. //private void ReadStation_S4(int plcNo)
  6652. //{
  6653. // // [S1] Tray盘上料装备
  6654. // // [S2] FCT
  6655. // // [S3] 值板机
  6656. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6657. // // [S5] Tray盘下料装备
  6658. // /// 上位机心跳
  6659. // /// 获取设备报警数据与状态信息
  6660. // string stationCode = "[S4_1]";
  6661. // string stationName = "载具下线装备";
  6662. // string stationNameStr = stationCode + stationName;
  6663. // string stationCode2 = "[S4_2]";
  6664. // string stationName2 = "桁架";
  6665. // string stationNameStr2 = stationCode2 + stationName2;
  6666. // string stationCode3 = "[S4_3]";
  6667. // string stationName3 = "提升机1";
  6668. // string stationNameStr3 = stationCode3 + stationName3;
  6669. // string stationCode4 = "[S4_4]";
  6670. // string stationName4 = "提升机2";
  6671. // string stationNameStr4 = stationCode4 + stationName4;
  6672. // string stationCode5 = "[S4_5]";
  6673. // string stationName5 = "载具上线装备";
  6674. // string stationNameStr5 = stationCode5 + stationName5;
  6675. // #region 创建字典
  6676. // // 触发信号字典 赋值
  6677. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6678. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6679. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6680. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6681. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6682. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6683. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6684. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6685. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6686. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6687. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6688. // // PLC数据字典 赋值
  6689. // // 载具下线装备(弹夹上线)
  6690. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6691. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6692. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6693. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6694. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6695. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6696. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6697. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6698. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6699. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6700. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6701. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6702. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6703. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6704. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6705. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6706. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6707. // s4PLCData.Add("d1Result", 0); // 产品结果
  6708. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6709. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6710. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6711. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6712. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6713. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6714. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6715. // // 真空标机(提升机)
  6716. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6717. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6718. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6719. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6720. // s4PLCData.Add("d3Result", 0); // 产品结果
  6721. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6722. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6723. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6724. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6725. // s4PLCData.Add("d4Result", 0); // 产品结果
  6726. // // 载具上线装备(弹夹下线)
  6727. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6728. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6729. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6730. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6731. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6732. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6733. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6734. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6735. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6736. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6737. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6738. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6739. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6740. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6741. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6742. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6743. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6744. // s4PLCData.Add("d5Result", 0); // 产品结果
  6745. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6746. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6747. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6748. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6749. // #endregion 创建字典
  6750. // while (IsRun)
  6751. // {
  6752. // try
  6753. // {
  6754. // if (!GlobalContext._IsCon_Funs4)
  6755. // {
  6756. // UpdatePLCMonitor(1, plcNo, 0);
  6757. // continue;
  6758. // }
  6759. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6760. // {
  6761. // Stopwatch stopwatch1 = new Stopwatch();
  6762. // Stopwatch stopwatch2 = new Stopwatch();
  6763. // stopwatch1.Start();
  6764. // stopwatch2.Start();
  6765. // #region 一次性读取所有数据
  6766. // // 载具下线装备(弹夹上线)
  6767. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6768. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6769. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6770. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6771. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6772. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6773. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6774. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6775. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6776. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6777. // int[] datas = data1.Concat(data2).ToArray();
  6778. // datas = datas.Concat(data3).ToArray();
  6779. // datas = datas.Concat(data4).ToArray();
  6780. // datas = datas.Concat(data5).ToArray();
  6781. // datas = datas.Concat(data6).ToArray();
  6782. // datas = datas.Concat(data7).ToArray();
  6783. // datas = datas.Concat(data8).ToArray();
  6784. // datas = datas.Concat(data9).ToArray();
  6785. // datas = datas.Concat(data10).ToArray();
  6786. // // 载具下线装备(弹夹上线)
  6787. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6788. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6789. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6790. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6791. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6792. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6793. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6794. // s4PLCData["d1MES_FLAG"] = datas[65];
  6795. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6796. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6797. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6798. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6799. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6800. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6801. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6802. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6803. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6804. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6805. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6806. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6807. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6808. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6809. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6810. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6811. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6812. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6813. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6814. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6815. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6816. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6817. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6818. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6819. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6820. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6821. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6822. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6823. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6824. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6825. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6826. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6827. // s4PLCData["d1Result"] = datas[386];
  6828. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6829. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6830. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6831. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6832. // s4PLCData["d1OEEType"] = datas[419];
  6833. // // 桁架(查询标机中弹夹的状态)
  6834. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6835. // s4PLCData["d2BulletclipStates"] = datas[431];
  6836. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6837. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6838. // // 真空标机
  6839. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6840. // s4PLCData["d3MES_FLAG"] = datas[463];
  6841. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6842. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6843. // s4PLCData["d3Result"] = datas[484];
  6844. // s4PLCData["d3Type"] = datas[485];
  6845. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6846. // s4PLCData["d4MES_FLAG"] = datas[496];
  6847. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6848. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6849. // s4PLCData["d4Result"] = datas[517];
  6850. // s4PLCData["d4Type"] = datas[518];
  6851. // // 载具上线装备(弹夹下线)
  6852. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6853. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6854. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6855. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6856. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6857. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6858. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6859. // s4PLCData["d5MES_FLAG"] = datas[591];
  6860. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6861. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6862. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6863. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6864. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6865. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6866. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6867. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6868. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6869. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6870. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6871. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6872. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6873. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6874. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6875. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6876. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6877. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6878. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6879. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6880. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6881. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6882. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6883. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6884. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6885. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6886. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6887. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6888. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6889. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6890. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6891. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6892. // s4PLCData["d5Result"] = datas[912];
  6893. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  6894. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  6895. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  6896. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  6897. // s4PLCData["d5OEEType"] = datas[945];
  6898. // #endregion 一次性读取所有数据
  6899. // stopwatch2.Stop();
  6900. // #region 回写操作,写后清空flag
  6901. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  6902. // #endregion 回写操作,写后清空flag
  6903. // // N801A-S4_1 弹夹扫码
  6904. // #region N801A-S4_1 弹夹扫码
  6905. // try
  6906. // {
  6907. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  6908. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  6909. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  6910. // {
  6911. // if (d1BulletclipScanCode == 1) // 0->1
  6912. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6913. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  6914. // }
  6915. // }
  6916. // catch (Exception ex)
  6917. // {
  6918. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  6919. // string str = ex.StackTrace;
  6920. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6921. // }
  6922. // #endregion N801A-S4_1 弹夹扫码
  6923. // // N801A-S4_1 载具扫码
  6924. // #region N801A-S4_1 载具扫码
  6925. // try
  6926. // {
  6927. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  6928. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  6929. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  6930. // {
  6931. // if (d1VehicleScanCode == 1) // 0->1
  6932. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6933. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  6934. // }
  6935. // }
  6936. // catch (Exception ex)
  6937. // {
  6938. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  6939. // string str = ex.StackTrace;
  6940. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6941. // }
  6942. // #endregion N801A-S4_1 载具扫码
  6943. // // N801A-S4_1 出站接口
  6944. // #region N801A-S4_1 出站接口
  6945. // try
  6946. // {
  6947. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  6948. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  6949. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  6950. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  6951. // {
  6952. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  6953. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6954. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  6955. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  6956. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  6957. // }
  6958. // }
  6959. // catch (Exception ex)
  6960. // {
  6961. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  6962. // string str = ex.StackTrace;
  6963. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6964. // }
  6965. // #endregion N801A-S4_1 出站接口
  6966. // // N801A-S4_1 节拍接口
  6967. // #region N801A-S4_1 节拍接口
  6968. // try
  6969. // {
  6970. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  6971. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  6972. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  6973. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  6974. // {
  6975. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  6976. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6977. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  6978. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  6979. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  6980. // }
  6981. // }
  6982. // catch (Exception ex)
  6983. // {
  6984. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  6985. // string str = ex.StackTrace;
  6986. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6987. // }
  6988. // #endregion N801A-S4_1 节拍接口
  6989. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  6990. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  6991. // try
  6992. // {
  6993. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  6994. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  6995. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  6996. // {
  6997. // if (d2BulletclipScanCode == 1) // 0->1
  6998. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  6999. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  7000. // }
  7001. // }
  7002. // catch (Exception ex)
  7003. // {
  7004. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7005. // string str = ex.StackTrace;
  7006. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7007. // }
  7008. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  7009. // // N801A-S4_3 真空标机1 数据
  7010. // #region N801A-S4_3 真空标机1
  7011. // try
  7012. // {
  7013. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  7014. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  7015. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  7016. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  7017. // {
  7018. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  7019. // {
  7020. // int stationType = (int)s4PLCData["d3Type"];
  7021. // if (stationType == 1)
  7022. // {
  7023. // // S4_3进站接口
  7024. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  7025. // }
  7026. // else if (stationType == 2)
  7027. // {
  7028. // // S4_3出站接口
  7029. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  7030. // }
  7031. // }
  7032. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  7033. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  7034. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  7035. // }
  7036. // }
  7037. // catch (Exception ex)
  7038. // {
  7039. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7040. // string str = ex.StackTrace;
  7041. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7042. // }
  7043. // #endregion N801A-S4_3 真空标机1
  7044. // // N801A-S4_4 真空标机2 数据
  7045. // #region N801A-S4_4 真空标机2
  7046. // try
  7047. // {
  7048. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  7049. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  7050. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  7051. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  7052. // {
  7053. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  7054. // {
  7055. // int stationType = (int)s4PLCData["d4Type"];
  7056. // if (stationType == 1)
  7057. // {
  7058. // // S4_4进站接口
  7059. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  7060. // }
  7061. // else if (stationType == 2)
  7062. // {
  7063. // // S4_4出站接口
  7064. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  7065. // }
  7066. // }
  7067. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  7068. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  7069. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  7070. // }
  7071. // }
  7072. // catch (Exception ex)
  7073. // {
  7074. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7075. // string str = ex.StackTrace;
  7076. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7077. // }
  7078. // #endregion N801A-S4_4 真空标机2
  7079. // // N801A-S4_5 弹夹扫码 数据
  7080. // #region N801A-S4_5 弹夹扫码
  7081. // try
  7082. // {
  7083. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7084. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7085. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7086. // {
  7087. // if (d5BulletclipScanCode == 1) // 0->1
  7088. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7089. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7090. // }
  7091. // }
  7092. // catch (Exception ex)
  7093. // {
  7094. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7095. // string str = ex.StackTrace;
  7096. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7097. // }
  7098. // #endregion N801A-S4_5 弹夹扫码
  7099. // // N801A-S4_5 载具扫码 数据
  7100. // #region N801A-S4_5 载具扫码
  7101. // try
  7102. // {
  7103. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7104. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7105. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7106. // {
  7107. // if (d5VehicleScanCode == 1) // 0->1
  7108. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7109. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7110. // }
  7111. // }
  7112. // catch (Exception ex)
  7113. // {
  7114. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7115. // string str = ex.StackTrace;
  7116. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7117. // }
  7118. // #endregion N801A-S4_5 载具扫码
  7119. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7120. // #region N801A-S4_5 出站接口
  7121. // try
  7122. // {
  7123. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7124. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7125. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7126. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7127. // {
  7128. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7129. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7130. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7131. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7132. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7133. // }
  7134. // }
  7135. // catch (Exception ex)
  7136. // {
  7137. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7138. // string str = ex.StackTrace;
  7139. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7140. // }
  7141. // #endregion N801A-S4_5 出站接口
  7142. // // N801A-S4_5 节拍接口 数据
  7143. // #region N801A-S4_5 节拍接口
  7144. // try
  7145. // {
  7146. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7147. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7148. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7149. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7150. // {
  7151. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7152. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7153. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7154. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7155. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7156. // }
  7157. // }
  7158. // catch (Exception ex)
  7159. // {
  7160. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7161. // string str = ex.StackTrace;
  7162. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7163. // }
  7164. // #endregion N801A-S4_5 节拍接口
  7165. // #region 心跳
  7166. // try
  7167. // {
  7168. // short states = 0;
  7169. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7170. // }
  7171. // catch (Exception ex)
  7172. // {
  7173. // string str = ex.StackTrace;
  7174. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7175. // }
  7176. // #endregion 心跳
  7177. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7178. // stopwatch1.Stop();
  7179. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7180. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7181. // }
  7182. // else
  7183. // {
  7184. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7185. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7186. // Funs[plcNo].Connect();
  7187. // }
  7188. // }
  7189. // catch (Exception ex)
  7190. // {
  7191. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7192. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7193. // Funs[plcNo].ReConnect();
  7194. // }
  7195. // Thread.Sleep(IntervalReadPLC);
  7196. // }
  7197. //}
  7198. /// <summary>
  7199. /// [S4] 取放桁架 - S4_1弹夹扫码
  7200. /// </summary>
  7201. /// <param name="plcNo">PLC编号</param>
  7202. /// <param name="stationNameStr">工站全称</param>
  7203. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7204. {
  7205. Stopwatch stopwatch1 = new Stopwatch();
  7206. Stopwatch stopwatch2 = new Stopwatch();
  7207. try
  7208. {
  7209. stopwatch1.Start();
  7210. // ZS 弹夹扫码
  7211. string d1BulletclipCode = " "; // 扫到的码
  7212. short d1BulletclipScanCode = 2;
  7213. stopwatch2.Start();
  7214. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7215. //// MES_Flag
  7216. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7217. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7218. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7219. writeToPLC_Flag.Adress = 2002;
  7220. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7221. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7222. {
  7223. Name = "d1BulletclipCode",
  7224. Adress = 2003,
  7225. ValueType = PLCValueType.String,
  7226. ValueTypeStrLength = 20,
  7227. Value = d1BulletclipCode
  7228. });
  7229. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7230. stopwatch2.Stop();
  7231. }
  7232. catch (Exception ex)
  7233. {
  7234. string str = ex.StackTrace;
  7235. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7236. stopwatch2.Start();
  7237. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7238. //// MES_Flag
  7239. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7240. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7241. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7242. writeToPLC_Flag.Adress = 2002;
  7243. writeToPLC_Flag.Value = (short)6;
  7244. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7245. {
  7246. Name = "d1BulletclipCode",
  7247. Adress = 2003,
  7248. ValueType = PLCValueType.String,
  7249. ValueTypeStrLength = 20,
  7250. Value = " "
  7251. });
  7252. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7253. stopwatch2.Stop();
  7254. }
  7255. stopwatch1.Stop();
  7256. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7257. }
  7258. /// <summary>
  7259. /// [S4] 取放桁架 - S4_1载具扫码
  7260. /// </summary>
  7261. /// <param name="plcNo">PLC编号</param>
  7262. /// <param name="stationNameStr">工站全称</param>
  7263. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7264. {
  7265. Stopwatch stopwatch1 = new Stopwatch();
  7266. Stopwatch stopwatch2 = new Stopwatch();
  7267. try
  7268. {
  7269. stopwatch1.Start();
  7270. // ZS 载具扫码
  7271. string d1VehicleCode = ""; // 扫到的码
  7272. short d1VehicleScanCode = 2;
  7273. #region 进站
  7274. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7275. {
  7276. #region 查询载具上的产品信息
  7277. string cavityData = string.Empty;
  7278. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7279. if (string.IsNullOrEmpty(cavityData))
  7280. cavityData = "";
  7281. if (snResult != 0)
  7282. {
  7283. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7284. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7285. writeToPLC_Flag1.Adress = 2033;
  7286. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7287. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7288. {
  7289. Name = "d1VehicleCode",
  7290. Adress = 2034,
  7291. ValueType = PLCValueType.String,
  7292. ValueTypeStrLength = 20,
  7293. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7294. });
  7295. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7296. stopwatch1.Stop();
  7297. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7298. return;
  7299. }
  7300. string[] cavitySNs = cavityData.Split('.');
  7301. string partNo = "";
  7302. if (cavitySNs != null && cavitySNs.Length >= 1)
  7303. {
  7304. partNo = cavitySNs[0];
  7305. }
  7306. #endregion 查询载具上的产品信息
  7307. List<TestItem> item = new List<TestItem>();
  7308. item.Add(new TestItem()
  7309. {
  7310. Parameter_name = "载具码",
  7311. Parameter_value = d1VehicleCode,
  7312. });
  7313. item.Add(new TestItem()
  7314. {
  7315. Parameter_name = "载具穴号",
  7316. Parameter_value = "1",
  7317. });
  7318. stopwatch2.Start();
  7319. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7320. stopwatch2.Stop();
  7321. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7322. }
  7323. #endregion 进站
  7324. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7325. //// MES_Flag
  7326. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7327. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7328. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7329. writeToPLC_Flag.Adress = 2033;
  7330. writeToPLC_Flag.Value = d1VehicleScanCode;
  7331. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7332. {
  7333. Name = "d1VehicleCode",
  7334. Adress = 2034,
  7335. ValueType = PLCValueType.String,
  7336. ValueTypeStrLength = 20,
  7337. Value = d1VehicleCode
  7338. });
  7339. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7340. }
  7341. catch (Exception ex)
  7342. {
  7343. string str = ex.StackTrace;
  7344. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7345. stopwatch2.Start();
  7346. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7347. //// MES_Flag
  7348. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7349. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7350. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7351. writeToPLC_Flag.Adress = 2033;
  7352. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7353. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7354. {
  7355. Name = "d1VehicleCode",
  7356. Adress = 2034,
  7357. ValueType = PLCValueType.String,
  7358. ValueTypeStrLength = 20,
  7359. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7360. });
  7361. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7362. stopwatch2.Stop();
  7363. }
  7364. stopwatch1.Stop();
  7365. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7366. }
  7367. // 上次采集到的SN
  7368. //private string sn_S4_1出站接口 = string.Empty;
  7369. /// <summary>
  7370. /// [S4] 取放桁架 - S4_1出站接口
  7371. /// </summary>
  7372. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7373. {
  7374. Stopwatch stopwatch1 = new Stopwatch();
  7375. Stopwatch stopwatch2 = new Stopwatch();
  7376. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7377. string stationNameStr = stationCode + stationName;
  7378. string processItem = stationName; // 测试项目
  7379. try
  7380. {
  7381. stopwatch1.Start();
  7382. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7383. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7384. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7385. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7386. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7387. sn = sn.Replace("\0", "");
  7388. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7389. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7390. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7391. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7392. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7393. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7394. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7395. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7396. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7397. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7398. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7399. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7400. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7401. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7402. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7403. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7404. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7405. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7406. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7407. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7408. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7409. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7410. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7411. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7412. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7413. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7414. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7415. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7416. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7417. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7418. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7419. bool pass = d1Result == 1;
  7420. // 存 载具SN列表
  7421. List<string> vehicleCodes = new List<string>()
  7422. {
  7423. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7424. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7425. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7426. };
  7427. // 统一查 产品SN列表
  7428. List<string> partNos = new List<string>();
  7429. foreach (string vehicleCode in vehicleCodes)
  7430. {
  7431. if (string.IsNullOrEmpty(vehicleCode))
  7432. partNos.Add("");
  7433. else
  7434. {
  7435. string partNo = "";
  7436. #region 查询载具上的产品信息
  7437. string cavityData = string.Empty;
  7438. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7439. if (string.IsNullOrEmpty(cavityData))
  7440. cavityData = "";
  7441. if (snResult != 0)
  7442. {
  7443. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7444. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7445. writeToPLC_Flag1.Adress = 2065;
  7446. writeToPLC_Flag1.Value = (short)4;
  7447. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7448. stopwatch1.Stop();
  7449. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7450. return;
  7451. }
  7452. string[] cavitySNs = cavityData.Split('.');
  7453. if (cavitySNs != null && cavitySNs.Length >= 1)
  7454. partNo = cavitySNs[0];
  7455. #endregion 查询载具上的产品信息
  7456. partNos.Add(partNo);
  7457. }
  7458. }
  7459. // 统一上传
  7460. stopwatch2.Start();
  7461. List<int> results = new List<int>();
  7462. for (int i = 0; i < partNos.Count; i++)
  7463. {
  7464. string index = (i + 1).ToString(); // 弹夹穴号
  7465. if (string.IsNullOrEmpty(partNos[i]))
  7466. results.Add(1);
  7467. else
  7468. {
  7469. List<TestItem> items1 = new List<TestItem>();
  7470. items1.Add(new TestItem()
  7471. {
  7472. Parameter_name = "弹夹码",
  7473. Parameter_value = sn,
  7474. Parameter_unit = ""
  7475. });
  7476. items1.Add(new TestItem()
  7477. {
  7478. Parameter_name = "弹夹穴号",
  7479. Parameter_value = index,
  7480. Parameter_unit = ""
  7481. });
  7482. items1.Add(new TestItem()
  7483. {
  7484. Parameter_name = "载具码",
  7485. Parameter_value = vehicleCodes[i],
  7486. Parameter_unit = ""
  7487. });
  7488. items1.Add(new TestItem()
  7489. {
  7490. Parameter_name = "载具穴号",
  7491. Parameter_value = "1",
  7492. Parameter_unit = ""
  7493. });
  7494. items1.Add(new TestItem()
  7495. {
  7496. Parameter_name = "产品结果",
  7497. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7498. Parameter_unit = ""
  7499. });
  7500. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7501. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7502. results.Add(result1);
  7503. }
  7504. }
  7505. short result = 0;
  7506. if (results.All(a => a == 1))
  7507. result = 1;
  7508. else if (results.Contains(3))
  7509. result = 3;
  7510. else if (results.Contains(2))
  7511. result = 2;
  7512. else if (results.Contains(4))
  7513. result = 4;
  7514. else
  7515. result = 4;
  7516. stopwatch2.Stop();
  7517. #region 存储绑定数据到 边线MES系统中
  7518. if (result == 1)
  7519. {
  7520. string data = string.Join(".", vehicleCodes);
  7521. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7522. if (resultMesR != 0)
  7523. {
  7524. result = 4;
  7525. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7526. }
  7527. }
  7528. #endregion 存储绑定数据到 边线MES系统中
  7529. // MES_Flag 为4MES报错
  7530. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7531. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7532. writeToPLC_Flag.Name = "d1MES_FLAG";
  7533. writeToPLC_Flag.Adress = 2065;
  7534. writeToPLC_Flag.Value = result;
  7535. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7536. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7537. }
  7538. catch (Exception ex)
  7539. {
  7540. stopwatch2.Restart();
  7541. // MES_Flag 为4上位机报错
  7542. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7543. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7544. writeToPLC_Flag.Name = "d1MES_FLAG";
  7545. writeToPLC_Flag.Adress = 2065;
  7546. writeToPLC_Flag.Value = (short)4;
  7547. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7548. stopwatch2.Stop();
  7549. string str = ex.StackTrace;
  7550. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7551. }
  7552. stopwatch1.Stop();
  7553. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7554. }
  7555. /// <summary>
  7556. /// [S4] 取放桁架 - S4_1节拍接口
  7557. /// </summary>
  7558. /// <param name="plcNo">PLC编号</param>
  7559. /// <param name="stationNameStr">工站全称</param>
  7560. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7561. {
  7562. Stopwatch stopwatch1 = new Stopwatch();
  7563. Stopwatch stopwatch2 = new Stopwatch();
  7564. string resultStr = string.Empty;
  7565. try
  7566. {
  7567. stopwatch1.Start();
  7568. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7569. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7570. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7571. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7572. if (!actionBool)
  7573. {
  7574. stopwatch2.Start();
  7575. // MES_Flag
  7576. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7577. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7578. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7579. writeToPLC_Flag1.Adress = 2398;
  7580. writeToPLC_Flag1.Value = (short)4;
  7581. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7582. stopwatch2.Stop();
  7583. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7584. return;
  7585. }
  7586. string d1OEEPartNo = string.Empty; // 物料码
  7587. if (string.IsNullOrEmpty(d1OEEProductSN))
  7588. {
  7589. stopwatch2.Start();
  7590. // MES_Flag
  7591. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7592. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7593. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7594. writeToPLC_Flag1.Adress = 2398;
  7595. writeToPLC_Flag1.Value = (short)1;
  7596. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7597. stopwatch2.Stop();
  7598. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7599. return;
  7600. }
  7601. else
  7602. { // 查产品SN ZS
  7603. d1OEEPartNo = "Test";
  7604. }
  7605. short d1OEEMES_FLAG = 0;
  7606. // 上传OEE
  7607. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7608. d1OEEMES_FLAG = result.Item1;
  7609. resultStr = result.Item2;
  7610. stopwatch2.Start();
  7611. // MES_Flag
  7612. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7613. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7614. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7615. writeToPLC_Flag.Adress = 2398;
  7616. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7617. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7618. stopwatch2.Stop();
  7619. }
  7620. catch (Exception ex)
  7621. {
  7622. string str = ex.StackTrace;
  7623. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7624. // MES_Flag
  7625. stopwatch2.Start();
  7626. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7627. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7628. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7629. writeToPLC_Flag.Adress = 2398;
  7630. writeToPLC_Flag.Value = (short)4;
  7631. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7632. stopwatch2.Stop();
  7633. }
  7634. stopwatch1.Stop();
  7635. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7636. }
  7637. /// <summary>
  7638. /// [S4] 取放桁架 - S4_2桁架
  7639. /// </summary>
  7640. /// <param name="plcNo">PLC编号</param>
  7641. /// <param name="stationNameStr">工站全称</param>
  7642. private void S4_2桁架(int plcNo, string stationNameStr)
  7643. {
  7644. Stopwatch stopwatch1 = new Stopwatch();
  7645. Stopwatch stopwatch2 = new Stopwatch();
  7646. try
  7647. {
  7648. stopwatch1.Start();
  7649. // ZS 弹夹扫码
  7650. string d2BulletclipCode = " "; // 扫到的码
  7651. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7652. short d2BulletclipScanCode = 2;
  7653. stopwatch2.Start();
  7654. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7655. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7656. //// MES_Flag
  7657. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7658. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7659. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7660. writeToPLC_Flag.Adress = 2430;
  7661. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7662. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7663. {
  7664. Name = "d2BulletclipCode",
  7665. Adress = 2432,
  7666. ValueType = PLCValueType.String,
  7667. ValueTypeStrLength = 20,
  7668. Value = d2BulletclipCode
  7669. });
  7670. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7671. {
  7672. Name = "d2BulletclipStates",
  7673. Adress = 2431,
  7674. ValueType = PLCValueType.Short,
  7675. Value = d2BulletclipStates
  7676. });
  7677. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7678. stopwatch2.Stop();
  7679. }
  7680. catch (Exception ex)
  7681. {
  7682. string str = ex.StackTrace;
  7683. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7684. stopwatch2.Start();
  7685. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7686. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7687. // MES_Flag
  7688. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7689. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7690. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7691. writeToPLC_Flag.Adress = 2430;
  7692. writeToPLC_Flag.Value = (short)6;
  7693. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7694. {
  7695. Name = "d2BulletclipCode",
  7696. Adress = 2432,
  7697. ValueType = PLCValueType.String,
  7698. ValueTypeStrLength = 20,
  7699. Value = " "
  7700. });
  7701. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7702. {
  7703. Name = "d2BulletclipStates",
  7704. Adress = 2431,
  7705. ValueType = PLCValueType.Short,
  7706. Value = (short)0
  7707. });
  7708. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7709. stopwatch2.Stop();
  7710. }
  7711. stopwatch1.Stop();
  7712. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7713. }
  7714. // 上次采集到的SN
  7715. //private string sn_S4_3进站接口 = string.Empty;
  7716. /// <summary>
  7717. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7718. /// </summary>
  7719. private void S4_3进站接口(int plcNo, string stationNameStr)
  7720. {
  7721. Stopwatch stopwatch1 = new Stopwatch();
  7722. Stopwatch stopwatch2 = new Stopwatch();
  7723. try
  7724. {
  7725. stopwatch1.Start();
  7726. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7727. sn = sn.Replace("\0", "");
  7728. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7729. #region 查询15个载具码
  7730. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7731. string vehicleData = string.Empty;
  7732. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7733. if (string.IsNullOrEmpty(vehicleData))
  7734. vehicleData = "";
  7735. if (snResult != 0)
  7736. {
  7737. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7738. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7739. writeToPLC_Flag1.Adress = 2463;
  7740. writeToPLC_Flag1.Value = (short)4;
  7741. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7742. stopwatch1.Stop();
  7743. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7744. return;
  7745. }
  7746. string[] cavitySNs = vehicleData.Split('.');
  7747. if (cavitySNs != null && cavitySNs.Length > 0)
  7748. {
  7749. for (int i = 0; i < cavitySNs.Length; i++)
  7750. {
  7751. if (string.IsNullOrEmpty(cavitySNs[i]))
  7752. vehicleCodes.Add("");
  7753. else
  7754. vehicleCodes.Add(cavitySNs[i]);
  7755. }
  7756. }
  7757. #endregion 查询15个载具码
  7758. #region 查询15个产品SN
  7759. List<string> portNos = new List<string>(); // 15个产品SN
  7760. foreach (string vehicleCode in vehicleCodes)
  7761. {
  7762. if (string.IsNullOrEmpty(vehicleCode))
  7763. portNos.Add("");
  7764. else
  7765. {
  7766. // 查询
  7767. string cavityData = string.Empty;
  7768. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7769. if (string.IsNullOrEmpty(cavityData))
  7770. cavityData = "";
  7771. if (snResult1 != 0)
  7772. {
  7773. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7774. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7775. writeToPLC_Flag1.Adress = 2463;
  7776. writeToPLC_Flag1.Value = (short)4;
  7777. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7778. stopwatch1.Stop();
  7779. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7780. return;
  7781. }
  7782. string[] partSNs = cavityData.Split('.');
  7783. if (partSNs != null && partSNs.Length >= 1)
  7784. portNos.Add(partSNs[0]);
  7785. else
  7786. portNos.Add("");
  7787. }
  7788. }
  7789. #endregion 查询15个产品SN
  7790. // 调用MES进站(最多15个)
  7791. stopwatch2.Start();
  7792. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7793. for (int i = 0; i < vehicleCodes.Count; i++)
  7794. {
  7795. // 循环进站
  7796. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7797. {
  7798. // 产品SN(物料码)校验
  7799. string portNo = portNos[i];
  7800. List<TestItem> item = new List<TestItem>();
  7801. item.Add(new TestItem()
  7802. {
  7803. Parameter_name = "弹夹码",
  7804. Parameter_value = sn,
  7805. });
  7806. item.Add(new TestItem()
  7807. {
  7808. Parameter_name = "弹夹穴位",
  7809. Parameter_value = (i + 1).ToString(),
  7810. });
  7811. item.Add(new TestItem()
  7812. {
  7813. Parameter_name = "载具码",
  7814. Parameter_value = vehicleCodes[i],
  7815. });
  7816. item.Add(new TestItem()
  7817. {
  7818. Parameter_name = "载具穴号",
  7819. Parameter_value = "1",
  7820. });
  7821. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7822. }
  7823. }
  7824. stopwatch2.Stop();
  7825. short result = 0;
  7826. bool haveMesWarn = results.Contains(5);
  7827. bool havePCWarn = results.Contains(6);
  7828. if (haveMesWarn)
  7829. result = 2; // 5->2
  7830. else if (havePCWarn)
  7831. result = 6; // 6->4
  7832. else
  7833. result = 1;
  7834. // MES_Flag 为4MES报错
  7835. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7836. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7837. writeToPLC_Flag.Name = "d3MES_FLAG";
  7838. writeToPLC_Flag.Adress = 2463;
  7839. writeToPLC_Flag.Value = result;
  7840. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7841. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7842. }
  7843. catch (Exception ex)
  7844. {
  7845. stopwatch2.Stop();
  7846. // MES_Flag 为4上位机报错
  7847. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7848. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7849. writeToPLC_Flag.Name = "d3MES_FLAG";
  7850. writeToPLC_Flag.Adress = 2463;
  7851. writeToPLC_Flag.Value = (short)4;
  7852. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7853. string str = ex.StackTrace;
  7854. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7855. }
  7856. stopwatch1.Stop();
  7857. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7858. }
  7859. // 上次采集到的SN
  7860. //private string sn_S4_3出站接口 = string.Empty;
  7861. /// <summary>
  7862. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7863. /// </summary>
  7864. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7865. {
  7866. Stopwatch stopwatch1 = new Stopwatch();
  7867. Stopwatch stopwatch2 = new Stopwatch();
  7868. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7869. string stationNameStr = stationCode + stationName;
  7870. string processItem = stationName; // 测试项目
  7871. try
  7872. {
  7873. stopwatch1.Start();
  7874. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7875. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7876. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7877. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7878. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7879. sn = sn.Replace("\0", "");
  7880. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7881. bool isPass = d3Result == 1; // 产品结果 bool
  7882. #region 查询15个载具码
  7883. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7884. string vehicleData = string.Empty;
  7885. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7886. if (string.IsNullOrEmpty(vehicleData))
  7887. vehicleData = "";
  7888. if (snResult1 != 0)
  7889. {
  7890. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7891. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7892. writeToPLC_Flag1.Adress = 2463;
  7893. writeToPLC_Flag1.Value = (short)4;
  7894. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7895. stopwatch1.Stop();
  7896. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7897. return;
  7898. }
  7899. string[] cavitySNs = vehicleData.Split('.');
  7900. if (cavitySNs != null && cavitySNs.Length > 0)
  7901. {
  7902. for (int i = 0; i < cavitySNs.Length; i++)
  7903. {
  7904. if (string.IsNullOrEmpty(cavitySNs[i]))
  7905. vehicleCodes.Add("");
  7906. else
  7907. vehicleCodes.Add(cavitySNs[i]);
  7908. }
  7909. }
  7910. #endregion 查询15个载具码
  7911. // 统一查 产品SN列表
  7912. List<string> partNos = new List<string>();
  7913. foreach (string vehicleCode in vehicleCodes)
  7914. {
  7915. if (string.IsNullOrEmpty(vehicleCode))
  7916. partNos.Add("");
  7917. else
  7918. {
  7919. string partNo = "";
  7920. #region 查询载具上的产品信息
  7921. string cavityData = string.Empty;
  7922. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7923. if (string.IsNullOrEmpty(cavityData))
  7924. cavityData = "";
  7925. if (snResult != 0)
  7926. {
  7927. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7928. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7929. writeToPLC_Flag1.Adress = 2463;
  7930. writeToPLC_Flag1.Value = (short)4;
  7931. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7932. stopwatch1.Stop();
  7933. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7934. return;
  7935. }
  7936. string[] partSNs = cavityData.Split('.');
  7937. if (partSNs != null && partSNs.Length >= 1)
  7938. partNo = partSNs[0];
  7939. #endregion 查询载具上的产品信息
  7940. partNos.Add(partNo);
  7941. }
  7942. }
  7943. // 统一上传 - 调用MES出站
  7944. stopwatch2.Start();
  7945. List<int> results = new List<int>();
  7946. for (int i = 0; i < partNos.Count; i++)
  7947. {
  7948. string index = (i + 1).ToString(); // 弹夹穴号
  7949. if (string.IsNullOrEmpty(partNos[i]))
  7950. results.Add(1);
  7951. else
  7952. {
  7953. List<TestItem> items1 = new List<TestItem>();
  7954. items1.Add(new TestItem()
  7955. {
  7956. Parameter_name = "弹夹码",
  7957. Parameter_value = sn,
  7958. Parameter_unit = ""
  7959. });
  7960. items1.Add(new TestItem()
  7961. {
  7962. Parameter_name = "弹夹穴号",
  7963. Parameter_value = index,
  7964. Parameter_unit = ""
  7965. });
  7966. items1.Add(new TestItem()
  7967. {
  7968. Parameter_name = "载具码",
  7969. Parameter_value = vehicleCodes[i],
  7970. Parameter_unit = ""
  7971. });
  7972. items1.Add(new TestItem()
  7973. {
  7974. Parameter_name = "载具穴号",
  7975. Parameter_value = "1",
  7976. Parameter_unit = ""
  7977. });
  7978. items1.Add(new TestItem()
  7979. {
  7980. Parameter_name = "产品结果",
  7981. Parameter_value = d3Result == 1 ? "OK" : "NG",
  7982. Parameter_unit = ""
  7983. });
  7984. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7985. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  7986. results.Add(result1);
  7987. }
  7988. }
  7989. short result = 0;
  7990. if (results.All(a => a == 1))
  7991. result = 1;
  7992. else if (results.Contains(3))
  7993. result = 3;
  7994. else if (results.Contains(2))
  7995. result = 2;
  7996. else if (results.Contains(4))
  7997. result = 4;
  7998. else
  7999. result = 4;
  8000. stopwatch2.Stop();
  8001. // MES_Flag 为4MES报错
  8002. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8003. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8004. writeToPLC_Flag.Name = "d3MES_FLAG";
  8005. writeToPLC_Flag.Adress = 2463;
  8006. writeToPLC_Flag.Value = result;
  8007. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8008. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8009. }
  8010. catch (Exception ex)
  8011. {
  8012. stopwatch2.Restart();
  8013. // MES_Flag 为4上位机报错
  8014. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  8015. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8016. writeToPLC_Flag.Name = "d3MES_FLAG";
  8017. writeToPLC_Flag.Adress = 2463;
  8018. writeToPLC_Flag.Value = (short)4;
  8019. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8020. string str = ex.StackTrace;
  8021. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8022. stopwatch2.Stop();
  8023. }
  8024. stopwatch1.Stop();
  8025. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8026. }
  8027. // 上次采集到的SN
  8028. //private string sn_S4_4进站接口 = string.Empty;
  8029. /// <summary>
  8030. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  8031. /// </summary>
  8032. private void S4_4进站接口(int plcNo, string stationNameStr)
  8033. {
  8034. Stopwatch stopwatch1 = new Stopwatch();
  8035. Stopwatch stopwatch2 = new Stopwatch();
  8036. try
  8037. {
  8038. stopwatch1.Start();
  8039. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8040. sn = sn.Replace("\0", "");
  8041. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8042. #region 查询15个载具码
  8043. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8044. string vehicleData = string.Empty;
  8045. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8046. if (string.IsNullOrEmpty(vehicleData))
  8047. vehicleData = "";
  8048. if (snResult != 0)
  8049. {
  8050. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8051. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8052. writeToPLC_Flag1.Adress = 2463;
  8053. writeToPLC_Flag1.Value = (short)4;
  8054. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8055. stopwatch1.Stop();
  8056. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8057. return;
  8058. }
  8059. string[] cavitySNs = vehicleData.Split('.');
  8060. if (cavitySNs != null && cavitySNs.Length > 0)
  8061. {
  8062. for (int i = 0; i < cavitySNs.Length; i++)
  8063. {
  8064. if (string.IsNullOrEmpty(cavitySNs[i]))
  8065. vehicleCodes.Add("");
  8066. else
  8067. vehicleCodes.Add(cavitySNs[i]);
  8068. }
  8069. }
  8070. #endregion 查询15个载具码
  8071. #region 查询15个产品SN
  8072. List<string> portNos = new List<string>(); // 15个产品SN
  8073. foreach (string vehicleCode in vehicleCodes)
  8074. {
  8075. if (string.IsNullOrEmpty(vehicleCode))
  8076. portNos.Add("");
  8077. else
  8078. {
  8079. // 查询
  8080. string cavityData = string.Empty;
  8081. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8082. if (string.IsNullOrEmpty(cavityData))
  8083. cavityData = "";
  8084. if (snResult1 != 0)
  8085. {
  8086. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8087. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8088. writeToPLC_Flag1.Adress = 2463;
  8089. writeToPLC_Flag1.Value = (short)4;
  8090. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8091. stopwatch1.Stop();
  8092. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8093. return;
  8094. }
  8095. string[] partSNs = cavityData.Split('.');
  8096. if (partSNs != null && partSNs.Length >= 1)
  8097. portNos.Add(partSNs[0]);
  8098. else
  8099. portNos.Add("");
  8100. }
  8101. }
  8102. #endregion 查询15个产品SN
  8103. // 调用MES进站(最多15个)
  8104. stopwatch2.Start();
  8105. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8106. for (int i = 0; i < vehicleCodes.Count; i++)
  8107. {
  8108. // 循环进站
  8109. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8110. {
  8111. // 产品SN(物料码)校验
  8112. string portNo = portNos[i];
  8113. List<TestItem> item = new List<TestItem>();
  8114. item.Add(new TestItem()
  8115. {
  8116. Parameter_name = "弹夹码",
  8117. Parameter_value = sn,
  8118. });
  8119. item.Add(new TestItem()
  8120. {
  8121. Parameter_name = "弹夹穴位",
  8122. Parameter_value = (i + 1).ToString(),
  8123. });
  8124. item.Add(new TestItem()
  8125. {
  8126. Parameter_name = "载具码",
  8127. Parameter_value = vehicleCodes[i],
  8128. });
  8129. item.Add(new TestItem()
  8130. {
  8131. Parameter_name = "载具穴号",
  8132. Parameter_value = "1",
  8133. });
  8134. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8135. }
  8136. }
  8137. stopwatch2.Stop();
  8138. short result = 0;
  8139. bool haveMesWarn = results.Contains(5);
  8140. bool havePCWarn = results.Contains(6);
  8141. if (haveMesWarn)
  8142. result = 2; // 5->2
  8143. else if (havePCWarn)
  8144. result = 6; // 6->4
  8145. else
  8146. result = 1;
  8147. // MES_Flag 为4MES报错
  8148. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8149. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8150. writeToPLC_Flag.Name = "d4MES_FLAG";
  8151. writeToPLC_Flag.Adress = 2496;
  8152. writeToPLC_Flag.Value = result;
  8153. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8154. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8155. }
  8156. catch (Exception ex)
  8157. {
  8158. stopwatch2.Stop();
  8159. // MES_Flag 为4上位机报错
  8160. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8161. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8162. writeToPLC_Flag.Name = "d4MES_FLAG";
  8163. writeToPLC_Flag.Adress = 2496;
  8164. writeToPLC_Flag.Value = (short)4;
  8165. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8166. string str = ex.StackTrace;
  8167. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8168. }
  8169. stopwatch1.Stop();
  8170. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8171. }
  8172. // 上次采集到的SN
  8173. //private string sn_S4_4出站接口 = string.Empty;
  8174. /// <summary>
  8175. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8176. /// </summary>
  8177. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8178. {
  8179. Stopwatch stopwatch1 = new Stopwatch();
  8180. Stopwatch stopwatch2 = new Stopwatch();
  8181. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8182. string stationNameStr = stationCode + stationName;
  8183. string processItem = stationName; // 测试项目
  8184. try
  8185. {
  8186. stopwatch1.Start();
  8187. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8188. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8189. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8190. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8191. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8192. sn = sn.Replace("\0", "");
  8193. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8194. bool isPass = d4Result == 1; // 产品结果 bool
  8195. #region 查询15个载具码
  8196. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8197. string vehicleData = string.Empty;
  8198. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8199. if (string.IsNullOrEmpty(vehicleData))
  8200. vehicleData = "";
  8201. if (snResult1 != 0)
  8202. {
  8203. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8204. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8205. writeToPLC_Flag1.Adress = 2496;
  8206. writeToPLC_Flag1.Value = (short)4;
  8207. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8208. stopwatch1.Stop();
  8209. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8210. return;
  8211. }
  8212. string[] cavitySNs = vehicleData.Split('.');
  8213. if (cavitySNs != null && cavitySNs.Length > 0)
  8214. {
  8215. for (int i = 0; i < cavitySNs.Length; i++)
  8216. {
  8217. if (string.IsNullOrEmpty(cavitySNs[i]))
  8218. vehicleCodes.Add("");
  8219. else
  8220. vehicleCodes.Add(cavitySNs[i]);
  8221. }
  8222. }
  8223. #endregion 查询15个载具码
  8224. // 统一查 产品SN列表
  8225. List<string> partNos = new List<string>();
  8226. foreach (string vehicleCode in vehicleCodes)
  8227. {
  8228. if (string.IsNullOrEmpty(vehicleCode))
  8229. partNos.Add("");
  8230. else
  8231. {
  8232. string partNo = "";
  8233. #region 查询载具上的产品信息
  8234. string cavityData = string.Empty;
  8235. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8236. if (string.IsNullOrEmpty(cavityData))
  8237. cavityData = "";
  8238. if (snResult != 0)
  8239. {
  8240. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8241. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8242. writeToPLC_Flag1.Adress = 2496;
  8243. writeToPLC_Flag1.Value = (short)4;
  8244. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8245. stopwatch1.Stop();
  8246. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8247. return;
  8248. }
  8249. string[] partSNs = cavityData.Split('.');
  8250. if (partSNs != null && partSNs.Length >= 1)
  8251. partNo = partSNs[0];
  8252. #endregion 查询载具上的产品信息
  8253. partNos.Add(partNo);
  8254. }
  8255. }
  8256. // 调用MES出站
  8257. stopwatch2.Start();
  8258. // 统一上传
  8259. List<int> results = new List<int>();
  8260. for (int i = 0; i < partNos.Count; i++)
  8261. {
  8262. string index = (i + 1).ToString(); // 弹夹穴号
  8263. if (string.IsNullOrEmpty(partNos[i]))
  8264. results.Add(1);
  8265. else
  8266. {
  8267. List<TestItem> items1 = new List<TestItem>();
  8268. items1.Add(new TestItem()
  8269. {
  8270. Parameter_name = "弹夹码",
  8271. Parameter_value = sn,
  8272. Parameter_unit = ""
  8273. });
  8274. items1.Add(new TestItem()
  8275. {
  8276. Parameter_name = "弹夹穴号",
  8277. Parameter_value = index,
  8278. Parameter_unit = ""
  8279. });
  8280. items1.Add(new TestItem()
  8281. {
  8282. Parameter_name = "载具码",
  8283. Parameter_value = vehicleCodes[i],
  8284. Parameter_unit = ""
  8285. });
  8286. items1.Add(new TestItem()
  8287. {
  8288. Parameter_name = "载具穴号",
  8289. Parameter_value = "1",
  8290. Parameter_unit = ""
  8291. });
  8292. items1.Add(new TestItem()
  8293. {
  8294. Parameter_name = "产品结果",
  8295. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8296. Parameter_unit = ""
  8297. });
  8298. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8299. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8300. results.Add(result1);
  8301. }
  8302. }
  8303. short result = 0;
  8304. if (results.All(a => a == 1))
  8305. result = 1;
  8306. else if (results.Contains(3))
  8307. result = 3;
  8308. else if (results.Contains(2))
  8309. result = 2;
  8310. else if (results.Contains(4))
  8311. result = 4;
  8312. else
  8313. result = 4;
  8314. stopwatch2.Stop();
  8315. // MES_Flag 为4MES报错
  8316. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8317. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8318. writeToPLC_Flag.Name = "d4MES_FLAG";
  8319. writeToPLC_Flag.Adress = 2496;
  8320. writeToPLC_Flag.Value = result;
  8321. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8322. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8323. }
  8324. catch (Exception ex)
  8325. {
  8326. stopwatch2.Restart();
  8327. // MES_Flag 为4上位机报错
  8328. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8329. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8330. writeToPLC_Flag.Name = "d4MES_FLAG";
  8331. writeToPLC_Flag.Adress = 2496;
  8332. writeToPLC_Flag.Value = (short)4;
  8333. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8334. string str = ex.StackTrace;
  8335. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8336. stopwatch2.Stop();
  8337. }
  8338. stopwatch1.Stop();
  8339. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8340. }
  8341. /// <summary>
  8342. /// [S4] 取放桁架 - S4_5弹夹扫码
  8343. /// </summary>
  8344. /// <param name="plcNo">PLC编号</param>
  8345. /// <param name="stationNameStr">工站全称</param>
  8346. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8347. {
  8348. Stopwatch stopwatch1 = new Stopwatch();
  8349. Stopwatch stopwatch2 = new Stopwatch();
  8350. try
  8351. {
  8352. stopwatch1.Start();
  8353. // ZS 弹夹扫码
  8354. string d5BulletclipCode = " "; // 扫到的码
  8355. short d5BulletclipScanCode = 2;
  8356. stopwatch2.Start();
  8357. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8358. //// MES_Flag
  8359. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8360. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8361. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8362. writeToPLC_Flag.Adress = 2528;
  8363. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8364. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8365. {
  8366. Name = "d5BulletclipCode",
  8367. Adress = 2529,
  8368. ValueType = PLCValueType.String,
  8369. ValueTypeStrLength = 20,
  8370. Value = d5BulletclipCode
  8371. });
  8372. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8373. stopwatch2.Stop();
  8374. }
  8375. catch (Exception ex)
  8376. {
  8377. string str = ex.StackTrace;
  8378. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8379. stopwatch2.Start();
  8380. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8381. //// MES_Flag
  8382. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8383. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8384. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8385. writeToPLC_Flag.Adress = 2528;
  8386. writeToPLC_Flag.Value = (short)6;
  8387. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8388. {
  8389. Name = "d5BulletclipCode",
  8390. Adress = 2529,
  8391. ValueType = PLCValueType.String,
  8392. ValueTypeStrLength = 20,
  8393. Value = " "
  8394. });
  8395. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8396. stopwatch2.Stop();
  8397. }
  8398. stopwatch1.Stop();
  8399. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8400. }
  8401. /// <summary>
  8402. /// [S4] 取放桁架 - S4_5载具扫码
  8403. /// </summary>
  8404. /// <param name="plcNo">PLC编号</param>
  8405. /// <param name="stationNameStr">工站全称</param>
  8406. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8407. {
  8408. Stopwatch stopwatch1 = new Stopwatch();
  8409. Stopwatch stopwatch2 = new Stopwatch();
  8410. try
  8411. {
  8412. stopwatch1.Start();
  8413. // ZS 载具扫码
  8414. string d5VehicleCode = " "; // 扫到的码
  8415. short d5VehicleScanCode = 2;
  8416. #region 进站
  8417. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8418. {
  8419. // 查产品SN
  8420. #region 查询载具上的产品信息
  8421. string cavityData = string.Empty;
  8422. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8423. if (string.IsNullOrEmpty(cavityData))
  8424. cavityData = "";
  8425. if (snResult != 0)
  8426. {
  8427. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8428. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8429. writeToPLC_Flag1.Adress = 2559;
  8430. writeToPLC_Flag1.Value = (short)6;
  8431. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8432. {
  8433. Name = "d5VehicleCode",
  8434. Adress = 2560,
  8435. ValueType = PLCValueType.String,
  8436. ValueTypeStrLength = 20,
  8437. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8438. });
  8439. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8440. stopwatch1.Stop();
  8441. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8442. return;
  8443. }
  8444. string[] cavitySNs = cavityData.Split('.');
  8445. string partNo = "";
  8446. if (cavitySNs != null && cavitySNs.Length >= 1)
  8447. {
  8448. partNo = cavitySNs[0];
  8449. }
  8450. #endregion 查询载具上的产品信息
  8451. List<TestItem> item = new List<TestItem>();
  8452. item.Add(new TestItem()
  8453. {
  8454. Parameter_name = "载具码",
  8455. Parameter_value = d5VehicleCode,
  8456. });
  8457. item.Add(new TestItem()
  8458. {
  8459. Parameter_name = "载具穴号",
  8460. Parameter_value = "1",
  8461. });
  8462. stopwatch2.Start();
  8463. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8464. stopwatch2.Stop();
  8465. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8466. }
  8467. #endregion 进站
  8468. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8469. //// MES_Flag
  8470. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8471. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8472. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8473. writeToPLC_Flag.Adress = 2559;
  8474. writeToPLC_Flag.Value = d5VehicleScanCode;
  8475. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8476. {
  8477. Name = "d5VehicleCode",
  8478. Adress = 2560,
  8479. ValueType = PLCValueType.String,
  8480. ValueTypeStrLength = 20,
  8481. Value = d5VehicleCode
  8482. });
  8483. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8484. }
  8485. catch (Exception ex)
  8486. {
  8487. string str = ex.StackTrace;
  8488. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8489. stopwatch2.Start();
  8490. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8491. //// MES_Flag
  8492. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8493. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8494. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8495. writeToPLC_Flag.Adress = 2559;
  8496. writeToPLC_Flag.Value = (short)6;
  8497. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8498. {
  8499. Name = "d5VehicleCode",
  8500. Adress = 2560,
  8501. ValueType = PLCValueType.String,
  8502. ValueTypeStrLength = 20,
  8503. Value = " "
  8504. });
  8505. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8506. stopwatch2.Stop();
  8507. }
  8508. stopwatch1.Stop();
  8509. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8510. }
  8511. // 上次采集到的SN
  8512. //private string sn_S4_5出站接口 = string.Empty;
  8513. /// <summary>
  8514. /// [S4] 取放桁架 - S4_5出站接口
  8515. /// </summary>
  8516. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8517. {
  8518. Stopwatch stopwatch1 = new Stopwatch();
  8519. Stopwatch stopwatch2 = new Stopwatch();
  8520. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8521. string stationNameStr = stationCode + stationName;
  8522. string processItem = stationName; // 测试项目
  8523. try
  8524. {
  8525. stopwatch1.Start();
  8526. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8527. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8528. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8529. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8530. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8531. sn = sn.Replace("\0", "");
  8532. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8533. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8534. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8535. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8536. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8537. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8538. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8539. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8540. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8541. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8542. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8543. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8544. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8545. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8546. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8547. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8548. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8549. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8550. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8551. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8552. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8553. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8554. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8555. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8556. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8557. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8558. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8559. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8560. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8561. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8562. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8563. bool pass = d5Result == 1;
  8564. // 存 载具SN列表
  8565. List<string> vehicleCodes = new List<string>()
  8566. {
  8567. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8568. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8569. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8570. };
  8571. // 统一查 产品SN列表
  8572. List<string> partNos = new List<string>();
  8573. foreach (string vehicleCode in vehicleCodes)
  8574. {
  8575. if (string.IsNullOrEmpty(vehicleCode))
  8576. partNos.Add("");
  8577. else
  8578. {
  8579. string partNo = "";
  8580. #region 查询载具上的产品信息
  8581. string cavityData = string.Empty;
  8582. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8583. if (string.IsNullOrEmpty(cavityData))
  8584. cavityData = "";
  8585. if (snResult != 0)
  8586. {
  8587. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8588. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8589. writeToPLC_Flag1.Adress = 2591;
  8590. writeToPLC_Flag1.Value = (short)4;
  8591. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8592. stopwatch1.Stop();
  8593. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8594. return;
  8595. }
  8596. string[] cavitySNs = cavityData.Split('.');
  8597. if (cavitySNs != null && cavitySNs.Length >= 1)
  8598. partNo = cavitySNs[0];
  8599. #endregion 查询载具上的产品信息
  8600. partNos.Add(partNo);
  8601. }
  8602. }
  8603. // 统一上传
  8604. stopwatch2.Start();
  8605. List<int> results = new List<int>();
  8606. for (int i = 0; i < partNos.Count; i++)
  8607. {
  8608. string index = (i + 1).ToString(); // 弹夹穴号
  8609. if (string.IsNullOrEmpty(partNos[i]))
  8610. results.Add(1);
  8611. else
  8612. {
  8613. List<TestItem> items1 = new List<TestItem>();
  8614. items1.Add(new TestItem()
  8615. {
  8616. Parameter_name = "弹夹码",
  8617. Parameter_value = sn,
  8618. Parameter_unit = ""
  8619. });
  8620. items1.Add(new TestItem()
  8621. {
  8622. Parameter_name = "弹夹穴号",
  8623. Parameter_value = index,
  8624. Parameter_unit = ""
  8625. });
  8626. items1.Add(new TestItem()
  8627. {
  8628. Parameter_name = "载具码",
  8629. Parameter_value = vehicleCodes[i],
  8630. Parameter_unit = ""
  8631. });
  8632. items1.Add(new TestItem()
  8633. {
  8634. Parameter_name = "载具穴号",
  8635. Parameter_value = "1",
  8636. Parameter_unit = ""
  8637. });
  8638. items1.Add(new TestItem()
  8639. {
  8640. Parameter_name = "产品结果",
  8641. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8642. Parameter_unit = ""
  8643. });
  8644. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8645. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8646. results.Add(result1);
  8647. }
  8648. }
  8649. short result = 0;
  8650. if (results.All(a => a == 1))
  8651. result = 1;
  8652. else if (results.Contains(3))
  8653. result = 3;
  8654. else if (results.Contains(2))
  8655. result = 2;
  8656. else if (results.Contains(4))
  8657. result = 4;
  8658. else
  8659. result = 4;
  8660. stopwatch2.Stop();
  8661. #region 存储绑定数据到 边线MES系统中
  8662. if (result == 1)
  8663. {
  8664. // 删除绑定信息
  8665. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8666. if (resultMesR != 0)
  8667. {
  8668. result = 4;
  8669. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8670. }
  8671. }
  8672. #endregion 存储绑定数据到 边线MES系统中
  8673. // MES_Flag 为4MES报错
  8674. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8675. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8676. writeToPLC_Flag.Name = "d5MES_FLAG";
  8677. writeToPLC_Flag.Adress = 2591;
  8678. writeToPLC_Flag.Value = result;
  8679. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8680. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8681. }
  8682. catch (Exception ex)
  8683. {
  8684. stopwatch2.Restart();
  8685. // MES_Flag 为4上位机报错
  8686. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8687. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8688. writeToPLC_Flag.Name = "d5MES_FLAG";
  8689. writeToPLC_Flag.Adress = 2591;
  8690. writeToPLC_Flag.Value = (short)4;
  8691. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8692. stopwatch2.Stop();
  8693. string str = ex.StackTrace;
  8694. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8695. }
  8696. stopwatch1.Stop();
  8697. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8698. }
  8699. /// <summary>
  8700. /// [S4] 取放桁架 - S4_5节拍接口
  8701. /// </summary>
  8702. /// <param name="plcNo">PLC编号</param>
  8703. /// <param name="stationNameStr">工站全称</param>
  8704. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8705. {
  8706. Stopwatch stopwatch1 = new Stopwatch();
  8707. Stopwatch stopwatch2 = new Stopwatch();
  8708. string resultStr = string.Empty;
  8709. try
  8710. {
  8711. stopwatch1.Start();
  8712. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8713. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8714. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8715. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8716. if (!actionBool)
  8717. {
  8718. stopwatch2.Start();
  8719. // MES_Flag
  8720. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8721. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8722. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8723. writeToPLC_Flag1.Adress = 2924;
  8724. writeToPLC_Flag1.Value = (short)4;
  8725. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8726. stopwatch2.Stop();
  8727. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8728. return;
  8729. }
  8730. string d5OEEPartNo = string.Empty; // 物料码
  8731. if (string.IsNullOrEmpty(d5OEEProductSN))
  8732. {
  8733. stopwatch2.Start();
  8734. // MES_Flag
  8735. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8736. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8737. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8738. writeToPLC_Flag1.Adress = 2924;
  8739. writeToPLC_Flag1.Value = (short)1;
  8740. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8741. stopwatch2.Stop();
  8742. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8743. return;
  8744. }
  8745. else
  8746. { // 查产品SN
  8747. d5OEEPartNo = "Test"; // ZS
  8748. }
  8749. short d5OEEMES_FLAG = 0;
  8750. // 上传OEE
  8751. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8752. d5OEEMES_FLAG = result.Item1;
  8753. resultStr = result.Item2;
  8754. stopwatch2.Start();
  8755. // MES_Flag
  8756. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8757. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8758. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8759. writeToPLC_Flag.Adress = 2924;
  8760. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8761. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8762. stopwatch2.Stop();
  8763. }
  8764. catch (Exception ex)
  8765. {
  8766. string str = ex.StackTrace;
  8767. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8768. // MES_Flag
  8769. stopwatch2.Start();
  8770. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8771. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8772. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8773. writeToPLC_Flag.Adress = 2924;
  8774. writeToPLC_Flag.Value = (short)4;
  8775. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8776. stopwatch2.Stop();
  8777. }
  8778. stopwatch1.Stop();
  8779. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8780. }
  8781. #endregion [S4] 取放桁架
  8782. #endregion PLC4 刘果段
  8783. #region PLC5 张超凡
  8784. #region [S5] Tray盘下料装备
  8785. /// <summary>
  8786. /// S5工位的数据- 触发信号上次的值
  8787. /// </summary>
  8788. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8789. /// <summary>
  8790. /// S5工位的数据(含触发信号)
  8791. /// </summary>
  8792. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8793. /// <summary>
  8794. /// S5工位的数据- 回写点位
  8795. /// </summary>
  8796. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8797. /// <summary>
  8798. /// [S5] Tray盘下料装备
  8799. /// </summary>
  8800. /// <param name="plcNo">PLC编号</param>
  8801. //private void ReadStation_S5(int plcNo)
  8802. //{
  8803. // // [S1] Tray盘上料装备
  8804. // // [S2] FCT
  8805. // // [S3] 值板机
  8806. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8807. // // [S5] Tray盘下料装备
  8808. // /// 上位机心跳
  8809. // /// 获取设备报警数据与状态信息
  8810. // string stationCode = "[S5]";
  8811. // string stationName = "Tray盘下料装备";
  8812. // string stationNameStr = stationCode + stationName;
  8813. // #region 创建字典
  8814. // // 触发信号字典 赋值
  8815. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8816. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8817. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8818. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8819. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8820. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8821. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8822. // // PLC数据字典 赋值
  8823. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8824. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8825. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8826. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8827. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8828. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8829. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8830. // s5PLCData.Add("e1Result", 0); // 产品结果
  8831. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8832. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8833. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8834. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8835. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8836. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8837. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8838. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8839. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8840. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8841. // #endregion 创建字典
  8842. // while (IsRun)
  8843. // {
  8844. // try
  8845. // {
  8846. // if (!GlobalContext._IsCon_Funs5)
  8847. // {
  8848. // UpdatePLCMonitor(1, plcNo, 0);
  8849. // continue;
  8850. // }
  8851. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8852. // {
  8853. // Stopwatch stopwatch1 = new Stopwatch();
  8854. // Stopwatch stopwatch2 = new Stopwatch();
  8855. // stopwatch1.Start();
  8856. // stopwatch2.Start();
  8857. // #region 一次性读取所有数据
  8858. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8859. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8860. // int[] datas = data1.Concat(data2).ToArray();
  8861. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8862. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8863. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8864. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8865. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8866. // s5PLCData["e1MES_FLAG"] = datas[35];
  8867. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8868. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8869. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8870. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8871. // s5PLCData["e1Result"] = datas[76];
  8872. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8873. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8874. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8875. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8876. // s5PLCData["e1OEEType"] = datas[109];
  8877. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8878. // s5PLCData["e1AGVUpStart"] = datas[121];
  8879. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8880. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8881. // s5PLCData["e1AGVDownStart"] = datas[134];
  8882. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8883. // #endregion 一次性读取所有数据
  8884. // stopwatch2.Stop();
  8885. // #region 回写操作,写后清空flag
  8886. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8887. // #endregion 回写操作,写后清空flag
  8888. // #region 进站校验
  8889. // try
  8890. // {
  8891. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8892. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8893. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  8894. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  8895. // {
  8896. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  8897. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8898. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  8899. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8900. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  8901. // }
  8902. // }
  8903. // catch (Exception ex)
  8904. // {
  8905. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8906. // string str = ex.StackTrace;
  8907. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8908. // }
  8909. // #endregion 进站校验
  8910. // #region 出站接口
  8911. // try
  8912. // {
  8913. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  8914. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  8915. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  8916. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  8917. // {
  8918. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  8919. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8920. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  8921. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  8922. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  8923. // }
  8924. // }
  8925. // catch (Exception ex)
  8926. // {
  8927. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  8928. // string str = ex.StackTrace;
  8929. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8930. // }
  8931. // #endregion 出站接口
  8932. // #region 节拍接口
  8933. // try
  8934. // {
  8935. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  8936. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  8937. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  8938. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  8939. // {
  8940. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  8941. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8942. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  8943. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  8944. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  8945. // }
  8946. // }
  8947. // catch (Exception ex)
  8948. // {
  8949. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  8950. // string str = ex.StackTrace;
  8951. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8952. // }
  8953. // #endregion 节拍接口
  8954. // #region AGV上料
  8955. // // AGV上料叫AGV信号
  8956. // try
  8957. // {
  8958. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  8959. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  8960. // if (e1AGVUpCall != e1AGVUpCallOld)
  8961. // {
  8962. // if (e1AGVUpCall == 1) // 0->1
  8963. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  8964. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  8965. // }
  8966. // }
  8967. // catch (Exception ex)
  8968. // {
  8969. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  8970. // string str = ex.StackTrace;
  8971. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8972. // }
  8973. // // AGV上料完成信号
  8974. // try
  8975. // {
  8976. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  8977. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  8978. // if (e1AGVUpEnd != e1AGVUpEndOld)
  8979. // {
  8980. // if (e1AGVUpEnd == 1) // 0->1
  8981. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  8982. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  8983. // }
  8984. // }
  8985. // catch (Exception ex)
  8986. // {
  8987. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  8988. // string str = ex.StackTrace;
  8989. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8990. // }
  8991. // #endregion AGV上料
  8992. // #region AGV下料
  8993. // // AGV下料叫agv信号
  8994. // try
  8995. // {
  8996. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  8997. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  8998. // if (e1AGVDownCall != e1AGVDownCallOld)
  8999. // {
  9000. // if (e1AGVDownCall == 1) // 0->1
  9001. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  9002. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  9003. // }
  9004. // }
  9005. // catch (Exception ex)
  9006. // {
  9007. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9008. // string str = ex.StackTrace;
  9009. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9010. // }
  9011. // // AGV下料完成信号
  9012. // try
  9013. // {
  9014. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  9015. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  9016. // if (e1AGVDownEnd != e1AGVDownEndOld)
  9017. // {
  9018. // if (e1AGVDownEnd == 1) // 0->1
  9019. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  9020. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  9021. // }
  9022. // }
  9023. // catch (Exception ex)
  9024. // {
  9025. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9026. // string str = ex.StackTrace;
  9027. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9028. // }
  9029. // #endregion AGV下料
  9030. // #region 心跳
  9031. // try
  9032. // {
  9033. // short states = 0;
  9034. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9035. // }
  9036. // catch (Exception ex)
  9037. // {
  9038. // string str = ex.StackTrace;
  9039. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9040. // }
  9041. // #endregion 心跳
  9042. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9043. // stopwatch1.Stop();
  9044. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9045. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9046. // }
  9047. // else
  9048. // {
  9049. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9050. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9051. // Funs[plcNo].Connect();
  9052. // }
  9053. // }
  9054. // catch (Exception ex)
  9055. // {
  9056. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9057. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9058. // Funs[plcNo].ReConnect();
  9059. // }
  9060. // Thread.Sleep(IntervalReadPLC);
  9061. // }
  9062. //}
  9063. /// <summary>
  9064. /// [S5] Tray盘下料装备 - 进站校验
  9065. /// </summary>
  9066. /// <param name="plcNo">PLC编号</param>
  9067. /// <param name="stationNameStr">工站全称</param>
  9068. private void S5进站校验(int plcNo, string stationNameStr)
  9069. {
  9070. Stopwatch stopwatch1 = new Stopwatch();
  9071. Stopwatch stopwatch2 = new Stopwatch();
  9072. try
  9073. {
  9074. stopwatch1.Start();
  9075. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9076. sn = sn.Replace("\0", "");
  9077. // 获取产品SN By 载具码
  9078. #region 查询载具上的产品信息
  9079. string cavityData = string.Empty;
  9080. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9081. if (string.IsNullOrEmpty(cavityData))
  9082. cavityData = "";
  9083. if (snResult != 0)
  9084. {
  9085. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9086. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9087. writeToPLC_Flag1.Adress = 2003;
  9088. writeToPLC_Flag1.Value = (short)6;
  9089. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9090. stopwatch1.Stop();
  9091. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9092. return;
  9093. }
  9094. string[] cavitySNs = cavityData.Split('.');
  9095. string partNo = string.Empty;
  9096. if (cavitySNs != null && cavitySNs.Length >= 1)
  9097. partNo = cavitySNs[0];
  9098. #endregion 查询载具上的产品信息
  9099. // 产品SN(物料码)校验
  9100. List<TestItem> item = new List<TestItem>();
  9101. item.Add(new TestItem()
  9102. {
  9103. Parameter_name = "载具码",
  9104. Parameter_value = sn,
  9105. });
  9106. item.Add(new TestItem()
  9107. {
  9108. Parameter_name = "载具穴号",
  9109. Parameter_value = "1",
  9110. });
  9111. stopwatch2.Start();
  9112. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9113. stopwatch2.Stop();
  9114. short e1MES_FLAG_Check = (short)result;
  9115. // MES_Flag
  9116. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9117. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9118. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9119. writeToPLC_Flag.Adress = 2003;
  9120. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9121. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9122. }
  9123. catch (Exception ex)
  9124. {
  9125. string str = ex.StackTrace;
  9126. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9127. // MES_Flag
  9128. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9129. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9130. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9131. writeToPLC_Flag.Adress = 2003;
  9132. writeToPLC_Flag.Value = (short)6;
  9133. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9134. }
  9135. stopwatch1.Stop();
  9136. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9137. }
  9138. /// <summary>
  9139. /// [S5] Tray盘下料装备 - 出站接口
  9140. /// </summary>
  9141. /// <param name="plcNo"></param>
  9142. /// <param name="stationCode"></param>
  9143. /// <param name="stationName"></param>
  9144. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9145. {
  9146. Stopwatch stopwatch1 = new Stopwatch();
  9147. Stopwatch stopwatch2 = new Stopwatch();
  9148. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9149. string stationNameStr = stationCode + stationName;
  9150. string processItem = stationName; // 测试项目
  9151. try
  9152. {
  9153. stopwatch1.Start();
  9154. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9155. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9156. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9157. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9158. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9159. sn = sn.Replace("\0", "");
  9160. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9161. //partNo = partNo.Replace("\0", "");
  9162. #region 查询载具上的产品信息
  9163. string cavityData = string.Empty;
  9164. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9165. if (string.IsNullOrEmpty(cavityData))
  9166. cavityData = "";
  9167. if (snResult != 0)
  9168. {
  9169. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9170. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9171. writeToPLC_Flag1.Adress = 2035;
  9172. writeToPLC_Flag1.Value = (short)4;
  9173. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9174. stopwatch1.Stop();
  9175. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9176. return;
  9177. }
  9178. string[] cavitySNs = cavityData.Split('.');
  9179. string partNo = string.Empty;
  9180. if (cavitySNs != null && cavitySNs.Length >= 1)
  9181. partNo = cavitySNs[0];
  9182. #endregion 查询载具上的产品信息
  9183. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9184. bool pass = e1Result == 1;
  9185. stopwatch2.Start();
  9186. // 上传MES
  9187. List<TestItem> items = new List<TestItem>();
  9188. items.Add(new TestItem()
  9189. {
  9190. Parameter_name = "载具码",
  9191. Parameter_value = sn,
  9192. Parameter_unit = ""
  9193. });
  9194. items.Add(new TestItem()
  9195. {
  9196. Parameter_name = "载具穴号",
  9197. Parameter_value = "1",
  9198. Parameter_unit = ""
  9199. });
  9200. items.Add(new TestItem()
  9201. {
  9202. Parameter_name = "产品结果",
  9203. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9204. Parameter_unit = ""
  9205. });
  9206. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  9207. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9208. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9209. short result = result1 == 1 ? (short)1 : (short)3;
  9210. stopwatch2.Stop();
  9211. #region 存储绑定数据到 边线MES系统中
  9212. if (result == 1)
  9213. {
  9214. // 删除绑定信息
  9215. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9216. if (resultMesR != 0)
  9217. {
  9218. result = 4;
  9219. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9220. }
  9221. }
  9222. #endregion 存储绑定数据到 边线MES系统中
  9223. // MES_Flag 为MES报错
  9224. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9225. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9226. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9227. writeToPLC_Flag.Name = "e1MES_FLAG";
  9228. writeToPLC_Flag.Adress = 2035;
  9229. writeToPLC_Flag.Value = result;
  9230. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9231. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9232. }
  9233. catch (Exception ex)
  9234. {
  9235. stopwatch2.Restart();
  9236. // MES_Flag 为4上位机报错
  9237. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9238. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9239. writeToPLC_Flag.Name = "e1MES_FLAG";
  9240. writeToPLC_Flag.Adress = 2035;
  9241. writeToPLC_Flag.Value = (short)4;
  9242. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9243. stopwatch2.Stop();
  9244. string str = ex.StackTrace;
  9245. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9246. }
  9247. stopwatch1.Stop();
  9248. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9249. }
  9250. /// <summary>
  9251. /// [S5] Tray盘下料装备 - 节拍接口
  9252. /// </summary>
  9253. /// <param name="plcNo">PLC编号</param>
  9254. /// <param name="stationNameStr">工站全称</param>
  9255. private void S5节拍接口(int plcNo, string stationNameStr)
  9256. {
  9257. Stopwatch stopwatch1 = new Stopwatch();
  9258. Stopwatch stopwatch2 = new Stopwatch();
  9259. string resultStr = string.Empty;
  9260. try
  9261. {
  9262. stopwatch1.Start();
  9263. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9264. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9265. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9266. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9267. if (!actionBool)
  9268. {
  9269. stopwatch2.Start();
  9270. // MES_Flag
  9271. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9272. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9273. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9274. writeToPLC_Flag1.Adress = 2088;
  9275. writeToPLC_Flag1.Value = (short)4;
  9276. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9277. stopwatch2.Stop();
  9278. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9279. return;
  9280. }
  9281. string e1OEEPartNo = string.Empty; // 物料码
  9282. if (string.IsNullOrEmpty(e1OEEProductSN))
  9283. {
  9284. stopwatch2.Start();
  9285. // MES_Flag
  9286. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9287. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9288. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9289. writeToPLC_Flag1.Adress = 2088;
  9290. writeToPLC_Flag1.Value = (short)1;
  9291. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9292. stopwatch2.Stop();
  9293. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9294. return;
  9295. }
  9296. else
  9297. { // 查产品SN
  9298. e1OEEPartNo = "Test"; // ZS
  9299. }
  9300. short e1OEEMES_FLAG = 0;
  9301. // 上传OEE
  9302. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9303. e1OEEMES_FLAG = result.Item1;
  9304. resultStr = result.Item2;
  9305. stopwatch2.Start();
  9306. // MES_Flag
  9307. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9308. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9309. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9310. writeToPLC_Flag.Adress = 2088;
  9311. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9312. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9313. stopwatch2.Stop();
  9314. }
  9315. catch (Exception ex)
  9316. {
  9317. string str = ex.StackTrace;
  9318. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9319. // MES_Flag
  9320. stopwatch2.Start();
  9321. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9322. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9323. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9324. writeToPLC_Flag.Adress = 2088;
  9325. writeToPLC_Flag.Value = (short)4;
  9326. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9327. stopwatch2.Stop();
  9328. }
  9329. stopwatch1.Stop();
  9330. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9331. }
  9332. /// <summary>
  9333. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9334. /// </summary>
  9335. /// <param name="plcNo">PLC编号</param>
  9336. /// <param name="stationNameStr">工站全称</param>
  9337. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9338. {
  9339. Stopwatch stopwatch1 = new Stopwatch();
  9340. Stopwatch stopwatch2 = new Stopwatch();
  9341. try
  9342. {
  9343. stopwatch1.Start();
  9344. // ZS 呼叫AGV
  9345. short e1AGVUpCall = 2;
  9346. stopwatch2.Start();
  9347. // e1AGVUpCall
  9348. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9349. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9350. writeToPLC_Flag.Name = "e1AGVUpCall";
  9351. writeToPLC_Flag.Adress = 2120;
  9352. writeToPLC_Flag.Value = e1AGVUpCall;
  9353. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9354. stopwatch2.Stop();
  9355. }
  9356. catch (Exception ex)
  9357. {
  9358. string str = ex.StackTrace;
  9359. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9360. // e1AGVUpCall
  9361. stopwatch2.Start();
  9362. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9363. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9364. writeToPLC_Flag.Name = "e1AGVUpCall";
  9365. writeToPLC_Flag.Adress = 2120;
  9366. writeToPLC_Flag.Value = (short)4;
  9367. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9368. stopwatch2.Stop();
  9369. }
  9370. stopwatch1.Stop();
  9371. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9372. }
  9373. /// <summary>
  9374. /// [S5] Tray盘下料装备 - AGV上料完成
  9375. /// </summary>
  9376. /// <param name="plcNo">PLC编号</param>
  9377. /// <param name="stationNameStr">工站全称</param>
  9378. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9379. {
  9380. Stopwatch stopwatch1 = new Stopwatch();
  9381. Stopwatch stopwatch2 = new Stopwatch();
  9382. try
  9383. {
  9384. stopwatch1.Start();
  9385. // ZS AGV上料完成,让小车离开
  9386. short e1AGVUpEnd = 2;
  9387. stopwatch2.Start();
  9388. // e1AGVUpEnd
  9389. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9390. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9391. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9392. writeToPLC_Flag.Adress = 2122;
  9393. writeToPLC_Flag.Value = e1AGVUpEnd;
  9394. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9395. stopwatch2.Stop();
  9396. }
  9397. catch (Exception ex)
  9398. {
  9399. string str = ex.StackTrace;
  9400. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9401. // e1AGVUpEnd
  9402. stopwatch2.Start();
  9403. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9404. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9405. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9406. writeToPLC_Flag.Adress = 2122;
  9407. writeToPLC_Flag.Value = (short)4;
  9408. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9409. stopwatch2.Stop();
  9410. }
  9411. stopwatch1.Stop();
  9412. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9413. }
  9414. /// <summary>
  9415. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9416. /// </summary>
  9417. /// <param name="plcNo">PLC编号</param>
  9418. /// <param name="stationNameStr">工站全称</param>
  9419. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9420. {
  9421. Stopwatch stopwatch1 = new Stopwatch();
  9422. Stopwatch stopwatch2 = new Stopwatch();
  9423. try
  9424. {
  9425. stopwatch1.Start();
  9426. // ZS 呼叫AGV
  9427. short e1AGVDownCall = 2;
  9428. stopwatch2.Start();
  9429. // e1AGVDownCall
  9430. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9431. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9432. writeToPLC_Flag.Name = "e1AGVDownCall";
  9433. writeToPLC_Flag.Adress = 2133;
  9434. writeToPLC_Flag.Value = e1AGVDownCall;
  9435. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9436. stopwatch2.Stop();
  9437. }
  9438. catch (Exception ex)
  9439. {
  9440. string str = ex.StackTrace;
  9441. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9442. // e1AGVDownCall
  9443. stopwatch2.Start();
  9444. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9445. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9446. writeToPLC_Flag.Name = "e1AGVDownCall";
  9447. writeToPLC_Flag.Adress = 2133;
  9448. writeToPLC_Flag.Value = (short)4;
  9449. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9450. stopwatch2.Stop();
  9451. }
  9452. stopwatch1.Stop();
  9453. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9454. }
  9455. /// <summary>
  9456. /// [S5] Tray盘下料装备 - AGV下料完成
  9457. /// </summary>
  9458. /// <param name="plcNo">PLC编号</param>
  9459. /// <param name="stationNameStr">工站全称</param>
  9460. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9461. {
  9462. Stopwatch stopwatch1 = new Stopwatch();
  9463. Stopwatch stopwatch2 = new Stopwatch();
  9464. try
  9465. {
  9466. stopwatch1.Start();
  9467. // ZS AGV上料完成,让小车离开
  9468. short e1AGVDownEnd = 2;
  9469. stopwatch2.Start();
  9470. // e1AGVDownEnd
  9471. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9472. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9473. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9474. writeToPLC_Flag.Adress = 2135;
  9475. writeToPLC_Flag.Value = e1AGVDownEnd;
  9476. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9477. stopwatch2.Stop();
  9478. }
  9479. catch (Exception ex)
  9480. {
  9481. string str = ex.StackTrace;
  9482. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9483. // e1AGVDownEnd
  9484. stopwatch2.Start();
  9485. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9486. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9487. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9488. writeToPLC_Flag.Adress = 2135;
  9489. writeToPLC_Flag.Value = (short)4;
  9490. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9491. stopwatch2.Stop();
  9492. }
  9493. stopwatch1.Stop();
  9494. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9495. }
  9496. #endregion [S5] Tray盘下料装备
  9497. #endregion PLC5 张超凡
  9498. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9499. /// <summary>
  9500. /// PLC读取到的数据 -添加数据
  9501. /// </summary>
  9502. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9503. {
  9504. if (sxPlcData.ContainsKey(newKey))
  9505. sxPlcData[newKey] = newValue;
  9506. else
  9507. sxPlcData.Add(newKey, newValue);
  9508. }
  9509. /// <summary>
  9510. /// PLC需要写入的数据 -添加数据
  9511. /// </summary>
  9512. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9513. {
  9514. if (sxPLCWriteData.ContainsKey(newKey))
  9515. sxPLCWriteData[newKey] = newValue;
  9516. else
  9517. sxPLCWriteData.Add(newKey, newValue);
  9518. }
  9519. /// <summary>
  9520. /// PLC回写操作,写后清空flag
  9521. /// </summary>
  9522. /// <param name="modbusClient">modbus对象</param>
  9523. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9524. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9525. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9526. {
  9527. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9528. {
  9529. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9530. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9531. {
  9532. string mesFlagName = pLCWriteDatas[i].Name;
  9533. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9534. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9535. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9536. {
  9537. // 先回写数据
  9538. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9539. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9540. {
  9541. int mesDataAdress = writeToPLCDatas[j].Adress;
  9542. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9543. switch (mesDataType)
  9544. {
  9545. case PLCValueType.Short:
  9546. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9547. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9548. break;
  9549. case PLCValueType.String:
  9550. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9551. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9552. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9553. break;
  9554. }
  9555. }
  9556. // 再回写信号
  9557. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9558. // 存储读取数据的字典
  9559. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9560. // 存储写入数据的字典 - 清空写入值
  9561. pLCWriteDatas[i].Value = (short)0;
  9562. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9563. }
  9564. }
  9565. }
  9566. }
  9567. /// <summary>
  9568. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9569. /// </summary>
  9570. /// <param name="no">3</param>
  9571. /// <param name="stationCode">设备编号</param>
  9572. /// <param name="stationNameStr">设备名称</param>
  9573. /// <param name="plcOrder">车间订单号</param>
  9574. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9575. {
  9576. try
  9577. {
  9578. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9579. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9580. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9581. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9582. int result1 = 0;
  9583. switch (stationCode)
  9584. {
  9585. case 2:
  9586. case 3:
  9587. case 4:
  9588. case 6:
  9589. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9590. break;
  9591. case 102:
  9592. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9593. break;
  9594. case 103:
  9595. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9596. break;
  9597. case 104:
  9598. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9599. break;
  9600. case 106:
  9601. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9602. break;
  9603. default:
  9604. // MES_Flag 为“6未找到正确设备编号”
  9605. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9606. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9607. return;
  9608. }
  9609. short result = result1 == 1 ? (short)1 : (short)2;
  9610. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9611. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9612. }
  9613. catch (Exception ex)
  9614. {
  9615. // MES_Flag 为2上位机报错
  9616. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9617. string str = ex.StackTrace;
  9618. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9619. }
  9620. }
  9621. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9622. #region UI刷新
  9623. /// <summary>
  9624. /// 更新商品信息的UI + 下发产品信息(SN)
  9625. /// </summary>
  9626. private void UpdateProductInfo()
  9627. {
  9628. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9629. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9630. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9631. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9632. }
  9633. /// <summary>
  9634. /// 更新PLC连接状态的UI
  9635. /// </summary>
  9636. /// <param name="no">PLC编号</param>
  9637. /// <param name="status">状态</param>
  9638. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9639. {
  9640. if (this != null && !this.IsDisposed)
  9641. {
  9642. switch (imgNo)
  9643. {
  9644. case 1:
  9645. this.BeginInvoke(new Action(() =>
  9646. {
  9647. picPLC.Image = imageListState.Images[status];
  9648. }));
  9649. break;
  9650. case 2:
  9651. this.BeginInvoke(new Action(() =>
  9652. {
  9653. pictureBox2.Image = imageListState.Images[status];
  9654. }));
  9655. break;
  9656. case 3:
  9657. this.BeginInvoke(new Action(() =>
  9658. {
  9659. pictureBox3.Image = imageListState.Images[status];
  9660. }));
  9661. break;
  9662. case 4:
  9663. this.BeginInvoke(new Action(() =>
  9664. {
  9665. pictureBox4.Image = imageListState.Images[status];
  9666. }));
  9667. break;
  9668. case 5:
  9669. this.BeginInvoke(new Action(() =>
  9670. {
  9671. pictureBox5.Image = imageListState.Images[status];
  9672. }));
  9673. break;
  9674. case 6:
  9675. this.BeginInvoke(new Action(() =>
  9676. {
  9677. pictureBox6.Image = imageListState.Images[status];
  9678. }));
  9679. break;
  9680. case 7:
  9681. this.BeginInvoke(new Action(() =>
  9682. {
  9683. pictureBox7.Image = imageListState.Images[status];
  9684. }));
  9685. break;
  9686. case 8:
  9687. this.BeginInvoke(new Action(() =>
  9688. {
  9689. pictureBox8.Image = imageListState.Images[status];
  9690. }));
  9691. break;
  9692. default:
  9693. break;
  9694. }
  9695. }
  9696. Task.Run(() => // 更新PLC交互页的指示灯
  9697. {
  9698. try
  9699. {
  9700. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9701. {
  9702. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9703. }
  9704. }
  9705. catch { }
  9706. });
  9707. }
  9708. #endregion UI刷新
  9709. #region 日志
  9710. /// <summary>
  9711. /// 添加各工位运行日志(同步至PLC交互页面)
  9712. /// </summary>
  9713. /// <param name="stationNameStr">工站名称</param>
  9714. /// <param name="logType">日志类型</param>
  9715. /// <param name="message">日志内容</param>
  9716. /// <param name="snNumber">产品数字SN</param>
  9717. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9718. {
  9719. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9720. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9721. ))
  9722. {
  9723. AddMessage(logType, message); // 首页展示+日志记录
  9724. }
  9725. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9726. {
  9727. StationName = stationNameStr,
  9728. SnNumber = snNumber,
  9729. Message = message,
  9730. CreateTime = DateTime.Now
  9731. };
  9732. // PLC交互页展示
  9733. Task.Run(() =>
  9734. {
  9735. try
  9736. {
  9737. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9738. {
  9739. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9740. }
  9741. }
  9742. catch { }
  9743. });
  9744. }
  9745. /// <summary>
  9746. /// 添加运行日志
  9747. /// </summary>
  9748. /// <param name="logType">日志类型</param>
  9749. /// <param name="message">日志内容</param>
  9750. public void AddMessage(LogType logType, string message)
  9751. {
  9752. OnMessage(logType, message);
  9753. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9754. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9755. string msgShow = time + "--> " + message + "\r\n";
  9756. this.BeginInvoke(new Action(() =>
  9757. {
  9758. systemLog.Rows.Insert(0, date, time, message);
  9759. if (systemLog.Rows.Count >= 100)
  9760. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9761. }));
  9762. }
  9763. /// <summary>
  9764. /// 添加运行日志-保存
  9765. /// </summary>
  9766. /// <param name="logType">日志类型</param>
  9767. /// <param name="message">日志内容</param>
  9768. private void OnMessage(LogType logType, string msg)
  9769. {
  9770. MessageEvent?.Invoke(logType, msg);
  9771. }
  9772. /// <summary>
  9773. /// 保存PLC写入日志
  9774. /// </summary>
  9775. /// <param name="logType"></param>
  9776. /// <param name="logValue"></param>
  9777. private void WritePLCLog(LogType logType, string logValue)
  9778. {
  9779. switch ((int)logType)
  9780. {
  9781. case 0:
  9782. _PLCLogNet.WriteDebug(logValue);
  9783. break;
  9784. case 1:
  9785. _PLCLogNet.WriteInfo(logValue);
  9786. break;
  9787. case 2:
  9788. _PLCLogNet.WriteWarn(logValue);
  9789. break;
  9790. case 3:
  9791. _PLCLogNet.WriteError(logValue);
  9792. break;
  9793. default:
  9794. _PLCLogNet.WriteFatal(logValue);
  9795. break;
  9796. }
  9797. }
  9798. /// <summary>
  9799. /// IOT Mqtt回调方法- With DataId
  9800. /// </summary>
  9801. /// <param name="id"></param>
  9802. /// <param name="v"></param>
  9803. /// <param name="dataId"></param>
  9804. public void CallbackWithDataId(string id, string msg, string dataId)
  9805. {
  9806. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9807. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9808. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9809. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9810. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9811. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9812. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9813. }
  9814. /// <summary>
  9815. /// AGV Mqtt回调方法- 记录Log并处理数据
  9816. /// </summary>
  9817. /// <param name="obj"></param>
  9818. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9819. {
  9820. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9821. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9822. // 接收到的信息
  9823. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9824. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9825. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9826. {
  9827. }
  9828. }
  9829. #endregion 日志
  9830. /// <summary>
  9831. /// 实例化报警字典
  9832. /// </summary>
  9833. private void InitalDicAlarm()
  9834. {
  9835. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9836. List<Alarm> keyValues1 = new List<Alarm>
  9837. {
  9838. #region 第一组报警(电机)
  9839. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9840. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9841. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9842. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9843. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9844. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9845. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9846. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9847. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9848. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9849. #endregion 第一组报警(电机)
  9850. #region 第二组报警(气缸)
  9851. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9852. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9853. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9854. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9855. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9856. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9857. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9858. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9859. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9860. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9861. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9862. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9863. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9864. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9865. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9866. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9867. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9868. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9869. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9870. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9871. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9872. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9873. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9874. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9875. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9876. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9877. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9878. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9879. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9880. #endregion 第二组报警(气缸)
  9881. #region 第三组报警(其他故障)
  9882. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9883. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9884. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9885. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9886. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9887. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9888. #endregion 第三组报警(其他故障)
  9889. };
  9890. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9891. #endregion 第一个工站(这里使用线体代替工位)
  9892. # region 第二个工站-原来的写法(废弃)
  9893. //keyValues = new Dictionary<int, AlarmData[]>();
  9894. ////1
  9895. //dicAlarmName = new Dictionary<int, Alarm>();
  9896. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  9897. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  9898. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  9899. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  9900. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  9901. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9902. //for (int i = 0; i < dicAlarmName.Count; i++)
  9903. //{
  9904. // alarmDatas[i] = new AlarmData();
  9905. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9906. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9907. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9908. // alarmDatas[i].AlarmType = 1;
  9909. //}
  9910. //keyValues.Add(1, alarmDatas);
  9911. ////2
  9912. //dicAlarmName = new Dictionary<int, Alarm>();
  9913. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  9914. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  9915. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  9916. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  9917. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  9918. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  9919. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  9920. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  9921. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9922. //for (int i = 0; i < dicAlarmName.Count; i++)
  9923. //{
  9924. // alarmDatas[i] = new AlarmData();
  9925. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9926. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9927. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9928. // alarmDatas[i].AlarmType = 2;
  9929. //}
  9930. //keyValues.Add(2, alarmDatas);
  9931. ////3
  9932. //dicAlarmName = new Dictionary<int, Alarm>();
  9933. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  9934. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  9935. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  9936. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  9937. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9938. //for (int i = 0; i < dicAlarmName.Count; i++)
  9939. //{
  9940. // alarmDatas[i] = new AlarmData();
  9941. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  9942. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9943. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9944. // alarmDatas[i].AlarmType = 3;
  9945. //}
  9946. //keyValues.Add(3, alarmDatas);
  9947. //DicAlarms.Add(2, keyValues);
  9948. #endregion 第二个工站-原来的写法(废弃)
  9949. }
  9950. private void button1_Click(object sender, EventArgs e)
  9951. {
  9952. string stationCode = "[OP40]";
  9953. string stationName = "胶线检测";
  9954. OP40_MesData_t OP40_MesData_t = new OP40_MesData_t();
  9955. OP40_MesData_t.BarcodeSet.strCarrierBarcode = "AAA111";
  9956. OP40_MesData_t.BarcodeSet.strProductBarcode = "CP20250217001";
  9957. SaveDBbyFileInfo(OP40_MesData_t, stationCode, stationName);
  9958. }
  9959. }
  9960. }