Form_Home.cs 579 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
  40. /*
  41. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  42. */
  43. namespace MainForm
  44. {
  45. /// <summary>
  46. /// 记录日志的委托
  47. /// </summary>
  48. /// <param name="logType">日志类型</param>
  49. /// <param name="message">日志信息</param>
  50. public delegate void HomeMessageHandler(LogType logType, string message);
  51. /// <summary>
  52. /// 主页窗体
  53. /// </summary>
  54. public partial class Form_Home : Form
  55. {
  56. #region 常量
  57. //文本常量
  58. private const string Head = "开始采集";
  59. private const string Tail = "采集完成";
  60. private const string Body = "工位出站数据";
  61. private const string BodyCheck = "工位点检数据";
  62. private const string BodyRun = "整线运行数据";
  63. private const string BodyAlarm = "整线报警数据";
  64. #endregion 常量
  65. #region 变量
  66. /// <summary>
  67. /// 委托-记录日志的方法
  68. /// </summary>
  69. public event HomeMessageHandler MessageEvent;
  70. /// <summary>
  71. /// 日志接口
  72. /// </summary>
  73. ILogNet _PLCLogNet;
  74. /// <summary>
  75. /// 用于记录IOT MQTT日志
  76. /// </summary>
  77. ILogNet _IOTMqttLogNet;
  78. /// <summary>
  79. /// 用于记录AGV MQTT日志
  80. /// </summary>
  81. ILogNet _AGVMqttLogNet;
  82. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  83. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  84. // 间隔时间
  85. private int IntervalReadPLC = 300; //ms 读PLC
  86. private int IntervalMonitorMES = 1000; //ms MES心跳
  87. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  88. // 软件状态
  89. private bool IsRun = true;
  90. #region PLC 与 TCP对象
  91. // 定义一个字典,存plc对象(通讯)
  92. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  93. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  94. // 定义TCPClient对象列表
  95. Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  96. // 定义MQTTHelper对象
  97. MQTTHelper _MQTTHelper = new MQTTHelper();
  98. #endregion PLC 与 TCP对象
  99. /// <summary>
  100. /// 上次的设备运行信息
  101. /// </summary>
  102. private string lineWorkingData1_OldStr = string.Empty;
  103. /// <summary>
  104. /// 设备报警字典-当前结果
  105. /// Dictionary<工位代码,List<报警信息>>
  106. /// </summary>
  107. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  108. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  109. #endregion 变量
  110. #region 窗体基础事件
  111. /// <summary>
  112. /// 初始化
  113. /// </summary>
  114. public Form_Home()
  115. {
  116. InitializeComponent();
  117. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  118. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  119. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  120. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  121. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  122. }
  123. /// <summary>
  124. /// 窗体加载事件
  125. /// </summary>
  126. private void Form_Home_Load(object sender, EventArgs e)
  127. {
  128. try
  129. {
  130. AddMessage(LogType.Info, "开始初始化程序");
  131. InitalDicAlarm(); // 实例化报警字典
  132. //组建plc对象字典
  133. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  134. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  135. if (GlobalContext.IsUsePLC1)
  136. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  137. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  138. if (GlobalContext.IsUsePLC2)
  139. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  140. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  141. if (GlobalContext.IsUsePLC3)
  142. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  143. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  144. if (GlobalContext.IsUsePLC4)
  145. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  146. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  147. if (GlobalContext.IsUsePLC5)
  148. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  149. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  150. if (GlobalContext.IsUsePLC6)
  151. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  152. if (GlobalContext.IsUsePLC7)
  153. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  154. if (GlobalContext.IsUsePLC8)
  155. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  156. if (GlobalContext.IsUsePLC9)
  157. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  158. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  159. {
  160. if (plcEIP != null)
  161. {
  162. try
  163. {
  164. (int, string) result = plcEIP.Connect();
  165. }
  166. catch (Exception ex)
  167. {
  168. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  169. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  170. }
  171. }
  172. }
  173. /*
  174. //plc1Alarm.Connect();
  175. foreach (ModbusClientHelper modbusClient in Funs.Values)
  176. {
  177. if (modbusClient != null)
  178. {
  179. try
  180. {
  181. modbusClient.Connect();
  182. }
  183. catch (Exception ex)
  184. {
  185. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  186. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  187. }
  188. }
  189. }
  190. */
  191. // 采集任务
  192. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  193. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  194. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  195. if (GlobalContext.IsUsePLC1)
  196. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  197. if (GlobalContext.IsUsePLC2)
  198. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  199. if (GlobalContext.IsUsePLC3)
  200. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  201. if (GlobalContext.IsUsePLC4)
  202. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  203. if (GlobalContext.IsUsePLC5)
  204. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  205. if (GlobalContext.IsUsePLC6)
  206. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  207. if (GlobalContext.IsUsePLC7)
  208. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  209. if (GlobalContext.IsUsePLC8)
  210. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  211. if (GlobalContext.IsUsePLC9)
  212. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  213. #region 初始化
  214. try
  215. {
  216. // 开启边线MES(绑定/查询数据)
  217. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  218. //if (mesRoute == 0)
  219. //{
  220. // //picMESStatus.Image = imageListState.Images[1];
  221. // //GlobalContext.MESIsConnect = true;
  222. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  223. //}
  224. //else
  225. //{
  226. // //picMESStatus.Image = imageListState.Images[0];
  227. // //GlobalContext.MESIsConnect = false;
  228. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  229. //}
  230. // 开启MES(Http)
  231. if (GlobalContext.IsUseMES)
  232. {
  233. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  234. if (mesret)
  235. {
  236. picMESStatus.Image = imageListState.Images[1];
  237. GlobalContext.MESIsConnect = true;
  238. AddMessage(LogType.Info, "小米MES初始连接成功!");
  239. }
  240. else
  241. {
  242. picMESStatus.Image = imageListState.Images[0];
  243. GlobalContext.MESIsConnect = false;
  244. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  245. }
  246. }
  247. // 开启IOT(MQTT)
  248. if (GlobalContext.IsUseIot)
  249. {
  250. string addr = GlobalContext.MQTTServerHost;
  251. int port = GlobalContext.MQTTServerPort;
  252. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer(addr, port, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  253. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  254. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  255. {
  256. picIot.Image = imageListState.Images[1];
  257. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  258. XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  259. }
  260. else
  261. {
  262. picIot.Image = imageListState.Images[0];
  263. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  264. }
  265. }
  266. // 开启AGV(Http与MQTT)
  267. if (GlobalContext.IsUseAGV)
  268. {
  269. // AGV HTTP
  270. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  271. if (mesret1)
  272. {
  273. picAgvHttp.Image = imageListState.Images[1];
  274. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  275. }
  276. else
  277. {
  278. picAgvHttp.Image = imageListState.Images[0];
  279. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  280. }
  281. string agvMqttIp = GlobalContext.MQTTServerHost;
  282. int agvMqttPort = GlobalContext.MQTTServerPort;
  283. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  284. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  285. // AGV MQTT
  286. if (result_MQTT.ResultCode == 1)
  287. {
  288. picAgvMqtt.Image = imageListState.Images[1];
  289. GlobalContext.AGVMQTTIsConnect = true;
  290. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  291. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  292. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  293. }
  294. else
  295. {
  296. picAgvMqtt.Image = imageListState.Images[0];
  297. GlobalContext.AGVMQTTIsConnect = false;
  298. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  299. }
  300. }
  301. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  302. Task.Run(MonitorMESConnect);
  303. // 查询PLC连接状态
  304. foreach (int plcNo in FunsEip.Keys)
  305. {
  306. bool connected = FunsEip[plcNo].IsConnected;
  307. if (connected)
  308. {
  309. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  310. AddMessage(LogType.Info, msg);
  311. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  312. }
  313. else
  314. {
  315. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  316. AddMessage(LogType.Info, msg);
  317. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  318. }
  319. }
  320. // PLC4时 初始化扫码器TCP
  321. //if (GlobalContext.IsUsePLC4)
  322. // HpTCPClientInit();
  323. // 开启PLC的业务处理线程-监听PLC点位+状态
  324. foreach (Task task in TaskReadProcess)
  325. {
  326. if (task != null)
  327. task.Start();
  328. }
  329. //// 开启“获取线体报警数据”的线程
  330. //TaskReadAlarm.Start();
  331. ////下传MES信息给1工位(先判断下plc对象数量)
  332. //if (Funs.Count > 1)
  333. // DownLoadProductInfo(1);
  334. AddMessage(LogType.Info, "程序初始化完成");
  335. }
  336. catch (Exception ex)
  337. {
  338. string str = ex.StackTrace;
  339. this.BeginInvoke(new Action(() =>
  340. {
  341. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  342. }));
  343. }
  344. #endregion
  345. }
  346. catch (Exception ex)
  347. {
  348. string str = ex.StackTrace;
  349. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  350. if (ex.Message != null && ex.Message.Contains("timed out"))
  351. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  352. else
  353. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  354. }
  355. }
  356. /// <summary>
  357. /// 窗体关闭事件
  358. /// </summary>
  359. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  360. {
  361. Closed2();
  362. }
  363. public void Closed2()
  364. {
  365. try
  366. {
  367. IsRun = false;
  368. Thread.Sleep(IntervalReadPLC);
  369. // 断开TCP
  370. int count = _HPSocket_TcpClients.Count();
  371. for (int i = 0; i < count; i++)
  372. {
  373. try
  374. {
  375. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  376. {
  377. _HPSocket_TcpClients[i].Stop();
  378. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  379. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  380. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  381. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  382. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  383. }
  384. }
  385. catch { }
  386. }
  387. // 关闭Iot
  388. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  389. // 关闭AGV Mqtt
  390. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  391. }
  392. catch { }
  393. }
  394. #endregion 窗体基础事件
  395. #region 监控MES状态
  396. /// <summary>
  397. /// 监控MES连接状态
  398. /// </summary>
  399. private void MonitorMESConnect()
  400. {
  401. while (IsRun) // 运行被控线程
  402. {
  403. try
  404. {
  405. // 开启MES(Http)
  406. if (GlobalContext.IsUseMES)
  407. {
  408. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  409. if (mesret)
  410. {
  411. picMESStatus.Image = imageListState.Images[1];
  412. GlobalContext.MESIsConnect = true;
  413. }
  414. else
  415. {
  416. picMESStatus.Image = imageListState.Images[0];
  417. GlobalContext.MESIsConnect = false;
  418. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  419. }
  420. }
  421. // 开启IOT(MQTT)
  422. if (GlobalContext.IsUseIot)
  423. {
  424. bool iIot = XiaomiMqttClient.IsOpen;
  425. if (iIot)
  426. picIot.Image = imageListState.Images[1];
  427. else
  428. {
  429. picIot.Image = imageListState.Images[0];
  430. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  431. }
  432. }
  433. // 开启AGV(Http与MQTT)
  434. if (GlobalContext.IsUseAGV)
  435. {
  436. // AGV Http
  437. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  438. if (mesret1)
  439. picAgvHttp.Image = imageListState.Images[1];
  440. else
  441. {
  442. picAgvHttp.Image = imageListState.Images[0];
  443. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  444. }
  445. // AGV MQTT
  446. if (GlobalContext.AGVMQTTIsConnect)
  447. picAgvMqtt.Image = imageListState.Images[1];
  448. else
  449. {
  450. picAgvMqtt.Image = imageListState.Images[0];
  451. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  452. }
  453. }
  454. }
  455. catch (Exception ex)
  456. {
  457. string str = ex.StackTrace;
  458. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  459. }
  460. Thread.Sleep(IntervalMonitorMES);
  461. }
  462. }
  463. #endregion 监控MES连接状态
  464. #region 采集设备状态、运行数据、报警数据
  465. /// <summary>
  466. /// 请求设备状态 5000
  467. /// </summary>
  468. /// <param name="no">1</param>
  469. /// <param name="stationNameStr"></param>
  470. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  471. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  472. {
  473. try
  474. {
  475. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  476. {
  477. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  478. return result;
  479. }
  480. else
  481. {
  482. return 0;
  483. }
  484. }
  485. catch (Exception ex)
  486. {
  487. string str = ex.StackTrace;
  488. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  489. return 0;
  490. }
  491. }
  492. /// <summary>
  493. /// 检查是否可采集点检数据 - 不取新值
  494. /// 5000不为1时可点检
  495. /// </summary>
  496. /// <returns></returns>
  497. public bool CheckCanSpotcheck1(int deviceState)
  498. {
  499. //return true;
  500. //D5000 = 1,代表设备控制状态处于运行状态
  501. //D5000 = 2, 代表设备控制状态处于故障状态
  502. //D5000 = 3,代表设备控制状态处于缺料状态
  503. //D5000 = 4, 代表设备控制状态处于待机状态
  504. //D5000 = 5,代表设备控制状态处于维修状态
  505. return deviceState != 1;
  506. }
  507. /// <summary>
  508. /// 检查是否可采集产品数据 - 不取新值
  509. /// </summary>
  510. /// <returns></returns>
  511. public bool CheckCanCollData(int deviceState)
  512. {
  513. return deviceState == 0; // 点检时该值不为0
  514. }
  515. /// <summary>
  516. /// 获取设备报警数据与获取设备运行信息
  517. /// </summary>
  518. private async void ReadAlarmAllPLC()
  519. {
  520. // [S1] Tray盘上料装备(板测)
  521. // [S2] FCT(板测)
  522. // [S3] 值板机
  523. // [S4] 取放桁架
  524. // [S5] Tray盘下料装备
  525. /// 上位机心跳
  526. /// 获取设备报警数据与状态信息
  527. string stationNameStr = "获取设备报警数据与状态信息";
  528. while (IsRun)
  529. {
  530. try
  531. {
  532. if (!GlobalContext._IsCon_plc1Alarm)
  533. {
  534. UpdatePLCMonitor(1, -2, 0);
  535. continue;
  536. }
  537. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  538. {
  539. DateTime dtNow = DateTime.Now;
  540. #region 获取设备运行信息
  541. try
  542. {
  543. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  544. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  545. lineWorkingData1.LineName = GlobalContext.LineCode;
  546. //
  547. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  548. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  549. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  550. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  551. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  552. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  553. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  554. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  555. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  556. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  557. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  558. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  559. lineWorkingData1.CreateTime = DateTime.Now;
  560. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  561. // UI展示-展示到设备状态页
  562. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  563. {
  564. // 查询数据库最新一条数据,确定是不是更新
  565. string qSql = @"SELECT top(1) [GUID]
  566. ,[LineName]
  567. ,[BootTimeLong]
  568. ,[NormalTimeLong]
  569. ,[StandbyTimeLong]
  570. ,[FaultTimeLong]
  571. ,[MaterialShortageTimeLong]
  572. ,[MaintenanceTimeLong]
  573. ,[FaultNumber]
  574. ,[OutputNumber]
  575. ,[QualifiedNumber]
  576. ,[QualifiedRate]
  577. ,[DesignRhythm]
  578. ,[RealityRhythm]
  579. ,[CreateTime]
  580. FROM [LineWorkingData]
  581. where [CreateTime] > '{0}'
  582. and [LineName]='{1}'
  583. order by [CreateTime] desc
  584. ";
  585. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  586. var ds = SQLHelper_New.Query(qSql, null);
  587. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  588. {
  589. var dataDBlast = new LineWorkingData_ThisTime();
  590. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  591. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  592. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  593. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  594. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  595. {
  596. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  597. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  598. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  599. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  600. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  601. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  602. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  603. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  604. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  605. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  606. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  607. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  608. string usql = dataDBlast.ToStringUpdate();
  609. SQLHelper_New.ExecuteSQL(usql, null);
  610. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  611. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  612. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  613. }
  614. }
  615. else
  616. {
  617. // 插入
  618. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  619. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  620. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  621. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  622. }
  623. }
  624. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  625. {
  626. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  627. //// 本次开机设备运行情况
  628. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  629. //Task.Run(() =>
  630. //{
  631. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  632. // {
  633. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  634. // }
  635. //});
  636. // 本日设备运行情况
  637. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  638. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  639. {
  640. // 更新
  641. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  642. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  643. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  644. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  645. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  646. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  647. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  648. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  649. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  650. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  651. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  652. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  653. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  654. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  655. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  656. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  657. }
  658. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  659. {
  660. // 插入
  661. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  662. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  663. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  664. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  665. }
  666. await Task.Run(() =>
  667. {
  668. try
  669. {
  670. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  671. {
  672. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  673. }
  674. }
  675. catch { }
  676. });
  677. }
  678. }
  679. catch (Exception ex)
  680. {
  681. string str = ex.StackTrace;
  682. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  683. }
  684. #endregion 获取设备运行信息
  685. #region 报警数据
  686. try
  687. {
  688. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  689. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  690. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  691. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  692. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  693. {
  694. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  695. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  696. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  697. {
  698. isNeedUpdUI = true; // 需要更新历史报警UI信息
  699. // 记录
  700. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  701. switch (dicAlarms_Cur_PLC1[i].是否报警)
  702. {
  703. case true: // 报警
  704. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  705. {
  706. GUID = Guid.NewGuid().ToString(),
  707. LineName = GlobalContext.LineCode, // 线体
  708. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  709. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  710. StartTime = dtNow // 开始时间
  711. };
  712. // 传输到页面
  713. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  714. {
  715. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  716. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  717. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  718. 开始时间 = dtNow
  719. });
  720. // 新增到数据库
  721. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  722. SaveAlarmDataByDB(stationNameStr, data1, false);
  723. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  724. break;
  725. case false: // 消除报警
  726. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  727. {
  728. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  729. {
  730. GUID = Guid.NewGuid().ToString(),
  731. LineName = GlobalContext.LineCode, // 线体
  732. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  733. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  734. StartTime = dtNow, // 开始时间
  735. EndTime = dtNow, // 开始时间
  736. PersistTime = 1, // 耗时1s
  737. };
  738. // 新增
  739. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  740. SaveAlarmDataByDB(stationNameStr, data2, false);
  741. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  742. }
  743. else
  744. {
  745. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  746. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  747. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  748. // 修改
  749. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  750. SaveAlarmDataByDB(stationNameStr, data3, true);
  751. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  752. }
  753. break;
  754. default:
  755. break;
  756. }
  757. }
  758. }
  759. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  760. // 有新报警则更新
  761. if (isNeedUpdUI)
  762. {
  763. // UI展示 - 展示到设备状态页
  764. await Task.Run(() =>
  765. {
  766. try
  767. {
  768. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  769. {
  770. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  771. if (Form_Main.formDevAlarm.Visible)
  772. {
  773. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  774. }
  775. }
  776. }
  777. catch { }
  778. });
  779. }
  780. }
  781. catch (Exception ex)
  782. {
  783. string str = ex.StackTrace;
  784. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  785. }
  786. #endregion 报警数据
  787. UpdatePLCMonitor(1, -2, 1);
  788. }
  789. else
  790. {
  791. UpdatePLCMonitor(1, -2, 0);
  792. }
  793. }
  794. catch (Exception ex)
  795. {
  796. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  797. }
  798. Thread.Sleep(IntervalAlarm);
  799. }
  800. }
  801. #endregion 轮询PLC
  802. #region 下发订单信息
  803. ///// <summary>
  804. ///// 壳体上料(下发工单)的交互逻辑
  805. ///// </summary>
  806. ///// <param name="no"></param>
  807. ///// <exception cref="NotImplementedException"></exception>
  808. //private void ReadStation_DownOrderInfo(int plcNo)
  809. //{
  810. // // [S1] Tray盘上料装备(板测)
  811. // // [S2] FCT(板测)
  812. // // [S3] 值板机
  813. // // [S4] 取放桁架
  814. // // [S5] Tray盘下料装备
  815. // /// 上位机心跳
  816. // /// 获取设备报警数据与状态信息
  817. // string stationNameStr = "[S0]壳体上料";
  818. // while (IsRun)
  819. // {
  820. // try
  821. // {
  822. // if (!GlobalContext._IsCon_Funs1)
  823. // {
  824. // UpdatePLCMonitor(plcNo, 0);
  825. // continue;
  826. // }
  827. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  828. // {
  829. // #region 壳体上料(下发工单)
  830. // try
  831. // {
  832. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  833. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  834. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  835. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  836. // // 重置数据和信号
  837. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  838. // {
  839. // // 清空写给PLC的数据
  840. // int[] i497 = new int[1] { 0 };
  841. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  842. // // MES_Flag重置为0
  843. // int[] i500 = new int[1] { 0 };
  844. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  845. // }
  846. // }
  847. // catch (Exception ex)
  848. // {
  849. // string str = ex.StackTrace;
  850. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  851. // }
  852. // #endregion 壳体上料(下发工单)
  853. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  854. // }
  855. // else
  856. // {
  857. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  858. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  859. //
  860. // Funs[plcNo].Connect();
  861. // }
  862. // }
  863. // catch (Exception ex)
  864. // {
  865. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  866. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  867. //
  868. // Funs[plcNo].ReConnect();
  869. // }
  870. // Thread.Sleep(IntervalReadPLC);
  871. // }
  872. //}
  873. ///// <summary>
  874. ///// 下发订单信息到PLC
  875. ///// </summary>
  876. ///// <param name="no">PLC编号</param>
  877. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  878. //{
  879. // try
  880. // {
  881. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  882. // {
  883. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  884. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  885. // }
  886. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  887. // }
  888. // catch (Exception ex)
  889. // {
  890. // string str = ex.StackTrace;
  891. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  892. // }
  893. //}
  894. /// <summary>
  895. /// 下发清料信号
  896. /// </summary>
  897. /// <param name="no">PLC编号</param>
  898. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  899. {
  900. try
  901. {
  902. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  903. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  904. return true;
  905. }
  906. catch (Exception ex)
  907. {
  908. string str = ex.StackTrace;
  909. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  910. return false;
  911. }
  912. }
  913. #endregion 下发订单信息
  914. #region Xiaomi 贲流
  915. #region 公共方法
  916. private static bool ProgressState = false;
  917. private static readonly object lockObj = new object(); // 锁对象
  918. private static bool isCollectingFlagLeft;
  919. private static bool isCollectingFlagRight;
  920. private bool OpenDailogFalg = true;//是否开启扫码弹窗标识
  921. /// <summary>
  922. /// float[]转为string
  923. /// </summary>
  924. public string FloatArrayToString(float[] nScrewResults)
  925. {
  926. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  927. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  928. }
  929. /// <summary>
  930. /// short[]转为string
  931. /// </summary>
  932. public string ShortArrayToString(short[] nScrewResults)
  933. {
  934. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  935. return string.Join(",", nScrewResults);
  936. }
  937. /// <summary>
  938. /// 写入PLC重复三次
  939. /// </summary>
  940. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  941. {
  942. int i = 0;
  943. int nRet = 0;
  944. string strRet = "";
  945. try
  946. {
  947. while (i < 3) // 最多上传三次
  948. {
  949. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  950. if (nRet == 0) //成功
  951. {
  952. break;
  953. }
  954. else
  955. {
  956. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  957. i++;
  958. }
  959. }
  960. return (nRet, strRet);
  961. }
  962. catch (Exception ex)
  963. {
  964. return (1, ex.Message);
  965. }
  966. }
  967. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  968. {
  969. try
  970. {
  971. // 获取当前日期
  972. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  973. // 构建保存路径
  974. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  975. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  976. // 确保目录存在
  977. Directory.CreateDirectory(savePath);
  978. // 文件名
  979. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  980. string filePath = Path.Combine(savePath, fileName);
  981. // 确保不会超出数组长度,只取前14个或数组的实际长度
  982. int count = Math.Min(14, fScrewTimes.Length);
  983. using (StreamWriter sw = new StreamWriter(filePath))
  984. {
  985. for (int i = 0; i < count; i++)
  986. {
  987. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  988. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  989. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  990. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  991. sw.WriteLine(); // 空行分隔不同螺丝的信息
  992. }
  993. }
  994. return (0, "");
  995. }
  996. catch (Exception ex)
  997. {
  998. return (1, ex.Message);
  999. }
  1000. }
  1001. /// <summary>
  1002. /// 调用进站接口并保存进站数据
  1003. /// </summary>
  1004. /// <param name="stationNameStr">工站信息</param>
  1005. /// <param name="workorder_code">工单号</param>
  1006. /// <param name="mtltmrk">型号(物料号)</param>
  1007. /// <param name="sn">产品SN</param>
  1008. /// <param name="items">进站数据</param>
  1009. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1010. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1011. {
  1012. int result = 0;
  1013. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1014. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1015. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1016. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1017. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1018. inRequest_Body.unitSn = sn; // 产品SN
  1019. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1020. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1021. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1022. StationIn stationIn = new StationIn()
  1023. {
  1024. Workorder_code = workorder_code, // 车间订单号
  1025. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1026. Sn = sn, // SN
  1027. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1028. Parameter_values = items, // 进站数据
  1029. Write_user = inRequest_Body.userId, // 员工Id
  1030. Test_time = inRequest_Body.clientTime // 进站时间
  1031. };
  1032. // 本地数据
  1033. string sql = stationIn.ToStringInsert(0);
  1034. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1035. result = ret == "成功" ? 1 : 6;
  1036. //await Task.Delay(200);
  1037. // 上传MES
  1038. if (GlobalContext.IsSendStationIn)
  1039. {
  1040. try
  1041. {
  1042. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1043. string mesRet = string.Empty;
  1044. int i = 0;
  1045. while (i < 2) // 1009会多次尝试上传
  1046. {
  1047. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1048. if (response != null && response.header.code == "200")
  1049. break;
  1050. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1051. i++;
  1052. i++;
  1053. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1054. // 记录失败原因
  1055. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1056. }
  1057. if (response?.header?.code == "200")
  1058. {
  1059. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1060. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1061. result = ret_Upd == "成功" ? 1 : 6;
  1062. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1063. }
  1064. else
  1065. {
  1066. result = 5;
  1067. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1068. }
  1069. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1070. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1071. }
  1072. catch (Exception ex)
  1073. {
  1074. result = 6;
  1075. string str = ex.StackTrace;
  1076. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1077. }
  1078. }
  1079. return result;
  1080. }
  1081. /// <summary>
  1082. /// 选择如何记录出站数据
  1083. /// </summary>
  1084. /// <param name="items">出站数据</param>
  1085. /// <param name="equipmentCode">设备编号</param>
  1086. /// <param name="processItem">测试项目</param>
  1087. /// <param name="workorder_code">车间订单号</param>
  1088. /// <param name="batch_num">批次号</param>
  1089. /// <param name="mtltmrk">型号</param>
  1090. /// <param name="proDate">日期</param>
  1091. /// <param name="supplierCode">供应商代码</param>
  1092. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1093. /// <returns>上传成功时返回1;失败返回0</returns>
  1094. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1095. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1096. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode)
  1097. {
  1098. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1099. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode);
  1100. }
  1101. /// <summary>
  1102. /// 添加出站数据(提交到MES+本地保存到数据库)
  1103. /// </summary>
  1104. /// <param name="items">出站数据</param>
  1105. /// <param name="equipmentCode">设备编号</param>
  1106. /// <param name="processItem">测试项目</param>
  1107. /// <param name="workorder_code">车间订单号</param>
  1108. /// <param name="batch_num">批次号</param>
  1109. /// <param name="mtltmrk">型号</param>
  1110. /// <param name="proDate">日期</param>
  1111. /// <param name="supplierCode">供应商代码</param>
  1112. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1113. /// <returns>上传成功时返回1;失败返回0</returns>
  1114. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1115. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1116. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode)
  1117. {
  1118. int upload = 0;
  1119. int result = 0;
  1120. ProcessData processData = new ProcessData()
  1121. {
  1122. Equipment_code = equipmentCode,
  1123. Workorder_code = workorder_code,
  1124. Batch_number = batch_num,
  1125. Sn = sn, // SN
  1126. Testitem = processItem,
  1127. Parameter_values = items,
  1128. Write_user = GlobalContext.CurrentUser,
  1129. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1130. };
  1131. // 本地数据
  1132. string sql = processData.ToStringInsert(upload);
  1133. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1134. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1135. // 上传MES
  1136. if (GlobalContext.IsSendProcessData)
  1137. {
  1138. try
  1139. {
  1140. string id = processData.ID.Copy();
  1141. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1142. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1143. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1144. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1145. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1146. outRequest_Body.unitSn = sn; // 产品SN
  1147. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1148. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1149. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1150. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1151. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1152. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1153. if (!string.IsNullOrEmpty(partBarcode))
  1154. {
  1155. outRequest_Body.unitData.keyMaterial.Add(
  1156. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1157. {
  1158. bindSort = 1,
  1159. materialSn = partBarcode
  1160. }); // 设备数据 - 部件码
  1161. }
  1162. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1163. if (GlobalContext.IsSendProcessData)
  1164. {
  1165. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1166. string mesRet = string.Empty;
  1167. int i = 0;
  1168. while (i < 2) // 1009会多次尝试上传
  1169. {
  1170. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1171. if (response != null && response.header.code == "200")
  1172. break;
  1173. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1174. i++;
  1175. i++;
  1176. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1177. // 记录失败原因
  1178. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1179. }
  1180. if (response?.header?.code == "200")
  1181. {
  1182. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1183. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1184. result = 1;
  1185. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1186. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1187. }
  1188. else
  1189. {
  1190. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1191. }
  1192. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1193. JsonConvert.SerializeObject(response), id);
  1194. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1195. }
  1196. }
  1197. catch (Exception ex)
  1198. {
  1199. string str = ex.StackTrace;
  1200. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1201. }
  1202. }
  1203. return result;
  1204. }
  1205. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1206. //{
  1207. // Stopwatch stopwatch = new Stopwatch();
  1208. // stopwatch.Start();
  1209. // try
  1210. // {
  1211. // // 初始化 AtlasScrew 实例
  1212. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1213. // atlasScrew1.Initial();
  1214. // // 存储结果的列表
  1215. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1216. // // 存储角度和扭力的字符串列表
  1217. // List<string> angleStrs = new List<string>();
  1218. // List<string> torqueStrs = new List<string>();
  1219. // // 上一次获取的数据
  1220. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1221. // while (isExitAtlasLeft) // 检查是否收集数据
  1222. // {
  1223. // // 获取当前数据
  1224. // var currentResult = atlasScrew1.GetResults();
  1225. // // 判断是否为新数据
  1226. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1227. // {
  1228. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1229. // // 更新角度和扭力的字符串列表
  1230. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1231. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1232. // // 计算角度、扭力、起始扭力和最大扭力
  1233. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1234. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1235. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1236. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1237. // // 将新数据添加到结果列表
  1238. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1239. // // 更新上一次获取的数据
  1240. // lastResult = currentResult;
  1241. // }
  1242. // // 等待一段时间后再次检查
  1243. // Thread.Sleep(20); // 轮询间隔时间
  1244. // // 如果触发了出站,则退出循环
  1245. // if (!isExitAtlasLeft)
  1246. // {
  1247. // break;
  1248. // }
  1249. // }
  1250. // // 生成文件名
  1251. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1252. // // 写入数据到文件
  1253. // using (StreamWriter writer = new StreamWriter(fileName))
  1254. // {
  1255. // // 写入标题行
  1256. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1257. // // 写入每一行数据
  1258. // foreach (var result in results)
  1259. // {
  1260. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1261. // }
  1262. // }
  1263. // stopwatch.Stop();
  1264. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1265. // }
  1266. // catch (Exception ex)
  1267. // {
  1268. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1269. // }
  1270. // finally
  1271. // {
  1272. // // 重置标志变量
  1273. // isExitAtlasLeft = false;
  1274. // }
  1275. //}
  1276. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1277. //{
  1278. // Stopwatch stopwatch = new Stopwatch();
  1279. // stopwatch.Start();
  1280. // try
  1281. // {
  1282. // // 初始化 AtlasScrew 实例
  1283. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1284. // atlasScrew2.Initial();
  1285. // // 存储结果的列表
  1286. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1287. // // 上一次获取的数据
  1288. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1289. // while (isExitAtlasRight) // 检查是否收集数据
  1290. // {
  1291. // // 获取当前数据
  1292. // var currentResult = atlasScrew2.GetResults();
  1293. // // 判断是否为新数据
  1294. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1295. // {
  1296. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1297. // // 将新数据写入PLC
  1298. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1299. // // 将新数据添加到结果列表
  1300. // results.Add(currentResult);
  1301. // // 更新上一次获取的数据
  1302. // lastResult = currentResult;
  1303. // }
  1304. // // 等待一段时间后再次检查
  1305. // Thread.Sleep(20); // 轮询间隔时间
  1306. // // 如果触发了出站,则退出循环
  1307. // if (!isExitAtlasRight)
  1308. // {
  1309. // break;
  1310. // }
  1311. // }
  1312. // // 将所有数据写入文件
  1313. // //WriteDataToFile(sn, direction, results);
  1314. // stopwatch.Stop();
  1315. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1316. // }
  1317. // catch (Exception ex)
  1318. // {
  1319. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1320. // }
  1321. // finally
  1322. // {
  1323. // // 重置标志变量
  1324. // isExitAtlasRight = false;
  1325. // }
  1326. //}
  1327. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1328. {
  1329. Stopwatch stopwatch = new Stopwatch();
  1330. stopwatch.Start();
  1331. int nRet = 0;
  1332. string strRet = "";
  1333. try
  1334. {
  1335. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1336. while (isCollectingFlagLeft)
  1337. {
  1338. // 从缓存中获取所有未处理的数据
  1339. var cachedData = atlasScrew.GetCachedDataLeft();
  1340. foreach (var currentResult in cachedData)
  1341. {
  1342. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1343. {
  1344. continue; // 跳过无效数据
  1345. }
  1346. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1347. // 写入PLC
  1348. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1349. {
  1350. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1351. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1352. };
  1353. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1354. if (nRet != 0)
  1355. {
  1356. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1357. }
  1358. else
  1359. {
  1360. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1361. }
  1362. // 构建保存路径
  1363. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1364. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1365. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1366. Directory.CreateDirectory(savePath); // 确保目录存在
  1367. // 构建文件名(以 SN + 序号命名)
  1368. string fileName = $"{sn}_{fileCounter}.txt";
  1369. string filePath = Path.Combine(savePath, fileName);
  1370. // 写入文件
  1371. using (StreamWriter writer = new StreamWriter(filePath))
  1372. {
  1373. writer.WriteLine("精度, 扭力");
  1374. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1375. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1376. {
  1377. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1378. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1379. writer.WriteLine($"{precision}, {torque}");
  1380. }
  1381. }
  1382. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1383. // 增加文件计数器
  1384. fileCounter++;
  1385. }
  1386. // 如果没有更多数据,则短暂休眠以节省资源
  1387. if (!cachedData.Any())
  1388. {
  1389. Thread.Sleep(10); // 根据需要调整休眠时间
  1390. }
  1391. // 如果触发了出站,则退出循环
  1392. if (!isCollectingFlagLeft)
  1393. {
  1394. break;
  1395. }
  1396. }
  1397. stopwatch.Stop();
  1398. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1399. }
  1400. catch (Exception ex)
  1401. {
  1402. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1403. }
  1404. finally
  1405. {
  1406. isCollectingFlagLeft = false;
  1407. }
  1408. }
  1409. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1410. {
  1411. Stopwatch stopwatch = new Stopwatch();
  1412. stopwatch.Start();
  1413. int nRet = 0;
  1414. string strRet = "";
  1415. try
  1416. {
  1417. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1418. while (isCollectingFlagRight)
  1419. {
  1420. // 从缓存中获取所有未处理的数据
  1421. var cachedData = atlasScrew.GetCachedDataLeft();
  1422. foreach (var currentResult in cachedData)
  1423. {
  1424. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1425. {
  1426. continue; // 跳过无效数据
  1427. }
  1428. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1429. // 写入PLC
  1430. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1431. {
  1432. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1433. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1434. };
  1435. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1436. if (nRet != 0)
  1437. {
  1438. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1439. }
  1440. else
  1441. {
  1442. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1443. }
  1444. // 构建保存路径
  1445. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1446. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1447. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1448. Directory.CreateDirectory(savePath); // 确保目录存在
  1449. // 构建文件名(以 SN + 序号命名)
  1450. string fileName = $"{sn}_{fileCounter}.txt";
  1451. string filePath = Path.Combine(savePath, fileName);
  1452. // 写入文件
  1453. using (StreamWriter writer = new StreamWriter(filePath))
  1454. {
  1455. writer.WriteLine("精度, 扭力");
  1456. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1457. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1458. {
  1459. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1460. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1461. writer.WriteLine($"{precision}, {torque}");
  1462. }
  1463. }
  1464. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1465. // 增加文件计数器
  1466. fileCounter++;
  1467. }
  1468. // 如果没有更多数据,则短暂休眠以节省资源
  1469. if (!cachedData.Any())
  1470. {
  1471. Thread.Sleep(10); // 根据需要调整休眠时间
  1472. }
  1473. // 如果触发了出站,则退出循环
  1474. if (!isCollectingFlagRight)
  1475. {
  1476. break;
  1477. }
  1478. }
  1479. stopwatch.Stop();
  1480. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1481. }
  1482. catch (Exception ex)
  1483. {
  1484. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1485. }
  1486. finally
  1487. {
  1488. isCollectingFlagRight = false;
  1489. }
  1490. }
  1491. #endregion
  1492. #region S1
  1493. /// <summary>
  1494. /// [S1] 壳体清洁上料装备
  1495. /// </summary>
  1496. /// <param name="plcNo">PLC编号</param>
  1497. private void ReadStation_S1(int plcNo)
  1498. {
  1499. string stationCode = "[OP10]";
  1500. string stationName = "壳体清洁上料";
  1501. string stationNameStr = stationCode + stationName;
  1502. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1503. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1504. string tagAgvCommName = "agvCommFrmPC";
  1505. string tagBarsetName = "BarcodeSet";
  1506. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1507. (int, string) result;
  1508. while (true)
  1509. {
  1510. try
  1511. {
  1512. if (!GlobalContext._IsCon_Funs1)
  1513. {
  1514. UpdatePLCMonitor(1, plcNo, 0);
  1515. continue;
  1516. }
  1517. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1518. {
  1519. Stopwatch stopwatch1 = new Stopwatch();
  1520. Stopwatch stopwatch2 = new Stopwatch();
  1521. stopwatch1.Start();
  1522. stopwatch2.Start();
  1523. #region 一次性读取所有数据
  1524. // 一次性读取所有数据
  1525. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1526. if (result.Item1 != 0)
  1527. {
  1528. //richTextBox1.AppendText("\n" + strRet);
  1529. }
  1530. else
  1531. {
  1532. //richTextBox1.AppendText("\n" + "读取成功");
  1533. }
  1534. #endregion 一次性读取所有数据
  1535. stopwatch2.Stop();
  1536. #region 进站
  1537. try
  1538. {
  1539. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1540. {
  1541. lock (lockObj)
  1542. {
  1543. if (!ProgressState)
  1544. {
  1545. ProgressState = true;
  1546. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1547. }
  1548. }
  1549. }
  1550. }
  1551. catch (Exception ex)
  1552. {
  1553. ProgressState = false;
  1554. string str = ex.StackTrace;
  1555. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1556. }
  1557. #endregion 进站
  1558. #region 出站
  1559. try
  1560. {
  1561. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1562. {
  1563. lock (lockObj)
  1564. {
  1565. if (!ProgressState)
  1566. {
  1567. ProgressState = true;
  1568. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1569. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1570. }
  1571. }
  1572. }
  1573. }
  1574. catch (Exception ex)
  1575. {
  1576. ProgressState = false;
  1577. string str = ex.StackTrace;
  1578. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1579. }
  1580. #endregion 出站
  1581. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1582. stopwatch1.Stop();
  1583. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1584. }
  1585. else
  1586. {
  1587. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1588. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1589. FunsEip[plcNo].Connect(); // 重连
  1590. }
  1591. }
  1592. catch (Exception ex)
  1593. {
  1594. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1595. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1596. }
  1597. Thread.Sleep(IntervalReadPLC);
  1598. }
  1599. }
  1600. /// <summary>
  1601. /// [S1] 壳体清洁上料 - 进站
  1602. /// </summary>
  1603. /// <param name="plcNo">PLC编号</param>
  1604. /// <param name="stationNameStr">工站全称</param>
  1605. /// <param name="stPLC_MesData"></param>
  1606. /// <param name="tagMesCommName"></param>
  1607. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1608. {
  1609. Stopwatch stopwatch1 = new Stopwatch();
  1610. Stopwatch stopwatch2 = new Stopwatch();
  1611. try
  1612. {
  1613. stopwatch1.Start();
  1614. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1615. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1616. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1617. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1618. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1619. if (string.IsNullOrEmpty(sn))
  1620. {
  1621. ProgressState = false;
  1622. return;
  1623. }
  1624. //正式生产就用PLC中取的
  1625. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1626. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1627. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1628. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1629. //绑定载具和产品
  1630. ResponseMessage message = new ResponseMessage();
  1631. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1632. if (message.result == false)
  1633. {
  1634. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1635. }
  1636. // 产品SN进站
  1637. List<TestItem> item = new List<TestItem>();
  1638. stopwatch2.Start();
  1639. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1640. stopwatch2.Stop();
  1641. //指令执行结果 1:OK 110:失败
  1642. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1643. //进站结果写入PLC
  1644. CommandFromPLC resultToPlC = new CommandFromPLC();
  1645. resultToPlC.cmd = 0;
  1646. resultToPlC.cmdParam = 0;
  1647. resultToPlC.cmdResult = mesResultFrmWeb;
  1648. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1649. }
  1650. catch (Exception ex)
  1651. {
  1652. string str = ex.StackTrace;
  1653. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1654. CommandFromPLC resultToPlC = new CommandFromPLC();
  1655. resultToPlC.cmd = 0;
  1656. resultToPlC.cmdParam = 0; //指令参数
  1657. resultToPlC.cmdResult = 110;
  1658. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1659. }
  1660. stopwatch1.Stop();
  1661. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1662. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1663. ProgressState = false;
  1664. }
  1665. /// <summary>
  1666. /// [S1] 壳体清洁上料 - 出站接口
  1667. /// </summary>
  1668. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1669. {
  1670. Stopwatch stopwatch1 = new Stopwatch();
  1671. Stopwatch stopwatch2 = new Stopwatch();
  1672. try
  1673. {
  1674. stopwatch1.Start();
  1675. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1676. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1677. string processItem = stationName; // 项目
  1678. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1679. string supplierCode = ""; // 供应商代码
  1680. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1681. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1682. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1683. string sn = string.Empty;
  1684. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1685. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1686. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1687. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1688. a1Result = 1;
  1689. bool pass = a1Result == 1;
  1690. //根据载具码获取产品码
  1691. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1692. if (string.IsNullOrEmpty(strProductBarcode))
  1693. {
  1694. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1695. }
  1696. sn = strProductBarcode;
  1697. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1698. List<TestItem> items = new List<TestItem>();
  1699. items.Add(new TestItem()
  1700. {
  1701. Parameter_name = "载具码",
  1702. Parameter_value = CarrierBarcode,
  1703. Parameter_unit = ""
  1704. });
  1705. items.Add(new TestItem()
  1706. {
  1707. Parameter_name = "产品码",
  1708. Parameter_value = sn,
  1709. Parameter_unit = ""
  1710. });
  1711. //出站接口
  1712. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1713. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1714. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1715. stopwatch2.Start();
  1716. //进站结果写入PLC
  1717. CommandFromPLC resultToPlC = new CommandFromPLC();
  1718. resultToPlC.cmd = 0;
  1719. resultToPlC.cmdParam = 0; //指令参数
  1720. resultToPlC.cmdResult = mesResultFrmWeb;
  1721. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1722. stopwatch2.Stop();
  1723. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1724. //保存PLC返回MES数据到本地
  1725. ResponseMessage message = new ResponseMessage();
  1726. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1727. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1728. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1729. stPLC_MesData.mesData.nRemainCount);
  1730. if (message.result == false)
  1731. {
  1732. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1733. }
  1734. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1735. }
  1736. catch (Exception ex)
  1737. {
  1738. stopwatch2.Start();
  1739. CommandFromPLC resultToPlC = new CommandFromPLC();
  1740. resultToPlC.cmd = 0;
  1741. resultToPlC.cmdParam = 0; //指令参数
  1742. resultToPlC.cmdResult = 110;
  1743. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1744. stopwatch2.Stop();
  1745. string str = ex.StackTrace;
  1746. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1747. }
  1748. stopwatch1.Stop();
  1749. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1750. ProgressState = false;
  1751. }
  1752. #endregion
  1753. #region S2
  1754. /// <summary>
  1755. /// [S2] 上盖板上料装备
  1756. /// </summary>
  1757. /// <param name="plcNo">PLC编号</param>
  1758. private void ReadStation_S2(int plcNo)
  1759. {
  1760. string stationCode = "[OP20]";
  1761. string stationName = "上盖板上料装备";
  1762. string stationNameStr = stationCode + stationName;
  1763. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1764. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1765. string tagAgvCommName = "agvCommFrmPC";
  1766. string tagBarsetName = "BarcodeSet";
  1767. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1768. (int, string) result;
  1769. while (true)
  1770. {
  1771. try
  1772. {
  1773. if (!GlobalContext._IsCon_Funs2)
  1774. {
  1775. UpdatePLCMonitor(1, plcNo, 0);
  1776. continue;
  1777. }
  1778. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1779. {
  1780. Stopwatch stopwatch1 = new Stopwatch();
  1781. Stopwatch stopwatch2 = new Stopwatch();
  1782. stopwatch1.Start();
  1783. stopwatch2.Start();
  1784. #region 一次性读取所有数据
  1785. // 一次性读取所有数据
  1786. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1787. if (result.Item1 != 0)
  1788. {
  1789. //richTextBox1.AppendText("\n" + strRet);
  1790. }
  1791. else
  1792. {
  1793. //richTextBox1.AppendText("\n" + "读取成功");
  1794. }
  1795. #endregion 一次性读取所有数据
  1796. stopwatch2.Stop();
  1797. #region 进站
  1798. try
  1799. {
  1800. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1801. {
  1802. lock (lockObj)
  1803. {
  1804. if (!ProgressState)
  1805. {
  1806. ProgressState = true;
  1807. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1808. }
  1809. }
  1810. }
  1811. }
  1812. catch (Exception ex)
  1813. {
  1814. ProgressState = false;
  1815. string str = ex.StackTrace;
  1816. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1817. }
  1818. #endregion 进站
  1819. #region 出站
  1820. try
  1821. {
  1822. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1823. {
  1824. lock (lockObj)
  1825. {
  1826. if (!ProgressState)
  1827. {
  1828. ProgressState = true;
  1829. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1830. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1831. }
  1832. }
  1833. }
  1834. }
  1835. catch (Exception ex)
  1836. {
  1837. ProgressState = false;
  1838. string str = ex.StackTrace;
  1839. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1840. }
  1841. #endregion 出站
  1842. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1843. stopwatch1.Stop();
  1844. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1845. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1846. }
  1847. else
  1848. {
  1849. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1850. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1851. FunsEip[plcNo].Connect();
  1852. }
  1853. }
  1854. catch (Exception ex)
  1855. {
  1856. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1857. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1858. //Funs[plcNo].ReConnect();
  1859. }
  1860. Thread.Sleep(IntervalReadPLC);
  1861. }
  1862. }
  1863. /// <summary>
  1864. /// [S2] 上盖板上料装备
  1865. /// </summary>
  1866. /// <param name="plcNo">PLC编号</param>
  1867. /// <param name="stationNameStr">工站全称</param>
  1868. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  1869. {
  1870. Stopwatch stopwatch1 = new Stopwatch();
  1871. Stopwatch stopwatch2 = new Stopwatch();
  1872. try
  1873. {
  1874. stopwatch1.Start();
  1875. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1876. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  1877. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1878. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  1879. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  1880. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  1881. //根据载具码获取产品码
  1882. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  1883. if (string.IsNullOrEmpty(strProductBarcode))
  1884. {
  1885. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1886. }
  1887. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  1888. //if (sn != strProductBarcode)
  1889. //{
  1890. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  1891. //}
  1892. sn = strProductBarcode;
  1893. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  1894. // 产品SN(物料码)校验
  1895. List<TestItem> item = new List<TestItem>();
  1896. stopwatch2.Start();
  1897. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1898. stopwatch2.Stop();
  1899. //指令执行结果 1:OK 110:失败
  1900. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1901. //进站结果写入PLC
  1902. CommandFromPLC resultToPlC = new CommandFromPLC();
  1903. resultToPlC.cmd = 0;
  1904. resultToPlC.cmdParam = 0; //指令参数
  1905. resultToPlC.cmdResult = mesResultFrmWeb;
  1906. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1907. }
  1908. catch (Exception ex)
  1909. {
  1910. string str = ex.StackTrace;
  1911. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1912. CommandFromPLC resultToPlC = new CommandFromPLC();
  1913. resultToPlC.cmd = 0;
  1914. resultToPlC.cmdParam = 0; //指令参数
  1915. resultToPlC.cmdResult = 110;
  1916. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1917. }
  1918. stopwatch1.Stop();
  1919. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1920. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1921. ProgressState = false;
  1922. }
  1923. /// <summary>
  1924. /// [S2] 上盖板上料装备 - 出站接口
  1925. /// </summary>
  1926. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1927. {
  1928. Stopwatch stopwatch1 = new Stopwatch();
  1929. Stopwatch stopwatch2 = new Stopwatch();
  1930. try
  1931. {
  1932. stopwatch1.Start();
  1933. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1934. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1935. string processItem = stationName; // 测试项目
  1936. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1937. string supplierCode = ""; // 供应商代码
  1938. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  1939. string batch_num = GlobalContext.BatchNumber; // 批次号
  1940. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  1941. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  1942. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1943. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  1944. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  1945. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  1946. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1947. bool pass = a1Result == 1;
  1948. //根据载具码获取产品码
  1949. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1950. if (string.IsNullOrEmpty(strProductBarcode))
  1951. {
  1952. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1953. }
  1954. sn = strProductBarcode;
  1955. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1956. List<TestItem> items = new List<TestItem>();
  1957. items.Add(new TestItem()
  1958. {
  1959. Parameter_name = "载具码",
  1960. Parameter_value = CarrierBarcode,
  1961. Parameter_unit = ""
  1962. });
  1963. items.Add(new TestItem()
  1964. {
  1965. Parameter_name = "产品码",
  1966. Parameter_value = sn,
  1967. Parameter_unit = ""
  1968. });
  1969. items.Add(new TestItem()
  1970. {
  1971. Parameter_name = "部件码",
  1972. Parameter_value = PartBarcode,
  1973. Parameter_unit = ""
  1974. });
  1975. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1976. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  1977. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1978. stopwatch2.Start();
  1979. //进站结果写入PLC
  1980. CommandFromPLC resultToPlC = new CommandFromPLC();
  1981. resultToPlC.cmd = 0;
  1982. resultToPlC.cmdParam = 0; //指令参数
  1983. resultToPlC.cmdResult = mesResultFrmWeb;
  1984. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1985. stopwatch2.Stop();
  1986. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1987. //保存PLC返回MES数据到本地
  1988. ResponseMessage message = new ResponseMessage();
  1989. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  1990. if (message.result == false)
  1991. {
  1992. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1993. }
  1994. if (!string.IsNullOrEmpty(PartBarcode))
  1995. {
  1996. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  1997. if (message.result == false)
  1998. {
  1999. AddMessage(LogType.Error, message.text);
  2000. }
  2001. }
  2002. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2003. }
  2004. catch (Exception ex)
  2005. {
  2006. stopwatch2.Start();
  2007. CommandFromPLC resultToPlC = new CommandFromPLC();
  2008. resultToPlC.cmd = 0;
  2009. resultToPlC.cmdParam = 0; //指令参数
  2010. resultToPlC.cmdResult = 110;
  2011. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2012. stopwatch2.Stop();
  2013. string str = ex.StackTrace;
  2014. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2015. }
  2016. stopwatch1.Stop();
  2017. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2018. ProgressState = false;
  2019. }
  2020. #endregion
  2021. #region S3
  2022. /// <summary>
  2023. /// [S3] 点散热胶装备
  2024. /// </summary>
  2025. /// <param name="plcNo">PLC编号</param>
  2026. private void ReadStation_S3(int plcNo)
  2027. {
  2028. string stationCode = "[OP30]";
  2029. string stationName = "点散热胶装备";
  2030. string stationNameStr = stationCode + stationName;
  2031. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2032. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2033. string tagAgvCommName = "agvCommFrmPC";
  2034. string tagBarsetName = "BarcodeSet";
  2035. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2036. (int, string) result;
  2037. #region 创建字典
  2038. // 触发信号字典 赋值
  2039. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2040. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2041. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2042. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2043. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2044. // PLC数据字典 赋值
  2045. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2046. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2047. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2048. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2049. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2050. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2051. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2052. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2053. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2054. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2055. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2056. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2057. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2058. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2059. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2060. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2061. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2062. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2063. s3PLCData.Add("c1Result", 0); // 产品结果
  2064. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2065. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2066. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2067. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2068. #endregion 创建字典
  2069. while (true)
  2070. {
  2071. try
  2072. {
  2073. if (!GlobalContext._IsCon_Funs2)
  2074. {
  2075. UpdatePLCMonitor(1, plcNo, 0);
  2076. continue;
  2077. }
  2078. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2079. {
  2080. Stopwatch stopwatch1 = new Stopwatch();
  2081. Stopwatch stopwatch2 = new Stopwatch();
  2082. stopwatch1.Start();
  2083. stopwatch2.Start();
  2084. #region 一次性读取所有数据
  2085. // 一次性读取所有数据
  2086. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2087. if (result.Item1 != 0)
  2088. {
  2089. //richTextBox1.AppendText("\n" + strRet);
  2090. }
  2091. else
  2092. {
  2093. //richTextBox1.AppendText("\n" + "读取成功");
  2094. }
  2095. #endregion 一次性读取所有数据
  2096. stopwatch2.Stop();
  2097. #region 左边进站
  2098. try
  2099. {
  2100. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2101. {
  2102. lock (lockObj)
  2103. {
  2104. if (!ProgressState)
  2105. {
  2106. ProgressState = true;
  2107. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2108. }
  2109. }
  2110. }
  2111. }
  2112. catch (Exception ex)
  2113. {
  2114. ProgressState = false;
  2115. string str = ex.StackTrace;
  2116. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2117. }
  2118. #endregion 左边进站
  2119. #region 左边出站
  2120. try
  2121. {
  2122. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2123. {
  2124. lock (lockObj)
  2125. {
  2126. if (!ProgressState)
  2127. {
  2128. ProgressState = true;
  2129. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2130. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  2131. }
  2132. }
  2133. }
  2134. }
  2135. catch (Exception ex)
  2136. {
  2137. ProgressState = false;
  2138. string str = ex.StackTrace;
  2139. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2140. }
  2141. #endregion 左边出站
  2142. #region 右边进站
  2143. try
  2144. {
  2145. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2146. {
  2147. lock (lockObj)
  2148. {
  2149. if (!ProgressState)
  2150. {
  2151. ProgressState = true;
  2152. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2153. }
  2154. }
  2155. }
  2156. }
  2157. catch (Exception ex)
  2158. {
  2159. ProgressState = false;
  2160. string str = ex.StackTrace;
  2161. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2162. }
  2163. #endregion 右边进站
  2164. #region 右边出站
  2165. try
  2166. {
  2167. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2168. {
  2169. lock (lockObj)
  2170. {
  2171. if (!ProgressState)
  2172. {
  2173. ProgressState = true;
  2174. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2175. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  2176. }
  2177. }
  2178. }
  2179. }
  2180. catch (Exception ex)
  2181. {
  2182. string str = ex.StackTrace;
  2183. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2184. }
  2185. #endregion 右边出站
  2186. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2187. stopwatch1.Stop();
  2188. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2189. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2190. }
  2191. else
  2192. {
  2193. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2194. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2195. FunsEip[plcNo].Connect();
  2196. }
  2197. }
  2198. catch (Exception ex)
  2199. {
  2200. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2201. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2202. //Funs[plcNo].ReConnect();
  2203. }
  2204. Thread.Sleep(IntervalReadPLC);
  2205. }
  2206. }
  2207. /// <summary>
  2208. /// [S3] 点散热胶装备 - 进站
  2209. /// </summary>
  2210. /// <param name="plcNo">PLC编号</param>
  2211. /// <param name="stationNameStr">工站全称</param>
  2212. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2213. {
  2214. Stopwatch stopwatch1 = new Stopwatch();
  2215. Stopwatch stopwatch2 = new Stopwatch();
  2216. try
  2217. {
  2218. stopwatch1.Start();
  2219. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2220. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2221. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2222. string StationId=string.Empty;
  2223. if (direction=="Left")
  2224. {
  2225. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2226. }
  2227. if (direction == "Right")
  2228. {
  2229. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2230. }
  2231. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2232. //载具码验证产品码
  2233. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2234. if (string.IsNullOrEmpty(strProductBarcode))
  2235. {
  2236. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2237. }
  2238. sn = strProductBarcode;
  2239. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2240. // 产品SN(物料码)校验
  2241. List<TestItem> item = new List<TestItem>();
  2242. stopwatch2.Start();
  2243. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2244. stopwatch2.Stop();
  2245. //指令执行结果 1:OK 110:失败
  2246. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2247. //进站结果写入PLC
  2248. CommandFromPLC resultToPlC = new CommandFromPLC();
  2249. resultToPlC.cmd = 0;
  2250. resultToPlC.cmdParam = 0; //指令参数
  2251. resultToPlC.cmdResult = mesResultFrmWeb;
  2252. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2253. }
  2254. catch (Exception ex)
  2255. {
  2256. string str = ex.StackTrace;
  2257. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2258. CommandFromPLC resultToPlC = new CommandFromPLC();
  2259. resultToPlC.cmd = 0;
  2260. resultToPlC.cmdParam = 0; //指令参数
  2261. resultToPlC.cmdResult = 110;
  2262. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2263. }
  2264. stopwatch1.Stop();
  2265. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2266. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2267. ProgressState = false;
  2268. }
  2269. /// <summary>
  2270. /// [S3] 点散热胶装备 - 出站
  2271. /// </summary>
  2272. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2273. {
  2274. Stopwatch stopwatch1 = new Stopwatch();
  2275. Stopwatch stopwatch2 = new Stopwatch();
  2276. try
  2277. {
  2278. stopwatch1.Start();
  2279. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2280. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2281. string processItem = stationName; // 测试项目
  2282. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2283. string supplierCode = ""; // 供应商代码
  2284. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2285. string batch_num = GlobalContext.BatchNumber; // 批次号
  2286. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2287. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2288. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2289. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2290. string StationId = string.Empty;
  2291. if (direction == "Left")
  2292. {
  2293. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2294. }
  2295. if (direction == "Right")
  2296. {
  2297. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2298. }
  2299. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2300. bool pass = a1Result == 1;
  2301. //根据载具码获取产品码
  2302. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2303. if (string.IsNullOrEmpty(strProductBarcode))
  2304. {
  2305. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2306. }
  2307. sn = strProductBarcode;
  2308. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2309. List<TestItem> items = new List<TestItem>();
  2310. items.Add(new TestItem()
  2311. {
  2312. Parameter_name = "载具码",
  2313. Parameter_value = CarrierBarcode,
  2314. Parameter_unit = ""
  2315. });
  2316. items.Add(new TestItem()
  2317. {
  2318. Parameter_name = "产品码",
  2319. Parameter_value = sn,
  2320. Parameter_unit = ""
  2321. });
  2322. int result1 = 1;
  2323. if (direction == "Right")
  2324. {
  2325. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2326. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2327. }
  2328. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2329. stopwatch2.Start();
  2330. //进站结果写入PLC
  2331. CommandFromPLC resultToPlC = new CommandFromPLC();
  2332. resultToPlC.cmd = 0;
  2333. resultToPlC.cmdParam = 0; //指令参数
  2334. resultToPlC.cmdResult = mesResultFrmWeb;
  2335. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2336. stopwatch2.Stop();
  2337. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2338. //保存PLC返回MES数据到本地
  2339. ResponseMessage message = new ResponseMessage();
  2340. if (direction == "Left")
  2341. {
  2342. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2343. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2344. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2345. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2346. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2347. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2348. if (message.result == false)
  2349. {
  2350. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2351. }
  2352. }
  2353. if (direction == "Right")
  2354. {
  2355. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2356. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2357. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2358. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2359. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2360. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2361. if (message.result == false)
  2362. {
  2363. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2364. }
  2365. }
  2366. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2367. }
  2368. catch (Exception ex)
  2369. {
  2370. stopwatch2.Start();
  2371. CommandFromPLC resultToPlC = new CommandFromPLC();
  2372. resultToPlC.cmd = 0;
  2373. resultToPlC.cmdParam = 0; //指令参数
  2374. resultToPlC.cmdResult = 110;
  2375. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2376. stopwatch2.Stop();
  2377. string str = ex.StackTrace;
  2378. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2379. }
  2380. stopwatch1.Stop();
  2381. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2382. ProgressState = false;
  2383. }
  2384. #endregion S3
  2385. #region S4
  2386. /// <summary>
  2387. /// [S4] 点胶检测设备
  2388. /// </summary>
  2389. /// <param name="plcNo">PLC编号</param>
  2390. private void ReadStation_S4(int plcNo)
  2391. {
  2392. string stationCode = "[OP40]";
  2393. string stationName = "胶线检测";
  2394. string stationNameStr = stationCode + stationName;
  2395. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2396. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2397. string tagAgvCommName = "agvCommFrmPC";
  2398. string tagBarsetName = "BarcodeSet";
  2399. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2400. (int, string) result;
  2401. while (true)
  2402. {
  2403. try
  2404. {
  2405. if (!GlobalContext._IsCon_Funs1)
  2406. {
  2407. UpdatePLCMonitor(1, plcNo, 0);
  2408. continue;
  2409. }
  2410. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2411. {
  2412. Stopwatch stopwatch1 = new Stopwatch();
  2413. Stopwatch stopwatch2 = new Stopwatch();
  2414. stopwatch1.Start();
  2415. stopwatch2.Start();
  2416. #region 一次性读取所有数据
  2417. // 一次性读取所有数据
  2418. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2419. if (result.Item1 != 0)
  2420. {
  2421. //richTextBox1.AppendText("\n" + strRet);
  2422. }
  2423. else
  2424. {
  2425. //richTextBox1.AppendText("\n" + "读取成功");
  2426. }
  2427. #endregion 一次性读取所有数据
  2428. stopwatch2.Stop();
  2429. #region 进站
  2430. try
  2431. {
  2432. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2433. {
  2434. lock (lockObj)
  2435. {
  2436. if (!ProgressState)
  2437. {
  2438. ProgressState = true;
  2439. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2440. }
  2441. }
  2442. }
  2443. }
  2444. catch (Exception ex)
  2445. {
  2446. ProgressState = false;
  2447. string str = ex.StackTrace;
  2448. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2449. }
  2450. #endregion 进站
  2451. #region 出站
  2452. try
  2453. {
  2454. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2455. {
  2456. lock (lockObj)
  2457. {
  2458. if (!ProgressState)
  2459. {
  2460. ProgressState = true;
  2461. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2462. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2463. }
  2464. }
  2465. }
  2466. }
  2467. catch (Exception ex)
  2468. {
  2469. string str = ex.StackTrace;
  2470. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2471. }
  2472. #endregion 出站
  2473. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2474. stopwatch1.Stop();
  2475. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2476. }
  2477. else
  2478. {
  2479. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2480. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2481. FunsEip[plcNo].Connect(); // 重连
  2482. }
  2483. }
  2484. catch (Exception ex)
  2485. {
  2486. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2487. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2488. }
  2489. Thread.Sleep(IntervalReadPLC);
  2490. }
  2491. }
  2492. /// <summary>
  2493. /// [S4] 点胶检测设备 - 进站
  2494. /// </summary>
  2495. /// <param name="plcNo">PLC编号</param>
  2496. /// <param name="stationNameStr">工站全称</param>
  2497. /// <param name="stPLC_MesData"></param>
  2498. /// <param name="tagMesCommName"></param>
  2499. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2500. {
  2501. Stopwatch stopwatch1 = new Stopwatch();
  2502. Stopwatch stopwatch2 = new Stopwatch();
  2503. try
  2504. {
  2505. stopwatch1.Start();
  2506. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2507. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2508. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2509. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2510. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2511. //载具码验证产品码
  2512. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2513. if (string.IsNullOrEmpty(strProductBarcode))
  2514. {
  2515. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2516. }
  2517. sn = strProductBarcode;
  2518. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2519. // 产品SN(物料码)校验
  2520. List<TestItem> item = new List<TestItem>();
  2521. stopwatch2.Start();
  2522. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2523. stopwatch2.Stop();
  2524. //指令执行结果 1:OK 110:失败
  2525. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2526. //进站结果写入PLC
  2527. CommandFromPLC resultToPlC = new CommandFromPLC();
  2528. resultToPlC.cmd = 0;
  2529. resultToPlC.cmdParam = 0; //指令参数
  2530. resultToPlC.cmdResult = mesResultFrmWeb;
  2531. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2532. }
  2533. catch (Exception ex)
  2534. {
  2535. string str = ex.StackTrace;
  2536. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2537. CommandFromPLC resultToPlC = new CommandFromPLC();
  2538. resultToPlC.cmd = 0;
  2539. resultToPlC.cmdParam = 0; //指令参数
  2540. resultToPlC.cmdResult = 110;
  2541. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2542. }
  2543. stopwatch1.Stop();
  2544. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2545. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2546. ProgressState = false;
  2547. }
  2548. /// <summary>
  2549. /// [S4] 点胶检测设备 - 出站接口
  2550. /// </summary>
  2551. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2552. {
  2553. Stopwatch stopwatch1 = new Stopwatch();
  2554. Stopwatch stopwatch2 = new Stopwatch();
  2555. try
  2556. {
  2557. stopwatch1.Start();
  2558. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2559. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2560. string processItem = stationName; // 测试项目
  2561. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2562. string supplierCode = ""; // 供应商代码
  2563. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2564. string batch_num = GlobalContext.BatchNumber; // 批次号
  2565. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2566. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2567. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2568. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2569. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2570. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2571. bool pass = a1Result == 1;
  2572. //根据载具码获取产品码
  2573. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2574. if (string.IsNullOrEmpty(strProductBarcode))
  2575. {
  2576. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2577. }
  2578. sn = strProductBarcode;
  2579. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2580. List<TestItem> items = new List<TestItem>();
  2581. items.Add(new TestItem()
  2582. {
  2583. Parameter_name = "载具码",
  2584. Parameter_value = CarrierBarcode,
  2585. Parameter_unit = ""
  2586. });
  2587. items.Add(new TestItem()
  2588. {
  2589. Parameter_name = "产品码",
  2590. Parameter_value = sn,
  2591. Parameter_unit = ""
  2592. });
  2593. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2594. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2595. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2596. stopwatch2.Start();
  2597. //进站结果写入PLC
  2598. CommandFromPLC resultToPlC = new CommandFromPLC();
  2599. resultToPlC.cmd = 0;
  2600. resultToPlC.cmdParam = 0; //指令参数
  2601. resultToPlC.cmdResult = mesResultFrmWeb;
  2602. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2603. stopwatch2.Stop();
  2604. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2605. //保存PLC返回MES数据到本地
  2606. ResponseMessage message = new ResponseMessage();
  2607. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2608. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2609. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2610. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2611. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2612. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2613. if (message.result == false)
  2614. {
  2615. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2616. }
  2617. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2618. }
  2619. catch (Exception ex)
  2620. {
  2621. stopwatch2.Start();
  2622. CommandFromPLC resultToPlC = new CommandFromPLC();
  2623. resultToPlC.cmd = 0;
  2624. resultToPlC.cmdParam = 0; //指令参数
  2625. resultToPlC.cmdResult = 110;
  2626. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2627. stopwatch2.Stop();
  2628. string str = ex.StackTrace;
  2629. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2630. }
  2631. stopwatch1.Stop();
  2632. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2633. ProgressState = false;
  2634. }
  2635. #endregion
  2636. #region S5
  2637. /// <summary>
  2638. /// [S5] 点胶检测设备
  2639. /// </summary>
  2640. /// <param name="plcNo">PLC编号</param>
  2641. private void ReadStation_S5(int plcNo)
  2642. {
  2643. string stationCode = "[OP50]";
  2644. string stationName = "ADD板上料组装装备";
  2645. string stationNameStr = stationCode + stationName;
  2646. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2647. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2648. string tagAgvCommName = "agvCommFrmPC";
  2649. string tagBarsetName = "BarcodeSet";
  2650. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2651. (int, string) result;
  2652. while (true)
  2653. {
  2654. try
  2655. {
  2656. if (!GlobalContext._IsCon_Funs1)
  2657. {
  2658. UpdatePLCMonitor(1, plcNo, 0);
  2659. continue;
  2660. }
  2661. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2662. {
  2663. Stopwatch stopwatch1 = new Stopwatch();
  2664. Stopwatch stopwatch2 = new Stopwatch();
  2665. stopwatch1.Start();
  2666. stopwatch2.Start();
  2667. #region 一次性读取所有数据
  2668. // 一次性读取所有数据
  2669. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2670. if (result.Item1 != 0)
  2671. {
  2672. //richTextBox1.AppendText("\n" + strRet);
  2673. }
  2674. else
  2675. {
  2676. //richTextBox1.AppendText("\n" + "读取成功");
  2677. }
  2678. #endregion 一次性读取所有数据
  2679. stopwatch2.Stop();
  2680. #region 进站
  2681. try
  2682. {
  2683. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2684. {
  2685. lock (lockObj)
  2686. {
  2687. if (!ProgressState)
  2688. {
  2689. ProgressState = true;
  2690. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2691. }
  2692. }
  2693. }
  2694. }
  2695. catch (Exception ex)
  2696. {
  2697. ProgressState = false;
  2698. string str = ex.StackTrace;
  2699. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2700. }
  2701. #endregion 进站
  2702. #region 出站
  2703. try
  2704. {
  2705. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2706. {
  2707. lock (lockObj)
  2708. {
  2709. if (!ProgressState)
  2710. {
  2711. ProgressState = true;
  2712. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2713. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2714. }
  2715. }
  2716. }
  2717. }
  2718. catch (Exception ex)
  2719. {
  2720. ProgressState = false;
  2721. string str = ex.StackTrace;
  2722. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2723. }
  2724. #endregion 出站
  2725. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2726. stopwatch1.Stop();
  2727. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2728. }
  2729. else
  2730. {
  2731. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2732. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2733. FunsEip[plcNo].Connect(); // 重连
  2734. }
  2735. }
  2736. catch (Exception ex)
  2737. {
  2738. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2739. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2740. }
  2741. Thread.Sleep(IntervalReadPLC);
  2742. }
  2743. }
  2744. /// <summary>
  2745. /// [S5] 点胶检测设备 - 进站
  2746. /// </summary>
  2747. /// <param name="plcNo">PLC编号</param>
  2748. /// <param name="stationNameStr">工站全称</param>
  2749. /// <param name="stPLC_MesData"></param>
  2750. /// <param name="tagMesCommName"></param>
  2751. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2752. {
  2753. Stopwatch stopwatch1 = new Stopwatch();
  2754. Stopwatch stopwatch2 = new Stopwatch();
  2755. try
  2756. {
  2757. stopwatch1.Start();
  2758. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2759. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2760. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2761. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2762. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2763. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  2764. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  2765. //绑定载具和产品
  2766. ResponseMessage message = new ResponseMessage();
  2767. message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
  2768. if (message.result == false)
  2769. {
  2770. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  2771. }
  2772. //载具码验证产品码 //载具码验证产品码
  2773. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2774. if (string.IsNullOrEmpty(strProductBarcode))
  2775. {
  2776. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2777. }
  2778. sn = strProductBarcode;
  2779. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  2780. // 产品SN(物料码)校验
  2781. List<TestItem> item = new List<TestItem>();
  2782. stopwatch2.Start();
  2783. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2784. stopwatch2.Stop();
  2785. //指令执行结果 1:OK 110:失败
  2786. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2787. //进站结果写入PLC
  2788. CommandFromPLC resultToPlC = new CommandFromPLC();
  2789. resultToPlC.cmd = 0;
  2790. resultToPlC.cmdParam = 0; //指令参数
  2791. resultToPlC.cmdResult = mesResultFrmWeb;
  2792. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2793. }
  2794. catch (Exception ex)
  2795. {
  2796. string str = ex.StackTrace;
  2797. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2798. CommandFromPLC resultToPlC = new CommandFromPLC();
  2799. resultToPlC.cmd = 0;
  2800. resultToPlC.cmdParam = 0; //指令参数
  2801. resultToPlC.cmdResult = 110;
  2802. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2803. }
  2804. stopwatch1.Stop();
  2805. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2806. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2807. ProgressState = false;
  2808. }
  2809. /// <summary>
  2810. /// [S5] 点胶检测设备 - 出站接口
  2811. /// </summary>
  2812. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2813. {
  2814. Stopwatch stopwatch1 = new Stopwatch();
  2815. Stopwatch stopwatch2 = new Stopwatch();
  2816. try
  2817. {
  2818. stopwatch1.Start();
  2819. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2820. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2821. string processItem = stationName; // 测试项目
  2822. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2823. string supplierCode = ""; // 供应商代码
  2824. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2825. string batch_num = GlobalContext.BatchNumber; // 批次号
  2826. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2827. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2828. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2829. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2830. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2831. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2832. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2833. bool pass = a1Result == 1;
  2834. //根据载具码获取产品码
  2835. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2836. if (string.IsNullOrEmpty(strProductBarcode))
  2837. {
  2838. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2839. }
  2840. sn = strProductBarcode;
  2841. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2842. List<TestItem> items = new List<TestItem>();
  2843. items.Add(new TestItem()
  2844. {
  2845. Parameter_name = "载具码",
  2846. Parameter_value = CarrierBarcode,
  2847. Parameter_unit = ""
  2848. });
  2849. items.Add(new TestItem()
  2850. {
  2851. Parameter_name = "产品码",
  2852. Parameter_value = sn,
  2853. Parameter_unit = ""
  2854. });
  2855. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2856. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2857. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2858. stopwatch2.Start();
  2859. //进站结果写入PLC
  2860. CommandFromPLC resultToPlC = new CommandFromPLC();
  2861. resultToPlC.cmd = 0;
  2862. resultToPlC.cmdParam = 0; //指令参数
  2863. resultToPlC.cmdResult = mesResultFrmWeb;
  2864. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2865. stopwatch2.Stop();
  2866. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2867. //保存PLC返回MES数据到本地
  2868. ResponseMessage message = new ResponseMessage();
  2869. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  2870. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  2871. if (message.result == false)
  2872. {
  2873. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2874. }
  2875. //保存部件码信息
  2876. if (!string.IsNullOrEmpty(PartBarcode))
  2877. {
  2878. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  2879. if (message.result == false)
  2880. {
  2881. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  2882. }
  2883. }
  2884. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2885. }
  2886. catch (Exception ex)
  2887. {
  2888. stopwatch2.Start();
  2889. CommandFromPLC resultToPlC = new CommandFromPLC();
  2890. resultToPlC.cmd = 0;
  2891. resultToPlC.cmdParam = 0; //指令参数
  2892. resultToPlC.cmdResult = 110;
  2893. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2894. stopwatch2.Stop();
  2895. string str = ex.StackTrace;
  2896. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2897. }
  2898. stopwatch1.Stop();
  2899. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2900. ProgressState = false;
  2901. }
  2902. #endregion
  2903. #region S6
  2904. /// <summary>
  2905. /// [S6] 顶盖装配设备
  2906. /// </summary>
  2907. /// <param name="plcNo">PLC编号</param>
  2908. private void ReadStation_S6(int plcNo)
  2909. {
  2910. string stationCode = "[OP60]";
  2911. string stationName = "组上盖板";
  2912. string stationNameStr = stationCode + stationName;
  2913. string tagBaseName = "g_OP60_MES"; //标签变量名称
  2914. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2915. string tagAgvCommName = "agvCommFrmPC";
  2916. string tagBarsetName = "BarcodeSet";
  2917. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  2918. (int, string) result;
  2919. while (true)
  2920. {
  2921. try
  2922. {
  2923. if (!GlobalContext._IsCon_Funs1)
  2924. {
  2925. UpdatePLCMonitor(1, plcNo, 0);
  2926. continue;
  2927. }
  2928. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2929. {
  2930. Stopwatch stopwatch1 = new Stopwatch();
  2931. Stopwatch stopwatch2 = new Stopwatch();
  2932. stopwatch1.Start();
  2933. stopwatch2.Start();
  2934. #region 一次性读取所有数据
  2935. // 一次性读取所有数据
  2936. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2937. if (result.Item1 != 0)
  2938. {
  2939. //richTextBox1.AppendText("\n" + strRet);
  2940. }
  2941. else
  2942. {
  2943. //richTextBox1.AppendText("\n" + "读取成功");
  2944. }
  2945. #endregion 一次性读取所有数据
  2946. stopwatch2.Stop();
  2947. #region 进站
  2948. try
  2949. {
  2950. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2951. {
  2952. lock (lockObj)
  2953. {
  2954. if (!ProgressState)
  2955. {
  2956. ProgressState = true;
  2957. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2958. }
  2959. }
  2960. }
  2961. }
  2962. catch (Exception ex)
  2963. {
  2964. ProgressState = false;
  2965. string str = ex.StackTrace;
  2966. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2967. }
  2968. #endregion 进站
  2969. #region 出站
  2970. try
  2971. {
  2972. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2973. {
  2974. lock (lockObj)
  2975. {
  2976. if (!ProgressState)
  2977. {
  2978. ProgressState = true; ;
  2979. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2980. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2981. }
  2982. }
  2983. }
  2984. }
  2985. catch (Exception ex)
  2986. {
  2987. ProgressState = false;
  2988. string str = ex.StackTrace;
  2989. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2990. }
  2991. #endregion 出站
  2992. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2993. stopwatch1.Stop();
  2994. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2995. }
  2996. else
  2997. {
  2998. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2999. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3000. FunsEip[plcNo].Connect(); // 重连
  3001. }
  3002. }
  3003. catch (Exception ex)
  3004. {
  3005. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3006. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3007. }
  3008. Thread.Sleep(IntervalReadPLC);
  3009. }
  3010. }
  3011. /// <summary>
  3012. /// [S6] 顶盖装配设备 - 进站
  3013. /// </summary>
  3014. /// <param name="plcNo">PLC编号</param>
  3015. /// <param name="stationNameStr">工站全称</param>
  3016. /// <param name="stPLC_MesData"></param>
  3017. /// <param name="tagMesCommName"></param>
  3018. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3019. {
  3020. Stopwatch stopwatch1 = new Stopwatch();
  3021. Stopwatch stopwatch2 = new Stopwatch();
  3022. try
  3023. {
  3024. stopwatch1.Start();
  3025. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3026. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3027. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3028. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3029. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3030. strCarrierBarcode = "N801A-003";
  3031. //载具码验证产品码
  3032. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3033. if (string.IsNullOrEmpty(strProductBarcode))
  3034. {
  3035. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3036. }
  3037. sn = strProductBarcode;
  3038. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3039. if (OpenDailogFalg)
  3040. {
  3041. using (var dialog = new BandBarodeDialog())
  3042. {
  3043. dialog._CarrierBarcode = strCarrierBarcode;
  3044. dialog._ProductBarcode = sn;
  3045. var rs = dialog.ShowDialog();
  3046. if (rs == DialogResult.OK)
  3047. {
  3048. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  3049. OpenDailogFalg = false;//关闭扫码
  3050. }
  3051. }
  3052. }
  3053. // 产品SN(物料码)校验
  3054. List<TestItem> item = new List<TestItem>();
  3055. stopwatch2.Start();
  3056. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3057. stopwatch2.Stop();
  3058. //指令执行结果 1:OK 110:失败
  3059. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3060. //进站结果写入PLC
  3061. CommandFromPLC resultToPlC = new CommandFromPLC();
  3062. resultToPlC.cmd = 0;
  3063. resultToPlC.cmdParam = 0; //指令参数
  3064. resultToPlC.cmdResult = mesResultFrmWeb;
  3065. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3066. }
  3067. catch (Exception ex)
  3068. {
  3069. string str = ex.StackTrace;
  3070. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3071. CommandFromPLC resultToPlC = new CommandFromPLC();
  3072. resultToPlC.cmd = 0;
  3073. resultToPlC.cmdParam = 0; //指令参数
  3074. resultToPlC.cmdResult = 110;
  3075. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3076. }
  3077. stopwatch1.Stop();
  3078. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3079. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3080. ProgressState = false;
  3081. OpenDailogFalg = true; //开启下一个物料的扫码
  3082. }
  3083. /// <summary>
  3084. /// [S6] 顶盖装配设备 - 出站接口
  3085. /// </summary>
  3086. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3087. {
  3088. Stopwatch stopwatch1 = new Stopwatch();
  3089. Stopwatch stopwatch2 = new Stopwatch();
  3090. try
  3091. {
  3092. stopwatch1.Start();
  3093. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3094. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3095. string processItem = stationName; // 测试项目
  3096. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3097. string supplierCode = ""; // 供应商代码
  3098. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3099. string batch_num = GlobalContext.BatchNumber; // 批次号
  3100. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3101. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3102. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3103. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3104. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3105. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3106. bool pass = a1Result == 1;
  3107. //根据载具码获取产品码
  3108. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3109. if (string.IsNullOrEmpty(strProductBarcode))
  3110. {
  3111. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3112. }
  3113. sn = strProductBarcode;
  3114. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3115. List<TestItem> items = new List<TestItem>();
  3116. items.Add(new TestItem()
  3117. {
  3118. Parameter_name = "载具码",
  3119. Parameter_value = CarrierBarcode,
  3120. Parameter_unit = ""
  3121. });
  3122. items.Add(new TestItem()
  3123. {
  3124. Parameter_name = "产品码",
  3125. Parameter_value = sn,
  3126. Parameter_unit = ""
  3127. });
  3128. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3129. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3130. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3131. stopwatch2.Start();
  3132. //进站结果写入PLC
  3133. CommandFromPLC resultToPlC = new CommandFromPLC();
  3134. resultToPlC.cmd = 0;
  3135. resultToPlC.cmdParam = 0; //指令参数
  3136. resultToPlC.cmdResult = mesResultFrmWeb;
  3137. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3138. stopwatch2.Stop();
  3139. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3140. //保存PLC返回MES数据到本地
  3141. ResponseMessage message = new ResponseMessage();
  3142. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3143. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3144. if (message.result == false)
  3145. {
  3146. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3147. }
  3148. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3149. }
  3150. catch (Exception ex)
  3151. {
  3152. stopwatch2.Start();
  3153. CommandFromPLC resultToPlC = new CommandFromPLC();
  3154. resultToPlC.cmd = 0;
  3155. resultToPlC.cmdParam = 0; //指令参数
  3156. resultToPlC.cmdResult = 110;
  3157. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3158. stopwatch2.Stop();
  3159. string str = ex.StackTrace;
  3160. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3161. }
  3162. stopwatch1.Stop();
  3163. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3164. ProgressState = false;
  3165. }
  3166. #endregion
  3167. #region S7
  3168. /// <summary>
  3169. /// [S7] 锁螺丝设备
  3170. /// </summary>
  3171. /// <param name="plcNo">PLC编号</param>
  3172. private void ReadStation_S7(int plcNo)
  3173. {
  3174. string stationCode = "[OP70]";
  3175. string stationName = "上盖板锁螺丝";
  3176. string stationNameStr = stationCode + stationName;
  3177. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3178. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3179. string tagAgvCommName = "agvCommFrmPC";
  3180. string tagBarsetName = "BarcodeSet";
  3181. string tagScrewDataset = "screwDataset";
  3182. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3183. (int, string) result;
  3184. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3185. atlasScrewLeft.Initial();
  3186. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3187. atlasScrewRight.Initial();
  3188. while (true)
  3189. {
  3190. try
  3191. {
  3192. if (!GlobalContext._IsCon_Funs1)
  3193. {
  3194. UpdatePLCMonitor(1, plcNo, 0);
  3195. continue;
  3196. }
  3197. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3198. {
  3199. Stopwatch stopwatch1 = new Stopwatch();
  3200. Stopwatch stopwatch2 = new Stopwatch();
  3201. stopwatch1.Start();
  3202. stopwatch2.Start();
  3203. #region 一次性读取所有数据
  3204. // 一次性读取所有数据
  3205. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3206. if (result.Item1 != 0)
  3207. {
  3208. //richTextBox1.AppendText("\n" + strRet);
  3209. }
  3210. else
  3211. {
  3212. //richTextBox1.AppendText("\n" + "读取成功");
  3213. }
  3214. #endregion 一次性读取所有数据
  3215. stopwatch2.Stop();
  3216. #region 左边进站
  3217. try
  3218. {
  3219. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3220. {
  3221. lock (lockObj)
  3222. {
  3223. if (!ProgressState)
  3224. {
  3225. ProgressState = true;
  3226. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3227. }
  3228. }
  3229. }
  3230. }
  3231. catch (Exception ex)
  3232. {
  3233. ProgressState = false;
  3234. string str = ex.StackTrace;
  3235. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3236. }
  3237. #endregion 左边进站
  3238. #region 左边出站
  3239. try
  3240. {
  3241. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3242. {
  3243. lock (lockObj)
  3244. {
  3245. if (!ProgressState)
  3246. {
  3247. ProgressState = true;
  3248. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3249. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3250. }
  3251. }
  3252. }
  3253. }
  3254. catch (Exception ex)
  3255. {
  3256. ProgressState = false;
  3257. string str = ex.StackTrace;
  3258. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3259. }
  3260. #endregion 左边出站
  3261. #region 右边进站
  3262. try
  3263. {
  3264. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3265. {
  3266. lock (lockObj)
  3267. {
  3268. if (!ProgressState)
  3269. {
  3270. ProgressState = true;
  3271. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3272. }
  3273. }
  3274. }
  3275. }
  3276. catch (Exception ex)
  3277. {
  3278. ProgressState = false;
  3279. string str = ex.StackTrace;
  3280. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3281. }
  3282. #endregion 右边进站
  3283. #region 右边出站
  3284. try
  3285. {
  3286. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3287. {
  3288. lock (lockObj)
  3289. {
  3290. if (!ProgressState)
  3291. {
  3292. ProgressState = true;
  3293. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3294. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3295. }
  3296. }
  3297. }
  3298. }
  3299. catch (Exception ex)
  3300. {
  3301. ProgressState = false;
  3302. string str = ex.StackTrace;
  3303. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3304. }
  3305. #endregion 右边出站
  3306. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3307. stopwatch1.Stop();
  3308. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3309. }
  3310. else
  3311. {
  3312. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3313. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3314. FunsEip[plcNo].Connect(); // 重连
  3315. }
  3316. }
  3317. catch (Exception ex)
  3318. {
  3319. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3320. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3321. }
  3322. Thread.Sleep(IntervalReadPLC);
  3323. }
  3324. }
  3325. /// <summary>
  3326. /// [S7] 锁螺丝设备 - 进站
  3327. /// </summary>
  3328. /// <param name="plcNo">PLC编号</param>
  3329. /// <param name="stationNameStr">工站全称</param>
  3330. /// <param name="stPLC_MesData"></param>
  3331. /// <param name="tagMesCommName"></param>
  3332. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3333. {
  3334. Stopwatch stopwatch1 = new Stopwatch();
  3335. Stopwatch stopwatch2 = new Stopwatch();
  3336. string atlasSn=string.Empty;
  3337. try
  3338. {
  3339. stopwatch1.Start();
  3340. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3341. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3342. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3343. string StationId = string.Empty; // 工位ID(可配置)
  3344. if (direction == "Left")
  3345. {
  3346. StationId = GlobalContext.S7_StationId_1;
  3347. }
  3348. if (direction == "Right")
  3349. {
  3350. StationId = GlobalContext.S7_StationId_2;
  3351. }
  3352. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3353. //载具码验证产品码
  3354. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3355. if (string.IsNullOrEmpty(strProductBarcode))
  3356. {
  3357. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3358. }
  3359. sn = strProductBarcode;
  3360. atlasSn= strProductBarcode;
  3361. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3362. if (direction == "Left")
  3363. {
  3364. isCollectingFlagLeft = false;//采集螺丝数据结束
  3365. }
  3366. if (direction == "Right")
  3367. {
  3368. isCollectingFlagRight = false;//采集螺丝数据结束
  3369. }
  3370. // 产品SN(物料码)校验
  3371. List<TestItem> item = new List<TestItem>();
  3372. stopwatch2.Start();
  3373. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3374. stopwatch2.Stop();
  3375. //指令执行结果 1:OK 110:失败
  3376. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3377. //进站结果写入PLC
  3378. CommandFromPLC resultToPlC = new CommandFromPLC();
  3379. resultToPlC.cmd = 0;
  3380. resultToPlC.cmdParam = 0; //指令参数
  3381. resultToPlC.cmdResult = mesResultFrmWeb;
  3382. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3383. }
  3384. catch (Exception ex)
  3385. {
  3386. string str = ex.StackTrace;
  3387. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3388. CommandFromPLC resultToPlC = new CommandFromPLC();
  3389. resultToPlC.cmd = 0;
  3390. resultToPlC.cmdParam = 0; //指令参数
  3391. resultToPlC.cmdResult = 110;
  3392. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3393. }
  3394. stopwatch1.Stop();
  3395. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3396. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3397. ProgressState = false;
  3398. //开始采集螺丝数据
  3399. if (direction == "Left")
  3400. {
  3401. isCollectingFlagLeft = true;
  3402. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3403. }
  3404. if (direction == "Right")
  3405. {
  3406. isCollectingFlagRight = true;
  3407. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3408. }
  3409. }
  3410. /// <summary>
  3411. /// [S7] 锁螺丝设备 - 出站
  3412. /// </summary>
  3413. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3414. {
  3415. Stopwatch stopwatch1 = new Stopwatch();
  3416. Stopwatch stopwatch2 = new Stopwatch();
  3417. try
  3418. {
  3419. stopwatch1.Start();
  3420. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3421. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3422. string processItem = stationName; // 测试项目
  3423. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3424. string supplierCode = ""; // 供应商代码
  3425. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3426. string batch_num = GlobalContext.BatchNumber; // 批次号
  3427. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3428. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3429. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3430. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3431. string StationId = string.Empty; // 工位ID(可配置)
  3432. if (direction == "Left")
  3433. {
  3434. StationId = GlobalContext.S7_StationId_1;
  3435. }
  3436. if (direction == "Right")
  3437. {
  3438. StationId = GlobalContext.S7_StationId_2;
  3439. }
  3440. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3441. a1Result = 1;
  3442. bool pass = a1Result == 1;
  3443. //根据载具码获取产品码
  3444. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3445. if (string.IsNullOrEmpty(strProductBarcode))
  3446. {
  3447. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3448. }
  3449. sn = strProductBarcode;
  3450. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3451. List<TestItem> items = new List<TestItem>();
  3452. items.Add(new TestItem()
  3453. {
  3454. Parameter_name = "载具码",
  3455. Parameter_value = CarrierBarcode,
  3456. Parameter_unit = ""
  3457. });
  3458. items.Add(new TestItem()
  3459. {
  3460. Parameter_name = "产品码",
  3461. Parameter_value = sn,
  3462. Parameter_unit = ""
  3463. });
  3464. int result1 = 1;
  3465. if (direction == "Right")
  3466. {
  3467. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3468. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3469. }
  3470. //if (direction == "Left")
  3471. //{
  3472. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3473. //}
  3474. //if (direction == "Right")
  3475. //{
  3476. // isCollectingFlagRight = false;//采集螺丝数据结束
  3477. //}
  3478. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3479. stopwatch2.Start();
  3480. //进站结果写入PLC
  3481. CommandFromPLC resultToPlC = new CommandFromPLC();
  3482. resultToPlC.cmd = 0;
  3483. resultToPlC.cmdParam = 0; //指令参数
  3484. resultToPlC.cmdResult = mesResultFrmWeb;
  3485. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3486. stopwatch2.Stop();
  3487. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3488. //保存PLC返回MES数据到本地
  3489. ResponseMessage message = new ResponseMessage();
  3490. if (direction == "Left")
  3491. {
  3492. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3493. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3494. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3495. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3496. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3497. if (message.result == false)
  3498. {
  3499. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3500. }
  3501. }
  3502. if (direction == "Right")
  3503. {
  3504. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3505. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3506. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3507. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3508. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3509. if (message.result == false)
  3510. {
  3511. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3512. }
  3513. }
  3514. //保存螺丝数据到txt
  3515. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3516. if (result.Item1 != 0)
  3517. {
  3518. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3519. }
  3520. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3521. }
  3522. catch (Exception ex)
  3523. {
  3524. stopwatch2.Start();
  3525. CommandFromPLC resultToPlC = new CommandFromPLC();
  3526. resultToPlC.cmd = 0;
  3527. resultToPlC.cmdParam = 0; //指令参数
  3528. resultToPlC.cmdResult = 110;
  3529. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3530. stopwatch2.Stop();
  3531. string str = ex.StackTrace;
  3532. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3533. }
  3534. stopwatch1.Stop();
  3535. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3536. ProgressState = false;
  3537. }
  3538. #endregion
  3539. #region S8
  3540. /// <summary>
  3541. /// [S8] 3D螺丝高度检测设备
  3542. /// </summary>
  3543. /// <param name="plcNo">PLC编号</param>
  3544. private void ReadStation_S8(int plcNo)
  3545. {
  3546. string stationCode = "[OP80]";
  3547. string stationName = "NG下料";
  3548. string stationNameStr = stationCode + stationName;
  3549. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3550. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3551. string tagAgvCommName = "agvCommFrmPC";
  3552. string tagBarsetName = "BarcodeSet";
  3553. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3554. (int, string) result;
  3555. while (true)
  3556. {
  3557. try
  3558. {
  3559. if (!GlobalContext._IsCon_Funs1)
  3560. {
  3561. UpdatePLCMonitor(1, plcNo, 0);
  3562. continue;
  3563. }
  3564. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3565. {
  3566. Stopwatch stopwatch1 = new Stopwatch();
  3567. Stopwatch stopwatch2 = new Stopwatch();
  3568. stopwatch1.Start();
  3569. stopwatch2.Start();
  3570. #region 一次性读取所有数据
  3571. // 一次性读取所有数据
  3572. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3573. if (result.Item1 != 0)
  3574. {
  3575. //richTextBox1.AppendText("\n" + strRet);
  3576. }
  3577. else
  3578. {
  3579. //richTextBox1.AppendText("\n" + "读取成功");
  3580. }
  3581. #endregion 一次性读取所有数据
  3582. stopwatch2.Stop();
  3583. #region 进站
  3584. try
  3585. {
  3586. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3587. {
  3588. lock (lockObj)
  3589. {
  3590. if (!ProgressState)
  3591. {
  3592. ProgressState = true;
  3593. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3594. }
  3595. }
  3596. }
  3597. }
  3598. catch (Exception ex)
  3599. {
  3600. ProgressState = false;
  3601. string str = ex.StackTrace;
  3602. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3603. }
  3604. #endregion 进站
  3605. #region 出站
  3606. try
  3607. {
  3608. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3609. {
  3610. lock (lockObj)
  3611. {
  3612. if (!ProgressState)
  3613. {
  3614. ProgressState = true;
  3615. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3616. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3617. }
  3618. }
  3619. }
  3620. }
  3621. catch (Exception ex)
  3622. {
  3623. ProgressState = false;
  3624. string str = ex.StackTrace;
  3625. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3626. }
  3627. #endregion 出站
  3628. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3629. stopwatch1.Stop();
  3630. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3631. }
  3632. else
  3633. {
  3634. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3635. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3636. FunsEip[plcNo].Connect(); // 重连
  3637. }
  3638. }
  3639. catch (Exception ex)
  3640. {
  3641. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3642. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3643. }
  3644. Thread.Sleep(IntervalReadPLC);
  3645. }
  3646. }
  3647. /// <summary>
  3648. /// [S8] 3D螺丝高度检测设备 - 进站
  3649. /// </summary>
  3650. /// <param name="plcNo">PLC编号</param>
  3651. /// <param name="stationNameStr">工站全称</param>
  3652. /// <param name="stPLC_MesData"></param>
  3653. /// <param name="tagMesCommName"></param>
  3654. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3655. {
  3656. Stopwatch stopwatch1 = new Stopwatch();
  3657. Stopwatch stopwatch2 = new Stopwatch();
  3658. try
  3659. {
  3660. stopwatch1.Start();
  3661. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3662. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3663. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3664. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3665. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3666. //载具码验证产品码
  3667. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3668. if (string.IsNullOrEmpty(strProductBarcode))
  3669. {
  3670. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3671. }
  3672. sn = strProductBarcode;
  3673. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3674. // 产品SN(物料码)校验
  3675. List<TestItem> item = new List<TestItem>();
  3676. stopwatch2.Start();
  3677. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3678. stopwatch2.Stop();
  3679. //指令执行结果 1:OK 110:失败
  3680. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3681. //进站结果写入PLC
  3682. CommandFromPLC resultToPlC = new CommandFromPLC();
  3683. resultToPlC.cmd = 0;
  3684. resultToPlC.cmdParam = 0; //指令参数
  3685. resultToPlC.cmdResult = mesResultFrmWeb;
  3686. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3687. }
  3688. catch (Exception ex)
  3689. {
  3690. string str = ex.StackTrace;
  3691. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3692. CommandFromPLC resultToPlC = new CommandFromPLC();
  3693. resultToPlC.cmd = 0;
  3694. resultToPlC.cmdParam = 0; //指令参数
  3695. resultToPlC.cmdResult = 110;
  3696. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3697. }
  3698. stopwatch1.Stop();
  3699. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3700. ProgressState = false;
  3701. }
  3702. /// <summary>
  3703. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3704. /// </summary>
  3705. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3706. {
  3707. Stopwatch stopwatch1 = new Stopwatch();
  3708. Stopwatch stopwatch2 = new Stopwatch();
  3709. try
  3710. {
  3711. stopwatch1.Start();
  3712. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3713. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3714. string processItem = stationName; // 测试项目
  3715. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3716. string supplierCode = ""; // 供应商代码
  3717. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3718. string batch_num = GlobalContext.BatchNumber; // 批次号
  3719. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3720. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3721. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3722. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3723. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3724. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3725. bool pass = a1Result == 1;
  3726. //根据载具码获取产品码
  3727. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3728. if (string.IsNullOrEmpty(strProductBarcode))
  3729. {
  3730. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3731. }
  3732. sn = strProductBarcode;
  3733. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3734. List<TestItem> items = new List<TestItem>();
  3735. items.Add(new TestItem()
  3736. {
  3737. Parameter_name = "载具码",
  3738. Parameter_value = CarrierBarcode,
  3739. Parameter_unit = ""
  3740. });
  3741. items.Add(new TestItem()
  3742. {
  3743. Parameter_name = "产品码",
  3744. Parameter_value = sn,
  3745. Parameter_unit = ""
  3746. });
  3747. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3748. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3749. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3750. stopwatch2.Start();
  3751. //进站结果写入PLC
  3752. CommandFromPLC resultToPlC = new CommandFromPLC();
  3753. resultToPlC.cmd = 0;
  3754. resultToPlC.cmdParam = 0; //指令参数
  3755. resultToPlC.cmdResult = mesResultFrmWeb;
  3756. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3757. stopwatch2.Stop();
  3758. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3759. //保存PLC返回MES数据到本地
  3760. ResponseMessage message = new ResponseMessage();
  3761. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3762. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3763. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3764. if (message.result == false)
  3765. {
  3766. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3767. }
  3768. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3769. }
  3770. catch (Exception ex)
  3771. {
  3772. stopwatch2.Start();
  3773. CommandFromPLC resultToPlC = new CommandFromPLC();
  3774. resultToPlC.cmd = 0;
  3775. resultToPlC.cmdParam = 0; //指令参数
  3776. resultToPlC.cmdResult = 110;
  3777. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3778. stopwatch2.Stop();
  3779. string str = ex.StackTrace;
  3780. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3781. }
  3782. stopwatch1.Stop();
  3783. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3784. ProgressState = false;
  3785. }
  3786. #endregion
  3787. #region S9
  3788. /// <summary>
  3789. /// [S9] 下料设备
  3790. /// </summary>
  3791. /// <param name="plcNo">PLC编号</param>
  3792. private void ReadStation_S9(int plcNo)
  3793. {
  3794. string stationCode = "[OP90]";
  3795. string stationName = "半成品下料";
  3796. string stationNameStr = stationCode + stationName;
  3797. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3798. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3799. string tagAgvCommName = "agvCommFrmPC";
  3800. string tagBarsetName = "BarcodeSet";
  3801. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3802. (int, string) result;
  3803. while (true)
  3804. {
  3805. try
  3806. {
  3807. if (!GlobalContext._IsCon_Funs1)
  3808. {
  3809. UpdatePLCMonitor(1, plcNo, 0);
  3810. continue;
  3811. }
  3812. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3813. {
  3814. Stopwatch stopwatch1 = new Stopwatch();
  3815. Stopwatch stopwatch2 = new Stopwatch();
  3816. stopwatch1.Start();
  3817. stopwatch2.Start();
  3818. #region 一次性读取所有数据
  3819. // 一次性读取所有数据
  3820. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3821. if (result.Item1 != 0)
  3822. {
  3823. //richTextBox1.AppendText("\n" + strRet);
  3824. }
  3825. else
  3826. {
  3827. //richTextBox1.AppendText("\n" + "读取成功");
  3828. }
  3829. #endregion 一次性读取所有数据
  3830. stopwatch2.Stop();
  3831. #region 进站
  3832. try
  3833. {
  3834. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3835. {
  3836. lock (lockObj)
  3837. {
  3838. if (!ProgressState)
  3839. {
  3840. ProgressState = true;
  3841. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3842. }
  3843. }
  3844. }
  3845. }
  3846. catch (Exception ex)
  3847. {
  3848. ProgressState = false;
  3849. string str = ex.StackTrace;
  3850. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3851. }
  3852. #endregion 进站
  3853. #region 出站
  3854. try
  3855. {
  3856. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3857. {
  3858. lock (lockObj)
  3859. {
  3860. if (!ProgressState)
  3861. {
  3862. ProgressState = true;
  3863. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3864. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3865. }
  3866. }
  3867. }
  3868. }
  3869. catch (Exception ex)
  3870. {
  3871. ProgressState = false;
  3872. string str = ex.StackTrace;
  3873. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3874. }
  3875. #endregion 出站
  3876. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3877. stopwatch1.Stop();
  3878. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3879. }
  3880. else
  3881. {
  3882. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3883. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3884. FunsEip[plcNo].Connect(); // 重连
  3885. }
  3886. }
  3887. catch (Exception ex)
  3888. {
  3889. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3890. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3891. }
  3892. Thread.Sleep(IntervalReadPLC);
  3893. }
  3894. }
  3895. /// <summary>
  3896. /// [S9] 下料设备 - 进站
  3897. /// </summary>
  3898. /// <param name="plcNo">PLC编号</param>
  3899. /// <param name="stationNameStr">工站全称</param>
  3900. /// <param name="stPLC_MesData"></param>
  3901. /// <param name="tagMesCommName"></param>
  3902. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3903. {
  3904. Stopwatch stopwatch1 = new Stopwatch();
  3905. Stopwatch stopwatch2 = new Stopwatch();
  3906. try
  3907. {
  3908. stopwatch1.Start();
  3909. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3910. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3911. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  3912. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  3913. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3914. //载具码验证产品码
  3915. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3916. if (string.IsNullOrEmpty(strProductBarcode))
  3917. {
  3918. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3919. }
  3920. sn = strProductBarcode;
  3921. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3922. // 产品SN(物料码)校验
  3923. List<TestItem> item = new List<TestItem>();
  3924. stopwatch2.Start();
  3925. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3926. stopwatch2.Stop();
  3927. //指令执行结果 1:OK 110:失败
  3928. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3929. //进站结果写入PLC
  3930. CommandFromPLC resultToPlC = new CommandFromPLC();
  3931. resultToPlC.cmd = 0;
  3932. resultToPlC.cmdParam = 0; //指令参数
  3933. resultToPlC.cmdResult = mesResultFrmWeb;
  3934. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3935. }
  3936. catch (Exception ex)
  3937. {
  3938. string str = ex.StackTrace;
  3939. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3940. CommandFromPLC resultToPlC = new CommandFromPLC();
  3941. resultToPlC.cmd = 0;
  3942. resultToPlC.cmdParam = 0; //指令参数
  3943. resultToPlC.cmdResult = 110;
  3944. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3945. }
  3946. stopwatch1.Stop();
  3947. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3948. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3949. ProgressState = false;
  3950. }
  3951. /// <summary>
  3952. /// [S9] 下料设备 - 出站接口
  3953. /// </summary>
  3954. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3955. {
  3956. Stopwatch stopwatch1 = new Stopwatch();
  3957. Stopwatch stopwatch2 = new Stopwatch();
  3958. try
  3959. {
  3960. stopwatch1.Start();
  3961. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3962. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3963. string processItem = stationName; // 测试项目
  3964. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3965. string supplierCode = ""; // 供应商代码
  3966. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3967. string batch_num = GlobalContext.BatchNumber; // 批次号
  3968. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3969. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3970. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3971. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  3972. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  3973. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3974. bool pass = a1Result == 1;
  3975. //根据载具码获取产品码
  3976. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3977. if (string.IsNullOrEmpty(strProductBarcode))
  3978. {
  3979. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3980. }
  3981. sn = strProductBarcode;
  3982. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3983. List<TestItem> items = new List<TestItem>();
  3984. items.Add(new TestItem()
  3985. {
  3986. Parameter_name = "载具码",
  3987. Parameter_value = CarrierBarcode,
  3988. Parameter_unit = ""
  3989. });
  3990. items.Add(new TestItem()
  3991. {
  3992. Parameter_name = "产品码",
  3993. Parameter_value = sn,
  3994. Parameter_unit = ""
  3995. });
  3996. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3997. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3998. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3999. stopwatch2.Start();
  4000. //进站结果写入PLC
  4001. CommandFromPLC resultToPlC = new CommandFromPLC();
  4002. resultToPlC.cmd = 0;
  4003. resultToPlC.cmdParam = 0; //指令参数
  4004. resultToPlC.cmdResult = mesResultFrmWeb;
  4005. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4006. stopwatch2.Stop();
  4007. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4008. //保存PLC返回MES数据到本地
  4009. ResponseMessage message = new ResponseMessage();
  4010. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4011. if (message.result == false)
  4012. {
  4013. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4014. }
  4015. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4016. if (result1 == 1)
  4017. {
  4018. //载具码解除绑定
  4019. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4020. if (message.result == false)
  4021. {
  4022. AddMessage(LogType.Error, message.text);
  4023. }
  4024. }
  4025. }
  4026. catch (Exception ex)
  4027. {
  4028. stopwatch2.Start();
  4029. CommandFromPLC resultToPlC = new CommandFromPLC();
  4030. resultToPlC.cmd = 0;
  4031. resultToPlC.cmdParam = 0; //指令参数
  4032. resultToPlC.cmdResult = 110;
  4033. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4034. stopwatch2.Stop();
  4035. string str = ex.StackTrace;
  4036. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4037. }
  4038. stopwatch1.Stop();
  4039. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4040. ProgressState = false;
  4041. }
  4042. #endregion
  4043. #endregion Xiaomi
  4044. #region PLC1 张超凡
  4045. #region [S1] Tray盘上料装备(板测)
  4046. /// <summary>
  4047. /// S1工位的数据- 触发信号上次的值
  4048. /// </summary>
  4049. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4050. /// <summary>
  4051. /// S1工位的数据(含触发信号)
  4052. /// </summary>
  4053. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4054. /// <summary>
  4055. /// S1工位的数据- 回写点位
  4056. /// </summary>
  4057. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4058. ///// <summary>
  4059. ///// 触发信号
  4060. ///// </summary>
  4061. //private ManualResetEvent[] MreTasks;
  4062. /// <summary>
  4063. /// [S1] Tray盘上料装备(板测)
  4064. /// </summary>
  4065. /// <param name="plcNo">PLC编号</param>
  4066. //private void ReadStation_S1(int plcNo)
  4067. //{
  4068. // // [S1] Tray盘上料装备
  4069. // // [S2] FCT
  4070. // // [S3] 值板机
  4071. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4072. // // [S5] Tray盘下料装备
  4073. // string stationCode = "[S1]";
  4074. // string stationName = "Tray盘上料装备";
  4075. // string stationNameStr = stationCode + stationName;
  4076. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4077. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4078. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4079. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4080. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4081. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4082. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4083. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4084. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4085. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4086. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4087. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4088. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4089. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4090. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4091. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4092. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4093. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4094. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4095. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4096. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4097. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4098. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4099. // s1PLCData.Add("a1Result", 0); // 产品结果
  4100. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4101. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4102. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4103. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4104. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4105. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4106. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4107. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4108. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4109. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4110. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4111. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4112. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4113. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4114. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4115. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4116. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4117. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4118. // while (IsRun)
  4119. // {
  4120. // try
  4121. // {
  4122. // if (!GlobalContext._IsCon_Funs1)
  4123. // {
  4124. // UpdatePLCMonitor(1, plcNo, 0);
  4125. // continue;
  4126. // }
  4127. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4128. // {
  4129. // Stopwatch stopwatch1 = new Stopwatch();
  4130. // Stopwatch stopwatch2 = new Stopwatch();
  4131. // stopwatch1.Start();
  4132. // stopwatch2.Start();
  4133. // #region 一次性读取所有数据
  4134. // // 一次性读取所有数据
  4135. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4136. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4137. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4138. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4139. // int[] datas = data1.Concat(data2).ToArray();
  4140. // datas = datas.Concat(data3).ToArray();
  4141. // datas = datas.Concat(data4).ToArray();
  4142. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4143. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4144. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4145. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4146. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4147. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4148. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4149. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4150. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4151. // s1PLCData["a1MES_FLAG"] = datas[109];
  4152. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4153. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4154. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4155. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4156. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4157. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4158. // s1PLCData["a1Result"] = datas[170];
  4159. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4160. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4161. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4162. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4163. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4164. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4165. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4166. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4167. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4168. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4169. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4170. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4171. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4172. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4173. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4174. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4175. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4176. // s1PLCData["a1AGVUpStart"] = datas[308];
  4177. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4178. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4179. // s1PLCData["a1AGVDownStart"] = datas[321];
  4180. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4181. // #endregion 一次性读取所有数据
  4182. // stopwatch2.Stop();
  4183. // #region 回写操作,写后清空flag
  4184. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4185. // #endregion 回写操作,写后清空flag
  4186. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4187. // try
  4188. // {
  4189. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4190. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4191. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4192. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4193. // {
  4194. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4195. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4196. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4197. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4198. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4199. // }
  4200. // }
  4201. // catch (Exception ex)
  4202. // {
  4203. // // 6代表上位机报警
  4204. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4205. // string str = ex.StackTrace;
  4206. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4207. // }
  4208. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4209. // #region 上料进站校验
  4210. // try
  4211. // {
  4212. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4213. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4214. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4215. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4216. // {
  4217. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4218. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4219. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4220. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4221. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4222. // }
  4223. // }
  4224. // catch (Exception ex)
  4225. // {
  4226. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4227. // string str = ex.StackTrace;
  4228. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4229. // }
  4230. // #endregion 上料进站校验
  4231. // #region Tray盘上料装备-出站接口
  4232. // try
  4233. // {
  4234. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4235. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4236. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4237. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4238. // {
  4239. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4240. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4241. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4242. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4243. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4244. // }
  4245. // }
  4246. // catch (Exception ex)
  4247. // {
  4248. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4249. // string str = ex.StackTrace;
  4250. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4251. // }
  4252. // #endregion Tray盘上料装备-出站接口
  4253. // #region Tray盘上料装备-将SN发给ICT标机
  4254. // try
  4255. // {
  4256. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4257. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4258. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4259. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4260. // {
  4261. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4262. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4263. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4264. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4265. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4266. // }
  4267. // }
  4268. // catch (Exception ex)
  4269. // {
  4270. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4271. // string str = ex.StackTrace;
  4272. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4273. // }
  4274. // #endregion Tray盘上料装备-将SN发给ICT标机
  4275. // #region Tray盘上料装备-点检数据
  4276. // //try
  4277. // //{
  4278. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4279. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4280. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4281. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4282. // // if (pLC_Flag && !mES_Flag) // 1 0
  4283. // // {
  4284. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4285. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4286. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4287. // // }
  4288. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4289. // // {
  4290. // // // 清空写给PLC的数据
  4291. // // // MES_Flag重置为0
  4292. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4293. // // }
  4294. // //}
  4295. // //catch (Exception ex)
  4296. // //{
  4297. // // // MES_Flag 为2上位机报错
  4298. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4299. // // string str = ex.StackTrace;
  4300. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4301. // //}
  4302. // #endregion Tray盘上料装备-点检数据
  4303. // #region 节拍接口
  4304. // try
  4305. // {
  4306. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4307. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4308. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4309. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4310. // {
  4311. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4312. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4313. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4314. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4315. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4316. // }
  4317. // }
  4318. // catch (Exception ex)
  4319. // {
  4320. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4321. // string str = ex.StackTrace;
  4322. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4323. // }
  4324. // #endregion 节拍接口
  4325. // #region AGV上料
  4326. // // AGV上料叫AGV信号
  4327. // try
  4328. // {
  4329. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4330. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4331. // if (a1AGVUpCall != a1AGVUpCallOld)
  4332. // {
  4333. // if (a1AGVUpCall == 1) // 0->1
  4334. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4335. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4336. // }
  4337. // }
  4338. // catch (Exception ex)
  4339. // {
  4340. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4341. // string str = ex.StackTrace;
  4342. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4343. // }
  4344. // // AGV上料完成信号
  4345. // try
  4346. // {
  4347. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4348. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4349. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4350. // {
  4351. // if (a1AGVUpEnd == 1) // 0->1
  4352. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4353. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4354. // }
  4355. // }
  4356. // catch (Exception ex)
  4357. // {
  4358. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4359. // string str = ex.StackTrace;
  4360. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4361. // }
  4362. // #endregion AGV上料
  4363. // #region AGV下料
  4364. // // AGV下料叫agv信号
  4365. // try
  4366. // {
  4367. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4368. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4369. // if (a1AGVDownCall != a1AGVDownCallOld)
  4370. // {
  4371. // if (a1AGVDownCall == 1) // 0->1
  4372. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4373. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4374. // }
  4375. // }
  4376. // catch (Exception ex)
  4377. // {
  4378. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4379. // string str = ex.StackTrace;
  4380. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4381. // }
  4382. // // AGV下料完成信号
  4383. // try
  4384. // {
  4385. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4386. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4387. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4388. // {
  4389. // if (a1AGVDownEnd == 1) // 0->1
  4390. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4391. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4392. // }
  4393. // }
  4394. // catch (Exception ex)
  4395. // {
  4396. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4397. // string str = ex.StackTrace;
  4398. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4399. // }
  4400. // #endregion AGV下料
  4401. // #region 心跳
  4402. // try
  4403. // {
  4404. // short states = 0;
  4405. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4406. // }
  4407. // catch (Exception ex)
  4408. // {
  4409. // string str = ex.StackTrace;
  4410. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4411. // }
  4412. // #endregion 心跳
  4413. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4414. // stopwatch1.Stop();
  4415. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4416. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4417. // }
  4418. // else
  4419. // {
  4420. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4421. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4422. // Funs[plcNo].Connect(); // 重连
  4423. // }
  4424. // }
  4425. // catch (Exception ex)
  4426. // {
  4427. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4428. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4429. // Funs[plcNo].ReConnect();
  4430. // }
  4431. // Thread.Sleep(IntervalReadPLC);
  4432. // }
  4433. //}
  4434. /// <summary>
  4435. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4436. /// </summary>
  4437. /// <param name="plcNo">PLC编号</param>
  4438. /// <param name="stationNameStr">工站全称</param>
  4439. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4440. {
  4441. Stopwatch stopwatch1 = new Stopwatch();
  4442. Stopwatch stopwatch2 = new Stopwatch();
  4443. try
  4444. {
  4445. stopwatch1.Start();
  4446. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4447. sn = sn.Replace("\0", "");
  4448. #region 查询载具上的产品信息
  4449. string cavityData = string.Empty;
  4450. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4451. if (string.IsNullOrEmpty(cavityData))
  4452. cavityData = "";
  4453. if (snResult != 0)
  4454. {
  4455. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4456. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4457. writeToPLC_Flag1.Adress = 2003;
  4458. writeToPLC_Flag1.Value = (short)6;
  4459. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4460. stopwatch1.Stop();
  4461. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4462. return;
  4463. }
  4464. #endregion 查询载具上的产品信息
  4465. string[] cavitySNs = cavityData.Split('.');
  4466. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4467. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4468. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4469. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4470. if (cavitySNs != null && cavitySNs.Length >= 2)
  4471. {
  4472. a1CavitySN1_VehicleStates = cavitySNs[0];
  4473. a1CavitySN2_VehicleStates = cavitySNs[1];
  4474. a1CavityResult1_VehicleStates = 2;
  4475. a1CavityResult2_VehicleStates = 2;
  4476. }
  4477. if (a1CavitySN1_VehicleStates == "假产品")
  4478. a1CavityResult1_VehicleStates = 3;
  4479. if (a1CavitySN2_VehicleStates == "假产品")
  4480. a1CavityResult2_VehicleStates = 3;
  4481. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4482. // 回写
  4483. stopwatch2.Start();
  4484. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4485. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4486. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4487. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4488. //// MES_Flag
  4489. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4490. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4491. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4492. writeToPLC_Flag.Adress = 2003;
  4493. writeToPLC_Flag.Value = mES_Flag;
  4494. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4495. {
  4496. Name = "a1CavitySN1_VehicleStates",
  4497. Adress = 2024,
  4498. ValueType = PLCValueType.String,
  4499. ValueTypeStrLength = 20,
  4500. Value = a1CavitySN1_VehicleStates
  4501. });
  4502. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4503. {
  4504. Name = "a1CavitySN2_VehicleStates",
  4505. Adress = 2044,
  4506. ValueType = PLCValueType.String,
  4507. ValueTypeStrLength = 20,
  4508. Value = a1CavitySN2_VehicleStates
  4509. });
  4510. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4511. {
  4512. Name = "a1CavityResult1_VehicleStates",
  4513. Adress = 2064,
  4514. ValueType = PLCValueType.Short,
  4515. Value = a1CavityResult1_VehicleStates
  4516. });
  4517. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4518. {
  4519. Name = "a1CavityResult2_VehicleStates",
  4520. Adress = 2065,
  4521. ValueType = PLCValueType.Short,
  4522. Value = a1CavityResult2_VehicleStates
  4523. });
  4524. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4525. stopwatch2.Stop();
  4526. }
  4527. catch (Exception ex)
  4528. {
  4529. string str = ex.StackTrace;
  4530. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4531. // MES_Flag
  4532. stopwatch2.Start();
  4533. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4534. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4535. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4536. writeToPLC_Flag.Adress = 2003;
  4537. writeToPLC_Flag.Value = (short)6;
  4538. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4539. stopwatch2.Stop();
  4540. }
  4541. stopwatch1.Stop();
  4542. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4543. }
  4544. /// <summary>
  4545. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4546. /// </summary>
  4547. /// <param name="plcNo">PLC编号</param>
  4548. /// <param name="stationNameStr">工站全称</param>
  4549. private void S1上料进站校验(int plcNo, string stationNameStr)
  4550. {
  4551. Stopwatch stopwatch1 = new Stopwatch();
  4552. Stopwatch stopwatch2 = new Stopwatch();
  4553. try
  4554. {
  4555. stopwatch1.Start();
  4556. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4557. sn = sn.Replace("\0", "");
  4558. // 保存进站数据+调用进站MES接口
  4559. List<TestItem> item = new List<TestItem>();
  4560. stopwatch2.Start();
  4561. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4562. stopwatch2.Stop();
  4563. short a1MES_FLAG_Check = (short)result;
  4564. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4565. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4566. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4567. writeToPLC_Flag.Adress = 2077;
  4568. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4569. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4570. }
  4571. catch (Exception ex)
  4572. {
  4573. string str = ex.StackTrace;
  4574. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4575. // MES_Flag
  4576. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4577. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4578. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4579. writeToPLC_Flag.Adress = 2077;
  4580. writeToPLC_Flag.Value = (short)6;
  4581. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4582. }
  4583. stopwatch1.Stop();
  4584. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4585. }
  4586. /// <summary>
  4587. /// [S1] Tray盘上料装备(板测)- 出站接口
  4588. /// </summary>
  4589. /// <param name="plcNo"></param>
  4590. /// <param name="stationCode"></param>
  4591. /// <param name="stationName"></param>
  4592. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4593. {
  4594. Stopwatch stopwatch1 = new Stopwatch();
  4595. Stopwatch stopwatch2 = new Stopwatch();
  4596. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4597. string stationNameStr = stationCode + stationName;
  4598. string processItem = stationName; // 测试项目
  4599. try
  4600. {
  4601. stopwatch1.Start();
  4602. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4603. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4604. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4605. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4606. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4607. sn = sn.Replace("\0", "");
  4608. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4609. partNo1 = partNo1.Replace("\0", "");
  4610. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4611. partNo2 = partNo2.Replace("\0", "");
  4612. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4613. bool pass = a1Result == 1;
  4614. stopwatch2.Start();
  4615. // 产品1
  4616. List<TestItem> items = new List<TestItem>();
  4617. items.Add(new TestItem()
  4618. {
  4619. Parameter_name = "载具码",
  4620. Parameter_value = sn,
  4621. Parameter_unit = ""
  4622. });
  4623. items.Add(new TestItem()
  4624. {
  4625. Parameter_name = "载具穴号",
  4626. Parameter_value = "1",
  4627. Parameter_unit = ""
  4628. });
  4629. items.Add(new TestItem()
  4630. {
  4631. Parameter_name = "产品结果",
  4632. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4633. Parameter_unit = ""
  4634. });
  4635. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4636. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4637. // 产品2
  4638. items = new List<TestItem>();
  4639. items.Add(new TestItem()
  4640. {
  4641. Parameter_name = "载具码",
  4642. Parameter_value = sn,
  4643. Parameter_unit = ""
  4644. });
  4645. items.Add(new TestItem()
  4646. {
  4647. Parameter_name = "载具穴号",
  4648. Parameter_value = "2",
  4649. Parameter_unit = ""
  4650. });
  4651. items.Add(new TestItem()
  4652. {
  4653. Parameter_name = "产品结果",
  4654. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4655. Parameter_unit = ""
  4656. });
  4657. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4658. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4659. short result = 0;
  4660. List<int> results = new List<int>() { result1, result2 };
  4661. if (result1 == 1 && result2 == 1)
  4662. result = 1;
  4663. else if (results.Contains(3))
  4664. result = 3;
  4665. else if (results.Contains(2))
  4666. result = 2;
  4667. else if (results.Contains(4))
  4668. result = 4;
  4669. else
  4670. result = 4;
  4671. stopwatch2.Stop();
  4672. #region 存储绑定数据到 边线MES系统中
  4673. if (result == 1)
  4674. {
  4675. string data = string.Concat(partNo1, ".", partNo2);
  4676. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4677. if (resultMesR != 0)
  4678. {
  4679. result = 4;
  4680. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4681. }
  4682. }
  4683. #endregion 存储绑定数据到 边线MES系统中
  4684. // MES_Flag 为MES报错
  4685. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4686. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4687. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4688. writeToPLC_Flag.Name = "a1MES_FLAG";
  4689. writeToPLC_Flag.Adress = 2109;
  4690. writeToPLC_Flag.Value = result;
  4691. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4692. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4693. }
  4694. catch (Exception ex)
  4695. {
  4696. stopwatch2.Restart();
  4697. // MES_Flag 为4上位机报错
  4698. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4699. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4700. writeToPLC_Flag.Name = "a1MES_FLAG";
  4701. writeToPLC_Flag.Adress = 2109;
  4702. writeToPLC_Flag.Value = (short)4;
  4703. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4704. stopwatch2.Stop();
  4705. string str = ex.StackTrace;
  4706. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4707. }
  4708. stopwatch1.Stop();
  4709. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4710. }
  4711. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4712. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4713. //{
  4714. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4715. // string stationNameStr = stationCode + stationName;
  4716. // string processItem = stationName; // 测试项目
  4717. // try
  4718. // {
  4719. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4720. // string accno = "1"; // 工序编号
  4721. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4722. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4723. // List<OneCheckItem> items = new List<OneCheckItem>()
  4724. // {
  4725. // new OneCheckItem()
  4726. // {
  4727. // Onecheck_name="胶圈装配行程设定上限",
  4728. // Onecheck_content="上限值",
  4729. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4730. // },
  4731. // };
  4732. // OneCheckData oneCheckData = new OneCheckData()
  4733. // {
  4734. // Line_code = GlobalContext.LineCode,
  4735. // Line_name = GlobalContext.LineName,
  4736. // Equipment_code = equipmentCode,
  4737. // Equipment_name = equipmentCode,
  4738. // Workorder_code = workorder_code,
  4739. // Procedure_code = accno,
  4740. // Procedure_name = processItem,
  4741. // Oneckeck_values = items,
  4742. // Onecheck_empcode = "",
  4743. // Onecheck_empname = "",
  4744. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4745. // };
  4746. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4747. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4748. // short result = result1 == 1 ? (short)1 : (short)2;
  4749. // // MES_Flag 为4MES报错
  4750. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4751. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4752. // }
  4753. // catch (Exception ex)
  4754. // {
  4755. // // MES_Flag 为2上位机报错
  4756. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4757. // string str = ex.StackTrace;
  4758. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4759. // }
  4760. //}
  4761. // ReadStation_S1_2 节拍接口+AGV
  4762. /// <summary>
  4763. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4764. /// </summary>
  4765. /// <param name="plcNo">PLC编号</param>
  4766. /// <param name="stationNameStr">工站全称</param>
  4767. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4768. {
  4769. Stopwatch stopwatch1 = new Stopwatch();
  4770. Stopwatch stopwatch2 = new Stopwatch();
  4771. try
  4772. {
  4773. stopwatch1.Start();
  4774. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4775. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4776. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4777. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4778. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4779. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4780. // ZS 将SN发给ICT标机(串口)
  4781. short a1MES_FLAG_ICT = 1;
  4782. stopwatch2.Start();
  4783. // MES_Flag
  4784. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4785. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4786. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4787. writeToPLC_Flag.Adress = 2182;
  4788. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4789. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4790. stopwatch2.Stop();
  4791. }
  4792. catch (Exception ex)
  4793. {
  4794. string str = ex.StackTrace;
  4795. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4796. stopwatch2.Start();
  4797. // MES_Flag
  4798. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4799. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4800. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4801. writeToPLC_Flag.Adress = 2182;
  4802. writeToPLC_Flag.Value = (short)4;
  4803. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4804. stopwatch2.Stop();
  4805. }
  4806. stopwatch1.Stop();
  4807. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4808. }
  4809. /// <summary>
  4810. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4811. /// </summary>
  4812. /// <param name="plcNo">PLC编号</param>
  4813. /// <param name="stationNameStr">工站全称</param>
  4814. private void S1节拍接口(int plcNo, string stationNameStr)
  4815. {
  4816. Stopwatch stopwatch1 = new Stopwatch();
  4817. Stopwatch stopwatch2 = new Stopwatch();
  4818. string resultStr = string.Empty;
  4819. try
  4820. {
  4821. stopwatch1.Start();
  4822. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4823. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4824. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4825. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4826. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4827. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4828. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  4829. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4830. if (!actionBool)
  4831. {
  4832. stopwatch2.Start();
  4833. // MES_Flag
  4834. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4835. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4836. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  4837. writeToPLC_Flag1.Adress = 2254;
  4838. writeToPLC_Flag1.Value = (short)1;
  4839. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  4840. stopwatch2.Stop();
  4841. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4842. return;
  4843. }
  4844. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  4845. {
  4846. stopwatch2.Start();
  4847. // MES_Flag
  4848. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4849. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  4850. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  4851. writeToPLC_Flag2.Adress = 2254;
  4852. writeToPLC_Flag2.Value = (short)1;
  4853. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  4854. stopwatch2.Stop();
  4855. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4856. return;
  4857. }
  4858. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  4859. { // 查产品SN
  4860. a1OEEPartNo = "Test"; // ZS
  4861. }
  4862. short a1OEEMES_FLAG = 0;
  4863. // 上传OEE
  4864. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  4865. a1OEEMES_FLAG = result.Item1;
  4866. resultStr = result.Item2;
  4867. stopwatch2.Start();
  4868. // MES_Flag
  4869. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4870. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4871. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4872. writeToPLC_Flag.Adress = 2254;
  4873. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  4874. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4875. stopwatch2.Stop();
  4876. }
  4877. catch (Exception ex)
  4878. {
  4879. string str = ex.StackTrace;
  4880. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4881. // MES_Flag
  4882. stopwatch2.Start();
  4883. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4884. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4885. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4886. writeToPLC_Flag.Adress = 2254;
  4887. writeToPLC_Flag.Value = (short)4;
  4888. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4889. stopwatch2.Stop();
  4890. }
  4891. stopwatch1.Stop();
  4892. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4893. }
  4894. /// <summary>
  4895. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  4896. /// </summary>
  4897. /// <param name="plcNo">PLC编号</param>
  4898. /// <param name="stationNameStr">工站全称</param>
  4899. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  4900. {
  4901. Stopwatch stopwatch1 = new Stopwatch();
  4902. Stopwatch stopwatch2 = new Stopwatch();
  4903. try
  4904. {
  4905. stopwatch1.Start();
  4906. // ZS 呼叫AGV
  4907. short a1AGVUpCall = 2;
  4908. stopwatch2.Start();
  4909. // a1AGVUpCall
  4910. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4911. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4912. writeToPLC_Flag.Name = "a1AGVUpCall";
  4913. writeToPLC_Flag.Adress = 2307;
  4914. writeToPLC_Flag.Value = a1AGVUpCall;
  4915. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4916. stopwatch2.Stop();
  4917. }
  4918. catch (Exception ex)
  4919. {
  4920. string str = ex.StackTrace;
  4921. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4922. // a1AGVUpCall
  4923. stopwatch2.Start();
  4924. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4925. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4926. writeToPLC_Flag.Name = "a1AGVUpCall";
  4927. writeToPLC_Flag.Adress = 2307;
  4928. writeToPLC_Flag.Value = (short)4;
  4929. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4930. stopwatch2.Stop();
  4931. }
  4932. stopwatch1.Stop();
  4933. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4934. }
  4935. /// <summary>
  4936. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  4937. /// </summary>
  4938. /// <param name="plcNo">PLC编号</param>
  4939. /// <param name="stationNameStr">工站全称</param>
  4940. private void S1AGV上料完成(int plcNo, string stationNameStr)
  4941. {
  4942. Stopwatch stopwatch1 = new Stopwatch();
  4943. Stopwatch stopwatch2 = new Stopwatch();
  4944. try
  4945. {
  4946. stopwatch1.Start();
  4947. // ZS AGV上料完成,让小车离开
  4948. short a1AGVUpEnd = 2;
  4949. stopwatch2.Start();
  4950. // a1AGVUpEnd
  4951. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4952. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4953. writeToPLC_Flag.Name = "a1AGVUpEnd";
  4954. writeToPLC_Flag.Adress = 2309;
  4955. writeToPLC_Flag.Value = a1AGVUpEnd;
  4956. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  4957. stopwatch2.Stop();
  4958. }
  4959. catch (Exception ex)
  4960. {
  4961. string str = ex.StackTrace;
  4962. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4963. // a1AGVUpEnd
  4964. stopwatch2.Start();
  4965. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4966. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4967. writeToPLC_Flag.Name = "a1AGVUpEnd";
  4968. writeToPLC_Flag.Adress = 2309;
  4969. writeToPLC_Flag.Value = (short)4;
  4970. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  4971. stopwatch2.Stop();
  4972. }
  4973. stopwatch1.Stop();
  4974. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4975. }
  4976. /// <summary>
  4977. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  4978. /// </summary>
  4979. /// <param name="plcNo">PLC编号</param>
  4980. /// <param name="stationNameStr">工站全称</param>
  4981. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  4982. {
  4983. Stopwatch stopwatch1 = new Stopwatch();
  4984. Stopwatch stopwatch2 = new Stopwatch();
  4985. try
  4986. {
  4987. stopwatch1.Start();
  4988. // ZS 呼叫AGV
  4989. short a1AGVDownCall = 2;
  4990. stopwatch2.Start();
  4991. // a1AGVDownCall
  4992. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4993. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4994. writeToPLC_Flag.Name = "a1AGVDownCall";
  4995. writeToPLC_Flag.Adress = 2320;
  4996. writeToPLC_Flag.Value = a1AGVDownCall;
  4997. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  4998. stopwatch2.Stop();
  4999. }
  5000. catch (Exception ex)
  5001. {
  5002. string str = ex.StackTrace;
  5003. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5004. // a1AGVDownCall
  5005. stopwatch2.Start();
  5006. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5007. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5008. writeToPLC_Flag.Name = "a1AGVDownCall";
  5009. writeToPLC_Flag.Adress = 2320;
  5010. writeToPLC_Flag.Value = (short)4;
  5011. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5012. stopwatch2.Stop();
  5013. }
  5014. stopwatch1.Stop();
  5015. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5016. }
  5017. /// <summary>
  5018. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5019. /// </summary>
  5020. /// <param name="plcNo">PLC编号</param>
  5021. /// <param name="stationNameStr">工站全称</param>
  5022. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5023. {
  5024. Stopwatch stopwatch1 = new Stopwatch();
  5025. Stopwatch stopwatch2 = new Stopwatch();
  5026. try
  5027. {
  5028. stopwatch1.Start();
  5029. // ZS AGV上料完成,让小车离开
  5030. short a1AGVDownEnd = 2;
  5031. stopwatch2.Start();
  5032. // a1AGVDownEnd
  5033. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5034. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5035. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5036. writeToPLC_Flag.Adress = 2322;
  5037. writeToPLC_Flag.Value = a1AGVDownEnd;
  5038. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5039. stopwatch2.Stop();
  5040. }
  5041. catch (Exception ex)
  5042. {
  5043. string str = ex.StackTrace;
  5044. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5045. // a1AGVDownEnd
  5046. stopwatch2.Start();
  5047. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5048. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5049. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5050. writeToPLC_Flag.Adress = 2322;
  5051. writeToPLC_Flag.Value = (short)4;
  5052. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5053. stopwatch2.Stop();
  5054. }
  5055. stopwatch1.Stop();
  5056. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5057. }
  5058. #endregion [S1] Tray盘上料装备(板测)
  5059. #endregion PLC1 张超凡
  5060. #region PLC2 李晓奇
  5061. #region [S2] FCT(板测)
  5062. /// <summary>
  5063. /// S2工位的数据- 触发信号上次的值
  5064. /// </summary>
  5065. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5066. /// <summary>
  5067. /// S2工位的数据(含触发信号)
  5068. /// </summary>
  5069. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5070. /// <summary>
  5071. /// S2工位的数据- 回写点位
  5072. /// </summary>
  5073. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5074. /// <summary>
  5075. /// [S2] FCT(板测)
  5076. /// </summary>
  5077. /// <param name="plcNo">PLC编号</param>
  5078. //private void ReadStation_S2(int plcNo)
  5079. //{
  5080. // // [S1] Tray盘上料装备
  5081. // // [S2] FCT
  5082. // // [S3] 值板机
  5083. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5084. // // [S5] Tray盘下料装备
  5085. // /// 上位机心跳
  5086. // /// 获取设备报警数据与状态信息
  5087. // string stationCode = "[S2]";
  5088. // string stationName = "FCT";
  5089. // string stationNameStr = stationCode + stationName;
  5090. // #region 创建字典
  5091. // // 触发信号字典 赋值
  5092. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5093. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5094. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5095. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5096. // // PLC数据字典 赋值
  5097. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5098. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5099. // s2PLCData.Add("b1ProductSN_Check", 0);
  5100. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5101. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5102. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5103. // s2PLCData.Add("b1ProductSN_Bind", "");
  5104. // s2PLCData.Add("b1Part1SN_Bind", "");
  5105. // s2PLCData.Add("b1Part2SN_Bind", "");
  5106. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5107. // s2PLCData.Add("b1MES_FLAG", 0);
  5108. // s2PLCData.Add("b1ProductSN", 0);
  5109. // s2PLCData.Add("b1Part1Result", 0);
  5110. // s2PLCData.Add("b1Part2Result", 0);
  5111. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5112. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5113. // s2PLCData.Add("b1OEEProductSN", "");
  5114. // s2PLCData.Add("b1OEEType", 0);
  5115. // #endregion 创建字典
  5116. // while (IsRun)
  5117. // {
  5118. // try
  5119. // {
  5120. // if (!GlobalContext._IsCon_Funs2)
  5121. // {
  5122. // UpdatePLCMonitor(1, plcNo, 0);
  5123. // continue;
  5124. // }
  5125. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5126. // {
  5127. // Stopwatch stopwatch1 = new Stopwatch();
  5128. // Stopwatch stopwatch2 = new Stopwatch();
  5129. // stopwatch1.Start();
  5130. // stopwatch2.Start();
  5131. // #region 一次性读取所有数据
  5132. // // 一次性读取所有数据
  5133. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5134. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5135. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5136. // int[] datas = data1.Concat(data2).ToArray();
  5137. // datas = datas.Concat(data3).ToArray();
  5138. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5139. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5140. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5141. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5142. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5143. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5144. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5145. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5146. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5147. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5148. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5149. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5150. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5151. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5152. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5153. // s2PLCData["b1MES_FLAG"] = datas[169];
  5154. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5155. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5156. // s2PLCData["b1Part1Result"] = datas[190];
  5157. // s2PLCData["b1Part2Result"] = datas[191];
  5158. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5159. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5160. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5161. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5162. // s2PLCData["b1OEEType"] = datas[224];
  5163. // #endregion 一次性读取所有数据
  5164. // stopwatch2.Stop();
  5165. // #region 回写操作,写后清空flag
  5166. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5167. // #endregion 回写操作,写后清空flag
  5168. // #region 进站校验
  5169. // try
  5170. // {
  5171. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5172. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5173. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5174. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5175. // {
  5176. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5177. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5178. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5179. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5180. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5181. // }
  5182. // }
  5183. // catch (Exception ex)
  5184. // {
  5185. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5186. // string str = ex.StackTrace;
  5187. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5188. // }
  5189. // #endregion 进站校验
  5190. // #region 二穴载具解绑/绑定(产品换载具)
  5191. // try
  5192. // {
  5193. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5194. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5195. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5196. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5197. // {
  5198. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5199. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5200. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5201. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5202. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5203. // }
  5204. // }
  5205. // catch (Exception ex)
  5206. // {
  5207. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5208. // string str = ex.StackTrace;
  5209. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5210. // }
  5211. // #endregion 二穴载具解绑/绑定(产品换载具)
  5212. // #region FCT-出站接口
  5213. // try
  5214. // {
  5215. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5216. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5217. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5218. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5219. // {
  5220. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5221. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5222. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5223. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5224. // }
  5225. // }
  5226. // catch (Exception ex)
  5227. // {
  5228. // // MES_Flag 为6上位机报错
  5229. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5230. // string str = ex.StackTrace;
  5231. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5232. // }
  5233. // #endregion FCT-出站接口
  5234. // #region 节拍接口
  5235. // try
  5236. // {
  5237. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5238. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5239. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5240. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5241. // {
  5242. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5243. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5244. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5245. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5246. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5247. // }
  5248. // }
  5249. // catch (Exception ex)
  5250. // {
  5251. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5252. // string str = ex.StackTrace;
  5253. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5254. // }
  5255. // #endregion 节拍接口
  5256. // #region 心跳
  5257. // try
  5258. // {
  5259. // short states = 0;
  5260. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5261. // }
  5262. // catch (Exception ex)
  5263. // {
  5264. // string str = ex.StackTrace;
  5265. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5266. // }
  5267. // #endregion 心跳
  5268. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5269. // stopwatch1.Stop();
  5270. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5271. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5272. // }
  5273. // else
  5274. // {
  5275. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5276. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5277. // Funs[plcNo].Connect();
  5278. // }
  5279. // }
  5280. // catch (Exception ex)
  5281. // {
  5282. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5283. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5284. // Funs[plcNo].ReConnect();
  5285. // }
  5286. // Thread.Sleep(IntervalReadPLC);
  5287. // }
  5288. //}
  5289. /// <summary>
  5290. /// [S2] FCT(板测)- 进站校验
  5291. /// </summary>
  5292. /// <param name="plcNo">PLC编号</param>
  5293. /// <param name="stationNameStr">工站全称</param>
  5294. private void S2进站校验(int plcNo, string stationNameStr)
  5295. {
  5296. Stopwatch stopwatch1 = new Stopwatch();
  5297. Stopwatch stopwatch2 = new Stopwatch();
  5298. try
  5299. {
  5300. stopwatch1.Start();
  5301. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5302. sn = sn.Replace("\0", "");
  5303. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5304. // 查询物料码By载具码 并判断是不是假产品
  5305. string cavityData = string.Empty;
  5306. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5307. if (string.IsNullOrEmpty(cavityData))
  5308. cavityData = "";
  5309. if (snResult != 0)
  5310. {
  5311. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5312. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5313. writeToPLC_Flag1.Adress = 2003;
  5314. writeToPLC_Flag1.Value = (short)6;
  5315. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5316. stopwatch1.Stop();
  5317. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5318. return;
  5319. }
  5320. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5321. string[] cavitySNs = cavityData.Split('.');
  5322. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5323. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5324. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5325. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5326. if (cavitySNs != null && cavitySNs.Length >= 2)
  5327. {
  5328. b1Part1SN_Check = cavitySNs[0];
  5329. b1Part2SN_Check = cavitySNs[1];
  5330. b1Part1Result_Check = 2;
  5331. b1Part2Result_Check = 2;
  5332. }
  5333. if (b1Part1SN_Check == "假产品")
  5334. b1Part1Result_Check = 3;
  5335. if (b1Part2SN_Check == "假产品")
  5336. b1Part2Result_Check = 3;
  5337. // 调用MES进站
  5338. stopwatch2.Start();
  5339. // 调用MES进站 - 产品1
  5340. List<TestItem> item;
  5341. int result1 = b1Part1Result_Check;
  5342. if (result1 != 3)
  5343. {
  5344. item = new List<TestItem>();
  5345. item.Add(new TestItem()
  5346. {
  5347. Parameter_name = "载具码",
  5348. Parameter_value = sn,
  5349. });
  5350. item.Add(new TestItem()
  5351. {
  5352. Parameter_name = "载具穴号",
  5353. Parameter_value = "1",
  5354. });
  5355. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5356. }
  5357. // 调用MES进站 - 产品2
  5358. int result2 = b1Part2Result_Check;
  5359. if (result2 != 3)
  5360. {
  5361. item = new List<TestItem>();
  5362. item.Add(new TestItem()
  5363. {
  5364. Parameter_name = "载具码",
  5365. Parameter_value = sn,
  5366. });
  5367. item.Add(new TestItem()
  5368. {
  5369. Parameter_name = "载具穴号",
  5370. Parameter_value = "2",
  5371. });
  5372. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5373. }
  5374. stopwatch2.Stop();
  5375. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5376. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5377. int result = result1;
  5378. if (result == 1)
  5379. result = result2;
  5380. short b1MES_FLAG_Check = (short)result;
  5381. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5382. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5383. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5384. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5385. //// MES_Flag
  5386. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5387. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5388. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5389. writeToPLC_Flag.Adress = 2003;
  5390. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5391. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5392. {
  5393. Name = "b1Part1SN_Check",
  5394. Adress = 2024,
  5395. ValueType = PLCValueType.String,
  5396. ValueTypeStrLength = 20,
  5397. Value = b1Part1SN_Check
  5398. });
  5399. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5400. {
  5401. Name = "b1Part2SN_Check",
  5402. Adress = 2044,
  5403. ValueType = PLCValueType.String,
  5404. ValueTypeStrLength = 20,
  5405. Value = b1Part2SN_Check
  5406. });
  5407. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5408. {
  5409. Name = "b1Part1Result_Check",
  5410. Adress = 2064,
  5411. ValueType = PLCValueType.Short,
  5412. Value = b1Part1Result_Check
  5413. });
  5414. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5415. {
  5416. Name = "b1Part2Result_Check",
  5417. Adress = 2065,
  5418. ValueType = PLCValueType.Short,
  5419. Value = b1Part2Result_Check
  5420. });
  5421. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5422. }
  5423. catch (Exception ex)
  5424. {
  5425. string str = ex.StackTrace;
  5426. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5427. // MES_Flag
  5428. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5429. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5430. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5431. writeToPLC_Flag.Adress = 2003;
  5432. writeToPLC_Flag.Value = (short)6;
  5433. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5434. }
  5435. stopwatch1.Stop();
  5436. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5437. }
  5438. /// <summary>
  5439. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5440. /// </summary>
  5441. /// <param name="plcNo">PLC编号</param>
  5442. /// <param name="stationNameStr">工站全称</param>
  5443. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5444. {
  5445. Stopwatch stopwatch1 = new Stopwatch();
  5446. Stopwatch stopwatch2 = new Stopwatch();
  5447. try
  5448. {
  5449. stopwatch1.Start();
  5450. // 产品换载具
  5451. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5452. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5453. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5454. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5455. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5456. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5457. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5458. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5459. stopwatch2.Start();
  5460. #region 查询载具上的产品信息
  5461. //string cavityData = string.Empty;
  5462. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5463. //if (string.IsNullOrEmpty(cavityData))
  5464. // cavityData = "";
  5465. //if (snResult != 0)
  5466. //{
  5467. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5468. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5469. // writeToPLC_Flag.Adress = 2077;
  5470. // writeToPLC_Flag.Value = (short)6;
  5471. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5472. // stopwatch1.Stop();
  5473. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5474. // return;
  5475. //}
  5476. #endregion 查询载具上的产品信息
  5477. #region 解绑(边线MES系统)
  5478. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5479. if (snResult != 0)
  5480. {
  5481. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5482. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5483. writeToPLC_Flag1.Adress = 2077;
  5484. writeToPLC_Flag1.Value = (short)6;
  5485. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5486. stopwatch1.Stop();
  5487. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5488. return;
  5489. }
  5490. #endregion 解绑(边线MES系统)
  5491. #region 存储绑定数据到 边线MES系统中
  5492. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5493. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5494. if (snResult != 0)
  5495. {
  5496. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5497. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5498. writeToPLC_Flag1.Adress = 2077;
  5499. writeToPLC_Flag1.Value = (short)6;
  5500. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5501. stopwatch1.Stop();
  5502. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5503. return;
  5504. }
  5505. #endregion 存储绑定数据到 边线MES系统中
  5506. stopwatch2.Stop();
  5507. short b1MES_FLAG_Unbind = 1;
  5508. // MES_Flag
  5509. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5510. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5511. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5512. writeToPLC_Flag.Adress = 2077;
  5513. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5514. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5515. }
  5516. catch (Exception ex)
  5517. {
  5518. string str = ex.StackTrace;
  5519. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5520. // MES_Flag
  5521. stopwatch2.Start();
  5522. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5523. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5524. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5525. writeToPLC_Flag.Adress = 2077;
  5526. writeToPLC_Flag.Value = (short)6;
  5527. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5528. stopwatch2.Stop();
  5529. }
  5530. stopwatch1.Stop();
  5531. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5532. }
  5533. //// 上次采集到的SN
  5534. //private string sn_FCT = string.Empty;
  5535. /// <summary>
  5536. /// [S2] FCT(板测)- 出站数据
  5537. /// </summary>
  5538. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5539. {
  5540. Stopwatch stopwatch1 = new Stopwatch();
  5541. Stopwatch stopwatch2 = new Stopwatch();
  5542. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5543. string stationNameStr = stationCode + stationName;
  5544. string processItem = stationName; // 测试项目
  5545. try
  5546. {
  5547. stopwatch1.Start();
  5548. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5549. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5550. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5551. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5552. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5553. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5554. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5555. bool pass1 = b1Part1Result == 1;
  5556. bool pass2 = b1Part2Result == 1;
  5557. #region 根据 载具SN 查 物料SN
  5558. string cavityData = string.Empty;
  5559. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5560. if (string.IsNullOrEmpty(cavityData))
  5561. cavityData = "";
  5562. if (snResult != 0)
  5563. {
  5564. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5565. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5566. writeToPLC_Flag1.Adress = 2169;
  5567. writeToPLC_Flag1.Value = (short)4;
  5568. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5569. stopwatch1.Stop();
  5570. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5571. return;
  5572. }
  5573. #endregion 根据 载具SN 查 物料SN
  5574. string[] cavitySNs = cavityData.Split('.');
  5575. string b1ProductSN1 = string.Empty;
  5576. string b1ProductSN2 = string.Empty;
  5577. if (cavitySNs != null && cavitySNs.Length >= 2)
  5578. {
  5579. b1ProductSN1 = cavitySNs[0];
  5580. b1ProductSN2 = cavitySNs[1];
  5581. }
  5582. stopwatch2.Start();
  5583. // 产品1
  5584. int result1 = 0;
  5585. if (b1ProductSN1 == "假产品")
  5586. result1 = 1;
  5587. else
  5588. {
  5589. List<TestItem> items1 = new List<TestItem>();
  5590. items1.Add(new TestItem()
  5591. {
  5592. Parameter_name = "载具码",
  5593. Parameter_value = b1ProductSN.ToString(),
  5594. Parameter_unit = ""
  5595. });
  5596. items1.Add(new TestItem()
  5597. {
  5598. Parameter_name = "载具穴号",
  5599. Parameter_value = "1",
  5600. Parameter_unit = ""
  5601. });
  5602. items1.Add(new TestItem()
  5603. {
  5604. Parameter_name = "产品结果",
  5605. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5606. Parameter_unit = ""
  5607. });
  5608. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5609. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5610. }
  5611. // 产品2
  5612. int result2 = 0;
  5613. if (b1ProductSN1 == "假产品")
  5614. result2 = 1;
  5615. else
  5616. {
  5617. List<TestItem> items2 = new List<TestItem>();
  5618. items2.Add(new TestItem()
  5619. {
  5620. Parameter_name = "载具码",
  5621. Parameter_value = b1ProductSN.ToString(),
  5622. Parameter_unit = ""
  5623. });
  5624. items2.Add(new TestItem()
  5625. {
  5626. Parameter_name = "载具穴号",
  5627. Parameter_value = "2",
  5628. Parameter_unit = ""
  5629. });
  5630. items2.Add(new TestItem()
  5631. {
  5632. Parameter_name = "产品结果",
  5633. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5634. Parameter_unit = ""
  5635. });
  5636. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5637. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5638. }
  5639. short result = 0;
  5640. List<int> results = new List<int>() { result1, result2 };
  5641. if (result1 == 1 && result2 == 1)
  5642. result = 1;
  5643. else if (results.Contains(3))
  5644. result = 3;
  5645. else if (results.Contains(2))
  5646. result = 2;
  5647. else if (results.Contains(4))
  5648. result = 4;
  5649. else
  5650. result = 4;
  5651. stopwatch2.Stop();
  5652. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5653. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5654. writeToPLC_Flag.Name = "b1MES_FLAG";
  5655. writeToPLC_Flag.Adress = 2169;
  5656. writeToPLC_Flag.Value = result;
  5657. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5658. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5659. }
  5660. catch (Exception ex)
  5661. {
  5662. stopwatch2.Restart();
  5663. // MES_Flag 为4上位机报错
  5664. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5665. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5666. writeToPLC_Flag.Name = "b1MES_FLAG";
  5667. writeToPLC_Flag.Adress = 2169;
  5668. writeToPLC_Flag.Value = (short)4;
  5669. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5670. stopwatch2.Stop();
  5671. string str = ex.StackTrace;
  5672. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5673. }
  5674. stopwatch1.Stop();
  5675. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5676. }
  5677. /// <summary>
  5678. /// [S2] FCT(板测)- 节拍接口
  5679. /// </summary>
  5680. /// <param name="plcNo">PLC编号</param>
  5681. /// <param name="stationNameStr">工站全称</param>
  5682. private void S2节拍接口(int plcNo, string stationNameStr)
  5683. {
  5684. Stopwatch stopwatch1 = new Stopwatch();
  5685. Stopwatch stopwatch2 = new Stopwatch();
  5686. string resultStr = string.Empty;
  5687. try
  5688. {
  5689. stopwatch1.Start();
  5690. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5691. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5692. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5693. if (!actionBool)
  5694. {
  5695. stopwatch2.Start();
  5696. // MES_Flag
  5697. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5698. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5699. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5700. writeToPLC_Flag1.Adress = 2203;
  5701. writeToPLC_Flag1.Value = (short)4;
  5702. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5703. stopwatch2.Stop();
  5704. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5705. return;
  5706. }
  5707. string b1OEEPartNo = string.Empty; // 物料码
  5708. if (string.IsNullOrEmpty(b1OEEProductSN))
  5709. {
  5710. stopwatch2.Start();
  5711. // MES_Flag
  5712. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5713. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5714. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5715. writeToPLC_Flag1.Adress = 2203;
  5716. writeToPLC_Flag1.Value = (short)1;
  5717. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5718. stopwatch2.Stop();
  5719. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5720. return;
  5721. }
  5722. else
  5723. { // 查产品SN
  5724. b1OEEPartNo = "Test"; // ZS
  5725. }
  5726. short b1OEEMES_FLAG = 0;
  5727. // 上传OEE
  5728. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5729. b1OEEMES_FLAG = result.Item1;
  5730. resultStr = result.Item2;
  5731. stopwatch2.Start();
  5732. // MES_Flag
  5733. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5734. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5735. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5736. writeToPLC_Flag.Adress = 2203;
  5737. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5738. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5739. stopwatch2.Stop();
  5740. }
  5741. catch (Exception ex)
  5742. {
  5743. string str = ex.StackTrace;
  5744. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5745. // MES_Flag
  5746. stopwatch2.Start();
  5747. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5748. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5749. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5750. writeToPLC_Flag.Adress = 2203;
  5751. writeToPLC_Flag.Value = (short)4;
  5752. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5753. stopwatch2.Stop();
  5754. }
  5755. stopwatch1.Stop();
  5756. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5757. }
  5758. #endregion [S2] FCT(板测)
  5759. #endregion PLC2 李晓奇
  5760. #region PLC3 刘永村
  5761. #region [S3] 值板机
  5762. /// <summary>
  5763. /// S3工位的数据- 触发信号上次的值
  5764. /// </summary>
  5765. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5766. /// <summary>
  5767. /// S3工位的数据(含触发信号)
  5768. /// </summary>
  5769. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5770. /// <summary>
  5771. /// S3工位的数据- 回写点位
  5772. /// </summary>
  5773. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5774. /// <summary>
  5775. /// [S3] 值板机
  5776. /// </summary>
  5777. /// <param name="plcNo">PLC编号</param>
  5778. //private void ReadStation_S3(int plcNo)
  5779. //{
  5780. // // [S1] Tray盘上料装备
  5781. // // [S2] FCT
  5782. // // [S3] 值板机
  5783. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5784. // // [S5] Tray盘下料装备
  5785. // /// 上位机心跳
  5786. // /// 获取设备报警数据与状态信息
  5787. // string stationCode = "[S3]";
  5788. // string stationName = "值板机";
  5789. // string stationNameStr = stationCode + stationName;
  5790. // #region 创建字典
  5791. // // 触发信号字典 赋值
  5792. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5793. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5794. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5795. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5796. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5797. // // PLC数据字典 赋值
  5798. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5799. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5800. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5801. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5802. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5803. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5804. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5805. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5806. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5807. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5808. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5809. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5810. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5811. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5812. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5813. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5814. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5815. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5816. // s3PLCData.Add("c1Result", 0); // 产品结果
  5817. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5818. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5819. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5820. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  5821. // #endregion 创建字典
  5822. // while (IsRun)
  5823. // {
  5824. // try
  5825. // {
  5826. // if (!GlobalContext._IsCon_Funs3)
  5827. // {
  5828. // UpdatePLCMonitor(1, plcNo, 0);
  5829. // continue;
  5830. // }
  5831. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5832. // {
  5833. // Stopwatch stopwatch1 = new Stopwatch();
  5834. // Stopwatch stopwatch2 = new Stopwatch();
  5835. // stopwatch1.Start();
  5836. // stopwatch2.Start();
  5837. // #region 一次性读取所有数据
  5838. // // 一次性读取所有数据
  5839. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  5840. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  5841. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  5842. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  5843. // int[] datas = data1.Concat(data2).ToArray();
  5844. // datas = datas.Concat(data3).ToArray();
  5845. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  5846. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  5847. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5848. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  5849. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  5850. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  5851. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5852. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  5853. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  5854. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  5855. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  5856. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5857. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  5858. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  5859. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  5860. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  5861. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5862. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  5863. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  5864. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  5865. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  5866. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  5867. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  5868. // #endregion 一次性读取所有数据
  5869. // stopwatch2.Stop();
  5870. // #region 回写操作,写后清空flag
  5871. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  5872. // #endregion 回写操作,写后清空flag
  5873. // #region S3进站校验
  5874. // try
  5875. // {
  5876. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  5877. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  5878. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  5879. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  5880. // {
  5881. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  5882. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5883. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  5884. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5885. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  5886. // }
  5887. // }
  5888. // catch (Exception ex)
  5889. // {
  5890. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5891. // string str = ex.StackTrace;
  5892. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5893. // }
  5894. // #endregion S3进站校验
  5895. // #region S3二穴载具解绑
  5896. // try
  5897. // {
  5898. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  5899. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  5900. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  5901. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  5902. // {
  5903. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5904. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  5905. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  5906. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  5907. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  5908. // }
  5909. // }
  5910. // catch (Exception ex)
  5911. // {
  5912. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  5913. // string str = ex.StackTrace;
  5914. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5915. // }
  5916. // #endregion S3二穴载具解绑
  5917. // #region S3二穴载具绑定
  5918. // try
  5919. // {
  5920. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  5921. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  5922. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  5923. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  5924. // {
  5925. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5926. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5927. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  5928. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  5929. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  5930. // }
  5931. // }
  5932. // catch (Exception ex)
  5933. // {
  5934. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  5935. // string str = ex.StackTrace;
  5936. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5937. // }
  5938. // #endregion S3二穴载具绑定
  5939. // #region S3出站接口(+一穴载具绑定)
  5940. // try
  5941. // {
  5942. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  5943. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  5944. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  5945. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  5946. // {
  5947. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  5948. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5949. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  5950. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  5951. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  5952. // }
  5953. // }
  5954. // catch (Exception ex)
  5955. // {
  5956. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  5957. // string str = ex.StackTrace;
  5958. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5959. // }
  5960. // #endregion S3出站接口(+一穴载具绑定)
  5961. // #region S3节拍接口
  5962. // try
  5963. // {
  5964. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  5965. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  5966. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  5967. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  5968. // {
  5969. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  5970. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5971. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  5972. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  5973. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  5974. // }
  5975. // }
  5976. // catch (Exception ex)
  5977. // {
  5978. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  5979. // string str = ex.StackTrace;
  5980. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5981. // }
  5982. // #endregion S3节拍接口
  5983. // #region 心跳
  5984. // try
  5985. // {
  5986. // short states = 0;
  5987. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5988. // }
  5989. // catch (Exception ex)
  5990. // {
  5991. // string str = ex.StackTrace;
  5992. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5993. // }
  5994. // #endregion 心跳
  5995. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5996. // stopwatch1.Stop();
  5997. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5998. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5999. // }
  6000. // else
  6001. // {
  6002. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6003. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6004. // Funs[plcNo].Connect();
  6005. // }
  6006. // }
  6007. // catch (Exception ex)
  6008. // {
  6009. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6010. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6011. // Funs[plcNo].ReConnect();
  6012. // }
  6013. // Thread.Sleep(IntervalReadPLC);
  6014. // }
  6015. //}
  6016. /// <summary>
  6017. /// [S3] 值板机- 进站校验
  6018. /// </summary>
  6019. /// <param name="plcNo">PLC编号</param>
  6020. /// <param name="stationNameStr">工站全称</param>
  6021. private void S3进站校验(int plcNo, string stationNameStr)
  6022. {
  6023. Stopwatch stopwatch1 = new Stopwatch();
  6024. Stopwatch stopwatch2 = new Stopwatch();
  6025. try
  6026. {
  6027. stopwatch1.Start();
  6028. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6029. sn = sn.Replace("\0", "");
  6030. #region 查询载具上的产品信息
  6031. string cavityData = string.Empty;
  6032. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6033. if (string.IsNullOrEmpty(cavityData))
  6034. cavityData = "";
  6035. if (snResult != 0)
  6036. {
  6037. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6038. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6039. writeToPLC_Flag1.Adress = 2003;
  6040. writeToPLC_Flag1.Value = (short)6;
  6041. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6042. stopwatch1.Stop();
  6043. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6044. return;
  6045. }
  6046. #endregion 查询载具上的产品信息
  6047. string[] cavitySNs = cavityData.Split('.');
  6048. string part1Str = ""; // 产品1的SN码
  6049. string part2Str = ""; // 产品2的SN码
  6050. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6051. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6052. if (cavitySNs != null && cavitySNs.Length >= 2)
  6053. {
  6054. part1Str = cavitySNs[0];
  6055. part2Str = cavitySNs[1];
  6056. c1Part1Result_Check = 2;
  6057. c1Part2Result_Check = 2;
  6058. }
  6059. if (part1Str == "假产品")
  6060. c1Part1Result_Check = 3;
  6061. if (part2Str == "假产品")
  6062. c1Part2Result_Check = 3;
  6063. // 调用MES进站
  6064. stopwatch2.Start();
  6065. // 调用MES进站 - 产品1
  6066. List<TestItem> item;
  6067. int result1 = c1Part1Result_Check;
  6068. if (result1 != 3)
  6069. {
  6070. item = new List<TestItem>();
  6071. item.Add(new TestItem()
  6072. {
  6073. Parameter_name = "载具码",
  6074. Parameter_value = sn,
  6075. });
  6076. item.Add(new TestItem()
  6077. {
  6078. Parameter_name = "载具穴号",
  6079. Parameter_value = "1",
  6080. });
  6081. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6082. }
  6083. // 调用MES进站 - 产品2
  6084. int result2 = c1Part2Result_Check;
  6085. if (result2 != 3)
  6086. {
  6087. item = new List<TestItem>();
  6088. item.Add(new TestItem()
  6089. {
  6090. Parameter_name = "载具码",
  6091. Parameter_value = sn,
  6092. });
  6093. item.Add(new TestItem()
  6094. {
  6095. Parameter_name = "载具穴号",
  6096. Parameter_value = "2",
  6097. });
  6098. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6099. }
  6100. stopwatch2.Stop();
  6101. if (result1 == 2)
  6102. c1Part1Result_Check = 2;
  6103. if (result2 == 2)
  6104. c1Part2Result_Check = 2;
  6105. int result = result1;
  6106. if (result == 1)
  6107. result = result2;
  6108. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6109. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6110. short c1MES_FLAG_Check = (short)result;
  6111. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6112. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6113. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6114. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6115. //// MES_Flag
  6116. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6117. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6118. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6119. writeToPLC_Flag.Adress = 2003;
  6120. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6121. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6122. {
  6123. Name = "c1Part1Result_Check",
  6124. Adress = 2024,
  6125. ValueType = PLCValueType.Short,
  6126. Value = c1Part1Result_Check
  6127. });
  6128. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6129. {
  6130. Name = "c1Part2Result_Check",
  6131. Adress = 2025,
  6132. ValueType = PLCValueType.Short,
  6133. Value = c1Part2Result_Check
  6134. });
  6135. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6136. {
  6137. Name = "c1Part1Num_Check",
  6138. Adress = 2026,
  6139. ValueType = PLCValueType.Short,
  6140. Value = c1Part1Num_Check
  6141. });
  6142. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6143. {
  6144. Name = "c1Part2Num_Check",
  6145. Adress = 2027,
  6146. ValueType = PLCValueType.Short,
  6147. Value = c1Part2Num_Check
  6148. });
  6149. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6150. }
  6151. catch (Exception ex)
  6152. {
  6153. string str = ex.StackTrace;
  6154. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6155. // MES_Flag
  6156. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6157. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6158. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6159. writeToPLC_Flag.Adress = 2003;
  6160. writeToPLC_Flag.Value = (short)6;
  6161. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6162. }
  6163. stopwatch1.Stop();
  6164. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6165. }
  6166. /// <summary>
  6167. /// [S3] 值板机 - 二穴载具解绑
  6168. /// </summary>
  6169. /// <param name="plcNo">PLC编号</param>
  6170. /// <param name="stationNameStr">工站全称</param>
  6171. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6172. {
  6173. Stopwatch stopwatch1 = new Stopwatch();
  6174. Stopwatch stopwatch2 = new Stopwatch();
  6175. try
  6176. {
  6177. stopwatch1.Start();
  6178. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6179. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6180. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6181. // 解绑
  6182. #region 查询载具上的产品信息
  6183. string cavityData = string.Empty;
  6184. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6185. if (string.IsNullOrEmpty(cavityData))
  6186. cavityData = "";
  6187. if (snResult != 0)
  6188. {
  6189. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6190. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6191. writeToPLC_Flag1.Adress = 2082;
  6192. writeToPLC_Flag1.Value = (short)6;
  6193. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6194. stopwatch1.Stop();
  6195. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6196. return;
  6197. }
  6198. #endregion 查询载具上的产品信息
  6199. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6200. #region 解绑
  6201. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6202. {
  6203. // 删除
  6204. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6205. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6206. }
  6207. else
  6208. {
  6209. string data_new = string.Join(".", cavitySNs);
  6210. // 删除再插入
  6211. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6212. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6213. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6214. }
  6215. #endregion 解绑
  6216. short c1MES_FLAG_Unbind = 1;
  6217. stopwatch2.Start();
  6218. // MES_Flag
  6219. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6220. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6221. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6222. writeToPLC_Flag.Adress = 2082;
  6223. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6224. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6225. stopwatch2.Stop();
  6226. }
  6227. catch (Exception ex)
  6228. {
  6229. string str = ex.StackTrace;
  6230. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6231. // MES_Flag
  6232. stopwatch2.Start();
  6233. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6234. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6235. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6236. writeToPLC_Flag.Adress = 2082;
  6237. writeToPLC_Flag.Value = (short)6;
  6238. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6239. stopwatch2.Stop();
  6240. }
  6241. stopwatch1.Stop();
  6242. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6243. }
  6244. /// <summary>
  6245. /// [S3] 值板机 - 二穴载具绑定
  6246. /// </summary>
  6247. /// <param name="plcNo">PLC编号</param>
  6248. /// <param name="stationNameStr">工站全称</param>
  6249. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6250. {
  6251. Stopwatch stopwatch1 = new Stopwatch();
  6252. Stopwatch stopwatch2 = new Stopwatch();
  6253. try
  6254. {
  6255. stopwatch1.Start();
  6256. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6257. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6258. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6259. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6260. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6261. stopwatch2.Start();
  6262. #region 查询载具上的产品信息
  6263. string cavityData = string.Empty;
  6264. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6265. if (string.IsNullOrEmpty(cavityData))
  6266. cavityData = "";
  6267. if (snResult != 0)
  6268. {
  6269. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6270. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6271. writeToPLC_Flag1.Adress = 2115;
  6272. writeToPLC_Flag1.Value = (short)6;
  6273. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6274. stopwatch1.Stop();
  6275. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6276. return;
  6277. }
  6278. #endregion 查询载具上的产品信息
  6279. // 产品换载具
  6280. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6281. string partSn1 = "";
  6282. string partSn2 = "";
  6283. if (cavitySNs != null && cavitySNs.Length >= 2)
  6284. {
  6285. partSn1 = cavitySNs[0];
  6286. partSn2 = cavitySNs[1];
  6287. }
  6288. string data_new = string.Empty;
  6289. // 是否是两个穴位交换
  6290. if (c1CavityReverse_Bind == 1)
  6291. {
  6292. // 交换
  6293. data_new = string.Concat(partSn2, ".", partSn1);
  6294. }
  6295. else
  6296. { // 不交换
  6297. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6298. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6299. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6300. data_new = string.Join(".", cavitySNs);
  6301. }
  6302. // 删除再插入
  6303. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6304. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6305. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6306. stopwatch2.Stop();
  6307. short c1MES_FLAG_Bind = 1;
  6308. // MES_Flag
  6309. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6310. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6311. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6312. writeToPLC_Flag.Adress = 2115;
  6313. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6314. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6315. }
  6316. catch (Exception ex)
  6317. {
  6318. string str = ex.StackTrace;
  6319. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6320. // MES_Flag
  6321. stopwatch2.Start();
  6322. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6323. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6324. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6325. writeToPLC_Flag.Adress = 2115;
  6326. writeToPLC_Flag.Value = (short)6;
  6327. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6328. stopwatch2.Stop();
  6329. }
  6330. stopwatch1.Stop();
  6331. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6332. }
  6333. //// 上次采集到的SN
  6334. //private string sn_值板机 = string.Empty;
  6335. /// <summary>
  6336. /// [S3] 值板机 - 出站接口
  6337. /// </summary>
  6338. /// <param name="plcNo">PLC编号</param>
  6339. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6340. {
  6341. Stopwatch stopwatch1 = new Stopwatch();
  6342. Stopwatch stopwatch2 = new Stopwatch();
  6343. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6344. string stationNameStr = stationCode + stationName;
  6345. string processItem = stationName; // 测试项目
  6346. try
  6347. {
  6348. stopwatch1.Start();
  6349. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6350. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6351. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6352. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6353. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6354. sn = sn.Replace("\0", "");
  6355. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6356. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6357. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6358. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6359. bool pass = c1Result == 1;
  6360. // 查sn
  6361. #region 查询载具上的产品信息
  6362. string cavityData = string.Empty;
  6363. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6364. if (string.IsNullOrEmpty(cavityData))
  6365. cavityData = "";
  6366. if (snResult != 0)
  6367. {
  6368. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6369. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6370. writeToPLC_Flag1.Adress = 2150;
  6371. writeToPLC_Flag1.Value = (short)4;
  6372. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6373. stopwatch1.Stop();
  6374. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6375. return;
  6376. }
  6377. #endregion 查询载具上的产品信息
  6378. string[] cavitySNs = cavityData.Split('.');
  6379. string productSN = "";
  6380. if (cavitySNs != null && cavitySNs.Length >= 2)
  6381. {
  6382. productSN = cavitySNs[c1VehicleCavity];
  6383. cavitySNs[c1VehicleCavity] = "";
  6384. }
  6385. stopwatch2.Start();
  6386. List<TestItem> items = new List<TestItem>();
  6387. items.Add(new TestItem()
  6388. {
  6389. Parameter_name = "二穴载具码",
  6390. Parameter_value = c1ProductSN_Check,
  6391. Parameter_unit = ""
  6392. });
  6393. items.Add(new TestItem()
  6394. {
  6395. Parameter_name = "二穴载具穴号",
  6396. Parameter_value = c1VehicleCavity.ToString(),
  6397. Parameter_unit = ""
  6398. });
  6399. items.Add(new TestItem()
  6400. {
  6401. Parameter_name = "一穴载具码",
  6402. Parameter_value = sn,
  6403. Parameter_unit = ""
  6404. });
  6405. items.Add(new TestItem()
  6406. {
  6407. Parameter_name = "一穴载具穴号",
  6408. Parameter_value = "1",
  6409. Parameter_unit = ""
  6410. });
  6411. items.Add(new TestItem()
  6412. {
  6413. Parameter_name = "产品结果",
  6414. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6415. Parameter_unit = ""
  6416. });
  6417. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6418. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6419. short result = (short)result1;
  6420. stopwatch2.Stop();
  6421. #region 存储绑定数据到 边线MES系统中
  6422. if (result == 1)
  6423. {
  6424. string data = string.Concat(productSN);
  6425. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6426. if (resultMesR != 0)
  6427. {
  6428. result = 4;
  6429. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6430. }
  6431. }
  6432. #endregion 存储绑定数据到 边线MES系统中
  6433. #region 产品从 来源载具(二穴载具)中删除
  6434. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6435. {
  6436. // 删除
  6437. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6438. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6439. }
  6440. else
  6441. {
  6442. string data_new = string.Join(".", cavitySNs);
  6443. // 删除再插入
  6444. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6445. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6446. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6447. }
  6448. #endregion 产品从 来源载具(二穴载具)中删除
  6449. // MES_Flag 为MES报错
  6450. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6451. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6452. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6453. writeToPLC_Flag.Name = "c1MES_FLAG";
  6454. writeToPLC_Flag.Adress = 2150;
  6455. writeToPLC_Flag.Value = result;
  6456. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6457. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6458. }
  6459. catch (Exception ex)
  6460. {
  6461. stopwatch2.Restart();
  6462. // MES_Flag 为4上位机报错
  6463. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6464. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6465. writeToPLC_Flag.Name = "c1MES_FLAG";
  6466. writeToPLC_Flag.Adress = 2150;
  6467. writeToPLC_Flag.Value = (short)4;
  6468. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6469. stopwatch2.Stop();
  6470. string str = ex.StackTrace;
  6471. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6472. }
  6473. stopwatch1.Stop();
  6474. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6475. }
  6476. /// <summary>
  6477. /// [S3] 值板机- 节拍接口
  6478. /// </summary>
  6479. /// <param name="plcNo">PLC编号</param>
  6480. /// <param name="stationNameStr">工站全称</param>
  6481. private void S3节拍接口(int plcNo, string stationNameStr)
  6482. {
  6483. Stopwatch stopwatch1 = new Stopwatch();
  6484. Stopwatch stopwatch2 = new Stopwatch();
  6485. string resultStr = string.Empty;
  6486. try
  6487. {
  6488. stopwatch1.Start();
  6489. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6490. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6491. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6492. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6493. if (!actionBool)
  6494. {
  6495. stopwatch2.Start();
  6496. // MES_Flag
  6497. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6498. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6499. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6500. writeToPLC_Flag1.Adress = 2204;
  6501. writeToPLC_Flag1.Value = (short)4;
  6502. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6503. stopwatch2.Stop();
  6504. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6505. return;
  6506. }
  6507. string c1OEEPartNo = string.Empty; // 物料码
  6508. if (string.IsNullOrEmpty(c1OEEProductSN))
  6509. {
  6510. stopwatch2.Start();
  6511. // MES_Flag
  6512. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6513. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6514. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6515. writeToPLC_Flag1.Adress = 2204;
  6516. writeToPLC_Flag1.Value = (short)1;
  6517. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6518. stopwatch2.Stop();
  6519. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6520. return;
  6521. }
  6522. else
  6523. { // 查产品SN
  6524. c1OEEPartNo = "Test"; // ZS
  6525. }
  6526. short c1OEEMES_FLAG = 0;
  6527. // 上传OEE
  6528. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6529. c1OEEMES_FLAG = result.Item1;
  6530. resultStr = result.Item2;
  6531. stopwatch2.Start();
  6532. // MES_Flag
  6533. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6534. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6535. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6536. writeToPLC_Flag.Adress = 2204;
  6537. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6538. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6539. stopwatch2.Stop();
  6540. }
  6541. catch (Exception ex)
  6542. {
  6543. string str = ex.StackTrace;
  6544. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6545. // MES_Flag
  6546. stopwatch2.Start();
  6547. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6548. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6549. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6550. writeToPLC_Flag.Adress = 2204;
  6551. writeToPLC_Flag.Value = (short)4;
  6552. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6553. stopwatch2.Stop();
  6554. }
  6555. stopwatch1.Stop();
  6556. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6557. }
  6558. #endregion [S3] 值板机
  6559. #endregion PLC3 刘永村
  6560. #region PLC4 刘果段
  6561. #region [S4] 取放桁架
  6562. /// <summary>
  6563. /// S4工位的数据- 触发信号上次的值
  6564. /// </summary>
  6565. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6566. /// <summary>
  6567. /// S4工位的数据(含触发信号)
  6568. /// </summary>
  6569. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6570. /// <summary>
  6571. /// S4工位的数据- 回写点位
  6572. /// </summary>
  6573. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6574. /// <summary>
  6575. /// [S4] 取放桁架
  6576. /// </summary>
  6577. /// <param name="plcNo">PLC编号</param>
  6578. //private void ReadStation_S4(int plcNo)
  6579. //{
  6580. // // [S1] Tray盘上料装备
  6581. // // [S2] FCT
  6582. // // [S3] 值板机
  6583. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6584. // // [S5] Tray盘下料装备
  6585. // /// 上位机心跳
  6586. // /// 获取设备报警数据与状态信息
  6587. // string stationCode = "[S4_1]";
  6588. // string stationName = "载具下线装备";
  6589. // string stationNameStr = stationCode + stationName;
  6590. // string stationCode2 = "[S4_2]";
  6591. // string stationName2 = "桁架";
  6592. // string stationNameStr2 = stationCode2 + stationName2;
  6593. // string stationCode3 = "[S4_3]";
  6594. // string stationName3 = "提升机1";
  6595. // string stationNameStr3 = stationCode3 + stationName3;
  6596. // string stationCode4 = "[S4_4]";
  6597. // string stationName4 = "提升机2";
  6598. // string stationNameStr4 = stationCode4 + stationName4;
  6599. // string stationCode5 = "[S4_5]";
  6600. // string stationName5 = "载具上线装备";
  6601. // string stationNameStr5 = stationCode5 + stationName5;
  6602. // #region 创建字典
  6603. // // 触发信号字典 赋值
  6604. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6605. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6606. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6607. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6608. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6609. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6610. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6611. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6612. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6613. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6614. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6615. // // PLC数据字典 赋值
  6616. // // 载具下线装备(弹夹上线)
  6617. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6618. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6619. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6620. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6621. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6622. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6623. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6624. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6625. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6626. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6627. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6628. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6629. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6630. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6631. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6632. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6633. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6634. // s4PLCData.Add("d1Result", 0); // 产品结果
  6635. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6636. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6637. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6638. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6639. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6640. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6641. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6642. // // 真空标机(提升机)
  6643. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6644. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6645. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6646. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6647. // s4PLCData.Add("d3Result", 0); // 产品结果
  6648. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6649. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6650. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6651. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6652. // s4PLCData.Add("d4Result", 0); // 产品结果
  6653. // // 载具上线装备(弹夹下线)
  6654. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6655. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6656. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6657. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6658. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6659. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6660. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6661. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6662. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6663. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6664. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6665. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6666. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6667. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6668. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6669. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6670. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6671. // s4PLCData.Add("d5Result", 0); // 产品结果
  6672. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6673. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6674. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6675. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6676. // #endregion 创建字典
  6677. // while (IsRun)
  6678. // {
  6679. // try
  6680. // {
  6681. // if (!GlobalContext._IsCon_Funs4)
  6682. // {
  6683. // UpdatePLCMonitor(1, plcNo, 0);
  6684. // continue;
  6685. // }
  6686. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6687. // {
  6688. // Stopwatch stopwatch1 = new Stopwatch();
  6689. // Stopwatch stopwatch2 = new Stopwatch();
  6690. // stopwatch1.Start();
  6691. // stopwatch2.Start();
  6692. // #region 一次性读取所有数据
  6693. // // 载具下线装备(弹夹上线)
  6694. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6695. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6696. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6697. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6698. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6699. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6700. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6701. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6702. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6703. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6704. // int[] datas = data1.Concat(data2).ToArray();
  6705. // datas = datas.Concat(data3).ToArray();
  6706. // datas = datas.Concat(data4).ToArray();
  6707. // datas = datas.Concat(data5).ToArray();
  6708. // datas = datas.Concat(data6).ToArray();
  6709. // datas = datas.Concat(data7).ToArray();
  6710. // datas = datas.Concat(data8).ToArray();
  6711. // datas = datas.Concat(data9).ToArray();
  6712. // datas = datas.Concat(data10).ToArray();
  6713. // // 载具下线装备(弹夹上线)
  6714. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6715. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6716. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6717. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6718. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6719. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6720. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6721. // s4PLCData["d1MES_FLAG"] = datas[65];
  6722. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6723. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6724. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6725. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6726. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6727. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6728. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6729. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6730. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6731. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6732. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6733. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6734. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6735. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6736. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6737. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6738. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6739. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6740. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6741. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6742. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6743. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6744. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6745. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6746. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6747. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6748. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6749. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6750. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6751. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6752. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6753. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6754. // s4PLCData["d1Result"] = datas[386];
  6755. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6756. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6757. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6758. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6759. // s4PLCData["d1OEEType"] = datas[419];
  6760. // // 桁架(查询标机中弹夹的状态)
  6761. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6762. // s4PLCData["d2BulletclipStates"] = datas[431];
  6763. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6764. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6765. // // 真空标机
  6766. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6767. // s4PLCData["d3MES_FLAG"] = datas[463];
  6768. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6769. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6770. // s4PLCData["d3Result"] = datas[484];
  6771. // s4PLCData["d3Type"] = datas[485];
  6772. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6773. // s4PLCData["d4MES_FLAG"] = datas[496];
  6774. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6775. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6776. // s4PLCData["d4Result"] = datas[517];
  6777. // s4PLCData["d4Type"] = datas[518];
  6778. // // 载具上线装备(弹夹下线)
  6779. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6780. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6781. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6782. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6783. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6784. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6785. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6786. // s4PLCData["d5MES_FLAG"] = datas[591];
  6787. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6788. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6789. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6790. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6791. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6792. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6793. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6794. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6795. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6796. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6797. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6798. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6799. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6800. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6801. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6802. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6803. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6804. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6805. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6806. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6807. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6808. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6809. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6810. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6811. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6812. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6813. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6814. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6815. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6816. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6817. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6818. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6819. // s4PLCData["d5Result"] = datas[912];
  6820. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  6821. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  6822. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  6823. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  6824. // s4PLCData["d5OEEType"] = datas[945];
  6825. // #endregion 一次性读取所有数据
  6826. // stopwatch2.Stop();
  6827. // #region 回写操作,写后清空flag
  6828. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  6829. // #endregion 回写操作,写后清空flag
  6830. // // N801A-S4_1 弹夹扫码
  6831. // #region N801A-S4_1 弹夹扫码
  6832. // try
  6833. // {
  6834. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  6835. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  6836. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  6837. // {
  6838. // if (d1BulletclipScanCode == 1) // 0->1
  6839. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6840. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  6841. // }
  6842. // }
  6843. // catch (Exception ex)
  6844. // {
  6845. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  6846. // string str = ex.StackTrace;
  6847. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6848. // }
  6849. // #endregion N801A-S4_1 弹夹扫码
  6850. // // N801A-S4_1 载具扫码
  6851. // #region N801A-S4_1 载具扫码
  6852. // try
  6853. // {
  6854. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  6855. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  6856. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  6857. // {
  6858. // if (d1VehicleScanCode == 1) // 0->1
  6859. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6860. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  6861. // }
  6862. // }
  6863. // catch (Exception ex)
  6864. // {
  6865. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  6866. // string str = ex.StackTrace;
  6867. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6868. // }
  6869. // #endregion N801A-S4_1 载具扫码
  6870. // // N801A-S4_1 出站接口
  6871. // #region N801A-S4_1 出站接口
  6872. // try
  6873. // {
  6874. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  6875. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  6876. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  6877. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  6878. // {
  6879. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  6880. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6881. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  6882. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  6883. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  6884. // }
  6885. // }
  6886. // catch (Exception ex)
  6887. // {
  6888. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  6889. // string str = ex.StackTrace;
  6890. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6891. // }
  6892. // #endregion N801A-S4_1 出站接口
  6893. // // N801A-S4_1 节拍接口
  6894. // #region N801A-S4_1 节拍接口
  6895. // try
  6896. // {
  6897. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  6898. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  6899. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  6900. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  6901. // {
  6902. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  6903. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6904. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  6905. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  6906. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  6907. // }
  6908. // }
  6909. // catch (Exception ex)
  6910. // {
  6911. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  6912. // string str = ex.StackTrace;
  6913. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6914. // }
  6915. // #endregion N801A-S4_1 节拍接口
  6916. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  6917. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  6918. // try
  6919. // {
  6920. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  6921. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  6922. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  6923. // {
  6924. // if (d2BulletclipScanCode == 1) // 0->1
  6925. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  6926. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  6927. // }
  6928. // }
  6929. // catch (Exception ex)
  6930. // {
  6931. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  6932. // string str = ex.StackTrace;
  6933. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6934. // }
  6935. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  6936. // // N801A-S4_3 真空标机1 数据
  6937. // #region N801A-S4_3 真空标机1
  6938. // try
  6939. // {
  6940. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  6941. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  6942. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  6943. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  6944. // {
  6945. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  6946. // {
  6947. // int stationType = (int)s4PLCData["d3Type"];
  6948. // if (stationType == 1)
  6949. // {
  6950. // // S4_3进站接口
  6951. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  6952. // }
  6953. // else if (stationType == 2)
  6954. // {
  6955. // // S4_3出站接口
  6956. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  6957. // }
  6958. // }
  6959. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  6960. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  6961. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  6962. // }
  6963. // }
  6964. // catch (Exception ex)
  6965. // {
  6966. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  6967. // string str = ex.StackTrace;
  6968. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6969. // }
  6970. // #endregion N801A-S4_3 真空标机1
  6971. // // N801A-S4_4 真空标机2 数据
  6972. // #region N801A-S4_4 真空标机2
  6973. // try
  6974. // {
  6975. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  6976. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  6977. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  6978. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  6979. // {
  6980. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  6981. // {
  6982. // int stationType = (int)s4PLCData["d4Type"];
  6983. // if (stationType == 1)
  6984. // {
  6985. // // S4_4进站接口
  6986. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  6987. // }
  6988. // else if (stationType == 2)
  6989. // {
  6990. // // S4_4出站接口
  6991. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  6992. // }
  6993. // }
  6994. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  6995. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  6996. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  6997. // }
  6998. // }
  6999. // catch (Exception ex)
  7000. // {
  7001. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7002. // string str = ex.StackTrace;
  7003. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7004. // }
  7005. // #endregion N801A-S4_4 真空标机2
  7006. // // N801A-S4_5 弹夹扫码 数据
  7007. // #region N801A-S4_5 弹夹扫码
  7008. // try
  7009. // {
  7010. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7011. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7012. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7013. // {
  7014. // if (d5BulletclipScanCode == 1) // 0->1
  7015. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7016. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7017. // }
  7018. // }
  7019. // catch (Exception ex)
  7020. // {
  7021. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7022. // string str = ex.StackTrace;
  7023. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7024. // }
  7025. // #endregion N801A-S4_5 弹夹扫码
  7026. // // N801A-S4_5 载具扫码 数据
  7027. // #region N801A-S4_5 载具扫码
  7028. // try
  7029. // {
  7030. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7031. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7032. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7033. // {
  7034. // if (d5VehicleScanCode == 1) // 0->1
  7035. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7036. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7037. // }
  7038. // }
  7039. // catch (Exception ex)
  7040. // {
  7041. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7042. // string str = ex.StackTrace;
  7043. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7044. // }
  7045. // #endregion N801A-S4_5 载具扫码
  7046. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7047. // #region N801A-S4_5 出站接口
  7048. // try
  7049. // {
  7050. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7051. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7052. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7053. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7054. // {
  7055. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7056. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7057. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7058. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7059. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7060. // }
  7061. // }
  7062. // catch (Exception ex)
  7063. // {
  7064. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7065. // string str = ex.StackTrace;
  7066. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7067. // }
  7068. // #endregion N801A-S4_5 出站接口
  7069. // // N801A-S4_5 节拍接口 数据
  7070. // #region N801A-S4_5 节拍接口
  7071. // try
  7072. // {
  7073. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7074. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7075. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7076. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7077. // {
  7078. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7079. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7080. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7081. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7082. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7083. // }
  7084. // }
  7085. // catch (Exception ex)
  7086. // {
  7087. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7088. // string str = ex.StackTrace;
  7089. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7090. // }
  7091. // #endregion N801A-S4_5 节拍接口
  7092. // #region 心跳
  7093. // try
  7094. // {
  7095. // short states = 0;
  7096. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7097. // }
  7098. // catch (Exception ex)
  7099. // {
  7100. // string str = ex.StackTrace;
  7101. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7102. // }
  7103. // #endregion 心跳
  7104. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7105. // stopwatch1.Stop();
  7106. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7107. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7108. // }
  7109. // else
  7110. // {
  7111. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7112. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7113. // Funs[plcNo].Connect();
  7114. // }
  7115. // }
  7116. // catch (Exception ex)
  7117. // {
  7118. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7119. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7120. // Funs[plcNo].ReConnect();
  7121. // }
  7122. // Thread.Sleep(IntervalReadPLC);
  7123. // }
  7124. //}
  7125. /// <summary>
  7126. /// [S4] 取放桁架 - S4_1弹夹扫码
  7127. /// </summary>
  7128. /// <param name="plcNo">PLC编号</param>
  7129. /// <param name="stationNameStr">工站全称</param>
  7130. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7131. {
  7132. Stopwatch stopwatch1 = new Stopwatch();
  7133. Stopwatch stopwatch2 = new Stopwatch();
  7134. try
  7135. {
  7136. stopwatch1.Start();
  7137. // ZS 弹夹扫码
  7138. string d1BulletclipCode = " "; // 扫到的码
  7139. short d1BulletclipScanCode = 2;
  7140. stopwatch2.Start();
  7141. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7142. //// MES_Flag
  7143. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7144. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7145. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7146. writeToPLC_Flag.Adress = 2002;
  7147. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7148. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7149. {
  7150. Name = "d1BulletclipCode",
  7151. Adress = 2003,
  7152. ValueType = PLCValueType.String,
  7153. ValueTypeStrLength = 20,
  7154. Value = d1BulletclipCode
  7155. });
  7156. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7157. stopwatch2.Stop();
  7158. }
  7159. catch (Exception ex)
  7160. {
  7161. string str = ex.StackTrace;
  7162. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7163. stopwatch2.Start();
  7164. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7165. //// MES_Flag
  7166. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7167. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7168. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7169. writeToPLC_Flag.Adress = 2002;
  7170. writeToPLC_Flag.Value = (short)6;
  7171. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7172. {
  7173. Name = "d1BulletclipCode",
  7174. Adress = 2003,
  7175. ValueType = PLCValueType.String,
  7176. ValueTypeStrLength = 20,
  7177. Value = " "
  7178. });
  7179. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7180. stopwatch2.Stop();
  7181. }
  7182. stopwatch1.Stop();
  7183. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7184. }
  7185. /// <summary>
  7186. /// [S4] 取放桁架 - S4_1载具扫码
  7187. /// </summary>
  7188. /// <param name="plcNo">PLC编号</param>
  7189. /// <param name="stationNameStr">工站全称</param>
  7190. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7191. {
  7192. Stopwatch stopwatch1 = new Stopwatch();
  7193. Stopwatch stopwatch2 = new Stopwatch();
  7194. try
  7195. {
  7196. stopwatch1.Start();
  7197. // ZS 载具扫码
  7198. string d1VehicleCode = ""; // 扫到的码
  7199. short d1VehicleScanCode = 2;
  7200. #region 进站
  7201. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7202. {
  7203. #region 查询载具上的产品信息
  7204. string cavityData = string.Empty;
  7205. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7206. if (string.IsNullOrEmpty(cavityData))
  7207. cavityData = "";
  7208. if (snResult != 0)
  7209. {
  7210. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7211. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7212. writeToPLC_Flag1.Adress = 2033;
  7213. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7214. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7215. {
  7216. Name = "d1VehicleCode",
  7217. Adress = 2034,
  7218. ValueType = PLCValueType.String,
  7219. ValueTypeStrLength = 20,
  7220. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7221. });
  7222. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7223. stopwatch1.Stop();
  7224. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7225. return;
  7226. }
  7227. string[] cavitySNs = cavityData.Split('.');
  7228. string partNo = "";
  7229. if (cavitySNs != null && cavitySNs.Length >= 1)
  7230. {
  7231. partNo = cavitySNs[0];
  7232. }
  7233. #endregion 查询载具上的产品信息
  7234. List<TestItem> item = new List<TestItem>();
  7235. item.Add(new TestItem()
  7236. {
  7237. Parameter_name = "载具码",
  7238. Parameter_value = d1VehicleCode,
  7239. });
  7240. item.Add(new TestItem()
  7241. {
  7242. Parameter_name = "载具穴号",
  7243. Parameter_value = "1",
  7244. });
  7245. stopwatch2.Start();
  7246. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7247. stopwatch2.Stop();
  7248. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7249. }
  7250. #endregion 进站
  7251. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7252. //// MES_Flag
  7253. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7254. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7255. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7256. writeToPLC_Flag.Adress = 2033;
  7257. writeToPLC_Flag.Value = d1VehicleScanCode;
  7258. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7259. {
  7260. Name = "d1VehicleCode",
  7261. Adress = 2034,
  7262. ValueType = PLCValueType.String,
  7263. ValueTypeStrLength = 20,
  7264. Value = d1VehicleCode
  7265. });
  7266. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7267. }
  7268. catch (Exception ex)
  7269. {
  7270. string str = ex.StackTrace;
  7271. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7272. stopwatch2.Start();
  7273. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7274. //// MES_Flag
  7275. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7276. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7277. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7278. writeToPLC_Flag.Adress = 2033;
  7279. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7280. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7281. {
  7282. Name = "d1VehicleCode",
  7283. Adress = 2034,
  7284. ValueType = PLCValueType.String,
  7285. ValueTypeStrLength = 20,
  7286. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7287. });
  7288. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7289. stopwatch2.Stop();
  7290. }
  7291. stopwatch1.Stop();
  7292. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7293. }
  7294. // 上次采集到的SN
  7295. //private string sn_S4_1出站接口 = string.Empty;
  7296. /// <summary>
  7297. /// [S4] 取放桁架 - S4_1出站接口
  7298. /// </summary>
  7299. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7300. {
  7301. Stopwatch stopwatch1 = new Stopwatch();
  7302. Stopwatch stopwatch2 = new Stopwatch();
  7303. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7304. string stationNameStr = stationCode + stationName;
  7305. string processItem = stationName; // 测试项目
  7306. try
  7307. {
  7308. stopwatch1.Start();
  7309. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7310. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7311. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7312. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7313. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7314. sn = sn.Replace("\0", "");
  7315. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7316. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7317. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7318. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7319. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7320. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7321. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7322. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7323. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7324. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7325. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7326. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7327. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7328. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7329. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7330. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7331. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7332. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7333. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7334. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7335. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7336. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7337. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7338. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7339. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7340. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7341. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7342. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7343. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7344. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7345. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7346. bool pass = d1Result == 1;
  7347. // 存 载具SN列表
  7348. List<string> vehicleCodes = new List<string>()
  7349. {
  7350. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7351. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7352. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7353. };
  7354. // 统一查 产品SN列表
  7355. List<string> partNos = new List<string>();
  7356. foreach (string vehicleCode in vehicleCodes)
  7357. {
  7358. if (string.IsNullOrEmpty(vehicleCode))
  7359. partNos.Add("");
  7360. else
  7361. {
  7362. string partNo = "";
  7363. #region 查询载具上的产品信息
  7364. string cavityData = string.Empty;
  7365. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7366. if (string.IsNullOrEmpty(cavityData))
  7367. cavityData = "";
  7368. if (snResult != 0)
  7369. {
  7370. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7371. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7372. writeToPLC_Flag1.Adress = 2065;
  7373. writeToPLC_Flag1.Value = (short)4;
  7374. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7375. stopwatch1.Stop();
  7376. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7377. return;
  7378. }
  7379. string[] cavitySNs = cavityData.Split('.');
  7380. if (cavitySNs != null && cavitySNs.Length >= 1)
  7381. partNo = cavitySNs[0];
  7382. #endregion 查询载具上的产品信息
  7383. partNos.Add(partNo);
  7384. }
  7385. }
  7386. // 统一上传
  7387. stopwatch2.Start();
  7388. List<int> results = new List<int>();
  7389. for (int i = 0; i < partNos.Count; i++)
  7390. {
  7391. string index = (i + 1).ToString(); // 弹夹穴号
  7392. if (string.IsNullOrEmpty(partNos[i]))
  7393. results.Add(1);
  7394. else
  7395. {
  7396. List<TestItem> items1 = new List<TestItem>();
  7397. items1.Add(new TestItem()
  7398. {
  7399. Parameter_name = "弹夹码",
  7400. Parameter_value = sn,
  7401. Parameter_unit = ""
  7402. });
  7403. items1.Add(new TestItem()
  7404. {
  7405. Parameter_name = "弹夹穴号",
  7406. Parameter_value = index,
  7407. Parameter_unit = ""
  7408. });
  7409. items1.Add(new TestItem()
  7410. {
  7411. Parameter_name = "载具码",
  7412. Parameter_value = vehicleCodes[i],
  7413. Parameter_unit = ""
  7414. });
  7415. items1.Add(new TestItem()
  7416. {
  7417. Parameter_name = "载具穴号",
  7418. Parameter_value = "1",
  7419. Parameter_unit = ""
  7420. });
  7421. items1.Add(new TestItem()
  7422. {
  7423. Parameter_name = "产品结果",
  7424. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7425. Parameter_unit = ""
  7426. });
  7427. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7428. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7429. results.Add(result1);
  7430. }
  7431. }
  7432. short result = 0;
  7433. if (results.All(a => a == 1))
  7434. result = 1;
  7435. else if (results.Contains(3))
  7436. result = 3;
  7437. else if (results.Contains(2))
  7438. result = 2;
  7439. else if (results.Contains(4))
  7440. result = 4;
  7441. else
  7442. result = 4;
  7443. stopwatch2.Stop();
  7444. #region 存储绑定数据到 边线MES系统中
  7445. if (result == 1)
  7446. {
  7447. string data = string.Join(".", vehicleCodes);
  7448. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7449. if (resultMesR != 0)
  7450. {
  7451. result = 4;
  7452. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7453. }
  7454. }
  7455. #endregion 存储绑定数据到 边线MES系统中
  7456. // MES_Flag 为4MES报错
  7457. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7458. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7459. writeToPLC_Flag.Name = "d1MES_FLAG";
  7460. writeToPLC_Flag.Adress = 2065;
  7461. writeToPLC_Flag.Value = result;
  7462. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7463. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7464. }
  7465. catch (Exception ex)
  7466. {
  7467. stopwatch2.Restart();
  7468. // MES_Flag 为4上位机报错
  7469. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7470. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7471. writeToPLC_Flag.Name = "d1MES_FLAG";
  7472. writeToPLC_Flag.Adress = 2065;
  7473. writeToPLC_Flag.Value = (short)4;
  7474. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7475. stopwatch2.Stop();
  7476. string str = ex.StackTrace;
  7477. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7478. }
  7479. stopwatch1.Stop();
  7480. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7481. }
  7482. /// <summary>
  7483. /// [S4] 取放桁架 - S4_1节拍接口
  7484. /// </summary>
  7485. /// <param name="plcNo">PLC编号</param>
  7486. /// <param name="stationNameStr">工站全称</param>
  7487. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7488. {
  7489. Stopwatch stopwatch1 = new Stopwatch();
  7490. Stopwatch stopwatch2 = new Stopwatch();
  7491. string resultStr = string.Empty;
  7492. try
  7493. {
  7494. stopwatch1.Start();
  7495. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7496. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7497. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7498. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7499. if (!actionBool)
  7500. {
  7501. stopwatch2.Start();
  7502. // MES_Flag
  7503. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7504. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7505. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7506. writeToPLC_Flag1.Adress = 2398;
  7507. writeToPLC_Flag1.Value = (short)4;
  7508. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7509. stopwatch2.Stop();
  7510. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7511. return;
  7512. }
  7513. string d1OEEPartNo = string.Empty; // 物料码
  7514. if (string.IsNullOrEmpty(d1OEEProductSN))
  7515. {
  7516. stopwatch2.Start();
  7517. // MES_Flag
  7518. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7519. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7520. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7521. writeToPLC_Flag1.Adress = 2398;
  7522. writeToPLC_Flag1.Value = (short)1;
  7523. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7524. stopwatch2.Stop();
  7525. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7526. return;
  7527. }
  7528. else
  7529. { // 查产品SN ZS
  7530. d1OEEPartNo = "Test";
  7531. }
  7532. short d1OEEMES_FLAG = 0;
  7533. // 上传OEE
  7534. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7535. d1OEEMES_FLAG = result.Item1;
  7536. resultStr = result.Item2;
  7537. stopwatch2.Start();
  7538. // MES_Flag
  7539. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7540. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7541. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7542. writeToPLC_Flag.Adress = 2398;
  7543. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7544. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7545. stopwatch2.Stop();
  7546. }
  7547. catch (Exception ex)
  7548. {
  7549. string str = ex.StackTrace;
  7550. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7551. // MES_Flag
  7552. stopwatch2.Start();
  7553. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7554. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7555. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7556. writeToPLC_Flag.Adress = 2398;
  7557. writeToPLC_Flag.Value = (short)4;
  7558. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7559. stopwatch2.Stop();
  7560. }
  7561. stopwatch1.Stop();
  7562. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7563. }
  7564. /// <summary>
  7565. /// [S4] 取放桁架 - S4_2桁架
  7566. /// </summary>
  7567. /// <param name="plcNo">PLC编号</param>
  7568. /// <param name="stationNameStr">工站全称</param>
  7569. private void S4_2桁架(int plcNo, string stationNameStr)
  7570. {
  7571. Stopwatch stopwatch1 = new Stopwatch();
  7572. Stopwatch stopwatch2 = new Stopwatch();
  7573. try
  7574. {
  7575. stopwatch1.Start();
  7576. // ZS 弹夹扫码
  7577. string d2BulletclipCode = " "; // 扫到的码
  7578. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7579. short d2BulletclipScanCode = 2;
  7580. stopwatch2.Start();
  7581. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7582. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7583. //// MES_Flag
  7584. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7585. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7586. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7587. writeToPLC_Flag.Adress = 2430;
  7588. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7589. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7590. {
  7591. Name = "d2BulletclipCode",
  7592. Adress = 2432,
  7593. ValueType = PLCValueType.String,
  7594. ValueTypeStrLength = 20,
  7595. Value = d2BulletclipCode
  7596. });
  7597. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7598. {
  7599. Name = "d2BulletclipStates",
  7600. Adress = 2431,
  7601. ValueType = PLCValueType.Short,
  7602. Value = d2BulletclipStates
  7603. });
  7604. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7605. stopwatch2.Stop();
  7606. }
  7607. catch (Exception ex)
  7608. {
  7609. string str = ex.StackTrace;
  7610. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7611. stopwatch2.Start();
  7612. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7613. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7614. // MES_Flag
  7615. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7616. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7617. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7618. writeToPLC_Flag.Adress = 2430;
  7619. writeToPLC_Flag.Value = (short)6;
  7620. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7621. {
  7622. Name = "d2BulletclipCode",
  7623. Adress = 2432,
  7624. ValueType = PLCValueType.String,
  7625. ValueTypeStrLength = 20,
  7626. Value = " "
  7627. });
  7628. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7629. {
  7630. Name = "d2BulletclipStates",
  7631. Adress = 2431,
  7632. ValueType = PLCValueType.Short,
  7633. Value = (short)0
  7634. });
  7635. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7636. stopwatch2.Stop();
  7637. }
  7638. stopwatch1.Stop();
  7639. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7640. }
  7641. // 上次采集到的SN
  7642. //private string sn_S4_3进站接口 = string.Empty;
  7643. /// <summary>
  7644. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7645. /// </summary>
  7646. private void S4_3进站接口(int plcNo, string stationNameStr)
  7647. {
  7648. Stopwatch stopwatch1 = new Stopwatch();
  7649. Stopwatch stopwatch2 = new Stopwatch();
  7650. try
  7651. {
  7652. stopwatch1.Start();
  7653. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7654. sn = sn.Replace("\0", "");
  7655. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7656. #region 查询15个载具码
  7657. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7658. string vehicleData = string.Empty;
  7659. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7660. if (string.IsNullOrEmpty(vehicleData))
  7661. vehicleData = "";
  7662. if (snResult != 0)
  7663. {
  7664. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7665. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7666. writeToPLC_Flag1.Adress = 2463;
  7667. writeToPLC_Flag1.Value = (short)4;
  7668. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7669. stopwatch1.Stop();
  7670. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7671. return;
  7672. }
  7673. string[] cavitySNs = vehicleData.Split('.');
  7674. if (cavitySNs != null && cavitySNs.Length > 0)
  7675. {
  7676. for (int i = 0; i < cavitySNs.Length; i++)
  7677. {
  7678. if (string.IsNullOrEmpty(cavitySNs[i]))
  7679. vehicleCodes.Add("");
  7680. else
  7681. vehicleCodes.Add(cavitySNs[i]);
  7682. }
  7683. }
  7684. #endregion 查询15个载具码
  7685. #region 查询15个产品SN
  7686. List<string> portNos = new List<string>(); // 15个产品SN
  7687. foreach (string vehicleCode in vehicleCodes)
  7688. {
  7689. if (string.IsNullOrEmpty(vehicleCode))
  7690. portNos.Add("");
  7691. else
  7692. {
  7693. // 查询
  7694. string cavityData = string.Empty;
  7695. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7696. if (string.IsNullOrEmpty(cavityData))
  7697. cavityData = "";
  7698. if (snResult1 != 0)
  7699. {
  7700. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7701. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7702. writeToPLC_Flag1.Adress = 2463;
  7703. writeToPLC_Flag1.Value = (short)4;
  7704. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7705. stopwatch1.Stop();
  7706. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7707. return;
  7708. }
  7709. string[] partSNs = cavityData.Split('.');
  7710. if (partSNs != null && partSNs.Length >= 1)
  7711. portNos.Add(partSNs[0]);
  7712. else
  7713. portNos.Add("");
  7714. }
  7715. }
  7716. #endregion 查询15个产品SN
  7717. // 调用MES进站(最多15个)
  7718. stopwatch2.Start();
  7719. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7720. for (int i = 0; i < vehicleCodes.Count; i++)
  7721. {
  7722. // 循环进站
  7723. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7724. {
  7725. // 产品SN(物料码)校验
  7726. string portNo = portNos[i];
  7727. List<TestItem> item = new List<TestItem>();
  7728. item.Add(new TestItem()
  7729. {
  7730. Parameter_name = "弹夹码",
  7731. Parameter_value = sn,
  7732. });
  7733. item.Add(new TestItem()
  7734. {
  7735. Parameter_name = "弹夹穴位",
  7736. Parameter_value = (i + 1).ToString(),
  7737. });
  7738. item.Add(new TestItem()
  7739. {
  7740. Parameter_name = "载具码",
  7741. Parameter_value = vehicleCodes[i],
  7742. });
  7743. item.Add(new TestItem()
  7744. {
  7745. Parameter_name = "载具穴号",
  7746. Parameter_value = "1",
  7747. });
  7748. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7749. }
  7750. }
  7751. stopwatch2.Stop();
  7752. short result = 0;
  7753. bool haveMesWarn = results.Contains(5);
  7754. bool havePCWarn = results.Contains(6);
  7755. if (haveMesWarn)
  7756. result = 2; // 5->2
  7757. else if (havePCWarn)
  7758. result = 6; // 6->4
  7759. else
  7760. result = 1;
  7761. // MES_Flag 为4MES报错
  7762. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7763. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7764. writeToPLC_Flag.Name = "d3MES_FLAG";
  7765. writeToPLC_Flag.Adress = 2463;
  7766. writeToPLC_Flag.Value = result;
  7767. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7768. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7769. }
  7770. catch (Exception ex)
  7771. {
  7772. stopwatch2.Stop();
  7773. // MES_Flag 为4上位机报错
  7774. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7775. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7776. writeToPLC_Flag.Name = "d3MES_FLAG";
  7777. writeToPLC_Flag.Adress = 2463;
  7778. writeToPLC_Flag.Value = (short)4;
  7779. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7780. string str = ex.StackTrace;
  7781. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7782. }
  7783. stopwatch1.Stop();
  7784. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7785. }
  7786. // 上次采集到的SN
  7787. //private string sn_S4_3出站接口 = string.Empty;
  7788. /// <summary>
  7789. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7790. /// </summary>
  7791. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7792. {
  7793. Stopwatch stopwatch1 = new Stopwatch();
  7794. Stopwatch stopwatch2 = new Stopwatch();
  7795. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7796. string stationNameStr = stationCode + stationName;
  7797. string processItem = stationName; // 测试项目
  7798. try
  7799. {
  7800. stopwatch1.Start();
  7801. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7802. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7803. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7804. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7805. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7806. sn = sn.Replace("\0", "");
  7807. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7808. bool isPass = d3Result == 1; // 产品结果 bool
  7809. #region 查询15个载具码
  7810. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7811. string vehicleData = string.Empty;
  7812. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7813. if (string.IsNullOrEmpty(vehicleData))
  7814. vehicleData = "";
  7815. if (snResult1 != 0)
  7816. {
  7817. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7818. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7819. writeToPLC_Flag1.Adress = 2463;
  7820. writeToPLC_Flag1.Value = (short)4;
  7821. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7822. stopwatch1.Stop();
  7823. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7824. return;
  7825. }
  7826. string[] cavitySNs = vehicleData.Split('.');
  7827. if (cavitySNs != null && cavitySNs.Length > 0)
  7828. {
  7829. for (int i = 0; i < cavitySNs.Length; i++)
  7830. {
  7831. if (string.IsNullOrEmpty(cavitySNs[i]))
  7832. vehicleCodes.Add("");
  7833. else
  7834. vehicleCodes.Add(cavitySNs[i]);
  7835. }
  7836. }
  7837. #endregion 查询15个载具码
  7838. // 统一查 产品SN列表
  7839. List<string> partNos = new List<string>();
  7840. foreach (string vehicleCode in vehicleCodes)
  7841. {
  7842. if (string.IsNullOrEmpty(vehicleCode))
  7843. partNos.Add("");
  7844. else
  7845. {
  7846. string partNo = "";
  7847. #region 查询载具上的产品信息
  7848. string cavityData = string.Empty;
  7849. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7850. if (string.IsNullOrEmpty(cavityData))
  7851. cavityData = "";
  7852. if (snResult != 0)
  7853. {
  7854. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7855. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7856. writeToPLC_Flag1.Adress = 2463;
  7857. writeToPLC_Flag1.Value = (short)4;
  7858. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7859. stopwatch1.Stop();
  7860. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7861. return;
  7862. }
  7863. string[] partSNs = cavityData.Split('.');
  7864. if (partSNs != null && partSNs.Length >= 1)
  7865. partNo = partSNs[0];
  7866. #endregion 查询载具上的产品信息
  7867. partNos.Add(partNo);
  7868. }
  7869. }
  7870. // 统一上传 - 调用MES出站
  7871. stopwatch2.Start();
  7872. List<int> results = new List<int>();
  7873. for (int i = 0; i < partNos.Count; i++)
  7874. {
  7875. string index = (i + 1).ToString(); // 弹夹穴号
  7876. if (string.IsNullOrEmpty(partNos[i]))
  7877. results.Add(1);
  7878. else
  7879. {
  7880. List<TestItem> items1 = new List<TestItem>();
  7881. items1.Add(new TestItem()
  7882. {
  7883. Parameter_name = "弹夹码",
  7884. Parameter_value = sn,
  7885. Parameter_unit = ""
  7886. });
  7887. items1.Add(new TestItem()
  7888. {
  7889. Parameter_name = "弹夹穴号",
  7890. Parameter_value = index,
  7891. Parameter_unit = ""
  7892. });
  7893. items1.Add(new TestItem()
  7894. {
  7895. Parameter_name = "载具码",
  7896. Parameter_value = vehicleCodes[i],
  7897. Parameter_unit = ""
  7898. });
  7899. items1.Add(new TestItem()
  7900. {
  7901. Parameter_name = "载具穴号",
  7902. Parameter_value = "1",
  7903. Parameter_unit = ""
  7904. });
  7905. items1.Add(new TestItem()
  7906. {
  7907. Parameter_name = "产品结果",
  7908. Parameter_value = d3Result == 1 ? "OK" : "NG",
  7909. Parameter_unit = ""
  7910. });
  7911. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7912. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  7913. results.Add(result1);
  7914. }
  7915. }
  7916. short result = 0;
  7917. if (results.All(a => a == 1))
  7918. result = 1;
  7919. else if (results.Contains(3))
  7920. result = 3;
  7921. else if (results.Contains(2))
  7922. result = 2;
  7923. else if (results.Contains(4))
  7924. result = 4;
  7925. else
  7926. result = 4;
  7927. stopwatch2.Stop();
  7928. // MES_Flag 为4MES报错
  7929. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7930. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7931. writeToPLC_Flag.Name = "d3MES_FLAG";
  7932. writeToPLC_Flag.Adress = 2463;
  7933. writeToPLC_Flag.Value = result;
  7934. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7935. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7936. }
  7937. catch (Exception ex)
  7938. {
  7939. stopwatch2.Restart();
  7940. // MES_Flag 为4上位机报错
  7941. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7942. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7943. writeToPLC_Flag.Name = "d3MES_FLAG";
  7944. writeToPLC_Flag.Adress = 2463;
  7945. writeToPLC_Flag.Value = (short)4;
  7946. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7947. string str = ex.StackTrace;
  7948. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7949. stopwatch2.Stop();
  7950. }
  7951. stopwatch1.Stop();
  7952. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7953. }
  7954. // 上次采集到的SN
  7955. //private string sn_S4_4进站接口 = string.Empty;
  7956. /// <summary>
  7957. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  7958. /// </summary>
  7959. private void S4_4进站接口(int plcNo, string stationNameStr)
  7960. {
  7961. Stopwatch stopwatch1 = new Stopwatch();
  7962. Stopwatch stopwatch2 = new Stopwatch();
  7963. try
  7964. {
  7965. stopwatch1.Start();
  7966. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  7967. sn = sn.Replace("\0", "");
  7968. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  7969. #region 查询15个载具码
  7970. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7971. string vehicleData = string.Empty;
  7972. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7973. if (string.IsNullOrEmpty(vehicleData))
  7974. vehicleData = "";
  7975. if (snResult != 0)
  7976. {
  7977. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7978. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7979. writeToPLC_Flag1.Adress = 2463;
  7980. writeToPLC_Flag1.Value = (short)4;
  7981. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7982. stopwatch1.Stop();
  7983. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7984. return;
  7985. }
  7986. string[] cavitySNs = vehicleData.Split('.');
  7987. if (cavitySNs != null && cavitySNs.Length > 0)
  7988. {
  7989. for (int i = 0; i < cavitySNs.Length; i++)
  7990. {
  7991. if (string.IsNullOrEmpty(cavitySNs[i]))
  7992. vehicleCodes.Add("");
  7993. else
  7994. vehicleCodes.Add(cavitySNs[i]);
  7995. }
  7996. }
  7997. #endregion 查询15个载具码
  7998. #region 查询15个产品SN
  7999. List<string> portNos = new List<string>(); // 15个产品SN
  8000. foreach (string vehicleCode in vehicleCodes)
  8001. {
  8002. if (string.IsNullOrEmpty(vehicleCode))
  8003. portNos.Add("");
  8004. else
  8005. {
  8006. // 查询
  8007. string cavityData = string.Empty;
  8008. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8009. if (string.IsNullOrEmpty(cavityData))
  8010. cavityData = "";
  8011. if (snResult1 != 0)
  8012. {
  8013. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8014. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8015. writeToPLC_Flag1.Adress = 2463;
  8016. writeToPLC_Flag1.Value = (short)4;
  8017. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8018. stopwatch1.Stop();
  8019. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8020. return;
  8021. }
  8022. string[] partSNs = cavityData.Split('.');
  8023. if (partSNs != null && partSNs.Length >= 1)
  8024. portNos.Add(partSNs[0]);
  8025. else
  8026. portNos.Add("");
  8027. }
  8028. }
  8029. #endregion 查询15个产品SN
  8030. // 调用MES进站(最多15个)
  8031. stopwatch2.Start();
  8032. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8033. for (int i = 0; i < vehicleCodes.Count; i++)
  8034. {
  8035. // 循环进站
  8036. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8037. {
  8038. // 产品SN(物料码)校验
  8039. string portNo = portNos[i];
  8040. List<TestItem> item = new List<TestItem>();
  8041. item.Add(new TestItem()
  8042. {
  8043. Parameter_name = "弹夹码",
  8044. Parameter_value = sn,
  8045. });
  8046. item.Add(new TestItem()
  8047. {
  8048. Parameter_name = "弹夹穴位",
  8049. Parameter_value = (i + 1).ToString(),
  8050. });
  8051. item.Add(new TestItem()
  8052. {
  8053. Parameter_name = "载具码",
  8054. Parameter_value = vehicleCodes[i],
  8055. });
  8056. item.Add(new TestItem()
  8057. {
  8058. Parameter_name = "载具穴号",
  8059. Parameter_value = "1",
  8060. });
  8061. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8062. }
  8063. }
  8064. stopwatch2.Stop();
  8065. short result = 0;
  8066. bool haveMesWarn = results.Contains(5);
  8067. bool havePCWarn = results.Contains(6);
  8068. if (haveMesWarn)
  8069. result = 2; // 5->2
  8070. else if (havePCWarn)
  8071. result = 6; // 6->4
  8072. else
  8073. result = 1;
  8074. // MES_Flag 为4MES报错
  8075. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8076. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8077. writeToPLC_Flag.Name = "d4MES_FLAG";
  8078. writeToPLC_Flag.Adress = 2496;
  8079. writeToPLC_Flag.Value = result;
  8080. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8081. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8082. }
  8083. catch (Exception ex)
  8084. {
  8085. stopwatch2.Stop();
  8086. // MES_Flag 为4上位机报错
  8087. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8088. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8089. writeToPLC_Flag.Name = "d4MES_FLAG";
  8090. writeToPLC_Flag.Adress = 2496;
  8091. writeToPLC_Flag.Value = (short)4;
  8092. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8093. string str = ex.StackTrace;
  8094. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8095. }
  8096. stopwatch1.Stop();
  8097. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8098. }
  8099. // 上次采集到的SN
  8100. //private string sn_S4_4出站接口 = string.Empty;
  8101. /// <summary>
  8102. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8103. /// </summary>
  8104. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8105. {
  8106. Stopwatch stopwatch1 = new Stopwatch();
  8107. Stopwatch stopwatch2 = new Stopwatch();
  8108. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8109. string stationNameStr = stationCode + stationName;
  8110. string processItem = stationName; // 测试项目
  8111. try
  8112. {
  8113. stopwatch1.Start();
  8114. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8115. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8116. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8117. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8118. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8119. sn = sn.Replace("\0", "");
  8120. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8121. bool isPass = d4Result == 1; // 产品结果 bool
  8122. #region 查询15个载具码
  8123. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8124. string vehicleData = string.Empty;
  8125. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8126. if (string.IsNullOrEmpty(vehicleData))
  8127. vehicleData = "";
  8128. if (snResult1 != 0)
  8129. {
  8130. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8131. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8132. writeToPLC_Flag1.Adress = 2496;
  8133. writeToPLC_Flag1.Value = (short)4;
  8134. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8135. stopwatch1.Stop();
  8136. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8137. return;
  8138. }
  8139. string[] cavitySNs = vehicleData.Split('.');
  8140. if (cavitySNs != null && cavitySNs.Length > 0)
  8141. {
  8142. for (int i = 0; i < cavitySNs.Length; i++)
  8143. {
  8144. if (string.IsNullOrEmpty(cavitySNs[i]))
  8145. vehicleCodes.Add("");
  8146. else
  8147. vehicleCodes.Add(cavitySNs[i]);
  8148. }
  8149. }
  8150. #endregion 查询15个载具码
  8151. // 统一查 产品SN列表
  8152. List<string> partNos = new List<string>();
  8153. foreach (string vehicleCode in vehicleCodes)
  8154. {
  8155. if (string.IsNullOrEmpty(vehicleCode))
  8156. partNos.Add("");
  8157. else
  8158. {
  8159. string partNo = "";
  8160. #region 查询载具上的产品信息
  8161. string cavityData = string.Empty;
  8162. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8163. if (string.IsNullOrEmpty(cavityData))
  8164. cavityData = "";
  8165. if (snResult != 0)
  8166. {
  8167. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8168. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8169. writeToPLC_Flag1.Adress = 2496;
  8170. writeToPLC_Flag1.Value = (short)4;
  8171. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8172. stopwatch1.Stop();
  8173. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8174. return;
  8175. }
  8176. string[] partSNs = cavityData.Split('.');
  8177. if (partSNs != null && partSNs.Length >= 1)
  8178. partNo = partSNs[0];
  8179. #endregion 查询载具上的产品信息
  8180. partNos.Add(partNo);
  8181. }
  8182. }
  8183. // 调用MES出站
  8184. stopwatch2.Start();
  8185. // 统一上传
  8186. List<int> results = new List<int>();
  8187. for (int i = 0; i < partNos.Count; i++)
  8188. {
  8189. string index = (i + 1).ToString(); // 弹夹穴号
  8190. if (string.IsNullOrEmpty(partNos[i]))
  8191. results.Add(1);
  8192. else
  8193. {
  8194. List<TestItem> items1 = new List<TestItem>();
  8195. items1.Add(new TestItem()
  8196. {
  8197. Parameter_name = "弹夹码",
  8198. Parameter_value = sn,
  8199. Parameter_unit = ""
  8200. });
  8201. items1.Add(new TestItem()
  8202. {
  8203. Parameter_name = "弹夹穴号",
  8204. Parameter_value = index,
  8205. Parameter_unit = ""
  8206. });
  8207. items1.Add(new TestItem()
  8208. {
  8209. Parameter_name = "载具码",
  8210. Parameter_value = vehicleCodes[i],
  8211. Parameter_unit = ""
  8212. });
  8213. items1.Add(new TestItem()
  8214. {
  8215. Parameter_name = "载具穴号",
  8216. Parameter_value = "1",
  8217. Parameter_unit = ""
  8218. });
  8219. items1.Add(new TestItem()
  8220. {
  8221. Parameter_name = "产品结果",
  8222. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8223. Parameter_unit = ""
  8224. });
  8225. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8226. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8227. results.Add(result1);
  8228. }
  8229. }
  8230. short result = 0;
  8231. if (results.All(a => a == 1))
  8232. result = 1;
  8233. else if (results.Contains(3))
  8234. result = 3;
  8235. else if (results.Contains(2))
  8236. result = 2;
  8237. else if (results.Contains(4))
  8238. result = 4;
  8239. else
  8240. result = 4;
  8241. stopwatch2.Stop();
  8242. // MES_Flag 为4MES报错
  8243. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8244. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8245. writeToPLC_Flag.Name = "d4MES_FLAG";
  8246. writeToPLC_Flag.Adress = 2496;
  8247. writeToPLC_Flag.Value = result;
  8248. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8249. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8250. }
  8251. catch (Exception ex)
  8252. {
  8253. stopwatch2.Restart();
  8254. // MES_Flag 为4上位机报错
  8255. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8256. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8257. writeToPLC_Flag.Name = "d4MES_FLAG";
  8258. writeToPLC_Flag.Adress = 2496;
  8259. writeToPLC_Flag.Value = (short)4;
  8260. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8261. string str = ex.StackTrace;
  8262. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8263. stopwatch2.Stop();
  8264. }
  8265. stopwatch1.Stop();
  8266. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8267. }
  8268. /// <summary>
  8269. /// [S4] 取放桁架 - S4_5弹夹扫码
  8270. /// </summary>
  8271. /// <param name="plcNo">PLC编号</param>
  8272. /// <param name="stationNameStr">工站全称</param>
  8273. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8274. {
  8275. Stopwatch stopwatch1 = new Stopwatch();
  8276. Stopwatch stopwatch2 = new Stopwatch();
  8277. try
  8278. {
  8279. stopwatch1.Start();
  8280. // ZS 弹夹扫码
  8281. string d5BulletclipCode = " "; // 扫到的码
  8282. short d5BulletclipScanCode = 2;
  8283. stopwatch2.Start();
  8284. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8285. //// MES_Flag
  8286. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8287. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8288. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8289. writeToPLC_Flag.Adress = 2528;
  8290. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8291. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8292. {
  8293. Name = "d5BulletclipCode",
  8294. Adress = 2529,
  8295. ValueType = PLCValueType.String,
  8296. ValueTypeStrLength = 20,
  8297. Value = d5BulletclipCode
  8298. });
  8299. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8300. stopwatch2.Stop();
  8301. }
  8302. catch (Exception ex)
  8303. {
  8304. string str = ex.StackTrace;
  8305. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8306. stopwatch2.Start();
  8307. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8308. //// MES_Flag
  8309. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8310. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8311. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8312. writeToPLC_Flag.Adress = 2528;
  8313. writeToPLC_Flag.Value = (short)6;
  8314. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8315. {
  8316. Name = "d5BulletclipCode",
  8317. Adress = 2529,
  8318. ValueType = PLCValueType.String,
  8319. ValueTypeStrLength = 20,
  8320. Value = " "
  8321. });
  8322. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8323. stopwatch2.Stop();
  8324. }
  8325. stopwatch1.Stop();
  8326. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8327. }
  8328. /// <summary>
  8329. /// [S4] 取放桁架 - S4_5载具扫码
  8330. /// </summary>
  8331. /// <param name="plcNo">PLC编号</param>
  8332. /// <param name="stationNameStr">工站全称</param>
  8333. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8334. {
  8335. Stopwatch stopwatch1 = new Stopwatch();
  8336. Stopwatch stopwatch2 = new Stopwatch();
  8337. try
  8338. {
  8339. stopwatch1.Start();
  8340. // ZS 载具扫码
  8341. string d5VehicleCode = " "; // 扫到的码
  8342. short d5VehicleScanCode = 2;
  8343. #region 进站
  8344. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8345. {
  8346. // 查产品SN
  8347. #region 查询载具上的产品信息
  8348. string cavityData = string.Empty;
  8349. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8350. if (string.IsNullOrEmpty(cavityData))
  8351. cavityData = "";
  8352. if (snResult != 0)
  8353. {
  8354. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8355. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8356. writeToPLC_Flag1.Adress = 2559;
  8357. writeToPLC_Flag1.Value = (short)6;
  8358. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8359. {
  8360. Name = "d5VehicleCode",
  8361. Adress = 2560,
  8362. ValueType = PLCValueType.String,
  8363. ValueTypeStrLength = 20,
  8364. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8365. });
  8366. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8367. stopwatch1.Stop();
  8368. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8369. return;
  8370. }
  8371. string[] cavitySNs = cavityData.Split('.');
  8372. string partNo = "";
  8373. if (cavitySNs != null && cavitySNs.Length >= 1)
  8374. {
  8375. partNo = cavitySNs[0];
  8376. }
  8377. #endregion 查询载具上的产品信息
  8378. List<TestItem> item = new List<TestItem>();
  8379. item.Add(new TestItem()
  8380. {
  8381. Parameter_name = "载具码",
  8382. Parameter_value = d5VehicleCode,
  8383. });
  8384. item.Add(new TestItem()
  8385. {
  8386. Parameter_name = "载具穴号",
  8387. Parameter_value = "1",
  8388. });
  8389. stopwatch2.Start();
  8390. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8391. stopwatch2.Stop();
  8392. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8393. }
  8394. #endregion 进站
  8395. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8396. //// MES_Flag
  8397. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8398. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8399. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8400. writeToPLC_Flag.Adress = 2559;
  8401. writeToPLC_Flag.Value = d5VehicleScanCode;
  8402. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8403. {
  8404. Name = "d5VehicleCode",
  8405. Adress = 2560,
  8406. ValueType = PLCValueType.String,
  8407. ValueTypeStrLength = 20,
  8408. Value = d5VehicleCode
  8409. });
  8410. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8411. }
  8412. catch (Exception ex)
  8413. {
  8414. string str = ex.StackTrace;
  8415. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8416. stopwatch2.Start();
  8417. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8418. //// MES_Flag
  8419. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8420. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8421. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8422. writeToPLC_Flag.Adress = 2559;
  8423. writeToPLC_Flag.Value = (short)6;
  8424. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8425. {
  8426. Name = "d5VehicleCode",
  8427. Adress = 2560,
  8428. ValueType = PLCValueType.String,
  8429. ValueTypeStrLength = 20,
  8430. Value = " "
  8431. });
  8432. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8433. stopwatch2.Stop();
  8434. }
  8435. stopwatch1.Stop();
  8436. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8437. }
  8438. // 上次采集到的SN
  8439. //private string sn_S4_5出站接口 = string.Empty;
  8440. /// <summary>
  8441. /// [S4] 取放桁架 - S4_5出站接口
  8442. /// </summary>
  8443. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8444. {
  8445. Stopwatch stopwatch1 = new Stopwatch();
  8446. Stopwatch stopwatch2 = new Stopwatch();
  8447. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8448. string stationNameStr = stationCode + stationName;
  8449. string processItem = stationName; // 测试项目
  8450. try
  8451. {
  8452. stopwatch1.Start();
  8453. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8454. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8455. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8456. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8457. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8458. sn = sn.Replace("\0", "");
  8459. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8460. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8461. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8462. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8463. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8464. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8465. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8466. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8467. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8468. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8469. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8470. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8471. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8472. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8473. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8474. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8475. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8476. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8477. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8478. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8479. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8480. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8481. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8482. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8483. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8484. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8485. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8486. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8487. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8488. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8489. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8490. bool pass = d5Result == 1;
  8491. // 存 载具SN列表
  8492. List<string> vehicleCodes = new List<string>()
  8493. {
  8494. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8495. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8496. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8497. };
  8498. // 统一查 产品SN列表
  8499. List<string> partNos = new List<string>();
  8500. foreach (string vehicleCode in vehicleCodes)
  8501. {
  8502. if (string.IsNullOrEmpty(vehicleCode))
  8503. partNos.Add("");
  8504. else
  8505. {
  8506. string partNo = "";
  8507. #region 查询载具上的产品信息
  8508. string cavityData = string.Empty;
  8509. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8510. if (string.IsNullOrEmpty(cavityData))
  8511. cavityData = "";
  8512. if (snResult != 0)
  8513. {
  8514. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8515. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8516. writeToPLC_Flag1.Adress = 2591;
  8517. writeToPLC_Flag1.Value = (short)4;
  8518. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8519. stopwatch1.Stop();
  8520. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8521. return;
  8522. }
  8523. string[] cavitySNs = cavityData.Split('.');
  8524. if (cavitySNs != null && cavitySNs.Length >= 1)
  8525. partNo = cavitySNs[0];
  8526. #endregion 查询载具上的产品信息
  8527. partNos.Add(partNo);
  8528. }
  8529. }
  8530. // 统一上传
  8531. stopwatch2.Start();
  8532. List<int> results = new List<int>();
  8533. for (int i = 0; i < partNos.Count; i++)
  8534. {
  8535. string index = (i + 1).ToString(); // 弹夹穴号
  8536. if (string.IsNullOrEmpty(partNos[i]))
  8537. results.Add(1);
  8538. else
  8539. {
  8540. List<TestItem> items1 = new List<TestItem>();
  8541. items1.Add(new TestItem()
  8542. {
  8543. Parameter_name = "弹夹码",
  8544. Parameter_value = sn,
  8545. Parameter_unit = ""
  8546. });
  8547. items1.Add(new TestItem()
  8548. {
  8549. Parameter_name = "弹夹穴号",
  8550. Parameter_value = index,
  8551. Parameter_unit = ""
  8552. });
  8553. items1.Add(new TestItem()
  8554. {
  8555. Parameter_name = "载具码",
  8556. Parameter_value = vehicleCodes[i],
  8557. Parameter_unit = ""
  8558. });
  8559. items1.Add(new TestItem()
  8560. {
  8561. Parameter_name = "载具穴号",
  8562. Parameter_value = "1",
  8563. Parameter_unit = ""
  8564. });
  8565. items1.Add(new TestItem()
  8566. {
  8567. Parameter_name = "产品结果",
  8568. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8569. Parameter_unit = ""
  8570. });
  8571. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8572. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8573. results.Add(result1);
  8574. }
  8575. }
  8576. short result = 0;
  8577. if (results.All(a => a == 1))
  8578. result = 1;
  8579. else if (results.Contains(3))
  8580. result = 3;
  8581. else if (results.Contains(2))
  8582. result = 2;
  8583. else if (results.Contains(4))
  8584. result = 4;
  8585. else
  8586. result = 4;
  8587. stopwatch2.Stop();
  8588. #region 存储绑定数据到 边线MES系统中
  8589. if (result == 1)
  8590. {
  8591. // 删除绑定信息
  8592. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8593. if (resultMesR != 0)
  8594. {
  8595. result = 4;
  8596. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8597. }
  8598. }
  8599. #endregion 存储绑定数据到 边线MES系统中
  8600. // MES_Flag 为4MES报错
  8601. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8602. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8603. writeToPLC_Flag.Name = "d5MES_FLAG";
  8604. writeToPLC_Flag.Adress = 2591;
  8605. writeToPLC_Flag.Value = result;
  8606. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8607. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8608. }
  8609. catch (Exception ex)
  8610. {
  8611. stopwatch2.Restart();
  8612. // MES_Flag 为4上位机报错
  8613. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8614. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8615. writeToPLC_Flag.Name = "d5MES_FLAG";
  8616. writeToPLC_Flag.Adress = 2591;
  8617. writeToPLC_Flag.Value = (short)4;
  8618. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8619. stopwatch2.Stop();
  8620. string str = ex.StackTrace;
  8621. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8622. }
  8623. stopwatch1.Stop();
  8624. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8625. }
  8626. /// <summary>
  8627. /// [S4] 取放桁架 - S4_5节拍接口
  8628. /// </summary>
  8629. /// <param name="plcNo">PLC编号</param>
  8630. /// <param name="stationNameStr">工站全称</param>
  8631. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8632. {
  8633. Stopwatch stopwatch1 = new Stopwatch();
  8634. Stopwatch stopwatch2 = new Stopwatch();
  8635. string resultStr = string.Empty;
  8636. try
  8637. {
  8638. stopwatch1.Start();
  8639. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8640. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8641. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8642. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8643. if (!actionBool)
  8644. {
  8645. stopwatch2.Start();
  8646. // MES_Flag
  8647. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8648. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8649. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8650. writeToPLC_Flag1.Adress = 2924;
  8651. writeToPLC_Flag1.Value = (short)4;
  8652. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8653. stopwatch2.Stop();
  8654. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8655. return;
  8656. }
  8657. string d5OEEPartNo = string.Empty; // 物料码
  8658. if (string.IsNullOrEmpty(d5OEEProductSN))
  8659. {
  8660. stopwatch2.Start();
  8661. // MES_Flag
  8662. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8663. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8664. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8665. writeToPLC_Flag1.Adress = 2924;
  8666. writeToPLC_Flag1.Value = (short)1;
  8667. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8668. stopwatch2.Stop();
  8669. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8670. return;
  8671. }
  8672. else
  8673. { // 查产品SN
  8674. d5OEEPartNo = "Test"; // ZS
  8675. }
  8676. short d5OEEMES_FLAG = 0;
  8677. // 上传OEE
  8678. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8679. d5OEEMES_FLAG = result.Item1;
  8680. resultStr = result.Item2;
  8681. stopwatch2.Start();
  8682. // MES_Flag
  8683. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8684. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8685. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8686. writeToPLC_Flag.Adress = 2924;
  8687. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8688. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8689. stopwatch2.Stop();
  8690. }
  8691. catch (Exception ex)
  8692. {
  8693. string str = ex.StackTrace;
  8694. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8695. // MES_Flag
  8696. stopwatch2.Start();
  8697. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8698. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8699. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8700. writeToPLC_Flag.Adress = 2924;
  8701. writeToPLC_Flag.Value = (short)4;
  8702. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8703. stopwatch2.Stop();
  8704. }
  8705. stopwatch1.Stop();
  8706. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8707. }
  8708. #endregion [S4] 取放桁架
  8709. #endregion PLC4 刘果段
  8710. #region PLC5 张超凡
  8711. #region [S5] Tray盘下料装备
  8712. /// <summary>
  8713. /// S5工位的数据- 触发信号上次的值
  8714. /// </summary>
  8715. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8716. /// <summary>
  8717. /// S5工位的数据(含触发信号)
  8718. /// </summary>
  8719. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8720. /// <summary>
  8721. /// S5工位的数据- 回写点位
  8722. /// </summary>
  8723. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8724. /// <summary>
  8725. /// [S5] Tray盘下料装备
  8726. /// </summary>
  8727. /// <param name="plcNo">PLC编号</param>
  8728. //private void ReadStation_S5(int plcNo)
  8729. //{
  8730. // // [S1] Tray盘上料装备
  8731. // // [S2] FCT
  8732. // // [S3] 值板机
  8733. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8734. // // [S5] Tray盘下料装备
  8735. // /// 上位机心跳
  8736. // /// 获取设备报警数据与状态信息
  8737. // string stationCode = "[S5]";
  8738. // string stationName = "Tray盘下料装备";
  8739. // string stationNameStr = stationCode + stationName;
  8740. // #region 创建字典
  8741. // // 触发信号字典 赋值
  8742. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8743. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8744. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8745. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8746. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8747. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8748. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8749. // // PLC数据字典 赋值
  8750. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8751. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8752. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8753. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8754. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8755. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8756. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8757. // s5PLCData.Add("e1Result", 0); // 产品结果
  8758. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8759. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8760. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8761. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8762. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8763. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8764. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8765. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8766. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8767. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8768. // #endregion 创建字典
  8769. // while (IsRun)
  8770. // {
  8771. // try
  8772. // {
  8773. // if (!GlobalContext._IsCon_Funs5)
  8774. // {
  8775. // UpdatePLCMonitor(1, plcNo, 0);
  8776. // continue;
  8777. // }
  8778. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8779. // {
  8780. // Stopwatch stopwatch1 = new Stopwatch();
  8781. // Stopwatch stopwatch2 = new Stopwatch();
  8782. // stopwatch1.Start();
  8783. // stopwatch2.Start();
  8784. // #region 一次性读取所有数据
  8785. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8786. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8787. // int[] datas = data1.Concat(data2).ToArray();
  8788. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8789. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8790. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8791. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8792. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8793. // s5PLCData["e1MES_FLAG"] = datas[35];
  8794. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8795. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8796. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8797. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8798. // s5PLCData["e1Result"] = datas[76];
  8799. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8800. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8801. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8802. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8803. // s5PLCData["e1OEEType"] = datas[109];
  8804. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8805. // s5PLCData["e1AGVUpStart"] = datas[121];
  8806. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8807. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8808. // s5PLCData["e1AGVDownStart"] = datas[134];
  8809. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8810. // #endregion 一次性读取所有数据
  8811. // stopwatch2.Stop();
  8812. // #region 回写操作,写后清空flag
  8813. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8814. // #endregion 回写操作,写后清空flag
  8815. // #region 进站校验
  8816. // try
  8817. // {
  8818. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8819. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8820. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  8821. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  8822. // {
  8823. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  8824. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8825. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  8826. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8827. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  8828. // }
  8829. // }
  8830. // catch (Exception ex)
  8831. // {
  8832. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8833. // string str = ex.StackTrace;
  8834. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8835. // }
  8836. // #endregion 进站校验
  8837. // #region 出站接口
  8838. // try
  8839. // {
  8840. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  8841. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  8842. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  8843. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  8844. // {
  8845. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  8846. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8847. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  8848. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  8849. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  8850. // }
  8851. // }
  8852. // catch (Exception ex)
  8853. // {
  8854. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  8855. // string str = ex.StackTrace;
  8856. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8857. // }
  8858. // #endregion 出站接口
  8859. // #region 节拍接口
  8860. // try
  8861. // {
  8862. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  8863. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  8864. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  8865. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  8866. // {
  8867. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  8868. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8869. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  8870. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  8871. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  8872. // }
  8873. // }
  8874. // catch (Exception ex)
  8875. // {
  8876. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  8877. // string str = ex.StackTrace;
  8878. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8879. // }
  8880. // #endregion 节拍接口
  8881. // #region AGV上料
  8882. // // AGV上料叫AGV信号
  8883. // try
  8884. // {
  8885. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  8886. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  8887. // if (e1AGVUpCall != e1AGVUpCallOld)
  8888. // {
  8889. // if (e1AGVUpCall == 1) // 0->1
  8890. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  8891. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  8892. // }
  8893. // }
  8894. // catch (Exception ex)
  8895. // {
  8896. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  8897. // string str = ex.StackTrace;
  8898. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8899. // }
  8900. // // AGV上料完成信号
  8901. // try
  8902. // {
  8903. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  8904. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  8905. // if (e1AGVUpEnd != e1AGVUpEndOld)
  8906. // {
  8907. // if (e1AGVUpEnd == 1) // 0->1
  8908. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  8909. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  8910. // }
  8911. // }
  8912. // catch (Exception ex)
  8913. // {
  8914. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  8915. // string str = ex.StackTrace;
  8916. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8917. // }
  8918. // #endregion AGV上料
  8919. // #region AGV下料
  8920. // // AGV下料叫agv信号
  8921. // try
  8922. // {
  8923. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  8924. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  8925. // if (e1AGVDownCall != e1AGVDownCallOld)
  8926. // {
  8927. // if (e1AGVDownCall == 1) // 0->1
  8928. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  8929. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  8930. // }
  8931. // }
  8932. // catch (Exception ex)
  8933. // {
  8934. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  8935. // string str = ex.StackTrace;
  8936. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8937. // }
  8938. // // AGV下料完成信号
  8939. // try
  8940. // {
  8941. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  8942. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  8943. // if (e1AGVDownEnd != e1AGVDownEndOld)
  8944. // {
  8945. // if (e1AGVDownEnd == 1) // 0->1
  8946. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  8947. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  8948. // }
  8949. // }
  8950. // catch (Exception ex)
  8951. // {
  8952. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  8953. // string str = ex.StackTrace;
  8954. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8955. // }
  8956. // #endregion AGV下料
  8957. // #region 心跳
  8958. // try
  8959. // {
  8960. // short states = 0;
  8961. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8962. // }
  8963. // catch (Exception ex)
  8964. // {
  8965. // string str = ex.StackTrace;
  8966. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8967. // }
  8968. // #endregion 心跳
  8969. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8970. // stopwatch1.Stop();
  8971. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8972. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8973. // }
  8974. // else
  8975. // {
  8976. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8977. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8978. // Funs[plcNo].Connect();
  8979. // }
  8980. // }
  8981. // catch (Exception ex)
  8982. // {
  8983. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8984. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8985. // Funs[plcNo].ReConnect();
  8986. // }
  8987. // Thread.Sleep(IntervalReadPLC);
  8988. // }
  8989. //}
  8990. /// <summary>
  8991. /// [S5] Tray盘下料装备 - 进站校验
  8992. /// </summary>
  8993. /// <param name="plcNo">PLC编号</param>
  8994. /// <param name="stationNameStr">工站全称</param>
  8995. private void S5进站校验(int plcNo, string stationNameStr)
  8996. {
  8997. Stopwatch stopwatch1 = new Stopwatch();
  8998. Stopwatch stopwatch2 = new Stopwatch();
  8999. try
  9000. {
  9001. stopwatch1.Start();
  9002. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9003. sn = sn.Replace("\0", "");
  9004. // 获取产品SN By 载具码
  9005. #region 查询载具上的产品信息
  9006. string cavityData = string.Empty;
  9007. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9008. if (string.IsNullOrEmpty(cavityData))
  9009. cavityData = "";
  9010. if (snResult != 0)
  9011. {
  9012. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9013. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9014. writeToPLC_Flag1.Adress = 2003;
  9015. writeToPLC_Flag1.Value = (short)6;
  9016. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9017. stopwatch1.Stop();
  9018. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9019. return;
  9020. }
  9021. string[] cavitySNs = cavityData.Split('.');
  9022. string partNo = string.Empty;
  9023. if (cavitySNs != null && cavitySNs.Length >= 1)
  9024. partNo = cavitySNs[0];
  9025. #endregion 查询载具上的产品信息
  9026. // 产品SN(物料码)校验
  9027. List<TestItem> item = new List<TestItem>();
  9028. item.Add(new TestItem()
  9029. {
  9030. Parameter_name = "载具码",
  9031. Parameter_value = sn,
  9032. });
  9033. item.Add(new TestItem()
  9034. {
  9035. Parameter_name = "载具穴号",
  9036. Parameter_value = "1",
  9037. });
  9038. stopwatch2.Start();
  9039. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9040. stopwatch2.Stop();
  9041. short e1MES_FLAG_Check = (short)result;
  9042. // MES_Flag
  9043. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9044. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9045. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9046. writeToPLC_Flag.Adress = 2003;
  9047. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9048. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9049. }
  9050. catch (Exception ex)
  9051. {
  9052. string str = ex.StackTrace;
  9053. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9054. // MES_Flag
  9055. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9056. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9057. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9058. writeToPLC_Flag.Adress = 2003;
  9059. writeToPLC_Flag.Value = (short)6;
  9060. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9061. }
  9062. stopwatch1.Stop();
  9063. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9064. }
  9065. /// <summary>
  9066. /// [S5] Tray盘下料装备 - 出站接口
  9067. /// </summary>
  9068. /// <param name="plcNo"></param>
  9069. /// <param name="stationCode"></param>
  9070. /// <param name="stationName"></param>
  9071. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9072. {
  9073. Stopwatch stopwatch1 = new Stopwatch();
  9074. Stopwatch stopwatch2 = new Stopwatch();
  9075. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9076. string stationNameStr = stationCode + stationName;
  9077. string processItem = stationName; // 测试项目
  9078. try
  9079. {
  9080. stopwatch1.Start();
  9081. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9082. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9083. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9084. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9085. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9086. sn = sn.Replace("\0", "");
  9087. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9088. //partNo = partNo.Replace("\0", "");
  9089. #region 查询载具上的产品信息
  9090. string cavityData = string.Empty;
  9091. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9092. if (string.IsNullOrEmpty(cavityData))
  9093. cavityData = "";
  9094. if (snResult != 0)
  9095. {
  9096. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9097. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9098. writeToPLC_Flag1.Adress = 2035;
  9099. writeToPLC_Flag1.Value = (short)4;
  9100. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9101. stopwatch1.Stop();
  9102. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9103. return;
  9104. }
  9105. string[] cavitySNs = cavityData.Split('.');
  9106. string partNo = string.Empty;
  9107. if (cavitySNs != null && cavitySNs.Length >= 1)
  9108. partNo = cavitySNs[0];
  9109. #endregion 查询载具上的产品信息
  9110. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9111. bool pass = e1Result == 1;
  9112. stopwatch2.Start();
  9113. // 上传MES
  9114. List<TestItem> items = new List<TestItem>();
  9115. items.Add(new TestItem()
  9116. {
  9117. Parameter_name = "载具码",
  9118. Parameter_value = sn,
  9119. Parameter_unit = ""
  9120. });
  9121. items.Add(new TestItem()
  9122. {
  9123. Parameter_name = "载具穴号",
  9124. Parameter_value = "1",
  9125. Parameter_unit = ""
  9126. });
  9127. items.Add(new TestItem()
  9128. {
  9129. Parameter_name = "产品结果",
  9130. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9131. Parameter_unit = ""
  9132. });
  9133. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  9134. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9135. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9136. short result = result1 == 1 ? (short)1 : (short)3;
  9137. stopwatch2.Stop();
  9138. #region 存储绑定数据到 边线MES系统中
  9139. if (result == 1)
  9140. {
  9141. // 删除绑定信息
  9142. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9143. if (resultMesR != 0)
  9144. {
  9145. result = 4;
  9146. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9147. }
  9148. }
  9149. #endregion 存储绑定数据到 边线MES系统中
  9150. // MES_Flag 为MES报错
  9151. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9152. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9153. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9154. writeToPLC_Flag.Name = "e1MES_FLAG";
  9155. writeToPLC_Flag.Adress = 2035;
  9156. writeToPLC_Flag.Value = result;
  9157. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9158. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9159. }
  9160. catch (Exception ex)
  9161. {
  9162. stopwatch2.Restart();
  9163. // MES_Flag 为4上位机报错
  9164. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9165. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9166. writeToPLC_Flag.Name = "e1MES_FLAG";
  9167. writeToPLC_Flag.Adress = 2035;
  9168. writeToPLC_Flag.Value = (short)4;
  9169. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9170. stopwatch2.Stop();
  9171. string str = ex.StackTrace;
  9172. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9173. }
  9174. stopwatch1.Stop();
  9175. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9176. }
  9177. /// <summary>
  9178. /// [S5] Tray盘下料装备 - 节拍接口
  9179. /// </summary>
  9180. /// <param name="plcNo">PLC编号</param>
  9181. /// <param name="stationNameStr">工站全称</param>
  9182. private void S5节拍接口(int plcNo, string stationNameStr)
  9183. {
  9184. Stopwatch stopwatch1 = new Stopwatch();
  9185. Stopwatch stopwatch2 = new Stopwatch();
  9186. string resultStr = string.Empty;
  9187. try
  9188. {
  9189. stopwatch1.Start();
  9190. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9191. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9192. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9193. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9194. if (!actionBool)
  9195. {
  9196. stopwatch2.Start();
  9197. // MES_Flag
  9198. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9199. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9200. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9201. writeToPLC_Flag1.Adress = 2088;
  9202. writeToPLC_Flag1.Value = (short)4;
  9203. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9204. stopwatch2.Stop();
  9205. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9206. return;
  9207. }
  9208. string e1OEEPartNo = string.Empty; // 物料码
  9209. if (string.IsNullOrEmpty(e1OEEProductSN))
  9210. {
  9211. stopwatch2.Start();
  9212. // MES_Flag
  9213. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9214. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9215. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9216. writeToPLC_Flag1.Adress = 2088;
  9217. writeToPLC_Flag1.Value = (short)1;
  9218. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9219. stopwatch2.Stop();
  9220. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9221. return;
  9222. }
  9223. else
  9224. { // 查产品SN
  9225. e1OEEPartNo = "Test"; // ZS
  9226. }
  9227. short e1OEEMES_FLAG = 0;
  9228. // 上传OEE
  9229. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9230. e1OEEMES_FLAG = result.Item1;
  9231. resultStr = result.Item2;
  9232. stopwatch2.Start();
  9233. // MES_Flag
  9234. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9235. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9236. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9237. writeToPLC_Flag.Adress = 2088;
  9238. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9239. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9240. stopwatch2.Stop();
  9241. }
  9242. catch (Exception ex)
  9243. {
  9244. string str = ex.StackTrace;
  9245. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9246. // MES_Flag
  9247. stopwatch2.Start();
  9248. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9249. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9250. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9251. writeToPLC_Flag.Adress = 2088;
  9252. writeToPLC_Flag.Value = (short)4;
  9253. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9254. stopwatch2.Stop();
  9255. }
  9256. stopwatch1.Stop();
  9257. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9258. }
  9259. /// <summary>
  9260. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9261. /// </summary>
  9262. /// <param name="plcNo">PLC编号</param>
  9263. /// <param name="stationNameStr">工站全称</param>
  9264. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9265. {
  9266. Stopwatch stopwatch1 = new Stopwatch();
  9267. Stopwatch stopwatch2 = new Stopwatch();
  9268. try
  9269. {
  9270. stopwatch1.Start();
  9271. // ZS 呼叫AGV
  9272. short e1AGVUpCall = 2;
  9273. stopwatch2.Start();
  9274. // e1AGVUpCall
  9275. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9276. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9277. writeToPLC_Flag.Name = "e1AGVUpCall";
  9278. writeToPLC_Flag.Adress = 2120;
  9279. writeToPLC_Flag.Value = e1AGVUpCall;
  9280. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9281. stopwatch2.Stop();
  9282. }
  9283. catch (Exception ex)
  9284. {
  9285. string str = ex.StackTrace;
  9286. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9287. // e1AGVUpCall
  9288. stopwatch2.Start();
  9289. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9290. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9291. writeToPLC_Flag.Name = "e1AGVUpCall";
  9292. writeToPLC_Flag.Adress = 2120;
  9293. writeToPLC_Flag.Value = (short)4;
  9294. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9295. stopwatch2.Stop();
  9296. }
  9297. stopwatch1.Stop();
  9298. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9299. }
  9300. /// <summary>
  9301. /// [S5] Tray盘下料装备 - AGV上料完成
  9302. /// </summary>
  9303. /// <param name="plcNo">PLC编号</param>
  9304. /// <param name="stationNameStr">工站全称</param>
  9305. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9306. {
  9307. Stopwatch stopwatch1 = new Stopwatch();
  9308. Stopwatch stopwatch2 = new Stopwatch();
  9309. try
  9310. {
  9311. stopwatch1.Start();
  9312. // ZS AGV上料完成,让小车离开
  9313. short e1AGVUpEnd = 2;
  9314. stopwatch2.Start();
  9315. // e1AGVUpEnd
  9316. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9317. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9318. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9319. writeToPLC_Flag.Adress = 2122;
  9320. writeToPLC_Flag.Value = e1AGVUpEnd;
  9321. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9322. stopwatch2.Stop();
  9323. }
  9324. catch (Exception ex)
  9325. {
  9326. string str = ex.StackTrace;
  9327. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9328. // e1AGVUpEnd
  9329. stopwatch2.Start();
  9330. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9331. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9332. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9333. writeToPLC_Flag.Adress = 2122;
  9334. writeToPLC_Flag.Value = (short)4;
  9335. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9336. stopwatch2.Stop();
  9337. }
  9338. stopwatch1.Stop();
  9339. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9340. }
  9341. /// <summary>
  9342. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9343. /// </summary>
  9344. /// <param name="plcNo">PLC编号</param>
  9345. /// <param name="stationNameStr">工站全称</param>
  9346. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9347. {
  9348. Stopwatch stopwatch1 = new Stopwatch();
  9349. Stopwatch stopwatch2 = new Stopwatch();
  9350. try
  9351. {
  9352. stopwatch1.Start();
  9353. // ZS 呼叫AGV
  9354. short e1AGVDownCall = 2;
  9355. stopwatch2.Start();
  9356. // e1AGVDownCall
  9357. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9358. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9359. writeToPLC_Flag.Name = "e1AGVDownCall";
  9360. writeToPLC_Flag.Adress = 2133;
  9361. writeToPLC_Flag.Value = e1AGVDownCall;
  9362. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9363. stopwatch2.Stop();
  9364. }
  9365. catch (Exception ex)
  9366. {
  9367. string str = ex.StackTrace;
  9368. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9369. // e1AGVDownCall
  9370. stopwatch2.Start();
  9371. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9372. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9373. writeToPLC_Flag.Name = "e1AGVDownCall";
  9374. writeToPLC_Flag.Adress = 2133;
  9375. writeToPLC_Flag.Value = (short)4;
  9376. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9377. stopwatch2.Stop();
  9378. }
  9379. stopwatch1.Stop();
  9380. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9381. }
  9382. /// <summary>
  9383. /// [S5] Tray盘下料装备 - AGV下料完成
  9384. /// </summary>
  9385. /// <param name="plcNo">PLC编号</param>
  9386. /// <param name="stationNameStr">工站全称</param>
  9387. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9388. {
  9389. Stopwatch stopwatch1 = new Stopwatch();
  9390. Stopwatch stopwatch2 = new Stopwatch();
  9391. try
  9392. {
  9393. stopwatch1.Start();
  9394. // ZS AGV上料完成,让小车离开
  9395. short e1AGVDownEnd = 2;
  9396. stopwatch2.Start();
  9397. // e1AGVDownEnd
  9398. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9399. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9400. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9401. writeToPLC_Flag.Adress = 2135;
  9402. writeToPLC_Flag.Value = e1AGVDownEnd;
  9403. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9404. stopwatch2.Stop();
  9405. }
  9406. catch (Exception ex)
  9407. {
  9408. string str = ex.StackTrace;
  9409. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9410. // e1AGVDownEnd
  9411. stopwatch2.Start();
  9412. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9413. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9414. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9415. writeToPLC_Flag.Adress = 2135;
  9416. writeToPLC_Flag.Value = (short)4;
  9417. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9418. stopwatch2.Stop();
  9419. }
  9420. stopwatch1.Stop();
  9421. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9422. }
  9423. #endregion [S5] Tray盘下料装备
  9424. #endregion PLC5 张超凡
  9425. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9426. /// <summary>
  9427. /// PLC读取到的数据 -添加数据
  9428. /// </summary>
  9429. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9430. {
  9431. if (sxPlcData.ContainsKey(newKey))
  9432. sxPlcData[newKey] = newValue;
  9433. else
  9434. sxPlcData.Add(newKey, newValue);
  9435. }
  9436. /// <summary>
  9437. /// PLC需要写入的数据 -添加数据
  9438. /// </summary>
  9439. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9440. {
  9441. if (sxPLCWriteData.ContainsKey(newKey))
  9442. sxPLCWriteData[newKey] = newValue;
  9443. else
  9444. sxPLCWriteData.Add(newKey, newValue);
  9445. }
  9446. /// <summary>
  9447. /// PLC回写操作,写后清空flag
  9448. /// </summary>
  9449. /// <param name="modbusClient">modbus对象</param>
  9450. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9451. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9452. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9453. {
  9454. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9455. {
  9456. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9457. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9458. {
  9459. string mesFlagName = pLCWriteDatas[i].Name;
  9460. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9461. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9462. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9463. {
  9464. // 先回写数据
  9465. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9466. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9467. {
  9468. int mesDataAdress = writeToPLCDatas[j].Adress;
  9469. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9470. switch (mesDataType)
  9471. {
  9472. case PLCValueType.Short:
  9473. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9474. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9475. break;
  9476. case PLCValueType.String:
  9477. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9478. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9479. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9480. break;
  9481. }
  9482. }
  9483. // 再回写信号
  9484. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9485. // 存储读取数据的字典
  9486. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9487. // 存储写入数据的字典 - 清空写入值
  9488. pLCWriteDatas[i].Value = (short)0;
  9489. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9490. }
  9491. }
  9492. }
  9493. }
  9494. /// <summary>
  9495. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9496. /// </summary>
  9497. /// <param name="no">3</param>
  9498. /// <param name="stationCode">设备编号</param>
  9499. /// <param name="stationNameStr">设备名称</param>
  9500. /// <param name="plcOrder">车间订单号</param>
  9501. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9502. {
  9503. try
  9504. {
  9505. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9506. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9507. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9508. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9509. int result1 = 0;
  9510. switch (stationCode)
  9511. {
  9512. case 2:
  9513. case 3:
  9514. case 4:
  9515. case 6:
  9516. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9517. break;
  9518. case 102:
  9519. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9520. break;
  9521. case 103:
  9522. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9523. break;
  9524. case 104:
  9525. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9526. break;
  9527. case 106:
  9528. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9529. break;
  9530. default:
  9531. // MES_Flag 为“6未找到正确设备编号”
  9532. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9533. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9534. return;
  9535. }
  9536. short result = result1 == 1 ? (short)1 : (short)2;
  9537. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9538. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9539. }
  9540. catch (Exception ex)
  9541. {
  9542. // MES_Flag 为2上位机报错
  9543. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9544. string str = ex.StackTrace;
  9545. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9546. }
  9547. }
  9548. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9549. #region UI刷新
  9550. /// <summary>
  9551. /// 更新商品信息的UI + 下发产品信息(SN)
  9552. /// </summary>
  9553. private void UpdateProductInfo()
  9554. {
  9555. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9556. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9557. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9558. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9559. }
  9560. /// <summary>
  9561. /// 更新PLC连接状态的UI
  9562. /// </summary>
  9563. /// <param name="no">PLC编号</param>
  9564. /// <param name="status">状态</param>
  9565. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9566. {
  9567. if (this != null && !this.IsDisposed)
  9568. {
  9569. switch (imgNo)
  9570. {
  9571. case 1:
  9572. this.BeginInvoke(new Action(() =>
  9573. {
  9574. picPLC.Image = imageListState.Images[status];
  9575. }));
  9576. break;
  9577. case 2:
  9578. this.BeginInvoke(new Action(() =>
  9579. {
  9580. pictureBox2.Image = imageListState.Images[status];
  9581. }));
  9582. break;
  9583. case 3:
  9584. this.BeginInvoke(new Action(() =>
  9585. {
  9586. pictureBox3.Image = imageListState.Images[status];
  9587. }));
  9588. break;
  9589. case 4:
  9590. this.BeginInvoke(new Action(() =>
  9591. {
  9592. pictureBox4.Image = imageListState.Images[status];
  9593. }));
  9594. break;
  9595. case 5:
  9596. this.BeginInvoke(new Action(() =>
  9597. {
  9598. pictureBox5.Image = imageListState.Images[status];
  9599. }));
  9600. break;
  9601. case 6:
  9602. this.BeginInvoke(new Action(() =>
  9603. {
  9604. pictureBox6.Image = imageListState.Images[status];
  9605. }));
  9606. break;
  9607. case 7:
  9608. this.BeginInvoke(new Action(() =>
  9609. {
  9610. pictureBox7.Image = imageListState.Images[status];
  9611. }));
  9612. break;
  9613. case 8:
  9614. this.BeginInvoke(new Action(() =>
  9615. {
  9616. pictureBox8.Image = imageListState.Images[status];
  9617. }));
  9618. break;
  9619. default:
  9620. break;
  9621. }
  9622. }
  9623. Task.Run(() => // 更新PLC交互页的指示灯
  9624. {
  9625. try
  9626. {
  9627. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9628. {
  9629. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9630. }
  9631. }
  9632. catch { }
  9633. });
  9634. }
  9635. #endregion UI刷新
  9636. #region 日志
  9637. /// <summary>
  9638. /// 添加各工位运行日志(同步至PLC交互页面)
  9639. /// </summary>
  9640. /// <param name="stationNameStr">工站名称</param>
  9641. /// <param name="logType">日志类型</param>
  9642. /// <param name="message">日志内容</param>
  9643. /// <param name="snNumber">产品数字SN</param>
  9644. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9645. {
  9646. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9647. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9648. ))
  9649. {
  9650. AddMessage(logType, message); // 首页展示+日志记录
  9651. }
  9652. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9653. {
  9654. StationName = stationNameStr,
  9655. SnNumber = snNumber,
  9656. Message = message,
  9657. CreateTime = DateTime.Now
  9658. };
  9659. // PLC交互页展示
  9660. Task.Run(() =>
  9661. {
  9662. try
  9663. {
  9664. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9665. {
  9666. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9667. }
  9668. }
  9669. catch { }
  9670. });
  9671. }
  9672. /// <summary>
  9673. /// 添加运行日志
  9674. /// </summary>
  9675. /// <param name="logType">日志类型</param>
  9676. /// <param name="message">日志内容</param>
  9677. public void AddMessage(LogType logType, string message)
  9678. {
  9679. OnMessage(logType, message);
  9680. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9681. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9682. string msgShow = time + "--> " + message + "\r\n";
  9683. this.BeginInvoke(new Action(() =>
  9684. {
  9685. systemLog.Rows.Insert(0, date, time, message);
  9686. if (systemLog.Rows.Count >= 100)
  9687. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9688. }));
  9689. }
  9690. /// <summary>
  9691. /// 添加运行日志-保存
  9692. /// </summary>
  9693. /// <param name="logType">日志类型</param>
  9694. /// <param name="message">日志内容</param>
  9695. private void OnMessage(LogType logType, string msg)
  9696. {
  9697. MessageEvent?.Invoke(logType, msg);
  9698. }
  9699. /// <summary>
  9700. /// 保存PLC写入日志
  9701. /// </summary>
  9702. /// <param name="logType"></param>
  9703. /// <param name="logValue"></param>
  9704. private void WritePLCLog(LogType logType, string logValue)
  9705. {
  9706. switch ((int)logType)
  9707. {
  9708. case 0:
  9709. _PLCLogNet.WriteDebug(logValue);
  9710. break;
  9711. case 1:
  9712. _PLCLogNet.WriteInfo(logValue);
  9713. break;
  9714. case 2:
  9715. _PLCLogNet.WriteWarn(logValue);
  9716. break;
  9717. case 3:
  9718. _PLCLogNet.WriteError(logValue);
  9719. break;
  9720. default:
  9721. _PLCLogNet.WriteFatal(logValue);
  9722. break;
  9723. }
  9724. }
  9725. /// <summary>
  9726. /// IOT Mqtt回调方法- With DataId
  9727. /// </summary>
  9728. /// <param name="id"></param>
  9729. /// <param name="v"></param>
  9730. /// <param name="dataId"></param>
  9731. public void CallbackWithDataId(string id, string msg, string dataId)
  9732. {
  9733. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9734. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9735. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9736. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9737. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9738. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9739. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9740. }
  9741. /// <summary>
  9742. /// AGV Mqtt回调方法- 记录Log并处理数据
  9743. /// </summary>
  9744. /// <param name="obj"></param>
  9745. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9746. {
  9747. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9748. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9749. // 接收到的信息
  9750. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9751. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9752. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9753. {
  9754. }
  9755. }
  9756. #endregion 日志
  9757. /// <summary>
  9758. /// 实例化报警字典
  9759. /// </summary>
  9760. private void InitalDicAlarm()
  9761. {
  9762. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9763. List<Alarm> keyValues1 = new List<Alarm>
  9764. {
  9765. #region 第一组报警(电机)
  9766. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9767. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9768. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9769. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9770. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9771. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9772. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9773. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9774. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9775. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9776. #endregion 第一组报警(电机)
  9777. #region 第二组报警(气缸)
  9778. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9779. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9780. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9781. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9782. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9783. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9784. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9785. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9786. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9787. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9788. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9789. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9790. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9791. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9792. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9793. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9794. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9795. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9796. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9797. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9798. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9799. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9800. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9801. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9802. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9803. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9804. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9805. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9806. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9807. #endregion 第二组报警(气缸)
  9808. #region 第三组报警(其他故障)
  9809. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9810. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9811. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9812. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9813. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9814. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9815. #endregion 第三组报警(其他故障)
  9816. };
  9817. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9818. #endregion 第一个工站(这里使用线体代替工位)
  9819. # region 第二个工站-原来的写法(废弃)
  9820. //keyValues = new Dictionary<int, AlarmData[]>();
  9821. ////1
  9822. //dicAlarmName = new Dictionary<int, Alarm>();
  9823. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  9824. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  9825. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  9826. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  9827. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  9828. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9829. //for (int i = 0; i < dicAlarmName.Count; i++)
  9830. //{
  9831. // alarmDatas[i] = new AlarmData();
  9832. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9833. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9834. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9835. // alarmDatas[i].AlarmType = 1;
  9836. //}
  9837. //keyValues.Add(1, alarmDatas);
  9838. ////2
  9839. //dicAlarmName = new Dictionary<int, Alarm>();
  9840. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  9841. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  9842. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  9843. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  9844. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  9845. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  9846. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  9847. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  9848. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9849. //for (int i = 0; i < dicAlarmName.Count; i++)
  9850. //{
  9851. // alarmDatas[i] = new AlarmData();
  9852. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9853. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9854. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9855. // alarmDatas[i].AlarmType = 2;
  9856. //}
  9857. //keyValues.Add(2, alarmDatas);
  9858. ////3
  9859. //dicAlarmName = new Dictionary<int, Alarm>();
  9860. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  9861. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  9862. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  9863. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  9864. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9865. //for (int i = 0; i < dicAlarmName.Count; i++)
  9866. //{
  9867. // alarmDatas[i] = new AlarmData();
  9868. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  9869. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9870. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9871. // alarmDatas[i].AlarmType = 3;
  9872. //}
  9873. //keyValues.Add(3, alarmDatas);
  9874. //DicAlarms.Add(2, keyValues);
  9875. #endregion 第二个工站-原来的写法(废弃)
  9876. }
  9877. private void button1_Click(object sender, EventArgs e)
  9878. {
  9879. OpenDailogFalg=true;
  9880. if (OpenDailogFalg)
  9881. {
  9882. using (var dialog = new BandBarodeDialog())
  9883. {
  9884. string strCarrierBarcode = "N801A-003";
  9885. dialog._CarrierBarcode = strCarrierBarcode;
  9886. string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  9887. dialog._ProductBarcode = sn;
  9888. var rs = dialog.ShowDialog();
  9889. if (rs == DialogResult.OK)
  9890. {
  9891. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  9892. OpenDailogFalg = false;//关闭扫码
  9893. }
  9894. }
  9895. }
  9896. }
  9897. }
  9898. }