Form_Home.cs 586 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. /*
  40. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  41. */
  42. namespace MainForm
  43. {
  44. /// <summary>
  45. /// 记录日志的委托
  46. /// </summary>
  47. /// <param name="logType">日志类型</param>
  48. /// <param name="message">日志信息</param>
  49. public delegate void HomeMessageHandler(LogType logType, string message);
  50. /// <summary>
  51. /// 主页窗体
  52. /// </summary>
  53. public partial class Form_Home : Form
  54. {
  55. #region 常量
  56. //文本常量
  57. private const string Head = "开始采集";
  58. private const string Tail = "采集完成";
  59. private const string Body = "工位出站数据";
  60. private const string BodyCheck = "工位点检数据";
  61. private const string BodyRun = "整线运行数据";
  62. private const string BodyAlarm = "整线报警数据";
  63. #endregion 常量
  64. #region 变量
  65. /// <summary>
  66. /// 委托-记录日志的方法
  67. /// </summary>
  68. public event HomeMessageHandler MessageEvent;
  69. /// <summary>
  70. /// 日志接口
  71. /// </summary>
  72. ILogNet _PLCLogNet;
  73. /// <summary>
  74. /// 用于记录IOT MQTT日志
  75. /// </summary>
  76. ILogNet _IOTMqttLogNet;
  77. /// <summary>
  78. /// 用于记录AGV MQTT日志
  79. /// </summary>
  80. ILogNet _AGVMqttLogNet;
  81. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  82. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  83. // 间隔时间
  84. private int IntervalReadPLC = 300; //ms 读PLC
  85. private int IntervalMonitorMES = 1000; //ms MES心跳
  86. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  87. // 软件状态
  88. private bool IsRun = true;
  89. #region PLC 与 TCP对象
  90. // 定义一个字典,存plc对象(通讯)
  91. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  92. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  93. // 定义TCPClient对象列表
  94. Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  95. // 定义MQTTHelper对象
  96. MQTTHelper _MQTTHelper = new MQTTHelper();
  97. #endregion PLC 与 TCP对象
  98. /// <summary>
  99. /// 上次的设备运行信息
  100. /// </summary>
  101. private string lineWorkingData1_OldStr = string.Empty;
  102. /// <summary>
  103. /// 设备报警字典-当前结果
  104. /// Dictionary<工位代码,List<报警信息>>
  105. /// </summary>
  106. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  107. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  108. #endregion 变量
  109. #region 窗体基础事件
  110. /// <summary>
  111. /// 初始化
  112. /// </summary>
  113. public Form_Home()
  114. {
  115. InitializeComponent();
  116. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  117. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  118. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  119. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  120. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  121. }
  122. /// <summary>
  123. /// 窗体加载事件
  124. /// </summary>
  125. private void Form_Home_Load(object sender, EventArgs e)
  126. {
  127. try
  128. {
  129. AddMessage(LogType.Info, "开始初始化程序");
  130. InitalDicAlarm(); // 实例化报警字典
  131. //组建plc对象字典
  132. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  133. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  134. if (GlobalContext.IsUsePLC1)
  135. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  136. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  137. if (GlobalContext.IsUsePLC2)
  138. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  139. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  140. if (GlobalContext.IsUsePLC3)
  141. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  142. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  143. if (GlobalContext.IsUsePLC4)
  144. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  145. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  146. if (GlobalContext.IsUsePLC5)
  147. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  148. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  149. if (GlobalContext.IsUsePLC6)
  150. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  151. if (GlobalContext.IsUsePLC7)
  152. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  153. if (GlobalContext.IsUsePLC8)
  154. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  155. if (GlobalContext.IsUsePLC9)
  156. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  157. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  158. {
  159. if (plcEIP != null)
  160. {
  161. try
  162. {
  163. (int, string) result = plcEIP.Connect();
  164. }
  165. catch (Exception ex)
  166. {
  167. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  168. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  169. }
  170. }
  171. }
  172. /*
  173. //plc1Alarm.Connect();
  174. foreach (ModbusClientHelper modbusClient in Funs.Values)
  175. {
  176. if (modbusClient != null)
  177. {
  178. try
  179. {
  180. modbusClient.Connect();
  181. }
  182. catch (Exception ex)
  183. {
  184. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  185. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  186. }
  187. }
  188. }
  189. */
  190. // 采集任务
  191. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  192. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  193. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  194. if (GlobalContext.IsUsePLC1)
  195. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  196. if (GlobalContext.IsUsePLC2)
  197. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  198. if (GlobalContext.IsUsePLC3)
  199. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  200. if (GlobalContext.IsUsePLC4)
  201. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  202. if (GlobalContext.IsUsePLC5)
  203. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  204. if (GlobalContext.IsUsePLC6)
  205. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  206. if (GlobalContext.IsUsePLC7)
  207. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  208. if (GlobalContext.IsUsePLC8)
  209. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  210. if (GlobalContext.IsUsePLC9)
  211. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  212. #region 初始化
  213. try
  214. {
  215. // 开启边线MES(绑定/查询数据)
  216. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  217. //if (mesRoute == 0)
  218. //{
  219. // //picMESStatus.Image = imageListState.Images[1];
  220. // //GlobalContext.MESIsConnect = true;
  221. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  222. //}
  223. //else
  224. //{
  225. // //picMESStatus.Image = imageListState.Images[0];
  226. // //GlobalContext.MESIsConnect = false;
  227. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  228. //}
  229. // 开启MES(Http)
  230. if (GlobalContext.IsUseMES)
  231. {
  232. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  233. if (mesret)
  234. {
  235. picMESStatus.Image = imageListState.Images[1];
  236. GlobalContext.MESIsConnect = true;
  237. AddMessage(LogType.Info, "小米MES初始连接成功!");
  238. }
  239. else
  240. {
  241. picMESStatus.Image = imageListState.Images[0];
  242. GlobalContext.MESIsConnect = false;
  243. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  244. }
  245. }
  246. // 开启IOT(MQTT)
  247. if (GlobalContext.IsUseIot)
  248. {
  249. string addr = GlobalContext.MQTTServerHost;
  250. int port = GlobalContext.MQTTServerPort;
  251. //生产环境需要修改
  252. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, 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. // 设置回调函数
  259. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  260. // 配置参数
  261. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  262. // fds
  263. param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
  264. param.parameter.fds.appId = "Auto-Soft";
  265. param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
  266. // mes
  267. param.parameter.mes.address = GlobalContext.ServerIp;
  268. param.parameter.mes.appId = GlobalContext.MESAppId;
  269. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  270. // mqtt
  271. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  272. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  273. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  274. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  275. // 设备配置
  276. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  277. if (GlobalContext.IsUsePLC1)
  278. {
  279. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  280. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  281. }
  282. if (GlobalContext.IsUsePLC2)
  283. {
  284. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  285. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  286. }
  287. if (GlobalContext.IsUsePLC3)
  288. {
  289. param.parameter.equipment.deviceCode = GlobalContext.S3_device_code; // 装备编码
  290. param.parameter.equipment.stationCode = GlobalContext.S3_station; // ⼯位Id
  291. }
  292. if (GlobalContext.IsUsePLC4)
  293. {
  294. param.parameter.equipment.deviceCode = GlobalContext.S4_1_device_code; // 装备编码
  295. param.parameter.equipment.stationCode = GlobalContext.S4_1_station; // ⼯位Id
  296. }
  297. if (GlobalContext.IsUsePLC5)
  298. {
  299. param.parameter.equipment.deviceCode = GlobalContext.S5_device_code; // 装备编码
  300. param.parameter.equipment.stationCode = GlobalContext.S5_station; // ⼯位Id
  301. }
  302. if (GlobalContext.IsUsePLC6)
  303. {
  304. param.parameter.equipment.deviceCode = GlobalContext.S6_device_code; // 装备编码
  305. param.parameter.equipment.stationCode = GlobalContext.S6_station; // ⼯位Id
  306. }
  307. if (GlobalContext.IsUsePLC7)
  308. {
  309. param.parameter.equipment.deviceCode = GlobalContext.S7_device_code; // 装备编码
  310. param.parameter.equipment.stationCode = GlobalContext.S7_station; // ⼯位Id
  311. }
  312. if (GlobalContext.IsUsePLC8)
  313. {
  314. param.parameter.equipment.deviceCode = GlobalContext.S8_device_code; // 装备编码
  315. param.parameter.equipment.stationCode = GlobalContext.S8_station; // ⼯位Id
  316. }
  317. if (GlobalContext.IsUsePLC9)
  318. {
  319. param.parameter.equipment.deviceCode = GlobalContext.S9_device_code; // 装备编码
  320. param.parameter.equipment.stationCode = GlobalContext.S9_station; // ⼯位Id
  321. }
  322. param.parameter.equipment.project = GlobalContext.Project_Code;
  323. param.parameter.equipment.productMode = "debug";
  324. //
  325. param.parameter.other.logLevel = 0;
  326. param.parameter.other.LogPath = "D:\\Test";
  327. XiaomiMqttClient_Extend.ParameterConfig(param);
  328. }
  329. else
  330. {
  331. picIot.Image = imageListState.Images[0];
  332. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  333. }
  334. }
  335. // 开启AGV(Http与MQTT)
  336. if (GlobalContext.IsUseAGV)
  337. {
  338. // AGV HTTP
  339. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  340. if (mesret1)
  341. {
  342. picAgvHttp.Image = imageListState.Images[1];
  343. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  344. }
  345. else
  346. {
  347. picAgvHttp.Image = imageListState.Images[0];
  348. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  349. }
  350. string agvMqttIp = GlobalContext.MQTTServerHost;
  351. int agvMqttPort = GlobalContext.MQTTServerPort;
  352. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  353. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  354. // AGV MQTT
  355. if (result_MQTT.ResultCode == 1)
  356. {
  357. picAgvMqtt.Image = imageListState.Images[1];
  358. GlobalContext.AGVMQTTIsConnect = true;
  359. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  360. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  361. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  362. }
  363. else
  364. {
  365. picAgvMqtt.Image = imageListState.Images[0];
  366. GlobalContext.AGVMQTTIsConnect = false;
  367. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  368. }
  369. }
  370. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  371. Task.Run(MonitorMESConnect);
  372. // 查询PLC连接状态
  373. foreach (int plcNo in FunsEip.Keys)
  374. {
  375. bool connected = FunsEip[plcNo].IsConnected;
  376. if (connected)
  377. {
  378. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  379. AddMessage(LogType.Info, msg);
  380. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  381. }
  382. else
  383. {
  384. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  385. AddMessage(LogType.Info, msg);
  386. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  387. }
  388. }
  389. // PLC4时 初始化扫码器TCP
  390. //if (GlobalContext.IsUsePLC4)
  391. // HpTCPClientInit();
  392. // 开启PLC的业务处理线程-监听PLC点位+状态
  393. foreach (Task task in TaskReadProcess)
  394. {
  395. if (task != null)
  396. task.Start();
  397. }
  398. //// 开启“获取线体报警数据”的线程
  399. //TaskReadAlarm.Start();
  400. ////下传MES信息给1工位(先判断下plc对象数量)
  401. //if (Funs.Count > 1)
  402. // DownLoadProductInfo(1);
  403. AddMessage(LogType.Info, "程序初始化完成");
  404. }
  405. catch (Exception ex)
  406. {
  407. string str = ex.StackTrace;
  408. this.BeginInvoke(new Action(() =>
  409. {
  410. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  411. }));
  412. }
  413. #endregion
  414. }
  415. catch (Exception ex)
  416. {
  417. string str = ex.StackTrace;
  418. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  419. if (ex.Message != null && ex.Message.Contains("timed out"))
  420. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  421. else
  422. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  423. }
  424. }
  425. /// <summary>
  426. /// 窗体关闭事件
  427. /// </summary>
  428. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  429. {
  430. Closed2();
  431. }
  432. public void Closed2()
  433. {
  434. try
  435. {
  436. IsRun = false;
  437. Thread.Sleep(IntervalReadPLC);
  438. // 断开TCP
  439. int count = _HPSocket_TcpClients.Count();
  440. for (int i = 0; i < count; i++)
  441. {
  442. try
  443. {
  444. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  445. {
  446. _HPSocket_TcpClients[i].Stop();
  447. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  448. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  449. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  450. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  451. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  452. }
  453. }
  454. catch { }
  455. }
  456. // 关闭Iot
  457. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  458. // 关闭AGV Mqtt
  459. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  460. }
  461. catch { }
  462. }
  463. #endregion 窗体基础事件
  464. #region 监控MES状态
  465. /// <summary>
  466. /// 监控MES连接状态
  467. /// </summary>
  468. private void MonitorMESConnect()
  469. {
  470. while (IsRun) // 运行被控线程
  471. {
  472. try
  473. {
  474. // 开启MES(Http)
  475. if (GlobalContext.IsUseMES)
  476. {
  477. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  478. if (mesret)
  479. {
  480. picMESStatus.Image = imageListState.Images[1];
  481. GlobalContext.MESIsConnect = true;
  482. }
  483. else
  484. {
  485. picMESStatus.Image = imageListState.Images[0];
  486. GlobalContext.MESIsConnect = false;
  487. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  488. }
  489. }
  490. // 开启IOT(MQTT)
  491. if (GlobalContext.IsUseIot)
  492. {
  493. bool iIot = XiaomiMqttClient.IsOpen;
  494. if (iIot)
  495. picIot.Image = imageListState.Images[1];
  496. else
  497. {
  498. picIot.Image = imageListState.Images[0];
  499. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  500. }
  501. }
  502. // 开启AGV(Http与MQTT)
  503. if (GlobalContext.IsUseAGV)
  504. {
  505. // AGV Http
  506. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  507. if (mesret1)
  508. picAgvHttp.Image = imageListState.Images[1];
  509. else
  510. {
  511. picAgvHttp.Image = imageListState.Images[0];
  512. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  513. }
  514. // AGV MQTT
  515. if (GlobalContext.AGVMQTTIsConnect)
  516. picAgvMqtt.Image = imageListState.Images[1];
  517. else
  518. {
  519. picAgvMqtt.Image = imageListState.Images[0];
  520. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  521. }
  522. }
  523. }
  524. catch (Exception ex)
  525. {
  526. string str = ex.StackTrace;
  527. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  528. }
  529. Thread.Sleep(IntervalMonitorMES);
  530. }
  531. }
  532. #endregion 监控MES连接状态
  533. #region 采集设备状态、运行数据、报警数据
  534. /// <summary>
  535. /// 请求设备状态 5000
  536. /// </summary>
  537. /// <param name="no">1</param>
  538. /// <param name="stationNameStr"></param>
  539. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  540. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  541. {
  542. try
  543. {
  544. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  545. {
  546. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  547. return result;
  548. }
  549. else
  550. {
  551. return 0;
  552. }
  553. }
  554. catch (Exception ex)
  555. {
  556. string str = ex.StackTrace;
  557. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  558. return 0;
  559. }
  560. }
  561. /// <summary>
  562. /// 检查是否可采集点检数据 - 不取新值
  563. /// 5000不为1时可点检
  564. /// </summary>
  565. /// <returns></returns>
  566. public bool CheckCanSpotcheck1(int deviceState)
  567. {
  568. //return true;
  569. //D5000 = 1,代表设备控制状态处于运行状态
  570. //D5000 = 2, 代表设备控制状态处于故障状态
  571. //D5000 = 3,代表设备控制状态处于缺料状态
  572. //D5000 = 4, 代表设备控制状态处于待机状态
  573. //D5000 = 5,代表设备控制状态处于维修状态
  574. return deviceState != 1;
  575. }
  576. /// <summary>
  577. /// 检查是否可采集产品数据 - 不取新值
  578. /// </summary>
  579. /// <returns></returns>
  580. public bool CheckCanCollData(int deviceState)
  581. {
  582. return deviceState == 0; // 点检时该值不为0
  583. }
  584. /// <summary>
  585. /// 获取设备报警数据与获取设备运行信息
  586. /// </summary>
  587. private async void ReadAlarmAllPLC()
  588. {
  589. // [S1] Tray盘上料装备(板测)
  590. // [S2] FCT(板测)
  591. // [S3] 值板机
  592. // [S4] 取放桁架
  593. // [S5] Tray盘下料装备
  594. /// 上位机心跳
  595. /// 获取设备报警数据与状态信息
  596. string stationNameStr = "获取设备报警数据与状态信息";
  597. while (IsRun)
  598. {
  599. try
  600. {
  601. if (!GlobalContext._IsCon_plc1Alarm)
  602. {
  603. UpdatePLCMonitor(1, -2, 0);
  604. continue;
  605. }
  606. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  607. {
  608. DateTime dtNow = DateTime.Now;
  609. #region 获取设备运行信息
  610. try
  611. {
  612. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  613. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  614. lineWorkingData1.LineName = GlobalContext.LineCode;
  615. //
  616. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  617. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  618. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  619. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  620. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  621. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  622. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  623. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  624. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  625. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  626. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  627. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  628. lineWorkingData1.CreateTime = DateTime.Now;
  629. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  630. // UI展示-展示到设备状态页
  631. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  632. {
  633. // 查询数据库最新一条数据,确定是不是更新
  634. string qSql = @"SELECT top(1) [GUID]
  635. ,[LineName]
  636. ,[BootTimeLong]
  637. ,[NormalTimeLong]
  638. ,[StandbyTimeLong]
  639. ,[FaultTimeLong]
  640. ,[MaterialShortageTimeLong]
  641. ,[MaintenanceTimeLong]
  642. ,[FaultNumber]
  643. ,[OutputNumber]
  644. ,[QualifiedNumber]
  645. ,[QualifiedRate]
  646. ,[DesignRhythm]
  647. ,[RealityRhythm]
  648. ,[CreateTime]
  649. FROM [LineWorkingData]
  650. where [CreateTime] > '{0}'
  651. and [LineName]='{1}'
  652. order by [CreateTime] desc
  653. ";
  654. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  655. var ds = SQLHelper_New.Query(qSql, null);
  656. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  657. {
  658. var dataDBlast = new LineWorkingData_ThisTime();
  659. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  660. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  661. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  662. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  663. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  664. {
  665. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  666. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  667. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  668. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  669. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  670. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  671. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  672. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  673. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  674. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  675. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  676. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  677. string usql = dataDBlast.ToStringUpdate();
  678. SQLHelper_New.ExecuteSQL(usql, null);
  679. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  680. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  681. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  682. }
  683. }
  684. else
  685. {
  686. // 插入
  687. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  688. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  689. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  690. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  691. }
  692. }
  693. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  694. {
  695. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  696. //// 本次开机设备运行情况
  697. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  698. //Task.Run(() =>
  699. //{
  700. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  701. // {
  702. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  703. // }
  704. //});
  705. // 本日设备运行情况
  706. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  707. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  708. {
  709. // 更新
  710. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  711. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  712. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  713. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  714. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  715. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  716. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  717. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  718. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  719. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  720. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  721. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  722. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  723. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  724. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  725. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  726. }
  727. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  728. {
  729. // 插入
  730. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  731. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  732. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  733. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  734. }
  735. await Task.Run(() =>
  736. {
  737. try
  738. {
  739. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  740. {
  741. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  742. }
  743. }
  744. catch { }
  745. });
  746. }
  747. }
  748. catch (Exception ex)
  749. {
  750. string str = ex.StackTrace;
  751. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  752. }
  753. #endregion 获取设备运行信息
  754. #region 报警数据
  755. try
  756. {
  757. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  758. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  759. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  760. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  761. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  762. {
  763. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  764. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  765. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  766. {
  767. isNeedUpdUI = true; // 需要更新历史报警UI信息
  768. // 记录
  769. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  770. switch (dicAlarms_Cur_PLC1[i].是否报警)
  771. {
  772. case true: // 报警
  773. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  774. {
  775. GUID = Guid.NewGuid().ToString(),
  776. LineName = GlobalContext.LineCode, // 线体
  777. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  778. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  779. StartTime = dtNow // 开始时间
  780. };
  781. // 传输到页面
  782. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  783. {
  784. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  785. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  786. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  787. 开始时间 = dtNow
  788. });
  789. // 新增到数据库
  790. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  791. SaveAlarmDataByDB(stationNameStr, data1, false);
  792. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  793. break;
  794. case false: // 消除报警
  795. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  796. {
  797. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  798. {
  799. GUID = Guid.NewGuid().ToString(),
  800. LineName = GlobalContext.LineCode, // 线体
  801. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  802. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  803. StartTime = dtNow, // 开始时间
  804. EndTime = dtNow, // 开始时间
  805. PersistTime = 1, // 耗时1s
  806. };
  807. // 新增
  808. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  809. SaveAlarmDataByDB(stationNameStr, data2, false);
  810. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  811. }
  812. else
  813. {
  814. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  815. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  816. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  817. // 修改
  818. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  819. SaveAlarmDataByDB(stationNameStr, data3, true);
  820. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  821. }
  822. break;
  823. default:
  824. break;
  825. }
  826. }
  827. }
  828. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  829. // 有新报警则更新
  830. if (isNeedUpdUI)
  831. {
  832. // UI展示 - 展示到设备状态页
  833. await Task.Run(() =>
  834. {
  835. try
  836. {
  837. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  838. {
  839. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  840. if (Form_Main.formDevAlarm.Visible)
  841. {
  842. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  843. }
  844. }
  845. }
  846. catch { }
  847. });
  848. }
  849. }
  850. catch (Exception ex)
  851. {
  852. string str = ex.StackTrace;
  853. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  854. }
  855. #endregion 报警数据
  856. UpdatePLCMonitor(1, -2, 1);
  857. }
  858. else
  859. {
  860. UpdatePLCMonitor(1, -2, 0);
  861. }
  862. }
  863. catch (Exception ex)
  864. {
  865. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  866. }
  867. Thread.Sleep(IntervalAlarm);
  868. }
  869. }
  870. #endregion 轮询PLC
  871. #region 下发订单信息
  872. ///// <summary>
  873. ///// 壳体上料(下发工单)的交互逻辑
  874. ///// </summary>
  875. ///// <param name="no"></param>
  876. ///// <exception cref="NotImplementedException"></exception>
  877. //private void ReadStation_DownOrderInfo(int plcNo)
  878. //{
  879. // // [S1] Tray盘上料装备(板测)
  880. // // [S2] FCT(板测)
  881. // // [S3] 值板机
  882. // // [S4] 取放桁架
  883. // // [S5] Tray盘下料装备
  884. // /// 上位机心跳
  885. // /// 获取设备报警数据与状态信息
  886. // string stationNameStr = "[S0]壳体上料";
  887. // while (IsRun)
  888. // {
  889. // try
  890. // {
  891. // if (!GlobalContext._IsCon_Funs1)
  892. // {
  893. // UpdatePLCMonitor(plcNo, 0);
  894. // continue;
  895. // }
  896. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  897. // {
  898. // #region 壳体上料(下发工单)
  899. // try
  900. // {
  901. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  902. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  903. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  904. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  905. // // 重置数据和信号
  906. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  907. // {
  908. // // 清空写给PLC的数据
  909. // int[] i497 = new int[1] { 0 };
  910. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  911. // // MES_Flag重置为0
  912. // int[] i500 = new int[1] { 0 };
  913. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  914. // }
  915. // }
  916. // catch (Exception ex)
  917. // {
  918. // string str = ex.StackTrace;
  919. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  920. // }
  921. // #endregion 壳体上料(下发工单)
  922. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  923. // }
  924. // else
  925. // {
  926. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  927. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  928. //
  929. // Funs[plcNo].Connect();
  930. // }
  931. // }
  932. // catch (Exception ex)
  933. // {
  934. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  935. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  936. //
  937. // Funs[plcNo].ReConnect();
  938. // }
  939. // Thread.Sleep(IntervalReadPLC);
  940. // }
  941. //}
  942. ///// <summary>
  943. ///// 下发订单信息到PLC
  944. ///// </summary>
  945. ///// <param name="no">PLC编号</param>
  946. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  947. //{
  948. // try
  949. // {
  950. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  951. // {
  952. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  953. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  954. // }
  955. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  956. // }
  957. // catch (Exception ex)
  958. // {
  959. // string str = ex.StackTrace;
  960. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  961. // }
  962. //}
  963. /// <summary>
  964. /// 下发清料信号
  965. /// </summary>
  966. /// <param name="no">PLC编号</param>
  967. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  968. {
  969. try
  970. {
  971. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  972. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  973. return true;
  974. }
  975. catch (Exception ex)
  976. {
  977. string str = ex.StackTrace;
  978. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  979. return false;
  980. }
  981. }
  982. #endregion 下发订单信息
  983. #region Xiaomi 贲流
  984. #region 公共方法
  985. private static bool ProgressState = false;
  986. private static readonly object lockObj = new object(); // 锁对象
  987. private static bool isCollectingFlagLeft;
  988. private static bool isCollectingFlagRight;
  989. /// <summary>
  990. /// float[]转为string
  991. /// </summary>
  992. public string FloatArrayToString(float[] nScrewResults)
  993. {
  994. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  995. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  996. }
  997. /// <summary>
  998. /// short[]转为string
  999. /// </summary>
  1000. public string ShortArrayToString(short[] nScrewResults)
  1001. {
  1002. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1003. return string.Join(",", nScrewResults);
  1004. }
  1005. /// <summary>
  1006. /// 写入PLC重复三次
  1007. /// </summary>
  1008. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  1009. {
  1010. int i = 0;
  1011. int nRet = 0;
  1012. string strRet = "";
  1013. try
  1014. {
  1015. while (i < 3) // 最多上传三次
  1016. {
  1017. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1018. if (nRet == 0) //成功
  1019. {
  1020. break;
  1021. }
  1022. else
  1023. {
  1024. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1025. i++;
  1026. }
  1027. }
  1028. return (nRet, strRet);
  1029. }
  1030. catch (Exception ex)
  1031. {
  1032. return (1, ex.Message);
  1033. }
  1034. }
  1035. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  1036. {
  1037. try
  1038. {
  1039. // 获取当前日期
  1040. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1041. // 构建保存路径
  1042. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1043. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  1044. // 确保目录存在
  1045. Directory.CreateDirectory(savePath);
  1046. // 文件名
  1047. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1048. string filePath = Path.Combine(savePath, fileName);
  1049. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1050. int count = Math.Min(14, fScrewTimes.Length);
  1051. using (StreamWriter sw = new StreamWriter(filePath))
  1052. {
  1053. for (int i = 0; i < count; i++)
  1054. {
  1055. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1056. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1057. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1058. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1059. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1060. }
  1061. }
  1062. return (0, "");
  1063. }
  1064. catch (Exception ex)
  1065. {
  1066. return (1, ex.Message);
  1067. }
  1068. }
  1069. public Dictionary<string, string> GetLastLineCompensation(string path,string direction,string sn)
  1070. {
  1071. // 创建字典存储补偿点及其对应的值
  1072. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1073. try
  1074. {
  1075. //string path = GlobalContext.MESLaserRPath;
  1076. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1077. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1078. string filename = $"Laser-{currentDate}-W0.txt";
  1079. // 拼接完整路径
  1080. string fullPath = Path.Combine(path, filename);
  1081. string lastNonEmptyLine = "";
  1082. // 判断文件是否存在
  1083. if (File.Exists(fullPath))
  1084. {
  1085. //读取文件内容
  1086. string[] lines = File.ReadAllLines(fullPath);
  1087. // 获取最后一行数据(忽略标题行)
  1088. if (lines.Length > 1)
  1089. {
  1090. string lastLine = "";
  1091. for (int i = lines.Length - 1; i > 0; i--)
  1092. {
  1093. if (!string.IsNullOrEmpty(lines[i]))
  1094. {
  1095. lastLine = lines[i];
  1096. break;
  1097. }
  1098. }
  1099. // 将最后一行按逗号分隔
  1100. string[] values = lastLine.Split(',');
  1101. values[1] = sn;
  1102. string key = "三点激光_"+ direction; // 构造键名
  1103. string value = string.Join(",", values); // 获取值并去除多余空格
  1104. compensationDict[key] = value;
  1105. //// 提取“1点补偿”到“6点补偿”的值
  1106. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1107. //{
  1108. // string key = $"{i - 1}点补偿"; // 构造键名
  1109. // string value = values[i].Trim(); // 获取值并去除多余空格
  1110. // compensationDict[key] = value;
  1111. //}
  1112. }
  1113. }
  1114. else
  1115. {
  1116. Console.WriteLine($"文件不存在: {fullPath}");
  1117. }
  1118. }
  1119. catch (Exception ex)
  1120. {
  1121. // 捕获异常并输出错误信息
  1122. Console.WriteLine($"发生错误: {ex.Message}");
  1123. }
  1124. return compensationDict;
  1125. }
  1126. /// <summary>
  1127. /// 调用进站接口并保存进站数据
  1128. /// </summary>
  1129. /// <param name="stationNameStr">工站信息</param>
  1130. /// <param name="workorder_code">工单号</param>
  1131. /// <param name="mtltmrk">型号(物料号)</param>
  1132. /// <param name="sn">产品SN</param>
  1133. /// <param name="items">进站数据</param>
  1134. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1135. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1136. {
  1137. int result = 0;
  1138. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1139. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1140. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1141. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1142. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1143. inRequest_Body.unitSn = sn; // 产品SN
  1144. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1145. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1146. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1147. StationIn stationIn = new StationIn()
  1148. {
  1149. Workorder_code = workorder_code, // 车间订单号
  1150. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1151. Sn = sn, // SN
  1152. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1153. Parameter_values = items, // 进站数据
  1154. Write_user = inRequest_Body.userId, // 员工Id
  1155. Test_time = inRequest_Body.clientTime // 进站时间
  1156. };
  1157. // 本地数据
  1158. string sql = stationIn.ToStringInsert(0);
  1159. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1160. result = ret == "成功" ? 1 : 6;
  1161. //await Task.Delay(200);
  1162. // 上传MES
  1163. if (GlobalContext.IsSendStationIn)
  1164. {
  1165. try
  1166. {
  1167. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1168. string mesRet = string.Empty;
  1169. int i = 0;
  1170. while (i < 2) // 1009会多次尝试上传
  1171. {
  1172. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1173. if (response != null && response.header.code == "200")
  1174. break;
  1175. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1176. i++;
  1177. i++;
  1178. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1179. // 记录失败原因
  1180. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1181. }
  1182. if (response?.header?.code == "200")
  1183. {
  1184. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1185. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1186. result = ret_Upd == "成功" ? 1 : 6;
  1187. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1188. }
  1189. else
  1190. {
  1191. result = 5;
  1192. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1193. }
  1194. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1195. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1196. }
  1197. catch (Exception ex)
  1198. {
  1199. result = 6;
  1200. string str = ex.StackTrace;
  1201. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1202. }
  1203. }
  1204. return result;
  1205. }
  1206. /// <summary>
  1207. /// 选择如何记录出站数据
  1208. /// </summary>
  1209. /// <param name="items">出站数据</param>
  1210. /// <param name="equipmentCode">设备编号</param>
  1211. /// <param name="processItem">测试项目</param>
  1212. /// <param name="workorder_code">车间订单号</param>
  1213. /// <param name="batch_num">批次号</param>
  1214. /// <param name="mtltmrk">型号</param>
  1215. /// <param name="proDate">日期</param>
  1216. /// <param name="supplierCode">供应商代码</param>
  1217. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1218. /// <returns>上传成功时返回1;失败返回0</returns>
  1219. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1220. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1221. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode,string direction="")
  1222. {
  1223. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1224. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, direction);
  1225. }
  1226. /// <summary>
  1227. /// 添加出站数据(提交到MES+本地保存到数据库)
  1228. /// </summary>
  1229. /// <param name="items">出站数据</param>
  1230. /// <param name="equipmentCode">设备编号</param>
  1231. /// <param name="processItem">测试项目</param>
  1232. /// <param name="workorder_code">车间订单号</param>
  1233. /// <param name="batch_num">批次号</param>
  1234. /// <param name="mtltmrk">型号</param>
  1235. /// <param name="proDate">日期</param>
  1236. /// <param name="supplierCode">供应商代码</param>
  1237. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1238. /// <returns>上传成功时返回1;失败返回0</returns>
  1239. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1240. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1241. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode,string direction="")
  1242. {
  1243. int upload = 0;
  1244. int result = 0;
  1245. ProcessData processData = new ProcessData()
  1246. {
  1247. Equipment_code = equipmentCode,
  1248. Workorder_code = workorder_code,
  1249. Batch_number = batch_num,
  1250. Sn = sn, // SN
  1251. Testitem = processItem,
  1252. Parameter_values = items,
  1253. Write_user = GlobalContext.CurrentUser,
  1254. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1255. };
  1256. // 本地数据
  1257. string sql = processData.ToStringInsert(upload);
  1258. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1259. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1260. // 上传MES
  1261. if (GlobalContext.IsSendProcessData)
  1262. {
  1263. try
  1264. {
  1265. string id = processData.ID.Copy();
  1266. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1267. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1268. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1269. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1270. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1271. outRequest_Body.unitSn = sn; // 产品SN
  1272. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1273. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1274. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1275. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1276. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1277. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1278. if (!string.IsNullOrEmpty(partBarcode))
  1279. {
  1280. outRequest_Body.unitData.keyMaterial.Add(
  1281. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1282. {
  1283. bindSort = 1,
  1284. materialSn = partBarcode
  1285. }); // 设备数据 - 部件码
  1286. }
  1287. //OP30站读txt数据
  1288. if (stationNameStr.Contains("OP30"))
  1289. {
  1290. string path = "";
  1291. if (direction == "Left")
  1292. path = GlobalContext.MESLaserLPath;
  1293. else
  1294. path= GlobalContext.MESLaserRPath;
  1295. //字典存储数据
  1296. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction,sn);
  1297. foreach (var kvp in compensationDict)
  1298. {
  1299. outRequest_Body.unitData.processData.Add(
  1300. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1301. {
  1302. dataName = kvp.Key.ToString(),
  1303. dataValue = kvp.Value.ToString()
  1304. });
  1305. }
  1306. }
  1307. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1308. if (GlobalContext.IsSendProcessData)
  1309. {
  1310. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1311. string mesRet = string.Empty;
  1312. int i = 0;
  1313. while (i < 2) // 1009会多次尝试上传
  1314. {
  1315. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1316. if (response != null && response.header.code == "200")
  1317. {
  1318. OnMessage(LogType.Error, "上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" + JsonConvert.SerializeObject(response.body));
  1319. break;
  1320. }
  1321. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1322. i++;
  1323. i++;
  1324. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1325. // 记录失败原因
  1326. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1327. }
  1328. if (response?.header?.code == "200")
  1329. {
  1330. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1331. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1332. result = 1;
  1333. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1334. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1335. }
  1336. else
  1337. {
  1338. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1339. }
  1340. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1341. JsonConvert.SerializeObject(response), id);
  1342. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1343. }
  1344. }
  1345. catch (Exception ex)
  1346. {
  1347. string str = ex.StackTrace;
  1348. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1349. }
  1350. }
  1351. return result;
  1352. }
  1353. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1354. //{
  1355. // Stopwatch stopwatch = new Stopwatch();
  1356. // stopwatch.Start();
  1357. // try
  1358. // {
  1359. // // 初始化 AtlasScrew 实例
  1360. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1361. // atlasScrew1.Initial();
  1362. // // 存储结果的列表
  1363. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1364. // // 存储角度和扭力的字符串列表
  1365. // List<string> angleStrs = new List<string>();
  1366. // List<string> torqueStrs = new List<string>();
  1367. // // 上一次获取的数据
  1368. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1369. // while (isExitAtlasLeft) // 检查是否收集数据
  1370. // {
  1371. // // 获取当前数据
  1372. // var currentResult = atlasScrew1.GetResults();
  1373. // // 判断是否为新数据
  1374. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1375. // {
  1376. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1377. // // 更新角度和扭力的字符串列表
  1378. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1379. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1380. // // 计算角度、扭力、起始扭力和最大扭力
  1381. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1382. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1383. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1384. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1385. // // 将新数据添加到结果列表
  1386. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1387. // // 更新上一次获取的数据
  1388. // lastResult = currentResult;
  1389. // }
  1390. // // 等待一段时间后再次检查
  1391. // Thread.Sleep(20); // 轮询间隔时间
  1392. // // 如果触发了出站,则退出循环
  1393. // if (!isExitAtlasLeft)
  1394. // {
  1395. // break;
  1396. // }
  1397. // }
  1398. // // 生成文件名
  1399. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1400. // // 写入数据到文件
  1401. // using (StreamWriter writer = new StreamWriter(fileName))
  1402. // {
  1403. // // 写入标题行
  1404. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1405. // // 写入每一行数据
  1406. // foreach (var result in results)
  1407. // {
  1408. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1409. // }
  1410. // }
  1411. // stopwatch.Stop();
  1412. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1413. // }
  1414. // catch (Exception ex)
  1415. // {
  1416. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1417. // }
  1418. // finally
  1419. // {
  1420. // // 重置标志变量
  1421. // isExitAtlasLeft = false;
  1422. // }
  1423. //}
  1424. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1425. //{
  1426. // Stopwatch stopwatch = new Stopwatch();
  1427. // stopwatch.Start();
  1428. // try
  1429. // {
  1430. // // 初始化 AtlasScrew 实例
  1431. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1432. // atlasScrew2.Initial();
  1433. // // 存储结果的列表
  1434. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1435. // // 上一次获取的数据
  1436. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1437. // while (isExitAtlasRight) // 检查是否收集数据
  1438. // {
  1439. // // 获取当前数据
  1440. // var currentResult = atlasScrew2.GetResults();
  1441. // // 判断是否为新数据
  1442. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1443. // {
  1444. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1445. // // 将新数据写入PLC
  1446. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1447. // // 将新数据添加到结果列表
  1448. // results.Add(currentResult);
  1449. // // 更新上一次获取的数据
  1450. // lastResult = currentResult;
  1451. // }
  1452. // // 等待一段时间后再次检查
  1453. // Thread.Sleep(20); // 轮询间隔时间
  1454. // // 如果触发了出站,则退出循环
  1455. // if (!isExitAtlasRight)
  1456. // {
  1457. // break;
  1458. // }
  1459. // }
  1460. // // 将所有数据写入文件
  1461. // //WriteDataToFile(sn, direction, results);
  1462. // stopwatch.Stop();
  1463. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1464. // }
  1465. // catch (Exception ex)
  1466. // {
  1467. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1468. // }
  1469. // finally
  1470. // {
  1471. // // 重置标志变量
  1472. // isExitAtlasRight = false;
  1473. // }
  1474. //}
  1475. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1476. {
  1477. Stopwatch stopwatch = new Stopwatch();
  1478. stopwatch.Start();
  1479. int nRet = 0;
  1480. string strRet = "";
  1481. try
  1482. {
  1483. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1484. while (isCollectingFlagLeft)
  1485. {
  1486. // 从缓存中获取所有未处理的数据
  1487. var cachedData = atlasScrew.GetCachedDataLeft();
  1488. foreach (var currentResult in cachedData)
  1489. {
  1490. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1491. {
  1492. continue; // 跳过无效数据
  1493. }
  1494. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1495. // 写入PLC
  1496. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1497. {
  1498. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1499. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1500. };
  1501. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1502. if (nRet != 0)
  1503. {
  1504. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1505. }
  1506. else
  1507. {
  1508. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1509. }
  1510. // 构建保存路径
  1511. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1512. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1513. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1514. Directory.CreateDirectory(savePath); // 确保目录存在
  1515. // 构建文件名(以 SN + 序号命名)
  1516. string fileName = $"{sn}_{fileCounter}.txt";
  1517. string filePath = Path.Combine(savePath, fileName);
  1518. // 写入文件
  1519. using (StreamWriter writer = new StreamWriter(filePath))
  1520. {
  1521. writer.WriteLine("精度, 扭力");
  1522. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1523. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1524. {
  1525. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1526. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1527. writer.WriteLine($"{precision}, {torque}");
  1528. }
  1529. }
  1530. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1531. // 增加文件计数器
  1532. fileCounter++;
  1533. }
  1534. // 如果没有更多数据,则短暂休眠以节省资源
  1535. if (!cachedData.Any())
  1536. {
  1537. Thread.Sleep(10); // 根据需要调整休眠时间
  1538. }
  1539. // 如果触发了出站,则退出循环
  1540. if (!isCollectingFlagLeft)
  1541. {
  1542. break;
  1543. }
  1544. }
  1545. stopwatch.Stop();
  1546. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1547. }
  1548. catch (Exception ex)
  1549. {
  1550. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1551. }
  1552. finally
  1553. {
  1554. isCollectingFlagLeft = false;
  1555. }
  1556. }
  1557. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1558. {
  1559. Stopwatch stopwatch = new Stopwatch();
  1560. stopwatch.Start();
  1561. int nRet = 0;
  1562. string strRet = "";
  1563. try
  1564. {
  1565. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1566. while (isCollectingFlagRight)
  1567. {
  1568. // 从缓存中获取所有未处理的数据
  1569. var cachedData = atlasScrew.GetCachedDataLeft();
  1570. foreach (var currentResult in cachedData)
  1571. {
  1572. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1573. {
  1574. continue; // 跳过无效数据
  1575. }
  1576. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1577. // 写入PLC
  1578. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1579. {
  1580. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1581. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1582. };
  1583. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1584. if (nRet != 0)
  1585. {
  1586. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1587. }
  1588. else
  1589. {
  1590. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1591. }
  1592. // 构建保存路径
  1593. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1594. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1595. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1596. Directory.CreateDirectory(savePath); // 确保目录存在
  1597. // 构建文件名(以 SN + 序号命名)
  1598. string fileName = $"{sn}_{fileCounter}.txt";
  1599. string filePath = Path.Combine(savePath, fileName);
  1600. // 写入文件
  1601. using (StreamWriter writer = new StreamWriter(filePath))
  1602. {
  1603. writer.WriteLine("精度, 扭力");
  1604. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1605. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1606. {
  1607. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1608. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1609. writer.WriteLine($"{precision}, {torque}");
  1610. }
  1611. }
  1612. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1613. // 增加文件计数器
  1614. fileCounter++;
  1615. }
  1616. // 如果没有更多数据,则短暂休眠以节省资源
  1617. if (!cachedData.Any())
  1618. {
  1619. Thread.Sleep(10); // 根据需要调整休眠时间
  1620. }
  1621. // 如果触发了出站,则退出循环
  1622. if (!isCollectingFlagRight)
  1623. {
  1624. break;
  1625. }
  1626. }
  1627. stopwatch.Stop();
  1628. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1629. }
  1630. catch (Exception ex)
  1631. {
  1632. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1633. }
  1634. finally
  1635. {
  1636. isCollectingFlagRight = false;
  1637. }
  1638. }
  1639. #endregion
  1640. #region S1
  1641. /// <summary>
  1642. /// [S1] 壳体清洁上料装备
  1643. /// </summary>
  1644. /// <param name="plcNo">PLC编号</param>
  1645. private void ReadStation_S1(int plcNo)
  1646. {
  1647. string stationCode = "[OP10]";
  1648. string stationName = "壳体清洁上料";
  1649. string stationNameStr = stationCode + stationName;
  1650. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1651. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1652. string tagAgvCommName = "agvCommFrmPC";
  1653. string tagBarsetName = "BarcodeSet";
  1654. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1655. (int, string) result;
  1656. while (true)
  1657. {
  1658. try
  1659. {
  1660. if (!GlobalContext._IsCon_Funs1)
  1661. {
  1662. UpdatePLCMonitor(1, plcNo, 0);
  1663. continue;
  1664. }
  1665. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1666. {
  1667. Stopwatch stopwatch1 = new Stopwatch();
  1668. Stopwatch stopwatch2 = new Stopwatch();
  1669. stopwatch1.Start();
  1670. stopwatch2.Start();
  1671. #region 一次性读取所有数据
  1672. // 一次性读取所有数据
  1673. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1674. if (result.Item1 != 0)
  1675. {
  1676. //richTextBox1.AppendText("\n" + strRet);
  1677. }
  1678. else
  1679. {
  1680. //richTextBox1.AppendText("\n" + "读取成功");
  1681. }
  1682. #endregion 一次性读取所有数据
  1683. stopwatch2.Stop();
  1684. #region 进站
  1685. try
  1686. {
  1687. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1688. {
  1689. lock (lockObj)
  1690. {
  1691. if (!ProgressState)
  1692. {
  1693. ProgressState = true;
  1694. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1695. }
  1696. }
  1697. }
  1698. }
  1699. catch (Exception ex)
  1700. {
  1701. ProgressState = false;
  1702. string str = ex.StackTrace;
  1703. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1704. }
  1705. #endregion 进站
  1706. #region 出站
  1707. try
  1708. {
  1709. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1710. {
  1711. lock (lockObj)
  1712. {
  1713. if (!ProgressState)
  1714. {
  1715. ProgressState = true;
  1716. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1717. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1718. }
  1719. }
  1720. }
  1721. }
  1722. catch (Exception ex)
  1723. {
  1724. ProgressState = false;
  1725. string str = ex.StackTrace;
  1726. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1727. }
  1728. #endregion 出站
  1729. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1730. stopwatch1.Stop();
  1731. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1732. }
  1733. else
  1734. {
  1735. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1736. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1737. FunsEip[plcNo].Connect(); // 重连
  1738. }
  1739. }
  1740. catch (Exception ex)
  1741. {
  1742. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1743. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1744. }
  1745. Thread.Sleep(IntervalReadPLC);
  1746. }
  1747. }
  1748. /// <summary>
  1749. /// [S1] 壳体清洁上料 - 进站
  1750. /// </summary>
  1751. /// <param name="plcNo">PLC编号</param>
  1752. /// <param name="stationNameStr">工站全称</param>
  1753. /// <param name="stPLC_MesData"></param>
  1754. /// <param name="tagMesCommName"></param>
  1755. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1756. {
  1757. Stopwatch stopwatch1 = new Stopwatch();
  1758. Stopwatch stopwatch2 = new Stopwatch();
  1759. try
  1760. {
  1761. stopwatch1.Start();
  1762. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1763. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1764. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1765. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1766. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1767. if (string.IsNullOrEmpty(sn))
  1768. {
  1769. ProgressState = false;
  1770. return;
  1771. }
  1772. //正式生产就用PLC中取的
  1773. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1774. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1775. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1776. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1777. //绑定载具和产品
  1778. ResponseMessage message = new ResponseMessage();
  1779. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1780. if (message.result == false)
  1781. {
  1782. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1783. }
  1784. // 产品SN进站
  1785. List<TestItem> item = new List<TestItem>();
  1786. stopwatch2.Start();
  1787. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1788. stopwatch2.Stop();
  1789. //指令执行结果 1:OK 110:失败
  1790. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1791. //进站结果写入PLC
  1792. CommandFromPLC resultToPlC = new CommandFromPLC();
  1793. resultToPlC.cmd = 0;
  1794. resultToPlC.cmdParam = 0;
  1795. resultToPlC.cmdResult = mesResultFrmWeb;
  1796. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1797. }
  1798. catch (Exception ex)
  1799. {
  1800. string str = ex.StackTrace;
  1801. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1802. CommandFromPLC resultToPlC = new CommandFromPLC();
  1803. resultToPlC.cmd = 0;
  1804. resultToPlC.cmdParam = 0; //指令参数
  1805. resultToPlC.cmdResult = 110;
  1806. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1807. }
  1808. stopwatch1.Stop();
  1809. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1810. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1811. ProgressState = false;
  1812. }
  1813. /// <summary>
  1814. /// [S1] 壳体清洁上料 - 出站接口
  1815. /// </summary>
  1816. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1817. {
  1818. Stopwatch stopwatch1 = new Stopwatch();
  1819. Stopwatch stopwatch2 = new Stopwatch();
  1820. try
  1821. {
  1822. stopwatch1.Start();
  1823. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1824. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1825. string processItem = stationName; // 项目
  1826. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1827. string supplierCode = ""; // 供应商代码
  1828. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1829. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1830. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1831. string sn = string.Empty;
  1832. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1833. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1834. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1835. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1836. a1Result = 1;
  1837. bool pass = a1Result == 1;
  1838. //根据载具码获取产品码
  1839. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1840. if (string.IsNullOrEmpty(strProductBarcode))
  1841. {
  1842. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1843. }
  1844. sn = strProductBarcode;
  1845. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1846. List<TestItem> items = new List<TestItem>();
  1847. items.Add(new TestItem()
  1848. {
  1849. Parameter_name = "载具码",
  1850. Parameter_value = CarrierBarcode,
  1851. Parameter_unit = ""
  1852. });
  1853. items.Add(new TestItem()
  1854. {
  1855. Parameter_name = "产品码",
  1856. Parameter_value = sn,
  1857. Parameter_unit = ""
  1858. });
  1859. //出站接口
  1860. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1861. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1862. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1863. stopwatch2.Start();
  1864. //进站结果写入PLC
  1865. CommandFromPLC resultToPlC = new CommandFromPLC();
  1866. resultToPlC.cmd = 0;
  1867. resultToPlC.cmdParam = 0; //指令参数
  1868. resultToPlC.cmdResult = mesResultFrmWeb;
  1869. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1870. stopwatch2.Stop();
  1871. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1872. //保存PLC返回MES数据到本地
  1873. ResponseMessage message = new ResponseMessage();
  1874. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1875. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1876. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1877. stPLC_MesData.mesData.nRemainCount);
  1878. if (message.result == false)
  1879. {
  1880. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1881. }
  1882. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1883. }
  1884. catch (Exception ex)
  1885. {
  1886. stopwatch2.Start();
  1887. CommandFromPLC resultToPlC = new CommandFromPLC();
  1888. resultToPlC.cmd = 0;
  1889. resultToPlC.cmdParam = 0; //指令参数
  1890. resultToPlC.cmdResult = 110;
  1891. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1892. stopwatch2.Stop();
  1893. string str = ex.StackTrace;
  1894. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1895. }
  1896. stopwatch1.Stop();
  1897. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1898. ProgressState = false;
  1899. }
  1900. #endregion
  1901. #region S2
  1902. /// <summary>
  1903. /// [S2] 上盖板上料装备
  1904. /// </summary>
  1905. /// <param name="plcNo">PLC编号</param>
  1906. private void ReadStation_S2(int plcNo)
  1907. {
  1908. string stationCode = "[OP20]";
  1909. string stationName = "上盖板上料装备";
  1910. string stationNameStr = stationCode + stationName;
  1911. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1912. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1913. string tagAgvCommName = "agvCommFrmPC";
  1914. string tagBarsetName = "BarcodeSet";
  1915. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1916. (int, string) result;
  1917. while (true)
  1918. {
  1919. try
  1920. {
  1921. if (!GlobalContext._IsCon_Funs2)
  1922. {
  1923. UpdatePLCMonitor(1, plcNo, 0);
  1924. continue;
  1925. }
  1926. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1927. {
  1928. Stopwatch stopwatch1 = new Stopwatch();
  1929. Stopwatch stopwatch2 = new Stopwatch();
  1930. stopwatch1.Start();
  1931. stopwatch2.Start();
  1932. #region 一次性读取所有数据
  1933. // 一次性读取所有数据
  1934. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1935. if (result.Item1 != 0)
  1936. {
  1937. //richTextBox1.AppendText("\n" + strRet);
  1938. }
  1939. else
  1940. {
  1941. //richTextBox1.AppendText("\n" + "读取成功");
  1942. }
  1943. #endregion 一次性读取所有数据
  1944. stopwatch2.Stop();
  1945. #region 进站
  1946. try
  1947. {
  1948. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1949. {
  1950. lock (lockObj)
  1951. {
  1952. if (!ProgressState)
  1953. {
  1954. ProgressState = true;
  1955. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1956. }
  1957. }
  1958. }
  1959. }
  1960. catch (Exception ex)
  1961. {
  1962. ProgressState = false;
  1963. string str = ex.StackTrace;
  1964. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1965. }
  1966. #endregion 进站
  1967. #region 出站
  1968. try
  1969. {
  1970. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1971. {
  1972. lock (lockObj)
  1973. {
  1974. if (!ProgressState)
  1975. {
  1976. ProgressState = true;
  1977. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1978. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1979. }
  1980. }
  1981. }
  1982. }
  1983. catch (Exception ex)
  1984. {
  1985. ProgressState = false;
  1986. string str = ex.StackTrace;
  1987. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1988. }
  1989. #endregion 出站
  1990. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1991. stopwatch1.Stop();
  1992. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1993. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1994. }
  1995. else
  1996. {
  1997. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1998. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1999. FunsEip[plcNo].Connect();
  2000. }
  2001. }
  2002. catch (Exception ex)
  2003. {
  2004. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2005. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2006. //Funs[plcNo].ReConnect();
  2007. }
  2008. Thread.Sleep(IntervalReadPLC);
  2009. }
  2010. }
  2011. /// <summary>
  2012. /// [S2] 上盖板上料装备
  2013. /// </summary>
  2014. /// <param name="plcNo">PLC编号</param>
  2015. /// <param name="stationNameStr">工站全称</param>
  2016. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2017. {
  2018. Stopwatch stopwatch1 = new Stopwatch();
  2019. Stopwatch stopwatch2 = new Stopwatch();
  2020. try
  2021. {
  2022. stopwatch1.Start();
  2023. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2024. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  2025. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2026. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  2027. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  2028. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2029. //根据载具码获取产品码
  2030. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2031. if (string.IsNullOrEmpty(strProductBarcode))
  2032. {
  2033. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2034. }
  2035. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2036. //if (sn != strProductBarcode)
  2037. //{
  2038. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2039. //}
  2040. sn = strProductBarcode;
  2041. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2042. // 产品SN(物料码)校验
  2043. List<TestItem> item = new List<TestItem>();
  2044. stopwatch2.Start();
  2045. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2046. stopwatch2.Stop();
  2047. //指令执行结果 1:OK 110:失败
  2048. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2049. //进站结果写入PLC
  2050. CommandFromPLC resultToPlC = new CommandFromPLC();
  2051. resultToPlC.cmd = 0;
  2052. resultToPlC.cmdParam = 0; //指令参数
  2053. resultToPlC.cmdResult = mesResultFrmWeb;
  2054. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2055. }
  2056. catch (Exception ex)
  2057. {
  2058. string str = ex.StackTrace;
  2059. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2060. CommandFromPLC resultToPlC = new CommandFromPLC();
  2061. resultToPlC.cmd = 0;
  2062. resultToPlC.cmdParam = 0; //指令参数
  2063. resultToPlC.cmdResult = 110;
  2064. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2065. }
  2066. stopwatch1.Stop();
  2067. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2068. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2069. ProgressState = false;
  2070. }
  2071. /// <summary>
  2072. /// [S2] 上盖板上料装备 - 出站接口
  2073. /// </summary>
  2074. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2075. {
  2076. Stopwatch stopwatch1 = new Stopwatch();
  2077. Stopwatch stopwatch2 = new Stopwatch();
  2078. try
  2079. {
  2080. stopwatch1.Start();
  2081. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2082. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2083. string processItem = stationName; // 测试项目
  2084. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2085. string supplierCode = ""; // 供应商代码
  2086. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2087. string batch_num = GlobalContext.BatchNumber; // 批次号
  2088. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2089. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2090. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2091. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2092. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2093. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  2094. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2095. bool pass = a1Result == 1;
  2096. //根据载具码获取产品码
  2097. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2098. if (string.IsNullOrEmpty(strProductBarcode))
  2099. {
  2100. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2101. }
  2102. sn = strProductBarcode;
  2103. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2104. List<TestItem> items = new List<TestItem>();
  2105. items.Add(new TestItem()
  2106. {
  2107. Parameter_name = "载具码",
  2108. Parameter_value = CarrierBarcode,
  2109. Parameter_unit = ""
  2110. });
  2111. items.Add(new TestItem()
  2112. {
  2113. Parameter_name = "产品码",
  2114. Parameter_value = sn,
  2115. Parameter_unit = ""
  2116. });
  2117. items.Add(new TestItem()
  2118. {
  2119. Parameter_name = "部件码",
  2120. Parameter_value = PartBarcode,
  2121. Parameter_unit = ""
  2122. });
  2123. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2124. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2125. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2126. stopwatch2.Start();
  2127. //进站结果写入PLC
  2128. CommandFromPLC resultToPlC = new CommandFromPLC();
  2129. resultToPlC.cmd = 0;
  2130. resultToPlC.cmdParam = 0; //指令参数
  2131. resultToPlC.cmdResult = mesResultFrmWeb;
  2132. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2133. stopwatch2.Stop();
  2134. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2135. //保存PLC返回MES数据到本地
  2136. ResponseMessage message = new ResponseMessage();
  2137. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  2138. if (message.result == false)
  2139. {
  2140. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2141. }
  2142. if (!string.IsNullOrEmpty(PartBarcode))
  2143. {
  2144. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2145. if (message.result == false)
  2146. {
  2147. AddMessage(LogType.Error, message.text);
  2148. }
  2149. }
  2150. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2151. }
  2152. catch (Exception ex)
  2153. {
  2154. stopwatch2.Start();
  2155. CommandFromPLC resultToPlC = new CommandFromPLC();
  2156. resultToPlC.cmd = 0;
  2157. resultToPlC.cmdParam = 0; //指令参数
  2158. resultToPlC.cmdResult = 110;
  2159. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2160. stopwatch2.Stop();
  2161. string str = ex.StackTrace;
  2162. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2163. }
  2164. stopwatch1.Stop();
  2165. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2166. ProgressState = false;
  2167. }
  2168. #endregion
  2169. #region S3
  2170. /// <summary>
  2171. /// [S3] 点散热胶装备
  2172. /// </summary>
  2173. /// <param name="plcNo">PLC编号</param>
  2174. private void ReadStation_S3(int plcNo)
  2175. {
  2176. string stationCode = "[OP30]";
  2177. string stationName = "点散热胶装备";
  2178. string stationNameStr = stationCode + stationName;
  2179. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2180. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2181. string tagAgvCommName = "agvCommFrmPC";
  2182. string tagBarsetName = "BarcodeSet";
  2183. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2184. (int, string) result;
  2185. #region 创建字典
  2186. // 触发信号字典 赋值
  2187. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2188. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2189. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2190. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2191. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2192. // PLC数据字典 赋值
  2193. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2194. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2195. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2196. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2197. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2198. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2199. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2200. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2201. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2202. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2203. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2204. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2205. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2206. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2207. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2208. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2209. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2210. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2211. s3PLCData.Add("c1Result", 0); // 产品结果
  2212. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2213. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2214. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2215. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2216. #endregion 创建字典
  2217. while (true)
  2218. {
  2219. try
  2220. {
  2221. if (!GlobalContext._IsCon_Funs2)
  2222. {
  2223. UpdatePLCMonitor(1, plcNo, 0);
  2224. continue;
  2225. }
  2226. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2227. {
  2228. Stopwatch stopwatch1 = new Stopwatch();
  2229. Stopwatch stopwatch2 = new Stopwatch();
  2230. stopwatch1.Start();
  2231. stopwatch2.Start();
  2232. #region 一次性读取所有数据
  2233. // 一次性读取所有数据
  2234. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2235. if (result.Item1 != 0)
  2236. {
  2237. //richTextBox1.AppendText("\n" + strRet);
  2238. }
  2239. else
  2240. {
  2241. //richTextBox1.AppendText("\n" + "读取成功");
  2242. }
  2243. #endregion 一次性读取所有数据
  2244. stopwatch2.Stop();
  2245. #region 左边进站
  2246. try
  2247. {
  2248. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2249. {
  2250. lock (lockObj)
  2251. {
  2252. if (!ProgressState)
  2253. {
  2254. ProgressState = true;
  2255. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2256. }
  2257. }
  2258. }
  2259. }
  2260. catch (Exception ex)
  2261. {
  2262. ProgressState = false;
  2263. string str = ex.StackTrace;
  2264. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2265. }
  2266. #endregion 左边进站
  2267. #region 左边出站
  2268. try
  2269. {
  2270. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2271. {
  2272. lock (lockObj)
  2273. {
  2274. if (!ProgressState)
  2275. {
  2276. ProgressState = true;
  2277. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2278. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  2279. }
  2280. }
  2281. }
  2282. }
  2283. catch (Exception ex)
  2284. {
  2285. ProgressState = false;
  2286. string str = ex.StackTrace;
  2287. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2288. }
  2289. #endregion 左边出站
  2290. #region 右边进站
  2291. try
  2292. {
  2293. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2294. {
  2295. lock (lockObj)
  2296. {
  2297. if (!ProgressState)
  2298. {
  2299. ProgressState = true;
  2300. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2301. }
  2302. }
  2303. }
  2304. }
  2305. catch (Exception ex)
  2306. {
  2307. ProgressState = false;
  2308. string str = ex.StackTrace;
  2309. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2310. }
  2311. #endregion 右边进站
  2312. #region 右边出站
  2313. try
  2314. {
  2315. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2316. {
  2317. lock (lockObj)
  2318. {
  2319. if (!ProgressState)
  2320. {
  2321. ProgressState = true;
  2322. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2323. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  2324. }
  2325. }
  2326. }
  2327. }
  2328. catch (Exception ex)
  2329. {
  2330. string str = ex.StackTrace;
  2331. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2332. }
  2333. #endregion 右边出站
  2334. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2335. stopwatch1.Stop();
  2336. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2337. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2338. }
  2339. else
  2340. {
  2341. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2342. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2343. FunsEip[plcNo].Connect();
  2344. }
  2345. }
  2346. catch (Exception ex)
  2347. {
  2348. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2349. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2350. //Funs[plcNo].ReConnect();
  2351. }
  2352. Thread.Sleep(IntervalReadPLC);
  2353. }
  2354. }
  2355. /// <summary>
  2356. /// [S3] 点散热胶装备 - 进站
  2357. /// </summary>
  2358. /// <param name="plcNo">PLC编号</param>
  2359. /// <param name="stationNameStr">工站全称</param>
  2360. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2361. {
  2362. Stopwatch stopwatch1 = new Stopwatch();
  2363. Stopwatch stopwatch2 = new Stopwatch();
  2364. try
  2365. {
  2366. stopwatch1.Start();
  2367. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2368. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2369. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2370. string StationId=string.Empty;
  2371. if (direction=="Left")
  2372. {
  2373. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2374. }
  2375. if (direction == "Right")
  2376. {
  2377. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2378. }
  2379. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2380. //载具码验证产品码
  2381. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2382. if (string.IsNullOrEmpty(strProductBarcode))
  2383. {
  2384. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2385. }
  2386. sn = strProductBarcode;
  2387. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2388. // 产品SN(物料码)校验
  2389. List<TestItem> item = new List<TestItem>();
  2390. stopwatch2.Start();
  2391. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2392. stopwatch2.Stop();
  2393. //指令执行结果 1:OK 110:失败
  2394. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2395. //进站结果写入PLC
  2396. CommandFromPLC resultToPlC = new CommandFromPLC();
  2397. resultToPlC.cmd = 0;
  2398. resultToPlC.cmdParam = 0; //指令参数
  2399. resultToPlC.cmdResult = mesResultFrmWeb;
  2400. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2401. }
  2402. catch (Exception ex)
  2403. {
  2404. string str = ex.StackTrace;
  2405. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2406. CommandFromPLC resultToPlC = new CommandFromPLC();
  2407. resultToPlC.cmd = 0;
  2408. resultToPlC.cmdParam = 0; //指令参数
  2409. resultToPlC.cmdResult = 110;
  2410. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2411. }
  2412. stopwatch1.Stop();
  2413. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2414. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2415. ProgressState = false;
  2416. }
  2417. /// <summary>
  2418. /// [S3] 点散热胶装备 - 出站
  2419. /// </summary>
  2420. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2421. {
  2422. Stopwatch stopwatch1 = new Stopwatch();
  2423. Stopwatch stopwatch2 = new Stopwatch();
  2424. try
  2425. {
  2426. stopwatch1.Start();
  2427. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2428. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2429. string processItem = stationName; // 测试项目
  2430. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2431. string supplierCode = ""; // 供应商代码
  2432. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2433. string batch_num = GlobalContext.BatchNumber; // 批次号
  2434. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2435. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2436. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2437. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2438. string StationId = string.Empty;
  2439. if (direction == "Left")
  2440. {
  2441. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2442. }
  2443. if (direction == "Right")
  2444. {
  2445. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2446. }
  2447. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2448. bool pass = a1Result == 1;
  2449. //根据载具码获取产品码
  2450. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2451. if (string.IsNullOrEmpty(strProductBarcode))
  2452. {
  2453. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2454. }
  2455. sn = strProductBarcode;
  2456. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2457. List<TestItem> items = new List<TestItem>();
  2458. items.Add(new TestItem()
  2459. {
  2460. Parameter_name = "载具码",
  2461. Parameter_value = CarrierBarcode,
  2462. Parameter_unit = ""
  2463. });
  2464. items.Add(new TestItem()
  2465. {
  2466. Parameter_name = "产品码",
  2467. Parameter_value = sn,
  2468. Parameter_unit = ""
  2469. });
  2470. int result1 = 1;
  2471. //if (direction == "Right")
  2472. //{
  2473. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2474. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", direction);
  2475. //}
  2476. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2477. stopwatch2.Start();
  2478. //进站结果写入PLC
  2479. CommandFromPLC resultToPlC = new CommandFromPLC();
  2480. resultToPlC.cmd = 0;
  2481. resultToPlC.cmdParam = 0; //指令参数
  2482. resultToPlC.cmdResult = mesResultFrmWeb;
  2483. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2484. stopwatch2.Stop();
  2485. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2486. //保存PLC返回MES数据到本地
  2487. ResponseMessage message = new ResponseMessage();
  2488. if (direction == "Left")
  2489. {
  2490. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2491. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2492. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2493. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2494. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2495. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2496. if (message.result == false)
  2497. {
  2498. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2499. }
  2500. }
  2501. if (direction == "Right")
  2502. {
  2503. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2504. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2505. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2506. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2507. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2508. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2509. if (message.result == false)
  2510. {
  2511. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2512. }
  2513. }
  2514. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2515. }
  2516. catch (Exception ex)
  2517. {
  2518. stopwatch2.Start();
  2519. CommandFromPLC resultToPlC = new CommandFromPLC();
  2520. resultToPlC.cmd = 0;
  2521. resultToPlC.cmdParam = 0; //指令参数
  2522. resultToPlC.cmdResult = 110;
  2523. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2524. stopwatch2.Stop();
  2525. string str = ex.StackTrace;
  2526. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2527. }
  2528. stopwatch1.Stop();
  2529. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2530. ProgressState = false;
  2531. }
  2532. #endregion S3
  2533. #region S4
  2534. /// <summary>
  2535. /// [S4] 点胶检测设备
  2536. /// </summary>
  2537. /// <param name="plcNo">PLC编号</param>
  2538. private void ReadStation_S4(int plcNo)
  2539. {
  2540. string stationCode = "[OP40]";
  2541. string stationName = "胶线检测";
  2542. string stationNameStr = stationCode + stationName;
  2543. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2544. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2545. string tagAgvCommName = "agvCommFrmPC";
  2546. string tagBarsetName = "BarcodeSet";
  2547. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2548. (int, string) result;
  2549. while (true)
  2550. {
  2551. try
  2552. {
  2553. if (!GlobalContext._IsCon_Funs1)
  2554. {
  2555. UpdatePLCMonitor(1, plcNo, 0);
  2556. continue;
  2557. }
  2558. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2559. {
  2560. Stopwatch stopwatch1 = new Stopwatch();
  2561. Stopwatch stopwatch2 = new Stopwatch();
  2562. stopwatch1.Start();
  2563. stopwatch2.Start();
  2564. #region 一次性读取所有数据
  2565. // 一次性读取所有数据
  2566. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2567. if (result.Item1 != 0)
  2568. {
  2569. //richTextBox1.AppendText("\n" + strRet);
  2570. }
  2571. else
  2572. {
  2573. //richTextBox1.AppendText("\n" + "读取成功");
  2574. }
  2575. #endregion 一次性读取所有数据
  2576. stopwatch2.Stop();
  2577. #region 进站
  2578. try
  2579. {
  2580. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2581. {
  2582. lock (lockObj)
  2583. {
  2584. if (!ProgressState)
  2585. {
  2586. ProgressState = true;
  2587. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2588. }
  2589. }
  2590. }
  2591. }
  2592. catch (Exception ex)
  2593. {
  2594. ProgressState = false;
  2595. string str = ex.StackTrace;
  2596. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2597. }
  2598. #endregion 进站
  2599. #region 出站
  2600. try
  2601. {
  2602. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2603. {
  2604. lock (lockObj)
  2605. {
  2606. if (!ProgressState)
  2607. {
  2608. ProgressState = true;
  2609. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2610. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2611. }
  2612. }
  2613. }
  2614. }
  2615. catch (Exception ex)
  2616. {
  2617. string str = ex.StackTrace;
  2618. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2619. }
  2620. #endregion 出站
  2621. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2622. stopwatch1.Stop();
  2623. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2624. }
  2625. else
  2626. {
  2627. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2628. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2629. FunsEip[plcNo].Connect(); // 重连
  2630. }
  2631. }
  2632. catch (Exception ex)
  2633. {
  2634. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2635. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2636. }
  2637. Thread.Sleep(IntervalReadPLC);
  2638. }
  2639. }
  2640. /// <summary>
  2641. /// [S4] 点胶检测设备 - 进站
  2642. /// </summary>
  2643. /// <param name="plcNo">PLC编号</param>
  2644. /// <param name="stationNameStr">工站全称</param>
  2645. /// <param name="stPLC_MesData"></param>
  2646. /// <param name="tagMesCommName"></param>
  2647. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2648. {
  2649. Stopwatch stopwatch1 = new Stopwatch();
  2650. Stopwatch stopwatch2 = new Stopwatch();
  2651. try
  2652. {
  2653. stopwatch1.Start();
  2654. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2655. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2656. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2657. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2658. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2659. //载具码验证产品码
  2660. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2661. if (string.IsNullOrEmpty(strProductBarcode))
  2662. {
  2663. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2664. }
  2665. sn = strProductBarcode;
  2666. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2667. // 产品SN(物料码)校验
  2668. List<TestItem> item = new List<TestItem>();
  2669. stopwatch2.Start();
  2670. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2671. stopwatch2.Stop();
  2672. //指令执行结果 1:OK 110:失败
  2673. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2674. //进站结果写入PLC
  2675. CommandFromPLC resultToPlC = new CommandFromPLC();
  2676. resultToPlC.cmd = 0;
  2677. resultToPlC.cmdParam = 0; //指令参数
  2678. resultToPlC.cmdResult = mesResultFrmWeb;
  2679. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2680. }
  2681. catch (Exception ex)
  2682. {
  2683. string str = ex.StackTrace;
  2684. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2685. CommandFromPLC resultToPlC = new CommandFromPLC();
  2686. resultToPlC.cmd = 0;
  2687. resultToPlC.cmdParam = 0; //指令参数
  2688. resultToPlC.cmdResult = 110;
  2689. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2690. }
  2691. stopwatch1.Stop();
  2692. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2693. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2694. ProgressState = false;
  2695. }
  2696. /// <summary>
  2697. /// [S4] 点胶检测设备 - 出站接口
  2698. /// </summary>
  2699. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2700. {
  2701. Stopwatch stopwatch1 = new Stopwatch();
  2702. Stopwatch stopwatch2 = new Stopwatch();
  2703. try
  2704. {
  2705. stopwatch1.Start();
  2706. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2707. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2708. string processItem = stationName; // 测试项目
  2709. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2710. string supplierCode = ""; // 供应商代码
  2711. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2712. string batch_num = GlobalContext.BatchNumber; // 批次号
  2713. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2714. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2715. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2716. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2717. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2718. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2719. bool pass = a1Result == 1;
  2720. //根据载具码获取产品码
  2721. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2722. if (string.IsNullOrEmpty(strProductBarcode))
  2723. {
  2724. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2725. }
  2726. sn = strProductBarcode;
  2727. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2728. List<TestItem> items = new List<TestItem>();
  2729. items.Add(new TestItem()
  2730. {
  2731. Parameter_name = "载具码",
  2732. Parameter_value = CarrierBarcode,
  2733. Parameter_unit = ""
  2734. });
  2735. items.Add(new TestItem()
  2736. {
  2737. Parameter_name = "产品码",
  2738. Parameter_value = sn,
  2739. Parameter_unit = ""
  2740. });
  2741. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2742. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2743. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2744. stopwatch2.Start();
  2745. //进站结果写入PLC
  2746. CommandFromPLC resultToPlC = new CommandFromPLC();
  2747. resultToPlC.cmd = 0;
  2748. resultToPlC.cmdParam = 0; //指令参数
  2749. resultToPlC.cmdResult = mesResultFrmWeb;
  2750. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2751. stopwatch2.Stop();
  2752. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2753. //保存PLC返回MES数据到本地
  2754. ResponseMessage message = new ResponseMessage();
  2755. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2756. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2757. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2758. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2759. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2760. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2761. if (message.result == false)
  2762. {
  2763. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2764. }
  2765. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2766. }
  2767. catch (Exception ex)
  2768. {
  2769. stopwatch2.Start();
  2770. CommandFromPLC resultToPlC = new CommandFromPLC();
  2771. resultToPlC.cmd = 0;
  2772. resultToPlC.cmdParam = 0; //指令参数
  2773. resultToPlC.cmdResult = 110;
  2774. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2775. stopwatch2.Stop();
  2776. string str = ex.StackTrace;
  2777. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2778. }
  2779. stopwatch1.Stop();
  2780. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2781. ProgressState = false;
  2782. }
  2783. #endregion
  2784. #region S5
  2785. /// <summary>
  2786. /// [S5] 点胶检测设备
  2787. /// </summary>
  2788. /// <param name="plcNo">PLC编号</param>
  2789. private void ReadStation_S5(int plcNo)
  2790. {
  2791. string stationCode = "[OP50]";
  2792. string stationName = "ADD板上料组装装备";
  2793. string stationNameStr = stationCode + stationName;
  2794. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2795. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2796. string tagAgvCommName = "agvCommFrmPC";
  2797. string tagBarsetName = "BarcodeSet";
  2798. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2799. (int, string) result;
  2800. while (true)
  2801. {
  2802. try
  2803. {
  2804. if (!GlobalContext._IsCon_Funs1)
  2805. {
  2806. UpdatePLCMonitor(1, plcNo, 0);
  2807. continue;
  2808. }
  2809. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2810. {
  2811. Stopwatch stopwatch1 = new Stopwatch();
  2812. Stopwatch stopwatch2 = new Stopwatch();
  2813. stopwatch1.Start();
  2814. stopwatch2.Start();
  2815. #region 一次性读取所有数据
  2816. // 一次性读取所有数据
  2817. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2818. if (result.Item1 != 0)
  2819. {
  2820. //richTextBox1.AppendText("\n" + strRet);
  2821. }
  2822. else
  2823. {
  2824. //richTextBox1.AppendText("\n" + "读取成功");
  2825. }
  2826. #endregion 一次性读取所有数据
  2827. stopwatch2.Stop();
  2828. #region 进站
  2829. try
  2830. {
  2831. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2832. {
  2833. lock (lockObj)
  2834. {
  2835. if (!ProgressState)
  2836. {
  2837. ProgressState = true;
  2838. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2839. }
  2840. }
  2841. }
  2842. }
  2843. catch (Exception ex)
  2844. {
  2845. ProgressState = false;
  2846. string str = ex.StackTrace;
  2847. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2848. }
  2849. #endregion 进站
  2850. #region 出站
  2851. try
  2852. {
  2853. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2854. {
  2855. lock (lockObj)
  2856. {
  2857. if (!ProgressState)
  2858. {
  2859. ProgressState = true;
  2860. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2861. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2862. }
  2863. }
  2864. }
  2865. }
  2866. catch (Exception ex)
  2867. {
  2868. ProgressState = false;
  2869. string str = ex.StackTrace;
  2870. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2871. }
  2872. #endregion 出站
  2873. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2874. stopwatch1.Stop();
  2875. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2876. }
  2877. else
  2878. {
  2879. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2880. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2881. FunsEip[plcNo].Connect(); // 重连
  2882. }
  2883. }
  2884. catch (Exception ex)
  2885. {
  2886. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2887. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2888. }
  2889. Thread.Sleep(IntervalReadPLC);
  2890. }
  2891. }
  2892. /// <summary>
  2893. /// [S5] 点胶检测设备 - 进站
  2894. /// </summary>
  2895. /// <param name="plcNo">PLC编号</param>
  2896. /// <param name="stationNameStr">工站全称</param>
  2897. /// <param name="stPLC_MesData"></param>
  2898. /// <param name="tagMesCommName"></param>
  2899. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2900. {
  2901. Stopwatch stopwatch1 = new Stopwatch();
  2902. Stopwatch stopwatch2 = new Stopwatch();
  2903. try
  2904. {
  2905. stopwatch1.Start();
  2906. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2907. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2908. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2909. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2910. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2911. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2912. //载具码验证产品码 //载具码验证产品码
  2913. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2914. if (string.IsNullOrEmpty(strProductBarcode))
  2915. {
  2916. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2917. }
  2918. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2919. //if (sn != strProductBarcode)
  2920. //{
  2921. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2922. //}
  2923. sn = strProductBarcode;
  2924. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2925. // 产品SN(物料码)校验
  2926. List<TestItem> item = new List<TestItem>();
  2927. stopwatch2.Start();
  2928. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2929. stopwatch2.Stop();
  2930. //指令执行结果 1:OK 110:失败
  2931. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2932. //进站结果写入PLC
  2933. CommandFromPLC resultToPlC = new CommandFromPLC();
  2934. resultToPlC.cmd = 0;
  2935. resultToPlC.cmdParam = 0; //指令参数
  2936. resultToPlC.cmdResult = mesResultFrmWeb;
  2937. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2938. }
  2939. catch (Exception ex)
  2940. {
  2941. string str = ex.StackTrace;
  2942. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2943. CommandFromPLC resultToPlC = new CommandFromPLC();
  2944. resultToPlC.cmd = 0;
  2945. resultToPlC.cmdParam = 0; //指令参数
  2946. resultToPlC.cmdResult = 110;
  2947. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2948. }
  2949. stopwatch1.Stop();
  2950. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2951. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2952. ProgressState = false;
  2953. }
  2954. /// <summary>
  2955. /// [S5] 点胶检测设备 - 出站接口
  2956. /// </summary>
  2957. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2958. {
  2959. Stopwatch stopwatch1 = new Stopwatch();
  2960. Stopwatch stopwatch2 = new Stopwatch();
  2961. try
  2962. {
  2963. stopwatch1.Start();
  2964. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2965. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2966. string processItem = stationName; // 测试项目
  2967. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2968. string supplierCode = ""; // 供应商代码
  2969. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2970. string batch_num = GlobalContext.BatchNumber; // 批次号
  2971. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2972. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2973. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2974. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2975. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2976. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2977. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2978. bool pass = a1Result == 1;
  2979. //根据载具码获取产品码
  2980. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2981. if (string.IsNullOrEmpty(strProductBarcode))
  2982. {
  2983. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2984. }
  2985. sn = strProductBarcode;
  2986. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2987. List<TestItem> items = new List<TestItem>();
  2988. items.Add(new TestItem()
  2989. {
  2990. Parameter_name = "载具码",
  2991. Parameter_value = CarrierBarcode,
  2992. Parameter_unit = ""
  2993. });
  2994. items.Add(new TestItem()
  2995. {
  2996. Parameter_name = "产品码",
  2997. Parameter_value = sn,
  2998. Parameter_unit = ""
  2999. });
  3000. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3001. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  3002. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3003. stopwatch2.Start();
  3004. //进站结果写入PLC
  3005. CommandFromPLC resultToPlC = new CommandFromPLC();
  3006. resultToPlC.cmd = 0;
  3007. resultToPlC.cmdParam = 0; //指令参数
  3008. resultToPlC.cmdResult = mesResultFrmWeb;
  3009. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3010. stopwatch2.Stop();
  3011. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3012. //保存PLC返回MES数据到本地
  3013. ResponseMessage message = new ResponseMessage();
  3014. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  3015. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  3016. if (message.result == false)
  3017. {
  3018. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3019. }
  3020. //保存部件码信息
  3021. if (!string.IsNullOrEmpty(PartBarcode))
  3022. {
  3023. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  3024. if (message.result == false)
  3025. {
  3026. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  3027. }
  3028. }
  3029. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3030. }
  3031. catch (Exception ex)
  3032. {
  3033. stopwatch2.Start();
  3034. CommandFromPLC resultToPlC = new CommandFromPLC();
  3035. resultToPlC.cmd = 0;
  3036. resultToPlC.cmdParam = 0; //指令参数
  3037. resultToPlC.cmdResult = 110;
  3038. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3039. stopwatch2.Stop();
  3040. string str = ex.StackTrace;
  3041. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3042. }
  3043. stopwatch1.Stop();
  3044. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3045. ProgressState = false;
  3046. }
  3047. #endregion
  3048. #region S6
  3049. /// <summary>
  3050. /// [S6] 顶盖装配设备
  3051. /// </summary>
  3052. /// <param name="plcNo">PLC编号</param>
  3053. private void ReadStation_S6(int plcNo)
  3054. {
  3055. string stationCode = "[OP60]";
  3056. string stationName = "组上盖板";
  3057. string stationNameStr = stationCode + stationName;
  3058. string tagBaseName = "g_OP60_MES"; //标签变量名称
  3059. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3060. string tagAgvCommName = "agvCommFrmPC";
  3061. string tagBarsetName = "BarcodeSet";
  3062. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  3063. (int, string) result;
  3064. while (true)
  3065. {
  3066. try
  3067. {
  3068. if (!GlobalContext._IsCon_Funs1)
  3069. {
  3070. UpdatePLCMonitor(1, plcNo, 0);
  3071. continue;
  3072. }
  3073. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3074. {
  3075. Stopwatch stopwatch1 = new Stopwatch();
  3076. Stopwatch stopwatch2 = new Stopwatch();
  3077. stopwatch1.Start();
  3078. stopwatch2.Start();
  3079. #region 一次性读取所有数据
  3080. // 一次性读取所有数据
  3081. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3082. if (result.Item1 != 0)
  3083. {
  3084. //richTextBox1.AppendText("\n" + strRet);
  3085. }
  3086. else
  3087. {
  3088. //richTextBox1.AppendText("\n" + "读取成功");
  3089. }
  3090. #endregion 一次性读取所有数据
  3091. stopwatch2.Stop();
  3092. #region 进站
  3093. try
  3094. {
  3095. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3096. {
  3097. lock (lockObj)
  3098. {
  3099. if (!ProgressState)
  3100. {
  3101. ProgressState = true;
  3102. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3103. }
  3104. }
  3105. }
  3106. }
  3107. catch (Exception ex)
  3108. {
  3109. ProgressState = false;
  3110. string str = ex.StackTrace;
  3111. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3112. }
  3113. #endregion 进站
  3114. #region 出站
  3115. try
  3116. {
  3117. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3118. {
  3119. lock (lockObj)
  3120. {
  3121. if (!ProgressState)
  3122. {
  3123. ProgressState = true; ;
  3124. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3125. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3126. }
  3127. }
  3128. }
  3129. }
  3130. catch (Exception ex)
  3131. {
  3132. ProgressState = false;
  3133. string str = ex.StackTrace;
  3134. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3135. }
  3136. #endregion 出站
  3137. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3138. stopwatch1.Stop();
  3139. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3140. }
  3141. else
  3142. {
  3143. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3144. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3145. FunsEip[plcNo].Connect(); // 重连
  3146. }
  3147. }
  3148. catch (Exception ex)
  3149. {
  3150. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3151. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3152. }
  3153. Thread.Sleep(IntervalReadPLC);
  3154. }
  3155. }
  3156. /// <summary>
  3157. /// [S6] 顶盖装配设备 - 进站
  3158. /// </summary>
  3159. /// <param name="plcNo">PLC编号</param>
  3160. /// <param name="stationNameStr">工站全称</param>
  3161. /// <param name="stPLC_MesData"></param>
  3162. /// <param name="tagMesCommName"></param>
  3163. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, 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 sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3172. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3173. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3174. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3175. //载具码验证产品码
  3176. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3177. if (string.IsNullOrEmpty(strProductBarcode))
  3178. {
  3179. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3180. }
  3181. sn = strProductBarcode;
  3182. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3183. // 产品SN(物料码)校验
  3184. List<TestItem> item = new List<TestItem>();
  3185. stopwatch2.Start();
  3186. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3187. stopwatch2.Stop();
  3188. //指令执行结果 1:OK 110:失败
  3189. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3190. //进站结果写入PLC
  3191. CommandFromPLC resultToPlC = new CommandFromPLC();
  3192. resultToPlC.cmd = 0;
  3193. resultToPlC.cmdParam = 0; //指令参数
  3194. resultToPlC.cmdResult = mesResultFrmWeb;
  3195. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3196. }
  3197. catch (Exception ex)
  3198. {
  3199. string str = ex.StackTrace;
  3200. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3201. CommandFromPLC resultToPlC = new CommandFromPLC();
  3202. resultToPlC.cmd = 0;
  3203. resultToPlC.cmdParam = 0; //指令参数
  3204. resultToPlC.cmdResult = 110;
  3205. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3206. }
  3207. stopwatch1.Stop();
  3208. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3209. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3210. ProgressState = false;
  3211. }
  3212. /// <summary>
  3213. /// [S6] 顶盖装配设备 - 出站接口
  3214. /// </summary>
  3215. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3216. {
  3217. Stopwatch stopwatch1 = new Stopwatch();
  3218. Stopwatch stopwatch2 = new Stopwatch();
  3219. try
  3220. {
  3221. stopwatch1.Start();
  3222. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3223. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3224. string processItem = stationName; // 测试项目
  3225. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3226. string supplierCode = ""; // 供应商代码
  3227. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3228. string batch_num = GlobalContext.BatchNumber; // 批次号
  3229. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3230. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3231. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3232. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3233. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3234. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3235. bool pass = a1Result == 1;
  3236. //根据载具码获取产品码
  3237. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3238. if (string.IsNullOrEmpty(strProductBarcode))
  3239. {
  3240. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3241. }
  3242. sn = strProductBarcode;
  3243. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3244. List<TestItem> items = new List<TestItem>();
  3245. items.Add(new TestItem()
  3246. {
  3247. Parameter_name = "载具码",
  3248. Parameter_value = CarrierBarcode,
  3249. Parameter_unit = ""
  3250. });
  3251. items.Add(new TestItem()
  3252. {
  3253. Parameter_name = "产品码",
  3254. Parameter_value = sn,
  3255. Parameter_unit = ""
  3256. });
  3257. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3258. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3259. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3260. stopwatch2.Start();
  3261. //进站结果写入PLC
  3262. CommandFromPLC resultToPlC = new CommandFromPLC();
  3263. resultToPlC.cmd = 0;
  3264. resultToPlC.cmdParam = 0; //指令参数
  3265. resultToPlC.cmdResult = mesResultFrmWeb;
  3266. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3267. stopwatch2.Stop();
  3268. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3269. //保存PLC返回MES数据到本地
  3270. ResponseMessage message = new ResponseMessage();
  3271. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3272. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3273. if (message.result == false)
  3274. {
  3275. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3276. }
  3277. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3278. }
  3279. catch (Exception ex)
  3280. {
  3281. stopwatch2.Start();
  3282. CommandFromPLC resultToPlC = new CommandFromPLC();
  3283. resultToPlC.cmd = 0;
  3284. resultToPlC.cmdParam = 0; //指令参数
  3285. resultToPlC.cmdResult = 110;
  3286. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3287. stopwatch2.Stop();
  3288. string str = ex.StackTrace;
  3289. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3290. }
  3291. stopwatch1.Stop();
  3292. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3293. ProgressState = false;
  3294. }
  3295. #endregion
  3296. #region S7
  3297. /// <summary>
  3298. /// [S7] 锁螺丝设备
  3299. /// </summary>
  3300. /// <param name="plcNo">PLC编号</param>
  3301. private void ReadStation_S7(int plcNo)
  3302. {
  3303. string stationCode = "[OP70]";
  3304. string stationName = "上盖板锁螺丝";
  3305. string stationNameStr = stationCode + stationName;
  3306. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3307. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3308. string tagAgvCommName = "agvCommFrmPC";
  3309. string tagBarsetName = "BarcodeSet";
  3310. string tagScrewDataset = "screwDataset";
  3311. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3312. (int, string) result;
  3313. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3314. atlasScrewLeft.Initial();
  3315. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3316. atlasScrewRight.Initial();
  3317. while (true)
  3318. {
  3319. try
  3320. {
  3321. if (!GlobalContext._IsCon_Funs1)
  3322. {
  3323. UpdatePLCMonitor(1, plcNo, 0);
  3324. continue;
  3325. }
  3326. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3327. {
  3328. Stopwatch stopwatch1 = new Stopwatch();
  3329. Stopwatch stopwatch2 = new Stopwatch();
  3330. stopwatch1.Start();
  3331. stopwatch2.Start();
  3332. #region 一次性读取所有数据
  3333. // 一次性读取所有数据
  3334. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3335. if (result.Item1 != 0)
  3336. {
  3337. //richTextBox1.AppendText("\n" + strRet);
  3338. }
  3339. else
  3340. {
  3341. //richTextBox1.AppendText("\n" + "读取成功");
  3342. }
  3343. #endregion 一次性读取所有数据
  3344. stopwatch2.Stop();
  3345. #region 左边进站
  3346. try
  3347. {
  3348. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3349. {
  3350. lock (lockObj)
  3351. {
  3352. if (!ProgressState)
  3353. {
  3354. ProgressState = true;
  3355. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3356. }
  3357. }
  3358. }
  3359. }
  3360. catch (Exception ex)
  3361. {
  3362. ProgressState = false;
  3363. string str = ex.StackTrace;
  3364. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3365. }
  3366. #endregion 左边进站
  3367. #region 左边出站
  3368. try
  3369. {
  3370. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3371. {
  3372. lock (lockObj)
  3373. {
  3374. if (!ProgressState)
  3375. {
  3376. ProgressState = true;
  3377. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3378. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3379. }
  3380. }
  3381. }
  3382. }
  3383. catch (Exception ex)
  3384. {
  3385. ProgressState = false;
  3386. string str = ex.StackTrace;
  3387. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3388. }
  3389. #endregion 左边出站
  3390. #region 右边进站
  3391. try
  3392. {
  3393. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3394. {
  3395. lock (lockObj)
  3396. {
  3397. if (!ProgressState)
  3398. {
  3399. ProgressState = true;
  3400. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3401. }
  3402. }
  3403. }
  3404. }
  3405. catch (Exception ex)
  3406. {
  3407. ProgressState = false;
  3408. string str = ex.StackTrace;
  3409. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3410. }
  3411. #endregion 右边进站
  3412. #region 右边出站
  3413. try
  3414. {
  3415. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3416. {
  3417. lock (lockObj)
  3418. {
  3419. if (!ProgressState)
  3420. {
  3421. ProgressState = true;
  3422. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3423. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3424. }
  3425. }
  3426. }
  3427. }
  3428. catch (Exception ex)
  3429. {
  3430. ProgressState = false;
  3431. string str = ex.StackTrace;
  3432. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3433. }
  3434. #endregion 右边出站
  3435. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3436. stopwatch1.Stop();
  3437. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3438. }
  3439. else
  3440. {
  3441. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3442. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3443. FunsEip[plcNo].Connect(); // 重连
  3444. }
  3445. }
  3446. catch (Exception ex)
  3447. {
  3448. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3449. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3450. }
  3451. Thread.Sleep(IntervalReadPLC);
  3452. }
  3453. }
  3454. /// <summary>
  3455. /// [S7] 锁螺丝设备 - 进站
  3456. /// </summary>
  3457. /// <param name="plcNo">PLC编号</param>
  3458. /// <param name="stationNameStr">工站全称</param>
  3459. /// <param name="stPLC_MesData"></param>
  3460. /// <param name="tagMesCommName"></param>
  3461. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3462. {
  3463. Stopwatch stopwatch1 = new Stopwatch();
  3464. Stopwatch stopwatch2 = new Stopwatch();
  3465. string atlasSn=string.Empty;
  3466. try
  3467. {
  3468. stopwatch1.Start();
  3469. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3470. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3471. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3472. string StationId = string.Empty; // 工位ID(可配置)
  3473. if (direction == "Left")
  3474. {
  3475. StationId = GlobalContext.S7_StationId_1;
  3476. }
  3477. if (direction == "Right")
  3478. {
  3479. StationId = GlobalContext.S7_StationId_2;
  3480. }
  3481. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3482. //载具码验证产品码
  3483. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3484. if (string.IsNullOrEmpty(strProductBarcode))
  3485. {
  3486. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3487. }
  3488. sn = strProductBarcode;
  3489. atlasSn= strProductBarcode;
  3490. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3491. if (direction == "Left")
  3492. {
  3493. isCollectingFlagLeft = false;//采集螺丝数据结束
  3494. }
  3495. if (direction == "Right")
  3496. {
  3497. isCollectingFlagRight = false;//采集螺丝数据结束
  3498. }
  3499. // 产品SN(物料码)校验
  3500. List<TestItem> item = new List<TestItem>();
  3501. stopwatch2.Start();
  3502. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3503. stopwatch2.Stop();
  3504. //指令执行结果 1:OK 110:失败
  3505. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3506. //进站结果写入PLC
  3507. CommandFromPLC resultToPlC = new CommandFromPLC();
  3508. resultToPlC.cmd = 0;
  3509. resultToPlC.cmdParam = 0; //指令参数
  3510. resultToPlC.cmdResult = mesResultFrmWeb;
  3511. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3512. }
  3513. catch (Exception ex)
  3514. {
  3515. string str = ex.StackTrace;
  3516. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3517. CommandFromPLC resultToPlC = new CommandFromPLC();
  3518. resultToPlC.cmd = 0;
  3519. resultToPlC.cmdParam = 0; //指令参数
  3520. resultToPlC.cmdResult = 110;
  3521. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3522. }
  3523. stopwatch1.Stop();
  3524. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3525. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3526. ProgressState = false;
  3527. //开始采集螺丝数据
  3528. if (direction == "Left")
  3529. {
  3530. isCollectingFlagLeft = true;
  3531. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3532. }
  3533. if (direction == "Right")
  3534. {
  3535. isCollectingFlagRight = true;
  3536. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3537. }
  3538. }
  3539. /// <summary>
  3540. /// [S7] 锁螺丝设备 - 出站
  3541. /// </summary>
  3542. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3543. {
  3544. Stopwatch stopwatch1 = new Stopwatch();
  3545. Stopwatch stopwatch2 = new Stopwatch();
  3546. try
  3547. {
  3548. stopwatch1.Start();
  3549. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3550. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3551. string processItem = stationName; // 测试项目
  3552. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3553. string supplierCode = ""; // 供应商代码
  3554. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3555. string batch_num = GlobalContext.BatchNumber; // 批次号
  3556. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3557. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3558. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3559. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3560. string StationId = string.Empty; // 工位ID(可配置)
  3561. if (direction == "Left")
  3562. {
  3563. StationId = GlobalContext.S7_StationId_1;
  3564. }
  3565. if (direction == "Right")
  3566. {
  3567. StationId = GlobalContext.S7_StationId_2;
  3568. }
  3569. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3570. a1Result = 1;
  3571. bool pass = a1Result == 1;
  3572. //根据载具码获取产品码
  3573. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3574. if (string.IsNullOrEmpty(strProductBarcode))
  3575. {
  3576. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3577. }
  3578. sn = strProductBarcode;
  3579. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3580. List<TestItem> items = new List<TestItem>();
  3581. items.Add(new TestItem()
  3582. {
  3583. Parameter_name = "载具码",
  3584. Parameter_value = CarrierBarcode,
  3585. Parameter_unit = ""
  3586. });
  3587. items.Add(new TestItem()
  3588. {
  3589. Parameter_name = "产品码",
  3590. Parameter_value = sn,
  3591. Parameter_unit = ""
  3592. });
  3593. int result1 = 1;
  3594. if (direction == "Right")
  3595. {
  3596. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3597. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3598. }
  3599. //if (direction == "Left")
  3600. //{
  3601. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3602. //}
  3603. //if (direction == "Right")
  3604. //{
  3605. // isCollectingFlagRight = false;//采集螺丝数据结束
  3606. //}
  3607. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3608. stopwatch2.Start();
  3609. //进站结果写入PLC
  3610. CommandFromPLC resultToPlC = new CommandFromPLC();
  3611. resultToPlC.cmd = 0;
  3612. resultToPlC.cmdParam = 0; //指令参数
  3613. resultToPlC.cmdResult = mesResultFrmWeb;
  3614. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3615. stopwatch2.Stop();
  3616. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3617. //保存PLC返回MES数据到本地
  3618. ResponseMessage message = new ResponseMessage();
  3619. if (direction == "Left")
  3620. {
  3621. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3622. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3623. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3624. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3625. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3626. if (message.result == false)
  3627. {
  3628. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3629. }
  3630. }
  3631. if (direction == "Right")
  3632. {
  3633. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3634. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3635. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3636. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3637. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3638. if (message.result == false)
  3639. {
  3640. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3641. }
  3642. }
  3643. //保存螺丝数据到txt
  3644. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3645. if (result.Item1 != 0)
  3646. {
  3647. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3648. }
  3649. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3650. }
  3651. catch (Exception ex)
  3652. {
  3653. stopwatch2.Start();
  3654. CommandFromPLC resultToPlC = new CommandFromPLC();
  3655. resultToPlC.cmd = 0;
  3656. resultToPlC.cmdParam = 0; //指令参数
  3657. resultToPlC.cmdResult = 110;
  3658. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3659. stopwatch2.Stop();
  3660. string str = ex.StackTrace;
  3661. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3662. }
  3663. stopwatch1.Stop();
  3664. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3665. ProgressState = false;
  3666. }
  3667. #endregion
  3668. #region S8
  3669. /// <summary>
  3670. /// [S8] 3D螺丝高度检测设备
  3671. /// </summary>
  3672. /// <param name="plcNo">PLC编号</param>
  3673. private void ReadStation_S8(int plcNo)
  3674. {
  3675. string stationCode = "[OP80]";
  3676. string stationName = "NG下料";
  3677. string stationNameStr = stationCode + stationName;
  3678. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3679. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3680. string tagAgvCommName = "agvCommFrmPC";
  3681. string tagBarsetName = "BarcodeSet";
  3682. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3683. (int, string) result;
  3684. while (true)
  3685. {
  3686. try
  3687. {
  3688. if (!GlobalContext._IsCon_Funs1)
  3689. {
  3690. UpdatePLCMonitor(1, plcNo, 0);
  3691. continue;
  3692. }
  3693. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3694. {
  3695. Stopwatch stopwatch1 = new Stopwatch();
  3696. Stopwatch stopwatch2 = new Stopwatch();
  3697. stopwatch1.Start();
  3698. stopwatch2.Start();
  3699. #region 一次性读取所有数据
  3700. // 一次性读取所有数据
  3701. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3702. if (result.Item1 != 0)
  3703. {
  3704. //richTextBox1.AppendText("\n" + strRet);
  3705. }
  3706. else
  3707. {
  3708. //richTextBox1.AppendText("\n" + "读取成功");
  3709. }
  3710. #endregion 一次性读取所有数据
  3711. stopwatch2.Stop();
  3712. #region 进站
  3713. try
  3714. {
  3715. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3716. {
  3717. lock (lockObj)
  3718. {
  3719. if (!ProgressState)
  3720. {
  3721. ProgressState = true;
  3722. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3723. }
  3724. }
  3725. }
  3726. }
  3727. catch (Exception ex)
  3728. {
  3729. ProgressState = false;
  3730. string str = ex.StackTrace;
  3731. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3732. }
  3733. #endregion 进站
  3734. #region 出站
  3735. try
  3736. {
  3737. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3738. {
  3739. lock (lockObj)
  3740. {
  3741. if (!ProgressState)
  3742. {
  3743. ProgressState = true;
  3744. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3745. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3746. }
  3747. }
  3748. }
  3749. }
  3750. catch (Exception ex)
  3751. {
  3752. ProgressState = false;
  3753. string str = ex.StackTrace;
  3754. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3755. }
  3756. #endregion 出站
  3757. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3758. stopwatch1.Stop();
  3759. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3760. }
  3761. else
  3762. {
  3763. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3764. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3765. FunsEip[plcNo].Connect(); // 重连
  3766. }
  3767. }
  3768. catch (Exception ex)
  3769. {
  3770. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3771. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3772. }
  3773. Thread.Sleep(IntervalReadPLC);
  3774. }
  3775. }
  3776. /// <summary>
  3777. /// [S8] 3D螺丝高度检测设备 - 进站
  3778. /// </summary>
  3779. /// <param name="plcNo">PLC编号</param>
  3780. /// <param name="stationNameStr">工站全称</param>
  3781. /// <param name="stPLC_MesData"></param>
  3782. /// <param name="tagMesCommName"></param>
  3783. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3784. {
  3785. Stopwatch stopwatch1 = new Stopwatch();
  3786. Stopwatch stopwatch2 = new Stopwatch();
  3787. try
  3788. {
  3789. stopwatch1.Start();
  3790. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3791. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3792. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3793. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3794. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3795. //载具码验证产品码
  3796. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3797. if (string.IsNullOrEmpty(strProductBarcode))
  3798. {
  3799. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3800. }
  3801. sn = strProductBarcode;
  3802. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3803. // 产品SN(物料码)校验
  3804. List<TestItem> item = new List<TestItem>();
  3805. stopwatch2.Start();
  3806. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3807. stopwatch2.Stop();
  3808. //指令执行结果 1:OK 110:失败
  3809. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3810. //进站结果写入PLC
  3811. CommandFromPLC resultToPlC = new CommandFromPLC();
  3812. resultToPlC.cmd = 0;
  3813. resultToPlC.cmdParam = 0; //指令参数
  3814. resultToPlC.cmdResult = mesResultFrmWeb;
  3815. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3816. }
  3817. catch (Exception ex)
  3818. {
  3819. string str = ex.StackTrace;
  3820. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3821. CommandFromPLC resultToPlC = new CommandFromPLC();
  3822. resultToPlC.cmd = 0;
  3823. resultToPlC.cmdParam = 0; //指令参数
  3824. resultToPlC.cmdResult = 110;
  3825. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3826. }
  3827. stopwatch1.Stop();
  3828. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3829. ProgressState = false;
  3830. }
  3831. /// <summary>
  3832. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3833. /// </summary>
  3834. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3835. {
  3836. Stopwatch stopwatch1 = new Stopwatch();
  3837. Stopwatch stopwatch2 = new Stopwatch();
  3838. try
  3839. {
  3840. stopwatch1.Start();
  3841. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3842. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3843. string processItem = stationName; // 测试项目
  3844. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3845. string supplierCode = ""; // 供应商代码
  3846. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3847. string batch_num = GlobalContext.BatchNumber; // 批次号
  3848. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3849. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3850. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3851. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3852. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3853. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3854. bool pass = a1Result == 1;
  3855. //根据载具码获取产品码
  3856. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3857. if (string.IsNullOrEmpty(strProductBarcode))
  3858. {
  3859. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3860. }
  3861. sn = strProductBarcode;
  3862. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3863. List<TestItem> items = new List<TestItem>();
  3864. items.Add(new TestItem()
  3865. {
  3866. Parameter_name = "载具码",
  3867. Parameter_value = CarrierBarcode,
  3868. Parameter_unit = ""
  3869. });
  3870. items.Add(new TestItem()
  3871. {
  3872. Parameter_name = "产品码",
  3873. Parameter_value = sn,
  3874. Parameter_unit = ""
  3875. });
  3876. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3877. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3878. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3879. stopwatch2.Start();
  3880. //进站结果写入PLC
  3881. CommandFromPLC resultToPlC = new CommandFromPLC();
  3882. resultToPlC.cmd = 0;
  3883. resultToPlC.cmdParam = 0; //指令参数
  3884. resultToPlC.cmdResult = mesResultFrmWeb;
  3885. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3886. stopwatch2.Stop();
  3887. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3888. //保存PLC返回MES数据到本地
  3889. ResponseMessage message = new ResponseMessage();
  3890. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3891. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3892. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3893. if (message.result == false)
  3894. {
  3895. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3896. }
  3897. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3898. }
  3899. catch (Exception ex)
  3900. {
  3901. stopwatch2.Start();
  3902. CommandFromPLC resultToPlC = new CommandFromPLC();
  3903. resultToPlC.cmd = 0;
  3904. resultToPlC.cmdParam = 0; //指令参数
  3905. resultToPlC.cmdResult = 110;
  3906. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3907. stopwatch2.Stop();
  3908. string str = ex.StackTrace;
  3909. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3910. }
  3911. stopwatch1.Stop();
  3912. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3913. ProgressState = false;
  3914. }
  3915. #endregion
  3916. #region S9
  3917. /// <summary>
  3918. /// [S9] 下料设备
  3919. /// </summary>
  3920. /// <param name="plcNo">PLC编号</param>
  3921. private void ReadStation_S9(int plcNo)
  3922. {
  3923. string stationCode = "[OP90]";
  3924. string stationName = "半成品下料";
  3925. string stationNameStr = stationCode + stationName;
  3926. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3927. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3928. string tagAgvCommName = "agvCommFrmPC";
  3929. string tagBarsetName = "BarcodeSet";
  3930. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3931. (int, string) result;
  3932. while (true)
  3933. {
  3934. try
  3935. {
  3936. if (!GlobalContext._IsCon_Funs1)
  3937. {
  3938. UpdatePLCMonitor(1, plcNo, 0);
  3939. continue;
  3940. }
  3941. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3942. {
  3943. Stopwatch stopwatch1 = new Stopwatch();
  3944. Stopwatch stopwatch2 = new Stopwatch();
  3945. stopwatch1.Start();
  3946. stopwatch2.Start();
  3947. #region 一次性读取所有数据
  3948. // 一次性读取所有数据
  3949. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3950. if (result.Item1 != 0)
  3951. {
  3952. //richTextBox1.AppendText("\n" + strRet);
  3953. }
  3954. else
  3955. {
  3956. //richTextBox1.AppendText("\n" + "读取成功");
  3957. }
  3958. #endregion 一次性读取所有数据
  3959. stopwatch2.Stop();
  3960. #region 进站
  3961. try
  3962. {
  3963. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3964. {
  3965. lock (lockObj)
  3966. {
  3967. if (!ProgressState)
  3968. {
  3969. ProgressState = true;
  3970. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3971. }
  3972. }
  3973. }
  3974. }
  3975. catch (Exception ex)
  3976. {
  3977. ProgressState = false;
  3978. string str = ex.StackTrace;
  3979. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3980. }
  3981. #endregion 进站
  3982. #region 出站
  3983. try
  3984. {
  3985. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3986. {
  3987. lock (lockObj)
  3988. {
  3989. if (!ProgressState)
  3990. {
  3991. ProgressState = true;
  3992. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3993. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3994. }
  3995. }
  3996. }
  3997. }
  3998. catch (Exception ex)
  3999. {
  4000. ProgressState = false;
  4001. string str = ex.StackTrace;
  4002. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4003. }
  4004. #endregion 出站
  4005. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4006. stopwatch1.Stop();
  4007. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4008. }
  4009. else
  4010. {
  4011. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4012. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4013. FunsEip[plcNo].Connect(); // 重连
  4014. }
  4015. }
  4016. catch (Exception ex)
  4017. {
  4018. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4019. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4020. }
  4021. Thread.Sleep(IntervalReadPLC);
  4022. }
  4023. }
  4024. /// <summary>
  4025. /// [S9] 下料设备 - 进站
  4026. /// </summary>
  4027. /// <param name="plcNo">PLC编号</param>
  4028. /// <param name="stationNameStr">工站全称</param>
  4029. /// <param name="stPLC_MesData"></param>
  4030. /// <param name="tagMesCommName"></param>
  4031. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  4032. {
  4033. Stopwatch stopwatch1 = new Stopwatch();
  4034. Stopwatch stopwatch2 = new Stopwatch();
  4035. try
  4036. {
  4037. stopwatch1.Start();
  4038. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4039. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4040. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  4041. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  4042. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4043. //载具码验证产品码
  4044. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4045. if (string.IsNullOrEmpty(strProductBarcode))
  4046. {
  4047. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4048. }
  4049. sn = strProductBarcode;
  4050. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4051. // 产品SN(物料码)校验
  4052. List<TestItem> item = new List<TestItem>();
  4053. stopwatch2.Start();
  4054. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  4055. stopwatch2.Stop();
  4056. //指令执行结果 1:OK 110:失败
  4057. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4058. //进站结果写入PLC
  4059. CommandFromPLC resultToPlC = new CommandFromPLC();
  4060. resultToPlC.cmd = 0;
  4061. resultToPlC.cmdParam = 0; //指令参数
  4062. resultToPlC.cmdResult = mesResultFrmWeb;
  4063. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4064. }
  4065. catch (Exception ex)
  4066. {
  4067. string str = ex.StackTrace;
  4068. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4069. CommandFromPLC resultToPlC = new CommandFromPLC();
  4070. resultToPlC.cmd = 0;
  4071. resultToPlC.cmdParam = 0; //指令参数
  4072. resultToPlC.cmdResult = 110;
  4073. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4074. }
  4075. stopwatch1.Stop();
  4076. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4077. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4078. ProgressState = false;
  4079. }
  4080. /// <summary>
  4081. /// [S9] 下料设备 - 出站接口
  4082. /// </summary>
  4083. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  4084. {
  4085. Stopwatch stopwatch1 = new Stopwatch();
  4086. Stopwatch stopwatch2 = new Stopwatch();
  4087. try
  4088. {
  4089. stopwatch1.Start();
  4090. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4091. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4092. string processItem = stationName; // 测试项目
  4093. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4094. string supplierCode = ""; // 供应商代码
  4095. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4096. string batch_num = GlobalContext.BatchNumber; // 批次号
  4097. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4098. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4099. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4100. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  4101. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  4102. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4103. bool pass = a1Result == 1;
  4104. //根据载具码获取产品码
  4105. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4106. if (string.IsNullOrEmpty(strProductBarcode))
  4107. {
  4108. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4109. }
  4110. sn = strProductBarcode;
  4111. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4112. List<TestItem> items = new List<TestItem>();
  4113. items.Add(new TestItem()
  4114. {
  4115. Parameter_name = "载具码",
  4116. Parameter_value = CarrierBarcode,
  4117. Parameter_unit = ""
  4118. });
  4119. items.Add(new TestItem()
  4120. {
  4121. Parameter_name = "产品码",
  4122. Parameter_value = sn,
  4123. Parameter_unit = ""
  4124. });
  4125. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4126. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  4127. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4128. stopwatch2.Start();
  4129. //进站结果写入PLC
  4130. CommandFromPLC resultToPlC = new CommandFromPLC();
  4131. resultToPlC.cmd = 0;
  4132. resultToPlC.cmdParam = 0; //指令参数
  4133. resultToPlC.cmdResult = mesResultFrmWeb;
  4134. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4135. stopwatch2.Stop();
  4136. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4137. //保存PLC返回MES数据到本地
  4138. ResponseMessage message = new ResponseMessage();
  4139. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4140. if (message.result == false)
  4141. {
  4142. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4143. }
  4144. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4145. if (result1 == 1)
  4146. {
  4147. //载具码解除绑定
  4148. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4149. if (message.result == false)
  4150. {
  4151. AddMessage(LogType.Error, message.text);
  4152. }
  4153. }
  4154. }
  4155. catch (Exception ex)
  4156. {
  4157. stopwatch2.Start();
  4158. CommandFromPLC resultToPlC = new CommandFromPLC();
  4159. resultToPlC.cmd = 0;
  4160. resultToPlC.cmdParam = 0; //指令参数
  4161. resultToPlC.cmdResult = 110;
  4162. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4163. stopwatch2.Stop();
  4164. string str = ex.StackTrace;
  4165. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4166. }
  4167. stopwatch1.Stop();
  4168. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4169. ProgressState = false;
  4170. }
  4171. #endregion
  4172. #endregion Xiaomi
  4173. #region PLC1 张超凡
  4174. #region [S1] Tray盘上料装备(板测)
  4175. /// <summary>
  4176. /// S1工位的数据- 触发信号上次的值
  4177. /// </summary>
  4178. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4179. /// <summary>
  4180. /// S1工位的数据(含触发信号)
  4181. /// </summary>
  4182. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4183. /// <summary>
  4184. /// S1工位的数据- 回写点位
  4185. /// </summary>
  4186. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4187. ///// <summary>
  4188. ///// 触发信号
  4189. ///// </summary>
  4190. //private ManualResetEvent[] MreTasks;
  4191. /// <summary>
  4192. /// [S1] Tray盘上料装备(板测)
  4193. /// </summary>
  4194. /// <param name="plcNo">PLC编号</param>
  4195. //private void ReadStation_S1(int plcNo)
  4196. //{
  4197. // // [S1] Tray盘上料装备
  4198. // // [S2] FCT
  4199. // // [S3] 值板机
  4200. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4201. // // [S5] Tray盘下料装备
  4202. // string stationCode = "[S1]";
  4203. // string stationName = "Tray盘上料装备";
  4204. // string stationNameStr = stationCode + stationName;
  4205. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4206. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4207. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4208. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4209. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4210. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4211. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4212. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4213. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4214. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4215. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4216. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4217. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4218. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4219. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4220. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4221. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4222. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4223. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4224. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4225. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4226. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4227. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4228. // s1PLCData.Add("a1Result", 0); // 产品结果
  4229. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4230. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4231. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4232. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4233. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4234. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4235. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4236. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4237. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4238. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4239. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4240. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4241. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4242. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4243. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4244. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4245. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4246. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4247. // while (IsRun)
  4248. // {
  4249. // try
  4250. // {
  4251. // if (!GlobalContext._IsCon_Funs1)
  4252. // {
  4253. // UpdatePLCMonitor(1, plcNo, 0);
  4254. // continue;
  4255. // }
  4256. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4257. // {
  4258. // Stopwatch stopwatch1 = new Stopwatch();
  4259. // Stopwatch stopwatch2 = new Stopwatch();
  4260. // stopwatch1.Start();
  4261. // stopwatch2.Start();
  4262. // #region 一次性读取所有数据
  4263. // // 一次性读取所有数据
  4264. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4265. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4266. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4267. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4268. // int[] datas = data1.Concat(data2).ToArray();
  4269. // datas = datas.Concat(data3).ToArray();
  4270. // datas = datas.Concat(data4).ToArray();
  4271. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4272. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4273. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4274. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4275. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4276. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4277. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4278. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4279. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4280. // s1PLCData["a1MES_FLAG"] = datas[109];
  4281. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4282. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4283. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4284. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4285. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4286. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4287. // s1PLCData["a1Result"] = datas[170];
  4288. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4289. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4290. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4291. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4292. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4293. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4294. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4295. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4296. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4297. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4298. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4299. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4300. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4301. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4302. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4303. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4304. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4305. // s1PLCData["a1AGVUpStart"] = datas[308];
  4306. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4307. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4308. // s1PLCData["a1AGVDownStart"] = datas[321];
  4309. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4310. // #endregion 一次性读取所有数据
  4311. // stopwatch2.Stop();
  4312. // #region 回写操作,写后清空flag
  4313. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4314. // #endregion 回写操作,写后清空flag
  4315. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4316. // try
  4317. // {
  4318. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4319. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4320. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4321. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4322. // {
  4323. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4324. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4325. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4326. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4327. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4328. // }
  4329. // }
  4330. // catch (Exception ex)
  4331. // {
  4332. // // 6代表上位机报警
  4333. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4334. // string str = ex.StackTrace;
  4335. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4336. // }
  4337. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4338. // #region 上料进站校验
  4339. // try
  4340. // {
  4341. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4342. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4343. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4344. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4345. // {
  4346. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4347. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4348. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4349. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4350. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4351. // }
  4352. // }
  4353. // catch (Exception ex)
  4354. // {
  4355. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4356. // string str = ex.StackTrace;
  4357. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4358. // }
  4359. // #endregion 上料进站校验
  4360. // #region Tray盘上料装备-出站接口
  4361. // try
  4362. // {
  4363. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4364. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4365. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4366. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4367. // {
  4368. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4369. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4370. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4371. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4372. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4373. // }
  4374. // }
  4375. // catch (Exception ex)
  4376. // {
  4377. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4378. // string str = ex.StackTrace;
  4379. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4380. // }
  4381. // #endregion Tray盘上料装备-出站接口
  4382. // #region Tray盘上料装备-将SN发给ICT标机
  4383. // try
  4384. // {
  4385. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4386. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4387. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4388. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4389. // {
  4390. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4391. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4392. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4393. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4394. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4395. // }
  4396. // }
  4397. // catch (Exception ex)
  4398. // {
  4399. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4400. // string str = ex.StackTrace;
  4401. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4402. // }
  4403. // #endregion Tray盘上料装备-将SN发给ICT标机
  4404. // #region Tray盘上料装备-点检数据
  4405. // //try
  4406. // //{
  4407. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4408. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4409. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4410. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4411. // // if (pLC_Flag && !mES_Flag) // 1 0
  4412. // // {
  4413. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4414. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4415. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4416. // // }
  4417. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4418. // // {
  4419. // // // 清空写给PLC的数据
  4420. // // // MES_Flag重置为0
  4421. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4422. // // }
  4423. // //}
  4424. // //catch (Exception ex)
  4425. // //{
  4426. // // // MES_Flag 为2上位机报错
  4427. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4428. // // string str = ex.StackTrace;
  4429. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4430. // //}
  4431. // #endregion Tray盘上料装备-点检数据
  4432. // #region 节拍接口
  4433. // try
  4434. // {
  4435. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4436. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4437. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4438. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4439. // {
  4440. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4441. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4442. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4443. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4444. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4445. // }
  4446. // }
  4447. // catch (Exception ex)
  4448. // {
  4449. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4450. // string str = ex.StackTrace;
  4451. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4452. // }
  4453. // #endregion 节拍接口
  4454. // #region AGV上料
  4455. // // AGV上料叫AGV信号
  4456. // try
  4457. // {
  4458. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4459. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4460. // if (a1AGVUpCall != a1AGVUpCallOld)
  4461. // {
  4462. // if (a1AGVUpCall == 1) // 0->1
  4463. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4464. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4465. // }
  4466. // }
  4467. // catch (Exception ex)
  4468. // {
  4469. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4470. // string str = ex.StackTrace;
  4471. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4472. // }
  4473. // // AGV上料完成信号
  4474. // try
  4475. // {
  4476. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4477. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4478. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4479. // {
  4480. // if (a1AGVUpEnd == 1) // 0->1
  4481. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4482. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4483. // }
  4484. // }
  4485. // catch (Exception ex)
  4486. // {
  4487. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4488. // string str = ex.StackTrace;
  4489. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4490. // }
  4491. // #endregion AGV上料
  4492. // #region AGV下料
  4493. // // AGV下料叫agv信号
  4494. // try
  4495. // {
  4496. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4497. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4498. // if (a1AGVDownCall != a1AGVDownCallOld)
  4499. // {
  4500. // if (a1AGVDownCall == 1) // 0->1
  4501. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4502. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4503. // }
  4504. // }
  4505. // catch (Exception ex)
  4506. // {
  4507. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4508. // string str = ex.StackTrace;
  4509. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4510. // }
  4511. // // AGV下料完成信号
  4512. // try
  4513. // {
  4514. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4515. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4516. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4517. // {
  4518. // if (a1AGVDownEnd == 1) // 0->1
  4519. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4520. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4521. // }
  4522. // }
  4523. // catch (Exception ex)
  4524. // {
  4525. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4526. // string str = ex.StackTrace;
  4527. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4528. // }
  4529. // #endregion AGV下料
  4530. // #region 心跳
  4531. // try
  4532. // {
  4533. // short states = 0;
  4534. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4535. // }
  4536. // catch (Exception ex)
  4537. // {
  4538. // string str = ex.StackTrace;
  4539. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4540. // }
  4541. // #endregion 心跳
  4542. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4543. // stopwatch1.Stop();
  4544. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4545. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4546. // }
  4547. // else
  4548. // {
  4549. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4550. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4551. // Funs[plcNo].Connect(); // 重连
  4552. // }
  4553. // }
  4554. // catch (Exception ex)
  4555. // {
  4556. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4557. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4558. // Funs[plcNo].ReConnect();
  4559. // }
  4560. // Thread.Sleep(IntervalReadPLC);
  4561. // }
  4562. //}
  4563. /// <summary>
  4564. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4565. /// </summary>
  4566. /// <param name="plcNo">PLC编号</param>
  4567. /// <param name="stationNameStr">工站全称</param>
  4568. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4569. {
  4570. Stopwatch stopwatch1 = new Stopwatch();
  4571. Stopwatch stopwatch2 = new Stopwatch();
  4572. try
  4573. {
  4574. stopwatch1.Start();
  4575. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4576. sn = sn.Replace("\0", "");
  4577. #region 查询载具上的产品信息
  4578. string cavityData = string.Empty;
  4579. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4580. if (string.IsNullOrEmpty(cavityData))
  4581. cavityData = "";
  4582. if (snResult != 0)
  4583. {
  4584. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4585. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4586. writeToPLC_Flag1.Adress = 2003;
  4587. writeToPLC_Flag1.Value = (short)6;
  4588. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4589. stopwatch1.Stop();
  4590. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4591. return;
  4592. }
  4593. #endregion 查询载具上的产品信息
  4594. string[] cavitySNs = cavityData.Split('.');
  4595. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4596. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4597. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4598. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4599. if (cavitySNs != null && cavitySNs.Length >= 2)
  4600. {
  4601. a1CavitySN1_VehicleStates = cavitySNs[0];
  4602. a1CavitySN2_VehicleStates = cavitySNs[1];
  4603. a1CavityResult1_VehicleStates = 2;
  4604. a1CavityResult2_VehicleStates = 2;
  4605. }
  4606. if (a1CavitySN1_VehicleStates == "假产品")
  4607. a1CavityResult1_VehicleStates = 3;
  4608. if (a1CavitySN2_VehicleStates == "假产品")
  4609. a1CavityResult2_VehicleStates = 3;
  4610. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4611. // 回写
  4612. stopwatch2.Start();
  4613. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4614. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4615. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4616. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4617. //// MES_Flag
  4618. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4619. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4620. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4621. writeToPLC_Flag.Adress = 2003;
  4622. writeToPLC_Flag.Value = mES_Flag;
  4623. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4624. {
  4625. Name = "a1CavitySN1_VehicleStates",
  4626. Adress = 2024,
  4627. ValueType = PLCValueType.String,
  4628. ValueTypeStrLength = 20,
  4629. Value = a1CavitySN1_VehicleStates
  4630. });
  4631. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4632. {
  4633. Name = "a1CavitySN2_VehicleStates",
  4634. Adress = 2044,
  4635. ValueType = PLCValueType.String,
  4636. ValueTypeStrLength = 20,
  4637. Value = a1CavitySN2_VehicleStates
  4638. });
  4639. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4640. {
  4641. Name = "a1CavityResult1_VehicleStates",
  4642. Adress = 2064,
  4643. ValueType = PLCValueType.Short,
  4644. Value = a1CavityResult1_VehicleStates
  4645. });
  4646. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4647. {
  4648. Name = "a1CavityResult2_VehicleStates",
  4649. Adress = 2065,
  4650. ValueType = PLCValueType.Short,
  4651. Value = a1CavityResult2_VehicleStates
  4652. });
  4653. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4654. stopwatch2.Stop();
  4655. }
  4656. catch (Exception ex)
  4657. {
  4658. string str = ex.StackTrace;
  4659. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4660. // MES_Flag
  4661. stopwatch2.Start();
  4662. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4663. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4664. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4665. writeToPLC_Flag.Adress = 2003;
  4666. writeToPLC_Flag.Value = (short)6;
  4667. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4668. stopwatch2.Stop();
  4669. }
  4670. stopwatch1.Stop();
  4671. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4672. }
  4673. /// <summary>
  4674. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4675. /// </summary>
  4676. /// <param name="plcNo">PLC编号</param>
  4677. /// <param name="stationNameStr">工站全称</param>
  4678. private void S1上料进站校验(int plcNo, string stationNameStr)
  4679. {
  4680. Stopwatch stopwatch1 = new Stopwatch();
  4681. Stopwatch stopwatch2 = new Stopwatch();
  4682. try
  4683. {
  4684. stopwatch1.Start();
  4685. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4686. sn = sn.Replace("\0", "");
  4687. // 保存进站数据+调用进站MES接口
  4688. List<TestItem> item = new List<TestItem>();
  4689. stopwatch2.Start();
  4690. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4691. stopwatch2.Stop();
  4692. short a1MES_FLAG_Check = (short)result;
  4693. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4694. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4695. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4696. writeToPLC_Flag.Adress = 2077;
  4697. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4698. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4699. }
  4700. catch (Exception ex)
  4701. {
  4702. string str = ex.StackTrace;
  4703. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4704. // MES_Flag
  4705. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4706. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4707. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4708. writeToPLC_Flag.Adress = 2077;
  4709. writeToPLC_Flag.Value = (short)6;
  4710. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4711. }
  4712. stopwatch1.Stop();
  4713. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4714. }
  4715. /// <summary>
  4716. /// [S1] Tray盘上料装备(板测)- 出站接口
  4717. /// </summary>
  4718. /// <param name="plcNo"></param>
  4719. /// <param name="stationCode"></param>
  4720. /// <param name="stationName"></param>
  4721. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4722. {
  4723. Stopwatch stopwatch1 = new Stopwatch();
  4724. Stopwatch stopwatch2 = new Stopwatch();
  4725. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4726. string stationNameStr = stationCode + stationName;
  4727. string processItem = stationName; // 测试项目
  4728. try
  4729. {
  4730. stopwatch1.Start();
  4731. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4732. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4733. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4734. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4735. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4736. sn = sn.Replace("\0", "");
  4737. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4738. partNo1 = partNo1.Replace("\0", "");
  4739. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4740. partNo2 = partNo2.Replace("\0", "");
  4741. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4742. bool pass = a1Result == 1;
  4743. stopwatch2.Start();
  4744. // 产品1
  4745. List<TestItem> items = new List<TestItem>();
  4746. items.Add(new TestItem()
  4747. {
  4748. Parameter_name = "载具码",
  4749. Parameter_value = sn,
  4750. Parameter_unit = ""
  4751. });
  4752. items.Add(new TestItem()
  4753. {
  4754. Parameter_name = "载具穴号",
  4755. Parameter_value = "1",
  4756. Parameter_unit = ""
  4757. });
  4758. items.Add(new TestItem()
  4759. {
  4760. Parameter_name = "产品结果",
  4761. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4762. Parameter_unit = ""
  4763. });
  4764. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4765. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4766. // 产品2
  4767. items = new List<TestItem>();
  4768. items.Add(new TestItem()
  4769. {
  4770. Parameter_name = "载具码",
  4771. Parameter_value = sn,
  4772. Parameter_unit = ""
  4773. });
  4774. items.Add(new TestItem()
  4775. {
  4776. Parameter_name = "载具穴号",
  4777. Parameter_value = "2",
  4778. Parameter_unit = ""
  4779. });
  4780. items.Add(new TestItem()
  4781. {
  4782. Parameter_name = "产品结果",
  4783. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4784. Parameter_unit = ""
  4785. });
  4786. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4787. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4788. short result = 0;
  4789. List<int> results = new List<int>() { result1, result2 };
  4790. if (result1 == 1 && result2 == 1)
  4791. result = 1;
  4792. else if (results.Contains(3))
  4793. result = 3;
  4794. else if (results.Contains(2))
  4795. result = 2;
  4796. else if (results.Contains(4))
  4797. result = 4;
  4798. else
  4799. result = 4;
  4800. stopwatch2.Stop();
  4801. #region 存储绑定数据到 边线MES系统中
  4802. if (result == 1)
  4803. {
  4804. string data = string.Concat(partNo1, ".", partNo2);
  4805. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4806. if (resultMesR != 0)
  4807. {
  4808. result = 4;
  4809. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4810. }
  4811. }
  4812. #endregion 存储绑定数据到 边线MES系统中
  4813. // MES_Flag 为MES报错
  4814. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4815. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4816. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4817. writeToPLC_Flag.Name = "a1MES_FLAG";
  4818. writeToPLC_Flag.Adress = 2109;
  4819. writeToPLC_Flag.Value = result;
  4820. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4821. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4822. }
  4823. catch (Exception ex)
  4824. {
  4825. stopwatch2.Restart();
  4826. // MES_Flag 为4上位机报错
  4827. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4828. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4829. writeToPLC_Flag.Name = "a1MES_FLAG";
  4830. writeToPLC_Flag.Adress = 2109;
  4831. writeToPLC_Flag.Value = (short)4;
  4832. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4833. stopwatch2.Stop();
  4834. string str = ex.StackTrace;
  4835. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4836. }
  4837. stopwatch1.Stop();
  4838. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4839. }
  4840. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4841. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4842. //{
  4843. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4844. // string stationNameStr = stationCode + stationName;
  4845. // string processItem = stationName; // 测试项目
  4846. // try
  4847. // {
  4848. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4849. // string accno = "1"; // 工序编号
  4850. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4851. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4852. // List<OneCheckItem> items = new List<OneCheckItem>()
  4853. // {
  4854. // new OneCheckItem()
  4855. // {
  4856. // Onecheck_name="胶圈装配行程设定上限",
  4857. // Onecheck_content="上限值",
  4858. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4859. // },
  4860. // };
  4861. // OneCheckData oneCheckData = new OneCheckData()
  4862. // {
  4863. // Line_code = GlobalContext.LineCode,
  4864. // Line_name = GlobalContext.LineName,
  4865. // Equipment_code = equipmentCode,
  4866. // Equipment_name = equipmentCode,
  4867. // Workorder_code = workorder_code,
  4868. // Procedure_code = accno,
  4869. // Procedure_name = processItem,
  4870. // Oneckeck_values = items,
  4871. // Onecheck_empcode = "",
  4872. // Onecheck_empname = "",
  4873. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4874. // };
  4875. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4876. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4877. // short result = result1 == 1 ? (short)1 : (short)2;
  4878. // // MES_Flag 为4MES报错
  4879. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4880. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4881. // }
  4882. // catch (Exception ex)
  4883. // {
  4884. // // MES_Flag 为2上位机报错
  4885. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4886. // string str = ex.StackTrace;
  4887. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4888. // }
  4889. //}
  4890. // ReadStation_S1_2 节拍接口+AGV
  4891. /// <summary>
  4892. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4893. /// </summary>
  4894. /// <param name="plcNo">PLC编号</param>
  4895. /// <param name="stationNameStr">工站全称</param>
  4896. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4897. {
  4898. Stopwatch stopwatch1 = new Stopwatch();
  4899. Stopwatch stopwatch2 = new Stopwatch();
  4900. try
  4901. {
  4902. stopwatch1.Start();
  4903. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4904. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4905. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4906. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4907. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4908. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4909. // ZS 将SN发给ICT标机(串口)
  4910. short a1MES_FLAG_ICT = 1;
  4911. stopwatch2.Start();
  4912. // MES_Flag
  4913. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4914. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4915. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4916. writeToPLC_Flag.Adress = 2182;
  4917. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4918. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4919. stopwatch2.Stop();
  4920. }
  4921. catch (Exception ex)
  4922. {
  4923. string str = ex.StackTrace;
  4924. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4925. stopwatch2.Start();
  4926. // MES_Flag
  4927. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4928. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4929. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4930. writeToPLC_Flag.Adress = 2182;
  4931. writeToPLC_Flag.Value = (short)4;
  4932. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4933. stopwatch2.Stop();
  4934. }
  4935. stopwatch1.Stop();
  4936. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4937. }
  4938. /// <summary>
  4939. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4940. /// </summary>
  4941. /// <param name="plcNo">PLC编号</param>
  4942. /// <param name="stationNameStr">工站全称</param>
  4943. private void S1节拍接口(int plcNo, string stationNameStr)
  4944. {
  4945. Stopwatch stopwatch1 = new Stopwatch();
  4946. Stopwatch stopwatch2 = new Stopwatch();
  4947. string resultStr = string.Empty;
  4948. try
  4949. {
  4950. stopwatch1.Start();
  4951. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4952. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4953. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4954. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4955. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4956. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4957. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  4958. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4959. if (!actionBool)
  4960. {
  4961. stopwatch2.Start();
  4962. // MES_Flag
  4963. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4964. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4965. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  4966. writeToPLC_Flag1.Adress = 2254;
  4967. writeToPLC_Flag1.Value = (short)1;
  4968. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  4969. stopwatch2.Stop();
  4970. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4971. return;
  4972. }
  4973. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  4974. {
  4975. stopwatch2.Start();
  4976. // MES_Flag
  4977. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4978. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  4979. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  4980. writeToPLC_Flag2.Adress = 2254;
  4981. writeToPLC_Flag2.Value = (short)1;
  4982. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  4983. stopwatch2.Stop();
  4984. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4985. return;
  4986. }
  4987. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  4988. { // 查产品SN
  4989. a1OEEPartNo = "Test"; // ZS
  4990. }
  4991. short a1OEEMES_FLAG = 0;
  4992. // 上传OEE
  4993. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  4994. a1OEEMES_FLAG = result.Item1;
  4995. resultStr = result.Item2;
  4996. stopwatch2.Start();
  4997. // MES_Flag
  4998. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4999. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5000. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5001. writeToPLC_Flag.Adress = 2254;
  5002. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  5003. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5004. stopwatch2.Stop();
  5005. }
  5006. catch (Exception ex)
  5007. {
  5008. string str = ex.StackTrace;
  5009. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5010. // MES_Flag
  5011. stopwatch2.Start();
  5012. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  5013. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5014. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5015. writeToPLC_Flag.Adress = 2254;
  5016. writeToPLC_Flag.Value = (short)4;
  5017. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5018. stopwatch2.Stop();
  5019. }
  5020. stopwatch1.Stop();
  5021. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5022. }
  5023. /// <summary>
  5024. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  5025. /// </summary>
  5026. /// <param name="plcNo">PLC编号</param>
  5027. /// <param name="stationNameStr">工站全称</param>
  5028. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  5029. {
  5030. Stopwatch stopwatch1 = new Stopwatch();
  5031. Stopwatch stopwatch2 = new Stopwatch();
  5032. try
  5033. {
  5034. stopwatch1.Start();
  5035. // ZS 呼叫AGV
  5036. short a1AGVUpCall = 2;
  5037. stopwatch2.Start();
  5038. // a1AGVUpCall
  5039. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5040. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5041. writeToPLC_Flag.Name = "a1AGVUpCall";
  5042. writeToPLC_Flag.Adress = 2307;
  5043. writeToPLC_Flag.Value = a1AGVUpCall;
  5044. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5045. stopwatch2.Stop();
  5046. }
  5047. catch (Exception ex)
  5048. {
  5049. string str = ex.StackTrace;
  5050. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5051. // a1AGVUpCall
  5052. stopwatch2.Start();
  5053. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  5054. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5055. writeToPLC_Flag.Name = "a1AGVUpCall";
  5056. writeToPLC_Flag.Adress = 2307;
  5057. writeToPLC_Flag.Value = (short)4;
  5058. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5059. stopwatch2.Stop();
  5060. }
  5061. stopwatch1.Stop();
  5062. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5063. }
  5064. /// <summary>
  5065. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  5066. /// </summary>
  5067. /// <param name="plcNo">PLC编号</param>
  5068. /// <param name="stationNameStr">工站全称</param>
  5069. private void S1AGV上料完成(int plcNo, string stationNameStr)
  5070. {
  5071. Stopwatch stopwatch1 = new Stopwatch();
  5072. Stopwatch stopwatch2 = new Stopwatch();
  5073. try
  5074. {
  5075. stopwatch1.Start();
  5076. // ZS AGV上料完成,让小车离开
  5077. short a1AGVUpEnd = 2;
  5078. stopwatch2.Start();
  5079. // a1AGVUpEnd
  5080. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5081. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5082. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5083. writeToPLC_Flag.Adress = 2309;
  5084. writeToPLC_Flag.Value = a1AGVUpEnd;
  5085. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5086. stopwatch2.Stop();
  5087. }
  5088. catch (Exception ex)
  5089. {
  5090. string str = ex.StackTrace;
  5091. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5092. // a1AGVUpEnd
  5093. stopwatch2.Start();
  5094. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  5095. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5096. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5097. writeToPLC_Flag.Adress = 2309;
  5098. writeToPLC_Flag.Value = (short)4;
  5099. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5100. stopwatch2.Stop();
  5101. }
  5102. stopwatch1.Stop();
  5103. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5104. }
  5105. /// <summary>
  5106. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  5107. /// </summary>
  5108. /// <param name="plcNo">PLC编号</param>
  5109. /// <param name="stationNameStr">工站全称</param>
  5110. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  5111. {
  5112. Stopwatch stopwatch1 = new Stopwatch();
  5113. Stopwatch stopwatch2 = new Stopwatch();
  5114. try
  5115. {
  5116. stopwatch1.Start();
  5117. // ZS 呼叫AGV
  5118. short a1AGVDownCall = 2;
  5119. stopwatch2.Start();
  5120. // a1AGVDownCall
  5121. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5122. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5123. writeToPLC_Flag.Name = "a1AGVDownCall";
  5124. writeToPLC_Flag.Adress = 2320;
  5125. writeToPLC_Flag.Value = a1AGVDownCall;
  5126. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5127. stopwatch2.Stop();
  5128. }
  5129. catch (Exception ex)
  5130. {
  5131. string str = ex.StackTrace;
  5132. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5133. // a1AGVDownCall
  5134. stopwatch2.Start();
  5135. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5136. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5137. writeToPLC_Flag.Name = "a1AGVDownCall";
  5138. writeToPLC_Flag.Adress = 2320;
  5139. writeToPLC_Flag.Value = (short)4;
  5140. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5141. stopwatch2.Stop();
  5142. }
  5143. stopwatch1.Stop();
  5144. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5145. }
  5146. /// <summary>
  5147. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5148. /// </summary>
  5149. /// <param name="plcNo">PLC编号</param>
  5150. /// <param name="stationNameStr">工站全称</param>
  5151. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5152. {
  5153. Stopwatch stopwatch1 = new Stopwatch();
  5154. Stopwatch stopwatch2 = new Stopwatch();
  5155. try
  5156. {
  5157. stopwatch1.Start();
  5158. // ZS AGV上料完成,让小车离开
  5159. short a1AGVDownEnd = 2;
  5160. stopwatch2.Start();
  5161. // a1AGVDownEnd
  5162. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5163. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5164. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5165. writeToPLC_Flag.Adress = 2322;
  5166. writeToPLC_Flag.Value = a1AGVDownEnd;
  5167. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5168. stopwatch2.Stop();
  5169. }
  5170. catch (Exception ex)
  5171. {
  5172. string str = ex.StackTrace;
  5173. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5174. // a1AGVDownEnd
  5175. stopwatch2.Start();
  5176. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5177. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5178. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5179. writeToPLC_Flag.Adress = 2322;
  5180. writeToPLC_Flag.Value = (short)4;
  5181. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5182. stopwatch2.Stop();
  5183. }
  5184. stopwatch1.Stop();
  5185. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5186. }
  5187. #endregion [S1] Tray盘上料装备(板测)
  5188. #endregion PLC1 张超凡
  5189. #region PLC2 李晓奇
  5190. #region [S2] FCT(板测)
  5191. /// <summary>
  5192. /// S2工位的数据- 触发信号上次的值
  5193. /// </summary>
  5194. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5195. /// <summary>
  5196. /// S2工位的数据(含触发信号)
  5197. /// </summary>
  5198. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5199. /// <summary>
  5200. /// S2工位的数据- 回写点位
  5201. /// </summary>
  5202. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5203. /// <summary>
  5204. /// [S2] FCT(板测)
  5205. /// </summary>
  5206. /// <param name="plcNo">PLC编号</param>
  5207. //private void ReadStation_S2(int plcNo)
  5208. //{
  5209. // // [S1] Tray盘上料装备
  5210. // // [S2] FCT
  5211. // // [S3] 值板机
  5212. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5213. // // [S5] Tray盘下料装备
  5214. // /// 上位机心跳
  5215. // /// 获取设备报警数据与状态信息
  5216. // string stationCode = "[S2]";
  5217. // string stationName = "FCT";
  5218. // string stationNameStr = stationCode + stationName;
  5219. // #region 创建字典
  5220. // // 触发信号字典 赋值
  5221. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5222. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5223. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5224. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5225. // // PLC数据字典 赋值
  5226. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5227. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5228. // s2PLCData.Add("b1ProductSN_Check", 0);
  5229. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5230. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5231. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5232. // s2PLCData.Add("b1ProductSN_Bind", "");
  5233. // s2PLCData.Add("b1Part1SN_Bind", "");
  5234. // s2PLCData.Add("b1Part2SN_Bind", "");
  5235. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5236. // s2PLCData.Add("b1MES_FLAG", 0);
  5237. // s2PLCData.Add("b1ProductSN", 0);
  5238. // s2PLCData.Add("b1Part1Result", 0);
  5239. // s2PLCData.Add("b1Part2Result", 0);
  5240. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5241. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5242. // s2PLCData.Add("b1OEEProductSN", "");
  5243. // s2PLCData.Add("b1OEEType", 0);
  5244. // #endregion 创建字典
  5245. // while (IsRun)
  5246. // {
  5247. // try
  5248. // {
  5249. // if (!GlobalContext._IsCon_Funs2)
  5250. // {
  5251. // UpdatePLCMonitor(1, plcNo, 0);
  5252. // continue;
  5253. // }
  5254. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5255. // {
  5256. // Stopwatch stopwatch1 = new Stopwatch();
  5257. // Stopwatch stopwatch2 = new Stopwatch();
  5258. // stopwatch1.Start();
  5259. // stopwatch2.Start();
  5260. // #region 一次性读取所有数据
  5261. // // 一次性读取所有数据
  5262. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5263. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5264. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5265. // int[] datas = data1.Concat(data2).ToArray();
  5266. // datas = datas.Concat(data3).ToArray();
  5267. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5268. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5269. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5270. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5271. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5272. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5273. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5274. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5275. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5276. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5277. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5278. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5279. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5280. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5281. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5282. // s2PLCData["b1MES_FLAG"] = datas[169];
  5283. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5284. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5285. // s2PLCData["b1Part1Result"] = datas[190];
  5286. // s2PLCData["b1Part2Result"] = datas[191];
  5287. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5288. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5289. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5290. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5291. // s2PLCData["b1OEEType"] = datas[224];
  5292. // #endregion 一次性读取所有数据
  5293. // stopwatch2.Stop();
  5294. // #region 回写操作,写后清空flag
  5295. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5296. // #endregion 回写操作,写后清空flag
  5297. // #region 进站校验
  5298. // try
  5299. // {
  5300. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5301. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5302. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5303. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5304. // {
  5305. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5306. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5307. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5308. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5309. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5310. // }
  5311. // }
  5312. // catch (Exception ex)
  5313. // {
  5314. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5315. // string str = ex.StackTrace;
  5316. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5317. // }
  5318. // #endregion 进站校验
  5319. // #region 二穴载具解绑/绑定(产品换载具)
  5320. // try
  5321. // {
  5322. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5323. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5324. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5325. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5326. // {
  5327. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5328. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5329. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5330. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5331. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5332. // }
  5333. // }
  5334. // catch (Exception ex)
  5335. // {
  5336. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  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. // #region FCT-出站接口
  5342. // try
  5343. // {
  5344. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5345. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5346. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5347. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5348. // {
  5349. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5350. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5351. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5352. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5353. // }
  5354. // }
  5355. // catch (Exception ex)
  5356. // {
  5357. // // MES_Flag 为6上位机报错
  5358. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5359. // string str = ex.StackTrace;
  5360. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5361. // }
  5362. // #endregion FCT-出站接口
  5363. // #region 节拍接口
  5364. // try
  5365. // {
  5366. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5367. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5368. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5369. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5370. // {
  5371. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5372. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5373. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5374. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5375. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5376. // }
  5377. // }
  5378. // catch (Exception ex)
  5379. // {
  5380. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5381. // string str = ex.StackTrace;
  5382. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5383. // }
  5384. // #endregion 节拍接口
  5385. // #region 心跳
  5386. // try
  5387. // {
  5388. // short states = 0;
  5389. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5390. // }
  5391. // catch (Exception ex)
  5392. // {
  5393. // string str = ex.StackTrace;
  5394. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5395. // }
  5396. // #endregion 心跳
  5397. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5398. // stopwatch1.Stop();
  5399. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5400. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5401. // }
  5402. // else
  5403. // {
  5404. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5405. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5406. // Funs[plcNo].Connect();
  5407. // }
  5408. // }
  5409. // catch (Exception ex)
  5410. // {
  5411. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5412. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5413. // Funs[plcNo].ReConnect();
  5414. // }
  5415. // Thread.Sleep(IntervalReadPLC);
  5416. // }
  5417. //}
  5418. /// <summary>
  5419. /// [S2] FCT(板测)- 进站校验
  5420. /// </summary>
  5421. /// <param name="plcNo">PLC编号</param>
  5422. /// <param name="stationNameStr">工站全称</param>
  5423. private void S2进站校验(int plcNo, string stationNameStr)
  5424. {
  5425. Stopwatch stopwatch1 = new Stopwatch();
  5426. Stopwatch stopwatch2 = new Stopwatch();
  5427. try
  5428. {
  5429. stopwatch1.Start();
  5430. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5431. sn = sn.Replace("\0", "");
  5432. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5433. // 查询物料码By载具码 并判断是不是假产品
  5434. string cavityData = string.Empty;
  5435. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5436. if (string.IsNullOrEmpty(cavityData))
  5437. cavityData = "";
  5438. if (snResult != 0)
  5439. {
  5440. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5441. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5442. writeToPLC_Flag1.Adress = 2003;
  5443. writeToPLC_Flag1.Value = (short)6;
  5444. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5445. stopwatch1.Stop();
  5446. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5447. return;
  5448. }
  5449. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5450. string[] cavitySNs = cavityData.Split('.');
  5451. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5452. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5453. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5454. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5455. if (cavitySNs != null && cavitySNs.Length >= 2)
  5456. {
  5457. b1Part1SN_Check = cavitySNs[0];
  5458. b1Part2SN_Check = cavitySNs[1];
  5459. b1Part1Result_Check = 2;
  5460. b1Part2Result_Check = 2;
  5461. }
  5462. if (b1Part1SN_Check == "假产品")
  5463. b1Part1Result_Check = 3;
  5464. if (b1Part2SN_Check == "假产品")
  5465. b1Part2Result_Check = 3;
  5466. // 调用MES进站
  5467. stopwatch2.Start();
  5468. // 调用MES进站 - 产品1
  5469. List<TestItem> item;
  5470. int result1 = b1Part1Result_Check;
  5471. if (result1 != 3)
  5472. {
  5473. item = new List<TestItem>();
  5474. item.Add(new TestItem()
  5475. {
  5476. Parameter_name = "载具码",
  5477. Parameter_value = sn,
  5478. });
  5479. item.Add(new TestItem()
  5480. {
  5481. Parameter_name = "载具穴号",
  5482. Parameter_value = "1",
  5483. });
  5484. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5485. }
  5486. // 调用MES进站 - 产品2
  5487. int result2 = b1Part2Result_Check;
  5488. if (result2 != 3)
  5489. {
  5490. item = new List<TestItem>();
  5491. item.Add(new TestItem()
  5492. {
  5493. Parameter_name = "载具码",
  5494. Parameter_value = sn,
  5495. });
  5496. item.Add(new TestItem()
  5497. {
  5498. Parameter_name = "载具穴号",
  5499. Parameter_value = "2",
  5500. });
  5501. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5502. }
  5503. stopwatch2.Stop();
  5504. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5505. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5506. int result = result1;
  5507. if (result == 1)
  5508. result = result2;
  5509. short b1MES_FLAG_Check = (short)result;
  5510. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5511. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5512. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5513. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5514. //// MES_Flag
  5515. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5516. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5517. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5518. writeToPLC_Flag.Adress = 2003;
  5519. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5520. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5521. {
  5522. Name = "b1Part1SN_Check",
  5523. Adress = 2024,
  5524. ValueType = PLCValueType.String,
  5525. ValueTypeStrLength = 20,
  5526. Value = b1Part1SN_Check
  5527. });
  5528. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5529. {
  5530. Name = "b1Part2SN_Check",
  5531. Adress = 2044,
  5532. ValueType = PLCValueType.String,
  5533. ValueTypeStrLength = 20,
  5534. Value = b1Part2SN_Check
  5535. });
  5536. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5537. {
  5538. Name = "b1Part1Result_Check",
  5539. Adress = 2064,
  5540. ValueType = PLCValueType.Short,
  5541. Value = b1Part1Result_Check
  5542. });
  5543. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5544. {
  5545. Name = "b1Part2Result_Check",
  5546. Adress = 2065,
  5547. ValueType = PLCValueType.Short,
  5548. Value = b1Part2Result_Check
  5549. });
  5550. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5551. }
  5552. catch (Exception ex)
  5553. {
  5554. string str = ex.StackTrace;
  5555. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5556. // MES_Flag
  5557. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5558. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5559. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5560. writeToPLC_Flag.Adress = 2003;
  5561. writeToPLC_Flag.Value = (short)6;
  5562. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5563. }
  5564. stopwatch1.Stop();
  5565. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5566. }
  5567. /// <summary>
  5568. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5569. /// </summary>
  5570. /// <param name="plcNo">PLC编号</param>
  5571. /// <param name="stationNameStr">工站全称</param>
  5572. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5573. {
  5574. Stopwatch stopwatch1 = new Stopwatch();
  5575. Stopwatch stopwatch2 = new Stopwatch();
  5576. try
  5577. {
  5578. stopwatch1.Start();
  5579. // 产品换载具
  5580. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5581. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5582. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5583. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5584. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5585. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5586. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5587. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5588. stopwatch2.Start();
  5589. #region 查询载具上的产品信息
  5590. //string cavityData = string.Empty;
  5591. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5592. //if (string.IsNullOrEmpty(cavityData))
  5593. // cavityData = "";
  5594. //if (snResult != 0)
  5595. //{
  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. // stopwatch1.Stop();
  5602. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5603. // return;
  5604. //}
  5605. #endregion 查询载具上的产品信息
  5606. #region 解绑(边线MES系统)
  5607. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5608. if (snResult != 0)
  5609. {
  5610. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5611. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5612. writeToPLC_Flag1.Adress = 2077;
  5613. writeToPLC_Flag1.Value = (short)6;
  5614. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5615. stopwatch1.Stop();
  5616. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5617. return;
  5618. }
  5619. #endregion 解绑(边线MES系统)
  5620. #region 存储绑定数据到 边线MES系统中
  5621. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5622. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5623. if (snResult != 0)
  5624. {
  5625. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5626. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5627. writeToPLC_Flag1.Adress = 2077;
  5628. writeToPLC_Flag1.Value = (short)6;
  5629. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5630. stopwatch1.Stop();
  5631. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5632. return;
  5633. }
  5634. #endregion 存储绑定数据到 边线MES系统中
  5635. stopwatch2.Stop();
  5636. short b1MES_FLAG_Unbind = 1;
  5637. // MES_Flag
  5638. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5639. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5640. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5641. writeToPLC_Flag.Adress = 2077;
  5642. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5643. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5644. }
  5645. catch (Exception ex)
  5646. {
  5647. string str = ex.StackTrace;
  5648. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5649. // MES_Flag
  5650. stopwatch2.Start();
  5651. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5652. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5653. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5654. writeToPLC_Flag.Adress = 2077;
  5655. writeToPLC_Flag.Value = (short)6;
  5656. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5657. stopwatch2.Stop();
  5658. }
  5659. stopwatch1.Stop();
  5660. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5661. }
  5662. //// 上次采集到的SN
  5663. //private string sn_FCT = string.Empty;
  5664. /// <summary>
  5665. /// [S2] FCT(板测)- 出站数据
  5666. /// </summary>
  5667. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5668. {
  5669. Stopwatch stopwatch1 = new Stopwatch();
  5670. Stopwatch stopwatch2 = new Stopwatch();
  5671. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5672. string stationNameStr = stationCode + stationName;
  5673. string processItem = stationName; // 测试项目
  5674. try
  5675. {
  5676. stopwatch1.Start();
  5677. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5678. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5679. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5680. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5681. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5682. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5683. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5684. bool pass1 = b1Part1Result == 1;
  5685. bool pass2 = b1Part2Result == 1;
  5686. #region 根据 载具SN 查 物料SN
  5687. string cavityData = string.Empty;
  5688. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5689. if (string.IsNullOrEmpty(cavityData))
  5690. cavityData = "";
  5691. if (snResult != 0)
  5692. {
  5693. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5694. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5695. writeToPLC_Flag1.Adress = 2169;
  5696. writeToPLC_Flag1.Value = (short)4;
  5697. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5698. stopwatch1.Stop();
  5699. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5700. return;
  5701. }
  5702. #endregion 根据 载具SN 查 物料SN
  5703. string[] cavitySNs = cavityData.Split('.');
  5704. string b1ProductSN1 = string.Empty;
  5705. string b1ProductSN2 = string.Empty;
  5706. if (cavitySNs != null && cavitySNs.Length >= 2)
  5707. {
  5708. b1ProductSN1 = cavitySNs[0];
  5709. b1ProductSN2 = cavitySNs[1];
  5710. }
  5711. stopwatch2.Start();
  5712. // 产品1
  5713. int result1 = 0;
  5714. if (b1ProductSN1 == "假产品")
  5715. result1 = 1;
  5716. else
  5717. {
  5718. List<TestItem> items1 = new List<TestItem>();
  5719. items1.Add(new TestItem()
  5720. {
  5721. Parameter_name = "载具码",
  5722. Parameter_value = b1ProductSN.ToString(),
  5723. Parameter_unit = ""
  5724. });
  5725. items1.Add(new TestItem()
  5726. {
  5727. Parameter_name = "载具穴号",
  5728. Parameter_value = "1",
  5729. Parameter_unit = ""
  5730. });
  5731. items1.Add(new TestItem()
  5732. {
  5733. Parameter_name = "产品结果",
  5734. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5735. Parameter_unit = ""
  5736. });
  5737. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5738. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5739. }
  5740. // 产品2
  5741. int result2 = 0;
  5742. if (b1ProductSN1 == "假产品")
  5743. result2 = 1;
  5744. else
  5745. {
  5746. List<TestItem> items2 = new List<TestItem>();
  5747. items2.Add(new TestItem()
  5748. {
  5749. Parameter_name = "载具码",
  5750. Parameter_value = b1ProductSN.ToString(),
  5751. Parameter_unit = ""
  5752. });
  5753. items2.Add(new TestItem()
  5754. {
  5755. Parameter_name = "载具穴号",
  5756. Parameter_value = "2",
  5757. Parameter_unit = ""
  5758. });
  5759. items2.Add(new TestItem()
  5760. {
  5761. Parameter_name = "产品结果",
  5762. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5763. Parameter_unit = ""
  5764. });
  5765. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5766. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5767. }
  5768. short result = 0;
  5769. List<int> results = new List<int>() { result1, result2 };
  5770. if (result1 == 1 && result2 == 1)
  5771. result = 1;
  5772. else if (results.Contains(3))
  5773. result = 3;
  5774. else if (results.Contains(2))
  5775. result = 2;
  5776. else if (results.Contains(4))
  5777. result = 4;
  5778. else
  5779. result = 4;
  5780. stopwatch2.Stop();
  5781. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5782. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5783. writeToPLC_Flag.Name = "b1MES_FLAG";
  5784. writeToPLC_Flag.Adress = 2169;
  5785. writeToPLC_Flag.Value = result;
  5786. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5787. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5788. }
  5789. catch (Exception ex)
  5790. {
  5791. stopwatch2.Restart();
  5792. // MES_Flag 为4上位机报错
  5793. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5794. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5795. writeToPLC_Flag.Name = "b1MES_FLAG";
  5796. writeToPLC_Flag.Adress = 2169;
  5797. writeToPLC_Flag.Value = (short)4;
  5798. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5799. stopwatch2.Stop();
  5800. string str = ex.StackTrace;
  5801. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5802. }
  5803. stopwatch1.Stop();
  5804. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5805. }
  5806. /// <summary>
  5807. /// [S2] FCT(板测)- 节拍接口
  5808. /// </summary>
  5809. /// <param name="plcNo">PLC编号</param>
  5810. /// <param name="stationNameStr">工站全称</param>
  5811. private void S2节拍接口(int plcNo, string stationNameStr)
  5812. {
  5813. Stopwatch stopwatch1 = new Stopwatch();
  5814. Stopwatch stopwatch2 = new Stopwatch();
  5815. string resultStr = string.Empty;
  5816. try
  5817. {
  5818. stopwatch1.Start();
  5819. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5820. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5821. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5822. if (!actionBool)
  5823. {
  5824. stopwatch2.Start();
  5825. // MES_Flag
  5826. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5827. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5828. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5829. writeToPLC_Flag1.Adress = 2203;
  5830. writeToPLC_Flag1.Value = (short)4;
  5831. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5832. stopwatch2.Stop();
  5833. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5834. return;
  5835. }
  5836. string b1OEEPartNo = string.Empty; // 物料码
  5837. if (string.IsNullOrEmpty(b1OEEProductSN))
  5838. {
  5839. stopwatch2.Start();
  5840. // MES_Flag
  5841. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5842. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5843. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5844. writeToPLC_Flag1.Adress = 2203;
  5845. writeToPLC_Flag1.Value = (short)1;
  5846. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5847. stopwatch2.Stop();
  5848. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5849. return;
  5850. }
  5851. else
  5852. { // 查产品SN
  5853. b1OEEPartNo = "Test"; // ZS
  5854. }
  5855. short b1OEEMES_FLAG = 0;
  5856. // 上传OEE
  5857. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5858. b1OEEMES_FLAG = result.Item1;
  5859. resultStr = result.Item2;
  5860. stopwatch2.Start();
  5861. // MES_Flag
  5862. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5863. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5864. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5865. writeToPLC_Flag.Adress = 2203;
  5866. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5867. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5868. stopwatch2.Stop();
  5869. }
  5870. catch (Exception ex)
  5871. {
  5872. string str = ex.StackTrace;
  5873. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5874. // MES_Flag
  5875. stopwatch2.Start();
  5876. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5877. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5878. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5879. writeToPLC_Flag.Adress = 2203;
  5880. writeToPLC_Flag.Value = (short)4;
  5881. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5882. stopwatch2.Stop();
  5883. }
  5884. stopwatch1.Stop();
  5885. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5886. }
  5887. #endregion [S2] FCT(板测)
  5888. #endregion PLC2 李晓奇
  5889. #region PLC3 刘永村
  5890. #region [S3] 值板机
  5891. /// <summary>
  5892. /// S3工位的数据- 触发信号上次的值
  5893. /// </summary>
  5894. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5895. /// <summary>
  5896. /// S3工位的数据(含触发信号)
  5897. /// </summary>
  5898. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5899. /// <summary>
  5900. /// S3工位的数据- 回写点位
  5901. /// </summary>
  5902. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5903. /// <summary>
  5904. /// [S3] 值板机
  5905. /// </summary>
  5906. /// <param name="plcNo">PLC编号</param>
  5907. //private void ReadStation_S3(int plcNo)
  5908. //{
  5909. // // [S1] Tray盘上料装备
  5910. // // [S2] FCT
  5911. // // [S3] 值板机
  5912. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5913. // // [S5] Tray盘下料装备
  5914. // /// 上位机心跳
  5915. // /// 获取设备报警数据与状态信息
  5916. // string stationCode = "[S3]";
  5917. // string stationName = "值板机";
  5918. // string stationNameStr = stationCode + stationName;
  5919. // #region 创建字典
  5920. // // 触发信号字典 赋值
  5921. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5922. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5923. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5924. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5925. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5926. // // PLC数据字典 赋值
  5927. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5928. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5929. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5930. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5931. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5932. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5933. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5934. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5935. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5936. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5937. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5938. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5939. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5940. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5941. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5942. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5943. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5944. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5945. // s3PLCData.Add("c1Result", 0); // 产品结果
  5946. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5947. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5948. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5949. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  5950. // #endregion 创建字典
  5951. // while (IsRun)
  5952. // {
  5953. // try
  5954. // {
  5955. // if (!GlobalContext._IsCon_Funs3)
  5956. // {
  5957. // UpdatePLCMonitor(1, plcNo, 0);
  5958. // continue;
  5959. // }
  5960. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5961. // {
  5962. // Stopwatch stopwatch1 = new Stopwatch();
  5963. // Stopwatch stopwatch2 = new Stopwatch();
  5964. // stopwatch1.Start();
  5965. // stopwatch2.Start();
  5966. // #region 一次性读取所有数据
  5967. // // 一次性读取所有数据
  5968. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  5969. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  5970. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  5971. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  5972. // int[] datas = data1.Concat(data2).ToArray();
  5973. // datas = datas.Concat(data3).ToArray();
  5974. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  5975. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  5976. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5977. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  5978. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  5979. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  5980. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5981. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  5982. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  5983. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  5984. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  5985. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5986. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  5987. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  5988. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  5989. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  5990. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5991. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  5992. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  5993. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  5994. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  5995. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  5996. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  5997. // #endregion 一次性读取所有数据
  5998. // stopwatch2.Stop();
  5999. // #region 回写操作,写后清空flag
  6000. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  6001. // #endregion 回写操作,写后清空flag
  6002. // #region S3进站校验
  6003. // try
  6004. // {
  6005. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  6006. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  6007. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  6008. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  6009. // {
  6010. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  6011. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6012. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  6013. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6014. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  6015. // }
  6016. // }
  6017. // catch (Exception ex)
  6018. // {
  6019. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6020. // string str = ex.StackTrace;
  6021. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6022. // }
  6023. // #endregion S3进站校验
  6024. // #region S3二穴载具解绑
  6025. // try
  6026. // {
  6027. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  6028. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  6029. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  6030. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  6031. // {
  6032. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6033. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  6034. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  6035. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  6036. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  6037. // }
  6038. // }
  6039. // catch (Exception ex)
  6040. // {
  6041. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  6042. // string str = ex.StackTrace;
  6043. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6044. // }
  6045. // #endregion S3二穴载具解绑
  6046. // #region S3二穴载具绑定
  6047. // try
  6048. // {
  6049. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  6050. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  6051. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  6052. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  6053. // {
  6054. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6055. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  6056. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  6057. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  6058. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  6059. // }
  6060. // }
  6061. // catch (Exception ex)
  6062. // {
  6063. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  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 S3二穴载具绑定
  6068. // #region S3出站接口(+一穴载具绑定)
  6069. // try
  6070. // {
  6071. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  6072. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  6073. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  6074. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  6075. // {
  6076. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  6077. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6078. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  6079. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  6080. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  6081. // }
  6082. // }
  6083. // catch (Exception ex)
  6084. // {
  6085. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  6086. // string str = ex.StackTrace;
  6087. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6088. // }
  6089. // #endregion S3出站接口(+一穴载具绑定)
  6090. // #region S3节拍接口
  6091. // try
  6092. // {
  6093. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  6094. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  6095. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  6096. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  6097. // {
  6098. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  6099. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6100. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  6101. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  6102. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  6103. // }
  6104. // }
  6105. // catch (Exception ex)
  6106. // {
  6107. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6108. // string str = ex.StackTrace;
  6109. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6110. // }
  6111. // #endregion S3节拍接口
  6112. // #region 心跳
  6113. // try
  6114. // {
  6115. // short states = 0;
  6116. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6117. // }
  6118. // catch (Exception ex)
  6119. // {
  6120. // string str = ex.StackTrace;
  6121. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6122. // }
  6123. // #endregion 心跳
  6124. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6125. // stopwatch1.Stop();
  6126. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6127. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6128. // }
  6129. // else
  6130. // {
  6131. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6132. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6133. // Funs[plcNo].Connect();
  6134. // }
  6135. // }
  6136. // catch (Exception ex)
  6137. // {
  6138. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6139. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6140. // Funs[plcNo].ReConnect();
  6141. // }
  6142. // Thread.Sleep(IntervalReadPLC);
  6143. // }
  6144. //}
  6145. /// <summary>
  6146. /// [S3] 值板机- 进站校验
  6147. /// </summary>
  6148. /// <param name="plcNo">PLC编号</param>
  6149. /// <param name="stationNameStr">工站全称</param>
  6150. private void S3进站校验(int plcNo, string stationNameStr)
  6151. {
  6152. Stopwatch stopwatch1 = new Stopwatch();
  6153. Stopwatch stopwatch2 = new Stopwatch();
  6154. try
  6155. {
  6156. stopwatch1.Start();
  6157. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6158. sn = sn.Replace("\0", "");
  6159. #region 查询载具上的产品信息
  6160. string cavityData = string.Empty;
  6161. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6162. if (string.IsNullOrEmpty(cavityData))
  6163. cavityData = "";
  6164. if (snResult != 0)
  6165. {
  6166. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6167. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6168. writeToPLC_Flag1.Adress = 2003;
  6169. writeToPLC_Flag1.Value = (short)6;
  6170. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6171. stopwatch1.Stop();
  6172. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6173. return;
  6174. }
  6175. #endregion 查询载具上的产品信息
  6176. string[] cavitySNs = cavityData.Split('.');
  6177. string part1Str = ""; // 产品1的SN码
  6178. string part2Str = ""; // 产品2的SN码
  6179. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6180. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6181. if (cavitySNs != null && cavitySNs.Length >= 2)
  6182. {
  6183. part1Str = cavitySNs[0];
  6184. part2Str = cavitySNs[1];
  6185. c1Part1Result_Check = 2;
  6186. c1Part2Result_Check = 2;
  6187. }
  6188. if (part1Str == "假产品")
  6189. c1Part1Result_Check = 3;
  6190. if (part2Str == "假产品")
  6191. c1Part2Result_Check = 3;
  6192. // 调用MES进站
  6193. stopwatch2.Start();
  6194. // 调用MES进站 - 产品1
  6195. List<TestItem> item;
  6196. int result1 = c1Part1Result_Check;
  6197. if (result1 != 3)
  6198. {
  6199. item = new List<TestItem>();
  6200. item.Add(new TestItem()
  6201. {
  6202. Parameter_name = "载具码",
  6203. Parameter_value = sn,
  6204. });
  6205. item.Add(new TestItem()
  6206. {
  6207. Parameter_name = "载具穴号",
  6208. Parameter_value = "1",
  6209. });
  6210. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6211. }
  6212. // 调用MES进站 - 产品2
  6213. int result2 = c1Part2Result_Check;
  6214. if (result2 != 3)
  6215. {
  6216. item = new List<TestItem>();
  6217. item.Add(new TestItem()
  6218. {
  6219. Parameter_name = "载具码",
  6220. Parameter_value = sn,
  6221. });
  6222. item.Add(new TestItem()
  6223. {
  6224. Parameter_name = "载具穴号",
  6225. Parameter_value = "2",
  6226. });
  6227. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6228. }
  6229. stopwatch2.Stop();
  6230. if (result1 == 2)
  6231. c1Part1Result_Check = 2;
  6232. if (result2 == 2)
  6233. c1Part2Result_Check = 2;
  6234. int result = result1;
  6235. if (result == 1)
  6236. result = result2;
  6237. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6238. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6239. short c1MES_FLAG_Check = (short)result;
  6240. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6241. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6242. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6243. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6244. //// MES_Flag
  6245. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6246. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6247. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6248. writeToPLC_Flag.Adress = 2003;
  6249. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6250. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6251. {
  6252. Name = "c1Part1Result_Check",
  6253. Adress = 2024,
  6254. ValueType = PLCValueType.Short,
  6255. Value = c1Part1Result_Check
  6256. });
  6257. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6258. {
  6259. Name = "c1Part2Result_Check",
  6260. Adress = 2025,
  6261. ValueType = PLCValueType.Short,
  6262. Value = c1Part2Result_Check
  6263. });
  6264. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6265. {
  6266. Name = "c1Part1Num_Check",
  6267. Adress = 2026,
  6268. ValueType = PLCValueType.Short,
  6269. Value = c1Part1Num_Check
  6270. });
  6271. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6272. {
  6273. Name = "c1Part2Num_Check",
  6274. Adress = 2027,
  6275. ValueType = PLCValueType.Short,
  6276. Value = c1Part2Num_Check
  6277. });
  6278. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6279. }
  6280. catch (Exception ex)
  6281. {
  6282. string str = ex.StackTrace;
  6283. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6284. // MES_Flag
  6285. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6286. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6287. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6288. writeToPLC_Flag.Adress = 2003;
  6289. writeToPLC_Flag.Value = (short)6;
  6290. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6291. }
  6292. stopwatch1.Stop();
  6293. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6294. }
  6295. /// <summary>
  6296. /// [S3] 值板机 - 二穴载具解绑
  6297. /// </summary>
  6298. /// <param name="plcNo">PLC编号</param>
  6299. /// <param name="stationNameStr">工站全称</param>
  6300. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6301. {
  6302. Stopwatch stopwatch1 = new Stopwatch();
  6303. Stopwatch stopwatch2 = new Stopwatch();
  6304. try
  6305. {
  6306. stopwatch1.Start();
  6307. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6308. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6309. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6310. // 解绑
  6311. #region 查询载具上的产品信息
  6312. string cavityData = string.Empty;
  6313. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6314. if (string.IsNullOrEmpty(cavityData))
  6315. cavityData = "";
  6316. if (snResult != 0)
  6317. {
  6318. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6319. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6320. writeToPLC_Flag1.Adress = 2082;
  6321. writeToPLC_Flag1.Value = (short)6;
  6322. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6323. stopwatch1.Stop();
  6324. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6325. return;
  6326. }
  6327. #endregion 查询载具上的产品信息
  6328. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6329. #region 解绑
  6330. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6331. {
  6332. // 删除
  6333. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6334. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6335. }
  6336. else
  6337. {
  6338. string data_new = string.Join(".", cavitySNs);
  6339. // 删除再插入
  6340. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6341. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6342. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6343. }
  6344. #endregion 解绑
  6345. short c1MES_FLAG_Unbind = 1;
  6346. stopwatch2.Start();
  6347. // MES_Flag
  6348. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6349. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6350. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6351. writeToPLC_Flag.Adress = 2082;
  6352. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6353. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6354. stopwatch2.Stop();
  6355. }
  6356. catch (Exception ex)
  6357. {
  6358. string str = ex.StackTrace;
  6359. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6360. // MES_Flag
  6361. stopwatch2.Start();
  6362. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6363. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6364. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6365. writeToPLC_Flag.Adress = 2082;
  6366. writeToPLC_Flag.Value = (short)6;
  6367. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6368. stopwatch2.Stop();
  6369. }
  6370. stopwatch1.Stop();
  6371. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6372. }
  6373. /// <summary>
  6374. /// [S3] 值板机 - 二穴载具绑定
  6375. /// </summary>
  6376. /// <param name="plcNo">PLC编号</param>
  6377. /// <param name="stationNameStr">工站全称</param>
  6378. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6379. {
  6380. Stopwatch stopwatch1 = new Stopwatch();
  6381. Stopwatch stopwatch2 = new Stopwatch();
  6382. try
  6383. {
  6384. stopwatch1.Start();
  6385. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6386. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6387. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6388. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6389. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6390. stopwatch2.Start();
  6391. #region 查询载具上的产品信息
  6392. string cavityData = string.Empty;
  6393. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6394. if (string.IsNullOrEmpty(cavityData))
  6395. cavityData = "";
  6396. if (snResult != 0)
  6397. {
  6398. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6399. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6400. writeToPLC_Flag1.Adress = 2115;
  6401. writeToPLC_Flag1.Value = (short)6;
  6402. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6403. stopwatch1.Stop();
  6404. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6405. return;
  6406. }
  6407. #endregion 查询载具上的产品信息
  6408. // 产品换载具
  6409. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6410. string partSn1 = "";
  6411. string partSn2 = "";
  6412. if (cavitySNs != null && cavitySNs.Length >= 2)
  6413. {
  6414. partSn1 = cavitySNs[0];
  6415. partSn2 = cavitySNs[1];
  6416. }
  6417. string data_new = string.Empty;
  6418. // 是否是两个穴位交换
  6419. if (c1CavityReverse_Bind == 1)
  6420. {
  6421. // 交换
  6422. data_new = string.Concat(partSn2, ".", partSn1);
  6423. }
  6424. else
  6425. { // 不交换
  6426. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6427. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6428. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6429. data_new = string.Join(".", cavitySNs);
  6430. }
  6431. // 删除再插入
  6432. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6433. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6434. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6435. stopwatch2.Stop();
  6436. short c1MES_FLAG_Bind = 1;
  6437. // MES_Flag
  6438. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6439. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6440. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6441. writeToPLC_Flag.Adress = 2115;
  6442. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6443. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6444. }
  6445. catch (Exception ex)
  6446. {
  6447. string str = ex.StackTrace;
  6448. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6449. // MES_Flag
  6450. stopwatch2.Start();
  6451. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6452. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6453. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6454. writeToPLC_Flag.Adress = 2115;
  6455. writeToPLC_Flag.Value = (short)6;
  6456. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6457. stopwatch2.Stop();
  6458. }
  6459. stopwatch1.Stop();
  6460. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6461. }
  6462. //// 上次采集到的SN
  6463. //private string sn_值板机 = string.Empty;
  6464. /// <summary>
  6465. /// [S3] 值板机 - 出站接口
  6466. /// </summary>
  6467. /// <param name="plcNo">PLC编号</param>
  6468. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6469. {
  6470. Stopwatch stopwatch1 = new Stopwatch();
  6471. Stopwatch stopwatch2 = new Stopwatch();
  6472. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6473. string stationNameStr = stationCode + stationName;
  6474. string processItem = stationName; // 测试项目
  6475. try
  6476. {
  6477. stopwatch1.Start();
  6478. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6479. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6480. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6481. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6482. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6483. sn = sn.Replace("\0", "");
  6484. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6485. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6486. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6487. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6488. bool pass = c1Result == 1;
  6489. // 查sn
  6490. #region 查询载具上的产品信息
  6491. string cavityData = string.Empty;
  6492. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6493. if (string.IsNullOrEmpty(cavityData))
  6494. cavityData = "";
  6495. if (snResult != 0)
  6496. {
  6497. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6498. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6499. writeToPLC_Flag1.Adress = 2150;
  6500. writeToPLC_Flag1.Value = (short)4;
  6501. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6502. stopwatch1.Stop();
  6503. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6504. return;
  6505. }
  6506. #endregion 查询载具上的产品信息
  6507. string[] cavitySNs = cavityData.Split('.');
  6508. string productSN = "";
  6509. if (cavitySNs != null && cavitySNs.Length >= 2)
  6510. {
  6511. productSN = cavitySNs[c1VehicleCavity];
  6512. cavitySNs[c1VehicleCavity] = "";
  6513. }
  6514. stopwatch2.Start();
  6515. List<TestItem> items = new List<TestItem>();
  6516. items.Add(new TestItem()
  6517. {
  6518. Parameter_name = "二穴载具码",
  6519. Parameter_value = c1ProductSN_Check,
  6520. Parameter_unit = ""
  6521. });
  6522. items.Add(new TestItem()
  6523. {
  6524. Parameter_name = "二穴载具穴号",
  6525. Parameter_value = c1VehicleCavity.ToString(),
  6526. Parameter_unit = ""
  6527. });
  6528. items.Add(new TestItem()
  6529. {
  6530. Parameter_name = "一穴载具码",
  6531. Parameter_value = sn,
  6532. Parameter_unit = ""
  6533. });
  6534. items.Add(new TestItem()
  6535. {
  6536. Parameter_name = "一穴载具穴号",
  6537. Parameter_value = "1",
  6538. Parameter_unit = ""
  6539. });
  6540. items.Add(new TestItem()
  6541. {
  6542. Parameter_name = "产品结果",
  6543. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6544. Parameter_unit = ""
  6545. });
  6546. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6547. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6548. short result = (short)result1;
  6549. stopwatch2.Stop();
  6550. #region 存储绑定数据到 边线MES系统中
  6551. if (result == 1)
  6552. {
  6553. string data = string.Concat(productSN);
  6554. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6555. if (resultMesR != 0)
  6556. {
  6557. result = 4;
  6558. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6559. }
  6560. }
  6561. #endregion 存储绑定数据到 边线MES系统中
  6562. #region 产品从 来源载具(二穴载具)中删除
  6563. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6564. {
  6565. // 删除
  6566. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6567. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6568. }
  6569. else
  6570. {
  6571. string data_new = string.Join(".", cavitySNs);
  6572. // 删除再插入
  6573. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6574. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6575. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6576. }
  6577. #endregion 产品从 来源载具(二穴载具)中删除
  6578. // MES_Flag 为MES报错
  6579. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6580. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6581. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6582. writeToPLC_Flag.Name = "c1MES_FLAG";
  6583. writeToPLC_Flag.Adress = 2150;
  6584. writeToPLC_Flag.Value = result;
  6585. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6586. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6587. }
  6588. catch (Exception ex)
  6589. {
  6590. stopwatch2.Restart();
  6591. // MES_Flag 为4上位机报错
  6592. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6593. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6594. writeToPLC_Flag.Name = "c1MES_FLAG";
  6595. writeToPLC_Flag.Adress = 2150;
  6596. writeToPLC_Flag.Value = (short)4;
  6597. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6598. stopwatch2.Stop();
  6599. string str = ex.StackTrace;
  6600. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6601. }
  6602. stopwatch1.Stop();
  6603. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6604. }
  6605. /// <summary>
  6606. /// [S3] 值板机- 节拍接口
  6607. /// </summary>
  6608. /// <param name="plcNo">PLC编号</param>
  6609. /// <param name="stationNameStr">工站全称</param>
  6610. private void S3节拍接口(int plcNo, string stationNameStr)
  6611. {
  6612. Stopwatch stopwatch1 = new Stopwatch();
  6613. Stopwatch stopwatch2 = new Stopwatch();
  6614. string resultStr = string.Empty;
  6615. try
  6616. {
  6617. stopwatch1.Start();
  6618. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6619. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6620. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6621. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6622. if (!actionBool)
  6623. {
  6624. stopwatch2.Start();
  6625. // MES_Flag
  6626. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6627. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6628. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6629. writeToPLC_Flag1.Adress = 2204;
  6630. writeToPLC_Flag1.Value = (short)4;
  6631. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6632. stopwatch2.Stop();
  6633. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6634. return;
  6635. }
  6636. string c1OEEPartNo = string.Empty; // 物料码
  6637. if (string.IsNullOrEmpty(c1OEEProductSN))
  6638. {
  6639. stopwatch2.Start();
  6640. // MES_Flag
  6641. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6642. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6643. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6644. writeToPLC_Flag1.Adress = 2204;
  6645. writeToPLC_Flag1.Value = (short)1;
  6646. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6647. stopwatch2.Stop();
  6648. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6649. return;
  6650. }
  6651. else
  6652. { // 查产品SN
  6653. c1OEEPartNo = "Test"; // ZS
  6654. }
  6655. short c1OEEMES_FLAG = 0;
  6656. // 上传OEE
  6657. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6658. c1OEEMES_FLAG = result.Item1;
  6659. resultStr = result.Item2;
  6660. stopwatch2.Start();
  6661. // MES_Flag
  6662. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6663. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6664. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6665. writeToPLC_Flag.Adress = 2204;
  6666. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6667. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6668. stopwatch2.Stop();
  6669. }
  6670. catch (Exception ex)
  6671. {
  6672. string str = ex.StackTrace;
  6673. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6674. // MES_Flag
  6675. stopwatch2.Start();
  6676. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6677. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6678. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6679. writeToPLC_Flag.Adress = 2204;
  6680. writeToPLC_Flag.Value = (short)4;
  6681. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6682. stopwatch2.Stop();
  6683. }
  6684. stopwatch1.Stop();
  6685. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6686. }
  6687. #endregion [S3] 值板机
  6688. #endregion PLC3 刘永村
  6689. #region PLC4 刘果段
  6690. #region [S4] 取放桁架
  6691. /// <summary>
  6692. /// S4工位的数据- 触发信号上次的值
  6693. /// </summary>
  6694. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6695. /// <summary>
  6696. /// S4工位的数据(含触发信号)
  6697. /// </summary>
  6698. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6699. /// <summary>
  6700. /// S4工位的数据- 回写点位
  6701. /// </summary>
  6702. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6703. /// <summary>
  6704. /// [S4] 取放桁架
  6705. /// </summary>
  6706. /// <param name="plcNo">PLC编号</param>
  6707. //private void ReadStation_S4(int plcNo)
  6708. //{
  6709. // // [S1] Tray盘上料装备
  6710. // // [S2] FCT
  6711. // // [S3] 值板机
  6712. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6713. // // [S5] Tray盘下料装备
  6714. // /// 上位机心跳
  6715. // /// 获取设备报警数据与状态信息
  6716. // string stationCode = "[S4_1]";
  6717. // string stationName = "载具下线装备";
  6718. // string stationNameStr = stationCode + stationName;
  6719. // string stationCode2 = "[S4_2]";
  6720. // string stationName2 = "桁架";
  6721. // string stationNameStr2 = stationCode2 + stationName2;
  6722. // string stationCode3 = "[S4_3]";
  6723. // string stationName3 = "提升机1";
  6724. // string stationNameStr3 = stationCode3 + stationName3;
  6725. // string stationCode4 = "[S4_4]";
  6726. // string stationName4 = "提升机2";
  6727. // string stationNameStr4 = stationCode4 + stationName4;
  6728. // string stationCode5 = "[S4_5]";
  6729. // string stationName5 = "载具上线装备";
  6730. // string stationNameStr5 = stationCode5 + stationName5;
  6731. // #region 创建字典
  6732. // // 触发信号字典 赋值
  6733. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6734. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6735. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6736. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6737. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6738. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6739. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6740. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6741. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6742. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6743. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6744. // // PLC数据字典 赋值
  6745. // // 载具下线装备(弹夹上线)
  6746. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6747. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6748. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6749. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6750. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6751. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6752. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6753. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6754. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6755. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6756. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6757. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6758. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6759. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6760. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6761. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6762. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6763. // s4PLCData.Add("d1Result", 0); // 产品结果
  6764. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6765. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6766. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6767. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6768. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6769. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6770. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6771. // // 真空标机(提升机)
  6772. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6773. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6774. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6775. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6776. // s4PLCData.Add("d3Result", 0); // 产品结果
  6777. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6778. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6779. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6780. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6781. // s4PLCData.Add("d4Result", 0); // 产品结果
  6782. // // 载具上线装备(弹夹下线)
  6783. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6784. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6785. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6786. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6787. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6788. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6789. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6790. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6791. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6792. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6793. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6794. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6795. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6796. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6797. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6798. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6799. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6800. // s4PLCData.Add("d5Result", 0); // 产品结果
  6801. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6802. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6803. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6804. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6805. // #endregion 创建字典
  6806. // while (IsRun)
  6807. // {
  6808. // try
  6809. // {
  6810. // if (!GlobalContext._IsCon_Funs4)
  6811. // {
  6812. // UpdatePLCMonitor(1, plcNo, 0);
  6813. // continue;
  6814. // }
  6815. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6816. // {
  6817. // Stopwatch stopwatch1 = new Stopwatch();
  6818. // Stopwatch stopwatch2 = new Stopwatch();
  6819. // stopwatch1.Start();
  6820. // stopwatch2.Start();
  6821. // #region 一次性读取所有数据
  6822. // // 载具下线装备(弹夹上线)
  6823. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6824. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6825. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6826. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6827. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6828. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6829. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6830. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6831. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6832. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6833. // int[] datas = data1.Concat(data2).ToArray();
  6834. // datas = datas.Concat(data3).ToArray();
  6835. // datas = datas.Concat(data4).ToArray();
  6836. // datas = datas.Concat(data5).ToArray();
  6837. // datas = datas.Concat(data6).ToArray();
  6838. // datas = datas.Concat(data7).ToArray();
  6839. // datas = datas.Concat(data8).ToArray();
  6840. // datas = datas.Concat(data9).ToArray();
  6841. // datas = datas.Concat(data10).ToArray();
  6842. // // 载具下线装备(弹夹上线)
  6843. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6844. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6845. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6846. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6847. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6848. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6849. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6850. // s4PLCData["d1MES_FLAG"] = datas[65];
  6851. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6852. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6853. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6854. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6855. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6856. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6857. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6858. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6859. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6860. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6861. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6862. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6863. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6864. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6865. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6866. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6867. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6868. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6869. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6870. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6871. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6872. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6873. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6874. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6875. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6876. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6877. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6878. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6879. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6880. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6881. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6882. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6883. // s4PLCData["d1Result"] = datas[386];
  6884. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6885. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6886. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6887. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6888. // s4PLCData["d1OEEType"] = datas[419];
  6889. // // 桁架(查询标机中弹夹的状态)
  6890. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6891. // s4PLCData["d2BulletclipStates"] = datas[431];
  6892. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6893. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6894. // // 真空标机
  6895. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6896. // s4PLCData["d3MES_FLAG"] = datas[463];
  6897. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6898. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6899. // s4PLCData["d3Result"] = datas[484];
  6900. // s4PLCData["d3Type"] = datas[485];
  6901. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6902. // s4PLCData["d4MES_FLAG"] = datas[496];
  6903. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6904. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6905. // s4PLCData["d4Result"] = datas[517];
  6906. // s4PLCData["d4Type"] = datas[518];
  6907. // // 载具上线装备(弹夹下线)
  6908. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6909. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6910. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6911. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6912. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6913. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6914. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6915. // s4PLCData["d5MES_FLAG"] = datas[591];
  6916. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6917. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6918. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6919. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6920. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6921. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6922. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6923. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6924. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6925. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6926. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6927. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6928. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6929. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6930. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6931. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6932. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6933. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6934. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6935. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6936. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6937. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6938. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6939. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6940. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6941. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6942. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6943. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6944. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6945. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6946. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6947. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6948. // s4PLCData["d5Result"] = datas[912];
  6949. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  6950. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  6951. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  6952. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  6953. // s4PLCData["d5OEEType"] = datas[945];
  6954. // #endregion 一次性读取所有数据
  6955. // stopwatch2.Stop();
  6956. // #region 回写操作,写后清空flag
  6957. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  6958. // #endregion 回写操作,写后清空flag
  6959. // // N801A-S4_1 弹夹扫码
  6960. // #region N801A-S4_1 弹夹扫码
  6961. // try
  6962. // {
  6963. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  6964. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  6965. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  6966. // {
  6967. // if (d1BulletclipScanCode == 1) // 0->1
  6968. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6969. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  6970. // }
  6971. // }
  6972. // catch (Exception ex)
  6973. // {
  6974. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  6975. // string str = ex.StackTrace;
  6976. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6977. // }
  6978. // #endregion N801A-S4_1 弹夹扫码
  6979. // // N801A-S4_1 载具扫码
  6980. // #region N801A-S4_1 载具扫码
  6981. // try
  6982. // {
  6983. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  6984. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  6985. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  6986. // {
  6987. // if (d1VehicleScanCode == 1) // 0->1
  6988. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6989. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  6990. // }
  6991. // }
  6992. // catch (Exception ex)
  6993. // {
  6994. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  6995. // string str = ex.StackTrace;
  6996. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6997. // }
  6998. // #endregion N801A-S4_1 载具扫码
  6999. // // N801A-S4_1 出站接口
  7000. // #region N801A-S4_1 出站接口
  7001. // try
  7002. // {
  7003. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  7004. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  7005. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  7006. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  7007. // {
  7008. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  7009. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7010. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  7011. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  7012. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  7013. // }
  7014. // }
  7015. // catch (Exception ex)
  7016. // {
  7017. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  7018. // string str = ex.StackTrace;
  7019. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7020. // }
  7021. // #endregion N801A-S4_1 出站接口
  7022. // // N801A-S4_1 节拍接口
  7023. // #region N801A-S4_1 节拍接口
  7024. // try
  7025. // {
  7026. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  7027. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  7028. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  7029. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  7030. // {
  7031. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  7032. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7033. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  7034. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  7035. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  7036. // }
  7037. // }
  7038. // catch (Exception ex)
  7039. // {
  7040. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7041. // string str = ex.StackTrace;
  7042. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7043. // }
  7044. // #endregion N801A-S4_1 节拍接口
  7045. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  7046. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  7047. // try
  7048. // {
  7049. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  7050. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  7051. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  7052. // {
  7053. // if (d2BulletclipScanCode == 1) // 0->1
  7054. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  7055. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  7056. // }
  7057. // }
  7058. // catch (Exception ex)
  7059. // {
  7060. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7061. // string str = ex.StackTrace;
  7062. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7063. // }
  7064. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  7065. // // N801A-S4_3 真空标机1 数据
  7066. // #region N801A-S4_3 真空标机1
  7067. // try
  7068. // {
  7069. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  7070. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  7071. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  7072. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  7073. // {
  7074. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  7075. // {
  7076. // int stationType = (int)s4PLCData["d3Type"];
  7077. // if (stationType == 1)
  7078. // {
  7079. // // S4_3进站接口
  7080. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  7081. // }
  7082. // else if (stationType == 2)
  7083. // {
  7084. // // S4_3出站接口
  7085. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  7086. // }
  7087. // }
  7088. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  7089. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  7090. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  7091. // }
  7092. // }
  7093. // catch (Exception ex)
  7094. // {
  7095. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7096. // string str = ex.StackTrace;
  7097. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7098. // }
  7099. // #endregion N801A-S4_3 真空标机1
  7100. // // N801A-S4_4 真空标机2 数据
  7101. // #region N801A-S4_4 真空标机2
  7102. // try
  7103. // {
  7104. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  7105. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  7106. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  7107. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  7108. // {
  7109. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  7110. // {
  7111. // int stationType = (int)s4PLCData["d4Type"];
  7112. // if (stationType == 1)
  7113. // {
  7114. // // S4_4进站接口
  7115. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  7116. // }
  7117. // else if (stationType == 2)
  7118. // {
  7119. // // S4_4出站接口
  7120. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  7121. // }
  7122. // }
  7123. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  7124. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  7125. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  7126. // }
  7127. // }
  7128. // catch (Exception ex)
  7129. // {
  7130. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7131. // string str = ex.StackTrace;
  7132. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7133. // }
  7134. // #endregion N801A-S4_4 真空标机2
  7135. // // N801A-S4_5 弹夹扫码 数据
  7136. // #region N801A-S4_5 弹夹扫码
  7137. // try
  7138. // {
  7139. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7140. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7141. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7142. // {
  7143. // if (d5BulletclipScanCode == 1) // 0->1
  7144. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7145. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7146. // }
  7147. // }
  7148. // catch (Exception ex)
  7149. // {
  7150. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7151. // string str = ex.StackTrace;
  7152. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7153. // }
  7154. // #endregion N801A-S4_5 弹夹扫码
  7155. // // N801A-S4_5 载具扫码 数据
  7156. // #region N801A-S4_5 载具扫码
  7157. // try
  7158. // {
  7159. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7160. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7161. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7162. // {
  7163. // if (d5VehicleScanCode == 1) // 0->1
  7164. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7165. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7166. // }
  7167. // }
  7168. // catch (Exception ex)
  7169. // {
  7170. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7171. // string str = ex.StackTrace;
  7172. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7173. // }
  7174. // #endregion N801A-S4_5 载具扫码
  7175. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7176. // #region N801A-S4_5 出站接口
  7177. // try
  7178. // {
  7179. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7180. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7181. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7182. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7183. // {
  7184. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7185. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7186. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7187. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7188. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7189. // }
  7190. // }
  7191. // catch (Exception ex)
  7192. // {
  7193. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7194. // string str = ex.StackTrace;
  7195. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7196. // }
  7197. // #endregion N801A-S4_5 出站接口
  7198. // // N801A-S4_5 节拍接口 数据
  7199. // #region N801A-S4_5 节拍接口
  7200. // try
  7201. // {
  7202. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7203. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7204. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7205. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7206. // {
  7207. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7208. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7209. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7210. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7211. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7212. // }
  7213. // }
  7214. // catch (Exception ex)
  7215. // {
  7216. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7217. // string str = ex.StackTrace;
  7218. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7219. // }
  7220. // #endregion N801A-S4_5 节拍接口
  7221. // #region 心跳
  7222. // try
  7223. // {
  7224. // short states = 0;
  7225. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7226. // }
  7227. // catch (Exception ex)
  7228. // {
  7229. // string str = ex.StackTrace;
  7230. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7231. // }
  7232. // #endregion 心跳
  7233. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7234. // stopwatch1.Stop();
  7235. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7236. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7237. // }
  7238. // else
  7239. // {
  7240. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7241. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7242. // Funs[plcNo].Connect();
  7243. // }
  7244. // }
  7245. // catch (Exception ex)
  7246. // {
  7247. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7248. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7249. // Funs[plcNo].ReConnect();
  7250. // }
  7251. // Thread.Sleep(IntervalReadPLC);
  7252. // }
  7253. //}
  7254. /// <summary>
  7255. /// [S4] 取放桁架 - S4_1弹夹扫码
  7256. /// </summary>
  7257. /// <param name="plcNo">PLC编号</param>
  7258. /// <param name="stationNameStr">工站全称</param>
  7259. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7260. {
  7261. Stopwatch stopwatch1 = new Stopwatch();
  7262. Stopwatch stopwatch2 = new Stopwatch();
  7263. try
  7264. {
  7265. stopwatch1.Start();
  7266. // ZS 弹夹扫码
  7267. string d1BulletclipCode = " "; // 扫到的码
  7268. short d1BulletclipScanCode = 2;
  7269. stopwatch2.Start();
  7270. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7271. //// MES_Flag
  7272. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7273. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7274. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7275. writeToPLC_Flag.Adress = 2002;
  7276. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7277. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7278. {
  7279. Name = "d1BulletclipCode",
  7280. Adress = 2003,
  7281. ValueType = PLCValueType.String,
  7282. ValueTypeStrLength = 20,
  7283. Value = d1BulletclipCode
  7284. });
  7285. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7286. stopwatch2.Stop();
  7287. }
  7288. catch (Exception ex)
  7289. {
  7290. string str = ex.StackTrace;
  7291. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7292. stopwatch2.Start();
  7293. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7294. //// MES_Flag
  7295. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7296. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7297. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7298. writeToPLC_Flag.Adress = 2002;
  7299. writeToPLC_Flag.Value = (short)6;
  7300. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7301. {
  7302. Name = "d1BulletclipCode",
  7303. Adress = 2003,
  7304. ValueType = PLCValueType.String,
  7305. ValueTypeStrLength = 20,
  7306. Value = " "
  7307. });
  7308. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7309. stopwatch2.Stop();
  7310. }
  7311. stopwatch1.Stop();
  7312. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7313. }
  7314. /// <summary>
  7315. /// [S4] 取放桁架 - S4_1载具扫码
  7316. /// </summary>
  7317. /// <param name="plcNo">PLC编号</param>
  7318. /// <param name="stationNameStr">工站全称</param>
  7319. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7320. {
  7321. Stopwatch stopwatch1 = new Stopwatch();
  7322. Stopwatch stopwatch2 = new Stopwatch();
  7323. try
  7324. {
  7325. stopwatch1.Start();
  7326. // ZS 载具扫码
  7327. string d1VehicleCode = ""; // 扫到的码
  7328. short d1VehicleScanCode = 2;
  7329. #region 进站
  7330. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7331. {
  7332. #region 查询载具上的产品信息
  7333. string cavityData = string.Empty;
  7334. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7335. if (string.IsNullOrEmpty(cavityData))
  7336. cavityData = "";
  7337. if (snResult != 0)
  7338. {
  7339. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7340. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7341. writeToPLC_Flag1.Adress = 2033;
  7342. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7343. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7344. {
  7345. Name = "d1VehicleCode",
  7346. Adress = 2034,
  7347. ValueType = PLCValueType.String,
  7348. ValueTypeStrLength = 20,
  7349. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7350. });
  7351. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7352. stopwatch1.Stop();
  7353. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7354. return;
  7355. }
  7356. string[] cavitySNs = cavityData.Split('.');
  7357. string partNo = "";
  7358. if (cavitySNs != null && cavitySNs.Length >= 1)
  7359. {
  7360. partNo = cavitySNs[0];
  7361. }
  7362. #endregion 查询载具上的产品信息
  7363. List<TestItem> item = new List<TestItem>();
  7364. item.Add(new TestItem()
  7365. {
  7366. Parameter_name = "载具码",
  7367. Parameter_value = d1VehicleCode,
  7368. });
  7369. item.Add(new TestItem()
  7370. {
  7371. Parameter_name = "载具穴号",
  7372. Parameter_value = "1",
  7373. });
  7374. stopwatch2.Start();
  7375. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7376. stopwatch2.Stop();
  7377. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7378. }
  7379. #endregion 进站
  7380. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7381. //// MES_Flag
  7382. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7383. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7384. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7385. writeToPLC_Flag.Adress = 2033;
  7386. writeToPLC_Flag.Value = d1VehicleScanCode;
  7387. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7388. {
  7389. Name = "d1VehicleCode",
  7390. Adress = 2034,
  7391. ValueType = PLCValueType.String,
  7392. ValueTypeStrLength = 20,
  7393. Value = d1VehicleCode
  7394. });
  7395. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7396. }
  7397. catch (Exception ex)
  7398. {
  7399. string str = ex.StackTrace;
  7400. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7401. stopwatch2.Start();
  7402. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7403. //// MES_Flag
  7404. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7405. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7406. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7407. writeToPLC_Flag.Adress = 2033;
  7408. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7409. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7410. {
  7411. Name = "d1VehicleCode",
  7412. Adress = 2034,
  7413. ValueType = PLCValueType.String,
  7414. ValueTypeStrLength = 20,
  7415. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7416. });
  7417. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7418. stopwatch2.Stop();
  7419. }
  7420. stopwatch1.Stop();
  7421. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7422. }
  7423. // 上次采集到的SN
  7424. //private string sn_S4_1出站接口 = string.Empty;
  7425. /// <summary>
  7426. /// [S4] 取放桁架 - S4_1出站接口
  7427. /// </summary>
  7428. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7429. {
  7430. Stopwatch stopwatch1 = new Stopwatch();
  7431. Stopwatch stopwatch2 = new Stopwatch();
  7432. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7433. string stationNameStr = stationCode + stationName;
  7434. string processItem = stationName; // 测试项目
  7435. try
  7436. {
  7437. stopwatch1.Start();
  7438. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7439. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7440. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7441. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7442. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7443. sn = sn.Replace("\0", "");
  7444. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7445. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7446. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7447. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7448. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7449. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7450. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7451. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7452. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7453. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7454. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7455. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7456. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7457. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7458. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7459. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7460. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7461. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7462. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7463. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7464. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7465. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7466. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7467. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7468. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7469. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7470. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7471. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7472. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7473. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7474. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7475. bool pass = d1Result == 1;
  7476. // 存 载具SN列表
  7477. List<string> vehicleCodes = new List<string>()
  7478. {
  7479. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7480. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7481. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7482. };
  7483. // 统一查 产品SN列表
  7484. List<string> partNos = new List<string>();
  7485. foreach (string vehicleCode in vehicleCodes)
  7486. {
  7487. if (string.IsNullOrEmpty(vehicleCode))
  7488. partNos.Add("");
  7489. else
  7490. {
  7491. string partNo = "";
  7492. #region 查询载具上的产品信息
  7493. string cavityData = string.Empty;
  7494. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7495. if (string.IsNullOrEmpty(cavityData))
  7496. cavityData = "";
  7497. if (snResult != 0)
  7498. {
  7499. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7500. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7501. writeToPLC_Flag1.Adress = 2065;
  7502. writeToPLC_Flag1.Value = (short)4;
  7503. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7504. stopwatch1.Stop();
  7505. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7506. return;
  7507. }
  7508. string[] cavitySNs = cavityData.Split('.');
  7509. if (cavitySNs != null && cavitySNs.Length >= 1)
  7510. partNo = cavitySNs[0];
  7511. #endregion 查询载具上的产品信息
  7512. partNos.Add(partNo);
  7513. }
  7514. }
  7515. // 统一上传
  7516. stopwatch2.Start();
  7517. List<int> results = new List<int>();
  7518. for (int i = 0; i < partNos.Count; i++)
  7519. {
  7520. string index = (i + 1).ToString(); // 弹夹穴号
  7521. if (string.IsNullOrEmpty(partNos[i]))
  7522. results.Add(1);
  7523. else
  7524. {
  7525. List<TestItem> items1 = new List<TestItem>();
  7526. items1.Add(new TestItem()
  7527. {
  7528. Parameter_name = "弹夹码",
  7529. Parameter_value = sn,
  7530. Parameter_unit = ""
  7531. });
  7532. items1.Add(new TestItem()
  7533. {
  7534. Parameter_name = "弹夹穴号",
  7535. Parameter_value = index,
  7536. Parameter_unit = ""
  7537. });
  7538. items1.Add(new TestItem()
  7539. {
  7540. Parameter_name = "载具码",
  7541. Parameter_value = vehicleCodes[i],
  7542. Parameter_unit = ""
  7543. });
  7544. items1.Add(new TestItem()
  7545. {
  7546. Parameter_name = "载具穴号",
  7547. Parameter_value = "1",
  7548. Parameter_unit = ""
  7549. });
  7550. items1.Add(new TestItem()
  7551. {
  7552. Parameter_name = "产品结果",
  7553. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7554. Parameter_unit = ""
  7555. });
  7556. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7557. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7558. results.Add(result1);
  7559. }
  7560. }
  7561. short result = 0;
  7562. if (results.All(a => a == 1))
  7563. result = 1;
  7564. else if (results.Contains(3))
  7565. result = 3;
  7566. else if (results.Contains(2))
  7567. result = 2;
  7568. else if (results.Contains(4))
  7569. result = 4;
  7570. else
  7571. result = 4;
  7572. stopwatch2.Stop();
  7573. #region 存储绑定数据到 边线MES系统中
  7574. if (result == 1)
  7575. {
  7576. string data = string.Join(".", vehicleCodes);
  7577. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7578. if (resultMesR != 0)
  7579. {
  7580. result = 4;
  7581. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7582. }
  7583. }
  7584. #endregion 存储绑定数据到 边线MES系统中
  7585. // MES_Flag 为4MES报错
  7586. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7587. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7588. writeToPLC_Flag.Name = "d1MES_FLAG";
  7589. writeToPLC_Flag.Adress = 2065;
  7590. writeToPLC_Flag.Value = result;
  7591. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7592. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7593. }
  7594. catch (Exception ex)
  7595. {
  7596. stopwatch2.Restart();
  7597. // MES_Flag 为4上位机报错
  7598. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7599. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7600. writeToPLC_Flag.Name = "d1MES_FLAG";
  7601. writeToPLC_Flag.Adress = 2065;
  7602. writeToPLC_Flag.Value = (short)4;
  7603. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7604. stopwatch2.Stop();
  7605. string str = ex.StackTrace;
  7606. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7607. }
  7608. stopwatch1.Stop();
  7609. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7610. }
  7611. /// <summary>
  7612. /// [S4] 取放桁架 - S4_1节拍接口
  7613. /// </summary>
  7614. /// <param name="plcNo">PLC编号</param>
  7615. /// <param name="stationNameStr">工站全称</param>
  7616. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7617. {
  7618. Stopwatch stopwatch1 = new Stopwatch();
  7619. Stopwatch stopwatch2 = new Stopwatch();
  7620. string resultStr = string.Empty;
  7621. try
  7622. {
  7623. stopwatch1.Start();
  7624. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7625. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7626. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7627. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7628. if (!actionBool)
  7629. {
  7630. stopwatch2.Start();
  7631. // MES_Flag
  7632. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7633. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7634. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7635. writeToPLC_Flag1.Adress = 2398;
  7636. writeToPLC_Flag1.Value = (short)4;
  7637. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7638. stopwatch2.Stop();
  7639. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7640. return;
  7641. }
  7642. string d1OEEPartNo = string.Empty; // 物料码
  7643. if (string.IsNullOrEmpty(d1OEEProductSN))
  7644. {
  7645. stopwatch2.Start();
  7646. // MES_Flag
  7647. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7648. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7649. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7650. writeToPLC_Flag1.Adress = 2398;
  7651. writeToPLC_Flag1.Value = (short)1;
  7652. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7653. stopwatch2.Stop();
  7654. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7655. return;
  7656. }
  7657. else
  7658. { // 查产品SN ZS
  7659. d1OEEPartNo = "Test";
  7660. }
  7661. short d1OEEMES_FLAG = 0;
  7662. // 上传OEE
  7663. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7664. d1OEEMES_FLAG = result.Item1;
  7665. resultStr = result.Item2;
  7666. stopwatch2.Start();
  7667. // MES_Flag
  7668. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7669. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7670. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7671. writeToPLC_Flag.Adress = 2398;
  7672. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7673. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7674. stopwatch2.Stop();
  7675. }
  7676. catch (Exception ex)
  7677. {
  7678. string str = ex.StackTrace;
  7679. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7680. // MES_Flag
  7681. stopwatch2.Start();
  7682. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7683. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7684. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7685. writeToPLC_Flag.Adress = 2398;
  7686. writeToPLC_Flag.Value = (short)4;
  7687. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7688. stopwatch2.Stop();
  7689. }
  7690. stopwatch1.Stop();
  7691. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7692. }
  7693. /// <summary>
  7694. /// [S4] 取放桁架 - S4_2桁架
  7695. /// </summary>
  7696. /// <param name="plcNo">PLC编号</param>
  7697. /// <param name="stationNameStr">工站全称</param>
  7698. private void S4_2桁架(int plcNo, string stationNameStr)
  7699. {
  7700. Stopwatch stopwatch1 = new Stopwatch();
  7701. Stopwatch stopwatch2 = new Stopwatch();
  7702. try
  7703. {
  7704. stopwatch1.Start();
  7705. // ZS 弹夹扫码
  7706. string d2BulletclipCode = " "; // 扫到的码
  7707. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7708. short d2BulletclipScanCode = 2;
  7709. stopwatch2.Start();
  7710. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7711. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7712. //// MES_Flag
  7713. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7714. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7715. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7716. writeToPLC_Flag.Adress = 2430;
  7717. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7718. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7719. {
  7720. Name = "d2BulletclipCode",
  7721. Adress = 2432,
  7722. ValueType = PLCValueType.String,
  7723. ValueTypeStrLength = 20,
  7724. Value = d2BulletclipCode
  7725. });
  7726. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7727. {
  7728. Name = "d2BulletclipStates",
  7729. Adress = 2431,
  7730. ValueType = PLCValueType.Short,
  7731. Value = d2BulletclipStates
  7732. });
  7733. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7734. stopwatch2.Stop();
  7735. }
  7736. catch (Exception ex)
  7737. {
  7738. string str = ex.StackTrace;
  7739. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7740. stopwatch2.Start();
  7741. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7742. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7743. // MES_Flag
  7744. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7745. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7746. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7747. writeToPLC_Flag.Adress = 2430;
  7748. writeToPLC_Flag.Value = (short)6;
  7749. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7750. {
  7751. Name = "d2BulletclipCode",
  7752. Adress = 2432,
  7753. ValueType = PLCValueType.String,
  7754. ValueTypeStrLength = 20,
  7755. Value = " "
  7756. });
  7757. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7758. {
  7759. Name = "d2BulletclipStates",
  7760. Adress = 2431,
  7761. ValueType = PLCValueType.Short,
  7762. Value = (short)0
  7763. });
  7764. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7765. stopwatch2.Stop();
  7766. }
  7767. stopwatch1.Stop();
  7768. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7769. }
  7770. // 上次采集到的SN
  7771. //private string sn_S4_3进站接口 = string.Empty;
  7772. /// <summary>
  7773. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7774. /// </summary>
  7775. private void S4_3进站接口(int plcNo, string stationNameStr)
  7776. {
  7777. Stopwatch stopwatch1 = new Stopwatch();
  7778. Stopwatch stopwatch2 = new Stopwatch();
  7779. try
  7780. {
  7781. stopwatch1.Start();
  7782. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7783. sn = sn.Replace("\0", "");
  7784. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7785. #region 查询15个载具码
  7786. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7787. string vehicleData = string.Empty;
  7788. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7789. if (string.IsNullOrEmpty(vehicleData))
  7790. vehicleData = "";
  7791. if (snResult != 0)
  7792. {
  7793. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7794. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7795. writeToPLC_Flag1.Adress = 2463;
  7796. writeToPLC_Flag1.Value = (short)4;
  7797. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7798. stopwatch1.Stop();
  7799. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7800. return;
  7801. }
  7802. string[] cavitySNs = vehicleData.Split('.');
  7803. if (cavitySNs != null && cavitySNs.Length > 0)
  7804. {
  7805. for (int i = 0; i < cavitySNs.Length; i++)
  7806. {
  7807. if (string.IsNullOrEmpty(cavitySNs[i]))
  7808. vehicleCodes.Add("");
  7809. else
  7810. vehicleCodes.Add(cavitySNs[i]);
  7811. }
  7812. }
  7813. #endregion 查询15个载具码
  7814. #region 查询15个产品SN
  7815. List<string> portNos = new List<string>(); // 15个产品SN
  7816. foreach (string vehicleCode in vehicleCodes)
  7817. {
  7818. if (string.IsNullOrEmpty(vehicleCode))
  7819. portNos.Add("");
  7820. else
  7821. {
  7822. // 查询
  7823. string cavityData = string.Empty;
  7824. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7825. if (string.IsNullOrEmpty(cavityData))
  7826. cavityData = "";
  7827. if (snResult1 != 0)
  7828. {
  7829. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7830. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7831. writeToPLC_Flag1.Adress = 2463;
  7832. writeToPLC_Flag1.Value = (short)4;
  7833. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7834. stopwatch1.Stop();
  7835. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7836. return;
  7837. }
  7838. string[] partSNs = cavityData.Split('.');
  7839. if (partSNs != null && partSNs.Length >= 1)
  7840. portNos.Add(partSNs[0]);
  7841. else
  7842. portNos.Add("");
  7843. }
  7844. }
  7845. #endregion 查询15个产品SN
  7846. // 调用MES进站(最多15个)
  7847. stopwatch2.Start();
  7848. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7849. for (int i = 0; i < vehicleCodes.Count; i++)
  7850. {
  7851. // 循环进站
  7852. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7853. {
  7854. // 产品SN(物料码)校验
  7855. string portNo = portNos[i];
  7856. List<TestItem> item = new List<TestItem>();
  7857. item.Add(new TestItem()
  7858. {
  7859. Parameter_name = "弹夹码",
  7860. Parameter_value = sn,
  7861. });
  7862. item.Add(new TestItem()
  7863. {
  7864. Parameter_name = "弹夹穴位",
  7865. Parameter_value = (i + 1).ToString(),
  7866. });
  7867. item.Add(new TestItem()
  7868. {
  7869. Parameter_name = "载具码",
  7870. Parameter_value = vehicleCodes[i],
  7871. });
  7872. item.Add(new TestItem()
  7873. {
  7874. Parameter_name = "载具穴号",
  7875. Parameter_value = "1",
  7876. });
  7877. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7878. }
  7879. }
  7880. stopwatch2.Stop();
  7881. short result = 0;
  7882. bool haveMesWarn = results.Contains(5);
  7883. bool havePCWarn = results.Contains(6);
  7884. if (haveMesWarn)
  7885. result = 2; // 5->2
  7886. else if (havePCWarn)
  7887. result = 6; // 6->4
  7888. else
  7889. result = 1;
  7890. // MES_Flag 为4MES报错
  7891. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7892. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7893. writeToPLC_Flag.Name = "d3MES_FLAG";
  7894. writeToPLC_Flag.Adress = 2463;
  7895. writeToPLC_Flag.Value = result;
  7896. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7897. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7898. }
  7899. catch (Exception ex)
  7900. {
  7901. stopwatch2.Stop();
  7902. // MES_Flag 为4上位机报错
  7903. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7904. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7905. writeToPLC_Flag.Name = "d3MES_FLAG";
  7906. writeToPLC_Flag.Adress = 2463;
  7907. writeToPLC_Flag.Value = (short)4;
  7908. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7909. string str = ex.StackTrace;
  7910. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7911. }
  7912. stopwatch1.Stop();
  7913. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7914. }
  7915. // 上次采集到的SN
  7916. //private string sn_S4_3出站接口 = string.Empty;
  7917. /// <summary>
  7918. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7919. /// </summary>
  7920. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7921. {
  7922. Stopwatch stopwatch1 = new Stopwatch();
  7923. Stopwatch stopwatch2 = new Stopwatch();
  7924. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7925. string stationNameStr = stationCode + stationName;
  7926. string processItem = stationName; // 测试项目
  7927. try
  7928. {
  7929. stopwatch1.Start();
  7930. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7931. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7932. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7933. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7934. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7935. sn = sn.Replace("\0", "");
  7936. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7937. bool isPass = d3Result == 1; // 产品结果 bool
  7938. #region 查询15个载具码
  7939. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7940. string vehicleData = string.Empty;
  7941. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7942. if (string.IsNullOrEmpty(vehicleData))
  7943. vehicleData = "";
  7944. if (snResult1 != 0)
  7945. {
  7946. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7947. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7948. writeToPLC_Flag1.Adress = 2463;
  7949. writeToPLC_Flag1.Value = (short)4;
  7950. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7951. stopwatch1.Stop();
  7952. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7953. return;
  7954. }
  7955. string[] cavitySNs = vehicleData.Split('.');
  7956. if (cavitySNs != null && cavitySNs.Length > 0)
  7957. {
  7958. for (int i = 0; i < cavitySNs.Length; i++)
  7959. {
  7960. if (string.IsNullOrEmpty(cavitySNs[i]))
  7961. vehicleCodes.Add("");
  7962. else
  7963. vehicleCodes.Add(cavitySNs[i]);
  7964. }
  7965. }
  7966. #endregion 查询15个载具码
  7967. // 统一查 产品SN列表
  7968. List<string> partNos = new List<string>();
  7969. foreach (string vehicleCode in vehicleCodes)
  7970. {
  7971. if (string.IsNullOrEmpty(vehicleCode))
  7972. partNos.Add("");
  7973. else
  7974. {
  7975. string partNo = "";
  7976. #region 查询载具上的产品信息
  7977. string cavityData = string.Empty;
  7978. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7979. if (string.IsNullOrEmpty(cavityData))
  7980. cavityData = "";
  7981. if (snResult != 0)
  7982. {
  7983. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7984. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7985. writeToPLC_Flag1.Adress = 2463;
  7986. writeToPLC_Flag1.Value = (short)4;
  7987. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7988. stopwatch1.Stop();
  7989. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7990. return;
  7991. }
  7992. string[] partSNs = cavityData.Split('.');
  7993. if (partSNs != null && partSNs.Length >= 1)
  7994. partNo = partSNs[0];
  7995. #endregion 查询载具上的产品信息
  7996. partNos.Add(partNo);
  7997. }
  7998. }
  7999. // 统一上传 - 调用MES出站
  8000. stopwatch2.Start();
  8001. List<int> results = new List<int>();
  8002. for (int i = 0; i < partNos.Count; i++)
  8003. {
  8004. string index = (i + 1).ToString(); // 弹夹穴号
  8005. if (string.IsNullOrEmpty(partNos[i]))
  8006. results.Add(1);
  8007. else
  8008. {
  8009. List<TestItem> items1 = new List<TestItem>();
  8010. items1.Add(new TestItem()
  8011. {
  8012. Parameter_name = "弹夹码",
  8013. Parameter_value = sn,
  8014. Parameter_unit = ""
  8015. });
  8016. items1.Add(new TestItem()
  8017. {
  8018. Parameter_name = "弹夹穴号",
  8019. Parameter_value = index,
  8020. Parameter_unit = ""
  8021. });
  8022. items1.Add(new TestItem()
  8023. {
  8024. Parameter_name = "载具码",
  8025. Parameter_value = vehicleCodes[i],
  8026. Parameter_unit = ""
  8027. });
  8028. items1.Add(new TestItem()
  8029. {
  8030. Parameter_name = "载具穴号",
  8031. Parameter_value = "1",
  8032. Parameter_unit = ""
  8033. });
  8034. items1.Add(new TestItem()
  8035. {
  8036. Parameter_name = "产品结果",
  8037. Parameter_value = d3Result == 1 ? "OK" : "NG",
  8038. Parameter_unit = ""
  8039. });
  8040. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8041. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8042. results.Add(result1);
  8043. }
  8044. }
  8045. short result = 0;
  8046. if (results.All(a => a == 1))
  8047. result = 1;
  8048. else if (results.Contains(3))
  8049. result = 3;
  8050. else if (results.Contains(2))
  8051. result = 2;
  8052. else if (results.Contains(4))
  8053. result = 4;
  8054. else
  8055. result = 4;
  8056. stopwatch2.Stop();
  8057. // MES_Flag 为4MES报错
  8058. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8059. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8060. writeToPLC_Flag.Name = "d3MES_FLAG";
  8061. writeToPLC_Flag.Adress = 2463;
  8062. writeToPLC_Flag.Value = result;
  8063. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8064. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8065. }
  8066. catch (Exception ex)
  8067. {
  8068. stopwatch2.Restart();
  8069. // MES_Flag 为4上位机报错
  8070. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  8071. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8072. writeToPLC_Flag.Name = "d3MES_FLAG";
  8073. writeToPLC_Flag.Adress = 2463;
  8074. writeToPLC_Flag.Value = (short)4;
  8075. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8076. string str = ex.StackTrace;
  8077. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8078. stopwatch2.Stop();
  8079. }
  8080. stopwatch1.Stop();
  8081. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8082. }
  8083. // 上次采集到的SN
  8084. //private string sn_S4_4进站接口 = string.Empty;
  8085. /// <summary>
  8086. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  8087. /// </summary>
  8088. private void S4_4进站接口(int plcNo, string stationNameStr)
  8089. {
  8090. Stopwatch stopwatch1 = new Stopwatch();
  8091. Stopwatch stopwatch2 = new Stopwatch();
  8092. try
  8093. {
  8094. stopwatch1.Start();
  8095. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8096. sn = sn.Replace("\0", "");
  8097. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8098. #region 查询15个载具码
  8099. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8100. string vehicleData = string.Empty;
  8101. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8102. if (string.IsNullOrEmpty(vehicleData))
  8103. vehicleData = "";
  8104. if (snResult != 0)
  8105. {
  8106. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8107. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8108. writeToPLC_Flag1.Adress = 2463;
  8109. writeToPLC_Flag1.Value = (short)4;
  8110. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8111. stopwatch1.Stop();
  8112. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8113. return;
  8114. }
  8115. string[] cavitySNs = vehicleData.Split('.');
  8116. if (cavitySNs != null && cavitySNs.Length > 0)
  8117. {
  8118. for (int i = 0; i < cavitySNs.Length; i++)
  8119. {
  8120. if (string.IsNullOrEmpty(cavitySNs[i]))
  8121. vehicleCodes.Add("");
  8122. else
  8123. vehicleCodes.Add(cavitySNs[i]);
  8124. }
  8125. }
  8126. #endregion 查询15个载具码
  8127. #region 查询15个产品SN
  8128. List<string> portNos = new List<string>(); // 15个产品SN
  8129. foreach (string vehicleCode in vehicleCodes)
  8130. {
  8131. if (string.IsNullOrEmpty(vehicleCode))
  8132. portNos.Add("");
  8133. else
  8134. {
  8135. // 查询
  8136. string cavityData = string.Empty;
  8137. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8138. if (string.IsNullOrEmpty(cavityData))
  8139. cavityData = "";
  8140. if (snResult1 != 0)
  8141. {
  8142. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8143. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8144. writeToPLC_Flag1.Adress = 2463;
  8145. writeToPLC_Flag1.Value = (short)4;
  8146. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8147. stopwatch1.Stop();
  8148. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8149. return;
  8150. }
  8151. string[] partSNs = cavityData.Split('.');
  8152. if (partSNs != null && partSNs.Length >= 1)
  8153. portNos.Add(partSNs[0]);
  8154. else
  8155. portNos.Add("");
  8156. }
  8157. }
  8158. #endregion 查询15个产品SN
  8159. // 调用MES进站(最多15个)
  8160. stopwatch2.Start();
  8161. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8162. for (int i = 0; i < vehicleCodes.Count; i++)
  8163. {
  8164. // 循环进站
  8165. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8166. {
  8167. // 产品SN(物料码)校验
  8168. string portNo = portNos[i];
  8169. List<TestItem> item = new List<TestItem>();
  8170. item.Add(new TestItem()
  8171. {
  8172. Parameter_name = "弹夹码",
  8173. Parameter_value = sn,
  8174. });
  8175. item.Add(new TestItem()
  8176. {
  8177. Parameter_name = "弹夹穴位",
  8178. Parameter_value = (i + 1).ToString(),
  8179. });
  8180. item.Add(new TestItem()
  8181. {
  8182. Parameter_name = "载具码",
  8183. Parameter_value = vehicleCodes[i],
  8184. });
  8185. item.Add(new TestItem()
  8186. {
  8187. Parameter_name = "载具穴号",
  8188. Parameter_value = "1",
  8189. });
  8190. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8191. }
  8192. }
  8193. stopwatch2.Stop();
  8194. short result = 0;
  8195. bool haveMesWarn = results.Contains(5);
  8196. bool havePCWarn = results.Contains(6);
  8197. if (haveMesWarn)
  8198. result = 2; // 5->2
  8199. else if (havePCWarn)
  8200. result = 6; // 6->4
  8201. else
  8202. result = 1;
  8203. // MES_Flag 为4MES报错
  8204. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8205. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8206. writeToPLC_Flag.Name = "d4MES_FLAG";
  8207. writeToPLC_Flag.Adress = 2496;
  8208. writeToPLC_Flag.Value = result;
  8209. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8210. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8211. }
  8212. catch (Exception ex)
  8213. {
  8214. stopwatch2.Stop();
  8215. // MES_Flag 为4上位机报错
  8216. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8217. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8218. writeToPLC_Flag.Name = "d4MES_FLAG";
  8219. writeToPLC_Flag.Adress = 2496;
  8220. writeToPLC_Flag.Value = (short)4;
  8221. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8222. string str = ex.StackTrace;
  8223. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8224. }
  8225. stopwatch1.Stop();
  8226. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8227. }
  8228. // 上次采集到的SN
  8229. //private string sn_S4_4出站接口 = string.Empty;
  8230. /// <summary>
  8231. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8232. /// </summary>
  8233. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8234. {
  8235. Stopwatch stopwatch1 = new Stopwatch();
  8236. Stopwatch stopwatch2 = new Stopwatch();
  8237. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8238. string stationNameStr = stationCode + stationName;
  8239. string processItem = stationName; // 测试项目
  8240. try
  8241. {
  8242. stopwatch1.Start();
  8243. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8244. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8245. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8246. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8247. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8248. sn = sn.Replace("\0", "");
  8249. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8250. bool isPass = d4Result == 1; // 产品结果 bool
  8251. #region 查询15个载具码
  8252. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8253. string vehicleData = string.Empty;
  8254. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8255. if (string.IsNullOrEmpty(vehicleData))
  8256. vehicleData = "";
  8257. if (snResult1 != 0)
  8258. {
  8259. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8260. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8261. writeToPLC_Flag1.Adress = 2496;
  8262. writeToPLC_Flag1.Value = (short)4;
  8263. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8264. stopwatch1.Stop();
  8265. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8266. return;
  8267. }
  8268. string[] cavitySNs = vehicleData.Split('.');
  8269. if (cavitySNs != null && cavitySNs.Length > 0)
  8270. {
  8271. for (int i = 0; i < cavitySNs.Length; i++)
  8272. {
  8273. if (string.IsNullOrEmpty(cavitySNs[i]))
  8274. vehicleCodes.Add("");
  8275. else
  8276. vehicleCodes.Add(cavitySNs[i]);
  8277. }
  8278. }
  8279. #endregion 查询15个载具码
  8280. // 统一查 产品SN列表
  8281. List<string> partNos = new List<string>();
  8282. foreach (string vehicleCode in vehicleCodes)
  8283. {
  8284. if (string.IsNullOrEmpty(vehicleCode))
  8285. partNos.Add("");
  8286. else
  8287. {
  8288. string partNo = "";
  8289. #region 查询载具上的产品信息
  8290. string cavityData = string.Empty;
  8291. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8292. if (string.IsNullOrEmpty(cavityData))
  8293. cavityData = "";
  8294. if (snResult != 0)
  8295. {
  8296. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8297. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8298. writeToPLC_Flag1.Adress = 2496;
  8299. writeToPLC_Flag1.Value = (short)4;
  8300. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8301. stopwatch1.Stop();
  8302. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8303. return;
  8304. }
  8305. string[] partSNs = cavityData.Split('.');
  8306. if (partSNs != null && partSNs.Length >= 1)
  8307. partNo = partSNs[0];
  8308. #endregion 查询载具上的产品信息
  8309. partNos.Add(partNo);
  8310. }
  8311. }
  8312. // 调用MES出站
  8313. stopwatch2.Start();
  8314. // 统一上传
  8315. List<int> results = new List<int>();
  8316. for (int i = 0; i < partNos.Count; i++)
  8317. {
  8318. string index = (i + 1).ToString(); // 弹夹穴号
  8319. if (string.IsNullOrEmpty(partNos[i]))
  8320. results.Add(1);
  8321. else
  8322. {
  8323. List<TestItem> items1 = new List<TestItem>();
  8324. items1.Add(new TestItem()
  8325. {
  8326. Parameter_name = "弹夹码",
  8327. Parameter_value = sn,
  8328. Parameter_unit = ""
  8329. });
  8330. items1.Add(new TestItem()
  8331. {
  8332. Parameter_name = "弹夹穴号",
  8333. Parameter_value = index,
  8334. Parameter_unit = ""
  8335. });
  8336. items1.Add(new TestItem()
  8337. {
  8338. Parameter_name = "载具码",
  8339. Parameter_value = vehicleCodes[i],
  8340. Parameter_unit = ""
  8341. });
  8342. items1.Add(new TestItem()
  8343. {
  8344. Parameter_name = "载具穴号",
  8345. Parameter_value = "1",
  8346. Parameter_unit = ""
  8347. });
  8348. items1.Add(new TestItem()
  8349. {
  8350. Parameter_name = "产品结果",
  8351. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8352. Parameter_unit = ""
  8353. });
  8354. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8355. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8356. results.Add(result1);
  8357. }
  8358. }
  8359. short result = 0;
  8360. if (results.All(a => a == 1))
  8361. result = 1;
  8362. else if (results.Contains(3))
  8363. result = 3;
  8364. else if (results.Contains(2))
  8365. result = 2;
  8366. else if (results.Contains(4))
  8367. result = 4;
  8368. else
  8369. result = 4;
  8370. stopwatch2.Stop();
  8371. // MES_Flag 为4MES报错
  8372. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8373. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8374. writeToPLC_Flag.Name = "d4MES_FLAG";
  8375. writeToPLC_Flag.Adress = 2496;
  8376. writeToPLC_Flag.Value = result;
  8377. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8378. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8379. }
  8380. catch (Exception ex)
  8381. {
  8382. stopwatch2.Restart();
  8383. // MES_Flag 为4上位机报错
  8384. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8385. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8386. writeToPLC_Flag.Name = "d4MES_FLAG";
  8387. writeToPLC_Flag.Adress = 2496;
  8388. writeToPLC_Flag.Value = (short)4;
  8389. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8390. string str = ex.StackTrace;
  8391. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8392. stopwatch2.Stop();
  8393. }
  8394. stopwatch1.Stop();
  8395. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8396. }
  8397. /// <summary>
  8398. /// [S4] 取放桁架 - S4_5弹夹扫码
  8399. /// </summary>
  8400. /// <param name="plcNo">PLC编号</param>
  8401. /// <param name="stationNameStr">工站全称</param>
  8402. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8403. {
  8404. Stopwatch stopwatch1 = new Stopwatch();
  8405. Stopwatch stopwatch2 = new Stopwatch();
  8406. try
  8407. {
  8408. stopwatch1.Start();
  8409. // ZS 弹夹扫码
  8410. string d5BulletclipCode = " "; // 扫到的码
  8411. short d5BulletclipScanCode = 2;
  8412. stopwatch2.Start();
  8413. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8414. //// MES_Flag
  8415. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8416. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8417. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8418. writeToPLC_Flag.Adress = 2528;
  8419. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8420. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8421. {
  8422. Name = "d5BulletclipCode",
  8423. Adress = 2529,
  8424. ValueType = PLCValueType.String,
  8425. ValueTypeStrLength = 20,
  8426. Value = d5BulletclipCode
  8427. });
  8428. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8429. stopwatch2.Stop();
  8430. }
  8431. catch (Exception ex)
  8432. {
  8433. string str = ex.StackTrace;
  8434. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8435. stopwatch2.Start();
  8436. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8437. //// MES_Flag
  8438. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8439. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8440. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8441. writeToPLC_Flag.Adress = 2528;
  8442. writeToPLC_Flag.Value = (short)6;
  8443. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8444. {
  8445. Name = "d5BulletclipCode",
  8446. Adress = 2529,
  8447. ValueType = PLCValueType.String,
  8448. ValueTypeStrLength = 20,
  8449. Value = " "
  8450. });
  8451. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8452. stopwatch2.Stop();
  8453. }
  8454. stopwatch1.Stop();
  8455. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8456. }
  8457. /// <summary>
  8458. /// [S4] 取放桁架 - S4_5载具扫码
  8459. /// </summary>
  8460. /// <param name="plcNo">PLC编号</param>
  8461. /// <param name="stationNameStr">工站全称</param>
  8462. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8463. {
  8464. Stopwatch stopwatch1 = new Stopwatch();
  8465. Stopwatch stopwatch2 = new Stopwatch();
  8466. try
  8467. {
  8468. stopwatch1.Start();
  8469. // ZS 载具扫码
  8470. string d5VehicleCode = " "; // 扫到的码
  8471. short d5VehicleScanCode = 2;
  8472. #region 进站
  8473. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8474. {
  8475. // 查产品SN
  8476. #region 查询载具上的产品信息
  8477. string cavityData = string.Empty;
  8478. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8479. if (string.IsNullOrEmpty(cavityData))
  8480. cavityData = "";
  8481. if (snResult != 0)
  8482. {
  8483. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8484. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8485. writeToPLC_Flag1.Adress = 2559;
  8486. writeToPLC_Flag1.Value = (short)6;
  8487. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8488. {
  8489. Name = "d5VehicleCode",
  8490. Adress = 2560,
  8491. ValueType = PLCValueType.String,
  8492. ValueTypeStrLength = 20,
  8493. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8494. });
  8495. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8496. stopwatch1.Stop();
  8497. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8498. return;
  8499. }
  8500. string[] cavitySNs = cavityData.Split('.');
  8501. string partNo = "";
  8502. if (cavitySNs != null && cavitySNs.Length >= 1)
  8503. {
  8504. partNo = cavitySNs[0];
  8505. }
  8506. #endregion 查询载具上的产品信息
  8507. List<TestItem> item = new List<TestItem>();
  8508. item.Add(new TestItem()
  8509. {
  8510. Parameter_name = "载具码",
  8511. Parameter_value = d5VehicleCode,
  8512. });
  8513. item.Add(new TestItem()
  8514. {
  8515. Parameter_name = "载具穴号",
  8516. Parameter_value = "1",
  8517. });
  8518. stopwatch2.Start();
  8519. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8520. stopwatch2.Stop();
  8521. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8522. }
  8523. #endregion 进站
  8524. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8525. //// MES_Flag
  8526. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8527. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8528. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8529. writeToPLC_Flag.Adress = 2559;
  8530. writeToPLC_Flag.Value = d5VehicleScanCode;
  8531. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8532. {
  8533. Name = "d5VehicleCode",
  8534. Adress = 2560,
  8535. ValueType = PLCValueType.String,
  8536. ValueTypeStrLength = 20,
  8537. Value = d5VehicleCode
  8538. });
  8539. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8540. }
  8541. catch (Exception ex)
  8542. {
  8543. string str = ex.StackTrace;
  8544. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8545. stopwatch2.Start();
  8546. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8547. //// MES_Flag
  8548. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8549. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8550. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8551. writeToPLC_Flag.Adress = 2559;
  8552. writeToPLC_Flag.Value = (short)6;
  8553. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8554. {
  8555. Name = "d5VehicleCode",
  8556. Adress = 2560,
  8557. ValueType = PLCValueType.String,
  8558. ValueTypeStrLength = 20,
  8559. Value = " "
  8560. });
  8561. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8562. stopwatch2.Stop();
  8563. }
  8564. stopwatch1.Stop();
  8565. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8566. }
  8567. // 上次采集到的SN
  8568. //private string sn_S4_5出站接口 = string.Empty;
  8569. /// <summary>
  8570. /// [S4] 取放桁架 - S4_5出站接口
  8571. /// </summary>
  8572. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8573. {
  8574. Stopwatch stopwatch1 = new Stopwatch();
  8575. Stopwatch stopwatch2 = new Stopwatch();
  8576. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8577. string stationNameStr = stationCode + stationName;
  8578. string processItem = stationName; // 测试项目
  8579. try
  8580. {
  8581. stopwatch1.Start();
  8582. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8583. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8584. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8585. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8586. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8587. sn = sn.Replace("\0", "");
  8588. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8589. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8590. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8591. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8592. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8593. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8594. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8595. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8596. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8597. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8598. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8599. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8600. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8601. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8602. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8603. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8604. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8605. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8606. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8607. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8608. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8609. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8610. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8611. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8612. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8613. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8614. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8615. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8616. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8617. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8618. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8619. bool pass = d5Result == 1;
  8620. // 存 载具SN列表
  8621. List<string> vehicleCodes = new List<string>()
  8622. {
  8623. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8624. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8625. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8626. };
  8627. // 统一查 产品SN列表
  8628. List<string> partNos = new List<string>();
  8629. foreach (string vehicleCode in vehicleCodes)
  8630. {
  8631. if (string.IsNullOrEmpty(vehicleCode))
  8632. partNos.Add("");
  8633. else
  8634. {
  8635. string partNo = "";
  8636. #region 查询载具上的产品信息
  8637. string cavityData = string.Empty;
  8638. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8639. if (string.IsNullOrEmpty(cavityData))
  8640. cavityData = "";
  8641. if (snResult != 0)
  8642. {
  8643. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8644. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8645. writeToPLC_Flag1.Adress = 2591;
  8646. writeToPLC_Flag1.Value = (short)4;
  8647. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8648. stopwatch1.Stop();
  8649. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8650. return;
  8651. }
  8652. string[] cavitySNs = cavityData.Split('.');
  8653. if (cavitySNs != null && cavitySNs.Length >= 1)
  8654. partNo = cavitySNs[0];
  8655. #endregion 查询载具上的产品信息
  8656. partNos.Add(partNo);
  8657. }
  8658. }
  8659. // 统一上传
  8660. stopwatch2.Start();
  8661. List<int> results = new List<int>();
  8662. for (int i = 0; i < partNos.Count; i++)
  8663. {
  8664. string index = (i + 1).ToString(); // 弹夹穴号
  8665. if (string.IsNullOrEmpty(partNos[i]))
  8666. results.Add(1);
  8667. else
  8668. {
  8669. List<TestItem> items1 = new List<TestItem>();
  8670. items1.Add(new TestItem()
  8671. {
  8672. Parameter_name = "弹夹码",
  8673. Parameter_value = sn,
  8674. Parameter_unit = ""
  8675. });
  8676. items1.Add(new TestItem()
  8677. {
  8678. Parameter_name = "弹夹穴号",
  8679. Parameter_value = index,
  8680. Parameter_unit = ""
  8681. });
  8682. items1.Add(new TestItem()
  8683. {
  8684. Parameter_name = "载具码",
  8685. Parameter_value = vehicleCodes[i],
  8686. Parameter_unit = ""
  8687. });
  8688. items1.Add(new TestItem()
  8689. {
  8690. Parameter_name = "载具穴号",
  8691. Parameter_value = "1",
  8692. Parameter_unit = ""
  8693. });
  8694. items1.Add(new TestItem()
  8695. {
  8696. Parameter_name = "产品结果",
  8697. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8698. Parameter_unit = ""
  8699. });
  8700. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8701. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8702. results.Add(result1);
  8703. }
  8704. }
  8705. short result = 0;
  8706. if (results.All(a => a == 1))
  8707. result = 1;
  8708. else if (results.Contains(3))
  8709. result = 3;
  8710. else if (results.Contains(2))
  8711. result = 2;
  8712. else if (results.Contains(4))
  8713. result = 4;
  8714. else
  8715. result = 4;
  8716. stopwatch2.Stop();
  8717. #region 存储绑定数据到 边线MES系统中
  8718. if (result == 1)
  8719. {
  8720. // 删除绑定信息
  8721. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8722. if (resultMesR != 0)
  8723. {
  8724. result = 4;
  8725. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8726. }
  8727. }
  8728. #endregion 存储绑定数据到 边线MES系统中
  8729. // MES_Flag 为4MES报错
  8730. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8731. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8732. writeToPLC_Flag.Name = "d5MES_FLAG";
  8733. writeToPLC_Flag.Adress = 2591;
  8734. writeToPLC_Flag.Value = result;
  8735. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8736. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8737. }
  8738. catch (Exception ex)
  8739. {
  8740. stopwatch2.Restart();
  8741. // MES_Flag 为4上位机报错
  8742. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8743. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8744. writeToPLC_Flag.Name = "d5MES_FLAG";
  8745. writeToPLC_Flag.Adress = 2591;
  8746. writeToPLC_Flag.Value = (short)4;
  8747. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8748. stopwatch2.Stop();
  8749. string str = ex.StackTrace;
  8750. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8751. }
  8752. stopwatch1.Stop();
  8753. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8754. }
  8755. /// <summary>
  8756. /// [S4] 取放桁架 - S4_5节拍接口
  8757. /// </summary>
  8758. /// <param name="plcNo">PLC编号</param>
  8759. /// <param name="stationNameStr">工站全称</param>
  8760. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8761. {
  8762. Stopwatch stopwatch1 = new Stopwatch();
  8763. Stopwatch stopwatch2 = new Stopwatch();
  8764. string resultStr = string.Empty;
  8765. try
  8766. {
  8767. stopwatch1.Start();
  8768. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8769. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8770. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8771. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8772. if (!actionBool)
  8773. {
  8774. stopwatch2.Start();
  8775. // MES_Flag
  8776. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8777. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8778. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8779. writeToPLC_Flag1.Adress = 2924;
  8780. writeToPLC_Flag1.Value = (short)4;
  8781. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8782. stopwatch2.Stop();
  8783. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8784. return;
  8785. }
  8786. string d5OEEPartNo = string.Empty; // 物料码
  8787. if (string.IsNullOrEmpty(d5OEEProductSN))
  8788. {
  8789. stopwatch2.Start();
  8790. // MES_Flag
  8791. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8792. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8793. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8794. writeToPLC_Flag1.Adress = 2924;
  8795. writeToPLC_Flag1.Value = (short)1;
  8796. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8797. stopwatch2.Stop();
  8798. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8799. return;
  8800. }
  8801. else
  8802. { // 查产品SN
  8803. d5OEEPartNo = "Test"; // ZS
  8804. }
  8805. short d5OEEMES_FLAG = 0;
  8806. // 上传OEE
  8807. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8808. d5OEEMES_FLAG = result.Item1;
  8809. resultStr = result.Item2;
  8810. stopwatch2.Start();
  8811. // MES_Flag
  8812. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8813. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8814. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8815. writeToPLC_Flag.Adress = 2924;
  8816. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8817. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8818. stopwatch2.Stop();
  8819. }
  8820. catch (Exception ex)
  8821. {
  8822. string str = ex.StackTrace;
  8823. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8824. // MES_Flag
  8825. stopwatch2.Start();
  8826. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8827. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8828. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8829. writeToPLC_Flag.Adress = 2924;
  8830. writeToPLC_Flag.Value = (short)4;
  8831. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8832. stopwatch2.Stop();
  8833. }
  8834. stopwatch1.Stop();
  8835. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8836. }
  8837. #endregion [S4] 取放桁架
  8838. #endregion PLC4 刘果段
  8839. #region PLC5 张超凡
  8840. #region [S5] Tray盘下料装备
  8841. /// <summary>
  8842. /// S5工位的数据- 触发信号上次的值
  8843. /// </summary>
  8844. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8845. /// <summary>
  8846. /// S5工位的数据(含触发信号)
  8847. /// </summary>
  8848. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8849. /// <summary>
  8850. /// S5工位的数据- 回写点位
  8851. /// </summary>
  8852. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8853. /// <summary>
  8854. /// [S5] Tray盘下料装备
  8855. /// </summary>
  8856. /// <param name="plcNo">PLC编号</param>
  8857. //private void ReadStation_S5(int plcNo)
  8858. //{
  8859. // // [S1] Tray盘上料装备
  8860. // // [S2] FCT
  8861. // // [S3] 值板机
  8862. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8863. // // [S5] Tray盘下料装备
  8864. // /// 上位机心跳
  8865. // /// 获取设备报警数据与状态信息
  8866. // string stationCode = "[S5]";
  8867. // string stationName = "Tray盘下料装备";
  8868. // string stationNameStr = stationCode + stationName;
  8869. // #region 创建字典
  8870. // // 触发信号字典 赋值
  8871. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8872. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8873. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8874. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8875. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8876. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8877. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8878. // // PLC数据字典 赋值
  8879. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8880. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8881. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8882. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8883. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8884. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8885. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8886. // s5PLCData.Add("e1Result", 0); // 产品结果
  8887. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8888. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8889. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8890. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8891. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8892. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8893. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8894. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8895. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8896. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8897. // #endregion 创建字典
  8898. // while (IsRun)
  8899. // {
  8900. // try
  8901. // {
  8902. // if (!GlobalContext._IsCon_Funs5)
  8903. // {
  8904. // UpdatePLCMonitor(1, plcNo, 0);
  8905. // continue;
  8906. // }
  8907. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8908. // {
  8909. // Stopwatch stopwatch1 = new Stopwatch();
  8910. // Stopwatch stopwatch2 = new Stopwatch();
  8911. // stopwatch1.Start();
  8912. // stopwatch2.Start();
  8913. // #region 一次性读取所有数据
  8914. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8915. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8916. // int[] datas = data1.Concat(data2).ToArray();
  8917. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8918. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8919. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8920. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8921. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8922. // s5PLCData["e1MES_FLAG"] = datas[35];
  8923. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8924. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8925. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8926. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8927. // s5PLCData["e1Result"] = datas[76];
  8928. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8929. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8930. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8931. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8932. // s5PLCData["e1OEEType"] = datas[109];
  8933. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8934. // s5PLCData["e1AGVUpStart"] = datas[121];
  8935. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8936. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8937. // s5PLCData["e1AGVDownStart"] = datas[134];
  8938. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8939. // #endregion 一次性读取所有数据
  8940. // stopwatch2.Stop();
  8941. // #region 回写操作,写后清空flag
  8942. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8943. // #endregion 回写操作,写后清空flag
  8944. // #region 进站校验
  8945. // try
  8946. // {
  8947. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8948. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8949. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  8950. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  8951. // {
  8952. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  8953. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8954. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  8955. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8956. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  8957. // }
  8958. // }
  8959. // catch (Exception ex)
  8960. // {
  8961. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8962. // string str = ex.StackTrace;
  8963. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8964. // }
  8965. // #endregion 进站校验
  8966. // #region 出站接口
  8967. // try
  8968. // {
  8969. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  8970. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  8971. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  8972. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  8973. // {
  8974. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  8975. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8976. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  8977. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  8978. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  8979. // }
  8980. // }
  8981. // catch (Exception ex)
  8982. // {
  8983. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  8984. // string str = ex.StackTrace;
  8985. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8986. // }
  8987. // #endregion 出站接口
  8988. // #region 节拍接口
  8989. // try
  8990. // {
  8991. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  8992. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  8993. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  8994. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  8995. // {
  8996. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  8997. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8998. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  8999. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  9000. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  9001. // }
  9002. // }
  9003. // catch (Exception ex)
  9004. // {
  9005. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9006. // string str = ex.StackTrace;
  9007. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9008. // }
  9009. // #endregion 节拍接口
  9010. // #region AGV上料
  9011. // // AGV上料叫AGV信号
  9012. // try
  9013. // {
  9014. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  9015. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  9016. // if (e1AGVUpCall != e1AGVUpCallOld)
  9017. // {
  9018. // if (e1AGVUpCall == 1) // 0->1
  9019. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  9020. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  9021. // }
  9022. // }
  9023. // catch (Exception ex)
  9024. // {
  9025. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9026. // string str = ex.StackTrace;
  9027. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9028. // }
  9029. // // AGV上料完成信号
  9030. // try
  9031. // {
  9032. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  9033. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  9034. // if (e1AGVUpEnd != e1AGVUpEndOld)
  9035. // {
  9036. // if (e1AGVUpEnd == 1) // 0->1
  9037. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  9038. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  9039. // }
  9040. // }
  9041. // catch (Exception ex)
  9042. // {
  9043. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9044. // string str = ex.StackTrace;
  9045. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9046. // }
  9047. // #endregion AGV上料
  9048. // #region AGV下料
  9049. // // AGV下料叫agv信号
  9050. // try
  9051. // {
  9052. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  9053. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  9054. // if (e1AGVDownCall != e1AGVDownCallOld)
  9055. // {
  9056. // if (e1AGVDownCall == 1) // 0->1
  9057. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  9058. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  9059. // }
  9060. // }
  9061. // catch (Exception ex)
  9062. // {
  9063. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9064. // string str = ex.StackTrace;
  9065. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9066. // }
  9067. // // AGV下料完成信号
  9068. // try
  9069. // {
  9070. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  9071. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  9072. // if (e1AGVDownEnd != e1AGVDownEndOld)
  9073. // {
  9074. // if (e1AGVDownEnd == 1) // 0->1
  9075. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  9076. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  9077. // }
  9078. // }
  9079. // catch (Exception ex)
  9080. // {
  9081. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9082. // string str = ex.StackTrace;
  9083. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9084. // }
  9085. // #endregion AGV下料
  9086. // #region 心跳
  9087. // try
  9088. // {
  9089. // short states = 0;
  9090. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9091. // }
  9092. // catch (Exception ex)
  9093. // {
  9094. // string str = ex.StackTrace;
  9095. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9096. // }
  9097. // #endregion 心跳
  9098. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9099. // stopwatch1.Stop();
  9100. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9101. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9102. // }
  9103. // else
  9104. // {
  9105. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9106. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9107. // Funs[plcNo].Connect();
  9108. // }
  9109. // }
  9110. // catch (Exception ex)
  9111. // {
  9112. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9113. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9114. // Funs[plcNo].ReConnect();
  9115. // }
  9116. // Thread.Sleep(IntervalReadPLC);
  9117. // }
  9118. //}
  9119. /// <summary>
  9120. /// [S5] Tray盘下料装备 - 进站校验
  9121. /// </summary>
  9122. /// <param name="plcNo">PLC编号</param>
  9123. /// <param name="stationNameStr">工站全称</param>
  9124. private void S5进站校验(int plcNo, string stationNameStr)
  9125. {
  9126. Stopwatch stopwatch1 = new Stopwatch();
  9127. Stopwatch stopwatch2 = new Stopwatch();
  9128. try
  9129. {
  9130. stopwatch1.Start();
  9131. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9132. sn = sn.Replace("\0", "");
  9133. // 获取产品SN By 载具码
  9134. #region 查询载具上的产品信息
  9135. string cavityData = string.Empty;
  9136. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9137. if (string.IsNullOrEmpty(cavityData))
  9138. cavityData = "";
  9139. if (snResult != 0)
  9140. {
  9141. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9142. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9143. writeToPLC_Flag1.Adress = 2003;
  9144. writeToPLC_Flag1.Value = (short)6;
  9145. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9146. stopwatch1.Stop();
  9147. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9148. return;
  9149. }
  9150. string[] cavitySNs = cavityData.Split('.');
  9151. string partNo = string.Empty;
  9152. if (cavitySNs != null && cavitySNs.Length >= 1)
  9153. partNo = cavitySNs[0];
  9154. #endregion 查询载具上的产品信息
  9155. // 产品SN(物料码)校验
  9156. List<TestItem> item = new List<TestItem>();
  9157. item.Add(new TestItem()
  9158. {
  9159. Parameter_name = "载具码",
  9160. Parameter_value = sn,
  9161. });
  9162. item.Add(new TestItem()
  9163. {
  9164. Parameter_name = "载具穴号",
  9165. Parameter_value = "1",
  9166. });
  9167. stopwatch2.Start();
  9168. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9169. stopwatch2.Stop();
  9170. short e1MES_FLAG_Check = (short)result;
  9171. // MES_Flag
  9172. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9173. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9174. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9175. writeToPLC_Flag.Adress = 2003;
  9176. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9177. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9178. }
  9179. catch (Exception ex)
  9180. {
  9181. string str = ex.StackTrace;
  9182. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9183. // MES_Flag
  9184. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9185. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9186. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9187. writeToPLC_Flag.Adress = 2003;
  9188. writeToPLC_Flag.Value = (short)6;
  9189. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9190. }
  9191. stopwatch1.Stop();
  9192. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9193. }
  9194. /// <summary>
  9195. /// [S5] Tray盘下料装备 - 出站接口
  9196. /// </summary>
  9197. /// <param name="plcNo"></param>
  9198. /// <param name="stationCode"></param>
  9199. /// <param name="stationName"></param>
  9200. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9201. {
  9202. Stopwatch stopwatch1 = new Stopwatch();
  9203. Stopwatch stopwatch2 = new Stopwatch();
  9204. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9205. string stationNameStr = stationCode + stationName;
  9206. string processItem = stationName; // 测试项目
  9207. try
  9208. {
  9209. stopwatch1.Start();
  9210. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9211. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9212. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9213. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9214. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9215. sn = sn.Replace("\0", "");
  9216. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9217. //partNo = partNo.Replace("\0", "");
  9218. #region 查询载具上的产品信息
  9219. string cavityData = string.Empty;
  9220. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9221. if (string.IsNullOrEmpty(cavityData))
  9222. cavityData = "";
  9223. if (snResult != 0)
  9224. {
  9225. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9226. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9227. writeToPLC_Flag1.Adress = 2035;
  9228. writeToPLC_Flag1.Value = (short)4;
  9229. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9230. stopwatch1.Stop();
  9231. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9232. return;
  9233. }
  9234. string[] cavitySNs = cavityData.Split('.');
  9235. string partNo = string.Empty;
  9236. if (cavitySNs != null && cavitySNs.Length >= 1)
  9237. partNo = cavitySNs[0];
  9238. #endregion 查询载具上的产品信息
  9239. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9240. bool pass = e1Result == 1;
  9241. stopwatch2.Start();
  9242. // 上传MES
  9243. List<TestItem> items = new List<TestItem>();
  9244. items.Add(new TestItem()
  9245. {
  9246. Parameter_name = "载具码",
  9247. Parameter_value = sn,
  9248. Parameter_unit = ""
  9249. });
  9250. items.Add(new TestItem()
  9251. {
  9252. Parameter_name = "载具穴号",
  9253. Parameter_value = "1",
  9254. Parameter_unit = ""
  9255. });
  9256. items.Add(new TestItem()
  9257. {
  9258. Parameter_name = "产品结果",
  9259. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9260. Parameter_unit = ""
  9261. });
  9262. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  9263. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9264. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9265. short result = result1 == 1 ? (short)1 : (short)3;
  9266. stopwatch2.Stop();
  9267. #region 存储绑定数据到 边线MES系统中
  9268. if (result == 1)
  9269. {
  9270. // 删除绑定信息
  9271. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9272. if (resultMesR != 0)
  9273. {
  9274. result = 4;
  9275. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9276. }
  9277. }
  9278. #endregion 存储绑定数据到 边线MES系统中
  9279. // MES_Flag 为MES报错
  9280. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9281. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9282. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9283. writeToPLC_Flag.Name = "e1MES_FLAG";
  9284. writeToPLC_Flag.Adress = 2035;
  9285. writeToPLC_Flag.Value = result;
  9286. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9287. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9288. }
  9289. catch (Exception ex)
  9290. {
  9291. stopwatch2.Restart();
  9292. // MES_Flag 为4上位机报错
  9293. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9294. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9295. writeToPLC_Flag.Name = "e1MES_FLAG";
  9296. writeToPLC_Flag.Adress = 2035;
  9297. writeToPLC_Flag.Value = (short)4;
  9298. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9299. stopwatch2.Stop();
  9300. string str = ex.StackTrace;
  9301. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9302. }
  9303. stopwatch1.Stop();
  9304. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9305. }
  9306. /// <summary>
  9307. /// [S5] Tray盘下料装备 - 节拍接口
  9308. /// </summary>
  9309. /// <param name="plcNo">PLC编号</param>
  9310. /// <param name="stationNameStr">工站全称</param>
  9311. private void S5节拍接口(int plcNo, string stationNameStr)
  9312. {
  9313. Stopwatch stopwatch1 = new Stopwatch();
  9314. Stopwatch stopwatch2 = new Stopwatch();
  9315. string resultStr = string.Empty;
  9316. try
  9317. {
  9318. stopwatch1.Start();
  9319. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9320. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9321. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9322. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9323. if (!actionBool)
  9324. {
  9325. stopwatch2.Start();
  9326. // MES_Flag
  9327. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9328. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9329. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9330. writeToPLC_Flag1.Adress = 2088;
  9331. writeToPLC_Flag1.Value = (short)4;
  9332. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9333. stopwatch2.Stop();
  9334. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9335. return;
  9336. }
  9337. string e1OEEPartNo = string.Empty; // 物料码
  9338. if (string.IsNullOrEmpty(e1OEEProductSN))
  9339. {
  9340. stopwatch2.Start();
  9341. // MES_Flag
  9342. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9343. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9344. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9345. writeToPLC_Flag1.Adress = 2088;
  9346. writeToPLC_Flag1.Value = (short)1;
  9347. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9348. stopwatch2.Stop();
  9349. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9350. return;
  9351. }
  9352. else
  9353. { // 查产品SN
  9354. e1OEEPartNo = "Test"; // ZS
  9355. }
  9356. short e1OEEMES_FLAG = 0;
  9357. // 上传OEE
  9358. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9359. e1OEEMES_FLAG = result.Item1;
  9360. resultStr = result.Item2;
  9361. stopwatch2.Start();
  9362. // MES_Flag
  9363. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9364. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9365. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9366. writeToPLC_Flag.Adress = 2088;
  9367. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9368. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9369. stopwatch2.Stop();
  9370. }
  9371. catch (Exception ex)
  9372. {
  9373. string str = ex.StackTrace;
  9374. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9375. // MES_Flag
  9376. stopwatch2.Start();
  9377. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9378. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9379. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9380. writeToPLC_Flag.Adress = 2088;
  9381. writeToPLC_Flag.Value = (short)4;
  9382. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9383. stopwatch2.Stop();
  9384. }
  9385. stopwatch1.Stop();
  9386. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9387. }
  9388. /// <summary>
  9389. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9390. /// </summary>
  9391. /// <param name="plcNo">PLC编号</param>
  9392. /// <param name="stationNameStr">工站全称</param>
  9393. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9394. {
  9395. Stopwatch stopwatch1 = new Stopwatch();
  9396. Stopwatch stopwatch2 = new Stopwatch();
  9397. try
  9398. {
  9399. stopwatch1.Start();
  9400. // ZS 呼叫AGV
  9401. short e1AGVUpCall = 2;
  9402. stopwatch2.Start();
  9403. // e1AGVUpCall
  9404. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9405. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9406. writeToPLC_Flag.Name = "e1AGVUpCall";
  9407. writeToPLC_Flag.Adress = 2120;
  9408. writeToPLC_Flag.Value = e1AGVUpCall;
  9409. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9410. stopwatch2.Stop();
  9411. }
  9412. catch (Exception ex)
  9413. {
  9414. string str = ex.StackTrace;
  9415. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9416. // e1AGVUpCall
  9417. stopwatch2.Start();
  9418. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9419. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9420. writeToPLC_Flag.Name = "e1AGVUpCall";
  9421. writeToPLC_Flag.Adress = 2120;
  9422. writeToPLC_Flag.Value = (short)4;
  9423. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9424. stopwatch2.Stop();
  9425. }
  9426. stopwatch1.Stop();
  9427. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9428. }
  9429. /// <summary>
  9430. /// [S5] Tray盘下料装备 - AGV上料完成
  9431. /// </summary>
  9432. /// <param name="plcNo">PLC编号</param>
  9433. /// <param name="stationNameStr">工站全称</param>
  9434. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9435. {
  9436. Stopwatch stopwatch1 = new Stopwatch();
  9437. Stopwatch stopwatch2 = new Stopwatch();
  9438. try
  9439. {
  9440. stopwatch1.Start();
  9441. // ZS AGV上料完成,让小车离开
  9442. short e1AGVUpEnd = 2;
  9443. stopwatch2.Start();
  9444. // e1AGVUpEnd
  9445. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9446. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9447. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9448. writeToPLC_Flag.Adress = 2122;
  9449. writeToPLC_Flag.Value = e1AGVUpEnd;
  9450. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9451. stopwatch2.Stop();
  9452. }
  9453. catch (Exception ex)
  9454. {
  9455. string str = ex.StackTrace;
  9456. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9457. // e1AGVUpEnd
  9458. stopwatch2.Start();
  9459. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9460. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9461. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9462. writeToPLC_Flag.Adress = 2122;
  9463. writeToPLC_Flag.Value = (short)4;
  9464. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9465. stopwatch2.Stop();
  9466. }
  9467. stopwatch1.Stop();
  9468. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9469. }
  9470. /// <summary>
  9471. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9472. /// </summary>
  9473. /// <param name="plcNo">PLC编号</param>
  9474. /// <param name="stationNameStr">工站全称</param>
  9475. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9476. {
  9477. Stopwatch stopwatch1 = new Stopwatch();
  9478. Stopwatch stopwatch2 = new Stopwatch();
  9479. try
  9480. {
  9481. stopwatch1.Start();
  9482. // ZS 呼叫AGV
  9483. short e1AGVDownCall = 2;
  9484. stopwatch2.Start();
  9485. // e1AGVDownCall
  9486. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9487. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9488. writeToPLC_Flag.Name = "e1AGVDownCall";
  9489. writeToPLC_Flag.Adress = 2133;
  9490. writeToPLC_Flag.Value = e1AGVDownCall;
  9491. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9492. stopwatch2.Stop();
  9493. }
  9494. catch (Exception ex)
  9495. {
  9496. string str = ex.StackTrace;
  9497. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9498. // e1AGVDownCall
  9499. stopwatch2.Start();
  9500. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9501. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9502. writeToPLC_Flag.Name = "e1AGVDownCall";
  9503. writeToPLC_Flag.Adress = 2133;
  9504. writeToPLC_Flag.Value = (short)4;
  9505. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9506. stopwatch2.Stop();
  9507. }
  9508. stopwatch1.Stop();
  9509. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9510. }
  9511. /// <summary>
  9512. /// [S5] Tray盘下料装备 - AGV下料完成
  9513. /// </summary>
  9514. /// <param name="plcNo">PLC编号</param>
  9515. /// <param name="stationNameStr">工站全称</param>
  9516. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9517. {
  9518. Stopwatch stopwatch1 = new Stopwatch();
  9519. Stopwatch stopwatch2 = new Stopwatch();
  9520. try
  9521. {
  9522. stopwatch1.Start();
  9523. // ZS AGV上料完成,让小车离开
  9524. short e1AGVDownEnd = 2;
  9525. stopwatch2.Start();
  9526. // e1AGVDownEnd
  9527. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9528. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9529. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9530. writeToPLC_Flag.Adress = 2135;
  9531. writeToPLC_Flag.Value = e1AGVDownEnd;
  9532. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9533. stopwatch2.Stop();
  9534. }
  9535. catch (Exception ex)
  9536. {
  9537. string str = ex.StackTrace;
  9538. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9539. // e1AGVDownEnd
  9540. stopwatch2.Start();
  9541. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9542. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9543. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9544. writeToPLC_Flag.Adress = 2135;
  9545. writeToPLC_Flag.Value = (short)4;
  9546. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9547. stopwatch2.Stop();
  9548. }
  9549. stopwatch1.Stop();
  9550. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9551. }
  9552. #endregion [S5] Tray盘下料装备
  9553. #endregion PLC5 张超凡
  9554. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9555. /// <summary>
  9556. /// PLC读取到的数据 -添加数据
  9557. /// </summary>
  9558. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9559. {
  9560. if (sxPlcData.ContainsKey(newKey))
  9561. sxPlcData[newKey] = newValue;
  9562. else
  9563. sxPlcData.Add(newKey, newValue);
  9564. }
  9565. /// <summary>
  9566. /// PLC需要写入的数据 -添加数据
  9567. /// </summary>
  9568. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9569. {
  9570. if (sxPLCWriteData.ContainsKey(newKey))
  9571. sxPLCWriteData[newKey] = newValue;
  9572. else
  9573. sxPLCWriteData.Add(newKey, newValue);
  9574. }
  9575. /// <summary>
  9576. /// PLC回写操作,写后清空flag
  9577. /// </summary>
  9578. /// <param name="modbusClient">modbus对象</param>
  9579. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9580. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9581. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9582. {
  9583. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9584. {
  9585. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9586. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9587. {
  9588. string mesFlagName = pLCWriteDatas[i].Name;
  9589. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9590. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9591. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9592. {
  9593. // 先回写数据
  9594. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9595. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9596. {
  9597. int mesDataAdress = writeToPLCDatas[j].Adress;
  9598. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9599. switch (mesDataType)
  9600. {
  9601. case PLCValueType.Short:
  9602. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9603. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9604. break;
  9605. case PLCValueType.String:
  9606. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9607. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9608. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9609. break;
  9610. }
  9611. }
  9612. // 再回写信号
  9613. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9614. // 存储读取数据的字典
  9615. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9616. // 存储写入数据的字典 - 清空写入值
  9617. pLCWriteDatas[i].Value = (short)0;
  9618. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9619. }
  9620. }
  9621. }
  9622. }
  9623. /// <summary>
  9624. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9625. /// </summary>
  9626. /// <param name="no">3</param>
  9627. /// <param name="stationCode">设备编号</param>
  9628. /// <param name="stationNameStr">设备名称</param>
  9629. /// <param name="plcOrder">车间订单号</param>
  9630. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9631. {
  9632. try
  9633. {
  9634. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9635. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9636. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9637. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9638. int result1 = 0;
  9639. switch (stationCode)
  9640. {
  9641. case 2:
  9642. case 3:
  9643. case 4:
  9644. case 6:
  9645. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9646. break;
  9647. case 102:
  9648. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9649. break;
  9650. case 103:
  9651. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9652. break;
  9653. case 104:
  9654. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9655. break;
  9656. case 106:
  9657. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9658. break;
  9659. default:
  9660. // MES_Flag 为“6未找到正确设备编号”
  9661. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9662. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9663. return;
  9664. }
  9665. short result = result1 == 1 ? (short)1 : (short)2;
  9666. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9667. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9668. }
  9669. catch (Exception ex)
  9670. {
  9671. // MES_Flag 为2上位机报错
  9672. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9673. string str = ex.StackTrace;
  9674. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9675. }
  9676. }
  9677. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9678. #region UI刷新
  9679. /// <summary>
  9680. /// 更新商品信息的UI + 下发产品信息(SN)
  9681. /// </summary>
  9682. private void UpdateProductInfo()
  9683. {
  9684. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9685. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9686. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9687. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9688. }
  9689. /// <summary>
  9690. /// 更新PLC连接状态的UI
  9691. /// </summary>
  9692. /// <param name="no">PLC编号</param>
  9693. /// <param name="status">状态</param>
  9694. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9695. {
  9696. if (this != null && !this.IsDisposed)
  9697. {
  9698. switch (imgNo)
  9699. {
  9700. case 1:
  9701. this.BeginInvoke(new Action(() =>
  9702. {
  9703. picPLC.Image = imageListState.Images[status];
  9704. }));
  9705. break;
  9706. case 2:
  9707. this.BeginInvoke(new Action(() =>
  9708. {
  9709. pictureBox2.Image = imageListState.Images[status];
  9710. }));
  9711. break;
  9712. case 3:
  9713. this.BeginInvoke(new Action(() =>
  9714. {
  9715. pictureBox3.Image = imageListState.Images[status];
  9716. }));
  9717. break;
  9718. case 4:
  9719. this.BeginInvoke(new Action(() =>
  9720. {
  9721. pictureBox4.Image = imageListState.Images[status];
  9722. }));
  9723. break;
  9724. case 5:
  9725. this.BeginInvoke(new Action(() =>
  9726. {
  9727. pictureBox5.Image = imageListState.Images[status];
  9728. }));
  9729. break;
  9730. case 6:
  9731. this.BeginInvoke(new Action(() =>
  9732. {
  9733. pictureBox6.Image = imageListState.Images[status];
  9734. }));
  9735. break;
  9736. case 7:
  9737. this.BeginInvoke(new Action(() =>
  9738. {
  9739. pictureBox7.Image = imageListState.Images[status];
  9740. }));
  9741. break;
  9742. case 8:
  9743. this.BeginInvoke(new Action(() =>
  9744. {
  9745. pictureBox8.Image = imageListState.Images[status];
  9746. }));
  9747. break;
  9748. default:
  9749. break;
  9750. }
  9751. }
  9752. Task.Run(() => // 更新PLC交互页的指示灯
  9753. {
  9754. try
  9755. {
  9756. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9757. {
  9758. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9759. }
  9760. }
  9761. catch { }
  9762. });
  9763. }
  9764. #endregion UI刷新
  9765. #region 日志
  9766. /// <summary>
  9767. /// 添加各工位运行日志(同步至PLC交互页面)
  9768. /// </summary>
  9769. /// <param name="stationNameStr">工站名称</param>
  9770. /// <param name="logType">日志类型</param>
  9771. /// <param name="message">日志内容</param>
  9772. /// <param name="snNumber">产品数字SN</param>
  9773. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9774. {
  9775. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9776. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9777. ))
  9778. {
  9779. AddMessage(logType, message); // 首页展示+日志记录
  9780. }
  9781. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9782. {
  9783. StationName = stationNameStr,
  9784. SnNumber = snNumber,
  9785. Message = message,
  9786. CreateTime = DateTime.Now
  9787. };
  9788. // PLC交互页展示
  9789. Task.Run(() =>
  9790. {
  9791. try
  9792. {
  9793. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9794. {
  9795. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9796. }
  9797. }
  9798. catch { }
  9799. });
  9800. }
  9801. /// <summary>
  9802. /// 添加运行日志
  9803. /// </summary>
  9804. /// <param name="logType">日志类型</param>
  9805. /// <param name="message">日志内容</param>
  9806. public void AddMessage(LogType logType, string message)
  9807. {
  9808. OnMessage(logType, message);
  9809. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9810. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9811. string msgShow = time + "--> " + message + "\r\n";
  9812. this.BeginInvoke(new Action(() =>
  9813. {
  9814. systemLog.Rows.Insert(0, date, time, message);
  9815. if (systemLog.Rows.Count >= 100)
  9816. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9817. }));
  9818. }
  9819. /// <summary>
  9820. /// 添加运行日志-保存
  9821. /// </summary>
  9822. /// <param name="logType">日志类型</param>
  9823. /// <param name="message">日志内容</param>
  9824. private void OnMessage(LogType logType, string msg)
  9825. {
  9826. MessageEvent?.Invoke(logType, msg);
  9827. }
  9828. /// <summary>
  9829. /// 保存PLC写入日志
  9830. /// </summary>
  9831. /// <param name="logType"></param>
  9832. /// <param name="logValue"></param>
  9833. private void WritePLCLog(LogType logType, string logValue)
  9834. {
  9835. switch ((int)logType)
  9836. {
  9837. case 0:
  9838. _PLCLogNet.WriteDebug(logValue);
  9839. break;
  9840. case 1:
  9841. _PLCLogNet.WriteInfo(logValue);
  9842. break;
  9843. case 2:
  9844. _PLCLogNet.WriteWarn(logValue);
  9845. break;
  9846. case 3:
  9847. _PLCLogNet.WriteError(logValue);
  9848. break;
  9849. default:
  9850. _PLCLogNet.WriteFatal(logValue);
  9851. break;
  9852. }
  9853. }
  9854. /// <summary>
  9855. /// IOT Mqtt回调方法- With DataId
  9856. /// </summary>
  9857. /// <param name="id"></param>
  9858. /// <param name="v"></param>
  9859. /// <param name="dataId"></param>
  9860. public void CallbackWithDataId(string id, string msg, string dataId)
  9861. {
  9862. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9863. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9864. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9865. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9866. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9867. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9868. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9869. }
  9870. /// <summary>
  9871. /// AGV Mqtt回调方法- 记录Log并处理数据
  9872. /// </summary>
  9873. /// <param name="obj"></param>
  9874. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9875. {
  9876. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9877. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9878. // 接收到的信息
  9879. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9880. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9881. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9882. {
  9883. }
  9884. }
  9885. #endregion 日志
  9886. /// <summary>
  9887. /// 实例化报警字典
  9888. /// </summary>
  9889. private void InitalDicAlarm()
  9890. {
  9891. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9892. List<Alarm> keyValues1 = new List<Alarm>
  9893. {
  9894. #region 第一组报警(电机)
  9895. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9896. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9897. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9898. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9899. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9900. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9901. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9902. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9903. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9904. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9905. #endregion 第一组报警(电机)
  9906. #region 第二组报警(气缸)
  9907. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9908. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9909. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9910. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9911. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9912. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9913. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9914. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9915. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9916. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9917. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9918. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9919. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9920. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9921. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9922. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9923. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9924. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9925. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9926. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9927. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9928. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9929. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9930. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9931. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9932. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9933. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9934. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9935. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9936. #endregion 第二组报警(气缸)
  9937. #region 第三组报警(其他故障)
  9938. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9939. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9940. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9941. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9942. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9943. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9944. #endregion 第三组报警(其他故障)
  9945. };
  9946. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9947. #endregion 第一个工站(这里使用线体代替工位)
  9948. # region 第二个工站-原来的写法(废弃)
  9949. //keyValues = new Dictionary<int, AlarmData[]>();
  9950. ////1
  9951. //dicAlarmName = new Dictionary<int, Alarm>();
  9952. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  9953. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  9954. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  9955. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  9956. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  9957. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9958. //for (int i = 0; i < dicAlarmName.Count; i++)
  9959. //{
  9960. // alarmDatas[i] = new AlarmData();
  9961. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9962. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9963. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9964. // alarmDatas[i].AlarmType = 1;
  9965. //}
  9966. //keyValues.Add(1, alarmDatas);
  9967. ////2
  9968. //dicAlarmName = new Dictionary<int, Alarm>();
  9969. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  9970. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  9971. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  9972. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  9973. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  9974. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  9975. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  9976. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  9977. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9978. //for (int i = 0; i < dicAlarmName.Count; i++)
  9979. //{
  9980. // alarmDatas[i] = new AlarmData();
  9981. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9982. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9983. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9984. // alarmDatas[i].AlarmType = 2;
  9985. //}
  9986. //keyValues.Add(2, alarmDatas);
  9987. ////3
  9988. //dicAlarmName = new Dictionary<int, Alarm>();
  9989. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  9990. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  9991. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  9992. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  9993. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9994. //for (int i = 0; i < dicAlarmName.Count; i++)
  9995. //{
  9996. // alarmDatas[i] = new AlarmData();
  9997. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  9998. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9999. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10000. // alarmDatas[i].AlarmType = 3;
  10001. //}
  10002. //keyValues.Add(3, alarmDatas);
  10003. //DicAlarms.Add(2, keyValues);
  10004. #endregion 第二个工站-原来的写法(废弃)
  10005. }
  10006. }
  10007. }