Form_Home.cs 590 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
  40. /*
  41. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  42. */
  43. namespace MainForm
  44. {
  45. /// <summary>
  46. /// 记录日志的委托
  47. /// </summary>
  48. /// <param name="logType">日志类型</param>
  49. /// <param name="message">日志信息</param>
  50. public delegate void HomeMessageHandler(LogType logType, string message);
  51. /// <summary>
  52. /// 主页窗体
  53. /// </summary>
  54. public partial class Form_Home : Form
  55. {
  56. #region 常量
  57. //文本常量
  58. private const string Head = "开始采集";
  59. private const string Tail = "采集完成";
  60. private const string Body = "工位出站数据";
  61. private const string BodyCheck = "工位点检数据";
  62. private const string BodyRun = "整线运行数据";
  63. private const string BodyAlarm = "整线报警数据";
  64. #endregion 常量
  65. #region 变量
  66. /// <summary>
  67. /// 委托-记录日志的方法
  68. /// </summary>
  69. public event HomeMessageHandler MessageEvent;
  70. /// <summary>
  71. /// 日志接口
  72. /// </summary>
  73. ILogNet _PLCLogNet;
  74. /// <summary>
  75. /// 用于记录IOT MQTT日志
  76. /// </summary>
  77. ILogNet _IOTMqttLogNet;
  78. /// <summary>
  79. /// 用于记录AGV MQTT日志
  80. /// </summary>
  81. ILogNet _AGVMqttLogNet;
  82. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  83. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  84. // 间隔时间
  85. private int IntervalReadPLC = 300; //ms 读PLC
  86. private int IntervalMonitorMES = 1000; //ms MES心跳
  87. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  88. // 软件状态
  89. private bool IsRun = true;
  90. #region PLC 与 TCP对象
  91. // 定义一个字典,存plc对象(通讯)
  92. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  93. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  94. // 定义TCPClient对象列表
  95. Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  96. // 定义MQTTHelper对象
  97. MQTTHelper _MQTTHelper = new MQTTHelper();
  98. #endregion PLC 与 TCP对象
  99. /// <summary>
  100. /// 上次的设备运行信息
  101. /// </summary>
  102. private string lineWorkingData1_OldStr = string.Empty;
  103. /// <summary>
  104. /// 设备报警字典-当前结果
  105. /// Dictionary<工位代码,List<报警信息>>
  106. /// </summary>
  107. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  108. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  109. #endregion 变量
  110. #region 窗体基础事件
  111. /// <summary>
  112. /// 初始化
  113. /// </summary>
  114. public Form_Home()
  115. {
  116. InitializeComponent();
  117. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  118. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  119. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  120. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  121. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  122. }
  123. /// <summary>
  124. /// 窗体加载事件
  125. /// </summary>
  126. private void Form_Home_Load(object sender, EventArgs e)
  127. {
  128. try
  129. {
  130. AddMessage(LogType.Info, "开始初始化程序");
  131. InitalDicAlarm(); // 实例化报警字典
  132. //组建plc对象字典
  133. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  134. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  135. if (GlobalContext.IsUsePLC1)
  136. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  137. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  138. if (GlobalContext.IsUsePLC2)
  139. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  140. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  141. if (GlobalContext.IsUsePLC3)
  142. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  143. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  144. if (GlobalContext.IsUsePLC4)
  145. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  146. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  147. if (GlobalContext.IsUsePLC5)
  148. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  149. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  150. if (GlobalContext.IsUsePLC6)
  151. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  152. if (GlobalContext.IsUsePLC7)
  153. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  154. if (GlobalContext.IsUsePLC8)
  155. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  156. if (GlobalContext.IsUsePLC9)
  157. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  158. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  159. {
  160. if (plcEIP != null)
  161. {
  162. try
  163. {
  164. (int, string) result = plcEIP.Connect();
  165. }
  166. catch (Exception ex)
  167. {
  168. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  169. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  170. }
  171. }
  172. }
  173. /*
  174. //plc1Alarm.Connect();
  175. foreach (ModbusClientHelper modbusClient in Funs.Values)
  176. {
  177. if (modbusClient != null)
  178. {
  179. try
  180. {
  181. modbusClient.Connect();
  182. }
  183. catch (Exception ex)
  184. {
  185. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  186. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  187. }
  188. }
  189. }
  190. */
  191. // 采集任务
  192. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  193. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  194. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  195. if (GlobalContext.IsUsePLC1)
  196. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  197. if (GlobalContext.IsUsePLC2)
  198. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  199. if (GlobalContext.IsUsePLC3)
  200. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  201. if (GlobalContext.IsUsePLC4)
  202. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  203. if (GlobalContext.IsUsePLC5)
  204. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  205. if (GlobalContext.IsUsePLC6)
  206. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  207. if (GlobalContext.IsUsePLC7)
  208. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  209. if (GlobalContext.IsUsePLC8)
  210. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  211. if (GlobalContext.IsUsePLC9)
  212. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  213. #region 初始化
  214. try
  215. {
  216. // 开启边线MES(绑定/查询数据)
  217. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  218. //if (mesRoute == 0)
  219. //{
  220. // //picMESStatus.Image = imageListState.Images[1];
  221. // //GlobalContext.MESIsConnect = true;
  222. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  223. //}
  224. //else
  225. //{
  226. // //picMESStatus.Image = imageListState.Images[0];
  227. // //GlobalContext.MESIsConnect = false;
  228. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  229. //}
  230. // 开启MES(Http)
  231. if (GlobalContext.IsUseMES)
  232. {
  233. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  234. if (mesret)
  235. {
  236. picMESStatus.Image = imageListState.Images[1];
  237. GlobalContext.MESIsConnect = true;
  238. AddMessage(LogType.Info, "小米MES初始连接成功!");
  239. }
  240. else
  241. {
  242. picMESStatus.Image = imageListState.Images[0];
  243. GlobalContext.MESIsConnect = false;
  244. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  245. }
  246. }
  247. // 开启IOT(MQTT)
  248. if (GlobalContext.IsUseIot)
  249. {
  250. string addr = GlobalContext.MQTTServerHost;
  251. int port = GlobalContext.MQTTServerPort;
  252. //生产环境需要修改
  253. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  254. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  255. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  256. {
  257. picIot.Image = imageListState.Images[1];
  258. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  259. // 设置回调函数
  260. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  261. // 配置参数
  262. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  263. // fds
  264. param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
  265. param.parameter.fds.appId = "Auto-Soft";
  266. param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
  267. // mes
  268. param.parameter.mes.address = GlobalContext.ServerIp;
  269. param.parameter.mes.appId = GlobalContext.MESAppId;
  270. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  271. // mqtt
  272. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  273. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  274. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  275. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  276. // 设备配置
  277. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  278. if (GlobalContext.IsUsePLC1)
  279. {
  280. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  281. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  282. }
  283. if (GlobalContext.IsUsePLC2)
  284. {
  285. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  286. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  287. }
  288. if (GlobalContext.IsUsePLC3)
  289. {
  290. param.parameter.equipment.deviceCode = GlobalContext.S3_device_code; // 装备编码
  291. param.parameter.equipment.stationCode = GlobalContext.S3_station; // ⼯位Id
  292. }
  293. if (GlobalContext.IsUsePLC4)
  294. {
  295. param.parameter.equipment.deviceCode = GlobalContext.S4_1_device_code; // 装备编码
  296. param.parameter.equipment.stationCode = GlobalContext.S4_1_station; // ⼯位Id
  297. }
  298. if (GlobalContext.IsUsePLC5)
  299. {
  300. param.parameter.equipment.deviceCode = GlobalContext.S5_device_code; // 装备编码
  301. param.parameter.equipment.stationCode = GlobalContext.S5_station; // ⼯位Id
  302. }
  303. if (GlobalContext.IsUsePLC6)
  304. {
  305. param.parameter.equipment.deviceCode = GlobalContext.S6_device_code; // 装备编码
  306. param.parameter.equipment.stationCode = GlobalContext.S6_station; // ⼯位Id
  307. }
  308. if (GlobalContext.IsUsePLC7)
  309. {
  310. param.parameter.equipment.deviceCode = GlobalContext.S7_device_code; // 装备编码
  311. param.parameter.equipment.stationCode = GlobalContext.S7_station; // ⼯位Id
  312. }
  313. if (GlobalContext.IsUsePLC8)
  314. {
  315. param.parameter.equipment.deviceCode = GlobalContext.S8_device_code; // 装备编码
  316. param.parameter.equipment.stationCode = GlobalContext.S8_station; // ⼯位Id
  317. }
  318. if (GlobalContext.IsUsePLC9)
  319. {
  320. param.parameter.equipment.deviceCode = GlobalContext.S9_device_code; // 装备编码
  321. param.parameter.equipment.stationCode = GlobalContext.S9_station; // ⼯位Id
  322. }
  323. param.parameter.equipment.project = GlobalContext.Project_Code;
  324. param.parameter.equipment.productMode = "debug";
  325. //
  326. param.parameter.other.logLevel = 0;
  327. param.parameter.other.LogPath = "D:\\Test";
  328. XiaomiMqttClient_Extend.ParameterConfig(param);
  329. }
  330. else
  331. {
  332. picIot.Image = imageListState.Images[0];
  333. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  334. }
  335. }
  336. // 开启AGV(Http与MQTT)
  337. if (GlobalContext.IsUseAGV)
  338. {
  339. // AGV HTTP
  340. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  341. if (mesret1)
  342. {
  343. picAgvHttp.Image = imageListState.Images[1];
  344. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  345. }
  346. else
  347. {
  348. picAgvHttp.Image = imageListState.Images[0];
  349. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  350. }
  351. string agvMqttIp = GlobalContext.MQTTServerHost;
  352. int agvMqttPort = GlobalContext.MQTTServerPort;
  353. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  354. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  355. // AGV MQTT
  356. if (result_MQTT.ResultCode == 1)
  357. {
  358. picAgvMqtt.Image = imageListState.Images[1];
  359. GlobalContext.AGVMQTTIsConnect = true;
  360. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  361. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  362. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  363. }
  364. else
  365. {
  366. picAgvMqtt.Image = imageListState.Images[0];
  367. GlobalContext.AGVMQTTIsConnect = false;
  368. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  369. }
  370. }
  371. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  372. Task.Run(MonitorMESConnect);
  373. // 查询PLC连接状态
  374. foreach (int plcNo in FunsEip.Keys)
  375. {
  376. bool connected = FunsEip[plcNo].IsConnected;
  377. if (connected)
  378. {
  379. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  380. AddMessage(LogType.Info, msg);
  381. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  382. }
  383. else
  384. {
  385. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  386. AddMessage(LogType.Info, msg);
  387. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  388. }
  389. }
  390. // PLC4时 初始化扫码器TCP
  391. //if (GlobalContext.IsUsePLC4)
  392. // HpTCPClientInit();
  393. // 开启PLC的业务处理线程-监听PLC点位+状态
  394. foreach (Task task in TaskReadProcess)
  395. {
  396. if (task != null)
  397. task.Start();
  398. }
  399. //// 开启“获取线体报警数据”的线程
  400. //TaskReadAlarm.Start();
  401. ////下传MES信息给1工位(先判断下plc对象数量)
  402. //if (Funs.Count > 1)
  403. // DownLoadProductInfo(1);
  404. AddMessage(LogType.Info, "程序初始化完成");
  405. }
  406. catch (Exception ex)
  407. {
  408. string str = ex.StackTrace;
  409. this.BeginInvoke(new Action(() =>
  410. {
  411. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  412. }));
  413. }
  414. #endregion
  415. }
  416. catch (Exception ex)
  417. {
  418. string str = ex.StackTrace;
  419. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  420. if (ex.Message != null && ex.Message.Contains("timed out"))
  421. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  422. else
  423. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  424. }
  425. }
  426. /// <summary>
  427. /// 窗体关闭事件
  428. /// </summary>
  429. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  430. {
  431. Closed2();
  432. }
  433. public void Closed2()
  434. {
  435. try
  436. {
  437. IsRun = false;
  438. Thread.Sleep(IntervalReadPLC);
  439. // 断开TCP
  440. int count = _HPSocket_TcpClients.Count();
  441. for (int i = 0; i < count; i++)
  442. {
  443. try
  444. {
  445. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  446. {
  447. _HPSocket_TcpClients[i].Stop();
  448. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  449. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  450. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  451. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  452. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  453. }
  454. }
  455. catch { }
  456. }
  457. // 关闭Iot
  458. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  459. // 关闭AGV Mqtt
  460. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  461. }
  462. catch { }
  463. }
  464. #endregion 窗体基础事件
  465. #region 监控MES状态
  466. /// <summary>
  467. /// 监控MES连接状态
  468. /// </summary>
  469. private void MonitorMESConnect()
  470. {
  471. while (IsRun) // 运行被控线程
  472. {
  473. try
  474. {
  475. // 开启MES(Http)
  476. if (GlobalContext.IsUseMES)
  477. {
  478. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  479. if (mesret)
  480. {
  481. picMESStatus.Image = imageListState.Images[1];
  482. GlobalContext.MESIsConnect = true;
  483. }
  484. else
  485. {
  486. picMESStatus.Image = imageListState.Images[0];
  487. GlobalContext.MESIsConnect = false;
  488. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  489. }
  490. }
  491. // 开启IOT(MQTT)
  492. if (GlobalContext.IsUseIot)
  493. {
  494. bool iIot = XiaomiMqttClient.IsOpen;
  495. if (iIot)
  496. picIot.Image = imageListState.Images[1];
  497. else
  498. {
  499. picIot.Image = imageListState.Images[0];
  500. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  501. }
  502. }
  503. // 开启AGV(Http与MQTT)
  504. if (GlobalContext.IsUseAGV)
  505. {
  506. // AGV Http
  507. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  508. if (mesret1)
  509. picAgvHttp.Image = imageListState.Images[1];
  510. else
  511. {
  512. picAgvHttp.Image = imageListState.Images[0];
  513. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  514. }
  515. // AGV MQTT
  516. if (GlobalContext.AGVMQTTIsConnect)
  517. picAgvMqtt.Image = imageListState.Images[1];
  518. else
  519. {
  520. picAgvMqtt.Image = imageListState.Images[0];
  521. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  522. }
  523. }
  524. }
  525. catch (Exception ex)
  526. {
  527. string str = ex.StackTrace;
  528. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  529. }
  530. Thread.Sleep(IntervalMonitorMES);
  531. }
  532. }
  533. #endregion 监控MES连接状态
  534. #region 采集设备状态、运行数据、报警数据
  535. /// <summary>
  536. /// 请求设备状态 5000
  537. /// </summary>
  538. /// <param name="no">1</param>
  539. /// <param name="stationNameStr"></param>
  540. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  541. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  542. {
  543. try
  544. {
  545. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  546. {
  547. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  548. return result;
  549. }
  550. else
  551. {
  552. return 0;
  553. }
  554. }
  555. catch (Exception ex)
  556. {
  557. string str = ex.StackTrace;
  558. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  559. return 0;
  560. }
  561. }
  562. /// <summary>
  563. /// 检查是否可采集点检数据 - 不取新值
  564. /// 5000不为1时可点检
  565. /// </summary>
  566. /// <returns></returns>
  567. public bool CheckCanSpotcheck1(int deviceState)
  568. {
  569. //return true;
  570. //D5000 = 1,代表设备控制状态处于运行状态
  571. //D5000 = 2, 代表设备控制状态处于故障状态
  572. //D5000 = 3,代表设备控制状态处于缺料状态
  573. //D5000 = 4, 代表设备控制状态处于待机状态
  574. //D5000 = 5,代表设备控制状态处于维修状态
  575. return deviceState != 1;
  576. }
  577. /// <summary>
  578. /// 检查是否可采集产品数据 - 不取新值
  579. /// </summary>
  580. /// <returns></returns>
  581. public bool CheckCanCollData(int deviceState)
  582. {
  583. return deviceState == 0; // 点检时该值不为0
  584. }
  585. /// <summary>
  586. /// 获取设备报警数据与获取设备运行信息
  587. /// </summary>
  588. private async void ReadAlarmAllPLC()
  589. {
  590. // [S1] Tray盘上料装备(板测)
  591. // [S2] FCT(板测)
  592. // [S3] 值板机
  593. // [S4] 取放桁架
  594. // [S5] Tray盘下料装备
  595. /// 上位机心跳
  596. /// 获取设备报警数据与状态信息
  597. string stationNameStr = "获取设备报警数据与状态信息";
  598. while (IsRun)
  599. {
  600. try
  601. {
  602. if (!GlobalContext._IsCon_plc1Alarm)
  603. {
  604. UpdatePLCMonitor(1, -2, 0);
  605. continue;
  606. }
  607. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  608. {
  609. DateTime dtNow = DateTime.Now;
  610. #region 获取设备运行信息
  611. try
  612. {
  613. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  614. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  615. lineWorkingData1.LineName = GlobalContext.LineCode;
  616. //
  617. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  618. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  619. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  620. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  621. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  622. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  623. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  624. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  625. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  626. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  627. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  628. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  629. lineWorkingData1.CreateTime = DateTime.Now;
  630. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  631. // UI展示-展示到设备状态页
  632. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  633. {
  634. // 查询数据库最新一条数据,确定是不是更新
  635. string qSql = @"SELECT top(1) [GUID]
  636. ,[LineName]
  637. ,[BootTimeLong]
  638. ,[NormalTimeLong]
  639. ,[StandbyTimeLong]
  640. ,[FaultTimeLong]
  641. ,[MaterialShortageTimeLong]
  642. ,[MaintenanceTimeLong]
  643. ,[FaultNumber]
  644. ,[OutputNumber]
  645. ,[QualifiedNumber]
  646. ,[QualifiedRate]
  647. ,[DesignRhythm]
  648. ,[RealityRhythm]
  649. ,[CreateTime]
  650. FROM [LineWorkingData]
  651. where [CreateTime] > '{0}'
  652. and [LineName]='{1}'
  653. order by [CreateTime] desc
  654. ";
  655. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  656. var ds = SQLHelper_New.Query(qSql, null);
  657. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  658. {
  659. var dataDBlast = new LineWorkingData_ThisTime();
  660. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  661. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  662. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  663. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  664. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  665. {
  666. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  667. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  668. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  669. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  670. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  671. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  672. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  673. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  674. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  675. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  676. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  677. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  678. string usql = dataDBlast.ToStringUpdate();
  679. SQLHelper_New.ExecuteSQL(usql, null);
  680. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  681. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  682. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  683. }
  684. }
  685. else
  686. {
  687. // 插入
  688. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  689. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  690. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  691. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  692. }
  693. }
  694. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  695. {
  696. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  697. //// 本次开机设备运行情况
  698. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  699. //Task.Run(() =>
  700. //{
  701. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  702. // {
  703. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  704. // }
  705. //});
  706. // 本日设备运行情况
  707. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  708. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  709. {
  710. // 更新
  711. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  712. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  713. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  714. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  715. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  716. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  717. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  718. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  719. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  720. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  721. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  722. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  723. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  724. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  725. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  726. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  727. }
  728. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  729. {
  730. // 插入
  731. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  732. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  733. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  734. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  735. }
  736. await Task.Run(() =>
  737. {
  738. try
  739. {
  740. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  741. {
  742. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  743. }
  744. }
  745. catch { }
  746. });
  747. }
  748. }
  749. catch (Exception ex)
  750. {
  751. string str = ex.StackTrace;
  752. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  753. }
  754. #endregion 获取设备运行信息
  755. #region 报警数据
  756. try
  757. {
  758. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  759. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  760. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  761. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  762. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  763. {
  764. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  765. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  766. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  767. {
  768. isNeedUpdUI = true; // 需要更新历史报警UI信息
  769. // 记录
  770. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  771. switch (dicAlarms_Cur_PLC1[i].是否报警)
  772. {
  773. case true: // 报警
  774. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  775. {
  776. GUID = Guid.NewGuid().ToString(),
  777. LineName = GlobalContext.LineCode, // 线体
  778. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  779. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  780. StartTime = dtNow // 开始时间
  781. };
  782. // 传输到页面
  783. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  784. {
  785. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  786. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  787. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  788. 开始时间 = dtNow
  789. });
  790. // 新增到数据库
  791. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  792. SaveAlarmDataByDB(stationNameStr, data1, false);
  793. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  794. break;
  795. case false: // 消除报警
  796. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  797. {
  798. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  799. {
  800. GUID = Guid.NewGuid().ToString(),
  801. LineName = GlobalContext.LineCode, // 线体
  802. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  803. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  804. StartTime = dtNow, // 开始时间
  805. EndTime = dtNow, // 开始时间
  806. PersistTime = 1, // 耗时1s
  807. };
  808. // 新增
  809. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  810. SaveAlarmDataByDB(stationNameStr, data2, false);
  811. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  812. }
  813. else
  814. {
  815. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  816. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  817. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  818. // 修改
  819. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  820. SaveAlarmDataByDB(stationNameStr, data3, true);
  821. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  822. }
  823. break;
  824. default:
  825. break;
  826. }
  827. }
  828. }
  829. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  830. // 有新报警则更新
  831. if (isNeedUpdUI)
  832. {
  833. // UI展示 - 展示到设备状态页
  834. await Task.Run(() =>
  835. {
  836. try
  837. {
  838. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  839. {
  840. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  841. if (Form_Main.formDevAlarm.Visible)
  842. {
  843. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  844. }
  845. }
  846. }
  847. catch { }
  848. });
  849. }
  850. }
  851. catch (Exception ex)
  852. {
  853. string str = ex.StackTrace;
  854. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  855. }
  856. #endregion 报警数据
  857. UpdatePLCMonitor(1, -2, 1);
  858. }
  859. else
  860. {
  861. UpdatePLCMonitor(1, -2, 0);
  862. }
  863. }
  864. catch (Exception ex)
  865. {
  866. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  867. }
  868. Thread.Sleep(IntervalAlarm);
  869. }
  870. }
  871. #endregion 轮询PLC
  872. #region 下发订单信息
  873. ///// <summary>
  874. ///// 壳体上料(下发工单)的交互逻辑
  875. ///// </summary>
  876. ///// <param name="no"></param>
  877. ///// <exception cref="NotImplementedException"></exception>
  878. //private void ReadStation_DownOrderInfo(int plcNo)
  879. //{
  880. // // [S1] Tray盘上料装备(板测)
  881. // // [S2] FCT(板测)
  882. // // [S3] 值板机
  883. // // [S4] 取放桁架
  884. // // [S5] Tray盘下料装备
  885. // /// 上位机心跳
  886. // /// 获取设备报警数据与状态信息
  887. // string stationNameStr = "[S0]壳体上料";
  888. // while (IsRun)
  889. // {
  890. // try
  891. // {
  892. // if (!GlobalContext._IsCon_Funs1)
  893. // {
  894. // UpdatePLCMonitor(plcNo, 0);
  895. // continue;
  896. // }
  897. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  898. // {
  899. // #region 壳体上料(下发工单)
  900. // try
  901. // {
  902. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  903. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  904. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  905. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  906. // // 重置数据和信号
  907. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  908. // {
  909. // // 清空写给PLC的数据
  910. // int[] i497 = new int[1] { 0 };
  911. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  912. // // MES_Flag重置为0
  913. // int[] i500 = new int[1] { 0 };
  914. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  915. // }
  916. // }
  917. // catch (Exception ex)
  918. // {
  919. // string str = ex.StackTrace;
  920. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  921. // }
  922. // #endregion 壳体上料(下发工单)
  923. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  924. // }
  925. // else
  926. // {
  927. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  928. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  929. //
  930. // Funs[plcNo].Connect();
  931. // }
  932. // }
  933. // catch (Exception ex)
  934. // {
  935. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  936. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  937. //
  938. // Funs[plcNo].ReConnect();
  939. // }
  940. // Thread.Sleep(IntervalReadPLC);
  941. // }
  942. //}
  943. ///// <summary>
  944. ///// 下发订单信息到PLC
  945. ///// </summary>
  946. ///// <param name="no">PLC编号</param>
  947. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  948. //{
  949. // try
  950. // {
  951. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  952. // {
  953. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  954. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  955. // }
  956. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  957. // }
  958. // catch (Exception ex)
  959. // {
  960. // string str = ex.StackTrace;
  961. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  962. // }
  963. //}
  964. /// <summary>
  965. /// 下发清料信号
  966. /// </summary>
  967. /// <param name="no">PLC编号</param>
  968. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  969. {
  970. try
  971. {
  972. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  973. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  974. return true;
  975. }
  976. catch (Exception ex)
  977. {
  978. string str = ex.StackTrace;
  979. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  980. return false;
  981. }
  982. }
  983. #endregion 下发订单信息
  984. #region Xiaomi 贲流
  985. #region 公共方法
  986. private static bool ProgressState = false;
  987. private static readonly object lockObj = new object(); // 锁对象
  988. private static bool isCollectingFlagLeft;
  989. private static bool isCollectingFlagRight;
  990. private bool OpenDailogFalg = true;//是否开启扫码弹窗标识
  991. /// <summary>
  992. /// float[]转为string
  993. /// </summary>
  994. public string FloatArrayToString(float[] nScrewResults)
  995. {
  996. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  997. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  998. }
  999. /// <summary>
  1000. /// short[]转为string
  1001. /// </summary>
  1002. public string ShortArrayToString(short[] nScrewResults)
  1003. {
  1004. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1005. return string.Join(",", nScrewResults);
  1006. }
  1007. /// <summary>
  1008. /// 写入PLC重复三次
  1009. /// </summary>
  1010. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  1011. {
  1012. int i = 0;
  1013. int nRet = 0;
  1014. string strRet = "";
  1015. try
  1016. {
  1017. while (i < 3) // 最多上传三次
  1018. {
  1019. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1020. if (nRet == 0) //成功
  1021. {
  1022. break;
  1023. }
  1024. else
  1025. {
  1026. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1027. i++;
  1028. }
  1029. }
  1030. return (nRet, strRet);
  1031. }
  1032. catch (Exception ex)
  1033. {
  1034. return (1, ex.Message);
  1035. }
  1036. }
  1037. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  1038. {
  1039. try
  1040. {
  1041. // 获取当前日期
  1042. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1043. // 构建保存路径
  1044. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1045. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  1046. // 确保目录存在
  1047. Directory.CreateDirectory(savePath);
  1048. // 文件名
  1049. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1050. string filePath = Path.Combine(savePath, fileName);
  1051. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1052. int count = Math.Min(14, fScrewTimes.Length);
  1053. using (StreamWriter sw = new StreamWriter(filePath))
  1054. {
  1055. for (int i = 0; i < count; i++)
  1056. {
  1057. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1058. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1059. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1060. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1061. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1062. }
  1063. }
  1064. return (0, "");
  1065. }
  1066. catch (Exception ex)
  1067. {
  1068. return (1, ex.Message);
  1069. }
  1070. }
  1071. public Dictionary<string, string> GetLastLineCompensation(string path,string direction,string sn)
  1072. {
  1073. // 创建字典存储补偿点及其对应的值
  1074. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1075. try
  1076. {
  1077. //string path = GlobalContext.MESLaserRPath;
  1078. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1079. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1080. string filename = $"Laser-{currentDate}-W0.txt";
  1081. // 拼接完整路径
  1082. string fullPath = Path.Combine(path, filename);
  1083. string lastNonEmptyLine = "";
  1084. // 判断文件是否存在
  1085. if (File.Exists(fullPath))
  1086. {
  1087. //读取文件内容
  1088. string[] lines = File.ReadAllLines(fullPath);
  1089. // 获取最后一行数据(忽略标题行)
  1090. if (lines.Length > 1)
  1091. {
  1092. string lastLine = "";
  1093. for (int i = lines.Length - 1; i > 0; i--)
  1094. {
  1095. if (!string.IsNullOrEmpty(lines[i]))
  1096. {
  1097. lastLine = lines[i];
  1098. break;
  1099. }
  1100. }
  1101. // 将最后一行按逗号分隔
  1102. string[] values = lastLine.Split(',');
  1103. values[1] = sn;
  1104. string key = "三点激光_"+ direction; // 构造键名
  1105. string value = string.Join(",", values); // 获取值并去除多余空格
  1106. compensationDict[key] = value;
  1107. //// 提取“1点补偿”到“6点补偿”的值
  1108. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1109. //{
  1110. // string key = $"{i - 1}点补偿"; // 构造键名
  1111. // string value = values[i].Trim(); // 获取值并去除多余空格
  1112. // compensationDict[key] = value;
  1113. //}
  1114. }
  1115. }
  1116. else
  1117. {
  1118. Console.WriteLine($"文件不存在: {fullPath}");
  1119. }
  1120. }
  1121. catch (Exception ex)
  1122. {
  1123. // 捕获异常并输出错误信息
  1124. Console.WriteLine($"发生错误: {ex.Message}");
  1125. }
  1126. return compensationDict;
  1127. }
  1128. /// <summary>
  1129. /// 调用进站接口并保存进站数据
  1130. /// </summary>
  1131. /// <param name="stationNameStr">工站信息</param>
  1132. /// <param name="workorder_code">工单号</param>
  1133. /// <param name="mtltmrk">型号(物料号)</param>
  1134. /// <param name="sn">产品SN</param>
  1135. /// <param name="items">进站数据</param>
  1136. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1137. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1138. {
  1139. int result = 0;
  1140. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1141. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1142. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1143. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1144. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1145. inRequest_Body.unitSn = sn; // 产品SN
  1146. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1147. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1148. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1149. StationIn stationIn = new StationIn()
  1150. {
  1151. Workorder_code = workorder_code, // 车间订单号
  1152. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1153. Sn = sn, // SN
  1154. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1155. Parameter_values = items, // 进站数据
  1156. Write_user = inRequest_Body.userId, // 员工Id
  1157. Test_time = inRequest_Body.clientTime // 进站时间
  1158. };
  1159. // 本地数据
  1160. string sql = stationIn.ToStringInsert(0);
  1161. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1162. result = ret == "成功" ? 1 : 6;
  1163. //await Task.Delay(200);
  1164. // 上传MES
  1165. if (GlobalContext.IsSendStationIn)
  1166. {
  1167. try
  1168. {
  1169. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1170. string resultJson = "";
  1171. string mesRet = string.Empty;
  1172. int i = 0;
  1173. while (i < 2) // 1009会多次尝试上传
  1174. {
  1175. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1176. resultJson = JsonConvert.SerializeObject(response);
  1177. if (response != null && response.header.code == "200")
  1178. break;
  1179. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1180. i++;
  1181. i++;
  1182. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1183. // 记录失败原因
  1184. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!请求参数:{json_Body},接口报错信息:" + mesRet);
  1185. }
  1186. if (response?.header?.code == "200")
  1187. {
  1188. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1189. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1190. result = ret_Upd == "成功" ? 1 : 6;
  1191. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,请求参数:{json_Body},返回参数:{resultJson}");
  1192. }
  1193. else
  1194. {
  1195. result = 5;
  1196. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!请求参数:{json_Body},接口报错信息:" + mesRet);
  1197. }
  1198. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1199. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1200. }
  1201. catch (Exception ex)
  1202. {
  1203. result = 6;
  1204. string str = ex.StackTrace;
  1205. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1206. }
  1207. }
  1208. return result;
  1209. }
  1210. /// <summary>
  1211. /// 选择如何记录出站数据
  1212. /// </summary>
  1213. /// <param name="items">出站数据</param>
  1214. /// <param name="equipmentCode">设备编号</param>
  1215. /// <param name="processItem">测试项目</param>
  1216. /// <param name="workorder_code">车间订单号</param>
  1217. /// <param name="batch_num">批次号</param>
  1218. /// <param name="mtltmrk">型号</param>
  1219. /// <param name="proDate">日期</param>
  1220. /// <param name="supplierCode">供应商代码</param>
  1221. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1222. /// <returns>上传成功时返回1;失败返回0</returns>
  1223. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1224. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1225. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode,string jsonParm, string direction="")
  1226. {
  1227. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1228. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm, direction);
  1229. }
  1230. /// <summary>
  1231. /// 添加出站数据(提交到MES+本地保存到数据库)
  1232. /// </summary>
  1233. /// <param name="items">出站数据</param>
  1234. /// <param name="equipmentCode">设备编号</param>
  1235. /// <param name="processItem">测试项目</param>
  1236. /// <param name="workorder_code">车间订单号</param>
  1237. /// <param name="batch_num">批次号</param>
  1238. /// <param name="mtltmrk">型号</param>
  1239. /// <param name="proDate">日期</param>
  1240. /// <param name="supplierCode">供应商代码</param>
  1241. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1242. /// <returns>上传成功时返回1;失败返回0</returns>
  1243. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1244. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1245. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode,string jsonParm,string direction="")
  1246. {
  1247. int upload = 0;
  1248. int result = 0;
  1249. ProcessData processData = new ProcessData()
  1250. {
  1251. Equipment_code = equipmentCode,
  1252. Workorder_code = workorder_code,
  1253. Batch_number = batch_num,
  1254. Sn = sn, // SN
  1255. Testitem = processItem,
  1256. Parameter_values = items,
  1257. Write_user = GlobalContext.CurrentUser,
  1258. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1259. };
  1260. // 本地数据
  1261. string sql = processData.ToStringInsert(upload);
  1262. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1263. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1264. // 上传MES
  1265. if (GlobalContext.IsSendProcessData)
  1266. {
  1267. try
  1268. {
  1269. string id = processData.ID.Copy();
  1270. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1271. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1272. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1273. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1274. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1275. outRequest_Body.unitSn = sn; // 产品SN
  1276. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1277. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1278. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1279. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1280. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1281. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1282. if (!string.IsNullOrEmpty(partBarcode))
  1283. {
  1284. outRequest_Body.unitData.keyMaterial.Add(
  1285. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1286. {
  1287. bindSort = 1,
  1288. materialSn = partBarcode
  1289. }); // 设备数据 - 部件码
  1290. }
  1291. //OP30站读txt数据
  1292. if (stationNameStr.Contains("CPAPHD"))
  1293. {
  1294. string path = "";
  1295. if (direction == "Left")
  1296. path = GlobalContext.MESLaserLPath;
  1297. else
  1298. path= GlobalContext.MESLaserRPath;
  1299. //字典存储数据
  1300. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction,sn);
  1301. foreach (var kvp in compensationDict)
  1302. {
  1303. outRequest_Body.unitData.processData.Add(
  1304. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1305. {
  1306. dataName = kvp.Key.ToString(),
  1307. dataValue = kvp.Value.ToString()
  1308. });
  1309. }
  1310. }
  1311. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1312. if (GlobalContext.IsSendProcessData)
  1313. {
  1314. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1315. string mesRet = string.Empty;
  1316. int i = 0;
  1317. while (i < 2) // 1009会多次尝试上传
  1318. {
  1319. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1320. if (response != null && response.header.code == "200")
  1321. {
  1322. OnMessage(LogType.Error, "上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" + JsonConvert.SerializeObject(response.body));
  1323. break;
  1324. }
  1325. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1326. i++;
  1327. i++;
  1328. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1329. // 记录失败原因
  1330. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1331. }
  1332. if (response?.header?.code == "200")
  1333. {
  1334. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1335. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1336. result = 1;
  1337. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1338. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1339. }
  1340. else
  1341. {
  1342. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1343. }
  1344. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1345. JsonConvert.SerializeObject(response), id);
  1346. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1347. }
  1348. }
  1349. catch (Exception ex)
  1350. {
  1351. string str = ex.StackTrace;
  1352. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1353. }
  1354. }
  1355. return result;
  1356. }
  1357. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1358. //{
  1359. // Stopwatch stopwatch = new Stopwatch();
  1360. // stopwatch.Start();
  1361. // try
  1362. // {
  1363. // // 初始化 AtlasScrew 实例
  1364. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1365. // atlasScrew1.Initial();
  1366. // // 存储结果的列表
  1367. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1368. // // 存储角度和扭力的字符串列表
  1369. // List<string> angleStrs = new List<string>();
  1370. // List<string> torqueStrs = new List<string>();
  1371. // // 上一次获取的数据
  1372. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1373. // while (isExitAtlasLeft) // 检查是否收集数据
  1374. // {
  1375. // // 获取当前数据
  1376. // var currentResult = atlasScrew1.GetResults();
  1377. // // 判断是否为新数据
  1378. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1379. // {
  1380. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1381. // // 更新角度和扭力的字符串列表
  1382. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1383. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1384. // // 计算角度、扭力、起始扭力和最大扭力
  1385. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1386. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1387. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1388. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1389. // // 将新数据添加到结果列表
  1390. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1391. // // 更新上一次获取的数据
  1392. // lastResult = currentResult;
  1393. // }
  1394. // // 等待一段时间后再次检查
  1395. // Thread.Sleep(20); // 轮询间隔时间
  1396. // // 如果触发了出站,则退出循环
  1397. // if (!isExitAtlasLeft)
  1398. // {
  1399. // break;
  1400. // }
  1401. // }
  1402. // // 生成文件名
  1403. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1404. // // 写入数据到文件
  1405. // using (StreamWriter writer = new StreamWriter(fileName))
  1406. // {
  1407. // // 写入标题行
  1408. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1409. // // 写入每一行数据
  1410. // foreach (var result in results)
  1411. // {
  1412. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1413. // }
  1414. // }
  1415. // stopwatch.Stop();
  1416. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1417. // }
  1418. // catch (Exception ex)
  1419. // {
  1420. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1421. // }
  1422. // finally
  1423. // {
  1424. // // 重置标志变量
  1425. // isExitAtlasLeft = false;
  1426. // }
  1427. //}
  1428. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1429. //{
  1430. // Stopwatch stopwatch = new Stopwatch();
  1431. // stopwatch.Start();
  1432. // try
  1433. // {
  1434. // // 初始化 AtlasScrew 实例
  1435. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1436. // atlasScrew2.Initial();
  1437. // // 存储结果的列表
  1438. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1439. // // 上一次获取的数据
  1440. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1441. // while (isExitAtlasRight) // 检查是否收集数据
  1442. // {
  1443. // // 获取当前数据
  1444. // var currentResult = atlasScrew2.GetResults();
  1445. // // 判断是否为新数据
  1446. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1447. // {
  1448. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1449. // // 将新数据写入PLC
  1450. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1451. // // 将新数据添加到结果列表
  1452. // results.Add(currentResult);
  1453. // // 更新上一次获取的数据
  1454. // lastResult = currentResult;
  1455. // }
  1456. // // 等待一段时间后再次检查
  1457. // Thread.Sleep(20); // 轮询间隔时间
  1458. // // 如果触发了出站,则退出循环
  1459. // if (!isExitAtlasRight)
  1460. // {
  1461. // break;
  1462. // }
  1463. // }
  1464. // // 将所有数据写入文件
  1465. // //WriteDataToFile(sn, direction, results);
  1466. // stopwatch.Stop();
  1467. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1468. // }
  1469. // catch (Exception ex)
  1470. // {
  1471. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1472. // }
  1473. // finally
  1474. // {
  1475. // // 重置标志变量
  1476. // isExitAtlasRight = false;
  1477. // }
  1478. //}
  1479. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1480. {
  1481. Stopwatch stopwatch = new Stopwatch();
  1482. stopwatch.Start();
  1483. int nRet = 0;
  1484. string strRet = "";
  1485. try
  1486. {
  1487. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1488. while (isCollectingFlagLeft)
  1489. {
  1490. // 从缓存中获取所有未处理的数据
  1491. var cachedData = atlasScrew.GetCachedDataLeft();
  1492. foreach (var currentResult in cachedData)
  1493. {
  1494. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1495. {
  1496. continue; // 跳过无效数据
  1497. }
  1498. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1499. // 写入PLC
  1500. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1501. {
  1502. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1503. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1504. };
  1505. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1506. if (nRet != 0)
  1507. {
  1508. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1509. }
  1510. else
  1511. {
  1512. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1513. }
  1514. // 构建保存路径
  1515. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1516. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1517. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1518. Directory.CreateDirectory(savePath); // 确保目录存在
  1519. // 构建文件名(以 SN + 序号命名)
  1520. string fileName = $"{sn}_{fileCounter}.txt";
  1521. string filePath = Path.Combine(savePath, fileName);
  1522. // 写入文件
  1523. using (StreamWriter writer = new StreamWriter(filePath))
  1524. {
  1525. writer.WriteLine("精度, 扭力");
  1526. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1527. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1528. {
  1529. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1530. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1531. writer.WriteLine($"{precision}, {torque}");
  1532. }
  1533. }
  1534. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1535. // 增加文件计数器
  1536. fileCounter++;
  1537. }
  1538. // 如果没有更多数据,则短暂休眠以节省资源
  1539. if (!cachedData.Any())
  1540. {
  1541. Thread.Sleep(10); // 根据需要调整休眠时间
  1542. }
  1543. // 如果触发了出站,则退出循环
  1544. if (!isCollectingFlagLeft)
  1545. {
  1546. break;
  1547. }
  1548. }
  1549. stopwatch.Stop();
  1550. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1551. }
  1552. catch (Exception ex)
  1553. {
  1554. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1555. }
  1556. finally
  1557. {
  1558. isCollectingFlagLeft = false;
  1559. }
  1560. }
  1561. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1562. {
  1563. Stopwatch stopwatch = new Stopwatch();
  1564. stopwatch.Start();
  1565. int nRet = 0;
  1566. string strRet = "";
  1567. try
  1568. {
  1569. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1570. while (isCollectingFlagRight)
  1571. {
  1572. // 从缓存中获取所有未处理的数据
  1573. var cachedData = atlasScrew.GetCachedDataLeft();
  1574. foreach (var currentResult in cachedData)
  1575. {
  1576. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1577. {
  1578. continue; // 跳过无效数据
  1579. }
  1580. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1581. // 写入PLC
  1582. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1583. {
  1584. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1585. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1586. };
  1587. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1588. if (nRet != 0)
  1589. {
  1590. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1591. }
  1592. else
  1593. {
  1594. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1595. }
  1596. // 构建保存路径
  1597. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1598. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1599. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1600. Directory.CreateDirectory(savePath); // 确保目录存在
  1601. // 构建文件名(以 SN + 序号命名)
  1602. string fileName = $"{sn}_{fileCounter}.txt";
  1603. string filePath = Path.Combine(savePath, fileName);
  1604. // 写入文件
  1605. using (StreamWriter writer = new StreamWriter(filePath))
  1606. {
  1607. writer.WriteLine("精度, 扭力");
  1608. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1609. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1610. {
  1611. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1612. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1613. writer.WriteLine($"{precision}, {torque}");
  1614. }
  1615. }
  1616. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1617. // 增加文件计数器
  1618. fileCounter++;
  1619. }
  1620. // 如果没有更多数据,则短暂休眠以节省资源
  1621. if (!cachedData.Any())
  1622. {
  1623. Thread.Sleep(10); // 根据需要调整休眠时间
  1624. }
  1625. // 如果触发了出站,则退出循环
  1626. if (!isCollectingFlagRight)
  1627. {
  1628. break;
  1629. }
  1630. }
  1631. stopwatch.Stop();
  1632. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1633. }
  1634. catch (Exception ex)
  1635. {
  1636. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1637. }
  1638. finally
  1639. {
  1640. isCollectingFlagRight = false;
  1641. }
  1642. }
  1643. #endregion
  1644. #region S1
  1645. /// <summary>
  1646. /// [S1] 壳体清洁上料装备
  1647. /// </summary>
  1648. /// <param name="plcNo">PLC编号</param>
  1649. private void ReadStation_S1(int plcNo)
  1650. {
  1651. string stationCode = "[OP10]";
  1652. string stationName = "壳体清洁上料";
  1653. string stationNameStr = stationCode + stationName;
  1654. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1655. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1656. string tagAgvCommName = "agvCommFrmPC";
  1657. string tagBarsetName = "BarcodeSet";
  1658. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1659. (int, string) result;
  1660. while (true)
  1661. {
  1662. try
  1663. {
  1664. if (!GlobalContext._IsCon_Funs1)
  1665. {
  1666. UpdatePLCMonitor(1, plcNo, 0);
  1667. continue;
  1668. }
  1669. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1670. {
  1671. Stopwatch stopwatch1 = new Stopwatch();
  1672. Stopwatch stopwatch2 = new Stopwatch();
  1673. stopwatch1.Start();
  1674. stopwatch2.Start();
  1675. #region 一次性读取所有数据
  1676. // 一次性读取所有数据
  1677. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1678. if (result.Item1 != 0)
  1679. {
  1680. //richTextBox1.AppendText("\n" + strRet);
  1681. }
  1682. else
  1683. {
  1684. //richTextBox1.AppendText("\n" + "读取成功");
  1685. }
  1686. #endregion 一次性读取所有数据
  1687. stopwatch2.Stop();
  1688. #region 进站
  1689. try
  1690. {
  1691. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1692. {
  1693. lock (lockObj)
  1694. {
  1695. if (!ProgressState)
  1696. {
  1697. ProgressState = true;
  1698. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1699. }
  1700. }
  1701. }
  1702. }
  1703. catch (Exception ex)
  1704. {
  1705. ProgressState = false;
  1706. string str = ex.StackTrace;
  1707. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1708. }
  1709. #endregion 进站
  1710. #region 出站
  1711. try
  1712. {
  1713. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1714. {
  1715. lock (lockObj)
  1716. {
  1717. if (!ProgressState)
  1718. {
  1719. ProgressState = true;
  1720. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1721. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1722. }
  1723. }
  1724. }
  1725. }
  1726. catch (Exception ex)
  1727. {
  1728. ProgressState = false;
  1729. string str = ex.StackTrace;
  1730. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1731. }
  1732. #endregion 出站
  1733. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1734. stopwatch1.Stop();
  1735. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1736. }
  1737. else
  1738. {
  1739. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1740. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1741. FunsEip[plcNo].Connect(); // 重连
  1742. }
  1743. }
  1744. catch (Exception ex)
  1745. {
  1746. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1747. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1748. }
  1749. Thread.Sleep(IntervalReadPLC);
  1750. }
  1751. }
  1752. /// <summary>
  1753. /// [S1] 壳体清洁上料 - 进站
  1754. /// </summary>
  1755. /// <param name="plcNo">PLC编号</param>
  1756. /// <param name="stationNameStr">工站全称</param>
  1757. /// <param name="stPLC_MesData"></param>
  1758. /// <param name="tagMesCommName"></param>
  1759. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1760. {
  1761. Stopwatch stopwatch1 = new Stopwatch();
  1762. Stopwatch stopwatch2 = new Stopwatch();
  1763. try
  1764. {
  1765. stopwatch1.Start();
  1766. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1767. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1768. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1769. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1770. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1771. if (string.IsNullOrEmpty(sn))
  1772. {
  1773. ProgressState = false;
  1774. return;
  1775. }
  1776. //正式生产就用PLC中取的
  1777. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1778. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1779. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1780. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1781. //绑定载具和产品
  1782. ResponseMessage message = new ResponseMessage();
  1783. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1784. if (message.result == false)
  1785. {
  1786. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1787. }
  1788. // 产品SN进站
  1789. List<TestItem> item = new List<TestItem>();
  1790. stopwatch2.Start();
  1791. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1792. stopwatch2.Stop();
  1793. //指令执行结果 1:OK 110:失败
  1794. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1795. //进站结果写入PLC
  1796. CommandFromPLC resultToPlC = new CommandFromPLC();
  1797. resultToPlC.cmd = 0;
  1798. resultToPlC.cmdParam = 0;
  1799. resultToPlC.cmdResult = mesResultFrmWeb;
  1800. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1801. }
  1802. catch (Exception ex)
  1803. {
  1804. string str = ex.StackTrace;
  1805. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1806. CommandFromPLC resultToPlC = new CommandFromPLC();
  1807. resultToPlC.cmd = 0;
  1808. resultToPlC.cmdParam = 0; //指令参数
  1809. resultToPlC.cmdResult = 110;
  1810. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1811. }
  1812. stopwatch1.Stop();
  1813. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1814. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1815. ProgressState = false;
  1816. }
  1817. /// <summary>
  1818. /// [S1] 壳体清洁上料 - 出站接口
  1819. /// </summary>
  1820. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1821. {
  1822. Stopwatch stopwatch1 = new Stopwatch();
  1823. Stopwatch stopwatch2 = new Stopwatch();
  1824. try
  1825. {
  1826. stopwatch1.Start();
  1827. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1828. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1829. string processItem = stationName; // 项目
  1830. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1831. string supplierCode = ""; // 供应商代码
  1832. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1833. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1834. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1835. string sn = string.Empty;
  1836. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1837. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1838. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1839. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1840. a1Result = 1;
  1841. bool pass = a1Result == 1;
  1842. //根据载具码获取产品码
  1843. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1844. if (string.IsNullOrEmpty(strProductBarcode))
  1845. {
  1846. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1847. }
  1848. sn = strProductBarcode;
  1849. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1850. List<TestItem> items = new List<TestItem>();
  1851. items.Add(new TestItem()
  1852. {
  1853. Parameter_name = "载具码",
  1854. Parameter_value = CarrierBarcode,
  1855. Parameter_unit = ""
  1856. });
  1857. items.Add(new TestItem()
  1858. {
  1859. Parameter_name = "产品码",
  1860. Parameter_value = sn,
  1861. Parameter_unit = ""
  1862. });
  1863. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  1864. //出站接口
  1865. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1866. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  1867. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1868. stopwatch2.Start();
  1869. //进站结果写入PLC
  1870. CommandFromPLC resultToPlC = new CommandFromPLC();
  1871. resultToPlC.cmd = 0;
  1872. resultToPlC.cmdParam = 0; //指令参数
  1873. resultToPlC.cmdResult = mesResultFrmWeb;
  1874. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1875. stopwatch2.Stop();
  1876. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1877. //保存PLC返回MES数据到本地
  1878. ResponseMessage message = new ResponseMessage();
  1879. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1880. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1881. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1882. stPLC_MesData.mesData.nRemainCount);
  1883. if (message.result == false)
  1884. {
  1885. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1886. }
  1887. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1888. }
  1889. catch (Exception ex)
  1890. {
  1891. stopwatch2.Start();
  1892. CommandFromPLC resultToPlC = new CommandFromPLC();
  1893. resultToPlC.cmd = 0;
  1894. resultToPlC.cmdParam = 0; //指令参数
  1895. resultToPlC.cmdResult = 110;
  1896. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1897. stopwatch2.Stop();
  1898. string str = ex.StackTrace;
  1899. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1900. }
  1901. stopwatch1.Stop();
  1902. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1903. ProgressState = false;
  1904. }
  1905. #endregion
  1906. #region S2
  1907. /// <summary>
  1908. /// [S2] 上盖板上料装备
  1909. /// </summary>
  1910. /// <param name="plcNo">PLC编号</param>
  1911. private void ReadStation_S2(int plcNo)
  1912. {
  1913. string stationCode = "[OP20]";
  1914. string stationName = "上盖板上料装备";
  1915. string stationNameStr = stationCode + stationName;
  1916. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1917. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1918. string tagAgvCommName = "agvCommFrmPC";
  1919. string tagBarsetName = "BarcodeSet";
  1920. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1921. (int, string) result;
  1922. while (true)
  1923. {
  1924. try
  1925. {
  1926. if (!GlobalContext._IsCon_Funs2)
  1927. {
  1928. UpdatePLCMonitor(1, plcNo, 0);
  1929. continue;
  1930. }
  1931. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1932. {
  1933. Stopwatch stopwatch1 = new Stopwatch();
  1934. Stopwatch stopwatch2 = new Stopwatch();
  1935. stopwatch1.Start();
  1936. stopwatch2.Start();
  1937. #region 一次性读取所有数据
  1938. // 一次性读取所有数据
  1939. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1940. if (result.Item1 != 0)
  1941. {
  1942. //richTextBox1.AppendText("\n" + strRet);
  1943. }
  1944. else
  1945. {
  1946. //richTextBox1.AppendText("\n" + "读取成功");
  1947. }
  1948. #endregion 一次性读取所有数据
  1949. stopwatch2.Stop();
  1950. #region 进站
  1951. try
  1952. {
  1953. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1954. {
  1955. lock (lockObj)
  1956. {
  1957. if (!ProgressState)
  1958. {
  1959. ProgressState = true;
  1960. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1961. }
  1962. }
  1963. }
  1964. }
  1965. catch (Exception ex)
  1966. {
  1967. ProgressState = false;
  1968. string str = ex.StackTrace;
  1969. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1970. }
  1971. #endregion 进站
  1972. #region 出站
  1973. try
  1974. {
  1975. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1976. {
  1977. lock (lockObj)
  1978. {
  1979. if (!ProgressState)
  1980. {
  1981. ProgressState = true;
  1982. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1983. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1984. }
  1985. }
  1986. }
  1987. }
  1988. catch (Exception ex)
  1989. {
  1990. ProgressState = false;
  1991. string str = ex.StackTrace;
  1992. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1993. }
  1994. #endregion 出站
  1995. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1996. stopwatch1.Stop();
  1997. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1998. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1999. }
  2000. else
  2001. {
  2002. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2003. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2004. FunsEip[plcNo].Connect();
  2005. }
  2006. }
  2007. catch (Exception ex)
  2008. {
  2009. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2010. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2011. //Funs[plcNo].ReConnect();
  2012. }
  2013. Thread.Sleep(IntervalReadPLC);
  2014. }
  2015. }
  2016. /// <summary>
  2017. /// [S2] 上盖板上料装备
  2018. /// </summary>
  2019. /// <param name="plcNo">PLC编号</param>
  2020. /// <param name="stationNameStr">工站全称</param>
  2021. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2022. {
  2023. Stopwatch stopwatch1 = new Stopwatch();
  2024. Stopwatch stopwatch2 = new Stopwatch();
  2025. try
  2026. {
  2027. stopwatch1.Start();
  2028. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2029. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  2030. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2031. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  2032. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  2033. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2034. //根据载具码获取产品码
  2035. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2036. if (string.IsNullOrEmpty(strProductBarcode))
  2037. {
  2038. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2039. }
  2040. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2041. //if (sn != strProductBarcode)
  2042. //{
  2043. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2044. //}
  2045. sn = strProductBarcode;
  2046. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2047. // 产品SN(物料码)校验
  2048. List<TestItem> item = new List<TestItem>();
  2049. stopwatch2.Start();
  2050. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2051. stopwatch2.Stop();
  2052. //指令执行结果 1:OK 110:失败
  2053. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2054. //进站结果写入PLC
  2055. CommandFromPLC resultToPlC = new CommandFromPLC();
  2056. resultToPlC.cmd = 0;
  2057. resultToPlC.cmdParam = 0; //指令参数
  2058. resultToPlC.cmdResult = mesResultFrmWeb;
  2059. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2060. }
  2061. catch (Exception ex)
  2062. {
  2063. string str = ex.StackTrace;
  2064. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2065. CommandFromPLC resultToPlC = new CommandFromPLC();
  2066. resultToPlC.cmd = 0;
  2067. resultToPlC.cmdParam = 0; //指令参数
  2068. resultToPlC.cmdResult = 110;
  2069. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2070. }
  2071. stopwatch1.Stop();
  2072. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2073. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2074. ProgressState = false;
  2075. }
  2076. /// <summary>
  2077. /// [S2] 上盖板上料装备 - 出站接口
  2078. /// </summary>
  2079. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2080. {
  2081. Stopwatch stopwatch1 = new Stopwatch();
  2082. Stopwatch stopwatch2 = new Stopwatch();
  2083. try
  2084. {
  2085. stopwatch1.Start();
  2086. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2087. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2088. string processItem = stationName; // 测试项目
  2089. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2090. string supplierCode = ""; // 供应商代码
  2091. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2092. string batch_num = GlobalContext.BatchNumber; // 批次号
  2093. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2094. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2095. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2096. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2097. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2098. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  2099. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2100. bool pass = a1Result == 1;
  2101. //根据载具码获取产品码
  2102. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2103. if (string.IsNullOrEmpty(strProductBarcode))
  2104. {
  2105. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2106. }
  2107. sn = strProductBarcode;
  2108. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2109. List<TestItem> items = new List<TestItem>();
  2110. items.Add(new TestItem()
  2111. {
  2112. Parameter_name = "载具码",
  2113. Parameter_value = CarrierBarcode,
  2114. Parameter_unit = ""
  2115. });
  2116. items.Add(new TestItem()
  2117. {
  2118. Parameter_name = "产品码",
  2119. Parameter_value = sn,
  2120. Parameter_unit = ""
  2121. });
  2122. items.Add(new TestItem()
  2123. {
  2124. Parameter_name = "部件码",
  2125. Parameter_value = PartBarcode,
  2126. Parameter_unit = ""
  2127. });
  2128. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  2129. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2130. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
  2131. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2132. stopwatch2.Start();
  2133. //进站结果写入PLC
  2134. CommandFromPLC resultToPlC = new CommandFromPLC();
  2135. resultToPlC.cmd = 0;
  2136. resultToPlC.cmdParam = 0; //指令参数
  2137. resultToPlC.cmdResult = mesResultFrmWeb;
  2138. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2139. stopwatch2.Stop();
  2140. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2141. //保存PLC返回MES数据到本地
  2142. ResponseMessage message = new ResponseMessage();
  2143. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  2144. if (message.result == false)
  2145. {
  2146. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2147. }
  2148. if (!string.IsNullOrEmpty(PartBarcode))
  2149. {
  2150. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2151. if (message.result == false)
  2152. {
  2153. AddMessage(LogType.Error, message.text);
  2154. }
  2155. }
  2156. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2157. }
  2158. catch (Exception ex)
  2159. {
  2160. stopwatch2.Start();
  2161. CommandFromPLC resultToPlC = new CommandFromPLC();
  2162. resultToPlC.cmd = 0;
  2163. resultToPlC.cmdParam = 0; //指令参数
  2164. resultToPlC.cmdResult = 110;
  2165. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2166. stopwatch2.Stop();
  2167. string str = ex.StackTrace;
  2168. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2169. }
  2170. stopwatch1.Stop();
  2171. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2172. ProgressState = false;
  2173. }
  2174. #endregion
  2175. #region S3
  2176. /// <summary>
  2177. /// [S3] 点散热胶装备
  2178. /// </summary>
  2179. /// <param name="plcNo">PLC编号</param>
  2180. private void ReadStation_S3(int plcNo)
  2181. {
  2182. string stationCode = "[OP30]";
  2183. string stationName = "点散热胶装备";
  2184. string stationNameStr = stationCode + stationName;
  2185. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2186. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2187. string tagAgvCommName = "agvCommFrmPC";
  2188. string tagBarsetName = "BarcodeSet";
  2189. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2190. (int, string) result;
  2191. #region 创建字典
  2192. // 触发信号字典 赋值
  2193. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2194. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2195. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2196. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2197. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2198. // PLC数据字典 赋值
  2199. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2200. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2201. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2202. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2203. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2204. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2205. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2206. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2207. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2208. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2209. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2210. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2211. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2212. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2213. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2214. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2215. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2216. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2217. s3PLCData.Add("c1Result", 0); // 产品结果
  2218. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2219. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2220. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2221. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2222. #endregion 创建字典
  2223. while (true)
  2224. {
  2225. try
  2226. {
  2227. if (!GlobalContext._IsCon_Funs2)
  2228. {
  2229. UpdatePLCMonitor(1, plcNo, 0);
  2230. continue;
  2231. }
  2232. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2233. {
  2234. Stopwatch stopwatch1 = new Stopwatch();
  2235. Stopwatch stopwatch2 = new Stopwatch();
  2236. stopwatch1.Start();
  2237. stopwatch2.Start();
  2238. #region 一次性读取所有数据
  2239. // 一次性读取所有数据
  2240. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2241. if (result.Item1 != 0)
  2242. {
  2243. //richTextBox1.AppendText("\n" + strRet);
  2244. }
  2245. else
  2246. {
  2247. //richTextBox1.AppendText("\n" + "读取成功");
  2248. }
  2249. #endregion 一次性读取所有数据
  2250. stopwatch2.Stop();
  2251. #region 左边进站
  2252. try
  2253. {
  2254. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2255. {
  2256. lock (lockObj)
  2257. {
  2258. if (!ProgressState)
  2259. {
  2260. ProgressState = true;
  2261. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2262. }
  2263. }
  2264. }
  2265. }
  2266. catch (Exception ex)
  2267. {
  2268. ProgressState = false;
  2269. string str = ex.StackTrace;
  2270. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2271. }
  2272. #endregion 左边进站
  2273. #region 左边出站
  2274. try
  2275. {
  2276. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2277. {
  2278. lock (lockObj)
  2279. {
  2280. if (!ProgressState)
  2281. {
  2282. ProgressState = true;
  2283. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2284. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  2285. }
  2286. }
  2287. }
  2288. }
  2289. catch (Exception ex)
  2290. {
  2291. ProgressState = false;
  2292. string str = ex.StackTrace;
  2293. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2294. }
  2295. #endregion 左边出站
  2296. #region 右边进站
  2297. try
  2298. {
  2299. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2300. {
  2301. lock (lockObj)
  2302. {
  2303. if (!ProgressState)
  2304. {
  2305. ProgressState = true;
  2306. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2307. }
  2308. }
  2309. }
  2310. }
  2311. catch (Exception ex)
  2312. {
  2313. ProgressState = false;
  2314. string str = ex.StackTrace;
  2315. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2316. }
  2317. #endregion 右边进站
  2318. #region 右边出站
  2319. try
  2320. {
  2321. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2322. {
  2323. lock (lockObj)
  2324. {
  2325. if (!ProgressState)
  2326. {
  2327. ProgressState = true;
  2328. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2329. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  2330. }
  2331. }
  2332. }
  2333. }
  2334. catch (Exception ex)
  2335. {
  2336. string str = ex.StackTrace;
  2337. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2338. }
  2339. #endregion 右边出站
  2340. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2341. stopwatch1.Stop();
  2342. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2343. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2344. }
  2345. else
  2346. {
  2347. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2348. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2349. FunsEip[plcNo].Connect();
  2350. }
  2351. }
  2352. catch (Exception ex)
  2353. {
  2354. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2355. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2356. //Funs[plcNo].ReConnect();
  2357. }
  2358. Thread.Sleep(IntervalReadPLC);
  2359. }
  2360. }
  2361. /// <summary>
  2362. /// [S3] 点散热胶装备 - 进站
  2363. /// </summary>
  2364. /// <param name="plcNo">PLC编号</param>
  2365. /// <param name="stationNameStr">工站全称</param>
  2366. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2367. {
  2368. Stopwatch stopwatch1 = new Stopwatch();
  2369. Stopwatch stopwatch2 = new Stopwatch();
  2370. try
  2371. {
  2372. stopwatch1.Start();
  2373. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2374. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2375. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2376. string StationId=string.Empty;
  2377. if (direction=="Left")
  2378. {
  2379. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2380. }
  2381. if (direction == "Right")
  2382. {
  2383. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2384. }
  2385. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2386. //载具码验证产品码
  2387. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2388. if (string.IsNullOrEmpty(strProductBarcode))
  2389. {
  2390. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2391. }
  2392. sn = strProductBarcode;
  2393. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2394. // 产品SN(物料码)校验
  2395. List<TestItem> item = new List<TestItem>();
  2396. stopwatch2.Start();
  2397. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2398. stopwatch2.Stop();
  2399. //指令执行结果 1:OK 110:失败
  2400. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2401. //进站结果写入PLC
  2402. CommandFromPLC resultToPlC = new CommandFromPLC();
  2403. resultToPlC.cmd = 0;
  2404. resultToPlC.cmdParam = 0; //指令参数
  2405. resultToPlC.cmdResult = mesResultFrmWeb;
  2406. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2407. }
  2408. catch (Exception ex)
  2409. {
  2410. string str = ex.StackTrace;
  2411. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2412. CommandFromPLC resultToPlC = new CommandFromPLC();
  2413. resultToPlC.cmd = 0;
  2414. resultToPlC.cmdParam = 0; //指令参数
  2415. resultToPlC.cmdResult = 110;
  2416. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2417. }
  2418. stopwatch1.Stop();
  2419. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2420. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2421. ProgressState = false;
  2422. }
  2423. /// <summary>
  2424. /// [S3] 点散热胶装备 - 出站
  2425. /// </summary>
  2426. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2427. {
  2428. Stopwatch stopwatch1 = new Stopwatch();
  2429. Stopwatch stopwatch2 = new Stopwatch();
  2430. try
  2431. {
  2432. stopwatch1.Start();
  2433. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2434. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2435. string processItem = stationName; // 测试项目
  2436. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2437. string supplierCode = ""; // 供应商代码
  2438. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2439. string batch_num = GlobalContext.BatchNumber; // 批次号
  2440. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2441. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2442. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2443. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2444. string StationId = string.Empty;
  2445. if (direction == "Left")
  2446. {
  2447. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2448. }
  2449. if (direction == "Right")
  2450. {
  2451. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2452. }
  2453. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2454. bool pass = a1Result == 1;
  2455. //根据载具码获取产品码
  2456. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2457. if (string.IsNullOrEmpty(strProductBarcode))
  2458. {
  2459. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2460. }
  2461. sn = strProductBarcode;
  2462. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2463. List<TestItem> items = new List<TestItem>();
  2464. items.Add(new TestItem()
  2465. {
  2466. Parameter_name = "载具码",
  2467. Parameter_value = CarrierBarcode,
  2468. Parameter_unit = ""
  2469. });
  2470. items.Add(new TestItem()
  2471. {
  2472. Parameter_name = "产品码",
  2473. Parameter_value = sn,
  2474. Parameter_unit = ""
  2475. });
  2476. int result1 = 1;
  2477. //if (direction == "Right")
  2478. //{
  2479. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  2480. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2481. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson, direction);
  2482. //}
  2483. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2484. stopwatch2.Start();
  2485. //进站结果写入PLC
  2486. CommandFromPLC resultToPlC = new CommandFromPLC();
  2487. resultToPlC.cmd = 0;
  2488. resultToPlC.cmdParam = 0; //指令参数
  2489. resultToPlC.cmdResult = mesResultFrmWeb;
  2490. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2491. stopwatch2.Stop();
  2492. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2493. //保存PLC返回MES数据到本地
  2494. ResponseMessage message = new ResponseMessage();
  2495. if (direction == "Left")
  2496. {
  2497. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2498. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2499. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2500. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2501. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2502. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2503. if (message.result == false)
  2504. {
  2505. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2506. }
  2507. }
  2508. if (direction == "Right")
  2509. {
  2510. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2511. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2512. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2513. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2514. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2515. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2516. if (message.result == false)
  2517. {
  2518. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2519. }
  2520. }
  2521. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2522. }
  2523. catch (Exception ex)
  2524. {
  2525. stopwatch2.Start();
  2526. CommandFromPLC resultToPlC = new CommandFromPLC();
  2527. resultToPlC.cmd = 0;
  2528. resultToPlC.cmdParam = 0; //指令参数
  2529. resultToPlC.cmdResult = 110;
  2530. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2531. stopwatch2.Stop();
  2532. string str = ex.StackTrace;
  2533. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2534. }
  2535. stopwatch1.Stop();
  2536. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2537. ProgressState = false;
  2538. }
  2539. #endregion S3
  2540. #region S4
  2541. /// <summary>
  2542. /// [S4] 点胶检测设备
  2543. /// </summary>
  2544. /// <param name="plcNo">PLC编号</param>
  2545. private void ReadStation_S4(int plcNo)
  2546. {
  2547. string stationCode = "[OP40]";
  2548. string stationName = "胶线检测";
  2549. string stationNameStr = stationCode + stationName;
  2550. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2551. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2552. string tagAgvCommName = "agvCommFrmPC";
  2553. string tagBarsetName = "BarcodeSet";
  2554. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2555. (int, string) result;
  2556. while (true)
  2557. {
  2558. try
  2559. {
  2560. if (!GlobalContext._IsCon_Funs1)
  2561. {
  2562. UpdatePLCMonitor(1, plcNo, 0);
  2563. continue;
  2564. }
  2565. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2566. {
  2567. Stopwatch stopwatch1 = new Stopwatch();
  2568. Stopwatch stopwatch2 = new Stopwatch();
  2569. stopwatch1.Start();
  2570. stopwatch2.Start();
  2571. #region 一次性读取所有数据
  2572. // 一次性读取所有数据
  2573. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2574. if (result.Item1 != 0)
  2575. {
  2576. //richTextBox1.AppendText("\n" + strRet);
  2577. }
  2578. else
  2579. {
  2580. //richTextBox1.AppendText("\n" + "读取成功");
  2581. }
  2582. #endregion 一次性读取所有数据
  2583. stopwatch2.Stop();
  2584. #region 进站
  2585. try
  2586. {
  2587. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2588. {
  2589. lock (lockObj)
  2590. {
  2591. if (!ProgressState)
  2592. {
  2593. ProgressState = true;
  2594. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2595. }
  2596. }
  2597. }
  2598. }
  2599. catch (Exception ex)
  2600. {
  2601. ProgressState = false;
  2602. string str = ex.StackTrace;
  2603. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2604. }
  2605. #endregion 进站
  2606. #region 出站
  2607. try
  2608. {
  2609. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2610. {
  2611. lock (lockObj)
  2612. {
  2613. if (!ProgressState)
  2614. {
  2615. ProgressState = true;
  2616. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2617. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2618. }
  2619. }
  2620. }
  2621. }
  2622. catch (Exception ex)
  2623. {
  2624. string str = ex.StackTrace;
  2625. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2626. }
  2627. #endregion 出站
  2628. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2629. stopwatch1.Stop();
  2630. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2631. }
  2632. else
  2633. {
  2634. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2635. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2636. FunsEip[plcNo].Connect(); // 重连
  2637. }
  2638. }
  2639. catch (Exception ex)
  2640. {
  2641. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2642. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2643. }
  2644. Thread.Sleep(IntervalReadPLC);
  2645. }
  2646. }
  2647. /// <summary>
  2648. /// [S4] 点胶检测设备 - 进站
  2649. /// </summary>
  2650. /// <param name="plcNo">PLC编号</param>
  2651. /// <param name="stationNameStr">工站全称</param>
  2652. /// <param name="stPLC_MesData"></param>
  2653. /// <param name="tagMesCommName"></param>
  2654. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2655. {
  2656. Stopwatch stopwatch1 = new Stopwatch();
  2657. Stopwatch stopwatch2 = new Stopwatch();
  2658. try
  2659. {
  2660. stopwatch1.Start();
  2661. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2662. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2663. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2664. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2665. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2666. //载具码验证产品码
  2667. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2668. if (string.IsNullOrEmpty(strProductBarcode))
  2669. {
  2670. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2671. }
  2672. sn = strProductBarcode;
  2673. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2674. // 产品SN(物料码)校验
  2675. List<TestItem> item = new List<TestItem>();
  2676. stopwatch2.Start();
  2677. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2678. stopwatch2.Stop();
  2679. //指令执行结果 1:OK 110:失败
  2680. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2681. //进站结果写入PLC
  2682. CommandFromPLC resultToPlC = new CommandFromPLC();
  2683. resultToPlC.cmd = 0;
  2684. resultToPlC.cmdParam = 0; //指令参数
  2685. resultToPlC.cmdResult = mesResultFrmWeb;
  2686. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2687. }
  2688. catch (Exception ex)
  2689. {
  2690. string str = ex.StackTrace;
  2691. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2692. CommandFromPLC resultToPlC = new CommandFromPLC();
  2693. resultToPlC.cmd = 0;
  2694. resultToPlC.cmdParam = 0; //指令参数
  2695. resultToPlC.cmdResult = 110;
  2696. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2697. }
  2698. stopwatch1.Stop();
  2699. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2700. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2701. ProgressState = false;
  2702. }
  2703. /// <summary>
  2704. /// [S4] 点胶检测设备 - 出站接口
  2705. /// </summary>
  2706. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2707. {
  2708. Stopwatch stopwatch1 = new Stopwatch();
  2709. Stopwatch stopwatch2 = new Stopwatch();
  2710. try
  2711. {
  2712. stopwatch1.Start();
  2713. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2714. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2715. string processItem = stationName; // 测试项目
  2716. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2717. string supplierCode = ""; // 供应商代码
  2718. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2719. string batch_num = GlobalContext.BatchNumber; // 批次号
  2720. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2721. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2722. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2723. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2724. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2725. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2726. bool pass = a1Result == 1;
  2727. //根据载具码获取产品码
  2728. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2729. if (string.IsNullOrEmpty(strProductBarcode))
  2730. {
  2731. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2732. }
  2733. sn = strProductBarcode;
  2734. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2735. List<TestItem> items = new List<TestItem>();
  2736. items.Add(new TestItem()
  2737. {
  2738. Parameter_name = "载具码",
  2739. Parameter_value = CarrierBarcode,
  2740. Parameter_unit = ""
  2741. });
  2742. items.Add(new TestItem()
  2743. {
  2744. Parameter_name = "产品码",
  2745. Parameter_value = sn,
  2746. Parameter_unit = ""
  2747. });
  2748. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  2749. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2750. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  2751. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2752. stopwatch2.Start();
  2753. //进站结果写入PLC
  2754. CommandFromPLC resultToPlC = new CommandFromPLC();
  2755. resultToPlC.cmd = 0;
  2756. resultToPlC.cmdParam = 0; //指令参数
  2757. resultToPlC.cmdResult = mesResultFrmWeb;
  2758. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2759. stopwatch2.Stop();
  2760. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2761. //保存PLC返回MES数据到本地
  2762. ResponseMessage message = new ResponseMessage();
  2763. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2764. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2765. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2766. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2767. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2768. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2769. if (message.result == false)
  2770. {
  2771. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2772. }
  2773. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2774. }
  2775. catch (Exception ex)
  2776. {
  2777. stopwatch2.Start();
  2778. CommandFromPLC resultToPlC = new CommandFromPLC();
  2779. resultToPlC.cmd = 0;
  2780. resultToPlC.cmdParam = 0; //指令参数
  2781. resultToPlC.cmdResult = 110;
  2782. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2783. stopwatch2.Stop();
  2784. string str = ex.StackTrace;
  2785. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2786. }
  2787. stopwatch1.Stop();
  2788. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2789. ProgressState = false;
  2790. }
  2791. #endregion
  2792. #region S5
  2793. /// <summary>
  2794. /// [S5] 点胶检测设备
  2795. /// </summary>
  2796. /// <param name="plcNo">PLC编号</param>
  2797. private void ReadStation_S5(int plcNo)
  2798. {
  2799. string stationCode = "[OP50]";
  2800. string stationName = "ADD板上料组装装备";
  2801. string stationNameStr = stationCode + stationName;
  2802. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2803. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2804. string tagAgvCommName = "agvCommFrmPC";
  2805. string tagBarsetName = "BarcodeSet";
  2806. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2807. (int, string) result;
  2808. while (true)
  2809. {
  2810. try
  2811. {
  2812. if (!GlobalContext._IsCon_Funs1)
  2813. {
  2814. UpdatePLCMonitor(1, plcNo, 0);
  2815. continue;
  2816. }
  2817. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2818. {
  2819. Stopwatch stopwatch1 = new Stopwatch();
  2820. Stopwatch stopwatch2 = new Stopwatch();
  2821. stopwatch1.Start();
  2822. stopwatch2.Start();
  2823. #region 一次性读取所有数据
  2824. // 一次性读取所有数据
  2825. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2826. if (result.Item1 != 0)
  2827. {
  2828. //richTextBox1.AppendText("\n" + strRet);
  2829. }
  2830. else
  2831. {
  2832. //richTextBox1.AppendText("\n" + "读取成功");
  2833. }
  2834. #endregion 一次性读取所有数据
  2835. stopwatch2.Stop();
  2836. #region 进站
  2837. try
  2838. {
  2839. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2840. {
  2841. lock (lockObj)
  2842. {
  2843. if (!ProgressState)
  2844. {
  2845. ProgressState = true;
  2846. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2847. }
  2848. }
  2849. }
  2850. }
  2851. catch (Exception ex)
  2852. {
  2853. ProgressState = false;
  2854. string str = ex.StackTrace;
  2855. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2856. }
  2857. #endregion 进站
  2858. #region 出站
  2859. try
  2860. {
  2861. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2862. {
  2863. lock (lockObj)
  2864. {
  2865. if (!ProgressState)
  2866. {
  2867. ProgressState = true;
  2868. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2869. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2870. }
  2871. }
  2872. }
  2873. }
  2874. catch (Exception ex)
  2875. {
  2876. ProgressState = false;
  2877. string str = ex.StackTrace;
  2878. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2879. }
  2880. #endregion 出站
  2881. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2882. stopwatch1.Stop();
  2883. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2884. }
  2885. else
  2886. {
  2887. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2888. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2889. FunsEip[plcNo].Connect(); // 重连
  2890. }
  2891. }
  2892. catch (Exception ex)
  2893. {
  2894. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2895. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2896. }
  2897. Thread.Sleep(IntervalReadPLC);
  2898. }
  2899. }
  2900. /// <summary>
  2901. /// [S5] 点胶检测设备 - 进站
  2902. /// </summary>
  2903. /// <param name="plcNo">PLC编号</param>
  2904. /// <param name="stationNameStr">工站全称</param>
  2905. /// <param name="stPLC_MesData"></param>
  2906. /// <param name="tagMesCommName"></param>
  2907. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2908. {
  2909. Stopwatch stopwatch1 = new Stopwatch();
  2910. Stopwatch stopwatch2 = new Stopwatch();
  2911. try
  2912. {
  2913. stopwatch1.Start();
  2914. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2915. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2916. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2917. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2918. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2919. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  2920. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  2921. //绑定载具和产品
  2922. ResponseMessage message = new ResponseMessage();
  2923. if (pcbBarcode == "ERROR")
  2924. {
  2925. ProgressState = false;
  2926. AddMessage(LogType.Error, stationNameStr + "_进站失败!无效PCB码");
  2927. return;
  2928. }
  2929. message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
  2930. if (message.result == false)
  2931. {
  2932. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  2933. }
  2934. //载具码验证产品码 //载具码验证产品码
  2935. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2936. if (string.IsNullOrEmpty(strProductBarcode))
  2937. {
  2938. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2939. }
  2940. sn = strProductBarcode;
  2941. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  2942. // 产品SN(物料码)校验
  2943. List<TestItem> item = new List<TestItem>();
  2944. stopwatch2.Start();
  2945. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2946. stopwatch2.Stop();
  2947. //指令执行结果 1:OK 110:失败
  2948. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2949. //进站结果写入PLC
  2950. CommandFromPLC resultToPlC = new CommandFromPLC();
  2951. resultToPlC.cmd = 0;
  2952. resultToPlC.cmdParam = 0; //指令参数
  2953. resultToPlC.cmdResult = mesResultFrmWeb;
  2954. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2955. }
  2956. catch (Exception ex)
  2957. {
  2958. string str = ex.StackTrace;
  2959. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2960. CommandFromPLC resultToPlC = new CommandFromPLC();
  2961. resultToPlC.cmd = 0;
  2962. resultToPlC.cmdParam = 0; //指令参数
  2963. resultToPlC.cmdResult = 110;
  2964. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2965. }
  2966. stopwatch1.Stop();
  2967. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2968. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2969. ProgressState = false;
  2970. }
  2971. /// <summary>
  2972. /// [S5] 点胶检测设备 - 出站接口
  2973. /// </summary>
  2974. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2975. {
  2976. Stopwatch stopwatch1 = new Stopwatch();
  2977. Stopwatch stopwatch2 = new Stopwatch();
  2978. try
  2979. {
  2980. stopwatch1.Start();
  2981. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2982. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2983. string processItem = stationName; // 测试项目
  2984. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2985. string supplierCode = ""; // 供应商代码
  2986. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2987. string batch_num = GlobalContext.BatchNumber; // 批次号
  2988. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2989. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2990. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2991. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2992. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2993. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2994. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2995. bool pass = a1Result == 1;
  2996. //根据载具码获取产品码
  2997. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2998. if (string.IsNullOrEmpty(strProductBarcode))
  2999. {
  3000. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3001. }
  3002. sn = strProductBarcode;
  3003. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3004. List<TestItem> items = new List<TestItem>();
  3005. items.Add(new TestItem()
  3006. {
  3007. Parameter_name = "载具码",
  3008. Parameter_value = CarrierBarcode,
  3009. Parameter_unit = ""
  3010. });
  3011. items.Add(new TestItem()
  3012. {
  3013. Parameter_name = "产品码",
  3014. Parameter_value = sn,
  3015. Parameter_unit = ""
  3016. });
  3017. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3018. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3019. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
  3020. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3021. stopwatch2.Start();
  3022. //进站结果写入PLC
  3023. CommandFromPLC resultToPlC = new CommandFromPLC();
  3024. resultToPlC.cmd = 0;
  3025. resultToPlC.cmdParam = 0; //指令参数
  3026. resultToPlC.cmdResult = mesResultFrmWeb;
  3027. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3028. stopwatch2.Stop();
  3029. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3030. //保存PLC返回MES数据到本地
  3031. ResponseMessage message = new ResponseMessage();
  3032. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  3033. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  3034. if (message.result == false)
  3035. {
  3036. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3037. }
  3038. //保存部件码信息
  3039. if (!string.IsNullOrEmpty(PartBarcode))
  3040. {
  3041. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  3042. if (message.result == false)
  3043. {
  3044. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  3045. }
  3046. }
  3047. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3048. }
  3049. catch (Exception ex)
  3050. {
  3051. stopwatch2.Start();
  3052. CommandFromPLC resultToPlC = new CommandFromPLC();
  3053. resultToPlC.cmd = 0;
  3054. resultToPlC.cmdParam = 0; //指令参数
  3055. resultToPlC.cmdResult = 110;
  3056. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3057. stopwatch2.Stop();
  3058. string str = ex.StackTrace;
  3059. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3060. }
  3061. stopwatch1.Stop();
  3062. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3063. ProgressState = false;
  3064. }
  3065. #endregion
  3066. #region S6
  3067. /// <summary>
  3068. /// [S6] 顶盖装配设备
  3069. /// </summary>
  3070. /// <param name="plcNo">PLC编号</param>
  3071. private void ReadStation_S6(int plcNo)
  3072. {
  3073. string stationCode = "[OP60]";
  3074. string stationName = "组上盖板";
  3075. string stationNameStr = stationCode + stationName;
  3076. string tagBaseName = "g_OP60_MES"; //标签变量名称
  3077. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3078. string tagAgvCommName = "agvCommFrmPC";
  3079. string tagBarsetName = "BarcodeSet";
  3080. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  3081. (int, string) result;
  3082. while (true)
  3083. {
  3084. try
  3085. {
  3086. if (!GlobalContext._IsCon_Funs1)
  3087. {
  3088. UpdatePLCMonitor(1, plcNo, 0);
  3089. continue;
  3090. }
  3091. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3092. {
  3093. Stopwatch stopwatch1 = new Stopwatch();
  3094. Stopwatch stopwatch2 = new Stopwatch();
  3095. stopwatch1.Start();
  3096. stopwatch2.Start();
  3097. #region 一次性读取所有数据
  3098. // 一次性读取所有数据
  3099. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3100. if (result.Item1 != 0)
  3101. {
  3102. //richTextBox1.AppendText("\n" + strRet);
  3103. }
  3104. else
  3105. {
  3106. //richTextBox1.AppendText("\n" + "读取成功");
  3107. }
  3108. #endregion 一次性读取所有数据
  3109. stopwatch2.Stop();
  3110. #region 进站
  3111. try
  3112. {
  3113. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3114. {
  3115. lock (lockObj)
  3116. {
  3117. if (!ProgressState)
  3118. {
  3119. ProgressState = true;
  3120. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3121. }
  3122. }
  3123. }
  3124. }
  3125. catch (Exception ex)
  3126. {
  3127. ProgressState = false;
  3128. string str = ex.StackTrace;
  3129. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3130. }
  3131. #endregion 进站
  3132. #region 出站
  3133. try
  3134. {
  3135. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3136. {
  3137. lock (lockObj)
  3138. {
  3139. if (!ProgressState)
  3140. {
  3141. ProgressState = true; ;
  3142. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3143. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3144. }
  3145. }
  3146. }
  3147. }
  3148. catch (Exception ex)
  3149. {
  3150. ProgressState = false;
  3151. string str = ex.StackTrace;
  3152. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3153. }
  3154. #endregion 出站
  3155. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3156. stopwatch1.Stop();
  3157. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3158. }
  3159. else
  3160. {
  3161. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3162. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3163. FunsEip[plcNo].Connect(); // 重连
  3164. }
  3165. }
  3166. catch (Exception ex)
  3167. {
  3168. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3169. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3170. }
  3171. Thread.Sleep(IntervalReadPLC);
  3172. }
  3173. }
  3174. /// <summary>
  3175. /// [S6] 顶盖装配设备 - 进站
  3176. /// </summary>
  3177. /// <param name="plcNo">PLC编号</param>
  3178. /// <param name="stationNameStr">工站全称</param>
  3179. /// <param name="stPLC_MesData"></param>
  3180. /// <param name="tagMesCommName"></param>
  3181. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3182. {
  3183. Stopwatch stopwatch1 = new Stopwatch();
  3184. Stopwatch stopwatch2 = new Stopwatch();
  3185. try
  3186. {
  3187. stopwatch1.Start();
  3188. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3189. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3190. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3191. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3192. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3193. //strCarrierBarcode = "N801A-003";
  3194. //载具码验证产品码
  3195. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3196. if (string.IsNullOrEmpty(strProductBarcode))
  3197. {
  3198. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3199. }
  3200. sn = strProductBarcode;
  3201. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3202. if (OpenDailogFalg)
  3203. {
  3204. using (var dialog = new BandBarodeDialog())
  3205. {
  3206. dialog._CarrierBarcode = strCarrierBarcode;
  3207. dialog._ProductBarcode = sn;
  3208. var rs = dialog.ShowDialog();
  3209. if (rs == DialogResult.OK)
  3210. {
  3211. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  3212. OpenDailogFalg = false;//关闭扫码
  3213. }
  3214. else {
  3215. ProgressState = false;
  3216. return;
  3217. }
  3218. }
  3219. }
  3220. // 产品SN(物料码)校验
  3221. List<TestItem> item = new List<TestItem>();
  3222. stopwatch2.Start();
  3223. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3224. stopwatch2.Stop();
  3225. //指令执行结果 1:OK 110:失败
  3226. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3227. //进站结果写入PLC
  3228. CommandFromPLC resultToPlC = new CommandFromPLC();
  3229. resultToPlC.cmd = 0;
  3230. resultToPlC.cmdParam = 0; //指令参数
  3231. resultToPlC.cmdResult = mesResultFrmWeb;
  3232. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3233. }
  3234. catch (Exception ex)
  3235. {
  3236. string str = ex.StackTrace;
  3237. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3238. CommandFromPLC resultToPlC = new CommandFromPLC();
  3239. resultToPlC.cmd = 0;
  3240. resultToPlC.cmdParam = 0; //指令参数
  3241. resultToPlC.cmdResult = 110;
  3242. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3243. }
  3244. stopwatch1.Stop();
  3245. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3246. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3247. ProgressState = false;
  3248. OpenDailogFalg = true; //开启下一个物料的扫码
  3249. }
  3250. /// <summary>
  3251. /// [S6] 顶盖装配设备 - 出站接口
  3252. /// </summary>
  3253. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3254. {
  3255. Stopwatch stopwatch1 = new Stopwatch();
  3256. Stopwatch stopwatch2 = new Stopwatch();
  3257. try
  3258. {
  3259. stopwatch1.Start();
  3260. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3261. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3262. string processItem = stationName; // 测试项目
  3263. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3264. string supplierCode = ""; // 供应商代码
  3265. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3266. string batch_num = GlobalContext.BatchNumber; // 批次号
  3267. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3268. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3269. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3270. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3271. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3272. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3273. bool pass = a1Result == 1;
  3274. //根据载具码获取产品码
  3275. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3276. if (string.IsNullOrEmpty(strProductBarcode))
  3277. {
  3278. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3279. }
  3280. sn = strProductBarcode;
  3281. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3282. List<TestItem> items = new List<TestItem>();
  3283. items.Add(new TestItem()
  3284. {
  3285. Parameter_name = "载具码",
  3286. Parameter_value = CarrierBarcode,
  3287. Parameter_unit = ""
  3288. });
  3289. items.Add(new TestItem()
  3290. {
  3291. Parameter_name = "产品码",
  3292. Parameter_value = sn,
  3293. Parameter_unit = ""
  3294. });
  3295. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3296. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3297. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  3298. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3299. stopwatch2.Start();
  3300. //进站结果写入PLC
  3301. CommandFromPLC resultToPlC = new CommandFromPLC();
  3302. resultToPlC.cmd = 0;
  3303. resultToPlC.cmdParam = 0; //指令参数
  3304. resultToPlC.cmdResult = mesResultFrmWeb;
  3305. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3306. stopwatch2.Stop();
  3307. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3308. //保存PLC返回MES数据到本地
  3309. ResponseMessage message = new ResponseMessage();
  3310. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3311. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3312. if (message.result == false)
  3313. {
  3314. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3315. }
  3316. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3317. }
  3318. catch (Exception ex)
  3319. {
  3320. stopwatch2.Start();
  3321. CommandFromPLC resultToPlC = new CommandFromPLC();
  3322. resultToPlC.cmd = 0;
  3323. resultToPlC.cmdParam = 0; //指令参数
  3324. resultToPlC.cmdResult = 110;
  3325. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3326. stopwatch2.Stop();
  3327. string str = ex.StackTrace;
  3328. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3329. }
  3330. stopwatch1.Stop();
  3331. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3332. ProgressState = false;
  3333. }
  3334. #endregion
  3335. #region S7
  3336. /// <summary>
  3337. /// [S7] 锁螺丝设备
  3338. /// </summary>
  3339. /// <param name="plcNo">PLC编号</param>
  3340. private void ReadStation_S7(int plcNo)
  3341. {
  3342. string stationCode = "[OP70]";
  3343. string stationName = "上盖板锁螺丝";
  3344. string stationNameStr = stationCode + stationName;
  3345. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3346. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3347. string tagAgvCommName = "agvCommFrmPC";
  3348. string tagBarsetName = "BarcodeSet";
  3349. string tagScrewDataset = "screwDataset";
  3350. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3351. (int, string) result;
  3352. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3353. atlasScrewLeft.Initial();
  3354. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3355. atlasScrewRight.Initial();
  3356. while (true)
  3357. {
  3358. try
  3359. {
  3360. if (!GlobalContext._IsCon_Funs1)
  3361. {
  3362. UpdatePLCMonitor(1, plcNo, 0);
  3363. continue;
  3364. }
  3365. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3366. {
  3367. Stopwatch stopwatch1 = new Stopwatch();
  3368. Stopwatch stopwatch2 = new Stopwatch();
  3369. stopwatch1.Start();
  3370. stopwatch2.Start();
  3371. #region 一次性读取所有数据
  3372. // 一次性读取所有数据
  3373. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3374. if (result.Item1 != 0)
  3375. {
  3376. //richTextBox1.AppendText("\n" + strRet);
  3377. }
  3378. else
  3379. {
  3380. //richTextBox1.AppendText("\n" + "读取成功");
  3381. }
  3382. #endregion 一次性读取所有数据
  3383. stopwatch2.Stop();
  3384. #region 左边进站
  3385. try
  3386. {
  3387. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3388. {
  3389. lock (lockObj)
  3390. {
  3391. if (!ProgressState)
  3392. {
  3393. ProgressState = true;
  3394. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3395. }
  3396. }
  3397. }
  3398. }
  3399. catch (Exception ex)
  3400. {
  3401. ProgressState = false;
  3402. string str = ex.StackTrace;
  3403. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3404. }
  3405. #endregion 左边进站
  3406. #region 左边出站
  3407. try
  3408. {
  3409. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3410. {
  3411. lock (lockObj)
  3412. {
  3413. if (!ProgressState)
  3414. {
  3415. ProgressState = true;
  3416. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3417. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3418. }
  3419. }
  3420. }
  3421. }
  3422. catch (Exception ex)
  3423. {
  3424. ProgressState = false;
  3425. string str = ex.StackTrace;
  3426. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3427. }
  3428. #endregion 左边出站
  3429. #region 右边进站
  3430. try
  3431. {
  3432. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3433. {
  3434. lock (lockObj)
  3435. {
  3436. if (!ProgressState)
  3437. {
  3438. ProgressState = true;
  3439. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3440. }
  3441. }
  3442. }
  3443. }
  3444. catch (Exception ex)
  3445. {
  3446. ProgressState = false;
  3447. string str = ex.StackTrace;
  3448. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3449. }
  3450. #endregion 右边进站
  3451. #region 右边出站
  3452. try
  3453. {
  3454. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3455. {
  3456. lock (lockObj)
  3457. {
  3458. if (!ProgressState)
  3459. {
  3460. ProgressState = true;
  3461. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3462. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3463. }
  3464. }
  3465. }
  3466. }
  3467. catch (Exception ex)
  3468. {
  3469. ProgressState = false;
  3470. string str = ex.StackTrace;
  3471. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3472. }
  3473. #endregion 右边出站
  3474. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3475. stopwatch1.Stop();
  3476. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3477. }
  3478. else
  3479. {
  3480. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3481. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3482. FunsEip[plcNo].Connect(); // 重连
  3483. }
  3484. }
  3485. catch (Exception ex)
  3486. {
  3487. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3488. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3489. }
  3490. Thread.Sleep(IntervalReadPLC);
  3491. }
  3492. }
  3493. /// <summary>
  3494. /// [S7] 锁螺丝设备 - 进站
  3495. /// </summary>
  3496. /// <param name="plcNo">PLC编号</param>
  3497. /// <param name="stationNameStr">工站全称</param>
  3498. /// <param name="stPLC_MesData"></param>
  3499. /// <param name="tagMesCommName"></param>
  3500. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3501. {
  3502. Stopwatch stopwatch1 = new Stopwatch();
  3503. Stopwatch stopwatch2 = new Stopwatch();
  3504. string atlasSn=string.Empty;
  3505. try
  3506. {
  3507. stopwatch1.Start();
  3508. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3509. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3510. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3511. string StationId = string.Empty; // 工位ID(可配置)
  3512. if (direction == "Left")
  3513. {
  3514. StationId = GlobalContext.S7_StationId_1;
  3515. }
  3516. if (direction == "Right")
  3517. {
  3518. StationId = GlobalContext.S7_StationId_2;
  3519. }
  3520. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3521. //载具码验证产品码
  3522. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3523. if (string.IsNullOrEmpty(strProductBarcode))
  3524. {
  3525. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3526. }
  3527. sn = strProductBarcode;
  3528. atlasSn= strProductBarcode;
  3529. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3530. if (direction == "Left")
  3531. {
  3532. isCollectingFlagLeft = false;//采集螺丝数据结束
  3533. }
  3534. if (direction == "Right")
  3535. {
  3536. isCollectingFlagRight = false;//采集螺丝数据结束
  3537. }
  3538. // 产品SN(物料码)校验
  3539. List<TestItem> item = new List<TestItem>();
  3540. stopwatch2.Start();
  3541. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3542. stopwatch2.Stop();
  3543. //指令执行结果 1:OK 110:失败
  3544. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3545. //进站结果写入PLC
  3546. CommandFromPLC resultToPlC = new CommandFromPLC();
  3547. resultToPlC.cmd = 0;
  3548. resultToPlC.cmdParam = 0; //指令参数
  3549. resultToPlC.cmdResult = mesResultFrmWeb;
  3550. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3551. }
  3552. catch (Exception ex)
  3553. {
  3554. string str = ex.StackTrace;
  3555. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3556. CommandFromPLC resultToPlC = new CommandFromPLC();
  3557. resultToPlC.cmd = 0;
  3558. resultToPlC.cmdParam = 0; //指令参数
  3559. resultToPlC.cmdResult = 110;
  3560. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3561. }
  3562. stopwatch1.Stop();
  3563. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3564. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3565. ProgressState = false;
  3566. //开始采集螺丝数据
  3567. if (direction == "Left")
  3568. {
  3569. isCollectingFlagLeft = true;
  3570. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3571. }
  3572. if (direction == "Right")
  3573. {
  3574. isCollectingFlagRight = true;
  3575. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3576. }
  3577. }
  3578. /// <summary>
  3579. /// [S7] 锁螺丝设备 - 出站
  3580. /// </summary>
  3581. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3582. {
  3583. Stopwatch stopwatch1 = new Stopwatch();
  3584. Stopwatch stopwatch2 = new Stopwatch();
  3585. try
  3586. {
  3587. stopwatch1.Start();
  3588. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3589. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3590. string processItem = stationName; // 测试项目
  3591. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3592. string supplierCode = ""; // 供应商代码
  3593. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3594. string batch_num = GlobalContext.BatchNumber; // 批次号
  3595. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3596. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3597. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3598. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3599. string StationId = string.Empty; // 工位ID(可配置)
  3600. if (direction == "Left")
  3601. {
  3602. StationId = GlobalContext.S7_StationId_1;
  3603. }
  3604. if (direction == "Right")
  3605. {
  3606. StationId = GlobalContext.S7_StationId_2;
  3607. }
  3608. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3609. a1Result = 1;
  3610. bool pass = a1Result == 1;
  3611. //根据载具码获取产品码
  3612. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3613. if (string.IsNullOrEmpty(strProductBarcode))
  3614. {
  3615. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3616. }
  3617. sn = strProductBarcode;
  3618. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3619. List<TestItem> items = new List<TestItem>();
  3620. items.Add(new TestItem()
  3621. {
  3622. Parameter_name = "载具码",
  3623. Parameter_value = CarrierBarcode,
  3624. Parameter_unit = ""
  3625. });
  3626. items.Add(new TestItem()
  3627. {
  3628. Parameter_name = "产品码",
  3629. Parameter_value = sn,
  3630. Parameter_unit = ""
  3631. });
  3632. int result1 = 1;
  3633. //if (direction == "Right")
  3634. //{
  3635. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3636. SwitctProcessData(stationNameStr, items, equipmentCode, processItem , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode
  3637. , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  3638. //}
  3639. //if (direction == "Left")
  3640. //{
  3641. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3642. //}
  3643. //if (direction == "Right")
  3644. //{
  3645. // isCollectingFlagRight = false;//采集螺丝数据结束
  3646. //}
  3647. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3648. stopwatch2.Start();
  3649. //进站结果写入PLC
  3650. CommandFromPLC resultToPlC = new CommandFromPLC();
  3651. resultToPlC.cmd = 0;
  3652. resultToPlC.cmdParam = 0; //指令参数
  3653. resultToPlC.cmdResult = mesResultFrmWeb;
  3654. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3655. stopwatch2.Stop();
  3656. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3657. //保存PLC返回MES数据到本地
  3658. ResponseMessage message = new ResponseMessage();
  3659. if (direction == "Left")
  3660. {
  3661. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3662. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3663. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3664. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3665. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3666. if (message.result == false)
  3667. {
  3668. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3669. }
  3670. }
  3671. if (direction == "Right")
  3672. {
  3673. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3674. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3675. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3676. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3677. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3678. if (message.result == false)
  3679. {
  3680. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3681. }
  3682. }
  3683. //保存螺丝数据到txt
  3684. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3685. if (result.Item1 != 0)
  3686. {
  3687. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3688. }
  3689. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3690. }
  3691. catch (Exception ex)
  3692. {
  3693. stopwatch2.Start();
  3694. CommandFromPLC resultToPlC = new CommandFromPLC();
  3695. resultToPlC.cmd = 0;
  3696. resultToPlC.cmdParam = 0; //指令参数
  3697. resultToPlC.cmdResult = 110;
  3698. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3699. stopwatch2.Stop();
  3700. string str = ex.StackTrace;
  3701. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3702. }
  3703. stopwatch1.Stop();
  3704. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3705. ProgressState = false;
  3706. }
  3707. #endregion
  3708. #region S8
  3709. /// <summary>
  3710. /// [S8] 3D螺丝高度检测设备
  3711. /// </summary>
  3712. /// <param name="plcNo">PLC编号</param>
  3713. private void ReadStation_S8(int plcNo)
  3714. {
  3715. string stationCode = "[OP80]";
  3716. string stationName = "NG下料";
  3717. string stationNameStr = stationCode + stationName;
  3718. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3719. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3720. string tagAgvCommName = "agvCommFrmPC";
  3721. string tagBarsetName = "BarcodeSet";
  3722. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3723. (int, string) result;
  3724. while (true)
  3725. {
  3726. try
  3727. {
  3728. if (!GlobalContext._IsCon_Funs1)
  3729. {
  3730. UpdatePLCMonitor(1, plcNo, 0);
  3731. continue;
  3732. }
  3733. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3734. {
  3735. Stopwatch stopwatch1 = new Stopwatch();
  3736. Stopwatch stopwatch2 = new Stopwatch();
  3737. stopwatch1.Start();
  3738. stopwatch2.Start();
  3739. #region 一次性读取所有数据
  3740. // 一次性读取所有数据
  3741. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3742. if (result.Item1 != 0)
  3743. {
  3744. //richTextBox1.AppendText("\n" + strRet);
  3745. }
  3746. else
  3747. {
  3748. //richTextBox1.AppendText("\n" + "读取成功");
  3749. }
  3750. #endregion 一次性读取所有数据
  3751. stopwatch2.Stop();
  3752. #region 进站
  3753. try
  3754. {
  3755. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3756. {
  3757. lock (lockObj)
  3758. {
  3759. if (!ProgressState)
  3760. {
  3761. ProgressState = true;
  3762. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3763. }
  3764. }
  3765. }
  3766. }
  3767. catch (Exception ex)
  3768. {
  3769. ProgressState = false;
  3770. string str = ex.StackTrace;
  3771. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3772. }
  3773. #endregion 进站
  3774. #region 出站
  3775. try
  3776. {
  3777. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3778. {
  3779. lock (lockObj)
  3780. {
  3781. if (!ProgressState)
  3782. {
  3783. ProgressState = true;
  3784. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3785. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3786. }
  3787. }
  3788. }
  3789. }
  3790. catch (Exception ex)
  3791. {
  3792. ProgressState = false;
  3793. string str = ex.StackTrace;
  3794. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3795. }
  3796. #endregion 出站
  3797. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3798. stopwatch1.Stop();
  3799. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3800. }
  3801. else
  3802. {
  3803. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3804. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3805. FunsEip[plcNo].Connect(); // 重连
  3806. }
  3807. }
  3808. catch (Exception ex)
  3809. {
  3810. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3811. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3812. }
  3813. Thread.Sleep(IntervalReadPLC);
  3814. }
  3815. }
  3816. /// <summary>
  3817. /// [S8] 3D螺丝高度检测设备 - 进站
  3818. /// </summary>
  3819. /// <param name="plcNo">PLC编号</param>
  3820. /// <param name="stationNameStr">工站全称</param>
  3821. /// <param name="stPLC_MesData"></param>
  3822. /// <param name="tagMesCommName"></param>
  3823. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3824. {
  3825. Stopwatch stopwatch1 = new Stopwatch();
  3826. Stopwatch stopwatch2 = new Stopwatch();
  3827. try
  3828. {
  3829. stopwatch1.Start();
  3830. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3831. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3832. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3833. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3834. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3835. //载具码验证产品码
  3836. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3837. if (string.IsNullOrEmpty(strProductBarcode))
  3838. {
  3839. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3840. }
  3841. sn = strProductBarcode;
  3842. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3843. // 产品SN(物料码)校验
  3844. List<TestItem> item = new List<TestItem>();
  3845. stopwatch2.Start();
  3846. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3847. stopwatch2.Stop();
  3848. //指令执行结果 1:OK 110:失败
  3849. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3850. //进站结果写入PLC
  3851. CommandFromPLC resultToPlC = new CommandFromPLC();
  3852. resultToPlC.cmd = 0;
  3853. resultToPlC.cmdParam = 0; //指令参数
  3854. resultToPlC.cmdResult = mesResultFrmWeb;
  3855. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3856. }
  3857. catch (Exception ex)
  3858. {
  3859. string str = ex.StackTrace;
  3860. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3861. CommandFromPLC resultToPlC = new CommandFromPLC();
  3862. resultToPlC.cmd = 0;
  3863. resultToPlC.cmdParam = 0; //指令参数
  3864. resultToPlC.cmdResult = 110;
  3865. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3866. }
  3867. stopwatch1.Stop();
  3868. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3869. ProgressState = false;
  3870. }
  3871. /// <summary>
  3872. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3873. /// </summary>
  3874. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3875. {
  3876. Stopwatch stopwatch1 = new Stopwatch();
  3877. Stopwatch stopwatch2 = new Stopwatch();
  3878. try
  3879. {
  3880. stopwatch1.Start();
  3881. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3882. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3883. string processItem = stationName; // 测试项目
  3884. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3885. string supplierCode = ""; // 供应商代码
  3886. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3887. string batch_num = GlobalContext.BatchNumber; // 批次号
  3888. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3889. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3890. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3891. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3892. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3893. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3894. bool pass = a1Result == 1;
  3895. //根据载具码获取产品码
  3896. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3897. if (string.IsNullOrEmpty(strProductBarcode))
  3898. {
  3899. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3900. }
  3901. sn = strProductBarcode;
  3902. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3903. List<TestItem> items = new List<TestItem>();
  3904. items.Add(new TestItem()
  3905. {
  3906. Parameter_name = "载具码",
  3907. Parameter_value = CarrierBarcode,
  3908. Parameter_unit = ""
  3909. });
  3910. items.Add(new TestItem()
  3911. {
  3912. Parameter_name = "产品码",
  3913. Parameter_value = sn,
  3914. Parameter_unit = ""
  3915. });
  3916. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3917. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3918. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  3919. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3920. stopwatch2.Start();
  3921. //进站结果写入PLC
  3922. CommandFromPLC resultToPlC = new CommandFromPLC();
  3923. resultToPlC.cmd = 0;
  3924. resultToPlC.cmdParam = 0; //指令参数
  3925. resultToPlC.cmdResult = mesResultFrmWeb;
  3926. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3927. stopwatch2.Stop();
  3928. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3929. //保存PLC返回MES数据到本地
  3930. ResponseMessage message = new ResponseMessage();
  3931. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3932. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3933. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3934. if (message.result == false)
  3935. {
  3936. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3937. }
  3938. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3939. }
  3940. catch (Exception ex)
  3941. {
  3942. stopwatch2.Start();
  3943. CommandFromPLC resultToPlC = new CommandFromPLC();
  3944. resultToPlC.cmd = 0;
  3945. resultToPlC.cmdParam = 0; //指令参数
  3946. resultToPlC.cmdResult = 110;
  3947. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3948. stopwatch2.Stop();
  3949. string str = ex.StackTrace;
  3950. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3951. }
  3952. stopwatch1.Stop();
  3953. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3954. ProgressState = false;
  3955. }
  3956. #endregion
  3957. #region S9
  3958. /// <summary>
  3959. /// [S9] 下料设备
  3960. /// </summary>
  3961. /// <param name="plcNo">PLC编号</param>
  3962. private void ReadStation_S9(int plcNo)
  3963. {
  3964. string stationCode = "[OP90]";
  3965. string stationName = "半成品下料";
  3966. string stationNameStr = stationCode + stationName;
  3967. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3968. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3969. string tagAgvCommName = "agvCommFrmPC";
  3970. string tagBarsetName = "BarcodeSet";
  3971. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3972. (int, string) result;
  3973. while (true)
  3974. {
  3975. try
  3976. {
  3977. if (!GlobalContext._IsCon_Funs1)
  3978. {
  3979. UpdatePLCMonitor(1, plcNo, 0);
  3980. continue;
  3981. }
  3982. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3983. {
  3984. Stopwatch stopwatch1 = new Stopwatch();
  3985. Stopwatch stopwatch2 = new Stopwatch();
  3986. stopwatch1.Start();
  3987. stopwatch2.Start();
  3988. #region 一次性读取所有数据
  3989. // 一次性读取所有数据
  3990. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3991. if (result.Item1 != 0)
  3992. {
  3993. //richTextBox1.AppendText("\n" + strRet);
  3994. }
  3995. else
  3996. {
  3997. //richTextBox1.AppendText("\n" + "读取成功");
  3998. }
  3999. #endregion 一次性读取所有数据
  4000. stopwatch2.Stop();
  4001. #region 进站
  4002. try
  4003. {
  4004. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4005. {
  4006. lock (lockObj)
  4007. {
  4008. if (!ProgressState)
  4009. {
  4010. ProgressState = true;
  4011. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  4012. }
  4013. }
  4014. }
  4015. }
  4016. catch (Exception ex)
  4017. {
  4018. ProgressState = false;
  4019. string str = ex.StackTrace;
  4020. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4021. }
  4022. #endregion 进站
  4023. #region 出站
  4024. try
  4025. {
  4026. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4027. {
  4028. lock (lockObj)
  4029. {
  4030. if (!ProgressState)
  4031. {
  4032. ProgressState = true;
  4033. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  4034. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4035. }
  4036. }
  4037. }
  4038. }
  4039. catch (Exception ex)
  4040. {
  4041. ProgressState = false;
  4042. string str = ex.StackTrace;
  4043. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4044. }
  4045. #endregion 出站
  4046. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4047. stopwatch1.Stop();
  4048. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4049. }
  4050. else
  4051. {
  4052. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4053. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4054. FunsEip[plcNo].Connect(); // 重连
  4055. }
  4056. }
  4057. catch (Exception ex)
  4058. {
  4059. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4060. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4061. }
  4062. Thread.Sleep(IntervalReadPLC);
  4063. }
  4064. }
  4065. /// <summary>
  4066. /// [S9] 下料设备 - 进站
  4067. /// </summary>
  4068. /// <param name="plcNo">PLC编号</param>
  4069. /// <param name="stationNameStr">工站全称</param>
  4070. /// <param name="stPLC_MesData"></param>
  4071. /// <param name="tagMesCommName"></param>
  4072. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  4073. {
  4074. Stopwatch stopwatch1 = new Stopwatch();
  4075. Stopwatch stopwatch2 = new Stopwatch();
  4076. try
  4077. {
  4078. stopwatch1.Start();
  4079. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4080. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4081. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  4082. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  4083. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4084. //载具码验证产品码
  4085. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4086. if (string.IsNullOrEmpty(strProductBarcode))
  4087. {
  4088. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4089. }
  4090. sn = strProductBarcode;
  4091. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4092. // 产品SN(物料码)校验
  4093. List<TestItem> item = new List<TestItem>();
  4094. stopwatch2.Start();
  4095. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  4096. stopwatch2.Stop();
  4097. //指令执行结果 1:OK 110:失败
  4098. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4099. //进站结果写入PLC
  4100. CommandFromPLC resultToPlC = new CommandFromPLC();
  4101. resultToPlC.cmd = 0;
  4102. resultToPlC.cmdParam = 0; //指令参数
  4103. resultToPlC.cmdResult = mesResultFrmWeb;
  4104. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4105. }
  4106. catch (Exception ex)
  4107. {
  4108. string str = ex.StackTrace;
  4109. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4110. CommandFromPLC resultToPlC = new CommandFromPLC();
  4111. resultToPlC.cmd = 0;
  4112. resultToPlC.cmdParam = 0; //指令参数
  4113. resultToPlC.cmdResult = 110;
  4114. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4115. }
  4116. stopwatch1.Stop();
  4117. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4118. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4119. ProgressState = false;
  4120. }
  4121. /// <summary>
  4122. /// [S9] 下料设备 - 出站接口
  4123. /// </summary>
  4124. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  4125. {
  4126. Stopwatch stopwatch1 = new Stopwatch();
  4127. Stopwatch stopwatch2 = new Stopwatch();
  4128. try
  4129. {
  4130. stopwatch1.Start();
  4131. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4132. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4133. string processItem = stationName; // 测试项目
  4134. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4135. string supplierCode = ""; // 供应商代码
  4136. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4137. string batch_num = GlobalContext.BatchNumber; // 批次号
  4138. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4139. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4140. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4141. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  4142. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  4143. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4144. bool pass = a1Result == 1;
  4145. //根据载具码获取产品码
  4146. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4147. if (string.IsNullOrEmpty(strProductBarcode))
  4148. {
  4149. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4150. }
  4151. sn = strProductBarcode;
  4152. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4153. List<TestItem> items = new List<TestItem>();
  4154. items.Add(new TestItem()
  4155. {
  4156. Parameter_name = "载具码",
  4157. Parameter_value = CarrierBarcode,
  4158. Parameter_unit = ""
  4159. });
  4160. items.Add(new TestItem()
  4161. {
  4162. Parameter_name = "产品码",
  4163. Parameter_value = sn,
  4164. Parameter_unit = ""
  4165. });
  4166. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4167. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4168. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  4169. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4170. stopwatch2.Start();
  4171. //进站结果写入PLC
  4172. CommandFromPLC resultToPlC = new CommandFromPLC();
  4173. resultToPlC.cmd = 0;
  4174. resultToPlC.cmdParam = 0; //指令参数
  4175. resultToPlC.cmdResult = mesResultFrmWeb;
  4176. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4177. stopwatch2.Stop();
  4178. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4179. //保存PLC返回MES数据到本地
  4180. ResponseMessage message = new ResponseMessage();
  4181. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4182. if (message.result == false)
  4183. {
  4184. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4185. }
  4186. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4187. if (result1 == 1)
  4188. {
  4189. //载具码解除绑定
  4190. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4191. if (message.result == false)
  4192. {
  4193. AddMessage(LogType.Error, message.text);
  4194. }
  4195. }
  4196. }
  4197. catch (Exception ex)
  4198. {
  4199. stopwatch2.Start();
  4200. CommandFromPLC resultToPlC = new CommandFromPLC();
  4201. resultToPlC.cmd = 0;
  4202. resultToPlC.cmdParam = 0; //指令参数
  4203. resultToPlC.cmdResult = 110;
  4204. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4205. stopwatch2.Stop();
  4206. string str = ex.StackTrace;
  4207. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4208. }
  4209. stopwatch1.Stop();
  4210. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4211. ProgressState = false;
  4212. }
  4213. #endregion
  4214. #endregion Xiaomi
  4215. #region PLC1 张超凡
  4216. #region [S1] Tray盘上料装备(板测)
  4217. /// <summary>
  4218. /// S1工位的数据- 触发信号上次的值
  4219. /// </summary>
  4220. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4221. /// <summary>
  4222. /// S1工位的数据(含触发信号)
  4223. /// </summary>
  4224. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4225. /// <summary>
  4226. /// S1工位的数据- 回写点位
  4227. /// </summary>
  4228. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4229. ///// <summary>
  4230. ///// 触发信号
  4231. ///// </summary>
  4232. //private ManualResetEvent[] MreTasks;
  4233. /// <summary>
  4234. /// [S1] Tray盘上料装备(板测)
  4235. /// </summary>
  4236. /// <param name="plcNo">PLC编号</param>
  4237. //private void ReadStation_S1(int plcNo)
  4238. //{
  4239. // // [S1] Tray盘上料装备
  4240. // // [S2] FCT
  4241. // // [S3] 值板机
  4242. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4243. // // [S5] Tray盘下料装备
  4244. // string stationCode = "[S1]";
  4245. // string stationName = "Tray盘上料装备";
  4246. // string stationNameStr = stationCode + stationName;
  4247. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4248. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4249. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4250. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4251. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4252. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4253. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4254. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4255. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4256. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4257. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4258. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4259. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4260. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4261. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4262. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4263. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4264. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4265. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4266. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4267. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4268. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4269. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4270. // s1PLCData.Add("a1Result", 0); // 产品结果
  4271. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4272. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4273. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4274. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4275. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4276. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4277. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4278. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4279. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4280. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4281. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4282. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4283. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4284. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4285. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4286. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4287. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4288. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4289. // while (IsRun)
  4290. // {
  4291. // try
  4292. // {
  4293. // if (!GlobalContext._IsCon_Funs1)
  4294. // {
  4295. // UpdatePLCMonitor(1, plcNo, 0);
  4296. // continue;
  4297. // }
  4298. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4299. // {
  4300. // Stopwatch stopwatch1 = new Stopwatch();
  4301. // Stopwatch stopwatch2 = new Stopwatch();
  4302. // stopwatch1.Start();
  4303. // stopwatch2.Start();
  4304. // #region 一次性读取所有数据
  4305. // // 一次性读取所有数据
  4306. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4307. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4308. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4309. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4310. // int[] datas = data1.Concat(data2).ToArray();
  4311. // datas = datas.Concat(data3).ToArray();
  4312. // datas = datas.Concat(data4).ToArray();
  4313. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4314. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4315. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4316. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4317. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4318. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4319. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4320. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4321. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4322. // s1PLCData["a1MES_FLAG"] = datas[109];
  4323. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4324. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4325. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4326. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4327. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4328. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4329. // s1PLCData["a1Result"] = datas[170];
  4330. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4331. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4332. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4333. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4334. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4335. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4336. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4337. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4338. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4339. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4340. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4341. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4342. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4343. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4344. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4345. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4346. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4347. // s1PLCData["a1AGVUpStart"] = datas[308];
  4348. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4349. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4350. // s1PLCData["a1AGVDownStart"] = datas[321];
  4351. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4352. // #endregion 一次性读取所有数据
  4353. // stopwatch2.Stop();
  4354. // #region 回写操作,写后清空flag
  4355. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4356. // #endregion 回写操作,写后清空flag
  4357. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4358. // try
  4359. // {
  4360. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4361. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4362. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4363. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4364. // {
  4365. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4366. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4367. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4368. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4369. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4370. // }
  4371. // }
  4372. // catch (Exception ex)
  4373. // {
  4374. // // 6代表上位机报警
  4375. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4376. // string str = ex.StackTrace;
  4377. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4378. // }
  4379. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4380. // #region 上料进站校验
  4381. // try
  4382. // {
  4383. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4384. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4385. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4386. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4387. // {
  4388. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4389. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4390. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4391. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4392. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4393. // }
  4394. // }
  4395. // catch (Exception ex)
  4396. // {
  4397. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4398. // string str = ex.StackTrace;
  4399. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4400. // }
  4401. // #endregion 上料进站校验
  4402. // #region Tray盘上料装备-出站接口
  4403. // try
  4404. // {
  4405. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4406. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4407. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4408. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4409. // {
  4410. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4411. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4412. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4413. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4414. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4415. // }
  4416. // }
  4417. // catch (Exception ex)
  4418. // {
  4419. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4420. // string str = ex.StackTrace;
  4421. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4422. // }
  4423. // #endregion Tray盘上料装备-出站接口
  4424. // #region Tray盘上料装备-将SN发给ICT标机
  4425. // try
  4426. // {
  4427. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4428. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4429. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4430. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4431. // {
  4432. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4433. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4434. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4435. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4436. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4437. // }
  4438. // }
  4439. // catch (Exception ex)
  4440. // {
  4441. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4442. // string str = ex.StackTrace;
  4443. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4444. // }
  4445. // #endregion Tray盘上料装备-将SN发给ICT标机
  4446. // #region Tray盘上料装备-点检数据
  4447. // //try
  4448. // //{
  4449. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4450. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4451. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4452. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4453. // // if (pLC_Flag && !mES_Flag) // 1 0
  4454. // // {
  4455. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4456. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4457. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4458. // // }
  4459. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4460. // // {
  4461. // // // 清空写给PLC的数据
  4462. // // // MES_Flag重置为0
  4463. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4464. // // }
  4465. // //}
  4466. // //catch (Exception ex)
  4467. // //{
  4468. // // // MES_Flag 为2上位机报错
  4469. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4470. // // string str = ex.StackTrace;
  4471. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4472. // //}
  4473. // #endregion Tray盘上料装备-点检数据
  4474. // #region 节拍接口
  4475. // try
  4476. // {
  4477. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4478. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4479. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4480. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4481. // {
  4482. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4483. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4484. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4485. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4486. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4487. // }
  4488. // }
  4489. // catch (Exception ex)
  4490. // {
  4491. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4492. // string str = ex.StackTrace;
  4493. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4494. // }
  4495. // #endregion 节拍接口
  4496. // #region AGV上料
  4497. // // AGV上料叫AGV信号
  4498. // try
  4499. // {
  4500. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4501. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4502. // if (a1AGVUpCall != a1AGVUpCallOld)
  4503. // {
  4504. // if (a1AGVUpCall == 1) // 0->1
  4505. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4506. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4507. // }
  4508. // }
  4509. // catch (Exception ex)
  4510. // {
  4511. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4512. // string str = ex.StackTrace;
  4513. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4514. // }
  4515. // // AGV上料完成信号
  4516. // try
  4517. // {
  4518. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4519. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4520. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4521. // {
  4522. // if (a1AGVUpEnd == 1) // 0->1
  4523. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4524. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4525. // }
  4526. // }
  4527. // catch (Exception ex)
  4528. // {
  4529. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4530. // string str = ex.StackTrace;
  4531. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4532. // }
  4533. // #endregion AGV上料
  4534. // #region AGV下料
  4535. // // AGV下料叫agv信号
  4536. // try
  4537. // {
  4538. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4539. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4540. // if (a1AGVDownCall != a1AGVDownCallOld)
  4541. // {
  4542. // if (a1AGVDownCall == 1) // 0->1
  4543. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4544. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4545. // }
  4546. // }
  4547. // catch (Exception ex)
  4548. // {
  4549. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4550. // string str = ex.StackTrace;
  4551. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4552. // }
  4553. // // AGV下料完成信号
  4554. // try
  4555. // {
  4556. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4557. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4558. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4559. // {
  4560. // if (a1AGVDownEnd == 1) // 0->1
  4561. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4562. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4563. // }
  4564. // }
  4565. // catch (Exception ex)
  4566. // {
  4567. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4568. // string str = ex.StackTrace;
  4569. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4570. // }
  4571. // #endregion AGV下料
  4572. // #region 心跳
  4573. // try
  4574. // {
  4575. // short states = 0;
  4576. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4577. // }
  4578. // catch (Exception ex)
  4579. // {
  4580. // string str = ex.StackTrace;
  4581. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4582. // }
  4583. // #endregion 心跳
  4584. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4585. // stopwatch1.Stop();
  4586. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4587. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4588. // }
  4589. // else
  4590. // {
  4591. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4592. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4593. // Funs[plcNo].Connect(); // 重连
  4594. // }
  4595. // }
  4596. // catch (Exception ex)
  4597. // {
  4598. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4599. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4600. // Funs[plcNo].ReConnect();
  4601. // }
  4602. // Thread.Sleep(IntervalReadPLC);
  4603. // }
  4604. //}
  4605. /// <summary>
  4606. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4607. /// </summary>
  4608. /// <param name="plcNo">PLC编号</param>
  4609. /// <param name="stationNameStr">工站全称</param>
  4610. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4611. {
  4612. Stopwatch stopwatch1 = new Stopwatch();
  4613. Stopwatch stopwatch2 = new Stopwatch();
  4614. try
  4615. {
  4616. stopwatch1.Start();
  4617. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4618. sn = sn.Replace("\0", "");
  4619. #region 查询载具上的产品信息
  4620. string cavityData = string.Empty;
  4621. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4622. if (string.IsNullOrEmpty(cavityData))
  4623. cavityData = "";
  4624. if (snResult != 0)
  4625. {
  4626. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4627. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4628. writeToPLC_Flag1.Adress = 2003;
  4629. writeToPLC_Flag1.Value = (short)6;
  4630. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4631. stopwatch1.Stop();
  4632. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4633. return;
  4634. }
  4635. #endregion 查询载具上的产品信息
  4636. string[] cavitySNs = cavityData.Split('.');
  4637. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4638. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4639. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4640. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4641. if (cavitySNs != null && cavitySNs.Length >= 2)
  4642. {
  4643. a1CavitySN1_VehicleStates = cavitySNs[0];
  4644. a1CavitySN2_VehicleStates = cavitySNs[1];
  4645. a1CavityResult1_VehicleStates = 2;
  4646. a1CavityResult2_VehicleStates = 2;
  4647. }
  4648. if (a1CavitySN1_VehicleStates == "假产品")
  4649. a1CavityResult1_VehicleStates = 3;
  4650. if (a1CavitySN2_VehicleStates == "假产品")
  4651. a1CavityResult2_VehicleStates = 3;
  4652. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4653. // 回写
  4654. stopwatch2.Start();
  4655. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4656. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4657. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4658. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4659. //// MES_Flag
  4660. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4661. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4662. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4663. writeToPLC_Flag.Adress = 2003;
  4664. writeToPLC_Flag.Value = mES_Flag;
  4665. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4666. {
  4667. Name = "a1CavitySN1_VehicleStates",
  4668. Adress = 2024,
  4669. ValueType = PLCValueType.String,
  4670. ValueTypeStrLength = 20,
  4671. Value = a1CavitySN1_VehicleStates
  4672. });
  4673. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4674. {
  4675. Name = "a1CavitySN2_VehicleStates",
  4676. Adress = 2044,
  4677. ValueType = PLCValueType.String,
  4678. ValueTypeStrLength = 20,
  4679. Value = a1CavitySN2_VehicleStates
  4680. });
  4681. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4682. {
  4683. Name = "a1CavityResult1_VehicleStates",
  4684. Adress = 2064,
  4685. ValueType = PLCValueType.Short,
  4686. Value = a1CavityResult1_VehicleStates
  4687. });
  4688. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4689. {
  4690. Name = "a1CavityResult2_VehicleStates",
  4691. Adress = 2065,
  4692. ValueType = PLCValueType.Short,
  4693. Value = a1CavityResult2_VehicleStates
  4694. });
  4695. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4696. stopwatch2.Stop();
  4697. }
  4698. catch (Exception ex)
  4699. {
  4700. string str = ex.StackTrace;
  4701. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4702. // MES_Flag
  4703. stopwatch2.Start();
  4704. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4705. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4706. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4707. writeToPLC_Flag.Adress = 2003;
  4708. writeToPLC_Flag.Value = (short)6;
  4709. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4710. stopwatch2.Stop();
  4711. }
  4712. stopwatch1.Stop();
  4713. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4714. }
  4715. /// <summary>
  4716. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4717. /// </summary>
  4718. /// <param name="plcNo">PLC编号</param>
  4719. /// <param name="stationNameStr">工站全称</param>
  4720. private void S1上料进站校验(int plcNo, string stationNameStr)
  4721. {
  4722. Stopwatch stopwatch1 = new Stopwatch();
  4723. Stopwatch stopwatch2 = new Stopwatch();
  4724. try
  4725. {
  4726. stopwatch1.Start();
  4727. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4728. sn = sn.Replace("\0", "");
  4729. // 保存进站数据+调用进站MES接口
  4730. List<TestItem> item = new List<TestItem>();
  4731. stopwatch2.Start();
  4732. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4733. stopwatch2.Stop();
  4734. short a1MES_FLAG_Check = (short)result;
  4735. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4736. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4737. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4738. writeToPLC_Flag.Adress = 2077;
  4739. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4740. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4741. }
  4742. catch (Exception ex)
  4743. {
  4744. string str = ex.StackTrace;
  4745. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4746. // MES_Flag
  4747. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4748. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4749. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4750. writeToPLC_Flag.Adress = 2077;
  4751. writeToPLC_Flag.Value = (short)6;
  4752. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4753. }
  4754. stopwatch1.Stop();
  4755. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4756. }
  4757. /// <summary>
  4758. /// [S1] Tray盘上料装备(板测)- 出站接口
  4759. /// </summary>
  4760. /// <param name="plcNo"></param>
  4761. /// <param name="stationCode"></param>
  4762. /// <param name="stationName"></param>
  4763. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4764. {
  4765. Stopwatch stopwatch1 = new Stopwatch();
  4766. Stopwatch stopwatch2 = new Stopwatch();
  4767. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4768. string stationNameStr = stationCode + stationName;
  4769. string processItem = stationName; // 测试项目
  4770. try
  4771. {
  4772. stopwatch1.Start();
  4773. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4774. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4775. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4776. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4777. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4778. sn = sn.Replace("\0", "");
  4779. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4780. partNo1 = partNo1.Replace("\0", "");
  4781. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4782. partNo2 = partNo2.Replace("\0", "");
  4783. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4784. bool pass = a1Result == 1;
  4785. stopwatch2.Start();
  4786. // 产品1
  4787. List<TestItem> items = new List<TestItem>();
  4788. items.Add(new TestItem()
  4789. {
  4790. Parameter_name = "载具码",
  4791. Parameter_value = sn,
  4792. Parameter_unit = ""
  4793. });
  4794. items.Add(new TestItem()
  4795. {
  4796. Parameter_name = "载具穴号",
  4797. Parameter_value = "1",
  4798. Parameter_unit = ""
  4799. });
  4800. items.Add(new TestItem()
  4801. {
  4802. Parameter_name = "产品结果",
  4803. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4804. Parameter_unit = ""
  4805. });
  4806. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  4807. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4808. // 产品2
  4809. items = new List<TestItem>();
  4810. items.Add(new TestItem()
  4811. {
  4812. Parameter_name = "载具码",
  4813. Parameter_value = sn,
  4814. Parameter_unit = ""
  4815. });
  4816. items.Add(new TestItem()
  4817. {
  4818. Parameter_name = "载具穴号",
  4819. Parameter_value = "2",
  4820. Parameter_unit = ""
  4821. });
  4822. items.Add(new TestItem()
  4823. {
  4824. Parameter_name = "产品结果",
  4825. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4826. Parameter_unit = ""
  4827. });
  4828. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  4829. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4830. short result = 0;
  4831. List<int> results = new List<int>() { result1, result2 };
  4832. if (result1 == 1 && result2 == 1)
  4833. result = 1;
  4834. else if (results.Contains(3))
  4835. result = 3;
  4836. else if (results.Contains(2))
  4837. result = 2;
  4838. else if (results.Contains(4))
  4839. result = 4;
  4840. else
  4841. result = 4;
  4842. stopwatch2.Stop();
  4843. #region 存储绑定数据到 边线MES系统中
  4844. if (result == 1)
  4845. {
  4846. string data = string.Concat(partNo1, ".", partNo2);
  4847. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4848. if (resultMesR != 0)
  4849. {
  4850. result = 4;
  4851. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4852. }
  4853. }
  4854. #endregion 存储绑定数据到 边线MES系统中
  4855. // MES_Flag 为MES报错
  4856. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4857. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4858. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4859. writeToPLC_Flag.Name = "a1MES_FLAG";
  4860. writeToPLC_Flag.Adress = 2109;
  4861. writeToPLC_Flag.Value = result;
  4862. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4863. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4864. }
  4865. catch (Exception ex)
  4866. {
  4867. stopwatch2.Restart();
  4868. // MES_Flag 为4上位机报错
  4869. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4870. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4871. writeToPLC_Flag.Name = "a1MES_FLAG";
  4872. writeToPLC_Flag.Adress = 2109;
  4873. writeToPLC_Flag.Value = (short)4;
  4874. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4875. stopwatch2.Stop();
  4876. string str = ex.StackTrace;
  4877. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4878. }
  4879. stopwatch1.Stop();
  4880. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4881. }
  4882. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4883. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4884. //{
  4885. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4886. // string stationNameStr = stationCode + stationName;
  4887. // string processItem = stationName; // 测试项目
  4888. // try
  4889. // {
  4890. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4891. // string accno = "1"; // 工序编号
  4892. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4893. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4894. // List<OneCheckItem> items = new List<OneCheckItem>()
  4895. // {
  4896. // new OneCheckItem()
  4897. // {
  4898. // Onecheck_name="胶圈装配行程设定上限",
  4899. // Onecheck_content="上限值",
  4900. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4901. // },
  4902. // };
  4903. // OneCheckData oneCheckData = new OneCheckData()
  4904. // {
  4905. // Line_code = GlobalContext.LineCode,
  4906. // Line_name = GlobalContext.LineName,
  4907. // Equipment_code = equipmentCode,
  4908. // Equipment_name = equipmentCode,
  4909. // Workorder_code = workorder_code,
  4910. // Procedure_code = accno,
  4911. // Procedure_name = processItem,
  4912. // Oneckeck_values = items,
  4913. // Onecheck_empcode = "",
  4914. // Onecheck_empname = "",
  4915. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4916. // };
  4917. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4918. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4919. // short result = result1 == 1 ? (short)1 : (short)2;
  4920. // // MES_Flag 为4MES报错
  4921. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4922. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4923. // }
  4924. // catch (Exception ex)
  4925. // {
  4926. // // MES_Flag 为2上位机报错
  4927. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4928. // string str = ex.StackTrace;
  4929. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4930. // }
  4931. //}
  4932. // ReadStation_S1_2 节拍接口+AGV
  4933. /// <summary>
  4934. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4935. /// </summary>
  4936. /// <param name="plcNo">PLC编号</param>
  4937. /// <param name="stationNameStr">工站全称</param>
  4938. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4939. {
  4940. Stopwatch stopwatch1 = new Stopwatch();
  4941. Stopwatch stopwatch2 = new Stopwatch();
  4942. try
  4943. {
  4944. stopwatch1.Start();
  4945. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4946. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4947. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4948. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4949. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4950. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4951. // ZS 将SN发给ICT标机(串口)
  4952. short a1MES_FLAG_ICT = 1;
  4953. stopwatch2.Start();
  4954. // MES_Flag
  4955. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4956. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4957. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4958. writeToPLC_Flag.Adress = 2182;
  4959. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4960. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4961. stopwatch2.Stop();
  4962. }
  4963. catch (Exception ex)
  4964. {
  4965. string str = ex.StackTrace;
  4966. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4967. stopwatch2.Start();
  4968. // MES_Flag
  4969. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4970. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4971. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4972. writeToPLC_Flag.Adress = 2182;
  4973. writeToPLC_Flag.Value = (short)4;
  4974. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4975. stopwatch2.Stop();
  4976. }
  4977. stopwatch1.Stop();
  4978. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4979. }
  4980. /// <summary>
  4981. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4982. /// </summary>
  4983. /// <param name="plcNo">PLC编号</param>
  4984. /// <param name="stationNameStr">工站全称</param>
  4985. private void S1节拍接口(int plcNo, string stationNameStr)
  4986. {
  4987. Stopwatch stopwatch1 = new Stopwatch();
  4988. Stopwatch stopwatch2 = new Stopwatch();
  4989. string resultStr = string.Empty;
  4990. try
  4991. {
  4992. stopwatch1.Start();
  4993. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4994. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4995. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4996. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4997. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4998. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4999. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  5000. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5001. if (!actionBool)
  5002. {
  5003. stopwatch2.Start();
  5004. // MES_Flag
  5005. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5006. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5007. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  5008. writeToPLC_Flag1.Adress = 2254;
  5009. writeToPLC_Flag1.Value = (short)1;
  5010. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  5011. stopwatch2.Stop();
  5012. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5013. return;
  5014. }
  5015. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  5016. {
  5017. stopwatch2.Start();
  5018. // MES_Flag
  5019. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5020. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  5021. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  5022. writeToPLC_Flag2.Adress = 2254;
  5023. writeToPLC_Flag2.Value = (short)1;
  5024. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  5025. stopwatch2.Stop();
  5026. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5027. return;
  5028. }
  5029. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  5030. { // 查产品SN
  5031. a1OEEPartNo = "Test"; // ZS
  5032. }
  5033. short a1OEEMES_FLAG = 0;
  5034. // 上传OEE
  5035. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  5036. a1OEEMES_FLAG = result.Item1;
  5037. resultStr = result.Item2;
  5038. stopwatch2.Start();
  5039. // MES_Flag
  5040. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5041. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5042. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5043. writeToPLC_Flag.Adress = 2254;
  5044. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  5045. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5046. stopwatch2.Stop();
  5047. }
  5048. catch (Exception ex)
  5049. {
  5050. string str = ex.StackTrace;
  5051. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5052. // MES_Flag
  5053. stopwatch2.Start();
  5054. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  5055. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5056. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5057. writeToPLC_Flag.Adress = 2254;
  5058. writeToPLC_Flag.Value = (short)4;
  5059. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5060. stopwatch2.Stop();
  5061. }
  5062. stopwatch1.Stop();
  5063. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5064. }
  5065. /// <summary>
  5066. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  5067. /// </summary>
  5068. /// <param name="plcNo">PLC编号</param>
  5069. /// <param name="stationNameStr">工站全称</param>
  5070. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  5071. {
  5072. Stopwatch stopwatch1 = new Stopwatch();
  5073. Stopwatch stopwatch2 = new Stopwatch();
  5074. try
  5075. {
  5076. stopwatch1.Start();
  5077. // ZS 呼叫AGV
  5078. short a1AGVUpCall = 2;
  5079. stopwatch2.Start();
  5080. // a1AGVUpCall
  5081. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5082. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5083. writeToPLC_Flag.Name = "a1AGVUpCall";
  5084. writeToPLC_Flag.Adress = 2307;
  5085. writeToPLC_Flag.Value = a1AGVUpCall;
  5086. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5087. stopwatch2.Stop();
  5088. }
  5089. catch (Exception ex)
  5090. {
  5091. string str = ex.StackTrace;
  5092. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5093. // a1AGVUpCall
  5094. stopwatch2.Start();
  5095. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  5096. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5097. writeToPLC_Flag.Name = "a1AGVUpCall";
  5098. writeToPLC_Flag.Adress = 2307;
  5099. writeToPLC_Flag.Value = (short)4;
  5100. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5101. stopwatch2.Stop();
  5102. }
  5103. stopwatch1.Stop();
  5104. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5105. }
  5106. /// <summary>
  5107. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  5108. /// </summary>
  5109. /// <param name="plcNo">PLC编号</param>
  5110. /// <param name="stationNameStr">工站全称</param>
  5111. private void S1AGV上料完成(int plcNo, string stationNameStr)
  5112. {
  5113. Stopwatch stopwatch1 = new Stopwatch();
  5114. Stopwatch stopwatch2 = new Stopwatch();
  5115. try
  5116. {
  5117. stopwatch1.Start();
  5118. // ZS AGV上料完成,让小车离开
  5119. short a1AGVUpEnd = 2;
  5120. stopwatch2.Start();
  5121. // a1AGVUpEnd
  5122. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5123. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5124. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5125. writeToPLC_Flag.Adress = 2309;
  5126. writeToPLC_Flag.Value = a1AGVUpEnd;
  5127. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5128. stopwatch2.Stop();
  5129. }
  5130. catch (Exception ex)
  5131. {
  5132. string str = ex.StackTrace;
  5133. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5134. // a1AGVUpEnd
  5135. stopwatch2.Start();
  5136. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  5137. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5138. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5139. writeToPLC_Flag.Adress = 2309;
  5140. writeToPLC_Flag.Value = (short)4;
  5141. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5142. stopwatch2.Stop();
  5143. }
  5144. stopwatch1.Stop();
  5145. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5146. }
  5147. /// <summary>
  5148. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  5149. /// </summary>
  5150. /// <param name="plcNo">PLC编号</param>
  5151. /// <param name="stationNameStr">工站全称</param>
  5152. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  5153. {
  5154. Stopwatch stopwatch1 = new Stopwatch();
  5155. Stopwatch stopwatch2 = new Stopwatch();
  5156. try
  5157. {
  5158. stopwatch1.Start();
  5159. // ZS 呼叫AGV
  5160. short a1AGVDownCall = 2;
  5161. stopwatch2.Start();
  5162. // a1AGVDownCall
  5163. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5164. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5165. writeToPLC_Flag.Name = "a1AGVDownCall";
  5166. writeToPLC_Flag.Adress = 2320;
  5167. writeToPLC_Flag.Value = a1AGVDownCall;
  5168. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5169. stopwatch2.Stop();
  5170. }
  5171. catch (Exception ex)
  5172. {
  5173. string str = ex.StackTrace;
  5174. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5175. // a1AGVDownCall
  5176. stopwatch2.Start();
  5177. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5178. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5179. writeToPLC_Flag.Name = "a1AGVDownCall";
  5180. writeToPLC_Flag.Adress = 2320;
  5181. writeToPLC_Flag.Value = (short)4;
  5182. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5183. stopwatch2.Stop();
  5184. }
  5185. stopwatch1.Stop();
  5186. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5187. }
  5188. /// <summary>
  5189. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5190. /// </summary>
  5191. /// <param name="plcNo">PLC编号</param>
  5192. /// <param name="stationNameStr">工站全称</param>
  5193. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5194. {
  5195. Stopwatch stopwatch1 = new Stopwatch();
  5196. Stopwatch stopwatch2 = new Stopwatch();
  5197. try
  5198. {
  5199. stopwatch1.Start();
  5200. // ZS AGV上料完成,让小车离开
  5201. short a1AGVDownEnd = 2;
  5202. stopwatch2.Start();
  5203. // a1AGVDownEnd
  5204. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5205. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5206. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5207. writeToPLC_Flag.Adress = 2322;
  5208. writeToPLC_Flag.Value = a1AGVDownEnd;
  5209. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5210. stopwatch2.Stop();
  5211. }
  5212. catch (Exception ex)
  5213. {
  5214. string str = ex.StackTrace;
  5215. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5216. // a1AGVDownEnd
  5217. stopwatch2.Start();
  5218. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5219. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5220. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5221. writeToPLC_Flag.Adress = 2322;
  5222. writeToPLC_Flag.Value = (short)4;
  5223. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5224. stopwatch2.Stop();
  5225. }
  5226. stopwatch1.Stop();
  5227. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5228. }
  5229. #endregion [S1] Tray盘上料装备(板测)
  5230. #endregion PLC1 张超凡
  5231. #region PLC2 李晓奇
  5232. #region [S2] FCT(板测)
  5233. /// <summary>
  5234. /// S2工位的数据- 触发信号上次的值
  5235. /// </summary>
  5236. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5237. /// <summary>
  5238. /// S2工位的数据(含触发信号)
  5239. /// </summary>
  5240. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5241. /// <summary>
  5242. /// S2工位的数据- 回写点位
  5243. /// </summary>
  5244. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5245. /// <summary>
  5246. /// [S2] FCT(板测)
  5247. /// </summary>
  5248. /// <param name="plcNo">PLC编号</param>
  5249. //private void ReadStation_S2(int plcNo)
  5250. //{
  5251. // // [S1] Tray盘上料装备
  5252. // // [S2] FCT
  5253. // // [S3] 值板机
  5254. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5255. // // [S5] Tray盘下料装备
  5256. // /// 上位机心跳
  5257. // /// 获取设备报警数据与状态信息
  5258. // string stationCode = "[S2]";
  5259. // string stationName = "FCT";
  5260. // string stationNameStr = stationCode + stationName;
  5261. // #region 创建字典
  5262. // // 触发信号字典 赋值
  5263. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5264. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5265. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5266. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5267. // // PLC数据字典 赋值
  5268. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5269. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5270. // s2PLCData.Add("b1ProductSN_Check", 0);
  5271. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5272. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5273. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5274. // s2PLCData.Add("b1ProductSN_Bind", "");
  5275. // s2PLCData.Add("b1Part1SN_Bind", "");
  5276. // s2PLCData.Add("b1Part2SN_Bind", "");
  5277. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5278. // s2PLCData.Add("b1MES_FLAG", 0);
  5279. // s2PLCData.Add("b1ProductSN", 0);
  5280. // s2PLCData.Add("b1Part1Result", 0);
  5281. // s2PLCData.Add("b1Part2Result", 0);
  5282. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5283. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5284. // s2PLCData.Add("b1OEEProductSN", "");
  5285. // s2PLCData.Add("b1OEEType", 0);
  5286. // #endregion 创建字典
  5287. // while (IsRun)
  5288. // {
  5289. // try
  5290. // {
  5291. // if (!GlobalContext._IsCon_Funs2)
  5292. // {
  5293. // UpdatePLCMonitor(1, plcNo, 0);
  5294. // continue;
  5295. // }
  5296. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5297. // {
  5298. // Stopwatch stopwatch1 = new Stopwatch();
  5299. // Stopwatch stopwatch2 = new Stopwatch();
  5300. // stopwatch1.Start();
  5301. // stopwatch2.Start();
  5302. // #region 一次性读取所有数据
  5303. // // 一次性读取所有数据
  5304. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5305. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5306. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5307. // int[] datas = data1.Concat(data2).ToArray();
  5308. // datas = datas.Concat(data3).ToArray();
  5309. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5310. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5311. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5312. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5313. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5314. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5315. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5316. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5317. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5318. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5319. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5320. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5321. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5322. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5323. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5324. // s2PLCData["b1MES_FLAG"] = datas[169];
  5325. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5326. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5327. // s2PLCData["b1Part1Result"] = datas[190];
  5328. // s2PLCData["b1Part2Result"] = datas[191];
  5329. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5330. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5331. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5332. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5333. // s2PLCData["b1OEEType"] = datas[224];
  5334. // #endregion 一次性读取所有数据
  5335. // stopwatch2.Stop();
  5336. // #region 回写操作,写后清空flag
  5337. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5338. // #endregion 回写操作,写后清空flag
  5339. // #region 进站校验
  5340. // try
  5341. // {
  5342. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5343. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5344. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5345. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5346. // {
  5347. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5348. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5349. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5350. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5351. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5352. // }
  5353. // }
  5354. // catch (Exception ex)
  5355. // {
  5356. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5357. // string str = ex.StackTrace;
  5358. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5359. // }
  5360. // #endregion 进站校验
  5361. // #region 二穴载具解绑/绑定(产品换载具)
  5362. // try
  5363. // {
  5364. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5365. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5366. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5367. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5368. // {
  5369. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5370. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5371. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5372. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5373. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5374. // }
  5375. // }
  5376. // catch (Exception ex)
  5377. // {
  5378. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5379. // string str = ex.StackTrace;
  5380. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5381. // }
  5382. // #endregion 二穴载具解绑/绑定(产品换载具)
  5383. // #region FCT-出站接口
  5384. // try
  5385. // {
  5386. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5387. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5388. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5389. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5390. // {
  5391. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5392. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5393. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5394. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5395. // }
  5396. // }
  5397. // catch (Exception ex)
  5398. // {
  5399. // // MES_Flag 为6上位机报错
  5400. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5401. // string str = ex.StackTrace;
  5402. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5403. // }
  5404. // #endregion FCT-出站接口
  5405. // #region 节拍接口
  5406. // try
  5407. // {
  5408. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5409. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5410. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5411. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5412. // {
  5413. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5414. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5415. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5416. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5417. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5418. // }
  5419. // }
  5420. // catch (Exception ex)
  5421. // {
  5422. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5423. // string str = ex.StackTrace;
  5424. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5425. // }
  5426. // #endregion 节拍接口
  5427. // #region 心跳
  5428. // try
  5429. // {
  5430. // short states = 0;
  5431. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5432. // }
  5433. // catch (Exception ex)
  5434. // {
  5435. // string str = ex.StackTrace;
  5436. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5437. // }
  5438. // #endregion 心跳
  5439. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5440. // stopwatch1.Stop();
  5441. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5442. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5443. // }
  5444. // else
  5445. // {
  5446. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5447. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5448. // Funs[plcNo].Connect();
  5449. // }
  5450. // }
  5451. // catch (Exception ex)
  5452. // {
  5453. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5454. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5455. // Funs[plcNo].ReConnect();
  5456. // }
  5457. // Thread.Sleep(IntervalReadPLC);
  5458. // }
  5459. //}
  5460. /// <summary>
  5461. /// [S2] FCT(板测)- 进站校验
  5462. /// </summary>
  5463. /// <param name="plcNo">PLC编号</param>
  5464. /// <param name="stationNameStr">工站全称</param>
  5465. private void S2进站校验(int plcNo, string stationNameStr)
  5466. {
  5467. Stopwatch stopwatch1 = new Stopwatch();
  5468. Stopwatch stopwatch2 = new Stopwatch();
  5469. try
  5470. {
  5471. stopwatch1.Start();
  5472. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5473. sn = sn.Replace("\0", "");
  5474. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5475. // 查询物料码By载具码 并判断是不是假产品
  5476. string cavityData = string.Empty;
  5477. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5478. if (string.IsNullOrEmpty(cavityData))
  5479. cavityData = "";
  5480. if (snResult != 0)
  5481. {
  5482. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5483. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5484. writeToPLC_Flag1.Adress = 2003;
  5485. writeToPLC_Flag1.Value = (short)6;
  5486. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5487. stopwatch1.Stop();
  5488. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5489. return;
  5490. }
  5491. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5492. string[] cavitySNs = cavityData.Split('.');
  5493. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5494. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5495. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5496. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5497. if (cavitySNs != null && cavitySNs.Length >= 2)
  5498. {
  5499. b1Part1SN_Check = cavitySNs[0];
  5500. b1Part2SN_Check = cavitySNs[1];
  5501. b1Part1Result_Check = 2;
  5502. b1Part2Result_Check = 2;
  5503. }
  5504. if (b1Part1SN_Check == "假产品")
  5505. b1Part1Result_Check = 3;
  5506. if (b1Part2SN_Check == "假产品")
  5507. b1Part2Result_Check = 3;
  5508. // 调用MES进站
  5509. stopwatch2.Start();
  5510. // 调用MES进站 - 产品1
  5511. List<TestItem> item;
  5512. int result1 = b1Part1Result_Check;
  5513. if (result1 != 3)
  5514. {
  5515. item = new List<TestItem>();
  5516. item.Add(new TestItem()
  5517. {
  5518. Parameter_name = "载具码",
  5519. Parameter_value = sn,
  5520. });
  5521. item.Add(new TestItem()
  5522. {
  5523. Parameter_name = "载具穴号",
  5524. Parameter_value = "1",
  5525. });
  5526. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5527. }
  5528. // 调用MES进站 - 产品2
  5529. int result2 = b1Part2Result_Check;
  5530. if (result2 != 3)
  5531. {
  5532. item = new List<TestItem>();
  5533. item.Add(new TestItem()
  5534. {
  5535. Parameter_name = "载具码",
  5536. Parameter_value = sn,
  5537. });
  5538. item.Add(new TestItem()
  5539. {
  5540. Parameter_name = "载具穴号",
  5541. Parameter_value = "2",
  5542. });
  5543. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5544. }
  5545. stopwatch2.Stop();
  5546. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5547. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5548. int result = result1;
  5549. if (result == 1)
  5550. result = result2;
  5551. short b1MES_FLAG_Check = (short)result;
  5552. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5553. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5554. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5555. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5556. //// MES_Flag
  5557. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5558. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5559. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5560. writeToPLC_Flag.Adress = 2003;
  5561. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5562. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5563. {
  5564. Name = "b1Part1SN_Check",
  5565. Adress = 2024,
  5566. ValueType = PLCValueType.String,
  5567. ValueTypeStrLength = 20,
  5568. Value = b1Part1SN_Check
  5569. });
  5570. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5571. {
  5572. Name = "b1Part2SN_Check",
  5573. Adress = 2044,
  5574. ValueType = PLCValueType.String,
  5575. ValueTypeStrLength = 20,
  5576. Value = b1Part2SN_Check
  5577. });
  5578. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5579. {
  5580. Name = "b1Part1Result_Check",
  5581. Adress = 2064,
  5582. ValueType = PLCValueType.Short,
  5583. Value = b1Part1Result_Check
  5584. });
  5585. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5586. {
  5587. Name = "b1Part2Result_Check",
  5588. Adress = 2065,
  5589. ValueType = PLCValueType.Short,
  5590. Value = b1Part2Result_Check
  5591. });
  5592. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5593. }
  5594. catch (Exception ex)
  5595. {
  5596. string str = ex.StackTrace;
  5597. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5598. // MES_Flag
  5599. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5600. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5601. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5602. writeToPLC_Flag.Adress = 2003;
  5603. writeToPLC_Flag.Value = (short)6;
  5604. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5605. }
  5606. stopwatch1.Stop();
  5607. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5608. }
  5609. /// <summary>
  5610. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5611. /// </summary>
  5612. /// <param name="plcNo">PLC编号</param>
  5613. /// <param name="stationNameStr">工站全称</param>
  5614. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5615. {
  5616. Stopwatch stopwatch1 = new Stopwatch();
  5617. Stopwatch stopwatch2 = new Stopwatch();
  5618. try
  5619. {
  5620. stopwatch1.Start();
  5621. // 产品换载具
  5622. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5623. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5624. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5625. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5626. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5627. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5628. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5629. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5630. stopwatch2.Start();
  5631. #region 查询载具上的产品信息
  5632. //string cavityData = string.Empty;
  5633. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5634. //if (string.IsNullOrEmpty(cavityData))
  5635. // cavityData = "";
  5636. //if (snResult != 0)
  5637. //{
  5638. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5639. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5640. // writeToPLC_Flag.Adress = 2077;
  5641. // writeToPLC_Flag.Value = (short)6;
  5642. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5643. // stopwatch1.Stop();
  5644. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5645. // return;
  5646. //}
  5647. #endregion 查询载具上的产品信息
  5648. #region 解绑(边线MES系统)
  5649. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5650. if (snResult != 0)
  5651. {
  5652. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5653. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5654. writeToPLC_Flag1.Adress = 2077;
  5655. writeToPLC_Flag1.Value = (short)6;
  5656. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5657. stopwatch1.Stop();
  5658. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5659. return;
  5660. }
  5661. #endregion 解绑(边线MES系统)
  5662. #region 存储绑定数据到 边线MES系统中
  5663. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5664. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5665. if (snResult != 0)
  5666. {
  5667. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5668. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5669. writeToPLC_Flag1.Adress = 2077;
  5670. writeToPLC_Flag1.Value = (short)6;
  5671. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5672. stopwatch1.Stop();
  5673. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5674. return;
  5675. }
  5676. #endregion 存储绑定数据到 边线MES系统中
  5677. stopwatch2.Stop();
  5678. short b1MES_FLAG_Unbind = 1;
  5679. // MES_Flag
  5680. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5681. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5682. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5683. writeToPLC_Flag.Adress = 2077;
  5684. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5685. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5686. }
  5687. catch (Exception ex)
  5688. {
  5689. string str = ex.StackTrace;
  5690. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5691. // MES_Flag
  5692. stopwatch2.Start();
  5693. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5694. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5695. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5696. writeToPLC_Flag.Adress = 2077;
  5697. writeToPLC_Flag.Value = (short)6;
  5698. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5699. stopwatch2.Stop();
  5700. }
  5701. stopwatch1.Stop();
  5702. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5703. }
  5704. //// 上次采集到的SN
  5705. //private string sn_FCT = string.Empty;
  5706. /// <summary>
  5707. /// [S2] FCT(板测)- 出站数据
  5708. /// </summary>
  5709. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5710. {
  5711. Stopwatch stopwatch1 = new Stopwatch();
  5712. Stopwatch stopwatch2 = new Stopwatch();
  5713. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5714. string stationNameStr = stationCode + stationName;
  5715. string processItem = stationName; // 测试项目
  5716. try
  5717. {
  5718. stopwatch1.Start();
  5719. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5720. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5721. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5722. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5723. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5724. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5725. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5726. bool pass1 = b1Part1Result == 1;
  5727. bool pass2 = b1Part2Result == 1;
  5728. #region 根据 载具SN 查 物料SN
  5729. string cavityData = string.Empty;
  5730. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5731. if (string.IsNullOrEmpty(cavityData))
  5732. cavityData = "";
  5733. if (snResult != 0)
  5734. {
  5735. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5736. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5737. writeToPLC_Flag1.Adress = 2169;
  5738. writeToPLC_Flag1.Value = (short)4;
  5739. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5740. stopwatch1.Stop();
  5741. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5742. return;
  5743. }
  5744. #endregion 根据 载具SN 查 物料SN
  5745. string[] cavitySNs = cavityData.Split('.');
  5746. string b1ProductSN1 = string.Empty;
  5747. string b1ProductSN2 = string.Empty;
  5748. if (cavitySNs != null && cavitySNs.Length >= 2)
  5749. {
  5750. b1ProductSN1 = cavitySNs[0];
  5751. b1ProductSN2 = cavitySNs[1];
  5752. }
  5753. stopwatch2.Start();
  5754. // 产品1
  5755. int result1 = 0;
  5756. if (b1ProductSN1 == "假产品")
  5757. result1 = 1;
  5758. else
  5759. {
  5760. List<TestItem> items1 = new List<TestItem>();
  5761. items1.Add(new TestItem()
  5762. {
  5763. Parameter_name = "载具码",
  5764. Parameter_value = b1ProductSN.ToString(),
  5765. Parameter_unit = ""
  5766. });
  5767. items1.Add(new TestItem()
  5768. {
  5769. Parameter_name = "载具穴号",
  5770. Parameter_value = "1",
  5771. Parameter_unit = ""
  5772. });
  5773. items1.Add(new TestItem()
  5774. {
  5775. Parameter_name = "产品结果",
  5776. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5777. Parameter_unit = ""
  5778. });
  5779. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  5780. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5781. }
  5782. // 产品2
  5783. int result2 = 0;
  5784. if (b1ProductSN1 == "假产品")
  5785. result2 = 1;
  5786. else
  5787. {
  5788. List<TestItem> items2 = new List<TestItem>();
  5789. items2.Add(new TestItem()
  5790. {
  5791. Parameter_name = "载具码",
  5792. Parameter_value = b1ProductSN.ToString(),
  5793. Parameter_unit = ""
  5794. });
  5795. items2.Add(new TestItem()
  5796. {
  5797. Parameter_name = "载具穴号",
  5798. Parameter_value = "2",
  5799. Parameter_unit = ""
  5800. });
  5801. items2.Add(new TestItem()
  5802. {
  5803. Parameter_name = "产品结果",
  5804. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5805. Parameter_unit = ""
  5806. });
  5807. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  5808. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5809. }
  5810. short result = 0;
  5811. List<int> results = new List<int>() { result1, result2 };
  5812. if (result1 == 1 && result2 == 1)
  5813. result = 1;
  5814. else if (results.Contains(3))
  5815. result = 3;
  5816. else if (results.Contains(2))
  5817. result = 2;
  5818. else if (results.Contains(4))
  5819. result = 4;
  5820. else
  5821. result = 4;
  5822. stopwatch2.Stop();
  5823. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5824. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5825. writeToPLC_Flag.Name = "b1MES_FLAG";
  5826. writeToPLC_Flag.Adress = 2169;
  5827. writeToPLC_Flag.Value = result;
  5828. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5829. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5830. }
  5831. catch (Exception ex)
  5832. {
  5833. stopwatch2.Restart();
  5834. // MES_Flag 为4上位机报错
  5835. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5836. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5837. writeToPLC_Flag.Name = "b1MES_FLAG";
  5838. writeToPLC_Flag.Adress = 2169;
  5839. writeToPLC_Flag.Value = (short)4;
  5840. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5841. stopwatch2.Stop();
  5842. string str = ex.StackTrace;
  5843. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5844. }
  5845. stopwatch1.Stop();
  5846. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5847. }
  5848. /// <summary>
  5849. /// [S2] FCT(板测)- 节拍接口
  5850. /// </summary>
  5851. /// <param name="plcNo">PLC编号</param>
  5852. /// <param name="stationNameStr">工站全称</param>
  5853. private void S2节拍接口(int plcNo, string stationNameStr)
  5854. {
  5855. Stopwatch stopwatch1 = new Stopwatch();
  5856. Stopwatch stopwatch2 = new Stopwatch();
  5857. string resultStr = string.Empty;
  5858. try
  5859. {
  5860. stopwatch1.Start();
  5861. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5862. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5863. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5864. if (!actionBool)
  5865. {
  5866. stopwatch2.Start();
  5867. // MES_Flag
  5868. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5869. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5870. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5871. writeToPLC_Flag1.Adress = 2203;
  5872. writeToPLC_Flag1.Value = (short)4;
  5873. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5874. stopwatch2.Stop();
  5875. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5876. return;
  5877. }
  5878. string b1OEEPartNo = string.Empty; // 物料码
  5879. if (string.IsNullOrEmpty(b1OEEProductSN))
  5880. {
  5881. stopwatch2.Start();
  5882. // MES_Flag
  5883. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5884. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5885. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5886. writeToPLC_Flag1.Adress = 2203;
  5887. writeToPLC_Flag1.Value = (short)1;
  5888. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5889. stopwatch2.Stop();
  5890. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5891. return;
  5892. }
  5893. else
  5894. { // 查产品SN
  5895. b1OEEPartNo = "Test"; // ZS
  5896. }
  5897. short b1OEEMES_FLAG = 0;
  5898. // 上传OEE
  5899. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5900. b1OEEMES_FLAG = result.Item1;
  5901. resultStr = result.Item2;
  5902. stopwatch2.Start();
  5903. // MES_Flag
  5904. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5905. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5906. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5907. writeToPLC_Flag.Adress = 2203;
  5908. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5909. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5910. stopwatch2.Stop();
  5911. }
  5912. catch (Exception ex)
  5913. {
  5914. string str = ex.StackTrace;
  5915. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5916. // MES_Flag
  5917. stopwatch2.Start();
  5918. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5919. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5920. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5921. writeToPLC_Flag.Adress = 2203;
  5922. writeToPLC_Flag.Value = (short)4;
  5923. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5924. stopwatch2.Stop();
  5925. }
  5926. stopwatch1.Stop();
  5927. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5928. }
  5929. #endregion [S2] FCT(板测)
  5930. #endregion PLC2 李晓奇
  5931. #region PLC3 刘永村
  5932. #region [S3] 值板机
  5933. /// <summary>
  5934. /// S3工位的数据- 触发信号上次的值
  5935. /// </summary>
  5936. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5937. /// <summary>
  5938. /// S3工位的数据(含触发信号)
  5939. /// </summary>
  5940. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5941. /// <summary>
  5942. /// S3工位的数据- 回写点位
  5943. /// </summary>
  5944. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5945. /// <summary>
  5946. /// [S3] 值板机
  5947. /// </summary>
  5948. /// <param name="plcNo">PLC编号</param>
  5949. //private void ReadStation_S3(int plcNo)
  5950. //{
  5951. // // [S1] Tray盘上料装备
  5952. // // [S2] FCT
  5953. // // [S3] 值板机
  5954. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5955. // // [S5] Tray盘下料装备
  5956. // /// 上位机心跳
  5957. // /// 获取设备报警数据与状态信息
  5958. // string stationCode = "[S3]";
  5959. // string stationName = "值板机";
  5960. // string stationNameStr = stationCode + stationName;
  5961. // #region 创建字典
  5962. // // 触发信号字典 赋值
  5963. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5964. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5965. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5966. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5967. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5968. // // PLC数据字典 赋值
  5969. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5970. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5971. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5972. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5973. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5974. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5975. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5976. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5977. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5978. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5979. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5980. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5981. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5982. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5983. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5984. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5985. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5986. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5987. // s3PLCData.Add("c1Result", 0); // 产品结果
  5988. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5989. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5990. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5991. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  5992. // #endregion 创建字典
  5993. // while (IsRun)
  5994. // {
  5995. // try
  5996. // {
  5997. // if (!GlobalContext._IsCon_Funs3)
  5998. // {
  5999. // UpdatePLCMonitor(1, plcNo, 0);
  6000. // continue;
  6001. // }
  6002. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6003. // {
  6004. // Stopwatch stopwatch1 = new Stopwatch();
  6005. // Stopwatch stopwatch2 = new Stopwatch();
  6006. // stopwatch1.Start();
  6007. // stopwatch2.Start();
  6008. // #region 一次性读取所有数据
  6009. // // 一次性读取所有数据
  6010. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  6011. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6012. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6013. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  6014. // int[] datas = data1.Concat(data2).ToArray();
  6015. // datas = datas.Concat(data3).ToArray();
  6016. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  6017. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  6018. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  6019. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  6020. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  6021. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  6022. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6023. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  6024. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  6025. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  6026. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6027. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6028. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  6029. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  6030. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  6031. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  6032. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6033. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  6034. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  6035. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  6036. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  6037. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  6038. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  6039. // #endregion 一次性读取所有数据
  6040. // stopwatch2.Stop();
  6041. // #region 回写操作,写后清空flag
  6042. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  6043. // #endregion 回写操作,写后清空flag
  6044. // #region S3进站校验
  6045. // try
  6046. // {
  6047. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  6048. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  6049. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  6050. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  6051. // {
  6052. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  6053. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6054. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  6055. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6056. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  6057. // }
  6058. // }
  6059. // catch (Exception ex)
  6060. // {
  6061. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6062. // string str = ex.StackTrace;
  6063. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6064. // }
  6065. // #endregion S3进站校验
  6066. // #region S3二穴载具解绑
  6067. // try
  6068. // {
  6069. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  6070. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  6071. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  6072. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  6073. // {
  6074. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6075. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  6076. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  6077. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  6078. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  6079. // }
  6080. // }
  6081. // catch (Exception ex)
  6082. // {
  6083. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  6084. // string str = ex.StackTrace;
  6085. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6086. // }
  6087. // #endregion S3二穴载具解绑
  6088. // #region S3二穴载具绑定
  6089. // try
  6090. // {
  6091. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  6092. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  6093. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  6094. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  6095. // {
  6096. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6097. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  6098. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  6099. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  6100. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  6101. // }
  6102. // }
  6103. // catch (Exception ex)
  6104. // {
  6105. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6106. // string str = ex.StackTrace;
  6107. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6108. // }
  6109. // #endregion S3二穴载具绑定
  6110. // #region S3出站接口(+一穴载具绑定)
  6111. // try
  6112. // {
  6113. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  6114. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  6115. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  6116. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  6117. // {
  6118. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  6119. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6120. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  6121. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  6122. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  6123. // }
  6124. // }
  6125. // catch (Exception ex)
  6126. // {
  6127. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  6128. // string str = ex.StackTrace;
  6129. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6130. // }
  6131. // #endregion S3出站接口(+一穴载具绑定)
  6132. // #region S3节拍接口
  6133. // try
  6134. // {
  6135. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  6136. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  6137. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  6138. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  6139. // {
  6140. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  6141. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6142. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  6143. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  6144. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  6145. // }
  6146. // }
  6147. // catch (Exception ex)
  6148. // {
  6149. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6150. // string str = ex.StackTrace;
  6151. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6152. // }
  6153. // #endregion S3节拍接口
  6154. // #region 心跳
  6155. // try
  6156. // {
  6157. // short states = 0;
  6158. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6159. // }
  6160. // catch (Exception ex)
  6161. // {
  6162. // string str = ex.StackTrace;
  6163. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6164. // }
  6165. // #endregion 心跳
  6166. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6167. // stopwatch1.Stop();
  6168. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6169. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6170. // }
  6171. // else
  6172. // {
  6173. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6174. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6175. // Funs[plcNo].Connect();
  6176. // }
  6177. // }
  6178. // catch (Exception ex)
  6179. // {
  6180. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6181. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6182. // Funs[plcNo].ReConnect();
  6183. // }
  6184. // Thread.Sleep(IntervalReadPLC);
  6185. // }
  6186. //}
  6187. /// <summary>
  6188. /// [S3] 值板机- 进站校验
  6189. /// </summary>
  6190. /// <param name="plcNo">PLC编号</param>
  6191. /// <param name="stationNameStr">工站全称</param>
  6192. private void S3进站校验(int plcNo, string stationNameStr)
  6193. {
  6194. Stopwatch stopwatch1 = new Stopwatch();
  6195. Stopwatch stopwatch2 = new Stopwatch();
  6196. try
  6197. {
  6198. stopwatch1.Start();
  6199. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6200. sn = sn.Replace("\0", "");
  6201. #region 查询载具上的产品信息
  6202. string cavityData = string.Empty;
  6203. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6204. if (string.IsNullOrEmpty(cavityData))
  6205. cavityData = "";
  6206. if (snResult != 0)
  6207. {
  6208. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6209. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6210. writeToPLC_Flag1.Adress = 2003;
  6211. writeToPLC_Flag1.Value = (short)6;
  6212. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6213. stopwatch1.Stop();
  6214. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6215. return;
  6216. }
  6217. #endregion 查询载具上的产品信息
  6218. string[] cavitySNs = cavityData.Split('.');
  6219. string part1Str = ""; // 产品1的SN码
  6220. string part2Str = ""; // 产品2的SN码
  6221. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6222. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6223. if (cavitySNs != null && cavitySNs.Length >= 2)
  6224. {
  6225. part1Str = cavitySNs[0];
  6226. part2Str = cavitySNs[1];
  6227. c1Part1Result_Check = 2;
  6228. c1Part2Result_Check = 2;
  6229. }
  6230. if (part1Str == "假产品")
  6231. c1Part1Result_Check = 3;
  6232. if (part2Str == "假产品")
  6233. c1Part2Result_Check = 3;
  6234. // 调用MES进站
  6235. stopwatch2.Start();
  6236. // 调用MES进站 - 产品1
  6237. List<TestItem> item;
  6238. int result1 = c1Part1Result_Check;
  6239. if (result1 != 3)
  6240. {
  6241. item = new List<TestItem>();
  6242. item.Add(new TestItem()
  6243. {
  6244. Parameter_name = "载具码",
  6245. Parameter_value = sn,
  6246. });
  6247. item.Add(new TestItem()
  6248. {
  6249. Parameter_name = "载具穴号",
  6250. Parameter_value = "1",
  6251. });
  6252. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6253. }
  6254. // 调用MES进站 - 产品2
  6255. int result2 = c1Part2Result_Check;
  6256. if (result2 != 3)
  6257. {
  6258. item = new List<TestItem>();
  6259. item.Add(new TestItem()
  6260. {
  6261. Parameter_name = "载具码",
  6262. Parameter_value = sn,
  6263. });
  6264. item.Add(new TestItem()
  6265. {
  6266. Parameter_name = "载具穴号",
  6267. Parameter_value = "2",
  6268. });
  6269. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6270. }
  6271. stopwatch2.Stop();
  6272. if (result1 == 2)
  6273. c1Part1Result_Check = 2;
  6274. if (result2 == 2)
  6275. c1Part2Result_Check = 2;
  6276. int result = result1;
  6277. if (result == 1)
  6278. result = result2;
  6279. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6280. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6281. short c1MES_FLAG_Check = (short)result;
  6282. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6283. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6284. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6285. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6286. //// MES_Flag
  6287. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6288. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6289. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6290. writeToPLC_Flag.Adress = 2003;
  6291. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6292. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6293. {
  6294. Name = "c1Part1Result_Check",
  6295. Adress = 2024,
  6296. ValueType = PLCValueType.Short,
  6297. Value = c1Part1Result_Check
  6298. });
  6299. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6300. {
  6301. Name = "c1Part2Result_Check",
  6302. Adress = 2025,
  6303. ValueType = PLCValueType.Short,
  6304. Value = c1Part2Result_Check
  6305. });
  6306. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6307. {
  6308. Name = "c1Part1Num_Check",
  6309. Adress = 2026,
  6310. ValueType = PLCValueType.Short,
  6311. Value = c1Part1Num_Check
  6312. });
  6313. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6314. {
  6315. Name = "c1Part2Num_Check",
  6316. Adress = 2027,
  6317. ValueType = PLCValueType.Short,
  6318. Value = c1Part2Num_Check
  6319. });
  6320. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6321. }
  6322. catch (Exception ex)
  6323. {
  6324. string str = ex.StackTrace;
  6325. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6326. // MES_Flag
  6327. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6328. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6329. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6330. writeToPLC_Flag.Adress = 2003;
  6331. writeToPLC_Flag.Value = (short)6;
  6332. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6333. }
  6334. stopwatch1.Stop();
  6335. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6336. }
  6337. /// <summary>
  6338. /// [S3] 值板机 - 二穴载具解绑
  6339. /// </summary>
  6340. /// <param name="plcNo">PLC编号</param>
  6341. /// <param name="stationNameStr">工站全称</param>
  6342. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6343. {
  6344. Stopwatch stopwatch1 = new Stopwatch();
  6345. Stopwatch stopwatch2 = new Stopwatch();
  6346. try
  6347. {
  6348. stopwatch1.Start();
  6349. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6350. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6351. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6352. // 解绑
  6353. #region 查询载具上的产品信息
  6354. string cavityData = string.Empty;
  6355. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6356. if (string.IsNullOrEmpty(cavityData))
  6357. cavityData = "";
  6358. if (snResult != 0)
  6359. {
  6360. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6361. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6362. writeToPLC_Flag1.Adress = 2082;
  6363. writeToPLC_Flag1.Value = (short)6;
  6364. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6365. stopwatch1.Stop();
  6366. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6367. return;
  6368. }
  6369. #endregion 查询载具上的产品信息
  6370. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6371. #region 解绑
  6372. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6373. {
  6374. // 删除
  6375. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6376. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6377. }
  6378. else
  6379. {
  6380. string data_new = string.Join(".", cavitySNs);
  6381. // 删除再插入
  6382. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6383. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6384. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6385. }
  6386. #endregion 解绑
  6387. short c1MES_FLAG_Unbind = 1;
  6388. stopwatch2.Start();
  6389. // MES_Flag
  6390. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6391. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6392. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6393. writeToPLC_Flag.Adress = 2082;
  6394. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6395. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6396. stopwatch2.Stop();
  6397. }
  6398. catch (Exception ex)
  6399. {
  6400. string str = ex.StackTrace;
  6401. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6402. // MES_Flag
  6403. stopwatch2.Start();
  6404. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6405. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6406. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6407. writeToPLC_Flag.Adress = 2082;
  6408. writeToPLC_Flag.Value = (short)6;
  6409. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6410. stopwatch2.Stop();
  6411. }
  6412. stopwatch1.Stop();
  6413. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6414. }
  6415. /// <summary>
  6416. /// [S3] 值板机 - 二穴载具绑定
  6417. /// </summary>
  6418. /// <param name="plcNo">PLC编号</param>
  6419. /// <param name="stationNameStr">工站全称</param>
  6420. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6421. {
  6422. Stopwatch stopwatch1 = new Stopwatch();
  6423. Stopwatch stopwatch2 = new Stopwatch();
  6424. try
  6425. {
  6426. stopwatch1.Start();
  6427. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6428. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6429. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6430. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6431. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6432. stopwatch2.Start();
  6433. #region 查询载具上的产品信息
  6434. string cavityData = string.Empty;
  6435. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6436. if (string.IsNullOrEmpty(cavityData))
  6437. cavityData = "";
  6438. if (snResult != 0)
  6439. {
  6440. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6441. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6442. writeToPLC_Flag1.Adress = 2115;
  6443. writeToPLC_Flag1.Value = (short)6;
  6444. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6445. stopwatch1.Stop();
  6446. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6447. return;
  6448. }
  6449. #endregion 查询载具上的产品信息
  6450. // 产品换载具
  6451. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6452. string partSn1 = "";
  6453. string partSn2 = "";
  6454. if (cavitySNs != null && cavitySNs.Length >= 2)
  6455. {
  6456. partSn1 = cavitySNs[0];
  6457. partSn2 = cavitySNs[1];
  6458. }
  6459. string data_new = string.Empty;
  6460. // 是否是两个穴位交换
  6461. if (c1CavityReverse_Bind == 1)
  6462. {
  6463. // 交换
  6464. data_new = string.Concat(partSn2, ".", partSn1);
  6465. }
  6466. else
  6467. { // 不交换
  6468. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6469. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6470. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6471. data_new = string.Join(".", cavitySNs);
  6472. }
  6473. // 删除再插入
  6474. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6475. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6476. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6477. stopwatch2.Stop();
  6478. short c1MES_FLAG_Bind = 1;
  6479. // MES_Flag
  6480. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6481. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6482. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6483. writeToPLC_Flag.Adress = 2115;
  6484. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6485. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6486. }
  6487. catch (Exception ex)
  6488. {
  6489. string str = ex.StackTrace;
  6490. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6491. // MES_Flag
  6492. stopwatch2.Start();
  6493. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6494. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6495. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6496. writeToPLC_Flag.Adress = 2115;
  6497. writeToPLC_Flag.Value = (short)6;
  6498. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6499. stopwatch2.Stop();
  6500. }
  6501. stopwatch1.Stop();
  6502. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6503. }
  6504. //// 上次采集到的SN
  6505. //private string sn_值板机 = string.Empty;
  6506. /// <summary>
  6507. /// [S3] 值板机 - 出站接口
  6508. /// </summary>
  6509. /// <param name="plcNo">PLC编号</param>
  6510. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6511. {
  6512. Stopwatch stopwatch1 = new Stopwatch();
  6513. Stopwatch stopwatch2 = new Stopwatch();
  6514. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6515. string stationNameStr = stationCode + stationName;
  6516. string processItem = stationName; // 测试项目
  6517. try
  6518. {
  6519. stopwatch1.Start();
  6520. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6521. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6522. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6523. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6524. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6525. sn = sn.Replace("\0", "");
  6526. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6527. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6528. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6529. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6530. bool pass = c1Result == 1;
  6531. // 查sn
  6532. #region 查询载具上的产品信息
  6533. string cavityData = string.Empty;
  6534. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6535. if (string.IsNullOrEmpty(cavityData))
  6536. cavityData = "";
  6537. if (snResult != 0)
  6538. {
  6539. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6540. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6541. writeToPLC_Flag1.Adress = 2150;
  6542. writeToPLC_Flag1.Value = (short)4;
  6543. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6544. stopwatch1.Stop();
  6545. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6546. return;
  6547. }
  6548. #endregion 查询载具上的产品信息
  6549. string[] cavitySNs = cavityData.Split('.');
  6550. string productSN = "";
  6551. if (cavitySNs != null && cavitySNs.Length >= 2)
  6552. {
  6553. productSN = cavitySNs[c1VehicleCavity];
  6554. cavitySNs[c1VehicleCavity] = "";
  6555. }
  6556. stopwatch2.Start();
  6557. List<TestItem> items = new List<TestItem>();
  6558. items.Add(new TestItem()
  6559. {
  6560. Parameter_name = "二穴载具码",
  6561. Parameter_value = c1ProductSN_Check,
  6562. Parameter_unit = ""
  6563. });
  6564. items.Add(new TestItem()
  6565. {
  6566. Parameter_name = "二穴载具穴号",
  6567. Parameter_value = c1VehicleCavity.ToString(),
  6568. Parameter_unit = ""
  6569. });
  6570. items.Add(new TestItem()
  6571. {
  6572. Parameter_name = "一穴载具码",
  6573. Parameter_value = sn,
  6574. Parameter_unit = ""
  6575. });
  6576. items.Add(new TestItem()
  6577. {
  6578. Parameter_name = "一穴载具穴号",
  6579. Parameter_value = "1",
  6580. Parameter_unit = ""
  6581. });
  6582. items.Add(new TestItem()
  6583. {
  6584. Parameter_name = "产品结果",
  6585. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6586. Parameter_unit = ""
  6587. });
  6588. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  6589. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6590. short result = (short)result1;
  6591. stopwatch2.Stop();
  6592. #region 存储绑定数据到 边线MES系统中
  6593. if (result == 1)
  6594. {
  6595. string data = string.Concat(productSN);
  6596. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6597. if (resultMesR != 0)
  6598. {
  6599. result = 4;
  6600. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6601. }
  6602. }
  6603. #endregion 存储绑定数据到 边线MES系统中
  6604. #region 产品从 来源载具(二穴载具)中删除
  6605. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6606. {
  6607. // 删除
  6608. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6609. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6610. }
  6611. else
  6612. {
  6613. string data_new = string.Join(".", cavitySNs);
  6614. // 删除再插入
  6615. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6616. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6617. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6618. }
  6619. #endregion 产品从 来源载具(二穴载具)中删除
  6620. // MES_Flag 为MES报错
  6621. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6622. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6623. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6624. writeToPLC_Flag.Name = "c1MES_FLAG";
  6625. writeToPLC_Flag.Adress = 2150;
  6626. writeToPLC_Flag.Value = result;
  6627. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6628. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6629. }
  6630. catch (Exception ex)
  6631. {
  6632. stopwatch2.Restart();
  6633. // MES_Flag 为4上位机报错
  6634. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6635. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6636. writeToPLC_Flag.Name = "c1MES_FLAG";
  6637. writeToPLC_Flag.Adress = 2150;
  6638. writeToPLC_Flag.Value = (short)4;
  6639. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6640. stopwatch2.Stop();
  6641. string str = ex.StackTrace;
  6642. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6643. }
  6644. stopwatch1.Stop();
  6645. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6646. }
  6647. /// <summary>
  6648. /// [S3] 值板机- 节拍接口
  6649. /// </summary>
  6650. /// <param name="plcNo">PLC编号</param>
  6651. /// <param name="stationNameStr">工站全称</param>
  6652. private void S3节拍接口(int plcNo, string stationNameStr)
  6653. {
  6654. Stopwatch stopwatch1 = new Stopwatch();
  6655. Stopwatch stopwatch2 = new Stopwatch();
  6656. string resultStr = string.Empty;
  6657. try
  6658. {
  6659. stopwatch1.Start();
  6660. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6661. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6662. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6663. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6664. if (!actionBool)
  6665. {
  6666. stopwatch2.Start();
  6667. // MES_Flag
  6668. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6669. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6670. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6671. writeToPLC_Flag1.Adress = 2204;
  6672. writeToPLC_Flag1.Value = (short)4;
  6673. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6674. stopwatch2.Stop();
  6675. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6676. return;
  6677. }
  6678. string c1OEEPartNo = string.Empty; // 物料码
  6679. if (string.IsNullOrEmpty(c1OEEProductSN))
  6680. {
  6681. stopwatch2.Start();
  6682. // MES_Flag
  6683. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6684. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6685. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6686. writeToPLC_Flag1.Adress = 2204;
  6687. writeToPLC_Flag1.Value = (short)1;
  6688. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6689. stopwatch2.Stop();
  6690. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6691. return;
  6692. }
  6693. else
  6694. { // 查产品SN
  6695. c1OEEPartNo = "Test"; // ZS
  6696. }
  6697. short c1OEEMES_FLAG = 0;
  6698. // 上传OEE
  6699. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6700. c1OEEMES_FLAG = result.Item1;
  6701. resultStr = result.Item2;
  6702. stopwatch2.Start();
  6703. // MES_Flag
  6704. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6705. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6706. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6707. writeToPLC_Flag.Adress = 2204;
  6708. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6709. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6710. stopwatch2.Stop();
  6711. }
  6712. catch (Exception ex)
  6713. {
  6714. string str = ex.StackTrace;
  6715. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6716. // MES_Flag
  6717. stopwatch2.Start();
  6718. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6719. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6720. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6721. writeToPLC_Flag.Adress = 2204;
  6722. writeToPLC_Flag.Value = (short)4;
  6723. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6724. stopwatch2.Stop();
  6725. }
  6726. stopwatch1.Stop();
  6727. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6728. }
  6729. #endregion [S3] 值板机
  6730. #endregion PLC3 刘永村
  6731. #region PLC4 刘果段
  6732. #region [S4] 取放桁架
  6733. /// <summary>
  6734. /// S4工位的数据- 触发信号上次的值
  6735. /// </summary>
  6736. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6737. /// <summary>
  6738. /// S4工位的数据(含触发信号)
  6739. /// </summary>
  6740. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6741. /// <summary>
  6742. /// S4工位的数据- 回写点位
  6743. /// </summary>
  6744. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6745. /// <summary>
  6746. /// [S4] 取放桁架
  6747. /// </summary>
  6748. /// <param name="plcNo">PLC编号</param>
  6749. //private void ReadStation_S4(int plcNo)
  6750. //{
  6751. // // [S1] Tray盘上料装备
  6752. // // [S2] FCT
  6753. // // [S3] 值板机
  6754. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6755. // // [S5] Tray盘下料装备
  6756. // /// 上位机心跳
  6757. // /// 获取设备报警数据与状态信息
  6758. // string stationCode = "[S4_1]";
  6759. // string stationName = "载具下线装备";
  6760. // string stationNameStr = stationCode + stationName;
  6761. // string stationCode2 = "[S4_2]";
  6762. // string stationName2 = "桁架";
  6763. // string stationNameStr2 = stationCode2 + stationName2;
  6764. // string stationCode3 = "[S4_3]";
  6765. // string stationName3 = "提升机1";
  6766. // string stationNameStr3 = stationCode3 + stationName3;
  6767. // string stationCode4 = "[S4_4]";
  6768. // string stationName4 = "提升机2";
  6769. // string stationNameStr4 = stationCode4 + stationName4;
  6770. // string stationCode5 = "[S4_5]";
  6771. // string stationName5 = "载具上线装备";
  6772. // string stationNameStr5 = stationCode5 + stationName5;
  6773. // #region 创建字典
  6774. // // 触发信号字典 赋值
  6775. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6776. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6777. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6778. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6779. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6780. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6781. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6782. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6783. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6784. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6785. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6786. // // PLC数据字典 赋值
  6787. // // 载具下线装备(弹夹上线)
  6788. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6789. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6790. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6791. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6792. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6793. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6794. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6795. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6796. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6797. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6798. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6799. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6800. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6801. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6802. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6803. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6804. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6805. // s4PLCData.Add("d1Result", 0); // 产品结果
  6806. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6807. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6808. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6809. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6810. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6811. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6812. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6813. // // 真空标机(提升机)
  6814. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6815. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6816. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6817. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6818. // s4PLCData.Add("d3Result", 0); // 产品结果
  6819. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6820. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6821. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6822. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6823. // s4PLCData.Add("d4Result", 0); // 产品结果
  6824. // // 载具上线装备(弹夹下线)
  6825. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6826. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6827. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6828. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6829. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6830. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6831. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6832. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6833. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6834. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6835. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6836. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6837. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6838. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6839. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6840. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6841. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6842. // s4PLCData.Add("d5Result", 0); // 产品结果
  6843. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6844. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6845. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6846. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6847. // #endregion 创建字典
  6848. // while (IsRun)
  6849. // {
  6850. // try
  6851. // {
  6852. // if (!GlobalContext._IsCon_Funs4)
  6853. // {
  6854. // UpdatePLCMonitor(1, plcNo, 0);
  6855. // continue;
  6856. // }
  6857. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6858. // {
  6859. // Stopwatch stopwatch1 = new Stopwatch();
  6860. // Stopwatch stopwatch2 = new Stopwatch();
  6861. // stopwatch1.Start();
  6862. // stopwatch2.Start();
  6863. // #region 一次性读取所有数据
  6864. // // 载具下线装备(弹夹上线)
  6865. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6866. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6867. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6868. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6869. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6870. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6871. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6872. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6873. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6874. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6875. // int[] datas = data1.Concat(data2).ToArray();
  6876. // datas = datas.Concat(data3).ToArray();
  6877. // datas = datas.Concat(data4).ToArray();
  6878. // datas = datas.Concat(data5).ToArray();
  6879. // datas = datas.Concat(data6).ToArray();
  6880. // datas = datas.Concat(data7).ToArray();
  6881. // datas = datas.Concat(data8).ToArray();
  6882. // datas = datas.Concat(data9).ToArray();
  6883. // datas = datas.Concat(data10).ToArray();
  6884. // // 载具下线装备(弹夹上线)
  6885. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6886. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6887. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6888. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6889. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6890. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6891. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6892. // s4PLCData["d1MES_FLAG"] = datas[65];
  6893. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6894. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6895. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6896. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6897. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6898. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6899. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6900. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6901. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6902. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6903. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6904. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6905. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6906. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6907. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6908. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6909. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6910. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6911. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6912. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6913. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6914. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6915. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6916. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6917. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6918. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6919. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6920. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6921. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6922. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6923. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6924. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6925. // s4PLCData["d1Result"] = datas[386];
  6926. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6927. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6928. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6929. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6930. // s4PLCData["d1OEEType"] = datas[419];
  6931. // // 桁架(查询标机中弹夹的状态)
  6932. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6933. // s4PLCData["d2BulletclipStates"] = datas[431];
  6934. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6935. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6936. // // 真空标机
  6937. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6938. // s4PLCData["d3MES_FLAG"] = datas[463];
  6939. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6940. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6941. // s4PLCData["d3Result"] = datas[484];
  6942. // s4PLCData["d3Type"] = datas[485];
  6943. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6944. // s4PLCData["d4MES_FLAG"] = datas[496];
  6945. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6946. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6947. // s4PLCData["d4Result"] = datas[517];
  6948. // s4PLCData["d4Type"] = datas[518];
  6949. // // 载具上线装备(弹夹下线)
  6950. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6951. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6952. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6953. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6954. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6955. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6956. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6957. // s4PLCData["d5MES_FLAG"] = datas[591];
  6958. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6959. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6960. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6961. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6962. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6963. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6964. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6965. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6966. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6967. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6968. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6969. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6970. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6971. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6972. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6973. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6974. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6975. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6976. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6977. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6978. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6979. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6980. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6981. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6982. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6983. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6984. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6985. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6986. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6987. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6988. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6989. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6990. // s4PLCData["d5Result"] = datas[912];
  6991. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  6992. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  6993. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  6994. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  6995. // s4PLCData["d5OEEType"] = datas[945];
  6996. // #endregion 一次性读取所有数据
  6997. // stopwatch2.Stop();
  6998. // #region 回写操作,写后清空flag
  6999. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  7000. // #endregion 回写操作,写后清空flag
  7001. // // N801A-S4_1 弹夹扫码
  7002. // #region N801A-S4_1 弹夹扫码
  7003. // try
  7004. // {
  7005. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  7006. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  7007. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  7008. // {
  7009. // if (d1BulletclipScanCode == 1) // 0->1
  7010. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  7011. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  7012. // }
  7013. // }
  7014. // catch (Exception ex)
  7015. // {
  7016. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7017. // string str = ex.StackTrace;
  7018. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7019. // }
  7020. // #endregion N801A-S4_1 弹夹扫码
  7021. // // N801A-S4_1 载具扫码
  7022. // #region N801A-S4_1 载具扫码
  7023. // try
  7024. // {
  7025. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  7026. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  7027. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  7028. // {
  7029. // if (d1VehicleScanCode == 1) // 0->1
  7030. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  7031. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  7032. // }
  7033. // }
  7034. // catch (Exception ex)
  7035. // {
  7036. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7037. // string str = ex.StackTrace;
  7038. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7039. // }
  7040. // #endregion N801A-S4_1 载具扫码
  7041. // // N801A-S4_1 出站接口
  7042. // #region N801A-S4_1 出站接口
  7043. // try
  7044. // {
  7045. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  7046. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  7047. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  7048. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  7049. // {
  7050. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  7051. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7052. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  7053. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  7054. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  7055. // }
  7056. // }
  7057. // catch (Exception ex)
  7058. // {
  7059. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  7060. // string str = ex.StackTrace;
  7061. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7062. // }
  7063. // #endregion N801A-S4_1 出站接口
  7064. // // N801A-S4_1 节拍接口
  7065. // #region N801A-S4_1 节拍接口
  7066. // try
  7067. // {
  7068. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  7069. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  7070. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  7071. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  7072. // {
  7073. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  7074. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7075. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  7076. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  7077. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  7078. // }
  7079. // }
  7080. // catch (Exception ex)
  7081. // {
  7082. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7083. // string str = ex.StackTrace;
  7084. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7085. // }
  7086. // #endregion N801A-S4_1 节拍接口
  7087. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  7088. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  7089. // try
  7090. // {
  7091. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  7092. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  7093. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  7094. // {
  7095. // if (d2BulletclipScanCode == 1) // 0->1
  7096. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  7097. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  7098. // }
  7099. // }
  7100. // catch (Exception ex)
  7101. // {
  7102. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7103. // string str = ex.StackTrace;
  7104. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7105. // }
  7106. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  7107. // // N801A-S4_3 真空标机1 数据
  7108. // #region N801A-S4_3 真空标机1
  7109. // try
  7110. // {
  7111. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  7112. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  7113. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  7114. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  7115. // {
  7116. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  7117. // {
  7118. // int stationType = (int)s4PLCData["d3Type"];
  7119. // if (stationType == 1)
  7120. // {
  7121. // // S4_3进站接口
  7122. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  7123. // }
  7124. // else if (stationType == 2)
  7125. // {
  7126. // // S4_3出站接口
  7127. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  7128. // }
  7129. // }
  7130. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  7131. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  7132. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  7133. // }
  7134. // }
  7135. // catch (Exception ex)
  7136. // {
  7137. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7138. // string str = ex.StackTrace;
  7139. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7140. // }
  7141. // #endregion N801A-S4_3 真空标机1
  7142. // // N801A-S4_4 真空标机2 数据
  7143. // #region N801A-S4_4 真空标机2
  7144. // try
  7145. // {
  7146. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  7147. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  7148. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  7149. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  7150. // {
  7151. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  7152. // {
  7153. // int stationType = (int)s4PLCData["d4Type"];
  7154. // if (stationType == 1)
  7155. // {
  7156. // // S4_4进站接口
  7157. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  7158. // }
  7159. // else if (stationType == 2)
  7160. // {
  7161. // // S4_4出站接口
  7162. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  7163. // }
  7164. // }
  7165. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  7166. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  7167. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  7168. // }
  7169. // }
  7170. // catch (Exception ex)
  7171. // {
  7172. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7173. // string str = ex.StackTrace;
  7174. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7175. // }
  7176. // #endregion N801A-S4_4 真空标机2
  7177. // // N801A-S4_5 弹夹扫码 数据
  7178. // #region N801A-S4_5 弹夹扫码
  7179. // try
  7180. // {
  7181. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7182. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7183. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7184. // {
  7185. // if (d5BulletclipScanCode == 1) // 0->1
  7186. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7187. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7188. // }
  7189. // }
  7190. // catch (Exception ex)
  7191. // {
  7192. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7193. // string str = ex.StackTrace;
  7194. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7195. // }
  7196. // #endregion N801A-S4_5 弹夹扫码
  7197. // // N801A-S4_5 载具扫码 数据
  7198. // #region N801A-S4_5 载具扫码
  7199. // try
  7200. // {
  7201. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7202. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7203. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7204. // {
  7205. // if (d5VehicleScanCode == 1) // 0->1
  7206. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7207. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7208. // }
  7209. // }
  7210. // catch (Exception ex)
  7211. // {
  7212. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7213. // string str = ex.StackTrace;
  7214. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7215. // }
  7216. // #endregion N801A-S4_5 载具扫码
  7217. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7218. // #region N801A-S4_5 出站接口
  7219. // try
  7220. // {
  7221. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7222. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7223. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7224. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7225. // {
  7226. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7227. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7228. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7229. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7230. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7231. // }
  7232. // }
  7233. // catch (Exception ex)
  7234. // {
  7235. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7236. // string str = ex.StackTrace;
  7237. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7238. // }
  7239. // #endregion N801A-S4_5 出站接口
  7240. // // N801A-S4_5 节拍接口 数据
  7241. // #region N801A-S4_5 节拍接口
  7242. // try
  7243. // {
  7244. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7245. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7246. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7247. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7248. // {
  7249. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7250. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7251. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7252. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7253. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7254. // }
  7255. // }
  7256. // catch (Exception ex)
  7257. // {
  7258. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7259. // string str = ex.StackTrace;
  7260. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7261. // }
  7262. // #endregion N801A-S4_5 节拍接口
  7263. // #region 心跳
  7264. // try
  7265. // {
  7266. // short states = 0;
  7267. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7268. // }
  7269. // catch (Exception ex)
  7270. // {
  7271. // string str = ex.StackTrace;
  7272. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7273. // }
  7274. // #endregion 心跳
  7275. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7276. // stopwatch1.Stop();
  7277. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7278. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7279. // }
  7280. // else
  7281. // {
  7282. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7283. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7284. // Funs[plcNo].Connect();
  7285. // }
  7286. // }
  7287. // catch (Exception ex)
  7288. // {
  7289. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7290. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7291. // Funs[plcNo].ReConnect();
  7292. // }
  7293. // Thread.Sleep(IntervalReadPLC);
  7294. // }
  7295. //}
  7296. /// <summary>
  7297. /// [S4] 取放桁架 - S4_1弹夹扫码
  7298. /// </summary>
  7299. /// <param name="plcNo">PLC编号</param>
  7300. /// <param name="stationNameStr">工站全称</param>
  7301. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7302. {
  7303. Stopwatch stopwatch1 = new Stopwatch();
  7304. Stopwatch stopwatch2 = new Stopwatch();
  7305. try
  7306. {
  7307. stopwatch1.Start();
  7308. // ZS 弹夹扫码
  7309. string d1BulletclipCode = " "; // 扫到的码
  7310. short d1BulletclipScanCode = 2;
  7311. stopwatch2.Start();
  7312. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7313. //// MES_Flag
  7314. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7315. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7316. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7317. writeToPLC_Flag.Adress = 2002;
  7318. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7319. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7320. {
  7321. Name = "d1BulletclipCode",
  7322. Adress = 2003,
  7323. ValueType = PLCValueType.String,
  7324. ValueTypeStrLength = 20,
  7325. Value = d1BulletclipCode
  7326. });
  7327. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7328. stopwatch2.Stop();
  7329. }
  7330. catch (Exception ex)
  7331. {
  7332. string str = ex.StackTrace;
  7333. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7334. stopwatch2.Start();
  7335. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7336. //// MES_Flag
  7337. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7338. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7339. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7340. writeToPLC_Flag.Adress = 2002;
  7341. writeToPLC_Flag.Value = (short)6;
  7342. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7343. {
  7344. Name = "d1BulletclipCode",
  7345. Adress = 2003,
  7346. ValueType = PLCValueType.String,
  7347. ValueTypeStrLength = 20,
  7348. Value = " "
  7349. });
  7350. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7351. stopwatch2.Stop();
  7352. }
  7353. stopwatch1.Stop();
  7354. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7355. }
  7356. /// <summary>
  7357. /// [S4] 取放桁架 - S4_1载具扫码
  7358. /// </summary>
  7359. /// <param name="plcNo">PLC编号</param>
  7360. /// <param name="stationNameStr">工站全称</param>
  7361. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7362. {
  7363. Stopwatch stopwatch1 = new Stopwatch();
  7364. Stopwatch stopwatch2 = new Stopwatch();
  7365. try
  7366. {
  7367. stopwatch1.Start();
  7368. // ZS 载具扫码
  7369. string d1VehicleCode = ""; // 扫到的码
  7370. short d1VehicleScanCode = 2;
  7371. #region 进站
  7372. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7373. {
  7374. #region 查询载具上的产品信息
  7375. string cavityData = string.Empty;
  7376. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7377. if (string.IsNullOrEmpty(cavityData))
  7378. cavityData = "";
  7379. if (snResult != 0)
  7380. {
  7381. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7382. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7383. writeToPLC_Flag1.Adress = 2033;
  7384. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7385. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7386. {
  7387. Name = "d1VehicleCode",
  7388. Adress = 2034,
  7389. ValueType = PLCValueType.String,
  7390. ValueTypeStrLength = 20,
  7391. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7392. });
  7393. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7394. stopwatch1.Stop();
  7395. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7396. return;
  7397. }
  7398. string[] cavitySNs = cavityData.Split('.');
  7399. string partNo = "";
  7400. if (cavitySNs != null && cavitySNs.Length >= 1)
  7401. {
  7402. partNo = cavitySNs[0];
  7403. }
  7404. #endregion 查询载具上的产品信息
  7405. List<TestItem> item = new List<TestItem>();
  7406. item.Add(new TestItem()
  7407. {
  7408. Parameter_name = "载具码",
  7409. Parameter_value = d1VehicleCode,
  7410. });
  7411. item.Add(new TestItem()
  7412. {
  7413. Parameter_name = "载具穴号",
  7414. Parameter_value = "1",
  7415. });
  7416. stopwatch2.Start();
  7417. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7418. stopwatch2.Stop();
  7419. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7420. }
  7421. #endregion 进站
  7422. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7423. //// MES_Flag
  7424. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7425. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7426. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7427. writeToPLC_Flag.Adress = 2033;
  7428. writeToPLC_Flag.Value = d1VehicleScanCode;
  7429. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7430. {
  7431. Name = "d1VehicleCode",
  7432. Adress = 2034,
  7433. ValueType = PLCValueType.String,
  7434. ValueTypeStrLength = 20,
  7435. Value = d1VehicleCode
  7436. });
  7437. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7438. }
  7439. catch (Exception ex)
  7440. {
  7441. string str = ex.StackTrace;
  7442. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7443. stopwatch2.Start();
  7444. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7445. //// MES_Flag
  7446. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7447. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7448. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7449. writeToPLC_Flag.Adress = 2033;
  7450. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7451. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7452. {
  7453. Name = "d1VehicleCode",
  7454. Adress = 2034,
  7455. ValueType = PLCValueType.String,
  7456. ValueTypeStrLength = 20,
  7457. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7458. });
  7459. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7460. stopwatch2.Stop();
  7461. }
  7462. stopwatch1.Stop();
  7463. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7464. }
  7465. // 上次采集到的SN
  7466. //private string sn_S4_1出站接口 = string.Empty;
  7467. /// <summary>
  7468. /// [S4] 取放桁架 - S4_1出站接口
  7469. /// </summary>
  7470. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7471. {
  7472. Stopwatch stopwatch1 = new Stopwatch();
  7473. Stopwatch stopwatch2 = new Stopwatch();
  7474. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7475. string stationNameStr = stationCode + stationName;
  7476. string processItem = stationName; // 测试项目
  7477. try
  7478. {
  7479. stopwatch1.Start();
  7480. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7481. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7482. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7483. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7484. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7485. sn = sn.Replace("\0", "");
  7486. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7487. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7488. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7489. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7490. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7491. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7492. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7493. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7494. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7495. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7496. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7497. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7498. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7499. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7500. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7501. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7502. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7503. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7504. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7505. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7506. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7507. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7508. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7509. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7510. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7511. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7512. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7513. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7514. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7515. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7516. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7517. bool pass = d1Result == 1;
  7518. // 存 载具SN列表
  7519. List<string> vehicleCodes = new List<string>()
  7520. {
  7521. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7522. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7523. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7524. };
  7525. // 统一查 产品SN列表
  7526. List<string> partNos = new List<string>();
  7527. foreach (string vehicleCode in vehicleCodes)
  7528. {
  7529. if (string.IsNullOrEmpty(vehicleCode))
  7530. partNos.Add("");
  7531. else
  7532. {
  7533. string partNo = "";
  7534. #region 查询载具上的产品信息
  7535. string cavityData = string.Empty;
  7536. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7537. if (string.IsNullOrEmpty(cavityData))
  7538. cavityData = "";
  7539. if (snResult != 0)
  7540. {
  7541. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7542. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7543. writeToPLC_Flag1.Adress = 2065;
  7544. writeToPLC_Flag1.Value = (short)4;
  7545. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7546. stopwatch1.Stop();
  7547. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7548. return;
  7549. }
  7550. string[] cavitySNs = cavityData.Split('.');
  7551. if (cavitySNs != null && cavitySNs.Length >= 1)
  7552. partNo = cavitySNs[0];
  7553. #endregion 查询载具上的产品信息
  7554. partNos.Add(partNo);
  7555. }
  7556. }
  7557. // 统一上传
  7558. stopwatch2.Start();
  7559. List<int> results = new List<int>();
  7560. for (int i = 0; i < partNos.Count; i++)
  7561. {
  7562. string index = (i + 1).ToString(); // 弹夹穴号
  7563. if (string.IsNullOrEmpty(partNos[i]))
  7564. results.Add(1);
  7565. else
  7566. {
  7567. List<TestItem> items1 = new List<TestItem>();
  7568. items1.Add(new TestItem()
  7569. {
  7570. Parameter_name = "弹夹码",
  7571. Parameter_value = sn,
  7572. Parameter_unit = ""
  7573. });
  7574. items1.Add(new TestItem()
  7575. {
  7576. Parameter_name = "弹夹穴号",
  7577. Parameter_value = index,
  7578. Parameter_unit = ""
  7579. });
  7580. items1.Add(new TestItem()
  7581. {
  7582. Parameter_name = "载具码",
  7583. Parameter_value = vehicleCodes[i],
  7584. Parameter_unit = ""
  7585. });
  7586. items1.Add(new TestItem()
  7587. {
  7588. Parameter_name = "载具穴号",
  7589. Parameter_value = "1",
  7590. Parameter_unit = ""
  7591. });
  7592. items1.Add(new TestItem()
  7593. {
  7594. Parameter_name = "产品结果",
  7595. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7596. Parameter_unit = ""
  7597. });
  7598. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  7599. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7600. results.Add(result1);
  7601. }
  7602. }
  7603. short result = 0;
  7604. if (results.All(a => a == 1))
  7605. result = 1;
  7606. else if (results.Contains(3))
  7607. result = 3;
  7608. else if (results.Contains(2))
  7609. result = 2;
  7610. else if (results.Contains(4))
  7611. result = 4;
  7612. else
  7613. result = 4;
  7614. stopwatch2.Stop();
  7615. #region 存储绑定数据到 边线MES系统中
  7616. if (result == 1)
  7617. {
  7618. string data = string.Join(".", vehicleCodes);
  7619. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7620. if (resultMesR != 0)
  7621. {
  7622. result = 4;
  7623. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7624. }
  7625. }
  7626. #endregion 存储绑定数据到 边线MES系统中
  7627. // MES_Flag 为4MES报错
  7628. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7629. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7630. writeToPLC_Flag.Name = "d1MES_FLAG";
  7631. writeToPLC_Flag.Adress = 2065;
  7632. writeToPLC_Flag.Value = result;
  7633. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7634. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7635. }
  7636. catch (Exception ex)
  7637. {
  7638. stopwatch2.Restart();
  7639. // MES_Flag 为4上位机报错
  7640. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7641. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7642. writeToPLC_Flag.Name = "d1MES_FLAG";
  7643. writeToPLC_Flag.Adress = 2065;
  7644. writeToPLC_Flag.Value = (short)4;
  7645. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7646. stopwatch2.Stop();
  7647. string str = ex.StackTrace;
  7648. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7649. }
  7650. stopwatch1.Stop();
  7651. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7652. }
  7653. /// <summary>
  7654. /// [S4] 取放桁架 - S4_1节拍接口
  7655. /// </summary>
  7656. /// <param name="plcNo">PLC编号</param>
  7657. /// <param name="stationNameStr">工站全称</param>
  7658. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7659. {
  7660. Stopwatch stopwatch1 = new Stopwatch();
  7661. Stopwatch stopwatch2 = new Stopwatch();
  7662. string resultStr = string.Empty;
  7663. try
  7664. {
  7665. stopwatch1.Start();
  7666. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7667. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7668. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7669. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7670. if (!actionBool)
  7671. {
  7672. stopwatch2.Start();
  7673. // MES_Flag
  7674. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7675. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7676. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7677. writeToPLC_Flag1.Adress = 2398;
  7678. writeToPLC_Flag1.Value = (short)4;
  7679. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7680. stopwatch2.Stop();
  7681. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7682. return;
  7683. }
  7684. string d1OEEPartNo = string.Empty; // 物料码
  7685. if (string.IsNullOrEmpty(d1OEEProductSN))
  7686. {
  7687. stopwatch2.Start();
  7688. // MES_Flag
  7689. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7690. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7691. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7692. writeToPLC_Flag1.Adress = 2398;
  7693. writeToPLC_Flag1.Value = (short)1;
  7694. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7695. stopwatch2.Stop();
  7696. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7697. return;
  7698. }
  7699. else
  7700. { // 查产品SN ZS
  7701. d1OEEPartNo = "Test";
  7702. }
  7703. short d1OEEMES_FLAG = 0;
  7704. // 上传OEE
  7705. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7706. d1OEEMES_FLAG = result.Item1;
  7707. resultStr = result.Item2;
  7708. stopwatch2.Start();
  7709. // MES_Flag
  7710. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7711. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7712. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7713. writeToPLC_Flag.Adress = 2398;
  7714. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7715. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7716. stopwatch2.Stop();
  7717. }
  7718. catch (Exception ex)
  7719. {
  7720. string str = ex.StackTrace;
  7721. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7722. // MES_Flag
  7723. stopwatch2.Start();
  7724. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7725. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7726. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7727. writeToPLC_Flag.Adress = 2398;
  7728. writeToPLC_Flag.Value = (short)4;
  7729. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7730. stopwatch2.Stop();
  7731. }
  7732. stopwatch1.Stop();
  7733. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7734. }
  7735. /// <summary>
  7736. /// [S4] 取放桁架 - S4_2桁架
  7737. /// </summary>
  7738. /// <param name="plcNo">PLC编号</param>
  7739. /// <param name="stationNameStr">工站全称</param>
  7740. private void S4_2桁架(int plcNo, string stationNameStr)
  7741. {
  7742. Stopwatch stopwatch1 = new Stopwatch();
  7743. Stopwatch stopwatch2 = new Stopwatch();
  7744. try
  7745. {
  7746. stopwatch1.Start();
  7747. // ZS 弹夹扫码
  7748. string d2BulletclipCode = " "; // 扫到的码
  7749. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7750. short d2BulletclipScanCode = 2;
  7751. stopwatch2.Start();
  7752. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7753. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7754. //// MES_Flag
  7755. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7756. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7757. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7758. writeToPLC_Flag.Adress = 2430;
  7759. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7760. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7761. {
  7762. Name = "d2BulletclipCode",
  7763. Adress = 2432,
  7764. ValueType = PLCValueType.String,
  7765. ValueTypeStrLength = 20,
  7766. Value = d2BulletclipCode
  7767. });
  7768. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7769. {
  7770. Name = "d2BulletclipStates",
  7771. Adress = 2431,
  7772. ValueType = PLCValueType.Short,
  7773. Value = d2BulletclipStates
  7774. });
  7775. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7776. stopwatch2.Stop();
  7777. }
  7778. catch (Exception ex)
  7779. {
  7780. string str = ex.StackTrace;
  7781. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7782. stopwatch2.Start();
  7783. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7784. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7785. // MES_Flag
  7786. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7787. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7788. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7789. writeToPLC_Flag.Adress = 2430;
  7790. writeToPLC_Flag.Value = (short)6;
  7791. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7792. {
  7793. Name = "d2BulletclipCode",
  7794. Adress = 2432,
  7795. ValueType = PLCValueType.String,
  7796. ValueTypeStrLength = 20,
  7797. Value = " "
  7798. });
  7799. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7800. {
  7801. Name = "d2BulletclipStates",
  7802. Adress = 2431,
  7803. ValueType = PLCValueType.Short,
  7804. Value = (short)0
  7805. });
  7806. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7807. stopwatch2.Stop();
  7808. }
  7809. stopwatch1.Stop();
  7810. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7811. }
  7812. // 上次采集到的SN
  7813. //private string sn_S4_3进站接口 = string.Empty;
  7814. /// <summary>
  7815. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7816. /// </summary>
  7817. private void S4_3进站接口(int plcNo, string stationNameStr)
  7818. {
  7819. Stopwatch stopwatch1 = new Stopwatch();
  7820. Stopwatch stopwatch2 = new Stopwatch();
  7821. try
  7822. {
  7823. stopwatch1.Start();
  7824. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7825. sn = sn.Replace("\0", "");
  7826. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7827. #region 查询15个载具码
  7828. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7829. string vehicleData = string.Empty;
  7830. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7831. if (string.IsNullOrEmpty(vehicleData))
  7832. vehicleData = "";
  7833. if (snResult != 0)
  7834. {
  7835. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7836. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7837. writeToPLC_Flag1.Adress = 2463;
  7838. writeToPLC_Flag1.Value = (short)4;
  7839. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7840. stopwatch1.Stop();
  7841. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7842. return;
  7843. }
  7844. string[] cavitySNs = vehicleData.Split('.');
  7845. if (cavitySNs != null && cavitySNs.Length > 0)
  7846. {
  7847. for (int i = 0; i < cavitySNs.Length; i++)
  7848. {
  7849. if (string.IsNullOrEmpty(cavitySNs[i]))
  7850. vehicleCodes.Add("");
  7851. else
  7852. vehicleCodes.Add(cavitySNs[i]);
  7853. }
  7854. }
  7855. #endregion 查询15个载具码
  7856. #region 查询15个产品SN
  7857. List<string> portNos = new List<string>(); // 15个产品SN
  7858. foreach (string vehicleCode in vehicleCodes)
  7859. {
  7860. if (string.IsNullOrEmpty(vehicleCode))
  7861. portNos.Add("");
  7862. else
  7863. {
  7864. // 查询
  7865. string cavityData = string.Empty;
  7866. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7867. if (string.IsNullOrEmpty(cavityData))
  7868. cavityData = "";
  7869. if (snResult1 != 0)
  7870. {
  7871. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7872. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7873. writeToPLC_Flag1.Adress = 2463;
  7874. writeToPLC_Flag1.Value = (short)4;
  7875. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7876. stopwatch1.Stop();
  7877. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7878. return;
  7879. }
  7880. string[] partSNs = cavityData.Split('.');
  7881. if (partSNs != null && partSNs.Length >= 1)
  7882. portNos.Add(partSNs[0]);
  7883. else
  7884. portNos.Add("");
  7885. }
  7886. }
  7887. #endregion 查询15个产品SN
  7888. // 调用MES进站(最多15个)
  7889. stopwatch2.Start();
  7890. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7891. for (int i = 0; i < vehicleCodes.Count; i++)
  7892. {
  7893. // 循环进站
  7894. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7895. {
  7896. // 产品SN(物料码)校验
  7897. string portNo = portNos[i];
  7898. List<TestItem> item = new List<TestItem>();
  7899. item.Add(new TestItem()
  7900. {
  7901. Parameter_name = "弹夹码",
  7902. Parameter_value = sn,
  7903. });
  7904. item.Add(new TestItem()
  7905. {
  7906. Parameter_name = "弹夹穴位",
  7907. Parameter_value = (i + 1).ToString(),
  7908. });
  7909. item.Add(new TestItem()
  7910. {
  7911. Parameter_name = "载具码",
  7912. Parameter_value = vehicleCodes[i],
  7913. });
  7914. item.Add(new TestItem()
  7915. {
  7916. Parameter_name = "载具穴号",
  7917. Parameter_value = "1",
  7918. });
  7919. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7920. }
  7921. }
  7922. stopwatch2.Stop();
  7923. short result = 0;
  7924. bool haveMesWarn = results.Contains(5);
  7925. bool havePCWarn = results.Contains(6);
  7926. if (haveMesWarn)
  7927. result = 2; // 5->2
  7928. else if (havePCWarn)
  7929. result = 6; // 6->4
  7930. else
  7931. result = 1;
  7932. // MES_Flag 为4MES报错
  7933. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7934. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7935. writeToPLC_Flag.Name = "d3MES_FLAG";
  7936. writeToPLC_Flag.Adress = 2463;
  7937. writeToPLC_Flag.Value = result;
  7938. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7939. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7940. }
  7941. catch (Exception ex)
  7942. {
  7943. stopwatch2.Stop();
  7944. // MES_Flag 为4上位机报错
  7945. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7946. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7947. writeToPLC_Flag.Name = "d3MES_FLAG";
  7948. writeToPLC_Flag.Adress = 2463;
  7949. writeToPLC_Flag.Value = (short)4;
  7950. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7951. string str = ex.StackTrace;
  7952. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7953. }
  7954. stopwatch1.Stop();
  7955. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7956. }
  7957. // 上次采集到的SN
  7958. //private string sn_S4_3出站接口 = string.Empty;
  7959. /// <summary>
  7960. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7961. /// </summary>
  7962. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7963. {
  7964. Stopwatch stopwatch1 = new Stopwatch();
  7965. Stopwatch stopwatch2 = new Stopwatch();
  7966. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7967. string stationNameStr = stationCode + stationName;
  7968. string processItem = stationName; // 测试项目
  7969. try
  7970. {
  7971. stopwatch1.Start();
  7972. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7973. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7974. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7975. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7976. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7977. sn = sn.Replace("\0", "");
  7978. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7979. bool isPass = d3Result == 1; // 产品结果 bool
  7980. #region 查询15个载具码
  7981. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7982. string vehicleData = string.Empty;
  7983. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7984. if (string.IsNullOrEmpty(vehicleData))
  7985. vehicleData = "";
  7986. if (snResult1 != 0)
  7987. {
  7988. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7989. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7990. writeToPLC_Flag1.Adress = 2463;
  7991. writeToPLC_Flag1.Value = (short)4;
  7992. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7993. stopwatch1.Stop();
  7994. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7995. return;
  7996. }
  7997. string[] cavitySNs = vehicleData.Split('.');
  7998. if (cavitySNs != null && cavitySNs.Length > 0)
  7999. {
  8000. for (int i = 0; i < cavitySNs.Length; i++)
  8001. {
  8002. if (string.IsNullOrEmpty(cavitySNs[i]))
  8003. vehicleCodes.Add("");
  8004. else
  8005. vehicleCodes.Add(cavitySNs[i]);
  8006. }
  8007. }
  8008. #endregion 查询15个载具码
  8009. // 统一查 产品SN列表
  8010. List<string> partNos = new List<string>();
  8011. foreach (string vehicleCode in vehicleCodes)
  8012. {
  8013. if (string.IsNullOrEmpty(vehicleCode))
  8014. partNos.Add("");
  8015. else
  8016. {
  8017. string partNo = "";
  8018. #region 查询载具上的产品信息
  8019. string cavityData = string.Empty;
  8020. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8021. if (string.IsNullOrEmpty(cavityData))
  8022. cavityData = "";
  8023. if (snResult != 0)
  8024. {
  8025. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8026. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8027. writeToPLC_Flag1.Adress = 2463;
  8028. writeToPLC_Flag1.Value = (short)4;
  8029. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8030. stopwatch1.Stop();
  8031. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8032. return;
  8033. }
  8034. string[] partSNs = cavityData.Split('.');
  8035. if (partSNs != null && partSNs.Length >= 1)
  8036. partNo = partSNs[0];
  8037. #endregion 查询载具上的产品信息
  8038. partNos.Add(partNo);
  8039. }
  8040. }
  8041. // 统一上传 - 调用MES出站
  8042. stopwatch2.Start();
  8043. List<int> results = new List<int>();
  8044. for (int i = 0; i < partNos.Count; i++)
  8045. {
  8046. string index = (i + 1).ToString(); // 弹夹穴号
  8047. if (string.IsNullOrEmpty(partNos[i]))
  8048. results.Add(1);
  8049. else
  8050. {
  8051. List<TestItem> items1 = new List<TestItem>();
  8052. items1.Add(new TestItem()
  8053. {
  8054. Parameter_name = "弹夹码",
  8055. Parameter_value = sn,
  8056. Parameter_unit = ""
  8057. });
  8058. items1.Add(new TestItem()
  8059. {
  8060. Parameter_name = "弹夹穴号",
  8061. Parameter_value = index,
  8062. Parameter_unit = ""
  8063. });
  8064. items1.Add(new TestItem()
  8065. {
  8066. Parameter_name = "载具码",
  8067. Parameter_value = vehicleCodes[i],
  8068. Parameter_unit = ""
  8069. });
  8070. items1.Add(new TestItem()
  8071. {
  8072. Parameter_name = "载具穴号",
  8073. Parameter_value = "1",
  8074. Parameter_unit = ""
  8075. });
  8076. items1.Add(new TestItem()
  8077. {
  8078. Parameter_name = "产品结果",
  8079. Parameter_value = d3Result == 1 ? "OK" : "NG",
  8080. Parameter_unit = ""
  8081. });
  8082. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8083. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8084. results.Add(result1);
  8085. }
  8086. }
  8087. short result = 0;
  8088. if (results.All(a => a == 1))
  8089. result = 1;
  8090. else if (results.Contains(3))
  8091. result = 3;
  8092. else if (results.Contains(2))
  8093. result = 2;
  8094. else if (results.Contains(4))
  8095. result = 4;
  8096. else
  8097. result = 4;
  8098. stopwatch2.Stop();
  8099. // MES_Flag 为4MES报错
  8100. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8101. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8102. writeToPLC_Flag.Name = "d3MES_FLAG";
  8103. writeToPLC_Flag.Adress = 2463;
  8104. writeToPLC_Flag.Value = result;
  8105. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8106. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8107. }
  8108. catch (Exception ex)
  8109. {
  8110. stopwatch2.Restart();
  8111. // MES_Flag 为4上位机报错
  8112. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  8113. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8114. writeToPLC_Flag.Name = "d3MES_FLAG";
  8115. writeToPLC_Flag.Adress = 2463;
  8116. writeToPLC_Flag.Value = (short)4;
  8117. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8118. string str = ex.StackTrace;
  8119. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8120. stopwatch2.Stop();
  8121. }
  8122. stopwatch1.Stop();
  8123. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8124. }
  8125. // 上次采集到的SN
  8126. //private string sn_S4_4进站接口 = string.Empty;
  8127. /// <summary>
  8128. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  8129. /// </summary>
  8130. private void S4_4进站接口(int plcNo, string stationNameStr)
  8131. {
  8132. Stopwatch stopwatch1 = new Stopwatch();
  8133. Stopwatch stopwatch2 = new Stopwatch();
  8134. try
  8135. {
  8136. stopwatch1.Start();
  8137. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8138. sn = sn.Replace("\0", "");
  8139. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8140. #region 查询15个载具码
  8141. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8142. string vehicleData = string.Empty;
  8143. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8144. if (string.IsNullOrEmpty(vehicleData))
  8145. vehicleData = "";
  8146. if (snResult != 0)
  8147. {
  8148. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8149. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8150. writeToPLC_Flag1.Adress = 2463;
  8151. writeToPLC_Flag1.Value = (short)4;
  8152. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8153. stopwatch1.Stop();
  8154. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8155. return;
  8156. }
  8157. string[] cavitySNs = vehicleData.Split('.');
  8158. if (cavitySNs != null && cavitySNs.Length > 0)
  8159. {
  8160. for (int i = 0; i < cavitySNs.Length; i++)
  8161. {
  8162. if (string.IsNullOrEmpty(cavitySNs[i]))
  8163. vehicleCodes.Add("");
  8164. else
  8165. vehicleCodes.Add(cavitySNs[i]);
  8166. }
  8167. }
  8168. #endregion 查询15个载具码
  8169. #region 查询15个产品SN
  8170. List<string> portNos = new List<string>(); // 15个产品SN
  8171. foreach (string vehicleCode in vehicleCodes)
  8172. {
  8173. if (string.IsNullOrEmpty(vehicleCode))
  8174. portNos.Add("");
  8175. else
  8176. {
  8177. // 查询
  8178. string cavityData = string.Empty;
  8179. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8180. if (string.IsNullOrEmpty(cavityData))
  8181. cavityData = "";
  8182. if (snResult1 != 0)
  8183. {
  8184. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8185. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8186. writeToPLC_Flag1.Adress = 2463;
  8187. writeToPLC_Flag1.Value = (short)4;
  8188. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8189. stopwatch1.Stop();
  8190. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8191. return;
  8192. }
  8193. string[] partSNs = cavityData.Split('.');
  8194. if (partSNs != null && partSNs.Length >= 1)
  8195. portNos.Add(partSNs[0]);
  8196. else
  8197. portNos.Add("");
  8198. }
  8199. }
  8200. #endregion 查询15个产品SN
  8201. // 调用MES进站(最多15个)
  8202. stopwatch2.Start();
  8203. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8204. for (int i = 0; i < vehicleCodes.Count; i++)
  8205. {
  8206. // 循环进站
  8207. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8208. {
  8209. // 产品SN(物料码)校验
  8210. string portNo = portNos[i];
  8211. List<TestItem> item = new List<TestItem>();
  8212. item.Add(new TestItem()
  8213. {
  8214. Parameter_name = "弹夹码",
  8215. Parameter_value = sn,
  8216. });
  8217. item.Add(new TestItem()
  8218. {
  8219. Parameter_name = "弹夹穴位",
  8220. Parameter_value = (i + 1).ToString(),
  8221. });
  8222. item.Add(new TestItem()
  8223. {
  8224. Parameter_name = "载具码",
  8225. Parameter_value = vehicleCodes[i],
  8226. });
  8227. item.Add(new TestItem()
  8228. {
  8229. Parameter_name = "载具穴号",
  8230. Parameter_value = "1",
  8231. });
  8232. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8233. }
  8234. }
  8235. stopwatch2.Stop();
  8236. short result = 0;
  8237. bool haveMesWarn = results.Contains(5);
  8238. bool havePCWarn = results.Contains(6);
  8239. if (haveMesWarn)
  8240. result = 2; // 5->2
  8241. else if (havePCWarn)
  8242. result = 6; // 6->4
  8243. else
  8244. result = 1;
  8245. // MES_Flag 为4MES报错
  8246. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8247. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8248. writeToPLC_Flag.Name = "d4MES_FLAG";
  8249. writeToPLC_Flag.Adress = 2496;
  8250. writeToPLC_Flag.Value = result;
  8251. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8252. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8253. }
  8254. catch (Exception ex)
  8255. {
  8256. stopwatch2.Stop();
  8257. // MES_Flag 为4上位机报错
  8258. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8259. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8260. writeToPLC_Flag.Name = "d4MES_FLAG";
  8261. writeToPLC_Flag.Adress = 2496;
  8262. writeToPLC_Flag.Value = (short)4;
  8263. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8264. string str = ex.StackTrace;
  8265. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8266. }
  8267. stopwatch1.Stop();
  8268. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8269. }
  8270. // 上次采集到的SN
  8271. //private string sn_S4_4出站接口 = string.Empty;
  8272. /// <summary>
  8273. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8274. /// </summary>
  8275. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8276. {
  8277. Stopwatch stopwatch1 = new Stopwatch();
  8278. Stopwatch stopwatch2 = new Stopwatch();
  8279. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8280. string stationNameStr = stationCode + stationName;
  8281. string processItem = stationName; // 测试项目
  8282. try
  8283. {
  8284. stopwatch1.Start();
  8285. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8286. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8287. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8288. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8289. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8290. sn = sn.Replace("\0", "");
  8291. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8292. bool isPass = d4Result == 1; // 产品结果 bool
  8293. #region 查询15个载具码
  8294. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8295. string vehicleData = string.Empty;
  8296. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8297. if (string.IsNullOrEmpty(vehicleData))
  8298. vehicleData = "";
  8299. if (snResult1 != 0)
  8300. {
  8301. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8302. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8303. writeToPLC_Flag1.Adress = 2496;
  8304. writeToPLC_Flag1.Value = (short)4;
  8305. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8306. stopwatch1.Stop();
  8307. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8308. return;
  8309. }
  8310. string[] cavitySNs = vehicleData.Split('.');
  8311. if (cavitySNs != null && cavitySNs.Length > 0)
  8312. {
  8313. for (int i = 0; i < cavitySNs.Length; i++)
  8314. {
  8315. if (string.IsNullOrEmpty(cavitySNs[i]))
  8316. vehicleCodes.Add("");
  8317. else
  8318. vehicleCodes.Add(cavitySNs[i]);
  8319. }
  8320. }
  8321. #endregion 查询15个载具码
  8322. // 统一查 产品SN列表
  8323. List<string> partNos = new List<string>();
  8324. foreach (string vehicleCode in vehicleCodes)
  8325. {
  8326. if (string.IsNullOrEmpty(vehicleCode))
  8327. partNos.Add("");
  8328. else
  8329. {
  8330. string partNo = "";
  8331. #region 查询载具上的产品信息
  8332. string cavityData = string.Empty;
  8333. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8334. if (string.IsNullOrEmpty(cavityData))
  8335. cavityData = "";
  8336. if (snResult != 0)
  8337. {
  8338. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8339. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8340. writeToPLC_Flag1.Adress = 2496;
  8341. writeToPLC_Flag1.Value = (short)4;
  8342. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8343. stopwatch1.Stop();
  8344. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8345. return;
  8346. }
  8347. string[] partSNs = cavityData.Split('.');
  8348. if (partSNs != null && partSNs.Length >= 1)
  8349. partNo = partSNs[0];
  8350. #endregion 查询载具上的产品信息
  8351. partNos.Add(partNo);
  8352. }
  8353. }
  8354. // 调用MES出站
  8355. stopwatch2.Start();
  8356. // 统一上传
  8357. List<int> results = new List<int>();
  8358. for (int i = 0; i < partNos.Count; i++)
  8359. {
  8360. string index = (i + 1).ToString(); // 弹夹穴号
  8361. if (string.IsNullOrEmpty(partNos[i]))
  8362. results.Add(1);
  8363. else
  8364. {
  8365. List<TestItem> items1 = new List<TestItem>();
  8366. items1.Add(new TestItem()
  8367. {
  8368. Parameter_name = "弹夹码",
  8369. Parameter_value = sn,
  8370. Parameter_unit = ""
  8371. });
  8372. items1.Add(new TestItem()
  8373. {
  8374. Parameter_name = "弹夹穴号",
  8375. Parameter_value = index,
  8376. Parameter_unit = ""
  8377. });
  8378. items1.Add(new TestItem()
  8379. {
  8380. Parameter_name = "载具码",
  8381. Parameter_value = vehicleCodes[i],
  8382. Parameter_unit = ""
  8383. });
  8384. items1.Add(new TestItem()
  8385. {
  8386. Parameter_name = "载具穴号",
  8387. Parameter_value = "1",
  8388. Parameter_unit = ""
  8389. });
  8390. items1.Add(new TestItem()
  8391. {
  8392. Parameter_name = "产品结果",
  8393. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8394. Parameter_unit = ""
  8395. });
  8396. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8397. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8398. results.Add(result1);
  8399. }
  8400. }
  8401. short result = 0;
  8402. if (results.All(a => a == 1))
  8403. result = 1;
  8404. else if (results.Contains(3))
  8405. result = 3;
  8406. else if (results.Contains(2))
  8407. result = 2;
  8408. else if (results.Contains(4))
  8409. result = 4;
  8410. else
  8411. result = 4;
  8412. stopwatch2.Stop();
  8413. // MES_Flag 为4MES报错
  8414. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8415. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8416. writeToPLC_Flag.Name = "d4MES_FLAG";
  8417. writeToPLC_Flag.Adress = 2496;
  8418. writeToPLC_Flag.Value = result;
  8419. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8420. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8421. }
  8422. catch (Exception ex)
  8423. {
  8424. stopwatch2.Restart();
  8425. // MES_Flag 为4上位机报错
  8426. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8427. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8428. writeToPLC_Flag.Name = "d4MES_FLAG";
  8429. writeToPLC_Flag.Adress = 2496;
  8430. writeToPLC_Flag.Value = (short)4;
  8431. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8432. string str = ex.StackTrace;
  8433. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8434. stopwatch2.Stop();
  8435. }
  8436. stopwatch1.Stop();
  8437. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8438. }
  8439. /// <summary>
  8440. /// [S4] 取放桁架 - S4_5弹夹扫码
  8441. /// </summary>
  8442. /// <param name="plcNo">PLC编号</param>
  8443. /// <param name="stationNameStr">工站全称</param>
  8444. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8445. {
  8446. Stopwatch stopwatch1 = new Stopwatch();
  8447. Stopwatch stopwatch2 = new Stopwatch();
  8448. try
  8449. {
  8450. stopwatch1.Start();
  8451. // ZS 弹夹扫码
  8452. string d5BulletclipCode = " "; // 扫到的码
  8453. short d5BulletclipScanCode = 2;
  8454. stopwatch2.Start();
  8455. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8456. //// MES_Flag
  8457. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8458. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8459. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8460. writeToPLC_Flag.Adress = 2528;
  8461. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8462. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8463. {
  8464. Name = "d5BulletclipCode",
  8465. Adress = 2529,
  8466. ValueType = PLCValueType.String,
  8467. ValueTypeStrLength = 20,
  8468. Value = d5BulletclipCode
  8469. });
  8470. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8471. stopwatch2.Stop();
  8472. }
  8473. catch (Exception ex)
  8474. {
  8475. string str = ex.StackTrace;
  8476. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8477. stopwatch2.Start();
  8478. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8479. //// MES_Flag
  8480. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8481. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8482. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8483. writeToPLC_Flag.Adress = 2528;
  8484. writeToPLC_Flag.Value = (short)6;
  8485. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8486. {
  8487. Name = "d5BulletclipCode",
  8488. Adress = 2529,
  8489. ValueType = PLCValueType.String,
  8490. ValueTypeStrLength = 20,
  8491. Value = " "
  8492. });
  8493. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8494. stopwatch2.Stop();
  8495. }
  8496. stopwatch1.Stop();
  8497. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8498. }
  8499. /// <summary>
  8500. /// [S4] 取放桁架 - S4_5载具扫码
  8501. /// </summary>
  8502. /// <param name="plcNo">PLC编号</param>
  8503. /// <param name="stationNameStr">工站全称</param>
  8504. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8505. {
  8506. Stopwatch stopwatch1 = new Stopwatch();
  8507. Stopwatch stopwatch2 = new Stopwatch();
  8508. try
  8509. {
  8510. stopwatch1.Start();
  8511. // ZS 载具扫码
  8512. string d5VehicleCode = " "; // 扫到的码
  8513. short d5VehicleScanCode = 2;
  8514. #region 进站
  8515. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8516. {
  8517. // 查产品SN
  8518. #region 查询载具上的产品信息
  8519. string cavityData = string.Empty;
  8520. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8521. if (string.IsNullOrEmpty(cavityData))
  8522. cavityData = "";
  8523. if (snResult != 0)
  8524. {
  8525. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8526. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8527. writeToPLC_Flag1.Adress = 2559;
  8528. writeToPLC_Flag1.Value = (short)6;
  8529. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8530. {
  8531. Name = "d5VehicleCode",
  8532. Adress = 2560,
  8533. ValueType = PLCValueType.String,
  8534. ValueTypeStrLength = 20,
  8535. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8536. });
  8537. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8538. stopwatch1.Stop();
  8539. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8540. return;
  8541. }
  8542. string[] cavitySNs = cavityData.Split('.');
  8543. string partNo = "";
  8544. if (cavitySNs != null && cavitySNs.Length >= 1)
  8545. {
  8546. partNo = cavitySNs[0];
  8547. }
  8548. #endregion 查询载具上的产品信息
  8549. List<TestItem> item = new List<TestItem>();
  8550. item.Add(new TestItem()
  8551. {
  8552. Parameter_name = "载具码",
  8553. Parameter_value = d5VehicleCode,
  8554. });
  8555. item.Add(new TestItem()
  8556. {
  8557. Parameter_name = "载具穴号",
  8558. Parameter_value = "1",
  8559. });
  8560. stopwatch2.Start();
  8561. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8562. stopwatch2.Stop();
  8563. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8564. }
  8565. #endregion 进站
  8566. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8567. //// MES_Flag
  8568. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8569. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8570. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8571. writeToPLC_Flag.Adress = 2559;
  8572. writeToPLC_Flag.Value = d5VehicleScanCode;
  8573. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8574. {
  8575. Name = "d5VehicleCode",
  8576. Adress = 2560,
  8577. ValueType = PLCValueType.String,
  8578. ValueTypeStrLength = 20,
  8579. Value = d5VehicleCode
  8580. });
  8581. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8582. }
  8583. catch (Exception ex)
  8584. {
  8585. string str = ex.StackTrace;
  8586. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8587. stopwatch2.Start();
  8588. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8589. //// MES_Flag
  8590. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8591. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8592. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8593. writeToPLC_Flag.Adress = 2559;
  8594. writeToPLC_Flag.Value = (short)6;
  8595. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8596. {
  8597. Name = "d5VehicleCode",
  8598. Adress = 2560,
  8599. ValueType = PLCValueType.String,
  8600. ValueTypeStrLength = 20,
  8601. Value = " "
  8602. });
  8603. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8604. stopwatch2.Stop();
  8605. }
  8606. stopwatch1.Stop();
  8607. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8608. }
  8609. // 上次采集到的SN
  8610. //private string sn_S4_5出站接口 = string.Empty;
  8611. /// <summary>
  8612. /// [S4] 取放桁架 - S4_5出站接口
  8613. /// </summary>
  8614. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8615. {
  8616. Stopwatch stopwatch1 = new Stopwatch();
  8617. Stopwatch stopwatch2 = new Stopwatch();
  8618. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8619. string stationNameStr = stationCode + stationName;
  8620. string processItem = stationName; // 测试项目
  8621. try
  8622. {
  8623. stopwatch1.Start();
  8624. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8625. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8626. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8627. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8628. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8629. sn = sn.Replace("\0", "");
  8630. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8631. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8632. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8633. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8634. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8635. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8636. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8637. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8638. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8639. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8640. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8641. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8642. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8643. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8644. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8645. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8646. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8647. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8648. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8649. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8650. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8651. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8652. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8653. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8654. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8655. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8656. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8657. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8658. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8659. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8660. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8661. bool pass = d5Result == 1;
  8662. // 存 载具SN列表
  8663. List<string> vehicleCodes = new List<string>()
  8664. {
  8665. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8666. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8667. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8668. };
  8669. // 统一查 产品SN列表
  8670. List<string> partNos = new List<string>();
  8671. foreach (string vehicleCode in vehicleCodes)
  8672. {
  8673. if (string.IsNullOrEmpty(vehicleCode))
  8674. partNos.Add("");
  8675. else
  8676. {
  8677. string partNo = "";
  8678. #region 查询载具上的产品信息
  8679. string cavityData = string.Empty;
  8680. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8681. if (string.IsNullOrEmpty(cavityData))
  8682. cavityData = "";
  8683. if (snResult != 0)
  8684. {
  8685. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8686. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8687. writeToPLC_Flag1.Adress = 2591;
  8688. writeToPLC_Flag1.Value = (short)4;
  8689. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8690. stopwatch1.Stop();
  8691. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8692. return;
  8693. }
  8694. string[] cavitySNs = cavityData.Split('.');
  8695. if (cavitySNs != null && cavitySNs.Length >= 1)
  8696. partNo = cavitySNs[0];
  8697. #endregion 查询载具上的产品信息
  8698. partNos.Add(partNo);
  8699. }
  8700. }
  8701. // 统一上传
  8702. stopwatch2.Start();
  8703. List<int> results = new List<int>();
  8704. for (int i = 0; i < partNos.Count; i++)
  8705. {
  8706. string index = (i + 1).ToString(); // 弹夹穴号
  8707. if (string.IsNullOrEmpty(partNos[i]))
  8708. results.Add(1);
  8709. else
  8710. {
  8711. List<TestItem> items1 = new List<TestItem>();
  8712. items1.Add(new TestItem()
  8713. {
  8714. Parameter_name = "弹夹码",
  8715. Parameter_value = sn,
  8716. Parameter_unit = ""
  8717. });
  8718. items1.Add(new TestItem()
  8719. {
  8720. Parameter_name = "弹夹穴号",
  8721. Parameter_value = index,
  8722. Parameter_unit = ""
  8723. });
  8724. items1.Add(new TestItem()
  8725. {
  8726. Parameter_name = "载具码",
  8727. Parameter_value = vehicleCodes[i],
  8728. Parameter_unit = ""
  8729. });
  8730. items1.Add(new TestItem()
  8731. {
  8732. Parameter_name = "载具穴号",
  8733. Parameter_value = "1",
  8734. Parameter_unit = ""
  8735. });
  8736. items1.Add(new TestItem()
  8737. {
  8738. Parameter_name = "产品结果",
  8739. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8740. Parameter_unit = ""
  8741. });
  8742. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8743. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8744. results.Add(result1);
  8745. }
  8746. }
  8747. short result = 0;
  8748. if (results.All(a => a == 1))
  8749. result = 1;
  8750. else if (results.Contains(3))
  8751. result = 3;
  8752. else if (results.Contains(2))
  8753. result = 2;
  8754. else if (results.Contains(4))
  8755. result = 4;
  8756. else
  8757. result = 4;
  8758. stopwatch2.Stop();
  8759. #region 存储绑定数据到 边线MES系统中
  8760. if (result == 1)
  8761. {
  8762. // 删除绑定信息
  8763. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8764. if (resultMesR != 0)
  8765. {
  8766. result = 4;
  8767. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8768. }
  8769. }
  8770. #endregion 存储绑定数据到 边线MES系统中
  8771. // MES_Flag 为4MES报错
  8772. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8773. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8774. writeToPLC_Flag.Name = "d5MES_FLAG";
  8775. writeToPLC_Flag.Adress = 2591;
  8776. writeToPLC_Flag.Value = result;
  8777. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8778. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8779. }
  8780. catch (Exception ex)
  8781. {
  8782. stopwatch2.Restart();
  8783. // MES_Flag 为4上位机报错
  8784. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8785. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8786. writeToPLC_Flag.Name = "d5MES_FLAG";
  8787. writeToPLC_Flag.Adress = 2591;
  8788. writeToPLC_Flag.Value = (short)4;
  8789. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8790. stopwatch2.Stop();
  8791. string str = ex.StackTrace;
  8792. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8793. }
  8794. stopwatch1.Stop();
  8795. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8796. }
  8797. /// <summary>
  8798. /// [S4] 取放桁架 - S4_5节拍接口
  8799. /// </summary>
  8800. /// <param name="plcNo">PLC编号</param>
  8801. /// <param name="stationNameStr">工站全称</param>
  8802. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8803. {
  8804. Stopwatch stopwatch1 = new Stopwatch();
  8805. Stopwatch stopwatch2 = new Stopwatch();
  8806. string resultStr = string.Empty;
  8807. try
  8808. {
  8809. stopwatch1.Start();
  8810. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8811. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8812. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8813. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8814. if (!actionBool)
  8815. {
  8816. stopwatch2.Start();
  8817. // MES_Flag
  8818. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8819. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8820. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8821. writeToPLC_Flag1.Adress = 2924;
  8822. writeToPLC_Flag1.Value = (short)4;
  8823. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8824. stopwatch2.Stop();
  8825. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8826. return;
  8827. }
  8828. string d5OEEPartNo = string.Empty; // 物料码
  8829. if (string.IsNullOrEmpty(d5OEEProductSN))
  8830. {
  8831. stopwatch2.Start();
  8832. // MES_Flag
  8833. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8834. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8835. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8836. writeToPLC_Flag1.Adress = 2924;
  8837. writeToPLC_Flag1.Value = (short)1;
  8838. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8839. stopwatch2.Stop();
  8840. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8841. return;
  8842. }
  8843. else
  8844. { // 查产品SN
  8845. d5OEEPartNo = "Test"; // ZS
  8846. }
  8847. short d5OEEMES_FLAG = 0;
  8848. // 上传OEE
  8849. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8850. d5OEEMES_FLAG = result.Item1;
  8851. resultStr = result.Item2;
  8852. stopwatch2.Start();
  8853. // MES_Flag
  8854. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8855. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8856. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8857. writeToPLC_Flag.Adress = 2924;
  8858. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8859. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8860. stopwatch2.Stop();
  8861. }
  8862. catch (Exception ex)
  8863. {
  8864. string str = ex.StackTrace;
  8865. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8866. // MES_Flag
  8867. stopwatch2.Start();
  8868. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8869. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8870. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8871. writeToPLC_Flag.Adress = 2924;
  8872. writeToPLC_Flag.Value = (short)4;
  8873. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8874. stopwatch2.Stop();
  8875. }
  8876. stopwatch1.Stop();
  8877. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8878. }
  8879. #endregion [S4] 取放桁架
  8880. #endregion PLC4 刘果段
  8881. #region PLC5 张超凡
  8882. #region [S5] Tray盘下料装备
  8883. /// <summary>
  8884. /// S5工位的数据- 触发信号上次的值
  8885. /// </summary>
  8886. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8887. /// <summary>
  8888. /// S5工位的数据(含触发信号)
  8889. /// </summary>
  8890. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8891. /// <summary>
  8892. /// S5工位的数据- 回写点位
  8893. /// </summary>
  8894. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8895. /// <summary>
  8896. /// [S5] Tray盘下料装备
  8897. /// </summary>
  8898. /// <param name="plcNo">PLC编号</param>
  8899. //private void ReadStation_S5(int plcNo)
  8900. //{
  8901. // // [S1] Tray盘上料装备
  8902. // // [S2] FCT
  8903. // // [S3] 值板机
  8904. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8905. // // [S5] Tray盘下料装备
  8906. // /// 上位机心跳
  8907. // /// 获取设备报警数据与状态信息
  8908. // string stationCode = "[S5]";
  8909. // string stationName = "Tray盘下料装备";
  8910. // string stationNameStr = stationCode + stationName;
  8911. // #region 创建字典
  8912. // // 触发信号字典 赋值
  8913. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8914. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8915. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8916. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8917. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8918. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8919. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8920. // // PLC数据字典 赋值
  8921. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8922. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8923. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8924. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8925. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8926. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8927. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8928. // s5PLCData.Add("e1Result", 0); // 产品结果
  8929. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8930. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8931. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8932. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8933. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8934. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8935. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8936. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8937. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8938. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8939. // #endregion 创建字典
  8940. // while (IsRun)
  8941. // {
  8942. // try
  8943. // {
  8944. // if (!GlobalContext._IsCon_Funs5)
  8945. // {
  8946. // UpdatePLCMonitor(1, plcNo, 0);
  8947. // continue;
  8948. // }
  8949. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8950. // {
  8951. // Stopwatch stopwatch1 = new Stopwatch();
  8952. // Stopwatch stopwatch2 = new Stopwatch();
  8953. // stopwatch1.Start();
  8954. // stopwatch2.Start();
  8955. // #region 一次性读取所有数据
  8956. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8957. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8958. // int[] datas = data1.Concat(data2).ToArray();
  8959. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8960. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8961. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8962. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8963. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8964. // s5PLCData["e1MES_FLAG"] = datas[35];
  8965. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8966. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8967. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8968. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8969. // s5PLCData["e1Result"] = datas[76];
  8970. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8971. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8972. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8973. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8974. // s5PLCData["e1OEEType"] = datas[109];
  8975. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8976. // s5PLCData["e1AGVUpStart"] = datas[121];
  8977. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8978. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8979. // s5PLCData["e1AGVDownStart"] = datas[134];
  8980. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8981. // #endregion 一次性读取所有数据
  8982. // stopwatch2.Stop();
  8983. // #region 回写操作,写后清空flag
  8984. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8985. // #endregion 回写操作,写后清空flag
  8986. // #region 进站校验
  8987. // try
  8988. // {
  8989. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8990. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8991. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  8992. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  8993. // {
  8994. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  8995. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8996. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  8997. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8998. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  8999. // }
  9000. // }
  9001. // catch (Exception ex)
  9002. // {
  9003. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9004. // string str = ex.StackTrace;
  9005. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9006. // }
  9007. // #endregion 进站校验
  9008. // #region 出站接口
  9009. // try
  9010. // {
  9011. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  9012. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  9013. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  9014. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  9015. // {
  9016. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  9017. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9018. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  9019. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  9020. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  9021. // }
  9022. // }
  9023. // catch (Exception ex)
  9024. // {
  9025. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  9026. // string str = ex.StackTrace;
  9027. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9028. // }
  9029. // #endregion 出站接口
  9030. // #region 节拍接口
  9031. // try
  9032. // {
  9033. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  9034. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  9035. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  9036. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  9037. // {
  9038. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  9039. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9040. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  9041. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  9042. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  9043. // }
  9044. // }
  9045. // catch (Exception ex)
  9046. // {
  9047. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9048. // string str = ex.StackTrace;
  9049. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9050. // }
  9051. // #endregion 节拍接口
  9052. // #region AGV上料
  9053. // // AGV上料叫AGV信号
  9054. // try
  9055. // {
  9056. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  9057. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  9058. // if (e1AGVUpCall != e1AGVUpCallOld)
  9059. // {
  9060. // if (e1AGVUpCall == 1) // 0->1
  9061. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  9062. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  9063. // }
  9064. // }
  9065. // catch (Exception ex)
  9066. // {
  9067. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9068. // string str = ex.StackTrace;
  9069. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9070. // }
  9071. // // AGV上料完成信号
  9072. // try
  9073. // {
  9074. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  9075. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  9076. // if (e1AGVUpEnd != e1AGVUpEndOld)
  9077. // {
  9078. // if (e1AGVUpEnd == 1) // 0->1
  9079. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  9080. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  9081. // }
  9082. // }
  9083. // catch (Exception ex)
  9084. // {
  9085. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9086. // string str = ex.StackTrace;
  9087. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9088. // }
  9089. // #endregion AGV上料
  9090. // #region AGV下料
  9091. // // AGV下料叫agv信号
  9092. // try
  9093. // {
  9094. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  9095. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  9096. // if (e1AGVDownCall != e1AGVDownCallOld)
  9097. // {
  9098. // if (e1AGVDownCall == 1) // 0->1
  9099. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  9100. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  9101. // }
  9102. // }
  9103. // catch (Exception ex)
  9104. // {
  9105. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9106. // string str = ex.StackTrace;
  9107. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9108. // }
  9109. // // AGV下料完成信号
  9110. // try
  9111. // {
  9112. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  9113. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  9114. // if (e1AGVDownEnd != e1AGVDownEndOld)
  9115. // {
  9116. // if (e1AGVDownEnd == 1) // 0->1
  9117. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  9118. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  9119. // }
  9120. // }
  9121. // catch (Exception ex)
  9122. // {
  9123. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9124. // string str = ex.StackTrace;
  9125. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9126. // }
  9127. // #endregion AGV下料
  9128. // #region 心跳
  9129. // try
  9130. // {
  9131. // short states = 0;
  9132. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9133. // }
  9134. // catch (Exception ex)
  9135. // {
  9136. // string str = ex.StackTrace;
  9137. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9138. // }
  9139. // #endregion 心跳
  9140. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9141. // stopwatch1.Stop();
  9142. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9143. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9144. // }
  9145. // else
  9146. // {
  9147. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9148. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9149. // Funs[plcNo].Connect();
  9150. // }
  9151. // }
  9152. // catch (Exception ex)
  9153. // {
  9154. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9155. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9156. // Funs[plcNo].ReConnect();
  9157. // }
  9158. // Thread.Sleep(IntervalReadPLC);
  9159. // }
  9160. //}
  9161. /// <summary>
  9162. /// [S5] Tray盘下料装备 - 进站校验
  9163. /// </summary>
  9164. /// <param name="plcNo">PLC编号</param>
  9165. /// <param name="stationNameStr">工站全称</param>
  9166. private void S5进站校验(int plcNo, string stationNameStr)
  9167. {
  9168. Stopwatch stopwatch1 = new Stopwatch();
  9169. Stopwatch stopwatch2 = new Stopwatch();
  9170. try
  9171. {
  9172. stopwatch1.Start();
  9173. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9174. sn = sn.Replace("\0", "");
  9175. // 获取产品SN By 载具码
  9176. #region 查询载具上的产品信息
  9177. string cavityData = string.Empty;
  9178. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9179. if (string.IsNullOrEmpty(cavityData))
  9180. cavityData = "";
  9181. if (snResult != 0)
  9182. {
  9183. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9184. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9185. writeToPLC_Flag1.Adress = 2003;
  9186. writeToPLC_Flag1.Value = (short)6;
  9187. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9188. stopwatch1.Stop();
  9189. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9190. return;
  9191. }
  9192. string[] cavitySNs = cavityData.Split('.');
  9193. string partNo = string.Empty;
  9194. if (cavitySNs != null && cavitySNs.Length >= 1)
  9195. partNo = cavitySNs[0];
  9196. #endregion 查询载具上的产品信息
  9197. // 产品SN(物料码)校验
  9198. List<TestItem> item = new List<TestItem>();
  9199. item.Add(new TestItem()
  9200. {
  9201. Parameter_name = "载具码",
  9202. Parameter_value = sn,
  9203. });
  9204. item.Add(new TestItem()
  9205. {
  9206. Parameter_name = "载具穴号",
  9207. Parameter_value = "1",
  9208. });
  9209. stopwatch2.Start();
  9210. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9211. stopwatch2.Stop();
  9212. short e1MES_FLAG_Check = (short)result;
  9213. // MES_Flag
  9214. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9215. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9216. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9217. writeToPLC_Flag.Adress = 2003;
  9218. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9219. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9220. }
  9221. catch (Exception ex)
  9222. {
  9223. string str = ex.StackTrace;
  9224. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9225. // MES_Flag
  9226. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9227. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9228. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9229. writeToPLC_Flag.Adress = 2003;
  9230. writeToPLC_Flag.Value = (short)6;
  9231. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9232. }
  9233. stopwatch1.Stop();
  9234. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9235. }
  9236. /// <summary>
  9237. /// [S5] Tray盘下料装备 - 出站接口
  9238. /// </summary>
  9239. /// <param name="plcNo"></param>
  9240. /// <param name="stationCode"></param>
  9241. /// <param name="stationName"></param>
  9242. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9243. {
  9244. Stopwatch stopwatch1 = new Stopwatch();
  9245. Stopwatch stopwatch2 = new Stopwatch();
  9246. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9247. string stationNameStr = stationCode + stationName;
  9248. string processItem = stationName; // 测试项目
  9249. try
  9250. {
  9251. stopwatch1.Start();
  9252. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9253. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9254. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9255. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9256. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9257. sn = sn.Replace("\0", "");
  9258. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9259. //partNo = partNo.Replace("\0", "");
  9260. #region 查询载具上的产品信息
  9261. string cavityData = string.Empty;
  9262. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9263. if (string.IsNullOrEmpty(cavityData))
  9264. cavityData = "";
  9265. if (snResult != 0)
  9266. {
  9267. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9268. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9269. writeToPLC_Flag1.Adress = 2035;
  9270. writeToPLC_Flag1.Value = (short)4;
  9271. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9272. stopwatch1.Stop();
  9273. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9274. return;
  9275. }
  9276. string[] cavitySNs = cavityData.Split('.');
  9277. string partNo = string.Empty;
  9278. if (cavitySNs != null && cavitySNs.Length >= 1)
  9279. partNo = cavitySNs[0];
  9280. #endregion 查询载具上的产品信息
  9281. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9282. bool pass = e1Result == 1;
  9283. stopwatch2.Start();
  9284. // 上传MES
  9285. List<TestItem> items = new List<TestItem>();
  9286. items.Add(new TestItem()
  9287. {
  9288. Parameter_name = "载具码",
  9289. Parameter_value = sn,
  9290. Parameter_unit = ""
  9291. });
  9292. items.Add(new TestItem()
  9293. {
  9294. Parameter_name = "载具穴号",
  9295. Parameter_value = "1",
  9296. Parameter_unit = ""
  9297. });
  9298. items.Add(new TestItem()
  9299. {
  9300. Parameter_name = "产品结果",
  9301. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9302. Parameter_unit = ""
  9303. });
  9304. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  9305. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9306. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9307. short result = result1 == 1 ? (short)1 : (short)3;
  9308. stopwatch2.Stop();
  9309. #region 存储绑定数据到 边线MES系统中
  9310. if (result == 1)
  9311. {
  9312. // 删除绑定信息
  9313. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9314. if (resultMesR != 0)
  9315. {
  9316. result = 4;
  9317. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9318. }
  9319. }
  9320. #endregion 存储绑定数据到 边线MES系统中
  9321. // MES_Flag 为MES报错
  9322. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9323. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9324. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9325. writeToPLC_Flag.Name = "e1MES_FLAG";
  9326. writeToPLC_Flag.Adress = 2035;
  9327. writeToPLC_Flag.Value = result;
  9328. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9329. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9330. }
  9331. catch (Exception ex)
  9332. {
  9333. stopwatch2.Restart();
  9334. // MES_Flag 为4上位机报错
  9335. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9336. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9337. writeToPLC_Flag.Name = "e1MES_FLAG";
  9338. writeToPLC_Flag.Adress = 2035;
  9339. writeToPLC_Flag.Value = (short)4;
  9340. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9341. stopwatch2.Stop();
  9342. string str = ex.StackTrace;
  9343. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9344. }
  9345. stopwatch1.Stop();
  9346. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9347. }
  9348. /// <summary>
  9349. /// [S5] Tray盘下料装备 - 节拍接口
  9350. /// </summary>
  9351. /// <param name="plcNo">PLC编号</param>
  9352. /// <param name="stationNameStr">工站全称</param>
  9353. private void S5节拍接口(int plcNo, string stationNameStr)
  9354. {
  9355. Stopwatch stopwatch1 = new Stopwatch();
  9356. Stopwatch stopwatch2 = new Stopwatch();
  9357. string resultStr = string.Empty;
  9358. try
  9359. {
  9360. stopwatch1.Start();
  9361. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9362. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9363. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9364. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9365. if (!actionBool)
  9366. {
  9367. stopwatch2.Start();
  9368. // MES_Flag
  9369. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9370. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9371. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9372. writeToPLC_Flag1.Adress = 2088;
  9373. writeToPLC_Flag1.Value = (short)4;
  9374. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9375. stopwatch2.Stop();
  9376. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9377. return;
  9378. }
  9379. string e1OEEPartNo = string.Empty; // 物料码
  9380. if (string.IsNullOrEmpty(e1OEEProductSN))
  9381. {
  9382. stopwatch2.Start();
  9383. // MES_Flag
  9384. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9385. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9386. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9387. writeToPLC_Flag1.Adress = 2088;
  9388. writeToPLC_Flag1.Value = (short)1;
  9389. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9390. stopwatch2.Stop();
  9391. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9392. return;
  9393. }
  9394. else
  9395. { // 查产品SN
  9396. e1OEEPartNo = "Test"; // ZS
  9397. }
  9398. short e1OEEMES_FLAG = 0;
  9399. // 上传OEE
  9400. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9401. e1OEEMES_FLAG = result.Item1;
  9402. resultStr = result.Item2;
  9403. stopwatch2.Start();
  9404. // MES_Flag
  9405. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9406. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9407. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9408. writeToPLC_Flag.Adress = 2088;
  9409. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9410. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9411. stopwatch2.Stop();
  9412. }
  9413. catch (Exception ex)
  9414. {
  9415. string str = ex.StackTrace;
  9416. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9417. // MES_Flag
  9418. stopwatch2.Start();
  9419. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9420. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9421. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9422. writeToPLC_Flag.Adress = 2088;
  9423. writeToPLC_Flag.Value = (short)4;
  9424. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9425. stopwatch2.Stop();
  9426. }
  9427. stopwatch1.Stop();
  9428. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9429. }
  9430. /// <summary>
  9431. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9432. /// </summary>
  9433. /// <param name="plcNo">PLC编号</param>
  9434. /// <param name="stationNameStr">工站全称</param>
  9435. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9436. {
  9437. Stopwatch stopwatch1 = new Stopwatch();
  9438. Stopwatch stopwatch2 = new Stopwatch();
  9439. try
  9440. {
  9441. stopwatch1.Start();
  9442. // ZS 呼叫AGV
  9443. short e1AGVUpCall = 2;
  9444. stopwatch2.Start();
  9445. // e1AGVUpCall
  9446. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9447. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9448. writeToPLC_Flag.Name = "e1AGVUpCall";
  9449. writeToPLC_Flag.Adress = 2120;
  9450. writeToPLC_Flag.Value = e1AGVUpCall;
  9451. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9452. stopwatch2.Stop();
  9453. }
  9454. catch (Exception ex)
  9455. {
  9456. string str = ex.StackTrace;
  9457. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9458. // e1AGVUpCall
  9459. stopwatch2.Start();
  9460. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9461. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9462. writeToPLC_Flag.Name = "e1AGVUpCall";
  9463. writeToPLC_Flag.Adress = 2120;
  9464. writeToPLC_Flag.Value = (short)4;
  9465. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9466. stopwatch2.Stop();
  9467. }
  9468. stopwatch1.Stop();
  9469. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9470. }
  9471. /// <summary>
  9472. /// [S5] Tray盘下料装备 - AGV上料完成
  9473. /// </summary>
  9474. /// <param name="plcNo">PLC编号</param>
  9475. /// <param name="stationNameStr">工站全称</param>
  9476. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9477. {
  9478. Stopwatch stopwatch1 = new Stopwatch();
  9479. Stopwatch stopwatch2 = new Stopwatch();
  9480. try
  9481. {
  9482. stopwatch1.Start();
  9483. // ZS AGV上料完成,让小车离开
  9484. short e1AGVUpEnd = 2;
  9485. stopwatch2.Start();
  9486. // e1AGVUpEnd
  9487. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9488. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9489. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9490. writeToPLC_Flag.Adress = 2122;
  9491. writeToPLC_Flag.Value = e1AGVUpEnd;
  9492. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9493. stopwatch2.Stop();
  9494. }
  9495. catch (Exception ex)
  9496. {
  9497. string str = ex.StackTrace;
  9498. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9499. // e1AGVUpEnd
  9500. stopwatch2.Start();
  9501. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9502. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9503. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9504. writeToPLC_Flag.Adress = 2122;
  9505. writeToPLC_Flag.Value = (short)4;
  9506. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9507. stopwatch2.Stop();
  9508. }
  9509. stopwatch1.Stop();
  9510. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9511. }
  9512. /// <summary>
  9513. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9514. /// </summary>
  9515. /// <param name="plcNo">PLC编号</param>
  9516. /// <param name="stationNameStr">工站全称</param>
  9517. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9518. {
  9519. Stopwatch stopwatch1 = new Stopwatch();
  9520. Stopwatch stopwatch2 = new Stopwatch();
  9521. try
  9522. {
  9523. stopwatch1.Start();
  9524. // ZS 呼叫AGV
  9525. short e1AGVDownCall = 2;
  9526. stopwatch2.Start();
  9527. // e1AGVDownCall
  9528. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9529. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9530. writeToPLC_Flag.Name = "e1AGVDownCall";
  9531. writeToPLC_Flag.Adress = 2133;
  9532. writeToPLC_Flag.Value = e1AGVDownCall;
  9533. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9534. stopwatch2.Stop();
  9535. }
  9536. catch (Exception ex)
  9537. {
  9538. string str = ex.StackTrace;
  9539. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9540. // e1AGVDownCall
  9541. stopwatch2.Start();
  9542. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9543. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9544. writeToPLC_Flag.Name = "e1AGVDownCall";
  9545. writeToPLC_Flag.Adress = 2133;
  9546. writeToPLC_Flag.Value = (short)4;
  9547. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9548. stopwatch2.Stop();
  9549. }
  9550. stopwatch1.Stop();
  9551. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9552. }
  9553. /// <summary>
  9554. /// [S5] Tray盘下料装备 - AGV下料完成
  9555. /// </summary>
  9556. /// <param name="plcNo">PLC编号</param>
  9557. /// <param name="stationNameStr">工站全称</param>
  9558. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9559. {
  9560. Stopwatch stopwatch1 = new Stopwatch();
  9561. Stopwatch stopwatch2 = new Stopwatch();
  9562. try
  9563. {
  9564. stopwatch1.Start();
  9565. // ZS AGV上料完成,让小车离开
  9566. short e1AGVDownEnd = 2;
  9567. stopwatch2.Start();
  9568. // e1AGVDownEnd
  9569. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9570. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9571. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9572. writeToPLC_Flag.Adress = 2135;
  9573. writeToPLC_Flag.Value = e1AGVDownEnd;
  9574. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9575. stopwatch2.Stop();
  9576. }
  9577. catch (Exception ex)
  9578. {
  9579. string str = ex.StackTrace;
  9580. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9581. // e1AGVDownEnd
  9582. stopwatch2.Start();
  9583. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9584. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9585. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9586. writeToPLC_Flag.Adress = 2135;
  9587. writeToPLC_Flag.Value = (short)4;
  9588. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9589. stopwatch2.Stop();
  9590. }
  9591. stopwatch1.Stop();
  9592. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9593. }
  9594. #endregion [S5] Tray盘下料装备
  9595. #endregion PLC5 张超凡
  9596. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9597. /// <summary>
  9598. /// PLC读取到的数据 -添加数据
  9599. /// </summary>
  9600. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9601. {
  9602. if (sxPlcData.ContainsKey(newKey))
  9603. sxPlcData[newKey] = newValue;
  9604. else
  9605. sxPlcData.Add(newKey, newValue);
  9606. }
  9607. /// <summary>
  9608. /// PLC需要写入的数据 -添加数据
  9609. /// </summary>
  9610. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9611. {
  9612. if (sxPLCWriteData.ContainsKey(newKey))
  9613. sxPLCWriteData[newKey] = newValue;
  9614. else
  9615. sxPLCWriteData.Add(newKey, newValue);
  9616. }
  9617. /// <summary>
  9618. /// PLC回写操作,写后清空flag
  9619. /// </summary>
  9620. /// <param name="modbusClient">modbus对象</param>
  9621. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9622. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9623. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9624. {
  9625. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9626. {
  9627. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9628. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9629. {
  9630. string mesFlagName = pLCWriteDatas[i].Name;
  9631. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9632. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9633. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9634. {
  9635. // 先回写数据
  9636. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9637. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9638. {
  9639. int mesDataAdress = writeToPLCDatas[j].Adress;
  9640. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9641. switch (mesDataType)
  9642. {
  9643. case PLCValueType.Short:
  9644. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9645. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9646. break;
  9647. case PLCValueType.String:
  9648. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9649. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9650. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9651. break;
  9652. }
  9653. }
  9654. // 再回写信号
  9655. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9656. // 存储读取数据的字典
  9657. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9658. // 存储写入数据的字典 - 清空写入值
  9659. pLCWriteDatas[i].Value = (short)0;
  9660. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9661. }
  9662. }
  9663. }
  9664. }
  9665. /// <summary>
  9666. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9667. /// </summary>
  9668. /// <param name="no">3</param>
  9669. /// <param name="stationCode">设备编号</param>
  9670. /// <param name="stationNameStr">设备名称</param>
  9671. /// <param name="plcOrder">车间订单号</param>
  9672. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9673. {
  9674. try
  9675. {
  9676. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9677. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9678. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9679. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9680. int result1 = 0;
  9681. switch (stationCode)
  9682. {
  9683. case 2:
  9684. case 3:
  9685. case 4:
  9686. case 6:
  9687. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9688. break;
  9689. case 102:
  9690. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9691. break;
  9692. case 103:
  9693. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9694. break;
  9695. case 104:
  9696. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9697. break;
  9698. case 106:
  9699. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9700. break;
  9701. default:
  9702. // MES_Flag 为“6未找到正确设备编号”
  9703. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9704. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9705. return;
  9706. }
  9707. short result = result1 == 1 ? (short)1 : (short)2;
  9708. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9709. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9710. }
  9711. catch (Exception ex)
  9712. {
  9713. // MES_Flag 为2上位机报错
  9714. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9715. string str = ex.StackTrace;
  9716. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9717. }
  9718. }
  9719. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9720. #region UI刷新
  9721. /// <summary>
  9722. /// 更新商品信息的UI + 下发产品信息(SN)
  9723. /// </summary>
  9724. private void UpdateProductInfo()
  9725. {
  9726. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9727. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9728. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9729. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9730. }
  9731. /// <summary>
  9732. /// 更新PLC连接状态的UI
  9733. /// </summary>
  9734. /// <param name="no">PLC编号</param>
  9735. /// <param name="status">状态</param>
  9736. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9737. {
  9738. if (this != null && !this.IsDisposed)
  9739. {
  9740. switch (imgNo)
  9741. {
  9742. case 1:
  9743. this.BeginInvoke(new Action(() =>
  9744. {
  9745. picPLC.Image = imageListState.Images[status];
  9746. }));
  9747. break;
  9748. case 2:
  9749. this.BeginInvoke(new Action(() =>
  9750. {
  9751. pictureBox2.Image = imageListState.Images[status];
  9752. }));
  9753. break;
  9754. case 3:
  9755. this.BeginInvoke(new Action(() =>
  9756. {
  9757. pictureBox3.Image = imageListState.Images[status];
  9758. }));
  9759. break;
  9760. case 4:
  9761. this.BeginInvoke(new Action(() =>
  9762. {
  9763. pictureBox4.Image = imageListState.Images[status];
  9764. }));
  9765. break;
  9766. case 5:
  9767. this.BeginInvoke(new Action(() =>
  9768. {
  9769. pictureBox5.Image = imageListState.Images[status];
  9770. }));
  9771. break;
  9772. case 6:
  9773. this.BeginInvoke(new Action(() =>
  9774. {
  9775. pictureBox6.Image = imageListState.Images[status];
  9776. }));
  9777. break;
  9778. case 7:
  9779. this.BeginInvoke(new Action(() =>
  9780. {
  9781. pictureBox7.Image = imageListState.Images[status];
  9782. }));
  9783. break;
  9784. case 8:
  9785. this.BeginInvoke(new Action(() =>
  9786. {
  9787. pictureBox8.Image = imageListState.Images[status];
  9788. }));
  9789. break;
  9790. default:
  9791. break;
  9792. }
  9793. }
  9794. Task.Run(() => // 更新PLC交互页的指示灯
  9795. {
  9796. try
  9797. {
  9798. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9799. {
  9800. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9801. }
  9802. }
  9803. catch { }
  9804. });
  9805. }
  9806. #endregion UI刷新
  9807. #region 日志
  9808. /// <summary>
  9809. /// 添加各工位运行日志(同步至PLC交互页面)
  9810. /// </summary>
  9811. /// <param name="stationNameStr">工站名称</param>
  9812. /// <param name="logType">日志类型</param>
  9813. /// <param name="message">日志内容</param>
  9814. /// <param name="snNumber">产品数字SN</param>
  9815. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9816. {
  9817. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9818. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9819. ))
  9820. {
  9821. AddMessage(logType, message); // 首页展示+日志记录
  9822. }
  9823. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9824. {
  9825. StationName = stationNameStr,
  9826. SnNumber = snNumber,
  9827. Message = message,
  9828. CreateTime = DateTime.Now
  9829. };
  9830. // PLC交互页展示
  9831. Task.Run(() =>
  9832. {
  9833. try
  9834. {
  9835. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9836. {
  9837. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9838. }
  9839. }
  9840. catch { }
  9841. });
  9842. }
  9843. /// <summary>
  9844. /// 添加运行日志
  9845. /// </summary>
  9846. /// <param name="logType">日志类型</param>
  9847. /// <param name="message">日志内容</param>
  9848. public void AddMessage(LogType logType, string message)
  9849. {
  9850. OnMessage(logType, message);
  9851. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9852. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9853. string msgShow = time + "--> " + message + "\r\n";
  9854. this.BeginInvoke(new Action(() =>
  9855. {
  9856. systemLog.Rows.Insert(0, date, time, message);
  9857. if (systemLog.Rows.Count >= 100)
  9858. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9859. }));
  9860. }
  9861. /// <summary>
  9862. /// 添加运行日志-保存
  9863. /// </summary>
  9864. /// <param name="logType">日志类型</param>
  9865. /// <param name="message">日志内容</param>
  9866. private void OnMessage(LogType logType, string msg)
  9867. {
  9868. MessageEvent?.Invoke(logType, msg);
  9869. }
  9870. /// <summary>
  9871. /// 保存PLC写入日志
  9872. /// </summary>
  9873. /// <param name="logType"></param>
  9874. /// <param name="logValue"></param>
  9875. private void WritePLCLog(LogType logType, string logValue)
  9876. {
  9877. switch ((int)logType)
  9878. {
  9879. case 0:
  9880. _PLCLogNet.WriteDebug(logValue);
  9881. break;
  9882. case 1:
  9883. _PLCLogNet.WriteInfo(logValue);
  9884. break;
  9885. case 2:
  9886. _PLCLogNet.WriteWarn(logValue);
  9887. break;
  9888. case 3:
  9889. _PLCLogNet.WriteError(logValue);
  9890. break;
  9891. default:
  9892. _PLCLogNet.WriteFatal(logValue);
  9893. break;
  9894. }
  9895. }
  9896. /// <summary>
  9897. /// IOT Mqtt回调方法- With DataId
  9898. /// </summary>
  9899. /// <param name="id"></param>
  9900. /// <param name="v"></param>
  9901. /// <param name="dataId"></param>
  9902. public void CallbackWithDataId(string id, string msg, string dataId)
  9903. {
  9904. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9905. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9906. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9907. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9908. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9909. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9910. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9911. }
  9912. /// <summary>
  9913. /// AGV Mqtt回调方法- 记录Log并处理数据
  9914. /// </summary>
  9915. /// <param name="obj"></param>
  9916. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9917. {
  9918. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9919. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9920. // 接收到的信息
  9921. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9922. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9923. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9924. {
  9925. }
  9926. }
  9927. #endregion 日志
  9928. /// <summary>
  9929. /// 实例化报警字典
  9930. /// </summary>
  9931. private void InitalDicAlarm()
  9932. {
  9933. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9934. List<Alarm> keyValues1 = new List<Alarm>
  9935. {
  9936. #region 第一组报警(电机)
  9937. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9938. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9939. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9940. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9941. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9942. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9943. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9944. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9945. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9946. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9947. #endregion 第一组报警(电机)
  9948. #region 第二组报警(气缸)
  9949. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9950. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9951. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9952. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9953. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9954. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9955. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9956. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9957. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9958. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9959. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9960. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9961. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9962. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9963. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9964. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9965. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9966. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9967. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9968. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9969. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9970. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9971. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9972. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9973. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9974. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9975. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9976. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9977. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9978. #endregion 第二组报警(气缸)
  9979. #region 第三组报警(其他故障)
  9980. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9981. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9982. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9983. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9984. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9985. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9986. #endregion 第三组报警(其他故障)
  9987. };
  9988. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9989. #endregion 第一个工站(这里使用线体代替工位)
  9990. # region 第二个工站-原来的写法(废弃)
  9991. //keyValues = new Dictionary<int, AlarmData[]>();
  9992. ////1
  9993. //dicAlarmName = new Dictionary<int, Alarm>();
  9994. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  9995. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  9996. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  9997. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  9998. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  9999. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10000. //for (int i = 0; i < dicAlarmName.Count; i++)
  10001. //{
  10002. // alarmDatas[i] = new AlarmData();
  10003. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  10004. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10005. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10006. // alarmDatas[i].AlarmType = 1;
  10007. //}
  10008. //keyValues.Add(1, alarmDatas);
  10009. ////2
  10010. //dicAlarmName = new Dictionary<int, Alarm>();
  10011. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  10012. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  10013. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  10014. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  10015. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  10016. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  10017. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  10018. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  10019. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10020. //for (int i = 0; i < dicAlarmName.Count; i++)
  10021. //{
  10022. // alarmDatas[i] = new AlarmData();
  10023. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  10024. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10025. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10026. // alarmDatas[i].AlarmType = 2;
  10027. //}
  10028. //keyValues.Add(2, alarmDatas);
  10029. ////3
  10030. //dicAlarmName = new Dictionary<int, Alarm>();
  10031. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  10032. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  10033. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  10034. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  10035. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10036. //for (int i = 0; i < dicAlarmName.Count; i++)
  10037. //{
  10038. // alarmDatas[i] = new AlarmData();
  10039. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  10040. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10041. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10042. // alarmDatas[i].AlarmType = 3;
  10043. //}
  10044. //keyValues.Add(3, alarmDatas);
  10045. //DicAlarms.Add(2, keyValues);
  10046. #endregion 第二个工站-原来的写法(废弃)
  10047. }
  10048. private void button1_Click(object sender, EventArgs e)
  10049. {
  10050. OpenDailogFalg=true;
  10051. if (OpenDailogFalg)
  10052. {
  10053. using (var dialog = new BandBarodeDialog())
  10054. {
  10055. string strCarrierBarcode = "N801A-003";
  10056. dialog._CarrierBarcode = strCarrierBarcode;
  10057. string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  10058. dialog._ProductBarcode = sn;
  10059. var rs = dialog.ShowDialog();
  10060. if (rs == DialogResult.OK)
  10061. {
  10062. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  10063. OpenDailogFalg = false;//关闭扫码
  10064. }
  10065. }
  10066. }
  10067. }
  10068. }
  10069. }