12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Text;
- using Microsoft.Win32;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using HslCommunication.LogNet;
- using MainForm.FaForm;
- using Sunny.UI;
- using MainForm.ClassFile.XiaomiAPI;
- using System.Diagnostics;
- using MainForm.Models;
- using SqlSugar;
- using EasyModbus;
- using ModBusClientSimple.Util;
- using csharp_networkprotocol_hpsocket;
- using MqttnetServerWin;
- using Sunny.UI.Win32;
- using MainForm.ClassFile.XiaomiAPI_AGV;
- using MainForm.ClassFile.XiaomiAPI_RouteCom;
- using HslCommunication.Controls;
- using EIP_Protocol;
- using MainForm.ClassFile.XiaomiAPI_MES;
- using NPOI.Util;
- using static MainForm.SQLHelper;
- using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
- using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
- using MainForm.ClassFile.ProjectClass;
- using CommonLib;
- using Org.BouncyCastle.Asn1.IsisMtt;
- using System.Web.Services.Description;
- using System.Numerics;
- using MathNet.Numerics.RootFinding;
- using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
- using static MainForm.ClassFile.XiaomiClass.MesHelper;
- using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
- /*
- * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
- */
- namespace MainForm
- {
- /// <summary>
- /// 记录日志的委托
- /// </summary>
- /// <param name="logType">日志类型</param>
- /// <param name="message">日志信息</param>
- public delegate void HomeMessageHandler(LogType logType, string message);
- /// <summary>
- /// 主页窗体
- /// </summary>
- public partial class Form_Home : Form
- {
- #region 常量
- //文本常量
- private const string Head = "开始采集";
- private const string Tail = "采集完成";
- private const string Body = "工位出站数据";
- private const string BodyCheck = "工位点检数据";
- private const string BodyRun = "整线运行数据";
- private const string BodyAlarm = "整线报警数据";
- #endregion 常量
- #region 变量
- /// <summary>
- /// 委托-记录日志的方法
- /// </summary>
- public event HomeMessageHandler MessageEvent;
- /// <summary>
- /// 日志接口
- /// </summary>
- ILogNet _PLCLogNet;
- /// <summary>
- /// 用于记录IOT MQTT日志
- /// </summary>
- ILogNet _IOTMqttLogNet;
- /// <summary>
- /// 用于记录AGV MQTT日志
- /// </summary>
- ILogNet _AGVMqttLogNet;
- //private int DataSwitch = 1; // 1-SQLServer;2-Excel
- // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
- // 间隔时间
- private int IntervalReadPLC = 300; //ms 读PLC
- private int IntervalMonitorMES = 1000; //ms MES心跳
- private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
- // 软件状态
- private bool IsRun = true;
- #region PLC 与 TCP对象
- // 定义一个字典,存plc对象(通讯)
- ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
- Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
- // 定义TCPClient对象列表
- Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
- // 定义MQTTHelper对象
- MQTTHelper _MQTTHelper = new MQTTHelper();
- #endregion PLC 与 TCP对象
- /// <summary>
- /// 上次的设备运行信息
- /// </summary>
- private string lineWorkingData1_OldStr = string.Empty;
- /// <summary>
- /// 设备报警字典-当前结果
- /// Dictionary<工位代码,List<报警信息>>
- /// </summary>
- private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
- Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
- #endregion 变量
- #region 窗体基础事件
- /// <summary>
- /// 初始化
- /// </summary>
- public Form_Home()
- {
- InitializeComponent();
- CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
- _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
- _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
- _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
- GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
-
- }
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- private void Form_Home_Load(object sender, EventArgs e)
- {
- try
- {
- AddMessage(LogType.Info, "开始初始化程序");
- InitalDicAlarm(); // 实例化报警字典
- //组建plc对象字典
- //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
- //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
- if (GlobalContext.IsUsePLC1)
- FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
- //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
- if (GlobalContext.IsUsePLC2)
- //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
- FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
- if (GlobalContext.IsUsePLC3)
- FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
- //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
- if (GlobalContext.IsUsePLC4)
- FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
- //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
- if (GlobalContext.IsUsePLC5)
- FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
- //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
- if (GlobalContext.IsUsePLC6)
- FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
- if (GlobalContext.IsUsePLC7)
- FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
- if (GlobalContext.IsUsePLC8)
- FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
- if (GlobalContext.IsUsePLC9)
- FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
- foreach (Inovance_EIP plcEIP in FunsEip.Values)
- {
- if (plcEIP != null)
- {
- try
- {
- (int, string) result = plcEIP.Connect();
- }
- catch (Exception ex)
- {
- MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
- "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
- }
- }
- }
- /*
- //plc1Alarm.Connect();
- foreach (ModbusClientHelper modbusClient in Funs.Values)
- {
- if (modbusClient != null)
- {
- try
- {
- modbusClient.Connect();
- }
- catch (Exception ex)
- {
- MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
- "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
- }
- }
- }
- */
- // 采集任务
- Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
- List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
- //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
- if (GlobalContext.IsUsePLC1)
- TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
- if (GlobalContext.IsUsePLC2)
- TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
- if (GlobalContext.IsUsePLC3)
- TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
- if (GlobalContext.IsUsePLC4)
- TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
- if (GlobalContext.IsUsePLC5)
- TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
- if (GlobalContext.IsUsePLC6)
- TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
- if (GlobalContext.IsUsePLC7)
- TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
- if (GlobalContext.IsUsePLC8)
- TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
- if (GlobalContext.IsUsePLC9)
- TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
- #region 初始化
- try
- {
- // 开启边线MES(绑定/查询数据)
- //int mesRoute = XiaomiMES_RouteCommunication.Init();
- //if (mesRoute == 0)
- //{
- // //picMESStatus.Image = imageListState.Images[1];
- // //GlobalContext.MESIsConnect = true;
- // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
- //}
- //else
- //{
- // //picMESStatus.Image = imageListState.Images[0];
- // //GlobalContext.MESIsConnect = false;
- // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
- //}
- // 开启MES(Http)
- if (GlobalContext.IsUseMES)
- {
- bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
- if (mesret)
- {
- picMESStatus.Image = imageListState.Images[1];
- GlobalContext.MESIsConnect = true;
- AddMessage(LogType.Info, "小米MES初始连接成功!");
- }
- else
- {
- picMESStatus.Image = imageListState.Images[0];
- GlobalContext.MESIsConnect = false;
- AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
- }
- }
- // 开启IOT(MQTT)
- if (GlobalContext.IsUseIot)
- {
- string addr = GlobalContext.MQTTServerHost;
- int port = GlobalContext.MQTTServerPort;
- //生产环境需要修改
- int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
- XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
- if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
- {
- picIot.Image = imageListState.Images[1];
- AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
- // 设置回调函数
- //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
- // 配置参数
- XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
- // fds
- param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
- param.parameter.fds.appId = "Auto-Soft";
- param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
- // mes
- param.parameter.mes.address = GlobalContext.ServerIp;
- param.parameter.mes.appId = GlobalContext.MESAppId;
- param.parameter.mes.appKey = GlobalContext.MESAppKey;
- // mqtt
- param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
- param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
- param.parameter.mqtt.username = GlobalContext.MQTTAppId;
- param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
- // 设备配置
- param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
- if (GlobalContext.IsUsePLC1)
- {
- param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
- }
- if (GlobalContext.IsUsePLC2)
- {
- param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
- }
- if (GlobalContext.IsUsePLC3)
- {
- param.parameter.equipment.deviceCode = GlobalContext.S3_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.S3_station; // ⼯位Id
- }
- if (GlobalContext.IsUsePLC4)
- {
- param.parameter.equipment.deviceCode = GlobalContext.S4_1_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.S4_1_station; // ⼯位Id
- }
- if (GlobalContext.IsUsePLC5)
- {
- param.parameter.equipment.deviceCode = GlobalContext.S5_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.S5_station; // ⼯位Id
- }
- if (GlobalContext.IsUsePLC6)
- {
- param.parameter.equipment.deviceCode = GlobalContext.S6_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.S6_station; // ⼯位Id
- }
- if (GlobalContext.IsUsePLC7)
- {
- param.parameter.equipment.deviceCode = GlobalContext.S7_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.S7_station; // ⼯位Id
- }
- if (GlobalContext.IsUsePLC8)
- {
- param.parameter.equipment.deviceCode = GlobalContext.S8_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.S8_station; // ⼯位Id
- }
- if (GlobalContext.IsUsePLC9)
- {
- param.parameter.equipment.deviceCode = GlobalContext.S9_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.S9_station; // ⼯位Id
- }
- param.parameter.equipment.project = GlobalContext.Project_Code;
- param.parameter.equipment.productMode = "debug";
- //
- param.parameter.other.logLevel = 0;
- param.parameter.other.LogPath = "D:\\Test";
- XiaomiMqttClient_Extend.ParameterConfig(param);
- }
- else
- {
- picIot.Image = imageListState.Images[0];
- AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
- }
- }
- // 开启AGV(Http与MQTT)
- if (GlobalContext.IsUseAGV)
- {
- // AGV HTTP
- bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
- if (mesret1)
- {
- picAgvHttp.Image = imageListState.Images[1];
- AddMessage(LogType.Info, "AGV Http初始连接成功!");
- }
- else
- {
- picAgvHttp.Image = imageListState.Images[0];
- AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
- }
- string agvMqttIp = GlobalContext.MQTTServerHost;
- int agvMqttPort = GlobalContext.MQTTServerPort;
- Action<ResultData_MQTT> callback = AGVMqttShowLog;
- ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
- // AGV MQTT
- if (result_MQTT.ResultCode == 1)
- {
- picAgvMqtt.Image = imageListState.Images[1];
- GlobalContext.AGVMQTTIsConnect = true;
- AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
- ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
- AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
- }
- else
- {
- picAgvMqtt.Image = imageListState.Images[0];
- GlobalContext.AGVMQTTIsConnect = false;
- AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
- }
- }
- // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
- Task.Run(MonitorMESConnect);
- // 查询PLC连接状态
- foreach (int plcNo in FunsEip.Keys)
- {
- bool connected = FunsEip[plcNo].IsConnected;
- if (connected)
- {
- string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
- AddMessage(LogType.Info, msg);
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
- }
- else
- {
- string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
- AddMessage(LogType.Info, msg);
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- }
- }
- // PLC4时 初始化扫码器TCP
- //if (GlobalContext.IsUsePLC4)
- // HpTCPClientInit();
- // 开启PLC的业务处理线程-监听PLC点位+状态
- foreach (Task task in TaskReadProcess)
- {
- if (task != null)
- task.Start();
- }
- //// 开启“获取线体报警数据”的线程
- //TaskReadAlarm.Start();
- ////下传MES信息给1工位(先判断下plc对象数量)
- //if (Funs.Count > 1)
- // DownLoadProductInfo(1);
- AddMessage(LogType.Info, "程序初始化完成");
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- this.BeginInvoke(new Action(() =>
- {
- AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }));
- }
- #endregion
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
- if (ex.Message != null && ex.Message.Contains("timed out"))
- MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
- else
- MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
- }
- }
- /// <summary>
- /// 窗体关闭事件
- /// </summary>
- private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
- {
- Closed2();
- }
- public void Closed2()
- {
- try
- {
- IsRun = false;
- Thread.Sleep(IntervalReadPLC);
- // 断开TCP
- int count = _HPSocket_TcpClients.Count();
- for (int i = 0; i < count; i++)
- {
- try
- {
- if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
- {
- _HPSocket_TcpClients[i].Stop();
- _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
- _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
- _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
- _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
- _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
- }
- }
- catch { }
- }
- // 关闭Iot
- try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
- // 关闭AGV Mqtt
- try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
- }
- catch { }
- }
- #endregion 窗体基础事件
- #region 监控MES状态
- /// <summary>
- /// 监控MES连接状态
- /// </summary>
- private void MonitorMESConnect()
- {
- while (IsRun) // 运行被控线程
- {
- try
- {
- // 开启MES(Http)
- if (GlobalContext.IsUseMES)
- {
- bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
- if (mesret)
- {
- picMESStatus.Image = imageListState.Images[1];
- GlobalContext.MESIsConnect = true;
- }
- else
- {
- picMESStatus.Image = imageListState.Images[0];
- GlobalContext.MESIsConnect = false;
- OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
- }
- }
- // 开启IOT(MQTT)
- if (GlobalContext.IsUseIot)
- {
- bool iIot = XiaomiMqttClient.IsOpen;
- if (iIot)
- picIot.Image = imageListState.Images[1];
- else
- {
- picIot.Image = imageListState.Images[0];
- OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
- }
- }
- // 开启AGV(Http与MQTT)
- if (GlobalContext.IsUseAGV)
- {
- // AGV Http
- bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
- if (mesret1)
- picAgvHttp.Image = imageListState.Images[1];
- else
- {
- picAgvHttp.Image = imageListState.Images[0];
- OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
- }
- // AGV MQTT
- if (GlobalContext.AGVMQTTIsConnect)
- picAgvMqtt.Image = imageListState.Images[1];
- else
- {
- picAgvMqtt.Image = imageListState.Images[0];
- OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
- }
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- Thread.Sleep(IntervalMonitorMES);
- }
- }
- #endregion 监控MES连接状态
- #region 采集设备状态、运行数据、报警数据
- /// <summary>
- /// 请求设备状态 5000
- /// </summary>
- /// <param name="no">1</param>
- /// <param name="stationNameStr"></param>
- /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
- public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
- {
- try
- {
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
- return result;
- }
- else
- {
- return 0;
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- return 0;
- }
- }
- /// <summary>
- /// 检查是否可采集点检数据 - 不取新值
- /// 5000不为1时可点检
- /// </summary>
- /// <returns></returns>
- public bool CheckCanSpotcheck1(int deviceState)
- {
- //return true;
- //D5000 = 1,代表设备控制状态处于运行状态
- //D5000 = 2, 代表设备控制状态处于故障状态
- //D5000 = 3,代表设备控制状态处于缺料状态
- //D5000 = 4, 代表设备控制状态处于待机状态
- //D5000 = 5,代表设备控制状态处于维修状态
- return deviceState != 1;
- }
- /// <summary>
- /// 检查是否可采集产品数据 - 不取新值
- /// </summary>
- /// <returns></returns>
- public bool CheckCanCollData(int deviceState)
- {
- return deviceState == 0; // 点检时该值不为0
- }
- /// <summary>
- /// 获取设备报警数据与获取设备运行信息
- /// </summary>
- private async void ReadAlarmAllPLC()
- {
- // [S1] Tray盘上料装备(板测)
- // [S2] FCT(板测)
- // [S3] 值板机
- // [S4] 取放桁架
- // [S5] Tray盘下料装备
- /// 上位机心跳
- /// 获取设备报警数据与状态信息
- string stationNameStr = "获取设备报警数据与状态信息";
- while (IsRun)
- {
- try
- {
- if (!GlobalContext._IsCon_plc1Alarm)
- {
- UpdatePLCMonitor(1, -2, 0);
- continue;
- }
- if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
- {
- DateTime dtNow = DateTime.Now;
- #region 获取设备运行信息
- try
- {
- LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
- lineWorkingData1.GUID = Guid.NewGuid().ToString();
- lineWorkingData1.LineName = GlobalContext.LineCode;
- //
- lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
- lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
- lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
- lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
- lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
- lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
- lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
- lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
- lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
- lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
- lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
- lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
- lineWorkingData1.CreateTime = DateTime.Now;
- string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
- // UI展示-展示到设备状态页
- if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
- {
- // 查询数据库最新一条数据,确定是不是更新
- string qSql = @"SELECT top(1) [GUID]
- ,[LineName]
- ,[BootTimeLong]
- ,[NormalTimeLong]
- ,[StandbyTimeLong]
- ,[FaultTimeLong]
- ,[MaterialShortageTimeLong]
- ,[MaintenanceTimeLong]
- ,[FaultNumber]
- ,[OutputNumber]
- ,[QualifiedNumber]
- ,[QualifiedRate]
- ,[DesignRhythm]
- ,[RealityRhythm]
- ,[CreateTime]
- FROM [LineWorkingData]
- where [CreateTime] > '{0}'
- and [LineName]='{1}'
- order by [CreateTime] desc
- ";
- qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
- var ds = SQLHelper_New.Query(qSql, null);
- if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
- {
- var dataDBlast = new LineWorkingData_ThisTime();
- dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
- dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
- dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
- dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
- if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
- {
- dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
- dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
- dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
- dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
- dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
- dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
- dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
- dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
- dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
- dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
- dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
- dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
- string usql = dataDBlast.ToStringUpdate();
- SQLHelper_New.ExecuteSQL(usql, null);
- lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
- AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
- //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
- }
- }
- else
- {
- // 插入
- SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
- lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
- AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
- //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
- }
- }
- else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
- {
- LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
- //// 本次开机设备运行情况
- //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
- //Task.Run(() =>
- //{
- // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
- // {
- // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
- // }
- //});
- // 本日设备运行情况
- // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
- if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
- {
- // 更新
- lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
- lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
- lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
- lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
- lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
- lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
- lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
- lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
- lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
- lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
- lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
- lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
- SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
- lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
- AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
- //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
- }
- else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
- {
- // 插入
- SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
- lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
- AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
- //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
- }
- await Task.Run(() =>
- {
- try
- {
- if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
- {
- Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
- }
- }
- catch { }
- });
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 获取设备运行信息
- #region 报警数据
- try
- {
- List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
- bool isNeedUpdUI = false; // 是否需要更新历史报警UI
- // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
- var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
- for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
- {
- short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
- dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
- if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
- {
- isNeedUpdUI = true; // 需要更新历史报警UI信息
- // 记录
- dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
- switch (dicAlarms_Cur_PLC1[i].是否报警)
- {
- case true: // 报警
- dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
- {
- GUID = Guid.NewGuid().ToString(),
- LineName = GlobalContext.LineCode, // 线体
- AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
- AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
- StartTime = dtNow // 开始时间
- };
- // 传输到页面
- deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
- {
- 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
- 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
- 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
- 开始时间 = dtNow
- });
- // 新增到数据库
- var data1 = dicAlarms_Cur_PLC1[i].报警数据;
- SaveAlarmDataByDB(stationNameStr, data1, false);
- AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
- break;
- case false: // 消除报警
- if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
- {
- dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
- {
- GUID = Guid.NewGuid().ToString(),
- LineName = GlobalContext.LineCode, // 线体
- AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
- AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
- StartTime = dtNow, // 开始时间
- EndTime = dtNow, // 开始时间
- PersistTime = 1, // 耗时1s
- };
- // 新增
- var data2 = dicAlarms_Cur_PLC1[i].报警数据;
- SaveAlarmDataByDB(stationNameStr, data2, false);
- AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
- }
- else
- {
- dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
- dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
- - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
- // 修改
- var data3 = dicAlarms_Cur_PLC1[i].报警数据;
- SaveAlarmDataByDB(stationNameStr, data3, true);
- AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
- }
- break;
- default:
- break;
- }
- }
- }
- DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
- // 有新报警则更新
- if (isNeedUpdUI)
- {
- // UI展示 - 展示到设备状态页
- await Task.Run(() =>
- {
- try
- {
- if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
- {
- Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
- if (Form_Main.formDevAlarm.Visible)
- {
- Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
- }
- }
- }
- catch { }
- });
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 报警数据
- UpdatePLCMonitor(1, -2, 1);
- }
- else
- {
- UpdatePLCMonitor(1, -2, 0);
- }
- }
- catch (Exception ex)
- {
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalAlarm);
- }
- }
- #endregion 轮询PLC
- #region 下发订单信息
- ///// <summary>
- ///// 壳体上料(下发工单)的交互逻辑
- ///// </summary>
- ///// <param name="no"></param>
- ///// <exception cref="NotImplementedException"></exception>
- //private void ReadStation_DownOrderInfo(int plcNo)
- //{
- // // [S1] Tray盘上料装备(板测)
- // // [S2] FCT(板测)
- // // [S3] 值板机
- // // [S4] 取放桁架
- // // [S5] Tray盘下料装备
- // /// 上位机心跳
- // /// 获取设备报警数据与状态信息
- // string stationNameStr = "[S0]壳体上料";
- // while (IsRun)
- // {
- // try
- // {
- // if (!GlobalContext._IsCon_Funs1)
- // {
- // UpdatePLCMonitor(plcNo, 0);
- // continue;
- // }
- // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
- // {
- // #region 壳体上料(下发工单)
- // try
- // {
- // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
- // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
- // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
- // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
- // // 重置数据和信号
- // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
- // {
- // // 清空写给PLC的数据
- // int[] i497 = new int[1] { 0 };
- // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
- // // MES_Flag重置为0
- // int[] i500 = new int[1] { 0 };
- // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
- // }
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 壳体上料(下发工单)
- // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- // }
- // else
- // {
- // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- //
- // Funs[plcNo].Connect();
- // }
- // }
- // catch (Exception ex)
- // {
- // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- //
- // Funs[plcNo].ReConnect();
- // }
- // Thread.Sleep(IntervalReadPLC);
- // }
- //}
- ///// <summary>
- ///// 下发订单信息到PLC
- ///// </summary>
- ///// <param name="no">PLC编号</param>
- //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
- //{
- // try
- // {
- // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
- // {
- // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
- // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
- // }
- // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- //}
- /// <summary>
- /// 下发清料信号
- /// </summary>
- /// <param name="no">PLC编号</param>
- public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
- {
- try
- {
- //Funs[plcNo].ReadHoldingRegisters<int>(496); //
- AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
- return true;
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- return false;
- }
- }
- #endregion 下发订单信息
- #region Xiaomi 贲流
- #region 公共方法
- private static bool ProgressState = false;
- private static readonly object lockObj = new object(); // 锁对象
- private static bool isCollectingFlagLeft;
- private static bool isCollectingFlagRight;
- private bool OpenDailogFalg = true;//是否开启扫码弹窗标识
- /// <summary>
- /// float[]转为string
- /// </summary>
- public string FloatArrayToString(float[] nScrewResults)
- {
- // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
- return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
- }
- /// <summary>
- /// short[]转为string
- /// </summary>
- public string ShortArrayToString(short[] nScrewResults)
- {
- // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
- return string.Join(",", nScrewResults);
- }
- /// <summary>
- /// 写入PLC重复三次
- /// </summary>
- public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
- {
- int i = 0;
- int nRet = 0;
- string strRet = "";
- try
- {
- while (i < 3) // 最多上传三次
- {
- (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
- if (nRet == 0) //成功
- {
- break;
- }
- else
- {
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
- i++;
- }
- }
- return (nRet, strRet);
- }
- catch (Exception ex)
- {
- return (1, ex.Message);
- }
- }
- public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
- {
- try
- {
- // 获取当前日期
- string dateFolder = DateTime.Now.ToString("yyyyMMdd");
- // 构建保存路径
- string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
- string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
- // 确保目录存在
- Directory.CreateDirectory(savePath);
- // 文件名
- string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
- string filePath = Path.Combine(savePath, fileName);
- // 确保不会超出数组长度,只取前14个或数组的实际长度
- int count = Math.Min(14, fScrewTimes.Length);
- using (StreamWriter sw = new StreamWriter(filePath))
- {
- for (int i = 0; i < count; i++)
- {
- sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
- sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
- sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
- sw.WriteLine($"锁附结果:{nScrewResults[i]}");
- sw.WriteLine(); // 空行分隔不同螺丝的信息
- }
- }
- return (0, "");
- }
- catch (Exception ex)
- {
- return (1, ex.Message);
- }
- }
- public Dictionary<string, string> GetLastLineCompensation(string path,string direction,string sn)
- {
- // 创建字典存储补偿点及其对应的值
- Dictionary<string, string> compensationDict = new Dictionary<string, string>();
- try
- {
- //string path = GlobalContext.MESLaserRPath;
- // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
- string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
- string filename = $"Laser-{currentDate}-W0.txt";
- // 拼接完整路径
- string fullPath = Path.Combine(path, filename);
- string lastNonEmptyLine = "";
- // 判断文件是否存在
- if (File.Exists(fullPath))
- {
- //读取文件内容
- string[] lines = File.ReadAllLines(fullPath);
- // 获取最后一行数据(忽略标题行)
- if (lines.Length > 1)
- {
- string lastLine = "";
- for (int i = lines.Length - 1; i > 0; i--)
- {
- if (!string.IsNullOrEmpty(lines[i]))
- {
- lastLine = lines[i];
- break;
- }
- }
- // 将最后一行按逗号分隔
- string[] values = lastLine.Split(',');
- values[1] = sn;
- string key = "三点激光_"+ direction; // 构造键名
- string value = string.Join(",", values); // 获取值并去除多余空格
- compensationDict[key] = value;
- //// 提取“1点补偿”到“6点补偿”的值
- //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
- //{
- // string key = $"{i - 1}点补偿"; // 构造键名
- // string value = values[i].Trim(); // 获取值并去除多余空格
- // compensationDict[key] = value;
- //}
- }
- }
- else
- {
- Console.WriteLine($"文件不存在: {fullPath}");
- }
- }
- catch (Exception ex)
- {
- // 捕获异常并输出错误信息
- Console.WriteLine($"发生错误: {ex.Message}");
- }
- return compensationDict;
- }
- public int PCBStationOutData(BarcodeSet_t Barcode,IoT_DataSet_t iotData)
- {
- int res = 0;
- string jsonstr1 = "";
- try
- {
- XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
- outRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备id(可配置)
- outRequest_Body.stationId = GlobalContext.S5_station; // ⼯位ID(可配置)
- outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
- outRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
- outRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
- int a1Result = (int)iotData.testStatus;
- //bool pass = a1Result == 1;
- //outRequest_Body.state = pass ? "PASS" : "FAIL"; ; // 出站条件 PASS或FAIL
- outRequest_Body.state = "PASS";
- outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
- outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
- XmStationOut_KeyMaterial keyMaterial = new XmStationOut_KeyMaterial();
- keyMaterial.bindSort = 1;
- keyMaterial.materialSn = Barcode.strProductBarcode;
- outRequest_Body.unitData.keyMaterial.Add(keyMaterial); // 产品码
- jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
- XmMES_StationOutResponse response = new XmMES_StationOutResponse();
- response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
- if (response != null && response.header.code == "200")
- {
- res = 1;
- AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---成功!请求信息:" + jsonstr1 + ",返回信息:" + JsonConvert.SerializeObject(response.body));
- }
- else
- {
- res = 0;
- AddMessage(LogType.Error, "上传PCB出站数据到MES服务器---失败!错误信息:"+ response.header.desc + ",请求信息:" + jsonstr1 + ",返回信息:" + JsonConvert.SerializeObject(response.body));
- }
- }
- catch (Exception e)
- {
- res = 0;
- AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---失败!请求信息:" + jsonstr1 + ",返回信息:" + e.Message);
- }
-
-
- return res;
- }
- public int PCBStationInData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
- {
- int res = 0;
- string json_Body = "";
- try
- {
- XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
- inRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
- inRequest_Body.stationId = GlobalContext.S5_station; // ⼯位ID(可配置)
- inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
- inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
- inRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
- inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
- inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
- json_Body = JsonConvert.SerializeObject(inRequest_Body);
- var response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
- string resultJson = JsonConvert.SerializeObject(response);
- if (response != null && response.header.code == "200")
- {
- res = 1;
- AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---成功!请求信息:" + json_Body + ",返回信息:" + JsonConvert.SerializeObject(response.body));
- }
- else
- {
- res = 0;
- AddMessage(LogType.Error, "上传PCB进站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + json_Body + ",返回信息:" + JsonConvert.SerializeObject(response.body));
- }
- }
- catch (Exception e)
- {
- res = 0;
- AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---失败!请求信息:" + json_Body + ",返回信息:" + e.Message);
- }
- return res;
- }
- /// <summary>
- /// 调用进站接口并保存进站数据
- /// </summary>
- /// <param name="stationNameStr">工站信息</param>
- /// <param name="workorder_code">工单号</param>
- /// <param name="mtltmrk">型号(物料号)</param>
- /// <param name="sn">产品SN</param>
- /// <param name="items">进站数据</param>
- /// <returns>1成功;5MES报警;6上位机报警</returns>
- public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
- {
- int result = 0;
- XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
- inRequest_Body.machineId = MachineId; // 装备ID(可配置)
- inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
- inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
- inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
- inRequest_Body.unitSn = sn; // 产品SN
- inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
- inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
- string json_Body = JsonConvert.SerializeObject(inRequest_Body);
- StationIn stationIn = new StationIn()
- {
- Workorder_code = workorder_code, // 车间订单号
- Mtltmrk = mtltmrk, // 产品型号(物料号)
- Sn = sn, // SN
- StationIn_body = json_Body, // 进站接口Json数据 - Body
- Parameter_values = items, // 进站数据
- Write_user = inRequest_Body.userId, // 员工Id
- Test_time = inRequest_Body.clientTime // 进站时间
- };
- // 本地数据
- string sql = stationIn.ToStringInsert(0);
- string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
- result = ret == "成功" ? 1 : 6;
-
- //await Task.Delay(200);
- // 上传MES
- if (GlobalContext.IsSendStationIn)
- {
- try
- {
- XmMES_StationInResponse response = new XmMES_StationInResponse();
- string resultJson = "";
- string mesRet = string.Empty;
- int i = 0;
- while (i < 2) // 1009会多次尝试上传
- {
- response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
- resultJson = JsonConvert.SerializeObject(response);
- if (response != null && response.header.code == "200")
- break;
- else if (!mesRet.Contains("1009")) // 1009是未知错误
- i++;
- i++;
- mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
- // 记录失败原因
- OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!请求参数:{json_Body},接口报错信息:" + mesRet);
- }
-
- if (response?.header?.code == "200")
- {
- string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
- string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
- result = ret_Upd == "成功" ? 1 : 6;
- AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,请求参数:{json_Body},返回参数:{resultJson}");
- }
- else
- {
- result = 5;
- AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!请求参数:{json_Body},接口报错信息:" + mesRet);
- }
- string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
- SQLHelper_New.ExecuteNonQuery(sql_response, null);
- }
- catch (Exception ex)
- {
- result = 6;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- }
- return result;
- }
- /// <summary>
- /// 选择如何记录出站数据
- /// </summary>
- /// <param name="items">出站数据</param>
- /// <param name="equipmentCode">设备编号</param>
- /// <param name="processItem">测试项目</param>
- /// <param name="workorder_code">车间订单号</param>
- /// <param name="batch_num">批次号</param>
- /// <param name="mtltmrk">型号</param>
- /// <param name="proDate">日期</param>
- /// <param name="supplierCode">供应商代码</param>
- /// <param name="sn_Number">产品序列号的 数字序列部分</param>
- /// <returns>上传成功时返回1;失败返回0</returns>
- private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
- string workorder_code, string batch_num, string mtltmrk, string proDate,
- string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode,string jsonParm, string direction="")
- {
- return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
- proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm, direction);
- }
- /// <summary>
- /// 添加出站数据(提交到MES+本地保存到数据库)
- /// </summary>
- /// <param name="items">出站数据</param>
- /// <param name="equipmentCode">设备编号</param>
- /// <param name="processItem">测试项目</param>
- /// <param name="workorder_code">车间订单号</param>
- /// <param name="batch_num">批次号</param>
- /// <param name="mtltmrk">型号</param>
- /// <param name="proDate">日期</param>
- /// <param name="supplierCode">供应商代码</param>
- /// <param name="sn_Number">产品序列号的 数字序列部分</param>
- /// <returns>上传成功时返回1;失败返回0</returns>
- public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
- string processItem, string workorder_code, string batch_num, string mtltmrk,
- string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode,string jsonParm,string direction="")
- {
- int upload = 0;
- int result = 0;
- ProcessData processData = new ProcessData()
- {
- Equipment_code = equipmentCode,
- Workorder_code = workorder_code,
- Batch_number = batch_num,
- Sn = sn, // SN
- Testitem = processItem,
- Parameter_values = items,
- Write_user = GlobalContext.CurrentUser,
- Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
- };
- // 本地数据
- string sql = processData.ToStringInsert(upload);
- string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
- //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
- // 上传MES
- if (GlobalContext.IsSendProcessData)
- {
- try
- {
- string id = processData.ID.Copy();
- XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
- outRequest_Body.machineId = machineId; // 装备id(可配置)
- outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
- outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
- outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
- outRequest_Body.unitSn = sn; // 产品SN
- outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
- outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
- outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
- outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
- outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
- outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
- if (!string.IsNullOrEmpty(partBarcode))
- {
- outRequest_Body.unitData.keyMaterial.Add(
- new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
- {
- bindSort = 1,
- materialSn = partBarcode
- }); // 设备数据 - 部件码
- }
- //OP30站读txt数据
- if (stationNameStr.Contains("CPAPHD"))
- {
- string path = "";
- if (direction == "Left")
- path = GlobalContext.MESLaserLPath;
- else
- path= GlobalContext.MESLaserRPath;
- //字典存储数据
- Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction,sn);
- foreach (var kvp in compensationDict)
- {
- outRequest_Body.unitData.processData.Add(
- new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
- {
- dataName = kvp.Key.ToString(),
- dataValue = kvp.Value.ToString()
- });
- }
- }
- string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
- if (GlobalContext.IsSendProcessData)
- {
- XmMES_StationOutResponse response = new XmMES_StationOutResponse();
- string mesRet = string.Empty;
- int i = 0;
- while (i < 2) // 1009会多次尝试上传
- {
- response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
- if (response != null && response.header.code == "200")
- {
- OnMessage(LogType.Error, "上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" + JsonConvert.SerializeObject(response.body));
- break;
- }
- else if (!mesRet.Contains("1009")) // 1009是未知错误
- i++;
- i++;
- mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
- // 记录失败原因
- OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
- }
- if (response?.header?.code == "200")
- {
- string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
- string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
- result = 1;
- //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
- AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
- }
- else
- {
- AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
- }
- string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
- JsonConvert.SerializeObject(response), id);
- SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- }
- return result;
- }
- //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
- //{
- // Stopwatch stopwatch = new Stopwatch();
- // stopwatch.Start();
- // try
- // {
- // // 初始化 AtlasScrew 实例
- // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
- // atlasScrew1.Initial();
- // // 存储结果的列表
- // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
- // // 存储角度和扭力的字符串列表
- // List<string> angleStrs = new List<string>();
- // List<string> torqueStrs = new List<string>();
- // // 上一次获取的数据
- // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
- // while (isExitAtlasLeft) // 检查是否收集数据
- // {
- // // 获取当前数据
- // var currentResult = atlasScrew1.GetResults();
- // // 判断是否为新数据
- // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
- // {
- // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
- // // 更新角度和扭力的字符串列表
- // angleStrs.Add(currentResult.JD_MEAN.ToString());
- // torqueStrs.Add(currentResult.NL_MEAN.ToString());
- // // 计算角度、扭力、起始扭力和最大扭力
- // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
- // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
- // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
- // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
- // // 将新数据添加到结果列表
- // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
- // // 更新上一次获取的数据
- // lastResult = currentResult;
- // }
- // // 等待一段时间后再次检查
- // Thread.Sleep(20); // 轮询间隔时间
- // // 如果触发了出站,则退出循环
- // if (!isExitAtlasLeft)
- // {
- // break;
- // }
- // }
- // // 生成文件名
- // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
- // // 写入数据到文件
- // using (StreamWriter writer = new StreamWriter(fileName))
- // {
- // // 写入标题行
- // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
- // // 写入每一行数据
- // foreach (var result in results)
- // {
- // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
- // }
- // }
- // stopwatch.Stop();
- // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
- // }
- // catch (Exception ex)
- // {
- // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
- // }
- // finally
- // {
- // // 重置标志变量
- // isExitAtlasLeft = false;
- // }
- //}
- //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
- //{
- // Stopwatch stopwatch = new Stopwatch();
- // stopwatch.Start();
- // try
- // {
- // // 初始化 AtlasScrew 实例
- // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
- // atlasScrew2.Initial();
- // // 存储结果的列表
- // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
- // // 上一次获取的数据
- // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
- // while (isExitAtlasRight) // 检查是否收集数据
- // {
- // // 获取当前数据
- // var currentResult = atlasScrew2.GetResults();
- // // 判断是否为新数据
- // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
- // {
- // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
- // // 将新数据写入PLC
- // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
- // // 将新数据添加到结果列表
- // results.Add(currentResult);
- // // 更新上一次获取的数据
- // lastResult = currentResult;
- // }
- // // 等待一段时间后再次检查
- // Thread.Sleep(20); // 轮询间隔时间
- // // 如果触发了出站,则退出循环
- // if (!isExitAtlasRight)
- // {
- // break;
- // }
- // }
- // // 将所有数据写入文件
- // //WriteDataToFile(sn, direction, results);
- // stopwatch.Stop();
- // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
- // }
- // catch (Exception ex)
- // {
- // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
- // }
- // finally
- // {
- // // 重置标志变量
- // isExitAtlasRight = false;
- // }
- //}
- private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- int nRet = 0;
- string strRet = "";
- try
- {
- int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
- while (isCollectingFlagLeft)
- {
- // 从缓存中获取所有未处理的数据
- var cachedData = atlasScrew.GetCachedDataLeft();
- foreach (var currentResult in cachedData)
- {
- if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
- {
- continue; // 跳过无效数据
- }
- OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
- // 写入PLC
- OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
- {
- fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
- fCircles = float.Parse(currentResult.JD_MEAN.ToString())
- };
- (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
- if (nRet != 0)
- {
- OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
- }
- else
- {
- OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
- }
- // 构建保存路径
- string dateFolder = DateTime.Now.ToString("yyyyMMdd");
- string basePath = AppDomain.CurrentDomain.BaseDirectory;
- string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
- Directory.CreateDirectory(savePath); // 确保目录存在
- // 构建文件名(以 SN + 序号命名)
- string fileName = $"{sn}_{fileCounter}.txt";
- string filePath = Path.Combine(savePath, fileName);
- // 写入文件
- using (StreamWriter writer = new StreamWriter(filePath))
- {
- writer.WriteLine("精度, 扭力");
- // 遍历 Pearkdegree 和 PearkTorque 的所有值
- for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
- {
- double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
- double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
- writer.WriteLine($"{precision}, {torque}");
- }
- }
- OnMessage(LogType.Info, $"保存文件成功: {filePath}");
- // 增加文件计数器
- fileCounter++;
- }
- // 如果没有更多数据,则短暂休眠以节省资源
- if (!cachedData.Any())
- {
- Thread.Sleep(10); // 根据需要调整休眠时间
- }
- // 如果触发了出站,则退出循环
- if (!isCollectingFlagLeft)
- {
- break;
- }
- }
- stopwatch.Stop();
- OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
- }
- catch (Exception ex)
- {
- OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
- }
- finally
- {
- isCollectingFlagLeft = false;
- }
- }
- private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- int nRet = 0;
- string strRet = "";
- try
- {
- int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
- while (isCollectingFlagRight)
- {
- // 从缓存中获取所有未处理的数据
- var cachedData = atlasScrew.GetCachedDataLeft();
- foreach (var currentResult in cachedData)
- {
- if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
- {
- continue; // 跳过无效数据
- }
- OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
- // 写入PLC
- OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
- {
- fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
- fCircles = float.Parse(currentResult.JD_MEAN.ToString())
- };
- (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
- if (nRet != 0)
- {
- OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
- }
- else
- {
- OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
- }
- // 构建保存路径
- string dateFolder = DateTime.Now.ToString("yyyyMMdd");
- string basePath = AppDomain.CurrentDomain.BaseDirectory;
- string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
- Directory.CreateDirectory(savePath); // 确保目录存在
- // 构建文件名(以 SN + 序号命名)
- string fileName = $"{sn}_{fileCounter}.txt";
- string filePath = Path.Combine(savePath, fileName);
- // 写入文件
- using (StreamWriter writer = new StreamWriter(filePath))
- {
- writer.WriteLine("精度, 扭力");
- // 遍历 Pearkdegree 和 PearkTorque 的所有值
- for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
- {
- double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
- double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
- writer.WriteLine($"{precision}, {torque}");
- }
- }
- OnMessage(LogType.Info, $"保存文件成功: {filePath}");
- // 增加文件计数器
- fileCounter++;
- }
- // 如果没有更多数据,则短暂休眠以节省资源
- if (!cachedData.Any())
- {
- Thread.Sleep(10); // 根据需要调整休眠时间
- }
- // 如果触发了出站,则退出循环
- if (!isCollectingFlagRight)
- {
- break;
- }
- }
- stopwatch.Stop();
- OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
- }
- catch (Exception ex)
- {
- OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
- }
- finally
- {
- isCollectingFlagRight = false;
- }
- }
- #endregion
- #region S1
- /// <summary>
- /// [S1] 壳体清洁上料装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S1(int plcNo)
- {
- string stationCode = "[OP10]";
- string stationName = "壳体清洁上料";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP10_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP10_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S1] 壳体清洁上料 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
- if (string.IsNullOrEmpty(sn))
- {
- ProgressState = false;
- return;
- }
- //正式生产就用PLC中取的
- //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
- //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
- //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- //绑定载具和产品
- ResponseMessage message = new ResponseMessage();
- message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
- if (message.result == false)
- {
- AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
- }
- // 产品SN进站
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
-
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
-
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0;
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站结束");
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S1] 壳体清洁上料 - 出站接口
- /// </summary>
- private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
- string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
- string sn = string.Empty;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
- string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- //a1Result = 1;
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- //出站接口
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
- stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
- stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
- stPLC_MesData.mesData.nRemainCount);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- #endregion
- #region S2
- /// <summary>
- /// [S2] 上盖板上料装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S2(int plcNo)
- {
- string stationCode = "[OP20]";
- string stationName = "上盖板上料装备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP20_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP20_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs2)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect();
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- //Funs[plcNo].ReConnect();
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S2] 上盖板上料装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
- //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
- string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
- //if (sn != strProductBarcode)
- //{
- // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
- //}
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站结束");
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S2] 上盖板上料装备 - 出站接口
- /// </summary>
- private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
- string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "部件码",
- Parameter_value = PartBarcode,
- Parameter_unit = ""
- });
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- if (!string.IsNullOrEmpty(PartBarcode))
- {
- message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
- if (message.result == false)
- {
- AddMessage(LogType.Error, message.text);
- }
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- #endregion
- #region S3
- /// <summary>
- /// [S3] 点散热胶装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S3(int plcNo)
- {
- string stationCode = "[OP30]";
- string stationName = "点散热胶装备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP30_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP30_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- #region 创建字典
- // 触发信号字典 赋值
- s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
- s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
- s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // PLC数据字典 赋值
- s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
- s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
- s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
- s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
- //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
- s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
- s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
- //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
- s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
- s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
- s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
- s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
- s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
- s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
- //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
- s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- s3PLCData.Add("c1Result", 0); // 产品结果
- s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
- s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
- s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
- #endregion 创建字典
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs2)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 左边进站
- try
- {
- if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 左边进站
- #region 左边出站
- try
- {
- if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
- stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 左边出站
- #region 右边进站
- try
- {
- if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 右边进站
- #region 右边出站
- try
- {
- if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
- stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
- }
- }
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 右边出站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect();
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- //Funs[plcNo].ReConnect();
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S3] 点散热胶装备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
- string StationId=string.Empty;
- if (direction=="Left")
- {
- StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
- }
- if (direction == "Right")
- {
- StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
- }
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S3] 点散热胶装备 - 出站
- /// </summary>
- private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
- string StationId = string.Empty;
- if (direction == "Left")
- {
- StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
- }
- if (direction == "Right")
- {
- StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
- }
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- int result1 = 1;
- //if (direction == "Right")
- //{
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson, direction);
- //}
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- if (direction == "Left")
- {
- string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
- string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
- string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
- message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
- stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
- strMesHeightInfos, strIntervalWeights, strRemainGlues);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- }
- if (direction == "Right")
- {
- string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
- string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
- string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
- message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
- stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
- strMesHeightInfos, strIntervalWeights, strRemainGlues);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- #endregion S3
- #region S4
- /// <summary>
- /// [S4] 点胶检测设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S4(int plcNo)
- {
- string stationCode = "[OP40]";
- string stationName = "胶线检测";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP40_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP40_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0;
- }
- }
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S4] 点胶检测设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站结束");
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S4] 点胶检测设备 - 出站接口
- /// </summary>
- private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
- string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
- string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
- string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
- message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
- strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- #endregion
- #region S5
- private static bool isPCBStation = false;//控制PCB是否进出站的标识
- /// <summary>
- /// [S5] 点胶检测设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S5(int plcNo)
- {
- string stationCode = "[OP50]";
- string stationName = "ADD板上料组装装备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP50_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- string pcbBarcode = "";
- string pcbBarcodeOld = "";
- OP50_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- #region PCB出站
- //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
- pcbBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
- if (pcbBarcode!= pcbBarcodeOld)
- {
- isPCBStation = true;
- }
- if (isPCBStation)
- {
- var r = S5_PCB进出站(stPLC_MesData, plcNo, stationNameStr, tagBaseName, tagMesCommName);
- if (r > 0)
- {
- isPCBStation = false;
- pcbBarcodeOld = pcbBarcode;
- }
- }
- //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
- #endregion
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- isPCBStation = true;//开启PCB进出站
- Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0;
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S5] 点胶检测设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
- string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
- //载具码验证产品码 //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站结束");
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S5] 点胶检测设备 - 出站接口
- /// </summary>
- private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
- string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- //数据库绑定载具和PCB
- ResponseMessage message = new ResponseMessage();
- message = SQLHelper.PCBCarrierBind(CarrierBarcode, pcbBarcode);
- if (message.result == false)
- {
- AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
- }
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- //ResponseMessage message = new ResponseMessage();
- message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
- stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- //保存部件码信息
- if (!string.IsNullOrEmpty(PartBarcode))
- {
- message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
- }
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- private int S5_PCB进出站(OP50_MesData_t stPLC_MesData,int plcNo,string stationNameStr,string tagBaseName,string tagMesCommName) {
- string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode.Replace("\r", "");
- stPLC_MesData.BarcodeSet.strPCBBarcode = PCBBarcode;//特殊字符处理
- if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
- {
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
- stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- if (GlobalContext.IsSendStationIn)
- {
- #region 出站
- int res1 = PCBStationInData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
- if (res1 == 1)
- {
- resultToPlC.cmdResult = 2;//OK
- WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
- }
- else
- {
- resultToPlC.cmdResult = 120;
- WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
- return 2;
- }
- #endregion
- #region 出站
- int res2 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
- if (res2 == 1)
- {
- resultToPlC.cmdResult = 2;//OK
- WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
- return 1;
- }
- else
- {
- resultToPlC.cmdResult = 120;
- WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
- return 2;
- }
- #endregion
- }
- else {
- return 2;
- }
- }
- else
- {
- return 2;
- }
- }
- #endregion
- #region S6
- /// <summary>
- /// [S6] 顶盖装配设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S6(int plcNo)
- {
- string stationCode = "[OP60]";
- string stationName = "组上盖板";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP60_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP60_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true; ;
- Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0;
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S6] 顶盖装配设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //strCarrierBarcode = "N801A-003";
- //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- if (OpenDailogFalg)
- {
- using (var dialog = new BandBarodeDialog())
- {
- dialog._CarrierBarcode = strCarrierBarcode;
- dialog._ProductBarcode = sn;
- var rs = dialog.ShowDialog();
- if (rs == DialogResult.OK)
- {
- AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
- OpenDailogFalg = false;//关闭扫码
- }
- else {
- ProgressState = false;
- return;
- }
- }
- }
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站结束");
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- OpenDailogFalg = true; //开启下一个物料的扫码
- }
- /// <summary>
- /// [S6] 顶盖装配设备 - 出站接口
- /// </summary>
- private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
- stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- #endregion
- #region S7
- /// <summary>
- /// [S7] 锁螺丝设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S7(int plcNo)
- {
- string stationCode = "[OP70]";
- string stationName = "上盖板锁螺丝";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP70_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- string tagScrewDataset = "screwDataset";
- OP70_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
- atlasScrewLeft.Initial();
- AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
- atlasScrewRight.Initial();
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 左边进站
- try
- {
- if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
-
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
- }
- }
-
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 左边进站
- #region 左边出站
- try
- {
- if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
- stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 左边出站
- #region 右边进站
- try
- {
- if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 右边进站
- #region 右边出站
- try
- {
- if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
- stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 右边出站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S7] 锁螺丝设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string atlasSn=string.Empty;
- try
- {
- stopwatch1.Start();
-
- AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
- string StationId = string.Empty; // 工位ID(可配置)
- if (direction == "Left")
- {
- StationId = GlobalContext.S7_StationId_1;
- }
- if (direction == "Right")
- {
- StationId = GlobalContext.S7_StationId_2;
- }
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- atlasSn= strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- if (direction == "Left")
- {
- isCollectingFlagLeft = false;//采集螺丝数据结束
- }
- if (direction == "Right")
- {
- isCollectingFlagRight = false;//采集螺丝数据结束
- }
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- //开始采集螺丝数据
- if (direction == "Left")
- {
- isCollectingFlagLeft = true;
- CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
- }
- if (direction == "Right")
- {
- isCollectingFlagRight = true;
- CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
- }
-
- }
- /// <summary>
- /// [S7] 锁螺丝设备 - 出站
- /// </summary>
- private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
-
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
- string StationId = string.Empty; // 工位ID(可配置)
- if (direction == "Left")
- {
- StationId = GlobalContext.S7_StationId_1;
- }
- if (direction == "Right")
- {
- StationId = GlobalContext.S7_StationId_2;
- }
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- //a1Result = 1;
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- int result1 = 1;
- //if (direction == "Right")
- //{
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- SwitctProcessData(stationNameStr, items, equipmentCode, processItem , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode
- , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
-
- //}
- //if (direction == "Left")
- //{
- // isCollectingFlagLeft = false;//采集螺丝数据结束
- //}
- //if (direction == "Right")
- //{
- // isCollectingFlagRight = false;//采集螺丝数据结束
- //}
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- if (direction == "Left")
- {
- string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
- string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
- string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
- message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
- strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
- }
- }
- if (direction == "Right")
- {
- string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
- string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
- string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
- message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
- strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
- }
- }
- //保存螺丝数据到txt
- (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
- if (result.Item1 != 0)
- {
- AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
- }
- AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
-
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- #endregion
- #region S8
- /// <summary>
- /// [S8] 3D螺丝高度检测设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S8(int plcNo)
- {
- string stationCode = "[OP80]";
- string stationName = "NG下料";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP80_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP80_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0;
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S8] 3D螺丝高度检测设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S8] 3D螺丝高度检测设备 - 出站接口
- /// </summary>
- private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
- string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
- message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- #endregion
- #region S9
- /// <summary>
- /// [S9] 下料设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S9(int plcNo)
- {
- string stationCode = "[OP90]";
- string stationName = "半成品下料";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP90_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- OP90_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0;
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S9] 下料设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站结束");
- AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S9] 下料设备 - 出站接口
- /// </summary>
- private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- if (result1 == 1)
- {
- //载具码解除绑定
- message = SQLHelper.DelCarrierBind(CarrierBarcode);
- if (message.result == false)
- {
- AddMessage(LogType.Error, message.text);
- }
- }
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- #endregion
- #endregion Xiaomi
- #region PLC1 张超凡
- #region [S1] Tray盘上料装备(板测)
- /// <summary>
- /// S1工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S1工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S1工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- ///// <summary>
- ///// 触发信号
- ///// </summary>
- //private ManualResetEvent[] MreTasks;
- /// <summary>
- /// [S1] Tray盘上料装备(板测)
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- //private void ReadStation_S1(int plcNo)
- //{
- // // [S1] Tray盘上料装备
- // // [S2] FCT
- // // [S3] 值板机
- // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
- // // [S5] Tray盘下料装备
- // string stationCode = "[S1]";
- // string stationName = "Tray盘上料装备";
- // string stationNameStr = stationCode + stationName;
- // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
- // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
- // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
- // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
- // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
- // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
- // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
- // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
- // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
- // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
- // s1PLCData.Add("a1Result", 0); // 产品结果
- // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
- // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
- // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
- // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
- // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
- // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
- // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
- // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
- // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
- // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
- // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
- // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
- // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
- // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // while (IsRun)
- // {
- // try
- // {
- // if (!GlobalContext._IsCon_Funs1)
- // {
- // UpdatePLCMonitor(1, plcNo, 0);
- // continue;
- // }
- // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- // {
- // Stopwatch stopwatch1 = new Stopwatch();
- // Stopwatch stopwatch2 = new Stopwatch();
- // stopwatch1.Start();
- // stopwatch2.Start();
- // #region 一次性读取所有数据
- // // 一次性读取所有数据
- // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
- // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
- // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
- // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
- // int[] datas = data1.Concat(data2).ToArray();
- // datas = datas.Concat(data3).ToArray();
- // datas = datas.Concat(data4).ToArray();
- // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
- // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
- // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
- // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
- // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
- // s1PLCData["a1MES_FLAG_Check"] = datas[77];
- // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
- // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
- // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
- // s1PLCData["a1MES_FLAG"] = datas[109];
- // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
- // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
- // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
- // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
- // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
- // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
- // s1PLCData["a1Result"] = datas[170];
- // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
- // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
- // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
- // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
- // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
- // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
- // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
- // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
- // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
- // s1PLCData["a1OEEMES_FLAG"] = datas[254];
- // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
- // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
- // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
- // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
- // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
- // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
- // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
- // s1PLCData["a1AGVUpStart"] = datas[308];
- // s1PLCData["a1AGVUpEnd"] = datas[309];
- // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
- // s1PLCData["a1AGVDownStart"] = datas[321];
- // s1PLCData["a1AGVDownEnd"] = datas[322];
- // #endregion 一次性读取所有数据
- // stopwatch2.Stop();
- // #region 回写操作,写后清空flag
- // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
- // #endregion 回写操作,写后清空flag
- // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
- // try
- // {
- // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
- // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
- // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
- // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
- // {
- // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
- // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
- // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
- // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
- // }
- // }
- // catch (Exception ex)
- // {
- // // 6代表上位机报警
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
- // #region 上料进站校验
- // try
- // {
- // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
- // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
- // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
- // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
- // {
- // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
- // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
- // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 上料进站校验
- // #region Tray盘上料装备-出站接口
- // try
- // {
- // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
- // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
- // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
- // if (a1PLC_FLAG != a1PLC_FLAGOld)
- // {
- // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
- // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
- // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
- // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion Tray盘上料装备-出站接口
- // #region Tray盘上料装备-将SN发给ICT标机
- // try
- // {
- // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
- // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
- // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
- // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
- // {
- // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
- // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
- // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
- // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion Tray盘上料装备-将SN发给ICT标机
- // #region Tray盘上料装备-点检数据
- // //try
- // //{
- // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
- // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
- // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
- // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
- // // if (pLC_Flag && !mES_Flag) // 1 0
- // // {
- // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
- // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
- // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
- // // }
- // // else if (!pLC_Flag && mES_Flag) // 0 1
- // // {
- // // // 清空写给PLC的数据
- // // // MES_Flag重置为0
- // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
- // // }
- // //}
- // //catch (Exception ex)
- // //{
- // // // MES_Flag 为2上位机报错
- // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
- // // string str = ex.StackTrace;
- // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // //}
- // #endregion Tray盘上料装备-点检数据
- // #region 节拍接口
- // try
- // {
- // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
- // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
- // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
- // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
- // {
- // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
- // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
- // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
- // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 节拍接口
- // #region AGV上料
- // // AGV上料叫AGV信号
- // try
- // {
- // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
- // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
- // if (a1AGVUpCall != a1AGVUpCallOld)
- // {
- // if (a1AGVUpCall == 1) // 0->1
- // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
- // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // // AGV上料完成信号
- // try
- // {
- // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
- // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
- // if (a1AGVUpEnd != a1AGVUpEndOld)
- // {
- // if (a1AGVUpEnd == 1) // 0->1
- // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
- // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion AGV上料
- // #region AGV下料
- // // AGV下料叫agv信号
- // try
- // {
- // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
- // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
- // if (a1AGVDownCall != a1AGVDownCallOld)
- // {
- // if (a1AGVDownCall == 1) // 0->1
- // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
- // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // // AGV下料完成信号
- // try
- // {
- // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
- // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
- // if (a1AGVDownEnd != a1AGVDownEndOld)
- // {
- // if (a1AGVDownEnd == 1) // 0->1
- // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
- // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion AGV下料
- // #region 心跳
- // try
- // {
- // short states = 0;
- // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 心跳
- // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- // stopwatch1.Stop();
- // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- // }
- // else
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- // Funs[plcNo].Connect(); // 重连
- // }
- // }
- // catch (Exception ex)
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- // Funs[plcNo].ReConnect();
- // }
- // Thread.Sleep(IntervalReadPLC);
- // }
- //}
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1载具进站查询状态(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
- sn = sn.Replace("\0", "");
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
- writeToPLC_Flag1.Adress = 2003;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 查询载具上的产品信息
- string[] cavitySNs = cavityData.Split('.');
- string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
- string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
- short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
- short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
- if (cavitySNs != null && cavitySNs.Length >= 2)
- {
- a1CavitySN1_VehicleStates = cavitySNs[0];
- a1CavitySN2_VehicleStates = cavitySNs[1];
- a1CavityResult1_VehicleStates = 2;
- a1CavityResult2_VehicleStates = 2;
- }
- if (a1CavitySN1_VehicleStates == "假产品")
- a1CavityResult1_VehicleStates = 3;
- if (a1CavitySN2_VehicleStates == "假产品")
- a1CavityResult2_VehicleStates = 3;
- short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- // 回写
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
- //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
- //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
- //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = mES_Flag;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
- {
- Name = "a1CavitySN1_VehicleStates",
- Adress = 2024,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = a1CavitySN1_VehicleStates
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
- {
- Name = "a1CavitySN2_VehicleStates",
- Adress = 2044,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = a1CavitySN2_VehicleStates
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "a1CavityResult1_VehicleStates",
- Adress = 2064,
- ValueType = PLCValueType.Short,
- Value = a1CavityResult1_VehicleStates
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "a1CavityResult2_VehicleStates",
- Adress = 2065,
- ValueType = PLCValueType.Short,
- Value = a1CavityResult2_VehicleStates
- });
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- 上料进站校验
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1上料进站校验(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
- sn = sn.Replace("\0", "");
- // 保存进站数据+调用进站MES接口
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
- stopwatch2.Stop();
- short a1MES_FLAG_Check = (short)result;
- //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2077;
- writeToPLC_Flag.Value = a1MES_FLAG_Check;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2077;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- 出站接口
- /// </summary>
- /// <param name="plcNo"></param>
- /// <param name="stationCode"></param>
- /// <param name="stationName"></param>
- private void S1出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
- sn = sn.Replace("\0", "");
- string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
- partNo1 = partNo1.Replace("\0", "");
- string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
- partNo2 = partNo2.Replace("\0", "");
- int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
- bool pass = a1Result == 1;
- stopwatch2.Start();
- // 产品1
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = a1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
- , workorder_code, mtltmrk, partNo1, pass, sn, "1");
- // 产品2
- items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "2",
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = a1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
- , workorder_code, mtltmrk, partNo2, pass, sn, "2");
- short result = 0;
- List<int> results = new List<int>() { result1, result2 };
- if (result1 == 1 && result2 == 1)
- result = 1;
- else if (results.Contains(3))
- result = 3;
- else if (results.Contains(2))
- result = 2;
- else if (results.Contains(4))
- result = 4;
- else
- result = 4;
- stopwatch2.Stop();
- #region 存储绑定数据到 边线MES系统中
- if (result == 1)
- {
- string data = string.Concat(partNo1, ".", partNo2);
- int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
- if (resultMesR != 0)
- {
- result = 4;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
- }
- }
- #endregion 存储绑定数据到 边线MES系统中
- // MES_Flag 为MES报错
- // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG";
- writeToPLC_Flag.Adress = 2109;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG";
- writeToPLC_Flag.Adress = 2109;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- //// 上传点检数据_ [S1] Tray盘上料装备(板测)
- //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
- //{
- // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- // string stationNameStr = stationCode + stationName;
- // string processItem = stationName; // 测试项目
- // try
- // {
- // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- // string accno = "1"; // 工序编号
- // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
- // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
- // List<OneCheckItem> items = new List<OneCheckItem>()
- // {
- // new OneCheckItem()
- // {
- // Onecheck_name="胶圈装配行程设定上限",
- // Onecheck_content="上限值",
- // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
- // },
- // };
- // OneCheckData oneCheckData = new OneCheckData()
- // {
- // Line_code = GlobalContext.LineCode,
- // Line_name = GlobalContext.LineName,
- // Equipment_code = equipmentCode,
- // Equipment_name = equipmentCode,
- // Workorder_code = workorder_code,
- // Procedure_code = accno,
- // Procedure_name = processItem,
- // Oneckeck_values = items,
- // Onecheck_empcode = "",
- // Onecheck_empname = "",
- // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
- // };
- // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
- // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
- // short result = result1 == 1 ? (short)1 : (short)2;
- // // MES_Flag 为4MES报错
- // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
- // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- // }
- // catch (Exception ex)
- // {
- // // MES_Flag 为2上位机报错
- // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- //}
- // ReadStation_S1_2 节拍接口+AGV
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
- a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
- string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
- a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
- string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
- a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
- // ZS 将SN发给ICT标机(串口)
- short a1MES_FLAG_ICT = 1;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
- writeToPLC_Flag.Adress = 2182;
- writeToPLC_Flag.Value = a1MES_FLAG_ICT;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
- writeToPLC_Flag.Adress = 2182;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- 节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
- string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
- a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
- string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
- a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
- string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
- a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2254;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
- writeToPLC_Flag2.Adress = 2254;
- writeToPLC_Flag2.Value = (short)1;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
- { // 查产品SN
- a1OEEPartNo = "Test"; // ZS
- }
- short a1OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
- a1OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2254;
- writeToPLC_Flag.Value = a1OEEMES_FLAG;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2254;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1AGV上料叫agv(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 呼叫AGV
- short a1AGVUpCall = 2;
- stopwatch2.Start();
- // a1AGVUpCall
- //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVUpCall";
- writeToPLC_Flag.Adress = 2307;
- writeToPLC_Flag.Value = a1AGVUpCall;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // a1AGVUpCall
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVUpCall";
- writeToPLC_Flag.Adress = 2307;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- AGV上料完成
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1AGV上料完成(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS AGV上料完成,让小车离开
- short a1AGVUpEnd = 2;
- stopwatch2.Start();
- // a1AGVUpEnd
- //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVUpEnd";
- writeToPLC_Flag.Adress = 2309;
- writeToPLC_Flag.Value = a1AGVUpEnd;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // a1AGVUpEnd
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVUpEnd";
- writeToPLC_Flag.Adress = 2309;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1AGV下料叫agv(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 呼叫AGV
- short a1AGVDownCall = 2;
- stopwatch2.Start();
- // a1AGVDownCall
- //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVDownCall";
- writeToPLC_Flag.Adress = 2320;
- writeToPLC_Flag.Value = a1AGVDownCall;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // a1AGVDownCall
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVDownCall";
- writeToPLC_Flag.Adress = 2320;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- AGV下料完成
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1AGV下料完成(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS AGV上料完成,让小车离开
- short a1AGVDownEnd = 2;
- stopwatch2.Start();
- // a1AGVDownEnd
- //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVDownEnd";
- writeToPLC_Flag.Adress = 2322;
- writeToPLC_Flag.Value = a1AGVDownEnd;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // a1AGVDownEnd
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVDownEnd";
- writeToPLC_Flag.Adress = 2322;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S1] Tray盘上料装备(板测)
- #endregion PLC1 张超凡
- #region PLC2 李晓奇
- #region [S2] FCT(板测)
- /// <summary>
- /// S2工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S2工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S2工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- /// <summary>
- /// [S2] FCT(板测)
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- //private void ReadStation_S2(int plcNo)
- //{
- // // [S1] Tray盘上料装备
- // // [S2] FCT
- // // [S3] 值板机
- // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
- // // [S5] Tray盘下料装备
- // /// 上位机心跳
- // /// 获取设备报警数据与状态信息
- // string stationCode = "[S2]";
- // string stationName = "FCT";
- // string stationNameStr = stationCode + stationName;
- // #region 创建字典
- // // 触发信号字典 赋值
- // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
- // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // // PLC数据字典 赋值
- // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
- // s2PLCData.Add("b1MES_FLAG_Check", 0);
- // s2PLCData.Add("b1ProductSN_Check", 0);
- // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
- // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
- // s2PLCData.Add("b1ProductSN_Unbind", "");
- // s2PLCData.Add("b1ProductSN_Bind", "");
- // s2PLCData.Add("b1Part1SN_Bind", "");
- // s2PLCData.Add("b1Part2SN_Bind", "");
- // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
- // s2PLCData.Add("b1MES_FLAG", 0);
- // s2PLCData.Add("b1ProductSN", 0);
- // s2PLCData.Add("b1Part1Result", 0);
- // s2PLCData.Add("b1Part2Result", 0);
- // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
- // s2PLCData.Add("b1OEEMES_FLAG", 0);
- // s2PLCData.Add("b1OEEProductSN", "");
- // s2PLCData.Add("b1OEEType", 0);
- // #endregion 创建字典
- // while (IsRun)
- // {
- // try
- // {
- // if (!GlobalContext._IsCon_Funs2)
- // {
- // UpdatePLCMonitor(1, plcNo, 0);
- // continue;
- // }
- // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- // {
- // Stopwatch stopwatch1 = new Stopwatch();
- // Stopwatch stopwatch2 = new Stopwatch();
- // stopwatch1.Start();
- // stopwatch2.Start();
- // #region 一次性读取所有数据
- // // 一次性读取所有数据
- // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
- // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
- // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
- // int[] datas = data1.Concat(data2).ToArray();
- // datas = datas.Concat(data3).ToArray();
- // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
- // s2PLCData["b1MES_FLAG_Check"] = datas[3];
- // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
- // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
- // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
- // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
- // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
- // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
- // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
- // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
- // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
- // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
- // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
- // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
- // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
- // s2PLCData["b1MES_FLAG"] = datas[169];
- // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
- // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
- // s2PLCData["b1Part1Result"] = datas[190];
- // s2PLCData["b1Part2Result"] = datas[191];
- // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
- // s2PLCData["b1OEEMES_FLAG"] = datas[203];
- // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
- // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
- // s2PLCData["b1OEEType"] = datas[224];
- // #endregion 一次性读取所有数据
- // stopwatch2.Stop();
- // #region 回写操作,写后清空flag
- // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
- // #endregion 回写操作,写后清空flag
- // #region 进站校验
- // try
- // {
- // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
- // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
- // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
- // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
- // {
- // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
- // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
- // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 进站校验
- // #region 二穴载具解绑/绑定(产品换载具)
- // try
- // {
- // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
- // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
- // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
- // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
- // {
- // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
- // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
- // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 二穴载具解绑/绑定(产品换载具)
- // #region FCT-出站接口
- // try
- // {
- // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
- // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
- // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
- // if (b1PLC_FLAG != b1PLC_FLAGOld)
- // {
- // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
- // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
- // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
- // }
- // }
- // catch (Exception ex)
- // {
- // // MES_Flag 为6上位机报错
- // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion FCT-出站接口
- // #region 节拍接口
- // try
- // {
- // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
- // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
- // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
- // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
- // {
- // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
- // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
- // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
- // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 节拍接口
- // #region 心跳
- // try
- // {
- // short states = 0;
- // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 心跳
- // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- // stopwatch1.Stop();
- // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- // }
- // else
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- // Funs[plcNo].Connect();
- // }
- // }
- // catch (Exception ex)
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- // Funs[plcNo].ReConnect();
- // }
- // Thread.Sleep(IntervalReadPLC);
- // }
- //}
- /// <summary>
- /// [S2] FCT(板测)- 进站校验
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S2进站校验(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
- sn = sn.Replace("\0", "");
- #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
- // 查询物料码By载具码 并判断是不是假产品
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
- writeToPLC_Flag1.Adress = 2003;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
- string[] cavitySNs = cavityData.Split('.');
- string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
- string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
- short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
- short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
- if (cavitySNs != null && cavitySNs.Length >= 2)
- {
- b1Part1SN_Check = cavitySNs[0];
- b1Part2SN_Check = cavitySNs[1];
- b1Part1Result_Check = 2;
- b1Part2Result_Check = 2;
- }
- if (b1Part1SN_Check == "假产品")
- b1Part1Result_Check = 3;
- if (b1Part2SN_Check == "假产品")
- b1Part2Result_Check = 3;
- // 调用MES进站
- stopwatch2.Start();
- // 调用MES进站 - 产品1
- List<TestItem> item;
- int result1 = b1Part1Result_Check;
- if (result1 != 3)
- {
- item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
- }
- // 调用MES进站 - 产品2
- int result2 = b1Part2Result_Check;
- if (result2 != 3)
- {
- item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "2",
- });
- result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
- }
- stopwatch2.Stop();
- b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
- b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
- int result = result1;
- if (result == 1)
- result = result2;
- short b1MES_FLAG_Check = (short)result;
- //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
- //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
- //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
- //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- writeToPLC_Flag.Name = "b1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = b1MES_FLAG_Check;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "b1Part1SN_Check",
- Adress = 2024,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = b1Part1SN_Check
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "b1Part2SN_Check",
- Adress = 2044,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = b1Part2SN_Check
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "b1Part1Result_Check",
- Adress = 2064,
- ValueType = PLCValueType.Short,
- Value = b1Part1Result_Check
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "b1Part2Result_Check",
- Adress = 2065,
- ValueType = PLCValueType.Short,
- Value = b1Part2Result_Check
- });
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S2] FCT(板测)- 二穴载具解绑绑定
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // 产品换载具
- string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
- b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
- string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
- b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
- string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
- b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
- string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
- b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
- stopwatch2.Start();
- #region 查询载具上的产品信息
- //string cavityData = string.Empty;
- //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
- //if (string.IsNullOrEmpty(cavityData))
- // cavityData = "";
- //if (snResult != 0)
- //{
- // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
- // writeToPLC_Flag.Adress = 2077;
- // writeToPLC_Flag.Value = (short)6;
- // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
- // stopwatch1.Stop();
- // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- // return;
- //}
- #endregion 查询载具上的产品信息
- #region 解绑(边线MES系统)
- int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
- writeToPLC_Flag1.Adress = 2077;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 解绑(边线MES系统)
- #region 存储绑定数据到 边线MES系统中
- string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
- snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
- writeToPLC_Flag1.Adress = 2077;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 存储绑定数据到 边线MES系统中
- stopwatch2.Stop();
- short b1MES_FLAG_Unbind = 1;
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
- writeToPLC_Flag.Adress = 2077;
- writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
- writeToPLC_Flag.Adress = 2077;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- //// 上次采集到的SN
- //private string sn_FCT = string.Empty;
- /// <summary>
- /// [S2] FCT(板测)- 出站数据
- /// </summary>
- private void S2出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
- int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
- int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
- bool pass1 = b1Part1Result == 1;
- bool pass2 = b1Part2Result == 1;
- #region 根据 载具SN 查 物料SN
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "b1MES_FLAG";
- writeToPLC_Flag1.Adress = 2169;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 根据 载具SN 查 物料SN
- string[] cavitySNs = cavityData.Split('.');
- string b1ProductSN1 = string.Empty;
- string b1ProductSN2 = string.Empty;
- if (cavitySNs != null && cavitySNs.Length >= 2)
- {
- b1ProductSN1 = cavitySNs[0];
- b1ProductSN2 = cavitySNs[1];
- }
- stopwatch2.Start();
- // 产品1
- int result1 = 0;
- if (b1ProductSN1 == "假产品")
- result1 = 1;
- else
- {
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = b1ProductSN.ToString(),
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
- , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
- }
- // 产品2
- int result2 = 0;
- if (b1ProductSN1 == "假产品")
- result2 = 1;
- else
- {
- List<TestItem> items2 = new List<TestItem>();
- items2.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = b1ProductSN.ToString(),
- Parameter_unit = ""
- });
- items2.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "2",
- Parameter_unit = ""
- });
- items2.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
- , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
- }
- short result = 0;
- List<int> results = new List<int>() { result1, result2 };
- if (result1 == 1 && result2 == 1)
- result = 1;
- else if (results.Contains(3))
- result = 3;
- else if (results.Contains(2))
- result = 2;
- else if (results.Contains(4))
- result = 4;
- else
- result = 4;
- stopwatch2.Stop();
- //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1MES_FLAG";
- writeToPLC_Flag.Adress = 2169;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1MES_FLAG";
- writeToPLC_Flag.Adress = 2169;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S2] FCT(板测)- 节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S2节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
- string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2203;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- string b1OEEPartNo = string.Empty; // 物料码
- if (string.IsNullOrEmpty(b1OEEProductSN))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2203;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else
- { // 查产品SN
- b1OEEPartNo = "Test"; // ZS
- }
- short b1OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
- b1OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2203;
- writeToPLC_Flag.Value = b1OEEMES_FLAG;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2203;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S2] FCT(板测)
- #endregion PLC2 李晓奇
- #region PLC3 刘永村
- #region [S3] 值板机
- /// <summary>
- /// S3工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S3工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S3工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- /// <summary>
- /// [S3] 值板机
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- //private void ReadStation_S3(int plcNo)
- //{
- // // [S1] Tray盘上料装备
- // // [S2] FCT
- // // [S3] 值板机
- // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
- // // [S5] Tray盘下料装备
- // /// 上位机心跳
- // /// 获取设备报警数据与状态信息
- // string stationCode = "[S3]";
- // string stationName = "值板机";
- // string stationNameStr = stationCode + stationName;
- // #region 创建字典
- // // 触发信号字典 赋值
- // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
- // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
- // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // // PLC数据字典 赋值
- // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
- // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
- // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
- // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
- // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
- // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
- // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
- // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
- // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
- // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
- // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
- // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
- // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
- // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
- // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- // s3PLCData.Add("c1Result", 0); // 产品结果
- // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
- // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
- // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
- // #endregion 创建字典
- // while (IsRun)
- // {
- // try
- // {
- // if (!GlobalContext._IsCon_Funs3)
- // {
- // UpdatePLCMonitor(1, plcNo, 0);
- // continue;
- // }
- // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- // {
- // Stopwatch stopwatch1 = new Stopwatch();
- // Stopwatch stopwatch2 = new Stopwatch();
- // stopwatch1.Start();
- // stopwatch2.Start();
- // #region 一次性读取所有数据
- // // 一次性读取所有数据
- // ModbusClientHelper modbusClientHelper = Funs[plcNo];
- // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
- // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
- // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
- // int[] datas = data1.Concat(data2).ToArray();
- // datas = datas.Concat(data3).ToArray();
- // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
- // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
- // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
- // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
- // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
- // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
- // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
- // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
- // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
- // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
- // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
- // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
- // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
- // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
- // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
- // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- // s3PLCData["c1Result"] = datas[192]; // 产品结果
- // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
- // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
- // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
- // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
- // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
- // #endregion 一次性读取所有数据
- // stopwatch2.Stop();
- // #region 回写操作,写后清空flag
- // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
- // #endregion 回写操作,写后清空flag
- // #region S3进站校验
- // try
- // {
- // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
- // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
- // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
- // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
- // {
- // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
- // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
- // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion S3进站校验
- // #region S3二穴载具解绑
- // try
- // {
- // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
- // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
- // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
- // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
- // {
- // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
- // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
- // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion S3二穴载具解绑
- // #region S3二穴载具绑定
- // try
- // {
- // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
- // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
- // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
- // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
- // {
- // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
- // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
- // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion S3二穴载具绑定
- // #region S3出站接口(+一穴载具绑定)
- // try
- // {
- // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
- // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
- // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
- // if (c1PLC_FLAG != c1PLC_FLAGOld)
- // {
- // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
- // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
- // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
- // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion S3出站接口(+一穴载具绑定)
- // #region S3节拍接口
- // try
- // {
- // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
- // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
- // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
- // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
- // {
- // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
- // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
- // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
- // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion S3节拍接口
- // #region 心跳
- // try
- // {
- // short states = 0;
- // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 心跳
- // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- // stopwatch1.Stop();
- // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- // }
- // else
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- // Funs[plcNo].Connect();
- // }
- // }
- // catch (Exception ex)
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- // Funs[plcNo].ReConnect();
- // }
- // Thread.Sleep(IntervalReadPLC);
- // }
- //}
- /// <summary>
- /// [S3] 值板机- 进站校验
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S3进站校验(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
- sn = sn.Replace("\0", "");
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
- writeToPLC_Flag1.Adress = 2003;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 查询载具上的产品信息
- string[] cavitySNs = cavityData.Split('.');
- string part1Str = ""; // 产品1的SN码
- string part2Str = ""; // 产品2的SN码
- short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
- short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
- if (cavitySNs != null && cavitySNs.Length >= 2)
- {
- part1Str = cavitySNs[0];
- part2Str = cavitySNs[1];
- c1Part1Result_Check = 2;
- c1Part2Result_Check = 2;
- }
- if (part1Str == "假产品")
- c1Part1Result_Check = 3;
- if (part2Str == "假产品")
- c1Part2Result_Check = 3;
- // 调用MES进站
- stopwatch2.Start();
- // 调用MES进站 - 产品1
- List<TestItem> item;
- int result1 = c1Part1Result_Check;
- if (result1 != 3)
- {
- item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
- }
- // 调用MES进站 - 产品2
- int result2 = c1Part2Result_Check;
- if (result2 != 3)
- {
- item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "2",
- });
- result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
- }
- stopwatch2.Stop();
- if (result1 == 2)
- c1Part1Result_Check = 2;
- if (result2 == 2)
- c1Part2Result_Check = 2;
- int result = result1;
- if (result == 1)
- result = result2;
- short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
- short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
- short c1MES_FLAG_Check = (short)result;
- //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
- //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
- //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
- //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = c1MES_FLAG_Check;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "c1Part1Result_Check",
- Adress = 2024,
- ValueType = PLCValueType.Short,
- Value = c1Part1Result_Check
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "c1Part2Result_Check",
- Adress = 2025,
- ValueType = PLCValueType.Short,
- Value = c1Part2Result_Check
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "c1Part1Num_Check",
- Adress = 2026,
- ValueType = PLCValueType.Short,
- Value = c1Part1Num_Check
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "c1Part2Num_Check",
- Adress = 2027,
- ValueType = PLCValueType.Short,
- Value = c1Part2Num_Check
- });
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S3] 值板机 - 二穴载具解绑
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S3二穴载具解绑(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
- c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
- int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- // 解绑
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
- writeToPLC_Flag1.Adress = 2082;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 查询载具上的产品信息
- string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
- #region 解绑
- if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
- {
- // 删除
- int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
- OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
- }
- else
- {
- string data_new = string.Join(".", cavitySNs);
- // 删除再插入
- int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
- int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
- OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
- }
- #endregion 解绑
- short c1MES_FLAG_Unbind = 1;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
- writeToPLC_Flag.Adress = 2082;
- writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
- writeToPLC_Flag.Adress = 2082;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S3] 值板机 - 二穴载具绑定
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S3二穴载具绑定(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
- c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
- int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
- int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
- int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
- stopwatch2.Start();
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
- writeToPLC_Flag1.Adress = 2115;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 查询载具上的产品信息
- // 产品换载具
- string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
- string partSn1 = "";
- string partSn2 = "";
- if (cavitySNs != null && cavitySNs.Length >= 2)
- {
- partSn1 = cavitySNs[0];
- partSn2 = cavitySNs[1];
- }
- string data_new = string.Empty;
- // 是否是两个穴位交换
- if (c1CavityReverse_Bind == 1)
- {
- // 交换
- data_new = string.Concat(partSn2, ".", partSn1);
- }
- else
- { // 不交换
- string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
- cavitySNs[c1VehicleCavityTo_Bind] = sn;
- cavitySNs[c1VehicleCavityFr_Bind] = "";
- data_new = string.Join(".", cavitySNs);
- }
- // 删除再插入
- int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
- int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
- OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
- stopwatch2.Stop();
- short c1MES_FLAG_Bind = 1;
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
- writeToPLC_Flag.Adress = 2115;
- writeToPLC_Flag.Value = c1MES_FLAG_Bind;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
- writeToPLC_Flag.Adress = 2115;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- //// 上次采集到的SN
- //private string sn_值板机 = string.Empty;
- /// <summary>
- /// [S3] 值板机 - 出站接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void S3出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
- sn = sn.Replace("\0", "");
- string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
- c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
- int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
- bool pass = c1Result == 1;
- // 查sn
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "c1MES_FLAG";
- writeToPLC_Flag1.Adress = 2150;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 查询载具上的产品信息
- string[] cavitySNs = cavityData.Split('.');
- string productSN = "";
- if (cavitySNs != null && cavitySNs.Length >= 2)
- {
- productSN = cavitySNs[c1VehicleCavity];
- cavitySNs[c1VehicleCavity] = "";
- }
- stopwatch2.Start();
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "二穴载具码",
- Parameter_value = c1ProductSN_Check,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "二穴载具穴号",
- Parameter_value = c1VehicleCavity.ToString(),
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "一穴载具码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "一穴载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = c1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
- , workorder_code, mtltmrk, productSN, pass, sn, "1");
- short result = (short)result1;
- stopwatch2.Stop();
- #region 存储绑定数据到 边线MES系统中
- if (result == 1)
- {
- string data = string.Concat(productSN);
- int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
- if (resultMesR != 0)
- {
- result = 4;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
- }
- }
- #endregion 存储绑定数据到 边线MES系统中
- #region 产品从 来源载具(二穴载具)中删除
- if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
- {
- // 删除
- int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
- OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
- }
- else
- {
- string data_new = string.Join(".", cavitySNs);
- // 删除再插入
- int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
- int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
- OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
- }
- #endregion 产品从 来源载具(二穴载具)中删除
- // MES_Flag 为MES报错
- // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG";
- writeToPLC_Flag.Adress = 2150;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG";
- writeToPLC_Flag.Adress = 2150;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S3] 值板机- 节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S3节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
- string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
- c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2204;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- string c1OEEPartNo = string.Empty; // 物料码
- if (string.IsNullOrEmpty(c1OEEProductSN))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2204;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else
- { // 查产品SN
- c1OEEPartNo = "Test"; // ZS
- }
- short c1OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
- c1OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2204;
- writeToPLC_Flag.Value = c1OEEMES_FLAG;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2204;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S3] 值板机
- #endregion PLC3 刘永村
- #region PLC4 刘果段
- #region [S4] 取放桁架
- /// <summary>
- /// S4工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S4工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S4工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- /// <summary>
- /// [S4] 取放桁架
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- //private void ReadStation_S4(int plcNo)
- //{
- // // [S1] Tray盘上料装备
- // // [S2] FCT
- // // [S3] 值板机
- // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
- // // [S5] Tray盘下料装备
- // /// 上位机心跳
- // /// 获取设备报警数据与状态信息
- // string stationCode = "[S4_1]";
- // string stationName = "载具下线装备";
- // string stationNameStr = stationCode + stationName;
- // string stationCode2 = "[S4_2]";
- // string stationName2 = "桁架";
- // string stationNameStr2 = stationCode2 + stationName2;
- // string stationCode3 = "[S4_3]";
- // string stationName3 = "提升机1";
- // string stationNameStr3 = stationCode3 + stationName3;
- // string stationCode4 = "[S4_4]";
- // string stationName4 = "提升机2";
- // string stationNameStr4 = stationCode4 + stationName4;
- // string stationCode5 = "[S4_5]";
- // string stationName5 = "载具上线装备";
- // string stationNameStr5 = stationCode5 + stationName5;
- // #region 创建字典
- // // 触发信号字典 赋值
- // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
- // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
- // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
- // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
- // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
- // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
- // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
- // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // // PLC数据字典 赋值
- // // 载具下线装备(弹夹上线)
- // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
- // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
- // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
- // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
- // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
- // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
- // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
- // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
- // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
- // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
- // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
- // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
- // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
- // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
- // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
- // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
- // s4PLCData.Add("d1Result", 0); // 产品结果
- // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
- // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
- // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
- // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
- // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
- // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
- // // 真空标机(提升机)
- // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
- // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
- // s4PLCData.Add("d3Type", 0); // 进站还是出站
- // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
- // s4PLCData.Add("d3Result", 0); // 产品结果
- // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
- // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
- // s4PLCData.Add("d4Type", 0); // 进站还是出站
- // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
- // s4PLCData.Add("d4Result", 0); // 产品结果
- // // 载具上线装备(弹夹下线)
- // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
- // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
- // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
- // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
- // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
- // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
- // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
- // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
- // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
- // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
- // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
- // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
- // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
- // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
- // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
- // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
- // s4PLCData.Add("d5Result", 0); // 产品结果
- // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
- // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
- // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
- // #endregion 创建字典
- // while (IsRun)
- // {
- // try
- // {
- // if (!GlobalContext._IsCon_Funs4)
- // {
- // UpdatePLCMonitor(1, plcNo, 0);
- // continue;
- // }
- // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- // {
- // Stopwatch stopwatch1 = new Stopwatch();
- // Stopwatch stopwatch2 = new Stopwatch();
- // stopwatch1.Start();
- // stopwatch2.Start();
- // #region 一次性读取所有数据
- // // 载具下线装备(弹夹上线)
- // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
- // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
- // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
- // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
- // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
- // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
- // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
- // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
- // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
- // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
- // int[] datas = data1.Concat(data2).ToArray();
- // datas = datas.Concat(data3).ToArray();
- // datas = datas.Concat(data4).ToArray();
- // datas = datas.Concat(data5).ToArray();
- // datas = datas.Concat(data6).ToArray();
- // datas = datas.Concat(data7).ToArray();
- // datas = datas.Concat(data8).ToArray();
- // datas = datas.Concat(data9).ToArray();
- // datas = datas.Concat(data10).ToArray();
- // // 载具下线装备(弹夹上线)
- // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
- // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
- // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
- // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
- // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
- // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
- // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
- // s4PLCData["d1MES_FLAG"] = datas[65];
- // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
- // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
- // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
- // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
- // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
- // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
- // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
- // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
- // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
- // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
- // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
- // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
- // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
- // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
- // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
- // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
- // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
- // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
- // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
- // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
- // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
- // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
- // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
- // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
- // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
- // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
- // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
- // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
- // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
- // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
- // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
- // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
- // s4PLCData["d1Result"] = datas[386];
- // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
- // s4PLCData["d1OEEMES_FLAG"] = datas[398];
- // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
- // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
- // s4PLCData["d1OEEType"] = datas[419];
- // // 桁架(查询标机中弹夹的状态)
- // s4PLCData["d2BulletclipScanCode"] = datas[430];
- // s4PLCData["d2BulletclipStates"] = datas[431];
- // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
- // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
- // // 真空标机
- // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
- // s4PLCData["d3MES_FLAG"] = datas[463];
- // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
- // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
- // s4PLCData["d3Result"] = datas[484];
- // s4PLCData["d3Type"] = datas[485];
- // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
- // s4PLCData["d4MES_FLAG"] = datas[496];
- // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
- // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
- // s4PLCData["d4Result"] = datas[517];
- // s4PLCData["d4Type"] = datas[518];
- // // 载具上线装备(弹夹下线)
- // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
- // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
- // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
- // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
- // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
- // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
- // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
- // s4PLCData["d5MES_FLAG"] = datas[591];
- // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
- // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
- // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
- // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
- // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
- // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
- // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
- // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
- // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
- // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
- // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
- // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
- // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
- // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
- // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
- // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
- // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
- // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
- // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
- // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
- // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
- // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
- // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
- // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
- // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
- // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
- // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
- // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
- // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
- // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
- // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
- // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
- // s4PLCData["d5Result"] = datas[912];
- // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
- // s4PLCData["d5OEEMES_FLAG"] = datas[924];
- // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
- // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
- // s4PLCData["d5OEEType"] = datas[945];
- // #endregion 一次性读取所有数据
- // stopwatch2.Stop();
- // #region 回写操作,写后清空flag
- // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
- // #endregion 回写操作,写后清空flag
- // // N801A-S4_1 弹夹扫码
- // #region N801A-S4_1 弹夹扫码
- // try
- // {
- // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
- // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
- // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
- // {
- // if (d1BulletclipScanCode == 1) // 0->1
- // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
- // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_1 弹夹扫码
- // // N801A-S4_1 载具扫码
- // #region N801A-S4_1 载具扫码
- // try
- // {
- // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
- // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
- // if (d1VehicleScanCode != d1VehicleScanCodeOld)
- // {
- // if (d1VehicleScanCode == 1) // 0->1
- // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
- // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_1 载具扫码
- // // N801A-S4_1 出站接口
- // #region N801A-S4_1 出站接口
- // try
- // {
- // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
- // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
- // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
- // if (d1PLC_FLAG != d1PLC_FLAGOld)
- // {
- // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
- // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
- // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
- // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_1 出站接口
- // // N801A-S4_1 节拍接口
- // #region N801A-S4_1 节拍接口
- // try
- // {
- // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
- // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
- // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
- // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
- // {
- // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
- // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
- // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
- // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_1 节拍接口
- // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
- // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
- // try
- // {
- // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
- // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
- // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
- // {
- // if (d2BulletclipScanCode == 1) // 0->1
- // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
- // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
- // // N801A-S4_3 真空标机1 数据
- // #region N801A-S4_3 真空标机1
- // try
- // {
- // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
- // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
- // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
- // if (d3PLC_FLAG != d3PLC_FLAGOld)
- // {
- // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
- // {
- // int stationType = (int)s4PLCData["d3Type"];
- // if (stationType == 1)
- // {
- // // S4_3进站接口
- // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
- // }
- // else if (stationType == 2)
- // {
- // // S4_3出站接口
- // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
- // }
- // }
- // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
- // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_3 真空标机1
- // // N801A-S4_4 真空标机2 数据
- // #region N801A-S4_4 真空标机2
- // try
- // {
- // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
- // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
- // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
- // if (d4PLC_FLAG != d4PLC_FLAGOld)
- // {
- // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
- // {
- // int stationType = (int)s4PLCData["d4Type"];
- // if (stationType == 1)
- // {
- // // S4_4进站接口
- // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
- // }
- // else if (stationType == 2)
- // {
- // // S4_4出站接口
- // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
- // }
- // }
- // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
- // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_4 真空标机2
- // // N801A-S4_5 弹夹扫码 数据
- // #region N801A-S4_5 弹夹扫码
- // try
- // {
- // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
- // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
- // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
- // {
- // if (d5BulletclipScanCode == 1) // 0->1
- // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
- // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_5 弹夹扫码
- // // N801A-S4_5 载具扫码 数据
- // #region N801A-S4_5 载具扫码
- // try
- // {
- // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
- // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
- // if (d5VehicleScanCode != d5VehicleScanCodeOld)
- // {
- // if (d5VehicleScanCode == 1) // 0->1
- // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
- // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_5 载具扫码
- // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
- // #region N801A-S4_5 出站接口
- // try
- // {
- // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
- // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
- // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
- // if (d5PLC_FLAG != d5PLC_FLAGOld)
- // {
- // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
- // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
- // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
- // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_5 出站接口
- // // N801A-S4_5 节拍接口 数据
- // #region N801A-S4_5 节拍接口
- // try
- // {
- // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
- // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
- // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
- // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
- // {
- // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
- // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
- // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
- // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_5 节拍接口
- // #region 心跳
- // try
- // {
- // short states = 0;
- // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 心跳
- // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- // stopwatch1.Stop();
- // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- // }
- // else
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
- // Funs[plcNo].Connect();
- // }
- // }
- // catch (Exception ex)
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
- // Funs[plcNo].ReConnect();
- // }
- // Thread.Sleep(IntervalReadPLC);
- // }
- //}
- /// <summary>
- /// [S4] 取放桁架 - S4_1弹夹扫码
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_1弹夹扫码(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 弹夹扫码
- string d1BulletclipCode = " "; // 扫到的码
- short d1BulletclipScanCode = 2;
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1BulletclipScanCode";
- writeToPLC_Flag.Adress = 2002;
- writeToPLC_Flag.Value = d1BulletclipScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
- {
- Name = "d1BulletclipCode",
- Adress = 2003,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d1BulletclipCode
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1BulletclipScanCode";
- writeToPLC_Flag.Adress = 2002;
- writeToPLC_Flag.Value = (short)6;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
- {
- Name = "d1BulletclipCode",
- Adress = 2003,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = " "
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_1载具扫码
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_1载具扫码(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 载具扫码
- string d1VehicleCode = ""; // 扫到的码
- short d1VehicleScanCode = 2;
- #region 进站
- if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
- {
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d1VehicleScanCode";
- writeToPLC_Flag1.Adress = 2033;
- writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
- writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d1VehicleCode",
- Adress = 2034,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = cavityData.Split('.');
- string partNo = "";
- if (cavitySNs != null && cavitySNs.Length >= 1)
- {
- partNo = cavitySNs[0];
- }
- #endregion 查询载具上的产品信息
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = d1VehicleCode,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
- stopwatch2.Stop();
- d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
- }
- #endregion 进站
- //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1VehicleScanCode";
- writeToPLC_Flag.Adress = 2033;
- writeToPLC_Flag.Value = d1VehicleScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d1VehicleCode",
- Adress = 2034,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d1VehicleCode
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1VehicleScanCode";
- writeToPLC_Flag.Adress = 2033;
- writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d1VehicleCode",
- Adress = 2034,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_1出站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_1出站接口
- /// </summary>
- private void S4_1出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
- d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
- string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
- d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
- string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
- d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
- string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
- d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
- string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
- d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
- string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
- d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
- string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
- d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
- string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
- d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
- string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
- d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
- string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
- d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
- string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
- d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
- string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
- d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
- string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
- d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
- string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
- d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
- string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
- d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
- int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
- bool pass = d1Result == 1;
- // 存 载具SN列表
- List<string> vehicleCodes = new List<string>()
- {
- d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
- d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
- d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
- };
- // 统一查 产品SN列表
- List<string> partNos = new List<string>();
- foreach (string vehicleCode in vehicleCodes)
- {
- if (string.IsNullOrEmpty(vehicleCode))
- partNos.Add("");
- else
- {
- string partNo = "";
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d1MES_FLAG";
- writeToPLC_Flag1.Adress = 2065;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = cavityData.Split('.');
- if (cavitySNs != null && cavitySNs.Length >= 1)
- partNo = cavitySNs[0];
- #endregion 查询载具上的产品信息
- partNos.Add(partNo);
- }
- }
- // 统一上传
- stopwatch2.Start();
- List<int> results = new List<int>();
- for (int i = 0; i < partNos.Count; i++)
- {
- string index = (i + 1).ToString(); // 弹夹穴号
- if (string.IsNullOrEmpty(partNos[i]))
- results.Add(1);
- else
- {
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹穴号",
- Parameter_value = index,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = d1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
- , workorder_code, mtltmrk, partNos[i], pass, sn, index);
- results.Add(result1);
- }
- }
- short result = 0;
- if (results.All(a => a == 1))
- result = 1;
- else if (results.Contains(3))
- result = 3;
- else if (results.Contains(2))
- result = 2;
- else if (results.Contains(4))
- result = 4;
- else
- result = 4;
- stopwatch2.Stop();
- #region 存储绑定数据到 边线MES系统中
- if (result == 1)
- {
- string data = string.Join(".", vehicleCodes);
- int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
- if (resultMesR != 0)
- {
- result = 4;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
- }
- }
- #endregion 存储绑定数据到 边线MES系统中
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1MES_FLAG";
- writeToPLC_Flag.Adress = 2065;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1MES_FLAG";
- writeToPLC_Flag.Adress = 2065;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_1节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_1节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
- string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
- d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2398;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- string d1OEEPartNo = string.Empty; // 物料码
- if (string.IsNullOrEmpty(d1OEEProductSN))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2398;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else
- { // 查产品SN ZS
- d1OEEPartNo = "Test";
- }
- short d1OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
- d1OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2398;
- writeToPLC_Flag.Value = d1OEEMES_FLAG;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2398;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_2桁架
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_2桁架(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 弹夹扫码
- string d2BulletclipCode = " "; // 扫到的码
- short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
- short d2BulletclipScanCode = 2;
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
- //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d2BulletclipScanCode";
- writeToPLC_Flag.Adress = 2430;
- writeToPLC_Flag.Value = d2BulletclipScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d2BulletclipCode",
- Adress = 2432,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d2BulletclipCode
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d2BulletclipStates",
- Adress = 2431,
- ValueType = PLCValueType.Short,
- Value = d2BulletclipStates
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
- Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
- // MES_Flag
- Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d2BulletclipScanCode";
- writeToPLC_Flag.Adress = 2430;
- writeToPLC_Flag.Value = (short)6;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d2BulletclipCode",
- Adress = 2432,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = " "
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d2BulletclipStates",
- Adress = 2431,
- ValueType = PLCValueType.Short,
- Value = (short)0
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_3进站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_3进站接口(提升机1)
- /// </summary>
- private void S4_3进站接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
- #region 查询15个载具码
- List<string> vehicleCodes = new List<string>(); // 15个载具码
- string vehicleData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
- if (string.IsNullOrEmpty(vehicleData))
- vehicleData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d3MES_FLAG";
- writeToPLC_Flag1.Adress = 2463;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = vehicleData.Split('.');
- if (cavitySNs != null && cavitySNs.Length > 0)
- {
- for (int i = 0; i < cavitySNs.Length; i++)
- {
- if (string.IsNullOrEmpty(cavitySNs[i]))
- vehicleCodes.Add("");
- else
- vehicleCodes.Add(cavitySNs[i]);
- }
- }
- #endregion 查询15个载具码
- #region 查询15个产品SN
- List<string> portNos = new List<string>(); // 15个产品SN
- foreach (string vehicleCode in vehicleCodes)
- {
- if (string.IsNullOrEmpty(vehicleCode))
- portNos.Add("");
- else
- {
- // 查询
- string cavityData = string.Empty;
- int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult1 != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d3MES_FLAG";
- writeToPLC_Flag1.Adress = 2463;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] partSNs = cavityData.Split('.');
- if (partSNs != null && partSNs.Length >= 1)
- portNos.Add(partSNs[0]);
- else
- portNos.Add("");
- }
- }
- #endregion 查询15个产品SN
- // 调用MES进站(最多15个)
- stopwatch2.Start();
- List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
- for (int i = 0; i < vehicleCodes.Count; i++)
- {
- // 循环进站
- if (!string.IsNullOrEmpty(vehicleCodes[i]))
- {
- // 产品SN(物料码)校验
- string portNo = portNos[i];
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹穴位",
- Parameter_value = (i + 1).ToString(),
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
- }
- }
- stopwatch2.Stop();
- short result = 0;
- bool haveMesWarn = results.Contains(5);
- bool havePCWarn = results.Contains(6);
- if (haveMesWarn)
- result = 2; // 5->2
- else if (havePCWarn)
- result = 6; // 6->4
- else
- result = 1;
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d3MES_FLAG";
- writeToPLC_Flag.Adress = 2463;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Stop();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d3MES_FLAG";
- writeToPLC_Flag.Adress = 2463;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_3出站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_3出站接口(提升机1)
- /// </summary>
- private void S4_3出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
- bool isPass = d3Result == 1; // 产品结果 bool
- #region 查询15个载具码
- List<string> vehicleCodes = new List<string>(); // 15个载具码
- string vehicleData = string.Empty;
- int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
- if (string.IsNullOrEmpty(vehicleData))
- vehicleData = "";
- if (snResult1 != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d3MES_FLAG";
- writeToPLC_Flag1.Adress = 2463;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = vehicleData.Split('.');
- if (cavitySNs != null && cavitySNs.Length > 0)
- {
- for (int i = 0; i < cavitySNs.Length; i++)
- {
- if (string.IsNullOrEmpty(cavitySNs[i]))
- vehicleCodes.Add("");
- else
- vehicleCodes.Add(cavitySNs[i]);
- }
- }
- #endregion 查询15个载具码
- // 统一查 产品SN列表
- List<string> partNos = new List<string>();
- foreach (string vehicleCode in vehicleCodes)
- {
- if (string.IsNullOrEmpty(vehicleCode))
- partNos.Add("");
- else
- {
- string partNo = "";
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d3MES_FLAG";
- writeToPLC_Flag1.Adress = 2463;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] partSNs = cavityData.Split('.');
- if (partSNs != null && partSNs.Length >= 1)
- partNo = partSNs[0];
- #endregion 查询载具上的产品信息
- partNos.Add(partNo);
- }
- }
- // 统一上传 - 调用MES出站
- stopwatch2.Start();
- List<int> results = new List<int>();
- for (int i = 0; i < partNos.Count; i++)
- {
- string index = (i + 1).ToString(); // 弹夹穴号
- if (string.IsNullOrEmpty(partNos[i]))
- results.Add(1);
- else
- {
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹穴号",
- Parameter_value = index,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = d3Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
- , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
- results.Add(result1);
- }
- }
- short result = 0;
- if (results.All(a => a == 1))
- result = 1;
- else if (results.Contains(3))
- result = 3;
- else if (results.Contains(2))
- result = 2;
- else if (results.Contains(4))
- result = 4;
- else
- result = 4;
- stopwatch2.Stop();
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d3MES_FLAG";
- writeToPLC_Flag.Adress = 2463;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d3MES_FLAG";
- writeToPLC_Flag.Adress = 2463;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_4进站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_4进站接口(提升机2)
- /// </summary>
- private void S4_4进站接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
- #region 查询15个载具码
- List<string> vehicleCodes = new List<string>(); // 15个载具码
- string vehicleData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
- if (string.IsNullOrEmpty(vehicleData))
- vehicleData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d3MES_FLAG";
- writeToPLC_Flag1.Adress = 2463;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = vehicleData.Split('.');
- if (cavitySNs != null && cavitySNs.Length > 0)
- {
- for (int i = 0; i < cavitySNs.Length; i++)
- {
- if (string.IsNullOrEmpty(cavitySNs[i]))
- vehicleCodes.Add("");
- else
- vehicleCodes.Add(cavitySNs[i]);
- }
- }
- #endregion 查询15个载具码
- #region 查询15个产品SN
- List<string> portNos = new List<string>(); // 15个产品SN
- foreach (string vehicleCode in vehicleCodes)
- {
- if (string.IsNullOrEmpty(vehicleCode))
- portNos.Add("");
- else
- {
- // 查询
- string cavityData = string.Empty;
- int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult1 != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d3MES_FLAG";
- writeToPLC_Flag1.Adress = 2463;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] partSNs = cavityData.Split('.');
- if (partSNs != null && partSNs.Length >= 1)
- portNos.Add(partSNs[0]);
- else
- portNos.Add("");
- }
- }
- #endregion 查询15个产品SN
- // 调用MES进站(最多15个)
- stopwatch2.Start();
- List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
- for (int i = 0; i < vehicleCodes.Count; i++)
- {
- // 循环进站
- if (!string.IsNullOrEmpty(vehicleCodes[i]))
- {
- // 产品SN(物料码)校验
- string portNo = portNos[i];
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹穴位",
- Parameter_value = (i + 1).ToString(),
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
- }
- }
- stopwatch2.Stop();
- short result = 0;
- bool haveMesWarn = results.Contains(5);
- bool havePCWarn = results.Contains(6);
- if (haveMesWarn)
- result = 2; // 5->2
- else if (havePCWarn)
- result = 6; // 6->4
- else
- result = 1;
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d4MES_FLAG";
- writeToPLC_Flag.Adress = 2496;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Stop();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d4MES_FLAG";
- writeToPLC_Flag.Adress = 2496;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_4出站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_4出站接口(提升机2)
- /// </summary>
- private void S4_4出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
- bool isPass = d4Result == 1; // 产品结果 bool
- #region 查询15个载具码
- List<string> vehicleCodes = new List<string>(); // 15个载具码
- string vehicleData = string.Empty;
- int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
- if (string.IsNullOrEmpty(vehicleData))
- vehicleData = "";
- if (snResult1 != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d4MES_FLAG";
- writeToPLC_Flag1.Adress = 2496;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = vehicleData.Split('.');
- if (cavitySNs != null && cavitySNs.Length > 0)
- {
- for (int i = 0; i < cavitySNs.Length; i++)
- {
- if (string.IsNullOrEmpty(cavitySNs[i]))
- vehicleCodes.Add("");
- else
- vehicleCodes.Add(cavitySNs[i]);
- }
- }
- #endregion 查询15个载具码
- // 统一查 产品SN列表
- List<string> partNos = new List<string>();
- foreach (string vehicleCode in vehicleCodes)
- {
- if (string.IsNullOrEmpty(vehicleCode))
- partNos.Add("");
- else
- {
- string partNo = "";
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d4MES_FLAG";
- writeToPLC_Flag1.Adress = 2496;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] partSNs = cavityData.Split('.');
- if (partSNs != null && partSNs.Length >= 1)
- partNo = partSNs[0];
- #endregion 查询载具上的产品信息
- partNos.Add(partNo);
- }
- }
- // 调用MES出站
- stopwatch2.Start();
- // 统一上传
- List<int> results = new List<int>();
- for (int i = 0; i < partNos.Count; i++)
- {
- string index = (i + 1).ToString(); // 弹夹穴号
- if (string.IsNullOrEmpty(partNos[i]))
- results.Add(1);
- else
- {
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹穴号",
- Parameter_value = index,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = d4Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
- , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
- results.Add(result1);
- }
- }
- short result = 0;
- if (results.All(a => a == 1))
- result = 1;
- else if (results.Contains(3))
- result = 3;
- else if (results.Contains(2))
- result = 2;
- else if (results.Contains(4))
- result = 4;
- else
- result = 4;
- stopwatch2.Stop();
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d4MES_FLAG";
- writeToPLC_Flag.Adress = 2496;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d4MES_FLAG";
- writeToPLC_Flag.Adress = 2496;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_5弹夹扫码
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_5弹夹扫码(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 弹夹扫码
- string d5BulletclipCode = " "; // 扫到的码
- short d5BulletclipScanCode = 2;
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5BulletclipScanCode";
- writeToPLC_Flag.Adress = 2528;
- writeToPLC_Flag.Value = d5BulletclipScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5BulletclipCode",
- Adress = 2529,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d5BulletclipCode
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5BulletclipScanCode";
- writeToPLC_Flag.Adress = 2528;
- writeToPLC_Flag.Value = (short)6;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5BulletclipCode",
- Adress = 2529,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = " "
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_5载具扫码
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_5载具扫码(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 载具扫码
- string d5VehicleCode = " "; // 扫到的码
- short d5VehicleScanCode = 2;
- #region 进站
- if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
- {
- // 查产品SN
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d5VehicleScanCode";
- writeToPLC_Flag1.Adress = 2559;
- writeToPLC_Flag1.Value = (short)6;
- writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5VehicleCode",
- Adress = 2560,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = cavityData.Split('.');
- string partNo = "";
- if (cavitySNs != null && cavitySNs.Length >= 1)
- {
- partNo = cavitySNs[0];
- }
- #endregion 查询载具上的产品信息
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = d5VehicleCode,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
- stopwatch2.Stop();
- d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
- }
- #endregion 进站
- //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5VehicleScanCode";
- writeToPLC_Flag.Adress = 2559;
- writeToPLC_Flag.Value = d5VehicleScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5VehicleCode",
- Adress = 2560,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d5VehicleCode
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5VehicleScanCode";
- writeToPLC_Flag.Adress = 2559;
- writeToPLC_Flag.Value = (short)6;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5VehicleCode",
- Adress = 2560,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = " "
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_5出站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_5出站接口
- /// </summary>
- private void S4_5出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
- d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
- string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
- d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
- string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
- d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
- string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
- d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
- string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
- d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
- string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
- d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
- string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
- d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
- string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
- d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
- string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
- d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
- string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
- d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
- string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
- d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
- string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
- d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
- string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
- d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
- string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
- d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
- string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
- d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
- int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
- bool pass = d5Result == 1;
- // 存 载具SN列表
- List<string> vehicleCodes = new List<string>()
- {
- d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
- d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
- d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
- };
- // 统一查 产品SN列表
- List<string> partNos = new List<string>();
- foreach (string vehicleCode in vehicleCodes)
- {
- if (string.IsNullOrEmpty(vehicleCode))
- partNos.Add("");
- else
- {
- string partNo = "";
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d5MES_FLAG";
- writeToPLC_Flag1.Adress = 2591;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = cavityData.Split('.');
- if (cavitySNs != null && cavitySNs.Length >= 1)
- partNo = cavitySNs[0];
- #endregion 查询载具上的产品信息
- partNos.Add(partNo);
- }
- }
- // 统一上传
- stopwatch2.Start();
- List<int> results = new List<int>();
- for (int i = 0; i < partNos.Count; i++)
- {
- string index = (i + 1).ToString(); // 弹夹穴号
- if (string.IsNullOrEmpty(partNos[i]))
- results.Add(1);
- else
- {
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹穴号",
- Parameter_value = index,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = d5Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
- , workorder_code, mtltmrk, partNos[i], pass, sn, index);
- results.Add(result1);
- }
- }
- short result = 0;
- if (results.All(a => a == 1))
- result = 1;
- else if (results.Contains(3))
- result = 3;
- else if (results.Contains(2))
- result = 2;
- else if (results.Contains(4))
- result = 4;
- else
- result = 4;
- stopwatch2.Stop();
- #region 存储绑定数据到 边线MES系统中
- if (result == 1)
- {
- // 删除绑定信息
- int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
- if (resultMesR != 0)
- {
- result = 4;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
- }
- }
- #endregion 存储绑定数据到 边线MES系统中
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5MES_FLAG";
- writeToPLC_Flag.Adress = 2591;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5MES_FLAG";
- writeToPLC_Flag.Adress = 2591;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_5节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_5节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
- string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
- d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2924;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- string d5OEEPartNo = string.Empty; // 物料码
- if (string.IsNullOrEmpty(d5OEEProductSN))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2924;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else
- { // 查产品SN
- d5OEEPartNo = "Test"; // ZS
- }
- short d5OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
- d5OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2924;
- writeToPLC_Flag.Value = d5OEEMES_FLAG;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2924;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S4] 取放桁架
- #endregion PLC4 刘果段
- #region PLC5 张超凡
- #region [S5] Tray盘下料装备
- /// <summary>
- /// S5工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S5工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S5工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- /// <summary>
- /// [S5] Tray盘下料装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- //private void ReadStation_S5(int plcNo)
- //{
- // // [S1] Tray盘上料装备
- // // [S2] FCT
- // // [S3] 值板机
- // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
- // // [S5] Tray盘下料装备
- // /// 上位机心跳
- // /// 获取设备报警数据与状态信息
- // string stationCode = "[S5]";
- // string stationName = "Tray盘下料装备";
- // string stationNameStr = stationCode + stationName;
- // #region 创建字典
- // // 触发信号字典 赋值
- // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
- // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
- // // PLC数据字典 赋值
- // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
- // s5PLCData.Add("e1ProductSN_Check", ""); //
- // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
- // s5PLCData.Add("e1ProductSN", ""); // 产品SN
- // s5PLCData.Add("e1PartNo", ""); // 物料码
- // s5PLCData.Add("e1Result", 0); // 产品结果
- // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
- // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
- // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
- // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
- // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
- // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
- // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
- // #endregion 创建字典
- // while (IsRun)
- // {
- // try
- // {
- // if (!GlobalContext._IsCon_Funs5)
- // {
- // UpdatePLCMonitor(1, plcNo, 0);
- // continue;
- // }
- // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- // {
- // Stopwatch stopwatch1 = new Stopwatch();
- // Stopwatch stopwatch2 = new Stopwatch();
- // stopwatch1.Start();
- // stopwatch2.Start();
- // #region 一次性读取所有数据
- // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
- // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
- // int[] datas = data1.Concat(data2).ToArray();
- // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
- // s5PLCData["e1MES_FLAG_Check"] = datas[3];
- // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
- // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
- // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
- // s5PLCData["e1MES_FLAG"] = datas[35];
- // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
- // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
- // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
- // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
- // s5PLCData["e1Result"] = datas[76];
- // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
- // s5PLCData["e1OEEMES_FLAG"] = datas[88];
- // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
- // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
- // s5PLCData["e1OEEType"] = datas[109];
- // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
- // s5PLCData["e1AGVUpStart"] = datas[121];
- // s5PLCData["e1AGVUpEnd"] = datas[122];
- // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
- // s5PLCData["e1AGVDownStart"] = datas[134];
- // s5PLCData["e1AGVDownEnd"] = datas[135];
- // #endregion 一次性读取所有数据
- // stopwatch2.Stop();
- // #region 回写操作,写后清空flag
- // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
- // #endregion 回写操作,写后清空flag
- // #region 进站校验
- // try
- // {
- // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
- // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
- // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
- // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
- // {
- // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
- // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
- // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 进站校验
- // #region 出站接口
- // try
- // {
- // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
- // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
- // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
- // if (e1PLC_FLAG != e1PLC_FLAGOld)
- // {
- // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
- // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
- // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
- // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 出站接口
- // #region 节拍接口
- // try
- // {
- // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
- // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
- // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
- // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
- // {
- // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
- // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
- // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
- // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 节拍接口
- // #region AGV上料
- // // AGV上料叫AGV信号
- // try
- // {
- // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
- // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
- // if (e1AGVUpCall != e1AGVUpCallOld)
- // {
- // if (e1AGVUpCall == 1) // 0->1
- // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
- // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // // AGV上料完成信号
- // try
- // {
- // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
- // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
- // if (e1AGVUpEnd != e1AGVUpEndOld)
- // {
- // if (e1AGVUpEnd == 1) // 0->1
- // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
- // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion AGV上料
- // #region AGV下料
- // // AGV下料叫agv信号
- // try
- // {
- // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
- // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
- // if (e1AGVDownCall != e1AGVDownCallOld)
- // {
- // if (e1AGVDownCall == 1) // 0->1
- // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
- // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // // AGV下料完成信号
- // try
- // {
- // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
- // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
- // if (e1AGVDownEnd != e1AGVDownEndOld)
- // {
- // if (e1AGVDownEnd == 1) // 0->1
- // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
- // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion AGV下料
- // #region 心跳
- // try
- // {
- // short states = 0;
- // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 心跳
- // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- // stopwatch1.Stop();
- // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- // }
- // else
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- // Funs[plcNo].Connect();
- // }
- // }
- // catch (Exception ex)
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- // Funs[plcNo].ReConnect();
- // }
- // Thread.Sleep(IntervalReadPLC);
- // }
- //}
- /// <summary>
- /// [S5] Tray盘下料装备 - 进站校验
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5进站校验(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
- sn = sn.Replace("\0", "");
- // 获取产品SN By 载具码
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
- writeToPLC_Flag1.Adress = 2003;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = cavityData.Split('.');
- string partNo = string.Empty;
- if (cavitySNs != null && cavitySNs.Length >= 1)
- partNo = cavitySNs[0];
- #endregion 查询载具上的产品信息
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
- stopwatch2.Stop();
- short e1MES_FLAG_Check = (short)result;
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = e1MES_FLAG_Check;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - 出站接口
- /// </summary>
- /// <param name="plcNo"></param>
- /// <param name="stationCode"></param>
- /// <param name="stationName"></param>
- private void S5出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
- sn = sn.Replace("\0", "");
- //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
- //partNo = partNo.Replace("\0", "");
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "e1MES_FLAG";
- writeToPLC_Flag1.Adress = 2035;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = cavityData.Split('.');
- string partNo = string.Empty;
- if (cavitySNs != null && cavitySNs.Length >= 1)
- partNo = cavitySNs[0];
- #endregion 查询载具上的产品信息
- int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
- bool pass = e1Result == 1;
- stopwatch2.Start();
- // 上传MES
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = e1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
- , workorder_code, mtltmrk, partNo, pass, sn, "1");
- //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
- short result = result1 == 1 ? (short)1 : (short)3;
- stopwatch2.Stop();
- #region 存储绑定数据到 边线MES系统中
- if (result == 1)
- {
- // 删除绑定信息
- int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
- if (resultMesR != 0)
- {
- result = 4;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
- }
- }
- #endregion 存储绑定数据到 边线MES系统中
- // MES_Flag 为MES报错
- // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1MES_FLAG";
- writeToPLC_Flag.Adress = 2035;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1MES_FLAG";
- writeToPLC_Flag.Adress = 2035;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - 节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
- string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
- e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2088;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- string e1OEEPartNo = string.Empty; // 物料码
- if (string.IsNullOrEmpty(e1OEEProductSN))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2088;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else
- { // 查产品SN
- e1OEEPartNo = "Test"; // ZS
- }
- short e1OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
- e1OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2088;
- writeToPLC_Flag.Value = e1OEEMES_FLAG;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2088;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - AGV上料叫agv
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5AGV上料叫agv(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 呼叫AGV
- short e1AGVUpCall = 2;
- stopwatch2.Start();
- // e1AGVUpCall
- //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVUpCall";
- writeToPLC_Flag.Adress = 2120;
- writeToPLC_Flag.Value = e1AGVUpCall;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // e1AGVUpCall
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVUpCall";
- writeToPLC_Flag.Adress = 2120;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - AGV上料完成
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5AGV上料完成(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS AGV上料完成,让小车离开
- short e1AGVUpEnd = 2;
- stopwatch2.Start();
- // e1AGVUpEnd
- //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVUpEnd";
- writeToPLC_Flag.Adress = 2122;
- writeToPLC_Flag.Value = e1AGVUpEnd;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // e1AGVUpEnd
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVUpEnd";
- writeToPLC_Flag.Adress = 2122;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - AGV下料叫agv
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5AGV下料叫agv(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 呼叫AGV
- short e1AGVDownCall = 2;
- stopwatch2.Start();
- // e1AGVDownCall
- //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVDownCall";
- writeToPLC_Flag.Adress = 2133;
- writeToPLC_Flag.Value = e1AGVDownCall;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // e1AGVDownCall
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVDownCall";
- writeToPLC_Flag.Adress = 2133;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - AGV下料完成
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5AGV下料完成(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS AGV上料完成,让小车离开
- short e1AGVDownEnd = 2;
- stopwatch2.Start();
- // e1AGVDownEnd
- //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVDownEnd";
- writeToPLC_Flag.Adress = 2135;
- writeToPLC_Flag.Value = e1AGVDownEnd;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // e1AGVDownEnd
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVDownEnd";
- writeToPLC_Flag.Adress = 2135;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S5] Tray盘下料装备
- #endregion PLC5 张超凡
- #region 缓存读取到的PLC数据 与 需要写入的PLC数据
- /// <summary>
- /// PLC读取到的数据 -添加数据
- /// </summary>
- public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
- {
- if (sxPlcData.ContainsKey(newKey))
- sxPlcData[newKey] = newValue;
- else
- sxPlcData.Add(newKey, newValue);
- }
- /// <summary>
- /// PLC需要写入的数据 -添加数据
- /// </summary>
- public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
- {
- if (sxPLCWriteData.ContainsKey(newKey))
- sxPLCWriteData[newKey] = newValue;
- else
- sxPLCWriteData.Add(newKey, newValue);
- }
- /// <summary>
- /// PLC回写操作,写后清空flag
- /// </summary>
- /// <param name="modbusClient">modbus对象</param>
- /// <param name="pLCReadDatas">读取到的数据字典</param>
- /// <param name="pLCWriteDatas">需要写入的数据</param>
- public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
- {
- if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
- {
- List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
- for (int i = 0; i < pLCWriteDatas.Count; i++)
- {
- string mesFlagName = pLCWriteDatas[i].Name;
- int mesFlagAdress = pLCWriteDatas[i].Adress;
- short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
- if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
- {
- // 先回写数据
- List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
- for (int j = 0; j < writeToPLCDatas.Count; j++)
- {
- int mesDataAdress = writeToPLCDatas[j].Adress;
- PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
- switch (mesDataType)
- {
- case PLCValueType.Short:
- short mesDataValueShort = (short)writeToPLCDatas[j].Value;
- modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
- break;
- case PLCValueType.String:
- string mesDataValueStr = (string)writeToPLCDatas[j].Value;
- int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
- modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
- break;
- }
- }
- // 再回写信号
- modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
- // 存储读取数据的字典
- pLCReadDatas[mesFlagName] = (int)mesFlagValue;
- // 存储写入数据的字典 - 清空写入值
- pLCWriteDatas[i].Value = (short)0;
- pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
- }
- }
- }
- }
- /// <summary>
- /// 提交点检数据到MES - 取数据库中缓存的 点检数据
- /// </summary>
- /// <param name="no">3</param>
- /// <param name="stationCode">设备编号</param>
- /// <param name="stationNameStr">设备名称</param>
- /// <param name="plcOrder">车间订单号</param>
- private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
- {
- try
- {
- /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
- /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
- /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
- /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
- int result1 = 0;
- switch (stationCode)
- {
- case 2:
- case 3:
- case 4:
- case 6:
- result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
- break;
- case 102:
- result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
- break;
- case 103:
- result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
- break;
- case 104:
- result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
- break;
- case 106:
- result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
- break;
- default:
- // MES_Flag 为“6未找到正确设备编号”
- Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
- return;
- }
- short result = result1 == 1 ? (short)1 : (short)2;
- Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
- OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- // MES_Flag 为2上位机报错
- Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- }
- #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
- #region UI刷新
- /// <summary>
- /// 更新商品信息的UI + 下发产品信息(SN)
- /// </summary>
- private void UpdateProductInfo()
- {
- currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
- currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
- //currentBN.Text = GlobalContext.BatchNumber; // 批次号
- //txt_CurSupplierCode.Text = ""; // 供应商代号
- }
- /// <summary>
- /// 更新PLC连接状态的UI
- /// </summary>
- /// <param name="no">PLC编号</param>
- /// <param name="status">状态</param>
- private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
- {
- if (this != null && !this.IsDisposed)
- {
- switch (imgNo)
- {
- case 1:
- this.BeginInvoke(new Action(() =>
- {
- picPLC.Image = imageListState.Images[status];
- }));
- break;
- case 2:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox2.Image = imageListState.Images[status];
- }));
- break;
- case 3:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox3.Image = imageListState.Images[status];
- }));
- break;
- case 4:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox4.Image = imageListState.Images[status];
- }));
- break;
- case 5:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox5.Image = imageListState.Images[status];
- }));
- break;
- case 6:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox6.Image = imageListState.Images[status];
- }));
- break;
- case 7:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox7.Image = imageListState.Images[status];
- }));
- break;
- case 8:
- this.BeginInvoke(new Action(() =>
- {
- pictureBox8.Image = imageListState.Images[status];
- }));
- break;
- default:
- break;
- }
- }
- Task.Run(() => // 更新PLC交互页的指示灯
- {
- try
- {
- if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
- {
- Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
- }
- }
- catch { }
- });
- }
- #endregion UI刷新
- #region 日志
- /// <summary>
- /// 添加各工位运行日志(同步至PLC交互页面)
- /// </summary>
- /// <param name="stationNameStr">工站名称</param>
- /// <param name="logType">日志类型</param>
- /// <param name="message">日志内容</param>
- /// <param name="snNumber">产品数字SN</param>
- public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
- {
- if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
- && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
- ))
- {
- AddMessage(logType, message); // 首页展示+日志记录
- }
- PLCDBFormMessage plcMessage = new PLCDBFormMessage()
- {
- StationName = stationNameStr,
- SnNumber = snNumber,
- Message = message,
- CreateTime = DateTime.Now
- };
- // PLC交互页展示
- Task.Run(() =>
- {
- try
- {
- if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
- {
- Form_Main.formPLCDB.UpdateMessage(plcMessage);
- }
- }
- catch { }
- });
- }
- /// <summary>
- /// 添加运行日志
- /// </summary>
- /// <param name="logType">日志类型</param>
- /// <param name="message">日志内容</param>
- public void AddMessage(LogType logType, string message)
- {
- OnMessage(logType, message);
- string date = DateTime.Now.ToString("yyyy/MM/dd");
- string time = DateTime.Now.ToString("HH:mm:ss:fff");
- string msgShow = time + "--> " + message + "\r\n";
- this.BeginInvoke(new Action(() =>
- {
- systemLog.Rows.Insert(0, date, time, message);
- if (systemLog.Rows.Count >= 100)
- systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
- }));
- }
- /// <summary>
- /// 添加运行日志-保存
- /// </summary>
- /// <param name="logType">日志类型</param>
- /// <param name="message">日志内容</param>
- private void OnMessage(LogType logType, string msg)
- {
- MessageEvent?.Invoke(logType, msg);
- }
- /// <summary>
- /// 保存PLC写入日志
- /// </summary>
- /// <param name="logType"></param>
- /// <param name="logValue"></param>
- private void WritePLCLog(LogType logType, string logValue)
- {
- switch ((int)logType)
- {
- case 0:
- _PLCLogNet.WriteDebug(logValue);
- break;
- case 1:
- _PLCLogNet.WriteInfo(logValue);
- break;
- case 2:
- _PLCLogNet.WriteWarn(logValue);
- break;
- case 3:
- _PLCLogNet.WriteError(logValue);
- break;
- default:
- _PLCLogNet.WriteFatal(logValue);
- break;
- }
- }
- /// <summary>
- /// IOT Mqtt回调方法- With DataId
- /// </summary>
- /// <param name="id"></param>
- /// <param name="v"></param>
- /// <param name="dataId"></param>
- public void CallbackWithDataId(string id, string msg, string dataId)
- {
- //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
- //byte[] buffer1 = Encoding.Default.GetBytes(v);
- //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
- //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
- //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
- string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
- _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
- }
- /// <summary>
- /// AGV Mqtt回调方法- 记录Log并处理数据
- /// </summary>
- /// <param name="obj"></param>
- private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
- {
- string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
- _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
- // 接收到的信息
- string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
- string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
- if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
- {
- }
- }
- #endregion 日志
- /// <summary>
- /// 实例化报警字典
- /// </summary>
- private void InitalDicAlarm()
- {
- #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
- List<Alarm> keyValues1 = new List<Alarm>
- {
- #region 第一组报警(电机)
- new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
- new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
- #endregion 第一组报警(电机)
- #region 第二组报警(气缸)
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
- new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
- #endregion 第二组报警(气缸)
- #region 第三组报警(其他故障)
- new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
- new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
- new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
- new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
- new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
- new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
- #endregion 第三组报警(其他故障)
- };
- DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
- #endregion 第一个工站(这里使用线体代替工位)
- # region 第二个工站-原来的写法(废弃)
- //keyValues = new Dictionary<int, AlarmData[]>();
- ////1
- //dicAlarmName = new Dictionary<int, Alarm>();
- //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
- //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
- //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
- //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
- //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
- //alarmDatas = new AlarmData[dicAlarmName.Count];
- //for (int i = 0; i < dicAlarmName.Count; i++)
- //{
- // alarmDatas[i] = new AlarmData();
- // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
- // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
- // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
- // alarmDatas[i].AlarmType = 1;
- //}
- //keyValues.Add(1, alarmDatas);
- ////2
- //dicAlarmName = new Dictionary<int, Alarm>();
- //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
- //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
- //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
- //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
- //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
- //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
- //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
- //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
- //alarmDatas = new AlarmData[dicAlarmName.Count];
- //for (int i = 0; i < dicAlarmName.Count; i++)
- //{
- // alarmDatas[i] = new AlarmData();
- // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
- // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
- // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
- // alarmDatas[i].AlarmType = 2;
- //}
- //keyValues.Add(2, alarmDatas);
- ////3
- //dicAlarmName = new Dictionary<int, Alarm>();
- //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
- //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
- //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
- //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
- //alarmDatas = new AlarmData[dicAlarmName.Count];
- //for (int i = 0; i < dicAlarmName.Count; i++)
- //{
- // alarmDatas[i] = new AlarmData();
- // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
- // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
- // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
- // alarmDatas[i].AlarmType = 3;
- //}
- //keyValues.Add(3, alarmDatas);
- //DicAlarms.Add(2, keyValues);
- #endregion 第二个工站-原来的写法(废弃)
- }
- private void button1_Click(object sender, EventArgs e)
- {
- OpenDailogFalg=true;
- if (OpenDailogFalg)
- {
- using (var dialog = new BandBarodeDialog())
- {
- string strCarrierBarcode = "N801A-003";
- dialog._CarrierBarcode = strCarrierBarcode;
- string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- dialog._ProductBarcode = sn;
- var rs = dialog.ShowDialog();
- if (rs == DialogResult.OK)
- {
- AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
- OpenDailogFalg = false;//关闭扫码
- }
- }
- }
- }
- }
- }
|