Form_Home.cs 586 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. /*
  40. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  41. */
  42. namespace MainForm
  43. {
  44. /// <summary>
  45. /// 记录日志的委托
  46. /// </summary>
  47. /// <param name="logType">日志类型</param>
  48. /// <param name="message">日志信息</param>
  49. public delegate void HomeMessageHandler(LogType logType, string message);
  50. /// <summary>
  51. /// 主页窗体
  52. /// </summary>
  53. public partial class Form_Home : Form
  54. {
  55. #region 常量
  56. //文本常量
  57. private const string Head = "开始采集";
  58. private const string Tail = "采集完成";
  59. private const string Body = "工位出站数据";
  60. private const string BodyCheck = "工位点检数据";
  61. private const string BodyRun = "整线运行数据";
  62. private const string BodyAlarm = "整线报警数据";
  63. #endregion 常量
  64. #region 变量
  65. /// <summary>
  66. /// 委托-记录日志的方法
  67. /// </summary>
  68. public event HomeMessageHandler MessageEvent;
  69. /// <summary>
  70. /// 日志接口
  71. /// </summary>
  72. ILogNet _PLCLogNet;
  73. /// <summary>
  74. /// 用于记录IOT MQTT日志
  75. /// </summary>
  76. ILogNet _IOTMqttLogNet;
  77. /// <summary>
  78. /// 用于记录AGV MQTT日志
  79. /// </summary>
  80. ILogNet _AGVMqttLogNet;
  81. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  82. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  83. // 间隔时间
  84. private int IntervalReadPLC = 300; //ms 读PLC
  85. private int IntervalMonitorMES = 1000; //ms MES心跳
  86. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  87. // 软件状态
  88. private bool IsRun = true;
  89. #region PLC 与 TCP对象
  90. // 定义一个字典,存plc对象(通讯)
  91. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  92. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  93. // 定义TCPClient对象列表
  94. Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  95. // 定义MQTTHelper对象
  96. MQTTHelper _MQTTHelper = new MQTTHelper();
  97. #endregion PLC 与 TCP对象
  98. /// <summary>
  99. /// 上次的设备运行信息
  100. /// </summary>
  101. private string lineWorkingData1_OldStr = string.Empty;
  102. /// <summary>
  103. /// 设备报警字典-当前结果
  104. /// Dictionary<工位代码,List<报警信息>>
  105. /// </summary>
  106. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  107. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  108. #endregion 变量
  109. #region 窗体基础事件
  110. /// <summary>
  111. /// 初始化
  112. /// </summary>
  113. public Form_Home()
  114. {
  115. InitializeComponent();
  116. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  117. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  118. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  119. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  120. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  121. }
  122. /// <summary>
  123. /// 窗体加载事件
  124. /// </summary>
  125. private void Form_Home_Load(object sender, EventArgs e)
  126. {
  127. try
  128. {
  129. AddMessage(LogType.Info, "开始初始化程序");
  130. InitalDicAlarm(); // 实例化报警字典
  131. //组建plc对象字典
  132. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  133. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  134. if (GlobalContext.IsUsePLC1)
  135. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  136. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  137. if (GlobalContext.IsUsePLC2)
  138. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  139. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  140. if (GlobalContext.IsUsePLC3)
  141. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  142. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  143. if (GlobalContext.IsUsePLC4)
  144. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  145. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  146. if (GlobalContext.IsUsePLC5)
  147. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  148. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  149. if (GlobalContext.IsUsePLC6)
  150. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  151. if (GlobalContext.IsUsePLC7)
  152. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  153. if (GlobalContext.IsUsePLC8)
  154. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  155. if (GlobalContext.IsUsePLC9)
  156. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  157. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  158. {
  159. if (plcEIP != null)
  160. {
  161. try
  162. {
  163. (int, string) result = plcEIP.Connect();
  164. }
  165. catch (Exception ex)
  166. {
  167. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  168. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  169. }
  170. }
  171. }
  172. /*
  173. //plc1Alarm.Connect();
  174. foreach (ModbusClientHelper modbusClient in Funs.Values)
  175. {
  176. if (modbusClient != null)
  177. {
  178. try
  179. {
  180. modbusClient.Connect();
  181. }
  182. catch (Exception ex)
  183. {
  184. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  185. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  186. }
  187. }
  188. }
  189. */
  190. // 采集任务
  191. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  192. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  193. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  194. if (GlobalContext.IsUsePLC1)
  195. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  196. if (GlobalContext.IsUsePLC2)
  197. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  198. if (GlobalContext.IsUsePLC3)
  199. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  200. if (GlobalContext.IsUsePLC4)
  201. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  202. if (GlobalContext.IsUsePLC5)
  203. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  204. if (GlobalContext.IsUsePLC6)
  205. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  206. if (GlobalContext.IsUsePLC7)
  207. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  208. if (GlobalContext.IsUsePLC8)
  209. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  210. if (GlobalContext.IsUsePLC9)
  211. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  212. #region 初始化
  213. try
  214. {
  215. // 开启边线MES(绑定/查询数据)
  216. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  217. //if (mesRoute == 0)
  218. //{
  219. // //picMESStatus.Image = imageListState.Images[1];
  220. // //GlobalContext.MESIsConnect = true;
  221. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  222. //}
  223. //else
  224. //{
  225. // //picMESStatus.Image = imageListState.Images[0];
  226. // //GlobalContext.MESIsConnect = false;
  227. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  228. //}
  229. // 开启MES(Http)
  230. if (GlobalContext.IsUseMES)
  231. {
  232. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  233. if (mesret)
  234. {
  235. picMESStatus.Image = imageListState.Images[1];
  236. GlobalContext.MESIsConnect = true;
  237. AddMessage(LogType.Info, "小米MES初始连接成功!");
  238. }
  239. else
  240. {
  241. picMESStatus.Image = imageListState.Images[0];
  242. GlobalContext.MESIsConnect = false;
  243. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  244. }
  245. }
  246. // 开启IOT(MQTT)
  247. if (GlobalContext.IsUseIot)
  248. {
  249. string addr = GlobalContext.MQTTServerHost;
  250. int port = GlobalContext.MQTTServerPort;
  251. //生产环境需要修改
  252. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  253. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  254. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  255. {
  256. picIot.Image = imageListState.Images[1];
  257. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  258. // 设置回调函数
  259. XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  260. // 配置参数
  261. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  262. // fds
  263. param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
  264. param.parameter.fds.appId = "Auto-Soft";
  265. param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
  266. // mes
  267. param.parameter.mes.address = GlobalContext.ServerIp;
  268. param.parameter.mes.appId = GlobalContext.MESAppId;
  269. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  270. // mqtt
  271. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  272. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  273. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  274. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  275. // 设备配置
  276. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  277. if (GlobalContext.IsUsePLC1)
  278. {
  279. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  280. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  281. }
  282. if (GlobalContext.IsUsePLC2)
  283. {
  284. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  285. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  286. }
  287. if (GlobalContext.IsUsePLC3)
  288. {
  289. param.parameter.equipment.deviceCode = GlobalContext.S3_device_code; // 装备编码
  290. param.parameter.equipment.stationCode = GlobalContext.S3_station; // ⼯位Id
  291. }
  292. if (GlobalContext.IsUsePLC4)
  293. {
  294. param.parameter.equipment.deviceCode = GlobalContext.S4_1_device_code; // 装备编码
  295. param.parameter.equipment.stationCode = GlobalContext.S4_1_station; // ⼯位Id
  296. }
  297. if (GlobalContext.IsUsePLC5)
  298. {
  299. param.parameter.equipment.deviceCode = GlobalContext.S5_device_code; // 装备编码
  300. param.parameter.equipment.stationCode = GlobalContext.S5_station; // ⼯位Id
  301. }
  302. if (GlobalContext.IsUsePLC6)
  303. {
  304. param.parameter.equipment.deviceCode = GlobalContext.S6_device_code; // 装备编码
  305. param.parameter.equipment.stationCode = GlobalContext.S6_station; // ⼯位Id
  306. }
  307. if (GlobalContext.IsUsePLC7)
  308. {
  309. param.parameter.equipment.deviceCode = GlobalContext.S7_device_code; // 装备编码
  310. param.parameter.equipment.stationCode = GlobalContext.S7_station; // ⼯位Id
  311. }
  312. if (GlobalContext.IsUsePLC8)
  313. {
  314. param.parameter.equipment.deviceCode = GlobalContext.S8_device_code; // 装备编码
  315. param.parameter.equipment.stationCode = GlobalContext.S8_station; // ⼯位Id
  316. }
  317. if (GlobalContext.IsUsePLC9)
  318. {
  319. param.parameter.equipment.deviceCode = GlobalContext.S9_device_code; // 装备编码
  320. param.parameter.equipment.stationCode = GlobalContext.S9_station; // ⼯位Id
  321. }
  322. param.parameter.equipment.project = GlobalContext.Project_Code;
  323. param.parameter.equipment.productMode = "debug";
  324. //
  325. param.parameter.other.logLevel = 0;
  326. param.parameter.other.LogPath = "D:\\Test";
  327. XiaomiMqttClient_Extend.ParameterConfig(param);
  328. }
  329. else
  330. {
  331. picIot.Image = imageListState.Images[0];
  332. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  333. }
  334. }
  335. // 开启AGV(Http与MQTT)
  336. if (GlobalContext.IsUseAGV)
  337. {
  338. // AGV HTTP
  339. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  340. if (mesret1)
  341. {
  342. picAgvHttp.Image = imageListState.Images[1];
  343. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  344. }
  345. else
  346. {
  347. picAgvHttp.Image = imageListState.Images[0];
  348. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  349. }
  350. string agvMqttIp = GlobalContext.MQTTServerHost;
  351. int agvMqttPort = GlobalContext.MQTTServerPort;
  352. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  353. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  354. // AGV MQTT
  355. if (result_MQTT.ResultCode == 1)
  356. {
  357. picAgvMqtt.Image = imageListState.Images[1];
  358. GlobalContext.AGVMQTTIsConnect = true;
  359. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  360. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  361. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  362. }
  363. else
  364. {
  365. picAgvMqtt.Image = imageListState.Images[0];
  366. GlobalContext.AGVMQTTIsConnect = false;
  367. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  368. }
  369. }
  370. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  371. Task.Run(MonitorMESConnect);
  372. // 查询PLC连接状态
  373. foreach (int plcNo in FunsEip.Keys)
  374. {
  375. bool connected = FunsEip[plcNo].IsConnected;
  376. if (connected)
  377. {
  378. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  379. AddMessage(LogType.Info, msg);
  380. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  381. }
  382. else
  383. {
  384. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  385. AddMessage(LogType.Info, msg);
  386. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  387. }
  388. }
  389. // PLC4时 初始化扫码器TCP
  390. //if (GlobalContext.IsUsePLC4)
  391. // HpTCPClientInit();
  392. // 开启PLC的业务处理线程-监听PLC点位+状态
  393. foreach (Task task in TaskReadProcess)
  394. {
  395. if (task != null)
  396. task.Start();
  397. }
  398. //// 开启“获取线体报警数据”的线程
  399. //TaskReadAlarm.Start();
  400. ////下传MES信息给1工位(先判断下plc对象数量)
  401. //if (Funs.Count > 1)
  402. // DownLoadProductInfo(1);
  403. AddMessage(LogType.Info, "程序初始化完成");
  404. }
  405. catch (Exception ex)
  406. {
  407. string str = ex.StackTrace;
  408. this.BeginInvoke(new Action(() =>
  409. {
  410. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  411. }));
  412. }
  413. #endregion
  414. }
  415. catch (Exception ex)
  416. {
  417. string str = ex.StackTrace;
  418. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  419. if (ex.Message != null && ex.Message.Contains("timed out"))
  420. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  421. else
  422. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  423. }
  424. }
  425. /// <summary>
  426. /// 窗体关闭事件
  427. /// </summary>
  428. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  429. {
  430. Closed2();
  431. }
  432. public void Closed2()
  433. {
  434. try
  435. {
  436. IsRun = false;
  437. Thread.Sleep(IntervalReadPLC);
  438. // 断开TCP
  439. int count = _HPSocket_TcpClients.Count();
  440. for (int i = 0; i < count; i++)
  441. {
  442. try
  443. {
  444. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  445. {
  446. _HPSocket_TcpClients[i].Stop();
  447. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  448. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  449. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  450. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  451. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  452. }
  453. }
  454. catch { }
  455. }
  456. // 关闭Iot
  457. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  458. // 关闭AGV Mqtt
  459. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  460. }
  461. catch { }
  462. }
  463. #endregion 窗体基础事件
  464. #region 监控MES状态
  465. /// <summary>
  466. /// 监控MES连接状态
  467. /// </summary>
  468. private void MonitorMESConnect()
  469. {
  470. while (IsRun) // 运行被控线程
  471. {
  472. try
  473. {
  474. // 开启MES(Http)
  475. if (GlobalContext.IsUseMES)
  476. {
  477. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  478. if (mesret)
  479. {
  480. picMESStatus.Image = imageListState.Images[1];
  481. GlobalContext.MESIsConnect = true;
  482. }
  483. else
  484. {
  485. picMESStatus.Image = imageListState.Images[0];
  486. GlobalContext.MESIsConnect = false;
  487. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  488. }
  489. }
  490. // 开启IOT(MQTT)
  491. if (GlobalContext.IsUseIot)
  492. {
  493. bool iIot = XiaomiMqttClient.IsOpen;
  494. if (iIot)
  495. picIot.Image = imageListState.Images[1];
  496. else
  497. {
  498. picIot.Image = imageListState.Images[0];
  499. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  500. }
  501. }
  502. // 开启AGV(Http与MQTT)
  503. if (GlobalContext.IsUseAGV)
  504. {
  505. // AGV Http
  506. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  507. if (mesret1)
  508. picAgvHttp.Image = imageListState.Images[1];
  509. else
  510. {
  511. picAgvHttp.Image = imageListState.Images[0];
  512. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  513. }
  514. // AGV MQTT
  515. if (GlobalContext.AGVMQTTIsConnect)
  516. picAgvMqtt.Image = imageListState.Images[1];
  517. else
  518. {
  519. picAgvMqtt.Image = imageListState.Images[0];
  520. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  521. }
  522. }
  523. }
  524. catch (Exception ex)
  525. {
  526. string str = ex.StackTrace;
  527. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  528. }
  529. Thread.Sleep(IntervalMonitorMES);
  530. }
  531. }
  532. #endregion 监控MES连接状态
  533. #region 采集设备状态、运行数据、报警数据
  534. /// <summary>
  535. /// 请求设备状态 5000
  536. /// </summary>
  537. /// <param name="no">1</param>
  538. /// <param name="stationNameStr"></param>
  539. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  540. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  541. {
  542. try
  543. {
  544. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  545. {
  546. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  547. return result;
  548. }
  549. else
  550. {
  551. return 0;
  552. }
  553. }
  554. catch (Exception ex)
  555. {
  556. string str = ex.StackTrace;
  557. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  558. return 0;
  559. }
  560. }
  561. /// <summary>
  562. /// 检查是否可采集点检数据 - 不取新值
  563. /// 5000不为1时可点检
  564. /// </summary>
  565. /// <returns></returns>
  566. public bool CheckCanSpotcheck1(int deviceState)
  567. {
  568. //return true;
  569. //D5000 = 1,代表设备控制状态处于运行状态
  570. //D5000 = 2, 代表设备控制状态处于故障状态
  571. //D5000 = 3,代表设备控制状态处于缺料状态
  572. //D5000 = 4, 代表设备控制状态处于待机状态
  573. //D5000 = 5,代表设备控制状态处于维修状态
  574. return deviceState != 1;
  575. }
  576. /// <summary>
  577. /// 检查是否可采集产品数据 - 不取新值
  578. /// </summary>
  579. /// <returns></returns>
  580. public bool CheckCanCollData(int deviceState)
  581. {
  582. return deviceState == 0; // 点检时该值不为0
  583. }
  584. /// <summary>
  585. /// 获取设备报警数据与获取设备运行信息
  586. /// </summary>
  587. private async void ReadAlarmAllPLC()
  588. {
  589. // [S1] Tray盘上料装备(板测)
  590. // [S2] FCT(板测)
  591. // [S3] 值板机
  592. // [S4] 取放桁架
  593. // [S5] Tray盘下料装备
  594. /// 上位机心跳
  595. /// 获取设备报警数据与状态信息
  596. string stationNameStr = "获取设备报警数据与状态信息";
  597. while (IsRun)
  598. {
  599. try
  600. {
  601. if (!GlobalContext._IsCon_plc1Alarm)
  602. {
  603. UpdatePLCMonitor(1, -2, 0);
  604. continue;
  605. }
  606. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  607. {
  608. DateTime dtNow = DateTime.Now;
  609. #region 获取设备运行信息
  610. try
  611. {
  612. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  613. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  614. lineWorkingData1.LineName = GlobalContext.LineCode;
  615. //
  616. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  617. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  618. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  619. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  620. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  621. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  622. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  623. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  624. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  625. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  626. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  627. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  628. lineWorkingData1.CreateTime = DateTime.Now;
  629. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  630. // UI展示-展示到设备状态页
  631. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  632. {
  633. // 查询数据库最新一条数据,确定是不是更新
  634. string qSql = @"SELECT top(1) [GUID]
  635. ,[LineName]
  636. ,[BootTimeLong]
  637. ,[NormalTimeLong]
  638. ,[StandbyTimeLong]
  639. ,[FaultTimeLong]
  640. ,[MaterialShortageTimeLong]
  641. ,[MaintenanceTimeLong]
  642. ,[FaultNumber]
  643. ,[OutputNumber]
  644. ,[QualifiedNumber]
  645. ,[QualifiedRate]
  646. ,[DesignRhythm]
  647. ,[RealityRhythm]
  648. ,[CreateTime]
  649. FROM [LineWorkingData]
  650. where [CreateTime] > '{0}'
  651. and [LineName]='{1}'
  652. order by [CreateTime] desc
  653. ";
  654. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  655. var ds = SQLHelper_New.Query(qSql, null);
  656. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  657. {
  658. var dataDBlast = new LineWorkingData_ThisTime();
  659. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  660. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  661. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  662. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  663. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  664. {
  665. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  666. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  667. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  668. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  669. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  670. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  671. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  672. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  673. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  674. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  675. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  676. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  677. string usql = dataDBlast.ToStringUpdate();
  678. SQLHelper_New.ExecuteSQL(usql, null);
  679. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  680. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  681. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  682. }
  683. }
  684. else
  685. {
  686. // 插入
  687. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  688. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  689. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  690. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  691. }
  692. }
  693. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  694. {
  695. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  696. //// 本次开机设备运行情况
  697. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  698. //Task.Run(() =>
  699. //{
  700. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  701. // {
  702. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  703. // }
  704. //});
  705. // 本日设备运行情况
  706. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  707. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  708. {
  709. // 更新
  710. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  711. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  712. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  713. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  714. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  715. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  716. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  717. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  718. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  719. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  720. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  721. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  722. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  723. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  724. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  725. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  726. }
  727. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  728. {
  729. // 插入
  730. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  731. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  732. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  733. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  734. }
  735. await Task.Run(() =>
  736. {
  737. try
  738. {
  739. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  740. {
  741. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  742. }
  743. }
  744. catch { }
  745. });
  746. }
  747. }
  748. catch (Exception ex)
  749. {
  750. string str = ex.StackTrace;
  751. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  752. }
  753. #endregion 获取设备运行信息
  754. #region 报警数据
  755. try
  756. {
  757. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  758. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  759. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  760. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  761. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  762. {
  763. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  764. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  765. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  766. {
  767. isNeedUpdUI = true; // 需要更新历史报警UI信息
  768. // 记录
  769. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  770. switch (dicAlarms_Cur_PLC1[i].是否报警)
  771. {
  772. case true: // 报警
  773. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  774. {
  775. GUID = Guid.NewGuid().ToString(),
  776. LineName = GlobalContext.LineCode, // 线体
  777. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  778. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  779. StartTime = dtNow // 开始时间
  780. };
  781. // 传输到页面
  782. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  783. {
  784. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  785. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  786. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  787. 开始时间 = dtNow
  788. });
  789. // 新增到数据库
  790. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  791. SaveAlarmDataByDB(stationNameStr, data1, false);
  792. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  793. break;
  794. case false: // 消除报警
  795. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  796. {
  797. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  798. {
  799. GUID = Guid.NewGuid().ToString(),
  800. LineName = GlobalContext.LineCode, // 线体
  801. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  802. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  803. StartTime = dtNow, // 开始时间
  804. EndTime = dtNow, // 开始时间
  805. PersistTime = 1, // 耗时1s
  806. };
  807. // 新增
  808. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  809. SaveAlarmDataByDB(stationNameStr, data2, false);
  810. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  811. }
  812. else
  813. {
  814. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  815. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  816. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  817. // 修改
  818. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  819. SaveAlarmDataByDB(stationNameStr, data3, true);
  820. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  821. }
  822. break;
  823. default:
  824. break;
  825. }
  826. }
  827. }
  828. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  829. // 有新报警则更新
  830. if (isNeedUpdUI)
  831. {
  832. // UI展示 - 展示到设备状态页
  833. await Task.Run(() =>
  834. {
  835. try
  836. {
  837. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  838. {
  839. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  840. if (Form_Main.formDevAlarm.Visible)
  841. {
  842. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  843. }
  844. }
  845. }
  846. catch { }
  847. });
  848. }
  849. }
  850. catch (Exception ex)
  851. {
  852. string str = ex.StackTrace;
  853. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  854. }
  855. #endregion 报警数据
  856. UpdatePLCMonitor(1, -2, 1);
  857. }
  858. else
  859. {
  860. UpdatePLCMonitor(1, -2, 0);
  861. }
  862. }
  863. catch (Exception ex)
  864. {
  865. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  866. }
  867. Thread.Sleep(IntervalAlarm);
  868. }
  869. }
  870. #endregion 轮询PLC
  871. #region 下发订单信息
  872. ///// <summary>
  873. ///// 壳体上料(下发工单)的交互逻辑
  874. ///// </summary>
  875. ///// <param name="no"></param>
  876. ///// <exception cref="NotImplementedException"></exception>
  877. //private void ReadStation_DownOrderInfo(int plcNo)
  878. //{
  879. // // [S1] Tray盘上料装备(板测)
  880. // // [S2] FCT(板测)
  881. // // [S3] 值板机
  882. // // [S4] 取放桁架
  883. // // [S5] Tray盘下料装备
  884. // /// 上位机心跳
  885. // /// 获取设备报警数据与状态信息
  886. // string stationNameStr = "[S0]壳体上料";
  887. // while (IsRun)
  888. // {
  889. // try
  890. // {
  891. // if (!GlobalContext._IsCon_Funs1)
  892. // {
  893. // UpdatePLCMonitor(plcNo, 0);
  894. // continue;
  895. // }
  896. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  897. // {
  898. // #region 壳体上料(下发工单)
  899. // try
  900. // {
  901. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  902. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  903. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  904. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  905. // // 重置数据和信号
  906. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  907. // {
  908. // // 清空写给PLC的数据
  909. // int[] i497 = new int[1] { 0 };
  910. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  911. // // MES_Flag重置为0
  912. // int[] i500 = new int[1] { 0 };
  913. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  914. // }
  915. // }
  916. // catch (Exception ex)
  917. // {
  918. // string str = ex.StackTrace;
  919. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  920. // }
  921. // #endregion 壳体上料(下发工单)
  922. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  923. // }
  924. // else
  925. // {
  926. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  927. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  928. //
  929. // Funs[plcNo].Connect();
  930. // }
  931. // }
  932. // catch (Exception ex)
  933. // {
  934. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  935. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  936. //
  937. // Funs[plcNo].ReConnect();
  938. // }
  939. // Thread.Sleep(IntervalReadPLC);
  940. // }
  941. //}
  942. ///// <summary>
  943. ///// 下发订单信息到PLC
  944. ///// </summary>
  945. ///// <param name="no">PLC编号</param>
  946. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  947. //{
  948. // try
  949. // {
  950. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  951. // {
  952. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  953. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  954. // }
  955. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  956. // }
  957. // catch (Exception ex)
  958. // {
  959. // string str = ex.StackTrace;
  960. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  961. // }
  962. //}
  963. /// <summary>
  964. /// 下发清料信号
  965. /// </summary>
  966. /// <param name="no">PLC编号</param>
  967. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  968. {
  969. try
  970. {
  971. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  972. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  973. return true;
  974. }
  975. catch (Exception ex)
  976. {
  977. string str = ex.StackTrace;
  978. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  979. return false;
  980. }
  981. }
  982. #endregion 下发订单信息
  983. #region Xiaomi 贲流
  984. #region 公共方法
  985. private static bool ProgressState = false;
  986. private static readonly object lockObj = new object(); // 锁对象
  987. private static bool isCollectingFlagLeft;
  988. private static bool isCollectingFlagRight;
  989. /// <summary>
  990. /// float[]转为string
  991. /// </summary>
  992. public string FloatArrayToString(float[] nScrewResults)
  993. {
  994. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  995. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  996. }
  997. /// <summary>
  998. /// short[]转为string
  999. /// </summary>
  1000. public string ShortArrayToString(short[] nScrewResults)
  1001. {
  1002. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1003. return string.Join(",", nScrewResults);
  1004. }
  1005. /// <summary>
  1006. /// 写入PLC重复三次
  1007. /// </summary>
  1008. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  1009. {
  1010. int i = 0;
  1011. int nRet = 0;
  1012. string strRet = "";
  1013. try
  1014. {
  1015. while (i < 3) // 最多上传三次
  1016. {
  1017. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1018. if (nRet == 0) //成功
  1019. {
  1020. break;
  1021. }
  1022. else
  1023. {
  1024. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1025. i++;
  1026. }
  1027. }
  1028. return (nRet, strRet);
  1029. }
  1030. catch (Exception ex)
  1031. {
  1032. return (1, ex.Message);
  1033. }
  1034. }
  1035. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  1036. {
  1037. try
  1038. {
  1039. // 获取当前日期
  1040. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1041. // 构建保存路径
  1042. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1043. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  1044. // 确保目录存在
  1045. Directory.CreateDirectory(savePath);
  1046. // 文件名
  1047. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1048. string filePath = Path.Combine(savePath, fileName);
  1049. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1050. int count = Math.Min(14, fScrewTimes.Length);
  1051. using (StreamWriter sw = new StreamWriter(filePath))
  1052. {
  1053. for (int i = 0; i < count; i++)
  1054. {
  1055. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1056. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1057. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1058. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1059. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1060. }
  1061. }
  1062. return (0, "");
  1063. }
  1064. catch (Exception ex)
  1065. {
  1066. return (1, ex.Message);
  1067. }
  1068. }
  1069. public Dictionary<string, string> GetLastLineCompensation(string path,string direction,string sn)
  1070. {
  1071. // 创建字典存储补偿点及其对应的值
  1072. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1073. try
  1074. {
  1075. //string path = GlobalContext.MESLaserRPath;
  1076. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1077. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1078. string filename = $"Laser-{currentDate}-W0.txt";
  1079. // 拼接完整路径
  1080. string fullPath = Path.Combine(path, filename);
  1081. string lastNonEmptyLine = "";
  1082. // 判断文件是否存在
  1083. if (File.Exists(fullPath))
  1084. {
  1085. //读取文件内容
  1086. string[] lines = File.ReadAllLines(fullPath);
  1087. // 获取最后一行数据(忽略标题行)
  1088. if (lines.Length > 1)
  1089. {
  1090. string lastLine = "";
  1091. for (int i = lines.Length - 1; i > 0; i--)
  1092. {
  1093. if (!string.IsNullOrEmpty(lines[i]))
  1094. {
  1095. lastLine = lines[i];
  1096. break;
  1097. }
  1098. }
  1099. // 将最后一行按逗号分隔
  1100. string[] values = lastLine.Split(',');
  1101. values[1] = sn;
  1102. string key = "三点激光_"+ direction; // 构造键名
  1103. string value = string.Join(",", values); // 获取值并去除多余空格
  1104. compensationDict[key] = value;
  1105. //// 提取“1点补偿”到“6点补偿”的值
  1106. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1107. //{
  1108. // string key = $"{i - 1}点补偿"; // 构造键名
  1109. // string value = values[i].Trim(); // 获取值并去除多余空格
  1110. // compensationDict[key] = value;
  1111. //}
  1112. }
  1113. }
  1114. else
  1115. {
  1116. Console.WriteLine($"文件不存在: {fullPath}");
  1117. }
  1118. }
  1119. catch (Exception ex)
  1120. {
  1121. // 捕获异常并输出错误信息
  1122. Console.WriteLine($"发生错误: {ex.Message}");
  1123. }
  1124. return compensationDict;
  1125. }
  1126. /// <summary>
  1127. /// 调用进站接口并保存进站数据
  1128. /// </summary>
  1129. /// <param name="stationNameStr">工站信息</param>
  1130. /// <param name="workorder_code">工单号</param>
  1131. /// <param name="mtltmrk">型号(物料号)</param>
  1132. /// <param name="sn">产品SN</param>
  1133. /// <param name="items">进站数据</param>
  1134. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1135. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1136. {
  1137. int result = 0;
  1138. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1139. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1140. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1141. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1142. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1143. inRequest_Body.unitSn = sn; // 产品SN
  1144. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1145. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1146. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1147. StationIn stationIn = new StationIn()
  1148. {
  1149. Workorder_code = workorder_code, // 车间订单号
  1150. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1151. Sn = sn, // SN
  1152. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1153. Parameter_values = items, // 进站数据
  1154. Write_user = inRequest_Body.userId, // 员工Id
  1155. Test_time = inRequest_Body.clientTime // 进站时间
  1156. };
  1157. // 本地数据
  1158. string sql = stationIn.ToStringInsert(0);
  1159. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1160. result = ret == "成功" ? 1 : 6;
  1161. //await Task.Delay(200);
  1162. // 上传MES
  1163. if (GlobalContext.IsSendStationIn)
  1164. {
  1165. try
  1166. {
  1167. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1168. string mesRet = string.Empty;
  1169. int i = 0;
  1170. while (i < 2) // 1009会多次尝试上传
  1171. {
  1172. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1173. if (response != null && response.header.code == "200")
  1174. break;
  1175. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1176. i++;
  1177. i++;
  1178. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1179. // 记录失败原因
  1180. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1181. }
  1182. if (response?.header?.code == "200")
  1183. {
  1184. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1185. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1186. result = ret_Upd == "成功" ? 1 : 6;
  1187. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1188. }
  1189. else
  1190. {
  1191. result = 5;
  1192. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1193. }
  1194. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1195. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1196. }
  1197. catch (Exception ex)
  1198. {
  1199. result = 6;
  1200. string str = ex.StackTrace;
  1201. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1202. }
  1203. }
  1204. return result;
  1205. }
  1206. /// <summary>
  1207. /// 选择如何记录出站数据
  1208. /// </summary>
  1209. /// <param name="items">出站数据</param>
  1210. /// <param name="equipmentCode">设备编号</param>
  1211. /// <param name="processItem">测试项目</param>
  1212. /// <param name="workorder_code">车间订单号</param>
  1213. /// <param name="batch_num">批次号</param>
  1214. /// <param name="mtltmrk">型号</param>
  1215. /// <param name="proDate">日期</param>
  1216. /// <param name="supplierCode">供应商代码</param>
  1217. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1218. /// <returns>上传成功时返回1;失败返回0</returns>
  1219. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1220. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1221. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode,string direction="")
  1222. {
  1223. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1224. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, direction);
  1225. }
  1226. /// <summary>
  1227. /// 添加出站数据(提交到MES+本地保存到数据库)
  1228. /// </summary>
  1229. /// <param name="items">出站数据</param>
  1230. /// <param name="equipmentCode">设备编号</param>
  1231. /// <param name="processItem">测试项目</param>
  1232. /// <param name="workorder_code">车间订单号</param>
  1233. /// <param name="batch_num">批次号</param>
  1234. /// <param name="mtltmrk">型号</param>
  1235. /// <param name="proDate">日期</param>
  1236. /// <param name="supplierCode">供应商代码</param>
  1237. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1238. /// <returns>上传成功时返回1;失败返回0</returns>
  1239. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1240. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1241. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode,string direction="")
  1242. {
  1243. int upload = 0;
  1244. int result = 0;
  1245. ProcessData processData = new ProcessData()
  1246. {
  1247. Equipment_code = equipmentCode,
  1248. Workorder_code = workorder_code,
  1249. Batch_number = batch_num,
  1250. Sn = sn, // SN
  1251. Testitem = processItem,
  1252. Parameter_values = items,
  1253. Write_user = GlobalContext.CurrentUser,
  1254. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1255. };
  1256. // 本地数据
  1257. string sql = processData.ToStringInsert(upload);
  1258. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1259. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1260. // 上传MES
  1261. if (GlobalContext.IsSendProcessData)
  1262. {
  1263. try
  1264. {
  1265. string id = processData.ID.Copy();
  1266. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1267. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1268. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1269. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1270. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1271. outRequest_Body.unitSn = sn; // 产品SN
  1272. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1273. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1274. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1275. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1276. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1277. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1278. if (!string.IsNullOrEmpty(partBarcode))
  1279. {
  1280. outRequest_Body.unitData.keyMaterial.Add(
  1281. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1282. {
  1283. bindSort = 1,
  1284. materialSn = partBarcode
  1285. }); // 设备数据 - 部件码
  1286. }
  1287. //OP30站读txt数据
  1288. if (stationNameStr.Contains("OP30"))
  1289. {
  1290. string path = "";
  1291. if (direction == "Left")
  1292. path = GlobalContext.MESLaserLPath;
  1293. else
  1294. path= GlobalContext.MESLaserRPath;
  1295. //字典存储数据
  1296. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction,sn);
  1297. foreach (var kvp in compensationDict)
  1298. {
  1299. outRequest_Body.unitData.processData.Add(
  1300. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1301. {
  1302. dataName = kvp.Key.ToString(),
  1303. dataValue = kvp.Value.ToString()
  1304. });
  1305. }
  1306. }
  1307. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1308. if (GlobalContext.IsSendProcessData)
  1309. {
  1310. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1311. string mesRet = string.Empty;
  1312. int i = 0;
  1313. while (i < 2) // 1009会多次尝试上传
  1314. {
  1315. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1316. if (response != null && response.header.code == "200")
  1317. {
  1318. OnMessage(LogType.Error, "上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" + JsonConvert.SerializeObject(response.body));
  1319. break;
  1320. }
  1321. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1322. i++;
  1323. i++;
  1324. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1325. // 记录失败原因
  1326. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1327. }
  1328. if (response?.header?.code == "200")
  1329. {
  1330. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1331. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1332. result = 1;
  1333. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1334. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1335. }
  1336. else
  1337. {
  1338. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1339. }
  1340. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1341. JsonConvert.SerializeObject(response), id);
  1342. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1343. }
  1344. }
  1345. catch (Exception ex)
  1346. {
  1347. string str = ex.StackTrace;
  1348. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1349. }
  1350. }
  1351. return result;
  1352. }
  1353. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1354. //{
  1355. // Stopwatch stopwatch = new Stopwatch();
  1356. // stopwatch.Start();
  1357. // try
  1358. // {
  1359. // // 初始化 AtlasScrew 实例
  1360. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1361. // atlasScrew1.Initial();
  1362. // // 存储结果的列表
  1363. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1364. // // 存储角度和扭力的字符串列表
  1365. // List<string> angleStrs = new List<string>();
  1366. // List<string> torqueStrs = new List<string>();
  1367. // // 上一次获取的数据
  1368. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1369. // while (isExitAtlasLeft) // 检查是否收集数据
  1370. // {
  1371. // // 获取当前数据
  1372. // var currentResult = atlasScrew1.GetResults();
  1373. // // 判断是否为新数据
  1374. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1375. // {
  1376. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1377. // // 更新角度和扭力的字符串列表
  1378. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1379. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1380. // // 计算角度、扭力、起始扭力和最大扭力
  1381. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1382. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1383. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1384. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1385. // // 将新数据添加到结果列表
  1386. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1387. // // 更新上一次获取的数据
  1388. // lastResult = currentResult;
  1389. // }
  1390. // // 等待一段时间后再次检查
  1391. // Thread.Sleep(20); // 轮询间隔时间
  1392. // // 如果触发了出站,则退出循环
  1393. // if (!isExitAtlasLeft)
  1394. // {
  1395. // break;
  1396. // }
  1397. // }
  1398. // // 生成文件名
  1399. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1400. // // 写入数据到文件
  1401. // using (StreamWriter writer = new StreamWriter(fileName))
  1402. // {
  1403. // // 写入标题行
  1404. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1405. // // 写入每一行数据
  1406. // foreach (var result in results)
  1407. // {
  1408. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1409. // }
  1410. // }
  1411. // stopwatch.Stop();
  1412. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1413. // }
  1414. // catch (Exception ex)
  1415. // {
  1416. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1417. // }
  1418. // finally
  1419. // {
  1420. // // 重置标志变量
  1421. // isExitAtlasLeft = false;
  1422. // }
  1423. //}
  1424. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1425. //{
  1426. // Stopwatch stopwatch = new Stopwatch();
  1427. // stopwatch.Start();
  1428. // try
  1429. // {
  1430. // // 初始化 AtlasScrew 实例
  1431. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1432. // atlasScrew2.Initial();
  1433. // // 存储结果的列表
  1434. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1435. // // 上一次获取的数据
  1436. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1437. // while (isExitAtlasRight) // 检查是否收集数据
  1438. // {
  1439. // // 获取当前数据
  1440. // var currentResult = atlasScrew2.GetResults();
  1441. // // 判断是否为新数据
  1442. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1443. // {
  1444. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1445. // // 将新数据写入PLC
  1446. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1447. // // 将新数据添加到结果列表
  1448. // results.Add(currentResult);
  1449. // // 更新上一次获取的数据
  1450. // lastResult = currentResult;
  1451. // }
  1452. // // 等待一段时间后再次检查
  1453. // Thread.Sleep(20); // 轮询间隔时间
  1454. // // 如果触发了出站,则退出循环
  1455. // if (!isExitAtlasRight)
  1456. // {
  1457. // break;
  1458. // }
  1459. // }
  1460. // // 将所有数据写入文件
  1461. // //WriteDataToFile(sn, direction, results);
  1462. // stopwatch.Stop();
  1463. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1464. // }
  1465. // catch (Exception ex)
  1466. // {
  1467. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1468. // }
  1469. // finally
  1470. // {
  1471. // // 重置标志变量
  1472. // isExitAtlasRight = false;
  1473. // }
  1474. //}
  1475. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1476. {
  1477. Stopwatch stopwatch = new Stopwatch();
  1478. stopwatch.Start();
  1479. int nRet = 0;
  1480. string strRet = "";
  1481. try
  1482. {
  1483. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1484. while (isCollectingFlagLeft)
  1485. {
  1486. // 从缓存中获取所有未处理的数据
  1487. var cachedData = atlasScrew.GetCachedDataLeft();
  1488. foreach (var currentResult in cachedData)
  1489. {
  1490. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1491. {
  1492. continue; // 跳过无效数据
  1493. }
  1494. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1495. // 写入PLC
  1496. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1497. {
  1498. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1499. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1500. };
  1501. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1502. if (nRet != 0)
  1503. {
  1504. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1505. }
  1506. else
  1507. {
  1508. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1509. }
  1510. // 构建保存路径
  1511. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1512. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1513. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1514. Directory.CreateDirectory(savePath); // 确保目录存在
  1515. // 构建文件名(以 SN + 序号命名)
  1516. string fileName = $"{sn}_{fileCounter}.txt";
  1517. string filePath = Path.Combine(savePath, fileName);
  1518. // 写入文件
  1519. using (StreamWriter writer = new StreamWriter(filePath))
  1520. {
  1521. writer.WriteLine("精度, 扭力");
  1522. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1523. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1524. {
  1525. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1526. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1527. writer.WriteLine($"{precision}, {torque}");
  1528. }
  1529. }
  1530. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1531. // 增加文件计数器
  1532. fileCounter++;
  1533. }
  1534. // 如果没有更多数据,则短暂休眠以节省资源
  1535. if (!cachedData.Any())
  1536. {
  1537. Thread.Sleep(10); // 根据需要调整休眠时间
  1538. }
  1539. // 如果触发了出站,则退出循环
  1540. if (!isCollectingFlagLeft)
  1541. {
  1542. break;
  1543. }
  1544. }
  1545. stopwatch.Stop();
  1546. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1547. }
  1548. catch (Exception ex)
  1549. {
  1550. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1551. }
  1552. finally
  1553. {
  1554. isCollectingFlagLeft = false;
  1555. }
  1556. }
  1557. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1558. {
  1559. Stopwatch stopwatch = new Stopwatch();
  1560. stopwatch.Start();
  1561. int nRet = 0;
  1562. string strRet = "";
  1563. try
  1564. {
  1565. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1566. while (isCollectingFlagRight)
  1567. {
  1568. // 从缓存中获取所有未处理的数据
  1569. var cachedData = atlasScrew.GetCachedDataLeft();
  1570. foreach (var currentResult in cachedData)
  1571. {
  1572. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1573. {
  1574. continue; // 跳过无效数据
  1575. }
  1576. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1577. // 写入PLC
  1578. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1579. {
  1580. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1581. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1582. };
  1583. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1584. if (nRet != 0)
  1585. {
  1586. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1587. }
  1588. else
  1589. {
  1590. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1591. }
  1592. // 构建保存路径
  1593. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1594. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1595. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1596. Directory.CreateDirectory(savePath); // 确保目录存在
  1597. // 构建文件名(以 SN + 序号命名)
  1598. string fileName = $"{sn}_{fileCounter}.txt";
  1599. string filePath = Path.Combine(savePath, fileName);
  1600. // 写入文件
  1601. using (StreamWriter writer = new StreamWriter(filePath))
  1602. {
  1603. writer.WriteLine("精度, 扭力");
  1604. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1605. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1606. {
  1607. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1608. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1609. writer.WriteLine($"{precision}, {torque}");
  1610. }
  1611. }
  1612. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1613. // 增加文件计数器
  1614. fileCounter++;
  1615. }
  1616. // 如果没有更多数据,则短暂休眠以节省资源
  1617. if (!cachedData.Any())
  1618. {
  1619. Thread.Sleep(10); // 根据需要调整休眠时间
  1620. }
  1621. // 如果触发了出站,则退出循环
  1622. if (!isCollectingFlagRight)
  1623. {
  1624. break;
  1625. }
  1626. }
  1627. stopwatch.Stop();
  1628. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1629. }
  1630. catch (Exception ex)
  1631. {
  1632. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1633. }
  1634. finally
  1635. {
  1636. isCollectingFlagRight = false;
  1637. }
  1638. }
  1639. #endregion
  1640. #region S1
  1641. /// <summary>
  1642. /// [S1] 壳体清洁上料装备
  1643. /// </summary>
  1644. /// <param name="plcNo">PLC编号</param>
  1645. private void ReadStation_S1(int plcNo)
  1646. {
  1647. string stationCode = "[OP10]";
  1648. string stationName = "壳体清洁上料";
  1649. string stationNameStr = stationCode + stationName;
  1650. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1651. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1652. string tagAgvCommName = "agvCommFrmPC";
  1653. string tagBarsetName = "BarcodeSet";
  1654. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1655. (int, string) result;
  1656. while (true)
  1657. {
  1658. try
  1659. {
  1660. if (!GlobalContext._IsCon_Funs1)
  1661. {
  1662. UpdatePLCMonitor(1, plcNo, 0);
  1663. continue;
  1664. }
  1665. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1666. {
  1667. Stopwatch stopwatch1 = new Stopwatch();
  1668. Stopwatch stopwatch2 = new Stopwatch();
  1669. stopwatch1.Start();
  1670. stopwatch2.Start();
  1671. #region 一次性读取所有数据
  1672. // 一次性读取所有数据
  1673. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1674. if (result.Item1 != 0)
  1675. {
  1676. //richTextBox1.AppendText("\n" + strRet);
  1677. }
  1678. else
  1679. {
  1680. //richTextBox1.AppendText("\n" + "读取成功");
  1681. }
  1682. #endregion 一次性读取所有数据
  1683. stopwatch2.Stop();
  1684. #region 进站
  1685. try
  1686. {
  1687. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1688. {
  1689. lock (lockObj)
  1690. {
  1691. if (!ProgressState)
  1692. {
  1693. ProgressState = true;
  1694. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1695. }
  1696. }
  1697. }
  1698. }
  1699. catch (Exception ex)
  1700. {
  1701. ProgressState = false;
  1702. string str = ex.StackTrace;
  1703. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1704. }
  1705. #endregion 进站
  1706. #region 出站
  1707. try
  1708. {
  1709. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1710. {
  1711. lock (lockObj)
  1712. {
  1713. if (!ProgressState)
  1714. {
  1715. ProgressState = true;
  1716. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1717. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1718. }
  1719. }
  1720. }
  1721. }
  1722. catch (Exception ex)
  1723. {
  1724. ProgressState = false;
  1725. string str = ex.StackTrace;
  1726. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1727. }
  1728. #endregion 出站
  1729. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1730. stopwatch1.Stop();
  1731. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1732. }
  1733. else
  1734. {
  1735. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1736. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1737. FunsEip[plcNo].Connect(); // 重连
  1738. }
  1739. }
  1740. catch (Exception ex)
  1741. {
  1742. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1743. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1744. }
  1745. Thread.Sleep(IntervalReadPLC);
  1746. }
  1747. }
  1748. /// <summary>
  1749. /// [S1] 壳体清洁上料 - 进站
  1750. /// </summary>
  1751. /// <param name="plcNo">PLC编号</param>
  1752. /// <param name="stationNameStr">工站全称</param>
  1753. /// <param name="stPLC_MesData"></param>
  1754. /// <param name="tagMesCommName"></param>
  1755. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1756. {
  1757. Stopwatch stopwatch1 = new Stopwatch();
  1758. Stopwatch stopwatch2 = new Stopwatch();
  1759. try
  1760. {
  1761. stopwatch1.Start();
  1762. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1763. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1764. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1765. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1766. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1767. if (string.IsNullOrEmpty(sn))
  1768. {
  1769. ProgressState = false;
  1770. return;
  1771. }
  1772. //正式生产就用PLC中取的
  1773. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1774. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1775. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1776. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1777. //绑定载具和产品
  1778. ResponseMessage message = new ResponseMessage();
  1779. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1780. if (message.result == false)
  1781. {
  1782. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1783. }
  1784. // 产品SN进站
  1785. List<TestItem> item = new List<TestItem>();
  1786. stopwatch2.Start();
  1787. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1788. stopwatch2.Stop();
  1789. //指令执行结果 1:OK 110:失败
  1790. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1791. //进站结果写入PLC
  1792. CommandFromPLC resultToPlC = new CommandFromPLC();
  1793. resultToPlC.cmd = 0;
  1794. resultToPlC.cmdParam = 0;
  1795. resultToPlC.cmdResult = mesResultFrmWeb;
  1796. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1797. }
  1798. catch (Exception ex)
  1799. {
  1800. string str = ex.StackTrace;
  1801. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1802. CommandFromPLC resultToPlC = new CommandFromPLC();
  1803. resultToPlC.cmd = 0;
  1804. resultToPlC.cmdParam = 0; //指令参数
  1805. resultToPlC.cmdResult = 110;
  1806. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1807. }
  1808. stopwatch1.Stop();
  1809. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1810. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1811. ProgressState = false;
  1812. }
  1813. /// <summary>
  1814. /// [S1] 壳体清洁上料 - 出站接口
  1815. /// </summary>
  1816. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1817. {
  1818. Stopwatch stopwatch1 = new Stopwatch();
  1819. Stopwatch stopwatch2 = new Stopwatch();
  1820. try
  1821. {
  1822. stopwatch1.Start();
  1823. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1824. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1825. string processItem = stationName; // 项目
  1826. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1827. string supplierCode = ""; // 供应商代码
  1828. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1829. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1830. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1831. string sn = string.Empty;
  1832. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1833. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1834. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1835. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1836. a1Result = 1;
  1837. bool pass = a1Result == 1;
  1838. //根据载具码获取产品码
  1839. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1840. if (string.IsNullOrEmpty(strProductBarcode))
  1841. {
  1842. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1843. }
  1844. sn = strProductBarcode;
  1845. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1846. List<TestItem> items = new List<TestItem>();
  1847. items.Add(new TestItem()
  1848. {
  1849. Parameter_name = "载具码",
  1850. Parameter_value = CarrierBarcode,
  1851. Parameter_unit = ""
  1852. });
  1853. items.Add(new TestItem()
  1854. {
  1855. Parameter_name = "产品码",
  1856. Parameter_value = sn,
  1857. Parameter_unit = ""
  1858. });
  1859. //出站接口
  1860. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1861. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1862. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1863. stopwatch2.Start();
  1864. //进站结果写入PLC
  1865. CommandFromPLC resultToPlC = new CommandFromPLC();
  1866. resultToPlC.cmd = 0;
  1867. resultToPlC.cmdParam = 0; //指令参数
  1868. resultToPlC.cmdResult = mesResultFrmWeb;
  1869. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1870. stopwatch2.Stop();
  1871. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1872. //保存PLC返回MES数据到本地
  1873. ResponseMessage message = new ResponseMessage();
  1874. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1875. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1876. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1877. stPLC_MesData.mesData.nRemainCount);
  1878. if (message.result == false)
  1879. {
  1880. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1881. }
  1882. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1883. }
  1884. catch (Exception ex)
  1885. {
  1886. stopwatch2.Start();
  1887. CommandFromPLC resultToPlC = new CommandFromPLC();
  1888. resultToPlC.cmd = 0;
  1889. resultToPlC.cmdParam = 0; //指令参数
  1890. resultToPlC.cmdResult = 110;
  1891. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1892. stopwatch2.Stop();
  1893. string str = ex.StackTrace;
  1894. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1895. }
  1896. stopwatch1.Stop();
  1897. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1898. ProgressState = false;
  1899. }
  1900. #endregion
  1901. #region S2
  1902. /// <summary>
  1903. /// [S2] 上盖板上料装备
  1904. /// </summary>
  1905. /// <param name="plcNo">PLC编号</param>
  1906. private void ReadStation_S2(int plcNo)
  1907. {
  1908. string stationCode = "[OP20]";
  1909. string stationName = "上盖板上料装备";
  1910. string stationNameStr = stationCode + stationName;
  1911. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1912. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1913. string tagAgvCommName = "agvCommFrmPC";
  1914. string tagBarsetName = "BarcodeSet";
  1915. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1916. (int, string) result;
  1917. while (true)
  1918. {
  1919. try
  1920. {
  1921. if (!GlobalContext._IsCon_Funs2)
  1922. {
  1923. UpdatePLCMonitor(1, plcNo, 0);
  1924. continue;
  1925. }
  1926. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1927. {
  1928. Stopwatch stopwatch1 = new Stopwatch();
  1929. Stopwatch stopwatch2 = new Stopwatch();
  1930. stopwatch1.Start();
  1931. stopwatch2.Start();
  1932. #region 一次性读取所有数据
  1933. // 一次性读取所有数据
  1934. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1935. if (result.Item1 != 0)
  1936. {
  1937. //richTextBox1.AppendText("\n" + strRet);
  1938. }
  1939. else
  1940. {
  1941. //richTextBox1.AppendText("\n" + "读取成功");
  1942. }
  1943. #endregion 一次性读取所有数据
  1944. stopwatch2.Stop();
  1945. #region 进站
  1946. try
  1947. {
  1948. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1949. {
  1950. lock (lockObj)
  1951. {
  1952. if (!ProgressState)
  1953. {
  1954. ProgressState = true;
  1955. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1956. }
  1957. }
  1958. }
  1959. }
  1960. catch (Exception ex)
  1961. {
  1962. ProgressState = false;
  1963. string str = ex.StackTrace;
  1964. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1965. }
  1966. #endregion 进站
  1967. #region 出站
  1968. try
  1969. {
  1970. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1971. {
  1972. lock (lockObj)
  1973. {
  1974. if (!ProgressState)
  1975. {
  1976. ProgressState = true;
  1977. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1978. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1979. }
  1980. }
  1981. }
  1982. }
  1983. catch (Exception ex)
  1984. {
  1985. ProgressState = false;
  1986. string str = ex.StackTrace;
  1987. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1988. }
  1989. #endregion 出站
  1990. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1991. stopwatch1.Stop();
  1992. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1993. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1994. }
  1995. else
  1996. {
  1997. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1998. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1999. FunsEip[plcNo].Connect();
  2000. }
  2001. }
  2002. catch (Exception ex)
  2003. {
  2004. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2005. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2006. //Funs[plcNo].ReConnect();
  2007. }
  2008. Thread.Sleep(IntervalReadPLC);
  2009. }
  2010. }
  2011. /// <summary>
  2012. /// [S2] 上盖板上料装备
  2013. /// </summary>
  2014. /// <param name="plcNo">PLC编号</param>
  2015. /// <param name="stationNameStr">工站全称</param>
  2016. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2017. {
  2018. Stopwatch stopwatch1 = new Stopwatch();
  2019. Stopwatch stopwatch2 = new Stopwatch();
  2020. try
  2021. {
  2022. stopwatch1.Start();
  2023. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2024. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  2025. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2026. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  2027. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  2028. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2029. //根据载具码获取产品码
  2030. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2031. if (string.IsNullOrEmpty(strProductBarcode))
  2032. {
  2033. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2034. }
  2035. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2036. //if (sn != strProductBarcode)
  2037. //{
  2038. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2039. //}
  2040. sn = strProductBarcode;
  2041. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2042. // 产品SN(物料码)校验
  2043. List<TestItem> item = new List<TestItem>();
  2044. stopwatch2.Start();
  2045. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2046. stopwatch2.Stop();
  2047. //指令执行结果 1:OK 110:失败
  2048. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2049. //进站结果写入PLC
  2050. CommandFromPLC resultToPlC = new CommandFromPLC();
  2051. resultToPlC.cmd = 0;
  2052. resultToPlC.cmdParam = 0; //指令参数
  2053. resultToPlC.cmdResult = mesResultFrmWeb;
  2054. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2055. }
  2056. catch (Exception ex)
  2057. {
  2058. string str = ex.StackTrace;
  2059. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2060. CommandFromPLC resultToPlC = new CommandFromPLC();
  2061. resultToPlC.cmd = 0;
  2062. resultToPlC.cmdParam = 0; //指令参数
  2063. resultToPlC.cmdResult = 110;
  2064. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2065. }
  2066. stopwatch1.Stop();
  2067. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2068. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2069. ProgressState = false;
  2070. }
  2071. /// <summary>
  2072. /// [S2] 上盖板上料装备 - 出站接口
  2073. /// </summary>
  2074. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2075. {
  2076. Stopwatch stopwatch1 = new Stopwatch();
  2077. Stopwatch stopwatch2 = new Stopwatch();
  2078. try
  2079. {
  2080. stopwatch1.Start();
  2081. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2082. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2083. string processItem = stationName; // 测试项目
  2084. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2085. string supplierCode = ""; // 供应商代码
  2086. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2087. string batch_num = GlobalContext.BatchNumber; // 批次号
  2088. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2089. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2090. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2091. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2092. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2093. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  2094. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2095. bool pass = a1Result == 1;
  2096. //根据载具码获取产品码
  2097. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2098. if (string.IsNullOrEmpty(strProductBarcode))
  2099. {
  2100. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2101. }
  2102. sn = strProductBarcode;
  2103. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2104. List<TestItem> items = new List<TestItem>();
  2105. items.Add(new TestItem()
  2106. {
  2107. Parameter_name = "载具码",
  2108. Parameter_value = CarrierBarcode,
  2109. Parameter_unit = ""
  2110. });
  2111. items.Add(new TestItem()
  2112. {
  2113. Parameter_name = "产品码",
  2114. Parameter_value = sn,
  2115. Parameter_unit = ""
  2116. });
  2117. items.Add(new TestItem()
  2118. {
  2119. Parameter_name = "部件码",
  2120. Parameter_value = PartBarcode,
  2121. Parameter_unit = ""
  2122. });
  2123. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2124. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2125. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2126. stopwatch2.Start();
  2127. //进站结果写入PLC
  2128. CommandFromPLC resultToPlC = new CommandFromPLC();
  2129. resultToPlC.cmd = 0;
  2130. resultToPlC.cmdParam = 0; //指令参数
  2131. resultToPlC.cmdResult = mesResultFrmWeb;
  2132. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2133. stopwatch2.Stop();
  2134. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2135. //保存PLC返回MES数据到本地
  2136. ResponseMessage message = new ResponseMessage();
  2137. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  2138. if (message.result == false)
  2139. {
  2140. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2141. }
  2142. if (!string.IsNullOrEmpty(PartBarcode))
  2143. {
  2144. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2145. if (message.result == false)
  2146. {
  2147. AddMessage(LogType.Error, message.text);
  2148. }
  2149. }
  2150. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2151. }
  2152. catch (Exception ex)
  2153. {
  2154. stopwatch2.Start();
  2155. CommandFromPLC resultToPlC = new CommandFromPLC();
  2156. resultToPlC.cmd = 0;
  2157. resultToPlC.cmdParam = 0; //指令参数
  2158. resultToPlC.cmdResult = 110;
  2159. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2160. stopwatch2.Stop();
  2161. string str = ex.StackTrace;
  2162. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2163. }
  2164. stopwatch1.Stop();
  2165. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2166. ProgressState = false;
  2167. }
  2168. #endregion
  2169. #region S3
  2170. /// <summary>
  2171. /// [S3] 点散热胶装备
  2172. /// </summary>
  2173. /// <param name="plcNo">PLC编号</param>
  2174. private void ReadStation_S3(int plcNo)
  2175. {
  2176. string stationCode = "[OP30]";
  2177. string stationName = "点散热胶装备";
  2178. string stationNameStr = stationCode + stationName;
  2179. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2180. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2181. string tagAgvCommName = "agvCommFrmPC";
  2182. string tagBarsetName = "BarcodeSet";
  2183. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2184. (int, string) result;
  2185. #region 创建字典
  2186. // 触发信号字典 赋值
  2187. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2188. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2189. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2190. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2191. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2192. // PLC数据字典 赋值
  2193. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2194. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2195. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2196. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2197. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2198. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2199. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2200. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2201. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2202. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2203. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2204. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2205. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2206. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2207. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2208. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2209. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2210. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2211. s3PLCData.Add("c1Result", 0); // 产品结果
  2212. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2213. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2214. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2215. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2216. #endregion 创建字典
  2217. while (true)
  2218. {
  2219. try
  2220. {
  2221. if (!GlobalContext._IsCon_Funs2)
  2222. {
  2223. UpdatePLCMonitor(1, plcNo, 0);
  2224. continue;
  2225. }
  2226. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2227. {
  2228. Stopwatch stopwatch1 = new Stopwatch();
  2229. Stopwatch stopwatch2 = new Stopwatch();
  2230. stopwatch1.Start();
  2231. stopwatch2.Start();
  2232. #region 一次性读取所有数据
  2233. // 一次性读取所有数据
  2234. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2235. if (result.Item1 != 0)
  2236. {
  2237. //richTextBox1.AppendText("\n" + strRet);
  2238. }
  2239. else
  2240. {
  2241. //richTextBox1.AppendText("\n" + "读取成功");
  2242. }
  2243. #endregion 一次性读取所有数据
  2244. stopwatch2.Stop();
  2245. #region 左边进站
  2246. try
  2247. {
  2248. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2249. {
  2250. lock (lockObj)
  2251. {
  2252. if (!ProgressState)
  2253. {
  2254. ProgressState = true;
  2255. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2256. }
  2257. }
  2258. }
  2259. }
  2260. catch (Exception ex)
  2261. {
  2262. ProgressState = false;
  2263. string str = ex.StackTrace;
  2264. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2265. }
  2266. #endregion 左边进站
  2267. #region 左边出站
  2268. try
  2269. {
  2270. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2271. {
  2272. lock (lockObj)
  2273. {
  2274. if (!ProgressState)
  2275. {
  2276. ProgressState = true;
  2277. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2278. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  2279. }
  2280. }
  2281. }
  2282. }
  2283. catch (Exception ex)
  2284. {
  2285. ProgressState = false;
  2286. string str = ex.StackTrace;
  2287. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2288. }
  2289. #endregion 左边出站
  2290. #region 右边进站
  2291. try
  2292. {
  2293. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2294. {
  2295. lock (lockObj)
  2296. {
  2297. if (!ProgressState)
  2298. {
  2299. ProgressState = true;
  2300. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2301. }
  2302. }
  2303. }
  2304. }
  2305. catch (Exception ex)
  2306. {
  2307. ProgressState = false;
  2308. string str = ex.StackTrace;
  2309. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2310. }
  2311. #endregion 右边进站
  2312. #region 右边出站
  2313. try
  2314. {
  2315. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2316. {
  2317. lock (lockObj)
  2318. {
  2319. if (!ProgressState)
  2320. {
  2321. ProgressState = true;
  2322. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2323. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  2324. }
  2325. }
  2326. }
  2327. }
  2328. catch (Exception ex)
  2329. {
  2330. string str = ex.StackTrace;
  2331. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2332. }
  2333. #endregion 右边出站
  2334. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2335. stopwatch1.Stop();
  2336. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2337. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2338. }
  2339. else
  2340. {
  2341. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2342. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2343. FunsEip[plcNo].Connect();
  2344. }
  2345. }
  2346. catch (Exception ex)
  2347. {
  2348. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2349. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2350. //Funs[plcNo].ReConnect();
  2351. }
  2352. Thread.Sleep(IntervalReadPLC);
  2353. }
  2354. }
  2355. /// <summary>
  2356. /// [S3] 点散热胶装备 - 进站
  2357. /// </summary>
  2358. /// <param name="plcNo">PLC编号</param>
  2359. /// <param name="stationNameStr">工站全称</param>
  2360. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2361. {
  2362. Stopwatch stopwatch1 = new Stopwatch();
  2363. Stopwatch stopwatch2 = new Stopwatch();
  2364. try
  2365. {
  2366. stopwatch1.Start();
  2367. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2368. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2369. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2370. string StationId=string.Empty;
  2371. if (direction=="Left")
  2372. {
  2373. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2374. }
  2375. if (direction == "Right")
  2376. {
  2377. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2378. }
  2379. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2380. //载具码验证产品码
  2381. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2382. if (string.IsNullOrEmpty(strProductBarcode))
  2383. {
  2384. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2385. }
  2386. sn = strProductBarcode;
  2387. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2388. // 产品SN(物料码)校验
  2389. List<TestItem> item = new List<TestItem>();
  2390. stopwatch2.Start();
  2391. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2392. stopwatch2.Stop();
  2393. //指令执行结果 1:OK 110:失败
  2394. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2395. //进站结果写入PLC
  2396. CommandFromPLC resultToPlC = new CommandFromPLC();
  2397. resultToPlC.cmd = 0;
  2398. resultToPlC.cmdParam = 0; //指令参数
  2399. resultToPlC.cmdResult = mesResultFrmWeb;
  2400. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2401. }
  2402. catch (Exception ex)
  2403. {
  2404. string str = ex.StackTrace;
  2405. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2406. CommandFromPLC resultToPlC = new CommandFromPLC();
  2407. resultToPlC.cmd = 0;
  2408. resultToPlC.cmdParam = 0; //指令参数
  2409. resultToPlC.cmdResult = 110;
  2410. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2411. }
  2412. stopwatch1.Stop();
  2413. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2414. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2415. ProgressState = false;
  2416. }
  2417. /// <summary>
  2418. /// [S3] 点散热胶装备 - 出站
  2419. /// </summary>
  2420. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2421. {
  2422. Stopwatch stopwatch1 = new Stopwatch();
  2423. Stopwatch stopwatch2 = new Stopwatch();
  2424. try
  2425. {
  2426. stopwatch1.Start();
  2427. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2428. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2429. string processItem = stationName; // 测试项目
  2430. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2431. string supplierCode = ""; // 供应商代码
  2432. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2433. string batch_num = GlobalContext.BatchNumber; // 批次号
  2434. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2435. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2436. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2437. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2438. string StationId = string.Empty;
  2439. if (direction == "Left")
  2440. {
  2441. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2442. }
  2443. if (direction == "Right")
  2444. {
  2445. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2446. }
  2447. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2448. bool pass = a1Result == 1;
  2449. //根据载具码获取产品码
  2450. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2451. if (string.IsNullOrEmpty(strProductBarcode))
  2452. {
  2453. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2454. }
  2455. sn = strProductBarcode;
  2456. sn = "AB123456789";
  2457. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2458. List<TestItem> items = new List<TestItem>();
  2459. items.Add(new TestItem()
  2460. {
  2461. Parameter_name = "载具码",
  2462. Parameter_value = CarrierBarcode,
  2463. Parameter_unit = ""
  2464. });
  2465. items.Add(new TestItem()
  2466. {
  2467. Parameter_name = "产品码",
  2468. Parameter_value = sn,
  2469. Parameter_unit = ""
  2470. });
  2471. int result1 = 1;
  2472. //if (direction == "Right")
  2473. //{
  2474. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2475. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", direction);
  2476. //}
  2477. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2478. stopwatch2.Start();
  2479. //进站结果写入PLC
  2480. CommandFromPLC resultToPlC = new CommandFromPLC();
  2481. resultToPlC.cmd = 0;
  2482. resultToPlC.cmdParam = 0; //指令参数
  2483. resultToPlC.cmdResult = mesResultFrmWeb;
  2484. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2485. stopwatch2.Stop();
  2486. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2487. //保存PLC返回MES数据到本地
  2488. ResponseMessage message = new ResponseMessage();
  2489. if (direction == "Left")
  2490. {
  2491. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2492. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2493. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2494. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2495. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2496. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2497. if (message.result == false)
  2498. {
  2499. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2500. }
  2501. }
  2502. if (direction == "Right")
  2503. {
  2504. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2505. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2506. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2507. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2508. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2509. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2510. if (message.result == false)
  2511. {
  2512. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2513. }
  2514. }
  2515. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2516. }
  2517. catch (Exception ex)
  2518. {
  2519. stopwatch2.Start();
  2520. CommandFromPLC resultToPlC = new CommandFromPLC();
  2521. resultToPlC.cmd = 0;
  2522. resultToPlC.cmdParam = 0; //指令参数
  2523. resultToPlC.cmdResult = 110;
  2524. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2525. stopwatch2.Stop();
  2526. string str = ex.StackTrace;
  2527. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2528. }
  2529. stopwatch1.Stop();
  2530. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2531. ProgressState = false;
  2532. }
  2533. #endregion S3
  2534. #region S4
  2535. /// <summary>
  2536. /// [S4] 点胶检测设备
  2537. /// </summary>
  2538. /// <param name="plcNo">PLC编号</param>
  2539. private void ReadStation_S4(int plcNo)
  2540. {
  2541. string stationCode = "[OP40]";
  2542. string stationName = "胶线检测";
  2543. string stationNameStr = stationCode + stationName;
  2544. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2545. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2546. string tagAgvCommName = "agvCommFrmPC";
  2547. string tagBarsetName = "BarcodeSet";
  2548. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2549. (int, string) result;
  2550. while (true)
  2551. {
  2552. try
  2553. {
  2554. if (!GlobalContext._IsCon_Funs1)
  2555. {
  2556. UpdatePLCMonitor(1, plcNo, 0);
  2557. continue;
  2558. }
  2559. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2560. {
  2561. Stopwatch stopwatch1 = new Stopwatch();
  2562. Stopwatch stopwatch2 = new Stopwatch();
  2563. stopwatch1.Start();
  2564. stopwatch2.Start();
  2565. #region 一次性读取所有数据
  2566. // 一次性读取所有数据
  2567. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2568. if (result.Item1 != 0)
  2569. {
  2570. //richTextBox1.AppendText("\n" + strRet);
  2571. }
  2572. else
  2573. {
  2574. //richTextBox1.AppendText("\n" + "读取成功");
  2575. }
  2576. #endregion 一次性读取所有数据
  2577. stopwatch2.Stop();
  2578. #region 进站
  2579. try
  2580. {
  2581. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2582. {
  2583. lock (lockObj)
  2584. {
  2585. if (!ProgressState)
  2586. {
  2587. ProgressState = true;
  2588. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2589. }
  2590. }
  2591. }
  2592. }
  2593. catch (Exception ex)
  2594. {
  2595. ProgressState = false;
  2596. string str = ex.StackTrace;
  2597. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2598. }
  2599. #endregion 进站
  2600. #region 出站
  2601. try
  2602. {
  2603. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2604. {
  2605. lock (lockObj)
  2606. {
  2607. if (!ProgressState)
  2608. {
  2609. ProgressState = true;
  2610. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2611. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2612. }
  2613. }
  2614. }
  2615. }
  2616. catch (Exception ex)
  2617. {
  2618. string str = ex.StackTrace;
  2619. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2620. }
  2621. #endregion 出站
  2622. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2623. stopwatch1.Stop();
  2624. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2625. }
  2626. else
  2627. {
  2628. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2629. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2630. FunsEip[plcNo].Connect(); // 重连
  2631. }
  2632. }
  2633. catch (Exception ex)
  2634. {
  2635. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2636. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2637. }
  2638. Thread.Sleep(IntervalReadPLC);
  2639. }
  2640. }
  2641. /// <summary>
  2642. /// [S4] 点胶检测设备 - 进站
  2643. /// </summary>
  2644. /// <param name="plcNo">PLC编号</param>
  2645. /// <param name="stationNameStr">工站全称</param>
  2646. /// <param name="stPLC_MesData"></param>
  2647. /// <param name="tagMesCommName"></param>
  2648. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2649. {
  2650. Stopwatch stopwatch1 = new Stopwatch();
  2651. Stopwatch stopwatch2 = new Stopwatch();
  2652. try
  2653. {
  2654. stopwatch1.Start();
  2655. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2656. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2657. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2658. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2659. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2660. //载具码验证产品码
  2661. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2662. if (string.IsNullOrEmpty(strProductBarcode))
  2663. {
  2664. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2665. }
  2666. sn = strProductBarcode;
  2667. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2668. // 产品SN(物料码)校验
  2669. List<TestItem> item = new List<TestItem>();
  2670. stopwatch2.Start();
  2671. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2672. stopwatch2.Stop();
  2673. //指令执行结果 1:OK 110:失败
  2674. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2675. //进站结果写入PLC
  2676. CommandFromPLC resultToPlC = new CommandFromPLC();
  2677. resultToPlC.cmd = 0;
  2678. resultToPlC.cmdParam = 0; //指令参数
  2679. resultToPlC.cmdResult = mesResultFrmWeb;
  2680. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2681. }
  2682. catch (Exception ex)
  2683. {
  2684. string str = ex.StackTrace;
  2685. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2686. CommandFromPLC resultToPlC = new CommandFromPLC();
  2687. resultToPlC.cmd = 0;
  2688. resultToPlC.cmdParam = 0; //指令参数
  2689. resultToPlC.cmdResult = 110;
  2690. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2691. }
  2692. stopwatch1.Stop();
  2693. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2694. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2695. ProgressState = false;
  2696. }
  2697. /// <summary>
  2698. /// [S4] 点胶检测设备 - 出站接口
  2699. /// </summary>
  2700. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2701. {
  2702. Stopwatch stopwatch1 = new Stopwatch();
  2703. Stopwatch stopwatch2 = new Stopwatch();
  2704. try
  2705. {
  2706. stopwatch1.Start();
  2707. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2708. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2709. string processItem = stationName; // 测试项目
  2710. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2711. string supplierCode = ""; // 供应商代码
  2712. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2713. string batch_num = GlobalContext.BatchNumber; // 批次号
  2714. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2715. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2716. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2717. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2718. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2719. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2720. bool pass = a1Result == 1;
  2721. //根据载具码获取产品码
  2722. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2723. if (string.IsNullOrEmpty(strProductBarcode))
  2724. {
  2725. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2726. }
  2727. sn = strProductBarcode;
  2728. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2729. List<TestItem> items = new List<TestItem>();
  2730. items.Add(new TestItem()
  2731. {
  2732. Parameter_name = "载具码",
  2733. Parameter_value = CarrierBarcode,
  2734. Parameter_unit = ""
  2735. });
  2736. items.Add(new TestItem()
  2737. {
  2738. Parameter_name = "产品码",
  2739. Parameter_value = sn,
  2740. Parameter_unit = ""
  2741. });
  2742. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2743. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2744. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2745. stopwatch2.Start();
  2746. //进站结果写入PLC
  2747. CommandFromPLC resultToPlC = new CommandFromPLC();
  2748. resultToPlC.cmd = 0;
  2749. resultToPlC.cmdParam = 0; //指令参数
  2750. resultToPlC.cmdResult = mesResultFrmWeb;
  2751. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2752. stopwatch2.Stop();
  2753. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2754. //保存PLC返回MES数据到本地
  2755. ResponseMessage message = new ResponseMessage();
  2756. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2757. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2758. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2759. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2760. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2761. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2762. if (message.result == false)
  2763. {
  2764. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2765. }
  2766. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2767. }
  2768. catch (Exception ex)
  2769. {
  2770. stopwatch2.Start();
  2771. CommandFromPLC resultToPlC = new CommandFromPLC();
  2772. resultToPlC.cmd = 0;
  2773. resultToPlC.cmdParam = 0; //指令参数
  2774. resultToPlC.cmdResult = 110;
  2775. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2776. stopwatch2.Stop();
  2777. string str = ex.StackTrace;
  2778. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2779. }
  2780. stopwatch1.Stop();
  2781. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2782. ProgressState = false;
  2783. }
  2784. #endregion
  2785. #region S5
  2786. /// <summary>
  2787. /// [S5] 点胶检测设备
  2788. /// </summary>
  2789. /// <param name="plcNo">PLC编号</param>
  2790. private void ReadStation_S5(int plcNo)
  2791. {
  2792. string stationCode = "[OP50]";
  2793. string stationName = "ADD板上料组装装备";
  2794. string stationNameStr = stationCode + stationName;
  2795. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2796. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2797. string tagAgvCommName = "agvCommFrmPC";
  2798. string tagBarsetName = "BarcodeSet";
  2799. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2800. (int, string) result;
  2801. while (true)
  2802. {
  2803. try
  2804. {
  2805. if (!GlobalContext._IsCon_Funs1)
  2806. {
  2807. UpdatePLCMonitor(1, plcNo, 0);
  2808. continue;
  2809. }
  2810. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2811. {
  2812. Stopwatch stopwatch1 = new Stopwatch();
  2813. Stopwatch stopwatch2 = new Stopwatch();
  2814. stopwatch1.Start();
  2815. stopwatch2.Start();
  2816. #region 一次性读取所有数据
  2817. // 一次性读取所有数据
  2818. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2819. if (result.Item1 != 0)
  2820. {
  2821. //richTextBox1.AppendText("\n" + strRet);
  2822. }
  2823. else
  2824. {
  2825. //richTextBox1.AppendText("\n" + "读取成功");
  2826. }
  2827. #endregion 一次性读取所有数据
  2828. stopwatch2.Stop();
  2829. #region 进站
  2830. try
  2831. {
  2832. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2833. {
  2834. lock (lockObj)
  2835. {
  2836. if (!ProgressState)
  2837. {
  2838. ProgressState = true;
  2839. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2840. }
  2841. }
  2842. }
  2843. }
  2844. catch (Exception ex)
  2845. {
  2846. ProgressState = false;
  2847. string str = ex.StackTrace;
  2848. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2849. }
  2850. #endregion 进站
  2851. #region 出站
  2852. try
  2853. {
  2854. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2855. {
  2856. lock (lockObj)
  2857. {
  2858. if (!ProgressState)
  2859. {
  2860. ProgressState = true;
  2861. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2862. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2863. }
  2864. }
  2865. }
  2866. }
  2867. catch (Exception ex)
  2868. {
  2869. ProgressState = false;
  2870. string str = ex.StackTrace;
  2871. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2872. }
  2873. #endregion 出站
  2874. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2875. stopwatch1.Stop();
  2876. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2877. }
  2878. else
  2879. {
  2880. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2881. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2882. FunsEip[plcNo].Connect(); // 重连
  2883. }
  2884. }
  2885. catch (Exception ex)
  2886. {
  2887. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2888. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2889. }
  2890. Thread.Sleep(IntervalReadPLC);
  2891. }
  2892. }
  2893. /// <summary>
  2894. /// [S5] 点胶检测设备 - 进站
  2895. /// </summary>
  2896. /// <param name="plcNo">PLC编号</param>
  2897. /// <param name="stationNameStr">工站全称</param>
  2898. /// <param name="stPLC_MesData"></param>
  2899. /// <param name="tagMesCommName"></param>
  2900. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2901. {
  2902. Stopwatch stopwatch1 = new Stopwatch();
  2903. Stopwatch stopwatch2 = new Stopwatch();
  2904. try
  2905. {
  2906. stopwatch1.Start();
  2907. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2908. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2909. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2910. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2911. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2912. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2913. //载具码验证产品码 //载具码验证产品码
  2914. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2915. if (string.IsNullOrEmpty(strProductBarcode))
  2916. {
  2917. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2918. }
  2919. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2920. //if (sn != strProductBarcode)
  2921. //{
  2922. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2923. //}
  2924. sn = strProductBarcode;
  2925. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2926. // 产品SN(物料码)校验
  2927. List<TestItem> item = new List<TestItem>();
  2928. stopwatch2.Start();
  2929. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2930. stopwatch2.Stop();
  2931. //指令执行结果 1:OK 110:失败
  2932. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2933. //进站结果写入PLC
  2934. CommandFromPLC resultToPlC = new CommandFromPLC();
  2935. resultToPlC.cmd = 0;
  2936. resultToPlC.cmdParam = 0; //指令参数
  2937. resultToPlC.cmdResult = mesResultFrmWeb;
  2938. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2939. }
  2940. catch (Exception ex)
  2941. {
  2942. string str = ex.StackTrace;
  2943. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2944. CommandFromPLC resultToPlC = new CommandFromPLC();
  2945. resultToPlC.cmd = 0;
  2946. resultToPlC.cmdParam = 0; //指令参数
  2947. resultToPlC.cmdResult = 110;
  2948. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2949. }
  2950. stopwatch1.Stop();
  2951. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2952. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2953. ProgressState = false;
  2954. }
  2955. /// <summary>
  2956. /// [S5] 点胶检测设备 - 出站接口
  2957. /// </summary>
  2958. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2959. {
  2960. Stopwatch stopwatch1 = new Stopwatch();
  2961. Stopwatch stopwatch2 = new Stopwatch();
  2962. try
  2963. {
  2964. stopwatch1.Start();
  2965. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2966. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2967. string processItem = stationName; // 测试项目
  2968. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2969. string supplierCode = ""; // 供应商代码
  2970. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2971. string batch_num = GlobalContext.BatchNumber; // 批次号
  2972. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2973. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2974. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2975. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2976. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2977. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2978. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2979. bool pass = a1Result == 1;
  2980. //根据载具码获取产品码
  2981. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2982. if (string.IsNullOrEmpty(strProductBarcode))
  2983. {
  2984. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2985. }
  2986. sn = strProductBarcode;
  2987. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2988. List<TestItem> items = new List<TestItem>();
  2989. items.Add(new TestItem()
  2990. {
  2991. Parameter_name = "载具码",
  2992. Parameter_value = CarrierBarcode,
  2993. Parameter_unit = ""
  2994. });
  2995. items.Add(new TestItem()
  2996. {
  2997. Parameter_name = "产品码",
  2998. Parameter_value = sn,
  2999. Parameter_unit = ""
  3000. });
  3001. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3002. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  3003. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3004. stopwatch2.Start();
  3005. //进站结果写入PLC
  3006. CommandFromPLC resultToPlC = new CommandFromPLC();
  3007. resultToPlC.cmd = 0;
  3008. resultToPlC.cmdParam = 0; //指令参数
  3009. resultToPlC.cmdResult = mesResultFrmWeb;
  3010. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3011. stopwatch2.Stop();
  3012. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3013. //保存PLC返回MES数据到本地
  3014. ResponseMessage message = new ResponseMessage();
  3015. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  3016. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  3017. if (message.result == false)
  3018. {
  3019. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3020. }
  3021. //保存部件码信息
  3022. if (!string.IsNullOrEmpty(PartBarcode))
  3023. {
  3024. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  3025. if (message.result == false)
  3026. {
  3027. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  3028. }
  3029. }
  3030. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3031. }
  3032. catch (Exception ex)
  3033. {
  3034. stopwatch2.Start();
  3035. CommandFromPLC resultToPlC = new CommandFromPLC();
  3036. resultToPlC.cmd = 0;
  3037. resultToPlC.cmdParam = 0; //指令参数
  3038. resultToPlC.cmdResult = 110;
  3039. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3040. stopwatch2.Stop();
  3041. string str = ex.StackTrace;
  3042. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3043. }
  3044. stopwatch1.Stop();
  3045. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3046. ProgressState = false;
  3047. }
  3048. #endregion
  3049. #region S6
  3050. /// <summary>
  3051. /// [S6] 顶盖装配设备
  3052. /// </summary>
  3053. /// <param name="plcNo">PLC编号</param>
  3054. private void ReadStation_S6(int plcNo)
  3055. {
  3056. string stationCode = "[OP60]";
  3057. string stationName = "组上盖板";
  3058. string stationNameStr = stationCode + stationName;
  3059. string tagBaseName = "g_OP60_MES"; //标签变量名称
  3060. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3061. string tagAgvCommName = "agvCommFrmPC";
  3062. string tagBarsetName = "BarcodeSet";
  3063. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  3064. (int, string) result;
  3065. while (true)
  3066. {
  3067. try
  3068. {
  3069. if (!GlobalContext._IsCon_Funs1)
  3070. {
  3071. UpdatePLCMonitor(1, plcNo, 0);
  3072. continue;
  3073. }
  3074. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3075. {
  3076. Stopwatch stopwatch1 = new Stopwatch();
  3077. Stopwatch stopwatch2 = new Stopwatch();
  3078. stopwatch1.Start();
  3079. stopwatch2.Start();
  3080. #region 一次性读取所有数据
  3081. // 一次性读取所有数据
  3082. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3083. if (result.Item1 != 0)
  3084. {
  3085. //richTextBox1.AppendText("\n" + strRet);
  3086. }
  3087. else
  3088. {
  3089. //richTextBox1.AppendText("\n" + "读取成功");
  3090. }
  3091. #endregion 一次性读取所有数据
  3092. stopwatch2.Stop();
  3093. #region 进站
  3094. try
  3095. {
  3096. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3097. {
  3098. lock (lockObj)
  3099. {
  3100. if (!ProgressState)
  3101. {
  3102. ProgressState = true;
  3103. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3104. }
  3105. }
  3106. }
  3107. }
  3108. catch (Exception ex)
  3109. {
  3110. ProgressState = false;
  3111. string str = ex.StackTrace;
  3112. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3113. }
  3114. #endregion 进站
  3115. #region 出站
  3116. try
  3117. {
  3118. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3119. {
  3120. lock (lockObj)
  3121. {
  3122. if (!ProgressState)
  3123. {
  3124. ProgressState = true; ;
  3125. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3126. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3127. }
  3128. }
  3129. }
  3130. }
  3131. catch (Exception ex)
  3132. {
  3133. ProgressState = false;
  3134. string str = ex.StackTrace;
  3135. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3136. }
  3137. #endregion 出站
  3138. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3139. stopwatch1.Stop();
  3140. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3141. }
  3142. else
  3143. {
  3144. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3145. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3146. FunsEip[plcNo].Connect(); // 重连
  3147. }
  3148. }
  3149. catch (Exception ex)
  3150. {
  3151. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3152. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3153. }
  3154. Thread.Sleep(IntervalReadPLC);
  3155. }
  3156. }
  3157. /// <summary>
  3158. /// [S6] 顶盖装配设备 - 进站
  3159. /// </summary>
  3160. /// <param name="plcNo">PLC编号</param>
  3161. /// <param name="stationNameStr">工站全称</param>
  3162. /// <param name="stPLC_MesData"></param>
  3163. /// <param name="tagMesCommName"></param>
  3164. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3165. {
  3166. Stopwatch stopwatch1 = new Stopwatch();
  3167. Stopwatch stopwatch2 = new Stopwatch();
  3168. try
  3169. {
  3170. stopwatch1.Start();
  3171. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3172. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3173. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3174. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3175. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3176. //载具码验证产品码
  3177. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3178. if (string.IsNullOrEmpty(strProductBarcode))
  3179. {
  3180. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3181. }
  3182. sn = strProductBarcode;
  3183. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3184. // 产品SN(物料码)校验
  3185. List<TestItem> item = new List<TestItem>();
  3186. stopwatch2.Start();
  3187. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3188. stopwatch2.Stop();
  3189. //指令执行结果 1:OK 110:失败
  3190. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3191. //进站结果写入PLC
  3192. CommandFromPLC resultToPlC = new CommandFromPLC();
  3193. resultToPlC.cmd = 0;
  3194. resultToPlC.cmdParam = 0; //指令参数
  3195. resultToPlC.cmdResult = mesResultFrmWeb;
  3196. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3197. }
  3198. catch (Exception ex)
  3199. {
  3200. string str = ex.StackTrace;
  3201. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3202. CommandFromPLC resultToPlC = new CommandFromPLC();
  3203. resultToPlC.cmd = 0;
  3204. resultToPlC.cmdParam = 0; //指令参数
  3205. resultToPlC.cmdResult = 110;
  3206. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3207. }
  3208. stopwatch1.Stop();
  3209. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3210. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3211. ProgressState = false;
  3212. }
  3213. /// <summary>
  3214. /// [S6] 顶盖装配设备 - 出站接口
  3215. /// </summary>
  3216. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3217. {
  3218. Stopwatch stopwatch1 = new Stopwatch();
  3219. Stopwatch stopwatch2 = new Stopwatch();
  3220. try
  3221. {
  3222. stopwatch1.Start();
  3223. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3224. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3225. string processItem = stationName; // 测试项目
  3226. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3227. string supplierCode = ""; // 供应商代码
  3228. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3229. string batch_num = GlobalContext.BatchNumber; // 批次号
  3230. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3231. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3232. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3233. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3234. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3235. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3236. bool pass = a1Result == 1;
  3237. //根据载具码获取产品码
  3238. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3239. if (string.IsNullOrEmpty(strProductBarcode))
  3240. {
  3241. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3242. }
  3243. sn = strProductBarcode;
  3244. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3245. List<TestItem> items = new List<TestItem>();
  3246. items.Add(new TestItem()
  3247. {
  3248. Parameter_name = "载具码",
  3249. Parameter_value = CarrierBarcode,
  3250. Parameter_unit = ""
  3251. });
  3252. items.Add(new TestItem()
  3253. {
  3254. Parameter_name = "产品码",
  3255. Parameter_value = sn,
  3256. Parameter_unit = ""
  3257. });
  3258. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3259. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3260. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3261. stopwatch2.Start();
  3262. //进站结果写入PLC
  3263. CommandFromPLC resultToPlC = new CommandFromPLC();
  3264. resultToPlC.cmd = 0;
  3265. resultToPlC.cmdParam = 0; //指令参数
  3266. resultToPlC.cmdResult = mesResultFrmWeb;
  3267. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3268. stopwatch2.Stop();
  3269. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3270. //保存PLC返回MES数据到本地
  3271. ResponseMessage message = new ResponseMessage();
  3272. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3273. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3274. if (message.result == false)
  3275. {
  3276. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3277. }
  3278. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3279. }
  3280. catch (Exception ex)
  3281. {
  3282. stopwatch2.Start();
  3283. CommandFromPLC resultToPlC = new CommandFromPLC();
  3284. resultToPlC.cmd = 0;
  3285. resultToPlC.cmdParam = 0; //指令参数
  3286. resultToPlC.cmdResult = 110;
  3287. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3288. stopwatch2.Stop();
  3289. string str = ex.StackTrace;
  3290. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3291. }
  3292. stopwatch1.Stop();
  3293. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3294. ProgressState = false;
  3295. }
  3296. #endregion
  3297. #region S7
  3298. /// <summary>
  3299. /// [S7] 锁螺丝设备
  3300. /// </summary>
  3301. /// <param name="plcNo">PLC编号</param>
  3302. private void ReadStation_S7(int plcNo)
  3303. {
  3304. string stationCode = "[OP70]";
  3305. string stationName = "上盖板锁螺丝";
  3306. string stationNameStr = stationCode + stationName;
  3307. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3308. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3309. string tagAgvCommName = "agvCommFrmPC";
  3310. string tagBarsetName = "BarcodeSet";
  3311. string tagScrewDataset = "screwDataset";
  3312. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3313. (int, string) result;
  3314. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3315. atlasScrewLeft.Initial();
  3316. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3317. atlasScrewRight.Initial();
  3318. while (true)
  3319. {
  3320. try
  3321. {
  3322. if (!GlobalContext._IsCon_Funs1)
  3323. {
  3324. UpdatePLCMonitor(1, plcNo, 0);
  3325. continue;
  3326. }
  3327. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3328. {
  3329. Stopwatch stopwatch1 = new Stopwatch();
  3330. Stopwatch stopwatch2 = new Stopwatch();
  3331. stopwatch1.Start();
  3332. stopwatch2.Start();
  3333. #region 一次性读取所有数据
  3334. // 一次性读取所有数据
  3335. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3336. if (result.Item1 != 0)
  3337. {
  3338. //richTextBox1.AppendText("\n" + strRet);
  3339. }
  3340. else
  3341. {
  3342. //richTextBox1.AppendText("\n" + "读取成功");
  3343. }
  3344. #endregion 一次性读取所有数据
  3345. stopwatch2.Stop();
  3346. #region 左边进站
  3347. try
  3348. {
  3349. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3350. {
  3351. lock (lockObj)
  3352. {
  3353. if (!ProgressState)
  3354. {
  3355. ProgressState = true;
  3356. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3357. }
  3358. }
  3359. }
  3360. }
  3361. catch (Exception ex)
  3362. {
  3363. ProgressState = false;
  3364. string str = ex.StackTrace;
  3365. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3366. }
  3367. #endregion 左边进站
  3368. #region 左边出站
  3369. try
  3370. {
  3371. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3372. {
  3373. lock (lockObj)
  3374. {
  3375. if (!ProgressState)
  3376. {
  3377. ProgressState = true;
  3378. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3379. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3380. }
  3381. }
  3382. }
  3383. }
  3384. catch (Exception ex)
  3385. {
  3386. ProgressState = false;
  3387. string str = ex.StackTrace;
  3388. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3389. }
  3390. #endregion 左边出站
  3391. #region 右边进站
  3392. try
  3393. {
  3394. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3395. {
  3396. lock (lockObj)
  3397. {
  3398. if (!ProgressState)
  3399. {
  3400. ProgressState = true;
  3401. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3402. }
  3403. }
  3404. }
  3405. }
  3406. catch (Exception ex)
  3407. {
  3408. ProgressState = false;
  3409. string str = ex.StackTrace;
  3410. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3411. }
  3412. #endregion 右边进站
  3413. #region 右边出站
  3414. try
  3415. {
  3416. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3417. {
  3418. lock (lockObj)
  3419. {
  3420. if (!ProgressState)
  3421. {
  3422. ProgressState = true;
  3423. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3424. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3425. }
  3426. }
  3427. }
  3428. }
  3429. catch (Exception ex)
  3430. {
  3431. ProgressState = false;
  3432. string str = ex.StackTrace;
  3433. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3434. }
  3435. #endregion 右边出站
  3436. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3437. stopwatch1.Stop();
  3438. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3439. }
  3440. else
  3441. {
  3442. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3443. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3444. FunsEip[plcNo].Connect(); // 重连
  3445. }
  3446. }
  3447. catch (Exception ex)
  3448. {
  3449. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3450. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3451. }
  3452. Thread.Sleep(IntervalReadPLC);
  3453. }
  3454. }
  3455. /// <summary>
  3456. /// [S7] 锁螺丝设备 - 进站
  3457. /// </summary>
  3458. /// <param name="plcNo">PLC编号</param>
  3459. /// <param name="stationNameStr">工站全称</param>
  3460. /// <param name="stPLC_MesData"></param>
  3461. /// <param name="tagMesCommName"></param>
  3462. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3463. {
  3464. Stopwatch stopwatch1 = new Stopwatch();
  3465. Stopwatch stopwatch2 = new Stopwatch();
  3466. string atlasSn=string.Empty;
  3467. try
  3468. {
  3469. stopwatch1.Start();
  3470. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3471. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3472. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3473. string StationId = string.Empty; // 工位ID(可配置)
  3474. if (direction == "Left")
  3475. {
  3476. StationId = GlobalContext.S7_StationId_1;
  3477. }
  3478. if (direction == "Right")
  3479. {
  3480. StationId = GlobalContext.S7_StationId_2;
  3481. }
  3482. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3483. //载具码验证产品码
  3484. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3485. if (string.IsNullOrEmpty(strProductBarcode))
  3486. {
  3487. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3488. }
  3489. sn = strProductBarcode;
  3490. atlasSn= strProductBarcode;
  3491. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3492. if (direction == "Left")
  3493. {
  3494. isCollectingFlagLeft = false;//采集螺丝数据结束
  3495. }
  3496. if (direction == "Right")
  3497. {
  3498. isCollectingFlagRight = false;//采集螺丝数据结束
  3499. }
  3500. // 产品SN(物料码)校验
  3501. List<TestItem> item = new List<TestItem>();
  3502. stopwatch2.Start();
  3503. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3504. stopwatch2.Stop();
  3505. //指令执行结果 1:OK 110:失败
  3506. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3507. //进站结果写入PLC
  3508. CommandFromPLC resultToPlC = new CommandFromPLC();
  3509. resultToPlC.cmd = 0;
  3510. resultToPlC.cmdParam = 0; //指令参数
  3511. resultToPlC.cmdResult = mesResultFrmWeb;
  3512. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3513. }
  3514. catch (Exception ex)
  3515. {
  3516. string str = ex.StackTrace;
  3517. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3518. CommandFromPLC resultToPlC = new CommandFromPLC();
  3519. resultToPlC.cmd = 0;
  3520. resultToPlC.cmdParam = 0; //指令参数
  3521. resultToPlC.cmdResult = 110;
  3522. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3523. }
  3524. stopwatch1.Stop();
  3525. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3526. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3527. ProgressState = false;
  3528. //开始采集螺丝数据
  3529. if (direction == "Left")
  3530. {
  3531. isCollectingFlagLeft = true;
  3532. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3533. }
  3534. if (direction == "Right")
  3535. {
  3536. isCollectingFlagRight = true;
  3537. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3538. }
  3539. }
  3540. /// <summary>
  3541. /// [S7] 锁螺丝设备 - 出站
  3542. /// </summary>
  3543. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3544. {
  3545. Stopwatch stopwatch1 = new Stopwatch();
  3546. Stopwatch stopwatch2 = new Stopwatch();
  3547. try
  3548. {
  3549. stopwatch1.Start();
  3550. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3551. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3552. string processItem = stationName; // 测试项目
  3553. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3554. string supplierCode = ""; // 供应商代码
  3555. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3556. string batch_num = GlobalContext.BatchNumber; // 批次号
  3557. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3558. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3559. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3560. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3561. string StationId = string.Empty; // 工位ID(可配置)
  3562. if (direction == "Left")
  3563. {
  3564. StationId = GlobalContext.S7_StationId_1;
  3565. }
  3566. if (direction == "Right")
  3567. {
  3568. StationId = GlobalContext.S7_StationId_2;
  3569. }
  3570. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3571. a1Result = 1;
  3572. bool pass = a1Result == 1;
  3573. //根据载具码获取产品码
  3574. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3575. if (string.IsNullOrEmpty(strProductBarcode))
  3576. {
  3577. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3578. }
  3579. sn = strProductBarcode;
  3580. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3581. List<TestItem> items = new List<TestItem>();
  3582. items.Add(new TestItem()
  3583. {
  3584. Parameter_name = "载具码",
  3585. Parameter_value = CarrierBarcode,
  3586. Parameter_unit = ""
  3587. });
  3588. items.Add(new TestItem()
  3589. {
  3590. Parameter_name = "产品码",
  3591. Parameter_value = sn,
  3592. Parameter_unit = ""
  3593. });
  3594. int result1 = 1;
  3595. if (direction == "Right")
  3596. {
  3597. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3598. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3599. }
  3600. //if (direction == "Left")
  3601. //{
  3602. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3603. //}
  3604. //if (direction == "Right")
  3605. //{
  3606. // isCollectingFlagRight = false;//采集螺丝数据结束
  3607. //}
  3608. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3609. stopwatch2.Start();
  3610. //进站结果写入PLC
  3611. CommandFromPLC resultToPlC = new CommandFromPLC();
  3612. resultToPlC.cmd = 0;
  3613. resultToPlC.cmdParam = 0; //指令参数
  3614. resultToPlC.cmdResult = mesResultFrmWeb;
  3615. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3616. stopwatch2.Stop();
  3617. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3618. //保存PLC返回MES数据到本地
  3619. ResponseMessage message = new ResponseMessage();
  3620. if (direction == "Left")
  3621. {
  3622. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3623. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3624. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3625. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3626. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3627. if (message.result == false)
  3628. {
  3629. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3630. }
  3631. }
  3632. if (direction == "Right")
  3633. {
  3634. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3635. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3636. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3637. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3638. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3639. if (message.result == false)
  3640. {
  3641. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3642. }
  3643. }
  3644. //保存螺丝数据到txt
  3645. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3646. if (result.Item1 != 0)
  3647. {
  3648. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3649. }
  3650. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3651. }
  3652. catch (Exception ex)
  3653. {
  3654. stopwatch2.Start();
  3655. CommandFromPLC resultToPlC = new CommandFromPLC();
  3656. resultToPlC.cmd = 0;
  3657. resultToPlC.cmdParam = 0; //指令参数
  3658. resultToPlC.cmdResult = 110;
  3659. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3660. stopwatch2.Stop();
  3661. string str = ex.StackTrace;
  3662. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3663. }
  3664. stopwatch1.Stop();
  3665. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3666. ProgressState = false;
  3667. }
  3668. #endregion
  3669. #region S8
  3670. /// <summary>
  3671. /// [S8] 3D螺丝高度检测设备
  3672. /// </summary>
  3673. /// <param name="plcNo">PLC编号</param>
  3674. private void ReadStation_S8(int plcNo)
  3675. {
  3676. string stationCode = "[OP80]";
  3677. string stationName = "NG下料";
  3678. string stationNameStr = stationCode + stationName;
  3679. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3680. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3681. string tagAgvCommName = "agvCommFrmPC";
  3682. string tagBarsetName = "BarcodeSet";
  3683. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3684. (int, string) result;
  3685. while (true)
  3686. {
  3687. try
  3688. {
  3689. if (!GlobalContext._IsCon_Funs1)
  3690. {
  3691. UpdatePLCMonitor(1, plcNo, 0);
  3692. continue;
  3693. }
  3694. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3695. {
  3696. Stopwatch stopwatch1 = new Stopwatch();
  3697. Stopwatch stopwatch2 = new Stopwatch();
  3698. stopwatch1.Start();
  3699. stopwatch2.Start();
  3700. #region 一次性读取所有数据
  3701. // 一次性读取所有数据
  3702. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3703. if (result.Item1 != 0)
  3704. {
  3705. //richTextBox1.AppendText("\n" + strRet);
  3706. }
  3707. else
  3708. {
  3709. //richTextBox1.AppendText("\n" + "读取成功");
  3710. }
  3711. #endregion 一次性读取所有数据
  3712. stopwatch2.Stop();
  3713. #region 进站
  3714. try
  3715. {
  3716. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3717. {
  3718. lock (lockObj)
  3719. {
  3720. if (!ProgressState)
  3721. {
  3722. ProgressState = true;
  3723. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3724. }
  3725. }
  3726. }
  3727. }
  3728. catch (Exception ex)
  3729. {
  3730. ProgressState = false;
  3731. string str = ex.StackTrace;
  3732. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3733. }
  3734. #endregion 进站
  3735. #region 出站
  3736. try
  3737. {
  3738. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3739. {
  3740. lock (lockObj)
  3741. {
  3742. if (!ProgressState)
  3743. {
  3744. ProgressState = true;
  3745. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3746. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3747. }
  3748. }
  3749. }
  3750. }
  3751. catch (Exception ex)
  3752. {
  3753. ProgressState = false;
  3754. string str = ex.StackTrace;
  3755. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3756. }
  3757. #endregion 出站
  3758. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3759. stopwatch1.Stop();
  3760. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3761. }
  3762. else
  3763. {
  3764. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3765. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3766. FunsEip[plcNo].Connect(); // 重连
  3767. }
  3768. }
  3769. catch (Exception ex)
  3770. {
  3771. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3772. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3773. }
  3774. Thread.Sleep(IntervalReadPLC);
  3775. }
  3776. }
  3777. /// <summary>
  3778. /// [S8] 3D螺丝高度检测设备 - 进站
  3779. /// </summary>
  3780. /// <param name="plcNo">PLC编号</param>
  3781. /// <param name="stationNameStr">工站全称</param>
  3782. /// <param name="stPLC_MesData"></param>
  3783. /// <param name="tagMesCommName"></param>
  3784. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3785. {
  3786. Stopwatch stopwatch1 = new Stopwatch();
  3787. Stopwatch stopwatch2 = new Stopwatch();
  3788. try
  3789. {
  3790. stopwatch1.Start();
  3791. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3792. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3793. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3794. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3795. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3796. //载具码验证产品码
  3797. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3798. if (string.IsNullOrEmpty(strProductBarcode))
  3799. {
  3800. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3801. }
  3802. sn = strProductBarcode;
  3803. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3804. // 产品SN(物料码)校验
  3805. List<TestItem> item = new List<TestItem>();
  3806. stopwatch2.Start();
  3807. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3808. stopwatch2.Stop();
  3809. //指令执行结果 1:OK 110:失败
  3810. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3811. //进站结果写入PLC
  3812. CommandFromPLC resultToPlC = new CommandFromPLC();
  3813. resultToPlC.cmd = 0;
  3814. resultToPlC.cmdParam = 0; //指令参数
  3815. resultToPlC.cmdResult = mesResultFrmWeb;
  3816. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3817. }
  3818. catch (Exception ex)
  3819. {
  3820. string str = ex.StackTrace;
  3821. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3822. CommandFromPLC resultToPlC = new CommandFromPLC();
  3823. resultToPlC.cmd = 0;
  3824. resultToPlC.cmdParam = 0; //指令参数
  3825. resultToPlC.cmdResult = 110;
  3826. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3827. }
  3828. stopwatch1.Stop();
  3829. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3830. ProgressState = false;
  3831. }
  3832. /// <summary>
  3833. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3834. /// </summary>
  3835. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3836. {
  3837. Stopwatch stopwatch1 = new Stopwatch();
  3838. Stopwatch stopwatch2 = new Stopwatch();
  3839. try
  3840. {
  3841. stopwatch1.Start();
  3842. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3843. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3844. string processItem = stationName; // 测试项目
  3845. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3846. string supplierCode = ""; // 供应商代码
  3847. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3848. string batch_num = GlobalContext.BatchNumber; // 批次号
  3849. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3850. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3851. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3852. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3853. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3854. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3855. bool pass = a1Result == 1;
  3856. //根据载具码获取产品码
  3857. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3858. if (string.IsNullOrEmpty(strProductBarcode))
  3859. {
  3860. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3861. }
  3862. sn = strProductBarcode;
  3863. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3864. List<TestItem> items = new List<TestItem>();
  3865. items.Add(new TestItem()
  3866. {
  3867. Parameter_name = "载具码",
  3868. Parameter_value = CarrierBarcode,
  3869. Parameter_unit = ""
  3870. });
  3871. items.Add(new TestItem()
  3872. {
  3873. Parameter_name = "产品码",
  3874. Parameter_value = sn,
  3875. Parameter_unit = ""
  3876. });
  3877. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3878. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3879. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3880. stopwatch2.Start();
  3881. //进站结果写入PLC
  3882. CommandFromPLC resultToPlC = new CommandFromPLC();
  3883. resultToPlC.cmd = 0;
  3884. resultToPlC.cmdParam = 0; //指令参数
  3885. resultToPlC.cmdResult = mesResultFrmWeb;
  3886. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3887. stopwatch2.Stop();
  3888. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3889. //保存PLC返回MES数据到本地
  3890. ResponseMessage message = new ResponseMessage();
  3891. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3892. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3893. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3894. if (message.result == false)
  3895. {
  3896. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3897. }
  3898. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3899. }
  3900. catch (Exception ex)
  3901. {
  3902. stopwatch2.Start();
  3903. CommandFromPLC resultToPlC = new CommandFromPLC();
  3904. resultToPlC.cmd = 0;
  3905. resultToPlC.cmdParam = 0; //指令参数
  3906. resultToPlC.cmdResult = 110;
  3907. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3908. stopwatch2.Stop();
  3909. string str = ex.StackTrace;
  3910. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3911. }
  3912. stopwatch1.Stop();
  3913. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3914. ProgressState = false;
  3915. }
  3916. #endregion
  3917. #region S9
  3918. /// <summary>
  3919. /// [S9] 下料设备
  3920. /// </summary>
  3921. /// <param name="plcNo">PLC编号</param>
  3922. private void ReadStation_S9(int plcNo)
  3923. {
  3924. string stationCode = "[OP90]";
  3925. string stationName = "半成品下料";
  3926. string stationNameStr = stationCode + stationName;
  3927. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3928. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3929. string tagAgvCommName = "agvCommFrmPC";
  3930. string tagBarsetName = "BarcodeSet";
  3931. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3932. (int, string) result;
  3933. while (true)
  3934. {
  3935. try
  3936. {
  3937. if (!GlobalContext._IsCon_Funs1)
  3938. {
  3939. UpdatePLCMonitor(1, plcNo, 0);
  3940. continue;
  3941. }
  3942. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3943. {
  3944. Stopwatch stopwatch1 = new Stopwatch();
  3945. Stopwatch stopwatch2 = new Stopwatch();
  3946. stopwatch1.Start();
  3947. stopwatch2.Start();
  3948. #region 一次性读取所有数据
  3949. // 一次性读取所有数据
  3950. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3951. if (result.Item1 != 0)
  3952. {
  3953. //richTextBox1.AppendText("\n" + strRet);
  3954. }
  3955. else
  3956. {
  3957. //richTextBox1.AppendText("\n" + "读取成功");
  3958. }
  3959. #endregion 一次性读取所有数据
  3960. stopwatch2.Stop();
  3961. #region 进站
  3962. try
  3963. {
  3964. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3965. {
  3966. lock (lockObj)
  3967. {
  3968. if (!ProgressState)
  3969. {
  3970. ProgressState = true;
  3971. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3972. }
  3973. }
  3974. }
  3975. }
  3976. catch (Exception ex)
  3977. {
  3978. ProgressState = false;
  3979. string str = ex.StackTrace;
  3980. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3981. }
  3982. #endregion 进站
  3983. #region 出站
  3984. try
  3985. {
  3986. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3987. {
  3988. lock (lockObj)
  3989. {
  3990. if (!ProgressState)
  3991. {
  3992. ProgressState = true;
  3993. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3994. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3995. }
  3996. }
  3997. }
  3998. }
  3999. catch (Exception ex)
  4000. {
  4001. ProgressState = false;
  4002. string str = ex.StackTrace;
  4003. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4004. }
  4005. #endregion 出站
  4006. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4007. stopwatch1.Stop();
  4008. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4009. }
  4010. else
  4011. {
  4012. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4013. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4014. FunsEip[plcNo].Connect(); // 重连
  4015. }
  4016. }
  4017. catch (Exception ex)
  4018. {
  4019. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4020. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4021. }
  4022. Thread.Sleep(IntervalReadPLC);
  4023. }
  4024. }
  4025. /// <summary>
  4026. /// [S9] 下料设备 - 进站
  4027. /// </summary>
  4028. /// <param name="plcNo">PLC编号</param>
  4029. /// <param name="stationNameStr">工站全称</param>
  4030. /// <param name="stPLC_MesData"></param>
  4031. /// <param name="tagMesCommName"></param>
  4032. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  4033. {
  4034. Stopwatch stopwatch1 = new Stopwatch();
  4035. Stopwatch stopwatch2 = new Stopwatch();
  4036. try
  4037. {
  4038. stopwatch1.Start();
  4039. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4040. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4041. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  4042. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  4043. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4044. //载具码验证产品码
  4045. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4046. if (string.IsNullOrEmpty(strProductBarcode))
  4047. {
  4048. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4049. }
  4050. sn = strProductBarcode;
  4051. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4052. // 产品SN(物料码)校验
  4053. List<TestItem> item = new List<TestItem>();
  4054. stopwatch2.Start();
  4055. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  4056. stopwatch2.Stop();
  4057. //指令执行结果 1:OK 110:失败
  4058. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4059. //进站结果写入PLC
  4060. CommandFromPLC resultToPlC = new CommandFromPLC();
  4061. resultToPlC.cmd = 0;
  4062. resultToPlC.cmdParam = 0; //指令参数
  4063. resultToPlC.cmdResult = mesResultFrmWeb;
  4064. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4065. }
  4066. catch (Exception ex)
  4067. {
  4068. string str = ex.StackTrace;
  4069. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4070. CommandFromPLC resultToPlC = new CommandFromPLC();
  4071. resultToPlC.cmd = 0;
  4072. resultToPlC.cmdParam = 0; //指令参数
  4073. resultToPlC.cmdResult = 110;
  4074. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4075. }
  4076. stopwatch1.Stop();
  4077. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4078. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4079. ProgressState = false;
  4080. }
  4081. /// <summary>
  4082. /// [S9] 下料设备 - 出站接口
  4083. /// </summary>
  4084. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  4085. {
  4086. Stopwatch stopwatch1 = new Stopwatch();
  4087. Stopwatch stopwatch2 = new Stopwatch();
  4088. try
  4089. {
  4090. stopwatch1.Start();
  4091. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4092. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4093. string processItem = stationName; // 测试项目
  4094. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4095. string supplierCode = ""; // 供应商代码
  4096. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4097. string batch_num = GlobalContext.BatchNumber; // 批次号
  4098. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4099. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4100. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4101. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  4102. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  4103. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4104. bool pass = a1Result == 1;
  4105. //根据载具码获取产品码
  4106. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4107. if (string.IsNullOrEmpty(strProductBarcode))
  4108. {
  4109. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4110. }
  4111. sn = strProductBarcode;
  4112. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4113. List<TestItem> items = new List<TestItem>();
  4114. items.Add(new TestItem()
  4115. {
  4116. Parameter_name = "载具码",
  4117. Parameter_value = CarrierBarcode,
  4118. Parameter_unit = ""
  4119. });
  4120. items.Add(new TestItem()
  4121. {
  4122. Parameter_name = "产品码",
  4123. Parameter_value = sn,
  4124. Parameter_unit = ""
  4125. });
  4126. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4127. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  4128. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4129. stopwatch2.Start();
  4130. //进站结果写入PLC
  4131. CommandFromPLC resultToPlC = new CommandFromPLC();
  4132. resultToPlC.cmd = 0;
  4133. resultToPlC.cmdParam = 0; //指令参数
  4134. resultToPlC.cmdResult = mesResultFrmWeb;
  4135. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4136. stopwatch2.Stop();
  4137. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4138. //保存PLC返回MES数据到本地
  4139. ResponseMessage message = new ResponseMessage();
  4140. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4141. if (message.result == false)
  4142. {
  4143. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4144. }
  4145. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4146. if (result1 == 1)
  4147. {
  4148. //载具码解除绑定
  4149. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4150. if (message.result == false)
  4151. {
  4152. AddMessage(LogType.Error, message.text);
  4153. }
  4154. }
  4155. }
  4156. catch (Exception ex)
  4157. {
  4158. stopwatch2.Start();
  4159. CommandFromPLC resultToPlC = new CommandFromPLC();
  4160. resultToPlC.cmd = 0;
  4161. resultToPlC.cmdParam = 0; //指令参数
  4162. resultToPlC.cmdResult = 110;
  4163. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4164. stopwatch2.Stop();
  4165. string str = ex.StackTrace;
  4166. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4167. }
  4168. stopwatch1.Stop();
  4169. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4170. ProgressState = false;
  4171. }
  4172. #endregion
  4173. #endregion Xiaomi
  4174. #region PLC1 张超凡
  4175. #region [S1] Tray盘上料装备(板测)
  4176. /// <summary>
  4177. /// S1工位的数据- 触发信号上次的值
  4178. /// </summary>
  4179. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4180. /// <summary>
  4181. /// S1工位的数据(含触发信号)
  4182. /// </summary>
  4183. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4184. /// <summary>
  4185. /// S1工位的数据- 回写点位
  4186. /// </summary>
  4187. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4188. ///// <summary>
  4189. ///// 触发信号
  4190. ///// </summary>
  4191. //private ManualResetEvent[] MreTasks;
  4192. /// <summary>
  4193. /// [S1] Tray盘上料装备(板测)
  4194. /// </summary>
  4195. /// <param name="plcNo">PLC编号</param>
  4196. //private void ReadStation_S1(int plcNo)
  4197. //{
  4198. // // [S1] Tray盘上料装备
  4199. // // [S2] FCT
  4200. // // [S3] 值板机
  4201. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4202. // // [S5] Tray盘下料装备
  4203. // string stationCode = "[S1]";
  4204. // string stationName = "Tray盘上料装备";
  4205. // string stationNameStr = stationCode + stationName;
  4206. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4207. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4208. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4209. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4210. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4211. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4212. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4213. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4214. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4215. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4216. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4217. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4218. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4219. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4220. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4221. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4222. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4223. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4224. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4225. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4226. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4227. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4228. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4229. // s1PLCData.Add("a1Result", 0); // 产品结果
  4230. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4231. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4232. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4233. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4234. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4235. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4236. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4237. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4238. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4239. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4240. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4241. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4242. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4243. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4244. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4245. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4246. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4247. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4248. // while (IsRun)
  4249. // {
  4250. // try
  4251. // {
  4252. // if (!GlobalContext._IsCon_Funs1)
  4253. // {
  4254. // UpdatePLCMonitor(1, plcNo, 0);
  4255. // continue;
  4256. // }
  4257. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4258. // {
  4259. // Stopwatch stopwatch1 = new Stopwatch();
  4260. // Stopwatch stopwatch2 = new Stopwatch();
  4261. // stopwatch1.Start();
  4262. // stopwatch2.Start();
  4263. // #region 一次性读取所有数据
  4264. // // 一次性读取所有数据
  4265. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4266. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4267. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4268. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4269. // int[] datas = data1.Concat(data2).ToArray();
  4270. // datas = datas.Concat(data3).ToArray();
  4271. // datas = datas.Concat(data4).ToArray();
  4272. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4273. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4274. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4275. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4276. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4277. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4278. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4279. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4280. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4281. // s1PLCData["a1MES_FLAG"] = datas[109];
  4282. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4283. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4284. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4285. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4286. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4287. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4288. // s1PLCData["a1Result"] = datas[170];
  4289. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4290. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4291. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4292. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4293. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4294. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4295. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4296. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4297. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4298. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4299. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4300. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4301. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4302. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4303. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4304. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4305. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4306. // s1PLCData["a1AGVUpStart"] = datas[308];
  4307. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4308. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4309. // s1PLCData["a1AGVDownStart"] = datas[321];
  4310. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4311. // #endregion 一次性读取所有数据
  4312. // stopwatch2.Stop();
  4313. // #region 回写操作,写后清空flag
  4314. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4315. // #endregion 回写操作,写后清空flag
  4316. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4317. // try
  4318. // {
  4319. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4320. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4321. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4322. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4323. // {
  4324. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4325. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4326. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4327. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4328. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4329. // }
  4330. // }
  4331. // catch (Exception ex)
  4332. // {
  4333. // // 6代表上位机报警
  4334. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4335. // string str = ex.StackTrace;
  4336. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4337. // }
  4338. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4339. // #region 上料进站校验
  4340. // try
  4341. // {
  4342. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4343. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4344. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4345. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4346. // {
  4347. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4348. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4349. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4350. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4351. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4352. // }
  4353. // }
  4354. // catch (Exception ex)
  4355. // {
  4356. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4357. // string str = ex.StackTrace;
  4358. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4359. // }
  4360. // #endregion 上料进站校验
  4361. // #region Tray盘上料装备-出站接口
  4362. // try
  4363. // {
  4364. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4365. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4366. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4367. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4368. // {
  4369. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4370. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4371. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4372. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4373. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4374. // }
  4375. // }
  4376. // catch (Exception ex)
  4377. // {
  4378. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4379. // string str = ex.StackTrace;
  4380. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4381. // }
  4382. // #endregion Tray盘上料装备-出站接口
  4383. // #region Tray盘上料装备-将SN发给ICT标机
  4384. // try
  4385. // {
  4386. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4387. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4388. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4389. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4390. // {
  4391. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4392. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4393. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4394. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4395. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4396. // }
  4397. // }
  4398. // catch (Exception ex)
  4399. // {
  4400. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4401. // string str = ex.StackTrace;
  4402. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4403. // }
  4404. // #endregion Tray盘上料装备-将SN发给ICT标机
  4405. // #region Tray盘上料装备-点检数据
  4406. // //try
  4407. // //{
  4408. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4409. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4410. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4411. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4412. // // if (pLC_Flag && !mES_Flag) // 1 0
  4413. // // {
  4414. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4415. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4416. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4417. // // }
  4418. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4419. // // {
  4420. // // // 清空写给PLC的数据
  4421. // // // MES_Flag重置为0
  4422. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4423. // // }
  4424. // //}
  4425. // //catch (Exception ex)
  4426. // //{
  4427. // // // MES_Flag 为2上位机报错
  4428. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4429. // // string str = ex.StackTrace;
  4430. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4431. // //}
  4432. // #endregion Tray盘上料装备-点检数据
  4433. // #region 节拍接口
  4434. // try
  4435. // {
  4436. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4437. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4438. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4439. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4440. // {
  4441. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4442. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4443. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4444. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4445. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4446. // }
  4447. // }
  4448. // catch (Exception ex)
  4449. // {
  4450. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4451. // string str = ex.StackTrace;
  4452. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4453. // }
  4454. // #endregion 节拍接口
  4455. // #region AGV上料
  4456. // // AGV上料叫AGV信号
  4457. // try
  4458. // {
  4459. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4460. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4461. // if (a1AGVUpCall != a1AGVUpCallOld)
  4462. // {
  4463. // if (a1AGVUpCall == 1) // 0->1
  4464. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4465. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4466. // }
  4467. // }
  4468. // catch (Exception ex)
  4469. // {
  4470. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4471. // string str = ex.StackTrace;
  4472. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4473. // }
  4474. // // AGV上料完成信号
  4475. // try
  4476. // {
  4477. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4478. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4479. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4480. // {
  4481. // if (a1AGVUpEnd == 1) // 0->1
  4482. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4483. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4484. // }
  4485. // }
  4486. // catch (Exception ex)
  4487. // {
  4488. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4489. // string str = ex.StackTrace;
  4490. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4491. // }
  4492. // #endregion AGV上料
  4493. // #region AGV下料
  4494. // // AGV下料叫agv信号
  4495. // try
  4496. // {
  4497. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4498. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4499. // if (a1AGVDownCall != a1AGVDownCallOld)
  4500. // {
  4501. // if (a1AGVDownCall == 1) // 0->1
  4502. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4503. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4504. // }
  4505. // }
  4506. // catch (Exception ex)
  4507. // {
  4508. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4509. // string str = ex.StackTrace;
  4510. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4511. // }
  4512. // // AGV下料完成信号
  4513. // try
  4514. // {
  4515. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4516. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4517. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4518. // {
  4519. // if (a1AGVDownEnd == 1) // 0->1
  4520. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4521. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4522. // }
  4523. // }
  4524. // catch (Exception ex)
  4525. // {
  4526. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4527. // string str = ex.StackTrace;
  4528. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4529. // }
  4530. // #endregion AGV下料
  4531. // #region 心跳
  4532. // try
  4533. // {
  4534. // short states = 0;
  4535. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4536. // }
  4537. // catch (Exception ex)
  4538. // {
  4539. // string str = ex.StackTrace;
  4540. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4541. // }
  4542. // #endregion 心跳
  4543. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4544. // stopwatch1.Stop();
  4545. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4546. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4547. // }
  4548. // else
  4549. // {
  4550. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4551. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4552. // Funs[plcNo].Connect(); // 重连
  4553. // }
  4554. // }
  4555. // catch (Exception ex)
  4556. // {
  4557. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4558. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4559. // Funs[plcNo].ReConnect();
  4560. // }
  4561. // Thread.Sleep(IntervalReadPLC);
  4562. // }
  4563. //}
  4564. /// <summary>
  4565. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4566. /// </summary>
  4567. /// <param name="plcNo">PLC编号</param>
  4568. /// <param name="stationNameStr">工站全称</param>
  4569. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4570. {
  4571. Stopwatch stopwatch1 = new Stopwatch();
  4572. Stopwatch stopwatch2 = new Stopwatch();
  4573. try
  4574. {
  4575. stopwatch1.Start();
  4576. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4577. sn = sn.Replace("\0", "");
  4578. #region 查询载具上的产品信息
  4579. string cavityData = string.Empty;
  4580. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4581. if (string.IsNullOrEmpty(cavityData))
  4582. cavityData = "";
  4583. if (snResult != 0)
  4584. {
  4585. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4586. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4587. writeToPLC_Flag1.Adress = 2003;
  4588. writeToPLC_Flag1.Value = (short)6;
  4589. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4590. stopwatch1.Stop();
  4591. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4592. return;
  4593. }
  4594. #endregion 查询载具上的产品信息
  4595. string[] cavitySNs = cavityData.Split('.');
  4596. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4597. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4598. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4599. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4600. if (cavitySNs != null && cavitySNs.Length >= 2)
  4601. {
  4602. a1CavitySN1_VehicleStates = cavitySNs[0];
  4603. a1CavitySN2_VehicleStates = cavitySNs[1];
  4604. a1CavityResult1_VehicleStates = 2;
  4605. a1CavityResult2_VehicleStates = 2;
  4606. }
  4607. if (a1CavitySN1_VehicleStates == "假产品")
  4608. a1CavityResult1_VehicleStates = 3;
  4609. if (a1CavitySN2_VehicleStates == "假产品")
  4610. a1CavityResult2_VehicleStates = 3;
  4611. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4612. // 回写
  4613. stopwatch2.Start();
  4614. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4615. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4616. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4617. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4618. //// MES_Flag
  4619. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4620. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4621. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4622. writeToPLC_Flag.Adress = 2003;
  4623. writeToPLC_Flag.Value = mES_Flag;
  4624. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4625. {
  4626. Name = "a1CavitySN1_VehicleStates",
  4627. Adress = 2024,
  4628. ValueType = PLCValueType.String,
  4629. ValueTypeStrLength = 20,
  4630. Value = a1CavitySN1_VehicleStates
  4631. });
  4632. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4633. {
  4634. Name = "a1CavitySN2_VehicleStates",
  4635. Adress = 2044,
  4636. ValueType = PLCValueType.String,
  4637. ValueTypeStrLength = 20,
  4638. Value = a1CavitySN2_VehicleStates
  4639. });
  4640. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4641. {
  4642. Name = "a1CavityResult1_VehicleStates",
  4643. Adress = 2064,
  4644. ValueType = PLCValueType.Short,
  4645. Value = a1CavityResult1_VehicleStates
  4646. });
  4647. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4648. {
  4649. Name = "a1CavityResult2_VehicleStates",
  4650. Adress = 2065,
  4651. ValueType = PLCValueType.Short,
  4652. Value = a1CavityResult2_VehicleStates
  4653. });
  4654. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4655. stopwatch2.Stop();
  4656. }
  4657. catch (Exception ex)
  4658. {
  4659. string str = ex.StackTrace;
  4660. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4661. // MES_Flag
  4662. stopwatch2.Start();
  4663. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4664. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4665. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4666. writeToPLC_Flag.Adress = 2003;
  4667. writeToPLC_Flag.Value = (short)6;
  4668. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4669. stopwatch2.Stop();
  4670. }
  4671. stopwatch1.Stop();
  4672. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4673. }
  4674. /// <summary>
  4675. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4676. /// </summary>
  4677. /// <param name="plcNo">PLC编号</param>
  4678. /// <param name="stationNameStr">工站全称</param>
  4679. private void S1上料进站校验(int plcNo, string stationNameStr)
  4680. {
  4681. Stopwatch stopwatch1 = new Stopwatch();
  4682. Stopwatch stopwatch2 = new Stopwatch();
  4683. try
  4684. {
  4685. stopwatch1.Start();
  4686. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4687. sn = sn.Replace("\0", "");
  4688. // 保存进站数据+调用进站MES接口
  4689. List<TestItem> item = new List<TestItem>();
  4690. stopwatch2.Start();
  4691. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4692. stopwatch2.Stop();
  4693. short a1MES_FLAG_Check = (short)result;
  4694. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4695. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4696. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4697. writeToPLC_Flag.Adress = 2077;
  4698. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4699. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4700. }
  4701. catch (Exception ex)
  4702. {
  4703. string str = ex.StackTrace;
  4704. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4705. // MES_Flag
  4706. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4707. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4708. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4709. writeToPLC_Flag.Adress = 2077;
  4710. writeToPLC_Flag.Value = (short)6;
  4711. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4712. }
  4713. stopwatch1.Stop();
  4714. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4715. }
  4716. /// <summary>
  4717. /// [S1] Tray盘上料装备(板测)- 出站接口
  4718. /// </summary>
  4719. /// <param name="plcNo"></param>
  4720. /// <param name="stationCode"></param>
  4721. /// <param name="stationName"></param>
  4722. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4723. {
  4724. Stopwatch stopwatch1 = new Stopwatch();
  4725. Stopwatch stopwatch2 = new Stopwatch();
  4726. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4727. string stationNameStr = stationCode + stationName;
  4728. string processItem = stationName; // 测试项目
  4729. try
  4730. {
  4731. stopwatch1.Start();
  4732. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4733. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4734. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4735. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4736. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4737. sn = sn.Replace("\0", "");
  4738. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4739. partNo1 = partNo1.Replace("\0", "");
  4740. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4741. partNo2 = partNo2.Replace("\0", "");
  4742. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4743. bool pass = a1Result == 1;
  4744. stopwatch2.Start();
  4745. // 产品1
  4746. List<TestItem> items = new List<TestItem>();
  4747. items.Add(new TestItem()
  4748. {
  4749. Parameter_name = "载具码",
  4750. Parameter_value = sn,
  4751. Parameter_unit = ""
  4752. });
  4753. items.Add(new TestItem()
  4754. {
  4755. Parameter_name = "载具穴号",
  4756. Parameter_value = "1",
  4757. Parameter_unit = ""
  4758. });
  4759. items.Add(new TestItem()
  4760. {
  4761. Parameter_name = "产品结果",
  4762. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4763. Parameter_unit = ""
  4764. });
  4765. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4766. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4767. // 产品2
  4768. items = new List<TestItem>();
  4769. items.Add(new TestItem()
  4770. {
  4771. Parameter_name = "载具码",
  4772. Parameter_value = sn,
  4773. Parameter_unit = ""
  4774. });
  4775. items.Add(new TestItem()
  4776. {
  4777. Parameter_name = "载具穴号",
  4778. Parameter_value = "2",
  4779. Parameter_unit = ""
  4780. });
  4781. items.Add(new TestItem()
  4782. {
  4783. Parameter_name = "产品结果",
  4784. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4785. Parameter_unit = ""
  4786. });
  4787. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4788. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4789. short result = 0;
  4790. List<int> results = new List<int>() { result1, result2 };
  4791. if (result1 == 1 && result2 == 1)
  4792. result = 1;
  4793. else if (results.Contains(3))
  4794. result = 3;
  4795. else if (results.Contains(2))
  4796. result = 2;
  4797. else if (results.Contains(4))
  4798. result = 4;
  4799. else
  4800. result = 4;
  4801. stopwatch2.Stop();
  4802. #region 存储绑定数据到 边线MES系统中
  4803. if (result == 1)
  4804. {
  4805. string data = string.Concat(partNo1, ".", partNo2);
  4806. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4807. if (resultMesR != 0)
  4808. {
  4809. result = 4;
  4810. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4811. }
  4812. }
  4813. #endregion 存储绑定数据到 边线MES系统中
  4814. // MES_Flag 为MES报错
  4815. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4816. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4817. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4818. writeToPLC_Flag.Name = "a1MES_FLAG";
  4819. writeToPLC_Flag.Adress = 2109;
  4820. writeToPLC_Flag.Value = result;
  4821. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4822. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4823. }
  4824. catch (Exception ex)
  4825. {
  4826. stopwatch2.Restart();
  4827. // MES_Flag 为4上位机报错
  4828. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4829. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4830. writeToPLC_Flag.Name = "a1MES_FLAG";
  4831. writeToPLC_Flag.Adress = 2109;
  4832. writeToPLC_Flag.Value = (short)4;
  4833. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4834. stopwatch2.Stop();
  4835. string str = ex.StackTrace;
  4836. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4837. }
  4838. stopwatch1.Stop();
  4839. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4840. }
  4841. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4842. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4843. //{
  4844. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4845. // string stationNameStr = stationCode + stationName;
  4846. // string processItem = stationName; // 测试项目
  4847. // try
  4848. // {
  4849. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4850. // string accno = "1"; // 工序编号
  4851. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4852. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4853. // List<OneCheckItem> items = new List<OneCheckItem>()
  4854. // {
  4855. // new OneCheckItem()
  4856. // {
  4857. // Onecheck_name="胶圈装配行程设定上限",
  4858. // Onecheck_content="上限值",
  4859. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4860. // },
  4861. // };
  4862. // OneCheckData oneCheckData = new OneCheckData()
  4863. // {
  4864. // Line_code = GlobalContext.LineCode,
  4865. // Line_name = GlobalContext.LineName,
  4866. // Equipment_code = equipmentCode,
  4867. // Equipment_name = equipmentCode,
  4868. // Workorder_code = workorder_code,
  4869. // Procedure_code = accno,
  4870. // Procedure_name = processItem,
  4871. // Oneckeck_values = items,
  4872. // Onecheck_empcode = "",
  4873. // Onecheck_empname = "",
  4874. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4875. // };
  4876. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4877. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4878. // short result = result1 == 1 ? (short)1 : (short)2;
  4879. // // MES_Flag 为4MES报错
  4880. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4881. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4882. // }
  4883. // catch (Exception ex)
  4884. // {
  4885. // // MES_Flag 为2上位机报错
  4886. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4887. // string str = ex.StackTrace;
  4888. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4889. // }
  4890. //}
  4891. // ReadStation_S1_2 节拍接口+AGV
  4892. /// <summary>
  4893. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4894. /// </summary>
  4895. /// <param name="plcNo">PLC编号</param>
  4896. /// <param name="stationNameStr">工站全称</param>
  4897. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4898. {
  4899. Stopwatch stopwatch1 = new Stopwatch();
  4900. Stopwatch stopwatch2 = new Stopwatch();
  4901. try
  4902. {
  4903. stopwatch1.Start();
  4904. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4905. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4906. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4907. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4908. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4909. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4910. // ZS 将SN发给ICT标机(串口)
  4911. short a1MES_FLAG_ICT = 1;
  4912. stopwatch2.Start();
  4913. // MES_Flag
  4914. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4915. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4916. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4917. writeToPLC_Flag.Adress = 2182;
  4918. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4919. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4920. stopwatch2.Stop();
  4921. }
  4922. catch (Exception ex)
  4923. {
  4924. string str = ex.StackTrace;
  4925. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4926. stopwatch2.Start();
  4927. // MES_Flag
  4928. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4929. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4930. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4931. writeToPLC_Flag.Adress = 2182;
  4932. writeToPLC_Flag.Value = (short)4;
  4933. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4934. stopwatch2.Stop();
  4935. }
  4936. stopwatch1.Stop();
  4937. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4938. }
  4939. /// <summary>
  4940. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4941. /// </summary>
  4942. /// <param name="plcNo">PLC编号</param>
  4943. /// <param name="stationNameStr">工站全称</param>
  4944. private void S1节拍接口(int plcNo, string stationNameStr)
  4945. {
  4946. Stopwatch stopwatch1 = new Stopwatch();
  4947. Stopwatch stopwatch2 = new Stopwatch();
  4948. string resultStr = string.Empty;
  4949. try
  4950. {
  4951. stopwatch1.Start();
  4952. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4953. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4954. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4955. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4956. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4957. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4958. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  4959. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4960. if (!actionBool)
  4961. {
  4962. stopwatch2.Start();
  4963. // MES_Flag
  4964. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4965. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4966. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  4967. writeToPLC_Flag1.Adress = 2254;
  4968. writeToPLC_Flag1.Value = (short)1;
  4969. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  4970. stopwatch2.Stop();
  4971. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4972. return;
  4973. }
  4974. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  4975. {
  4976. stopwatch2.Start();
  4977. // MES_Flag
  4978. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4979. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  4980. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  4981. writeToPLC_Flag2.Adress = 2254;
  4982. writeToPLC_Flag2.Value = (short)1;
  4983. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  4984. stopwatch2.Stop();
  4985. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4986. return;
  4987. }
  4988. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  4989. { // 查产品SN
  4990. a1OEEPartNo = "Test"; // ZS
  4991. }
  4992. short a1OEEMES_FLAG = 0;
  4993. // 上传OEE
  4994. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  4995. a1OEEMES_FLAG = result.Item1;
  4996. resultStr = result.Item2;
  4997. stopwatch2.Start();
  4998. // MES_Flag
  4999. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5000. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5001. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5002. writeToPLC_Flag.Adress = 2254;
  5003. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  5004. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5005. stopwatch2.Stop();
  5006. }
  5007. catch (Exception ex)
  5008. {
  5009. string str = ex.StackTrace;
  5010. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5011. // MES_Flag
  5012. stopwatch2.Start();
  5013. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  5014. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5015. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5016. writeToPLC_Flag.Adress = 2254;
  5017. writeToPLC_Flag.Value = (short)4;
  5018. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5019. stopwatch2.Stop();
  5020. }
  5021. stopwatch1.Stop();
  5022. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5023. }
  5024. /// <summary>
  5025. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  5026. /// </summary>
  5027. /// <param name="plcNo">PLC编号</param>
  5028. /// <param name="stationNameStr">工站全称</param>
  5029. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  5030. {
  5031. Stopwatch stopwatch1 = new Stopwatch();
  5032. Stopwatch stopwatch2 = new Stopwatch();
  5033. try
  5034. {
  5035. stopwatch1.Start();
  5036. // ZS 呼叫AGV
  5037. short a1AGVUpCall = 2;
  5038. stopwatch2.Start();
  5039. // a1AGVUpCall
  5040. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5041. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5042. writeToPLC_Flag.Name = "a1AGVUpCall";
  5043. writeToPLC_Flag.Adress = 2307;
  5044. writeToPLC_Flag.Value = a1AGVUpCall;
  5045. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", 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} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5052. // a1AGVUpCall
  5053. stopwatch2.Start();
  5054. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  5055. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5056. writeToPLC_Flag.Name = "a1AGVUpCall";
  5057. writeToPLC_Flag.Adress = 2307;
  5058. writeToPLC_Flag.Value = (short)4;
  5059. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5060. stopwatch2.Stop();
  5061. }
  5062. stopwatch1.Stop();
  5063. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5064. }
  5065. /// <summary>
  5066. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  5067. /// </summary>
  5068. /// <param name="plcNo">PLC编号</param>
  5069. /// <param name="stationNameStr">工站全称</param>
  5070. private void S1AGV上料完成(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 a1AGVUpEnd = 2;
  5079. stopwatch2.Start();
  5080. // a1AGVUpEnd
  5081. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5082. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5083. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5084. writeToPLC_Flag.Adress = 2309;
  5085. writeToPLC_Flag.Value = a1AGVUpEnd;
  5086. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", 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上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5093. // a1AGVUpEnd
  5094. stopwatch2.Start();
  5095. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  5096. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5097. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5098. writeToPLC_Flag.Adress = 2309;
  5099. writeToPLC_Flag.Value = (short)4;
  5100. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5101. stopwatch2.Stop();
  5102. }
  5103. stopwatch1.Stop();
  5104. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5105. }
  5106. /// <summary>
  5107. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  5108. /// </summary>
  5109. /// <param name="plcNo">PLC编号</param>
  5110. /// <param name="stationNameStr">工站全称</param>
  5111. private void S1AGV下料叫agv(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 a1AGVDownCall = 2;
  5120. stopwatch2.Start();
  5121. // a1AGVDownCall
  5122. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5123. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5124. writeToPLC_Flag.Name = "a1AGVDownCall";
  5125. writeToPLC_Flag.Adress = 2320;
  5126. writeToPLC_Flag.Value = a1AGVDownCall;
  5127. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", 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下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5134. // a1AGVDownCall
  5135. stopwatch2.Start();
  5136. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5137. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5138. writeToPLC_Flag.Name = "a1AGVDownCall";
  5139. writeToPLC_Flag.Adress = 2320;
  5140. writeToPLC_Flag.Value = (short)4;
  5141. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5142. stopwatch2.Stop();
  5143. }
  5144. stopwatch1.Stop();
  5145. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5146. }
  5147. /// <summary>
  5148. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5149. /// </summary>
  5150. /// <param name="plcNo">PLC编号</param>
  5151. /// <param name="stationNameStr">工站全称</param>
  5152. private void S1AGV下料完成(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 a1AGVDownEnd = 2;
  5161. stopwatch2.Start();
  5162. // a1AGVDownEnd
  5163. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5164. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5165. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5166. writeToPLC_Flag.Adress = 2322;
  5167. writeToPLC_Flag.Value = a1AGVDownEnd;
  5168. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", 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下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5175. // a1AGVDownEnd
  5176. stopwatch2.Start();
  5177. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5178. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5179. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5180. writeToPLC_Flag.Adress = 2322;
  5181. writeToPLC_Flag.Value = (short)4;
  5182. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5183. stopwatch2.Stop();
  5184. }
  5185. stopwatch1.Stop();
  5186. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5187. }
  5188. #endregion [S1] Tray盘上料装备(板测)
  5189. #endregion PLC1 张超凡
  5190. #region PLC2 李晓奇
  5191. #region [S2] FCT(板测)
  5192. /// <summary>
  5193. /// S2工位的数据- 触发信号上次的值
  5194. /// </summary>
  5195. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5196. /// <summary>
  5197. /// S2工位的数据(含触发信号)
  5198. /// </summary>
  5199. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5200. /// <summary>
  5201. /// S2工位的数据- 回写点位
  5202. /// </summary>
  5203. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5204. /// <summary>
  5205. /// [S2] FCT(板测)
  5206. /// </summary>
  5207. /// <param name="plcNo">PLC编号</param>
  5208. //private void ReadStation_S2(int plcNo)
  5209. //{
  5210. // // [S1] Tray盘上料装备
  5211. // // [S2] FCT
  5212. // // [S3] 值板机
  5213. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5214. // // [S5] Tray盘下料装备
  5215. // /// 上位机心跳
  5216. // /// 获取设备报警数据与状态信息
  5217. // string stationCode = "[S2]";
  5218. // string stationName = "FCT";
  5219. // string stationNameStr = stationCode + stationName;
  5220. // #region 创建字典
  5221. // // 触发信号字典 赋值
  5222. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5223. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5224. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5225. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5226. // // PLC数据字典 赋值
  5227. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5228. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5229. // s2PLCData.Add("b1ProductSN_Check", 0);
  5230. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5231. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5232. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5233. // s2PLCData.Add("b1ProductSN_Bind", "");
  5234. // s2PLCData.Add("b1Part1SN_Bind", "");
  5235. // s2PLCData.Add("b1Part2SN_Bind", "");
  5236. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5237. // s2PLCData.Add("b1MES_FLAG", 0);
  5238. // s2PLCData.Add("b1ProductSN", 0);
  5239. // s2PLCData.Add("b1Part1Result", 0);
  5240. // s2PLCData.Add("b1Part2Result", 0);
  5241. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5242. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5243. // s2PLCData.Add("b1OEEProductSN", "");
  5244. // s2PLCData.Add("b1OEEType", 0);
  5245. // #endregion 创建字典
  5246. // while (IsRun)
  5247. // {
  5248. // try
  5249. // {
  5250. // if (!GlobalContext._IsCon_Funs2)
  5251. // {
  5252. // UpdatePLCMonitor(1, plcNo, 0);
  5253. // continue;
  5254. // }
  5255. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5256. // {
  5257. // Stopwatch stopwatch1 = new Stopwatch();
  5258. // Stopwatch stopwatch2 = new Stopwatch();
  5259. // stopwatch1.Start();
  5260. // stopwatch2.Start();
  5261. // #region 一次性读取所有数据
  5262. // // 一次性读取所有数据
  5263. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5264. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5265. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5266. // int[] datas = data1.Concat(data2).ToArray();
  5267. // datas = datas.Concat(data3).ToArray();
  5268. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5269. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5270. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5271. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5272. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5273. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5274. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5275. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5276. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5277. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5278. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5279. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5280. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5281. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5282. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5283. // s2PLCData["b1MES_FLAG"] = datas[169];
  5284. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5285. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5286. // s2PLCData["b1Part1Result"] = datas[190];
  5287. // s2PLCData["b1Part2Result"] = datas[191];
  5288. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5289. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5290. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5291. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5292. // s2PLCData["b1OEEType"] = datas[224];
  5293. // #endregion 一次性读取所有数据
  5294. // stopwatch2.Stop();
  5295. // #region 回写操作,写后清空flag
  5296. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5297. // #endregion 回写操作,写后清空flag
  5298. // #region 进站校验
  5299. // try
  5300. // {
  5301. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5302. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5303. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5304. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5305. // {
  5306. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5307. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5308. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5309. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5310. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5311. // }
  5312. // }
  5313. // catch (Exception ex)
  5314. // {
  5315. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5316. // string str = ex.StackTrace;
  5317. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5318. // }
  5319. // #endregion 进站校验
  5320. // #region 二穴载具解绑/绑定(产品换载具)
  5321. // try
  5322. // {
  5323. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5324. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5325. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5326. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5327. // {
  5328. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5329. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5330. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5331. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5332. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5333. // }
  5334. // }
  5335. // catch (Exception ex)
  5336. // {
  5337. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5338. // string str = ex.StackTrace;
  5339. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5340. // }
  5341. // #endregion 二穴载具解绑/绑定(产品换载具)
  5342. // #region FCT-出站接口
  5343. // try
  5344. // {
  5345. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5346. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5347. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5348. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5349. // {
  5350. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5351. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5352. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5353. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5354. // }
  5355. // }
  5356. // catch (Exception ex)
  5357. // {
  5358. // // MES_Flag 为6上位机报错
  5359. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5360. // string str = ex.StackTrace;
  5361. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5362. // }
  5363. // #endregion FCT-出站接口
  5364. // #region 节拍接口
  5365. // try
  5366. // {
  5367. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5368. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5369. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5370. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5371. // {
  5372. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5373. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5374. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5375. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5376. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5377. // }
  5378. // }
  5379. // catch (Exception ex)
  5380. // {
  5381. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5382. // string str = ex.StackTrace;
  5383. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5384. // }
  5385. // #endregion 节拍接口
  5386. // #region 心跳
  5387. // try
  5388. // {
  5389. // short states = 0;
  5390. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5391. // }
  5392. // catch (Exception ex)
  5393. // {
  5394. // string str = ex.StackTrace;
  5395. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5396. // }
  5397. // #endregion 心跳
  5398. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5399. // stopwatch1.Stop();
  5400. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5401. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5402. // }
  5403. // else
  5404. // {
  5405. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5406. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5407. // Funs[plcNo].Connect();
  5408. // }
  5409. // }
  5410. // catch (Exception ex)
  5411. // {
  5412. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5413. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5414. // Funs[plcNo].ReConnect();
  5415. // }
  5416. // Thread.Sleep(IntervalReadPLC);
  5417. // }
  5418. //}
  5419. /// <summary>
  5420. /// [S2] FCT(板测)- 进站校验
  5421. /// </summary>
  5422. /// <param name="plcNo">PLC编号</param>
  5423. /// <param name="stationNameStr">工站全称</param>
  5424. private void S2进站校验(int plcNo, string stationNameStr)
  5425. {
  5426. Stopwatch stopwatch1 = new Stopwatch();
  5427. Stopwatch stopwatch2 = new Stopwatch();
  5428. try
  5429. {
  5430. stopwatch1.Start();
  5431. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5432. sn = sn.Replace("\0", "");
  5433. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5434. // 查询物料码By载具码 并判断是不是假产品
  5435. string cavityData = string.Empty;
  5436. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5437. if (string.IsNullOrEmpty(cavityData))
  5438. cavityData = "";
  5439. if (snResult != 0)
  5440. {
  5441. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5442. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5443. writeToPLC_Flag1.Adress = 2003;
  5444. writeToPLC_Flag1.Value = (short)6;
  5445. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5446. stopwatch1.Stop();
  5447. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5448. return;
  5449. }
  5450. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5451. string[] cavitySNs = cavityData.Split('.');
  5452. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5453. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5454. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5455. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5456. if (cavitySNs != null && cavitySNs.Length >= 2)
  5457. {
  5458. b1Part1SN_Check = cavitySNs[0];
  5459. b1Part2SN_Check = cavitySNs[1];
  5460. b1Part1Result_Check = 2;
  5461. b1Part2Result_Check = 2;
  5462. }
  5463. if (b1Part1SN_Check == "假产品")
  5464. b1Part1Result_Check = 3;
  5465. if (b1Part2SN_Check == "假产品")
  5466. b1Part2Result_Check = 3;
  5467. // 调用MES进站
  5468. stopwatch2.Start();
  5469. // 调用MES进站 - 产品1
  5470. List<TestItem> item;
  5471. int result1 = b1Part1Result_Check;
  5472. if (result1 != 3)
  5473. {
  5474. item = new List<TestItem>();
  5475. item.Add(new TestItem()
  5476. {
  5477. Parameter_name = "载具码",
  5478. Parameter_value = sn,
  5479. });
  5480. item.Add(new TestItem()
  5481. {
  5482. Parameter_name = "载具穴号",
  5483. Parameter_value = "1",
  5484. });
  5485. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5486. }
  5487. // 调用MES进站 - 产品2
  5488. int result2 = b1Part2Result_Check;
  5489. if (result2 != 3)
  5490. {
  5491. item = new List<TestItem>();
  5492. item.Add(new TestItem()
  5493. {
  5494. Parameter_name = "载具码",
  5495. Parameter_value = sn,
  5496. });
  5497. item.Add(new TestItem()
  5498. {
  5499. Parameter_name = "载具穴号",
  5500. Parameter_value = "2",
  5501. });
  5502. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5503. }
  5504. stopwatch2.Stop();
  5505. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5506. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5507. int result = result1;
  5508. if (result == 1)
  5509. result = result2;
  5510. short b1MES_FLAG_Check = (short)result;
  5511. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5512. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5513. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5514. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5515. //// MES_Flag
  5516. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5517. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5518. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5519. writeToPLC_Flag.Adress = 2003;
  5520. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5521. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5522. {
  5523. Name = "b1Part1SN_Check",
  5524. Adress = 2024,
  5525. ValueType = PLCValueType.String,
  5526. ValueTypeStrLength = 20,
  5527. Value = b1Part1SN_Check
  5528. });
  5529. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5530. {
  5531. Name = "b1Part2SN_Check",
  5532. Adress = 2044,
  5533. ValueType = PLCValueType.String,
  5534. ValueTypeStrLength = 20,
  5535. Value = b1Part2SN_Check
  5536. });
  5537. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5538. {
  5539. Name = "b1Part1Result_Check",
  5540. Adress = 2064,
  5541. ValueType = PLCValueType.Short,
  5542. Value = b1Part1Result_Check
  5543. });
  5544. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5545. {
  5546. Name = "b1Part2Result_Check",
  5547. Adress = 2065,
  5548. ValueType = PLCValueType.Short,
  5549. Value = b1Part2Result_Check
  5550. });
  5551. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5552. }
  5553. catch (Exception ex)
  5554. {
  5555. string str = ex.StackTrace;
  5556. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5557. // MES_Flag
  5558. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5559. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5560. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5561. writeToPLC_Flag.Adress = 2003;
  5562. writeToPLC_Flag.Value = (short)6;
  5563. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5564. }
  5565. stopwatch1.Stop();
  5566. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5567. }
  5568. /// <summary>
  5569. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5570. /// </summary>
  5571. /// <param name="plcNo">PLC编号</param>
  5572. /// <param name="stationNameStr">工站全称</param>
  5573. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5574. {
  5575. Stopwatch stopwatch1 = new Stopwatch();
  5576. Stopwatch stopwatch2 = new Stopwatch();
  5577. try
  5578. {
  5579. stopwatch1.Start();
  5580. // 产品换载具
  5581. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5582. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5583. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5584. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5585. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5586. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5587. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5588. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5589. stopwatch2.Start();
  5590. #region 查询载具上的产品信息
  5591. //string cavityData = string.Empty;
  5592. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5593. //if (string.IsNullOrEmpty(cavityData))
  5594. // cavityData = "";
  5595. //if (snResult != 0)
  5596. //{
  5597. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5598. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5599. // writeToPLC_Flag.Adress = 2077;
  5600. // writeToPLC_Flag.Value = (short)6;
  5601. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5602. // stopwatch1.Stop();
  5603. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5604. // return;
  5605. //}
  5606. #endregion 查询载具上的产品信息
  5607. #region 解绑(边线MES系统)
  5608. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5609. if (snResult != 0)
  5610. {
  5611. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5612. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5613. writeToPLC_Flag1.Adress = 2077;
  5614. writeToPLC_Flag1.Value = (short)6;
  5615. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5616. stopwatch1.Stop();
  5617. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5618. return;
  5619. }
  5620. #endregion 解绑(边线MES系统)
  5621. #region 存储绑定数据到 边线MES系统中
  5622. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5623. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5624. if (snResult != 0)
  5625. {
  5626. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5627. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5628. writeToPLC_Flag1.Adress = 2077;
  5629. writeToPLC_Flag1.Value = (short)6;
  5630. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5631. stopwatch1.Stop();
  5632. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5633. return;
  5634. }
  5635. #endregion 存储绑定数据到 边线MES系统中
  5636. stopwatch2.Stop();
  5637. short b1MES_FLAG_Unbind = 1;
  5638. // MES_Flag
  5639. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5640. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5641. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5642. writeToPLC_Flag.Adress = 2077;
  5643. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5644. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5645. }
  5646. catch (Exception ex)
  5647. {
  5648. string str = ex.StackTrace;
  5649. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5650. // MES_Flag
  5651. stopwatch2.Start();
  5652. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5653. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5654. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5655. writeToPLC_Flag.Adress = 2077;
  5656. writeToPLC_Flag.Value = (short)6;
  5657. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5658. stopwatch2.Stop();
  5659. }
  5660. stopwatch1.Stop();
  5661. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5662. }
  5663. //// 上次采集到的SN
  5664. //private string sn_FCT = string.Empty;
  5665. /// <summary>
  5666. /// [S2] FCT(板测)- 出站数据
  5667. /// </summary>
  5668. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5669. {
  5670. Stopwatch stopwatch1 = new Stopwatch();
  5671. Stopwatch stopwatch2 = new Stopwatch();
  5672. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5673. string stationNameStr = stationCode + stationName;
  5674. string processItem = stationName; // 测试项目
  5675. try
  5676. {
  5677. stopwatch1.Start();
  5678. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5679. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5680. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5681. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5682. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5683. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5684. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5685. bool pass1 = b1Part1Result == 1;
  5686. bool pass2 = b1Part2Result == 1;
  5687. #region 根据 载具SN 查 物料SN
  5688. string cavityData = string.Empty;
  5689. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5690. if (string.IsNullOrEmpty(cavityData))
  5691. cavityData = "";
  5692. if (snResult != 0)
  5693. {
  5694. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5695. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5696. writeToPLC_Flag1.Adress = 2169;
  5697. writeToPLC_Flag1.Value = (short)4;
  5698. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5699. stopwatch1.Stop();
  5700. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5701. return;
  5702. }
  5703. #endregion 根据 载具SN 查 物料SN
  5704. string[] cavitySNs = cavityData.Split('.');
  5705. string b1ProductSN1 = string.Empty;
  5706. string b1ProductSN2 = string.Empty;
  5707. if (cavitySNs != null && cavitySNs.Length >= 2)
  5708. {
  5709. b1ProductSN1 = cavitySNs[0];
  5710. b1ProductSN2 = cavitySNs[1];
  5711. }
  5712. stopwatch2.Start();
  5713. // 产品1
  5714. int result1 = 0;
  5715. if (b1ProductSN1 == "假产品")
  5716. result1 = 1;
  5717. else
  5718. {
  5719. List<TestItem> items1 = new List<TestItem>();
  5720. items1.Add(new TestItem()
  5721. {
  5722. Parameter_name = "载具码",
  5723. Parameter_value = b1ProductSN.ToString(),
  5724. Parameter_unit = ""
  5725. });
  5726. items1.Add(new TestItem()
  5727. {
  5728. Parameter_name = "载具穴号",
  5729. Parameter_value = "1",
  5730. Parameter_unit = ""
  5731. });
  5732. items1.Add(new TestItem()
  5733. {
  5734. Parameter_name = "产品结果",
  5735. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5736. Parameter_unit = ""
  5737. });
  5738. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5739. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5740. }
  5741. // 产品2
  5742. int result2 = 0;
  5743. if (b1ProductSN1 == "假产品")
  5744. result2 = 1;
  5745. else
  5746. {
  5747. List<TestItem> items2 = new List<TestItem>();
  5748. items2.Add(new TestItem()
  5749. {
  5750. Parameter_name = "载具码",
  5751. Parameter_value = b1ProductSN.ToString(),
  5752. Parameter_unit = ""
  5753. });
  5754. items2.Add(new TestItem()
  5755. {
  5756. Parameter_name = "载具穴号",
  5757. Parameter_value = "2",
  5758. Parameter_unit = ""
  5759. });
  5760. items2.Add(new TestItem()
  5761. {
  5762. Parameter_name = "产品结果",
  5763. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5764. Parameter_unit = ""
  5765. });
  5766. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5767. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5768. }
  5769. short result = 0;
  5770. List<int> results = new List<int>() { result1, result2 };
  5771. if (result1 == 1 && result2 == 1)
  5772. result = 1;
  5773. else if (results.Contains(3))
  5774. result = 3;
  5775. else if (results.Contains(2))
  5776. result = 2;
  5777. else if (results.Contains(4))
  5778. result = 4;
  5779. else
  5780. result = 4;
  5781. stopwatch2.Stop();
  5782. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5783. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5784. writeToPLC_Flag.Name = "b1MES_FLAG";
  5785. writeToPLC_Flag.Adress = 2169;
  5786. writeToPLC_Flag.Value = result;
  5787. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5788. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5789. }
  5790. catch (Exception ex)
  5791. {
  5792. stopwatch2.Restart();
  5793. // MES_Flag 为4上位机报错
  5794. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5795. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5796. writeToPLC_Flag.Name = "b1MES_FLAG";
  5797. writeToPLC_Flag.Adress = 2169;
  5798. writeToPLC_Flag.Value = (short)4;
  5799. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5800. stopwatch2.Stop();
  5801. string str = ex.StackTrace;
  5802. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5803. }
  5804. stopwatch1.Stop();
  5805. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5806. }
  5807. /// <summary>
  5808. /// [S2] FCT(板测)- 节拍接口
  5809. /// </summary>
  5810. /// <param name="plcNo">PLC编号</param>
  5811. /// <param name="stationNameStr">工站全称</param>
  5812. private void S2节拍接口(int plcNo, string stationNameStr)
  5813. {
  5814. Stopwatch stopwatch1 = new Stopwatch();
  5815. Stopwatch stopwatch2 = new Stopwatch();
  5816. string resultStr = string.Empty;
  5817. try
  5818. {
  5819. stopwatch1.Start();
  5820. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5821. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5822. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5823. if (!actionBool)
  5824. {
  5825. stopwatch2.Start();
  5826. // MES_Flag
  5827. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5828. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5829. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5830. writeToPLC_Flag1.Adress = 2203;
  5831. writeToPLC_Flag1.Value = (short)4;
  5832. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5833. stopwatch2.Stop();
  5834. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5835. return;
  5836. }
  5837. string b1OEEPartNo = string.Empty; // 物料码
  5838. if (string.IsNullOrEmpty(b1OEEProductSN))
  5839. {
  5840. stopwatch2.Start();
  5841. // MES_Flag
  5842. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5843. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5844. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5845. writeToPLC_Flag1.Adress = 2203;
  5846. writeToPLC_Flag1.Value = (short)1;
  5847. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5848. stopwatch2.Stop();
  5849. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5850. return;
  5851. }
  5852. else
  5853. { // 查产品SN
  5854. b1OEEPartNo = "Test"; // ZS
  5855. }
  5856. short b1OEEMES_FLAG = 0;
  5857. // 上传OEE
  5858. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5859. b1OEEMES_FLAG = result.Item1;
  5860. resultStr = result.Item2;
  5861. stopwatch2.Start();
  5862. // MES_Flag
  5863. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5864. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5865. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5866. writeToPLC_Flag.Adress = 2203;
  5867. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5868. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5869. stopwatch2.Stop();
  5870. }
  5871. catch (Exception ex)
  5872. {
  5873. string str = ex.StackTrace;
  5874. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5875. // MES_Flag
  5876. stopwatch2.Start();
  5877. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5878. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5879. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5880. writeToPLC_Flag.Adress = 2203;
  5881. writeToPLC_Flag.Value = (short)4;
  5882. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5883. stopwatch2.Stop();
  5884. }
  5885. stopwatch1.Stop();
  5886. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5887. }
  5888. #endregion [S2] FCT(板测)
  5889. #endregion PLC2 李晓奇
  5890. #region PLC3 刘永村
  5891. #region [S3] 值板机
  5892. /// <summary>
  5893. /// S3工位的数据- 触发信号上次的值
  5894. /// </summary>
  5895. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5896. /// <summary>
  5897. /// S3工位的数据(含触发信号)
  5898. /// </summary>
  5899. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5900. /// <summary>
  5901. /// S3工位的数据- 回写点位
  5902. /// </summary>
  5903. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5904. /// <summary>
  5905. /// [S3] 值板机
  5906. /// </summary>
  5907. /// <param name="plcNo">PLC编号</param>
  5908. //private void ReadStation_S3(int plcNo)
  5909. //{
  5910. // // [S1] Tray盘上料装备
  5911. // // [S2] FCT
  5912. // // [S3] 值板机
  5913. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5914. // // [S5] Tray盘下料装备
  5915. // /// 上位机心跳
  5916. // /// 获取设备报警数据与状态信息
  5917. // string stationCode = "[S3]";
  5918. // string stationName = "值板机";
  5919. // string stationNameStr = stationCode + stationName;
  5920. // #region 创建字典
  5921. // // 触发信号字典 赋值
  5922. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5923. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5924. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5925. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5926. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5927. // // PLC数据字典 赋值
  5928. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5929. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5930. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5931. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5932. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5933. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5934. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5935. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5936. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5937. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5938. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5939. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5940. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5941. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5942. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5943. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5944. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5945. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5946. // s3PLCData.Add("c1Result", 0); // 产品结果
  5947. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5948. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5949. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5950. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  5951. // #endregion 创建字典
  5952. // while (IsRun)
  5953. // {
  5954. // try
  5955. // {
  5956. // if (!GlobalContext._IsCon_Funs3)
  5957. // {
  5958. // UpdatePLCMonitor(1, plcNo, 0);
  5959. // continue;
  5960. // }
  5961. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5962. // {
  5963. // Stopwatch stopwatch1 = new Stopwatch();
  5964. // Stopwatch stopwatch2 = new Stopwatch();
  5965. // stopwatch1.Start();
  5966. // stopwatch2.Start();
  5967. // #region 一次性读取所有数据
  5968. // // 一次性读取所有数据
  5969. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  5970. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  5971. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  5972. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  5973. // int[] datas = data1.Concat(data2).ToArray();
  5974. // datas = datas.Concat(data3).ToArray();
  5975. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  5976. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  5977. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5978. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  5979. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  5980. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  5981. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5982. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  5983. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  5984. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  5985. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  5986. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5987. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  5988. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  5989. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  5990. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  5991. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5992. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  5993. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  5994. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  5995. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  5996. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  5997. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  5998. // #endregion 一次性读取所有数据
  5999. // stopwatch2.Stop();
  6000. // #region 回写操作,写后清空flag
  6001. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  6002. // #endregion 回写操作,写后清空flag
  6003. // #region S3进站校验
  6004. // try
  6005. // {
  6006. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  6007. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  6008. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  6009. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  6010. // {
  6011. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  6012. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6013. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  6014. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6015. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  6016. // }
  6017. // }
  6018. // catch (Exception ex)
  6019. // {
  6020. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6021. // string str = ex.StackTrace;
  6022. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6023. // }
  6024. // #endregion S3进站校验
  6025. // #region S3二穴载具解绑
  6026. // try
  6027. // {
  6028. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  6029. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  6030. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  6031. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  6032. // {
  6033. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6034. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  6035. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  6036. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  6037. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  6038. // }
  6039. // }
  6040. // catch (Exception ex)
  6041. // {
  6042. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  6043. // string str = ex.StackTrace;
  6044. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6045. // }
  6046. // #endregion S3二穴载具解绑
  6047. // #region S3二穴载具绑定
  6048. // try
  6049. // {
  6050. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  6051. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  6052. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  6053. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  6054. // {
  6055. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6056. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  6057. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  6058. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  6059. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  6060. // }
  6061. // }
  6062. // catch (Exception ex)
  6063. // {
  6064. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6065. // string str = ex.StackTrace;
  6066. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6067. // }
  6068. // #endregion S3二穴载具绑定
  6069. // #region S3出站接口(+一穴载具绑定)
  6070. // try
  6071. // {
  6072. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  6073. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  6074. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  6075. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  6076. // {
  6077. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  6078. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6079. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  6080. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  6081. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  6082. // }
  6083. // }
  6084. // catch (Exception ex)
  6085. // {
  6086. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  6087. // string str = ex.StackTrace;
  6088. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6089. // }
  6090. // #endregion S3出站接口(+一穴载具绑定)
  6091. // #region S3节拍接口
  6092. // try
  6093. // {
  6094. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  6095. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  6096. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  6097. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  6098. // {
  6099. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  6100. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6101. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  6102. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  6103. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  6104. // }
  6105. // }
  6106. // catch (Exception ex)
  6107. // {
  6108. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6109. // string str = ex.StackTrace;
  6110. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6111. // }
  6112. // #endregion S3节拍接口
  6113. // #region 心跳
  6114. // try
  6115. // {
  6116. // short states = 0;
  6117. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6118. // }
  6119. // catch (Exception ex)
  6120. // {
  6121. // string str = ex.StackTrace;
  6122. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6123. // }
  6124. // #endregion 心跳
  6125. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6126. // stopwatch1.Stop();
  6127. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6128. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6129. // }
  6130. // else
  6131. // {
  6132. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6133. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6134. // Funs[plcNo].Connect();
  6135. // }
  6136. // }
  6137. // catch (Exception ex)
  6138. // {
  6139. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6140. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6141. // Funs[plcNo].ReConnect();
  6142. // }
  6143. // Thread.Sleep(IntervalReadPLC);
  6144. // }
  6145. //}
  6146. /// <summary>
  6147. /// [S3] 值板机- 进站校验
  6148. /// </summary>
  6149. /// <param name="plcNo">PLC编号</param>
  6150. /// <param name="stationNameStr">工站全称</param>
  6151. private void S3进站校验(int plcNo, string stationNameStr)
  6152. {
  6153. Stopwatch stopwatch1 = new Stopwatch();
  6154. Stopwatch stopwatch2 = new Stopwatch();
  6155. try
  6156. {
  6157. stopwatch1.Start();
  6158. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6159. sn = sn.Replace("\0", "");
  6160. #region 查询载具上的产品信息
  6161. string cavityData = string.Empty;
  6162. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6163. if (string.IsNullOrEmpty(cavityData))
  6164. cavityData = "";
  6165. if (snResult != 0)
  6166. {
  6167. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6168. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6169. writeToPLC_Flag1.Adress = 2003;
  6170. writeToPLC_Flag1.Value = (short)6;
  6171. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6172. stopwatch1.Stop();
  6173. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6174. return;
  6175. }
  6176. #endregion 查询载具上的产品信息
  6177. string[] cavitySNs = cavityData.Split('.');
  6178. string part1Str = ""; // 产品1的SN码
  6179. string part2Str = ""; // 产品2的SN码
  6180. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6181. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6182. if (cavitySNs != null && cavitySNs.Length >= 2)
  6183. {
  6184. part1Str = cavitySNs[0];
  6185. part2Str = cavitySNs[1];
  6186. c1Part1Result_Check = 2;
  6187. c1Part2Result_Check = 2;
  6188. }
  6189. if (part1Str == "假产品")
  6190. c1Part1Result_Check = 3;
  6191. if (part2Str == "假产品")
  6192. c1Part2Result_Check = 3;
  6193. // 调用MES进站
  6194. stopwatch2.Start();
  6195. // 调用MES进站 - 产品1
  6196. List<TestItem> item;
  6197. int result1 = c1Part1Result_Check;
  6198. if (result1 != 3)
  6199. {
  6200. item = new List<TestItem>();
  6201. item.Add(new TestItem()
  6202. {
  6203. Parameter_name = "载具码",
  6204. Parameter_value = sn,
  6205. });
  6206. item.Add(new TestItem()
  6207. {
  6208. Parameter_name = "载具穴号",
  6209. Parameter_value = "1",
  6210. });
  6211. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6212. }
  6213. // 调用MES进站 - 产品2
  6214. int result2 = c1Part2Result_Check;
  6215. if (result2 != 3)
  6216. {
  6217. item = new List<TestItem>();
  6218. item.Add(new TestItem()
  6219. {
  6220. Parameter_name = "载具码",
  6221. Parameter_value = sn,
  6222. });
  6223. item.Add(new TestItem()
  6224. {
  6225. Parameter_name = "载具穴号",
  6226. Parameter_value = "2",
  6227. });
  6228. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6229. }
  6230. stopwatch2.Stop();
  6231. if (result1 == 2)
  6232. c1Part1Result_Check = 2;
  6233. if (result2 == 2)
  6234. c1Part2Result_Check = 2;
  6235. int result = result1;
  6236. if (result == 1)
  6237. result = result2;
  6238. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6239. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6240. short c1MES_FLAG_Check = (short)result;
  6241. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6242. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6243. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6244. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6245. //// MES_Flag
  6246. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6247. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6248. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6249. writeToPLC_Flag.Adress = 2003;
  6250. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6251. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6252. {
  6253. Name = "c1Part1Result_Check",
  6254. Adress = 2024,
  6255. ValueType = PLCValueType.Short,
  6256. Value = c1Part1Result_Check
  6257. });
  6258. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6259. {
  6260. Name = "c1Part2Result_Check",
  6261. Adress = 2025,
  6262. ValueType = PLCValueType.Short,
  6263. Value = c1Part2Result_Check
  6264. });
  6265. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6266. {
  6267. Name = "c1Part1Num_Check",
  6268. Adress = 2026,
  6269. ValueType = PLCValueType.Short,
  6270. Value = c1Part1Num_Check
  6271. });
  6272. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6273. {
  6274. Name = "c1Part2Num_Check",
  6275. Adress = 2027,
  6276. ValueType = PLCValueType.Short,
  6277. Value = c1Part2Num_Check
  6278. });
  6279. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6280. }
  6281. catch (Exception ex)
  6282. {
  6283. string str = ex.StackTrace;
  6284. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6285. // MES_Flag
  6286. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6287. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6288. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6289. writeToPLC_Flag.Adress = 2003;
  6290. writeToPLC_Flag.Value = (short)6;
  6291. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6292. }
  6293. stopwatch1.Stop();
  6294. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6295. }
  6296. /// <summary>
  6297. /// [S3] 值板机 - 二穴载具解绑
  6298. /// </summary>
  6299. /// <param name="plcNo">PLC编号</param>
  6300. /// <param name="stationNameStr">工站全称</param>
  6301. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6302. {
  6303. Stopwatch stopwatch1 = new Stopwatch();
  6304. Stopwatch stopwatch2 = new Stopwatch();
  6305. try
  6306. {
  6307. stopwatch1.Start();
  6308. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6309. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6310. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6311. // 解绑
  6312. #region 查询载具上的产品信息
  6313. string cavityData = string.Empty;
  6314. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6315. if (string.IsNullOrEmpty(cavityData))
  6316. cavityData = "";
  6317. if (snResult != 0)
  6318. {
  6319. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6320. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6321. writeToPLC_Flag1.Adress = 2082;
  6322. writeToPLC_Flag1.Value = (short)6;
  6323. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6324. stopwatch1.Stop();
  6325. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6326. return;
  6327. }
  6328. #endregion 查询载具上的产品信息
  6329. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6330. #region 解绑
  6331. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6332. {
  6333. // 删除
  6334. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6335. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6336. }
  6337. else
  6338. {
  6339. string data_new = string.Join(".", cavitySNs);
  6340. // 删除再插入
  6341. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6342. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6343. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6344. }
  6345. #endregion 解绑
  6346. short c1MES_FLAG_Unbind = 1;
  6347. stopwatch2.Start();
  6348. // MES_Flag
  6349. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6350. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6351. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6352. writeToPLC_Flag.Adress = 2082;
  6353. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6354. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6355. stopwatch2.Stop();
  6356. }
  6357. catch (Exception ex)
  6358. {
  6359. string str = ex.StackTrace;
  6360. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6361. // MES_Flag
  6362. stopwatch2.Start();
  6363. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6364. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6365. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6366. writeToPLC_Flag.Adress = 2082;
  6367. writeToPLC_Flag.Value = (short)6;
  6368. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6369. stopwatch2.Stop();
  6370. }
  6371. stopwatch1.Stop();
  6372. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6373. }
  6374. /// <summary>
  6375. /// [S3] 值板机 - 二穴载具绑定
  6376. /// </summary>
  6377. /// <param name="plcNo">PLC编号</param>
  6378. /// <param name="stationNameStr">工站全称</param>
  6379. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6380. {
  6381. Stopwatch stopwatch1 = new Stopwatch();
  6382. Stopwatch stopwatch2 = new Stopwatch();
  6383. try
  6384. {
  6385. stopwatch1.Start();
  6386. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6387. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6388. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6389. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6390. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6391. stopwatch2.Start();
  6392. #region 查询载具上的产品信息
  6393. string cavityData = string.Empty;
  6394. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6395. if (string.IsNullOrEmpty(cavityData))
  6396. cavityData = "";
  6397. if (snResult != 0)
  6398. {
  6399. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6400. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6401. writeToPLC_Flag1.Adress = 2115;
  6402. writeToPLC_Flag1.Value = (short)6;
  6403. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6404. stopwatch1.Stop();
  6405. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6406. return;
  6407. }
  6408. #endregion 查询载具上的产品信息
  6409. // 产品换载具
  6410. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6411. string partSn1 = "";
  6412. string partSn2 = "";
  6413. if (cavitySNs != null && cavitySNs.Length >= 2)
  6414. {
  6415. partSn1 = cavitySNs[0];
  6416. partSn2 = cavitySNs[1];
  6417. }
  6418. string data_new = string.Empty;
  6419. // 是否是两个穴位交换
  6420. if (c1CavityReverse_Bind == 1)
  6421. {
  6422. // 交换
  6423. data_new = string.Concat(partSn2, ".", partSn1);
  6424. }
  6425. else
  6426. { // 不交换
  6427. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6428. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6429. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6430. data_new = string.Join(".", cavitySNs);
  6431. }
  6432. // 删除再插入
  6433. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6434. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6435. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6436. stopwatch2.Stop();
  6437. short c1MES_FLAG_Bind = 1;
  6438. // MES_Flag
  6439. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6440. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6441. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6442. writeToPLC_Flag.Adress = 2115;
  6443. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6444. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6445. }
  6446. catch (Exception ex)
  6447. {
  6448. string str = ex.StackTrace;
  6449. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6450. // MES_Flag
  6451. stopwatch2.Start();
  6452. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6453. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6454. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6455. writeToPLC_Flag.Adress = 2115;
  6456. writeToPLC_Flag.Value = (short)6;
  6457. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6458. stopwatch2.Stop();
  6459. }
  6460. stopwatch1.Stop();
  6461. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6462. }
  6463. //// 上次采集到的SN
  6464. //private string sn_值板机 = string.Empty;
  6465. /// <summary>
  6466. /// [S3] 值板机 - 出站接口
  6467. /// </summary>
  6468. /// <param name="plcNo">PLC编号</param>
  6469. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6470. {
  6471. Stopwatch stopwatch1 = new Stopwatch();
  6472. Stopwatch stopwatch2 = new Stopwatch();
  6473. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6474. string stationNameStr = stationCode + stationName;
  6475. string processItem = stationName; // 测试项目
  6476. try
  6477. {
  6478. stopwatch1.Start();
  6479. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6480. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6481. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6482. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6483. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6484. sn = sn.Replace("\0", "");
  6485. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6486. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6487. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6488. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6489. bool pass = c1Result == 1;
  6490. // 查sn
  6491. #region 查询载具上的产品信息
  6492. string cavityData = string.Empty;
  6493. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6494. if (string.IsNullOrEmpty(cavityData))
  6495. cavityData = "";
  6496. if (snResult != 0)
  6497. {
  6498. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6499. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6500. writeToPLC_Flag1.Adress = 2150;
  6501. writeToPLC_Flag1.Value = (short)4;
  6502. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6503. stopwatch1.Stop();
  6504. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6505. return;
  6506. }
  6507. #endregion 查询载具上的产品信息
  6508. string[] cavitySNs = cavityData.Split('.');
  6509. string productSN = "";
  6510. if (cavitySNs != null && cavitySNs.Length >= 2)
  6511. {
  6512. productSN = cavitySNs[c1VehicleCavity];
  6513. cavitySNs[c1VehicleCavity] = "";
  6514. }
  6515. stopwatch2.Start();
  6516. List<TestItem> items = new List<TestItem>();
  6517. items.Add(new TestItem()
  6518. {
  6519. Parameter_name = "二穴载具码",
  6520. Parameter_value = c1ProductSN_Check,
  6521. Parameter_unit = ""
  6522. });
  6523. items.Add(new TestItem()
  6524. {
  6525. Parameter_name = "二穴载具穴号",
  6526. Parameter_value = c1VehicleCavity.ToString(),
  6527. Parameter_unit = ""
  6528. });
  6529. items.Add(new TestItem()
  6530. {
  6531. Parameter_name = "一穴载具码",
  6532. Parameter_value = sn,
  6533. Parameter_unit = ""
  6534. });
  6535. items.Add(new TestItem()
  6536. {
  6537. Parameter_name = "一穴载具穴号",
  6538. Parameter_value = "1",
  6539. Parameter_unit = ""
  6540. });
  6541. items.Add(new TestItem()
  6542. {
  6543. Parameter_name = "产品结果",
  6544. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6545. Parameter_unit = ""
  6546. });
  6547. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6548. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6549. short result = (short)result1;
  6550. stopwatch2.Stop();
  6551. #region 存储绑定数据到 边线MES系统中
  6552. if (result == 1)
  6553. {
  6554. string data = string.Concat(productSN);
  6555. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6556. if (resultMesR != 0)
  6557. {
  6558. result = 4;
  6559. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6560. }
  6561. }
  6562. #endregion 存储绑定数据到 边线MES系统中
  6563. #region 产品从 来源载具(二穴载具)中删除
  6564. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6565. {
  6566. // 删除
  6567. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6568. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6569. }
  6570. else
  6571. {
  6572. string data_new = string.Join(".", cavitySNs);
  6573. // 删除再插入
  6574. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6575. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6576. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6577. }
  6578. #endregion 产品从 来源载具(二穴载具)中删除
  6579. // MES_Flag 为MES报错
  6580. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6581. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6582. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6583. writeToPLC_Flag.Name = "c1MES_FLAG";
  6584. writeToPLC_Flag.Adress = 2150;
  6585. writeToPLC_Flag.Value = result;
  6586. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6587. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6588. }
  6589. catch (Exception ex)
  6590. {
  6591. stopwatch2.Restart();
  6592. // MES_Flag 为4上位机报错
  6593. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6594. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6595. writeToPLC_Flag.Name = "c1MES_FLAG";
  6596. writeToPLC_Flag.Adress = 2150;
  6597. writeToPLC_Flag.Value = (short)4;
  6598. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6599. stopwatch2.Stop();
  6600. string str = ex.StackTrace;
  6601. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6602. }
  6603. stopwatch1.Stop();
  6604. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6605. }
  6606. /// <summary>
  6607. /// [S3] 值板机- 节拍接口
  6608. /// </summary>
  6609. /// <param name="plcNo">PLC编号</param>
  6610. /// <param name="stationNameStr">工站全称</param>
  6611. private void S3节拍接口(int plcNo, string stationNameStr)
  6612. {
  6613. Stopwatch stopwatch1 = new Stopwatch();
  6614. Stopwatch stopwatch2 = new Stopwatch();
  6615. string resultStr = string.Empty;
  6616. try
  6617. {
  6618. stopwatch1.Start();
  6619. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6620. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6621. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6622. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6623. if (!actionBool)
  6624. {
  6625. stopwatch2.Start();
  6626. // MES_Flag
  6627. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6628. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6629. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6630. writeToPLC_Flag1.Adress = 2204;
  6631. writeToPLC_Flag1.Value = (short)4;
  6632. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6633. stopwatch2.Stop();
  6634. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6635. return;
  6636. }
  6637. string c1OEEPartNo = string.Empty; // 物料码
  6638. if (string.IsNullOrEmpty(c1OEEProductSN))
  6639. {
  6640. stopwatch2.Start();
  6641. // MES_Flag
  6642. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6643. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6644. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6645. writeToPLC_Flag1.Adress = 2204;
  6646. writeToPLC_Flag1.Value = (short)1;
  6647. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6648. stopwatch2.Stop();
  6649. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6650. return;
  6651. }
  6652. else
  6653. { // 查产品SN
  6654. c1OEEPartNo = "Test"; // ZS
  6655. }
  6656. short c1OEEMES_FLAG = 0;
  6657. // 上传OEE
  6658. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6659. c1OEEMES_FLAG = result.Item1;
  6660. resultStr = result.Item2;
  6661. stopwatch2.Start();
  6662. // MES_Flag
  6663. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6664. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6665. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6666. writeToPLC_Flag.Adress = 2204;
  6667. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6668. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6669. stopwatch2.Stop();
  6670. }
  6671. catch (Exception ex)
  6672. {
  6673. string str = ex.StackTrace;
  6674. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6675. // MES_Flag
  6676. stopwatch2.Start();
  6677. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6678. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6679. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6680. writeToPLC_Flag.Adress = 2204;
  6681. writeToPLC_Flag.Value = (short)4;
  6682. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6683. stopwatch2.Stop();
  6684. }
  6685. stopwatch1.Stop();
  6686. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6687. }
  6688. #endregion [S3] 值板机
  6689. #endregion PLC3 刘永村
  6690. #region PLC4 刘果段
  6691. #region [S4] 取放桁架
  6692. /// <summary>
  6693. /// S4工位的数据- 触发信号上次的值
  6694. /// </summary>
  6695. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6696. /// <summary>
  6697. /// S4工位的数据(含触发信号)
  6698. /// </summary>
  6699. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6700. /// <summary>
  6701. /// S4工位的数据- 回写点位
  6702. /// </summary>
  6703. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6704. /// <summary>
  6705. /// [S4] 取放桁架
  6706. /// </summary>
  6707. /// <param name="plcNo">PLC编号</param>
  6708. //private void ReadStation_S4(int plcNo)
  6709. //{
  6710. // // [S1] Tray盘上料装备
  6711. // // [S2] FCT
  6712. // // [S3] 值板机
  6713. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6714. // // [S5] Tray盘下料装备
  6715. // /// 上位机心跳
  6716. // /// 获取设备报警数据与状态信息
  6717. // string stationCode = "[S4_1]";
  6718. // string stationName = "载具下线装备";
  6719. // string stationNameStr = stationCode + stationName;
  6720. // string stationCode2 = "[S4_2]";
  6721. // string stationName2 = "桁架";
  6722. // string stationNameStr2 = stationCode2 + stationName2;
  6723. // string stationCode3 = "[S4_3]";
  6724. // string stationName3 = "提升机1";
  6725. // string stationNameStr3 = stationCode3 + stationName3;
  6726. // string stationCode4 = "[S4_4]";
  6727. // string stationName4 = "提升机2";
  6728. // string stationNameStr4 = stationCode4 + stationName4;
  6729. // string stationCode5 = "[S4_5]";
  6730. // string stationName5 = "载具上线装备";
  6731. // string stationNameStr5 = stationCode5 + stationName5;
  6732. // #region 创建字典
  6733. // // 触发信号字典 赋值
  6734. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6735. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6736. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6737. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6738. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6739. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6740. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6741. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6742. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6743. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6744. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6745. // // PLC数据字典 赋值
  6746. // // 载具下线装备(弹夹上线)
  6747. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6748. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6749. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6750. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6751. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6752. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6753. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6754. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6755. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6756. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6757. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6758. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6759. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6760. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6761. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6762. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6763. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6764. // s4PLCData.Add("d1Result", 0); // 产品结果
  6765. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6766. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6767. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6768. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6769. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6770. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6771. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6772. // // 真空标机(提升机)
  6773. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6774. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6775. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6776. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6777. // s4PLCData.Add("d3Result", 0); // 产品结果
  6778. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6779. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6780. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6781. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6782. // s4PLCData.Add("d4Result", 0); // 产品结果
  6783. // // 载具上线装备(弹夹下线)
  6784. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6785. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6786. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6787. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6788. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6789. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6790. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6791. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6792. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6793. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6794. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6795. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6796. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6797. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6798. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6799. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6800. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6801. // s4PLCData.Add("d5Result", 0); // 产品结果
  6802. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6803. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6804. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6805. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6806. // #endregion 创建字典
  6807. // while (IsRun)
  6808. // {
  6809. // try
  6810. // {
  6811. // if (!GlobalContext._IsCon_Funs4)
  6812. // {
  6813. // UpdatePLCMonitor(1, plcNo, 0);
  6814. // continue;
  6815. // }
  6816. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6817. // {
  6818. // Stopwatch stopwatch1 = new Stopwatch();
  6819. // Stopwatch stopwatch2 = new Stopwatch();
  6820. // stopwatch1.Start();
  6821. // stopwatch2.Start();
  6822. // #region 一次性读取所有数据
  6823. // // 载具下线装备(弹夹上线)
  6824. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6825. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6826. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6827. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6828. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6829. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6830. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6831. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6832. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6833. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6834. // int[] datas = data1.Concat(data2).ToArray();
  6835. // datas = datas.Concat(data3).ToArray();
  6836. // datas = datas.Concat(data4).ToArray();
  6837. // datas = datas.Concat(data5).ToArray();
  6838. // datas = datas.Concat(data6).ToArray();
  6839. // datas = datas.Concat(data7).ToArray();
  6840. // datas = datas.Concat(data8).ToArray();
  6841. // datas = datas.Concat(data9).ToArray();
  6842. // datas = datas.Concat(data10).ToArray();
  6843. // // 载具下线装备(弹夹上线)
  6844. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6845. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6846. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6847. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6848. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6849. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6850. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6851. // s4PLCData["d1MES_FLAG"] = datas[65];
  6852. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6853. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6854. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6855. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6856. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6857. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6858. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6859. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6860. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6861. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6862. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6863. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6864. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6865. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6866. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6867. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6868. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6869. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6870. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6871. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6872. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6873. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6874. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6875. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6876. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6877. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6878. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6879. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6880. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6881. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6882. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6883. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6884. // s4PLCData["d1Result"] = datas[386];
  6885. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6886. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6887. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6888. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6889. // s4PLCData["d1OEEType"] = datas[419];
  6890. // // 桁架(查询标机中弹夹的状态)
  6891. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6892. // s4PLCData["d2BulletclipStates"] = datas[431];
  6893. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6894. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6895. // // 真空标机
  6896. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6897. // s4PLCData["d3MES_FLAG"] = datas[463];
  6898. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6899. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6900. // s4PLCData["d3Result"] = datas[484];
  6901. // s4PLCData["d3Type"] = datas[485];
  6902. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6903. // s4PLCData["d4MES_FLAG"] = datas[496];
  6904. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6905. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6906. // s4PLCData["d4Result"] = datas[517];
  6907. // s4PLCData["d4Type"] = datas[518];
  6908. // // 载具上线装备(弹夹下线)
  6909. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6910. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6911. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6912. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6913. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6914. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6915. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6916. // s4PLCData["d5MES_FLAG"] = datas[591];
  6917. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6918. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6919. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6920. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6921. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6922. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6923. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6924. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6925. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6926. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6927. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6928. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6929. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6930. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6931. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6932. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6933. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6934. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6935. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6936. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6937. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6938. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6939. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6940. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6941. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6942. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6943. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6944. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6945. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6946. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6947. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6948. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6949. // s4PLCData["d5Result"] = datas[912];
  6950. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  6951. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  6952. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  6953. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  6954. // s4PLCData["d5OEEType"] = datas[945];
  6955. // #endregion 一次性读取所有数据
  6956. // stopwatch2.Stop();
  6957. // #region 回写操作,写后清空flag
  6958. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  6959. // #endregion 回写操作,写后清空flag
  6960. // // N801A-S4_1 弹夹扫码
  6961. // #region N801A-S4_1 弹夹扫码
  6962. // try
  6963. // {
  6964. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  6965. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  6966. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  6967. // {
  6968. // if (d1BulletclipScanCode == 1) // 0->1
  6969. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6970. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  6971. // }
  6972. // }
  6973. // catch (Exception ex)
  6974. // {
  6975. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  6976. // string str = ex.StackTrace;
  6977. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6978. // }
  6979. // #endregion N801A-S4_1 弹夹扫码
  6980. // // N801A-S4_1 载具扫码
  6981. // #region N801A-S4_1 载具扫码
  6982. // try
  6983. // {
  6984. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  6985. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  6986. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  6987. // {
  6988. // if (d1VehicleScanCode == 1) // 0->1
  6989. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6990. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  6991. // }
  6992. // }
  6993. // catch (Exception ex)
  6994. // {
  6995. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  6996. // string str = ex.StackTrace;
  6997. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6998. // }
  6999. // #endregion N801A-S4_1 载具扫码
  7000. // // N801A-S4_1 出站接口
  7001. // #region N801A-S4_1 出站接口
  7002. // try
  7003. // {
  7004. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  7005. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  7006. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  7007. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  7008. // {
  7009. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  7010. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7011. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  7012. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  7013. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  7014. // }
  7015. // }
  7016. // catch (Exception ex)
  7017. // {
  7018. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  7019. // string str = ex.StackTrace;
  7020. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7021. // }
  7022. // #endregion N801A-S4_1 出站接口
  7023. // // N801A-S4_1 节拍接口
  7024. // #region N801A-S4_1 节拍接口
  7025. // try
  7026. // {
  7027. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  7028. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  7029. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  7030. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  7031. // {
  7032. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  7033. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7034. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  7035. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  7036. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  7037. // }
  7038. // }
  7039. // catch (Exception ex)
  7040. // {
  7041. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7042. // string str = ex.StackTrace;
  7043. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7044. // }
  7045. // #endregion N801A-S4_1 节拍接口
  7046. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  7047. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  7048. // try
  7049. // {
  7050. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  7051. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  7052. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  7053. // {
  7054. // if (d2BulletclipScanCode == 1) // 0->1
  7055. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  7056. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  7057. // }
  7058. // }
  7059. // catch (Exception ex)
  7060. // {
  7061. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7062. // string str = ex.StackTrace;
  7063. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7064. // }
  7065. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  7066. // // N801A-S4_3 真空标机1 数据
  7067. // #region N801A-S4_3 真空标机1
  7068. // try
  7069. // {
  7070. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  7071. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  7072. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  7073. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  7074. // {
  7075. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  7076. // {
  7077. // int stationType = (int)s4PLCData["d3Type"];
  7078. // if (stationType == 1)
  7079. // {
  7080. // // S4_3进站接口
  7081. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  7082. // }
  7083. // else if (stationType == 2)
  7084. // {
  7085. // // S4_3出站接口
  7086. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  7087. // }
  7088. // }
  7089. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  7090. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  7091. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  7092. // }
  7093. // }
  7094. // catch (Exception ex)
  7095. // {
  7096. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7097. // string str = ex.StackTrace;
  7098. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7099. // }
  7100. // #endregion N801A-S4_3 真空标机1
  7101. // // N801A-S4_4 真空标机2 数据
  7102. // #region N801A-S4_4 真空标机2
  7103. // try
  7104. // {
  7105. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  7106. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  7107. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  7108. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  7109. // {
  7110. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  7111. // {
  7112. // int stationType = (int)s4PLCData["d4Type"];
  7113. // if (stationType == 1)
  7114. // {
  7115. // // S4_4进站接口
  7116. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  7117. // }
  7118. // else if (stationType == 2)
  7119. // {
  7120. // // S4_4出站接口
  7121. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  7122. // }
  7123. // }
  7124. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  7125. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  7126. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  7127. // }
  7128. // }
  7129. // catch (Exception ex)
  7130. // {
  7131. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7132. // string str = ex.StackTrace;
  7133. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7134. // }
  7135. // #endregion N801A-S4_4 真空标机2
  7136. // // N801A-S4_5 弹夹扫码 数据
  7137. // #region N801A-S4_5 弹夹扫码
  7138. // try
  7139. // {
  7140. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7141. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7142. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7143. // {
  7144. // if (d5BulletclipScanCode == 1) // 0->1
  7145. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7146. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7147. // }
  7148. // }
  7149. // catch (Exception ex)
  7150. // {
  7151. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7152. // string str = ex.StackTrace;
  7153. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7154. // }
  7155. // #endregion N801A-S4_5 弹夹扫码
  7156. // // N801A-S4_5 载具扫码 数据
  7157. // #region N801A-S4_5 载具扫码
  7158. // try
  7159. // {
  7160. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7161. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7162. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7163. // {
  7164. // if (d5VehicleScanCode == 1) // 0->1
  7165. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7166. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7167. // }
  7168. // }
  7169. // catch (Exception ex)
  7170. // {
  7171. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7172. // string str = ex.StackTrace;
  7173. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7174. // }
  7175. // #endregion N801A-S4_5 载具扫码
  7176. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7177. // #region N801A-S4_5 出站接口
  7178. // try
  7179. // {
  7180. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7181. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7182. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7183. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7184. // {
  7185. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7186. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7187. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7188. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7189. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7190. // }
  7191. // }
  7192. // catch (Exception ex)
  7193. // {
  7194. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7195. // string str = ex.StackTrace;
  7196. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7197. // }
  7198. // #endregion N801A-S4_5 出站接口
  7199. // // N801A-S4_5 节拍接口 数据
  7200. // #region N801A-S4_5 节拍接口
  7201. // try
  7202. // {
  7203. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7204. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7205. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7206. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7207. // {
  7208. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7209. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7210. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7211. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7212. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7213. // }
  7214. // }
  7215. // catch (Exception ex)
  7216. // {
  7217. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7218. // string str = ex.StackTrace;
  7219. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7220. // }
  7221. // #endregion N801A-S4_5 节拍接口
  7222. // #region 心跳
  7223. // try
  7224. // {
  7225. // short states = 0;
  7226. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7227. // }
  7228. // catch (Exception ex)
  7229. // {
  7230. // string str = ex.StackTrace;
  7231. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7232. // }
  7233. // #endregion 心跳
  7234. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7235. // stopwatch1.Stop();
  7236. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7237. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7238. // }
  7239. // else
  7240. // {
  7241. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7242. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7243. // Funs[plcNo].Connect();
  7244. // }
  7245. // }
  7246. // catch (Exception ex)
  7247. // {
  7248. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7249. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7250. // Funs[plcNo].ReConnect();
  7251. // }
  7252. // Thread.Sleep(IntervalReadPLC);
  7253. // }
  7254. //}
  7255. /// <summary>
  7256. /// [S4] 取放桁架 - S4_1弹夹扫码
  7257. /// </summary>
  7258. /// <param name="plcNo">PLC编号</param>
  7259. /// <param name="stationNameStr">工站全称</param>
  7260. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7261. {
  7262. Stopwatch stopwatch1 = new Stopwatch();
  7263. Stopwatch stopwatch2 = new Stopwatch();
  7264. try
  7265. {
  7266. stopwatch1.Start();
  7267. // ZS 弹夹扫码
  7268. string d1BulletclipCode = " "; // 扫到的码
  7269. short d1BulletclipScanCode = 2;
  7270. stopwatch2.Start();
  7271. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7272. //// MES_Flag
  7273. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7274. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7275. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7276. writeToPLC_Flag.Adress = 2002;
  7277. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7278. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7279. {
  7280. Name = "d1BulletclipCode",
  7281. Adress = 2003,
  7282. ValueType = PLCValueType.String,
  7283. ValueTypeStrLength = 20,
  7284. Value = d1BulletclipCode
  7285. });
  7286. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7287. stopwatch2.Stop();
  7288. }
  7289. catch (Exception ex)
  7290. {
  7291. string str = ex.StackTrace;
  7292. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7293. stopwatch2.Start();
  7294. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7295. //// MES_Flag
  7296. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7297. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7298. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7299. writeToPLC_Flag.Adress = 2002;
  7300. writeToPLC_Flag.Value = (short)6;
  7301. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7302. {
  7303. Name = "d1BulletclipCode",
  7304. Adress = 2003,
  7305. ValueType = PLCValueType.String,
  7306. ValueTypeStrLength = 20,
  7307. Value = " "
  7308. });
  7309. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7310. stopwatch2.Stop();
  7311. }
  7312. stopwatch1.Stop();
  7313. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7314. }
  7315. /// <summary>
  7316. /// [S4] 取放桁架 - S4_1载具扫码
  7317. /// </summary>
  7318. /// <param name="plcNo">PLC编号</param>
  7319. /// <param name="stationNameStr">工站全称</param>
  7320. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7321. {
  7322. Stopwatch stopwatch1 = new Stopwatch();
  7323. Stopwatch stopwatch2 = new Stopwatch();
  7324. try
  7325. {
  7326. stopwatch1.Start();
  7327. // ZS 载具扫码
  7328. string d1VehicleCode = ""; // 扫到的码
  7329. short d1VehicleScanCode = 2;
  7330. #region 进站
  7331. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7332. {
  7333. #region 查询载具上的产品信息
  7334. string cavityData = string.Empty;
  7335. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7336. if (string.IsNullOrEmpty(cavityData))
  7337. cavityData = "";
  7338. if (snResult != 0)
  7339. {
  7340. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7341. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7342. writeToPLC_Flag1.Adress = 2033;
  7343. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7344. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7345. {
  7346. Name = "d1VehicleCode",
  7347. Adress = 2034,
  7348. ValueType = PLCValueType.String,
  7349. ValueTypeStrLength = 20,
  7350. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7351. });
  7352. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7353. stopwatch1.Stop();
  7354. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7355. return;
  7356. }
  7357. string[] cavitySNs = cavityData.Split('.');
  7358. string partNo = "";
  7359. if (cavitySNs != null && cavitySNs.Length >= 1)
  7360. {
  7361. partNo = cavitySNs[0];
  7362. }
  7363. #endregion 查询载具上的产品信息
  7364. List<TestItem> item = new List<TestItem>();
  7365. item.Add(new TestItem()
  7366. {
  7367. Parameter_name = "载具码",
  7368. Parameter_value = d1VehicleCode,
  7369. });
  7370. item.Add(new TestItem()
  7371. {
  7372. Parameter_name = "载具穴号",
  7373. Parameter_value = "1",
  7374. });
  7375. stopwatch2.Start();
  7376. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7377. stopwatch2.Stop();
  7378. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7379. }
  7380. #endregion 进站
  7381. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7382. //// MES_Flag
  7383. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7384. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7385. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7386. writeToPLC_Flag.Adress = 2033;
  7387. writeToPLC_Flag.Value = d1VehicleScanCode;
  7388. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7389. {
  7390. Name = "d1VehicleCode",
  7391. Adress = 2034,
  7392. ValueType = PLCValueType.String,
  7393. ValueTypeStrLength = 20,
  7394. Value = d1VehicleCode
  7395. });
  7396. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7397. }
  7398. catch (Exception ex)
  7399. {
  7400. string str = ex.StackTrace;
  7401. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7402. stopwatch2.Start();
  7403. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7404. //// MES_Flag
  7405. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7406. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7407. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7408. writeToPLC_Flag.Adress = 2033;
  7409. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7410. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7411. {
  7412. Name = "d1VehicleCode",
  7413. Adress = 2034,
  7414. ValueType = PLCValueType.String,
  7415. ValueTypeStrLength = 20,
  7416. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7417. });
  7418. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7419. stopwatch2.Stop();
  7420. }
  7421. stopwatch1.Stop();
  7422. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7423. }
  7424. // 上次采集到的SN
  7425. //private string sn_S4_1出站接口 = string.Empty;
  7426. /// <summary>
  7427. /// [S4] 取放桁架 - S4_1出站接口
  7428. /// </summary>
  7429. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7430. {
  7431. Stopwatch stopwatch1 = new Stopwatch();
  7432. Stopwatch stopwatch2 = new Stopwatch();
  7433. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7434. string stationNameStr = stationCode + stationName;
  7435. string processItem = stationName; // 测试项目
  7436. try
  7437. {
  7438. stopwatch1.Start();
  7439. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7440. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7441. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7442. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7443. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7444. sn = sn.Replace("\0", "");
  7445. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7446. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7447. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7448. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7449. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7450. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7451. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7452. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7453. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7454. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7455. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7456. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7457. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7458. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7459. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7460. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7461. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7462. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7463. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7464. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7465. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7466. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7467. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7468. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7469. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7470. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7471. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7472. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7473. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7474. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7475. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7476. bool pass = d1Result == 1;
  7477. // 存 载具SN列表
  7478. List<string> vehicleCodes = new List<string>()
  7479. {
  7480. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7481. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7482. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7483. };
  7484. // 统一查 产品SN列表
  7485. List<string> partNos = new List<string>();
  7486. foreach (string vehicleCode in vehicleCodes)
  7487. {
  7488. if (string.IsNullOrEmpty(vehicleCode))
  7489. partNos.Add("");
  7490. else
  7491. {
  7492. string partNo = "";
  7493. #region 查询载具上的产品信息
  7494. string cavityData = string.Empty;
  7495. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7496. if (string.IsNullOrEmpty(cavityData))
  7497. cavityData = "";
  7498. if (snResult != 0)
  7499. {
  7500. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7501. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7502. writeToPLC_Flag1.Adress = 2065;
  7503. writeToPLC_Flag1.Value = (short)4;
  7504. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7505. stopwatch1.Stop();
  7506. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7507. return;
  7508. }
  7509. string[] cavitySNs = cavityData.Split('.');
  7510. if (cavitySNs != null && cavitySNs.Length >= 1)
  7511. partNo = cavitySNs[0];
  7512. #endregion 查询载具上的产品信息
  7513. partNos.Add(partNo);
  7514. }
  7515. }
  7516. // 统一上传
  7517. stopwatch2.Start();
  7518. List<int> results = new List<int>();
  7519. for (int i = 0; i < partNos.Count; i++)
  7520. {
  7521. string index = (i + 1).ToString(); // 弹夹穴号
  7522. if (string.IsNullOrEmpty(partNos[i]))
  7523. results.Add(1);
  7524. else
  7525. {
  7526. List<TestItem> items1 = new List<TestItem>();
  7527. items1.Add(new TestItem()
  7528. {
  7529. Parameter_name = "弹夹码",
  7530. Parameter_value = sn,
  7531. Parameter_unit = ""
  7532. });
  7533. items1.Add(new TestItem()
  7534. {
  7535. Parameter_name = "弹夹穴号",
  7536. Parameter_value = index,
  7537. Parameter_unit = ""
  7538. });
  7539. items1.Add(new TestItem()
  7540. {
  7541. Parameter_name = "载具码",
  7542. Parameter_value = vehicleCodes[i],
  7543. Parameter_unit = ""
  7544. });
  7545. items1.Add(new TestItem()
  7546. {
  7547. Parameter_name = "载具穴号",
  7548. Parameter_value = "1",
  7549. Parameter_unit = ""
  7550. });
  7551. items1.Add(new TestItem()
  7552. {
  7553. Parameter_name = "产品结果",
  7554. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7555. Parameter_unit = ""
  7556. });
  7557. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7558. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7559. results.Add(result1);
  7560. }
  7561. }
  7562. short result = 0;
  7563. if (results.All(a => a == 1))
  7564. result = 1;
  7565. else if (results.Contains(3))
  7566. result = 3;
  7567. else if (results.Contains(2))
  7568. result = 2;
  7569. else if (results.Contains(4))
  7570. result = 4;
  7571. else
  7572. result = 4;
  7573. stopwatch2.Stop();
  7574. #region 存储绑定数据到 边线MES系统中
  7575. if (result == 1)
  7576. {
  7577. string data = string.Join(".", vehicleCodes);
  7578. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7579. if (resultMesR != 0)
  7580. {
  7581. result = 4;
  7582. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7583. }
  7584. }
  7585. #endregion 存储绑定数据到 边线MES系统中
  7586. // MES_Flag 为4MES报错
  7587. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7588. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7589. writeToPLC_Flag.Name = "d1MES_FLAG";
  7590. writeToPLC_Flag.Adress = 2065;
  7591. writeToPLC_Flag.Value = result;
  7592. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7593. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7594. }
  7595. catch (Exception ex)
  7596. {
  7597. stopwatch2.Restart();
  7598. // MES_Flag 为4上位机报错
  7599. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7600. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7601. writeToPLC_Flag.Name = "d1MES_FLAG";
  7602. writeToPLC_Flag.Adress = 2065;
  7603. writeToPLC_Flag.Value = (short)4;
  7604. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7605. stopwatch2.Stop();
  7606. string str = ex.StackTrace;
  7607. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7608. }
  7609. stopwatch1.Stop();
  7610. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7611. }
  7612. /// <summary>
  7613. /// [S4] 取放桁架 - S4_1节拍接口
  7614. /// </summary>
  7615. /// <param name="plcNo">PLC编号</param>
  7616. /// <param name="stationNameStr">工站全称</param>
  7617. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7618. {
  7619. Stopwatch stopwatch1 = new Stopwatch();
  7620. Stopwatch stopwatch2 = new Stopwatch();
  7621. string resultStr = string.Empty;
  7622. try
  7623. {
  7624. stopwatch1.Start();
  7625. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7626. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7627. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7628. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7629. if (!actionBool)
  7630. {
  7631. stopwatch2.Start();
  7632. // MES_Flag
  7633. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7634. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7635. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7636. writeToPLC_Flag1.Adress = 2398;
  7637. writeToPLC_Flag1.Value = (short)4;
  7638. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7639. stopwatch2.Stop();
  7640. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7641. return;
  7642. }
  7643. string d1OEEPartNo = string.Empty; // 物料码
  7644. if (string.IsNullOrEmpty(d1OEEProductSN))
  7645. {
  7646. stopwatch2.Start();
  7647. // MES_Flag
  7648. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7649. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7650. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7651. writeToPLC_Flag1.Adress = 2398;
  7652. writeToPLC_Flag1.Value = (short)1;
  7653. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7654. stopwatch2.Stop();
  7655. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7656. return;
  7657. }
  7658. else
  7659. { // 查产品SN ZS
  7660. d1OEEPartNo = "Test";
  7661. }
  7662. short d1OEEMES_FLAG = 0;
  7663. // 上传OEE
  7664. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7665. d1OEEMES_FLAG = result.Item1;
  7666. resultStr = result.Item2;
  7667. stopwatch2.Start();
  7668. // MES_Flag
  7669. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7670. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7671. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7672. writeToPLC_Flag.Adress = 2398;
  7673. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7674. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7675. stopwatch2.Stop();
  7676. }
  7677. catch (Exception ex)
  7678. {
  7679. string str = ex.StackTrace;
  7680. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7681. // MES_Flag
  7682. stopwatch2.Start();
  7683. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7684. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7685. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7686. writeToPLC_Flag.Adress = 2398;
  7687. writeToPLC_Flag.Value = (short)4;
  7688. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7689. stopwatch2.Stop();
  7690. }
  7691. stopwatch1.Stop();
  7692. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7693. }
  7694. /// <summary>
  7695. /// [S4] 取放桁架 - S4_2桁架
  7696. /// </summary>
  7697. /// <param name="plcNo">PLC编号</param>
  7698. /// <param name="stationNameStr">工站全称</param>
  7699. private void S4_2桁架(int plcNo, string stationNameStr)
  7700. {
  7701. Stopwatch stopwatch1 = new Stopwatch();
  7702. Stopwatch stopwatch2 = new Stopwatch();
  7703. try
  7704. {
  7705. stopwatch1.Start();
  7706. // ZS 弹夹扫码
  7707. string d2BulletclipCode = " "; // 扫到的码
  7708. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7709. short d2BulletclipScanCode = 2;
  7710. stopwatch2.Start();
  7711. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7712. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7713. //// MES_Flag
  7714. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7715. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7716. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7717. writeToPLC_Flag.Adress = 2430;
  7718. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7719. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7720. {
  7721. Name = "d2BulletclipCode",
  7722. Adress = 2432,
  7723. ValueType = PLCValueType.String,
  7724. ValueTypeStrLength = 20,
  7725. Value = d2BulletclipCode
  7726. });
  7727. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7728. {
  7729. Name = "d2BulletclipStates",
  7730. Adress = 2431,
  7731. ValueType = PLCValueType.Short,
  7732. Value = d2BulletclipStates
  7733. });
  7734. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7735. stopwatch2.Stop();
  7736. }
  7737. catch (Exception ex)
  7738. {
  7739. string str = ex.StackTrace;
  7740. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7741. stopwatch2.Start();
  7742. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7743. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7744. // MES_Flag
  7745. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7746. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7747. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7748. writeToPLC_Flag.Adress = 2430;
  7749. writeToPLC_Flag.Value = (short)6;
  7750. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7751. {
  7752. Name = "d2BulletclipCode",
  7753. Adress = 2432,
  7754. ValueType = PLCValueType.String,
  7755. ValueTypeStrLength = 20,
  7756. Value = " "
  7757. });
  7758. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7759. {
  7760. Name = "d2BulletclipStates",
  7761. Adress = 2431,
  7762. ValueType = PLCValueType.Short,
  7763. Value = (short)0
  7764. });
  7765. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7766. stopwatch2.Stop();
  7767. }
  7768. stopwatch1.Stop();
  7769. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7770. }
  7771. // 上次采集到的SN
  7772. //private string sn_S4_3进站接口 = string.Empty;
  7773. /// <summary>
  7774. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7775. /// </summary>
  7776. private void S4_3进站接口(int plcNo, string stationNameStr)
  7777. {
  7778. Stopwatch stopwatch1 = new Stopwatch();
  7779. Stopwatch stopwatch2 = new Stopwatch();
  7780. try
  7781. {
  7782. stopwatch1.Start();
  7783. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7784. sn = sn.Replace("\0", "");
  7785. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7786. #region 查询15个载具码
  7787. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7788. string vehicleData = string.Empty;
  7789. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7790. if (string.IsNullOrEmpty(vehicleData))
  7791. vehicleData = "";
  7792. if (snResult != 0)
  7793. {
  7794. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7795. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7796. writeToPLC_Flag1.Adress = 2463;
  7797. writeToPLC_Flag1.Value = (short)4;
  7798. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7799. stopwatch1.Stop();
  7800. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7801. return;
  7802. }
  7803. string[] cavitySNs = vehicleData.Split('.');
  7804. if (cavitySNs != null && cavitySNs.Length > 0)
  7805. {
  7806. for (int i = 0; i < cavitySNs.Length; i++)
  7807. {
  7808. if (string.IsNullOrEmpty(cavitySNs[i]))
  7809. vehicleCodes.Add("");
  7810. else
  7811. vehicleCodes.Add(cavitySNs[i]);
  7812. }
  7813. }
  7814. #endregion 查询15个载具码
  7815. #region 查询15个产品SN
  7816. List<string> portNos = new List<string>(); // 15个产品SN
  7817. foreach (string vehicleCode in vehicleCodes)
  7818. {
  7819. if (string.IsNullOrEmpty(vehicleCode))
  7820. portNos.Add("");
  7821. else
  7822. {
  7823. // 查询
  7824. string cavityData = string.Empty;
  7825. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7826. if (string.IsNullOrEmpty(cavityData))
  7827. cavityData = "";
  7828. if (snResult1 != 0)
  7829. {
  7830. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7831. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7832. writeToPLC_Flag1.Adress = 2463;
  7833. writeToPLC_Flag1.Value = (short)4;
  7834. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7835. stopwatch1.Stop();
  7836. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7837. return;
  7838. }
  7839. string[] partSNs = cavityData.Split('.');
  7840. if (partSNs != null && partSNs.Length >= 1)
  7841. portNos.Add(partSNs[0]);
  7842. else
  7843. portNos.Add("");
  7844. }
  7845. }
  7846. #endregion 查询15个产品SN
  7847. // 调用MES进站(最多15个)
  7848. stopwatch2.Start();
  7849. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7850. for (int i = 0; i < vehicleCodes.Count; i++)
  7851. {
  7852. // 循环进站
  7853. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7854. {
  7855. // 产品SN(物料码)校验
  7856. string portNo = portNos[i];
  7857. List<TestItem> item = new List<TestItem>();
  7858. item.Add(new TestItem()
  7859. {
  7860. Parameter_name = "弹夹码",
  7861. Parameter_value = sn,
  7862. });
  7863. item.Add(new TestItem()
  7864. {
  7865. Parameter_name = "弹夹穴位",
  7866. Parameter_value = (i + 1).ToString(),
  7867. });
  7868. item.Add(new TestItem()
  7869. {
  7870. Parameter_name = "载具码",
  7871. Parameter_value = vehicleCodes[i],
  7872. });
  7873. item.Add(new TestItem()
  7874. {
  7875. Parameter_name = "载具穴号",
  7876. Parameter_value = "1",
  7877. });
  7878. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7879. }
  7880. }
  7881. stopwatch2.Stop();
  7882. short result = 0;
  7883. bool haveMesWarn = results.Contains(5);
  7884. bool havePCWarn = results.Contains(6);
  7885. if (haveMesWarn)
  7886. result = 2; // 5->2
  7887. else if (havePCWarn)
  7888. result = 6; // 6->4
  7889. else
  7890. result = 1;
  7891. // MES_Flag 为4MES报错
  7892. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7893. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7894. writeToPLC_Flag.Name = "d3MES_FLAG";
  7895. writeToPLC_Flag.Adress = 2463;
  7896. writeToPLC_Flag.Value = result;
  7897. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7898. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7899. }
  7900. catch (Exception ex)
  7901. {
  7902. stopwatch2.Stop();
  7903. // MES_Flag 为4上位机报错
  7904. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7905. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7906. writeToPLC_Flag.Name = "d3MES_FLAG";
  7907. writeToPLC_Flag.Adress = 2463;
  7908. writeToPLC_Flag.Value = (short)4;
  7909. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7910. string str = ex.StackTrace;
  7911. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7912. }
  7913. stopwatch1.Stop();
  7914. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7915. }
  7916. // 上次采集到的SN
  7917. //private string sn_S4_3出站接口 = string.Empty;
  7918. /// <summary>
  7919. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7920. /// </summary>
  7921. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7922. {
  7923. Stopwatch stopwatch1 = new Stopwatch();
  7924. Stopwatch stopwatch2 = new Stopwatch();
  7925. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7926. string stationNameStr = stationCode + stationName;
  7927. string processItem = stationName; // 测试项目
  7928. try
  7929. {
  7930. stopwatch1.Start();
  7931. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7932. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7933. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7934. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7935. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7936. sn = sn.Replace("\0", "");
  7937. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7938. bool isPass = d3Result == 1; // 产品结果 bool
  7939. #region 查询15个载具码
  7940. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7941. string vehicleData = string.Empty;
  7942. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7943. if (string.IsNullOrEmpty(vehicleData))
  7944. vehicleData = "";
  7945. if (snResult1 != 0)
  7946. {
  7947. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7948. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7949. writeToPLC_Flag1.Adress = 2463;
  7950. writeToPLC_Flag1.Value = (short)4;
  7951. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7952. stopwatch1.Stop();
  7953. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7954. return;
  7955. }
  7956. string[] cavitySNs = vehicleData.Split('.');
  7957. if (cavitySNs != null && cavitySNs.Length > 0)
  7958. {
  7959. for (int i = 0; i < cavitySNs.Length; i++)
  7960. {
  7961. if (string.IsNullOrEmpty(cavitySNs[i]))
  7962. vehicleCodes.Add("");
  7963. else
  7964. vehicleCodes.Add(cavitySNs[i]);
  7965. }
  7966. }
  7967. #endregion 查询15个载具码
  7968. // 统一查 产品SN列表
  7969. List<string> partNos = new List<string>();
  7970. foreach (string vehicleCode in vehicleCodes)
  7971. {
  7972. if (string.IsNullOrEmpty(vehicleCode))
  7973. partNos.Add("");
  7974. else
  7975. {
  7976. string partNo = "";
  7977. #region 查询载具上的产品信息
  7978. string cavityData = string.Empty;
  7979. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7980. if (string.IsNullOrEmpty(cavityData))
  7981. cavityData = "";
  7982. if (snResult != 0)
  7983. {
  7984. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7985. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7986. writeToPLC_Flag1.Adress = 2463;
  7987. writeToPLC_Flag1.Value = (short)4;
  7988. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7989. stopwatch1.Stop();
  7990. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7991. return;
  7992. }
  7993. string[] partSNs = cavityData.Split('.');
  7994. if (partSNs != null && partSNs.Length >= 1)
  7995. partNo = partSNs[0];
  7996. #endregion 查询载具上的产品信息
  7997. partNos.Add(partNo);
  7998. }
  7999. }
  8000. // 统一上传 - 调用MES出站
  8001. stopwatch2.Start();
  8002. List<int> results = new List<int>();
  8003. for (int i = 0; i < partNos.Count; i++)
  8004. {
  8005. string index = (i + 1).ToString(); // 弹夹穴号
  8006. if (string.IsNullOrEmpty(partNos[i]))
  8007. results.Add(1);
  8008. else
  8009. {
  8010. List<TestItem> items1 = new List<TestItem>();
  8011. items1.Add(new TestItem()
  8012. {
  8013. Parameter_name = "弹夹码",
  8014. Parameter_value = sn,
  8015. Parameter_unit = ""
  8016. });
  8017. items1.Add(new TestItem()
  8018. {
  8019. Parameter_name = "弹夹穴号",
  8020. Parameter_value = index,
  8021. Parameter_unit = ""
  8022. });
  8023. items1.Add(new TestItem()
  8024. {
  8025. Parameter_name = "载具码",
  8026. Parameter_value = vehicleCodes[i],
  8027. Parameter_unit = ""
  8028. });
  8029. items1.Add(new TestItem()
  8030. {
  8031. Parameter_name = "载具穴号",
  8032. Parameter_value = "1",
  8033. Parameter_unit = ""
  8034. });
  8035. items1.Add(new TestItem()
  8036. {
  8037. Parameter_name = "产品结果",
  8038. Parameter_value = d3Result == 1 ? "OK" : "NG",
  8039. Parameter_unit = ""
  8040. });
  8041. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8042. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8043. results.Add(result1);
  8044. }
  8045. }
  8046. short result = 0;
  8047. if (results.All(a => a == 1))
  8048. result = 1;
  8049. else if (results.Contains(3))
  8050. result = 3;
  8051. else if (results.Contains(2))
  8052. result = 2;
  8053. else if (results.Contains(4))
  8054. result = 4;
  8055. else
  8056. result = 4;
  8057. stopwatch2.Stop();
  8058. // MES_Flag 为4MES报错
  8059. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8060. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8061. writeToPLC_Flag.Name = "d3MES_FLAG";
  8062. writeToPLC_Flag.Adress = 2463;
  8063. writeToPLC_Flag.Value = result;
  8064. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8065. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8066. }
  8067. catch (Exception ex)
  8068. {
  8069. stopwatch2.Restart();
  8070. // MES_Flag 为4上位机报错
  8071. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  8072. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8073. writeToPLC_Flag.Name = "d3MES_FLAG";
  8074. writeToPLC_Flag.Adress = 2463;
  8075. writeToPLC_Flag.Value = (short)4;
  8076. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8077. string str = ex.StackTrace;
  8078. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8079. stopwatch2.Stop();
  8080. }
  8081. stopwatch1.Stop();
  8082. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8083. }
  8084. // 上次采集到的SN
  8085. //private string sn_S4_4进站接口 = string.Empty;
  8086. /// <summary>
  8087. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  8088. /// </summary>
  8089. private void S4_4进站接口(int plcNo, string stationNameStr)
  8090. {
  8091. Stopwatch stopwatch1 = new Stopwatch();
  8092. Stopwatch stopwatch2 = new Stopwatch();
  8093. try
  8094. {
  8095. stopwatch1.Start();
  8096. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8097. sn = sn.Replace("\0", "");
  8098. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8099. #region 查询15个载具码
  8100. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8101. string vehicleData = string.Empty;
  8102. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8103. if (string.IsNullOrEmpty(vehicleData))
  8104. vehicleData = "";
  8105. if (snResult != 0)
  8106. {
  8107. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8108. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8109. writeToPLC_Flag1.Adress = 2463;
  8110. writeToPLC_Flag1.Value = (short)4;
  8111. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8112. stopwatch1.Stop();
  8113. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8114. return;
  8115. }
  8116. string[] cavitySNs = vehicleData.Split('.');
  8117. if (cavitySNs != null && cavitySNs.Length > 0)
  8118. {
  8119. for (int i = 0; i < cavitySNs.Length; i++)
  8120. {
  8121. if (string.IsNullOrEmpty(cavitySNs[i]))
  8122. vehicleCodes.Add("");
  8123. else
  8124. vehicleCodes.Add(cavitySNs[i]);
  8125. }
  8126. }
  8127. #endregion 查询15个载具码
  8128. #region 查询15个产品SN
  8129. List<string> portNos = new List<string>(); // 15个产品SN
  8130. foreach (string vehicleCode in vehicleCodes)
  8131. {
  8132. if (string.IsNullOrEmpty(vehicleCode))
  8133. portNos.Add("");
  8134. else
  8135. {
  8136. // 查询
  8137. string cavityData = string.Empty;
  8138. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8139. if (string.IsNullOrEmpty(cavityData))
  8140. cavityData = "";
  8141. if (snResult1 != 0)
  8142. {
  8143. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8144. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8145. writeToPLC_Flag1.Adress = 2463;
  8146. writeToPLC_Flag1.Value = (short)4;
  8147. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8148. stopwatch1.Stop();
  8149. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8150. return;
  8151. }
  8152. string[] partSNs = cavityData.Split('.');
  8153. if (partSNs != null && partSNs.Length >= 1)
  8154. portNos.Add(partSNs[0]);
  8155. else
  8156. portNos.Add("");
  8157. }
  8158. }
  8159. #endregion 查询15个产品SN
  8160. // 调用MES进站(最多15个)
  8161. stopwatch2.Start();
  8162. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8163. for (int i = 0; i < vehicleCodes.Count; i++)
  8164. {
  8165. // 循环进站
  8166. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8167. {
  8168. // 产品SN(物料码)校验
  8169. string portNo = portNos[i];
  8170. List<TestItem> item = new List<TestItem>();
  8171. item.Add(new TestItem()
  8172. {
  8173. Parameter_name = "弹夹码",
  8174. Parameter_value = sn,
  8175. });
  8176. item.Add(new TestItem()
  8177. {
  8178. Parameter_name = "弹夹穴位",
  8179. Parameter_value = (i + 1).ToString(),
  8180. });
  8181. item.Add(new TestItem()
  8182. {
  8183. Parameter_name = "载具码",
  8184. Parameter_value = vehicleCodes[i],
  8185. });
  8186. item.Add(new TestItem()
  8187. {
  8188. Parameter_name = "载具穴号",
  8189. Parameter_value = "1",
  8190. });
  8191. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8192. }
  8193. }
  8194. stopwatch2.Stop();
  8195. short result = 0;
  8196. bool haveMesWarn = results.Contains(5);
  8197. bool havePCWarn = results.Contains(6);
  8198. if (haveMesWarn)
  8199. result = 2; // 5->2
  8200. else if (havePCWarn)
  8201. result = 6; // 6->4
  8202. else
  8203. result = 1;
  8204. // MES_Flag 为4MES报错
  8205. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8206. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8207. writeToPLC_Flag.Name = "d4MES_FLAG";
  8208. writeToPLC_Flag.Adress = 2496;
  8209. writeToPLC_Flag.Value = result;
  8210. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8211. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8212. }
  8213. catch (Exception ex)
  8214. {
  8215. stopwatch2.Stop();
  8216. // MES_Flag 为4上位机报错
  8217. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8218. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8219. writeToPLC_Flag.Name = "d4MES_FLAG";
  8220. writeToPLC_Flag.Adress = 2496;
  8221. writeToPLC_Flag.Value = (short)4;
  8222. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8223. string str = ex.StackTrace;
  8224. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8225. }
  8226. stopwatch1.Stop();
  8227. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8228. }
  8229. // 上次采集到的SN
  8230. //private string sn_S4_4出站接口 = string.Empty;
  8231. /// <summary>
  8232. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8233. /// </summary>
  8234. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8235. {
  8236. Stopwatch stopwatch1 = new Stopwatch();
  8237. Stopwatch stopwatch2 = new Stopwatch();
  8238. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8239. string stationNameStr = stationCode + stationName;
  8240. string processItem = stationName; // 测试项目
  8241. try
  8242. {
  8243. stopwatch1.Start();
  8244. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8245. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8246. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8247. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8248. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8249. sn = sn.Replace("\0", "");
  8250. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8251. bool isPass = d4Result == 1; // 产品结果 bool
  8252. #region 查询15个载具码
  8253. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8254. string vehicleData = string.Empty;
  8255. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8256. if (string.IsNullOrEmpty(vehicleData))
  8257. vehicleData = "";
  8258. if (snResult1 != 0)
  8259. {
  8260. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8261. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8262. writeToPLC_Flag1.Adress = 2496;
  8263. writeToPLC_Flag1.Value = (short)4;
  8264. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8265. stopwatch1.Stop();
  8266. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8267. return;
  8268. }
  8269. string[] cavitySNs = vehicleData.Split('.');
  8270. if (cavitySNs != null && cavitySNs.Length > 0)
  8271. {
  8272. for (int i = 0; i < cavitySNs.Length; i++)
  8273. {
  8274. if (string.IsNullOrEmpty(cavitySNs[i]))
  8275. vehicleCodes.Add("");
  8276. else
  8277. vehicleCodes.Add(cavitySNs[i]);
  8278. }
  8279. }
  8280. #endregion 查询15个载具码
  8281. // 统一查 产品SN列表
  8282. List<string> partNos = new List<string>();
  8283. foreach (string vehicleCode in vehicleCodes)
  8284. {
  8285. if (string.IsNullOrEmpty(vehicleCode))
  8286. partNos.Add("");
  8287. else
  8288. {
  8289. string partNo = "";
  8290. #region 查询载具上的产品信息
  8291. string cavityData = string.Empty;
  8292. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8293. if (string.IsNullOrEmpty(cavityData))
  8294. cavityData = "";
  8295. if (snResult != 0)
  8296. {
  8297. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8298. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8299. writeToPLC_Flag1.Adress = 2496;
  8300. writeToPLC_Flag1.Value = (short)4;
  8301. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8302. stopwatch1.Stop();
  8303. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8304. return;
  8305. }
  8306. string[] partSNs = cavityData.Split('.');
  8307. if (partSNs != null && partSNs.Length >= 1)
  8308. partNo = partSNs[0];
  8309. #endregion 查询载具上的产品信息
  8310. partNos.Add(partNo);
  8311. }
  8312. }
  8313. // 调用MES出站
  8314. stopwatch2.Start();
  8315. // 统一上传
  8316. List<int> results = new List<int>();
  8317. for (int i = 0; i < partNos.Count; i++)
  8318. {
  8319. string index = (i + 1).ToString(); // 弹夹穴号
  8320. if (string.IsNullOrEmpty(partNos[i]))
  8321. results.Add(1);
  8322. else
  8323. {
  8324. List<TestItem> items1 = new List<TestItem>();
  8325. items1.Add(new TestItem()
  8326. {
  8327. Parameter_name = "弹夹码",
  8328. Parameter_value = sn,
  8329. Parameter_unit = ""
  8330. });
  8331. items1.Add(new TestItem()
  8332. {
  8333. Parameter_name = "弹夹穴号",
  8334. Parameter_value = index,
  8335. Parameter_unit = ""
  8336. });
  8337. items1.Add(new TestItem()
  8338. {
  8339. Parameter_name = "载具码",
  8340. Parameter_value = vehicleCodes[i],
  8341. Parameter_unit = ""
  8342. });
  8343. items1.Add(new TestItem()
  8344. {
  8345. Parameter_name = "载具穴号",
  8346. Parameter_value = "1",
  8347. Parameter_unit = ""
  8348. });
  8349. items1.Add(new TestItem()
  8350. {
  8351. Parameter_name = "产品结果",
  8352. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8353. Parameter_unit = ""
  8354. });
  8355. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8356. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8357. results.Add(result1);
  8358. }
  8359. }
  8360. short result = 0;
  8361. if (results.All(a => a == 1))
  8362. result = 1;
  8363. else if (results.Contains(3))
  8364. result = 3;
  8365. else if (results.Contains(2))
  8366. result = 2;
  8367. else if (results.Contains(4))
  8368. result = 4;
  8369. else
  8370. result = 4;
  8371. stopwatch2.Stop();
  8372. // MES_Flag 为4MES报错
  8373. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8374. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8375. writeToPLC_Flag.Name = "d4MES_FLAG";
  8376. writeToPLC_Flag.Adress = 2496;
  8377. writeToPLC_Flag.Value = result;
  8378. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8379. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8380. }
  8381. catch (Exception ex)
  8382. {
  8383. stopwatch2.Restart();
  8384. // MES_Flag 为4上位机报错
  8385. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8386. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8387. writeToPLC_Flag.Name = "d4MES_FLAG";
  8388. writeToPLC_Flag.Adress = 2496;
  8389. writeToPLC_Flag.Value = (short)4;
  8390. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8391. string str = ex.StackTrace;
  8392. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8393. stopwatch2.Stop();
  8394. }
  8395. stopwatch1.Stop();
  8396. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8397. }
  8398. /// <summary>
  8399. /// [S4] 取放桁架 - S4_5弹夹扫码
  8400. /// </summary>
  8401. /// <param name="plcNo">PLC编号</param>
  8402. /// <param name="stationNameStr">工站全称</param>
  8403. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8404. {
  8405. Stopwatch stopwatch1 = new Stopwatch();
  8406. Stopwatch stopwatch2 = new Stopwatch();
  8407. try
  8408. {
  8409. stopwatch1.Start();
  8410. // ZS 弹夹扫码
  8411. string d5BulletclipCode = " "; // 扫到的码
  8412. short d5BulletclipScanCode = 2;
  8413. stopwatch2.Start();
  8414. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8415. //// MES_Flag
  8416. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8417. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8418. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8419. writeToPLC_Flag.Adress = 2528;
  8420. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8421. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8422. {
  8423. Name = "d5BulletclipCode",
  8424. Adress = 2529,
  8425. ValueType = PLCValueType.String,
  8426. ValueTypeStrLength = 20,
  8427. Value = d5BulletclipCode
  8428. });
  8429. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8430. stopwatch2.Stop();
  8431. }
  8432. catch (Exception ex)
  8433. {
  8434. string str = ex.StackTrace;
  8435. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8436. stopwatch2.Start();
  8437. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8438. //// MES_Flag
  8439. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8440. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8441. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8442. writeToPLC_Flag.Adress = 2528;
  8443. writeToPLC_Flag.Value = (short)6;
  8444. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8445. {
  8446. Name = "d5BulletclipCode",
  8447. Adress = 2529,
  8448. ValueType = PLCValueType.String,
  8449. ValueTypeStrLength = 20,
  8450. Value = " "
  8451. });
  8452. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8453. stopwatch2.Stop();
  8454. }
  8455. stopwatch1.Stop();
  8456. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8457. }
  8458. /// <summary>
  8459. /// [S4] 取放桁架 - S4_5载具扫码
  8460. /// </summary>
  8461. /// <param name="plcNo">PLC编号</param>
  8462. /// <param name="stationNameStr">工站全称</param>
  8463. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8464. {
  8465. Stopwatch stopwatch1 = new Stopwatch();
  8466. Stopwatch stopwatch2 = new Stopwatch();
  8467. try
  8468. {
  8469. stopwatch1.Start();
  8470. // ZS 载具扫码
  8471. string d5VehicleCode = " "; // 扫到的码
  8472. short d5VehicleScanCode = 2;
  8473. #region 进站
  8474. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8475. {
  8476. // 查产品SN
  8477. #region 查询载具上的产品信息
  8478. string cavityData = string.Empty;
  8479. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8480. if (string.IsNullOrEmpty(cavityData))
  8481. cavityData = "";
  8482. if (snResult != 0)
  8483. {
  8484. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8485. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8486. writeToPLC_Flag1.Adress = 2559;
  8487. writeToPLC_Flag1.Value = (short)6;
  8488. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8489. {
  8490. Name = "d5VehicleCode",
  8491. Adress = 2560,
  8492. ValueType = PLCValueType.String,
  8493. ValueTypeStrLength = 20,
  8494. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8495. });
  8496. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8497. stopwatch1.Stop();
  8498. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8499. return;
  8500. }
  8501. string[] cavitySNs = cavityData.Split('.');
  8502. string partNo = "";
  8503. if (cavitySNs != null && cavitySNs.Length >= 1)
  8504. {
  8505. partNo = cavitySNs[0];
  8506. }
  8507. #endregion 查询载具上的产品信息
  8508. List<TestItem> item = new List<TestItem>();
  8509. item.Add(new TestItem()
  8510. {
  8511. Parameter_name = "载具码",
  8512. Parameter_value = d5VehicleCode,
  8513. });
  8514. item.Add(new TestItem()
  8515. {
  8516. Parameter_name = "载具穴号",
  8517. Parameter_value = "1",
  8518. });
  8519. stopwatch2.Start();
  8520. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8521. stopwatch2.Stop();
  8522. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8523. }
  8524. #endregion 进站
  8525. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8526. //// MES_Flag
  8527. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8528. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8529. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8530. writeToPLC_Flag.Adress = 2559;
  8531. writeToPLC_Flag.Value = d5VehicleScanCode;
  8532. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8533. {
  8534. Name = "d5VehicleCode",
  8535. Adress = 2560,
  8536. ValueType = PLCValueType.String,
  8537. ValueTypeStrLength = 20,
  8538. Value = d5VehicleCode
  8539. });
  8540. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8541. }
  8542. catch (Exception ex)
  8543. {
  8544. string str = ex.StackTrace;
  8545. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8546. stopwatch2.Start();
  8547. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8548. //// MES_Flag
  8549. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8550. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8551. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8552. writeToPLC_Flag.Adress = 2559;
  8553. writeToPLC_Flag.Value = (short)6;
  8554. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8555. {
  8556. Name = "d5VehicleCode",
  8557. Adress = 2560,
  8558. ValueType = PLCValueType.String,
  8559. ValueTypeStrLength = 20,
  8560. Value = " "
  8561. });
  8562. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8563. stopwatch2.Stop();
  8564. }
  8565. stopwatch1.Stop();
  8566. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8567. }
  8568. // 上次采集到的SN
  8569. //private string sn_S4_5出站接口 = string.Empty;
  8570. /// <summary>
  8571. /// [S4] 取放桁架 - S4_5出站接口
  8572. /// </summary>
  8573. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8574. {
  8575. Stopwatch stopwatch1 = new Stopwatch();
  8576. Stopwatch stopwatch2 = new Stopwatch();
  8577. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8578. string stationNameStr = stationCode + stationName;
  8579. string processItem = stationName; // 测试项目
  8580. try
  8581. {
  8582. stopwatch1.Start();
  8583. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8584. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8585. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8586. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8587. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8588. sn = sn.Replace("\0", "");
  8589. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8590. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8591. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8592. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8593. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8594. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8595. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8596. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8597. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8598. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8599. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8600. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8601. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8602. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8603. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8604. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8605. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8606. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8607. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8608. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8609. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8610. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8611. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8612. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8613. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8614. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8615. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8616. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8617. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8618. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8619. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8620. bool pass = d5Result == 1;
  8621. // 存 载具SN列表
  8622. List<string> vehicleCodes = new List<string>()
  8623. {
  8624. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8625. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8626. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8627. };
  8628. // 统一查 产品SN列表
  8629. List<string> partNos = new List<string>();
  8630. foreach (string vehicleCode in vehicleCodes)
  8631. {
  8632. if (string.IsNullOrEmpty(vehicleCode))
  8633. partNos.Add("");
  8634. else
  8635. {
  8636. string partNo = "";
  8637. #region 查询载具上的产品信息
  8638. string cavityData = string.Empty;
  8639. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8640. if (string.IsNullOrEmpty(cavityData))
  8641. cavityData = "";
  8642. if (snResult != 0)
  8643. {
  8644. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8645. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8646. writeToPLC_Flag1.Adress = 2591;
  8647. writeToPLC_Flag1.Value = (short)4;
  8648. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8649. stopwatch1.Stop();
  8650. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8651. return;
  8652. }
  8653. string[] cavitySNs = cavityData.Split('.');
  8654. if (cavitySNs != null && cavitySNs.Length >= 1)
  8655. partNo = cavitySNs[0];
  8656. #endregion 查询载具上的产品信息
  8657. partNos.Add(partNo);
  8658. }
  8659. }
  8660. // 统一上传
  8661. stopwatch2.Start();
  8662. List<int> results = new List<int>();
  8663. for (int i = 0; i < partNos.Count; i++)
  8664. {
  8665. string index = (i + 1).ToString(); // 弹夹穴号
  8666. if (string.IsNullOrEmpty(partNos[i]))
  8667. results.Add(1);
  8668. else
  8669. {
  8670. List<TestItem> items1 = new List<TestItem>();
  8671. items1.Add(new TestItem()
  8672. {
  8673. Parameter_name = "弹夹码",
  8674. Parameter_value = sn,
  8675. Parameter_unit = ""
  8676. });
  8677. items1.Add(new TestItem()
  8678. {
  8679. Parameter_name = "弹夹穴号",
  8680. Parameter_value = index,
  8681. Parameter_unit = ""
  8682. });
  8683. items1.Add(new TestItem()
  8684. {
  8685. Parameter_name = "载具码",
  8686. Parameter_value = vehicleCodes[i],
  8687. Parameter_unit = ""
  8688. });
  8689. items1.Add(new TestItem()
  8690. {
  8691. Parameter_name = "载具穴号",
  8692. Parameter_value = "1",
  8693. Parameter_unit = ""
  8694. });
  8695. items1.Add(new TestItem()
  8696. {
  8697. Parameter_name = "产品结果",
  8698. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8699. Parameter_unit = ""
  8700. });
  8701. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8702. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8703. results.Add(result1);
  8704. }
  8705. }
  8706. short result = 0;
  8707. if (results.All(a => a == 1))
  8708. result = 1;
  8709. else if (results.Contains(3))
  8710. result = 3;
  8711. else if (results.Contains(2))
  8712. result = 2;
  8713. else if (results.Contains(4))
  8714. result = 4;
  8715. else
  8716. result = 4;
  8717. stopwatch2.Stop();
  8718. #region 存储绑定数据到 边线MES系统中
  8719. if (result == 1)
  8720. {
  8721. // 删除绑定信息
  8722. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8723. if (resultMesR != 0)
  8724. {
  8725. result = 4;
  8726. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8727. }
  8728. }
  8729. #endregion 存储绑定数据到 边线MES系统中
  8730. // MES_Flag 为4MES报错
  8731. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8732. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8733. writeToPLC_Flag.Name = "d5MES_FLAG";
  8734. writeToPLC_Flag.Adress = 2591;
  8735. writeToPLC_Flag.Value = result;
  8736. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8737. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8738. }
  8739. catch (Exception ex)
  8740. {
  8741. stopwatch2.Restart();
  8742. // MES_Flag 为4上位机报错
  8743. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8744. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8745. writeToPLC_Flag.Name = "d5MES_FLAG";
  8746. writeToPLC_Flag.Adress = 2591;
  8747. writeToPLC_Flag.Value = (short)4;
  8748. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8749. stopwatch2.Stop();
  8750. string str = ex.StackTrace;
  8751. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8752. }
  8753. stopwatch1.Stop();
  8754. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8755. }
  8756. /// <summary>
  8757. /// [S4] 取放桁架 - S4_5节拍接口
  8758. /// </summary>
  8759. /// <param name="plcNo">PLC编号</param>
  8760. /// <param name="stationNameStr">工站全称</param>
  8761. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8762. {
  8763. Stopwatch stopwatch1 = new Stopwatch();
  8764. Stopwatch stopwatch2 = new Stopwatch();
  8765. string resultStr = string.Empty;
  8766. try
  8767. {
  8768. stopwatch1.Start();
  8769. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8770. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8771. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8772. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8773. if (!actionBool)
  8774. {
  8775. stopwatch2.Start();
  8776. // MES_Flag
  8777. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8778. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8779. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8780. writeToPLC_Flag1.Adress = 2924;
  8781. writeToPLC_Flag1.Value = (short)4;
  8782. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8783. stopwatch2.Stop();
  8784. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8785. return;
  8786. }
  8787. string d5OEEPartNo = string.Empty; // 物料码
  8788. if (string.IsNullOrEmpty(d5OEEProductSN))
  8789. {
  8790. stopwatch2.Start();
  8791. // MES_Flag
  8792. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8793. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8794. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8795. writeToPLC_Flag1.Adress = 2924;
  8796. writeToPLC_Flag1.Value = (short)1;
  8797. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8798. stopwatch2.Stop();
  8799. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8800. return;
  8801. }
  8802. else
  8803. { // 查产品SN
  8804. d5OEEPartNo = "Test"; // ZS
  8805. }
  8806. short d5OEEMES_FLAG = 0;
  8807. // 上传OEE
  8808. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8809. d5OEEMES_FLAG = result.Item1;
  8810. resultStr = result.Item2;
  8811. stopwatch2.Start();
  8812. // MES_Flag
  8813. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8814. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8815. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8816. writeToPLC_Flag.Adress = 2924;
  8817. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8818. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8819. stopwatch2.Stop();
  8820. }
  8821. catch (Exception ex)
  8822. {
  8823. string str = ex.StackTrace;
  8824. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8825. // MES_Flag
  8826. stopwatch2.Start();
  8827. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8828. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8829. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8830. writeToPLC_Flag.Adress = 2924;
  8831. writeToPLC_Flag.Value = (short)4;
  8832. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8833. stopwatch2.Stop();
  8834. }
  8835. stopwatch1.Stop();
  8836. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8837. }
  8838. #endregion [S4] 取放桁架
  8839. #endregion PLC4 刘果段
  8840. #region PLC5 张超凡
  8841. #region [S5] Tray盘下料装备
  8842. /// <summary>
  8843. /// S5工位的数据- 触发信号上次的值
  8844. /// </summary>
  8845. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8846. /// <summary>
  8847. /// S5工位的数据(含触发信号)
  8848. /// </summary>
  8849. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8850. /// <summary>
  8851. /// S5工位的数据- 回写点位
  8852. /// </summary>
  8853. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8854. /// <summary>
  8855. /// [S5] Tray盘下料装备
  8856. /// </summary>
  8857. /// <param name="plcNo">PLC编号</param>
  8858. //private void ReadStation_S5(int plcNo)
  8859. //{
  8860. // // [S1] Tray盘上料装备
  8861. // // [S2] FCT
  8862. // // [S3] 值板机
  8863. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8864. // // [S5] Tray盘下料装备
  8865. // /// 上位机心跳
  8866. // /// 获取设备报警数据与状态信息
  8867. // string stationCode = "[S5]";
  8868. // string stationName = "Tray盘下料装备";
  8869. // string stationNameStr = stationCode + stationName;
  8870. // #region 创建字典
  8871. // // 触发信号字典 赋值
  8872. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8873. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8874. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8875. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8876. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8877. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8878. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8879. // // PLC数据字典 赋值
  8880. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8881. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8882. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8883. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8884. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8885. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8886. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8887. // s5PLCData.Add("e1Result", 0); // 产品结果
  8888. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8889. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8890. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8891. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8892. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8893. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8894. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8895. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8896. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8897. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8898. // #endregion 创建字典
  8899. // while (IsRun)
  8900. // {
  8901. // try
  8902. // {
  8903. // if (!GlobalContext._IsCon_Funs5)
  8904. // {
  8905. // UpdatePLCMonitor(1, plcNo, 0);
  8906. // continue;
  8907. // }
  8908. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8909. // {
  8910. // Stopwatch stopwatch1 = new Stopwatch();
  8911. // Stopwatch stopwatch2 = new Stopwatch();
  8912. // stopwatch1.Start();
  8913. // stopwatch2.Start();
  8914. // #region 一次性读取所有数据
  8915. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8916. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8917. // int[] datas = data1.Concat(data2).ToArray();
  8918. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8919. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8920. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8921. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8922. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8923. // s5PLCData["e1MES_FLAG"] = datas[35];
  8924. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8925. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8926. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8927. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8928. // s5PLCData["e1Result"] = datas[76];
  8929. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8930. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8931. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8932. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8933. // s5PLCData["e1OEEType"] = datas[109];
  8934. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8935. // s5PLCData["e1AGVUpStart"] = datas[121];
  8936. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8937. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8938. // s5PLCData["e1AGVDownStart"] = datas[134];
  8939. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8940. // #endregion 一次性读取所有数据
  8941. // stopwatch2.Stop();
  8942. // #region 回写操作,写后清空flag
  8943. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8944. // #endregion 回写操作,写后清空flag
  8945. // #region 进站校验
  8946. // try
  8947. // {
  8948. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8949. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8950. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  8951. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  8952. // {
  8953. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  8954. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8955. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  8956. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8957. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  8958. // }
  8959. // }
  8960. // catch (Exception ex)
  8961. // {
  8962. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8963. // string str = ex.StackTrace;
  8964. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8965. // }
  8966. // #endregion 进站校验
  8967. // #region 出站接口
  8968. // try
  8969. // {
  8970. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  8971. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  8972. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  8973. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  8974. // {
  8975. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  8976. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8977. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  8978. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  8979. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  8980. // }
  8981. // }
  8982. // catch (Exception ex)
  8983. // {
  8984. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  8985. // string str = ex.StackTrace;
  8986. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8987. // }
  8988. // #endregion 出站接口
  8989. // #region 节拍接口
  8990. // try
  8991. // {
  8992. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  8993. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  8994. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  8995. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  8996. // {
  8997. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  8998. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8999. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  9000. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  9001. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  9002. // }
  9003. // }
  9004. // catch (Exception ex)
  9005. // {
  9006. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9007. // string str = ex.StackTrace;
  9008. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9009. // }
  9010. // #endregion 节拍接口
  9011. // #region AGV上料
  9012. // // AGV上料叫AGV信号
  9013. // try
  9014. // {
  9015. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  9016. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  9017. // if (e1AGVUpCall != e1AGVUpCallOld)
  9018. // {
  9019. // if (e1AGVUpCall == 1) // 0->1
  9020. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  9021. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  9022. // }
  9023. // }
  9024. // catch (Exception ex)
  9025. // {
  9026. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9027. // string str = ex.StackTrace;
  9028. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9029. // }
  9030. // // AGV上料完成信号
  9031. // try
  9032. // {
  9033. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  9034. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  9035. // if (e1AGVUpEnd != e1AGVUpEndOld)
  9036. // {
  9037. // if (e1AGVUpEnd == 1) // 0->1
  9038. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  9039. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  9040. // }
  9041. // }
  9042. // catch (Exception ex)
  9043. // {
  9044. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9045. // string str = ex.StackTrace;
  9046. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9047. // }
  9048. // #endregion AGV上料
  9049. // #region AGV下料
  9050. // // AGV下料叫agv信号
  9051. // try
  9052. // {
  9053. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  9054. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  9055. // if (e1AGVDownCall != e1AGVDownCallOld)
  9056. // {
  9057. // if (e1AGVDownCall == 1) // 0->1
  9058. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  9059. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  9060. // }
  9061. // }
  9062. // catch (Exception ex)
  9063. // {
  9064. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9065. // string str = ex.StackTrace;
  9066. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9067. // }
  9068. // // AGV下料完成信号
  9069. // try
  9070. // {
  9071. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  9072. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  9073. // if (e1AGVDownEnd != e1AGVDownEndOld)
  9074. // {
  9075. // if (e1AGVDownEnd == 1) // 0->1
  9076. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  9077. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  9078. // }
  9079. // }
  9080. // catch (Exception ex)
  9081. // {
  9082. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9083. // string str = ex.StackTrace;
  9084. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9085. // }
  9086. // #endregion AGV下料
  9087. // #region 心跳
  9088. // try
  9089. // {
  9090. // short states = 0;
  9091. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9092. // }
  9093. // catch (Exception ex)
  9094. // {
  9095. // string str = ex.StackTrace;
  9096. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9097. // }
  9098. // #endregion 心跳
  9099. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9100. // stopwatch1.Stop();
  9101. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9102. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9103. // }
  9104. // else
  9105. // {
  9106. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9107. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9108. // Funs[plcNo].Connect();
  9109. // }
  9110. // }
  9111. // catch (Exception ex)
  9112. // {
  9113. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9114. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9115. // Funs[plcNo].ReConnect();
  9116. // }
  9117. // Thread.Sleep(IntervalReadPLC);
  9118. // }
  9119. //}
  9120. /// <summary>
  9121. /// [S5] Tray盘下料装备 - 进站校验
  9122. /// </summary>
  9123. /// <param name="plcNo">PLC编号</param>
  9124. /// <param name="stationNameStr">工站全称</param>
  9125. private void S5进站校验(int plcNo, string stationNameStr)
  9126. {
  9127. Stopwatch stopwatch1 = new Stopwatch();
  9128. Stopwatch stopwatch2 = new Stopwatch();
  9129. try
  9130. {
  9131. stopwatch1.Start();
  9132. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9133. sn = sn.Replace("\0", "");
  9134. // 获取产品SN By 载具码
  9135. #region 查询载具上的产品信息
  9136. string cavityData = string.Empty;
  9137. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9138. if (string.IsNullOrEmpty(cavityData))
  9139. cavityData = "";
  9140. if (snResult != 0)
  9141. {
  9142. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9143. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9144. writeToPLC_Flag1.Adress = 2003;
  9145. writeToPLC_Flag1.Value = (short)6;
  9146. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9147. stopwatch1.Stop();
  9148. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9149. return;
  9150. }
  9151. string[] cavitySNs = cavityData.Split('.');
  9152. string partNo = string.Empty;
  9153. if (cavitySNs != null && cavitySNs.Length >= 1)
  9154. partNo = cavitySNs[0];
  9155. #endregion 查询载具上的产品信息
  9156. // 产品SN(物料码)校验
  9157. List<TestItem> item = new List<TestItem>();
  9158. item.Add(new TestItem()
  9159. {
  9160. Parameter_name = "载具码",
  9161. Parameter_value = sn,
  9162. });
  9163. item.Add(new TestItem()
  9164. {
  9165. Parameter_name = "载具穴号",
  9166. Parameter_value = "1",
  9167. });
  9168. stopwatch2.Start();
  9169. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9170. stopwatch2.Stop();
  9171. short e1MES_FLAG_Check = (short)result;
  9172. // MES_Flag
  9173. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9174. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9175. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9176. writeToPLC_Flag.Adress = 2003;
  9177. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9178. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9179. }
  9180. catch (Exception ex)
  9181. {
  9182. string str = ex.StackTrace;
  9183. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9184. // MES_Flag
  9185. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9186. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9187. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9188. writeToPLC_Flag.Adress = 2003;
  9189. writeToPLC_Flag.Value = (short)6;
  9190. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9191. }
  9192. stopwatch1.Stop();
  9193. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9194. }
  9195. /// <summary>
  9196. /// [S5] Tray盘下料装备 - 出站接口
  9197. /// </summary>
  9198. /// <param name="plcNo"></param>
  9199. /// <param name="stationCode"></param>
  9200. /// <param name="stationName"></param>
  9201. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9202. {
  9203. Stopwatch stopwatch1 = new Stopwatch();
  9204. Stopwatch stopwatch2 = new Stopwatch();
  9205. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9206. string stationNameStr = stationCode + stationName;
  9207. string processItem = stationName; // 测试项目
  9208. try
  9209. {
  9210. stopwatch1.Start();
  9211. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9212. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9213. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9214. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9215. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9216. sn = sn.Replace("\0", "");
  9217. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9218. //partNo = partNo.Replace("\0", "");
  9219. #region 查询载具上的产品信息
  9220. string cavityData = string.Empty;
  9221. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9222. if (string.IsNullOrEmpty(cavityData))
  9223. cavityData = "";
  9224. if (snResult != 0)
  9225. {
  9226. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9227. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9228. writeToPLC_Flag1.Adress = 2035;
  9229. writeToPLC_Flag1.Value = (short)4;
  9230. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9231. stopwatch1.Stop();
  9232. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9233. return;
  9234. }
  9235. string[] cavitySNs = cavityData.Split('.');
  9236. string partNo = string.Empty;
  9237. if (cavitySNs != null && cavitySNs.Length >= 1)
  9238. partNo = cavitySNs[0];
  9239. #endregion 查询载具上的产品信息
  9240. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9241. bool pass = e1Result == 1;
  9242. stopwatch2.Start();
  9243. // 上传MES
  9244. List<TestItem> items = new List<TestItem>();
  9245. items.Add(new TestItem()
  9246. {
  9247. Parameter_name = "载具码",
  9248. Parameter_value = sn,
  9249. Parameter_unit = ""
  9250. });
  9251. items.Add(new TestItem()
  9252. {
  9253. Parameter_name = "载具穴号",
  9254. Parameter_value = "1",
  9255. Parameter_unit = ""
  9256. });
  9257. items.Add(new TestItem()
  9258. {
  9259. Parameter_name = "产品结果",
  9260. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9261. Parameter_unit = ""
  9262. });
  9263. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  9264. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9265. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9266. short result = result1 == 1 ? (short)1 : (short)3;
  9267. stopwatch2.Stop();
  9268. #region 存储绑定数据到 边线MES系统中
  9269. if (result == 1)
  9270. {
  9271. // 删除绑定信息
  9272. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9273. if (resultMesR != 0)
  9274. {
  9275. result = 4;
  9276. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9277. }
  9278. }
  9279. #endregion 存储绑定数据到 边线MES系统中
  9280. // MES_Flag 为MES报错
  9281. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9282. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9283. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9284. writeToPLC_Flag.Name = "e1MES_FLAG";
  9285. writeToPLC_Flag.Adress = 2035;
  9286. writeToPLC_Flag.Value = result;
  9287. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9288. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9289. }
  9290. catch (Exception ex)
  9291. {
  9292. stopwatch2.Restart();
  9293. // MES_Flag 为4上位机报错
  9294. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9295. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9296. writeToPLC_Flag.Name = "e1MES_FLAG";
  9297. writeToPLC_Flag.Adress = 2035;
  9298. writeToPLC_Flag.Value = (short)4;
  9299. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9300. stopwatch2.Stop();
  9301. string str = ex.StackTrace;
  9302. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9303. }
  9304. stopwatch1.Stop();
  9305. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9306. }
  9307. /// <summary>
  9308. /// [S5] Tray盘下料装备 - 节拍接口
  9309. /// </summary>
  9310. /// <param name="plcNo">PLC编号</param>
  9311. /// <param name="stationNameStr">工站全称</param>
  9312. private void S5节拍接口(int plcNo, string stationNameStr)
  9313. {
  9314. Stopwatch stopwatch1 = new Stopwatch();
  9315. Stopwatch stopwatch2 = new Stopwatch();
  9316. string resultStr = string.Empty;
  9317. try
  9318. {
  9319. stopwatch1.Start();
  9320. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9321. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9322. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9323. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9324. if (!actionBool)
  9325. {
  9326. stopwatch2.Start();
  9327. // MES_Flag
  9328. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9329. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9330. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9331. writeToPLC_Flag1.Adress = 2088;
  9332. writeToPLC_Flag1.Value = (short)4;
  9333. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9334. stopwatch2.Stop();
  9335. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9336. return;
  9337. }
  9338. string e1OEEPartNo = string.Empty; // 物料码
  9339. if (string.IsNullOrEmpty(e1OEEProductSN))
  9340. {
  9341. stopwatch2.Start();
  9342. // MES_Flag
  9343. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9344. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9345. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9346. writeToPLC_Flag1.Adress = 2088;
  9347. writeToPLC_Flag1.Value = (short)1;
  9348. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9349. stopwatch2.Stop();
  9350. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9351. return;
  9352. }
  9353. else
  9354. { // 查产品SN
  9355. e1OEEPartNo = "Test"; // ZS
  9356. }
  9357. short e1OEEMES_FLAG = 0;
  9358. // 上传OEE
  9359. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9360. e1OEEMES_FLAG = result.Item1;
  9361. resultStr = result.Item2;
  9362. stopwatch2.Start();
  9363. // MES_Flag
  9364. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9365. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9366. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9367. writeToPLC_Flag.Adress = 2088;
  9368. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9369. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9370. stopwatch2.Stop();
  9371. }
  9372. catch (Exception ex)
  9373. {
  9374. string str = ex.StackTrace;
  9375. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9376. // MES_Flag
  9377. stopwatch2.Start();
  9378. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9379. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9380. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9381. writeToPLC_Flag.Adress = 2088;
  9382. writeToPLC_Flag.Value = (short)4;
  9383. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9384. stopwatch2.Stop();
  9385. }
  9386. stopwatch1.Stop();
  9387. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9388. }
  9389. /// <summary>
  9390. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9391. /// </summary>
  9392. /// <param name="plcNo">PLC编号</param>
  9393. /// <param name="stationNameStr">工站全称</param>
  9394. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9395. {
  9396. Stopwatch stopwatch1 = new Stopwatch();
  9397. Stopwatch stopwatch2 = new Stopwatch();
  9398. try
  9399. {
  9400. stopwatch1.Start();
  9401. // ZS 呼叫AGV
  9402. short e1AGVUpCall = 2;
  9403. stopwatch2.Start();
  9404. // e1AGVUpCall
  9405. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9406. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9407. writeToPLC_Flag.Name = "e1AGVUpCall";
  9408. writeToPLC_Flag.Adress = 2120;
  9409. writeToPLC_Flag.Value = e1AGVUpCall;
  9410. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", 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} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9417. // e1AGVUpCall
  9418. stopwatch2.Start();
  9419. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9420. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9421. writeToPLC_Flag.Name = "e1AGVUpCall";
  9422. writeToPLC_Flag.Adress = 2120;
  9423. writeToPLC_Flag.Value = (short)4;
  9424. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9425. stopwatch2.Stop();
  9426. }
  9427. stopwatch1.Stop();
  9428. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9429. }
  9430. /// <summary>
  9431. /// [S5] Tray盘下料装备 - AGV上料完成
  9432. /// </summary>
  9433. /// <param name="plcNo">PLC编号</param>
  9434. /// <param name="stationNameStr">工站全称</param>
  9435. private void S5AGV上料完成(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 e1AGVUpEnd = 2;
  9444. stopwatch2.Start();
  9445. // e1AGVUpEnd
  9446. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9447. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9448. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9449. writeToPLC_Flag.Adress = 2122;
  9450. writeToPLC_Flag.Value = e1AGVUpEnd;
  9451. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", 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上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9458. // e1AGVUpEnd
  9459. stopwatch2.Start();
  9460. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9461. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9462. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9463. writeToPLC_Flag.Adress = 2122;
  9464. writeToPLC_Flag.Value = (short)4;
  9465. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9466. stopwatch2.Stop();
  9467. }
  9468. stopwatch1.Stop();
  9469. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9470. }
  9471. /// <summary>
  9472. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9473. /// </summary>
  9474. /// <param name="plcNo">PLC编号</param>
  9475. /// <param name="stationNameStr">工站全称</param>
  9476. private void S5AGV下料叫agv(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 e1AGVDownCall = 2;
  9485. stopwatch2.Start();
  9486. // e1AGVDownCall
  9487. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9488. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9489. writeToPLC_Flag.Name = "e1AGVDownCall";
  9490. writeToPLC_Flag.Adress = 2133;
  9491. writeToPLC_Flag.Value = e1AGVDownCall;
  9492. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", 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下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9499. // e1AGVDownCall
  9500. stopwatch2.Start();
  9501. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9502. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9503. writeToPLC_Flag.Name = "e1AGVDownCall";
  9504. writeToPLC_Flag.Adress = 2133;
  9505. writeToPLC_Flag.Value = (short)4;
  9506. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9507. stopwatch2.Stop();
  9508. }
  9509. stopwatch1.Stop();
  9510. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9511. }
  9512. /// <summary>
  9513. /// [S5] Tray盘下料装备 - AGV下料完成
  9514. /// </summary>
  9515. /// <param name="plcNo">PLC编号</param>
  9516. /// <param name="stationNameStr">工站全称</param>
  9517. private void S5AGV下料完成(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 e1AGVDownEnd = 2;
  9526. stopwatch2.Start();
  9527. // e1AGVDownEnd
  9528. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9529. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9530. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9531. writeToPLC_Flag.Adress = 2135;
  9532. writeToPLC_Flag.Value = e1AGVDownEnd;
  9533. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", 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下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9540. // e1AGVDownEnd
  9541. stopwatch2.Start();
  9542. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9543. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9544. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9545. writeToPLC_Flag.Adress = 2135;
  9546. writeToPLC_Flag.Value = (short)4;
  9547. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9548. stopwatch2.Stop();
  9549. }
  9550. stopwatch1.Stop();
  9551. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9552. }
  9553. #endregion [S5] Tray盘下料装备
  9554. #endregion PLC5 张超凡
  9555. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9556. /// <summary>
  9557. /// PLC读取到的数据 -添加数据
  9558. /// </summary>
  9559. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9560. {
  9561. if (sxPlcData.ContainsKey(newKey))
  9562. sxPlcData[newKey] = newValue;
  9563. else
  9564. sxPlcData.Add(newKey, newValue);
  9565. }
  9566. /// <summary>
  9567. /// PLC需要写入的数据 -添加数据
  9568. /// </summary>
  9569. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9570. {
  9571. if (sxPLCWriteData.ContainsKey(newKey))
  9572. sxPLCWriteData[newKey] = newValue;
  9573. else
  9574. sxPLCWriteData.Add(newKey, newValue);
  9575. }
  9576. /// <summary>
  9577. /// PLC回写操作,写后清空flag
  9578. /// </summary>
  9579. /// <param name="modbusClient">modbus对象</param>
  9580. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9581. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9582. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9583. {
  9584. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9585. {
  9586. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9587. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9588. {
  9589. string mesFlagName = pLCWriteDatas[i].Name;
  9590. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9591. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9592. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9593. {
  9594. // 先回写数据
  9595. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9596. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9597. {
  9598. int mesDataAdress = writeToPLCDatas[j].Adress;
  9599. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9600. switch (mesDataType)
  9601. {
  9602. case PLCValueType.Short:
  9603. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9604. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9605. break;
  9606. case PLCValueType.String:
  9607. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9608. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9609. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9610. break;
  9611. }
  9612. }
  9613. // 再回写信号
  9614. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9615. // 存储读取数据的字典
  9616. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9617. // 存储写入数据的字典 - 清空写入值
  9618. pLCWriteDatas[i].Value = (short)0;
  9619. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9620. }
  9621. }
  9622. }
  9623. }
  9624. /// <summary>
  9625. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9626. /// </summary>
  9627. /// <param name="no">3</param>
  9628. /// <param name="stationCode">设备编号</param>
  9629. /// <param name="stationNameStr">设备名称</param>
  9630. /// <param name="plcOrder">车间订单号</param>
  9631. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9632. {
  9633. try
  9634. {
  9635. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9636. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9637. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9638. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9639. int result1 = 0;
  9640. switch (stationCode)
  9641. {
  9642. case 2:
  9643. case 3:
  9644. case 4:
  9645. case 6:
  9646. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9647. break;
  9648. case 102:
  9649. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9650. break;
  9651. case 103:
  9652. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9653. break;
  9654. case 104:
  9655. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9656. break;
  9657. case 106:
  9658. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9659. break;
  9660. default:
  9661. // MES_Flag 为“6未找到正确设备编号”
  9662. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9663. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9664. return;
  9665. }
  9666. short result = result1 == 1 ? (short)1 : (short)2;
  9667. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9668. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9669. }
  9670. catch (Exception ex)
  9671. {
  9672. // MES_Flag 为2上位机报错
  9673. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9674. string str = ex.StackTrace;
  9675. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9676. }
  9677. }
  9678. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9679. #region UI刷新
  9680. /// <summary>
  9681. /// 更新商品信息的UI + 下发产品信息(SN)
  9682. /// </summary>
  9683. private void UpdateProductInfo()
  9684. {
  9685. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9686. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9687. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9688. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9689. }
  9690. /// <summary>
  9691. /// 更新PLC连接状态的UI
  9692. /// </summary>
  9693. /// <param name="no">PLC编号</param>
  9694. /// <param name="status">状态</param>
  9695. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9696. {
  9697. if (this != null && !this.IsDisposed)
  9698. {
  9699. switch (imgNo)
  9700. {
  9701. case 1:
  9702. this.BeginInvoke(new Action(() =>
  9703. {
  9704. picPLC.Image = imageListState.Images[status];
  9705. }));
  9706. break;
  9707. case 2:
  9708. this.BeginInvoke(new Action(() =>
  9709. {
  9710. pictureBox2.Image = imageListState.Images[status];
  9711. }));
  9712. break;
  9713. case 3:
  9714. this.BeginInvoke(new Action(() =>
  9715. {
  9716. pictureBox3.Image = imageListState.Images[status];
  9717. }));
  9718. break;
  9719. case 4:
  9720. this.BeginInvoke(new Action(() =>
  9721. {
  9722. pictureBox4.Image = imageListState.Images[status];
  9723. }));
  9724. break;
  9725. case 5:
  9726. this.BeginInvoke(new Action(() =>
  9727. {
  9728. pictureBox5.Image = imageListState.Images[status];
  9729. }));
  9730. break;
  9731. case 6:
  9732. this.BeginInvoke(new Action(() =>
  9733. {
  9734. pictureBox6.Image = imageListState.Images[status];
  9735. }));
  9736. break;
  9737. case 7:
  9738. this.BeginInvoke(new Action(() =>
  9739. {
  9740. pictureBox7.Image = imageListState.Images[status];
  9741. }));
  9742. break;
  9743. case 8:
  9744. this.BeginInvoke(new Action(() =>
  9745. {
  9746. pictureBox8.Image = imageListState.Images[status];
  9747. }));
  9748. break;
  9749. default:
  9750. break;
  9751. }
  9752. }
  9753. Task.Run(() => // 更新PLC交互页的指示灯
  9754. {
  9755. try
  9756. {
  9757. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9758. {
  9759. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9760. }
  9761. }
  9762. catch { }
  9763. });
  9764. }
  9765. #endregion UI刷新
  9766. #region 日志
  9767. /// <summary>
  9768. /// 添加各工位运行日志(同步至PLC交互页面)
  9769. /// </summary>
  9770. /// <param name="stationNameStr">工站名称</param>
  9771. /// <param name="logType">日志类型</param>
  9772. /// <param name="message">日志内容</param>
  9773. /// <param name="snNumber">产品数字SN</param>
  9774. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9775. {
  9776. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9777. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9778. ))
  9779. {
  9780. AddMessage(logType, message); // 首页展示+日志记录
  9781. }
  9782. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9783. {
  9784. StationName = stationNameStr,
  9785. SnNumber = snNumber,
  9786. Message = message,
  9787. CreateTime = DateTime.Now
  9788. };
  9789. // PLC交互页展示
  9790. Task.Run(() =>
  9791. {
  9792. try
  9793. {
  9794. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9795. {
  9796. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9797. }
  9798. }
  9799. catch { }
  9800. });
  9801. }
  9802. /// <summary>
  9803. /// 添加运行日志
  9804. /// </summary>
  9805. /// <param name="logType">日志类型</param>
  9806. /// <param name="message">日志内容</param>
  9807. public void AddMessage(LogType logType, string message)
  9808. {
  9809. OnMessage(logType, message);
  9810. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9811. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9812. string msgShow = time + "--> " + message + "\r\n";
  9813. this.BeginInvoke(new Action(() =>
  9814. {
  9815. systemLog.Rows.Insert(0, date, time, message);
  9816. if (systemLog.Rows.Count >= 100)
  9817. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9818. }));
  9819. }
  9820. /// <summary>
  9821. /// 添加运行日志-保存
  9822. /// </summary>
  9823. /// <param name="logType">日志类型</param>
  9824. /// <param name="message">日志内容</param>
  9825. private void OnMessage(LogType logType, string msg)
  9826. {
  9827. MessageEvent?.Invoke(logType, msg);
  9828. }
  9829. /// <summary>
  9830. /// 保存PLC写入日志
  9831. /// </summary>
  9832. /// <param name="logType"></param>
  9833. /// <param name="logValue"></param>
  9834. private void WritePLCLog(LogType logType, string logValue)
  9835. {
  9836. switch ((int)logType)
  9837. {
  9838. case 0:
  9839. _PLCLogNet.WriteDebug(logValue);
  9840. break;
  9841. case 1:
  9842. _PLCLogNet.WriteInfo(logValue);
  9843. break;
  9844. case 2:
  9845. _PLCLogNet.WriteWarn(logValue);
  9846. break;
  9847. case 3:
  9848. _PLCLogNet.WriteError(logValue);
  9849. break;
  9850. default:
  9851. _PLCLogNet.WriteFatal(logValue);
  9852. break;
  9853. }
  9854. }
  9855. /// <summary>
  9856. /// IOT Mqtt回调方法- With DataId
  9857. /// </summary>
  9858. /// <param name="id"></param>
  9859. /// <param name="v"></param>
  9860. /// <param name="dataId"></param>
  9861. public void CallbackWithDataId(string id, string msg, string dataId)
  9862. {
  9863. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9864. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9865. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9866. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9867. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9868. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9869. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9870. }
  9871. /// <summary>
  9872. /// AGV Mqtt回调方法- 记录Log并处理数据
  9873. /// </summary>
  9874. /// <param name="obj"></param>
  9875. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9876. {
  9877. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9878. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9879. // 接收到的信息
  9880. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9881. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9882. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9883. {
  9884. }
  9885. }
  9886. #endregion 日志
  9887. /// <summary>
  9888. /// 实例化报警字典
  9889. /// </summary>
  9890. private void InitalDicAlarm()
  9891. {
  9892. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9893. List<Alarm> keyValues1 = new List<Alarm>
  9894. {
  9895. #region 第一组报警(电机)
  9896. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9897. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9898. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9899. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9900. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9901. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9902. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9903. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9904. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9905. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9906. #endregion 第一组报警(电机)
  9907. #region 第二组报警(气缸)
  9908. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9909. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9910. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9911. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9912. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9913. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9914. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9915. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9916. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9917. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9918. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9919. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9920. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9921. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9922. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9923. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9924. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9925. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9926. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9927. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9928. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9929. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9930. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9931. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9932. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9933. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9934. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9935. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9936. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9937. #endregion 第二组报警(气缸)
  9938. #region 第三组报警(其他故障)
  9939. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9940. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9941. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9942. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9943. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9944. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9945. #endregion 第三组报警(其他故障)
  9946. };
  9947. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9948. #endregion 第一个工站(这里使用线体代替工位)
  9949. # region 第二个工站-原来的写法(废弃)
  9950. //keyValues = new Dictionary<int, AlarmData[]>();
  9951. ////1
  9952. //dicAlarmName = new Dictionary<int, Alarm>();
  9953. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  9954. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  9955. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  9956. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  9957. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  9958. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9959. //for (int i = 0; i < dicAlarmName.Count; i++)
  9960. //{
  9961. // alarmDatas[i] = new AlarmData();
  9962. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9963. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9964. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9965. // alarmDatas[i].AlarmType = 1;
  9966. //}
  9967. //keyValues.Add(1, alarmDatas);
  9968. ////2
  9969. //dicAlarmName = new Dictionary<int, Alarm>();
  9970. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  9971. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  9972. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  9973. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  9974. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  9975. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  9976. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  9977. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  9978. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9979. //for (int i = 0; i < dicAlarmName.Count; i++)
  9980. //{
  9981. // alarmDatas[i] = new AlarmData();
  9982. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9983. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9984. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9985. // alarmDatas[i].AlarmType = 2;
  9986. //}
  9987. //keyValues.Add(2, alarmDatas);
  9988. ////3
  9989. //dicAlarmName = new Dictionary<int, Alarm>();
  9990. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  9991. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  9992. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  9993. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  9994. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9995. //for (int i = 0; i < dicAlarmName.Count; i++)
  9996. //{
  9997. // alarmDatas[i] = new AlarmData();
  9998. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  9999. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10000. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10001. // alarmDatas[i].AlarmType = 3;
  10002. //}
  10003. //keyValues.Add(3, alarmDatas);
  10004. //DicAlarms.Add(2, keyValues);
  10005. #endregion 第二个工站-原来的写法(废弃)
  10006. }
  10007. }
  10008. }