Form_Home.cs 679 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. //using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using HslCommunication.Enthernet;
  40. using BZFAStandardLib;
  41. using MainForm.ClassFile;
  42. using NPOI.SS.Formula.Functions;
  43. using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
  44. using System.Net.Http;
  45. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_UpLoadFile;
  46. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
  47. using System.Reflection;
  48. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  49. using FaFrameUI;
  50. using System.Security.Policy;
  51. using static MainForm.ClassFile.XiaomiClass.MesHelper;
  52. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  53. using System.Drawing.Imaging;
  54. using System.Drawing;
  55. using ICSharpCode.SharpZipLib.Zip;
  56. using System.Text.RegularExpressions;
  57. using System.Text;
  58. /*
  59. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  60. */
  61. namespace MainForm
  62. {
  63. /// <summary>
  64. /// 记录日志的委托
  65. /// </summary>
  66. /// <param name="logType">日志类型</param>
  67. /// <param name="message">日志信息</param>
  68. public delegate void HomeMessageHandler(LogType logType, string message);
  69. /// <summary>
  70. /// 主页窗体
  71. /// </summary>
  72. public partial class Form_Home : Form
  73. {
  74. #region 常量
  75. //文本常量
  76. private const string Head = "开始采集";
  77. private const string Tail = "采集完成";
  78. private const string Body = "工位出站数据";
  79. private const string BodyCheck = "工位点检数据";
  80. private const string BodyRun = "整线运行数据";
  81. private const string BodyAlarm = "整线报警数据";
  82. #endregion 常量
  83. #region 变量
  84. /// <summary>
  85. /// 委托-记录日志的方法
  86. /// </summary>
  87. public event HomeMessageHandler MessageEvent;
  88. /// <summary>
  89. /// 日志接口
  90. /// </summary>
  91. ILogNet _PLCLogNet;
  92. /// <summary>
  93. /// 用于记录IOT MQTT日志
  94. /// </summary>
  95. ILogNet _IOTMqttLogNet;
  96. /// <summary>
  97. /// 用于记录AGV MQTT日志
  98. /// </summary>
  99. ILogNet _AGVMqttLogNet;
  100. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  101. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  102. // 间隔时间
  103. private int IntervalReadPLC = 300; //ms 读PLC
  104. private int IntervalMonitorMES = 1000; //ms MES心跳
  105. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  106. /// <summary>
  107. /// 设备报警数据
  108. /// </summary>
  109. uint[] _FaultDatas = { };
  110. uint[] _FaultDatas_Old = { };
  111. uint[] _FaultDatas2 = { };
  112. uint[] _FaultDatas_Old2 = { };
  113. // 软件状态
  114. private bool IsRun = true;
  115. #region PLC 与 TCP对象
  116. // 定义一个字典,存plc对象(通讯)
  117. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  118. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  119. // 定义TCPClient对象列表
  120. Dictionary<int, HPSocket_TcpClientHelper>
  121. _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  122. // 定义MQTTHelper对象
  123. MQTTHelper _MQTTHelper = new MQTTHelper();
  124. #endregion PLC 与 TCP对象
  125. /// <summary>
  126. /// 上次的设备运行信息
  127. /// </summary>
  128. private string lineWorkingData1_OldStr = string.Empty;
  129. /// <summary>
  130. /// 设备报警字典-当前结果
  131. /// Dictionary<工位代码,List<报警信息>>
  132. /// </summary>
  133. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  134. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  135. /// <summary>
  136. /// 单机用-设备状态
  137. /// </summary>
  138. //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  139. XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
  140. private int test_item_num = 0; //iot 过站数据序号
  141. public static string uuid = ""; //单工位或左工位
  142. public static string uuid2 = ""; //右工位
  143. private bool inpass = false; //保存进站测试状态
  144. public static XiaoMiParm xiaomiParm = new XiaoMiParm();
  145. //记录上传附件的信息
  146. public static FileUpload_FileData fileUploadData = new FileUpload_FileData();
  147. #endregion 变量
  148. #region 窗体基础事件
  149. /// <summary>
  150. /// 初始化
  151. /// </summary>
  152. public Form_Home()
  153. {
  154. InitializeComponent();
  155. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  156. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  157. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  158. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  159. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  160. }
  161. /// <summary>
  162. /// 窗体加载事件
  163. /// </summary>
  164. public void Form_Home_Load(object sender, EventArgs e)
  165. {
  166. try
  167. {
  168. AddMessage(LogType.Info, "开始初始化程序");
  169. //组建plc对象字典
  170. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  171. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  172. if (GlobalContext.IsUsePLC1)
  173. {
  174. GlobalContext.IsUsePLCNow = 1;
  175. GlobalContext.IsUseStationName = "[OP10]壳体清洁上料";
  176. FunsEip.Add(GlobalContext.IsUsePLCNow,
  177. new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  178. }
  179. if (GlobalContext.IsUsePLC2)
  180. {
  181. GlobalContext.IsUsePLCNow = 2;
  182. GlobalContext.IsUseStationName = "[OP20]上盖板上料装备";
  183. FunsEip.Add(GlobalContext.IsUsePLCNow,
  184. new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  185. }
  186. if (GlobalContext.IsUsePLC3)
  187. {
  188. GlobalContext.IsUsePLCNow = 3;
  189. GlobalContext.IsUseStationName = "[OP30]点散热胶装备";
  190. FunsEip.Add(GlobalContext.IsUsePLCNow,
  191. new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  192. }
  193. if (GlobalContext.IsUsePLC4)
  194. {
  195. GlobalContext.IsUsePLCNow = 4;
  196. GlobalContext.IsUseStationName = "[OP40]胶线检测";
  197. FunsEip.Add(GlobalContext.IsUsePLCNow,
  198. new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  199. }
  200. if (GlobalContext.IsUsePLC5)
  201. {
  202. GlobalContext.IsUsePLCNow = 5;
  203. GlobalContext.IsUseStationName = "[OP50]ADD板上料组装装备";
  204. FunsEip.Add(GlobalContext.IsUsePLCNow,
  205. new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  206. }
  207. if (GlobalContext.IsUsePLC6)
  208. {
  209. GlobalContext.IsUsePLCNow = 6;
  210. GlobalContext.IsUseStationName = "[OP70]组上盖板";
  211. FunsEip.Add(GlobalContext.IsUsePLCNow,
  212. new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  213. }
  214. if (GlobalContext.IsUsePLC7)
  215. {
  216. GlobalContext.IsUsePLCNow = 7;
  217. GlobalContext.IsUseStationName = "[OP80]上盖板锁螺丝";
  218. FunsEip.Add(GlobalContext.IsUsePLCNow,
  219. new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  220. }
  221. if (GlobalContext.IsUsePLC8)
  222. {
  223. GlobalContext.IsUsePLCNow = 8;
  224. GlobalContext.IsUseStationName = "[OP90]NG下料";
  225. FunsEip.Add(GlobalContext.IsUsePLCNow,
  226. new Inovance_EIP(GlobalContext.PC8Address,
  227. GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  228. }
  229. if (GlobalContext.IsUsePLC9)
  230. {
  231. GlobalContext.IsUsePLCNow = 9;
  232. GlobalContext.IsUseStationName = "[OP100]半成品下料";
  233. FunsEip.Add(GlobalContext.IsUsePLCNow,
  234. new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  235. }
  236. (bool, string) DicResult = InitalDicAlarm(); // 实例化报警字典
  237. AddMessage(LogType.Info, DicResult.Item2);
  238. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  239. {
  240. if (plcEIP != null)
  241. {
  242. try
  243. {
  244. (int, string) result = plcEIP.Connect();
  245. }
  246. catch (Exception ex)
  247. {
  248. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  249. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
  250. MessageBoxOptions.ServiceNotification);
  251. }
  252. }
  253. }
  254. // 采集任务
  255. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  256. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  257. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  258. if (GlobalContext.IsUsePLC1)
  259. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  260. if (GlobalContext.IsUsePLC2)
  261. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  262. if (GlobalContext.IsUsePLC3)
  263. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  264. if (GlobalContext.IsUsePLC4)
  265. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  266. if (GlobalContext.IsUsePLC5)
  267. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  268. if (GlobalContext.IsUsePLC6)
  269. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  270. if (GlobalContext.IsUsePLC7)
  271. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  272. if (GlobalContext.IsUsePLC8)
  273. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  274. if (GlobalContext.IsUsePLC9)
  275. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  276. #region 初始化
  277. try
  278. {
  279. // 开启MES(Http)
  280. if (GlobalContext.IsUseMES)
  281. {
  282. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  283. if (mesret)
  284. {
  285. picMESStatus.Image = imageListState.Images[1];
  286. GlobalContext.MESIsConnect = true;
  287. AddMessage(LogType.Info, "小米MES初始连接成功!");
  288. }
  289. else
  290. {
  291. picMESStatus.Image = imageListState.Images[0];
  292. GlobalContext.MESIsConnect = false;
  293. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  294. }
  295. }
  296. // 开启IOT(MQTT)
  297. if (GlobalContext.IsUseIot)
  298. {
  299. string addr = GlobalContext.MQTTServerHost;
  300. int port = GlobalContext.MQTTServerPort;
  301. //生产环境需要修改
  302. (int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666,
  303. GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  304. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
  305. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  306. {
  307. picIot.Image = imageListState.Images[1];
  308. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  309. // 设置回调函数
  310. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  311. // 配置参数
  312. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  313. // fds
  314. param.parameter.fds.address = GlobalContext.address;
  315. param.parameter.fds.appId = GlobalContext.appId;
  316. param.parameter.fds.appKey = GlobalContext.appKey;
  317. // mes
  318. param.parameter.mes.address = GlobalContext.ServerIp;
  319. param.parameter.mes.appId = GlobalContext.MESAppId;
  320. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  321. // mqtt
  322. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  323. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  324. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  325. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  326. // 设备配置
  327. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  328. if (GlobalContext.IsUsePLC1)
  329. {
  330. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  331. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  332. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  333. }
  334. if (GlobalContext.IsUsePLC2)
  335. {
  336. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  337. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  338. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  339. }
  340. if (GlobalContext.IsUsePLC3)
  341. {
  342. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  343. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  344. }
  345. if (GlobalContext.IsUsePLC4)
  346. {
  347. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  348. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  349. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  350. }
  351. if (GlobalContext.IsUsePLC5)
  352. {
  353. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  354. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  355. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  356. }
  357. if (GlobalContext.IsUsePLC6)
  358. {
  359. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  360. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  361. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  362. }
  363. if (GlobalContext.IsUsePLC7)
  364. {
  365. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  366. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  367. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  368. }
  369. if (GlobalContext.IsUsePLC8)
  370. {
  371. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  372. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  373. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  374. }
  375. if (GlobalContext.IsUsePLC9)
  376. {
  377. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  378. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  379. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  380. }
  381. param.parameter.equipment.project = GlobalContext.Project_Code;
  382. param.parameter.equipment.productMode = "debug";
  383. param.parameter.other.logLevel = 0;
  384. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  385. XiaomiMqttClient_Extend.ParameterConfig(param);
  386. //保存全局变量
  387. xiaomiParm.stationCode = param.parameter.equipment.stationCode;
  388. xiaomiParm.deviceCode = param.parameter.equipment.deviceCode;
  389. }
  390. else
  391. {
  392. picIot.Image = imageListState.Images[0];
  393. AddMessage(LogType.Info,
  394. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  395. }
  396. }
  397. // 开启AGV(Http与MQTT)
  398. if (GlobalContext.IsUseAGV)
  399. {
  400. // AGV HTTP
  401. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  402. if (mesret1)
  403. {
  404. picAgvHttp.Image = imageListState.Images[1];
  405. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  406. }
  407. else
  408. {
  409. picAgvHttp.Image = imageListState.Images[0];
  410. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  411. }
  412. string agvMqttIp = GlobalContext.MQTTServerHost;
  413. int agvMqttPort = GlobalContext.MQTTServerPort;
  414. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  415. ResultData_MQTT result_MQTT = _MQTTHelper
  416. .CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  417. // AGV MQTT
  418. if (result_MQTT.ResultCode == 1)
  419. {
  420. picAgvMqtt.Image = imageListState.Images[1];
  421. GlobalContext.AGVMQTTIsConnect = true;
  422. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  423. ResultData_MQTT result =
  424. XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  425. AddMessage(LogType.Info,
  426. $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  427. }
  428. else
  429. {
  430. picAgvMqtt.Image = imageListState.Images[0];
  431. GlobalContext.AGVMQTTIsConnect = false;
  432. AddMessage(LogType.Info,
  433. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  434. }
  435. }
  436. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  437. Task.Run(MonitorMESConnect);
  438. // 查询PLC连接状态
  439. foreach (int plcNo in FunsEip.Keys)
  440. {
  441. bool connected = FunsEip[plcNo].IsConnected;
  442. if (connected)
  443. {
  444. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  445. AddMessage(LogType.Info, msg);
  446. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  447. }
  448. else
  449. {
  450. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  451. AddMessage(LogType.Info, msg);
  452. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  453. }
  454. }
  455. // PLC4时 初始化扫码器TCP
  456. //if (GlobalContext.IsUsePLC4)
  457. // HpTCPClientInit();
  458. // 开启PLC的业务处理线程-监听PLC点位+状态
  459. foreach (Task task in TaskReadProcess)
  460. {
  461. if (task != null)
  462. task.Start();
  463. }
  464. //// 开启iot的线程
  465. TaskReadAlarm.Start();
  466. ////下传MES信息给1工位(先判断下plc对象数量)
  467. //if (Funs.Count > 1)
  468. // DownLoadProductInfo(1);
  469. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  470. {
  471. //state_l.Text = "设备状态(左):";
  472. //state_r.Text = "设备状态(右):";
  473. //state_r.Visible = true;
  474. //lblDeviceStates2.Visible = true;
  475. }
  476. //上传操作记录
  477. operateToIot("startup", "开启");
  478. AddMessage(LogType.Info, "程序初始化完成");
  479. }
  480. catch (Exception ex)
  481. {
  482. string str = ex.StackTrace;
  483. this.BeginInvoke(new Action(() =>
  484. {
  485. AddMessage(LogType.Error,
  486. "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  487. str.Length - str.LastIndexOf("\\") - 1));
  488. }));
  489. }
  490. #endregion
  491. }
  492. catch (Exception ex)
  493. {
  494. string str = ex.StackTrace;
  495. OnMessage(LogType.Info,
  496. "主窗体的首页初始化出错!异常位置:" +
  497. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
  498. ex.Message.ToString());
  499. if (ex.Message != null && ex.Message.Contains("timed out"))
  500. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  501. else
  502. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  503. }
  504. }
  505. /// <summary>
  506. /// 窗体关闭事件
  507. /// </summary>
  508. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  509. {
  510. Closed2();
  511. }
  512. public void Closed2()
  513. {
  514. try
  515. {
  516. IsRun = false;
  517. Thread.Sleep(IntervalReadPLC);
  518. // 断开TCP
  519. int count = _HPSocket_TcpClients.Count();
  520. for (int i = 0; i < count; i++)
  521. {
  522. try
  523. {
  524. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  525. {
  526. _HPSocket_TcpClients[i].Stop();
  527. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  528. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  529. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  530. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  531. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  532. }
  533. }
  534. catch
  535. {
  536. }
  537. }
  538. // 关闭Iot
  539. try
  540. {
  541. XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
  542. GlobalContext.MqttServerName);
  543. }
  544. catch
  545. {
  546. }
  547. // 关闭AGV Mqtt
  548. try
  549. {
  550. _MQTTHelper.DisconnectAsync_Client().Wait();
  551. }
  552. catch
  553. {
  554. }
  555. }
  556. catch
  557. {
  558. }
  559. }
  560. #endregion 窗体基础事件
  561. #region 监控MES状态
  562. /// <summary>
  563. /// 监控MES连接状态
  564. /// </summary>
  565. private void MonitorMESConnect()
  566. {
  567. while (IsRun) // 运行被控线程
  568. {
  569. try
  570. {
  571. // 开启MES(Http)
  572. if (GlobalContext.IsUseMES)
  573. {
  574. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  575. if (mesret)
  576. {
  577. picMESStatus.Image = imageListState.Images[1];
  578. GlobalContext.MESIsConnect = true;
  579. }
  580. else
  581. {
  582. picMESStatus.Image = imageListState.Images[0];
  583. GlobalContext.MESIsConnect = false;
  584. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  585. }
  586. }
  587. // 开启IOT(MQTT)
  588. if (GlobalContext.IsUseIot)
  589. {
  590. bool iIot = XiaomiMqttClient.IsOpen;
  591. if (iIot)
  592. picIot.Image = imageListState.Images[1];
  593. else
  594. {
  595. picIot.Image = imageListState.Images[0];
  596. OnMessage(LogType.Info,
  597. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  598. }
  599. }
  600. // 开启AGV(Http与MQTT)
  601. if (GlobalContext.IsUseAGV)
  602. {
  603. // AGV Http
  604. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  605. if (mesret1)
  606. picAgvHttp.Image = imageListState.Images[1];
  607. else
  608. {
  609. picAgvHttp.Image = imageListState.Images[0];
  610. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  611. }
  612. // AGV MQTT
  613. if (GlobalContext.AGVMQTTIsConnect)
  614. picAgvMqtt.Image = imageListState.Images[1];
  615. else
  616. {
  617. picAgvMqtt.Image = imageListState.Images[0];
  618. OnMessage(LogType.Info,
  619. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  620. }
  621. }
  622. }
  623. catch (Exception ex)
  624. {
  625. string str = ex.StackTrace;
  626. AddMessage(LogType.Error,
  627. "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  628. str.Length - str.LastIndexOf("\\") - 1));
  629. }
  630. Thread.Sleep(IntervalMonitorMES);
  631. }
  632. }
  633. #endregion 监控MES连接状态
  634. #region 采集设备状态、运行数据、报警数据
  635. /// <summary>
  636. /// 请求设备状态 5000
  637. /// </summary>
  638. /// <param name="no">1</param>
  639. /// <param name="stationNameStr"></param>
  640. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  641. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  642. {
  643. try
  644. {
  645. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  646. {
  647. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  648. return result;
  649. }
  650. else
  651. {
  652. return 0;
  653. }
  654. }
  655. catch (Exception ex)
  656. {
  657. string str = ex.StackTrace;
  658. AddMessage_Station(stationNameStr, LogType.Error,
  659. "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  660. str.Length - str.LastIndexOf("\\") - 1));
  661. return 0;
  662. }
  663. }
  664. /// <summary>
  665. /// 检查是否可采集点检数据 - 不取新值
  666. /// 5000不为1时可点检
  667. /// </summary>
  668. /// <returns></returns>
  669. public bool CheckCanSpotcheck1(int deviceState)
  670. {
  671. //return true;
  672. //D5000 = 1,代表设备控制状态处于运行状态
  673. //D5000 = 2, 代表设备控制状态处于故障状态
  674. //D5000 = 3,代表设备控制状态处于缺料状态
  675. //D5000 = 4, 代表设备控制状态处于待机状态
  676. //D5000 = 5,代表设备控制状态处于维修状态
  677. return deviceState != 1;
  678. }
  679. /// <summary>
  680. /// 检查是否可采集产品数据 - 不取新值
  681. /// </summary>
  682. /// <returns></returns>
  683. public bool CheckCanCollData(int deviceState)
  684. {
  685. return deviceState == 0; // 点检时该值不为0
  686. }
  687. /// <summary>
  688. /// 采集到的设备状态
  689. /// </summary>
  690. private string _DeviceStates = "未知状态";
  691. private string _DeviceStates_Old = "未知状态";
  692. private string _DeviceStates2 = "未知状态";
  693. private string _DeviceStates_Old2 = "未知状态";
  694. private static string AlarmStateCode=""; //记录出发故障时的其中一笔警报,上传设备状态用
  695. private static string AlarmStateName = ""; //记录出发故障时的其中一笔警报,上传设备状态用
  696. /// <summary>
  697. /// 获取设备报警数据与获取设备运行信息
  698. /// </summary>
  699. private async void ReadAlarmAllPLC()
  700. {
  701. /// 获取设备报警数据与状态信息
  702. string stationNameStr = "获取设备报警数据与状态信息";
  703. // 已连接到PLC
  704. while (IsRun)
  705. {
  706. try
  707. {
  708. #region 报警数据
  709. try
  710. {
  711. //_FaultDatas = new uint[] { 4, 0, 30, 10 };
  712. if (_FaultDatas.Length > 0)
  713. {
  714. ReadPLCAlarmToIot(_FaultDatas, _FaultDatas_Old, stationNameStr,"left");
  715. }
  716. else
  717. {
  718. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  719. }
  720. if (_FaultDatas2.Length > 0)
  721. {
  722. ReadPLCAlarmToIot(_FaultDatas2, _FaultDatas_Old2, stationNameStr,"right");
  723. }
  724. else
  725. {
  726. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  727. }
  728. }
  729. catch (Exception ex)
  730. {
  731. string str = ex.StackTrace;
  732. AddMessage_Station(stationNameStr, LogType.Error,
  733. $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  734. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  735. }
  736. #endregion 报警数据
  737. #region 设备状态
  738. //if (!GlobalContext._IsCon_plc1Alarm)
  739. //{
  740. // UpdatePLCMonitor(1, -2, 0);
  741. // continue;
  742. //}
  743. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  744. {
  745. if (plcEIP != null)
  746. {
  747. if (plcEIP.IsConnected)
  748. {
  749. #region 主页展示设备运行状态并上传到IOT中,有双工位left就是左工位,没有双工位left就是单工位
  750. switch (xmDeviceStateData.left)
  751. {
  752. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  753. _DeviceStates = "未初始化状态";
  754. lblDeviceStates.Text = _DeviceStates;
  755. break;
  756. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  757. _DeviceStates = "初始化状态";
  758. lblDeviceStates.Text = _DeviceStates;
  759. break;
  760. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  761. _DeviceStates = "初始化完成状态";
  762. lblDeviceStates.Text = _DeviceStates;
  763. break;
  764. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  765. _DeviceStates = "运行状态";
  766. lblDeviceStates.Text = _DeviceStates;
  767. break;
  768. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  769. _DeviceStates = "暂停状态";
  770. lblDeviceStates.Text = _DeviceStates;
  771. break;
  772. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  773. _DeviceStates = "故障状态";
  774. lblDeviceStates.Text = _DeviceStates;
  775. break;
  776. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  777. _DeviceStates = "警报状态";
  778. lblDeviceStates.Text = _DeviceStates;
  779. break;
  780. }
  781. if (!_DeviceStates.Equals(_DeviceStates_Old))
  782. {
  783. var iotResult =
  784. SaveDeviceStateData(stationNameStr, xmDeviceStateData.left, "left"); // 上传+保存
  785. if (iotResult.Item1 == 1)
  786. {
  787. _DeviceStates_Old = _DeviceStates;
  788. AddMessage_Station(stationNameStr, LogType.Info,
  789. "【设备状态】" + stationNameStr + $"_上传设备状态到Iot成功!");
  790. }
  791. else
  792. AddMessage_Station(stationNameStr, LogType.Info,
  793. "【设备状态】" + stationNameStr +
  794. $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  795. }
  796. #endregion 主页展示设备运行状态并上传到IOT中
  797. #region 右工位
  798. //if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  799. //{
  800. // switch (xmDeviceStateData.right)
  801. // {
  802. // case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  803. // _DeviceStates2 = "未初始化状态";
  804. // lblDeviceStates2.Text = _DeviceStates2;
  805. // break;
  806. // case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  807. // _DeviceStates2 = "初始化状态";
  808. // lblDeviceStates2.Text = _DeviceStates2;
  809. // break;
  810. // case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  811. // _DeviceStates2 = "初始化完成状态";
  812. // lblDeviceStates2.Text = _DeviceStates2;
  813. // break;
  814. // case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  815. // _DeviceStates2 = "运行状态";
  816. // lblDeviceStates2.Text = _DeviceStates2;
  817. // break;
  818. // case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  819. // _DeviceStates2 = "暂停状态";
  820. // lblDeviceStates2.Text = _DeviceStates2;
  821. // break;
  822. // case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  823. // _DeviceStates2 = "故障状态";
  824. // lblDeviceStates2.Text = _DeviceStates2;
  825. // break;
  826. // case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  827. // _DeviceStates2 = "警报状态";
  828. // lblDeviceStates2.Text = _DeviceStates2;
  829. // break;
  830. // }
  831. // if (!_DeviceStates2.Equals(_DeviceStates_Old2))
  832. // {
  833. // var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceStateData.left,
  834. // "right"); // 上传+保存
  835. // if (iotResult.Item1 == 1)
  836. // {
  837. // _DeviceStates_Old2 = _DeviceStates2;
  838. // AddMessage_Station(stationNameStr, LogType.Info,
  839. // "【设备状态】" + stationNameStr + $"_上传Iot成功!");
  840. // }
  841. // else
  842. // AddMessage_Station(stationNameStr, LogType.Info,
  843. // "【设备状态】" + stationNameStr +
  844. // $"_上传Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  845. // }
  846. //}
  847. #endregion 右工位
  848. }
  849. }
  850. }
  851. #endregion
  852. }
  853. catch (Exception ex)
  854. {
  855. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  856. AddMessage_Station(stationNameStr, LogType.Error,
  857. $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  858. }
  859. Thread.Sleep(IntervalAlarm);
  860. }
  861. }
  862. #endregion 轮询PLC
  863. #region 下发订单信息
  864. ///// <summary>
  865. ///// 壳体上料(下发工单)的交互逻辑
  866. ///// </summary>
  867. ///// <param name="no"></param>
  868. ///// <exception cref="NotImplementedException"></exception>
  869. //private void ReadStation_DownOrderInfo(int plcNo)
  870. //{
  871. // // [S1] Tray盘上料装备(板测)
  872. // // [S2] FCT(板测)
  873. // // [S3] 值板机
  874. // // [S4] 取放桁架
  875. // // [S5] Tray盘下料装备
  876. // /// 上位机心跳
  877. // /// 获取设备报警数据与状态信息
  878. // string stationNameStr = "[S0]壳体上料";
  879. // while (IsRun)
  880. // {
  881. // try
  882. // {
  883. // if (!GlobalContext._IsCon_Funs1)
  884. // {
  885. // UpdatePLCMonitor(plcNo, 0);
  886. // continue;
  887. // }
  888. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  889. // {
  890. // #region 壳体上料(下发工单)
  891. // try
  892. // {
  893. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  894. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  895. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  896. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  897. // // 重置数据和信号
  898. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  899. // {
  900. // // 清空写给PLC的数据
  901. // int[] i497 = new int[1] { 0 };
  902. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  903. // // MES_Flag重置为0
  904. // int[] i500 = new int[1] { 0 };
  905. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  906. // }
  907. // }
  908. // catch (Exception ex)
  909. // {
  910. // string str = ex.StackTrace;
  911. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  912. // }
  913. // #endregion 壳体上料(下发工单)
  914. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  915. // }
  916. // else
  917. // {
  918. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  919. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  920. //
  921. // Funs[plcNo].Connect();
  922. // }
  923. // }
  924. // catch (Exception ex)
  925. // {
  926. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  927. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  928. //
  929. // Funs[plcNo].ReConnect();
  930. // }
  931. // Thread.Sleep(IntervalReadPLC);
  932. // }
  933. //}
  934. ///// <summary>
  935. ///// 下发订单信息到PLC
  936. ///// </summary>
  937. ///// <param name="no">PLC编号</param>
  938. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  939. //{
  940. // try
  941. // {
  942. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  943. // {
  944. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  945. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  946. // }
  947. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  948. // }
  949. // catch (Exception ex)
  950. // {
  951. // string str = ex.StackTrace;
  952. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  953. // }
  954. //}
  955. /// <summary>
  956. /// 下发清料信号
  957. /// </summary>
  958. /// <param name="no">PLC编号</param>
  959. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  960. {
  961. try
  962. {
  963. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  964. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  965. return true;
  966. }
  967. catch (Exception ex)
  968. {
  969. string str = ex.StackTrace;
  970. AddMessage_Station(stationNameStr, LogType.Error,
  971. "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  972. str.Length - str.LastIndexOf("\\") - 1));
  973. return false;
  974. }
  975. }
  976. #endregion 下发订单信息
  977. #region Xiaomi 贲流
  978. #region 公共方法
  979. private static bool ProgressState = false;
  980. private static readonly object lockObj = new object(); // 锁对象
  981. private static bool isCollectingFlagLeft;
  982. private static bool isCollectingFlagRight;
  983. private bool OpenDailogFalg = true; //是否开启扫码弹窗标识
  984. private static int res = 0;
  985. public static bool StopWhile =false;
  986. public void ConnectToIOT()
  987. {
  988. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  989. // fds
  990. param.parameter.fds.address = GlobalContext.address;
  991. param.parameter.fds.appId = GlobalContext.appId;
  992. param.parameter.fds.appKey = GlobalContext.appKey;
  993. // mes
  994. param.parameter.mes.address = GlobalContext.ServerIp;
  995. param.parameter.mes.appId = GlobalContext.MESAppId;
  996. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  997. // mqtt
  998. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  999. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  1000. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  1001. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  1002. // 设备配置
  1003. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  1004. if (GlobalContext.IsUsePLC1)
  1005. {
  1006. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  1007. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  1008. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  1009. }
  1010. if (GlobalContext.IsUsePLC2)
  1011. {
  1012. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  1013. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  1014. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  1015. }
  1016. if (GlobalContext.IsUsePLC3)
  1017. {
  1018. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  1019. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  1020. }
  1021. if (GlobalContext.IsUsePLC4)
  1022. {
  1023. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  1024. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  1025. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  1026. }
  1027. if (GlobalContext.IsUsePLC5)
  1028. {
  1029. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  1030. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  1031. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  1032. }
  1033. if (GlobalContext.IsUsePLC6)
  1034. {
  1035. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  1036. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  1037. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  1038. }
  1039. if (GlobalContext.IsUsePLC7)
  1040. {
  1041. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  1042. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  1043. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  1044. }
  1045. if (GlobalContext.IsUsePLC8)
  1046. {
  1047. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  1048. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  1049. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  1050. }
  1051. if (GlobalContext.IsUsePLC9)
  1052. {
  1053. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  1054. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  1055. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  1056. }
  1057. param.parameter.equipment.project = GlobalContext.Project_Code;
  1058. param.parameter.equipment.productMode = "debug";
  1059. param.parameter.other.logLevel = 0;
  1060. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  1061. XiaomiMqttClient_Extend.ParameterConfig(param);
  1062. }
  1063. /// <summary>
  1064. /// float[]转为string
  1065. /// </summary>
  1066. public string FloatArrayToString(float[] nScrewResults)
  1067. {
  1068. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1069. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1070. }
  1071. /// <summary>
  1072. /// short[]转为string
  1073. /// </summary>
  1074. public string ShortArrayToString(short[] nScrewResults)
  1075. {
  1076. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1077. return string.Join(",", nScrewResults);
  1078. }
  1079. /// <summary>
  1080. /// 写入PLC重复三次
  1081. /// </summary>
  1082. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount,
  1083. T inObj)
  1084. {
  1085. int i = 0;
  1086. int nRet = 0;
  1087. string strRet = "";
  1088. try
  1089. {
  1090. while (i < 3) // 最多上传三次
  1091. {
  1092. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1093. if (nRet == 0) //成功
  1094. {
  1095. break;
  1096. }
  1097. else
  1098. {
  1099. AddMessage_Station(stationNameStr, LogType.Error,
  1100. $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1101. i++;
  1102. }
  1103. }
  1104. return (nRet, strRet);
  1105. }
  1106. catch (Exception ex)
  1107. {
  1108. return (1, ex.Message);
  1109. }
  1110. }
  1111. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
  1112. short[] nScrewOrders, short[] nScrewResults)
  1113. {
  1114. try
  1115. {
  1116. // 获取当前日期
  1117. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1118. // 构建保存路径
  1119. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1120. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
  1121. // 确保目录存在
  1122. Directory.CreateDirectory(savePath);
  1123. // 文件名
  1124. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1125. string filePath = Path.Combine(savePath, fileName);
  1126. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1127. int count = Math.Min(14, fScrewTimes.Length);
  1128. using (StreamWriter sw = new StreamWriter(filePath))
  1129. {
  1130. for (int i = 0; i < count; i++)
  1131. {
  1132. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1133. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1134. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1135. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1136. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1137. }
  1138. }
  1139. return (0, "");
  1140. }
  1141. catch (Exception ex)
  1142. {
  1143. return (1, ex.Message);
  1144. }
  1145. }
  1146. public Dictionary<string, string> GetLastLineCompensation(string path, string direction, string sn)
  1147. {
  1148. // 创建字典存储补偿点及其对应的值
  1149. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1150. try
  1151. {
  1152. //string path = GlobalContext.MESLaserRPath;
  1153. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1154. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1155. string filename = $"Laser-{currentDate}-W0.txt";
  1156. // 拼接完整路径
  1157. string fullPath = Path.Combine(path, filename);
  1158. string lastNonEmptyLine = "";
  1159. // 判断文件是否存在
  1160. if (File.Exists(fullPath))
  1161. {
  1162. //读取文件内容
  1163. string[] lines = File.ReadAllLines(fullPath);
  1164. // 获取最后一行数据(忽略标题行)
  1165. if (lines.Length > 1)
  1166. {
  1167. string lastLine = "";
  1168. for (int i = lines.Length - 1; i > 0; i--)
  1169. {
  1170. if (!string.IsNullOrEmpty(lines[i]))
  1171. {
  1172. lastLine = lines[i];
  1173. break;
  1174. }
  1175. }
  1176. // 将最后一行按逗号分隔
  1177. string[] values = lastLine.Split(',');
  1178. values[1] = sn;
  1179. string key = "三点激光_" + direction; // 构造键名
  1180. string value = string.Join(",", values); // 获取值并去除多余空格
  1181. compensationDict[key] = value;
  1182. //// 提取“1点补偿”到“6点补偿”的值
  1183. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1184. //{
  1185. // string key = $"{i - 1}点补偿"; // 构造键名
  1186. // string value = values[i].Trim(); // 获取值并去除多余空格
  1187. // compensationDict[key] = value;
  1188. //}
  1189. }
  1190. }
  1191. else
  1192. {
  1193. Console.WriteLine($"文件不存在: {fullPath}");
  1194. }
  1195. }
  1196. catch (Exception ex)
  1197. {
  1198. // 捕获异常并输出错误信息
  1199. Console.WriteLine($"发生错误: {ex.Message}");
  1200. }
  1201. return compensationDict;
  1202. }
  1203. public int PCBStationOutData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1204. {
  1205. int res = 0;
  1206. string jsonstr1 = "";
  1207. try
  1208. {
  1209. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1210. outRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备id(可配置)
  1211. outRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1212. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1213. outRequest_Body.clientTime =
  1214. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1215. outRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1216. int a1Result = (int)iotData.testStatus;
  1217. //bool pass = a1Result == 1;
  1218. //outRequest_Body.state = pass ? "PASS" : "FAIL"; ; // 出站条件 PASS或FAIL
  1219. outRequest_Body.state = "PASS";
  1220. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1221. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1222. XmStationOut_KeyMaterial keyMaterial = new XmStationOut_KeyMaterial();
  1223. keyMaterial.bindSort = 1;
  1224. keyMaterial.materialSn = Barcode.strProductBarcode;
  1225. outRequest_Body.unitData.keyMaterial.Add(keyMaterial); // 产品码
  1226. jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1227. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1228. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1229. if (response != null && response.header.code == "200")
  1230. {
  1231. res = 1;
  1232. AddMessage(LogType.Info,
  1233. "上传PCB出站数据到MES服务器---成功!请求信息:" + jsonstr1 + ",返回信息:" +
  1234. JsonConvert.SerializeObject(response.body));
  1235. }
  1236. else
  1237. {
  1238. res = 0;
  1239. AddMessage(LogType.Error,
  1240. "上传PCB出站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + jsonstr1 + ",返回信息:" +
  1241. JsonConvert.SerializeObject(response.body));
  1242. }
  1243. }
  1244. catch (Exception e)
  1245. {
  1246. res = 0;
  1247. AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---失败!请求信息:" + jsonstr1 + ",返回信息:" + e.Message);
  1248. }
  1249. return res;
  1250. }
  1251. public int PCBStationInData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1252. {
  1253. int res = 0;
  1254. string json_Body = "";
  1255. try
  1256. {
  1257. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1258. inRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  1259. inRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1260. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1261. inRequest_Body.clientTime =
  1262. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1263. inRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1264. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1265. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1266. json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1267. var response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1268. string resultJson = JsonConvert.SerializeObject(response);
  1269. if (response != null && response.header.code == "200")
  1270. {
  1271. res = 1;
  1272. AddMessage(LogType.Info,
  1273. "上传PCB进站数据到MES服务器---成功!请求信息:" + json_Body + ",返回信息:" +
  1274. JsonConvert.SerializeObject(response.body));
  1275. }
  1276. else
  1277. {
  1278. res = 0;
  1279. AddMessage(LogType.Error,
  1280. "上传PCB进站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + json_Body + ",返回信息:" +
  1281. JsonConvert.SerializeObject(response.body));
  1282. }
  1283. }
  1284. catch (Exception e)
  1285. {
  1286. res = 0;
  1287. AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---失败!请求信息:" + json_Body + ",返回信息:" + e.Message);
  1288. }
  1289. return res;
  1290. }
  1291. /// <summary>
  1292. /// 调用进站接口并保存进站数据
  1293. /// </summary>
  1294. /// <param name="stationNameStr">工站信息</param>
  1295. /// <param name="workorder_code">工单号</param>
  1296. /// <param name="mtltmrk">型号(物料号)</param>
  1297. /// <param name="sn">产品SN</param>
  1298. /// <param name="items">进站数据</param>
  1299. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1300. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
  1301. List<TestItem> items, string MachineId, string StationId, bool pass, string slot)
  1302. {
  1303. int result = 0;
  1304. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1305. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1306. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1307. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1308. inRequest_Body.clientTime =
  1309. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1310. inRequest_Body.unitSn = sn; // 产品SN
  1311. inRequest_Body.uuidInspection = uuid;
  1312. inRequest_Body.state = pass ? "PASS" : "FAIL";
  1313. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1314. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1315. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1316. StationIn stationIn = new StationIn()
  1317. {
  1318. Workorder_code = workorder_code, // 车间订单号
  1319. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1320. Sn = sn, // SN
  1321. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1322. Parameter_values = items, // 进站数据
  1323. Write_user = inRequest_Body.userId, // 员工Id
  1324. Test_time = inRequest_Body.clientTime // 进站时间
  1325. };
  1326. // 本地数据
  1327. string sql = stationIn.ToStringInsert(0);
  1328. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1329. result = ret == "成功" ? 1 : 6;
  1330. #region MES
  1331. if (GlobalContext.IsSendStationIn)
  1332. {
  1333. try
  1334. {
  1335. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1336. string resultJson = "";
  1337. string mesRet = string.Empty;
  1338. int i = 0;
  1339. while (i < 2) // 1009会多次尝试上传
  1340. {
  1341. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1342. resultJson = JsonConvert.SerializeObject(response);
  1343. if (response != null && response.header.code == "200")
  1344. break;
  1345. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1346. i++;
  1347. i++;
  1348. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1349. // 记录失败原因
  1350. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:{mesRet},请求参数:{json_Body}");
  1351. }
  1352. if (response?.header?.code == "200")
  1353. {
  1354. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1355. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1356. result = ret_Upd == "成功" ? 1 : 6;
  1357. AddMessage(LogType.Info,
  1358. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,返回参数:{resultJson},请求参数:{json_Body}");
  1359. }
  1360. else
  1361. {
  1362. result = 5;
  1363. AddMessage(LogType.Info,
  1364. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息: {mesRet},请求参数:{json_Body}");
  1365. }
  1366. string sql_response =
  1367. stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1368. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1369. }
  1370. catch (Exception ex)
  1371. {
  1372. result = 6;
  1373. string str = ex.StackTrace;
  1374. AddMessage_Station(stationNameStr, LogType.Error,
  1375. $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1376. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1377. }
  1378. }
  1379. #endregion
  1380. #region IOT
  1381. //过站结果
  1382. if (GlobalContext.IsMqttSendProcessData)
  1383. {
  1384. PassStationResultRequest request = new PassStationResultRequest();
  1385. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1386. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1387. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1388. request.line_code = GlobalContext.LineCode; // 线体编码
  1389. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1390. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1391. request.station = xiaomiParm.stationCode;
  1392. request.process_time =
  1393. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1394. request.slot = slot; // 槽位编码
  1395. request.sn = sn; // 产品SN
  1396. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1397. request.enter_status = pass ? "PASS" : "FAIL"; // 进站状态
  1398. request.result = ""; // 出站条件 PASS或FAIL; // 过站结果
  1399. request.work_type = "OUT_STATION"; // 作业类型
  1400. // 上传过站结果
  1401. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1402. if (iotResult.Item1 != 0)
  1403. {
  1404. OnMessage(LogType.Info,
  1405. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1406. }
  1407. }
  1408. #endregion
  1409. return result;
  1410. }
  1411. /// <summary>
  1412. /// 选择如何记录出站数据
  1413. /// </summary>
  1414. /// <param name="items">出站数据</param>
  1415. /// <param name="equipmentCode">设备编号</param>
  1416. /// <param name="processItem">测试项目</param>
  1417. /// <param name="workorder_code">车间订单号</param>
  1418. /// <param name="batch_num">批次号</param>
  1419. /// <param name="mtltmrk">型号</param>
  1420. /// <param name="proDate">日期</param>
  1421. /// <param name="supplierCode">供应商代码</param>
  1422. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1423. /// <returns>上传成功时返回1;失败返回0</returns>
  1424. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode,
  1425. string processItem,
  1426. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1427. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId,
  1428. string StationId, string PartBarcode, string jsonParm, string direction = "")
  1429. {
  1430. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num,
  1431. mtltmrk,
  1432. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm,
  1433. direction);
  1434. }
  1435. /// <summary>
  1436. /// 添加出站数据(提交到MES+本地保存到数据库)
  1437. /// </summary>
  1438. /// <param name="items">出站数据</param>
  1439. /// <param name="equipmentCode">设备编号</param>
  1440. /// <param name="processItem">测试项目</param>
  1441. /// <param name="workorder_code">车间订单号</param>
  1442. /// <param name="batch_num">批次号</param>
  1443. /// <param name="mtltmrk">型号</param>
  1444. /// <param name="proDate">日期</param>
  1445. /// <param name="supplierCode">供应商代码</param>
  1446. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1447. /// <returns>上传成功时返回1;失败返回0</returns>
  1448. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1449. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1450. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot,
  1451. string machineId, string stationId, string partBarcode, string jsonParm, string direction = "")
  1452. {
  1453. int upload = 0;
  1454. int result = 0;
  1455. ProcessData processData = new ProcessData()
  1456. {
  1457. Equipment_code = equipmentCode,
  1458. Workorder_code = workorder_code,
  1459. Batch_number = batch_num,
  1460. Sn = sn, // SN
  1461. Testitem = processItem,
  1462. Parameter_values = items,
  1463. Write_user = GlobalContext.CurrentUser,
  1464. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1465. };
  1466. // 本地数据
  1467. string sql = processData.ToStringInsert(upload);
  1468. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1469. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1470. #region MES
  1471. if (GlobalContext.IsSendProcessData)
  1472. {
  1473. try
  1474. {
  1475. string id = processData.ID.Copy();
  1476. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1477. if (direction == "Right")
  1478. outRequest_Body.uuidInspection = uuid2;
  1479. else
  1480. outRequest_Body.uuidInspection = uuid;
  1481. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1482. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1483. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1484. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1485. outRequest_Body.unitSn = sn; // 产品SN
  1486. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1487. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1488. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1489. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1490. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1491. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1492. if (!string.IsNullOrEmpty(partBarcode))
  1493. {
  1494. outRequest_Body.unitData.keyMaterial.Add(
  1495. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1496. {
  1497. bindSort = 1,
  1498. materialSn = partBarcode
  1499. }); // 设备数据 - 部件码
  1500. }
  1501. //OP30站读txt数据
  1502. if (stationNameStr.Contains("OP31") || stationNameStr.Contains("OP32"))
  1503. {
  1504. string path = "";
  1505. if (direction == "Left")
  1506. {
  1507. string pathStr = GlobalContext.MESLaserLPath;
  1508. path = DecFileName(pathStr);
  1509. }
  1510. else {
  1511. string pathStr = GlobalContext.MESLaserRPath;
  1512. path = DecFileName(pathStr);
  1513. }
  1514. //字典存储数据
  1515. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction, sn);
  1516. foreach (var kvp in compensationDict)
  1517. {
  1518. outRequest_Body.unitData.processData.Add(
  1519. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1520. {
  1521. dataName = kvp.Key.ToString(),
  1522. dataValue = kvp.Value.ToString()
  1523. });
  1524. }
  1525. }
  1526. //过站明细
  1527. if (GlobalContext.IsSendProcessDetail)
  1528. {
  1529. if (jsonParm.Length > 0)
  1530. {
  1531. //jsonParm = "{\"fGlueSupplySpeed\":0.63,\"fAB_AirPress\":0.0,\"fAB_AirPressDiff\":0.0,\"fMesHeightInfos\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],\"fIntervalWeights\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],\"fRemainGlues\":[600.0,600.0]}";
  1532. // 解析JSON字符串为字典
  1533. jsonParm = jsonParm.Replace("[", "\"[");
  1534. jsonParm = jsonParm.Replace("]", "]\"");
  1535. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1536. foreach (var kvp in dictionary)
  1537. {
  1538. outRequest_Body.unitData.processData.Add(
  1539. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1540. {
  1541. dataName = kvp.Key.ToString(),
  1542. dataValue = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString()
  1543. });
  1544. }
  1545. }
  1546. }
  1547. if (GlobalContext.MESIsSendUpFile)
  1548. {
  1549. foreach (var item in fileUploadData.fileData)
  1550. {
  1551. if (!string.IsNullOrEmpty(item.FileName))
  1552. {
  1553. outRequest_Body.unitData.fileData.Add(
  1554. new XmStationOut_FileData()
  1555. {
  1556. fileName = item.FileName,
  1557. fileId = item.FileId,
  1558. bucket = item.Bucket
  1559. });
  1560. }
  1561. }
  1562. }
  1563. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1564. if (GlobalContext.IsSendProcessData)
  1565. {
  1566. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1567. string mesRet = string.Empty;
  1568. int i = 0;
  1569. while (i < 2) // 1009会多次尝试上传
  1570. {
  1571. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1572. if (response != null && response.header.code == "200")
  1573. {
  1574. OnMessage(LogType.Info,
  1575. $"【出站数据 SN {sn}】上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
  1576. JsonConvert.SerializeObject(response.body));
  1577. break;
  1578. }
  1579. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1580. i++;
  1581. i++;
  1582. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1583. // 记录失败原因
  1584. OnMessage(LogType.Error,
  1585. $"【出站数据 SN {sn}】上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1586. }
  1587. if (response?.header?.code == "200")
  1588. {
  1589. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1590. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1591. result = 1;
  1592. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1593. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1594. }
  1595. else
  1596. {
  1597. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1598. }
  1599. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
  1600. JsonConvert.SerializeObject(outRequest_Body),
  1601. JsonConvert.SerializeObject(response), id);
  1602. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1603. }
  1604. }
  1605. catch (Exception ex)
  1606. {
  1607. string str = ex.StackTrace;
  1608. AddMessage_Station(stationNameStr, LogType.Error,
  1609. $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1610. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1611. }
  1612. }
  1613. #endregion
  1614. #region IOT
  1615. //过站明细
  1616. if (GlobalContext.IsMqttSendProcessData)
  1617. {
  1618. PassStationDetailRequest request = new PassStationDetailRequest();
  1619. if (direction == "Right")
  1620. request.pass_station_id = uuid2;
  1621. else
  1622. request.pass_station_id = uuid;
  1623. request.sn = sn; // 产品SN
  1624. request.slot = vehicleSlot; // 槽位编码
  1625. request.function_name = "Machine_加⼯模块";
  1626. request.status = "PASS";
  1627. (int, string) iotResult = (0, "");
  1628. if (jsonParm.Length > 0)
  1629. {
  1630. // 解析JSON字符串为字典
  1631. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1632. foreach (var kvp in dictionary)
  1633. {
  1634. test_item_num += 1;
  1635. request.test_item_num = test_item_num.ToString();
  1636. request.test_item = kvp.Key.ToString();
  1637. request.result_val = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString();
  1638. request.description = request.test_item;
  1639. // 上传过站明细
  1640. iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  1641. if (iotResult.Item1 != 0)
  1642. {
  1643. OnMessage(LogType.Info,
  1644. $"【IOT过站明细】上传失败!错误原因:{iotResult.Item2},过站明细;产品码[{sn}] 测试项目[{request.test_item}] 测试值[{request.result_val}]");
  1645. }
  1646. }
  1647. }
  1648. }
  1649. //过站结果
  1650. if (GlobalContext.IsMqttSendProcessData)
  1651. {
  1652. PassStationResultRequest request = new PassStationResultRequest();
  1653. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1654. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1655. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1656. request.line_code = GlobalContext.LineCode; // 线体编码
  1657. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1658. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1659. request.station = xiaomiParm.stationCode;
  1660. request.process_time =
  1661. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1662. request.slot = vehicleSlot; // 槽位编码
  1663. request.sn = sn; // 产品SN
  1664. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1665. request.enter_status = ""; // 进站状态
  1666. request.result = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL; // 过站结果
  1667. request.work_type = "OUT_STATION"; // 作业类型
  1668. // 上传过站结果
  1669. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1670. if (iotResult.Item1 != 0)
  1671. {
  1672. OnMessage(LogType.Info,
  1673. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1674. }
  1675. }
  1676. #endregion
  1677. return result;
  1678. }
  1679. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1680. //{
  1681. // Stopwatch stopwatch = new Stopwatch();
  1682. // stopwatch.Start();
  1683. // try
  1684. // {
  1685. // // 初始化 AtlasScrew 实例
  1686. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1687. // atlasScrew1.Initial();
  1688. // // 存储结果的列表
  1689. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1690. // // 存储角度和扭力的字符串列表
  1691. // List<string> angleStrs = new List<string>();
  1692. // List<string> torqueStrs = new List<string>();
  1693. // // 上一次获取的数据
  1694. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1695. // while (isExitAtlasLeft) // 检查是否收集数据
  1696. // {
  1697. // // 获取当前数据
  1698. // var currentResult = atlasScrew1.GetResults();
  1699. // // 判断是否为新数据
  1700. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1701. // {
  1702. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1703. // // 更新角度和扭力的字符串列表
  1704. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1705. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1706. // // 计算角度、扭力、起始扭力和最大扭力
  1707. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1708. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1709. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1710. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1711. // // 将新数据添加到结果列表
  1712. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1713. // // 更新上一次获取的数据
  1714. // lastResult = currentResult;
  1715. // }
  1716. // // 等待一段时间后再次检查
  1717. // Thread.Sleep(20); // 轮询间隔时间
  1718. // // 如果触发了出站,则退出循环
  1719. // if (!isExitAtlasLeft)
  1720. // {
  1721. // break;
  1722. // }
  1723. // }
  1724. // // 生成文件名
  1725. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1726. // // 写入数据到文件
  1727. // using (StreamWriter writer = new StreamWriter(fileName))
  1728. // {
  1729. // // 写入标题行
  1730. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1731. // // 写入每一行数据
  1732. // foreach (var result in results)
  1733. // {
  1734. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1735. // }
  1736. // }
  1737. // stopwatch.Stop();
  1738. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1739. // }
  1740. // catch (Exception ex)
  1741. // {
  1742. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1743. // }
  1744. // finally
  1745. // {
  1746. // // 重置标志变量
  1747. // isExitAtlasLeft = false;
  1748. // }
  1749. //}
  1750. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1751. //{
  1752. // Stopwatch stopwatch = new Stopwatch();
  1753. // stopwatch.Start();
  1754. // try
  1755. // {
  1756. // // 初始化 AtlasScrew 实例
  1757. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1758. // atlasScrew2.Initial();
  1759. // // 存储结果的列表
  1760. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1761. // // 上一次获取的数据
  1762. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1763. // while (isExitAtlasRight) // 检查是否收集数据
  1764. // {
  1765. // // 获取当前数据
  1766. // var currentResult = atlasScrew2.GetResults();
  1767. // // 判断是否为新数据
  1768. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1769. // {
  1770. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1771. // // 将新数据写入PLC
  1772. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1773. // // 将新数据添加到结果列表
  1774. // results.Add(currentResult);
  1775. // // 更新上一次获取的数据
  1776. // lastResult = currentResult;
  1777. // }
  1778. // // 等待一段时间后再次检查
  1779. // Thread.Sleep(20); // 轮询间隔时间
  1780. // // 如果触发了出站,则退出循环
  1781. // if (!isExitAtlasRight)
  1782. // {
  1783. // break;
  1784. // }
  1785. // }
  1786. // // 将所有数据写入文件
  1787. // //WriteDataToFile(sn, direction, results);
  1788. // stopwatch.Stop();
  1789. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1790. // }
  1791. // catch (Exception ex)
  1792. // {
  1793. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1794. // }
  1795. // finally
  1796. // {
  1797. // // 重置标志变量
  1798. // isExitAtlasRight = false;
  1799. // }
  1800. //}
  1801. /// <summary>
  1802. ///字符串中文乱码解决
  1803. /// </summary>
  1804. /// <param name="str"></param>
  1805. /// <returns></returns>
  1806. public static string DecFileName(string str)
  1807. {
  1808. Encoding utf8 = Encoding.GetEncoding("gbk");
  1809. byte[] btArr = utf8.GetBytes(str);
  1810. return Encoding.UTF8.GetString(btArr);
  1811. }
  1812. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1813. {
  1814. Stopwatch stopwatch = new Stopwatch();
  1815. stopwatch.Start();
  1816. int nRet = 0;
  1817. string strRet = "";
  1818. try
  1819. {
  1820. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1821. while (isCollectingFlagLeft)
  1822. {
  1823. // 从缓存中获取所有未处理的数据
  1824. var cachedData = atlasScrew.GetCachedDataLeft();
  1825. foreach (var currentResult in cachedData)
  1826. {
  1827. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1828. {
  1829. continue; // 跳过无效数据
  1830. }
  1831. OnMessage(LogType.Info,
  1832. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1833. // 写入PLC
  1834. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1835. {
  1836. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1837. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1838. };
  1839. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1840. if (nRet != 0)
  1841. {
  1842. OnMessage(LogType.Info,
  1843. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1844. }
  1845. else
  1846. {
  1847. OnMessage(LogType.Info,
  1848. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1849. }
  1850. // 构建保存路径
  1851. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1852. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1853. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1854. Directory.CreateDirectory(savePath); // 确保目录存在
  1855. // 构建文件名(以 SN + 序号命名)
  1856. string fileName = $"{sn}_{fileCounter}.txt";
  1857. string filePath = Path.Combine(savePath, fileName);
  1858. // 写入文件
  1859. using (StreamWriter writer = new StreamWriter(filePath))
  1860. {
  1861. writer.WriteLine("精度, 扭力");
  1862. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1863. for (int i = 0;
  1864. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1865. i++)
  1866. {
  1867. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1868. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1869. writer.WriteLine($"{precision}, {torque}");
  1870. }
  1871. }
  1872. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1873. // 增加文件计数器
  1874. fileCounter++;
  1875. }
  1876. // 如果没有更多数据,则短暂休眠以节省资源
  1877. if (!cachedData.Any())
  1878. {
  1879. Thread.Sleep(10); // 根据需要调整休眠时间
  1880. }
  1881. // 如果触发了出站,则退出循环
  1882. if (!isCollectingFlagLeft)
  1883. {
  1884. break;
  1885. }
  1886. }
  1887. stopwatch.Stop();
  1888. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1889. }
  1890. catch (Exception ex)
  1891. {
  1892. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1893. }
  1894. finally
  1895. {
  1896. isCollectingFlagLeft = false;
  1897. }
  1898. }
  1899. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1900. {
  1901. Stopwatch stopwatch = new Stopwatch();
  1902. stopwatch.Start();
  1903. int nRet = 0;
  1904. string strRet = "";
  1905. try
  1906. {
  1907. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1908. while (isCollectingFlagRight)
  1909. {
  1910. // 从缓存中获取所有未处理的数据
  1911. var cachedData = atlasScrew.GetCachedDataLeft();
  1912. foreach (var currentResult in cachedData)
  1913. {
  1914. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1915. {
  1916. continue; // 跳过无效数据
  1917. }
  1918. OnMessage(LogType.Info,
  1919. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1920. // 写入PLC
  1921. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1922. {
  1923. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1924. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1925. };
  1926. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1927. if (nRet != 0)
  1928. {
  1929. OnMessage(LogType.Info,
  1930. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1931. }
  1932. else
  1933. {
  1934. OnMessage(LogType.Info,
  1935. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1936. }
  1937. // 构建保存路径
  1938. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1939. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1940. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1941. Directory.CreateDirectory(savePath); // 确保目录存在
  1942. // 构建文件名(以 SN + 序号命名)
  1943. string fileName = $"{sn}_{fileCounter}.txt";
  1944. string filePath = Path.Combine(savePath, fileName);
  1945. // 写入文件
  1946. using (StreamWriter writer = new StreamWriter(filePath))
  1947. {
  1948. writer.WriteLine("精度, 扭力");
  1949. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1950. for (int i = 0;
  1951. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1952. i++)
  1953. {
  1954. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1955. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1956. writer.WriteLine($"{precision}, {torque}");
  1957. }
  1958. }
  1959. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1960. // 增加文件计数器
  1961. fileCounter++;
  1962. }
  1963. // 如果没有更多数据,则短暂休眠以节省资源
  1964. if (!cachedData.Any())
  1965. {
  1966. Thread.Sleep(10); // 根据需要调整休眠时间
  1967. }
  1968. // 如果触发了出站,则退出循环
  1969. if (!isCollectingFlagRight)
  1970. {
  1971. break;
  1972. }
  1973. }
  1974. stopwatch.Stop();
  1975. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1976. }
  1977. catch (Exception ex)
  1978. {
  1979. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1980. }
  1981. finally
  1982. {
  1983. isCollectingFlagRight = false;
  1984. }
  1985. }
  1986. public static (int, string) CompressFolder(string folderPath, string zipFilePath)
  1987. {
  1988. try
  1989. {
  1990. // 创建zip文件,将指定文件夹内的所有内容压缩到这个zip文件中
  1991. System.IO.Compression.ZipFile.CreateFromDirectory(folderPath, zipFilePath);
  1992. return (1, "文件夹已成功压缩!");
  1993. }
  1994. catch (Exception ex)
  1995. {
  1996. return (0, "文件压缩出错!" + ex.Message);
  1997. }
  1998. }
  1999. /// <summary>
  2000. /// 上传文件
  2001. /// </summary>
  2002. /// <param name="BarcodeSet_t">条码集合</param>
  2003. /// <param name="stationCode">工站编号</param>
  2004. /// <param name="stationName">工站名称</param>
  2005. /// <param name="path">文件路径</param>
  2006. public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode,
  2007. string stationName, int pass, string path, string guid = "")
  2008. {
  2009. string sql, filename = "";
  2010. int result = 0;
  2011. var formData = new MultipartFormDataContent();
  2012. string msg = "";
  2013. string file_category = "IMAGE"; //IMAGE 、TEXT 、UNKNOWN
  2014. string file_type = "IMAGE";
  2015. string project = GlobalContext.ProgramName;
  2016. string run_mode = GlobalContext.run_mode;
  2017. string product_mode = GlobalContext.product_mode;
  2018. string pass_result = (pass == 1 ? "PASS" : "Fail");
  2019. string device_code = xiaomiParm.deviceCode;
  2020. string sn = BarcodeSet.strProductBarcode;
  2021. string staion_id = xiaomiParm.stationCode;
  2022. string bucket =
  2023. $"{file_category}/{file_type}/{project}/{product_mode}/{run_mode}/{pass_result}/{device_code}/{sn}/{staion_id}";
  2024. // 获取所有图片文件
  2025. if (guid == "")
  2026. {
  2027. guid = Guid.NewGuid().ToString();
  2028. }
  2029. try
  2030. {
  2031. if (GlobalContext.MESIsSendUpFile)
  2032. {
  2033. List<string> imageFiles = GetAllImageFiles(path);
  2034. string toPath = GlobalContext.MqttFileBackupLogDir;
  2035. filename =
  2036. $"{xiaomiParm.workstation}_{file_type}_{sn}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  2037. //string directoryPath = Path.GetDirectoryName(path);
  2038. string strFilePath = toPath + "\\" + filename;
  2039. if (imageFiles.Count > 0)
  2040. {
  2041. var r = CompressFolder(path, strFilePath);
  2042. if (r.Item1 == 0)
  2043. {
  2044. return (0, r.Item2);
  2045. }
  2046. else
  2047. {
  2048. msg = r.Item2 + "\r\n";
  2049. }
  2050. }
  2051. else
  2052. {
  2053. return (0, "文件不存在!");
  2054. }
  2055. FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  2056. fileUpload_X5.bucket = bucket;
  2057. fileUpload_X5.name = filename;
  2058. fileUpload_X5.uuid = guid.ToString();
  2059. ///需要上传文件
  2060. FileInfo file = new FileInfo(strFilePath);
  2061. string fileMd5Hex = GetMD5Hex(file);
  2062. fileUpload_X5.md5 = fileMd5Hex;
  2063. fileUpload_X5.uploadCloud = true;
  2064. fileUpload_X5.informMqtt = true;
  2065. FileMqttPayload fileMqttPayload = new FileMqttPayload();
  2066. fileMqttPayload.factory = GlobalContext.Factory_Code;
  2067. fileMqttPayload.project_name = GlobalContext.Project_Code;
  2068. fileMqttPayload.product_mode = GlobalContext.product_mode;
  2069. fileMqttPayload.line_no = GlobalContext.LineCode;
  2070. fileMqttPayload.work_station_no = xiaomiParm.workstation;
  2071. fileMqttPayload.equipment_no = xiaomiParm.deviceCode;
  2072. fileMqttPayload.station_no = xiaomiParm.stationCode;
  2073. fileMqttPayload.file_id = guid;
  2074. fileMqttPayload.file_name = filename;
  2075. fileMqttPayload.sn = BarcodeSet.strProductBarcode;
  2076. //fileMqttPayload.opt_time = "";
  2077. //fileMqttPayload.file_type = "";
  2078. //fileMqttPayload.file_category = "";
  2079. //fileMqttPayload.tag = "";
  2080. fileMqttPayload.reference_info.pass_station_id = uuid;
  2081. var fileresult = await
  2082. XiaomiMESHttp_UpLoadFile.FileUoladToMes(strFilePath, fileUpload_X5, fileMqttPayload);
  2083. if (fileresult.Item1 != 1)
  2084. {
  2085. return (0, msg + fileresult.Item2 + "\r\n");
  2086. }
  2087. else
  2088. {
  2089. msg = msg + fileresult.Item2 + "\r\n";
  2090. }
  2091. foreach (var imageFile in imageFiles)
  2092. {
  2093. if (File.Exists(imageFile))
  2094. {
  2095. //删除文件
  2096. (bool, string) newResult = DeleteFile(imageFile);
  2097. if (!newResult.Item1)
  2098. {
  2099. return (0, Path.GetFileName(imageFile) + newResult.Item2);
  2100. }
  2101. }
  2102. }
  2103. }
  2104. return (1, msg);
  2105. }
  2106. catch (Exception e)
  2107. {
  2108. return (0,
  2109. filename + $"文件上传错误!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" +
  2110. e.Message);
  2111. }
  2112. }
  2113. /// <summary>
  2114. /// 获取路径下的所有图片
  2115. /// </summary>
  2116. /// <param name="directoryPath"></param>
  2117. /// <returns></returns>
  2118. public List<string> GetAllImageFiles(string directoryPath)
  2119. {
  2120. var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
  2121. { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
  2122. var imageFiles = new List<string>();
  2123. try
  2124. {
  2125. // 遍历目录及子目录中的所有文件
  2126. foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
  2127. {
  2128. // 获取文件扩展名并检查是否为图片格式
  2129. string extension = Path.GetExtension(file);
  2130. if (imageExtensions.Contains(extension))
  2131. {
  2132. imageFiles.Add(file);
  2133. }
  2134. }
  2135. }
  2136. catch (Exception ex)
  2137. {
  2138. OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
  2139. }
  2140. return imageFiles;
  2141. }
  2142. /// <summary>
  2143. /// 实例化报警字典
  2144. /// </summary>
  2145. private (bool, string) InitalDicAlarm()
  2146. {
  2147. #region 加载报警表
  2148. string excelPath = "";
  2149. switch (GlobalContext.IsUsePLCNow)
  2150. {
  2151. case 1:
  2152. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_10_壳体清洁上料.xlsx";
  2153. break;
  2154. case 2:
  2155. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_20_上盖板上料装备.xlsx";
  2156. break;
  2157. case 3:
  2158. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_30_点散热胶装备.xlsx";
  2159. break;
  2160. case 4:
  2161. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_40_胶线检测.xlsx";
  2162. break;
  2163. case 5:
  2164. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_50_ADD板上料组装装备.xlsx";
  2165. break;
  2166. case 6:
  2167. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_60_组上盖板.xlsx";
  2168. break;
  2169. case 7:
  2170. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_70_上盖板锁螺丝.xlsx";
  2171. break;
  2172. case 8:
  2173. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_80_NG下料.xlsx";
  2174. break;
  2175. case 9:
  2176. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_90_半成品下料.xlsx";
  2177. break;
  2178. default:
  2179. return (false, $"不支持当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请在设置页切换到正确的plc后重启该软件!");
  2180. }
  2181. if (!File.Exists(excelPath))
  2182. return (false, $"未找到当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请检查文件路径:'{excelPath}'。");
  2183. DataTable DtModel = NPOIHelper.ReadExcel(excelPath);
  2184. if (DtModel == null || DtModel.Rows.Count < 1)
  2185. return (false, $"报警点位表未包含任何报警数据!请检查‘{excelPath}’文件!");
  2186. // 检查列名
  2187. List<string> isNeedParms = new List<string>()
  2188. {
  2189. "设备分类名称", "设备分类编码", "分类层级1", "分类层级2", "分类层级3", "分类层级4", "事件名称", "事件ID", "描述", "标签", "PLC地址", "工位"
  2190. }; // 必须要有的列
  2191. // 指定列名 + 检查列是否完整
  2192. DataRow dtRowName = DtModel.Rows[0];
  2193. int count = DtModel.Columns.Count;
  2194. for (int i = 0; i < count; i++)
  2195. {
  2196. string columeName = dtRowName[i]?.ToString();
  2197. if (!string.IsNullOrEmpty(columeName))
  2198. DtModel.Columns[i].ColumnName = columeName;
  2199. if ((!string.IsNullOrEmpty(columeName)) && isNeedParms.Count > 0 && isNeedParms.Contains(columeName))
  2200. isNeedParms.Remove(columeName);
  2201. }
  2202. DtModel.Rows.RemoveAt(0);
  2203. if (isNeedParms.Count > 0)
  2204. {
  2205. string msg1 = string.Join(",", isNeedParms);
  2206. return (false, $"报警点位表未包含列:{msg1}!请检查‘{excelPath}’文件!");
  2207. }
  2208. #endregion 加载报警表
  2209. List<Alarm> keyValues1 = new List<Alarm>();
  2210. for (int i = 0; i < DtModel.Rows.Count; i++)
  2211. {
  2212. Alarm alarm = new Alarm();
  2213. alarm.plcName = DtModel.Rows[i]["设备分类名称"]?.ToString(); // 设备名;
  2214. string type1Str = DtModel.Rows[i]["分类层级1"]?.ToString(); // 分类层级1;
  2215. alarm.type1CH = type1Str; // 分类层级1 中文
  2216. alarm.type1 = type1Str; // 分类层级1
  2217. if (!string.IsNullOrEmpty(type1Str) && type1Str.Contains("\n"))
  2218. {
  2219. string[] type1Strs = type1Str.Split('\n');
  2220. if (type1Strs.Length >= 2)
  2221. {
  2222. alarm.type1CH = type1Strs[0].Trim(); // 分类层级1 中文
  2223. alarm.type1 = type1Strs[1].Trim(); // 分类层级1
  2224. if (string.IsNullOrEmpty(alarm.type1))
  2225. alarm.type1 = alarm.type1CH;
  2226. }
  2227. }
  2228. string type2Str = DtModel.Rows[i]["分类层级2"]?.ToString(); // 分类层级2;电气控制 electric_control
  2229. alarm.type2CH = type2Str; // 分类层级2 中文
  2230. alarm.type2 = type2Str; // 分类层级2
  2231. if (!string.IsNullOrEmpty(type2Str) && type2Str.Contains("\n"))
  2232. {
  2233. string[] type2Strs = type2Str.Split('\n');
  2234. if (type2Strs.Length >= 2)
  2235. {
  2236. alarm.type2CH = type2Strs[0].Trim(); // 分类层级2 中文
  2237. alarm.type2 = type2Strs[1].Trim(); // 分类层级2
  2238. if (string.IsNullOrEmpty(alarm.type2))
  2239. alarm.type2 = alarm.type2CH;
  2240. }
  2241. }
  2242. string type3Str = DtModel.Rows[i]["分类层级3"]?.ToString(); // 分类层级3;故障 Fault
  2243. alarm.type3CH = type3Str; // 分类层级3 中文
  2244. alarm.type3 = type3Str; // 分类层级3
  2245. if (!string.IsNullOrEmpty(type3Str) && type3Str.Contains("\n"))
  2246. {
  2247. string[] type3Strs = type3Str.Split('\n');
  2248. if (type3Strs.Length >= 2)
  2249. {
  2250. alarm.type3CH = type3Strs[0].Trim(); // 分类层级3 中文
  2251. alarm.type3 = type3Strs[1].Trim(); // 分类层级3
  2252. if (string.IsNullOrEmpty(alarm.type3))
  2253. alarm.type3 = alarm.type3CH;
  2254. }
  2255. }
  2256. string faultStr = DtModel.Rows[i]["分类层级4"]?.ToString(); // 故障部件;overall_module
  2257. alarm.type4 = faultStr; // 分类层级4 中文
  2258. alarm.type4CH = faultStr; // 分类层级4
  2259. if (!string.IsNullOrEmpty(faultStr) && faultStr.Contains("\n"))
  2260. {
  2261. string[] faultStrs = faultStr.Split('\n');
  2262. if (faultStrs.Length >= 2)
  2263. {
  2264. alarm.type4CH = faultStrs[0].Trim(); // 故障部件;overall_module
  2265. alarm.type4 = faultStrs[1].Trim(); // 故障部件
  2266. if (string.IsNullOrEmpty(alarm.type4))
  2267. alarm.type4 = alarm.type4CH;
  2268. }
  2269. }
  2270. alarm.fault_code = DtModel.Rows[i]["事件ID"]?.ToString(); // 故障编码;A40001
  2271. alarm.fault_name = DtModel.Rows[i]["事件名称"]?.ToString(); // 故障名称;AL[1000]_系统_HMI急停故障
  2272. alarm.fault_desc = alarm.fault_name; // 故障描述;AL[1000]_系统_HMI急停故障
  2273. string plcAdress = DtModel.Rows[i]["PLC地址"]?.ToString();
  2274. alarm.PLC地址 = plcAdress;
  2275. plcAdress = plcAdress.Replace("fault_codes[", "");
  2276. plcAdress = plcAdress.Replace("]", "");
  2277. alarm.group_index = Convert.ToInt32(plcAdress.Split(".")[0]);
  2278. keyValues1.Add(alarm);
  2279. }
  2280. DicAlarms_Cur.Add(GlobalContext.IsUseStationName, keyValues1); // 这里使用线体代替工位
  2281. return (true, "报警字典表初始化成功!");
  2282. }
  2283. private async void ReadPLCAlarmToIot(uint[] FaultData, uint[] FaultDataOld, string stationNameStr,string flag)
  2284. {
  2285. DateTime dtNow = DateTime.Now;
  2286. try
  2287. {
  2288. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  2289. List<(int, int)> AlarmIndexList = new List<(int, int)>(); //收集所有报警信息的位置
  2290. AlarmData alarmData = new AlarmData();
  2291. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  2292. bool isNoAlarm = false; //是否有报警
  2293. string binaryString = "";
  2294. bool isNoNewAlarm = false; //是否有新的报警
  2295. if (FaultData.Length > 0)
  2296. {
  2297. foreach (var item in FaultData)
  2298. {
  2299. if (item > 0)
  2300. {
  2301. isNoAlarm = true;
  2302. break;
  2303. }
  2304. else {
  2305. isNoAlarm = false;
  2306. }
  2307. }
  2308. if (!FaultData.SequenceEqual(FaultDataOld))
  2309. {
  2310. isNoNewAlarm = true;
  2311. isNeedUpdUI = true;
  2312. }
  2313. if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
  2314. {
  2315. //解析报警信息,分析当前报警在字典中的定位
  2316. for (int i = 0; i <= FaultData.Length - 1; i++)
  2317. {
  2318. var num = 0;
  2319. if (FaultData[i] > 0)
  2320. {
  2321. //转换二进制
  2322. binaryString = Convert.ToString(FaultData[i], 2);
  2323. for (int j = binaryString.Length - 1; j >= 0; j--)
  2324. {
  2325. num++;
  2326. char s = binaryString[j];
  2327. if (binaryString[j] == '1')
  2328. {
  2329. //记录1的位置
  2330. AlarmIndexList.Add((i, num - 1));
  2331. }
  2332. }
  2333. }
  2334. }
  2335. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  2336. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
  2337. foreach ((int index, int row) in AlarmIndexList)
  2338. {
  2339. var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
  2340. for (int i = 0; i < tempDic.Count - 1; i++) // 读取
  2341. {
  2342. //若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
  2343. if (tempDic[i].group_index == index && i == row)
  2344. {
  2345. dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 =
  2346. new AlarmData()
  2347. {
  2348. GUID = Guid.NewGuid().ToString(),
  2349. LineName = GlobalContext.IsUseStationName, // 工站
  2350. PlcStation = tempDic[i].plcName, // 工站全称;[S1]
  2351. Type1 = tempDic[i].type1, // 故障层级1
  2352. Type2 = tempDic[i].type2, // 故障层级2
  2353. Type3 = tempDic[i].type3, // 故障层级3
  2354. Type4 = tempDic[i].type4, // 故障层级4
  2355. AlarmType = tempDic[i].fault_code, // 报警类型
  2356. AlarmDesc = tempDic[i].fault_name, // 报警内容
  2357. StartTime = dtNow // 开始时间
  2358. };
  2359. // 传输到页面
  2360. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  2361. {
  2362. 线体名称 = tempDic[i].plcName,
  2363. 报警类型 = tempDic[i].fault_code,
  2364. 报警内容 = tempDic[i].fault_name,
  2365. 开始时间 = dtNow
  2366. });
  2367. // 新增到数据库
  2368. //var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
  2369. //SaveAlarmDataByDB(stationNameStr, data1, false);
  2370. //OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
  2371. }
  2372. }
  2373. }
  2374. //筛选含报警数据的字典
  2375. var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
  2376. if (dicAlarms_Cur.Count > 0)
  2377. {
  2378. string stationId = "";
  2379. foreach (var item in dicAlarms_Cur)
  2380. {
  2381. if (!string.IsNullOrEmpty(xiaomiParm.stationCode))
  2382. {
  2383. stationId = xiaomiParm.stationCode;
  2384. //上传
  2385. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2386. }
  2387. else {
  2388. if (flag == "left")
  2389. {
  2390. if (GlobalContext.IsUsePLC3)
  2391. stationId = GlobalContext.s3_1_station;
  2392. if (GlobalContext.IsUsePLC7)
  2393. stationId = GlobalContext.s7_1_station;
  2394. //上传
  2395. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2396. }
  2397. else {
  2398. if (GlobalContext.IsUsePLC3)
  2399. stationId = GlobalContext.s3_2_station;
  2400. if (GlobalContext.IsUsePLC7)
  2401. stationId = GlobalContext.s7_2_station;
  2402. //上传
  2403. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2404. }
  2405. }
  2406. }
  2407. }
  2408. // 有新报警则更新
  2409. if (isNeedUpdUI)
  2410. // UI展示 - 展示到设备状态页
  2411. await Task.Run(() =>
  2412. {
  2413. try
  2414. {
  2415. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  2416. {
  2417. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  2418. if (Form_Main.formDevAlarm.Visible)
  2419. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  2420. }
  2421. }
  2422. catch
  2423. {
  2424. }
  2425. });
  2426. if (flag == "left")
  2427. {
  2428. _FaultDatas_Old = FaultData.ToArray();
  2429. }
  2430. else {
  2431. _FaultDatas_Old2 = FaultData.ToArray();
  2432. }
  2433. }
  2434. }
  2435. //FaultLogRequest request = new FaultLogRequest();
  2436. //request.station = mesStation; // 工位
  2437. //request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
  2438. //request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
  2439. //request.fault_cmpnt = xmFaultCmpnt; // 故障部件
  2440. //request.fault_desc = xmFaultDesc; // 故障描述
  2441. //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发生时间 2022-06-01 14:27:57.283
  2442. // // 上传
  2443. //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
  2444. }
  2445. catch (Exception ex)
  2446. {
  2447. string str = ex.StackTrace;
  2448. AddMessage_Station(stationNameStr, LogType.Error,
  2449. $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  2450. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2451. }
  2452. }
  2453. public void operateToIot(string action, string stationNameStr)
  2454. {
  2455. OperateLogRequest request = new OperateLogRequest();
  2456. request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
  2457. request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
  2458. request.operate_action = action; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
  2459. //request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
  2460. request.current_process = Application.ProductName;
  2461. request.operate_desc = stationNameStr; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
  2462. request.operate_result = "success"; // 操作结果
  2463. request.operator_name = "default"; // 操作账号名;填当前操作⽤⼾,如⽆则填default
  2464. // 上传
  2465. (int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
  2466. if (iotResult.Item1 != 0)
  2467. {
  2468. AddMessage(LogType.Info, "【操作记录】上传失败!错误原因:" + iotResult.Item2 + "操作状态:" + stationNameStr);
  2469. }
  2470. }
  2471. private void 通用节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
  2472. IoT_DataSet_t iot_data, out int res)
  2473. {
  2474. Stopwatch stopwatch1 = new Stopwatch();
  2475. Stopwatch stopwatch2 = new Stopwatch();
  2476. string resultStr = string.Empty;
  2477. try
  2478. {
  2479. string oEEType = iot_data.beatAction.ToString(); // 节拍类型(plc写入)
  2480. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
  2481. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  2482. (short, string) result = (0, "");
  2483. // 上传开始节拍
  2484. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2485. //上传结束节拍
  2486. switch (oEEType)
  2487. {
  2488. case "1":
  2489. Enum.TryParse("2", out deviceOEE);
  2490. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2491. break;
  2492. case "5":
  2493. Enum.TryParse("6", out deviceOEE);
  2494. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2495. break;
  2496. }
  2497. if (result.Item1 == 1)
  2498. {
  2499. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]上传成功!");
  2500. //写入PLC
  2501. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2502. iotData.machineState = iot_data.machineState;
  2503. iotData.work_type = iot_data.work_type;
  2504. iotData.testStatus = iot_data.testStatus;
  2505. iotData.beatAction = 0;
  2506. iotData.beatReturn = 1; //OK
  2507. iotData.fault_codes = iot_data.fault_codes;
  2508. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2509. if (PLCresult.Item1 == 0)
  2510. {
  2511. res = 1;
  2512. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]写入成功!");
  2513. }
  2514. else
  2515. {
  2516. res = 0;
  2517. }
  2518. }
  2519. else
  2520. {
  2521. res = 0;
  2522. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]接口出错!错误信息:" + result.Item2);
  2523. //写入PLC
  2524. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2525. iotData.machineState = iot_data.machineState;
  2526. iotData.work_type = iot_data.work_type;
  2527. iotData.testStatus = iot_data.testStatus;
  2528. iotData.beatAction = 0;
  2529. iotData.beatReturn = 2; //NG
  2530. iotData.fault_codes = iot_data.fault_codes;
  2531. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2532. }
  2533. }
  2534. catch (Exception ex)
  2535. {
  2536. res = 0;
  2537. string str = ex.StackTrace;
  2538. AddMessage_Station(stationNameStr, LogType.Error,
  2539. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  2540. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2541. //写入PLC
  2542. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2543. iotData.machineState = iot_data.machineState;
  2544. iotData.work_type = iot_data.work_type;
  2545. iotData.testStatus = iot_data.testStatus;
  2546. iotData.beatAction = 0;
  2547. iotData.beatReturn = 2; //NG
  2548. iotData.fault_codes = iot_data.fault_codes;
  2549. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2550. }
  2551. }
  2552. /// <summary>
  2553. /// 去除常见特殊字符,如 \r, \n, \t 等
  2554. /// </summary>
  2555. /// <param name="format"></param>
  2556. /// <returns></returns>
  2557. private static string FormatStrbyPLC(string format)
  2558. {
  2559. string cleanedString = "";
  2560. if (!string.IsNullOrEmpty(format))
  2561. {
  2562. cleanedString = Regex.Replace(format, @"[\r\n\t]", "");
  2563. }
  2564. return cleanedString;
  2565. }
  2566. #endregion
  2567. #region S1
  2568. /// <summary>
  2569. /// [S1] 壳体清洁上料装备
  2570. /// </summary>
  2571. /// <param name="plcNo">PLC编号</param>
  2572. private void ReadStation_S1(int plcNo)
  2573. {
  2574. string stationCode = "[OP10]";
  2575. string stationName = "壳体清洁上料";
  2576. string stationNameStr = stationCode + stationName;
  2577. string tagBaseName = "g_OP10_MES"; //标签变量名称
  2578. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2579. string tagAgvCommName = "agvCommFrmPC";
  2580. string tagiotComnName = "iotData";
  2581. string tagBarsetName = "BarcodeSet";
  2582. string CarrierBarcode = "";
  2583. string ProductBarcode = "";
  2584. // 触发信号字典
  2585. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2586. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2587. // PLC数据字典 赋值
  2588. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2589. s1PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  2590. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  2591. (int, string) result;
  2592. while (true)
  2593. {
  2594. try
  2595. {
  2596. if (!GlobalContext._IsCon_Funs1)
  2597. {
  2598. UpdatePLCMonitor(1, plcNo, 0);
  2599. continue;
  2600. }
  2601. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2602. {
  2603. Stopwatch stopwatch1 = new Stopwatch();
  2604. Stopwatch stopwatch2 = new Stopwatch();
  2605. stopwatch1.Start();
  2606. stopwatch2.Start();
  2607. #region 一次性读取所有数据
  2608. // 一次性读取所有数据
  2609. result = FunsEip[plcNo]
  2610. .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2611. if (result.Item1 != 0)
  2612. {
  2613. //richTextBox1.AppendText("\n" + strRet);
  2614. }
  2615. else
  2616. {
  2617. //richTextBox1.AppendText("\n" + "读取成功");
  2618. stPLC_MesData.BarcodeSet.strProductBarcode =
  2619. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  2620. stPLC_MesData.BarcodeSet.strPartBarcode =
  2621. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  2622. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  2623. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  2624. stPLC_MesData.BarcodeSet.strPCBBarcode =
  2625. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  2626. //设备状态
  2627. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2628. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2629. ? XiaomiDeviceState.Unknown
  2630. : (XiaomiDeviceState)xmDeviceStateInt;
  2631. // 载具SN
  2632. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  2633. // 物料码(物料码还未绑定载具SN时必填)
  2634. ProductBarcode = stPLC_MesData.BarcodeSet.strProductBarcode;
  2635. // 节拍
  2636. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.beatAction;
  2637. //报警信息
  2638. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  2639. }
  2640. #endregion 一次性读取所有数据
  2641. stopwatch2.Stop();
  2642. #region 进站
  2643. try
  2644. {
  2645. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2646. {
  2647. lock (lockObj)
  2648. {
  2649. if (!ProgressState)
  2650. {
  2651. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  2652. ProgressState = true;
  2653. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
  2654. tagBaseName + "." + tagMesCommName, out ProgressState));
  2655. }
  2656. }
  2657. }
  2658. }
  2659. catch (Exception ex)
  2660. {
  2661. ProgressState = false;
  2662. string str = ex.StackTrace;
  2663. AddMessage_Station(stationNameStr, LogType.Error,
  2664. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2665. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2666. }
  2667. #endregion 进站
  2668. #region 出站
  2669. try
  2670. {
  2671. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2672. {
  2673. lock (lockObj)
  2674. {
  2675. if (!ProgressState)
  2676. {
  2677. ProgressState = true;
  2678. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
  2679. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2680. out ProgressState));
  2681. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2682. }
  2683. }
  2684. }
  2685. }
  2686. catch (Exception ex)
  2687. {
  2688. ProgressState = false;
  2689. string str = ex.StackTrace;
  2690. AddMessage_Station(stationNameStr, LogType.Error,
  2691. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2692. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2693. }
  2694. #endregion 出站
  2695. #region 节拍接口
  2696. try
  2697. {
  2698. if (stPLC_MesData.iotData.beatAction > 0)
  2699. {
  2700. int a1OEEType = Convert.ToInt32(s1PLCData["a1OEEType"]);
  2701. int a1OEETypeGOld = Convert.ToInt32(s1PLCSignal_Old["a1OEEType"]);
  2702. if (a1OEEType != a1OEETypeGOld)
  2703. {
  2704. s1PLCData["OEETypeFlag"] = "1";
  2705. }
  2706. else
  2707. {
  2708. s1PLCData["OEETypeFlag"] = "0";
  2709. }
  2710. if (s1PLCData["OEETypeFlag"].ToString() == "1" && (a1OEEType == 1 || a1OEEType == 3 || a1OEEType == 4 || a1OEEType == 5))
  2711. {
  2712. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  2713. if (res == 1)
  2714. {
  2715. s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
  2716. }
  2717. else {
  2718. s1PLCSignal_Old["a1OEEType"] = 0;
  2719. }
  2720. }
  2721. }
  2722. else {
  2723. s1PLCSignal_Old["a1OEEType"] = 0;
  2724. }
  2725. }
  2726. catch (Exception ex)
  2727. {
  2728. string str = ex.StackTrace;
  2729. AddMessage_Station(stationNameStr, LogType.Error,
  2730. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2731. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2732. }
  2733. #endregion
  2734. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2735. stopwatch1.Stop();
  2736. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2737. }
  2738. else
  2739. {
  2740. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2741. AddMessage_Station(stationNameStr, LogType.Info,
  2742. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2743. FunsEip[plcNo].Connect(); // 重连
  2744. }
  2745. }
  2746. catch (Exception ex)
  2747. {
  2748. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2749. AddMessage_Station(stationNameStr, LogType.Error,
  2750. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2751. }
  2752. Thread.Sleep(IntervalReadPLC);
  2753. }
  2754. }
  2755. /// <summary>
  2756. /// [S1] 壳体清洁上料 - 进站
  2757. /// </summary>
  2758. /// <param name="plcNo">PLC编号</param>
  2759. /// <param name="stationNameStr">工站全称</param>
  2760. /// <param name="stPLC_MesData"></param>
  2761. /// <param name="tagMesCommName"></param>
  2762. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2763. out bool ProgressState)
  2764. {
  2765. Stopwatch stopwatch1 = new Stopwatch();
  2766. Stopwatch stopwatch2 = new Stopwatch();
  2767. try
  2768. {
  2769. stopwatch1.Start();
  2770. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2771. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  2772. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2773. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  2774. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  2775. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2776. bool pass = a1Result == 1;
  2777. if (string.IsNullOrEmpty(sn))
  2778. {
  2779. ProgressState = false;
  2780. AddMessage(LogType.Error, $"{stationNameStr}_未能查到产品码");
  2781. Thread.Sleep(10000);
  2782. return;
  2783. }
  2784. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  2785. // sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2786. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2787. //绑定载具和产品
  2788. ResponseMessage message = new ResponseMessage();
  2789. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  2790. if (message.result == false)
  2791. {
  2792. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  2793. ProgressState = false;
  2794. Thread.Sleep(10000);
  2795. return;
  2796. }
  2797. // 产品SN进站
  2798. List<TestItem> item = new List<TestItem>();
  2799. stopwatch2.Start();
  2800. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  2801. item, MachineId, StationId, pass, "01-SLOT-01");
  2802. stopwatch2.Stop();
  2803. //指令执行结果 1:OK 110:失败
  2804. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2805. if (mesResultFrmWeb == 1)
  2806. {
  2807. if (a1Result == 1)
  2808. {
  2809. mesResultFrmWeb = 1;
  2810. }
  2811. else
  2812. {
  2813. mesResultFrmWeb = 110;
  2814. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  2815. }
  2816. }
  2817. //进站结果写入PLC
  2818. CommandFromPLC resultToPlC = new CommandFromPLC();
  2819. resultToPlC.cmd = 0;
  2820. resultToPlC.cmdParam = 0;
  2821. resultToPlC.cmdResult = mesResultFrmWeb;
  2822. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2823. }
  2824. catch (Exception ex)
  2825. {
  2826. string str = ex.StackTrace;
  2827. AddMessage(LogType.Error,
  2828. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  2829. str.Length - str.LastIndexOf("\\") - 1));
  2830. CommandFromPLC resultToPlC = new CommandFromPLC();
  2831. resultToPlC.cmd = 0;
  2832. resultToPlC.cmdParam = 0; //指令参数
  2833. resultToPlC.cmdResult = 110;
  2834. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2835. }
  2836. stopwatch1.Stop();
  2837. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2838. AddMessage(LogType.Info,
  2839. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  2840. stopwatch2.ElapsedMilliseconds + "ms");
  2841. ProgressState = false;
  2842. }
  2843. /// <summary>
  2844. /// [S1] 壳体清洁上料 - 出站接口
  2845. /// </summary>
  2846. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2847. string stationCode, string stationName, out bool ProgressState)
  2848. {
  2849. Stopwatch stopwatch1 = new Stopwatch();
  2850. Stopwatch stopwatch2 = new Stopwatch();
  2851. try
  2852. {
  2853. stopwatch1.Start();
  2854. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2855. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2856. string processItem = stationName; // 项目
  2857. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2858. string supplierCode = ""; // 供应商代码
  2859. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  2860. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  2861. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  2862. string sn = string.Empty;
  2863. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2864. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  2865. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  2866. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2867. //a1Result = 1;
  2868. bool pass = a1Result == 1;
  2869. //根据载具码获取产品码
  2870. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2871. if (string.IsNullOrEmpty(strProductBarcode))
  2872. {
  2873. ProgressState = false;
  2874. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  2875. Thread.Sleep(10000);
  2876. return;
  2877. }
  2878. sn = strProductBarcode;
  2879. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2880. List<TestItem> items = new List<TestItem>();
  2881. items.Add(new TestItem()
  2882. {
  2883. Parameter_name = "载具码",
  2884. Parameter_value = CarrierBarcode,
  2885. Parameter_unit = ""
  2886. });
  2887. items.Add(new TestItem()
  2888. {
  2889. Parameter_name = "产品码",
  2890. Parameter_value = sn,
  2891. Parameter_unit = ""
  2892. });
  2893. #region 转换过站明细字符串
  2894. //创建字典
  2895. var dic = new Dictionary<string, string>();
  2896. // 获取结构体类型
  2897. FieldInfo[] fields = typeof(OP10_DataSet_t).GetFields();
  2898. // 遍历变量名转换成字典描述
  2899. foreach (FieldInfo field in fields)
  2900. {
  2901. //获取枚举描述
  2902. string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  2903. typeof(XiaomiMESEnum_ProcessData.Enum_10_ProcessData));
  2904. //获取过站明细的值
  2905. object valueObj = field.GetValue(stPLC_MesData.mesData);
  2906. dic.Add(name, valueObj.ToString());
  2907. }
  2908. string paramJson = JsonConvert.SerializeObject(dic);
  2909. #endregion
  2910. //出站接口
  2911. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2912. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  2913. MachineId, StationId, "", paramJson);
  2914. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2915. if (mesResultFrmWeb == 1)
  2916. {
  2917. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  2918. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  2919. }
  2920. stopwatch2.Start();
  2921. //进站结果写入PLC
  2922. CommandFromPLC resultToPlC = new CommandFromPLC();
  2923. resultToPlC.cmd = 0;
  2924. resultToPlC.cmdParam = 0; //指令参数
  2925. resultToPlC.cmdResult = mesResultFrmWeb;
  2926. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2927. stopwatch2.Stop();
  2928. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2929. //保存PLC返回MES数据到本地
  2930. ResponseMessage message = new ResponseMessage();
  2931. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  2932. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
  2933. stPLC_MesData.mesData.fCleanSpeed,
  2934. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
  2935. stPLC_MesData.mesData.nCleanCount,
  2936. stPLC_MesData.mesData.nRemainCount);
  2937. if (message.result == false)
  2938. {
  2939. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2940. }
  2941. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  2942. }
  2943. catch (Exception ex)
  2944. {
  2945. stopwatch2.Start();
  2946. CommandFromPLC resultToPlC = new CommandFromPLC();
  2947. resultToPlC.cmd = 0;
  2948. resultToPlC.cmdParam = 0; //指令参数
  2949. resultToPlC.cmdResult = 110;
  2950. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2951. stopwatch2.Stop();
  2952. string str = ex.StackTrace;
  2953. AddMessage(LogType.Error,
  2954. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  2955. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2956. }
  2957. stopwatch1.Stop();
  2958. AddMessage(LogType.Info,
  2959. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  2960. stopwatch2.ElapsedMilliseconds + "ms");
  2961. ProgressState = false;
  2962. uuid = "";
  2963. }
  2964. #endregion
  2965. #region S2
  2966. /// <summary>
  2967. /// [S2] 上盖板上料装备
  2968. /// </summary>
  2969. /// <param name="plcNo">PLC编号</param>
  2970. private void ReadStation_S2(int plcNo)
  2971. {
  2972. string stationCode = "[OP20]";
  2973. string stationName = "上盖板上料装备";
  2974. string stationNameStr = stationCode + stationName;
  2975. string tagBaseName = "g_OP20_MES"; //标签变量名称
  2976. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2977. string tagAgvCommName = "agvCommFrmPC";
  2978. string tagiotComnName = "iotData";
  2979. string tagBarsetName = "BarcodeSet";
  2980. string CarrierBarcode = "";
  2981. // 触发信号字典
  2982. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2983. s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
  2984. // PLC数据字典 赋值
  2985. s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
  2986. s2PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  2987. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  2988. (int, string) result;
  2989. while (true)
  2990. {
  2991. try
  2992. {
  2993. if (!GlobalContext._IsCon_Funs2)
  2994. {
  2995. UpdatePLCMonitor(1, plcNo, 0);
  2996. continue;
  2997. }
  2998. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2999. {
  3000. Stopwatch stopwatch1 = new Stopwatch();
  3001. Stopwatch stopwatch2 = new Stopwatch();
  3002. stopwatch1.Start();
  3003. stopwatch2.Start();
  3004. #region 一次性读取所有数据
  3005. // 一次性读取所有数据
  3006. result = FunsEip[plcNo]
  3007. .Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3008. if (result.Item1 != 0)
  3009. {
  3010. //richTextBox1.AppendText("\n" + strRet);
  3011. }
  3012. else
  3013. {
  3014. //richTextBox1.AppendText("\n" + "读取成功");
  3015. stPLC_MesData.BarcodeSet.strProductBarcode =
  3016. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  3017. stPLC_MesData.BarcodeSet.strPartBarcode =
  3018. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  3019. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  3020. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  3021. stPLC_MesData.BarcodeSet.strPCBBarcode =
  3022. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  3023. //设备状态
  3024. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3025. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3026. ? XiaomiDeviceState.Unknown
  3027. : (XiaomiDeviceState)xmDeviceStateInt;
  3028. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3029. s2PLCData["a2OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  3030. //报警信息
  3031. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  3032. }
  3033. #endregion 一次性读取所有数据
  3034. stopwatch2.Stop();
  3035. #region 进站
  3036. try
  3037. {
  3038. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3039. {
  3040. lock (lockObj)
  3041. {
  3042. if (!ProgressState)
  3043. {
  3044. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3045. ProgressState = true;
  3046. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
  3047. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3048. out ProgressState));
  3049. }
  3050. }
  3051. }
  3052. }
  3053. catch (Exception ex)
  3054. {
  3055. ProgressState = false;
  3056. string str = ex.StackTrace;
  3057. AddMessage_Station(stationNameStr, LogType.Error,
  3058. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3059. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3060. }
  3061. #endregion 进站
  3062. #region 出站
  3063. try
  3064. {
  3065. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3066. {
  3067. lock (lockObj)
  3068. {
  3069. if (!ProgressState)
  3070. {
  3071. ProgressState = true;
  3072. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
  3073. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3074. out ProgressState));
  3075. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  3076. }
  3077. }
  3078. }
  3079. }
  3080. catch (Exception ex)
  3081. {
  3082. ProgressState = false;
  3083. string str = ex.StackTrace;
  3084. AddMessage_Station(stationNameStr, LogType.Error,
  3085. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3086. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3087. }
  3088. #endregion 出站
  3089. #region 节拍接口
  3090. try
  3091. {
  3092. if (stPLC_MesData.iotData.beatAction > 0)
  3093. {
  3094. int a2OEEType = Convert.ToInt32(s2PLCData["a2OEEType"]);
  3095. int a2OEETypeGOld = Convert.ToInt32(s2PLCSignal_Old["a2OEEType"]);
  3096. if (a2OEEType != a2OEETypeGOld)
  3097. {
  3098. s2PLCData["OEETypeFlag"] = "1";
  3099. }
  3100. else
  3101. {
  3102. s2PLCData["OEETypeFlag"] = "0";
  3103. }
  3104. if (s2PLCData["OEETypeFlag"].ToString() == "1" && (a2OEEType == 1 || a2OEEType == 3 || a2OEEType == 4 || a2OEEType == 5))
  3105. {
  3106. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  3107. if (res == 1)
  3108. {
  3109. s2PLCSignal_Old["a2OEEType"] = s2PLCData["a2OEEType"];
  3110. }
  3111. else
  3112. {
  3113. s2PLCSignal_Old["a2OEEType"] = 0;
  3114. }
  3115. }
  3116. }
  3117. else {
  3118. s2PLCSignal_Old["a2OEEType"] = 0;
  3119. }
  3120. }
  3121. catch (Exception ex)
  3122. {
  3123. string str = ex.StackTrace;
  3124. AddMessage_Station(stationNameStr, LogType.Error,
  3125. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3126. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3127. }
  3128. #endregion
  3129. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3130. stopwatch1.Stop();
  3131. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3132. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3133. }
  3134. else
  3135. {
  3136. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3137. AddMessage_Station(stationNameStr, LogType.Info,
  3138. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3139. FunsEip[plcNo].Connect();
  3140. }
  3141. }
  3142. catch (Exception ex)
  3143. {
  3144. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3145. AddMessage_Station(stationNameStr, LogType.Error,
  3146. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3147. //Funs[plcNo].ReConnect();
  3148. }
  3149. Thread.Sleep(IntervalReadPLC);
  3150. }
  3151. }
  3152. /// <summary>
  3153. /// [S2] 上盖板上料装备
  3154. /// </summary>
  3155. /// <param name="plcNo">PLC编号</param>
  3156. /// <param name="stationNameStr">工站全称</param>
  3157. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3158. string tagBarsetName, out bool ProgressState)
  3159. {
  3160. Stopwatch stopwatch1 = new Stopwatch();
  3161. Stopwatch stopwatch2 = new Stopwatch();
  3162. try
  3163. {
  3164. stopwatch1.Start();
  3165. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3166. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  3167. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3168. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3169. bool pass = a1Result == 1;
  3170. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  3171. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  3172. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3173. //根据载具码获取产品码
  3174. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3175. if (string.IsNullOrEmpty(strProductBarcode))
  3176. {
  3177. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3178. ProgressState = false;
  3179. Thread.Sleep(10000);
  3180. return;
  3181. }
  3182. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  3183. //if (sn != strProductBarcode)
  3184. //{
  3185. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  3186. //}
  3187. sn = strProductBarcode;
  3188. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3189. // 产品SN(物料码)校验
  3190. List<TestItem> item = new List<TestItem>();
  3191. stopwatch2.Start();
  3192. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3193. item, MachineId, StationId, pass, "01-SLOT-01");
  3194. stopwatch2.Stop();
  3195. //指令执行结果 1:OK 110:失败
  3196. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3197. if (mesResultFrmWeb == 1)
  3198. {
  3199. if (a1Result == 1)
  3200. {
  3201. mesResultFrmWeb = 1;
  3202. }
  3203. else
  3204. {
  3205. mesResultFrmWeb = 110;
  3206. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3207. }
  3208. }
  3209. //进站结果写入PLC
  3210. CommandFromPLC resultToPlC = new CommandFromPLC();
  3211. resultToPlC.cmd = 0;
  3212. resultToPlC.cmdParam = 0; //指令参数
  3213. resultToPlC.cmdResult = mesResultFrmWeb;
  3214. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3215. }
  3216. catch (Exception ex)
  3217. {
  3218. string str = ex.StackTrace;
  3219. AddMessage(LogType.Error,
  3220. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3221. str.Length - str.LastIndexOf("\\") - 1));
  3222. CommandFromPLC resultToPlC = new CommandFromPLC();
  3223. resultToPlC.cmd = 0;
  3224. resultToPlC.cmdParam = 0; //指令参数
  3225. resultToPlC.cmdResult = 110;
  3226. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3227. }
  3228. stopwatch1.Stop();
  3229. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3230. AddMessage(LogType.Info,
  3231. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3232. stopwatch2.ElapsedMilliseconds + "ms");
  3233. ProgressState = false;
  3234. }
  3235. /// <summary>
  3236. /// [S2] 上盖板上料装备 - 出站接口
  3237. /// </summary>
  3238. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3239. string stationCode, string stationName, out bool ProgressState)
  3240. {
  3241. Stopwatch stopwatch1 = new Stopwatch();
  3242. Stopwatch stopwatch2 = new Stopwatch();
  3243. try
  3244. {
  3245. stopwatch1.Start();
  3246. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3247. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3248. string processItem = stationName; // 测试项目
  3249. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3250. string supplierCode = ""; // 供应商代码
  3251. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3252. string batch_num = GlobalContext.BatchNumber; // 批次号
  3253. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3254. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3255. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3256. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  3257. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  3258. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  3259. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3260. bool pass = a1Result == 1;
  3261. //根据载具码获取产品码
  3262. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3263. if (string.IsNullOrEmpty(strProductBarcode))
  3264. {
  3265. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3266. ProgressState = false;
  3267. Thread.Sleep(10000);
  3268. return;
  3269. }
  3270. sn = strProductBarcode;
  3271. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3272. List<TestItem> items = new List<TestItem>();
  3273. items.Add(new TestItem()
  3274. {
  3275. Parameter_name = "载具码",
  3276. Parameter_value = CarrierBarcode,
  3277. Parameter_unit = ""
  3278. });
  3279. items.Add(new TestItem()
  3280. {
  3281. Parameter_name = "产品码",
  3282. Parameter_value = sn,
  3283. Parameter_unit = ""
  3284. });
  3285. items.Add(new TestItem()
  3286. {
  3287. Parameter_name = "部件码",
  3288. Parameter_value = PartBarcode,
  3289. Parameter_unit = ""
  3290. });
  3291. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3292. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3293. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3294. MachineId, StationId, PartBarcode, paramJson);
  3295. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3296. if (mesResultFrmWeb == 1)
  3297. {
  3298. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3299. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3300. }
  3301. stopwatch2.Start();
  3302. //进站结果写入PLC
  3303. CommandFromPLC resultToPlC = new CommandFromPLC();
  3304. resultToPlC.cmd = 0;
  3305. resultToPlC.cmdParam = 0; //指令参数
  3306. resultToPlC.cmdResult = mesResultFrmWeb;
  3307. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3308. stopwatch2.Stop();
  3309. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3310. //保存PLC返回MES数据到本地
  3311. ResponseMessage message = new ResponseMessage();
  3312. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  3313. stPLC_MesData.mesData.nRemainCount);
  3314. if (message.result == false)
  3315. {
  3316. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3317. }
  3318. if (!string.IsNullOrEmpty(PartBarcode))
  3319. {
  3320. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  3321. if (message.result == false)
  3322. {
  3323. AddMessage(LogType.Error, message.text);
  3324. }
  3325. }
  3326. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3327. }
  3328. catch (Exception ex)
  3329. {
  3330. stopwatch2.Start();
  3331. CommandFromPLC resultToPlC = new CommandFromPLC();
  3332. resultToPlC.cmd = 0;
  3333. resultToPlC.cmdParam = 0; //指令参数
  3334. resultToPlC.cmdResult = 110;
  3335. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3336. stopwatch2.Stop();
  3337. string str = ex.StackTrace;
  3338. AddMessage(LogType.Error,
  3339. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3340. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3341. }
  3342. stopwatch1.Stop();
  3343. AddMessage(LogType.Info,
  3344. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3345. stopwatch2.ElapsedMilliseconds + "ms");
  3346. ProgressState = false;
  3347. uuid = "";
  3348. }
  3349. #endregion
  3350. #region S3
  3351. /// <summary>
  3352. /// [S3] 点散热胶装备
  3353. /// </summary>
  3354. /// <param name="plcNo">PLC编号</param>
  3355. private void ReadStation_S3(int plcNo)
  3356. {
  3357. string stationCode = "[OP30]";
  3358. string stationName = "点散热胶装备";
  3359. string stationNameStr = stationCode + stationName;
  3360. string tagBaseName = "g_OP30_MES"; //标签变量名称
  3361. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3362. string tagAgvCommName = "agvCommFrmPC";
  3363. string tagiotComnName = "iotData";
  3364. string tagBarsetName = "BarcodeSet";
  3365. string CarrierBarcode_Left = "";
  3366. string CarrierBarcode_Right = "";
  3367. s3PLCSignal_Old.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3368. s3PLCSignal_Old.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3369. // PLC数据字典 赋值
  3370. s3PLCData.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3371. s3PLCData.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3372. s5PLCData.Add("OEETypeFlag_left", 0); // 节拍标识 0 不上传 ,1 上传
  3373. s5PLCData.Add("OEETypeFlag_right", 0); // 节拍标识 0 不上传 ,1 上传
  3374. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  3375. (int, string) result;
  3376. while (true)
  3377. {
  3378. try
  3379. {
  3380. if (!GlobalContext._IsCon_Funs2)
  3381. {
  3382. UpdatePLCMonitor(1, plcNo, 0);
  3383. continue;
  3384. }
  3385. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3386. {
  3387. Stopwatch stopwatch1 = new Stopwatch();
  3388. Stopwatch stopwatch2 = new Stopwatch();
  3389. stopwatch1.Start();
  3390. stopwatch2.Start();
  3391. #region 一次性读取所有数据
  3392. // 一次性读取所有数据
  3393. result = FunsEip[plcNo]
  3394. .Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3395. if (result.Item1 != 0)
  3396. {
  3397. //richTextBox1.AppendText("\n" + strRet);
  3398. }
  3399. else
  3400. {
  3401. //测试数据
  3402. //stPLC_MesData.Left.mesCommFrmPLC.cmd = 2;
  3403. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3404. //stPLC_MesData.Left.BarcodeSet.strPCBBarcode = "A1507V000239";
  3405. //stPLC_MesData.Left.iotData.beatAction = 1;
  3406. //stPLC_MesData.Left.iotData.beatAction = 2;
  3407. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3408. #region 去除扫码产生的特殊字符
  3409. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  3410. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  3411. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  3412. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  3413. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  3414. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  3415. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  3416. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  3417. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  3418. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  3419. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  3420. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  3421. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  3422. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  3423. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  3424. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  3425. #endregion
  3426. //richTextBox1.AppendText("\n" + "读取成功");
  3427. //设备状态
  3428. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  3429. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  3430. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3431. ? XiaomiDeviceState.Unknown
  3432. : (XiaomiDeviceState)xmDeviceStateInt_L;
  3433. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3434. ? XiaomiDeviceState.Unknown
  3435. : (XiaomiDeviceState)xmDeviceStateInt_R;
  3436. //载具SN
  3437. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  3438. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  3439. // 节拍
  3440. s3PLCData["a3OEEType_left"] = stPLC_MesData.Left.iotData.beatAction;
  3441. s3PLCData["a3OEEType_right"] = stPLC_MesData.Right.iotData.beatAction;
  3442. //报警信息
  3443. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  3444. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  3445. //_FaultDatas = new uint[] { 2, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
  3446. //_FaultDatas2 = new uint[] { 2, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
  3447. }
  3448. #endregion 一次性读取所有数据
  3449. stopwatch2.Stop();
  3450. #region 左边进站
  3451. try
  3452. {
  3453. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3454. {
  3455. lock (lockObj)
  3456. {
  3457. if (!ProgressState)
  3458. {
  3459. stationCode = "[OP31]";
  3460. stationName = "点散热胶装备1";
  3461. stationNameStr = stationCode + stationName;
  3462. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3463. ProgressState = true;
  3464. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
  3465. tagBaseName + ".Left." + tagMesCommName,
  3466. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  3467. }
  3468. }
  3469. }
  3470. }
  3471. catch (Exception ex)
  3472. {
  3473. ProgressState = false;
  3474. string str = ex.StackTrace;
  3475. AddMessage_Station(stationNameStr, LogType.Error,
  3476. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3477. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3478. }
  3479. #endregion 左边进站
  3480. #region 左边出站
  3481. try
  3482. {
  3483. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3484. {
  3485. lock (lockObj)
  3486. {
  3487. if (!ProgressState)
  3488. {
  3489. stationCode = "[OP31]";
  3490. stationName = "点散热胶装备1";
  3491. stationNameStr = stationCode + stationName;
  3492. ProgressState = true;
  3493. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
  3494. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  3495. out ProgressState));
  3496. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3497. }
  3498. }
  3499. }
  3500. }
  3501. catch (Exception ex)
  3502. {
  3503. ProgressState = false;
  3504. string str = ex.StackTrace;
  3505. AddMessage_Station(stationNameStr, LogType.Error,
  3506. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3507. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3508. }
  3509. #endregion 左边出站
  3510. #region 右边进站
  3511. try
  3512. {
  3513. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3514. {
  3515. lock (lockObj)
  3516. {
  3517. if (!ProgressState)
  3518. {
  3519. uuid2 = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3520. stationCode = "[OP32]";
  3521. stationName = "点散热胶装备2";
  3522. stationNameStr = stationCode + stationName;
  3523. ProgressState = true;
  3524. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
  3525. tagBaseName + ".Right." + tagMesCommName,
  3526. tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
  3527. }
  3528. }
  3529. }
  3530. }
  3531. catch (Exception ex)
  3532. {
  3533. ProgressState = false;
  3534. string str = ex.StackTrace;
  3535. AddMessage_Station(stationNameStr, LogType.Error,
  3536. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3537. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3538. }
  3539. #endregion 右边进站
  3540. #region 右边出站
  3541. try
  3542. {
  3543. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3544. {
  3545. lock (lockObj)
  3546. {
  3547. if (!ProgressState)
  3548. {
  3549. stationCode = "[OP32]";
  3550. stationName = "点散热胶装备2";
  3551. stationNameStr = stationCode + stationName;
  3552. ProgressState = true;
  3553. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
  3554. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  3555. out ProgressState));
  3556. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3557. }
  3558. }
  3559. }
  3560. }
  3561. catch (Exception ex)
  3562. {
  3563. string str = ex.StackTrace;
  3564. AddMessage_Station(stationNameStr, LogType.Error,
  3565. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3566. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3567. }
  3568. #endregion 右边出站
  3569. #region 节拍接口
  3570. try
  3571. {
  3572. #region 左工位 节拍
  3573. if (stPLC_MesData.Left.iotData.beatAction > 0)
  3574. {
  3575. stationCode = "[OP31]";
  3576. stationName = "点散热胶装备1";
  3577. stationNameStr = stationCode + stationName;
  3578. int a3OEEType_left = Convert.ToInt32(s3PLCData["a3OEEType_left"]);
  3579. int a3OEETypeGOld_left = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_left"]);
  3580. if (a3OEEType_left != a3OEETypeGOld_left)
  3581. {
  3582. s3PLCData["OEETypeFlag_left"] = "1";
  3583. }
  3584. else
  3585. {
  3586. s3PLCData["OEETypeFlag_left"] = "0";
  3587. }
  3588. if (s3PLCData["OEETypeFlag_left"].ToString() == "1" && (a3OEEType_left == 1 || a3OEEType_left == 3 || a3OEEType_left == 4 || a3OEEType_left == 5))
  3589. {
  3590. 通用节拍接口(plcNo, stationNameStr,
  3591. tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  3592. stPLC_MesData.Left.iotData, out res);
  3593. if (res == 1)
  3594. {
  3595. s3PLCSignal_Old["a3OEEType_left"] = a3OEEType_left;
  3596. }
  3597. else {
  3598. s3PLCSignal_Old["a3OEEType_left"] = 0;
  3599. }
  3600. }
  3601. }
  3602. else
  3603. {
  3604. s3PLCSignal_Old["a3OEEType_left"] = 0;
  3605. }
  3606. #endregion 左工位 节拍
  3607. #region 右工位 节拍
  3608. if (stPLC_MesData.Right.iotData.beatAction > 0)
  3609. {
  3610. stationCode = "[OP32]";
  3611. stationName = "点散热胶装备2";
  3612. stationNameStr = stationCode + stationName;
  3613. int a3OEEType_right = Convert.ToInt32(s3PLCData["a3OEEType_right"]);
  3614. int a3OEETypeGOld_right = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_right"]);
  3615. if (a3OEEType_right != a3OEETypeGOld_right)
  3616. {
  3617. s3PLCData["OEETypeFlag_right"] = "1";
  3618. }
  3619. else
  3620. {
  3621. s3PLCData["OEETypeFlag_right"] = "0";
  3622. }
  3623. if (s3PLCData["OEETypeFlag_right"].ToString() == "1" && (a3OEEType_right == 1 || a3OEEType_right == 3 || a3OEEType_right == 4 || a3OEEType_right == 5))
  3624. {
  3625. 通用节拍接口(plcNo, stationNameStr,
  3626. tagBaseName + ".Right." + tagiotComnName, CarrierBarcode_Right,
  3627. stPLC_MesData.Right.iotData, out res);
  3628. if (res == 1)
  3629. {
  3630. s3PLCSignal_Old["a3OEEType_right"] = a3OEEType_right;
  3631. }
  3632. else {
  3633. s3PLCSignal_Old["a3OEEType_right"] = 0;
  3634. }
  3635. }
  3636. }
  3637. else
  3638. {
  3639. s3PLCSignal_Old["a3OEEType_right"] = 0;
  3640. }
  3641. #endregion 右工位 节拍
  3642. }
  3643. catch (Exception ex)
  3644. {
  3645. string str = ex.StackTrace;
  3646. AddMessage_Station(stationNameStr, LogType.Error,
  3647. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3648. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3649. }
  3650. #endregion
  3651. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3652. stopwatch1.Stop();
  3653. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3654. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3655. }
  3656. else
  3657. {
  3658. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3659. AddMessage_Station(stationNameStr, LogType.Info,
  3660. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3661. FunsEip[plcNo].Connect();
  3662. }
  3663. }
  3664. catch (Exception ex)
  3665. {
  3666. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3667. AddMessage_Station(stationNameStr, LogType.Error,
  3668. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3669. //Funs[plcNo].ReConnect();
  3670. }
  3671. Thread.Sleep(IntervalReadPLC);
  3672. }
  3673. }
  3674. /// <summary>
  3675. /// [S3] 点散热胶装备 - 进站
  3676. /// </summary>
  3677. /// <param name="plcNo">PLC编号</param>
  3678. /// <param name="stationNameStr">工站全称</param>
  3679. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3680. string tagBarsetName, string direction, out bool ProgressState)
  3681. {
  3682. Stopwatch stopwatch1 = new Stopwatch();
  3683. Stopwatch stopwatch2 = new Stopwatch();
  3684. try
  3685. {
  3686. stopwatch1.Start();
  3687. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  3688. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3689. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  3690. string StationId = string.Empty;
  3691. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3692. bool pass = a1Result == 1;
  3693. string slot = "";
  3694. if (direction == "Left")
  3695. {
  3696. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3697. slot = "01-SLOT-01";
  3698. }
  3699. if (direction == "Right")
  3700. {
  3701. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3702. slot = "01-SLOT-02";
  3703. }
  3704. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3705. //载具码验证产品码
  3706. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3707. if (string.IsNullOrEmpty(strProductBarcode))
  3708. {
  3709. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3710. ProgressState = false;
  3711. Thread.Sleep(10000);
  3712. return;
  3713. }
  3714. sn = strProductBarcode;
  3715. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  3716. // 产品SN(物料码)校验
  3717. List<TestItem> item = new List<TestItem>();
  3718. stopwatch2.Start();
  3719. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3720. item, MachineId, StationId, pass, slot);
  3721. stopwatch2.Stop();
  3722. //指令执行结果 1:OK 110:失败
  3723. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3724. if (mesResultFrmWeb == 1)
  3725. {
  3726. if (a1Result == 1)
  3727. {
  3728. mesResultFrmWeb = 1;
  3729. }
  3730. else
  3731. {
  3732. mesResultFrmWeb = 110;
  3733. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3734. }
  3735. }
  3736. //进站结果写入PLC
  3737. CommandFromPLC resultToPlC = new CommandFromPLC();
  3738. resultToPlC.cmd = 0;
  3739. resultToPlC.cmdParam = 0; //指令参数
  3740. resultToPlC.cmdResult = mesResultFrmWeb;
  3741. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3742. }
  3743. catch (Exception ex)
  3744. {
  3745. string str = ex.StackTrace;
  3746. AddMessage(LogType.Error,
  3747. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3748. str.Length - str.LastIndexOf("\\") - 1));
  3749. CommandFromPLC resultToPlC = new CommandFromPLC();
  3750. resultToPlC.cmd = 0;
  3751. resultToPlC.cmdParam = 0; //指令参数
  3752. resultToPlC.cmdResult = 110;
  3753. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3754. }
  3755. stopwatch1.Stop();
  3756. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3757. AddMessage(LogType.Info,
  3758. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3759. stopwatch2.ElapsedMilliseconds + "ms");
  3760. ProgressState = false;
  3761. }
  3762. /// <summary>
  3763. /// [S3] 点散热胶装备 - 出站
  3764. /// </summary>
  3765. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3766. string stationCode, string stationName, string direction, out bool ProgressState)
  3767. {
  3768. Stopwatch stopwatch1 = new Stopwatch();
  3769. Stopwatch stopwatch2 = new Stopwatch();
  3770. try
  3771. {
  3772. stopwatch1.Start();
  3773. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  3774. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3775. string processItem = stationName; // 测试项目
  3776. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3777. string supplierCode = ""; // 供应商代码
  3778. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3779. string batch_num = GlobalContext.BatchNumber; // 批次号
  3780. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3781. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3782. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3783. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  3784. string StationId = string.Empty;
  3785. if (direction == "Left")
  3786. {
  3787. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3788. }
  3789. if (direction == "Right")
  3790. {
  3791. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3792. }
  3793. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3794. bool pass = a1Result == 1;
  3795. //根据载具码获取产品码
  3796. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3797. if (string.IsNullOrEmpty(strProductBarcode))
  3798. {
  3799. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3800. ProgressState = false;
  3801. Thread.Sleep(10000);
  3802. return;
  3803. }
  3804. Console.WriteLine($"异常1:{strProductBarcode}");
  3805. sn = strProductBarcode;
  3806. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3807. List<TestItem> items = new List<TestItem>();
  3808. items.Add(new TestItem()
  3809. {
  3810. Parameter_name = "载具码",
  3811. Parameter_value = CarrierBarcode,
  3812. Parameter_unit = ""
  3813. });
  3814. items.Add(new TestItem()
  3815. {
  3816. Parameter_name = "产品码",
  3817. Parameter_value = sn,
  3818. Parameter_unit = ""
  3819. });
  3820. //if (direction == "Right")
  3821. //{
  3822. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData).Replace("null","0");
  3823. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3824. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3825. MachineId, StationId, "", paramJson, direction);
  3826. //}
  3827. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3828. if (mesResultFrmWeb == 1)
  3829. {
  3830. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3831. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3832. }
  3833. stopwatch2.Start();
  3834. //进站结果写入PLC
  3835. CommandFromPLC resultToPlC = new CommandFromPLC();
  3836. resultToPlC.cmd = 0;
  3837. resultToPlC.cmdParam = 0; //指令参数
  3838. resultToPlC.cmdResult = mesResultFrmWeb;
  3839. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3840. stopwatch2.Stop();
  3841. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3842. //保存PLC返回MES数据到本地
  3843. ResponseMessage message = new ResponseMessage();
  3844. if (direction == "Left")
  3845. {
  3846. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  3847. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  3848. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  3849. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  3850. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  3851. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  3852. if (message.result == false)
  3853. {
  3854. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3855. }
  3856. }
  3857. if (direction == "Right")
  3858. {
  3859. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  3860. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  3861. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  3862. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  3863. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  3864. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  3865. if (message.result == false)
  3866. {
  3867. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3868. }
  3869. }
  3870. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3871. }
  3872. catch (Exception ex)
  3873. {
  3874. stopwatch2.Start();
  3875. CommandFromPLC resultToPlC = new CommandFromPLC();
  3876. resultToPlC.cmd = 0;
  3877. resultToPlC.cmdParam = 0; //指令参数
  3878. resultToPlC.cmdResult = 110;
  3879. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3880. stopwatch2.Stop();
  3881. string str = ex.StackTrace;
  3882. AddMessage(LogType.Error,
  3883. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3884. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3885. }
  3886. stopwatch1.Stop();
  3887. AddMessage(LogType.Info,
  3888. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3889. stopwatch2.ElapsedMilliseconds + "ms");
  3890. ProgressState = false;
  3891. if (direction == "Left") uuid = "";
  3892. if (direction == "Right") uuid2 = "";
  3893. }
  3894. #endregion S3
  3895. #region S4
  3896. /// <summary>
  3897. /// [S4] 点胶检测设备
  3898. /// </summary>
  3899. /// <param name="plcNo">PLC编号</param>
  3900. private void ReadStation_S4(int plcNo)
  3901. {
  3902. string stationCode = "[OP40]";
  3903. string stationName = "胶线检测";
  3904. string stationNameStr = stationCode + stationName;
  3905. string tagBaseName = "g_OP40_MES"; //标签变量名称
  3906. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3907. string tagAgvCommName = "agvCommFrmPC";
  3908. string tagiotComnName = "iotData";
  3909. string tagBarsetName = "BarcodeSet";
  3910. string CarrierBarcode = "";
  3911. // 触发信号字典
  3912. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3913. s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
  3914. // PLC数据字典 赋值
  3915. s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
  3916. s4PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  3917. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  3918. (int, string) result;
  3919. while (true)
  3920. {
  3921. try
  3922. {
  3923. if (!GlobalContext._IsCon_Funs1)
  3924. {
  3925. UpdatePLCMonitor(1, plcNo, 0);
  3926. continue;
  3927. }
  3928. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3929. {
  3930. Stopwatch stopwatch1 = new Stopwatch();
  3931. Stopwatch stopwatch2 = new Stopwatch();
  3932. stopwatch1.Start();
  3933. stopwatch2.Start();
  3934. #region 一次性读取所有数据
  3935. // 一次性读取所有数据
  3936. result = FunsEip[plcNo]
  3937. .Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3938. if (result.Item1 != 0)
  3939. {
  3940. //richTextBox1.AppendText("\n" + strRet);
  3941. }
  3942. else
  3943. {
  3944. //去除扫码产生的特殊字符
  3945. stPLC_MesData.BarcodeSet.strProductBarcode =
  3946. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  3947. stPLC_MesData.BarcodeSet.strPartBarcode =
  3948. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  3949. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  3950. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  3951. stPLC_MesData.BarcodeSet.strPCBBarcode =
  3952. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  3953. //richTextBox1.AppendText("\n" + "读取成功");
  3954. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3955. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3956. ? XiaomiDeviceState.Unknown
  3957. : (XiaomiDeviceState)xmDeviceStateInt;
  3958. // 载具SN
  3959. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode;
  3960. // 节拍
  3961. s4PLCData["a4OEEType"] = stPLC_MesData.iotData.beatAction;
  3962. //报警信息
  3963. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  3964. }
  3965. #endregion 一次性读取所有数据
  3966. stopwatch2.Stop();
  3967. #region 进站
  3968. try
  3969. {
  3970. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3971. {
  3972. lock (lockObj)
  3973. {
  3974. if (!ProgressState)
  3975. {
  3976. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3977. ProgressState = true;
  3978. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
  3979. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3980. out ProgressState));
  3981. }
  3982. }
  3983. }
  3984. }
  3985. catch (Exception ex)
  3986. {
  3987. ProgressState = false;
  3988. string str = ex.StackTrace;
  3989. AddMessage_Station(stationNameStr, LogType.Error,
  3990. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3991. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3992. }
  3993. #endregion 进站
  3994. #region 出站
  3995. try
  3996. {
  3997. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3998. {
  3999. lock (lockObj)
  4000. {
  4001. if (!ProgressState)
  4002. {
  4003. ProgressState = true;
  4004. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
  4005. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4006. out ProgressState));
  4007. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4008. }
  4009. }
  4010. }
  4011. }
  4012. catch (Exception ex)
  4013. {
  4014. string str = ex.StackTrace;
  4015. AddMessage_Station(stationNameStr, LogType.Error,
  4016. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4017. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4018. }
  4019. #endregion 出站
  4020. #region 节拍接口
  4021. try
  4022. {
  4023. if (stPLC_MesData.iotData.beatAction > 0)
  4024. {
  4025. int a4OEEType = Convert.ToInt32(s4PLCData["a4OEEType"]);
  4026. int a4OEETypeGOld = Convert.ToInt32(s4PLCSignal_Old["a4OEEType"]);
  4027. //若设备紧急复原后节拍重置
  4028. if (a4OEEType == 1)
  4029. {
  4030. a4OEETypeGOld = 0;
  4031. }
  4032. if (a4OEEType != a4OEETypeGOld)
  4033. {
  4034. s4PLCData["OEETypeFlag"] = "1";
  4035. }
  4036. else
  4037. {
  4038. s4PLCData["OEETypeFlag"] = "0";
  4039. }
  4040. if (s4PLCData["OEETypeFlag"].ToString() == "1" && (a4OEEType == 1 || a4OEEType == 3 || a4OEEType == 4 || a4OEEType == 5))
  4041. {
  4042. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  4043. if (res == 1)
  4044. {
  4045. s4PLCSignal_Old["a4OEEType"] = s4PLCData["a4OEEType"];
  4046. }
  4047. else
  4048. {
  4049. s4PLCSignal_Old["a4OEEType"] = 0;
  4050. }
  4051. }
  4052. }
  4053. else {
  4054. s4PLCSignal_Old["a4OEEType"] = 0;
  4055. }
  4056. }
  4057. catch (Exception ex)
  4058. {
  4059. string str = ex.StackTrace;
  4060. AddMessage_Station(stationNameStr, LogType.Error,
  4061. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4062. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4063. }
  4064. #endregion
  4065. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4066. stopwatch1.Stop();
  4067. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4068. }
  4069. else
  4070. {
  4071. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4072. AddMessage_Station(stationNameStr, LogType.Info,
  4073. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4074. FunsEip[plcNo].Connect(); // 重连
  4075. }
  4076. }
  4077. catch (Exception ex)
  4078. {
  4079. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4080. AddMessage_Station(stationNameStr, LogType.Error,
  4081. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4082. }
  4083. Thread.Sleep(IntervalReadPLC);
  4084. }
  4085. }
  4086. /// <summary>
  4087. /// [S4] 点胶检测设备 - 进站
  4088. /// </summary>
  4089. /// <param name="plcNo">PLC编号</param>
  4090. /// <param name="stationNameStr">工站全称</param>
  4091. /// <param name="stPLC_MesData"></param>
  4092. /// <param name="tagMesCommName"></param>
  4093. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4094. string tagBarsetName, out bool ProgressState)
  4095. {
  4096. Stopwatch stopwatch1 = new Stopwatch();
  4097. Stopwatch stopwatch2 = new Stopwatch();
  4098. try
  4099. {
  4100. stopwatch1.Start();
  4101. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4102. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4103. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  4104. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  4105. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4106. bool pass = a1Result == 1;
  4107. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4108. //载具码验证产品码
  4109. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4110. if (string.IsNullOrEmpty(strProductBarcode))
  4111. {
  4112. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4113. ProgressState = false;
  4114. Thread.Sleep(10000);
  4115. return;
  4116. }
  4117. sn = strProductBarcode;
  4118. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4119. // 产品SN(物料码)校验
  4120. List<TestItem> item = new List<TestItem>();
  4121. stopwatch2.Start();
  4122. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4123. item, MachineId, StationId, pass, "01-SLOT-01");
  4124. stopwatch2.Stop();
  4125. //指令执行结果 1:OK 110:失败
  4126. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4127. if (mesResultFrmWeb == 1)
  4128. {
  4129. if (a1Result == 1)
  4130. {
  4131. mesResultFrmWeb = 1;
  4132. }
  4133. else
  4134. {
  4135. mesResultFrmWeb = 110;
  4136. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4137. }
  4138. }
  4139. //进站结果写入PLC
  4140. CommandFromPLC resultToPlC = new CommandFromPLC();
  4141. resultToPlC.cmd = 0;
  4142. resultToPlC.cmdParam = 0; //指令参数
  4143. resultToPlC.cmdResult = mesResultFrmWeb;
  4144. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4145. }
  4146. catch (Exception ex)
  4147. {
  4148. string str = ex.StackTrace;
  4149. AddMessage(LogType.Error,
  4150. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4151. str.Length - str.LastIndexOf("\\") - 1));
  4152. CommandFromPLC resultToPlC = new CommandFromPLC();
  4153. resultToPlC.cmd = 0;
  4154. resultToPlC.cmdParam = 0; //指令参数
  4155. resultToPlC.cmdResult = 110;
  4156. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4157. }
  4158. stopwatch1.Stop();
  4159. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4160. AddMessage(LogType.Info,
  4161. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4162. stopwatch2.ElapsedMilliseconds + "ms");
  4163. ProgressState = false;
  4164. }
  4165. /// <summary>
  4166. /// [S4] 点胶检测设备 - 出站接口
  4167. /// </summary>
  4168. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4169. string stationCode, string stationName, out bool ProgressState)
  4170. {
  4171. Stopwatch stopwatch1 = new Stopwatch();
  4172. Stopwatch stopwatch2 = new Stopwatch();
  4173. try
  4174. {
  4175. stopwatch1.Start();
  4176. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4177. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4178. string processItem = stationName; // 测试项目
  4179. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4180. string supplierCode = ""; // 供应商代码
  4181. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4182. string batch_num = GlobalContext.BatchNumber; // 批次号
  4183. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4184. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4185. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4186. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  4187. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  4188. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4189. bool pass = a1Result == 1;
  4190. //根据载具码获取产品码
  4191. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4192. if (string.IsNullOrEmpty(strProductBarcode))
  4193. {
  4194. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4195. ProgressState = false;
  4196. Thread.Sleep(10000);
  4197. return;
  4198. }
  4199. sn = strProductBarcode;
  4200. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4201. List<TestItem> items = new List<TestItem>();
  4202. items.Add(new TestItem()
  4203. {
  4204. Parameter_name = "载具码",
  4205. Parameter_value = CarrierBarcode,
  4206. Parameter_unit = ""
  4207. });
  4208. items.Add(new TestItem()
  4209. {
  4210. Parameter_name = "产品码",
  4211. Parameter_value = sn,
  4212. Parameter_unit = ""
  4213. });
  4214. #region 上传图片
  4215. if (GlobalContext.MQTTIsSendUpFile)
  4216. {
  4217. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4218. fileUploadData.fileData.Clear();
  4219. foreach (var item in urlarry)
  4220. {
  4221. if (!string.IsNullOrEmpty(item))
  4222. {
  4223. //上传图片
  4224. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4225. item, uuid).Result;
  4226. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4227. }
  4228. }
  4229. }
  4230. #endregion
  4231. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4232. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4233. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode,
  4234. "01-SLOT-01", MachineId, StationId, "", paramJson);
  4235. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4236. if (mesResultFrmWeb == 1)
  4237. {
  4238. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4239. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4240. }
  4241. stopwatch2.Start();
  4242. //进站结果写入PLC
  4243. CommandFromPLC resultToPlC = new CommandFromPLC();
  4244. resultToPlC.cmd = 0;
  4245. resultToPlC.cmdParam = 0; //指令参数
  4246. resultToPlC.cmdResult = mesResultFrmWeb;
  4247. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4248. stopwatch2.Stop();
  4249. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4250. //保存PLC返回MES数据到本地
  4251. ResponseMessage message = new ResponseMessage();
  4252. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  4253. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  4254. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  4255. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  4256. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  4257. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  4258. if (message.result == false)
  4259. {
  4260. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4261. }
  4262. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4263. }
  4264. catch (Exception ex)
  4265. {
  4266. stopwatch2.Start();
  4267. CommandFromPLC resultToPlC = new CommandFromPLC();
  4268. resultToPlC.cmd = 0;
  4269. resultToPlC.cmdParam = 0; //指令参数
  4270. resultToPlC.cmdResult = 110;
  4271. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4272. stopwatch2.Stop();
  4273. string str = ex.StackTrace;
  4274. AddMessage(LogType.Error,
  4275. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4276. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4277. }
  4278. stopwatch1.Stop();
  4279. AddMessage(LogType.Info,
  4280. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4281. stopwatch2.ElapsedMilliseconds + "ms");
  4282. ProgressState = false;
  4283. uuid = "";
  4284. }
  4285. #endregion
  4286. #region S5
  4287. private static bool isPCBStation = false; //控制PCB是否进出站的标识
  4288. /// <summary>
  4289. /// [S5] 点胶检测设备
  4290. /// </summary>
  4291. /// <param name="plcNo">PLC编号</param>
  4292. private void ReadStation_S5(int plcNo)
  4293. {
  4294. string stationCode = "[OP50]";
  4295. string stationName = "ADD板上料组装装备";
  4296. string stationNameStr = stationCode + stationName;
  4297. string tagBaseName = "g_OP50_MES"; //标签变量名称
  4298. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4299. string tagAgvCommName = "agvCommFrmPC";
  4300. string tagiotComnName = "iotData";
  4301. string tagBarsetName = "BarcodeSet";
  4302. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  4303. string CarrierBarcode = "";
  4304. // 触发信号字典
  4305. s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4306. // PLC数据字典 赋值
  4307. s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4308. s5PLCData.Add("OEETypeFlag", 0); // 节拍标识 0 不上传 ,1 上传
  4309. (int, string) result;
  4310. while (true)
  4311. {
  4312. try
  4313. {
  4314. if (!GlobalContext._IsCon_Funs1)
  4315. {
  4316. UpdatePLCMonitor(1, plcNo, 0);
  4317. continue;
  4318. }
  4319. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4320. {
  4321. Stopwatch stopwatch1 = new Stopwatch();
  4322. Stopwatch stopwatch2 = new Stopwatch();
  4323. stopwatch1.Start();
  4324. stopwatch2.Start();
  4325. #region 一次性读取所有数据
  4326. // 一次性读取所有数据
  4327. result = FunsEip[plcNo]
  4328. .Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4329. if (result.Item1 != 0)
  4330. {
  4331. }
  4332. else
  4333. {
  4334. //测试数据
  4335. //stPLC_MesData.mesCommFrmPLC.cmd = 2;
  4336. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A235461";
  4337. //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
  4338. //stPLC_MesData.iotData.beatAction = 1;
  4339. //stPLC_MesData.iotData.beatAction = 2;
  4340. //stPLC_MesData.iotData.beatAction = 3;
  4341. //stPLC_MesData.iotData.beatAction = 4;
  4342. //stPLC_MesData.iotData.beatAction = 5;
  4343. //stPLC_MesData.iotData.beatAction = 6;
  4344. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  4345. #region 去除扫码产生的特殊字符
  4346. stPLC_MesData.BarcodeSet.strProductBarcode =
  4347. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4348. stPLC_MesData.BarcodeSet.strPartBarcode =
  4349. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4350. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4351. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4352. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4353. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4354. #endregion
  4355. //richTextBox1.AppendText("\n" + "读取成功");
  4356. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4357. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4358. ? XiaomiDeviceState.Unknown
  4359. : (XiaomiDeviceState)xmDeviceStateInt;
  4360. // 节拍
  4361. s5PLCData["a5OEEType"] = stPLC_MesData.iotData.beatAction;
  4362. //载具码
  4363. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  4364. //报警信息
  4365. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4366. }
  4367. #endregion 一次性读取所有数据
  4368. stopwatch2.Stop();
  4369. #region 进站
  4370. try
  4371. {
  4372. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4373. {
  4374. lock (lockObj)
  4375. {
  4376. if (!ProgressState)
  4377. {
  4378. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4379. ProgressState = true;
  4380. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  4381. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  4382. {
  4383. ProgressState = true;
  4384. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData,
  4385. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4386. out ProgressState));
  4387. }
  4388. }
  4389. }
  4390. }
  4391. }
  4392. catch (Exception ex)
  4393. {
  4394. ProgressState = false;
  4395. string str = ex.StackTrace;
  4396. AddMessage_Station(stationNameStr, LogType.Error,
  4397. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4398. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4399. }
  4400. #endregion 进站
  4401. #region 出站
  4402. try
  4403. {
  4404. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4405. {
  4406. lock (lockObj)
  4407. {
  4408. if (!ProgressState)
  4409. {
  4410. ProgressState = true;
  4411. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
  4412. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4413. out ProgressState));
  4414. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4415. }
  4416. }
  4417. }
  4418. }
  4419. catch (Exception ex)
  4420. {
  4421. ProgressState = false;
  4422. string str = ex.StackTrace;
  4423. AddMessage_Station(stationNameStr, LogType.Error,
  4424. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4425. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4426. }
  4427. #endregion 出站
  4428. #region 节拍接口
  4429. try
  4430. {
  4431. if (stPLC_MesData.iotData.beatAction > 0)
  4432. {
  4433. int a5OEEType = Convert.ToInt32(s5PLCData["a5OEEType"]);
  4434. int a5OEETypeGOld = Convert.ToInt32(s5PLCSignal_Old["a5OEEType"]);
  4435. if (a5OEEType != a5OEETypeGOld)
  4436. {
  4437. s5PLCData["OEETypeFlag"] = "1";
  4438. }
  4439. else
  4440. {
  4441. s5PLCData["OEETypeFlag"] = "0";
  4442. }
  4443. if (s5PLCData["OEETypeFlag"].ToString() == "1" && (a5OEEType == 1 || a5OEEType == 3 || a5OEEType == 4 || a5OEEType == 5))
  4444. {
  4445. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  4446. if (res == 1)
  4447. {
  4448. s5PLCSignal_Old["a5OEEType"] = s5PLCData["a5OEEType"];
  4449. }
  4450. else {
  4451. s5PLCSignal_Old["a5OEEType"] = 0;
  4452. }
  4453. }
  4454. }
  4455. else {
  4456. s5PLCSignal_Old["a5OEEType"] = 0;
  4457. }
  4458. }
  4459. catch (Exception ex)
  4460. {
  4461. string str = ex.StackTrace;
  4462. AddMessage_Station(stationNameStr, LogType.Error,
  4463. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4464. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4465. }
  4466. #endregion
  4467. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4468. stopwatch1.Stop();
  4469. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4470. }
  4471. else
  4472. {
  4473. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4474. AddMessage_Station(stationNameStr, LogType.Info,
  4475. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4476. FunsEip[plcNo].Connect(); // 重连
  4477. }
  4478. }
  4479. catch (Exception ex)
  4480. {
  4481. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4482. AddMessage_Station(stationNameStr, LogType.Error,
  4483. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4484. }
  4485. Thread.Sleep(IntervalReadPLC);
  4486. }
  4487. }
  4488. /// <summary>
  4489. /// [S5] 点胶检测设备 - 进站
  4490. /// </summary>
  4491. /// <param name="plcNo">PLC编号</param>
  4492. /// <param name="stationNameStr">工站全称</param>
  4493. /// <param name="stPLC_MesData"></param>
  4494. /// <param name="tagMesCommName"></param>
  4495. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4496. string tagBarsetName, out bool ProgressState)
  4497. {
  4498. Stopwatch stopwatch1 = new Stopwatch();
  4499. Stopwatch stopwatch2 = new Stopwatch();
  4500. try
  4501. {
  4502. stopwatch1.Start();
  4503. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4504. //string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4505. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  4506. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  4507. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  4508. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  4509. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4510. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4511. bool pass = a1Result == 1;
  4512. AddMessage(LogType.Info, $"ADD板编码(PCB码):{pcbBarcode}");
  4513. //绑定载具和产品
  4514. //ResponseMessage message = new ResponseMessage();
  4515. //message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
  4516. //if (message.result == false)
  4517. //{
  4518. // AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  4519. // ProgressState = false;
  4520. // Thread.Sleep(10000);
  4521. // return;
  4522. //}
  4523. //载具码验证产品码 //载具码验证产品码
  4524. //string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4525. //if (string.IsNullOrEmpty(strProductBarcode))
  4526. //{
  4527. // AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4528. //}
  4529. //sn = strProductBarcode;
  4530. //AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4531. // 产品SN(物料码)校验
  4532. List<TestItem> item = new List<TestItem>();
  4533. stopwatch2.Start();
  4534. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  4535. pcbBarcode,
  4536. item, MachineId, StationId, pass, "01-SLOT-01");
  4537. stopwatch2.Stop();
  4538. //指令执行结果 1:OK 110:失败
  4539. byte mesResultFrmWeb = (byte)(result == 1 ? 2 : 120);
  4540. if (mesResultFrmWeb == 1)
  4541. {
  4542. if (a1Result == 1)
  4543. {
  4544. mesResultFrmWeb = 2;
  4545. }
  4546. else
  4547. {
  4548. mesResultFrmWeb = 120;
  4549. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4550. }
  4551. }
  4552. //进站结果写入PLC
  4553. CommandFromPLC resultToPlC = new CommandFromPLC();
  4554. resultToPlC.cmd = 0;
  4555. resultToPlC.cmdParam = 0; //指令参数
  4556. resultToPlC.cmdResult = mesResultFrmWeb;
  4557. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4558. }
  4559. catch (Exception ex)
  4560. {
  4561. string str = ex.StackTrace;
  4562. AddMessage(LogType.Error,
  4563. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4564. str.Length - str.LastIndexOf("\\") - 1));
  4565. CommandFromPLC resultToPlC = new CommandFromPLC();
  4566. resultToPlC.cmd = 0;
  4567. resultToPlC.cmdParam = 0; //指令参数
  4568. resultToPlC.cmdResult = 120;
  4569. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4570. }
  4571. stopwatch1.Stop();
  4572. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4573. AddMessage(LogType.Info,
  4574. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4575. stopwatch2.ElapsedMilliseconds + "ms");
  4576. ProgressState = false;
  4577. }
  4578. /// <summary>
  4579. /// [S5] 点胶检测设备 - 出站接口
  4580. /// </summary>
  4581. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4582. string stationCode, string stationName, out bool ProgressState)
  4583. {
  4584. Stopwatch stopwatch1 = new Stopwatch();
  4585. Stopwatch stopwatch2 = new Stopwatch();
  4586. try
  4587. {
  4588. stopwatch1.Start();
  4589. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4590. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4591. string processItem = stationName; // 测试项目
  4592. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4593. string supplierCode = ""; // 供应商代码
  4594. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4595. string batch_num = GlobalContext.BatchNumber; // 批次号
  4596. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4597. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4598. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 部件条码;
  4599. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4600. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4601. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  4602. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  4603. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4604. bool pass = a1Result == 1;
  4605. CommandFromPLC resultToPlC = new CommandFromPLC();
  4606. //根据载具码获取产品码
  4607. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4608. if (string.IsNullOrEmpty(strProductBarcode))
  4609. {
  4610. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4611. ProgressState = false;
  4612. Thread.Sleep(10000);
  4613. return;
  4614. }
  4615. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  4616. sn = strProductBarcode;
  4617. //数据库绑定载具和PCB
  4618. ResponseMessage message = new ResponseMessage();
  4619. message = SQLHelper.PCBCarrierBind(CarrierBarcode, pcbBarcode);
  4620. if (message.result == false)
  4621. {
  4622. AddMessage(LogType.Error, stationNameStr + "_PCB码数据库绑定失败,错误:" + message.text);
  4623. ProgressState = true; //防止循环报错
  4624. return;
  4625. }
  4626. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  4627. List<TestItem> items = new List<TestItem>();
  4628. items.Add(new TestItem()
  4629. {
  4630. Parameter_name = "载具码",
  4631. Parameter_value = CarrierBarcode,
  4632. Parameter_unit = ""
  4633. });
  4634. items.Add(new TestItem()
  4635. {
  4636. Parameter_name = "产品码",
  4637. Parameter_value = sn,
  4638. Parameter_unit = ""
  4639. });
  4640. items.Add(new TestItem()
  4641. {
  4642. Parameter_name = "PCB码",
  4643. Parameter_value = pcbBarcode,
  4644. Parameter_unit = ""
  4645. });
  4646. #region 上传图片
  4647. if (GlobalContext.MQTTIsSendUpFile)
  4648. {
  4649. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4650. fileUploadData.fileData.Clear();
  4651. foreach (var item in urlarry)
  4652. {
  4653. if (!string.IsNullOrEmpty(item))
  4654. {
  4655. //上传图片
  4656. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4657. item, uuid).Result;
  4658. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4659. }
  4660. }
  4661. }
  4662. #endregion
  4663. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4664. int result1 = 0;
  4665. byte mesResultFrmWeb = 0;
  4666. if (stPLC_MesData.mesCommFrmPLC.cmdParam == 2)
  4667. {
  4668. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  4669. batch_num
  4670. , mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId,
  4671. PartBarcode, paramJson);
  4672. }
  4673. else if (stPLC_MesData.mesCommFrmPLC.cmdParam == 1)
  4674. {
  4675. result1 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4676. }
  4677. mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4678. //进站结果写入PLC
  4679. resultToPlC.cmd = 0;
  4680. resultToPlC.cmdParam = 0; //指令参数
  4681. resultToPlC.cmdResult = mesResultFrmWeb;
  4682. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4683. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4684. //保存PLC返回MES数据到本地
  4685. //ResponseMessage message = new ResponseMessage();
  4686. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  4687. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB,
  4688. stPLC_MesData.mesData.nRemainCount, "");
  4689. if (message.result == false)
  4690. {
  4691. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4692. }
  4693. //保存部件码信息
  4694. if (!string.IsNullOrEmpty(PartBarcode))
  4695. {
  4696. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  4697. if (message.result == false)
  4698. {
  4699. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  4700. }
  4701. }
  4702. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4703. }
  4704. catch (Exception ex)
  4705. {
  4706. stopwatch2.Start();
  4707. CommandFromPLC resultToPlC = new CommandFromPLC();
  4708. resultToPlC.cmd = 0;
  4709. resultToPlC.cmdParam = 0; //指令参数
  4710. resultToPlC.cmdResult = 110;
  4711. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4712. stopwatch2.Stop();
  4713. string str = ex.StackTrace;
  4714. AddMessage(LogType.Error,
  4715. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4716. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4717. }
  4718. stopwatch1.Stop();
  4719. AddMessage(LogType.Info,
  4720. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4721. stopwatch2.ElapsedMilliseconds + "ms");
  4722. ProgressState = false;
  4723. uuid = "";
  4724. }
  4725. private int S5_PCB进出站(OP50_MesData_t stPLC_MesData, int plcNo, string stationNameStr, string tagBaseName,
  4726. string tagMesCommName)
  4727. {
  4728. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  4729. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  4730. {
  4731. string strProductBarcode =
  4732. SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4733. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  4734. CommandFromPLC resultToPlC = new CommandFromPLC();
  4735. resultToPlC.cmd = 0;
  4736. resultToPlC.cmdParam = 0; //指令参数
  4737. if (GlobalContext.IsSendStationIn)
  4738. {
  4739. #region 进站
  4740. //int res1 = PCBStationInData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4741. //if (res1 == 1)
  4742. //{
  4743. // resultToPlC.cmdResult = 2;//OK
  4744. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4745. //}
  4746. //else
  4747. //{
  4748. // resultToPlC.cmdResult = 120;
  4749. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4750. // return 2;
  4751. //}
  4752. #endregion
  4753. #region 出站
  4754. int res2 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4755. if (res2 == 1)
  4756. {
  4757. resultToPlC.cmdResult = 2; //OK
  4758. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4759. return 1;
  4760. }
  4761. else
  4762. {
  4763. resultToPlC.cmdResult = 120;
  4764. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4765. return 2;
  4766. }
  4767. #endregion
  4768. }
  4769. else
  4770. {
  4771. return 2;
  4772. }
  4773. }
  4774. else
  4775. {
  4776. return 2;
  4777. }
  4778. }
  4779. #endregion
  4780. #region S6
  4781. private Dictionary<string, object> s6PLCData = new Dictionary<string, object>();
  4782. private Dictionary<string, object> s6PLCSignal_Old = new Dictionary<string, object>();
  4783. /// <summary>
  4784. /// [S6] 顶盖装配设备
  4785. /// </summary>
  4786. /// <param name="plcNo">PLC编号</param>
  4787. public void ReadStation_S6(int plcNo)
  4788. {
  4789. string stationCode = "[OP70]";
  4790. string stationName = "组上盖板";
  4791. string stationNameStr = stationCode + stationName;
  4792. string tagBaseName = "g_OP60_MES"; //标签变量名称
  4793. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4794. string tagAgvCommName = "agvCommFrmPC";
  4795. string tagiotComnName = "iotData";
  4796. string tagBarsetName = "BarcodeSet";
  4797. string CarrierBarcode = "";
  4798. // 触发信号字典
  4799. s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
  4800. // PLC数据字典 赋值
  4801. s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
  4802. s6PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  4803. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  4804. (int, string) result;
  4805. while (true)
  4806. {
  4807. try
  4808. {
  4809. if (!GlobalContext._IsCon_Funs1)
  4810. {
  4811. UpdatePLCMonitor(1, plcNo, 0);
  4812. continue;
  4813. }
  4814. if (StopWhile)
  4815. {
  4816. continue;
  4817. }
  4818. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4819. {
  4820. Stopwatch stopwatch1 = new Stopwatch();
  4821. Stopwatch stopwatch2 = new Stopwatch();
  4822. stopwatch1.Start();
  4823. stopwatch2.Start();
  4824. #region 一次性读取所有数据
  4825. // 一次性读取所有数据
  4826. result = FunsEip[plcNo]
  4827. .Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4828. if (result.Item1 != 0)
  4829. {
  4830. //richTextBox1.AppendText("\n" + strRet);
  4831. }
  4832. else
  4833. {
  4834. //测试
  4835. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  4836. //stPLC_MesData.mesCommFrmPLC.cmd = 1;
  4837. //去除扫码产生的特殊字符
  4838. stPLC_MesData.BarcodeSet.strProductBarcode =
  4839. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4840. stPLC_MesData.BarcodeSet.strPartBarcode =
  4841. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4842. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4843. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4844. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4845. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4846. //richTextBox1.AppendText("\n" + "读取成功");
  4847. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4848. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4849. ? XiaomiDeviceState.Unknown
  4850. : (XiaomiDeviceState)xmDeviceStateInt;
  4851. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  4852. s6PLCData["a6OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  4853. //报警信息
  4854. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4855. }
  4856. #endregion 一次性读取所有数据
  4857. stopwatch2.Stop();
  4858. #region 进站
  4859. try
  4860. {
  4861. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4862. {
  4863. lock (lockObj)
  4864. {
  4865. if (!ProgressState)
  4866. {
  4867. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4868. ProgressState = true;
  4869. //载具码验证产品码
  4870. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
  4871. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4872. out ProgressState));
  4873. }
  4874. }
  4875. }
  4876. }
  4877. catch (Exception ex)
  4878. {
  4879. ProgressState = false;
  4880. string str = ex.StackTrace;
  4881. AddMessage_Station(stationNameStr, LogType.Error,
  4882. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4883. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4884. }
  4885. #endregion 进站
  4886. #region 出站
  4887. try
  4888. {
  4889. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4890. {
  4891. lock (lockObj)
  4892. {
  4893. if (!ProgressState)
  4894. {
  4895. ProgressState = true;
  4896. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
  4897. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4898. out ProgressState));
  4899. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4900. }
  4901. }
  4902. }
  4903. }
  4904. catch (Exception ex)
  4905. {
  4906. ProgressState = false;
  4907. string str = ex.StackTrace;
  4908. AddMessage_Station(stationNameStr, LogType.Error,
  4909. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4910. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4911. }
  4912. #endregion 出站
  4913. #region 节拍接口
  4914. try
  4915. {
  4916. if (stPLC_MesData.iotData.beatAction > 0)
  4917. {
  4918. int a6OEEType = Convert.ToInt32(s6PLCData["a6OEEType"]);
  4919. int a6OEETypeGOld = Convert.ToInt32(s6PLCSignal_Old["a6OEEType"]);
  4920. if (a6OEEType != a6OEETypeGOld)
  4921. {
  4922. s6PLCData["OEETypeFlag"] = "1";
  4923. }
  4924. else
  4925. {
  4926. s6PLCData["OEETypeFlag"] = "0";
  4927. }
  4928. if (s6PLCData["OEETypeFlag"].ToString() == "1" && (a6OEEType == 1 || a6OEEType == 3 || a6OEEType == 4 || a6OEEType == 5))
  4929. {
  4930. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  4931. if (res == 1)
  4932. {
  4933. s6PLCSignal_Old["a6OEEType"] = s6PLCData["a6OEEType"];
  4934. }
  4935. else
  4936. {
  4937. s6PLCSignal_Old["a6OEEType"] = 0;
  4938. }
  4939. }
  4940. }
  4941. else {
  4942. s6PLCSignal_Old["a6OEEType"] = 0;
  4943. }
  4944. }
  4945. catch (Exception ex)
  4946. {
  4947. string str = ex.StackTrace;
  4948. AddMessage_Station(stationNameStr, LogType.Error,
  4949. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4950. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4951. }
  4952. #endregion
  4953. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4954. stopwatch1.Stop();
  4955. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4956. }
  4957. else
  4958. {
  4959. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4960. AddMessage_Station(stationNameStr, LogType.Info,
  4961. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4962. FunsEip[plcNo].Connect(); // 重连
  4963. }
  4964. }
  4965. catch (Exception ex)
  4966. {
  4967. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4968. AddMessage_Station(stationNameStr, LogType.Error,
  4969. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4970. }
  4971. Thread.Sleep(IntervalReadPLC);
  4972. }
  4973. }
  4974. /// <summary>
  4975. /// [S6] 顶盖装配设备 - 进站
  4976. /// </summary>
  4977. /// <param name="plcNo">PLC编号</param>
  4978. /// <param name="stationNameStr">工站全称</param>
  4979. /// <param name="stPLC_MesData"></param>
  4980. /// <param name="tagMesCommName"></param>
  4981. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  4982. string tagBarsetName, out bool ProgressState)
  4983. {
  4984. Stopwatch stopwatch1 = new Stopwatch();
  4985. Stopwatch stopwatch2 = new Stopwatch();
  4986. try
  4987. {
  4988. stopwatch1.Start();
  4989. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4990. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4991. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  4992. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  4993. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4994. bool pass = a1Result == 1;
  4995. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4996. string ProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4997. string PCBBarcode = SQLHelper.GetPCBBarcodeByCarrierCode(strCarrierBarcode);
  4998. //strCarrierBarcode = "N801A-003";
  4999. //载具码验证产品码
  5000. if (string.IsNullOrEmpty(ProductBarcode))
  5001. {
  5002. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5003. ProgressState = false;
  5004. Thread.Sleep(10000);
  5005. return;
  5006. }
  5007. sn = ProductBarcode;
  5008. if (OpenDailogFalg)
  5009. {
  5010. using (var dialog = new BandBarodeDialog(strCarrierBarcode, ProductBarcode, PCBBarcode))
  5011. {
  5012. var rs = dialog.ShowDialog();
  5013. if (rs == DialogResult.OK)
  5014. {
  5015. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode}");
  5016. OpenDailogFalg = false; //关闭扫码
  5017. StopWhile = false;//开启while循环
  5018. }
  5019. else
  5020. {
  5021. ProgressState = false;
  5022. return;
  5023. }
  5024. }
  5025. }
  5026. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5027. // 产品SN(物料码)校验
  5028. List<TestItem> item = new List<TestItem>();
  5029. stopwatch2.Start();
  5030. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5031. item, MachineId, StationId, pass, "01-SLOT-01");
  5032. stopwatch2.Stop();
  5033. //指令执行结果 1:OK 110:失败
  5034. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5035. if (mesResultFrmWeb == 1)
  5036. {
  5037. if (a1Result == 1)
  5038. {
  5039. mesResultFrmWeb = 1;
  5040. }
  5041. else
  5042. {
  5043. mesResultFrmWeb = 110;
  5044. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5045. }
  5046. }
  5047. //进站结果写入PLC
  5048. CommandFromPLC resultToPlC = new CommandFromPLC();
  5049. resultToPlC.cmd = 0;
  5050. resultToPlC.cmdParam = 0; //指令参数
  5051. resultToPlC.cmdResult = mesResultFrmWeb;
  5052. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5053. }
  5054. catch (Exception ex)
  5055. {
  5056. string str = ex.StackTrace;
  5057. AddMessage(LogType.Error,
  5058. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5059. str.Length - str.LastIndexOf("\\") - 1));
  5060. CommandFromPLC resultToPlC = new CommandFromPLC();
  5061. resultToPlC.cmd = 0;
  5062. resultToPlC.cmdParam = 0; //指令参数
  5063. resultToPlC.cmdResult = 110;
  5064. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5065. }
  5066. stopwatch1.Stop();
  5067. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  5068. AddMessage(LogType.Info,
  5069. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5070. stopwatch2.ElapsedMilliseconds + "ms");
  5071. ProgressState = false;
  5072. }
  5073. /// <summary>
  5074. /// [S6] 顶盖装配设备 - 出站接口
  5075. /// </summary>
  5076. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5077. string stationCode, string stationName, out bool ProgressState)
  5078. {
  5079. Stopwatch stopwatch1 = new Stopwatch();
  5080. Stopwatch stopwatch2 = new Stopwatch();
  5081. try
  5082. {
  5083. stopwatch1.Start();
  5084. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5085. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5086. string processItem = stationName; // 测试项目
  5087. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5088. string supplierCode = ""; // 供应商代码
  5089. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5090. string batch_num = GlobalContext.BatchNumber; // 批次号
  5091. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5092. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5093. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5094. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  5095. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  5096. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5097. bool pass = a1Result == 1;
  5098. //根据载具码获取产品码
  5099. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5100. if (string.IsNullOrEmpty(strProductBarcode))
  5101. {
  5102. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5103. ProgressState = false;
  5104. Thread.Sleep(10000);
  5105. return;
  5106. }
  5107. sn = strProductBarcode;
  5108. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5109. List<TestItem> items = new List<TestItem>();
  5110. items.Add(new TestItem()
  5111. {
  5112. Parameter_name = "载具码",
  5113. Parameter_value = CarrierBarcode,
  5114. Parameter_unit = ""
  5115. });
  5116. items.Add(new TestItem()
  5117. {
  5118. Parameter_name = "产品码",
  5119. Parameter_value = sn,
  5120. Parameter_unit = ""
  5121. });
  5122. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5123. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5124. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  5125. MachineId, StationId, "", paramJson);
  5126. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5127. if (mesResultFrmWeb == 1)
  5128. {
  5129. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5130. if (mesResultFrmWeb==110)
  5131. {
  5132. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  5133. }
  5134. }
  5135. stopwatch2.Start();
  5136. //进站结果写入PLC
  5137. CommandFromPLC resultToPlC = new CommandFromPLC();
  5138. resultToPlC.cmd = 0;
  5139. resultToPlC.cmdParam = 0; //指令参数
  5140. resultToPlC.cmdResult = mesResultFrmWeb;
  5141. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5142. stopwatch2.Stop();
  5143. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5144. //保存PLC返回MES数据到本地
  5145. ResponseMessage message = new ResponseMessage();
  5146. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  5147. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  5148. }
  5149. catch (Exception ex)
  5150. {
  5151. stopwatch2.Start();
  5152. CommandFromPLC resultToPlC = new CommandFromPLC();
  5153. resultToPlC.cmd = 0;
  5154. resultToPlC.cmdParam = 0; //指令参数
  5155. resultToPlC.cmdResult = 110;
  5156. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5157. stopwatch2.Stop();
  5158. string str = ex.StackTrace;
  5159. AddMessage(LogType.Error,
  5160. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5161. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5162. }
  5163. stopwatch1.Stop();
  5164. AddMessage(LogType.Info,
  5165. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5166. stopwatch2.ElapsedMilliseconds + "ms");
  5167. ProgressState = false;
  5168. uuid = "";
  5169. OpenDailogFalg = true; //开启下一个物料的扫码
  5170. }
  5171. #endregion
  5172. #region S7
  5173. private Dictionary<string, object> s7PLCSignal_Old = new Dictionary<string, object>();
  5174. private Dictionary<string, object> s7PLCData = new Dictionary<string, object>();
  5175. /// <summary>
  5176. /// [S7] 锁螺丝设备
  5177. /// </summary>
  5178. /// <param name="plcNo">PLC编号</param>
  5179. private void ReadStation_S7(int plcNo)
  5180. {
  5181. string stationCode = "[OP80]";
  5182. string stationName = "上盖板锁螺丝";
  5183. string stationNameStr = stationCode + stationName;
  5184. string tagBaseName = "g_OP70_MES"; //标签变量名称
  5185. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5186. string tagAgvCommName = "agvCommFrmPC";
  5187. string tagBarsetName = "BarcodeSet";
  5188. string tagiotComnName = "iotData";
  5189. string tagScrewDataset = "screwDataset";
  5190. string CarrierBarcode_Left = "";
  5191. string CarrierBarcode_Right = "";
  5192. s7PLCSignal_Old.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5193. s7PLCSignal_Old.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5194. // PLC数据字典 赋值
  5195. s7PLCData.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5196. s7PLCData.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5197. s5PLCData.Add("OEETypeFlag_left", 0); // 节拍标识 0 不上传 ,1 上传
  5198. s5PLCData.Add("OEETypeFlag_right", 0); // 节拍标识 0 不上传 ,1 上传
  5199. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  5200. (int, string) result;
  5201. AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
  5202. 3000, 3000, "Left");
  5203. atlasScrewLeft.Initial();
  5204. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
  5205. 3000, 3000, "Right");
  5206. atlasScrewRight.Initial();
  5207. while (true)
  5208. {
  5209. try
  5210. {
  5211. if (!GlobalContext._IsCon_Funs1)
  5212. {
  5213. UpdatePLCMonitor(1, plcNo, 0);
  5214. continue;
  5215. }
  5216. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5217. {
  5218. Stopwatch stopwatch1 = new Stopwatch();
  5219. Stopwatch stopwatch2 = new Stopwatch();
  5220. stopwatch1.Start();
  5221. stopwatch2.Start();
  5222. #region 一次性读取所有数据
  5223. // 一次性读取所有数据
  5224. result = FunsEip[plcNo]
  5225. .Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5226. if (result.Item1 != 0)
  5227. {
  5228. //richTextBox1.AppendText("\n" + strRet);
  5229. }
  5230. else
  5231. {
  5232. #region 去除扫码产生的特殊字符
  5233. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  5234. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  5235. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  5236. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  5237. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  5238. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  5239. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  5240. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  5241. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  5242. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  5243. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  5244. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  5245. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  5246. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  5247. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  5248. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  5249. #endregion
  5250. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  5251. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  5252. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5253. ? XiaomiDeviceState.Unknown
  5254. : (XiaomiDeviceState)xmDeviceStateInt_L;
  5255. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5256. ? XiaomiDeviceState.Unknown
  5257. : (XiaomiDeviceState)xmDeviceStateInt_R;
  5258. s7PLCData["a7OEEPartNo"] =
  5259. stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5260. // 载具SN
  5261. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  5262. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  5263. // 节拍
  5264. s7PLCData["a7OEEType"] = stPLC_MesData.Left.iotData.beatAction;
  5265. s7PLCData["a7OEEType_left"] = stPLC_MesData.Left .iotData.beatAction;
  5266. s7PLCData["a7OEEType_right"] = stPLC_MesData.Right.iotData.beatAction;
  5267. //报警信息
  5268. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  5269. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  5270. }
  5271. #endregion 一次性读取所有数据
  5272. stopwatch2.Stop();
  5273. #region 左边进站
  5274. try
  5275. {
  5276. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5277. {
  5278. lock (lockObj)
  5279. {
  5280. if (!ProgressState)
  5281. {
  5282. stationCode = "[OP81]";
  5283. stationName = "上盖板锁螺丝1";
  5284. stationNameStr = stationCode + stationName;
  5285. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5286. ProgressState = true;
  5287. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
  5288. tagBaseName + ".Left." + tagMesCommName,
  5289. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
  5290. atlasScrewLeft));
  5291. }
  5292. }
  5293. }
  5294. }
  5295. catch (Exception ex)
  5296. {
  5297. ProgressState = false;
  5298. string str = ex.StackTrace;
  5299. AddMessage_Station(stationNameStr, LogType.Error,
  5300. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5301. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5302. }
  5303. #endregion 左边进站
  5304. #region 左边出站
  5305. try
  5306. {
  5307. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5308. {
  5309. lock (lockObj)
  5310. {
  5311. if (!ProgressState)
  5312. {
  5313. stationCode = "[OP81]";
  5314. stationName = "上盖板锁螺丝1";
  5315. stationNameStr = stationCode + stationName;
  5316. ProgressState = true;
  5317. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
  5318. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  5319. out ProgressState));
  5320. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  5321. }
  5322. }
  5323. }
  5324. }
  5325. catch (Exception ex)
  5326. {
  5327. ProgressState = false;
  5328. string str = ex.StackTrace;
  5329. AddMessage_Station(stationNameStr, LogType.Error,
  5330. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5331. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5332. }
  5333. #endregion 左边出站
  5334. #region 右边进站
  5335. try
  5336. {
  5337. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5338. {
  5339. lock (lockObj)
  5340. {
  5341. if (!ProgressState)
  5342. {
  5343. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5344. stationCode = "[OP82]";
  5345. stationName = "上盖板锁螺丝2";
  5346. stationNameStr = stationCode + stationName;
  5347. ProgressState = true;
  5348. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
  5349. tagBaseName + ".Right." + tagMesCommName,
  5350. tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
  5351. atlasScrewRight));
  5352. }
  5353. }
  5354. }
  5355. }
  5356. catch (Exception ex)
  5357. {
  5358. ProgressState = false;
  5359. string str = ex.StackTrace;
  5360. AddMessage_Station(stationNameStr, LogType.Error,
  5361. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5362. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5363. }
  5364. #endregion 右边进站
  5365. #region 右边出站
  5366. try
  5367. {
  5368. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5369. {
  5370. lock (lockObj)
  5371. {
  5372. if (!ProgressState)
  5373. {
  5374. stationCode = "[OP82]";
  5375. stationName = "上盖板锁螺丝2";
  5376. stationNameStr = stationCode + stationName;
  5377. ProgressState = true;
  5378. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
  5379. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  5380. out ProgressState));
  5381. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  5382. }
  5383. }
  5384. }
  5385. }
  5386. catch (Exception ex)
  5387. {
  5388. ProgressState = false;
  5389. string str = ex.StackTrace;
  5390. AddMessage_Station(stationNameStr, LogType.Error,
  5391. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5392. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5393. }
  5394. #endregion 右边出站
  5395. #region 节拍接口
  5396. try
  5397. {
  5398. #region 左工位 节拍
  5399. if (stPLC_MesData.Left.iotData.beatAction > 0)
  5400. {
  5401. stationCode = "[OP81]";
  5402. stationName = "上盖板锁螺丝1";
  5403. stationNameStr = stationCode + stationName;
  5404. int a7OEEType_left = Convert.ToInt32(s7PLCData["a7OEEType_left"]);
  5405. int a7OEETypeGOld_left = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_left"]);
  5406. if (a7OEEType_left != a7OEETypeGOld_left)
  5407. {
  5408. if (a7OEEType_left != a7OEETypeGOld_left)
  5409. s7PLCData["OEETypeFlag_left"] = "1";
  5410. else
  5411. s7PLCData["OEETypeFlag_left"] = "0";
  5412. if (s7PLCData["OEETypeFlag_left"].ToString() == "1" && (a7OEEType_left == 1 || a7OEEType_left == 3 || a7OEEType_left == 4 || a7OEEType_left == 5))
  5413. {
  5414. int res = 0;
  5415. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  5416. stPLC_MesData.Left.iotData, out res);
  5417. if (res == 1)
  5418. {
  5419. s7PLCSignal_Old["a7OEEType_left"] = s7PLCData["a7OEEType_left"];
  5420. }
  5421. else {
  5422. s7PLCSignal_Old["a7OEEType_left"] = 0;
  5423. }
  5424. }
  5425. }
  5426. }
  5427. else
  5428. {
  5429. s7PLCSignal_Old["a7OEEType_left"] = 0;
  5430. }
  5431. #endregion 左工位 节拍
  5432. #region 右工位 节拍
  5433. if (stPLC_MesData.Right.iotData.beatAction > 0)
  5434. {
  5435. stationCode = "[OP82]";
  5436. stationName = "上盖板锁螺丝2";
  5437. stationNameStr = stationCode + stationName;
  5438. int a7OEEType_right = Convert.ToInt32(s7PLCData["a7OEEType_right"]);
  5439. int a7OEETypeGOld_right = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_right"]);
  5440. if (a7OEEType_right != a7OEETypeGOld_right)
  5441. {
  5442. if (a7OEEType_right != a7OEETypeGOld_right)
  5443. s7PLCData["a7OEEType_right"] = "1";
  5444. else
  5445. s7PLCData["a7OEEType_right"] = "0";
  5446. if (s7PLCData["a7OEEType_right"].ToString() == "1" && (a7OEEType_right == 1 || a7OEEType_right == 3 || a7OEEType_right == 4 || a7OEEType_right == 5))
  5447. {
  5448. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagiotComnName, CarrierBarcode_Left,
  5449. stPLC_MesData.Right.iotData, out res);
  5450. if (res == 1)
  5451. {
  5452. s7PLCSignal_Old["a7OEEType_right"] = s7PLCData["a7OEEType_right"];
  5453. }
  5454. else {
  5455. s7PLCSignal_Old["a7OEEType_right"] = 0;
  5456. }
  5457. }
  5458. }
  5459. }
  5460. else
  5461. {
  5462. s7PLCSignal_Old["a7OEEType_right"] = 0;
  5463. }
  5464. #endregion 右工位 节拍
  5465. }
  5466. catch (Exception ex)
  5467. {
  5468. string str = ex.StackTrace;
  5469. AddMessage_Station(stationNameStr, LogType.Error,
  5470. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5471. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5472. }
  5473. #endregion
  5474. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5475. stopwatch1.Stop();
  5476. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5477. }
  5478. else
  5479. {
  5480. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5481. AddMessage_Station(stationNameStr, LogType.Info,
  5482. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5483. FunsEip[plcNo].Connect(); // 重连
  5484. }
  5485. }
  5486. catch (Exception ex)
  5487. {
  5488. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5489. AddMessage_Station(stationNameStr, LogType.Error,
  5490. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5491. }
  5492. Thread.Sleep(IntervalReadPLC);
  5493. }
  5494. }
  5495. /// <summary>
  5496. /// [S7] 锁螺丝设备 - 进站
  5497. /// </summary>
  5498. /// <param name="plcNo">PLC编号</param>
  5499. /// <param name="stationNameStr">工站全称</param>
  5500. /// <param name="stPLC_MesData"></param>
  5501. /// <param name="tagMesCommName"></param>
  5502. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5503. string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
  5504. {
  5505. Stopwatch stopwatch1 = new Stopwatch();
  5506. Stopwatch stopwatch2 = new Stopwatch();
  5507. string atlasSn = string.Empty;
  5508. try
  5509. {
  5510. stopwatch1.Start();
  5511. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  5512. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5513. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  5514. string StationId = string.Empty; // 工位ID(可配置)
  5515. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5516. bool pass = a1Result == 1;
  5517. if (direction == "Left")
  5518. {
  5519. StationId = GlobalContext.S7_StationId_1;
  5520. }
  5521. if (direction == "Right")
  5522. {
  5523. StationId = GlobalContext.S7_StationId_2;
  5524. }
  5525. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5526. //载具码验证产品码
  5527. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5528. if (string.IsNullOrEmpty(strProductBarcode))
  5529. {
  5530. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5531. ProgressState = false;
  5532. Thread.Sleep(10000);
  5533. return;
  5534. }
  5535. sn = strProductBarcode;
  5536. atlasSn = strProductBarcode;
  5537. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5538. string slot = "";
  5539. if (direction == "Left")
  5540. {
  5541. isCollectingFlagLeft = false; //采集螺丝数据结束
  5542. slot = "01-SLOT-01";
  5543. }
  5544. if (direction == "Right")
  5545. {
  5546. isCollectingFlagRight = false; //采集螺丝数据结束
  5547. slot = "01-SLOT-02";
  5548. }
  5549. // 产品SN(物料码)校验
  5550. List<TestItem> item = new List<TestItem>();
  5551. stopwatch2.Start();
  5552. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5553. item, MachineId, StationId, pass, slot);
  5554. stopwatch2.Stop();
  5555. //指令执行结果 1:OK 110:失败
  5556. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5557. if (mesResultFrmWeb == 1)
  5558. {
  5559. if (a1Result == 1)
  5560. {
  5561. mesResultFrmWeb = 1;
  5562. }
  5563. else
  5564. {
  5565. mesResultFrmWeb = 110;
  5566. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5567. }
  5568. }
  5569. //进站结果写入PLC
  5570. CommandFromPLC resultToPlC = new CommandFromPLC();
  5571. resultToPlC.cmd = 0;
  5572. resultToPlC.cmdParam = 0; //指令参数
  5573. resultToPlC.cmdResult = mesResultFrmWeb;
  5574. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5575. }
  5576. catch (Exception ex)
  5577. {
  5578. string str = ex.StackTrace;
  5579. AddMessage(LogType.Error,
  5580. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5581. str.Length - str.LastIndexOf("\\") - 1));
  5582. CommandFromPLC resultToPlC = new CommandFromPLC();
  5583. resultToPlC.cmd = 0;
  5584. resultToPlC.cmdParam = 0; //指令参数
  5585. resultToPlC.cmdResult = 110;
  5586. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5587. }
  5588. stopwatch1.Stop();
  5589. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  5590. AddMessage(LogType.Info,
  5591. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5592. stopwatch2.ElapsedMilliseconds + "ms");
  5593. ProgressState = false;
  5594. //开始采集螺丝数据
  5595. if (direction == "Left")
  5596. {
  5597. isCollectingFlagLeft = true;
  5598. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  5599. }
  5600. if (direction == "Right")
  5601. {
  5602. isCollectingFlagRight = true;
  5603. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  5604. }
  5605. }
  5606. /// <summary>
  5607. /// [S7] 锁螺丝设备 - 出站
  5608. /// </summary>
  5609. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5610. string stationCode, string stationName, string direction, out bool ProgressState)
  5611. {
  5612. Stopwatch stopwatch1 = new Stopwatch();
  5613. Stopwatch stopwatch2 = new Stopwatch();
  5614. try
  5615. {
  5616. stopwatch1.Start();
  5617. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  5618. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5619. string processItem = stationName; // 测试项目
  5620. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5621. string supplierCode = ""; // 供应商代码
  5622. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5623. string batch_num = GlobalContext.BatchNumber; // 批次号
  5624. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5625. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5626. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5627. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  5628. string StationId = string.Empty; // 工位ID(可配置)
  5629. if (direction == "Left")
  5630. {
  5631. StationId = GlobalContext.S7_StationId_1;
  5632. }
  5633. if (direction == "Right")
  5634. {
  5635. StationId = GlobalContext.S7_StationId_2;
  5636. }
  5637. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5638. //a1Result = 1;
  5639. bool pass = a1Result == 1;
  5640. //根据载具码获取产品码
  5641. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5642. if (string.IsNullOrEmpty(strProductBarcode))
  5643. {
  5644. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5645. ProgressState = false;
  5646. Thread.Sleep(10000);
  5647. return;
  5648. }
  5649. sn = strProductBarcode;
  5650. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5651. List<TestItem> items = new List<TestItem>();
  5652. items.Add(new TestItem()
  5653. {
  5654. Parameter_name = "载具码",
  5655. Parameter_value = CarrierBarcode,
  5656. Parameter_unit = ""
  5657. });
  5658. items.Add(new TestItem()
  5659. {
  5660. Parameter_name = "产品码",
  5661. Parameter_value = sn,
  5662. Parameter_unit = ""
  5663. });
  5664. //if (direction == "Right")
  5665. //{
  5666. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5667. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  5668. batch_num, mtltmrk, plcDate_YMD, supplierCode
  5669. , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  5670. //}
  5671. //if (direction == "Left")
  5672. //{
  5673. // isCollectingFlagLeft = false;//采集螺丝数据结束
  5674. //}
  5675. //if (direction == "Right")
  5676. //{
  5677. // isCollectingFlagRight = false;//采集螺丝数据结束
  5678. //}
  5679. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5680. if (mesResultFrmWeb == 1)
  5681. {
  5682. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5683. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  5684. }
  5685. stopwatch2.Start();
  5686. //进站结果写入PLC
  5687. CommandFromPLC resultToPlC = new CommandFromPLC();
  5688. resultToPlC.cmd = 0;
  5689. resultToPlC.cmdParam = 0; //指令参数
  5690. resultToPlC.cmdResult = mesResultFrmWeb;
  5691. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5692. stopwatch2.Stop();
  5693. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  5694. //保存PLC返回MES数据到本地
  5695. ResponseMessage message = new ResponseMessage();
  5696. if (direction == "Left")
  5697. {
  5698. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5699. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5700. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5701. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  5702. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5703. //if (message.result == false)
  5704. //{
  5705. // AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  5706. //}
  5707. }
  5708. if (direction == "Right")
  5709. {
  5710. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5711. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5712. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5713. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  5714. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5715. //if (message.result == false)
  5716. //{
  5717. // AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  5718. //}
  5719. }
  5720. //保存螺丝数据到txt
  5721. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
  5722. stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  5723. if (result.Item1 != 0)
  5724. {
  5725. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  5726. }
  5727. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
  5728. }
  5729. catch (Exception ex)
  5730. {
  5731. stopwatch2.Start();
  5732. CommandFromPLC resultToPlC = new CommandFromPLC();
  5733. resultToPlC.cmd = 0;
  5734. resultToPlC.cmdParam = 0; //指令参数
  5735. resultToPlC.cmdResult = 110;
  5736. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5737. stopwatch2.Stop();
  5738. string str = ex.StackTrace;
  5739. AddMessage(LogType.Error,
  5740. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5741. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5742. }
  5743. stopwatch1.Stop();
  5744. AddMessage(LogType.Info,
  5745. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5746. stopwatch2.ElapsedMilliseconds + "ms");
  5747. ProgressState = false;
  5748. if (direction == "Left") uuid = "";
  5749. if (direction == "Right") uuid2 = "";
  5750. }
  5751. #endregion
  5752. #region S8
  5753. private Dictionary<string, object> s8PLCData = new Dictionary<string, object>();
  5754. private Dictionary<string, object> s8PLCSignal_Old = new Dictionary<string, object>();
  5755. /// <summary>
  5756. /// [S8] 3D螺丝高度检测设备
  5757. /// </summary>
  5758. /// <param name="plcNo">PLC编号</param>
  5759. private void ReadStation_S8(int plcNo)
  5760. {
  5761. string stationCode = "[OP90]";
  5762. string stationName = "NG下料";
  5763. string stationNameStr = stationCode + stationName;
  5764. string tagBaseName = "g_OP80_MES"; //标签变量名称
  5765. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5766. string tagAgvCommName = "agvCommFrmPC";
  5767. string tagiotComnName = "iotData";
  5768. string tagBarsetName = "BarcodeSet";
  5769. string CarrierBarcode = "";
  5770. // 触发信号字典
  5771. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5772. s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
  5773. // PLC数据字典 赋值
  5774. s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
  5775. s8PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  5776. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  5777. (int, string) result;
  5778. while (true)
  5779. {
  5780. try
  5781. {
  5782. if (!GlobalContext._IsCon_Funs1)
  5783. {
  5784. UpdatePLCMonitor(1, plcNo, 0);
  5785. continue;
  5786. }
  5787. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5788. {
  5789. Stopwatch stopwatch1 = new Stopwatch();
  5790. Stopwatch stopwatch2 = new Stopwatch();
  5791. stopwatch1.Start();
  5792. stopwatch2.Start();
  5793. #region 一次性读取所有数据
  5794. // 一次性读取所有数据
  5795. result = FunsEip[plcNo]
  5796. .Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5797. if (result.Item1 != 0)
  5798. {
  5799. //richTextBox1.AppendText("\n" + strRet);
  5800. }
  5801. else
  5802. {
  5803. //去除扫码产生的特殊字符
  5804. stPLC_MesData.BarcodeSet.strProductBarcode =
  5805. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  5806. stPLC_MesData.BarcodeSet.strPartBarcode =
  5807. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  5808. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  5809. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  5810. stPLC_MesData.BarcodeSet.strPCBBarcode =
  5811. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  5812. }
  5813. #endregion 一次性读取所有数据
  5814. stopwatch2.Stop();
  5815. //richTextBox1.AppendText("\n" + "读取成功");
  5816. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  5817. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  5818. ? XiaomiDeviceState.Unknown
  5819. : (XiaomiDeviceState)xmDeviceStateInt;
  5820. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  5821. s8PLCData["a8OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  5822. //报警信息
  5823. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  5824. stopwatch2.Stop();
  5825. #region 进站
  5826. try
  5827. {
  5828. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5829. {
  5830. lock (lockObj)
  5831. {
  5832. if (!ProgressState)
  5833. {
  5834. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5835. ProgressState = true;
  5836. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
  5837. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  5838. out ProgressState));
  5839. }
  5840. }
  5841. }
  5842. }
  5843. catch (Exception ex)
  5844. {
  5845. ProgressState = false;
  5846. string str = ex.StackTrace;
  5847. AddMessage_Station(stationNameStr, LogType.Error,
  5848. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5849. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5850. }
  5851. #endregion 进站
  5852. #region 出站
  5853. try
  5854. {
  5855. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5856. {
  5857. lock (lockObj)
  5858. {
  5859. if (!ProgressState)
  5860. {
  5861. ProgressState = true;
  5862. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
  5863. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5864. out ProgressState));
  5865. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5866. uuid = "";
  5867. }
  5868. }
  5869. }
  5870. }
  5871. catch (Exception ex)
  5872. {
  5873. ProgressState = false;
  5874. string str = ex.StackTrace;
  5875. AddMessage_Station(stationNameStr, LogType.Error,
  5876. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5877. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5878. }
  5879. #endregion 出站
  5880. #region 节拍接口
  5881. try
  5882. {
  5883. int a8OEEType = Convert.ToInt32(s8PLCData["a8OEEType"]);
  5884. int a8OEETypeGOld = Convert.ToInt32(s8PLCSignal_Old["a8OEEType"]);
  5885. if (stPLC_MesData.iotData.beatAction > 0)
  5886. {
  5887. if (a8OEEType != a8OEETypeGOld)
  5888. {
  5889. s8PLCData["OEETypeFlag"] = "1";
  5890. }
  5891. else
  5892. {
  5893. s8PLCData["OEETypeFlag"] = "0";
  5894. }
  5895. if (s8PLCData["OEETypeFlag"].ToString() == "1" && (a8OEEType == 1 || a8OEEType == 3 || a8OEEType == 4 || a8OEEType == 5))
  5896. {
  5897. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  5898. CarrierBarcode, stPLC_MesData.iotData, out res);
  5899. if (res == 1)
  5900. {
  5901. s8PLCSignal_Old["a8OEEType"] = s8PLCData["a8OEEType"];
  5902. }
  5903. else
  5904. {
  5905. s8PLCSignal_Old["a8OEEType"] = 0;
  5906. }
  5907. }
  5908. }
  5909. else {
  5910. s8PLCSignal_Old["a8OEEType"] = 0;
  5911. }
  5912. }
  5913. catch (Exception ex)
  5914. {
  5915. string str = ex.StackTrace;
  5916. AddMessage_Station(stationNameStr, LogType.Error,
  5917. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5918. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5919. }
  5920. #endregion
  5921. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5922. stopwatch1.Stop();
  5923. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5924. }
  5925. else
  5926. {
  5927. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5928. AddMessage_Station(stationNameStr, LogType.Info,
  5929. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5930. FunsEip[plcNo].Connect(); // 重连
  5931. }
  5932. }
  5933. catch (Exception ex)
  5934. {
  5935. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5936. AddMessage_Station(stationNameStr, LogType.Error,
  5937. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5938. }
  5939. Thread.Sleep(IntervalReadPLC);
  5940. }
  5941. }
  5942. /// <summary>
  5943. /// [S8] 3D螺丝高度检测设备 - 进站
  5944. /// </summary>
  5945. /// <param name="plcNo">PLC编号</param>
  5946. /// <param name="stationNameStr">工站全称</param>
  5947. /// <param name="stPLC_MesData"></param>
  5948. /// <param name="tagMesCommName"></param>
  5949. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  5950. string tagBarsetName, out bool ProgressState)
  5951. {
  5952. Stopwatch stopwatch1 = new Stopwatch();
  5953. Stopwatch stopwatch2 = new Stopwatch();
  5954. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5955. bool pass = a1Result == 1;
  5956. try
  5957. {
  5958. stopwatch1.Start();
  5959. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5960. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5961. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  5962. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  5963. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5964. //载具码验证产品码
  5965. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5966. if (string.IsNullOrEmpty(strProductBarcode))
  5967. {
  5968. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5969. ProgressState = false;
  5970. Thread.Sleep(10000);
  5971. return;
  5972. }
  5973. sn = strProductBarcode;
  5974. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5975. // 产品SN(物料码)校验
  5976. List<TestItem> item = new List<TestItem>();
  5977. stopwatch2.Start();
  5978. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  5979. sn,
  5980. item, MachineId, StationId, pass, "01-SLOT-01");
  5981. stopwatch2.Stop();
  5982. //指令执行结果 1:OK 110:失败
  5983. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5984. if (mesResultFrmWeb == 1)
  5985. {
  5986. if (a1Result == 1)
  5987. {
  5988. mesResultFrmWeb = 1;
  5989. }
  5990. else
  5991. {
  5992. mesResultFrmWeb = 110;
  5993. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5994. }
  5995. }
  5996. //进站结果写入PLC
  5997. CommandFromPLC resultToPlC = new CommandFromPLC();
  5998. resultToPlC.cmd = 0;
  5999. resultToPlC.cmdParam = 0; //指令参数
  6000. resultToPlC.cmdResult = mesResultFrmWeb;
  6001. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6002. }
  6003. catch (Exception ex)
  6004. {
  6005. string str = ex.StackTrace;
  6006. AddMessage(LogType.Error,
  6007. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(
  6008. str.LastIndexOf("\\") + 1,
  6009. str.Length - str.LastIndexOf("\\") - 1));
  6010. CommandFromPLC resultToPlC = new CommandFromPLC();
  6011. resultToPlC.cmd = 0;
  6012. resultToPlC.cmdParam = 0; //指令参数
  6013. resultToPlC.cmdResult = 110;
  6014. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6015. }
  6016. stopwatch1.Stop();
  6017. AddMessage(LogType.Info,
  6018. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6019. stopwatch2.ElapsedMilliseconds + "ms");
  6020. ProgressState = false;
  6021. }
  6022. /// <summary>
  6023. /// [S8] 3D螺丝高度检测设备 - 出站接口
  6024. /// </summary>
  6025. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6026. string stationCode, string stationName, out bool ProgressState)
  6027. {
  6028. Stopwatch stopwatch1 = new Stopwatch();
  6029. Stopwatch stopwatch2 = new Stopwatch();
  6030. try
  6031. {
  6032. stopwatch1.Start();
  6033. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6034. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6035. string processItem = stationName; // 测试项目
  6036. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6037. string supplierCode = ""; // 供应商代码
  6038. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6039. string batch_num = GlobalContext.BatchNumber; // 批次号
  6040. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6041. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6042. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6043. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  6044. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  6045. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6046. bool pass = a1Result == 1;
  6047. //根据载具码获取产品码
  6048. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6049. if (string.IsNullOrEmpty(strProductBarcode))
  6050. {
  6051. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6052. ProgressState = false;
  6053. Thread.Sleep(10000);
  6054. return;
  6055. }
  6056. sn = strProductBarcode;
  6057. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6058. List<TestItem> items = new List<TestItem>();
  6059. items.Add(new TestItem()
  6060. {
  6061. Parameter_name = "载具码",
  6062. Parameter_value = CarrierBarcode,
  6063. Parameter_unit = ""
  6064. });
  6065. items.Add(new TestItem()
  6066. {
  6067. Parameter_name = "产品码",
  6068. Parameter_value = sn,
  6069. Parameter_unit = ""
  6070. });
  6071. #region 上传图片
  6072. if (GlobalContext.MQTTIsSendUpFile)
  6073. {
  6074. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  6075. fileUploadData.fileData.Clear();
  6076. foreach (var item in urlarry)
  6077. {
  6078. if (!string.IsNullOrEmpty(item))
  6079. {
  6080. //上传图片
  6081. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName,
  6082. a1Result, item, uuid).Result;
  6083. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  6084. }
  6085. }
  6086. }
  6087. #endregion
  6088. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6089. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6090. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  6091. MachineId, StationId, "", paramJson);
  6092. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6093. if (mesResultFrmWeb == 1)
  6094. {
  6095. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6096. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6097. }
  6098. stopwatch2.Start();
  6099. //进站结果写入PLC
  6100. CommandFromPLC resultToPlC = new CommandFromPLC();
  6101. resultToPlC.cmd = 0;
  6102. resultToPlC.cmdParam = 0; //指令参数
  6103. resultToPlC.cmdResult = mesResultFrmWeb;
  6104. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6105. stopwatch2.Stop();
  6106. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6107. //保存PLC返回MES数据到本地
  6108. ResponseMessage message = new ResponseMessage();
  6109. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  6110. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6111. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  6112. if (message.result == false)
  6113. {
  6114. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6115. }
  6116. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6117. }
  6118. catch (Exception ex)
  6119. {
  6120. stopwatch2.Start();
  6121. CommandFromPLC resultToPlC = new CommandFromPLC();
  6122. resultToPlC.cmd = 0;
  6123. resultToPlC.cmdParam = 0; //指令参数
  6124. resultToPlC.cmdResult = 110;
  6125. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6126. stopwatch2.Stop();
  6127. string str = ex.StackTrace;
  6128. AddMessage(LogType.Error,
  6129. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6130. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6131. }
  6132. stopwatch1.Stop();
  6133. AddMessage(LogType.Info,
  6134. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6135. stopwatch2.ElapsedMilliseconds + "ms");
  6136. ProgressState = false;
  6137. }
  6138. #endregion
  6139. #region S9
  6140. private Dictionary<string, object> s9PLCData = new Dictionary<string, object>();
  6141. private Dictionary<string, object> s9PLCSignal_Old = new Dictionary<string, object>();
  6142. /// <summary>
  6143. /// [S9] 下料设备
  6144. /// </summary>
  6145. /// <param name="plcNo">PLC编号</param>
  6146. private void ReadStation_S9(int plcNo)
  6147. {
  6148. string stationCode = "[OP100]";
  6149. string stationName = "半成品下料";
  6150. string stationNameStr = stationCode + stationName;
  6151. string tagBaseName = "g_OP90_MES"; //标签变量名称
  6152. string tagMesCommName = "mesCommToPC"; //标签变量名称
  6153. string tagAgvCommName = "agvCommFrmPC";
  6154. string tagiotComnName = "iotData";
  6155. string tagBarsetName = "BarcodeSet";
  6156. string CarrierBarcode = "";
  6157. // 触发信号字典
  6158. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6159. s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6160. // PLC数据字典 赋值
  6161. s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6162. s9PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  6163. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  6164. (int, string) result;
  6165. while (true)
  6166. {
  6167. try
  6168. {
  6169. if (!GlobalContext._IsCon_Funs1)
  6170. {
  6171. UpdatePLCMonitor(1, plcNo, 0);
  6172. continue;
  6173. }
  6174. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  6175. {
  6176. Stopwatch stopwatch1 = new Stopwatch();
  6177. Stopwatch stopwatch2 = new Stopwatch();
  6178. stopwatch1.Start();
  6179. stopwatch2.Start();
  6180. #region 一次性读取所有数据
  6181. // 一次性读取所有数据
  6182. result = FunsEip[plcNo]
  6183. .Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6184. if (result.Item1 != 0)
  6185. {
  6186. //richTextBox1.AppendText("\n" + strRet);
  6187. }
  6188. else
  6189. {
  6190. //去除扫码产生的特殊字符
  6191. stPLC_MesData.BarcodeSet.strProductBarcode =
  6192. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  6193. stPLC_MesData.BarcodeSet.strPartBarcode =
  6194. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  6195. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  6196. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  6197. stPLC_MesData.BarcodeSet.strPCBBarcode =
  6198. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  6199. //richTextBox1.AppendText("\n" + "读取成功");
  6200. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6201. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6202. ? XiaomiDeviceState.Unknown
  6203. : (XiaomiDeviceState)xmDeviceStateInt;
  6204. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6205. s9PLCData["a9OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  6206. //报警信息
  6207. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  6208. }
  6209. #endregion 一次性读取所有数据
  6210. stopwatch2.Stop();
  6211. #region 进站
  6212. try
  6213. {
  6214. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6215. {
  6216. lock (lockObj)
  6217. {
  6218. if (!ProgressState)
  6219. {
  6220. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6221. ProgressState = true;
  6222. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
  6223. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6224. out ProgressState));
  6225. }
  6226. }
  6227. }
  6228. }
  6229. catch (Exception ex)
  6230. {
  6231. ProgressState = false;
  6232. string str = ex.StackTrace;
  6233. AddMessage_Station(stationNameStr, LogType.Error,
  6234. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6235. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6236. }
  6237. #endregion 进站
  6238. #region 出站
  6239. try
  6240. {
  6241. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6242. {
  6243. lock (lockObj)
  6244. {
  6245. if (!ProgressState)
  6246. {
  6247. ProgressState = true;
  6248. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
  6249. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  6250. out ProgressState));
  6251. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  6252. }
  6253. }
  6254. }
  6255. }
  6256. catch (Exception ex)
  6257. {
  6258. ProgressState = false;
  6259. string str = ex.StackTrace;
  6260. AddMessage_Station(stationNameStr, LogType.Error,
  6261. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6262. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6263. }
  6264. #endregion 出站
  6265. #region 节拍接口
  6266. try
  6267. {
  6268. if (stPLC_MesData.iotData.beatAction > 0)
  6269. {
  6270. int a9OEEType = Convert.ToInt32(s9PLCData["a9OEEType"]);
  6271. int a9OEETypeGOld = Convert.ToInt32(s9PLCSignal_Old["a9OEEType"]);
  6272. if (a9OEEType != a9OEETypeGOld)
  6273. {
  6274. s9PLCData["OEETypeFlag"] = "1";
  6275. }
  6276. else
  6277. {
  6278. s9PLCData["OEETypeFlag"] = "0";
  6279. }
  6280. if (s9PLCData["OEETypeFlag"].ToString() == "1" && (a9OEEType == 1 || a9OEEType == 3 || a9OEEType == 4 || a9OEEType == 5))
  6281. {
  6282. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6283. CarrierBarcode, stPLC_MesData.iotData, out res);
  6284. if (res == 1)
  6285. {
  6286. s9PLCSignal_Old["a9OEEType"] = s9PLCData["a9OEEType"];
  6287. }
  6288. else
  6289. {
  6290. s9PLCSignal_Old["a9OEEType"] = 0;
  6291. }
  6292. }
  6293. }
  6294. else {
  6295. s9PLCSignal_Old["a9OEEType"] = 0;
  6296. }
  6297. }
  6298. catch (Exception ex)
  6299. {
  6300. string str = ex.StackTrace;
  6301. AddMessage_Station(stationNameStr, LogType.Error,
  6302. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6303. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6304. }
  6305. #endregion
  6306. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6307. stopwatch1.Stop();
  6308. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6309. }
  6310. else
  6311. {
  6312. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6313. AddMessage_Station(stationNameStr, LogType.Info,
  6314. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6315. FunsEip[plcNo].Connect(); // 重连
  6316. }
  6317. }
  6318. catch (Exception ex)
  6319. {
  6320. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6321. AddMessage_Station(stationNameStr, LogType.Error,
  6322. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6323. }
  6324. Thread.Sleep(IntervalReadPLC);
  6325. }
  6326. }
  6327. /// <summary>
  6328. /// [S9] 下料设备 - 进站
  6329. /// </summary>
  6330. /// <param name="plcNo">PLC编号</param>
  6331. /// <param name="stationNameStr">工站全称</param>
  6332. /// <param name="stPLC_MesData"></param>
  6333. /// <param name="tagMesCommName"></param>
  6334. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6335. string tagBarsetName, out bool ProgressState)
  6336. {
  6337. Stopwatch stopwatch1 = new Stopwatch();
  6338. Stopwatch stopwatch2 = new Stopwatch();
  6339. try
  6340. {
  6341. stopwatch1.Start();
  6342. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6343. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6344. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  6345. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  6346. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6347. bool pass = a1Result == 1;
  6348. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6349. //载具码验证产品码
  6350. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6351. if (string.IsNullOrEmpty(strProductBarcode))
  6352. {
  6353. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6354. ProgressState = false;
  6355. Thread.Sleep(10000);
  6356. return;
  6357. }
  6358. sn = strProductBarcode;
  6359. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6360. // 产品SN(物料码)校验
  6361. List<TestItem> item = new List<TestItem>();
  6362. stopwatch2.Start();
  6363. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6364. item, MachineId, StationId, pass, "01-SLOT-01");
  6365. stopwatch2.Stop();
  6366. //指令执行结果 1:OK 110:失败
  6367. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6368. if (mesResultFrmWeb == 1)
  6369. {
  6370. if (a1Result == 1)
  6371. {
  6372. mesResultFrmWeb = 1;
  6373. }
  6374. else
  6375. {
  6376. mesResultFrmWeb = 110;
  6377. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6378. }
  6379. }
  6380. //进站结果写入PLC
  6381. CommandFromPLC resultToPlC = new CommandFromPLC();
  6382. resultToPlC.cmd = 0;
  6383. resultToPlC.cmdParam = 0; //指令参数
  6384. resultToPlC.cmdResult = mesResultFrmWeb;
  6385. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6386. }
  6387. catch (Exception ex)
  6388. {
  6389. string str = ex.StackTrace;
  6390. AddMessage(LogType.Error,
  6391. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  6392. str.Length - str.LastIndexOf("\\") - 1));
  6393. CommandFromPLC resultToPlC = new CommandFromPLC();
  6394. resultToPlC.cmd = 0;
  6395. resultToPlC.cmdParam = 0; //指令参数
  6396. resultToPlC.cmdResult = 110;
  6397. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6398. }
  6399. stopwatch1.Stop();
  6400. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  6401. AddMessage(LogType.Info,
  6402. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6403. stopwatch2.ElapsedMilliseconds + "ms");
  6404. ProgressState = false;
  6405. }
  6406. /// <summary>
  6407. /// [S9] 下料设备 - 出站接口
  6408. /// </summary>
  6409. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6410. string stationCode, string stationName, out bool ProgressState)
  6411. {
  6412. Stopwatch stopwatch1 = new Stopwatch();
  6413. Stopwatch stopwatch2 = new Stopwatch();
  6414. try
  6415. {
  6416. stopwatch1.Start();
  6417. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6418. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6419. string processItem = stationName; // 测试项目
  6420. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6421. string supplierCode = ""; // 供应商代码
  6422. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6423. string batch_num = GlobalContext.BatchNumber; // 批次号
  6424. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6425. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6426. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6427. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  6428. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  6429. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6430. bool pass = a1Result == 1;
  6431. //根据载具码获取产品码
  6432. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6433. if (string.IsNullOrEmpty(strProductBarcode))
  6434. {
  6435. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6436. ProgressState = false;
  6437. Thread.Sleep(10000);
  6438. return;
  6439. }
  6440. sn = strProductBarcode;
  6441. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6442. List<TestItem> items = new List<TestItem>();
  6443. items.Add(new TestItem()
  6444. {
  6445. Parameter_name = "载具码",
  6446. Parameter_value = CarrierBarcode,
  6447. Parameter_unit = ""
  6448. });
  6449. items.Add(new TestItem()
  6450. {
  6451. Parameter_name = "产品码",
  6452. Parameter_value = sn,
  6453. Parameter_unit = ""
  6454. });
  6455. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6456. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6457. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  6458. MachineId, StationId, "", paramJson);
  6459. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6460. if (mesResultFrmWeb == 1)
  6461. {
  6462. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6463. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6464. }
  6465. stopwatch2.Start();
  6466. //进站结果写入PLC
  6467. CommandFromPLC resultToPlC = new CommandFromPLC();
  6468. resultToPlC.cmd = 0;
  6469. resultToPlC.cmdParam = 0; //指令参数
  6470. resultToPlC.cmdResult = mesResultFrmWeb;
  6471. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6472. stopwatch2.Stop();
  6473. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6474. //保存PLC返回MES数据到本地
  6475. ResponseMessage message = new ResponseMessage();
  6476. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  6477. stPLC_MesData.mesData.nRemainCount);
  6478. if (message.result == false)
  6479. {
  6480. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6481. }
  6482. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6483. if (result1 == 1)
  6484. {
  6485. //载具码解除绑定
  6486. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  6487. if (message.result == false)
  6488. {
  6489. AddMessage(LogType.Error, message.text);
  6490. }
  6491. }
  6492. }
  6493. catch (Exception ex)
  6494. {
  6495. stopwatch2.Start();
  6496. CommandFromPLC resultToPlC = new CommandFromPLC();
  6497. resultToPlC.cmd = 0;
  6498. resultToPlC.cmdParam = 0; //指令参数
  6499. resultToPlC.cmdResult = 110;
  6500. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6501. stopwatch2.Stop();
  6502. string str = ex.StackTrace;
  6503. AddMessage(LogType.Error,
  6504. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6505. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6506. }
  6507. stopwatch1.Stop();
  6508. AddMessage(LogType.Info,
  6509. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6510. stopwatch2.ElapsedMilliseconds + "ms");
  6511. ProgressState = false;
  6512. uuid = "";
  6513. }
  6514. #endregion
  6515. #endregion Xiaomi
  6516. #region PLC1 张超凡
  6517. #region [S1] Tray盘上料装备(板测)
  6518. /// <summary>
  6519. /// S1工位的数据- 触发信号上次的值
  6520. /// </summary>
  6521. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  6522. /// <summary>
  6523. /// S1工位的数据(含触发信号)
  6524. /// </summary>
  6525. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  6526. /// <summary>
  6527. /// S1工位的数据- 回写点位
  6528. /// </summary>
  6529. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6530. ///// <summary>
  6531. ///// 触发信号
  6532. ///// </summary>
  6533. //private ManualResetEvent[] MreTasks;
  6534. /// <summary>
  6535. /// [S1] Tray盘上料装备(板测)
  6536. /// </summary>
  6537. /// <param name="plcNo">PLC编号</param>
  6538. //private void ReadStation_S1(int plcNo)
  6539. //{
  6540. // // [S1] Tray盘上料装备
  6541. // // [S2] FCT
  6542. // // [S3] 值板机
  6543. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6544. // // [S5] Tray盘下料装备
  6545. // string stationCode = "[S1]";
  6546. // string stationName = "Tray盘上料装备";
  6547. // string stationNameStr = stationCode + stationName;
  6548. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6549. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6550. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6551. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6552. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6553. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6554. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6555. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6556. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  6557. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6558. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  6559. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6560. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6561. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  6562. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  6563. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6564. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  6565. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  6566. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6567. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  6568. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  6569. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  6570. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  6571. // s1PLCData.Add("a1Result", 0); // 产品结果
  6572. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6573. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  6574. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  6575. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  6576. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  6577. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6578. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  6579. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  6580. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  6581. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  6582. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  6583. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6584. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  6585. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  6586. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6587. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  6588. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  6589. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6590. // while (IsRun)
  6591. // {
  6592. // try
  6593. // {
  6594. // if (!GlobalContext._IsCon_Funs1)
  6595. // {
  6596. // UpdatePLCMonitor(1, plcNo, 0);
  6597. // continue;
  6598. // }
  6599. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6600. // {
  6601. // Stopwatch stopwatch1 = new Stopwatch();
  6602. // Stopwatch stopwatch2 = new Stopwatch();
  6603. // stopwatch1.Start();
  6604. // stopwatch2.Start();
  6605. // #region 一次性读取所有数据
  6606. // // 一次性读取所有数据
  6607. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6608. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6609. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6610. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  6611. // int[] datas = data1.Concat(data2).ToArray();
  6612. // datas = datas.Concat(data3).ToArray();
  6613. // datas = datas.Concat(data4).ToArray();
  6614. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  6615. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  6616. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  6617. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  6618. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  6619. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  6620. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  6621. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  6622. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  6623. // s1PLCData["a1MES_FLAG"] = datas[109];
  6624. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  6625. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  6626. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  6627. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  6628. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  6629. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  6630. // s1PLCData["a1Result"] = datas[170];
  6631. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  6632. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  6633. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  6634. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  6635. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  6636. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  6637. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  6638. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  6639. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  6640. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  6641. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  6642. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  6643. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  6644. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  6645. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  6646. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  6647. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  6648. // s1PLCData["a1AGVUpStart"] = datas[308];
  6649. // s1PLCData["a1AGVUpEnd"] = datas[309];
  6650. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  6651. // s1PLCData["a1AGVDownStart"] = datas[321];
  6652. // s1PLCData["a1AGVDownEnd"] = datas[322];
  6653. // #endregion 一次性读取所有数据
  6654. // stopwatch2.Stop();
  6655. // #region 回写操作,写后清空flag
  6656. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  6657. // #endregion 回写操作,写后清空flag
  6658. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6659. // try
  6660. // {
  6661. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  6662. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  6663. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  6664. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  6665. // {
  6666. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  6667. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  6668. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  6669. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6670. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  6671. // }
  6672. // }
  6673. // catch (Exception ex)
  6674. // {
  6675. // // 6代表上位机报警
  6676. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  6677. // string str = ex.StackTrace;
  6678. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6679. // }
  6680. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6681. // #region 上料进站校验
  6682. // try
  6683. // {
  6684. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  6685. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  6686. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  6687. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  6688. // {
  6689. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  6690. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6691. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  6692. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  6693. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  6694. // }
  6695. // }
  6696. // catch (Exception ex)
  6697. // {
  6698. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  6699. // string str = ex.StackTrace;
  6700. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6701. // }
  6702. // #endregion 上料进站校验
  6703. // #region Tray盘上料装备-出站接口
  6704. // try
  6705. // {
  6706. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  6707. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  6708. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  6709. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  6710. // {
  6711. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  6712. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6713. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  6714. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  6715. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  6716. // }
  6717. // }
  6718. // catch (Exception ex)
  6719. // {
  6720. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  6721. // string str = ex.StackTrace;
  6722. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6723. // }
  6724. // #endregion Tray盘上料装备-出站接口
  6725. // #region Tray盘上料装备-将SN发给ICT标机
  6726. // try
  6727. // {
  6728. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  6729. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  6730. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  6731. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  6732. // {
  6733. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  6734. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  6735. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  6736. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  6737. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  6738. // }
  6739. // }
  6740. // catch (Exception ex)
  6741. // {
  6742. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  6743. // string str = ex.StackTrace;
  6744. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6745. // }
  6746. // #endregion Tray盘上料装备-将SN发给ICT标机
  6747. // #region Tray盘上料装备-点检数据
  6748. // //try
  6749. // //{
  6750. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  6751. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  6752. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  6753. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  6754. // // if (pLC_Flag && !mES_Flag) // 1 0
  6755. // // {
  6756. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  6757. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  6758. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  6759. // // }
  6760. // // else if (!pLC_Flag && mES_Flag) // 0 1
  6761. // // {
  6762. // // // 清空写给PLC的数据
  6763. // // // MES_Flag重置为0
  6764. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  6765. // // }
  6766. // //}
  6767. // //catch (Exception ex)
  6768. // //{
  6769. // // // MES_Flag 为2上位机报错
  6770. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  6771. // // string str = ex.StackTrace;
  6772. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6773. // //}
  6774. // #endregion Tray盘上料装备-点检数据
  6775. // #region 节拍接口
  6776. // try
  6777. // {
  6778. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  6779. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  6780. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  6781. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  6782. // {
  6783. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  6784. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6785. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  6786. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  6787. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  6788. // }
  6789. // }
  6790. // catch (Exception ex)
  6791. // {
  6792. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  6793. // string str = ex.StackTrace;
  6794. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6795. // }
  6796. // #endregion 节拍接口
  6797. // #region AGV上料
  6798. // // AGV上料叫AGV信号
  6799. // try
  6800. // {
  6801. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  6802. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  6803. // if (a1AGVUpCall != a1AGVUpCallOld)
  6804. // {
  6805. // if (a1AGVUpCall == 1) // 0->1
  6806. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  6807. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  6808. // }
  6809. // }
  6810. // catch (Exception ex)
  6811. // {
  6812. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  6813. // string str = ex.StackTrace;
  6814. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6815. // }
  6816. // // AGV上料完成信号
  6817. // try
  6818. // {
  6819. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  6820. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  6821. // if (a1AGVUpEnd != a1AGVUpEndOld)
  6822. // {
  6823. // if (a1AGVUpEnd == 1) // 0->1
  6824. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  6825. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  6826. // }
  6827. // }
  6828. // catch (Exception ex)
  6829. // {
  6830. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  6831. // string str = ex.StackTrace;
  6832. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6833. // }
  6834. // #endregion AGV上料
  6835. // #region AGV下料
  6836. // // AGV下料叫agv信号
  6837. // try
  6838. // {
  6839. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  6840. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  6841. // if (a1AGVDownCall != a1AGVDownCallOld)
  6842. // {
  6843. // if (a1AGVDownCall == 1) // 0->1
  6844. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  6845. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  6846. // }
  6847. // }
  6848. // catch (Exception ex)
  6849. // {
  6850. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  6851. // string str = ex.StackTrace;
  6852. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6853. // }
  6854. // // AGV下料完成信号
  6855. // try
  6856. // {
  6857. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  6858. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  6859. // if (a1AGVDownEnd != a1AGVDownEndOld)
  6860. // {
  6861. // if (a1AGVDownEnd == 1) // 0->1
  6862. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  6863. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  6864. // }
  6865. // }
  6866. // catch (Exception ex)
  6867. // {
  6868. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  6869. // string str = ex.StackTrace;
  6870. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6871. // }
  6872. // #endregion AGV下料
  6873. // #region 心跳
  6874. // try
  6875. // {
  6876. // short states = 0;
  6877. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6878. // }
  6879. // catch (Exception ex)
  6880. // {
  6881. // string str = ex.StackTrace;
  6882. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6883. // }
  6884. // #endregion 心跳
  6885. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6886. // stopwatch1.Stop();
  6887. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6888. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6889. // }
  6890. // else
  6891. // {
  6892. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6893. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6894. // Funs[plcNo].Connect(); // 重连
  6895. // }
  6896. // }
  6897. // catch (Exception ex)
  6898. // {
  6899. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6900. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6901. // Funs[plcNo].ReConnect();
  6902. // }
  6903. // Thread.Sleep(IntervalReadPLC);
  6904. // }
  6905. //}
  6906. /// <summary>
  6907. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  6908. /// </summary>
  6909. /// <param name="plcNo">PLC编号</param>
  6910. /// <param name="stationNameStr">工站全称</param>
  6911. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  6912. {
  6913. Stopwatch stopwatch1 = new Stopwatch();
  6914. Stopwatch stopwatch2 = new Stopwatch();
  6915. try
  6916. {
  6917. stopwatch1.Start();
  6918. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  6919. sn = sn.Replace("\0", "");
  6920. #region 查询载具上的产品信息
  6921. string cavityData = string.Empty;
  6922. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6923. if (string.IsNullOrEmpty(cavityData))
  6924. cavityData = "";
  6925. if (snResult != 0)
  6926. {
  6927. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6928. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  6929. writeToPLC_Flag1.Adress = 2003;
  6930. writeToPLC_Flag1.Value = (short)6;
  6931. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  6932. stopwatch1.Stop();
  6933. AddMessage(LogType.Info,
  6934. stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  6935. "ms");
  6936. return;
  6937. }
  6938. #endregion 查询载具上的产品信息
  6939. string[] cavitySNs = cavityData.Split('.');
  6940. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  6941. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  6942. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  6943. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  6944. if (cavitySNs != null && cavitySNs.Length >= 2)
  6945. {
  6946. a1CavitySN1_VehicleStates = cavitySNs[0];
  6947. a1CavitySN2_VehicleStates = cavitySNs[1];
  6948. a1CavityResult1_VehicleStates = 2;
  6949. a1CavityResult2_VehicleStates = 2;
  6950. }
  6951. if (a1CavitySN1_VehicleStates == "假产品")
  6952. a1CavityResult1_VehicleStates = 3;
  6953. if (a1CavitySN2_VehicleStates == "假产品")
  6954. a1CavityResult2_VehicleStates = 3;
  6955. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6956. // 回写
  6957. stopwatch2.Start();
  6958. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  6959. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  6960. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  6961. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  6962. //// MES_Flag
  6963. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  6964. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6965. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  6966. writeToPLC_Flag.Adress = 2003;
  6967. writeToPLC_Flag.Value = mES_Flag;
  6968. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  6969. {
  6970. Name = "a1CavitySN1_VehicleStates",
  6971. Adress = 2024,
  6972. ValueType = PLCValueType.String,
  6973. ValueTypeStrLength = 20,
  6974. Value = a1CavitySN1_VehicleStates
  6975. });
  6976. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  6977. {
  6978. Name = "a1CavitySN2_VehicleStates",
  6979. Adress = 2044,
  6980. ValueType = PLCValueType.String,
  6981. ValueTypeStrLength = 20,
  6982. Value = a1CavitySN2_VehicleStates
  6983. });
  6984. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  6985. {
  6986. Name = "a1CavityResult1_VehicleStates",
  6987. Adress = 2064,
  6988. ValueType = PLCValueType.Short,
  6989. Value = a1CavityResult1_VehicleStates
  6990. });
  6991. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  6992. {
  6993. Name = "a1CavityResult2_VehicleStates",
  6994. Adress = 2065,
  6995. ValueType = PLCValueType.Short,
  6996. Value = a1CavityResult2_VehicleStates
  6997. });
  6998. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  6999. stopwatch2.Stop();
  7000. }
  7001. catch (Exception ex)
  7002. {
  7003. string str = ex.StackTrace;
  7004. AddMessage_Station(stationNameStr, LogType.Error,
  7005. $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
  7006. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7007. // MES_Flag
  7008. stopwatch2.Start();
  7009. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7010. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7011. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7012. writeToPLC_Flag.Adress = 2003;
  7013. writeToPLC_Flag.Value = (short)6;
  7014. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7015. stopwatch2.Stop();
  7016. }
  7017. stopwatch1.Stop();
  7018. AddMessage(LogType.Info,
  7019. stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7020. stopwatch2.ElapsedMilliseconds + "ms");
  7021. }
  7022. /// <summary>
  7023. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  7024. /// </summary>
  7025. /// <param name="plcNo">PLC编号</param>
  7026. /// <param name="stationNameStr">工站全称</param>
  7027. private void S1上料进站校验(int plcNo, string stationNameStr)
  7028. {
  7029. Stopwatch stopwatch1 = new Stopwatch();
  7030. Stopwatch stopwatch2 = new Stopwatch();
  7031. try
  7032. {
  7033. stopwatch1.Start();
  7034. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  7035. sn = sn.Replace("\0", "");
  7036. // 保存进站数据+调用进站MES接口
  7037. List<TestItem> item = new List<TestItem>();
  7038. stopwatch2.Start();
  7039. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  7040. item, out string errorMsg);
  7041. stopwatch2.Stop();
  7042. short a1MES_FLAG_Check = (short)result;
  7043. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7044. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7045. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7046. writeToPLC_Flag.Adress = 2077;
  7047. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  7048. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7049. }
  7050. catch (Exception ex)
  7051. {
  7052. string str = ex.StackTrace;
  7053. AddMessage_Station(stationNameStr, LogType.Error,
  7054. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  7055. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7056. // MES_Flag
  7057. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7058. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7059. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7060. writeToPLC_Flag.Adress = 2077;
  7061. writeToPLC_Flag.Value = (short)6;
  7062. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7063. }
  7064. stopwatch1.Stop();
  7065. AddMessage(LogType.Info,
  7066. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7067. stopwatch2.ElapsedMilliseconds + "ms");
  7068. }
  7069. /// <summary>
  7070. /// [S1] Tray盘上料装备(板测)- 出站接口
  7071. /// </summary>
  7072. /// <param name="plcNo"></param>
  7073. /// <param name="stationCode"></param>
  7074. /// <param name="stationName"></param>
  7075. private void S1出站接口(int plcNo, string stationCode, string stationName)
  7076. {
  7077. Stopwatch stopwatch1 = new Stopwatch();
  7078. Stopwatch stopwatch2 = new Stopwatch();
  7079. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7080. string stationNameStr = stationCode + stationName;
  7081. string processItem = stationName; // 测试项目
  7082. try
  7083. {
  7084. stopwatch1.Start();
  7085. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7086. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7087. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7088. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7089. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  7090. sn = sn.Replace("\0", "");
  7091. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  7092. partNo1 = partNo1.Replace("\0", "");
  7093. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  7094. partNo2 = partNo2.Replace("\0", "");
  7095. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  7096. bool pass = a1Result == 1;
  7097. stopwatch2.Start();
  7098. // 产品1
  7099. List<TestItem> items = new List<TestItem>();
  7100. items.Add(new TestItem()
  7101. {
  7102. Parameter_name = "载具码",
  7103. Parameter_value = sn,
  7104. Parameter_unit = ""
  7105. });
  7106. items.Add(new TestItem()
  7107. {
  7108. Parameter_name = "载具穴号",
  7109. Parameter_value = "1",
  7110. Parameter_unit = ""
  7111. });
  7112. items.Add(new TestItem()
  7113. {
  7114. Parameter_name = "产品结果",
  7115. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7116. Parameter_unit = ""
  7117. });
  7118. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7119. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  7120. // 产品2
  7121. items = new List<TestItem>();
  7122. items.Add(new TestItem()
  7123. {
  7124. Parameter_name = "载具码",
  7125. Parameter_value = sn,
  7126. Parameter_unit = ""
  7127. });
  7128. items.Add(new TestItem()
  7129. {
  7130. Parameter_name = "载具穴号",
  7131. Parameter_value = "2",
  7132. Parameter_unit = ""
  7133. });
  7134. items.Add(new TestItem()
  7135. {
  7136. Parameter_name = "产品结果",
  7137. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7138. Parameter_unit = ""
  7139. });
  7140. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7141. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  7142. short result = 0;
  7143. List<int> results = new List<int>() { result1, result2 };
  7144. if (result1 == 1 && result2 == 1)
  7145. result = 1;
  7146. else if (results.Contains(3))
  7147. result = 3;
  7148. else if (results.Contains(2))
  7149. result = 2;
  7150. else if (results.Contains(4))
  7151. result = 4;
  7152. else
  7153. result = 4;
  7154. stopwatch2.Stop();
  7155. #region 存储绑定数据到 边线MES系统中
  7156. if (result == 1)
  7157. {
  7158. string data = string.Concat(partNo1, ".", partNo2);
  7159. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7160. if (resultMesR != 0)
  7161. {
  7162. result = 4;
  7163. AddMessage_Station(stationNameStr, LogType.Error,
  7164. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  7165. }
  7166. }
  7167. #endregion 存储绑定数据到 边线MES系统中
  7168. // MES_Flag 为MES报错
  7169. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7170. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  7171. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7172. writeToPLC_Flag.Name = "a1MES_FLAG";
  7173. writeToPLC_Flag.Adress = 2109;
  7174. writeToPLC_Flag.Value = result;
  7175. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7176. OnMessage(LogType.Debug,
  7177. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7178. }
  7179. catch (Exception ex)
  7180. {
  7181. stopwatch2.Restart();
  7182. // MES_Flag 为4上位机报错
  7183. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  7184. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7185. writeToPLC_Flag.Name = "a1MES_FLAG";
  7186. writeToPLC_Flag.Adress = 2109;
  7187. writeToPLC_Flag.Value = (short)4;
  7188. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7189. stopwatch2.Stop();
  7190. string str = ex.StackTrace;
  7191. AddMessage_Station(stationNameStr, LogType.Error,
  7192. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  7193. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7194. }
  7195. stopwatch1.Stop();
  7196. AddMessage(LogType.Info,
  7197. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  7198. stopwatch2.ElapsedMilliseconds + "ms");
  7199. }
  7200. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  7201. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  7202. //{
  7203. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7204. // string stationNameStr = stationCode + stationName;
  7205. // string processItem = stationName; // 测试项目
  7206. // try
  7207. // {
  7208. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7209. // string accno = "1"; // 工序编号
  7210. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  7211. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  7212. // List<OneCheckItem> items = new List<OneCheckItem>()
  7213. // {
  7214. // new OneCheckItem()
  7215. // {
  7216. // Onecheck_name="胶圈装配行程设定上限",
  7217. // Onecheck_content="上限值",
  7218. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  7219. // },
  7220. // };
  7221. // OneCheckData oneCheckData = new OneCheckData()
  7222. // {
  7223. // Line_code = GlobalContext.LineCode,
  7224. // Line_name = GlobalContext.LineName,
  7225. // Equipment_code = equipmentCode,
  7226. // Equipment_name = equipmentCode,
  7227. // Workorder_code = workorder_code,
  7228. // Procedure_code = accno,
  7229. // Procedure_name = processItem,
  7230. // Oneckeck_values = items,
  7231. // Onecheck_empcode = "",
  7232. // Onecheck_empname = "",
  7233. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  7234. // };
  7235. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  7236. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  7237. // short result = result1 == 1 ? (short)1 : (short)2;
  7238. // // MES_Flag 为4MES报错
  7239. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  7240. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7241. // }
  7242. // catch (Exception ex)
  7243. // {
  7244. // // MES_Flag 为2上位机报错
  7245. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7246. // string str = ex.StackTrace;
  7247. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7248. // }
  7249. //}
  7250. // ReadStation_S1_2 节拍接口+AGV
  7251. /// <summary>
  7252. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  7253. /// </summary>
  7254. /// <param name="plcNo">PLC编号</param>
  7255. /// <param name="stationNameStr">工站全称</param>
  7256. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  7257. {
  7258. Stopwatch stopwatch1 = new Stopwatch();
  7259. Stopwatch stopwatch2 = new Stopwatch();
  7260. try
  7261. {
  7262. stopwatch1.Start();
  7263. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  7264. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  7265. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  7266. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  7267. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  7268. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  7269. // ZS 将SN发给ICT标机(串口)
  7270. short a1MES_FLAG_ICT = 1;
  7271. stopwatch2.Start();
  7272. // MES_Flag
  7273. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  7274. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7275. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7276. writeToPLC_Flag.Adress = 2182;
  7277. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  7278. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7279. stopwatch2.Stop();
  7280. }
  7281. catch (Exception ex)
  7282. {
  7283. string str = ex.StackTrace;
  7284. AddMessage_Station(stationNameStr, LogType.Error,
  7285. $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
  7286. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7287. stopwatch2.Start();
  7288. // MES_Flag
  7289. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  7290. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7291. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7292. writeToPLC_Flag.Adress = 2182;
  7293. writeToPLC_Flag.Value = (short)4;
  7294. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7295. stopwatch2.Stop();
  7296. }
  7297. stopwatch1.Stop();
  7298. AddMessage(LogType.Info,
  7299. stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7300. stopwatch2.ElapsedMilliseconds + "ms");
  7301. }
  7302. /// <summary>
  7303. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  7304. /// </summary>
  7305. /// <param name="plcNo">PLC编号</param>
  7306. /// <param name="stationNameStr">工站全称</param>
  7307. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  7308. {
  7309. Stopwatch stopwatch1 = new Stopwatch();
  7310. Stopwatch stopwatch2 = new Stopwatch();
  7311. try
  7312. {
  7313. stopwatch1.Start();
  7314. // ZS 呼叫AGV
  7315. short a1AGVUpCall = 2;
  7316. stopwatch2.Start();
  7317. // a1AGVUpCall
  7318. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7319. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7320. writeToPLC_Flag.Name = "a1AGVUpCall";
  7321. writeToPLC_Flag.Adress = 2307;
  7322. writeToPLC_Flag.Value = a1AGVUpCall;
  7323. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7324. stopwatch2.Stop();
  7325. }
  7326. catch (Exception ex)
  7327. {
  7328. string str = ex.StackTrace;
  7329. AddMessage_Station(stationNameStr, LogType.Error,
  7330. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7331. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7332. // a1AGVUpCall
  7333. stopwatch2.Start();
  7334. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7335. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7336. writeToPLC_Flag.Name = "a1AGVUpCall";
  7337. writeToPLC_Flag.Adress = 2307;
  7338. writeToPLC_Flag.Value = (short)4;
  7339. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7340. stopwatch2.Stop();
  7341. }
  7342. stopwatch1.Stop();
  7343. AddMessage(LogType.Info,
  7344. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7345. stopwatch2.ElapsedMilliseconds + "ms");
  7346. }
  7347. /// <summary>
  7348. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  7349. /// </summary>
  7350. /// <param name="plcNo">PLC编号</param>
  7351. /// <param name="stationNameStr">工站全称</param>
  7352. private void S1AGV上料完成(int plcNo, string stationNameStr)
  7353. {
  7354. Stopwatch stopwatch1 = new Stopwatch();
  7355. Stopwatch stopwatch2 = new Stopwatch();
  7356. try
  7357. {
  7358. stopwatch1.Start();
  7359. // ZS AGV上料完成,让小车离开
  7360. short a1AGVUpEnd = 2;
  7361. stopwatch2.Start();
  7362. // a1AGVUpEnd
  7363. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7364. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7365. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7366. writeToPLC_Flag.Adress = 2309;
  7367. writeToPLC_Flag.Value = a1AGVUpEnd;
  7368. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7369. stopwatch2.Stop();
  7370. }
  7371. catch (Exception ex)
  7372. {
  7373. string str = ex.StackTrace;
  7374. AddMessage_Station(stationNameStr, LogType.Error,
  7375. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7376. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7377. // a1AGVUpEnd
  7378. stopwatch2.Start();
  7379. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7380. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7381. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7382. writeToPLC_Flag.Adress = 2309;
  7383. writeToPLC_Flag.Value = (short)4;
  7384. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7385. stopwatch2.Stop();
  7386. }
  7387. stopwatch1.Stop();
  7388. AddMessage(LogType.Info,
  7389. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7390. stopwatch2.ElapsedMilliseconds + "ms");
  7391. }
  7392. /// <summary>
  7393. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  7394. /// </summary>
  7395. /// <param name="plcNo">PLC编号</param>
  7396. /// <param name="stationNameStr">工站全称</param>
  7397. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  7398. {
  7399. Stopwatch stopwatch1 = new Stopwatch();
  7400. Stopwatch stopwatch2 = new Stopwatch();
  7401. try
  7402. {
  7403. stopwatch1.Start();
  7404. // ZS 呼叫AGV
  7405. short a1AGVDownCall = 2;
  7406. stopwatch2.Start();
  7407. // a1AGVDownCall
  7408. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7409. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7410. writeToPLC_Flag.Name = "a1AGVDownCall";
  7411. writeToPLC_Flag.Adress = 2320;
  7412. writeToPLC_Flag.Value = a1AGVDownCall;
  7413. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7414. stopwatch2.Stop();
  7415. }
  7416. catch (Exception ex)
  7417. {
  7418. string str = ex.StackTrace;
  7419. AddMessage_Station(stationNameStr, LogType.Error,
  7420. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7421. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7422. // a1AGVDownCall
  7423. stopwatch2.Start();
  7424. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7425. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7426. writeToPLC_Flag.Name = "a1AGVDownCall";
  7427. writeToPLC_Flag.Adress = 2320;
  7428. writeToPLC_Flag.Value = (short)4;
  7429. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7430. stopwatch2.Stop();
  7431. }
  7432. stopwatch1.Stop();
  7433. AddMessage(LogType.Info,
  7434. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7435. stopwatch2.ElapsedMilliseconds + "ms");
  7436. }
  7437. /// <summary>
  7438. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  7439. /// </summary>
  7440. /// <param name="plcNo">PLC编号</param>
  7441. /// <param name="stationNameStr">工站全称</param>
  7442. private void S1AGV下料完成(int plcNo, string stationNameStr)
  7443. {
  7444. Stopwatch stopwatch1 = new Stopwatch();
  7445. Stopwatch stopwatch2 = new Stopwatch();
  7446. try
  7447. {
  7448. stopwatch1.Start();
  7449. // ZS AGV上料完成,让小车离开
  7450. short a1AGVDownEnd = 2;
  7451. stopwatch2.Start();
  7452. // a1AGVDownEnd
  7453. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7454. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7455. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7456. writeToPLC_Flag.Adress = 2322;
  7457. writeToPLC_Flag.Value = a1AGVDownEnd;
  7458. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7459. stopwatch2.Stop();
  7460. }
  7461. catch (Exception ex)
  7462. {
  7463. string str = ex.StackTrace;
  7464. AddMessage_Station(stationNameStr, LogType.Error,
  7465. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7466. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7467. // a1AGVDownEnd
  7468. stopwatch2.Start();
  7469. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7470. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7471. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7472. writeToPLC_Flag.Adress = 2322;
  7473. writeToPLC_Flag.Value = (short)4;
  7474. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7475. stopwatch2.Stop();
  7476. }
  7477. stopwatch1.Stop();
  7478. AddMessage(LogType.Info,
  7479. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7480. stopwatch2.ElapsedMilliseconds + "ms");
  7481. }
  7482. #endregion [S1] Tray盘上料装备(板测)
  7483. #endregion PLC1 张超凡
  7484. #region PLC2 李晓奇
  7485. #region [S2] FCT(板测)
  7486. /// <summary>
  7487. /// S2工位的数据- 触发信号上次的值
  7488. /// </summary>
  7489. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  7490. /// <summary>
  7491. /// S2工位的数据(含触发信号)
  7492. /// </summary>
  7493. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  7494. /// <summary>
  7495. /// S2工位的数据- 回写点位
  7496. /// </summary>
  7497. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  7498. /// <summary>
  7499. /// [S2] FCT(板测)
  7500. /// </summary>
  7501. /// <param name="plcNo">PLC编号</param>
  7502. //private void ReadStation_S2(int plcNo)
  7503. //{
  7504. // // [S1] Tray盘上料装备
  7505. // // [S2] FCT
  7506. // // [S3] 值板机
  7507. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  7508. // // [S5] Tray盘下料装备
  7509. // /// 上位机心跳
  7510. // /// 获取设备报警数据与状态信息
  7511. // string stationCode = "[S2]";
  7512. // string stationName = "FCT";
  7513. // string stationNameStr = stationCode + stationName;
  7514. // #region 创建字典
  7515. // // 触发信号字典 赋值
  7516. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  7517. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  7518. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7519. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7520. // // PLC数据字典 赋值
  7521. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  7522. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  7523. // s2PLCData.Add("b1ProductSN_Check", 0);
  7524. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  7525. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  7526. // s2PLCData.Add("b1ProductSN_Unbind", "");
  7527. // s2PLCData.Add("b1ProductSN_Bind", "");
  7528. // s2PLCData.Add("b1Part1SN_Bind", "");
  7529. // s2PLCData.Add("b1Part2SN_Bind", "");
  7530. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  7531. // s2PLCData.Add("b1MES_FLAG", 0);
  7532. // s2PLCData.Add("b1ProductSN", 0);
  7533. // s2PLCData.Add("b1Part1Result", 0);
  7534. // s2PLCData.Add("b1Part2Result", 0);
  7535. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  7536. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  7537. // s2PLCData.Add("b1OEEProductSN", "");
  7538. // s2PLCData.Add("b1OEEType", 0);
  7539. // #endregion 创建字典
  7540. // while (IsRun)
  7541. // {
  7542. // try
  7543. // {
  7544. // if (!GlobalContext._IsCon_Funs2)
  7545. // {
  7546. // UpdatePLCMonitor(1, plcNo, 0);
  7547. // continue;
  7548. // }
  7549. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  7550. // {
  7551. // Stopwatch stopwatch1 = new Stopwatch();
  7552. // Stopwatch stopwatch2 = new Stopwatch();
  7553. // stopwatch1.Start();
  7554. // stopwatch2.Start();
  7555. // #region 一次性读取所有数据
  7556. // // 一次性读取所有数据
  7557. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  7558. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  7559. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  7560. // int[] datas = data1.Concat(data2).ToArray();
  7561. // datas = datas.Concat(data3).ToArray();
  7562. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  7563. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  7564. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  7565. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  7566. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  7567. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  7568. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  7569. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  7570. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  7571. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  7572. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  7573. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  7574. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  7575. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  7576. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  7577. // s2PLCData["b1MES_FLAG"] = datas[169];
  7578. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  7579. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  7580. // s2PLCData["b1Part1Result"] = datas[190];
  7581. // s2PLCData["b1Part2Result"] = datas[191];
  7582. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  7583. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  7584. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  7585. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  7586. // s2PLCData["b1OEEType"] = datas[224];
  7587. // #endregion 一次性读取所有数据
  7588. // stopwatch2.Stop();
  7589. // #region 回写操作,写后清空flag
  7590. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  7591. // #endregion 回写操作,写后清空flag
  7592. // #region 进站校验
  7593. // try
  7594. // {
  7595. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  7596. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7597. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  7598. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  7599. // {
  7600. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  7601. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  7602. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  7603. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  7604. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  7605. // }
  7606. // }
  7607. // catch (Exception ex)
  7608. // {
  7609. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7610. // string str = ex.StackTrace;
  7611. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7612. // }
  7613. // #endregion 进站校验
  7614. // #region 二穴载具解绑/绑定(产品换载具)
  7615. // try
  7616. // {
  7617. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  7618. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7619. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  7620. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  7621. // {
  7622. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  7623. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  7624. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  7625. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  7626. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  7627. // }
  7628. // }
  7629. // catch (Exception ex)
  7630. // {
  7631. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7632. // string str = ex.StackTrace;
  7633. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7634. // }
  7635. // #endregion 二穴载具解绑/绑定(产品换载具)
  7636. // #region FCT-出站接口
  7637. // try
  7638. // {
  7639. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  7640. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  7641. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  7642. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  7643. // {
  7644. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  7645. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7646. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  7647. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  7648. // }
  7649. // }
  7650. // catch (Exception ex)
  7651. // {
  7652. // // MES_Flag 为6上位机报错
  7653. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  7654. // string str = ex.StackTrace;
  7655. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7656. // }
  7657. // #endregion FCT-出站接口
  7658. // #region 节拍接口
  7659. // try
  7660. // {
  7661. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  7662. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  7663. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  7664. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  7665. // {
  7666. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  7667. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7668. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  7669. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  7670. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  7671. // }
  7672. // }
  7673. // catch (Exception ex)
  7674. // {
  7675. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  7676. // string str = ex.StackTrace;
  7677. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7678. // }
  7679. // #endregion 节拍接口
  7680. // #region 心跳
  7681. // try
  7682. // {
  7683. // short states = 0;
  7684. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7685. // }
  7686. // catch (Exception ex)
  7687. // {
  7688. // string str = ex.StackTrace;
  7689. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7690. // }
  7691. // #endregion 心跳
  7692. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7693. // stopwatch1.Stop();
  7694. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7695. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7696. // }
  7697. // else
  7698. // {
  7699. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7700. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7701. // Funs[plcNo].Connect();
  7702. // }
  7703. // }
  7704. // catch (Exception ex)
  7705. // {
  7706. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7707. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7708. // Funs[plcNo].ReConnect();
  7709. // }
  7710. // Thread.Sleep(IntervalReadPLC);
  7711. // }
  7712. //}
  7713. /// <summary>
  7714. /// [S2] FCT(板测)- 进站校验
  7715. /// </summary>
  7716. /// <param name="plcNo">PLC编号</param>
  7717. /// <param name="stationNameStr">工站全称</param>
  7718. private void S2进站校验(int plcNo, string stationNameStr)
  7719. {
  7720. Stopwatch stopwatch1 = new Stopwatch();
  7721. Stopwatch stopwatch2 = new Stopwatch();
  7722. try
  7723. {
  7724. stopwatch1.Start();
  7725. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  7726. sn = sn.Replace("\0", "");
  7727. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7728. // 查询物料码By载具码 并判断是不是假产品
  7729. string cavityData = string.Empty;
  7730. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7731. if (string.IsNullOrEmpty(cavityData))
  7732. cavityData = "";
  7733. if (snResult != 0)
  7734. {
  7735. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7736. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  7737. writeToPLC_Flag1.Adress = 2003;
  7738. writeToPLC_Flag1.Value = (short)6;
  7739. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  7740. stopwatch1.Stop();
  7741. AddMessage(LogType.Info,
  7742. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7743. return;
  7744. }
  7745. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7746. string[] cavitySNs = cavityData.Split('.');
  7747. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  7748. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  7749. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7750. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7751. if (cavitySNs != null && cavitySNs.Length >= 2)
  7752. {
  7753. b1Part1SN_Check = cavitySNs[0];
  7754. b1Part2SN_Check = cavitySNs[1];
  7755. b1Part1Result_Check = 2;
  7756. b1Part2Result_Check = 2;
  7757. }
  7758. if (b1Part1SN_Check == "假产品")
  7759. b1Part1Result_Check = 3;
  7760. if (b1Part2SN_Check == "假产品")
  7761. b1Part2Result_Check = 3;
  7762. // 调用MES进站
  7763. stopwatch2.Start();
  7764. // 调用MES进站 - 产品1
  7765. List<TestItem> item;
  7766. int result1 = b1Part1Result_Check;
  7767. if (result1 != 3)
  7768. {
  7769. item = new List<TestItem>();
  7770. item.Add(new TestItem()
  7771. {
  7772. Parameter_name = "载具码",
  7773. Parameter_value = sn,
  7774. });
  7775. item.Add(new TestItem()
  7776. {
  7777. Parameter_name = "载具穴号",
  7778. Parameter_value = "1",
  7779. });
  7780. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7781. b1Part1SN_Check, item, out string errorMsg);
  7782. }
  7783. // 调用MES进站 - 产品2
  7784. int result2 = b1Part2Result_Check;
  7785. if (result2 != 3)
  7786. {
  7787. item = new List<TestItem>();
  7788. item.Add(new TestItem()
  7789. {
  7790. Parameter_name = "载具码",
  7791. Parameter_value = sn,
  7792. });
  7793. item.Add(new TestItem()
  7794. {
  7795. Parameter_name = "载具穴号",
  7796. Parameter_value = "2",
  7797. });
  7798. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7799. b1Part2SN_Check, item, out string errorMsg);
  7800. }
  7801. stopwatch2.Stop();
  7802. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7803. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7804. int result = result1;
  7805. if (result == 1)
  7806. result = result2;
  7807. short b1MES_FLAG_Check = (short)result;
  7808. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  7809. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  7810. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  7811. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  7812. //// MES_Flag
  7813. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7814. WriteToPLC_Flag
  7815. writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7816. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  7817. writeToPLC_Flag.Adress = 2003;
  7818. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  7819. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7820. {
  7821. Name = "b1Part1SN_Check",
  7822. Adress = 2024,
  7823. ValueType = PLCValueType.String,
  7824. ValueTypeStrLength = 20,
  7825. Value = b1Part1SN_Check
  7826. });
  7827. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7828. {
  7829. Name = "b1Part2SN_Check",
  7830. Adress = 2044,
  7831. ValueType = PLCValueType.String,
  7832. ValueTypeStrLength = 20,
  7833. Value = b1Part2SN_Check
  7834. });
  7835. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7836. {
  7837. Name = "b1Part1Result_Check",
  7838. Adress = 2064,
  7839. ValueType = PLCValueType.Short,
  7840. Value = b1Part1Result_Check
  7841. });
  7842. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7843. {
  7844. Name = "b1Part2Result_Check",
  7845. Adress = 2065,
  7846. ValueType = PLCValueType.Short,
  7847. Value = b1Part2Result_Check
  7848. });
  7849. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  7850. }
  7851. catch (Exception ex)
  7852. {
  7853. string str = ex.StackTrace;
  7854. AddMessage_Station(stationNameStr, LogType.Error,
  7855. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  7856. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7857. // MES_Flag
  7858. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7859. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7860. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  7861. writeToPLC_Flag.Adress = 2003;
  7862. writeToPLC_Flag.Value = (short)6;
  7863. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  7864. }
  7865. stopwatch1.Stop();
  7866. AddMessage(LogType.Info,
  7867. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7868. stopwatch2.ElapsedMilliseconds + "ms");
  7869. }
  7870. /// <summary>
  7871. /// [S2] FCT(板测)- 二穴载具解绑绑定
  7872. /// </summary>
  7873. /// <param name="plcNo">PLC编号</param>
  7874. /// <param name="stationNameStr">工站全称</param>
  7875. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  7876. {
  7877. Stopwatch stopwatch1 = new Stopwatch();
  7878. Stopwatch stopwatch2 = new Stopwatch();
  7879. try
  7880. {
  7881. stopwatch1.Start();
  7882. // 产品换载具
  7883. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  7884. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  7885. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  7886. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  7887. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  7888. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  7889. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  7890. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  7891. stopwatch2.Start();
  7892. #region 查询载具上的产品信息
  7893. //string cavityData = string.Empty;
  7894. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  7895. //if (string.IsNullOrEmpty(cavityData))
  7896. // cavityData = "";
  7897. //if (snResult != 0)
  7898. //{
  7899. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7900. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7901. // writeToPLC_Flag.Adress = 2077;
  7902. // writeToPLC_Flag.Value = (short)6;
  7903. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7904. // stopwatch1.Stop();
  7905. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7906. // return;
  7907. //}
  7908. #endregion 查询载具上的产品信息
  7909. #region 解绑(边线MES系统)
  7910. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  7911. if (snResult != 0)
  7912. {
  7913. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7914. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  7915. writeToPLC_Flag1.Adress = 2077;
  7916. writeToPLC_Flag1.Value = (short)6;
  7917. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  7918. stopwatch1.Stop();
  7919. AddMessage(LogType.Info,
  7920. stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
  7921. stopwatch1.ElapsedMilliseconds + "ms");
  7922. return;
  7923. }
  7924. #endregion 解绑(边线MES系统)
  7925. #region 存储绑定数据到 边线MES系统中
  7926. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  7927. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  7928. if (snResult != 0)
  7929. {
  7930. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7931. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  7932. writeToPLC_Flag1.Adress = 2077;
  7933. writeToPLC_Flag1.Value = (short)6;
  7934. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  7935. stopwatch1.Stop();
  7936. AddMessage(LogType.Info,
  7937. stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
  7938. stopwatch1.ElapsedMilliseconds + "ms");
  7939. return;
  7940. }
  7941. #endregion 存储绑定数据到 边线MES系统中
  7942. stopwatch2.Stop();
  7943. short b1MES_FLAG_Unbind = 1;
  7944. // MES_Flag
  7945. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7946. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7947. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7948. writeToPLC_Flag.Adress = 2077;
  7949. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  7950. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7951. }
  7952. catch (Exception ex)
  7953. {
  7954. string str = ex.StackTrace;
  7955. AddMessage_Station(stationNameStr, LogType.Error,
  7956. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
  7957. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7958. // MES_Flag
  7959. stopwatch2.Start();
  7960. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7961. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7962. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7963. writeToPLC_Flag.Adress = 2077;
  7964. writeToPLC_Flag.Value = (short)6;
  7965. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7966. stopwatch2.Stop();
  7967. }
  7968. stopwatch1.Stop();
  7969. AddMessage(LogType.Info,
  7970. stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7971. stopwatch2.ElapsedMilliseconds + "ms");
  7972. }
  7973. //// 上次采集到的SN
  7974. //private string sn_FCT = string.Empty;
  7975. /// <summary>
  7976. /// [S2] FCT(板测)- 出站数据
  7977. /// </summary>
  7978. private void S2出站接口(int plcNo, string stationCode, string stationName)
  7979. {
  7980. Stopwatch stopwatch1 = new Stopwatch();
  7981. Stopwatch stopwatch2 = new Stopwatch();
  7982. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7983. string stationNameStr = stationCode + stationName;
  7984. string processItem = stationName; // 测试项目
  7985. try
  7986. {
  7987. stopwatch1.Start();
  7988. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7989. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7990. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7991. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7992. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  7993. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  7994. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  7995. bool pass1 = b1Part1Result == 1;
  7996. bool pass2 = b1Part2Result == 1;
  7997. #region 根据 载具SN 查 物料SN
  7998. string cavityData = string.Empty;
  7999. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  8000. if (string.IsNullOrEmpty(cavityData))
  8001. cavityData = "";
  8002. if (snResult != 0)
  8003. {
  8004. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8005. writeToPLC_Flag1.Name = "b1MES_FLAG";
  8006. writeToPLC_Flag1.Adress = 2169;
  8007. writeToPLC_Flag1.Value = (short)4;
  8008. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  8009. stopwatch1.Stop();
  8010. AddMessage(LogType.Info,
  8011. stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8012. "ms");
  8013. return;
  8014. }
  8015. #endregion 根据 载具SN 查 物料SN
  8016. string[] cavitySNs = cavityData.Split('.');
  8017. string b1ProductSN1 = string.Empty;
  8018. string b1ProductSN2 = string.Empty;
  8019. if (cavitySNs != null && cavitySNs.Length >= 2)
  8020. {
  8021. b1ProductSN1 = cavitySNs[0];
  8022. b1ProductSN2 = cavitySNs[1];
  8023. }
  8024. stopwatch2.Start();
  8025. // 产品1
  8026. int result1 = 0;
  8027. if (b1ProductSN1 == "假产品")
  8028. result1 = 1;
  8029. else
  8030. {
  8031. List<TestItem> items1 = new List<TestItem>();
  8032. items1.Add(new TestItem()
  8033. {
  8034. Parameter_name = "载具码",
  8035. Parameter_value = b1ProductSN.ToString(),
  8036. Parameter_unit = ""
  8037. });
  8038. items1.Add(new TestItem()
  8039. {
  8040. Parameter_name = "载具穴号",
  8041. Parameter_value = "1",
  8042. Parameter_unit = ""
  8043. });
  8044. items1.Add(new TestItem()
  8045. {
  8046. Parameter_name = "产品结果",
  8047. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  8048. Parameter_unit = ""
  8049. });
  8050. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8051. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  8052. }
  8053. // 产品2
  8054. int result2 = 0;
  8055. if (b1ProductSN1 == "假产品")
  8056. result2 = 1;
  8057. else
  8058. {
  8059. List<TestItem> items2 = new List<TestItem>();
  8060. items2.Add(new TestItem()
  8061. {
  8062. Parameter_name = "载具码",
  8063. Parameter_value = b1ProductSN.ToString(),
  8064. Parameter_unit = ""
  8065. });
  8066. items2.Add(new TestItem()
  8067. {
  8068. Parameter_name = "载具穴号",
  8069. Parameter_value = "2",
  8070. Parameter_unit = ""
  8071. });
  8072. items2.Add(new TestItem()
  8073. {
  8074. Parameter_name = "产品结果",
  8075. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  8076. Parameter_unit = ""
  8077. });
  8078. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  8079. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  8080. }
  8081. short result = 0;
  8082. List<int> results = new List<int>() { result1, result2 };
  8083. if (result1 == 1 && result2 == 1)
  8084. result = 1;
  8085. else if (results.Contains(3))
  8086. result = 3;
  8087. else if (results.Contains(2))
  8088. result = 2;
  8089. else if (results.Contains(4))
  8090. result = 4;
  8091. else
  8092. result = 4;
  8093. stopwatch2.Stop();
  8094. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8095. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8096. writeToPLC_Flag.Name = "b1MES_FLAG";
  8097. writeToPLC_Flag.Adress = 2169;
  8098. writeToPLC_Flag.Value = result;
  8099. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8100. OnMessage(LogType.Debug,
  8101. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8102. }
  8103. catch (Exception ex)
  8104. {
  8105. stopwatch2.Restart();
  8106. // MES_Flag 为4上位机报错
  8107. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  8108. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8109. writeToPLC_Flag.Name = "b1MES_FLAG";
  8110. writeToPLC_Flag.Adress = 2169;
  8111. writeToPLC_Flag.Value = (short)4;
  8112. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8113. stopwatch2.Stop();
  8114. string str = ex.StackTrace;
  8115. AddMessage_Station(stationNameStr, LogType.Error,
  8116. $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8117. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8118. }
  8119. stopwatch1.Stop();
  8120. AddMessage(LogType.Info,
  8121. stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8122. stopwatch2.ElapsedMilliseconds + "ms");
  8123. }
  8124. #endregion [S2] FCT(板测)
  8125. #endregion PLC2 李晓奇
  8126. #region PLC3 刘永村
  8127. #region [S3] 值板机
  8128. /// <summary>
  8129. /// S3工位的数据- 触发信号上次的值
  8130. /// </summary>
  8131. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  8132. /// <summary>
  8133. /// S3工位的数据(含触发信号)
  8134. /// </summary>
  8135. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  8136. /// <summary>
  8137. /// S3工位的数据- 回写点位
  8138. /// </summary>
  8139. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8140. /// <summary>
  8141. /// [S3] 值板机
  8142. /// </summary>
  8143. /// <param name="plcNo">PLC编号</param>
  8144. //private void ReadStation_S3(int plcNo)
  8145. //{
  8146. // // [S1] Tray盘上料装备
  8147. // // [S2] FCT
  8148. // // [S3] 值板机
  8149. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8150. // // [S5] Tray盘下料装备
  8151. // /// 上位机心跳
  8152. // /// 获取设备报警数据与状态信息
  8153. // string stationCode = "[S3]";
  8154. // string stationName = "值板机";
  8155. // string stationNameStr = stationCode + stationName;
  8156. // #region 创建字典
  8157. // // 触发信号字典 赋值
  8158. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8159. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8160. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8161. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8162. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8163. // // PLC数据字典 赋值
  8164. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8165. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  8166. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8167. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8168. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  8169. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8170. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8171. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8172. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  8173. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8174. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  8175. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  8176. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8177. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8178. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  8179. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  8180. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  8181. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8182. // s3PLCData.Add("c1Result", 0); // 产品结果
  8183. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8184. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  8185. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  8186. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  8187. // #endregion 创建字典
  8188. // while (IsRun)
  8189. // {
  8190. // try
  8191. // {
  8192. // if (!GlobalContext._IsCon_Funs3)
  8193. // {
  8194. // UpdatePLCMonitor(1, plcNo, 0);
  8195. // continue;
  8196. // }
  8197. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8198. // {
  8199. // Stopwatch stopwatch1 = new Stopwatch();
  8200. // Stopwatch stopwatch2 = new Stopwatch();
  8201. // stopwatch1.Start();
  8202. // stopwatch2.Start();
  8203. // #region 一次性读取所有数据
  8204. // // 一次性读取所有数据
  8205. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  8206. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8207. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  8208. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  8209. // int[] datas = data1.Concat(data2).ToArray();
  8210. // datas = datas.Concat(data3).ToArray();
  8211. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  8212. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  8213. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8214. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  8215. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  8216. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  8217. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8218. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  8219. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  8220. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  8221. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8222. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8223. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  8224. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  8225. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  8226. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  8227. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8228. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  8229. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  8230. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  8231. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  8232. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  8233. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  8234. // #endregion 一次性读取所有数据
  8235. // stopwatch2.Stop();
  8236. // #region 回写操作,写后清空flag
  8237. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  8238. // #endregion 回写操作,写后清空flag
  8239. // #region S3进站校验
  8240. // try
  8241. // {
  8242. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  8243. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  8244. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  8245. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  8246. // {
  8247. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  8248. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8249. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  8250. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8251. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  8252. // }
  8253. // }
  8254. // catch (Exception ex)
  8255. // {
  8256. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8257. // string str = ex.StackTrace;
  8258. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8259. // }
  8260. // #endregion S3进站校验
  8261. // #region S3二穴载具解绑
  8262. // try
  8263. // {
  8264. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  8265. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  8266. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  8267. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  8268. // {
  8269. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8270. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  8271. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  8272. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  8273. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  8274. // }
  8275. // }
  8276. // catch (Exception ex)
  8277. // {
  8278. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  8279. // string str = ex.StackTrace;
  8280. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8281. // }
  8282. // #endregion S3二穴载具解绑
  8283. // #region S3二穴载具绑定
  8284. // try
  8285. // {
  8286. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  8287. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  8288. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  8289. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  8290. // {
  8291. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8292. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  8293. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  8294. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  8295. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  8296. // }
  8297. // }
  8298. // catch (Exception ex)
  8299. // {
  8300. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8301. // string str = ex.StackTrace;
  8302. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8303. // }
  8304. // #endregion S3二穴载具绑定
  8305. // #region S3出站接口(+一穴载具绑定)
  8306. // try
  8307. // {
  8308. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  8309. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  8310. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  8311. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  8312. // {
  8313. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  8314. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8315. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  8316. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  8317. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  8318. // }
  8319. // }
  8320. // catch (Exception ex)
  8321. // {
  8322. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  8323. // string str = ex.StackTrace;
  8324. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8325. // }
  8326. // #endregion S3出站接口(+一穴载具绑定)
  8327. // #region S3节拍接口
  8328. // try
  8329. // {
  8330. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  8331. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  8332. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  8333. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  8334. // {
  8335. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  8336. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8337. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  8338. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  8339. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  8340. // }
  8341. // }
  8342. // catch (Exception ex)
  8343. // {
  8344. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  8345. // string str = ex.StackTrace;
  8346. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8347. // }
  8348. // #endregion S3节拍接口
  8349. // #region 心跳
  8350. // try
  8351. // {
  8352. // short states = 0;
  8353. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8354. // }
  8355. // catch (Exception ex)
  8356. // {
  8357. // string str = ex.StackTrace;
  8358. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8359. // }
  8360. // #endregion 心跳
  8361. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8362. // stopwatch1.Stop();
  8363. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8364. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8365. // }
  8366. // else
  8367. // {
  8368. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8369. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8370. // Funs[plcNo].Connect();
  8371. // }
  8372. // }
  8373. // catch (Exception ex)
  8374. // {
  8375. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8376. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8377. // Funs[plcNo].ReConnect();
  8378. // }
  8379. // Thread.Sleep(IntervalReadPLC);
  8380. // }
  8381. //}
  8382. /// <summary>
  8383. /// [S3] 值板机- 进站校验
  8384. /// </summary>
  8385. /// <param name="plcNo">PLC编号</param>
  8386. /// <param name="stationNameStr">工站全称</param>
  8387. private void S3进站校验(int plcNo, string stationNameStr)
  8388. {
  8389. Stopwatch stopwatch1 = new Stopwatch();
  8390. Stopwatch stopwatch2 = new Stopwatch();
  8391. try
  8392. {
  8393. stopwatch1.Start();
  8394. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  8395. sn = sn.Replace("\0", "");
  8396. #region 查询载具上的产品信息
  8397. string cavityData = string.Empty;
  8398. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8399. if (string.IsNullOrEmpty(cavityData))
  8400. cavityData = "";
  8401. if (snResult != 0)
  8402. {
  8403. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8404. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  8405. writeToPLC_Flag1.Adress = 2003;
  8406. writeToPLC_Flag1.Value = (short)6;
  8407. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  8408. stopwatch1.Stop();
  8409. AddMessage(LogType.Info,
  8410. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8411. return;
  8412. }
  8413. #endregion 查询载具上的产品信息
  8414. string[] cavitySNs = cavityData.Split('.');
  8415. string part1Str = ""; // 产品1的SN码
  8416. string part2Str = ""; // 产品2的SN码
  8417. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8418. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8419. if (cavitySNs != null && cavitySNs.Length >= 2)
  8420. {
  8421. part1Str = cavitySNs[0];
  8422. part2Str = cavitySNs[1];
  8423. c1Part1Result_Check = 2;
  8424. c1Part2Result_Check = 2;
  8425. }
  8426. if (part1Str == "假产品")
  8427. c1Part1Result_Check = 3;
  8428. if (part2Str == "假产品")
  8429. c1Part2Result_Check = 3;
  8430. // 调用MES进站
  8431. stopwatch2.Start();
  8432. // 调用MES进站 - 产品1
  8433. List<TestItem> item;
  8434. int result1 = c1Part1Result_Check;
  8435. if (result1 != 3)
  8436. {
  8437. item = new List<TestItem>();
  8438. item.Add(new TestItem()
  8439. {
  8440. Parameter_name = "载具码",
  8441. Parameter_value = sn,
  8442. });
  8443. item.Add(new TestItem()
  8444. {
  8445. Parameter_name = "载具穴号",
  8446. Parameter_value = "1",
  8447. });
  8448. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8449. part1Str, item, out string errorMsg);
  8450. }
  8451. // 调用MES进站 - 产品2
  8452. int result2 = c1Part2Result_Check;
  8453. if (result2 != 3)
  8454. {
  8455. item = new List<TestItem>();
  8456. item.Add(new TestItem()
  8457. {
  8458. Parameter_name = "载具码",
  8459. Parameter_value = sn,
  8460. });
  8461. item.Add(new TestItem()
  8462. {
  8463. Parameter_name = "载具穴号",
  8464. Parameter_value = "2",
  8465. });
  8466. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8467. part2Str, item, out string errorMsg);
  8468. }
  8469. stopwatch2.Stop();
  8470. if (result1 == 2)
  8471. c1Part1Result_Check = 2;
  8472. if (result2 == 2)
  8473. c1Part2Result_Check = 2;
  8474. int result = result1;
  8475. if (result == 1)
  8476. result = result2;
  8477. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  8478. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  8479. short c1MES_FLAG_Check = (short)result;
  8480. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  8481. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  8482. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  8483. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  8484. //// MES_Flag
  8485. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8486. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8487. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8488. writeToPLC_Flag.Adress = 2003;
  8489. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  8490. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8491. {
  8492. Name = "c1Part1Result_Check",
  8493. Adress = 2024,
  8494. ValueType = PLCValueType.Short,
  8495. Value = c1Part1Result_Check
  8496. });
  8497. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8498. {
  8499. Name = "c1Part2Result_Check",
  8500. Adress = 2025,
  8501. ValueType = PLCValueType.Short,
  8502. Value = c1Part2Result_Check
  8503. });
  8504. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8505. {
  8506. Name = "c1Part1Num_Check",
  8507. Adress = 2026,
  8508. ValueType = PLCValueType.Short,
  8509. Value = c1Part1Num_Check
  8510. });
  8511. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8512. {
  8513. Name = "c1Part2Num_Check",
  8514. Adress = 2027,
  8515. ValueType = PLCValueType.Short,
  8516. Value = c1Part2Num_Check
  8517. });
  8518. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8519. }
  8520. catch (Exception ex)
  8521. {
  8522. string str = ex.StackTrace;
  8523. AddMessage_Station(stationNameStr, LogType.Error,
  8524. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8525. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8526. // MES_Flag
  8527. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8528. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8529. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8530. writeToPLC_Flag.Adress = 2003;
  8531. writeToPLC_Flag.Value = (short)6;
  8532. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8533. }
  8534. stopwatch1.Stop();
  8535. AddMessage(LogType.Info,
  8536. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8537. stopwatch2.ElapsedMilliseconds + "ms");
  8538. }
  8539. /// <summary>
  8540. /// [S3] 值板机 - 二穴载具解绑
  8541. /// </summary>
  8542. /// <param name="plcNo">PLC编号</param>
  8543. /// <param name="stationNameStr">工站全称</param>
  8544. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  8545. {
  8546. Stopwatch stopwatch1 = new Stopwatch();
  8547. Stopwatch stopwatch2 = new Stopwatch();
  8548. try
  8549. {
  8550. stopwatch1.Start();
  8551. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8552. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8553. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8554. // 解绑
  8555. #region 查询载具上的产品信息
  8556. string cavityData = string.Empty;
  8557. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8558. if (string.IsNullOrEmpty(cavityData))
  8559. cavityData = "";
  8560. if (snResult != 0)
  8561. {
  8562. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8563. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  8564. writeToPLC_Flag1.Adress = 2082;
  8565. writeToPLC_Flag1.Value = (short)6;
  8566. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  8567. stopwatch1.Stop();
  8568. AddMessage(LogType.Info,
  8569. stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8570. "ms");
  8571. return;
  8572. }
  8573. #endregion 查询载具上的产品信息
  8574. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8575. #region 解绑
  8576. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  8577. {
  8578. // 删除
  8579. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8580. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  8581. }
  8582. else
  8583. {
  8584. string data_new = string.Join(".", cavitySNs);
  8585. // 删除再插入
  8586. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8587. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8588. OnMessage(LogType.Debug,
  8589. $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  8590. }
  8591. #endregion 解绑
  8592. short c1MES_FLAG_Unbind = 1;
  8593. stopwatch2.Start();
  8594. // MES_Flag
  8595. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8596. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8597. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8598. writeToPLC_Flag.Adress = 2082;
  8599. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  8600. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8601. stopwatch2.Stop();
  8602. }
  8603. catch (Exception ex)
  8604. {
  8605. string str = ex.StackTrace;
  8606. AddMessage_Station(stationNameStr, LogType.Error,
  8607. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
  8608. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8609. // MES_Flag
  8610. stopwatch2.Start();
  8611. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  8612. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8613. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8614. writeToPLC_Flag.Adress = 2082;
  8615. writeToPLC_Flag.Value = (short)6;
  8616. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8617. stopwatch2.Stop();
  8618. }
  8619. stopwatch1.Stop();
  8620. AddMessage(LogType.Info,
  8621. stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8622. stopwatch2.ElapsedMilliseconds + "ms");
  8623. }
  8624. /// <summary>
  8625. /// [S3] 值板机 - 二穴载具绑定
  8626. /// </summary>
  8627. /// <param name="plcNo">PLC编号</param>
  8628. /// <param name="stationNameStr">工站全称</param>
  8629. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  8630. {
  8631. Stopwatch stopwatch1 = new Stopwatch();
  8632. Stopwatch stopwatch2 = new Stopwatch();
  8633. try
  8634. {
  8635. stopwatch1.Start();
  8636. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8637. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8638. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  8639. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8640. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8641. stopwatch2.Start();
  8642. #region 查询载具上的产品信息
  8643. string cavityData = string.Empty;
  8644. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8645. if (string.IsNullOrEmpty(cavityData))
  8646. cavityData = "";
  8647. if (snResult != 0)
  8648. {
  8649. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8650. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  8651. writeToPLC_Flag1.Adress = 2115;
  8652. writeToPLC_Flag1.Value = (short)6;
  8653. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  8654. stopwatch1.Stop();
  8655. AddMessage(LogType.Info,
  8656. stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8657. "ms");
  8658. return;
  8659. }
  8660. #endregion 查询载具上的产品信息
  8661. // 产品换载具
  8662. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8663. string partSn1 = "";
  8664. string partSn2 = "";
  8665. if (cavitySNs != null && cavitySNs.Length >= 2)
  8666. {
  8667. partSn1 = cavitySNs[0];
  8668. partSn2 = cavitySNs[1];
  8669. }
  8670. string data_new = string.Empty;
  8671. // 是否是两个穴位交换
  8672. if (c1CavityReverse_Bind == 1)
  8673. {
  8674. // 交换
  8675. data_new = string.Concat(partSn2, ".", partSn1);
  8676. }
  8677. else
  8678. {
  8679. // 不交换
  8680. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  8681. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  8682. cavitySNs[c1VehicleCavityFr_Bind] = "";
  8683. data_new = string.Join(".", cavitySNs);
  8684. }
  8685. // 删除再插入
  8686. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8687. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8688. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  8689. stopwatch2.Stop();
  8690. short c1MES_FLAG_Bind = 1;
  8691. // MES_Flag
  8692. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8693. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8694. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8695. writeToPLC_Flag.Adress = 2115;
  8696. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  8697. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8698. }
  8699. catch (Exception ex)
  8700. {
  8701. string str = ex.StackTrace;
  8702. AddMessage_Station(stationNameStr, LogType.Error,
  8703. $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8704. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8705. // MES_Flag
  8706. stopwatch2.Start();
  8707. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8708. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8709. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8710. writeToPLC_Flag.Adress = 2115;
  8711. writeToPLC_Flag.Value = (short)6;
  8712. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8713. stopwatch2.Stop();
  8714. }
  8715. stopwatch1.Stop();
  8716. AddMessage(LogType.Info,
  8717. stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8718. stopwatch2.ElapsedMilliseconds + "ms");
  8719. }
  8720. //// 上次采集到的SN
  8721. //private string sn_值板机 = string.Empty;
  8722. /// <summary>
  8723. /// [S3] 值板机 - 出站接口
  8724. /// </summary>
  8725. /// <param name="plcNo">PLC编号</param>
  8726. private void S3出站接口(int plcNo, string stationCode, string stationName)
  8727. {
  8728. Stopwatch stopwatch1 = new Stopwatch();
  8729. Stopwatch stopwatch2 = new Stopwatch();
  8730. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8731. string stationNameStr = stationCode + stationName;
  8732. string processItem = stationName; // 测试项目
  8733. try
  8734. {
  8735. stopwatch1.Start();
  8736. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8737. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8738. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8739. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8740. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  8741. sn = sn.Replace("\0", "");
  8742. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  8743. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8744. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8745. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  8746. bool pass = c1Result == 1;
  8747. // 查sn
  8748. #region 查询载具上的产品信息
  8749. string cavityData = string.Empty;
  8750. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8751. if (string.IsNullOrEmpty(cavityData))
  8752. cavityData = "";
  8753. if (snResult != 0)
  8754. {
  8755. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8756. writeToPLC_Flag1.Name = "c1MES_FLAG";
  8757. writeToPLC_Flag1.Adress = 2150;
  8758. writeToPLC_Flag1.Value = (short)4;
  8759. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  8760. stopwatch1.Stop();
  8761. AddMessage(LogType.Info,
  8762. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8763. return;
  8764. }
  8765. #endregion 查询载具上的产品信息
  8766. string[] cavitySNs = cavityData.Split('.');
  8767. string productSN = "";
  8768. if (cavitySNs != null && cavitySNs.Length >= 2)
  8769. {
  8770. productSN = cavitySNs[c1VehicleCavity];
  8771. cavitySNs[c1VehicleCavity] = "";
  8772. }
  8773. stopwatch2.Start();
  8774. List<TestItem> items = new List<TestItem>();
  8775. items.Add(new TestItem()
  8776. {
  8777. Parameter_name = "二穴载具码",
  8778. Parameter_value = c1ProductSN_Check,
  8779. Parameter_unit = ""
  8780. });
  8781. items.Add(new TestItem()
  8782. {
  8783. Parameter_name = "二穴载具穴号",
  8784. Parameter_value = c1VehicleCavity.ToString(),
  8785. Parameter_unit = ""
  8786. });
  8787. items.Add(new TestItem()
  8788. {
  8789. Parameter_name = "一穴载具码",
  8790. Parameter_value = sn,
  8791. Parameter_unit = ""
  8792. });
  8793. items.Add(new TestItem()
  8794. {
  8795. Parameter_name = "一穴载具穴号",
  8796. Parameter_value = "1",
  8797. Parameter_unit = ""
  8798. });
  8799. items.Add(new TestItem()
  8800. {
  8801. Parameter_name = "产品结果",
  8802. Parameter_value = c1Result == 1 ? "OK" : "NG",
  8803. Parameter_unit = ""
  8804. });
  8805. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  8806. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  8807. short result = (short)result1;
  8808. stopwatch2.Stop();
  8809. #region 存储绑定数据到 边线MES系统中
  8810. if (result == 1)
  8811. {
  8812. string data = string.Concat(productSN);
  8813. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  8814. if (resultMesR != 0)
  8815. {
  8816. result = 4;
  8817. AddMessage_Station(stationNameStr, LogType.Error,
  8818. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  8819. }
  8820. }
  8821. #endregion 存储绑定数据到 边线MES系统中
  8822. #region 产品从 来源载具(二穴载具)中删除
  8823. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  8824. {
  8825. // 删除
  8826. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8827. OnMessage(LogType.Debug,
  8828. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  8829. }
  8830. else
  8831. {
  8832. string data_new = string.Join(".", cavitySNs);
  8833. // 删除再插入
  8834. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8835. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8836. OnMessage(LogType.Debug,
  8837. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  8838. }
  8839. #endregion 产品从 来源载具(二穴载具)中删除
  8840. // MES_Flag 为MES报错
  8841. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8842. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  8843. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8844. writeToPLC_Flag.Name = "c1MES_FLAG";
  8845. writeToPLC_Flag.Adress = 2150;
  8846. writeToPLC_Flag.Value = result;
  8847. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  8848. OnMessage(LogType.Debug,
  8849. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8850. }
  8851. catch (Exception ex)
  8852. {
  8853. stopwatch2.Restart();
  8854. // MES_Flag 为4上位机报错
  8855. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  8856. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8857. writeToPLC_Flag.Name = "c1MES_FLAG";
  8858. writeToPLC_Flag.Adress = 2150;
  8859. writeToPLC_Flag.Value = (short)4;
  8860. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  8861. stopwatch2.Stop();
  8862. string str = ex.StackTrace;
  8863. AddMessage_Station(stationNameStr, LogType.Error,
  8864. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8865. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8866. }
  8867. stopwatch1.Stop();
  8868. AddMessage(LogType.Info,
  8869. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8870. stopwatch2.ElapsedMilliseconds + "ms");
  8871. }
  8872. #endregion [S3] 值板机
  8873. #endregion PLC3 刘永村
  8874. #region PLC4 刘果段
  8875. #region [S4] 取放桁架
  8876. /// <summary>
  8877. /// S4工位的数据- 触发信号上次的值
  8878. /// </summary>
  8879. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  8880. /// <summary>
  8881. /// S4工位的数据(含触发信号)
  8882. /// </summary>
  8883. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  8884. /// <summary>
  8885. /// S4工位的数据- 回写点位
  8886. /// </summary>
  8887. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8888. /// <summary>
  8889. /// [S4] 取放桁架
  8890. /// </summary>
  8891. /// <param name="plcNo">PLC编号</param>
  8892. //private void ReadStation_S4(int plcNo)
  8893. //{
  8894. // // [S1] Tray盘上料装备
  8895. // // [S2] FCT
  8896. // // [S3] 值板机
  8897. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8898. // // [S5] Tray盘下料装备
  8899. // /// 上位机心跳
  8900. // /// 获取设备报警数据与状态信息
  8901. // string stationCode = "[S4_1]";
  8902. // string stationName = "载具下线装备";
  8903. // string stationNameStr = stationCode + stationName;
  8904. // string stationCode2 = "[S4_2]";
  8905. // string stationName2 = "桁架";
  8906. // string stationNameStr2 = stationCode2 + stationName2;
  8907. // string stationCode3 = "[S4_3]";
  8908. // string stationName3 = "提升机1";
  8909. // string stationNameStr3 = stationCode3 + stationName3;
  8910. // string stationCode4 = "[S4_4]";
  8911. // string stationName4 = "提升机2";
  8912. // string stationNameStr4 = stationCode4 + stationName4;
  8913. // string stationCode5 = "[S4_5]";
  8914. // string stationName5 = "载具上线装备";
  8915. // string stationNameStr5 = stationCode5 + stationName5;
  8916. // #region 创建字典
  8917. // // 触发信号字典 赋值
  8918. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  8919. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  8920. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8921. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8922. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  8923. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  8924. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  8925. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  8926. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  8927. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  8928. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8929. // // PLC数据字典 赋值
  8930. // // 载具下线装备(弹夹上线)
  8931. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  8932. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  8933. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  8934. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  8935. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8936. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  8937. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  8938. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  8939. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  8940. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  8941. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  8942. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  8943. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  8944. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  8945. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  8946. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  8947. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  8948. // s4PLCData.Add("d1Result", 0); // 产品结果
  8949. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8950. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  8951. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  8952. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  8953. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  8954. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  8955. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  8956. // // 真空标机(提升机)
  8957. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  8958. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  8959. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  8960. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  8961. // s4PLCData.Add("d3Result", 0); // 产品结果
  8962. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  8963. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  8964. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  8965. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  8966. // s4PLCData.Add("d4Result", 0); // 产品结果
  8967. // // 载具上线装备(弹夹下线)
  8968. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  8969. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  8970. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  8971. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  8972. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  8973. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  8974. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  8975. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  8976. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  8977. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  8978. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  8979. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  8980. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  8981. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  8982. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  8983. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  8984. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  8985. // s4PLCData.Add("d5Result", 0); // 产品结果
  8986. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8987. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  8988. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  8989. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  8990. // #endregion 创建字典
  8991. // while (IsRun)
  8992. // {
  8993. // try
  8994. // {
  8995. // if (!GlobalContext._IsCon_Funs4)
  8996. // {
  8997. // UpdatePLCMonitor(1, plcNo, 0);
  8998. // continue;
  8999. // }
  9000. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9001. // {
  9002. // Stopwatch stopwatch1 = new Stopwatch();
  9003. // Stopwatch stopwatch2 = new Stopwatch();
  9004. // stopwatch1.Start();
  9005. // stopwatch2.Start();
  9006. // #region 一次性读取所有数据
  9007. // // 载具下线装备(弹夹上线)
  9008. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9009. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  9010. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  9011. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  9012. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  9013. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  9014. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  9015. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  9016. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  9017. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  9018. // int[] datas = data1.Concat(data2).ToArray();
  9019. // datas = datas.Concat(data3).ToArray();
  9020. // datas = datas.Concat(data4).ToArray();
  9021. // datas = datas.Concat(data5).ToArray();
  9022. // datas = datas.Concat(data6).ToArray();
  9023. // datas = datas.Concat(data7).ToArray();
  9024. // datas = datas.Concat(data8).ToArray();
  9025. // datas = datas.Concat(data9).ToArray();
  9026. // datas = datas.Concat(data10).ToArray();
  9027. // // 载具下线装备(弹夹上线)
  9028. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  9029. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  9030. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  9031. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  9032. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  9033. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  9034. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  9035. // s4PLCData["d1MES_FLAG"] = datas[65];
  9036. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  9037. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  9038. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  9039. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  9040. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  9041. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  9042. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  9043. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  9044. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  9045. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  9046. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  9047. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  9048. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  9049. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  9050. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  9051. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  9052. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  9053. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  9054. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  9055. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  9056. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  9057. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  9058. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  9059. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  9060. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  9061. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  9062. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  9063. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  9064. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  9065. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  9066. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  9067. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  9068. // s4PLCData["d1Result"] = datas[386];
  9069. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  9070. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  9071. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  9072. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  9073. // s4PLCData["d1OEEType"] = datas[419];
  9074. // // 桁架(查询标机中弹夹的状态)
  9075. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  9076. // s4PLCData["d2BulletclipStates"] = datas[431];
  9077. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  9078. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  9079. // // 真空标机
  9080. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  9081. // s4PLCData["d3MES_FLAG"] = datas[463];
  9082. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  9083. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  9084. // s4PLCData["d3Result"] = datas[484];
  9085. // s4PLCData["d3Type"] = datas[485];
  9086. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  9087. // s4PLCData["d4MES_FLAG"] = datas[496];
  9088. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  9089. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  9090. // s4PLCData["d4Result"] = datas[517];
  9091. // s4PLCData["d4Type"] = datas[518];
  9092. // // 载具上线装备(弹夹下线)
  9093. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  9094. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  9095. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  9096. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  9097. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  9098. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  9099. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  9100. // s4PLCData["d5MES_FLAG"] = datas[591];
  9101. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  9102. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  9103. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  9104. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  9105. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  9106. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  9107. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  9108. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  9109. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  9110. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  9111. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  9112. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  9113. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  9114. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  9115. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  9116. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  9117. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  9118. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  9119. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  9120. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  9121. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  9122. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  9123. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  9124. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  9125. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  9126. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  9127. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  9128. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  9129. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  9130. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  9131. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  9132. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  9133. // s4PLCData["d5Result"] = datas[912];
  9134. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  9135. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  9136. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  9137. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  9138. // s4PLCData["d5OEEType"] = datas[945];
  9139. // #endregion 一次性读取所有数据
  9140. // stopwatch2.Stop();
  9141. // #region 回写操作,写后清空flag
  9142. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  9143. // #endregion 回写操作,写后清空flag
  9144. // // N801A-S4_1 弹夹扫码
  9145. // #region N801A-S4_1 弹夹扫码
  9146. // try
  9147. // {
  9148. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  9149. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  9150. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  9151. // {
  9152. // if (d1BulletclipScanCode == 1) // 0->1
  9153. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9154. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  9155. // }
  9156. // }
  9157. // catch (Exception ex)
  9158. // {
  9159. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9160. // string str = ex.StackTrace;
  9161. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9162. // }
  9163. // #endregion N801A-S4_1 弹夹扫码
  9164. // // N801A-S4_1 载具扫码
  9165. // #region N801A-S4_1 载具扫码
  9166. // try
  9167. // {
  9168. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  9169. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  9170. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  9171. // {
  9172. // if (d1VehicleScanCode == 1) // 0->1
  9173. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9174. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  9175. // }
  9176. // }
  9177. // catch (Exception ex)
  9178. // {
  9179. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9180. // string str = ex.StackTrace;
  9181. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9182. // }
  9183. // #endregion N801A-S4_1 载具扫码
  9184. // // N801A-S4_1 出站接口
  9185. // #region N801A-S4_1 出站接口
  9186. // try
  9187. // {
  9188. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  9189. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  9190. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  9191. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  9192. // {
  9193. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  9194. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9195. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  9196. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  9197. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  9198. // }
  9199. // }
  9200. // catch (Exception ex)
  9201. // {
  9202. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  9203. // string str = ex.StackTrace;
  9204. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9205. // }
  9206. // #endregion N801A-S4_1 出站接口
  9207. // // N801A-S4_1 节拍接口
  9208. // #region N801A-S4_1 节拍接口
  9209. // try
  9210. // {
  9211. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  9212. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  9213. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  9214. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  9215. // {
  9216. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  9217. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9218. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  9219. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  9220. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  9221. // }
  9222. // }
  9223. // catch (Exception ex)
  9224. // {
  9225. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  9226. // string str = ex.StackTrace;
  9227. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9228. // }
  9229. // #endregion N801A-S4_1 节拍接口
  9230. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  9231. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  9232. // try
  9233. // {
  9234. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  9235. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  9236. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  9237. // {
  9238. // if (d2BulletclipScanCode == 1) // 0->1
  9239. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  9240. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  9241. // }
  9242. // }
  9243. // catch (Exception ex)
  9244. // {
  9245. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  9246. // string str = ex.StackTrace;
  9247. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9248. // }
  9249. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  9250. // // N801A-S4_3 真空标机1 数据
  9251. // #region N801A-S4_3 真空标机1
  9252. // try
  9253. // {
  9254. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  9255. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  9256. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  9257. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  9258. // {
  9259. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  9260. // {
  9261. // int stationType = (int)s4PLCData["d3Type"];
  9262. // if (stationType == 1)
  9263. // {
  9264. // // S4_3进站接口
  9265. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  9266. // }
  9267. // else if (stationType == 2)
  9268. // {
  9269. // // S4_3出站接口
  9270. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  9271. // }
  9272. // }
  9273. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  9274. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  9275. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  9276. // }
  9277. // }
  9278. // catch (Exception ex)
  9279. // {
  9280. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  9281. // string str = ex.StackTrace;
  9282. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9283. // }
  9284. // #endregion N801A-S4_3 真空标机1
  9285. // // N801A-S4_4 真空标机2 数据
  9286. // #region N801A-S4_4 真空标机2
  9287. // try
  9288. // {
  9289. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  9290. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  9291. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  9292. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  9293. // {
  9294. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  9295. // {
  9296. // int stationType = (int)s4PLCData["d4Type"];
  9297. // if (stationType == 1)
  9298. // {
  9299. // // S4_4进站接口
  9300. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  9301. // }
  9302. // else if (stationType == 2)
  9303. // {
  9304. // // S4_4出站接口
  9305. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  9306. // }
  9307. // }
  9308. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  9309. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  9310. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  9311. // }
  9312. // }
  9313. // catch (Exception ex)
  9314. // {
  9315. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  9316. // string str = ex.StackTrace;
  9317. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9318. // }
  9319. // #endregion N801A-S4_4 真空标机2
  9320. // // N801A-S4_5 弹夹扫码 数据
  9321. // #region N801A-S4_5 弹夹扫码
  9322. // try
  9323. // {
  9324. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  9325. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  9326. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  9327. // {
  9328. // if (d5BulletclipScanCode == 1) // 0->1
  9329. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9330. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  9331. // }
  9332. // }
  9333. // catch (Exception ex)
  9334. // {
  9335. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  9336. // string str = ex.StackTrace;
  9337. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9338. // }
  9339. // #endregion N801A-S4_5 弹夹扫码
  9340. // // N801A-S4_5 载具扫码 数据
  9341. // #region N801A-S4_5 载具扫码
  9342. // try
  9343. // {
  9344. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  9345. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  9346. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  9347. // {
  9348. // if (d5VehicleScanCode == 1) // 0->1
  9349. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9350. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  9351. // }
  9352. // }
  9353. // catch (Exception ex)
  9354. // {
  9355. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  9356. // string str = ex.StackTrace;
  9357. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9358. // }
  9359. // #endregion N801A-S4_5 载具扫码
  9360. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  9361. // #region N801A-S4_5 出站接口
  9362. // try
  9363. // {
  9364. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  9365. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  9366. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  9367. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  9368. // {
  9369. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  9370. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  9371. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  9372. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  9373. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  9374. // }
  9375. // }
  9376. // catch (Exception ex)
  9377. // {
  9378. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  9379. // string str = ex.StackTrace;
  9380. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9381. // }
  9382. // #endregion N801A-S4_5 出站接口
  9383. // // N801A-S4_5 节拍接口 数据
  9384. // #region N801A-S4_5 节拍接口
  9385. // try
  9386. // {
  9387. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  9388. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  9389. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  9390. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  9391. // {
  9392. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  9393. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  9394. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  9395. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  9396. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  9397. // }
  9398. // }
  9399. // catch (Exception ex)
  9400. // {
  9401. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  9402. // string str = ex.StackTrace;
  9403. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9404. // }
  9405. // #endregion N801A-S4_5 节拍接口
  9406. // #region 心跳
  9407. // try
  9408. // {
  9409. // short states = 0;
  9410. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9411. // }
  9412. // catch (Exception ex)
  9413. // {
  9414. // string str = ex.StackTrace;
  9415. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9416. // }
  9417. // #endregion 心跳
  9418. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9419. // stopwatch1.Stop();
  9420. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9421. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9422. // }
  9423. // else
  9424. // {
  9425. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9426. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  9427. // Funs[plcNo].Connect();
  9428. // }
  9429. // }
  9430. // catch (Exception ex)
  9431. // {
  9432. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9433. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  9434. // Funs[plcNo].ReConnect();
  9435. // }
  9436. // Thread.Sleep(IntervalReadPLC);
  9437. // }
  9438. //}
  9439. /// <summary>
  9440. /// [S4] 取放桁架 - S4_1弹夹扫码
  9441. /// </summary>
  9442. /// <param name="plcNo">PLC编号</param>
  9443. /// <param name="stationNameStr">工站全称</param>
  9444. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  9445. {
  9446. Stopwatch stopwatch1 = new Stopwatch();
  9447. Stopwatch stopwatch2 = new Stopwatch();
  9448. try
  9449. {
  9450. stopwatch1.Start();
  9451. // ZS 弹夹扫码
  9452. string d1BulletclipCode = " "; // 扫到的码
  9453. short d1BulletclipScanCode = 2;
  9454. stopwatch2.Start();
  9455. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  9456. //// MES_Flag
  9457. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9458. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9459. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9460. writeToPLC_Flag.Adress = 2002;
  9461. writeToPLC_Flag.Value = d1BulletclipScanCode;
  9462. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9463. {
  9464. Name = "d1BulletclipCode",
  9465. Adress = 2003,
  9466. ValueType = PLCValueType.String,
  9467. ValueTypeStrLength = 20,
  9468. Value = d1BulletclipCode
  9469. });
  9470. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9471. stopwatch2.Stop();
  9472. }
  9473. catch (Exception ex)
  9474. {
  9475. string str = ex.StackTrace;
  9476. AddMessage_Station(stationNameStr, LogType.Error,
  9477. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9478. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9479. stopwatch2.Start();
  9480. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  9481. //// MES_Flag
  9482. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9483. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9484. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9485. writeToPLC_Flag.Adress = 2002;
  9486. writeToPLC_Flag.Value = (short)6;
  9487. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9488. {
  9489. Name = "d1BulletclipCode",
  9490. Adress = 2003,
  9491. ValueType = PLCValueType.String,
  9492. ValueTypeStrLength = 20,
  9493. Value = " "
  9494. });
  9495. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9496. stopwatch2.Stop();
  9497. }
  9498. stopwatch1.Stop();
  9499. AddMessage(LogType.Info,
  9500. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9501. stopwatch2.ElapsedMilliseconds + "ms");
  9502. }
  9503. /// <summary>
  9504. /// [S4] 取放桁架 - S4_1载具扫码
  9505. /// </summary>
  9506. /// <param name="plcNo">PLC编号</param>
  9507. /// <param name="stationNameStr">工站全称</param>
  9508. private void S4_1载具扫码(int plcNo, string stationNameStr)
  9509. {
  9510. Stopwatch stopwatch1 = new Stopwatch();
  9511. Stopwatch stopwatch2 = new Stopwatch();
  9512. try
  9513. {
  9514. stopwatch1.Start();
  9515. // ZS 载具扫码
  9516. string d1VehicleCode = ""; // 扫到的码
  9517. short d1VehicleScanCode = 2;
  9518. #region 进站
  9519. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  9520. {
  9521. #region 查询载具上的产品信息
  9522. string cavityData = string.Empty;
  9523. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  9524. if (string.IsNullOrEmpty(cavityData))
  9525. cavityData = "";
  9526. if (snResult != 0)
  9527. {
  9528. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9529. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  9530. writeToPLC_Flag1.Adress = 2033;
  9531. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  9532. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9533. {
  9534. Name = "d1VehicleCode",
  9535. Adress = 2034,
  9536. ValueType = PLCValueType.String,
  9537. ValueTypeStrLength = 20,
  9538. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9539. });
  9540. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  9541. stopwatch1.Stop();
  9542. AddMessage(LogType.Info,
  9543. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9544. "ms");
  9545. return;
  9546. }
  9547. string[] cavitySNs = cavityData.Split('.');
  9548. string partNo = "";
  9549. if (cavitySNs != null && cavitySNs.Length >= 1)
  9550. {
  9551. partNo = cavitySNs[0];
  9552. }
  9553. #endregion 查询载具上的产品信息
  9554. List<TestItem> item = new List<TestItem>();
  9555. item.Add(new TestItem()
  9556. {
  9557. Parameter_name = "载具码",
  9558. Parameter_value = d1VehicleCode,
  9559. });
  9560. item.Add(new TestItem()
  9561. {
  9562. Parameter_name = "载具穴号",
  9563. Parameter_value = "1",
  9564. });
  9565. stopwatch2.Start();
  9566. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9567. partNo, item, out string errorMsg);
  9568. stopwatch2.Stop();
  9569. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  9570. }
  9571. #endregion 进站
  9572. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  9573. //// MES_Flag
  9574. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9575. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9576. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9577. writeToPLC_Flag.Adress = 2033;
  9578. writeToPLC_Flag.Value = d1VehicleScanCode;
  9579. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9580. {
  9581. Name = "d1VehicleCode",
  9582. Adress = 2034,
  9583. ValueType = PLCValueType.String,
  9584. ValueTypeStrLength = 20,
  9585. Value = d1VehicleCode
  9586. });
  9587. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9588. }
  9589. catch (Exception ex)
  9590. {
  9591. string str = ex.StackTrace;
  9592. AddMessage_Station(stationNameStr, LogType.Error,
  9593. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9594. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9595. stopwatch2.Start();
  9596. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  9597. //// MES_Flag
  9598. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9599. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9600. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9601. writeToPLC_Flag.Adress = 2033;
  9602. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  9603. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9604. {
  9605. Name = "d1VehicleCode",
  9606. Adress = 2034,
  9607. ValueType = PLCValueType.String,
  9608. ValueTypeStrLength = 20,
  9609. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9610. });
  9611. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9612. stopwatch2.Stop();
  9613. }
  9614. stopwatch1.Stop();
  9615. AddMessage(LogType.Info,
  9616. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9617. stopwatch2.ElapsedMilliseconds + "ms");
  9618. }
  9619. // 上次采集到的SN
  9620. //private string sn_S4_1出站接口 = string.Empty;
  9621. /// <summary>
  9622. /// [S4] 取放桁架 - S4_1出站接口
  9623. /// </summary>
  9624. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  9625. {
  9626. Stopwatch stopwatch1 = new Stopwatch();
  9627. Stopwatch stopwatch2 = new Stopwatch();
  9628. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9629. string stationNameStr = stationCode + stationName;
  9630. string processItem = stationName; // 测试项目
  9631. try
  9632. {
  9633. stopwatch1.Start();
  9634. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9635. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9636. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9637. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9638. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  9639. sn = sn.Replace("\0", "");
  9640. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  9641. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  9642. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  9643. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  9644. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  9645. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  9646. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  9647. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  9648. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  9649. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  9650. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  9651. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  9652. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  9653. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  9654. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  9655. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  9656. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  9657. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  9658. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  9659. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  9660. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  9661. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  9662. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  9663. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  9664. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  9665. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  9666. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  9667. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  9668. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  9669. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  9670. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  9671. bool pass = d1Result == 1;
  9672. // 存 载具SN列表
  9673. List<string> vehicleCodes = new List<string>()
  9674. {
  9675. d1VehicleCode1, d1VehicleCode2, d1VehicleCode3, d1VehicleCode4, d1VehicleCode5,
  9676. d1VehicleCode6, d1VehicleCode7, d1VehicleCode8, d1VehicleCode9, d1VehicleCode10,
  9677. d1VehicleCode11, d1VehicleCode12, d1VehicleCode13, d1VehicleCode14, d1VehicleCode15
  9678. };
  9679. // 统一查 产品SN列表
  9680. List<string> partNos = new List<string>();
  9681. foreach (string vehicleCode in vehicleCodes)
  9682. {
  9683. if (string.IsNullOrEmpty(vehicleCode))
  9684. partNos.Add("");
  9685. else
  9686. {
  9687. string partNo = "";
  9688. #region 查询载具上的产品信息
  9689. string cavityData = string.Empty;
  9690. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  9691. if (string.IsNullOrEmpty(cavityData))
  9692. cavityData = "";
  9693. if (snResult != 0)
  9694. {
  9695. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9696. writeToPLC_Flag1.Name = "d1MES_FLAG";
  9697. writeToPLC_Flag1.Adress = 2065;
  9698. writeToPLC_Flag1.Value = (short)4;
  9699. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  9700. stopwatch1.Stop();
  9701. AddMessage(LogType.Info,
  9702. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9703. "ms");
  9704. return;
  9705. }
  9706. string[] cavitySNs = cavityData.Split('.');
  9707. if (cavitySNs != null && cavitySNs.Length >= 1)
  9708. partNo = cavitySNs[0];
  9709. #endregion 查询载具上的产品信息
  9710. partNos.Add(partNo);
  9711. }
  9712. }
  9713. // 统一上传
  9714. stopwatch2.Start();
  9715. List<int> results = new List<int>();
  9716. for (int i = 0; i < partNos.Count; i++)
  9717. {
  9718. string index = (i + 1).ToString(); // 弹夹穴号
  9719. if (string.IsNullOrEmpty(partNos[i]))
  9720. results.Add(1);
  9721. else
  9722. {
  9723. List<TestItem> items1 = new List<TestItem>();
  9724. items1.Add(new TestItem()
  9725. {
  9726. Parameter_name = "弹夹码",
  9727. Parameter_value = sn,
  9728. Parameter_unit = ""
  9729. });
  9730. items1.Add(new TestItem()
  9731. {
  9732. Parameter_name = "弹夹穴号",
  9733. Parameter_value = index,
  9734. Parameter_unit = ""
  9735. });
  9736. items1.Add(new TestItem()
  9737. {
  9738. Parameter_name = "载具码",
  9739. Parameter_value = vehicleCodes[i],
  9740. Parameter_unit = ""
  9741. });
  9742. items1.Add(new TestItem()
  9743. {
  9744. Parameter_name = "载具穴号",
  9745. Parameter_value = "1",
  9746. Parameter_unit = ""
  9747. });
  9748. items1.Add(new TestItem()
  9749. {
  9750. Parameter_name = "产品结果",
  9751. Parameter_value = d1Result == 1 ? "OK" : "NG",
  9752. Parameter_unit = ""
  9753. });
  9754. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  9755. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  9756. results.Add(result1);
  9757. }
  9758. }
  9759. short result = 0;
  9760. if (results.All(a => a == 1))
  9761. result = 1;
  9762. else if (results.Contains(3))
  9763. result = 3;
  9764. else if (results.Contains(2))
  9765. result = 2;
  9766. else if (results.Contains(4))
  9767. result = 4;
  9768. else
  9769. result = 4;
  9770. stopwatch2.Stop();
  9771. #region 存储绑定数据到 边线MES系统中
  9772. if (result == 1)
  9773. {
  9774. string data = string.Join(".", vehicleCodes);
  9775. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  9776. if (resultMesR != 0)
  9777. {
  9778. result = 4;
  9779. AddMessage_Station(stationNameStr, LogType.Error,
  9780. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9781. }
  9782. }
  9783. #endregion 存储绑定数据到 边线MES系统中
  9784. // MES_Flag 为4MES报错
  9785. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9786. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9787. writeToPLC_Flag.Name = "d1MES_FLAG";
  9788. writeToPLC_Flag.Adress = 2065;
  9789. writeToPLC_Flag.Value = result;
  9790. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  9791. OnMessage(LogType.Debug,
  9792. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9793. }
  9794. catch (Exception ex)
  9795. {
  9796. stopwatch2.Restart();
  9797. // MES_Flag 为4上位机报错
  9798. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  9799. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9800. writeToPLC_Flag.Name = "d1MES_FLAG";
  9801. writeToPLC_Flag.Adress = 2065;
  9802. writeToPLC_Flag.Value = (short)4;
  9803. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  9804. stopwatch2.Stop();
  9805. string str = ex.StackTrace;
  9806. AddMessage_Station(stationNameStr, LogType.Error,
  9807. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9808. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9809. }
  9810. stopwatch1.Stop();
  9811. AddMessage(LogType.Info,
  9812. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  9813. stopwatch2.ElapsedMilliseconds + "ms");
  9814. }
  9815. /// <summary>
  9816. /// [S4] 取放桁架 - S4_1节拍接口
  9817. /// </summary>
  9818. /// <param name="plcNo">PLC编号</param>
  9819. /// <param name="stationNameStr">工站全称</param>
  9820. private void S4_1节拍接口(int plcNo, string stationNameStr)
  9821. {
  9822. Stopwatch stopwatch1 = new Stopwatch();
  9823. Stopwatch stopwatch2 = new Stopwatch();
  9824. string resultStr = string.Empty;
  9825. try
  9826. {
  9827. stopwatch1.Start();
  9828. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  9829. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  9830. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  9831. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9832. if (!actionBool)
  9833. {
  9834. stopwatch2.Start();
  9835. // MES_Flag
  9836. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9837. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9838. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  9839. writeToPLC_Flag1.Adress = 2398;
  9840. writeToPLC_Flag1.Value = (short)4;
  9841. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  9842. stopwatch2.Stop();
  9843. AddMessage(LogType.Info,
  9844. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  9845. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9846. return;
  9847. }
  9848. string d1OEEPartNo = string.Empty; // 物料码
  9849. if (string.IsNullOrEmpty(d1OEEProductSN))
  9850. {
  9851. stopwatch2.Start();
  9852. // MES_Flag
  9853. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9854. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9855. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  9856. writeToPLC_Flag1.Adress = 2398;
  9857. writeToPLC_Flag1.Value = (short)1;
  9858. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  9859. stopwatch2.Stop();
  9860. AddMessage(LogType.Info,
  9861. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9862. stopwatch2.ElapsedMilliseconds + "ms");
  9863. return;
  9864. }
  9865. else
  9866. {
  9867. // 查产品SN ZS
  9868. d1OEEPartNo = "Test";
  9869. }
  9870. short d1OEEMES_FLAG = 0;
  9871. // 上传OEE
  9872. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  9873. d1OEEMES_FLAG = result.Item1;
  9874. resultStr = result.Item2;
  9875. stopwatch2.Start();
  9876. // MES_Flag
  9877. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9878. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9879. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  9880. writeToPLC_Flag.Adress = 2398;
  9881. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  9882. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  9883. stopwatch2.Stop();
  9884. }
  9885. catch (Exception ex)
  9886. {
  9887. string str = ex.StackTrace;
  9888. AddMessage_Station(stationNameStr, LogType.Error,
  9889. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  9890. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9891. // MES_Flag
  9892. stopwatch2.Start();
  9893. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  9894. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9895. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  9896. writeToPLC_Flag.Adress = 2398;
  9897. writeToPLC_Flag.Value = (short)4;
  9898. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  9899. stopwatch2.Stop();
  9900. }
  9901. stopwatch1.Stop();
  9902. AddMessage(LogType.Info,
  9903. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9904. stopwatch2.ElapsedMilliseconds + "ms");
  9905. }
  9906. /// <summary>
  9907. /// [S4] 取放桁架 - S4_2桁架
  9908. /// </summary>
  9909. /// <param name="plcNo">PLC编号</param>
  9910. /// <param name="stationNameStr">工站全称</param>
  9911. private void S4_2桁架(int plcNo, string stationNameStr)
  9912. {
  9913. Stopwatch stopwatch1 = new Stopwatch();
  9914. Stopwatch stopwatch2 = new Stopwatch();
  9915. try
  9916. {
  9917. stopwatch1.Start();
  9918. // ZS 弹夹扫码
  9919. string d2BulletclipCode = " "; // 扫到的码
  9920. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  9921. short d2BulletclipScanCode = 2;
  9922. stopwatch2.Start();
  9923. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  9924. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  9925. //// MES_Flag
  9926. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9927. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9928. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  9929. writeToPLC_Flag.Adress = 2430;
  9930. writeToPLC_Flag.Value = d2BulletclipScanCode;
  9931. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9932. {
  9933. Name = "d2BulletclipCode",
  9934. Adress = 2432,
  9935. ValueType = PLCValueType.String,
  9936. ValueTypeStrLength = 20,
  9937. Value = d2BulletclipCode
  9938. });
  9939. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9940. {
  9941. Name = "d2BulletclipStates",
  9942. Adress = 2431,
  9943. ValueType = PLCValueType.Short,
  9944. Value = d2BulletclipStates
  9945. });
  9946. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  9947. stopwatch2.Stop();
  9948. }
  9949. catch (Exception ex)
  9950. {
  9951. string str = ex.StackTrace;
  9952. AddMessage_Station(stationNameStr, LogType.Error,
  9953. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9954. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9955. stopwatch2.Start();
  9956. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  9957. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  9958. // MES_Flag
  9959. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  9960. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9961. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  9962. writeToPLC_Flag.Adress = 2430;
  9963. writeToPLC_Flag.Value = (short)6;
  9964. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9965. {
  9966. Name = "d2BulletclipCode",
  9967. Adress = 2432,
  9968. ValueType = PLCValueType.String,
  9969. ValueTypeStrLength = 20,
  9970. Value = " "
  9971. });
  9972. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9973. {
  9974. Name = "d2BulletclipStates",
  9975. Adress = 2431,
  9976. ValueType = PLCValueType.Short,
  9977. Value = (short)0
  9978. });
  9979. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  9980. stopwatch2.Stop();
  9981. }
  9982. stopwatch1.Stop();
  9983. AddMessage(LogType.Info,
  9984. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9985. stopwatch2.ElapsedMilliseconds + "ms");
  9986. }
  9987. // 上次采集到的SN
  9988. //private string sn_S4_3进站接口 = string.Empty;
  9989. /// <summary>
  9990. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  9991. /// </summary>
  9992. private void S4_3进站接口(int plcNo, string stationNameStr)
  9993. {
  9994. Stopwatch stopwatch1 = new Stopwatch();
  9995. Stopwatch stopwatch2 = new Stopwatch();
  9996. try
  9997. {
  9998. stopwatch1.Start();
  9999. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10000. sn = sn.Replace("\0", "");
  10001. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10002. #region 查询15个载具码
  10003. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10004. string vehicleData = string.Empty;
  10005. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10006. if (string.IsNullOrEmpty(vehicleData))
  10007. vehicleData = "";
  10008. if (snResult != 0)
  10009. {
  10010. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10011. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10012. writeToPLC_Flag1.Adress = 2463;
  10013. writeToPLC_Flag1.Value = (short)4;
  10014. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10015. stopwatch1.Stop();
  10016. AddMessage(LogType.Info,
  10017. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10018. return;
  10019. }
  10020. string[] cavitySNs = vehicleData.Split('.');
  10021. if (cavitySNs != null && cavitySNs.Length > 0)
  10022. {
  10023. for (int i = 0; i < cavitySNs.Length; i++)
  10024. {
  10025. if (string.IsNullOrEmpty(cavitySNs[i]))
  10026. vehicleCodes.Add("");
  10027. else
  10028. vehicleCodes.Add(cavitySNs[i]);
  10029. }
  10030. }
  10031. #endregion 查询15个载具码
  10032. #region 查询15个产品SN
  10033. List<string> portNos = new List<string>(); // 15个产品SN
  10034. foreach (string vehicleCode in vehicleCodes)
  10035. {
  10036. if (string.IsNullOrEmpty(vehicleCode))
  10037. portNos.Add("");
  10038. else
  10039. {
  10040. // 查询
  10041. string cavityData = string.Empty;
  10042. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10043. if (string.IsNullOrEmpty(cavityData))
  10044. cavityData = "";
  10045. if (snResult1 != 0)
  10046. {
  10047. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10048. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10049. writeToPLC_Flag1.Adress = 2463;
  10050. writeToPLC_Flag1.Value = (short)4;
  10051. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10052. stopwatch1.Stop();
  10053. AddMessage(LogType.Info,
  10054. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10055. stopwatch1.ElapsedMilliseconds + "ms");
  10056. return;
  10057. }
  10058. string[] partSNs = cavityData.Split('.');
  10059. if (partSNs != null && partSNs.Length >= 1)
  10060. portNos.Add(partSNs[0]);
  10061. else
  10062. portNos.Add("");
  10063. }
  10064. }
  10065. #endregion 查询15个产品SN
  10066. // 调用MES进站(最多15个)
  10067. stopwatch2.Start();
  10068. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10069. for (int i = 0; i < vehicleCodes.Count; i++)
  10070. {
  10071. // 循环进站
  10072. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10073. {
  10074. // 产品SN(物料码)校验
  10075. string portNo = portNos[i];
  10076. List<TestItem> item = new List<TestItem>();
  10077. item.Add(new TestItem()
  10078. {
  10079. Parameter_name = "弹夹码",
  10080. Parameter_value = sn,
  10081. });
  10082. item.Add(new TestItem()
  10083. {
  10084. Parameter_name = "弹夹穴位",
  10085. Parameter_value = (i + 1).ToString(),
  10086. });
  10087. item.Add(new TestItem()
  10088. {
  10089. Parameter_name = "载具码",
  10090. Parameter_value = vehicleCodes[i],
  10091. });
  10092. item.Add(new TestItem()
  10093. {
  10094. Parameter_name = "载具穴号",
  10095. Parameter_value = "1",
  10096. });
  10097. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10098. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10099. }
  10100. }
  10101. stopwatch2.Stop();
  10102. short result = 0;
  10103. bool haveMesWarn = results.Contains(5);
  10104. bool havePCWarn = results.Contains(6);
  10105. if (haveMesWarn)
  10106. result = 2; // 5->2
  10107. else if (havePCWarn)
  10108. result = 6; // 6->4
  10109. else
  10110. result = 1;
  10111. // MES_Flag 为4MES报错
  10112. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10113. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10114. writeToPLC_Flag.Name = "d3MES_FLAG";
  10115. writeToPLC_Flag.Adress = 2463;
  10116. writeToPLC_Flag.Value = result;
  10117. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10118. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10119. }
  10120. catch (Exception ex)
  10121. {
  10122. stopwatch2.Stop();
  10123. // MES_Flag 为4上位机报错
  10124. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10125. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10126. writeToPLC_Flag.Name = "d3MES_FLAG";
  10127. writeToPLC_Flag.Adress = 2463;
  10128. writeToPLC_Flag.Value = (short)4;
  10129. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10130. string str = ex.StackTrace;
  10131. AddMessage_Station(stationNameStr, LogType.Error,
  10132. $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10133. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10134. }
  10135. stopwatch1.Stop();
  10136. AddMessage(LogType.Info,
  10137. stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10138. stopwatch2.ElapsedMilliseconds + "ms");
  10139. }
  10140. // 上次采集到的SN
  10141. //private string sn_S4_3出站接口 = string.Empty;
  10142. /// <summary>
  10143. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  10144. /// </summary>
  10145. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  10146. {
  10147. Stopwatch stopwatch1 = new Stopwatch();
  10148. Stopwatch stopwatch2 = new Stopwatch();
  10149. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10150. string stationNameStr = stationCode + stationName;
  10151. string processItem = stationName; // 测试项目
  10152. try
  10153. {
  10154. stopwatch1.Start();
  10155. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10156. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10157. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10158. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10159. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10160. sn = sn.Replace("\0", "");
  10161. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10162. bool isPass = d3Result == 1; // 产品结果 bool
  10163. #region 查询15个载具码
  10164. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10165. string vehicleData = string.Empty;
  10166. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10167. if (string.IsNullOrEmpty(vehicleData))
  10168. vehicleData = "";
  10169. if (snResult1 != 0)
  10170. {
  10171. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10172. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10173. writeToPLC_Flag1.Adress = 2463;
  10174. writeToPLC_Flag1.Value = (short)4;
  10175. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10176. stopwatch1.Stop();
  10177. AddMessage(LogType.Info,
  10178. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10179. return;
  10180. }
  10181. string[] cavitySNs = vehicleData.Split('.');
  10182. if (cavitySNs != null && cavitySNs.Length > 0)
  10183. {
  10184. for (int i = 0; i < cavitySNs.Length; i++)
  10185. {
  10186. if (string.IsNullOrEmpty(cavitySNs[i]))
  10187. vehicleCodes.Add("");
  10188. else
  10189. vehicleCodes.Add(cavitySNs[i]);
  10190. }
  10191. }
  10192. #endregion 查询15个载具码
  10193. // 统一查 产品SN列表
  10194. List<string> partNos = new List<string>();
  10195. foreach (string vehicleCode in vehicleCodes)
  10196. {
  10197. if (string.IsNullOrEmpty(vehicleCode))
  10198. partNos.Add("");
  10199. else
  10200. {
  10201. string partNo = "";
  10202. #region 查询载具上的产品信息
  10203. string cavityData = string.Empty;
  10204. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10205. if (string.IsNullOrEmpty(cavityData))
  10206. cavityData = "";
  10207. if (snResult != 0)
  10208. {
  10209. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10210. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10211. writeToPLC_Flag1.Adress = 2463;
  10212. writeToPLC_Flag1.Value = (short)4;
  10213. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10214. stopwatch1.Stop();
  10215. AddMessage(LogType.Info,
  10216. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10217. "ms");
  10218. return;
  10219. }
  10220. string[] partSNs = cavityData.Split('.');
  10221. if (partSNs != null && partSNs.Length >= 1)
  10222. partNo = partSNs[0];
  10223. #endregion 查询载具上的产品信息
  10224. partNos.Add(partNo);
  10225. }
  10226. }
  10227. // 统一上传 - 调用MES出站
  10228. stopwatch2.Start();
  10229. List<int> results = new List<int>();
  10230. for (int i = 0; i < partNos.Count; i++)
  10231. {
  10232. string index = (i + 1).ToString(); // 弹夹穴号
  10233. if (string.IsNullOrEmpty(partNos[i]))
  10234. results.Add(1);
  10235. else
  10236. {
  10237. List<TestItem> items1 = new List<TestItem>();
  10238. items1.Add(new TestItem()
  10239. {
  10240. Parameter_name = "弹夹码",
  10241. Parameter_value = sn,
  10242. Parameter_unit = ""
  10243. });
  10244. items1.Add(new TestItem()
  10245. {
  10246. Parameter_name = "弹夹穴号",
  10247. Parameter_value = index,
  10248. Parameter_unit = ""
  10249. });
  10250. items1.Add(new TestItem()
  10251. {
  10252. Parameter_name = "载具码",
  10253. Parameter_value = vehicleCodes[i],
  10254. Parameter_unit = ""
  10255. });
  10256. items1.Add(new TestItem()
  10257. {
  10258. Parameter_name = "载具穴号",
  10259. Parameter_value = "1",
  10260. Parameter_unit = ""
  10261. });
  10262. items1.Add(new TestItem()
  10263. {
  10264. Parameter_name = "产品结果",
  10265. Parameter_value = d3Result == 1 ? "OK" : "NG",
  10266. Parameter_unit = ""
  10267. });
  10268. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10269. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10270. results.Add(result1);
  10271. }
  10272. }
  10273. short result = 0;
  10274. if (results.All(a => a == 1))
  10275. result = 1;
  10276. else if (results.Contains(3))
  10277. result = 3;
  10278. else if (results.Contains(2))
  10279. result = 2;
  10280. else if (results.Contains(4))
  10281. result = 4;
  10282. else
  10283. result = 4;
  10284. stopwatch2.Stop();
  10285. // MES_Flag 为4MES报错
  10286. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10287. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10288. writeToPLC_Flag.Name = "d3MES_FLAG";
  10289. writeToPLC_Flag.Adress = 2463;
  10290. writeToPLC_Flag.Value = result;
  10291. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10292. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10293. }
  10294. catch (Exception ex)
  10295. {
  10296. stopwatch2.Restart();
  10297. // MES_Flag 为4上位机报错
  10298. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10299. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10300. writeToPLC_Flag.Name = "d3MES_FLAG";
  10301. writeToPLC_Flag.Adress = 2463;
  10302. writeToPLC_Flag.Value = (short)4;
  10303. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10304. string str = ex.StackTrace;
  10305. AddMessage_Station(stationNameStr, LogType.Error,
  10306. $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10307. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10308. stopwatch2.Stop();
  10309. }
  10310. stopwatch1.Stop();
  10311. AddMessage(LogType.Info,
  10312. stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10313. stopwatch2.ElapsedMilliseconds + "ms");
  10314. }
  10315. // 上次采集到的SN
  10316. //private string sn_S4_4进站接口 = string.Empty;
  10317. /// <summary>
  10318. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  10319. /// </summary>
  10320. private void S4_4进站接口(int plcNo, string stationNameStr)
  10321. {
  10322. Stopwatch stopwatch1 = new Stopwatch();
  10323. Stopwatch stopwatch2 = new Stopwatch();
  10324. try
  10325. {
  10326. stopwatch1.Start();
  10327. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10328. sn = sn.Replace("\0", "");
  10329. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10330. #region 查询15个载具码
  10331. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10332. string vehicleData = string.Empty;
  10333. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10334. if (string.IsNullOrEmpty(vehicleData))
  10335. vehicleData = "";
  10336. if (snResult != 0)
  10337. {
  10338. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10339. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10340. writeToPLC_Flag1.Adress = 2463;
  10341. writeToPLC_Flag1.Value = (short)4;
  10342. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10343. stopwatch1.Stop();
  10344. AddMessage(LogType.Info,
  10345. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10346. return;
  10347. }
  10348. string[] cavitySNs = vehicleData.Split('.');
  10349. if (cavitySNs != null && cavitySNs.Length > 0)
  10350. {
  10351. for (int i = 0; i < cavitySNs.Length; i++)
  10352. {
  10353. if (string.IsNullOrEmpty(cavitySNs[i]))
  10354. vehicleCodes.Add("");
  10355. else
  10356. vehicleCodes.Add(cavitySNs[i]);
  10357. }
  10358. }
  10359. #endregion 查询15个载具码
  10360. #region 查询15个产品SN
  10361. List<string> portNos = new List<string>(); // 15个产品SN
  10362. foreach (string vehicleCode in vehicleCodes)
  10363. {
  10364. if (string.IsNullOrEmpty(vehicleCode))
  10365. portNos.Add("");
  10366. else
  10367. {
  10368. // 查询
  10369. string cavityData = string.Empty;
  10370. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10371. if (string.IsNullOrEmpty(cavityData))
  10372. cavityData = "";
  10373. if (snResult1 != 0)
  10374. {
  10375. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10376. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10377. writeToPLC_Flag1.Adress = 2463;
  10378. writeToPLC_Flag1.Value = (short)4;
  10379. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10380. stopwatch1.Stop();
  10381. AddMessage(LogType.Info,
  10382. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10383. stopwatch1.ElapsedMilliseconds + "ms");
  10384. return;
  10385. }
  10386. string[] partSNs = cavityData.Split('.');
  10387. if (partSNs != null && partSNs.Length >= 1)
  10388. portNos.Add(partSNs[0]);
  10389. else
  10390. portNos.Add("");
  10391. }
  10392. }
  10393. #endregion 查询15个产品SN
  10394. // 调用MES进站(最多15个)
  10395. stopwatch2.Start();
  10396. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10397. for (int i = 0; i < vehicleCodes.Count; i++)
  10398. {
  10399. // 循环进站
  10400. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10401. {
  10402. // 产品SN(物料码)校验
  10403. string portNo = portNos[i];
  10404. List<TestItem> item = new List<TestItem>();
  10405. item.Add(new TestItem()
  10406. {
  10407. Parameter_name = "弹夹码",
  10408. Parameter_value = sn,
  10409. });
  10410. item.Add(new TestItem()
  10411. {
  10412. Parameter_name = "弹夹穴位",
  10413. Parameter_value = (i + 1).ToString(),
  10414. });
  10415. item.Add(new TestItem()
  10416. {
  10417. Parameter_name = "载具码",
  10418. Parameter_value = vehicleCodes[i],
  10419. });
  10420. item.Add(new TestItem()
  10421. {
  10422. Parameter_name = "载具穴号",
  10423. Parameter_value = "1",
  10424. });
  10425. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10426. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10427. }
  10428. }
  10429. stopwatch2.Stop();
  10430. short result = 0;
  10431. bool haveMesWarn = results.Contains(5);
  10432. bool havePCWarn = results.Contains(6);
  10433. if (haveMesWarn)
  10434. result = 2; // 5->2
  10435. else if (havePCWarn)
  10436. result = 6; // 6->4
  10437. else
  10438. result = 1;
  10439. // MES_Flag 为4MES报错
  10440. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10441. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10442. writeToPLC_Flag.Name = "d4MES_FLAG";
  10443. writeToPLC_Flag.Adress = 2496;
  10444. writeToPLC_Flag.Value = result;
  10445. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10446. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10447. }
  10448. catch (Exception ex)
  10449. {
  10450. stopwatch2.Stop();
  10451. // MES_Flag 为4上位机报错
  10452. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10453. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10454. writeToPLC_Flag.Name = "d4MES_FLAG";
  10455. writeToPLC_Flag.Adress = 2496;
  10456. writeToPLC_Flag.Value = (short)4;
  10457. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10458. string str = ex.StackTrace;
  10459. AddMessage_Station(stationNameStr, LogType.Error,
  10460. $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10461. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10462. }
  10463. stopwatch1.Stop();
  10464. AddMessage(LogType.Info,
  10465. stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10466. stopwatch2.ElapsedMilliseconds + "ms");
  10467. }
  10468. // 上次采集到的SN
  10469. //private string sn_S4_4出站接口 = string.Empty;
  10470. /// <summary>
  10471. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  10472. /// </summary>
  10473. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  10474. {
  10475. Stopwatch stopwatch1 = new Stopwatch();
  10476. Stopwatch stopwatch2 = new Stopwatch();
  10477. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10478. string stationNameStr = stationCode + stationName;
  10479. string processItem = stationName; // 测试项目
  10480. try
  10481. {
  10482. stopwatch1.Start();
  10483. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10484. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10485. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10486. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10487. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10488. sn = sn.Replace("\0", "");
  10489. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10490. bool isPass = d4Result == 1; // 产品结果 bool
  10491. #region 查询15个载具码
  10492. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10493. string vehicleData = string.Empty;
  10494. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10495. if (string.IsNullOrEmpty(vehicleData))
  10496. vehicleData = "";
  10497. if (snResult1 != 0)
  10498. {
  10499. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10500. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10501. writeToPLC_Flag1.Adress = 2496;
  10502. writeToPLC_Flag1.Value = (short)4;
  10503. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10504. stopwatch1.Stop();
  10505. AddMessage(LogType.Info,
  10506. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10507. return;
  10508. }
  10509. string[] cavitySNs = vehicleData.Split('.');
  10510. if (cavitySNs != null && cavitySNs.Length > 0)
  10511. {
  10512. for (int i = 0; i < cavitySNs.Length; i++)
  10513. {
  10514. if (string.IsNullOrEmpty(cavitySNs[i]))
  10515. vehicleCodes.Add("");
  10516. else
  10517. vehicleCodes.Add(cavitySNs[i]);
  10518. }
  10519. }
  10520. #endregion 查询15个载具码
  10521. // 统一查 产品SN列表
  10522. List<string> partNos = new List<string>();
  10523. foreach (string vehicleCode in vehicleCodes)
  10524. {
  10525. if (string.IsNullOrEmpty(vehicleCode))
  10526. partNos.Add("");
  10527. else
  10528. {
  10529. string partNo = "";
  10530. #region 查询载具上的产品信息
  10531. string cavityData = string.Empty;
  10532. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10533. if (string.IsNullOrEmpty(cavityData))
  10534. cavityData = "";
  10535. if (snResult != 0)
  10536. {
  10537. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10538. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10539. writeToPLC_Flag1.Adress = 2496;
  10540. writeToPLC_Flag1.Value = (short)4;
  10541. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10542. stopwatch1.Stop();
  10543. AddMessage(LogType.Info,
  10544. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10545. "ms");
  10546. return;
  10547. }
  10548. string[] partSNs = cavityData.Split('.');
  10549. if (partSNs != null && partSNs.Length >= 1)
  10550. partNo = partSNs[0];
  10551. #endregion 查询载具上的产品信息
  10552. partNos.Add(partNo);
  10553. }
  10554. }
  10555. // 调用MES出站
  10556. stopwatch2.Start();
  10557. // 统一上传
  10558. List<int> results = new List<int>();
  10559. for (int i = 0; i < partNos.Count; i++)
  10560. {
  10561. string index = (i + 1).ToString(); // 弹夹穴号
  10562. if (string.IsNullOrEmpty(partNos[i]))
  10563. results.Add(1);
  10564. else
  10565. {
  10566. List<TestItem> items1 = new List<TestItem>();
  10567. items1.Add(new TestItem()
  10568. {
  10569. Parameter_name = "弹夹码",
  10570. Parameter_value = sn,
  10571. Parameter_unit = ""
  10572. });
  10573. items1.Add(new TestItem()
  10574. {
  10575. Parameter_name = "弹夹穴号",
  10576. Parameter_value = index,
  10577. Parameter_unit = ""
  10578. });
  10579. items1.Add(new TestItem()
  10580. {
  10581. Parameter_name = "载具码",
  10582. Parameter_value = vehicleCodes[i],
  10583. Parameter_unit = ""
  10584. });
  10585. items1.Add(new TestItem()
  10586. {
  10587. Parameter_name = "载具穴号",
  10588. Parameter_value = "1",
  10589. Parameter_unit = ""
  10590. });
  10591. items1.Add(new TestItem()
  10592. {
  10593. Parameter_name = "产品结果",
  10594. Parameter_value = d4Result == 1 ? "OK" : "NG",
  10595. Parameter_unit = ""
  10596. });
  10597. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10598. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10599. results.Add(result1);
  10600. }
  10601. }
  10602. short result = 0;
  10603. if (results.All(a => a == 1))
  10604. result = 1;
  10605. else if (results.Contains(3))
  10606. result = 3;
  10607. else if (results.Contains(2))
  10608. result = 2;
  10609. else if (results.Contains(4))
  10610. result = 4;
  10611. else
  10612. result = 4;
  10613. stopwatch2.Stop();
  10614. // MES_Flag 为4MES报错
  10615. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10616. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10617. writeToPLC_Flag.Name = "d4MES_FLAG";
  10618. writeToPLC_Flag.Adress = 2496;
  10619. writeToPLC_Flag.Value = result;
  10620. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10621. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10622. }
  10623. catch (Exception ex)
  10624. {
  10625. stopwatch2.Restart();
  10626. // MES_Flag 为4上位机报错
  10627. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10628. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10629. writeToPLC_Flag.Name = "d4MES_FLAG";
  10630. writeToPLC_Flag.Adress = 2496;
  10631. writeToPLC_Flag.Value = (short)4;
  10632. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10633. string str = ex.StackTrace;
  10634. AddMessage_Station(stationNameStr, LogType.Error,
  10635. $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10636. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10637. stopwatch2.Stop();
  10638. }
  10639. stopwatch1.Stop();
  10640. AddMessage(LogType.Info,
  10641. stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10642. stopwatch2.ElapsedMilliseconds + "ms");
  10643. }
  10644. /// <summary>
  10645. /// [S4] 取放桁架 - S4_5弹夹扫码
  10646. /// </summary>
  10647. /// <param name="plcNo">PLC编号</param>
  10648. /// <param name="stationNameStr">工站全称</param>
  10649. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  10650. {
  10651. Stopwatch stopwatch1 = new Stopwatch();
  10652. Stopwatch stopwatch2 = new Stopwatch();
  10653. try
  10654. {
  10655. stopwatch1.Start();
  10656. // ZS 弹夹扫码
  10657. string d5BulletclipCode = " "; // 扫到的码
  10658. short d5BulletclipScanCode = 2;
  10659. stopwatch2.Start();
  10660. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  10661. //// MES_Flag
  10662. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10663. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10664. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10665. writeToPLC_Flag.Adress = 2528;
  10666. writeToPLC_Flag.Value = d5BulletclipScanCode;
  10667. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10668. {
  10669. Name = "d5BulletclipCode",
  10670. Adress = 2529,
  10671. ValueType = PLCValueType.String,
  10672. ValueTypeStrLength = 20,
  10673. Value = d5BulletclipCode
  10674. });
  10675. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10676. stopwatch2.Stop();
  10677. }
  10678. catch (Exception ex)
  10679. {
  10680. string str = ex.StackTrace;
  10681. AddMessage_Station(stationNameStr, LogType.Error,
  10682. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10683. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10684. stopwatch2.Start();
  10685. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  10686. //// MES_Flag
  10687. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  10688. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10689. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10690. writeToPLC_Flag.Adress = 2528;
  10691. writeToPLC_Flag.Value = (short)6;
  10692. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10693. {
  10694. Name = "d5BulletclipCode",
  10695. Adress = 2529,
  10696. ValueType = PLCValueType.String,
  10697. ValueTypeStrLength = 20,
  10698. Value = " "
  10699. });
  10700. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10701. stopwatch2.Stop();
  10702. }
  10703. stopwatch1.Stop();
  10704. AddMessage(LogType.Info,
  10705. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10706. stopwatch2.ElapsedMilliseconds + "ms");
  10707. }
  10708. /// <summary>
  10709. /// [S4] 取放桁架 - S4_5载具扫码
  10710. /// </summary>
  10711. /// <param name="plcNo">PLC编号</param>
  10712. /// <param name="stationNameStr">工站全称</param>
  10713. private void S4_5载具扫码(int plcNo, string stationNameStr)
  10714. {
  10715. Stopwatch stopwatch1 = new Stopwatch();
  10716. Stopwatch stopwatch2 = new Stopwatch();
  10717. try
  10718. {
  10719. stopwatch1.Start();
  10720. // ZS 载具扫码
  10721. string d5VehicleCode = " "; // 扫到的码
  10722. short d5VehicleScanCode = 2;
  10723. #region 进站
  10724. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  10725. {
  10726. // 查产品SN
  10727. #region 查询载具上的产品信息
  10728. string cavityData = string.Empty;
  10729. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  10730. if (string.IsNullOrEmpty(cavityData))
  10731. cavityData = "";
  10732. if (snResult != 0)
  10733. {
  10734. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10735. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  10736. writeToPLC_Flag1.Adress = 2559;
  10737. writeToPLC_Flag1.Value = (short)6;
  10738. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10739. {
  10740. Name = "d5VehicleCode",
  10741. Adress = 2560,
  10742. ValueType = PLCValueType.String,
  10743. ValueTypeStrLength = 20,
  10744. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10745. });
  10746. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  10747. stopwatch1.Stop();
  10748. AddMessage(LogType.Info,
  10749. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10750. "ms");
  10751. return;
  10752. }
  10753. string[] cavitySNs = cavityData.Split('.');
  10754. string partNo = "";
  10755. if (cavitySNs != null && cavitySNs.Length >= 1)
  10756. {
  10757. partNo = cavitySNs[0];
  10758. }
  10759. #endregion 查询载具上的产品信息
  10760. List<TestItem> item = new List<TestItem>();
  10761. item.Add(new TestItem()
  10762. {
  10763. Parameter_name = "载具码",
  10764. Parameter_value = d5VehicleCode,
  10765. });
  10766. item.Add(new TestItem()
  10767. {
  10768. Parameter_name = "载具穴号",
  10769. Parameter_value = "1",
  10770. });
  10771. stopwatch2.Start();
  10772. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  10773. partNo, item, out string errorMsg);
  10774. stopwatch2.Stop();
  10775. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  10776. }
  10777. #endregion 进站
  10778. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  10779. //// MES_Flag
  10780. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10781. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10782. writeToPLC_Flag.Name = "d5VehicleScanCode";
  10783. writeToPLC_Flag.Adress = 2559;
  10784. writeToPLC_Flag.Value = d5VehicleScanCode;
  10785. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10786. {
  10787. Name = "d5VehicleCode",
  10788. Adress = 2560,
  10789. ValueType = PLCValueType.String,
  10790. ValueTypeStrLength = 20,
  10791. Value = d5VehicleCode
  10792. });
  10793. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  10794. }
  10795. catch (Exception ex)
  10796. {
  10797. string str = ex.StackTrace;
  10798. AddMessage_Station(stationNameStr, LogType.Error,
  10799. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10800. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10801. stopwatch2.Start();
  10802. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  10803. //// MES_Flag
  10804. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  10805. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10806. writeToPLC_Flag.Name = "d5VehicleScanCode";
  10807. writeToPLC_Flag.Adress = 2559;
  10808. writeToPLC_Flag.Value = (short)6;
  10809. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10810. {
  10811. Name = "d5VehicleCode",
  10812. Adress = 2560,
  10813. ValueType = PLCValueType.String,
  10814. ValueTypeStrLength = 20,
  10815. Value = " "
  10816. });
  10817. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  10818. stopwatch2.Stop();
  10819. }
  10820. stopwatch1.Stop();
  10821. AddMessage(LogType.Info,
  10822. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10823. stopwatch2.ElapsedMilliseconds + "ms");
  10824. }
  10825. // 上次采集到的SN
  10826. //private string sn_S4_5出站接口 = string.Empty;
  10827. /// <summary>
  10828. /// [S4] 取放桁架 - S4_5出站接口
  10829. /// </summary>
  10830. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  10831. {
  10832. Stopwatch stopwatch1 = new Stopwatch();
  10833. Stopwatch stopwatch2 = new Stopwatch();
  10834. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10835. string stationNameStr = stationCode + stationName;
  10836. string processItem = stationName; // 测试项目
  10837. try
  10838. {
  10839. stopwatch1.Start();
  10840. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10841. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10842. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10843. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10844. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  10845. sn = sn.Replace("\0", "");
  10846. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  10847. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  10848. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  10849. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  10850. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  10851. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  10852. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  10853. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  10854. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  10855. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  10856. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  10857. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  10858. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  10859. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  10860. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  10861. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  10862. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  10863. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  10864. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  10865. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  10866. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  10867. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  10868. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  10869. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  10870. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  10871. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  10872. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  10873. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  10874. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  10875. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  10876. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  10877. bool pass = d5Result == 1;
  10878. // 存 载具SN列表
  10879. List<string> vehicleCodes = new List<string>()
  10880. {
  10881. d5VehicleCode1, d5VehicleCode2, d5VehicleCode3, d5VehicleCode4, d5VehicleCode5,
  10882. d5VehicleCode6, d5VehicleCode7, d5VehicleCode8, d5VehicleCode9, d5VehicleCode10,
  10883. d5VehicleCode11, d5VehicleCode12, d5VehicleCode13, d5VehicleCode14, d5VehicleCode15
  10884. };
  10885. // 统一查 产品SN列表
  10886. List<string> partNos = new List<string>();
  10887. foreach (string vehicleCode in vehicleCodes)
  10888. {
  10889. if (string.IsNullOrEmpty(vehicleCode))
  10890. partNos.Add("");
  10891. else
  10892. {
  10893. string partNo = "";
  10894. #region 查询载具上的产品信息
  10895. string cavityData = string.Empty;
  10896. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10897. if (string.IsNullOrEmpty(cavityData))
  10898. cavityData = "";
  10899. if (snResult != 0)
  10900. {
  10901. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10902. writeToPLC_Flag1.Name = "d5MES_FLAG";
  10903. writeToPLC_Flag1.Adress = 2591;
  10904. writeToPLC_Flag1.Value = (short)4;
  10905. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  10906. stopwatch1.Stop();
  10907. AddMessage(LogType.Info,
  10908. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10909. "ms");
  10910. return;
  10911. }
  10912. string[] cavitySNs = cavityData.Split('.');
  10913. if (cavitySNs != null && cavitySNs.Length >= 1)
  10914. partNo = cavitySNs[0];
  10915. #endregion 查询载具上的产品信息
  10916. partNos.Add(partNo);
  10917. }
  10918. }
  10919. // 统一上传
  10920. stopwatch2.Start();
  10921. List<int> results = new List<int>();
  10922. for (int i = 0; i < partNos.Count; i++)
  10923. {
  10924. string index = (i + 1).ToString(); // 弹夹穴号
  10925. if (string.IsNullOrEmpty(partNos[i]))
  10926. results.Add(1);
  10927. else
  10928. {
  10929. List<TestItem> items1 = new List<TestItem>();
  10930. items1.Add(new TestItem()
  10931. {
  10932. Parameter_name = "弹夹码",
  10933. Parameter_value = sn,
  10934. Parameter_unit = ""
  10935. });
  10936. items1.Add(new TestItem()
  10937. {
  10938. Parameter_name = "弹夹穴号",
  10939. Parameter_value = index,
  10940. Parameter_unit = ""
  10941. });
  10942. items1.Add(new TestItem()
  10943. {
  10944. Parameter_name = "载具码",
  10945. Parameter_value = vehicleCodes[i],
  10946. Parameter_unit = ""
  10947. });
  10948. items1.Add(new TestItem()
  10949. {
  10950. Parameter_name = "载具穴号",
  10951. Parameter_value = "1",
  10952. Parameter_unit = ""
  10953. });
  10954. items1.Add(new TestItem()
  10955. {
  10956. Parameter_name = "产品结果",
  10957. Parameter_value = d5Result == 1 ? "OK" : "NG",
  10958. Parameter_unit = ""
  10959. });
  10960. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10961. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  10962. results.Add(result1);
  10963. }
  10964. }
  10965. short result = 0;
  10966. if (results.All(a => a == 1))
  10967. result = 1;
  10968. else if (results.Contains(3))
  10969. result = 3;
  10970. else if (results.Contains(2))
  10971. result = 2;
  10972. else if (results.Contains(4))
  10973. result = 4;
  10974. else
  10975. result = 4;
  10976. stopwatch2.Stop();
  10977. #region 存储绑定数据到 边线MES系统中
  10978. if (result == 1)
  10979. {
  10980. // 删除绑定信息
  10981. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  10982. if (resultMesR != 0)
  10983. {
  10984. result = 4;
  10985. AddMessage_Station(stationNameStr, LogType.Error,
  10986. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  10987. }
  10988. }
  10989. #endregion 存储绑定数据到 边线MES系统中
  10990. // MES_Flag 为4MES报错
  10991. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10992. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10993. writeToPLC_Flag.Name = "d5MES_FLAG";
  10994. writeToPLC_Flag.Adress = 2591;
  10995. writeToPLC_Flag.Value = result;
  10996. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  10997. OnMessage(LogType.Debug,
  10998. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  10999. }
  11000. catch (Exception ex)
  11001. {
  11002. stopwatch2.Restart();
  11003. // MES_Flag 为4上位机报错
  11004. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  11005. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11006. writeToPLC_Flag.Name = "d5MES_FLAG";
  11007. writeToPLC_Flag.Adress = 2591;
  11008. writeToPLC_Flag.Value = (short)4;
  11009. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11010. stopwatch2.Stop();
  11011. string str = ex.StackTrace;
  11012. AddMessage_Station(stationNameStr, LogType.Error,
  11013. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11014. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11015. }
  11016. stopwatch1.Stop();
  11017. AddMessage(LogType.Info,
  11018. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11019. stopwatch2.ElapsedMilliseconds + "ms");
  11020. }
  11021. /// <summary>
  11022. /// [S4] 取放桁架 - S4_5节拍接口
  11023. /// </summary>
  11024. /// <param name="plcNo">PLC编号</param>
  11025. /// <param name="stationNameStr">工站全称</param>
  11026. private void S4_5节拍接口(int plcNo, string stationNameStr)
  11027. {
  11028. Stopwatch stopwatch1 = new Stopwatch();
  11029. Stopwatch stopwatch2 = new Stopwatch();
  11030. string resultStr = string.Empty;
  11031. try
  11032. {
  11033. stopwatch1.Start();
  11034. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  11035. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  11036. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  11037. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11038. if (!actionBool)
  11039. {
  11040. stopwatch2.Start();
  11041. // MES_Flag
  11042. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  11043. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11044. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11045. writeToPLC_Flag1.Adress = 2924;
  11046. writeToPLC_Flag1.Value = (short)4;
  11047. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11048. stopwatch2.Stop();
  11049. AddMessage(LogType.Info,
  11050. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11051. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11052. return;
  11053. }
  11054. string d5OEEPartNo = string.Empty; // 物料码
  11055. if (string.IsNullOrEmpty(d5OEEProductSN))
  11056. {
  11057. stopwatch2.Start();
  11058. // MES_Flag
  11059. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11060. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11061. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11062. writeToPLC_Flag1.Adress = 2924;
  11063. writeToPLC_Flag1.Value = (short)1;
  11064. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11065. stopwatch2.Stop();
  11066. AddMessage(LogType.Info,
  11067. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11068. stopwatch2.ElapsedMilliseconds + "ms");
  11069. return;
  11070. }
  11071. else
  11072. {
  11073. // 查产品SN
  11074. d5OEEPartNo = "Test"; // ZS
  11075. }
  11076. short d5OEEMES_FLAG = 0;
  11077. // 上传OEE
  11078. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  11079. d5OEEMES_FLAG = result.Item1;
  11080. resultStr = result.Item2;
  11081. stopwatch2.Start();
  11082. // MES_Flag
  11083. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11084. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11085. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11086. writeToPLC_Flag.Adress = 2924;
  11087. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  11088. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11089. stopwatch2.Stop();
  11090. }
  11091. catch (Exception ex)
  11092. {
  11093. string str = ex.StackTrace;
  11094. AddMessage_Station(stationNameStr, LogType.Error,
  11095. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11096. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11097. // MES_Flag
  11098. stopwatch2.Start();
  11099. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  11100. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11101. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11102. writeToPLC_Flag.Adress = 2924;
  11103. writeToPLC_Flag.Value = (short)4;
  11104. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11105. stopwatch2.Stop();
  11106. }
  11107. stopwatch1.Stop();
  11108. AddMessage(LogType.Info,
  11109. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11110. stopwatch2.ElapsedMilliseconds + "ms");
  11111. }
  11112. #endregion [S4] 取放桁架
  11113. #endregion PLC4 刘果段
  11114. #region PLC5 张超凡
  11115. #region [S5] Tray盘下料装备
  11116. /// <summary>
  11117. /// S5工位的数据- 触发信号上次的值
  11118. /// </summary>
  11119. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  11120. /// <summary>
  11121. /// S5工位的数据(含触发信号)
  11122. /// </summary>
  11123. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  11124. /// <summary>
  11125. /// S5工位的数据- 回写点位
  11126. /// </summary>
  11127. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  11128. /// <summary>
  11129. /// [S5] Tray盘下料装备
  11130. /// </summary>
  11131. /// <param name="plcNo">PLC编号</param>
  11132. //private void ReadStation_S5(int plcNo)
  11133. //{
  11134. // // [S1] Tray盘上料装备
  11135. // // [S2] FCT
  11136. // // [S3] 值板机
  11137. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  11138. // // [S5] Tray盘下料装备
  11139. // /// 上位机心跳
  11140. // /// 获取设备报警数据与状态信息
  11141. // string stationCode = "[S5]";
  11142. // string stationName = "Tray盘下料装备";
  11143. // string stationNameStr = stationCode + stationName;
  11144. // #region 创建字典
  11145. // // 触发信号字典 赋值
  11146. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11147. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11148. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11149. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11150. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  11151. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11152. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  11153. // // PLC数据字典 赋值
  11154. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11155. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  11156. // s5PLCData.Add("e1ProductSN_Check", ""); //
  11157. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11158. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  11159. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  11160. // s5PLCData.Add("e1PartNo", ""); // 物料码
  11161. // s5PLCData.Add("e1Result", 0); // 产品结果
  11162. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11163. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  11164. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  11165. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  11166. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11167. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  11168. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  11169. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11170. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  11171. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  11172. // #endregion 创建字典
  11173. // while (IsRun)
  11174. // {
  11175. // try
  11176. // {
  11177. // if (!GlobalContext._IsCon_Funs5)
  11178. // {
  11179. // UpdatePLCMonitor(1, plcNo, 0);
  11180. // continue;
  11181. // }
  11182. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  11183. // {
  11184. // Stopwatch stopwatch1 = new Stopwatch();
  11185. // Stopwatch stopwatch2 = new Stopwatch();
  11186. // stopwatch1.Start();
  11187. // stopwatch2.Start();
  11188. // #region 一次性读取所有数据
  11189. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  11190. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  11191. // int[] datas = data1.Concat(data2).ToArray();
  11192. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  11193. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  11194. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  11195. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  11196. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  11197. // s5PLCData["e1MES_FLAG"] = datas[35];
  11198. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  11199. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  11200. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  11201. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  11202. // s5PLCData["e1Result"] = datas[76];
  11203. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  11204. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  11205. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  11206. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  11207. // s5PLCData["e1OEEType"] = datas[109];
  11208. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  11209. // s5PLCData["e1AGVUpStart"] = datas[121];
  11210. // s5PLCData["e1AGVUpEnd"] = datas[122];
  11211. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  11212. // s5PLCData["e1AGVDownStart"] = datas[134];
  11213. // s5PLCData["e1AGVDownEnd"] = datas[135];
  11214. // #endregion 一次性读取所有数据
  11215. // stopwatch2.Stop();
  11216. // #region 回写操作,写后清空flag
  11217. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  11218. // #endregion 回写操作,写后清空flag
  11219. // #region 进站校验
  11220. // try
  11221. // {
  11222. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  11223. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  11224. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  11225. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  11226. // {
  11227. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  11228. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  11229. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  11230. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  11231. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  11232. // }
  11233. // }
  11234. // catch (Exception ex)
  11235. // {
  11236. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11237. // string str = ex.StackTrace;
  11238. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11239. // }
  11240. // #endregion 进站校验
  11241. // #region 出站接口
  11242. // try
  11243. // {
  11244. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  11245. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  11246. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  11247. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  11248. // {
  11249. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  11250. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  11251. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  11252. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  11253. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  11254. // }
  11255. // }
  11256. // catch (Exception ex)
  11257. // {
  11258. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  11259. // string str = ex.StackTrace;
  11260. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11261. // }
  11262. // #endregion 出站接口
  11263. // #region 节拍接口
  11264. // try
  11265. // {
  11266. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  11267. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  11268. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  11269. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  11270. // {
  11271. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  11272. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  11273. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  11274. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  11275. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  11276. // }
  11277. // }
  11278. // catch (Exception ex)
  11279. // {
  11280. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11281. // string str = ex.StackTrace;
  11282. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11283. // }
  11284. // #endregion 节拍接口
  11285. // #region AGV上料
  11286. // // AGV上料叫AGV信号
  11287. // try
  11288. // {
  11289. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  11290. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  11291. // if (e1AGVUpCall != e1AGVUpCallOld)
  11292. // {
  11293. // if (e1AGVUpCall == 1) // 0->1
  11294. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  11295. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  11296. // }
  11297. // }
  11298. // catch (Exception ex)
  11299. // {
  11300. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11301. // string str = ex.StackTrace;
  11302. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11303. // }
  11304. // // AGV上料完成信号
  11305. // try
  11306. // {
  11307. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  11308. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  11309. // if (e1AGVUpEnd != e1AGVUpEndOld)
  11310. // {
  11311. // if (e1AGVUpEnd == 1) // 0->1
  11312. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  11313. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  11314. // }
  11315. // }
  11316. // catch (Exception ex)
  11317. // {
  11318. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  11319. // string str = ex.StackTrace;
  11320. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11321. // }
  11322. // #endregion AGV上料
  11323. // #region AGV下料
  11324. // // AGV下料叫agv信号
  11325. // try
  11326. // {
  11327. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  11328. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  11329. // if (e1AGVDownCall != e1AGVDownCallOld)
  11330. // {
  11331. // if (e1AGVDownCall == 1) // 0->1
  11332. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  11333. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  11334. // }
  11335. // }
  11336. // catch (Exception ex)
  11337. // {
  11338. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  11339. // string str = ex.StackTrace;
  11340. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11341. // }
  11342. // // AGV下料完成信号
  11343. // try
  11344. // {
  11345. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  11346. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  11347. // if (e1AGVDownEnd != e1AGVDownEndOld)
  11348. // {
  11349. // if (e1AGVDownEnd == 1) // 0->1
  11350. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  11351. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  11352. // }
  11353. // }
  11354. // catch (Exception ex)
  11355. // {
  11356. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  11357. // string str = ex.StackTrace;
  11358. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11359. // }
  11360. // #endregion AGV下料
  11361. // #region 心跳
  11362. // try
  11363. // {
  11364. // short states = 0;
  11365. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  11366. // }
  11367. // catch (Exception ex)
  11368. // {
  11369. // string str = ex.StackTrace;
  11370. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11371. // }
  11372. // #endregion 心跳
  11373. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  11374. // stopwatch1.Stop();
  11375. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  11376. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  11377. // }
  11378. // else
  11379. // {
  11380. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11381. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  11382. // Funs[plcNo].Connect();
  11383. // }
  11384. // }
  11385. // catch (Exception ex)
  11386. // {
  11387. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11388. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  11389. // Funs[plcNo].ReConnect();
  11390. // }
  11391. // Thread.Sleep(IntervalReadPLC);
  11392. // }
  11393. //}
  11394. /// <summary>
  11395. /// [S5] Tray盘下料装备 - 进站校验
  11396. /// </summary>
  11397. /// <param name="plcNo">PLC编号</param>
  11398. /// <param name="stationNameStr">工站全称</param>
  11399. private void S5进站校验(int plcNo, string stationNameStr)
  11400. {
  11401. Stopwatch stopwatch1 = new Stopwatch();
  11402. Stopwatch stopwatch2 = new Stopwatch();
  11403. try
  11404. {
  11405. stopwatch1.Start();
  11406. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  11407. sn = sn.Replace("\0", "");
  11408. // 获取产品SN By 载具码
  11409. #region 查询载具上的产品信息
  11410. string cavityData = string.Empty;
  11411. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11412. if (string.IsNullOrEmpty(cavityData))
  11413. cavityData = "";
  11414. if (snResult != 0)
  11415. {
  11416. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11417. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  11418. writeToPLC_Flag1.Adress = 2003;
  11419. writeToPLC_Flag1.Value = (short)6;
  11420. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  11421. stopwatch1.Stop();
  11422. AddMessage(LogType.Info,
  11423. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11424. return;
  11425. }
  11426. string[] cavitySNs = cavityData.Split('.');
  11427. string partNo = string.Empty;
  11428. if (cavitySNs != null && cavitySNs.Length >= 1)
  11429. partNo = cavitySNs[0];
  11430. #endregion 查询载具上的产品信息
  11431. // 产品SN(物料码)校验
  11432. List<TestItem> item = new List<TestItem>();
  11433. item.Add(new TestItem()
  11434. {
  11435. Parameter_name = "载具码",
  11436. Parameter_value = sn,
  11437. });
  11438. item.Add(new TestItem()
  11439. {
  11440. Parameter_name = "载具穴号",
  11441. Parameter_value = "1",
  11442. });
  11443. stopwatch2.Start();
  11444. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11445. partNo, item, out string errorMsg);
  11446. stopwatch2.Stop();
  11447. short e1MES_FLAG_Check = (short)result;
  11448. // MES_Flag
  11449. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  11450. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11451. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11452. writeToPLC_Flag.Adress = 2003;
  11453. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  11454. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11455. }
  11456. catch (Exception ex)
  11457. {
  11458. string str = ex.StackTrace;
  11459. AddMessage_Station(stationNameStr, LogType.Error,
  11460. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  11461. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11462. // MES_Flag
  11463. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11464. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11465. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11466. writeToPLC_Flag.Adress = 2003;
  11467. writeToPLC_Flag.Value = (short)6;
  11468. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11469. }
  11470. stopwatch1.Stop();
  11471. AddMessage(LogType.Info,
  11472. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  11473. stopwatch2.ElapsedMilliseconds + "ms");
  11474. }
  11475. /// <summary>
  11476. /// [S5] Tray盘下料装备 - 出站接口
  11477. /// </summary>
  11478. /// <param name="plcNo"></param>
  11479. /// <param name="stationCode"></param>
  11480. /// <param name="stationName"></param>
  11481. private void S5出站接口(int plcNo, string stationCode, string stationName)
  11482. {
  11483. Stopwatch stopwatch1 = new Stopwatch();
  11484. Stopwatch stopwatch2 = new Stopwatch();
  11485. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11486. string stationNameStr = stationCode + stationName;
  11487. string processItem = stationName; // 测试项目
  11488. try
  11489. {
  11490. stopwatch1.Start();
  11491. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11492. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11493. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11494. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11495. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  11496. sn = sn.Replace("\0", "");
  11497. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  11498. //partNo = partNo.Replace("\0", "");
  11499. #region 查询载具上的产品信息
  11500. string cavityData = string.Empty;
  11501. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11502. if (string.IsNullOrEmpty(cavityData))
  11503. cavityData = "";
  11504. if (snResult != 0)
  11505. {
  11506. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11507. writeToPLC_Flag1.Name = "e1MES_FLAG";
  11508. writeToPLC_Flag1.Adress = 2035;
  11509. writeToPLC_Flag1.Value = (short)4;
  11510. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  11511. stopwatch1.Stop();
  11512. AddMessage(LogType.Info,
  11513. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11514. return;
  11515. }
  11516. string[] cavitySNs = cavityData.Split('.');
  11517. string partNo = string.Empty;
  11518. if (cavitySNs != null && cavitySNs.Length >= 1)
  11519. partNo = cavitySNs[0];
  11520. #endregion 查询载具上的产品信息
  11521. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  11522. bool pass = e1Result == 1;
  11523. stopwatch2.Start();
  11524. // 上传MES
  11525. List<TestItem> items = new List<TestItem>();
  11526. items.Add(new TestItem()
  11527. {
  11528. Parameter_name = "载具码",
  11529. Parameter_value = sn,
  11530. Parameter_unit = ""
  11531. });
  11532. items.Add(new TestItem()
  11533. {
  11534. Parameter_name = "载具穴号",
  11535. Parameter_value = "1",
  11536. Parameter_unit = ""
  11537. });
  11538. items.Add(new TestItem()
  11539. {
  11540. Parameter_name = "产品结果",
  11541. Parameter_value = e1Result == 1 ? "OK" : "NG",
  11542. Parameter_unit = ""
  11543. });
  11544. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  11545. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  11546. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  11547. short result = result1 == 1 ? (short)1 : (short)3;
  11548. stopwatch2.Stop();
  11549. #region 存储绑定数据到 边线MES系统中
  11550. if (result == 1)
  11551. {
  11552. // 删除绑定信息
  11553. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11554. if (resultMesR != 0)
  11555. {
  11556. result = 4;
  11557. AddMessage_Station(stationNameStr, LogType.Error,
  11558. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11559. }
  11560. }
  11561. #endregion 存储绑定数据到 边线MES系统中
  11562. // MES_Flag 为MES报错
  11563. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11564. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  11565. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11566. writeToPLC_Flag.Name = "e1MES_FLAG";
  11567. writeToPLC_Flag.Adress = 2035;
  11568. writeToPLC_Flag.Value = result;
  11569. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11570. OnMessage(LogType.Debug,
  11571. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11572. }
  11573. catch (Exception ex)
  11574. {
  11575. stopwatch2.Restart();
  11576. // MES_Flag 为4上位机报错
  11577. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  11578. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11579. writeToPLC_Flag.Name = "e1MES_FLAG";
  11580. writeToPLC_Flag.Adress = 2035;
  11581. writeToPLC_Flag.Value = (short)4;
  11582. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11583. stopwatch2.Stop();
  11584. string str = ex.StackTrace;
  11585. AddMessage_Station(stationNameStr, LogType.Error,
  11586. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11587. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11588. }
  11589. stopwatch1.Stop();
  11590. AddMessage(LogType.Info,
  11591. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11592. stopwatch2.ElapsedMilliseconds + "ms");
  11593. }
  11594. /// <summary>
  11595. /// [S5] Tray盘下料装备 - 节拍接口
  11596. /// </summary>
  11597. /// <param name="plcNo">PLC编号</param>
  11598. /// <param name="stationNameStr">工站全称</param>
  11599. //private void S5节拍接口(int plcNo, string stationNameStr)
  11600. //{
  11601. // Stopwatch stopwatch1 = new Stopwatch();
  11602. // Stopwatch stopwatch2 = new Stopwatch();
  11603. // string resultStr = string.Empty;
  11604. // try
  11605. // {
  11606. // stopwatch1.Start();
  11607. // string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  11608. // string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  11609. // e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  11610. // bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11611. // if (!actionBool)
  11612. // {
  11613. // stopwatch2.Start();
  11614. // // MES_Flag
  11615. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11616. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11617. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11618. // writeToPLC_Flag1.Adress = 2088;
  11619. // writeToPLC_Flag1.Value = (short)4;
  11620. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11621. // stopwatch2.Stop();
  11622. // AddMessage(LogType.Info,
  11623. // stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11624. // "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11625. // return;
  11626. // }
  11627. // string e1OEEPartNo = string.Empty; // 物料码
  11628. // if (string.IsNullOrEmpty(e1OEEProductSN))
  11629. // {
  11630. // stopwatch2.Start();
  11631. // // MES_Flag
  11632. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11633. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11634. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11635. // writeToPLC_Flag1.Adress = 2088;
  11636. // writeToPLC_Flag1.Value = (short)1;
  11637. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11638. // stopwatch2.Stop();
  11639. // AddMessage(LogType.Info,
  11640. // stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11641. // stopwatch2.ElapsedMilliseconds + "ms");
  11642. // return;
  11643. // }
  11644. // else
  11645. // {
  11646. // // 查产品SN
  11647. // e1OEEPartNo = "Test"; // ZS
  11648. // }
  11649. // short e1OEEMES_FLAG = 0;
  11650. // // 上传OEE
  11651. // (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  11652. // e1OEEMES_FLAG = result.Item1;
  11653. // resultStr = result.Item2;
  11654. // stopwatch2.Start();
  11655. // // MES_Flag
  11656. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11657. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11658. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11659. // writeToPLC_Flag.Adress = 2088;
  11660. // writeToPLC_Flag.Value = e1OEEMES_FLAG;
  11661. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11662. // stopwatch2.Stop();
  11663. // }
  11664. // catch (Exception ex)
  11665. // {
  11666. // string str = ex.StackTrace;
  11667. // AddMessage_Station(stationNameStr, LogType.Error,
  11668. // $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11669. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11670. // // MES_Flag
  11671. // stopwatch2.Start();
  11672. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11673. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11674. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11675. // writeToPLC_Flag.Adress = 2088;
  11676. // writeToPLC_Flag.Value = (short)4;
  11677. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11678. // stopwatch2.Stop();
  11679. // }
  11680. // stopwatch1.Stop();
  11681. // AddMessage(LogType.Info,
  11682. // stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11683. // stopwatch2.ElapsedMilliseconds + "ms");
  11684. //}
  11685. /// <summary>
  11686. /// [S5] Tray盘下料装备 - AGV上料叫agv
  11687. /// </summary>
  11688. /// <param name="plcNo">PLC编号</param>
  11689. /// <param name="stationNameStr">工站全称</param>
  11690. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  11691. {
  11692. Stopwatch stopwatch1 = new Stopwatch();
  11693. Stopwatch stopwatch2 = new Stopwatch();
  11694. try
  11695. {
  11696. stopwatch1.Start();
  11697. // ZS 呼叫AGV
  11698. short e1AGVUpCall = 2;
  11699. stopwatch2.Start();
  11700. // e1AGVUpCall
  11701. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11702. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11703. writeToPLC_Flag.Name = "e1AGVUpCall";
  11704. writeToPLC_Flag.Adress = 2120;
  11705. writeToPLC_Flag.Value = e1AGVUpCall;
  11706. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11707. stopwatch2.Stop();
  11708. }
  11709. catch (Exception ex)
  11710. {
  11711. string str = ex.StackTrace;
  11712. AddMessage_Station(stationNameStr, LogType.Error,
  11713. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  11714. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11715. // e1AGVUpCall
  11716. stopwatch2.Start();
  11717. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11718. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11719. writeToPLC_Flag.Name = "e1AGVUpCall";
  11720. writeToPLC_Flag.Adress = 2120;
  11721. writeToPLC_Flag.Value = (short)4;
  11722. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11723. stopwatch2.Stop();
  11724. }
  11725. stopwatch1.Stop();
  11726. AddMessage(LogType.Info,
  11727. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11728. stopwatch2.ElapsedMilliseconds + "ms");
  11729. }
  11730. /// <summary>
  11731. /// [S5] Tray盘下料装备 - AGV上料完成
  11732. /// </summary>
  11733. /// <param name="plcNo">PLC编号</param>
  11734. /// <param name="stationNameStr">工站全称</param>
  11735. private void S5AGV上料完成(int plcNo, string stationNameStr)
  11736. {
  11737. Stopwatch stopwatch1 = new Stopwatch();
  11738. Stopwatch stopwatch2 = new Stopwatch();
  11739. try
  11740. {
  11741. stopwatch1.Start();
  11742. // ZS AGV上料完成,让小车离开
  11743. short e1AGVUpEnd = 2;
  11744. stopwatch2.Start();
  11745. // e1AGVUpEnd
  11746. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11747. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11748. writeToPLC_Flag.Name = "e1AGVUpEnd";
  11749. writeToPLC_Flag.Adress = 2122;
  11750. writeToPLC_Flag.Value = e1AGVUpEnd;
  11751. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  11752. stopwatch2.Stop();
  11753. }
  11754. catch (Exception ex)
  11755. {
  11756. string str = ex.StackTrace;
  11757. AddMessage_Station(stationNameStr, LogType.Error,
  11758. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  11759. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11760. // e1AGVUpEnd
  11761. stopwatch2.Start();
  11762. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  11763. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11764. writeToPLC_Flag.Name = "e1AGVUpEnd";
  11765. writeToPLC_Flag.Adress = 2122;
  11766. writeToPLC_Flag.Value = (short)4;
  11767. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  11768. stopwatch2.Stop();
  11769. }
  11770. stopwatch1.Stop();
  11771. AddMessage(LogType.Info,
  11772. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11773. stopwatch2.ElapsedMilliseconds + "ms");
  11774. }
  11775. /// <summary>
  11776. /// [S5] Tray盘下料装备 - AGV下料叫agv
  11777. /// </summary>
  11778. /// <param name="plcNo">PLC编号</param>
  11779. /// <param name="stationNameStr">工站全称</param>
  11780. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  11781. {
  11782. Stopwatch stopwatch1 = new Stopwatch();
  11783. Stopwatch stopwatch2 = new Stopwatch();
  11784. try
  11785. {
  11786. stopwatch1.Start();
  11787. // ZS 呼叫AGV
  11788. short e1AGVDownCall = 2;
  11789. stopwatch2.Start();
  11790. // e1AGVDownCall
  11791. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11792. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11793. writeToPLC_Flag.Name = "e1AGVDownCall";
  11794. writeToPLC_Flag.Adress = 2133;
  11795. writeToPLC_Flag.Value = e1AGVDownCall;
  11796. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  11797. stopwatch2.Stop();
  11798. }
  11799. catch (Exception ex)
  11800. {
  11801. string str = ex.StackTrace;
  11802. AddMessage_Station(stationNameStr, LogType.Error,
  11803. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  11804. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11805. // e1AGVDownCall
  11806. stopwatch2.Start();
  11807. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  11808. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11809. writeToPLC_Flag.Name = "e1AGVDownCall";
  11810. writeToPLC_Flag.Adress = 2133;
  11811. writeToPLC_Flag.Value = (short)4;
  11812. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  11813. stopwatch2.Stop();
  11814. }
  11815. stopwatch1.Stop();
  11816. AddMessage(LogType.Info,
  11817. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11818. stopwatch2.ElapsedMilliseconds + "ms");
  11819. }
  11820. /// <summary>
  11821. /// [S5] Tray盘下料装备 - AGV下料完成
  11822. /// </summary>
  11823. /// <param name="plcNo">PLC编号</param>
  11824. /// <param name="stationNameStr">工站全称</param>
  11825. private void S5AGV下料完成(int plcNo, string stationNameStr)
  11826. {
  11827. Stopwatch stopwatch1 = new Stopwatch();
  11828. Stopwatch stopwatch2 = new Stopwatch();
  11829. try
  11830. {
  11831. stopwatch1.Start();
  11832. // ZS AGV上料完成,让小车离开
  11833. short e1AGVDownEnd = 2;
  11834. stopwatch2.Start();
  11835. // e1AGVDownEnd
  11836. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11837. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11838. writeToPLC_Flag.Name = "e1AGVDownEnd";
  11839. writeToPLC_Flag.Adress = 2135;
  11840. writeToPLC_Flag.Value = e1AGVDownEnd;
  11841. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  11842. stopwatch2.Stop();
  11843. }
  11844. catch (Exception ex)
  11845. {
  11846. string str = ex.StackTrace;
  11847. AddMessage_Station(stationNameStr, LogType.Error,
  11848. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  11849. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11850. // e1AGVDownEnd
  11851. stopwatch2.Start();
  11852. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  11853. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11854. writeToPLC_Flag.Name = "e1AGVDownEnd";
  11855. writeToPLC_Flag.Adress = 2135;
  11856. writeToPLC_Flag.Value = (short)4;
  11857. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  11858. stopwatch2.Stop();
  11859. }
  11860. stopwatch1.Stop();
  11861. AddMessage(LogType.Info,
  11862. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11863. stopwatch2.ElapsedMilliseconds + "ms");
  11864. }
  11865. #endregion [S5] Tray盘下料装备
  11866. #endregion PLC5 张超凡
  11867. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  11868. /// <summary>
  11869. /// PLC读取到的数据 -添加数据
  11870. /// </summary>
  11871. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  11872. {
  11873. if (sxPlcData.ContainsKey(newKey))
  11874. sxPlcData[newKey] = newValue;
  11875. else
  11876. sxPlcData.Add(newKey, newValue);
  11877. }
  11878. /// <summary>
  11879. /// PLC需要写入的数据 -添加数据
  11880. /// </summary>
  11881. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey,
  11882. WriteToPLC_Flag newValue)
  11883. {
  11884. if (sxPLCWriteData.ContainsKey(newKey))
  11885. sxPLCWriteData[newKey] = newValue;
  11886. else
  11887. sxPLCWriteData.Add(newKey, newValue);
  11888. }
  11889. /// <summary>
  11890. /// PLC回写操作,写后清空flag
  11891. /// </summary>
  11892. /// <param name="modbusClient">modbus对象</param>
  11893. /// <param name="pLCReadDatas">读取到的数据字典</param>
  11894. /// <param name="pLCWriteDatas">需要写入的数据</param>
  11895. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas,
  11896. ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  11897. {
  11898. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  11899. {
  11900. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  11901. for (int i = 0; i < pLCWriteDatas.Count; i++)
  11902. {
  11903. string mesFlagName = pLCWriteDatas[i].Name;
  11904. int mesFlagAdress = pLCWriteDatas[i].Adress;
  11905. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  11906. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  11907. {
  11908. // 先回写数据
  11909. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  11910. for (int j = 0; j < writeToPLCDatas.Count; j++)
  11911. {
  11912. int mesDataAdress = writeToPLCDatas[j].Adress;
  11913. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  11914. switch (mesDataType)
  11915. {
  11916. case PLCValueType.Short:
  11917. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  11918. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  11919. break;
  11920. case PLCValueType.String:
  11921. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  11922. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  11923. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr,
  11924. mesDataValueStrLength);
  11925. break;
  11926. }
  11927. }
  11928. // 再回写信号
  11929. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  11930. // 存储读取数据的字典
  11931. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  11932. // 存储写入数据的字典 - 清空写入值
  11933. pLCWriteDatas[i].Value = (short)0;
  11934. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  11935. }
  11936. }
  11937. }
  11938. }
  11939. /// <summary>
  11940. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  11941. /// </summary>
  11942. /// <param name="no">3</param>
  11943. /// <param name="stationCode">设备编号</param>
  11944. /// <param name="stationNameStr">设备名称</param>
  11945. /// <param name="plcOrder">车间订单号</param>
  11946. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  11947. {
  11948. try
  11949. {
  11950. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  11951. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  11952. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  11953. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  11954. int result1 = 0;
  11955. switch (stationCode)
  11956. {
  11957. case 2:
  11958. case 3:
  11959. case 4:
  11960. case 6:
  11961. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  11962. break;
  11963. case 102:
  11964. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  11965. break;
  11966. case 103:
  11967. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  11968. break;
  11969. case 104:
  11970. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  11971. break;
  11972. case 106:
  11973. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  11974. break;
  11975. default:
  11976. // MES_Flag 为“6未找到正确设备编号”
  11977. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  11978. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  11979. return;
  11980. }
  11981. short result = result1 == 1 ? (short)1 : (short)2;
  11982. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  11983. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  11984. }
  11985. catch (Exception ex)
  11986. {
  11987. // MES_Flag 为2上位机报错
  11988. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  11989. string str = ex.StackTrace;
  11990. AddMessage_Station(stationNameStr, LogType.Error,
  11991. $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11992. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11993. }
  11994. }
  11995. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  11996. #region UI刷新
  11997. /// <summary>
  11998. /// 更新商品信息的UI + 下发产品信息(SN)
  11999. /// </summary>
  12000. private void UpdateProductInfo()
  12001. {
  12002. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  12003. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  12004. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  12005. //txt_CurSupplierCode.Text = ""; // 供应商代号
  12006. }
  12007. /// <summary>
  12008. /// 更新PLC连接状态的UI
  12009. /// </summary>
  12010. /// <param name="no">PLC编号</param>
  12011. /// <param name="status">状态</param>
  12012. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  12013. {
  12014. if (this != null && !this.IsDisposed)
  12015. {
  12016. switch (imgNo)
  12017. {
  12018. case 1:
  12019. this.BeginInvoke(new Action(() => { picPLC.Image = imageListState.Images[status]; }));
  12020. break;
  12021. case 2:
  12022. this.BeginInvoke(new Action(() => { pictureBox2.Image = imageListState.Images[status]; }));
  12023. break;
  12024. case 3:
  12025. this.BeginInvoke(new Action(() => { pictureBox3.Image = imageListState.Images[status]; }));
  12026. break;
  12027. case 4:
  12028. this.BeginInvoke(new Action(() => { pictureBox4.Image = imageListState.Images[status]; }));
  12029. break;
  12030. case 5:
  12031. this.BeginInvoke(new Action(() => { pictureBox5.Image = imageListState.Images[status]; }));
  12032. break;
  12033. case 6:
  12034. this.BeginInvoke(new Action(() => { pictureBox6.Image = imageListState.Images[status]; }));
  12035. break;
  12036. case 7:
  12037. this.BeginInvoke(new Action(() => { pictureBox7.Image = imageListState.Images[status]; }));
  12038. break;
  12039. case 8:
  12040. this.BeginInvoke(new Action(() => { pictureBox8.Image = imageListState.Images[status]; }));
  12041. break;
  12042. default:
  12043. break;
  12044. }
  12045. }
  12046. Task.Run(() => // 更新PLC交互页的指示灯
  12047. {
  12048. try
  12049. {
  12050. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12051. {
  12052. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  12053. }
  12054. }
  12055. catch
  12056. {
  12057. }
  12058. });
  12059. }
  12060. #endregion UI刷新
  12061. #region 日志
  12062. /// <summary>
  12063. /// 添加各工位运行日志(同步至PLC交互页面)
  12064. /// </summary>
  12065. /// <param name="stationNameStr">工站名称</param>
  12066. /// <param name="logType">日志类型</param>
  12067. /// <param name="message">日志内容</param>
  12068. /// <param name="snNumber">产品数字SN</param>
  12069. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  12070. {
  12071. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")))
  12072. {
  12073. AddMessage(logType, message); // 首页展示+日志记录
  12074. }
  12075. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  12076. {
  12077. StationName = stationNameStr,
  12078. SnNumber = snNumber,
  12079. Message = message,
  12080. CreateTime = DateTime.Now
  12081. };
  12082. // PLC交互页展示
  12083. Task.Run(() =>
  12084. {
  12085. try
  12086. {
  12087. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12088. {
  12089. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  12090. }
  12091. }
  12092. catch
  12093. {
  12094. }
  12095. });
  12096. }
  12097. /// <summary>
  12098. /// 添加运行日志
  12099. /// </summary>
  12100. /// <param name="logType">日志类型</param>
  12101. /// <param name="message">日志内容</param>
  12102. public void AddMessage(LogType logType, string message)
  12103. {
  12104. OnMessage(logType, message);
  12105. string date = DateTime.Now.ToString("yyyy/MM/dd");
  12106. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  12107. string msgShow = time + "--> " + message + "\r\n";
  12108. try
  12109. {
  12110. this.BeginInvoke(new Action(() =>
  12111. {
  12112. systemLog.Rows.Insert(0, date, time, message);
  12113. if (systemLog.Rows.Count >= 100)
  12114. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  12115. }));
  12116. }
  12117. catch (Exception ex) { }
  12118. }
  12119. /// <summary>
  12120. /// 添加运行日志-保存
  12121. /// </summary>
  12122. /// <param name="logType">日志类型</param>
  12123. /// <param name="message">日志内容</param>
  12124. private void OnMessage(LogType logType, string msg)
  12125. {
  12126. MessageEvent?.Invoke(logType, msg);
  12127. }
  12128. /// <summary>
  12129. /// 保存PLC写入日志
  12130. /// </summary>
  12131. /// <param name="logType"></param>
  12132. /// <param name="logValue"></param>
  12133. private void WritePLCLog(LogType logType, string logValue)
  12134. {
  12135. switch ((int)logType)
  12136. {
  12137. case 0:
  12138. _PLCLogNet.WriteDebug(logValue);
  12139. break;
  12140. case 1:
  12141. _PLCLogNet.WriteInfo(logValue);
  12142. break;
  12143. case 2:
  12144. _PLCLogNet.WriteWarn(logValue);
  12145. break;
  12146. case 3:
  12147. _PLCLogNet.WriteError(logValue);
  12148. break;
  12149. default:
  12150. _PLCLogNet.WriteFatal(logValue);
  12151. break;
  12152. }
  12153. }
  12154. /// <summary>
  12155. /// IOT Mqtt回调方法- With DataId
  12156. /// </summary>
  12157. /// <param name="id"></param>
  12158. /// <param name="v"></param>
  12159. /// <param name="dataId"></param>
  12160. public void CallbackWithDataId(string id, string msg, string dataId)
  12161. {
  12162. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  12163. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  12164. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  12165. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  12166. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  12167. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12168. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  12169. }
  12170. /// <summary>
  12171. /// AGV Mqtt回调方法- 记录Log并处理数据
  12172. /// </summary>
  12173. /// <param name="obj"></param>
  12174. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  12175. {
  12176. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12177. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  12178. // 接收到的信息
  12179. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  12180. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  12181. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  12182. {
  12183. }
  12184. }
  12185. #endregion 日志
  12186. //private void button1_Click(object sender, EventArgs e)
  12187. //{
  12188. // OpenDailogFalg=true;
  12189. // if (OpenDailogFalg)
  12190. // {
  12191. // using (var dialog = new BandBarodeDialog())
  12192. // {
  12193. // string strCarrierBarcode = "N801A-003";
  12194. // dialog._CarrierBarcode = strCarrierBarcode;
  12195. // string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  12196. // dialog._ProductBarcode = sn;
  12197. // var rs = dialog.ShowDialog();
  12198. // if (rs == DialogResult.OK)
  12199. // {
  12200. // AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  12201. // OpenDailogFalg = false;//关闭扫码
  12202. // }
  12203. // }
  12204. // }
  12205. //}
  12206. }
  12207. }