Form_Home.cs 585 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using HslCommunication.Enthernet;
  40. /*
  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. /// <summary>
  110. /// 单机用-设备状态
  111. /// </summary>
  112. XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  113. #endregion 变量
  114. #region 窗体基础事件
  115. /// <summary>
  116. /// 初始化
  117. /// </summary>
  118. public Form_Home()
  119. {
  120. InitializeComponent();
  121. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  122. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  123. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  124. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  125. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  126. }
  127. /// <summary>
  128. /// 窗体加载事件
  129. /// </summary>
  130. private void Form_Home_Load(object sender, EventArgs e)
  131. {
  132. try
  133. {
  134. AddMessage(LogType.Info, "开始初始化程序");
  135. InitalDicAlarm(); // 实例化报警字典
  136. //组建plc对象字典
  137. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  138. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  139. if (GlobalContext.IsUsePLC1)
  140. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  141. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  142. if (GlobalContext.IsUsePLC2)
  143. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  144. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  145. if (GlobalContext.IsUsePLC3)
  146. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  147. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  148. if (GlobalContext.IsUsePLC4)
  149. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  150. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  151. if (GlobalContext.IsUsePLC5)
  152. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  153. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  154. if (GlobalContext.IsUsePLC6)
  155. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  156. if (GlobalContext.IsUsePLC7)
  157. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  158. if (GlobalContext.IsUsePLC8)
  159. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  160. if (GlobalContext.IsUsePLC9)
  161. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  162. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  163. {
  164. if (plcEIP != null)
  165. {
  166. try
  167. {
  168. (int, string) result = plcEIP.Connect();
  169. }
  170. catch (Exception ex)
  171. {
  172. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  173. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  174. }
  175. }
  176. }
  177. /*
  178. //plc1Alarm.Connect();
  179. foreach (ModbusClientHelper modbusClient in Funs.Values)
  180. {
  181. if (modbusClient != null)
  182. {
  183. try
  184. {
  185. modbusClient.Connect();
  186. }
  187. catch (Exception ex)
  188. {
  189. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  190. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  191. }
  192. }
  193. }
  194. */
  195. // 采集任务
  196. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  197. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  198. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  199. if (GlobalContext.IsUsePLC1)
  200. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  201. if (GlobalContext.IsUsePLC2)
  202. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  203. if (GlobalContext.IsUsePLC3)
  204. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  205. if (GlobalContext.IsUsePLC4)
  206. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  207. if (GlobalContext.IsUsePLC5)
  208. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  209. if (GlobalContext.IsUsePLC6)
  210. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  211. if (GlobalContext.IsUsePLC7)
  212. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  213. if (GlobalContext.IsUsePLC8)
  214. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  215. if (GlobalContext.IsUsePLC9)
  216. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  217. #region 初始化
  218. try
  219. {
  220. // 开启边线MES(绑定/查询数据)
  221. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  222. //if (mesRoute == 0)
  223. //{
  224. // //picMESStatus.Image = imageListState.Images[1];
  225. // //GlobalContext.MESIsConnect = true;
  226. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  227. //}
  228. //else
  229. //{
  230. // //picMESStatus.Image = imageListState.Images[0];
  231. // //GlobalContext.MESIsConnect = false;
  232. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  233. //}
  234. // 开启MES(Http)
  235. if (GlobalContext.IsUseMES)
  236. {
  237. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  238. if (mesret)
  239. {
  240. picMESStatus.Image = imageListState.Images[1];
  241. GlobalContext.MESIsConnect = true;
  242. AddMessage(LogType.Info, "小米MES初始连接成功!");
  243. }
  244. else
  245. {
  246. picMESStatus.Image = imageListState.Images[0];
  247. GlobalContext.MESIsConnect = false;
  248. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  249. }
  250. }
  251. // 开启IOT(MQTT)
  252. if (GlobalContext.IsUseIot)
  253. {
  254. string addr = GlobalContext.MQTTServerHost;
  255. int port = GlobalContext.MQTTServerPort;
  256. //生产环境需要修改
  257. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  258. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  259. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  260. {
  261. picIot.Image = imageListState.Images[1];
  262. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  263. // 设置回调函数
  264. XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  265. // 配置参数
  266. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  267. // fds
  268. param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
  269. param.parameter.fds.appId = "Auto-Soft";
  270. param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
  271. // mes
  272. param.parameter.mes.address = GlobalContext.ServerIp;
  273. param.parameter.mes.appId = GlobalContext.MESAppId;
  274. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  275. // mqtt
  276. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  277. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  278. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  279. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  280. // 设备配置
  281. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  282. if (GlobalContext.IsUsePLC1)
  283. {
  284. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  285. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  286. }
  287. if (GlobalContext.IsUsePLC2)
  288. {
  289. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  290. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  291. }
  292. if (GlobalContext.IsUsePLC3)
  293. {
  294. param.parameter.equipment.deviceCode = GlobalContext.S3_device_code; // 装备编码
  295. param.parameter.equipment.stationCode = GlobalContext.S3_station; // ⼯位Id
  296. }
  297. if (GlobalContext.IsUsePLC4)
  298. {
  299. param.parameter.equipment.deviceCode = GlobalContext.S4_1_device_code; // 装备编码
  300. param.parameter.equipment.stationCode = GlobalContext.S4_1_station; // ⼯位Id
  301. }
  302. if (GlobalContext.IsUsePLC5)
  303. {
  304. param.parameter.equipment.deviceCode = GlobalContext.S5_device_code; // 装备编码
  305. param.parameter.equipment.stationCode = GlobalContext.S5_station; // ⼯位Id
  306. }
  307. if (GlobalContext.IsUsePLC6)
  308. {
  309. param.parameter.equipment.deviceCode = GlobalContext.S6_device_code; // 装备编码
  310. param.parameter.equipment.stationCode = GlobalContext.S6_station; // ⼯位Id
  311. }
  312. if (GlobalContext.IsUsePLC7)
  313. {
  314. param.parameter.equipment.deviceCode = GlobalContext.S7_device_code; // 装备编码
  315. param.parameter.equipment.stationCode = GlobalContext.S7_station; // ⼯位Id
  316. }
  317. if (GlobalContext.IsUsePLC8)
  318. {
  319. param.parameter.equipment.deviceCode = GlobalContext.S8_device_code; // 装备编码
  320. param.parameter.equipment.stationCode = GlobalContext.S8_station; // ⼯位Id
  321. }
  322. if (GlobalContext.IsUsePLC9)
  323. {
  324. param.parameter.equipment.deviceCode = GlobalContext.S9_device_code; // 装备编码
  325. param.parameter.equipment.stationCode = GlobalContext.S9_station; // ⼯位Id
  326. }
  327. param.parameter.equipment.project = GlobalContext.Project_Code;
  328. param.parameter.equipment.productMode = "debug";
  329. //
  330. param.parameter.other.logLevel = 0;
  331. param.parameter.other.LogPath = "D:\\Test";
  332. XiaomiMqttClient_Extend.ParameterConfig(param);
  333. }
  334. else
  335. {
  336. picIot.Image = imageListState.Images[0];
  337. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  338. }
  339. }
  340. // 开启AGV(Http与MQTT)
  341. if (GlobalContext.IsUseAGV)
  342. {
  343. // AGV HTTP
  344. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  345. if (mesret1)
  346. {
  347. picAgvHttp.Image = imageListState.Images[1];
  348. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  349. }
  350. else
  351. {
  352. picAgvHttp.Image = imageListState.Images[0];
  353. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  354. }
  355. string agvMqttIp = GlobalContext.MQTTServerHost;
  356. int agvMqttPort = GlobalContext.MQTTServerPort;
  357. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  358. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  359. // AGV MQTT
  360. if (result_MQTT.ResultCode == 1)
  361. {
  362. picAgvMqtt.Image = imageListState.Images[1];
  363. GlobalContext.AGVMQTTIsConnect = true;
  364. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  365. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  366. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  367. }
  368. else
  369. {
  370. picAgvMqtt.Image = imageListState.Images[0];
  371. GlobalContext.AGVMQTTIsConnect = false;
  372. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  373. }
  374. }
  375. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  376. Task.Run(MonitorMESConnect);
  377. // 查询PLC连接状态
  378. foreach (int plcNo in FunsEip.Keys)
  379. {
  380. bool connected = FunsEip[plcNo].IsConnected;
  381. if (connected)
  382. {
  383. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  384. AddMessage(LogType.Info, msg);
  385. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  386. }
  387. else
  388. {
  389. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  390. AddMessage(LogType.Info, msg);
  391. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  392. }
  393. }
  394. // PLC4时 初始化扫码器TCP
  395. //if (GlobalContext.IsUsePLC4)
  396. // HpTCPClientInit();
  397. // 开启PLC的业务处理线程-监听PLC点位+状态
  398. foreach (Task task in TaskReadProcess)
  399. {
  400. if (task != null)
  401. task.Start();
  402. }
  403. //// 开启“获取线体报警数据”的线程
  404. TaskReadAlarm.Start();
  405. ////下传MES信息给1工位(先判断下plc对象数量)
  406. //if (Funs.Count > 1)
  407. // DownLoadProductInfo(1);
  408. AddMessage(LogType.Info, "程序初始化完成");
  409. }
  410. catch (Exception ex)
  411. {
  412. string str = ex.StackTrace;
  413. this.BeginInvoke(new Action(() =>
  414. {
  415. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  416. }));
  417. }
  418. #endregion
  419. }
  420. catch (Exception ex)
  421. {
  422. string str = ex.StackTrace;
  423. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  424. if (ex.Message != null && ex.Message.Contains("timed out"))
  425. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  426. else
  427. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  428. }
  429. }
  430. /// <summary>
  431. /// 窗体关闭事件
  432. /// </summary>
  433. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  434. {
  435. Closed2();
  436. }
  437. public void Closed2()
  438. {
  439. try
  440. {
  441. IsRun = false;
  442. Thread.Sleep(IntervalReadPLC);
  443. // 断开TCP
  444. int count = _HPSocket_TcpClients.Count();
  445. for (int i = 0; i < count; i++)
  446. {
  447. try
  448. {
  449. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  450. {
  451. _HPSocket_TcpClients[i].Stop();
  452. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  453. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  454. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  455. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  456. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  457. }
  458. }
  459. catch { }
  460. }
  461. // 关闭Iot
  462. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  463. // 关闭AGV Mqtt
  464. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  465. }
  466. catch { }
  467. }
  468. #endregion 窗体基础事件
  469. #region 监控MES状态
  470. /// <summary>
  471. /// 监控MES连接状态
  472. /// </summary>
  473. private void MonitorMESConnect()
  474. {
  475. while (IsRun) // 运行被控线程
  476. {
  477. try
  478. {
  479. // 开启MES(Http)
  480. if (GlobalContext.IsUseMES)
  481. {
  482. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  483. if (mesret)
  484. {
  485. picMESStatus.Image = imageListState.Images[1];
  486. GlobalContext.MESIsConnect = true;
  487. }
  488. else
  489. {
  490. picMESStatus.Image = imageListState.Images[0];
  491. GlobalContext.MESIsConnect = false;
  492. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  493. }
  494. }
  495. // 开启IOT(MQTT)
  496. if (GlobalContext.IsUseIot)
  497. {
  498. bool iIot = XiaomiMqttClient.IsOpen;
  499. if (iIot)
  500. picIot.Image = imageListState.Images[1];
  501. else
  502. {
  503. picIot.Image = imageListState.Images[0];
  504. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  505. }
  506. }
  507. // 开启AGV(Http与MQTT)
  508. if (GlobalContext.IsUseAGV)
  509. {
  510. // AGV Http
  511. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  512. if (mesret1)
  513. picAgvHttp.Image = imageListState.Images[1];
  514. else
  515. {
  516. picAgvHttp.Image = imageListState.Images[0];
  517. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  518. }
  519. // AGV MQTT
  520. if (GlobalContext.AGVMQTTIsConnect)
  521. picAgvMqtt.Image = imageListState.Images[1];
  522. else
  523. {
  524. picAgvMqtt.Image = imageListState.Images[0];
  525. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  526. }
  527. }
  528. }
  529. catch (Exception ex)
  530. {
  531. string str = ex.StackTrace;
  532. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  533. }
  534. Thread.Sleep(IntervalMonitorMES);
  535. }
  536. }
  537. #endregion 监控MES连接状态
  538. #region 采集设备状态、运行数据、报警数据
  539. /// <summary>
  540. /// 请求设备状态 5000
  541. /// </summary>
  542. /// <param name="no">1</param>
  543. /// <param name="stationNameStr"></param>
  544. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  545. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  546. {
  547. try
  548. {
  549. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  550. {
  551. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  552. return result;
  553. }
  554. else
  555. {
  556. return 0;
  557. }
  558. }
  559. catch (Exception ex)
  560. {
  561. string str = ex.StackTrace;
  562. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  563. return 0;
  564. }
  565. }
  566. /// <summary>
  567. /// 检查是否可采集点检数据 - 不取新值
  568. /// 5000不为1时可点检
  569. /// </summary>
  570. /// <returns></returns>
  571. public bool CheckCanSpotcheck1(int deviceState)
  572. {
  573. //return true;
  574. //D5000 = 1,代表设备控制状态处于运行状态
  575. //D5000 = 2, 代表设备控制状态处于故障状态
  576. //D5000 = 3,代表设备控制状态处于缺料状态
  577. //D5000 = 4, 代表设备控制状态处于待机状态
  578. //D5000 = 5,代表设备控制状态处于维修状态
  579. return deviceState != 1;
  580. }
  581. /// <summary>
  582. /// 检查是否可采集产品数据 - 不取新值
  583. /// </summary>
  584. /// <returns></returns>
  585. public bool CheckCanCollData(int deviceState)
  586. {
  587. return deviceState == 0; // 点检时该值不为0
  588. }
  589. /// <summary>
  590. /// 采集到的设备状态
  591. /// </summary>
  592. private string _DeviceStates = "未知状态";
  593. private string _DeviceStates_Old = "未知状态";
  594. /// <summary>
  595. /// 获取设备报警数据与获取设备运行信息
  596. /// </summary>
  597. private async void ReadAlarmAllPLC()
  598. {
  599. // [S1] Tray盘上料装备(板测)
  600. // [S2] FCT(板测)
  601. // [S3] 值板机
  602. // [S4] 取放桁架
  603. // [S5] Tray盘下料装备
  604. /// 上位机心跳
  605. /// 获取设备报警数据与状态信息
  606. string stationNameStr = "获取设备报警数据与状态信息";
  607. // 已连接到PLC
  608. while (IsRun)
  609. {
  610. try
  611. {
  612. //if (!GlobalContext._IsCon_plc1Alarm)
  613. //{
  614. // UpdatePLCMonitor(1, -2, 0);
  615. // continue;
  616. //}
  617. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  618. {
  619. #region 主页展示设备运行状态并上传到IOT中
  620. switch (xmDeviceState)
  621. {
  622. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  623. _DeviceStates = "未初始化状态";
  624. lblDeviceStates.Text = _DeviceStates;
  625. break;
  626. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  627. _DeviceStates = "初始化状态";
  628. lblDeviceStates.Text = _DeviceStates;
  629. break;
  630. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  631. _DeviceStates = "初始化完成状态";
  632. lblDeviceStates.Text = _DeviceStates;
  633. break;
  634. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  635. _DeviceStates = "运行状态";
  636. lblDeviceStates.Text = _DeviceStates;
  637. break;
  638. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  639. _DeviceStates = "暂停状态";
  640. lblDeviceStates.Text = _DeviceStates;
  641. break;
  642. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  643. _DeviceStates = "故障状态";
  644. lblDeviceStates.Text = _DeviceStates;
  645. break;
  646. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  647. _DeviceStates = "警报状态";
  648. lblDeviceStates.Text = _DeviceStates;
  649. break;
  650. }
  651. if (!_DeviceStates.Equals(_DeviceStates_Old))
  652. {
  653. var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceState); // 上传+保存
  654. if (iotResult.Item1 == 1)
  655. {
  656. _DeviceStates_Old = _DeviceStates;
  657. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_上传设备状态到Iot成功!");
  658. }
  659. else
  660. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  661. }
  662. #endregion 主页展示设备运行状态并上传到IOT中
  663. DateTime dtNow = DateTime.Now;
  664. //#region 获取设备运行信息
  665. //try
  666. //{
  667. // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  668. // lineWorkingData1.GUID = Guid.NewGuid().ToString();
  669. // lineWorkingData1.LineName = GlobalContext.LineCode;
  670. // //
  671. // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  672. // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  673. // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  674. // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  675. // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  676. // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  677. // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  678. // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  679. // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  680. // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  681. // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  682. // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  683. // lineWorkingData1.CreateTime = DateTime.Now;
  684. // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  685. // // UI展示-展示到设备状态页
  686. // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  687. // {
  688. // // 查询数据库最新一条数据,确定是不是更新
  689. // string qSql = @"SELECT top(1) [GUID]
  690. // ,[LineName]
  691. // ,[BootTimeLong]
  692. // ,[NormalTimeLong]
  693. // ,[StandbyTimeLong]
  694. // ,[FaultTimeLong]
  695. // ,[MaterialShortageTimeLong]
  696. // ,[MaintenanceTimeLong]
  697. // ,[FaultNumber]
  698. // ,[OutputNumber]
  699. // ,[QualifiedNumber]
  700. // ,[QualifiedRate]
  701. // ,[DesignRhythm]
  702. // ,[RealityRhythm]
  703. // ,[CreateTime]
  704. // FROM [LineWorkingData]
  705. // where [CreateTime] > '{0}'
  706. // and [LineName]='{1}'
  707. // order by [CreateTime] desc
  708. // ";
  709. // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  710. // var ds = SQLHelper_New.Query(qSql, null);
  711. // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  712. // {
  713. // var dataDBlast = new LineWorkingData_ThisTime();
  714. // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  715. // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  716. // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  717. // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  718. // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  719. // {
  720. // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  721. // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  722. // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  723. // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  724. // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  725. // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  726. // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  727. // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  728. // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  729. // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  730. // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  731. // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  732. // string usql = dataDBlast.ToStringUpdate();
  733. // SQLHelper_New.ExecuteSQL(usql, null);
  734. // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  735. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  736. // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  737. // }
  738. // }
  739. // else
  740. // {
  741. // // 插入
  742. // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  743. // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  744. // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  745. // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  746. // }
  747. // }
  748. // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  749. // {
  750. // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  751. // //// 本次开机设备运行情况
  752. // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  753. // //Task.Run(() =>
  754. // //{
  755. // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  756. // // {
  757. // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  758. // // }
  759. // //});
  760. // // 本日设备运行情况
  761. // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  762. // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  763. // {
  764. // // 更新
  765. // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  766. // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  767. // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  768. // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  769. // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  770. // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  771. // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  772. // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  773. // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  774. // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  775. // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  776. // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  777. // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  778. // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  779. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  780. // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  781. // }
  782. // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  783. // {
  784. // // 插入
  785. // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  786. // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  787. // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  788. // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  789. // }
  790. // await Task.Run(() =>
  791. // {
  792. // try
  793. // {
  794. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  795. // {
  796. // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  797. // }
  798. // }
  799. // catch { }
  800. // });
  801. // }
  802. //}
  803. //catch (Exception ex)
  804. //{
  805. // string str = ex.StackTrace;
  806. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  807. //}
  808. //#endregion 获取设备运行信息
  809. #region 报警数据
  810. try
  811. {
  812. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  813. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  814. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  815. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  816. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  817. {
  818. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  819. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  820. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  821. {
  822. isNeedUpdUI = true; // 需要更新历史报警UI信息
  823. // 记录
  824. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  825. switch (dicAlarms_Cur_PLC1[i].是否报警)
  826. {
  827. case true: // 报警
  828. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  829. {
  830. GUID = Guid.NewGuid().ToString(),
  831. LineName = GlobalContext.LineCode, // 线体
  832. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  833. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  834. StartTime = dtNow // 开始时间
  835. };
  836. // 传输到页面
  837. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  838. {
  839. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  840. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  841. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  842. 开始时间 = dtNow
  843. });
  844. // 新增到数据库
  845. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  846. SaveAlarmDataByDB(stationNameStr, data1, false);
  847. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  848. break;
  849. case false: // 消除报警
  850. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  851. {
  852. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  853. {
  854. GUID = Guid.NewGuid().ToString(),
  855. LineName = GlobalContext.LineCode, // 线体
  856. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  857. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  858. StartTime = dtNow, // 开始时间
  859. EndTime = dtNow, // 开始时间
  860. PersistTime = 1, // 耗时1s
  861. };
  862. // 新增
  863. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  864. SaveAlarmDataByDB(stationNameStr, data2, false);
  865. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  866. }
  867. else
  868. {
  869. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  870. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  871. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  872. // 修改
  873. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  874. SaveAlarmDataByDB(stationNameStr, data3, true);
  875. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  876. }
  877. break;
  878. default:
  879. break;
  880. }
  881. }
  882. }
  883. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  884. // 有新报警则更新
  885. if (isNeedUpdUI)
  886. {
  887. // UI展示 - 展示到设备状态页
  888. await Task.Run(() =>
  889. {
  890. try
  891. {
  892. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  893. {
  894. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  895. if (Form_Main.formDevAlarm.Visible)
  896. {
  897. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  898. }
  899. }
  900. }
  901. catch { }
  902. });
  903. }
  904. }
  905. catch (Exception ex)
  906. {
  907. string str = ex.StackTrace;
  908. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  909. }
  910. #endregion 报警数据
  911. UpdatePLCMonitor(1, -2, 1);
  912. }
  913. else
  914. {
  915. UpdatePLCMonitor(1, -2, 0);
  916. }
  917. }
  918. catch (Exception ex)
  919. {
  920. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  921. }
  922. Thread.Sleep(IntervalAlarm);
  923. }
  924. }
  925. #endregion 轮询PLC
  926. #region 下发订单信息
  927. ///// <summary>
  928. ///// 壳体上料(下发工单)的交互逻辑
  929. ///// </summary>
  930. ///// <param name="no"></param>
  931. ///// <exception cref="NotImplementedException"></exception>
  932. //private void ReadStation_DownOrderInfo(int plcNo)
  933. //{
  934. // // [S1] Tray盘上料装备(板测)
  935. // // [S2] FCT(板测)
  936. // // [S3] 值板机
  937. // // [S4] 取放桁架
  938. // // [S5] Tray盘下料装备
  939. // /// 上位机心跳
  940. // /// 获取设备报警数据与状态信息
  941. // string stationNameStr = "[S0]壳体上料";
  942. // while (IsRun)
  943. // {
  944. // try
  945. // {
  946. // if (!GlobalContext._IsCon_Funs1)
  947. // {
  948. // UpdatePLCMonitor(plcNo, 0);
  949. // continue;
  950. // }
  951. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  952. // {
  953. // #region 壳体上料(下发工单)
  954. // try
  955. // {
  956. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  957. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  958. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  959. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  960. // // 重置数据和信号
  961. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  962. // {
  963. // // 清空写给PLC的数据
  964. // int[] i497 = new int[1] { 0 };
  965. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  966. // // MES_Flag重置为0
  967. // int[] i500 = new int[1] { 0 };
  968. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  969. // }
  970. // }
  971. // catch (Exception ex)
  972. // {
  973. // string str = ex.StackTrace;
  974. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  975. // }
  976. // #endregion 壳体上料(下发工单)
  977. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  978. // }
  979. // else
  980. // {
  981. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  982. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  983. //
  984. // Funs[plcNo].Connect();
  985. // }
  986. // }
  987. // catch (Exception ex)
  988. // {
  989. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  990. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  991. //
  992. // Funs[plcNo].ReConnect();
  993. // }
  994. // Thread.Sleep(IntervalReadPLC);
  995. // }
  996. //}
  997. ///// <summary>
  998. ///// 下发订单信息到PLC
  999. ///// </summary>
  1000. ///// <param name="no">PLC编号</param>
  1001. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  1002. //{
  1003. // try
  1004. // {
  1005. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  1006. // {
  1007. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  1008. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  1009. // }
  1010. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  1011. // }
  1012. // catch (Exception ex)
  1013. // {
  1014. // string str = ex.StackTrace;
  1015. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1016. // }
  1017. //}
  1018. /// <summary>
  1019. /// 下发清料信号
  1020. /// </summary>
  1021. /// <param name="no">PLC编号</param>
  1022. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  1023. {
  1024. try
  1025. {
  1026. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  1027. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  1028. return true;
  1029. }
  1030. catch (Exception ex)
  1031. {
  1032. string str = ex.StackTrace;
  1033. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1034. return false;
  1035. }
  1036. }
  1037. #endregion 下发订单信息
  1038. #region Xiaomi 贲流
  1039. #region 公共方法
  1040. private static bool ProgressState = false;
  1041. private static readonly object lockObj = new object(); // 锁对象
  1042. private static bool isCollectingFlagLeft;
  1043. private static bool isCollectingFlagRight;
  1044. /// <summary>
  1045. /// float[]转为string
  1046. /// </summary>
  1047. public string FloatArrayToString(float[] nScrewResults)
  1048. {
  1049. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1050. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1051. }
  1052. /// <summary>
  1053. /// short[]转为string
  1054. /// </summary>
  1055. public string ShortArrayToString(short[] nScrewResults)
  1056. {
  1057. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1058. return string.Join(",", nScrewResults);
  1059. }
  1060. /// <summary>
  1061. /// 写入PLC重复三次
  1062. /// </summary>
  1063. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  1064. {
  1065. int i = 0;
  1066. int nRet = 0;
  1067. string strRet = "";
  1068. try
  1069. {
  1070. while (i < 3) // 最多上传三次
  1071. {
  1072. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1073. if (nRet == 0) //成功
  1074. {
  1075. break;
  1076. }
  1077. else
  1078. {
  1079. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1080. i++;
  1081. }
  1082. }
  1083. return (nRet, strRet);
  1084. }
  1085. catch (Exception ex)
  1086. {
  1087. return (1, ex.Message);
  1088. }
  1089. }
  1090. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  1091. {
  1092. try
  1093. {
  1094. // 获取当前日期
  1095. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1096. // 构建保存路径
  1097. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1098. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  1099. // 确保目录存在
  1100. Directory.CreateDirectory(savePath);
  1101. // 文件名
  1102. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1103. string filePath = Path.Combine(savePath, fileName);
  1104. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1105. int count = Math.Min(14, fScrewTimes.Length);
  1106. using (StreamWriter sw = new StreamWriter(filePath))
  1107. {
  1108. for (int i = 0; i < count; i++)
  1109. {
  1110. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1111. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1112. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1113. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1114. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1115. }
  1116. }
  1117. return (0, "");
  1118. }
  1119. catch (Exception ex)
  1120. {
  1121. return (1, ex.Message);
  1122. }
  1123. }
  1124. /// <summary>
  1125. /// 调用进站接口并保存进站数据
  1126. /// </summary>
  1127. /// <param name="stationNameStr">工站信息</param>
  1128. /// <param name="workorder_code">工单号</param>
  1129. /// <param name="mtltmrk">型号(物料号)</param>
  1130. /// <param name="sn">产品SN</param>
  1131. /// <param name="items">进站数据</param>
  1132. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1133. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1134. {
  1135. int result = 0;
  1136. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1137. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1138. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1139. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1140. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1141. inRequest_Body.unitSn = sn; // 产品SN
  1142. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1143. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1144. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1145. StationIn stationIn = new StationIn()
  1146. {
  1147. Workorder_code = workorder_code, // 车间订单号
  1148. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1149. Sn = sn, // SN
  1150. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1151. Parameter_values = items, // 进站数据
  1152. Write_user = inRequest_Body.userId, // 员工Id
  1153. Test_time = inRequest_Body.clientTime // 进站时间
  1154. };
  1155. // 本地数据
  1156. string sql = stationIn.ToStringInsert(0);
  1157. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1158. result = ret == "成功" ? 1 : 6;
  1159. //await Task.Delay(200);
  1160. // 上传MES
  1161. if (GlobalContext.IsSendStationIn)
  1162. {
  1163. try
  1164. {
  1165. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1166. string mesRet = string.Empty;
  1167. int i = 0;
  1168. while (i < 2) // 1009会多次尝试上传
  1169. {
  1170. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_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 + "参数:" + json_Body);
  1179. }
  1180. if (response?.header?.code == "200")
  1181. {
  1182. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1183. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1184. result = ret_Upd == "成功" ? 1 : 6;
  1185. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1186. }
  1187. else
  1188. {
  1189. result = 5;
  1190. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1191. }
  1192. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1193. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1194. }
  1195. catch (Exception ex)
  1196. {
  1197. result = 6;
  1198. string str = ex.StackTrace;
  1199. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1200. }
  1201. }
  1202. return result;
  1203. }
  1204. /// <summary>
  1205. /// 选择如何记录出站数据
  1206. /// </summary>
  1207. /// <param name="items">出站数据</param>
  1208. /// <param name="equipmentCode">设备编号</param>
  1209. /// <param name="processItem">测试项目</param>
  1210. /// <param name="workorder_code">车间订单号</param>
  1211. /// <param name="batch_num">批次号</param>
  1212. /// <param name="mtltmrk">型号</param>
  1213. /// <param name="proDate">日期</param>
  1214. /// <param name="supplierCode">供应商代码</param>
  1215. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1216. /// <returns>上传成功时返回1;失败返回0</returns>
  1217. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1218. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1219. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode)
  1220. {
  1221. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1222. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode);
  1223. }
  1224. /// <summary>
  1225. /// 添加出站数据(提交到MES+本地保存到数据库)
  1226. /// </summary>
  1227. /// <param name="items">出站数据</param>
  1228. /// <param name="equipmentCode">设备编号</param>
  1229. /// <param name="processItem">测试项目</param>
  1230. /// <param name="workorder_code">车间订单号</param>
  1231. /// <param name="batch_num">批次号</param>
  1232. /// <param name="mtltmrk">型号</param>
  1233. /// <param name="proDate">日期</param>
  1234. /// <param name="supplierCode">供应商代码</param>
  1235. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1236. /// <returns>上传成功时返回1;失败返回0</returns>
  1237. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1238. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1239. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode)
  1240. {
  1241. int upload = 0;
  1242. int result = 0;
  1243. ProcessData processData = new ProcessData()
  1244. {
  1245. Equipment_code = equipmentCode,
  1246. Workorder_code = workorder_code,
  1247. Batch_number = batch_num,
  1248. Sn = sn, // SN
  1249. Testitem = processItem,
  1250. Parameter_values = items,
  1251. Write_user = GlobalContext.CurrentUser,
  1252. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1253. };
  1254. // 本地数据
  1255. string sql = processData.ToStringInsert(upload);
  1256. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1257. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1258. // 上传MES
  1259. if (GlobalContext.IsSendProcessData)
  1260. {
  1261. try
  1262. {
  1263. string id = processData.ID.Copy();
  1264. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1265. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1266. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1267. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1268. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1269. outRequest_Body.unitSn = sn; // 产品SN
  1270. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1271. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1272. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1273. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1274. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1275. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1276. if (!string.IsNullOrEmpty(partBarcode))
  1277. {
  1278. outRequest_Body.unitData.keyMaterial.Add(
  1279. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1280. {
  1281. bindSort = 1,
  1282. materialSn = partBarcode
  1283. }); // 设备数据 - 部件码
  1284. }
  1285. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1286. if (GlobalContext.IsSendProcessData)
  1287. {
  1288. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1289. string mesRet = string.Empty;
  1290. int i = 0;
  1291. while (i < 2) // 1009会多次尝试上传
  1292. {
  1293. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1294. if (response != null && response.header.code == "200")
  1295. break;
  1296. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1297. i++;
  1298. i++;
  1299. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1300. // 记录失败原因
  1301. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1302. }
  1303. if (response?.header?.code == "200")
  1304. {
  1305. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1306. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1307. result = 1;
  1308. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1309. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1310. }
  1311. else
  1312. {
  1313. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1314. }
  1315. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1316. JsonConvert.SerializeObject(response), id);
  1317. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1318. }
  1319. }
  1320. catch (Exception ex)
  1321. {
  1322. string str = ex.StackTrace;
  1323. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1324. }
  1325. }
  1326. return result;
  1327. }
  1328. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1329. //{
  1330. // Stopwatch stopwatch = new Stopwatch();
  1331. // stopwatch.Start();
  1332. // try
  1333. // {
  1334. // // 初始化 AtlasScrew 实例
  1335. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1336. // atlasScrew1.Initial();
  1337. // // 存储结果的列表
  1338. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1339. // // 存储角度和扭力的字符串列表
  1340. // List<string> angleStrs = new List<string>();
  1341. // List<string> torqueStrs = new List<string>();
  1342. // // 上一次获取的数据
  1343. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1344. // while (isExitAtlasLeft) // 检查是否收集数据
  1345. // {
  1346. // // 获取当前数据
  1347. // var currentResult = atlasScrew1.GetResults();
  1348. // // 判断是否为新数据
  1349. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1350. // {
  1351. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1352. // // 更新角度和扭力的字符串列表
  1353. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1354. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1355. // // 计算角度、扭力、起始扭力和最大扭力
  1356. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1357. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1358. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1359. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1360. // // 将新数据添加到结果列表
  1361. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1362. // // 更新上一次获取的数据
  1363. // lastResult = currentResult;
  1364. // }
  1365. // // 等待一段时间后再次检查
  1366. // Thread.Sleep(20); // 轮询间隔时间
  1367. // // 如果触发了出站,则退出循环
  1368. // if (!isExitAtlasLeft)
  1369. // {
  1370. // break;
  1371. // }
  1372. // }
  1373. // // 生成文件名
  1374. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1375. // // 写入数据到文件
  1376. // using (StreamWriter writer = new StreamWriter(fileName))
  1377. // {
  1378. // // 写入标题行
  1379. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1380. // // 写入每一行数据
  1381. // foreach (var result in results)
  1382. // {
  1383. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1384. // }
  1385. // }
  1386. // stopwatch.Stop();
  1387. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1388. // }
  1389. // catch (Exception ex)
  1390. // {
  1391. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1392. // }
  1393. // finally
  1394. // {
  1395. // // 重置标志变量
  1396. // isExitAtlasLeft = false;
  1397. // }
  1398. //}
  1399. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1400. //{
  1401. // Stopwatch stopwatch = new Stopwatch();
  1402. // stopwatch.Start();
  1403. // try
  1404. // {
  1405. // // 初始化 AtlasScrew 实例
  1406. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1407. // atlasScrew2.Initial();
  1408. // // 存储结果的列表
  1409. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1410. // // 上一次获取的数据
  1411. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1412. // while (isExitAtlasRight) // 检查是否收集数据
  1413. // {
  1414. // // 获取当前数据
  1415. // var currentResult = atlasScrew2.GetResults();
  1416. // // 判断是否为新数据
  1417. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1418. // {
  1419. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1420. // // 将新数据写入PLC
  1421. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1422. // // 将新数据添加到结果列表
  1423. // results.Add(currentResult);
  1424. // // 更新上一次获取的数据
  1425. // lastResult = currentResult;
  1426. // }
  1427. // // 等待一段时间后再次检查
  1428. // Thread.Sleep(20); // 轮询间隔时间
  1429. // // 如果触发了出站,则退出循环
  1430. // if (!isExitAtlasRight)
  1431. // {
  1432. // break;
  1433. // }
  1434. // }
  1435. // // 将所有数据写入文件
  1436. // //WriteDataToFile(sn, direction, results);
  1437. // stopwatch.Stop();
  1438. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1439. // }
  1440. // catch (Exception ex)
  1441. // {
  1442. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1443. // }
  1444. // finally
  1445. // {
  1446. // // 重置标志变量
  1447. // isExitAtlasRight = false;
  1448. // }
  1449. //}
  1450. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1451. {
  1452. Stopwatch stopwatch = new Stopwatch();
  1453. stopwatch.Start();
  1454. int nRet = 0;
  1455. string strRet = "";
  1456. try
  1457. {
  1458. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1459. while (isCollectingFlagLeft)
  1460. {
  1461. // 从缓存中获取所有未处理的数据
  1462. var cachedData = atlasScrew.GetCachedDataLeft();
  1463. foreach (var currentResult in cachedData)
  1464. {
  1465. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1466. {
  1467. continue; // 跳过无效数据
  1468. }
  1469. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1470. // 写入PLC
  1471. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1472. {
  1473. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1474. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1475. };
  1476. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1477. if (nRet != 0)
  1478. {
  1479. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1480. }
  1481. else
  1482. {
  1483. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1484. }
  1485. // 构建保存路径
  1486. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1487. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1488. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1489. Directory.CreateDirectory(savePath); // 确保目录存在
  1490. // 构建文件名(以 SN + 序号命名)
  1491. string fileName = $"{sn}_{fileCounter}.txt";
  1492. string filePath = Path.Combine(savePath, fileName);
  1493. // 写入文件
  1494. using (StreamWriter writer = new StreamWriter(filePath))
  1495. {
  1496. writer.WriteLine("精度, 扭力");
  1497. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1498. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1499. {
  1500. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1501. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1502. writer.WriteLine($"{precision}, {torque}");
  1503. }
  1504. }
  1505. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1506. // 增加文件计数器
  1507. fileCounter++;
  1508. }
  1509. // 如果没有更多数据,则短暂休眠以节省资源
  1510. if (!cachedData.Any())
  1511. {
  1512. Thread.Sleep(10); // 根据需要调整休眠时间
  1513. }
  1514. // 如果触发了出站,则退出循环
  1515. if (!isCollectingFlagLeft)
  1516. {
  1517. break;
  1518. }
  1519. }
  1520. stopwatch.Stop();
  1521. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1522. }
  1523. catch (Exception ex)
  1524. {
  1525. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1526. }
  1527. finally
  1528. {
  1529. isCollectingFlagLeft = false;
  1530. }
  1531. }
  1532. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1533. {
  1534. Stopwatch stopwatch = new Stopwatch();
  1535. stopwatch.Start();
  1536. int nRet = 0;
  1537. string strRet = "";
  1538. try
  1539. {
  1540. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1541. while (isCollectingFlagRight)
  1542. {
  1543. // 从缓存中获取所有未处理的数据
  1544. var cachedData = atlasScrew.GetCachedDataLeft();
  1545. foreach (var currentResult in cachedData)
  1546. {
  1547. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1548. {
  1549. continue; // 跳过无效数据
  1550. }
  1551. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1552. // 写入PLC
  1553. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1554. {
  1555. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1556. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1557. };
  1558. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1559. if (nRet != 0)
  1560. {
  1561. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1562. }
  1563. else
  1564. {
  1565. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1566. }
  1567. // 构建保存路径
  1568. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1569. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1570. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1571. Directory.CreateDirectory(savePath); // 确保目录存在
  1572. // 构建文件名(以 SN + 序号命名)
  1573. string fileName = $"{sn}_{fileCounter}.txt";
  1574. string filePath = Path.Combine(savePath, fileName);
  1575. // 写入文件
  1576. using (StreamWriter writer = new StreamWriter(filePath))
  1577. {
  1578. writer.WriteLine("精度, 扭力");
  1579. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1580. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1581. {
  1582. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1583. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1584. writer.WriteLine($"{precision}, {torque}");
  1585. }
  1586. }
  1587. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1588. // 增加文件计数器
  1589. fileCounter++;
  1590. }
  1591. // 如果没有更多数据,则短暂休眠以节省资源
  1592. if (!cachedData.Any())
  1593. {
  1594. Thread.Sleep(10); // 根据需要调整休眠时间
  1595. }
  1596. // 如果触发了出站,则退出循环
  1597. if (!isCollectingFlagRight)
  1598. {
  1599. break;
  1600. }
  1601. }
  1602. stopwatch.Stop();
  1603. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1604. }
  1605. catch (Exception ex)
  1606. {
  1607. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1608. }
  1609. finally
  1610. {
  1611. isCollectingFlagRight = false;
  1612. }
  1613. }
  1614. #endregion
  1615. #region S1
  1616. /// <summary>
  1617. /// [S1] 壳体清洁上料装备
  1618. /// </summary>
  1619. /// <param name="plcNo">PLC编号</param>
  1620. private void ReadStation_S1(int plcNo)
  1621. {
  1622. string stationCode = "[OP10]";
  1623. string stationName = "壳体清洁上料";
  1624. string stationNameStr = stationCode + stationName;
  1625. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1626. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1627. string tagAgvCommName = "agvCommFrmPC";
  1628. string tagBarsetName = "BarcodeSet";
  1629. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1630. (int, string) result;
  1631. while (true)
  1632. {
  1633. try
  1634. {
  1635. if (!GlobalContext._IsCon_Funs1)
  1636. {
  1637. UpdatePLCMonitor(1, plcNo, 0);
  1638. continue;
  1639. }
  1640. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1641. {
  1642. Stopwatch stopwatch1 = new Stopwatch();
  1643. Stopwatch stopwatch2 = new Stopwatch();
  1644. stopwatch1.Start();
  1645. stopwatch2.Start();
  1646. #region 一次性读取所有数据
  1647. // 一次性读取所有数据
  1648. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1649. if (result.Item1 != 0)
  1650. {
  1651. //richTextBox1.AppendText("\n" + strRet);
  1652. }
  1653. else
  1654. {
  1655. //richTextBox1.AppendText("\n" + "读取成功");
  1656. }
  1657. #endregion 一次性读取所有数据
  1658. stopwatch2.Stop();
  1659. #region 进站
  1660. try
  1661. {
  1662. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1663. {
  1664. lock (lockObj)
  1665. {
  1666. if (!ProgressState)
  1667. {
  1668. ProgressState = true;
  1669. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1670. }
  1671. }
  1672. }
  1673. }
  1674. catch (Exception ex)
  1675. {
  1676. ProgressState = false;
  1677. string str = ex.StackTrace;
  1678. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1679. }
  1680. #endregion 进站
  1681. #region 出站
  1682. try
  1683. {
  1684. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1685. {
  1686. lock (lockObj)
  1687. {
  1688. if (!ProgressState)
  1689. {
  1690. ProgressState = true;
  1691. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1692. }
  1693. }
  1694. }
  1695. }
  1696. catch (Exception ex)
  1697. {
  1698. ProgressState = false;
  1699. string str = ex.StackTrace;
  1700. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1701. }
  1702. #endregion 进站
  1703. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1704. stopwatch1.Stop();
  1705. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1706. }
  1707. else
  1708. {
  1709. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1710. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1711. FunsEip[plcNo].Connect(); // 重连
  1712. }
  1713. }
  1714. catch (Exception ex)
  1715. {
  1716. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1717. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1718. }
  1719. Thread.Sleep(IntervalReadPLC);
  1720. }
  1721. }
  1722. /// <summary>
  1723. /// [S1] 壳体清洁上料 - 进站
  1724. /// </summary>
  1725. /// <param name="plcNo">PLC编号</param>
  1726. /// <param name="stationNameStr">工站全称</param>
  1727. /// <param name="stPLC_MesData"></param>
  1728. /// <param name="tagMesCommName"></param>
  1729. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1730. {
  1731. Stopwatch stopwatch1 = new Stopwatch();
  1732. Stopwatch stopwatch2 = new Stopwatch();
  1733. try
  1734. {
  1735. stopwatch1.Start();
  1736. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1737. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1738. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1739. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1740. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1741. if (string.IsNullOrEmpty(sn))
  1742. {
  1743. ProgressState = false;
  1744. return;
  1745. }
  1746. //正式生产就用PLC中取的
  1747. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1748. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1749. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1750. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1751. //绑定载具和产品
  1752. ResponseMessage message = new ResponseMessage();
  1753. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1754. if (message.result == false)
  1755. {
  1756. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1757. }
  1758. // 产品SN进站
  1759. List<TestItem> item = new List<TestItem>();
  1760. stopwatch2.Start();
  1761. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1762. stopwatch2.Stop();
  1763. //指令执行结果 1:OK 110:失败
  1764. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1765. //进站结果写入PLC
  1766. CommandFromPLC resultToPlC = new CommandFromPLC();
  1767. resultToPlC.cmd = 0;
  1768. resultToPlC.cmdParam = 0;
  1769. resultToPlC.cmdResult = mesResultFrmWeb;
  1770. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1771. }
  1772. catch (Exception ex)
  1773. {
  1774. string str = ex.StackTrace;
  1775. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1776. CommandFromPLC resultToPlC = new CommandFromPLC();
  1777. resultToPlC.cmd = 0;
  1778. resultToPlC.cmdParam = 0; //指令参数
  1779. resultToPlC.cmdResult = 110;
  1780. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1781. }
  1782. stopwatch1.Stop();
  1783. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1784. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1785. ProgressState = false;
  1786. }
  1787. /// <summary>
  1788. /// [S1] 壳体清洁上料 - 出站接口
  1789. /// </summary>
  1790. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1791. {
  1792. Stopwatch stopwatch1 = new Stopwatch();
  1793. Stopwatch stopwatch2 = new Stopwatch();
  1794. try
  1795. {
  1796. stopwatch1.Start();
  1797. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1798. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1799. string processItem = stationName; // 项目
  1800. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1801. string supplierCode = ""; // 供应商代码
  1802. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1803. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1804. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1805. string sn = string.Empty;
  1806. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1807. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1808. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1809. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1810. a1Result = 1;
  1811. bool pass = a1Result == 1;
  1812. //根据载具码获取产品码
  1813. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1814. if (string.IsNullOrEmpty(strProductBarcode))
  1815. {
  1816. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1817. }
  1818. sn = strProductBarcode;
  1819. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1820. List<TestItem> items = new List<TestItem>();
  1821. items.Add(new TestItem()
  1822. {
  1823. Parameter_name = "载具码",
  1824. Parameter_value = CarrierBarcode,
  1825. Parameter_unit = ""
  1826. });
  1827. items.Add(new TestItem()
  1828. {
  1829. Parameter_name = "产品码",
  1830. Parameter_value = sn,
  1831. Parameter_unit = ""
  1832. });
  1833. //出站接口
  1834. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1835. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1836. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1837. stopwatch2.Start();
  1838. //进站结果写入PLC
  1839. CommandFromPLC resultToPlC = new CommandFromPLC();
  1840. resultToPlC.cmd = 0;
  1841. resultToPlC.cmdParam = 0; //指令参数
  1842. resultToPlC.cmdResult = mesResultFrmWeb;
  1843. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1844. stopwatch2.Stop();
  1845. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1846. //保存PLC返回MES数据到本地
  1847. ResponseMessage message = new ResponseMessage();
  1848. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1849. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1850. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1851. stPLC_MesData.mesData.nRemainCount);
  1852. if (message.result == false)
  1853. {
  1854. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1855. }
  1856. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1857. }
  1858. catch (Exception ex)
  1859. {
  1860. stopwatch2.Start();
  1861. CommandFromPLC resultToPlC = new CommandFromPLC();
  1862. resultToPlC.cmd = 0;
  1863. resultToPlC.cmdParam = 0; //指令参数
  1864. resultToPlC.cmdResult = 110;
  1865. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1866. stopwatch2.Stop();
  1867. string str = ex.StackTrace;
  1868. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1869. }
  1870. stopwatch1.Stop();
  1871. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1872. ProgressState = false;
  1873. }
  1874. #endregion
  1875. #region S2
  1876. /// <summary>
  1877. /// [S2] 上盖板上料装备
  1878. /// </summary>
  1879. /// <param name="plcNo">PLC编号</param>
  1880. private void ReadStation_S2(int plcNo)
  1881. {
  1882. string stationCode = "[OP20]";
  1883. string stationName = "上盖板上料装备";
  1884. string stationNameStr = stationCode + stationName;
  1885. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1886. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1887. string tagAgvCommName = "agvCommFrmPC";
  1888. string tagBarsetName = "BarcodeSet";
  1889. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1890. (int, string) result;
  1891. while (true)
  1892. {
  1893. try
  1894. {
  1895. if (!GlobalContext._IsCon_Funs2)
  1896. {
  1897. UpdatePLCMonitor(1, plcNo, 0);
  1898. continue;
  1899. }
  1900. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1901. {
  1902. Stopwatch stopwatch1 = new Stopwatch();
  1903. Stopwatch stopwatch2 = new Stopwatch();
  1904. stopwatch1.Start();
  1905. stopwatch2.Start();
  1906. #region 一次性读取所有数据
  1907. // 一次性读取所有数据
  1908. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1909. if (result.Item1 != 0)
  1910. {
  1911. //richTextBox1.AppendText("\n" + strRet);
  1912. }
  1913. else
  1914. {
  1915. //richTextBox1.AppendText("\n" + "读取成功");
  1916. }
  1917. #endregion 一次性读取所有数据
  1918. stopwatch2.Stop();
  1919. #region 进站
  1920. try
  1921. {
  1922. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1923. {
  1924. lock (lockObj)
  1925. {
  1926. if (!ProgressState)
  1927. {
  1928. ProgressState = true;
  1929. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1930. }
  1931. }
  1932. }
  1933. }
  1934. catch (Exception ex)
  1935. {
  1936. ProgressState = false;
  1937. string str = ex.StackTrace;
  1938. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1939. }
  1940. #endregion 进站
  1941. #region 出站
  1942. try
  1943. {
  1944. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1945. {
  1946. lock (lockObj)
  1947. {
  1948. if (!ProgressState)
  1949. {
  1950. ProgressState = true;
  1951. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1952. }
  1953. }
  1954. }
  1955. }
  1956. catch (Exception ex)
  1957. {
  1958. ProgressState = false;
  1959. string str = ex.StackTrace;
  1960. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1961. }
  1962. #endregion 进站
  1963. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1964. stopwatch1.Stop();
  1965. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1966. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1967. }
  1968. else
  1969. {
  1970. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1971. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1972. FunsEip[plcNo].Connect();
  1973. }
  1974. }
  1975. catch (Exception ex)
  1976. {
  1977. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1978. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1979. //Funs[plcNo].ReConnect();
  1980. }
  1981. Thread.Sleep(IntervalReadPLC);
  1982. }
  1983. }
  1984. /// <summary>
  1985. /// [S2] 上盖板上料装备
  1986. /// </summary>
  1987. /// <param name="plcNo">PLC编号</param>
  1988. /// <param name="stationNameStr">工站全称</param>
  1989. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  1990. {
  1991. Stopwatch stopwatch1 = new Stopwatch();
  1992. Stopwatch stopwatch2 = new Stopwatch();
  1993. try
  1994. {
  1995. stopwatch1.Start();
  1996. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1997. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  1998. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1999. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  2000. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  2001. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2002. //根据载具码获取产品码
  2003. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2004. if (string.IsNullOrEmpty(strProductBarcode))
  2005. {
  2006. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2007. }
  2008. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2009. //if (sn != strProductBarcode)
  2010. //{
  2011. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2012. //}
  2013. sn = strProductBarcode;
  2014. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2015. // 产品SN(物料码)校验
  2016. List<TestItem> item = new List<TestItem>();
  2017. stopwatch2.Start();
  2018. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2019. stopwatch2.Stop();
  2020. //指令执行结果 1:OK 110:失败
  2021. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2022. //进站结果写入PLC
  2023. CommandFromPLC resultToPlC = new CommandFromPLC();
  2024. resultToPlC.cmd = 0;
  2025. resultToPlC.cmdParam = 0; //指令参数
  2026. resultToPlC.cmdResult = mesResultFrmWeb;
  2027. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2028. }
  2029. catch (Exception ex)
  2030. {
  2031. string str = ex.StackTrace;
  2032. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2033. CommandFromPLC resultToPlC = new CommandFromPLC();
  2034. resultToPlC.cmd = 0;
  2035. resultToPlC.cmdParam = 0; //指令参数
  2036. resultToPlC.cmdResult = 110;
  2037. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2038. }
  2039. stopwatch1.Stop();
  2040. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2041. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2042. ProgressState = false;
  2043. }
  2044. /// <summary>
  2045. /// [S2] 上盖板上料装备 - 出站接口
  2046. /// </summary>
  2047. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2048. {
  2049. Stopwatch stopwatch1 = new Stopwatch();
  2050. Stopwatch stopwatch2 = new Stopwatch();
  2051. try
  2052. {
  2053. stopwatch1.Start();
  2054. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2055. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2056. string processItem = stationName; // 测试项目
  2057. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2058. string supplierCode = ""; // 供应商代码
  2059. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2060. string batch_num = GlobalContext.BatchNumber; // 批次号
  2061. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2062. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2063. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2064. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2065. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2066. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  2067. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2068. bool pass = a1Result == 1;
  2069. //根据载具码获取产品码
  2070. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2071. if (string.IsNullOrEmpty(strProductBarcode))
  2072. {
  2073. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2074. }
  2075. sn = strProductBarcode;
  2076. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2077. List<TestItem> items = new List<TestItem>();
  2078. items.Add(new TestItem()
  2079. {
  2080. Parameter_name = "载具码",
  2081. Parameter_value = CarrierBarcode,
  2082. Parameter_unit = ""
  2083. });
  2084. items.Add(new TestItem()
  2085. {
  2086. Parameter_name = "产品码",
  2087. Parameter_value = sn,
  2088. Parameter_unit = ""
  2089. });
  2090. items.Add(new TestItem()
  2091. {
  2092. Parameter_name = "部件码",
  2093. Parameter_value = PartBarcode,
  2094. Parameter_unit = ""
  2095. });
  2096. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2097. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2098. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2099. stopwatch2.Start();
  2100. //进站结果写入PLC
  2101. CommandFromPLC resultToPlC = new CommandFromPLC();
  2102. resultToPlC.cmd = 0;
  2103. resultToPlC.cmdParam = 0; //指令参数
  2104. resultToPlC.cmdResult = mesResultFrmWeb;
  2105. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2106. stopwatch2.Stop();
  2107. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2108. //保存PLC返回MES数据到本地
  2109. ResponseMessage message = new ResponseMessage();
  2110. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  2111. if (message.result == false)
  2112. {
  2113. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2114. }
  2115. if (!string.IsNullOrEmpty(PartBarcode))
  2116. {
  2117. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2118. if (message.result == false)
  2119. {
  2120. AddMessage(LogType.Error, message.text);
  2121. }
  2122. }
  2123. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2124. }
  2125. catch (Exception ex)
  2126. {
  2127. stopwatch2.Start();
  2128. CommandFromPLC resultToPlC = new CommandFromPLC();
  2129. resultToPlC.cmd = 0;
  2130. resultToPlC.cmdParam = 0; //指令参数
  2131. resultToPlC.cmdResult = 110;
  2132. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2133. stopwatch2.Stop();
  2134. string str = ex.StackTrace;
  2135. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2136. }
  2137. stopwatch1.Stop();
  2138. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2139. ProgressState = false;
  2140. }
  2141. #endregion
  2142. #region S3
  2143. /// <summary>
  2144. /// [S3] 点散热胶装备
  2145. /// </summary>
  2146. /// <param name="plcNo">PLC编号</param>
  2147. private void ReadStation_S3(int plcNo)
  2148. {
  2149. string stationCode = "[OP30]";
  2150. string stationName = "点散热胶装备";
  2151. string stationNameStr = stationCode + stationName;
  2152. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2153. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2154. string tagAgvCommName = "agvCommFrmPC";
  2155. string tagBarsetName = "BarcodeSet";
  2156. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2157. (int, string) result;
  2158. #region 创建字典
  2159. // 触发信号字典 赋值
  2160. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2161. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2162. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2163. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2164. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2165. // PLC数据字典 赋值
  2166. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2167. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2168. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2169. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2170. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2171. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2172. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2173. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2174. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2175. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2176. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2177. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2178. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2179. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2180. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2181. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2182. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2183. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2184. s3PLCData.Add("c1Result", 0); // 产品结果
  2185. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2186. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2187. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2188. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2189. #endregion 创建字典
  2190. while (true)
  2191. {
  2192. try
  2193. {
  2194. if (!GlobalContext._IsCon_Funs2)
  2195. {
  2196. UpdatePLCMonitor(1, plcNo, 0);
  2197. continue;
  2198. }
  2199. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2200. {
  2201. Stopwatch stopwatch1 = new Stopwatch();
  2202. Stopwatch stopwatch2 = new Stopwatch();
  2203. stopwatch1.Start();
  2204. stopwatch2.Start();
  2205. #region 一次性读取所有数据
  2206. // 一次性读取所有数据
  2207. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2208. if (result.Item1 != 0)
  2209. {
  2210. //richTextBox1.AppendText("\n" + strRet);
  2211. }
  2212. else
  2213. {
  2214. //richTextBox1.AppendText("\n" + "读取成功");
  2215. }
  2216. #endregion 一次性读取所有数据
  2217. stopwatch2.Stop();
  2218. #region 左边进站
  2219. try
  2220. {
  2221. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2222. {
  2223. lock (lockObj)
  2224. {
  2225. if (!ProgressState)
  2226. {
  2227. ProgressState = true;
  2228. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2229. }
  2230. }
  2231. }
  2232. }
  2233. catch (Exception ex)
  2234. {
  2235. ProgressState = false;
  2236. string str = ex.StackTrace;
  2237. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2238. }
  2239. #endregion 左边进站
  2240. #region 左边出站
  2241. try
  2242. {
  2243. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2244. {
  2245. lock (lockObj)
  2246. {
  2247. if (!ProgressState)
  2248. {
  2249. ProgressState = true;
  2250. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2251. }
  2252. }
  2253. }
  2254. }
  2255. catch (Exception ex)
  2256. {
  2257. ProgressState = false;
  2258. string str = ex.StackTrace;
  2259. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2260. }
  2261. #endregion 左边出站
  2262. #region 右边进站
  2263. try
  2264. {
  2265. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2266. {
  2267. lock (lockObj)
  2268. {
  2269. if (!ProgressState)
  2270. {
  2271. ProgressState = true;
  2272. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2273. }
  2274. }
  2275. }
  2276. }
  2277. catch (Exception ex)
  2278. {
  2279. ProgressState = false;
  2280. string str = ex.StackTrace;
  2281. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2282. }
  2283. #endregion 右边进站
  2284. #region 右边出站
  2285. try
  2286. {
  2287. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2288. {
  2289. lock (lockObj)
  2290. {
  2291. if (!ProgressState)
  2292. {
  2293. ProgressState = true;
  2294. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2295. }
  2296. }
  2297. }
  2298. }
  2299. catch (Exception ex)
  2300. {
  2301. string str = ex.StackTrace;
  2302. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2303. }
  2304. #endregion 右边出站
  2305. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2306. stopwatch1.Stop();
  2307. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2308. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2309. }
  2310. else
  2311. {
  2312. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2313. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2314. FunsEip[plcNo].Connect();
  2315. }
  2316. }
  2317. catch (Exception ex)
  2318. {
  2319. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2320. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2321. //Funs[plcNo].ReConnect();
  2322. }
  2323. Thread.Sleep(IntervalReadPLC);
  2324. }
  2325. }
  2326. /// <summary>
  2327. /// [S3] 点散热胶装备 - 进站
  2328. /// </summary>
  2329. /// <param name="plcNo">PLC编号</param>
  2330. /// <param name="stationNameStr">工站全称</param>
  2331. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2332. {
  2333. Stopwatch stopwatch1 = new Stopwatch();
  2334. Stopwatch stopwatch2 = new Stopwatch();
  2335. try
  2336. {
  2337. stopwatch1.Start();
  2338. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2339. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2340. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2341. string StationId=string.Empty;
  2342. if (direction=="Left")
  2343. {
  2344. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2345. }
  2346. if (direction == "Right")
  2347. {
  2348. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2349. }
  2350. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2351. //载具码验证产品码
  2352. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2353. if (string.IsNullOrEmpty(strProductBarcode))
  2354. {
  2355. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2356. }
  2357. sn = strProductBarcode;
  2358. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2359. // 产品SN(物料码)校验
  2360. List<TestItem> item = new List<TestItem>();
  2361. stopwatch2.Start();
  2362. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2363. stopwatch2.Stop();
  2364. //指令执行结果 1:OK 110:失败
  2365. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2366. //进站结果写入PLC
  2367. CommandFromPLC resultToPlC = new CommandFromPLC();
  2368. resultToPlC.cmd = 0;
  2369. resultToPlC.cmdParam = 0; //指令参数
  2370. resultToPlC.cmdResult = mesResultFrmWeb;
  2371. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2372. }
  2373. catch (Exception ex)
  2374. {
  2375. string str = ex.StackTrace;
  2376. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2377. CommandFromPLC resultToPlC = new CommandFromPLC();
  2378. resultToPlC.cmd = 0;
  2379. resultToPlC.cmdParam = 0; //指令参数
  2380. resultToPlC.cmdResult = 110;
  2381. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2382. }
  2383. stopwatch1.Stop();
  2384. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2385. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2386. ProgressState = false;
  2387. }
  2388. /// <summary>
  2389. /// [S3] 点散热胶装备 - 出站
  2390. /// </summary>
  2391. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2392. {
  2393. Stopwatch stopwatch1 = new Stopwatch();
  2394. Stopwatch stopwatch2 = new Stopwatch();
  2395. try
  2396. {
  2397. stopwatch1.Start();
  2398. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2399. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2400. string processItem = stationName; // 测试项目
  2401. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2402. string supplierCode = ""; // 供应商代码
  2403. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2404. string batch_num = GlobalContext.BatchNumber; // 批次号
  2405. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2406. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2407. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2408. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2409. string StationId = string.Empty;
  2410. if (direction == "Left")
  2411. {
  2412. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2413. }
  2414. if (direction == "Right")
  2415. {
  2416. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2417. }
  2418. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2419. bool pass = a1Result == 1;
  2420. //根据载具码获取产品码
  2421. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2422. if (string.IsNullOrEmpty(strProductBarcode))
  2423. {
  2424. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2425. }
  2426. sn = strProductBarcode;
  2427. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2428. List<TestItem> items = new List<TestItem>();
  2429. items.Add(new TestItem()
  2430. {
  2431. Parameter_name = "载具码",
  2432. Parameter_value = CarrierBarcode,
  2433. Parameter_unit = ""
  2434. });
  2435. items.Add(new TestItem()
  2436. {
  2437. Parameter_name = "产品码",
  2438. Parameter_value = sn,
  2439. Parameter_unit = ""
  2440. });
  2441. int result1 = 1;
  2442. if (direction == "Right")
  2443. {
  2444. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2445. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2446. }
  2447. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2448. stopwatch2.Start();
  2449. //进站结果写入PLC
  2450. CommandFromPLC resultToPlC = new CommandFromPLC();
  2451. resultToPlC.cmd = 0;
  2452. resultToPlC.cmdParam = 0; //指令参数
  2453. resultToPlC.cmdResult = mesResultFrmWeb;
  2454. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2455. stopwatch2.Stop();
  2456. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2457. //保存PLC返回MES数据到本地
  2458. ResponseMessage message = new ResponseMessage();
  2459. if (direction == "Left")
  2460. {
  2461. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2462. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2463. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2464. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2465. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2466. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2467. if (message.result == false)
  2468. {
  2469. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2470. }
  2471. }
  2472. if (direction == "Right")
  2473. {
  2474. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2475. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2476. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2477. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2478. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2479. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2480. if (message.result == false)
  2481. {
  2482. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2483. }
  2484. }
  2485. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2486. }
  2487. catch (Exception ex)
  2488. {
  2489. stopwatch2.Start();
  2490. CommandFromPLC resultToPlC = new CommandFromPLC();
  2491. resultToPlC.cmd = 0;
  2492. resultToPlC.cmdParam = 0; //指令参数
  2493. resultToPlC.cmdResult = 110;
  2494. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2495. stopwatch2.Stop();
  2496. string str = ex.StackTrace;
  2497. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2498. }
  2499. stopwatch1.Stop();
  2500. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2501. ProgressState = false;
  2502. }
  2503. #endregion S3
  2504. #region S4
  2505. /// <summary>
  2506. /// [S4] 点胶检测设备
  2507. /// </summary>
  2508. /// <param name="plcNo">PLC编号</param>
  2509. private void ReadStation_S4(int plcNo)
  2510. {
  2511. string stationCode = "[OP40]";
  2512. string stationName = "胶线检测";
  2513. string stationNameStr = stationCode + stationName;
  2514. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2515. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2516. string tagAgvCommName = "agvCommFrmPC";
  2517. string tagBarsetName = "BarcodeSet";
  2518. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2519. (int, string) result;
  2520. while (true)
  2521. {
  2522. try
  2523. {
  2524. if (!GlobalContext._IsCon_Funs1)
  2525. {
  2526. UpdatePLCMonitor(1, plcNo, 0);
  2527. continue;
  2528. }
  2529. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2530. {
  2531. Stopwatch stopwatch1 = new Stopwatch();
  2532. Stopwatch stopwatch2 = new Stopwatch();
  2533. stopwatch1.Start();
  2534. stopwatch2.Start();
  2535. #region 一次性读取所有数据
  2536. // 一次性读取所有数据
  2537. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2538. if (result.Item1 != 0)
  2539. {
  2540. //richTextBox1.AppendText("\n" + strRet);
  2541. }
  2542. else
  2543. {
  2544. //richTextBox1.AppendText("\n" + "读取成功");
  2545. }
  2546. #endregion 一次性读取所有数据
  2547. stopwatch2.Stop();
  2548. #region 进站
  2549. try
  2550. {
  2551. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2552. {
  2553. lock (lockObj)
  2554. {
  2555. if (!ProgressState)
  2556. {
  2557. ProgressState = true;
  2558. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2559. }
  2560. }
  2561. }
  2562. }
  2563. catch (Exception ex)
  2564. {
  2565. ProgressState = false;
  2566. string str = ex.StackTrace;
  2567. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2568. }
  2569. #endregion 进站
  2570. #region 出站
  2571. try
  2572. {
  2573. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2574. {
  2575. lock (lockObj)
  2576. {
  2577. if (!ProgressState)
  2578. {
  2579. ProgressState = true;
  2580. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2581. }
  2582. }
  2583. }
  2584. }
  2585. catch (Exception ex)
  2586. {
  2587. string str = ex.StackTrace;
  2588. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2589. }
  2590. #endregion 进站
  2591. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2592. stopwatch1.Stop();
  2593. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2594. }
  2595. else
  2596. {
  2597. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2598. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2599. FunsEip[plcNo].Connect(); // 重连
  2600. }
  2601. }
  2602. catch (Exception ex)
  2603. {
  2604. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2605. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2606. }
  2607. Thread.Sleep(IntervalReadPLC);
  2608. }
  2609. }
  2610. /// <summary>
  2611. /// [S4] 点胶检测设备 - 进站
  2612. /// </summary>
  2613. /// <param name="plcNo">PLC编号</param>
  2614. /// <param name="stationNameStr">工站全称</param>
  2615. /// <param name="stPLC_MesData"></param>
  2616. /// <param name="tagMesCommName"></param>
  2617. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2618. {
  2619. Stopwatch stopwatch1 = new Stopwatch();
  2620. Stopwatch stopwatch2 = new Stopwatch();
  2621. try
  2622. {
  2623. stopwatch1.Start();
  2624. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2625. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2626. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2627. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2628. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2629. //载具码验证产品码
  2630. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2631. if (string.IsNullOrEmpty(strProductBarcode))
  2632. {
  2633. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2634. }
  2635. sn = strProductBarcode;
  2636. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2637. // 产品SN(物料码)校验
  2638. List<TestItem> item = new List<TestItem>();
  2639. stopwatch2.Start();
  2640. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2641. stopwatch2.Stop();
  2642. //指令执行结果 1:OK 110:失败
  2643. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2644. //进站结果写入PLC
  2645. CommandFromPLC resultToPlC = new CommandFromPLC();
  2646. resultToPlC.cmd = 0;
  2647. resultToPlC.cmdParam = 0; //指令参数
  2648. resultToPlC.cmdResult = mesResultFrmWeb;
  2649. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2650. }
  2651. catch (Exception ex)
  2652. {
  2653. string str = ex.StackTrace;
  2654. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2655. CommandFromPLC resultToPlC = new CommandFromPLC();
  2656. resultToPlC.cmd = 0;
  2657. resultToPlC.cmdParam = 0; //指令参数
  2658. resultToPlC.cmdResult = 110;
  2659. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2660. }
  2661. stopwatch1.Stop();
  2662. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2663. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2664. ProgressState = false;
  2665. }
  2666. /// <summary>
  2667. /// [S4] 点胶检测设备 - 出站接口
  2668. /// </summary>
  2669. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2670. {
  2671. Stopwatch stopwatch1 = new Stopwatch();
  2672. Stopwatch stopwatch2 = new Stopwatch();
  2673. try
  2674. {
  2675. stopwatch1.Start();
  2676. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2677. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2678. string processItem = stationName; // 测试项目
  2679. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2680. string supplierCode = ""; // 供应商代码
  2681. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2682. string batch_num = GlobalContext.BatchNumber; // 批次号
  2683. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2684. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2685. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2686. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2687. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2688. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2689. bool pass = a1Result == 1;
  2690. //根据载具码获取产品码
  2691. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2692. if (string.IsNullOrEmpty(strProductBarcode))
  2693. {
  2694. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2695. }
  2696. sn = strProductBarcode;
  2697. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2698. List<TestItem> items = new List<TestItem>();
  2699. items.Add(new TestItem()
  2700. {
  2701. Parameter_name = "载具码",
  2702. Parameter_value = CarrierBarcode,
  2703. Parameter_unit = ""
  2704. });
  2705. items.Add(new TestItem()
  2706. {
  2707. Parameter_name = "产品码",
  2708. Parameter_value = sn,
  2709. Parameter_unit = ""
  2710. });
  2711. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2712. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2713. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2714. stopwatch2.Start();
  2715. //进站结果写入PLC
  2716. CommandFromPLC resultToPlC = new CommandFromPLC();
  2717. resultToPlC.cmd = 0;
  2718. resultToPlC.cmdParam = 0; //指令参数
  2719. resultToPlC.cmdResult = mesResultFrmWeb;
  2720. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2721. stopwatch2.Stop();
  2722. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2723. //保存PLC返回MES数据到本地
  2724. ResponseMessage message = new ResponseMessage();
  2725. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2726. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2727. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2728. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2729. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2730. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2731. if (message.result == false)
  2732. {
  2733. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2734. }
  2735. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2736. }
  2737. catch (Exception ex)
  2738. {
  2739. stopwatch2.Start();
  2740. CommandFromPLC resultToPlC = new CommandFromPLC();
  2741. resultToPlC.cmd = 0;
  2742. resultToPlC.cmdParam = 0; //指令参数
  2743. resultToPlC.cmdResult = 110;
  2744. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2745. stopwatch2.Stop();
  2746. string str = ex.StackTrace;
  2747. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2748. }
  2749. stopwatch1.Stop();
  2750. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2751. ProgressState = false;
  2752. }
  2753. #endregion
  2754. #region S5
  2755. /// <summary>
  2756. /// [S5] 点胶检测设备
  2757. /// </summary>
  2758. /// <param name="plcNo">PLC编号</param>
  2759. private void ReadStation_S5(int plcNo)
  2760. {
  2761. string stationCode = "[OP50]";
  2762. string stationName = "ADD板上料组装装备";
  2763. string stationNameStr = stationCode + stationName;
  2764. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2765. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2766. string tagAgvCommName = "agvCommFrmPC";
  2767. string tagBarsetName = "BarcodeSet";
  2768. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2769. (int, string) result;
  2770. while (true)
  2771. {
  2772. try
  2773. {
  2774. if (!GlobalContext._IsCon_Funs1)
  2775. {
  2776. UpdatePLCMonitor(1, plcNo, 0);
  2777. continue;
  2778. }
  2779. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2780. {
  2781. Stopwatch stopwatch1 = new Stopwatch();
  2782. Stopwatch stopwatch2 = new Stopwatch();
  2783. stopwatch1.Start();
  2784. stopwatch2.Start();
  2785. #region 一次性读取所有数据
  2786. // 一次性读取所有数据
  2787. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2788. if (result.Item1 != 0)
  2789. {
  2790. //richTextBox1.AppendText("\n" + strRet);
  2791. }
  2792. else
  2793. {
  2794. //richTextBox1.AppendText("\n" + "读取成功");
  2795. }
  2796. #endregion 一次性读取所有数据
  2797. stopwatch2.Stop();
  2798. #region 进站
  2799. try
  2800. {
  2801. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2802. {
  2803. lock (lockObj)
  2804. {
  2805. if (!ProgressState)
  2806. {
  2807. ProgressState = true;
  2808. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2809. }
  2810. }
  2811. }
  2812. }
  2813. catch (Exception ex)
  2814. {
  2815. ProgressState = false;
  2816. string str = ex.StackTrace;
  2817. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2818. }
  2819. #endregion 进站
  2820. #region 出站
  2821. try
  2822. {
  2823. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2824. {
  2825. lock (lockObj)
  2826. {
  2827. if (!ProgressState)
  2828. {
  2829. ProgressState = true;
  2830. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2831. }
  2832. }
  2833. }
  2834. }
  2835. catch (Exception ex)
  2836. {
  2837. ProgressState = false;
  2838. string str = ex.StackTrace;
  2839. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2840. }
  2841. #endregion 进站
  2842. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2843. stopwatch1.Stop();
  2844. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2845. }
  2846. else
  2847. {
  2848. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2849. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2850. FunsEip[plcNo].Connect(); // 重连
  2851. }
  2852. }
  2853. catch (Exception ex)
  2854. {
  2855. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2856. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2857. }
  2858. Thread.Sleep(IntervalReadPLC);
  2859. }
  2860. }
  2861. /// <summary>
  2862. /// [S5] 点胶检测设备 - 进站
  2863. /// </summary>
  2864. /// <param name="plcNo">PLC编号</param>
  2865. /// <param name="stationNameStr">工站全称</param>
  2866. /// <param name="stPLC_MesData"></param>
  2867. /// <param name="tagMesCommName"></param>
  2868. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2869. {
  2870. Stopwatch stopwatch1 = new Stopwatch();
  2871. Stopwatch stopwatch2 = new Stopwatch();
  2872. try
  2873. {
  2874. stopwatch1.Start();
  2875. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2876. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2877. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2878. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2879. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2880. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2881. //载具码验证产品码 //载具码验证产品码
  2882. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2883. if (string.IsNullOrEmpty(strProductBarcode))
  2884. {
  2885. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2886. }
  2887. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2888. //if (sn != strProductBarcode)
  2889. //{
  2890. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2891. //}
  2892. sn = strProductBarcode;
  2893. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2894. // 产品SN(物料码)校验
  2895. List<TestItem> item = new List<TestItem>();
  2896. stopwatch2.Start();
  2897. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2898. stopwatch2.Stop();
  2899. //指令执行结果 1:OK 110:失败
  2900. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2901. //进站结果写入PLC
  2902. CommandFromPLC resultToPlC = new CommandFromPLC();
  2903. resultToPlC.cmd = 0;
  2904. resultToPlC.cmdParam = 0; //指令参数
  2905. resultToPlC.cmdResult = mesResultFrmWeb;
  2906. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2907. }
  2908. catch (Exception ex)
  2909. {
  2910. string str = ex.StackTrace;
  2911. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2912. CommandFromPLC resultToPlC = new CommandFromPLC();
  2913. resultToPlC.cmd = 0;
  2914. resultToPlC.cmdParam = 0; //指令参数
  2915. resultToPlC.cmdResult = 110;
  2916. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2917. }
  2918. stopwatch1.Stop();
  2919. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2920. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2921. ProgressState = false;
  2922. }
  2923. /// <summary>
  2924. /// [S5] 点胶检测设备 - 出站接口
  2925. /// </summary>
  2926. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2927. {
  2928. Stopwatch stopwatch1 = new Stopwatch();
  2929. Stopwatch stopwatch2 = new Stopwatch();
  2930. try
  2931. {
  2932. stopwatch1.Start();
  2933. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2934. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2935. string processItem = stationName; // 测试项目
  2936. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2937. string supplierCode = ""; // 供应商代码
  2938. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2939. string batch_num = GlobalContext.BatchNumber; // 批次号
  2940. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2941. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2942. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2943. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2944. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2945. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2946. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2947. bool pass = a1Result == 1;
  2948. //根据载具码获取产品码
  2949. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2950. if (string.IsNullOrEmpty(strProductBarcode))
  2951. {
  2952. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2953. }
  2954. sn = strProductBarcode;
  2955. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2956. List<TestItem> items = new List<TestItem>();
  2957. items.Add(new TestItem()
  2958. {
  2959. Parameter_name = "载具码",
  2960. Parameter_value = CarrierBarcode,
  2961. Parameter_unit = ""
  2962. });
  2963. items.Add(new TestItem()
  2964. {
  2965. Parameter_name = "产品码",
  2966. Parameter_value = sn,
  2967. Parameter_unit = ""
  2968. });
  2969. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2970. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2971. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2972. stopwatch2.Start();
  2973. //进站结果写入PLC
  2974. CommandFromPLC resultToPlC = new CommandFromPLC();
  2975. resultToPlC.cmd = 0;
  2976. resultToPlC.cmdParam = 0; //指令参数
  2977. resultToPlC.cmdResult = mesResultFrmWeb;
  2978. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2979. stopwatch2.Stop();
  2980. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2981. //保存PLC返回MES数据到本地
  2982. ResponseMessage message = new ResponseMessage();
  2983. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  2984. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  2985. if (message.result == false)
  2986. {
  2987. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2988. }
  2989. //保存部件码信息
  2990. if (!string.IsNullOrEmpty(PartBarcode))
  2991. {
  2992. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  2993. if (message.result == false)
  2994. {
  2995. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  2996. }
  2997. }
  2998. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2999. }
  3000. catch (Exception ex)
  3001. {
  3002. stopwatch2.Start();
  3003. CommandFromPLC resultToPlC = new CommandFromPLC();
  3004. resultToPlC.cmd = 0;
  3005. resultToPlC.cmdParam = 0; //指令参数
  3006. resultToPlC.cmdResult = 110;
  3007. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3008. stopwatch2.Stop();
  3009. string str = ex.StackTrace;
  3010. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3011. }
  3012. stopwatch1.Stop();
  3013. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3014. ProgressState = false;
  3015. }
  3016. #endregion
  3017. #region S6
  3018. /// <summary>
  3019. /// [S6] 顶盖装配设备
  3020. /// </summary>
  3021. /// <param name="plcNo">PLC编号</param>
  3022. private void ReadStation_S6(int plcNo)
  3023. {
  3024. string stationCode = "[OP60]";
  3025. string stationName = "组上盖板";
  3026. string stationNameStr = stationCode + stationName;
  3027. string tagBaseName = "g_OP60_MES"; //标签变量名称
  3028. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3029. string tagAgvCommName = "agvCommFrmPC";
  3030. string tagBarsetName = "BarcodeSet";
  3031. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  3032. (int, string) result;
  3033. while (true)
  3034. {
  3035. try
  3036. {
  3037. if (!GlobalContext._IsCon_Funs1)
  3038. {
  3039. UpdatePLCMonitor(1, plcNo, 0);
  3040. continue;
  3041. }
  3042. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3043. {
  3044. Stopwatch stopwatch1 = new Stopwatch();
  3045. Stopwatch stopwatch2 = new Stopwatch();
  3046. stopwatch1.Start();
  3047. stopwatch2.Start();
  3048. #region 一次性读取所有数据
  3049. // 一次性读取所有数据
  3050. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3051. if (result.Item1 != 0)
  3052. {
  3053. //richTextBox1.AppendText("\n" + strRet);
  3054. }
  3055. else
  3056. {
  3057. //richTextBox1.AppendText("\n" + "读取成功");
  3058. }
  3059. #endregion 一次性读取所有数据
  3060. stopwatch2.Stop();
  3061. #region 进站
  3062. try
  3063. {
  3064. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3065. {
  3066. lock (lockObj)
  3067. {
  3068. if (!ProgressState)
  3069. {
  3070. ProgressState = true;
  3071. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3072. }
  3073. }
  3074. }
  3075. }
  3076. catch (Exception ex)
  3077. {
  3078. ProgressState = false;
  3079. string str = ex.StackTrace;
  3080. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3081. }
  3082. #endregion 进站
  3083. #region 出站
  3084. try
  3085. {
  3086. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3087. {
  3088. lock (lockObj)
  3089. {
  3090. if (!ProgressState)
  3091. {
  3092. ProgressState = true; ;
  3093. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3094. }
  3095. }
  3096. }
  3097. }
  3098. catch (Exception ex)
  3099. {
  3100. ProgressState = false;
  3101. string str = ex.StackTrace;
  3102. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3103. }
  3104. #endregion 进站
  3105. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3106. stopwatch1.Stop();
  3107. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3108. }
  3109. else
  3110. {
  3111. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3112. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3113. FunsEip[plcNo].Connect(); // 重连
  3114. }
  3115. }
  3116. catch (Exception ex)
  3117. {
  3118. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3119. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3120. }
  3121. Thread.Sleep(IntervalReadPLC);
  3122. }
  3123. }
  3124. /// <summary>
  3125. /// [S6] 顶盖装配设备 - 进站
  3126. /// </summary>
  3127. /// <param name="plcNo">PLC编号</param>
  3128. /// <param name="stationNameStr">工站全称</param>
  3129. /// <param name="stPLC_MesData"></param>
  3130. /// <param name="tagMesCommName"></param>
  3131. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3132. {
  3133. Stopwatch stopwatch1 = new Stopwatch();
  3134. Stopwatch stopwatch2 = new Stopwatch();
  3135. try
  3136. {
  3137. stopwatch1.Start();
  3138. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3139. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3140. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3141. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3142. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3143. //载具码验证产品码
  3144. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3145. if (string.IsNullOrEmpty(strProductBarcode))
  3146. {
  3147. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3148. }
  3149. sn = strProductBarcode;
  3150. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3151. // 产品SN(物料码)校验
  3152. List<TestItem> item = new List<TestItem>();
  3153. stopwatch2.Start();
  3154. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3155. stopwatch2.Stop();
  3156. //指令执行结果 1:OK 110:失败
  3157. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3158. //进站结果写入PLC
  3159. CommandFromPLC resultToPlC = new CommandFromPLC();
  3160. resultToPlC.cmd = 0;
  3161. resultToPlC.cmdParam = 0; //指令参数
  3162. resultToPlC.cmdResult = mesResultFrmWeb;
  3163. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3164. }
  3165. catch (Exception ex)
  3166. {
  3167. string str = ex.StackTrace;
  3168. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3169. CommandFromPLC resultToPlC = new CommandFromPLC();
  3170. resultToPlC.cmd = 0;
  3171. resultToPlC.cmdParam = 0; //指令参数
  3172. resultToPlC.cmdResult = 110;
  3173. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3174. }
  3175. stopwatch1.Stop();
  3176. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3177. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3178. ProgressState = false;
  3179. }
  3180. /// <summary>
  3181. /// [S6] 顶盖装配设备 - 出站接口
  3182. /// </summary>
  3183. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3184. {
  3185. Stopwatch stopwatch1 = new Stopwatch();
  3186. Stopwatch stopwatch2 = new Stopwatch();
  3187. try
  3188. {
  3189. stopwatch1.Start();
  3190. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3191. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3192. string processItem = stationName; // 测试项目
  3193. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3194. string supplierCode = ""; // 供应商代码
  3195. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3196. string batch_num = GlobalContext.BatchNumber; // 批次号
  3197. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3198. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3199. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3200. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3201. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3202. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3203. bool pass = a1Result == 1;
  3204. //根据载具码获取产品码
  3205. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3206. if (string.IsNullOrEmpty(strProductBarcode))
  3207. {
  3208. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3209. }
  3210. sn = strProductBarcode;
  3211. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3212. List<TestItem> items = new List<TestItem>();
  3213. items.Add(new TestItem()
  3214. {
  3215. Parameter_name = "载具码",
  3216. Parameter_value = CarrierBarcode,
  3217. Parameter_unit = ""
  3218. });
  3219. items.Add(new TestItem()
  3220. {
  3221. Parameter_name = "产品码",
  3222. Parameter_value = sn,
  3223. Parameter_unit = ""
  3224. });
  3225. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3226. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3227. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3228. stopwatch2.Start();
  3229. //进站结果写入PLC
  3230. CommandFromPLC resultToPlC = new CommandFromPLC();
  3231. resultToPlC.cmd = 0;
  3232. resultToPlC.cmdParam = 0; //指令参数
  3233. resultToPlC.cmdResult = mesResultFrmWeb;
  3234. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3235. stopwatch2.Stop();
  3236. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3237. //保存PLC返回MES数据到本地
  3238. ResponseMessage message = new ResponseMessage();
  3239. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3240. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3241. if (message.result == false)
  3242. {
  3243. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3244. }
  3245. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3246. }
  3247. catch (Exception ex)
  3248. {
  3249. stopwatch2.Start();
  3250. CommandFromPLC resultToPlC = new CommandFromPLC();
  3251. resultToPlC.cmd = 0;
  3252. resultToPlC.cmdParam = 0; //指令参数
  3253. resultToPlC.cmdResult = 110;
  3254. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3255. stopwatch2.Stop();
  3256. string str = ex.StackTrace;
  3257. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3258. }
  3259. stopwatch1.Stop();
  3260. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3261. ProgressState = false;
  3262. }
  3263. #endregion
  3264. #region S7
  3265. /// <summary>
  3266. /// [S7] 锁螺丝设备
  3267. /// </summary>
  3268. /// <param name="plcNo">PLC编号</param>
  3269. private void ReadStation_S7(int plcNo)
  3270. {
  3271. string stationCode = "[OP70]";
  3272. string stationName = "上盖板锁螺丝";
  3273. string stationNameStr = stationCode + stationName;
  3274. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3275. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3276. string tagAgvCommName = "agvCommFrmPC";
  3277. string tagBarsetName = "BarcodeSet";
  3278. string tagScrewDataset = "screwDataset";
  3279. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3280. (int, string) result;
  3281. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3282. atlasScrewLeft.Initial();
  3283. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3284. atlasScrewRight.Initial();
  3285. while (true)
  3286. {
  3287. try
  3288. {
  3289. if (!GlobalContext._IsCon_Funs1)
  3290. {
  3291. UpdatePLCMonitor(1, plcNo, 0);
  3292. continue;
  3293. }
  3294. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3295. {
  3296. Stopwatch stopwatch1 = new Stopwatch();
  3297. Stopwatch stopwatch2 = new Stopwatch();
  3298. stopwatch1.Start();
  3299. stopwatch2.Start();
  3300. #region 一次性读取所有数据
  3301. // 一次性读取所有数据
  3302. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3303. if (result.Item1 != 0)
  3304. {
  3305. //richTextBox1.AppendText("\n" + strRet);
  3306. }
  3307. else
  3308. {
  3309. //richTextBox1.AppendText("\n" + "读取成功");
  3310. }
  3311. #endregion 一次性读取所有数据
  3312. stopwatch2.Stop();
  3313. #region 左边进站
  3314. try
  3315. {
  3316. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3317. {
  3318. lock (lockObj)
  3319. {
  3320. if (!ProgressState)
  3321. {
  3322. ProgressState = true;
  3323. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3324. }
  3325. }
  3326. }
  3327. }
  3328. catch (Exception ex)
  3329. {
  3330. ProgressState = false;
  3331. string str = ex.StackTrace;
  3332. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3333. }
  3334. #endregion 左边进站
  3335. #region 左边出站
  3336. try
  3337. {
  3338. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3339. {
  3340. lock (lockObj)
  3341. {
  3342. if (!ProgressState)
  3343. {
  3344. ProgressState = true;
  3345. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3346. }
  3347. }
  3348. }
  3349. }
  3350. catch (Exception ex)
  3351. {
  3352. ProgressState = false;
  3353. string str = ex.StackTrace;
  3354. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3355. }
  3356. #endregion 左边出站
  3357. #region 右边进站
  3358. try
  3359. {
  3360. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3361. {
  3362. lock (lockObj)
  3363. {
  3364. if (!ProgressState)
  3365. {
  3366. ProgressState = true;
  3367. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3368. }
  3369. }
  3370. }
  3371. }
  3372. catch (Exception ex)
  3373. {
  3374. ProgressState = false;
  3375. string str = ex.StackTrace;
  3376. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3377. }
  3378. #endregion 右边进站
  3379. #region 右边出站
  3380. try
  3381. {
  3382. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3383. {
  3384. lock (lockObj)
  3385. {
  3386. if (!ProgressState)
  3387. {
  3388. ProgressState = true;
  3389. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3390. }
  3391. }
  3392. }
  3393. }
  3394. catch (Exception ex)
  3395. {
  3396. ProgressState = false;
  3397. string str = ex.StackTrace;
  3398. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3399. }
  3400. #endregion 右边出站
  3401. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3402. stopwatch1.Stop();
  3403. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3404. }
  3405. else
  3406. {
  3407. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3408. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3409. FunsEip[plcNo].Connect(); // 重连
  3410. }
  3411. }
  3412. catch (Exception ex)
  3413. {
  3414. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3415. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3416. }
  3417. Thread.Sleep(IntervalReadPLC);
  3418. }
  3419. }
  3420. /// <summary>
  3421. /// [S7] 锁螺丝设备 - 进站
  3422. /// </summary>
  3423. /// <param name="plcNo">PLC编号</param>
  3424. /// <param name="stationNameStr">工站全称</param>
  3425. /// <param name="stPLC_MesData"></param>
  3426. /// <param name="tagMesCommName"></param>
  3427. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3428. {
  3429. Stopwatch stopwatch1 = new Stopwatch();
  3430. Stopwatch stopwatch2 = new Stopwatch();
  3431. string atlasSn=string.Empty;
  3432. try
  3433. {
  3434. stopwatch1.Start();
  3435. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3436. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3437. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3438. string StationId = string.Empty; // 工位ID(可配置)
  3439. if (direction == "Left")
  3440. {
  3441. StationId = GlobalContext.S7_StationId_1;
  3442. }
  3443. if (direction == "Right")
  3444. {
  3445. StationId = GlobalContext.S7_StationId_2;
  3446. }
  3447. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3448. //载具码验证产品码
  3449. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3450. if (string.IsNullOrEmpty(strProductBarcode))
  3451. {
  3452. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3453. }
  3454. sn = strProductBarcode;
  3455. atlasSn= strProductBarcode;
  3456. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3457. if (direction == "Left")
  3458. {
  3459. isCollectingFlagLeft = false;//采集螺丝数据结束
  3460. }
  3461. if (direction == "Right")
  3462. {
  3463. isCollectingFlagRight = false;//采集螺丝数据结束
  3464. }
  3465. // 产品SN(物料码)校验
  3466. List<TestItem> item = new List<TestItem>();
  3467. stopwatch2.Start();
  3468. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3469. stopwatch2.Stop();
  3470. //指令执行结果 1:OK 110:失败
  3471. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3472. //进站结果写入PLC
  3473. CommandFromPLC resultToPlC = new CommandFromPLC();
  3474. resultToPlC.cmd = 0;
  3475. resultToPlC.cmdParam = 0; //指令参数
  3476. resultToPlC.cmdResult = mesResultFrmWeb;
  3477. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3478. }
  3479. catch (Exception ex)
  3480. {
  3481. string str = ex.StackTrace;
  3482. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3483. CommandFromPLC resultToPlC = new CommandFromPLC();
  3484. resultToPlC.cmd = 0;
  3485. resultToPlC.cmdParam = 0; //指令参数
  3486. resultToPlC.cmdResult = 110;
  3487. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3488. }
  3489. stopwatch1.Stop();
  3490. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3491. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3492. ProgressState = false;
  3493. //开始采集螺丝数据
  3494. if (direction == "Left")
  3495. {
  3496. isCollectingFlagLeft = true;
  3497. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3498. }
  3499. if (direction == "Right")
  3500. {
  3501. isCollectingFlagRight = true;
  3502. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3503. }
  3504. }
  3505. /// <summary>
  3506. /// [S7] 锁螺丝设备 - 出站
  3507. /// </summary>
  3508. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3509. {
  3510. Stopwatch stopwatch1 = new Stopwatch();
  3511. Stopwatch stopwatch2 = new Stopwatch();
  3512. try
  3513. {
  3514. stopwatch1.Start();
  3515. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3516. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3517. string processItem = stationName; // 测试项目
  3518. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3519. string supplierCode = ""; // 供应商代码
  3520. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3521. string batch_num = GlobalContext.BatchNumber; // 批次号
  3522. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3523. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3524. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3525. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3526. string StationId = string.Empty; // 工位ID(可配置)
  3527. if (direction == "Left")
  3528. {
  3529. StationId = GlobalContext.S7_StationId_1;
  3530. }
  3531. if (direction == "Right")
  3532. {
  3533. StationId = GlobalContext.S7_StationId_2;
  3534. }
  3535. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3536. a1Result = 1;
  3537. bool pass = a1Result == 1;
  3538. //根据载具码获取产品码
  3539. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3540. if (string.IsNullOrEmpty(strProductBarcode))
  3541. {
  3542. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3543. }
  3544. sn = strProductBarcode;
  3545. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3546. List<TestItem> items = new List<TestItem>();
  3547. items.Add(new TestItem()
  3548. {
  3549. Parameter_name = "载具码",
  3550. Parameter_value = CarrierBarcode,
  3551. Parameter_unit = ""
  3552. });
  3553. items.Add(new TestItem()
  3554. {
  3555. Parameter_name = "产品码",
  3556. Parameter_value = sn,
  3557. Parameter_unit = ""
  3558. });
  3559. int result1 = 1;
  3560. if (direction == "Right")
  3561. {
  3562. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3563. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3564. }
  3565. //if (direction == "Left")
  3566. //{
  3567. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3568. //}
  3569. //if (direction == "Right")
  3570. //{
  3571. // isCollectingFlagRight = false;//采集螺丝数据结束
  3572. //}
  3573. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3574. stopwatch2.Start();
  3575. //进站结果写入PLC
  3576. CommandFromPLC resultToPlC = new CommandFromPLC();
  3577. resultToPlC.cmd = 0;
  3578. resultToPlC.cmdParam = 0; //指令参数
  3579. resultToPlC.cmdResult = mesResultFrmWeb;
  3580. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3581. stopwatch2.Stop();
  3582. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3583. //保存PLC返回MES数据到本地
  3584. ResponseMessage message = new ResponseMessage();
  3585. if (direction == "Left")
  3586. {
  3587. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3588. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3589. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3590. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3591. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3592. if (message.result == false)
  3593. {
  3594. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3595. }
  3596. }
  3597. if (direction == "Right")
  3598. {
  3599. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3600. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3601. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3602. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3603. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3604. if (message.result == false)
  3605. {
  3606. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3607. }
  3608. }
  3609. //保存螺丝数据到txt
  3610. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3611. if (result.Item1 != 0)
  3612. {
  3613. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3614. }
  3615. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3616. }
  3617. catch (Exception ex)
  3618. {
  3619. stopwatch2.Start();
  3620. CommandFromPLC resultToPlC = new CommandFromPLC();
  3621. resultToPlC.cmd = 0;
  3622. resultToPlC.cmdParam = 0; //指令参数
  3623. resultToPlC.cmdResult = 110;
  3624. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3625. stopwatch2.Stop();
  3626. string str = ex.StackTrace;
  3627. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3628. }
  3629. stopwatch1.Stop();
  3630. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3631. ProgressState = false;
  3632. }
  3633. #endregion
  3634. #region S8
  3635. /// <summary>
  3636. /// [S8] 3D螺丝高度检测设备
  3637. /// </summary>
  3638. /// <param name="plcNo">PLC编号</param>
  3639. private void ReadStation_S8(int plcNo)
  3640. {
  3641. string stationCode = "[OP80]";
  3642. string stationName = "NG下料";
  3643. string stationNameStr = stationCode + stationName;
  3644. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3645. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3646. string tagAgvCommName = "agvCommFrmPC";
  3647. string tagBarsetName = "BarcodeSet";
  3648. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3649. (int, string) result;
  3650. while (true)
  3651. {
  3652. try
  3653. {
  3654. if (!GlobalContext._IsCon_Funs1)
  3655. {
  3656. UpdatePLCMonitor(1, plcNo, 0);
  3657. continue;
  3658. }
  3659. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3660. {
  3661. Stopwatch stopwatch1 = new Stopwatch();
  3662. Stopwatch stopwatch2 = new Stopwatch();
  3663. stopwatch1.Start();
  3664. stopwatch2.Start();
  3665. #region 一次性读取所有数据
  3666. // 一次性读取所有数据
  3667. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3668. if (result.Item1 != 0)
  3669. {
  3670. //richTextBox1.AppendText("\n" + strRet);
  3671. }
  3672. else
  3673. {
  3674. //richTextBox1.AppendText("\n" + "读取成功");
  3675. }
  3676. #endregion 一次性读取所有数据
  3677. stopwatch2.Stop();
  3678. #region 进站
  3679. try
  3680. {
  3681. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3682. {
  3683. lock (lockObj)
  3684. {
  3685. if (!ProgressState)
  3686. {
  3687. ProgressState = true;
  3688. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3689. }
  3690. }
  3691. }
  3692. }
  3693. catch (Exception ex)
  3694. {
  3695. ProgressState = false;
  3696. string str = ex.StackTrace;
  3697. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3698. }
  3699. #endregion 进站
  3700. #region 出站
  3701. try
  3702. {
  3703. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3704. {
  3705. lock (lockObj)
  3706. {
  3707. if (!ProgressState)
  3708. {
  3709. ProgressState = true;
  3710. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3711. }
  3712. }
  3713. }
  3714. }
  3715. catch (Exception ex)
  3716. {
  3717. ProgressState = false;
  3718. string str = ex.StackTrace;
  3719. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3720. }
  3721. #endregion 进站
  3722. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3723. stopwatch1.Stop();
  3724. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3725. }
  3726. else
  3727. {
  3728. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3729. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3730. FunsEip[plcNo].Connect(); // 重连
  3731. }
  3732. }
  3733. catch (Exception ex)
  3734. {
  3735. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3736. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3737. }
  3738. Thread.Sleep(IntervalReadPLC);
  3739. }
  3740. }
  3741. /// <summary>
  3742. /// [S8] 3D螺丝高度检测设备 - 进站
  3743. /// </summary>
  3744. /// <param name="plcNo">PLC编号</param>
  3745. /// <param name="stationNameStr">工站全称</param>
  3746. /// <param name="stPLC_MesData"></param>
  3747. /// <param name="tagMesCommName"></param>
  3748. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3749. {
  3750. Stopwatch stopwatch1 = new Stopwatch();
  3751. Stopwatch stopwatch2 = new Stopwatch();
  3752. try
  3753. {
  3754. stopwatch1.Start();
  3755. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3756. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3757. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3758. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3759. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3760. //载具码验证产品码
  3761. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3762. if (string.IsNullOrEmpty(strProductBarcode))
  3763. {
  3764. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3765. }
  3766. sn = strProductBarcode;
  3767. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3768. // 产品SN(物料码)校验
  3769. List<TestItem> item = new List<TestItem>();
  3770. stopwatch2.Start();
  3771. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3772. stopwatch2.Stop();
  3773. //指令执行结果 1:OK 110:失败
  3774. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3775. //进站结果写入PLC
  3776. CommandFromPLC resultToPlC = new CommandFromPLC();
  3777. resultToPlC.cmd = 0;
  3778. resultToPlC.cmdParam = 0; //指令参数
  3779. resultToPlC.cmdResult = mesResultFrmWeb;
  3780. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3781. }
  3782. catch (Exception ex)
  3783. {
  3784. string str = ex.StackTrace;
  3785. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3786. CommandFromPLC resultToPlC = new CommandFromPLC();
  3787. resultToPlC.cmd = 0;
  3788. resultToPlC.cmdParam = 0; //指令参数
  3789. resultToPlC.cmdResult = 110;
  3790. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3791. }
  3792. stopwatch1.Stop();
  3793. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3794. ProgressState = false;
  3795. }
  3796. /// <summary>
  3797. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3798. /// </summary>
  3799. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3800. {
  3801. Stopwatch stopwatch1 = new Stopwatch();
  3802. Stopwatch stopwatch2 = new Stopwatch();
  3803. try
  3804. {
  3805. stopwatch1.Start();
  3806. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3807. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3808. string processItem = stationName; // 测试项目
  3809. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3810. string supplierCode = ""; // 供应商代码
  3811. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3812. string batch_num = GlobalContext.BatchNumber; // 批次号
  3813. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3814. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3815. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3816. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3817. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3818. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3819. bool pass = a1Result == 1;
  3820. //根据载具码获取产品码
  3821. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3822. if (string.IsNullOrEmpty(strProductBarcode))
  3823. {
  3824. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3825. }
  3826. sn = strProductBarcode;
  3827. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3828. List<TestItem> items = new List<TestItem>();
  3829. items.Add(new TestItem()
  3830. {
  3831. Parameter_name = "载具码",
  3832. Parameter_value = CarrierBarcode,
  3833. Parameter_unit = ""
  3834. });
  3835. items.Add(new TestItem()
  3836. {
  3837. Parameter_name = "产品码",
  3838. Parameter_value = sn,
  3839. Parameter_unit = ""
  3840. });
  3841. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3842. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3843. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3844. stopwatch2.Start();
  3845. //进站结果写入PLC
  3846. CommandFromPLC resultToPlC = new CommandFromPLC();
  3847. resultToPlC.cmd = 0;
  3848. resultToPlC.cmdParam = 0; //指令参数
  3849. resultToPlC.cmdResult = mesResultFrmWeb;
  3850. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3851. stopwatch2.Stop();
  3852. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3853. //保存PLC返回MES数据到本地
  3854. ResponseMessage message = new ResponseMessage();
  3855. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3856. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3857. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3858. if (message.result == false)
  3859. {
  3860. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3861. }
  3862. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3863. }
  3864. catch (Exception ex)
  3865. {
  3866. stopwatch2.Start();
  3867. CommandFromPLC resultToPlC = new CommandFromPLC();
  3868. resultToPlC.cmd = 0;
  3869. resultToPlC.cmdParam = 0; //指令参数
  3870. resultToPlC.cmdResult = 110;
  3871. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3872. stopwatch2.Stop();
  3873. string str = ex.StackTrace;
  3874. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3875. }
  3876. stopwatch1.Stop();
  3877. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3878. ProgressState = false;
  3879. }
  3880. #endregion
  3881. #region S9
  3882. /// <summary>
  3883. /// [S9] 下料设备
  3884. /// </summary>
  3885. /// <param name="plcNo">PLC编号</param>
  3886. private void ReadStation_S9(int plcNo)
  3887. {
  3888. string stationCode = "[OP90]";
  3889. string stationName = "半成品下料";
  3890. string stationNameStr = stationCode + stationName;
  3891. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3892. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3893. string tagAgvCommName = "agvCommFrmPC";
  3894. string tagBarsetName = "BarcodeSet";
  3895. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3896. (int, string) result;
  3897. while (true)
  3898. {
  3899. try
  3900. {
  3901. if (!GlobalContext._IsCon_Funs1)
  3902. {
  3903. UpdatePLCMonitor(1, plcNo, 0);
  3904. continue;
  3905. }
  3906. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3907. {
  3908. Stopwatch stopwatch1 = new Stopwatch();
  3909. Stopwatch stopwatch2 = new Stopwatch();
  3910. stopwatch1.Start();
  3911. stopwatch2.Start();
  3912. #region 一次性读取所有数据
  3913. // 一次性读取所有数据
  3914. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3915. if (result.Item1 != 0)
  3916. {
  3917. //richTextBox1.AppendText("\n" + strRet);
  3918. }
  3919. else
  3920. {
  3921. //richTextBox1.AppendText("\n" + "读取成功");
  3922. }
  3923. #endregion 一次性读取所有数据
  3924. stopwatch2.Stop();
  3925. #region 进站
  3926. try
  3927. {
  3928. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3929. {
  3930. lock (lockObj)
  3931. {
  3932. if (!ProgressState)
  3933. {
  3934. ProgressState = true;
  3935. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3936. }
  3937. }
  3938. }
  3939. }
  3940. catch (Exception ex)
  3941. {
  3942. ProgressState = false;
  3943. string str = ex.StackTrace;
  3944. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3945. }
  3946. #endregion 进站
  3947. #region 出站
  3948. try
  3949. {
  3950. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3951. {
  3952. lock (lockObj)
  3953. {
  3954. if (!ProgressState)
  3955. {
  3956. ProgressState = true;
  3957. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3958. }
  3959. }
  3960. }
  3961. }
  3962. catch (Exception ex)
  3963. {
  3964. ProgressState = false;
  3965. string str = ex.StackTrace;
  3966. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3967. }
  3968. #endregion 进站
  3969. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3970. stopwatch1.Stop();
  3971. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3972. }
  3973. else
  3974. {
  3975. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3976. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3977. FunsEip[plcNo].Connect(); // 重连
  3978. }
  3979. }
  3980. catch (Exception ex)
  3981. {
  3982. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3983. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3984. }
  3985. Thread.Sleep(IntervalReadPLC);
  3986. }
  3987. }
  3988. /// <summary>
  3989. /// [S9] 下料设备 - 进站
  3990. /// </summary>
  3991. /// <param name="plcNo">PLC编号</param>
  3992. /// <param name="stationNameStr">工站全称</param>
  3993. /// <param name="stPLC_MesData"></param>
  3994. /// <param name="tagMesCommName"></param>
  3995. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3996. {
  3997. Stopwatch stopwatch1 = new Stopwatch();
  3998. Stopwatch stopwatch2 = new Stopwatch();
  3999. try
  4000. {
  4001. stopwatch1.Start();
  4002. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4003. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4004. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  4005. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  4006. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4007. //载具码验证产品码
  4008. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4009. if (string.IsNullOrEmpty(strProductBarcode))
  4010. {
  4011. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4012. }
  4013. sn = strProductBarcode;
  4014. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4015. // 产品SN(物料码)校验
  4016. List<TestItem> item = new List<TestItem>();
  4017. stopwatch2.Start();
  4018. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  4019. stopwatch2.Stop();
  4020. //指令执行结果 1:OK 110:失败
  4021. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4022. //进站结果写入PLC
  4023. CommandFromPLC resultToPlC = new CommandFromPLC();
  4024. resultToPlC.cmd = 0;
  4025. resultToPlC.cmdParam = 0; //指令参数
  4026. resultToPlC.cmdResult = mesResultFrmWeb;
  4027. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4028. }
  4029. catch (Exception ex)
  4030. {
  4031. string str = ex.StackTrace;
  4032. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4033. CommandFromPLC resultToPlC = new CommandFromPLC();
  4034. resultToPlC.cmd = 0;
  4035. resultToPlC.cmdParam = 0; //指令参数
  4036. resultToPlC.cmdResult = 110;
  4037. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4038. }
  4039. stopwatch1.Stop();
  4040. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4041. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4042. ProgressState = false;
  4043. }
  4044. /// <summary>
  4045. /// [S9] 下料设备 - 出站接口
  4046. /// </summary>
  4047. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  4048. {
  4049. Stopwatch stopwatch1 = new Stopwatch();
  4050. Stopwatch stopwatch2 = new Stopwatch();
  4051. try
  4052. {
  4053. stopwatch1.Start();
  4054. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4055. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4056. string processItem = stationName; // 测试项目
  4057. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4058. string supplierCode = ""; // 供应商代码
  4059. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4060. string batch_num = GlobalContext.BatchNumber; // 批次号
  4061. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4062. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4063. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4064. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  4065. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  4066. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4067. bool pass = a1Result == 1;
  4068. //根据载具码获取产品码
  4069. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4070. if (string.IsNullOrEmpty(strProductBarcode))
  4071. {
  4072. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4073. }
  4074. sn = strProductBarcode;
  4075. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4076. List<TestItem> items = new List<TestItem>();
  4077. items.Add(new TestItem()
  4078. {
  4079. Parameter_name = "载具码",
  4080. Parameter_value = CarrierBarcode,
  4081. Parameter_unit = ""
  4082. });
  4083. items.Add(new TestItem()
  4084. {
  4085. Parameter_name = "产品码",
  4086. Parameter_value = sn,
  4087. Parameter_unit = ""
  4088. });
  4089. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4090. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  4091. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4092. stopwatch2.Start();
  4093. //进站结果写入PLC
  4094. CommandFromPLC resultToPlC = new CommandFromPLC();
  4095. resultToPlC.cmd = 0;
  4096. resultToPlC.cmdParam = 0; //指令参数
  4097. resultToPlC.cmdResult = mesResultFrmWeb;
  4098. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4099. stopwatch2.Stop();
  4100. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4101. //保存PLC返回MES数据到本地
  4102. ResponseMessage message = new ResponseMessage();
  4103. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4104. if (message.result == false)
  4105. {
  4106. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4107. }
  4108. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4109. if (result1 == 1)
  4110. {
  4111. //载具码解除绑定
  4112. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4113. if (message.result == false)
  4114. {
  4115. AddMessage(LogType.Error, message.text);
  4116. }
  4117. }
  4118. }
  4119. catch (Exception ex)
  4120. {
  4121. stopwatch2.Start();
  4122. CommandFromPLC resultToPlC = new CommandFromPLC();
  4123. resultToPlC.cmd = 0;
  4124. resultToPlC.cmdParam = 0; //指令参数
  4125. resultToPlC.cmdResult = 110;
  4126. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4127. stopwatch2.Stop();
  4128. string str = ex.StackTrace;
  4129. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4130. }
  4131. stopwatch1.Stop();
  4132. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4133. ProgressState = false;
  4134. }
  4135. #endregion
  4136. #endregion Xiaomi
  4137. #region PLC1 张超凡
  4138. #region [S1] Tray盘上料装备(板测)
  4139. /// <summary>
  4140. /// S1工位的数据- 触发信号上次的值
  4141. /// </summary>
  4142. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4143. /// <summary>
  4144. /// S1工位的数据(含触发信号)
  4145. /// </summary>
  4146. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4147. /// <summary>
  4148. /// S1工位的数据- 回写点位
  4149. /// </summary>
  4150. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4151. ///// <summary>
  4152. ///// 触发信号
  4153. ///// </summary>
  4154. //private ManualResetEvent[] MreTasks;
  4155. /// <summary>
  4156. /// [S1] Tray盘上料装备(板测)
  4157. /// </summary>
  4158. /// <param name="plcNo">PLC编号</param>
  4159. //private void ReadStation_S1(int plcNo)
  4160. //{
  4161. // // [S1] Tray盘上料装备
  4162. // // [S2] FCT
  4163. // // [S3] 值板机
  4164. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4165. // // [S5] Tray盘下料装备
  4166. // string stationCode = "[S1]";
  4167. // string stationName = "Tray盘上料装备";
  4168. // string stationNameStr = stationCode + stationName;
  4169. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4170. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4171. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4172. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4173. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4174. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4175. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4176. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4177. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4178. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4179. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4180. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4181. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4182. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4183. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4184. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4185. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4186. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4187. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4188. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4189. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4190. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4191. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4192. // s1PLCData.Add("a1Result", 0); // 产品结果
  4193. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4194. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4195. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4196. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4197. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4198. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4199. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4200. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4201. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4202. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4203. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4204. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4205. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4206. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4207. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4208. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4209. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4210. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4211. // while (IsRun)
  4212. // {
  4213. // try
  4214. // {
  4215. // if (!GlobalContext._IsCon_Funs1)
  4216. // {
  4217. // UpdatePLCMonitor(1, plcNo, 0);
  4218. // continue;
  4219. // }
  4220. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4221. // {
  4222. // Stopwatch stopwatch1 = new Stopwatch();
  4223. // Stopwatch stopwatch2 = new Stopwatch();
  4224. // stopwatch1.Start();
  4225. // stopwatch2.Start();
  4226. // #region 一次性读取所有数据
  4227. // // 一次性读取所有数据
  4228. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4229. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4230. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4231. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4232. // int[] datas = data1.Concat(data2).ToArray();
  4233. // datas = datas.Concat(data3).ToArray();
  4234. // datas = datas.Concat(data4).ToArray();
  4235. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4236. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4237. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4238. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4239. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4240. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4241. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4242. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4243. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4244. // s1PLCData["a1MES_FLAG"] = datas[109];
  4245. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4246. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4247. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4248. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4249. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4250. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4251. // s1PLCData["a1Result"] = datas[170];
  4252. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4253. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4254. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4255. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4256. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4257. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4258. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4259. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4260. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4261. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4262. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4263. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4264. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4265. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4266. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4267. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4268. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4269. // s1PLCData["a1AGVUpStart"] = datas[308];
  4270. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4271. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4272. // s1PLCData["a1AGVDownStart"] = datas[321];
  4273. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4274. // #endregion 一次性读取所有数据
  4275. // stopwatch2.Stop();
  4276. // #region 回写操作,写后清空flag
  4277. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4278. // #endregion 回写操作,写后清空flag
  4279. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4280. // try
  4281. // {
  4282. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4283. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4284. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4285. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4286. // {
  4287. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4288. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4289. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4290. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4291. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4292. // }
  4293. // }
  4294. // catch (Exception ex)
  4295. // {
  4296. // // 6代表上位机报警
  4297. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4298. // string str = ex.StackTrace;
  4299. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4300. // }
  4301. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4302. // #region 上料进站校验
  4303. // try
  4304. // {
  4305. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4306. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4307. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4308. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4309. // {
  4310. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4311. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4312. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4313. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4314. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4315. // }
  4316. // }
  4317. // catch (Exception ex)
  4318. // {
  4319. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4320. // string str = ex.StackTrace;
  4321. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4322. // }
  4323. // #endregion 上料进站校验
  4324. // #region Tray盘上料装备-出站接口
  4325. // try
  4326. // {
  4327. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4328. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4329. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4330. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4331. // {
  4332. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4333. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4334. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4335. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4336. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4337. // }
  4338. // }
  4339. // catch (Exception ex)
  4340. // {
  4341. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4342. // string str = ex.StackTrace;
  4343. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4344. // }
  4345. // #endregion Tray盘上料装备-出站接口
  4346. // #region Tray盘上料装备-将SN发给ICT标机
  4347. // try
  4348. // {
  4349. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4350. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4351. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4352. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4353. // {
  4354. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4355. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4356. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4357. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4358. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4359. // }
  4360. // }
  4361. // catch (Exception ex)
  4362. // {
  4363. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4364. // string str = ex.StackTrace;
  4365. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4366. // }
  4367. // #endregion Tray盘上料装备-将SN发给ICT标机
  4368. // #region Tray盘上料装备-点检数据
  4369. // //try
  4370. // //{
  4371. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4372. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4373. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4374. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4375. // // if (pLC_Flag && !mES_Flag) // 1 0
  4376. // // {
  4377. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4378. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4379. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4380. // // }
  4381. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4382. // // {
  4383. // // // 清空写给PLC的数据
  4384. // // // MES_Flag重置为0
  4385. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4386. // // }
  4387. // //}
  4388. // //catch (Exception ex)
  4389. // //{
  4390. // // // MES_Flag 为2上位机报错
  4391. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4392. // // string str = ex.StackTrace;
  4393. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4394. // //}
  4395. // #endregion Tray盘上料装备-点检数据
  4396. // #region 节拍接口
  4397. // try
  4398. // {
  4399. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4400. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4401. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4402. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4403. // {
  4404. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4405. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4406. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4407. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4408. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4409. // }
  4410. // }
  4411. // catch (Exception ex)
  4412. // {
  4413. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4414. // string str = ex.StackTrace;
  4415. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4416. // }
  4417. // #endregion 节拍接口
  4418. // #region AGV上料
  4419. // // AGV上料叫AGV信号
  4420. // try
  4421. // {
  4422. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4423. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4424. // if (a1AGVUpCall != a1AGVUpCallOld)
  4425. // {
  4426. // if (a1AGVUpCall == 1) // 0->1
  4427. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4428. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4429. // }
  4430. // }
  4431. // catch (Exception ex)
  4432. // {
  4433. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4434. // string str = ex.StackTrace;
  4435. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4436. // }
  4437. // // AGV上料完成信号
  4438. // try
  4439. // {
  4440. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4441. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4442. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4443. // {
  4444. // if (a1AGVUpEnd == 1) // 0->1
  4445. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4446. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4447. // }
  4448. // }
  4449. // catch (Exception ex)
  4450. // {
  4451. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4452. // string str = ex.StackTrace;
  4453. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4454. // }
  4455. // #endregion AGV上料
  4456. // #region AGV下料
  4457. // // AGV下料叫agv信号
  4458. // try
  4459. // {
  4460. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4461. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4462. // if (a1AGVDownCall != a1AGVDownCallOld)
  4463. // {
  4464. // if (a1AGVDownCall == 1) // 0->1
  4465. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4466. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4467. // }
  4468. // }
  4469. // catch (Exception ex)
  4470. // {
  4471. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4472. // string str = ex.StackTrace;
  4473. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4474. // }
  4475. // // AGV下料完成信号
  4476. // try
  4477. // {
  4478. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4479. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4480. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4481. // {
  4482. // if (a1AGVDownEnd == 1) // 0->1
  4483. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4484. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4485. // }
  4486. // }
  4487. // catch (Exception ex)
  4488. // {
  4489. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4490. // string str = ex.StackTrace;
  4491. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4492. // }
  4493. // #endregion AGV下料
  4494. // #region 心跳
  4495. // try
  4496. // {
  4497. // short states = 0;
  4498. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4499. // }
  4500. // catch (Exception ex)
  4501. // {
  4502. // string str = ex.StackTrace;
  4503. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4504. // }
  4505. // #endregion 心跳
  4506. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4507. // stopwatch1.Stop();
  4508. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4509. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4510. // }
  4511. // else
  4512. // {
  4513. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4514. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4515. // Funs[plcNo].Connect(); // 重连
  4516. // }
  4517. // }
  4518. // catch (Exception ex)
  4519. // {
  4520. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4521. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4522. // Funs[plcNo].ReConnect();
  4523. // }
  4524. // Thread.Sleep(IntervalReadPLC);
  4525. // }
  4526. //}
  4527. /// <summary>
  4528. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4529. /// </summary>
  4530. /// <param name="plcNo">PLC编号</param>
  4531. /// <param name="stationNameStr">工站全称</param>
  4532. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4533. {
  4534. Stopwatch stopwatch1 = new Stopwatch();
  4535. Stopwatch stopwatch2 = new Stopwatch();
  4536. try
  4537. {
  4538. stopwatch1.Start();
  4539. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4540. sn = sn.Replace("\0", "");
  4541. #region 查询载具上的产品信息
  4542. string cavityData = string.Empty;
  4543. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4544. if (string.IsNullOrEmpty(cavityData))
  4545. cavityData = "";
  4546. if (snResult != 0)
  4547. {
  4548. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4549. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4550. writeToPLC_Flag1.Adress = 2003;
  4551. writeToPLC_Flag1.Value = (short)6;
  4552. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4553. stopwatch1.Stop();
  4554. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4555. return;
  4556. }
  4557. #endregion 查询载具上的产品信息
  4558. string[] cavitySNs = cavityData.Split('.');
  4559. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4560. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4561. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4562. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4563. if (cavitySNs != null && cavitySNs.Length >= 2)
  4564. {
  4565. a1CavitySN1_VehicleStates = cavitySNs[0];
  4566. a1CavitySN2_VehicleStates = cavitySNs[1];
  4567. a1CavityResult1_VehicleStates = 2;
  4568. a1CavityResult2_VehicleStates = 2;
  4569. }
  4570. if (a1CavitySN1_VehicleStates == "假产品")
  4571. a1CavityResult1_VehicleStates = 3;
  4572. if (a1CavitySN2_VehicleStates == "假产品")
  4573. a1CavityResult2_VehicleStates = 3;
  4574. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4575. // 回写
  4576. stopwatch2.Start();
  4577. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4578. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4579. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4580. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4581. //// MES_Flag
  4582. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4583. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4584. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4585. writeToPLC_Flag.Adress = 2003;
  4586. writeToPLC_Flag.Value = mES_Flag;
  4587. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4588. {
  4589. Name = "a1CavitySN1_VehicleStates",
  4590. Adress = 2024,
  4591. ValueType = PLCValueType.String,
  4592. ValueTypeStrLength = 20,
  4593. Value = a1CavitySN1_VehicleStates
  4594. });
  4595. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4596. {
  4597. Name = "a1CavitySN2_VehicleStates",
  4598. Adress = 2044,
  4599. ValueType = PLCValueType.String,
  4600. ValueTypeStrLength = 20,
  4601. Value = a1CavitySN2_VehicleStates
  4602. });
  4603. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4604. {
  4605. Name = "a1CavityResult1_VehicleStates",
  4606. Adress = 2064,
  4607. ValueType = PLCValueType.Short,
  4608. Value = a1CavityResult1_VehicleStates
  4609. });
  4610. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4611. {
  4612. Name = "a1CavityResult2_VehicleStates",
  4613. Adress = 2065,
  4614. ValueType = PLCValueType.Short,
  4615. Value = a1CavityResult2_VehicleStates
  4616. });
  4617. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4618. stopwatch2.Stop();
  4619. }
  4620. catch (Exception ex)
  4621. {
  4622. string str = ex.StackTrace;
  4623. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4624. // MES_Flag
  4625. stopwatch2.Start();
  4626. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4627. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4628. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4629. writeToPLC_Flag.Adress = 2003;
  4630. writeToPLC_Flag.Value = (short)6;
  4631. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4632. stopwatch2.Stop();
  4633. }
  4634. stopwatch1.Stop();
  4635. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4636. }
  4637. /// <summary>
  4638. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4639. /// </summary>
  4640. /// <param name="plcNo">PLC编号</param>
  4641. /// <param name="stationNameStr">工站全称</param>
  4642. private void S1上料进站校验(int plcNo, string stationNameStr)
  4643. {
  4644. Stopwatch stopwatch1 = new Stopwatch();
  4645. Stopwatch stopwatch2 = new Stopwatch();
  4646. try
  4647. {
  4648. stopwatch1.Start();
  4649. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4650. sn = sn.Replace("\0", "");
  4651. // 保存进站数据+调用进站MES接口
  4652. List<TestItem> item = new List<TestItem>();
  4653. stopwatch2.Start();
  4654. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4655. stopwatch2.Stop();
  4656. short a1MES_FLAG_Check = (short)result;
  4657. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4658. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4659. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4660. writeToPLC_Flag.Adress = 2077;
  4661. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4662. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4663. }
  4664. catch (Exception ex)
  4665. {
  4666. string str = ex.StackTrace;
  4667. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4668. // MES_Flag
  4669. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4670. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4671. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4672. writeToPLC_Flag.Adress = 2077;
  4673. writeToPLC_Flag.Value = (short)6;
  4674. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4675. }
  4676. stopwatch1.Stop();
  4677. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4678. }
  4679. /// <summary>
  4680. /// [S1] Tray盘上料装备(板测)- 出站接口
  4681. /// </summary>
  4682. /// <param name="plcNo"></param>
  4683. /// <param name="stationCode"></param>
  4684. /// <param name="stationName"></param>
  4685. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4686. {
  4687. Stopwatch stopwatch1 = new Stopwatch();
  4688. Stopwatch stopwatch2 = new Stopwatch();
  4689. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4690. string stationNameStr = stationCode + stationName;
  4691. string processItem = stationName; // 测试项目
  4692. try
  4693. {
  4694. stopwatch1.Start();
  4695. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4696. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4697. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4698. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4699. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4700. sn = sn.Replace("\0", "");
  4701. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4702. partNo1 = partNo1.Replace("\0", "");
  4703. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4704. partNo2 = partNo2.Replace("\0", "");
  4705. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4706. bool pass = a1Result == 1;
  4707. stopwatch2.Start();
  4708. // 产品1
  4709. List<TestItem> items = new List<TestItem>();
  4710. items.Add(new TestItem()
  4711. {
  4712. Parameter_name = "载具码",
  4713. Parameter_value = sn,
  4714. Parameter_unit = ""
  4715. });
  4716. items.Add(new TestItem()
  4717. {
  4718. Parameter_name = "载具穴号",
  4719. Parameter_value = "1",
  4720. Parameter_unit = ""
  4721. });
  4722. items.Add(new TestItem()
  4723. {
  4724. Parameter_name = "产品结果",
  4725. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4726. Parameter_unit = ""
  4727. });
  4728. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4729. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4730. // 产品2
  4731. items = new List<TestItem>();
  4732. items.Add(new TestItem()
  4733. {
  4734. Parameter_name = "载具码",
  4735. Parameter_value = sn,
  4736. Parameter_unit = ""
  4737. });
  4738. items.Add(new TestItem()
  4739. {
  4740. Parameter_name = "载具穴号",
  4741. Parameter_value = "2",
  4742. Parameter_unit = ""
  4743. });
  4744. items.Add(new TestItem()
  4745. {
  4746. Parameter_name = "产品结果",
  4747. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4748. Parameter_unit = ""
  4749. });
  4750. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4751. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4752. short result = 0;
  4753. List<int> results = new List<int>() { result1, result2 };
  4754. if (result1 == 1 && result2 == 1)
  4755. result = 1;
  4756. else if (results.Contains(3))
  4757. result = 3;
  4758. else if (results.Contains(2))
  4759. result = 2;
  4760. else if (results.Contains(4))
  4761. result = 4;
  4762. else
  4763. result = 4;
  4764. stopwatch2.Stop();
  4765. #region 存储绑定数据到 边线MES系统中
  4766. if (result == 1)
  4767. {
  4768. string data = string.Concat(partNo1, ".", partNo2);
  4769. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4770. if (resultMesR != 0)
  4771. {
  4772. result = 4;
  4773. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4774. }
  4775. }
  4776. #endregion 存储绑定数据到 边线MES系统中
  4777. // MES_Flag 为MES报错
  4778. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4779. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4780. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4781. writeToPLC_Flag.Name = "a1MES_FLAG";
  4782. writeToPLC_Flag.Adress = 2109;
  4783. writeToPLC_Flag.Value = result;
  4784. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4785. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4786. }
  4787. catch (Exception ex)
  4788. {
  4789. stopwatch2.Restart();
  4790. // MES_Flag 为4上位机报错
  4791. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4792. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4793. writeToPLC_Flag.Name = "a1MES_FLAG";
  4794. writeToPLC_Flag.Adress = 2109;
  4795. writeToPLC_Flag.Value = (short)4;
  4796. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4797. stopwatch2.Stop();
  4798. string str = ex.StackTrace;
  4799. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4800. }
  4801. stopwatch1.Stop();
  4802. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4803. }
  4804. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4805. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4806. //{
  4807. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4808. // string stationNameStr = stationCode + stationName;
  4809. // string processItem = stationName; // 测试项目
  4810. // try
  4811. // {
  4812. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4813. // string accno = "1"; // 工序编号
  4814. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4815. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4816. // List<OneCheckItem> items = new List<OneCheckItem>()
  4817. // {
  4818. // new OneCheckItem()
  4819. // {
  4820. // Onecheck_name="胶圈装配行程设定上限",
  4821. // Onecheck_content="上限值",
  4822. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4823. // },
  4824. // };
  4825. // OneCheckData oneCheckData = new OneCheckData()
  4826. // {
  4827. // Line_code = GlobalContext.LineCode,
  4828. // Line_name = GlobalContext.LineName,
  4829. // Equipment_code = equipmentCode,
  4830. // Equipment_name = equipmentCode,
  4831. // Workorder_code = workorder_code,
  4832. // Procedure_code = accno,
  4833. // Procedure_name = processItem,
  4834. // Oneckeck_values = items,
  4835. // Onecheck_empcode = "",
  4836. // Onecheck_empname = "",
  4837. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4838. // };
  4839. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4840. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4841. // short result = result1 == 1 ? (short)1 : (short)2;
  4842. // // MES_Flag 为4MES报错
  4843. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4844. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4845. // }
  4846. // catch (Exception ex)
  4847. // {
  4848. // // MES_Flag 为2上位机报错
  4849. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4850. // string str = ex.StackTrace;
  4851. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4852. // }
  4853. //}
  4854. // ReadStation_S1_2 节拍接口+AGV
  4855. /// <summary>
  4856. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4857. /// </summary>
  4858. /// <param name="plcNo">PLC编号</param>
  4859. /// <param name="stationNameStr">工站全称</param>
  4860. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4861. {
  4862. Stopwatch stopwatch1 = new Stopwatch();
  4863. Stopwatch stopwatch2 = new Stopwatch();
  4864. try
  4865. {
  4866. stopwatch1.Start();
  4867. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4868. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4869. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4870. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4871. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4872. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4873. // ZS 将SN发给ICT标机(串口)
  4874. short a1MES_FLAG_ICT = 1;
  4875. stopwatch2.Start();
  4876. // MES_Flag
  4877. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4878. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4879. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4880. writeToPLC_Flag.Adress = 2182;
  4881. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4882. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4883. stopwatch2.Stop();
  4884. }
  4885. catch (Exception ex)
  4886. {
  4887. string str = ex.StackTrace;
  4888. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4889. stopwatch2.Start();
  4890. // MES_Flag
  4891. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4892. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4893. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4894. writeToPLC_Flag.Adress = 2182;
  4895. writeToPLC_Flag.Value = (short)4;
  4896. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4897. stopwatch2.Stop();
  4898. }
  4899. stopwatch1.Stop();
  4900. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4901. }
  4902. /// <summary>
  4903. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4904. /// </summary>
  4905. /// <param name="plcNo">PLC编号</param>
  4906. /// <param name="stationNameStr">工站全称</param>
  4907. private void S1节拍接口(int plcNo, string stationNameStr)
  4908. {
  4909. Stopwatch stopwatch1 = new Stopwatch();
  4910. Stopwatch stopwatch2 = new Stopwatch();
  4911. string resultStr = string.Empty;
  4912. try
  4913. {
  4914. stopwatch1.Start();
  4915. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4916. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4917. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4918. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4919. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4920. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4921. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  4922. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4923. if (!actionBool)
  4924. {
  4925. stopwatch2.Start();
  4926. // MES_Flag
  4927. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4928. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4929. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  4930. writeToPLC_Flag1.Adress = 2254;
  4931. writeToPLC_Flag1.Value = (short)1;
  4932. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  4933. stopwatch2.Stop();
  4934. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4935. return;
  4936. }
  4937. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  4938. {
  4939. stopwatch2.Start();
  4940. // MES_Flag
  4941. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4942. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  4943. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  4944. writeToPLC_Flag2.Adress = 2254;
  4945. writeToPLC_Flag2.Value = (short)1;
  4946. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  4947. stopwatch2.Stop();
  4948. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4949. return;
  4950. }
  4951. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  4952. { // 查产品SN
  4953. a1OEEPartNo = "Test"; // ZS
  4954. }
  4955. short a1OEEMES_FLAG = 0;
  4956. // 上传OEE
  4957. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  4958. a1OEEMES_FLAG = result.Item1;
  4959. resultStr = result.Item2;
  4960. stopwatch2.Start();
  4961. // MES_Flag
  4962. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4963. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4964. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4965. writeToPLC_Flag.Adress = 2254;
  4966. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  4967. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4968. stopwatch2.Stop();
  4969. }
  4970. catch (Exception ex)
  4971. {
  4972. string str = ex.StackTrace;
  4973. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4974. // MES_Flag
  4975. stopwatch2.Start();
  4976. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4977. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4978. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4979. writeToPLC_Flag.Adress = 2254;
  4980. writeToPLC_Flag.Value = (short)4;
  4981. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4982. stopwatch2.Stop();
  4983. }
  4984. stopwatch1.Stop();
  4985. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4986. }
  4987. /// <summary>
  4988. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  4989. /// </summary>
  4990. /// <param name="plcNo">PLC编号</param>
  4991. /// <param name="stationNameStr">工站全称</param>
  4992. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  4993. {
  4994. Stopwatch stopwatch1 = new Stopwatch();
  4995. Stopwatch stopwatch2 = new Stopwatch();
  4996. try
  4997. {
  4998. stopwatch1.Start();
  4999. // ZS 呼叫AGV
  5000. short a1AGVUpCall = 2;
  5001. stopwatch2.Start();
  5002. // a1AGVUpCall
  5003. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5004. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5005. writeToPLC_Flag.Name = "a1AGVUpCall";
  5006. writeToPLC_Flag.Adress = 2307;
  5007. writeToPLC_Flag.Value = a1AGVUpCall;
  5008. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5009. stopwatch2.Stop();
  5010. }
  5011. catch (Exception ex)
  5012. {
  5013. string str = ex.StackTrace;
  5014. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5015. // a1AGVUpCall
  5016. stopwatch2.Start();
  5017. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  5018. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5019. writeToPLC_Flag.Name = "a1AGVUpCall";
  5020. writeToPLC_Flag.Adress = 2307;
  5021. writeToPLC_Flag.Value = (short)4;
  5022. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5023. stopwatch2.Stop();
  5024. }
  5025. stopwatch1.Stop();
  5026. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5027. }
  5028. /// <summary>
  5029. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  5030. /// </summary>
  5031. /// <param name="plcNo">PLC编号</param>
  5032. /// <param name="stationNameStr">工站全称</param>
  5033. private void S1AGV上料完成(int plcNo, string stationNameStr)
  5034. {
  5035. Stopwatch stopwatch1 = new Stopwatch();
  5036. Stopwatch stopwatch2 = new Stopwatch();
  5037. try
  5038. {
  5039. stopwatch1.Start();
  5040. // ZS AGV上料完成,让小车离开
  5041. short a1AGVUpEnd = 2;
  5042. stopwatch2.Start();
  5043. // a1AGVUpEnd
  5044. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5045. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5046. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5047. writeToPLC_Flag.Adress = 2309;
  5048. writeToPLC_Flag.Value = a1AGVUpEnd;
  5049. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5050. stopwatch2.Stop();
  5051. }
  5052. catch (Exception ex)
  5053. {
  5054. string str = ex.StackTrace;
  5055. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5056. // a1AGVUpEnd
  5057. stopwatch2.Start();
  5058. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  5059. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5060. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5061. writeToPLC_Flag.Adress = 2309;
  5062. writeToPLC_Flag.Value = (short)4;
  5063. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5064. stopwatch2.Stop();
  5065. }
  5066. stopwatch1.Stop();
  5067. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5068. }
  5069. /// <summary>
  5070. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  5071. /// </summary>
  5072. /// <param name="plcNo">PLC编号</param>
  5073. /// <param name="stationNameStr">工站全称</param>
  5074. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  5075. {
  5076. Stopwatch stopwatch1 = new Stopwatch();
  5077. Stopwatch stopwatch2 = new Stopwatch();
  5078. try
  5079. {
  5080. stopwatch1.Start();
  5081. // ZS 呼叫AGV
  5082. short a1AGVDownCall = 2;
  5083. stopwatch2.Start();
  5084. // a1AGVDownCall
  5085. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5086. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5087. writeToPLC_Flag.Name = "a1AGVDownCall";
  5088. writeToPLC_Flag.Adress = 2320;
  5089. writeToPLC_Flag.Value = a1AGVDownCall;
  5090. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5091. stopwatch2.Stop();
  5092. }
  5093. catch (Exception ex)
  5094. {
  5095. string str = ex.StackTrace;
  5096. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5097. // a1AGVDownCall
  5098. stopwatch2.Start();
  5099. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5100. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5101. writeToPLC_Flag.Name = "a1AGVDownCall";
  5102. writeToPLC_Flag.Adress = 2320;
  5103. writeToPLC_Flag.Value = (short)4;
  5104. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5105. stopwatch2.Stop();
  5106. }
  5107. stopwatch1.Stop();
  5108. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5109. }
  5110. /// <summary>
  5111. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5112. /// </summary>
  5113. /// <param name="plcNo">PLC编号</param>
  5114. /// <param name="stationNameStr">工站全称</param>
  5115. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5116. {
  5117. Stopwatch stopwatch1 = new Stopwatch();
  5118. Stopwatch stopwatch2 = new Stopwatch();
  5119. try
  5120. {
  5121. stopwatch1.Start();
  5122. // ZS AGV上料完成,让小车离开
  5123. short a1AGVDownEnd = 2;
  5124. stopwatch2.Start();
  5125. // a1AGVDownEnd
  5126. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5127. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5128. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5129. writeToPLC_Flag.Adress = 2322;
  5130. writeToPLC_Flag.Value = a1AGVDownEnd;
  5131. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5132. stopwatch2.Stop();
  5133. }
  5134. catch (Exception ex)
  5135. {
  5136. string str = ex.StackTrace;
  5137. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5138. // a1AGVDownEnd
  5139. stopwatch2.Start();
  5140. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5141. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5142. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5143. writeToPLC_Flag.Adress = 2322;
  5144. writeToPLC_Flag.Value = (short)4;
  5145. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5146. stopwatch2.Stop();
  5147. }
  5148. stopwatch1.Stop();
  5149. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5150. }
  5151. #endregion [S1] Tray盘上料装备(板测)
  5152. #endregion PLC1 张超凡
  5153. #region PLC2 李晓奇
  5154. #region [S2] FCT(板测)
  5155. /// <summary>
  5156. /// S2工位的数据- 触发信号上次的值
  5157. /// </summary>
  5158. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5159. /// <summary>
  5160. /// S2工位的数据(含触发信号)
  5161. /// </summary>
  5162. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5163. /// <summary>
  5164. /// S2工位的数据- 回写点位
  5165. /// </summary>
  5166. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5167. /// <summary>
  5168. /// [S2] FCT(板测)
  5169. /// </summary>
  5170. /// <param name="plcNo">PLC编号</param>
  5171. //private void ReadStation_S2(int plcNo)
  5172. //{
  5173. // // [S1] Tray盘上料装备
  5174. // // [S2] FCT
  5175. // // [S3] 值板机
  5176. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5177. // // [S5] Tray盘下料装备
  5178. // /// 上位机心跳
  5179. // /// 获取设备报警数据与状态信息
  5180. // string stationCode = "[S2]";
  5181. // string stationName = "FCT";
  5182. // string stationNameStr = stationCode + stationName;
  5183. // #region 创建字典
  5184. // // 触发信号字典 赋值
  5185. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5186. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5187. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5188. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5189. // // PLC数据字典 赋值
  5190. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5191. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5192. // s2PLCData.Add("b1ProductSN_Check", 0);
  5193. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5194. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5195. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5196. // s2PLCData.Add("b1ProductSN_Bind", "");
  5197. // s2PLCData.Add("b1Part1SN_Bind", "");
  5198. // s2PLCData.Add("b1Part2SN_Bind", "");
  5199. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5200. // s2PLCData.Add("b1MES_FLAG", 0);
  5201. // s2PLCData.Add("b1ProductSN", 0);
  5202. // s2PLCData.Add("b1Part1Result", 0);
  5203. // s2PLCData.Add("b1Part2Result", 0);
  5204. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5205. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5206. // s2PLCData.Add("b1OEEProductSN", "");
  5207. // s2PLCData.Add("b1OEEType", 0);
  5208. // #endregion 创建字典
  5209. // while (IsRun)
  5210. // {
  5211. // try
  5212. // {
  5213. // if (!GlobalContext._IsCon_Funs2)
  5214. // {
  5215. // UpdatePLCMonitor(1, plcNo, 0);
  5216. // continue;
  5217. // }
  5218. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5219. // {
  5220. // Stopwatch stopwatch1 = new Stopwatch();
  5221. // Stopwatch stopwatch2 = new Stopwatch();
  5222. // stopwatch1.Start();
  5223. // stopwatch2.Start();
  5224. // #region 一次性读取所有数据
  5225. // // 一次性读取所有数据
  5226. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5227. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5228. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5229. // int[] datas = data1.Concat(data2).ToArray();
  5230. // datas = datas.Concat(data3).ToArray();
  5231. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5232. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5233. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5234. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5235. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5236. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5237. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5238. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5239. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5240. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5241. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5242. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5243. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5244. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5245. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5246. // s2PLCData["b1MES_FLAG"] = datas[169];
  5247. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5248. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5249. // s2PLCData["b1Part1Result"] = datas[190];
  5250. // s2PLCData["b1Part2Result"] = datas[191];
  5251. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5252. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5253. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5254. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5255. // s2PLCData["b1OEEType"] = datas[224];
  5256. // #endregion 一次性读取所有数据
  5257. // stopwatch2.Stop();
  5258. // #region 回写操作,写后清空flag
  5259. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5260. // #endregion 回写操作,写后清空flag
  5261. // #region 进站校验
  5262. // try
  5263. // {
  5264. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5265. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5266. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5267. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5268. // {
  5269. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5270. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5271. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5272. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5273. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5274. // }
  5275. // }
  5276. // catch (Exception ex)
  5277. // {
  5278. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5279. // string str = ex.StackTrace;
  5280. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5281. // }
  5282. // #endregion 进站校验
  5283. // #region 二穴载具解绑/绑定(产品换载具)
  5284. // try
  5285. // {
  5286. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5287. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5288. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5289. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5290. // {
  5291. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5292. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5293. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5294. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5295. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5296. // }
  5297. // }
  5298. // catch (Exception ex)
  5299. // {
  5300. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5301. // string str = ex.StackTrace;
  5302. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5303. // }
  5304. // #endregion 二穴载具解绑/绑定(产品换载具)
  5305. // #region FCT-出站接口
  5306. // try
  5307. // {
  5308. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5309. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5310. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5311. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5312. // {
  5313. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5314. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5315. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5316. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5317. // }
  5318. // }
  5319. // catch (Exception ex)
  5320. // {
  5321. // // MES_Flag 为6上位机报错
  5322. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5323. // string str = ex.StackTrace;
  5324. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5325. // }
  5326. // #endregion FCT-出站接口
  5327. // #region 节拍接口
  5328. // try
  5329. // {
  5330. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5331. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5332. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5333. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5334. // {
  5335. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5336. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5337. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5338. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5339. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5340. // }
  5341. // }
  5342. // catch (Exception ex)
  5343. // {
  5344. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5345. // string str = ex.StackTrace;
  5346. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5347. // }
  5348. // #endregion 节拍接口
  5349. // #region 心跳
  5350. // try
  5351. // {
  5352. // short states = 0;
  5353. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5354. // }
  5355. // catch (Exception ex)
  5356. // {
  5357. // string str = ex.StackTrace;
  5358. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5359. // }
  5360. // #endregion 心跳
  5361. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5362. // stopwatch1.Stop();
  5363. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5364. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5365. // }
  5366. // else
  5367. // {
  5368. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5369. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5370. // Funs[plcNo].Connect();
  5371. // }
  5372. // }
  5373. // catch (Exception ex)
  5374. // {
  5375. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5376. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5377. // Funs[plcNo].ReConnect();
  5378. // }
  5379. // Thread.Sleep(IntervalReadPLC);
  5380. // }
  5381. //}
  5382. /// <summary>
  5383. /// [S2] FCT(板测)- 进站校验
  5384. /// </summary>
  5385. /// <param name="plcNo">PLC编号</param>
  5386. /// <param name="stationNameStr">工站全称</param>
  5387. private void S2进站校验(int plcNo, string stationNameStr)
  5388. {
  5389. Stopwatch stopwatch1 = new Stopwatch();
  5390. Stopwatch stopwatch2 = new Stopwatch();
  5391. try
  5392. {
  5393. stopwatch1.Start();
  5394. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5395. sn = sn.Replace("\0", "");
  5396. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5397. // 查询物料码By载具码 并判断是不是假产品
  5398. string cavityData = string.Empty;
  5399. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5400. if (string.IsNullOrEmpty(cavityData))
  5401. cavityData = "";
  5402. if (snResult != 0)
  5403. {
  5404. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5405. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5406. writeToPLC_Flag1.Adress = 2003;
  5407. writeToPLC_Flag1.Value = (short)6;
  5408. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5409. stopwatch1.Stop();
  5410. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5411. return;
  5412. }
  5413. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5414. string[] cavitySNs = cavityData.Split('.');
  5415. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5416. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5417. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5418. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5419. if (cavitySNs != null && cavitySNs.Length >= 2)
  5420. {
  5421. b1Part1SN_Check = cavitySNs[0];
  5422. b1Part2SN_Check = cavitySNs[1];
  5423. b1Part1Result_Check = 2;
  5424. b1Part2Result_Check = 2;
  5425. }
  5426. if (b1Part1SN_Check == "假产品")
  5427. b1Part1Result_Check = 3;
  5428. if (b1Part2SN_Check == "假产品")
  5429. b1Part2Result_Check = 3;
  5430. // 调用MES进站
  5431. stopwatch2.Start();
  5432. // 调用MES进站 - 产品1
  5433. List<TestItem> item;
  5434. int result1 = b1Part1Result_Check;
  5435. if (result1 != 3)
  5436. {
  5437. item = new List<TestItem>();
  5438. item.Add(new TestItem()
  5439. {
  5440. Parameter_name = "载具码",
  5441. Parameter_value = sn,
  5442. });
  5443. item.Add(new TestItem()
  5444. {
  5445. Parameter_name = "载具穴号",
  5446. Parameter_value = "1",
  5447. });
  5448. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5449. }
  5450. // 调用MES进站 - 产品2
  5451. int result2 = b1Part2Result_Check;
  5452. if (result2 != 3)
  5453. {
  5454. item = new List<TestItem>();
  5455. item.Add(new TestItem()
  5456. {
  5457. Parameter_name = "载具码",
  5458. Parameter_value = sn,
  5459. });
  5460. item.Add(new TestItem()
  5461. {
  5462. Parameter_name = "载具穴号",
  5463. Parameter_value = "2",
  5464. });
  5465. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5466. }
  5467. stopwatch2.Stop();
  5468. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5469. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5470. int result = result1;
  5471. if (result == 1)
  5472. result = result2;
  5473. short b1MES_FLAG_Check = (short)result;
  5474. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5475. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5476. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5477. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5478. //// MES_Flag
  5479. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5480. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5481. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5482. writeToPLC_Flag.Adress = 2003;
  5483. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5484. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5485. {
  5486. Name = "b1Part1SN_Check",
  5487. Adress = 2024,
  5488. ValueType = PLCValueType.String,
  5489. ValueTypeStrLength = 20,
  5490. Value = b1Part1SN_Check
  5491. });
  5492. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5493. {
  5494. Name = "b1Part2SN_Check",
  5495. Adress = 2044,
  5496. ValueType = PLCValueType.String,
  5497. ValueTypeStrLength = 20,
  5498. Value = b1Part2SN_Check
  5499. });
  5500. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5501. {
  5502. Name = "b1Part1Result_Check",
  5503. Adress = 2064,
  5504. ValueType = PLCValueType.Short,
  5505. Value = b1Part1Result_Check
  5506. });
  5507. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5508. {
  5509. Name = "b1Part2Result_Check",
  5510. Adress = 2065,
  5511. ValueType = PLCValueType.Short,
  5512. Value = b1Part2Result_Check
  5513. });
  5514. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", 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. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5522. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5523. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5524. writeToPLC_Flag.Adress = 2003;
  5525. writeToPLC_Flag.Value = (short)6;
  5526. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5527. }
  5528. stopwatch1.Stop();
  5529. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5530. }
  5531. /// <summary>
  5532. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5533. /// </summary>
  5534. /// <param name="plcNo">PLC编号</param>
  5535. /// <param name="stationNameStr">工站全称</param>
  5536. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5537. {
  5538. Stopwatch stopwatch1 = new Stopwatch();
  5539. Stopwatch stopwatch2 = new Stopwatch();
  5540. try
  5541. {
  5542. stopwatch1.Start();
  5543. // 产品换载具
  5544. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5545. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5546. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5547. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5548. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5549. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5550. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5551. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5552. stopwatch2.Start();
  5553. #region 查询载具上的产品信息
  5554. //string cavityData = string.Empty;
  5555. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5556. //if (string.IsNullOrEmpty(cavityData))
  5557. // cavityData = "";
  5558. //if (snResult != 0)
  5559. //{
  5560. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5561. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5562. // writeToPLC_Flag.Adress = 2077;
  5563. // writeToPLC_Flag.Value = (short)6;
  5564. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5565. // stopwatch1.Stop();
  5566. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5567. // return;
  5568. //}
  5569. #endregion 查询载具上的产品信息
  5570. #region 解绑(边线MES系统)
  5571. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5572. if (snResult != 0)
  5573. {
  5574. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5575. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5576. writeToPLC_Flag1.Adress = 2077;
  5577. writeToPLC_Flag1.Value = (short)6;
  5578. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5579. stopwatch1.Stop();
  5580. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5581. return;
  5582. }
  5583. #endregion 解绑(边线MES系统)
  5584. #region 存储绑定数据到 边线MES系统中
  5585. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5586. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5587. if (snResult != 0)
  5588. {
  5589. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5590. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5591. writeToPLC_Flag1.Adress = 2077;
  5592. writeToPLC_Flag1.Value = (short)6;
  5593. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5594. stopwatch1.Stop();
  5595. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5596. return;
  5597. }
  5598. #endregion 存储绑定数据到 边线MES系统中
  5599. stopwatch2.Stop();
  5600. short b1MES_FLAG_Unbind = 1;
  5601. // MES_Flag
  5602. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5603. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5604. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5605. writeToPLC_Flag.Adress = 2077;
  5606. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5607. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5608. }
  5609. catch (Exception ex)
  5610. {
  5611. string str = ex.StackTrace;
  5612. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5613. // MES_Flag
  5614. stopwatch2.Start();
  5615. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5616. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5617. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5618. writeToPLC_Flag.Adress = 2077;
  5619. writeToPLC_Flag.Value = (short)6;
  5620. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5621. stopwatch2.Stop();
  5622. }
  5623. stopwatch1.Stop();
  5624. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5625. }
  5626. //// 上次采集到的SN
  5627. //private string sn_FCT = string.Empty;
  5628. /// <summary>
  5629. /// [S2] FCT(板测)- 出站数据
  5630. /// </summary>
  5631. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5632. {
  5633. Stopwatch stopwatch1 = new Stopwatch();
  5634. Stopwatch stopwatch2 = new Stopwatch();
  5635. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5636. string stationNameStr = stationCode + stationName;
  5637. string processItem = stationName; // 测试项目
  5638. try
  5639. {
  5640. stopwatch1.Start();
  5641. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5642. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5643. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5644. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5645. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5646. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5647. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5648. bool pass1 = b1Part1Result == 1;
  5649. bool pass2 = b1Part2Result == 1;
  5650. #region 根据 载具SN 查 物料SN
  5651. string cavityData = string.Empty;
  5652. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5653. if (string.IsNullOrEmpty(cavityData))
  5654. cavityData = "";
  5655. if (snResult != 0)
  5656. {
  5657. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5658. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5659. writeToPLC_Flag1.Adress = 2169;
  5660. writeToPLC_Flag1.Value = (short)4;
  5661. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5662. stopwatch1.Stop();
  5663. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5664. return;
  5665. }
  5666. #endregion 根据 载具SN 查 物料SN
  5667. string[] cavitySNs = cavityData.Split('.');
  5668. string b1ProductSN1 = string.Empty;
  5669. string b1ProductSN2 = string.Empty;
  5670. if (cavitySNs != null && cavitySNs.Length >= 2)
  5671. {
  5672. b1ProductSN1 = cavitySNs[0];
  5673. b1ProductSN2 = cavitySNs[1];
  5674. }
  5675. stopwatch2.Start();
  5676. // 产品1
  5677. int result1 = 0;
  5678. if (b1ProductSN1 == "假产品")
  5679. result1 = 1;
  5680. else
  5681. {
  5682. List<TestItem> items1 = new List<TestItem>();
  5683. items1.Add(new TestItem()
  5684. {
  5685. Parameter_name = "载具码",
  5686. Parameter_value = b1ProductSN.ToString(),
  5687. Parameter_unit = ""
  5688. });
  5689. items1.Add(new TestItem()
  5690. {
  5691. Parameter_name = "载具穴号",
  5692. Parameter_value = "1",
  5693. Parameter_unit = ""
  5694. });
  5695. items1.Add(new TestItem()
  5696. {
  5697. Parameter_name = "产品结果",
  5698. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5699. Parameter_unit = ""
  5700. });
  5701. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5702. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5703. }
  5704. // 产品2
  5705. int result2 = 0;
  5706. if (b1ProductSN1 == "假产品")
  5707. result2 = 1;
  5708. else
  5709. {
  5710. List<TestItem> items2 = new List<TestItem>();
  5711. items2.Add(new TestItem()
  5712. {
  5713. Parameter_name = "载具码",
  5714. Parameter_value = b1ProductSN.ToString(),
  5715. Parameter_unit = ""
  5716. });
  5717. items2.Add(new TestItem()
  5718. {
  5719. Parameter_name = "载具穴号",
  5720. Parameter_value = "2",
  5721. Parameter_unit = ""
  5722. });
  5723. items2.Add(new TestItem()
  5724. {
  5725. Parameter_name = "产品结果",
  5726. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5727. Parameter_unit = ""
  5728. });
  5729. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5730. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5731. }
  5732. short result = 0;
  5733. List<int> results = new List<int>() { result1, result2 };
  5734. if (result1 == 1 && result2 == 1)
  5735. result = 1;
  5736. else if (results.Contains(3))
  5737. result = 3;
  5738. else if (results.Contains(2))
  5739. result = 2;
  5740. else if (results.Contains(4))
  5741. result = 4;
  5742. else
  5743. result = 4;
  5744. stopwatch2.Stop();
  5745. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5746. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5747. writeToPLC_Flag.Name = "b1MES_FLAG";
  5748. writeToPLC_Flag.Adress = 2169;
  5749. writeToPLC_Flag.Value = result;
  5750. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5751. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5752. }
  5753. catch (Exception ex)
  5754. {
  5755. stopwatch2.Restart();
  5756. // MES_Flag 为4上位机报错
  5757. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5758. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5759. writeToPLC_Flag.Name = "b1MES_FLAG";
  5760. writeToPLC_Flag.Adress = 2169;
  5761. writeToPLC_Flag.Value = (short)4;
  5762. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5763. stopwatch2.Stop();
  5764. string str = ex.StackTrace;
  5765. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5766. }
  5767. stopwatch1.Stop();
  5768. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5769. }
  5770. /// <summary>
  5771. /// [S2] FCT(板测)- 节拍接口
  5772. /// </summary>
  5773. /// <param name="plcNo">PLC编号</param>
  5774. /// <param name="stationNameStr">工站全称</param>
  5775. private void S2节拍接口(int plcNo, string stationNameStr)
  5776. {
  5777. Stopwatch stopwatch1 = new Stopwatch();
  5778. Stopwatch stopwatch2 = new Stopwatch();
  5779. string resultStr = string.Empty;
  5780. try
  5781. {
  5782. stopwatch1.Start();
  5783. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5784. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5785. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5786. if (!actionBool)
  5787. {
  5788. stopwatch2.Start();
  5789. // MES_Flag
  5790. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5791. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5792. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5793. writeToPLC_Flag1.Adress = 2203;
  5794. writeToPLC_Flag1.Value = (short)4;
  5795. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5796. stopwatch2.Stop();
  5797. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5798. return;
  5799. }
  5800. string b1OEEPartNo = string.Empty; // 物料码
  5801. if (string.IsNullOrEmpty(b1OEEProductSN))
  5802. {
  5803. stopwatch2.Start();
  5804. // MES_Flag
  5805. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5806. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5807. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5808. writeToPLC_Flag1.Adress = 2203;
  5809. writeToPLC_Flag1.Value = (short)1;
  5810. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5811. stopwatch2.Stop();
  5812. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5813. return;
  5814. }
  5815. else
  5816. { // 查产品SN
  5817. b1OEEPartNo = "Test"; // ZS
  5818. }
  5819. short b1OEEMES_FLAG = 0;
  5820. // 上传OEE
  5821. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5822. b1OEEMES_FLAG = result.Item1;
  5823. resultStr = result.Item2;
  5824. stopwatch2.Start();
  5825. // MES_Flag
  5826. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5827. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5828. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5829. writeToPLC_Flag.Adress = 2203;
  5830. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5831. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5832. stopwatch2.Stop();
  5833. }
  5834. catch (Exception ex)
  5835. {
  5836. string str = ex.StackTrace;
  5837. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5838. // MES_Flag
  5839. stopwatch2.Start();
  5840. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5841. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5842. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5843. writeToPLC_Flag.Adress = 2203;
  5844. writeToPLC_Flag.Value = (short)4;
  5845. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5846. stopwatch2.Stop();
  5847. }
  5848. stopwatch1.Stop();
  5849. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5850. }
  5851. #endregion [S2] FCT(板测)
  5852. #endregion PLC2 李晓奇
  5853. #region PLC3 刘永村
  5854. #region [S3] 值板机
  5855. /// <summary>
  5856. /// S3工位的数据- 触发信号上次的值
  5857. /// </summary>
  5858. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5859. /// <summary>
  5860. /// S3工位的数据(含触发信号)
  5861. /// </summary>
  5862. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5863. /// <summary>
  5864. /// S3工位的数据- 回写点位
  5865. /// </summary>
  5866. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5867. /// <summary>
  5868. /// [S3] 值板机
  5869. /// </summary>
  5870. /// <param name="plcNo">PLC编号</param>
  5871. //private void ReadStation_S3(int plcNo)
  5872. //{
  5873. // // [S1] Tray盘上料装备
  5874. // // [S2] FCT
  5875. // // [S3] 值板机
  5876. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5877. // // [S5] Tray盘下料装备
  5878. // /// 上位机心跳
  5879. // /// 获取设备报警数据与状态信息
  5880. // string stationCode = "[S3]";
  5881. // string stationName = "值板机";
  5882. // string stationNameStr = stationCode + stationName;
  5883. // #region 创建字典
  5884. // // 触发信号字典 赋值
  5885. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5886. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5887. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5888. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5889. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5890. // // PLC数据字典 赋值
  5891. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5892. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5893. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5894. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5895. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5896. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5897. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5898. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5899. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5900. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5901. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5902. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5903. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5904. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5905. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5906. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5907. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5908. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5909. // s3PLCData.Add("c1Result", 0); // 产品结果
  5910. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5911. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5912. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5913. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  5914. // #endregion 创建字典
  5915. // while (IsRun)
  5916. // {
  5917. // try
  5918. // {
  5919. // if (!GlobalContext._IsCon_Funs3)
  5920. // {
  5921. // UpdatePLCMonitor(1, plcNo, 0);
  5922. // continue;
  5923. // }
  5924. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5925. // {
  5926. // Stopwatch stopwatch1 = new Stopwatch();
  5927. // Stopwatch stopwatch2 = new Stopwatch();
  5928. // stopwatch1.Start();
  5929. // stopwatch2.Start();
  5930. // #region 一次性读取所有数据
  5931. // // 一次性读取所有数据
  5932. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  5933. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  5934. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  5935. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  5936. // int[] datas = data1.Concat(data2).ToArray();
  5937. // datas = datas.Concat(data3).ToArray();
  5938. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  5939. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  5940. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5941. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  5942. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  5943. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  5944. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5945. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  5946. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  5947. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  5948. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  5949. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5950. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  5951. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  5952. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  5953. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  5954. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5955. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  5956. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  5957. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  5958. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  5959. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  5960. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  5961. // #endregion 一次性读取所有数据
  5962. // stopwatch2.Stop();
  5963. // #region 回写操作,写后清空flag
  5964. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  5965. // #endregion 回写操作,写后清空flag
  5966. // #region S3进站校验
  5967. // try
  5968. // {
  5969. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  5970. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  5971. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  5972. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  5973. // {
  5974. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  5975. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5976. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  5977. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5978. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  5979. // }
  5980. // }
  5981. // catch (Exception ex)
  5982. // {
  5983. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5984. // string str = ex.StackTrace;
  5985. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5986. // }
  5987. // #endregion S3进站校验
  5988. // #region S3二穴载具解绑
  5989. // try
  5990. // {
  5991. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  5992. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  5993. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  5994. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  5995. // {
  5996. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5997. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  5998. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  5999. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  6000. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  6001. // }
  6002. // }
  6003. // catch (Exception ex)
  6004. // {
  6005. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  6006. // string str = ex.StackTrace;
  6007. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6008. // }
  6009. // #endregion S3二穴载具解绑
  6010. // #region S3二穴载具绑定
  6011. // try
  6012. // {
  6013. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  6014. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  6015. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  6016. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  6017. // {
  6018. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6019. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  6020. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  6021. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  6022. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  6023. // }
  6024. // }
  6025. // catch (Exception ex)
  6026. // {
  6027. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6028. // string str = ex.StackTrace;
  6029. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6030. // }
  6031. // #endregion S3二穴载具绑定
  6032. // #region S3出站接口(+一穴载具绑定)
  6033. // try
  6034. // {
  6035. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  6036. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  6037. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  6038. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  6039. // {
  6040. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  6041. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6042. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  6043. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  6044. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  6045. // }
  6046. // }
  6047. // catch (Exception ex)
  6048. // {
  6049. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  6050. // string str = ex.StackTrace;
  6051. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6052. // }
  6053. // #endregion S3出站接口(+一穴载具绑定)
  6054. // #region S3节拍接口
  6055. // try
  6056. // {
  6057. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  6058. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  6059. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  6060. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  6061. // {
  6062. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  6063. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6064. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  6065. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  6066. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  6067. // }
  6068. // }
  6069. // catch (Exception ex)
  6070. // {
  6071. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6072. // string str = ex.StackTrace;
  6073. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6074. // }
  6075. // #endregion S3节拍接口
  6076. // #region 心跳
  6077. // try
  6078. // {
  6079. // short states = 0;
  6080. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6081. // }
  6082. // catch (Exception ex)
  6083. // {
  6084. // string str = ex.StackTrace;
  6085. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6086. // }
  6087. // #endregion 心跳
  6088. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6089. // stopwatch1.Stop();
  6090. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6091. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6092. // }
  6093. // else
  6094. // {
  6095. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6096. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6097. // Funs[plcNo].Connect();
  6098. // }
  6099. // }
  6100. // catch (Exception ex)
  6101. // {
  6102. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6103. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6104. // Funs[plcNo].ReConnect();
  6105. // }
  6106. // Thread.Sleep(IntervalReadPLC);
  6107. // }
  6108. //}
  6109. /// <summary>
  6110. /// [S3] 值板机- 进站校验
  6111. /// </summary>
  6112. /// <param name="plcNo">PLC编号</param>
  6113. /// <param name="stationNameStr">工站全称</param>
  6114. private void S3进站校验(int plcNo, string stationNameStr)
  6115. {
  6116. Stopwatch stopwatch1 = new Stopwatch();
  6117. Stopwatch stopwatch2 = new Stopwatch();
  6118. try
  6119. {
  6120. stopwatch1.Start();
  6121. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6122. sn = sn.Replace("\0", "");
  6123. #region 查询载具上的产品信息
  6124. string cavityData = string.Empty;
  6125. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6126. if (string.IsNullOrEmpty(cavityData))
  6127. cavityData = "";
  6128. if (snResult != 0)
  6129. {
  6130. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6131. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6132. writeToPLC_Flag1.Adress = 2003;
  6133. writeToPLC_Flag1.Value = (short)6;
  6134. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6135. stopwatch1.Stop();
  6136. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6137. return;
  6138. }
  6139. #endregion 查询载具上的产品信息
  6140. string[] cavitySNs = cavityData.Split('.');
  6141. string part1Str = ""; // 产品1的SN码
  6142. string part2Str = ""; // 产品2的SN码
  6143. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6144. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6145. if (cavitySNs != null && cavitySNs.Length >= 2)
  6146. {
  6147. part1Str = cavitySNs[0];
  6148. part2Str = cavitySNs[1];
  6149. c1Part1Result_Check = 2;
  6150. c1Part2Result_Check = 2;
  6151. }
  6152. if (part1Str == "假产品")
  6153. c1Part1Result_Check = 3;
  6154. if (part2Str == "假产品")
  6155. c1Part2Result_Check = 3;
  6156. // 调用MES进站
  6157. stopwatch2.Start();
  6158. // 调用MES进站 - 产品1
  6159. List<TestItem> item;
  6160. int result1 = c1Part1Result_Check;
  6161. if (result1 != 3)
  6162. {
  6163. item = new List<TestItem>();
  6164. item.Add(new TestItem()
  6165. {
  6166. Parameter_name = "载具码",
  6167. Parameter_value = sn,
  6168. });
  6169. item.Add(new TestItem()
  6170. {
  6171. Parameter_name = "载具穴号",
  6172. Parameter_value = "1",
  6173. });
  6174. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6175. }
  6176. // 调用MES进站 - 产品2
  6177. int result2 = c1Part2Result_Check;
  6178. if (result2 != 3)
  6179. {
  6180. item = new List<TestItem>();
  6181. item.Add(new TestItem()
  6182. {
  6183. Parameter_name = "载具码",
  6184. Parameter_value = sn,
  6185. });
  6186. item.Add(new TestItem()
  6187. {
  6188. Parameter_name = "载具穴号",
  6189. Parameter_value = "2",
  6190. });
  6191. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6192. }
  6193. stopwatch2.Stop();
  6194. if (result1 == 2)
  6195. c1Part1Result_Check = 2;
  6196. if (result2 == 2)
  6197. c1Part2Result_Check = 2;
  6198. int result = result1;
  6199. if (result == 1)
  6200. result = result2;
  6201. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6202. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6203. short c1MES_FLAG_Check = (short)result;
  6204. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6205. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6206. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6207. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6208. //// MES_Flag
  6209. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6210. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6211. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6212. writeToPLC_Flag.Adress = 2003;
  6213. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6214. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6215. {
  6216. Name = "c1Part1Result_Check",
  6217. Adress = 2024,
  6218. ValueType = PLCValueType.Short,
  6219. Value = c1Part1Result_Check
  6220. });
  6221. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6222. {
  6223. Name = "c1Part2Result_Check",
  6224. Adress = 2025,
  6225. ValueType = PLCValueType.Short,
  6226. Value = c1Part2Result_Check
  6227. });
  6228. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6229. {
  6230. Name = "c1Part1Num_Check",
  6231. Adress = 2026,
  6232. ValueType = PLCValueType.Short,
  6233. Value = c1Part1Num_Check
  6234. });
  6235. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6236. {
  6237. Name = "c1Part2Num_Check",
  6238. Adress = 2027,
  6239. ValueType = PLCValueType.Short,
  6240. Value = c1Part2Num_Check
  6241. });
  6242. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6243. }
  6244. catch (Exception ex)
  6245. {
  6246. string str = ex.StackTrace;
  6247. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6248. // MES_Flag
  6249. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6250. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6251. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6252. writeToPLC_Flag.Adress = 2003;
  6253. writeToPLC_Flag.Value = (short)6;
  6254. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6255. }
  6256. stopwatch1.Stop();
  6257. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6258. }
  6259. /// <summary>
  6260. /// [S3] 值板机 - 二穴载具解绑
  6261. /// </summary>
  6262. /// <param name="plcNo">PLC编号</param>
  6263. /// <param name="stationNameStr">工站全称</param>
  6264. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6265. {
  6266. Stopwatch stopwatch1 = new Stopwatch();
  6267. Stopwatch stopwatch2 = new Stopwatch();
  6268. try
  6269. {
  6270. stopwatch1.Start();
  6271. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6272. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6273. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6274. // 解绑
  6275. #region 查询载具上的产品信息
  6276. string cavityData = string.Empty;
  6277. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6278. if (string.IsNullOrEmpty(cavityData))
  6279. cavityData = "";
  6280. if (snResult != 0)
  6281. {
  6282. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6283. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6284. writeToPLC_Flag1.Adress = 2082;
  6285. writeToPLC_Flag1.Value = (short)6;
  6286. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6287. stopwatch1.Stop();
  6288. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6289. return;
  6290. }
  6291. #endregion 查询载具上的产品信息
  6292. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6293. #region 解绑
  6294. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6295. {
  6296. // 删除
  6297. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6298. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6299. }
  6300. else
  6301. {
  6302. string data_new = string.Join(".", cavitySNs);
  6303. // 删除再插入
  6304. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6305. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6306. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6307. }
  6308. #endregion 解绑
  6309. short c1MES_FLAG_Unbind = 1;
  6310. stopwatch2.Start();
  6311. // MES_Flag
  6312. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6313. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6314. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6315. writeToPLC_Flag.Adress = 2082;
  6316. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6317. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6318. stopwatch2.Stop();
  6319. }
  6320. catch (Exception ex)
  6321. {
  6322. string str = ex.StackTrace;
  6323. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6324. // MES_Flag
  6325. stopwatch2.Start();
  6326. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6327. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6328. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6329. writeToPLC_Flag.Adress = 2082;
  6330. writeToPLC_Flag.Value = (short)6;
  6331. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6332. stopwatch2.Stop();
  6333. }
  6334. stopwatch1.Stop();
  6335. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6336. }
  6337. /// <summary>
  6338. /// [S3] 值板机 - 二穴载具绑定
  6339. /// </summary>
  6340. /// <param name="plcNo">PLC编号</param>
  6341. /// <param name="stationNameStr">工站全称</param>
  6342. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6343. {
  6344. Stopwatch stopwatch1 = new Stopwatch();
  6345. Stopwatch stopwatch2 = new Stopwatch();
  6346. try
  6347. {
  6348. stopwatch1.Start();
  6349. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6350. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6351. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6352. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6353. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6354. stopwatch2.Start();
  6355. #region 查询载具上的产品信息
  6356. string cavityData = string.Empty;
  6357. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6358. if (string.IsNullOrEmpty(cavityData))
  6359. cavityData = "";
  6360. if (snResult != 0)
  6361. {
  6362. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6363. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6364. writeToPLC_Flag1.Adress = 2115;
  6365. writeToPLC_Flag1.Value = (short)6;
  6366. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6367. stopwatch1.Stop();
  6368. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6369. return;
  6370. }
  6371. #endregion 查询载具上的产品信息
  6372. // 产品换载具
  6373. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6374. string partSn1 = "";
  6375. string partSn2 = "";
  6376. if (cavitySNs != null && cavitySNs.Length >= 2)
  6377. {
  6378. partSn1 = cavitySNs[0];
  6379. partSn2 = cavitySNs[1];
  6380. }
  6381. string data_new = string.Empty;
  6382. // 是否是两个穴位交换
  6383. if (c1CavityReverse_Bind == 1)
  6384. {
  6385. // 交换
  6386. data_new = string.Concat(partSn2, ".", partSn1);
  6387. }
  6388. else
  6389. { // 不交换
  6390. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6391. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6392. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6393. data_new = string.Join(".", cavitySNs);
  6394. }
  6395. // 删除再插入
  6396. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6397. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6398. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6399. stopwatch2.Stop();
  6400. short c1MES_FLAG_Bind = 1;
  6401. // MES_Flag
  6402. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6403. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6404. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6405. writeToPLC_Flag.Adress = 2115;
  6406. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6407. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6408. }
  6409. catch (Exception ex)
  6410. {
  6411. string str = ex.StackTrace;
  6412. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6413. // MES_Flag
  6414. stopwatch2.Start();
  6415. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6416. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6417. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6418. writeToPLC_Flag.Adress = 2115;
  6419. writeToPLC_Flag.Value = (short)6;
  6420. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6421. stopwatch2.Stop();
  6422. }
  6423. stopwatch1.Stop();
  6424. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6425. }
  6426. //// 上次采集到的SN
  6427. //private string sn_值板机 = string.Empty;
  6428. /// <summary>
  6429. /// [S3] 值板机 - 出站接口
  6430. /// </summary>
  6431. /// <param name="plcNo">PLC编号</param>
  6432. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6433. {
  6434. Stopwatch stopwatch1 = new Stopwatch();
  6435. Stopwatch stopwatch2 = new Stopwatch();
  6436. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6437. string stationNameStr = stationCode + stationName;
  6438. string processItem = stationName; // 测试项目
  6439. try
  6440. {
  6441. stopwatch1.Start();
  6442. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6443. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6444. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6445. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6446. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6447. sn = sn.Replace("\0", "");
  6448. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6449. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6450. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6451. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6452. bool pass = c1Result == 1;
  6453. // 查sn
  6454. #region 查询载具上的产品信息
  6455. string cavityData = string.Empty;
  6456. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6457. if (string.IsNullOrEmpty(cavityData))
  6458. cavityData = "";
  6459. if (snResult != 0)
  6460. {
  6461. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6462. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6463. writeToPLC_Flag1.Adress = 2150;
  6464. writeToPLC_Flag1.Value = (short)4;
  6465. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6466. stopwatch1.Stop();
  6467. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6468. return;
  6469. }
  6470. #endregion 查询载具上的产品信息
  6471. string[] cavitySNs = cavityData.Split('.');
  6472. string productSN = "";
  6473. if (cavitySNs != null && cavitySNs.Length >= 2)
  6474. {
  6475. productSN = cavitySNs[c1VehicleCavity];
  6476. cavitySNs[c1VehicleCavity] = "";
  6477. }
  6478. stopwatch2.Start();
  6479. List<TestItem> items = new List<TestItem>();
  6480. items.Add(new TestItem()
  6481. {
  6482. Parameter_name = "二穴载具码",
  6483. Parameter_value = c1ProductSN_Check,
  6484. Parameter_unit = ""
  6485. });
  6486. items.Add(new TestItem()
  6487. {
  6488. Parameter_name = "二穴载具穴号",
  6489. Parameter_value = c1VehicleCavity.ToString(),
  6490. Parameter_unit = ""
  6491. });
  6492. items.Add(new TestItem()
  6493. {
  6494. Parameter_name = "一穴载具码",
  6495. Parameter_value = sn,
  6496. Parameter_unit = ""
  6497. });
  6498. items.Add(new TestItem()
  6499. {
  6500. Parameter_name = "一穴载具穴号",
  6501. Parameter_value = "1",
  6502. Parameter_unit = ""
  6503. });
  6504. items.Add(new TestItem()
  6505. {
  6506. Parameter_name = "产品结果",
  6507. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6508. Parameter_unit = ""
  6509. });
  6510. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6511. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6512. short result = (short)result1;
  6513. stopwatch2.Stop();
  6514. #region 存储绑定数据到 边线MES系统中
  6515. if (result == 1)
  6516. {
  6517. string data = string.Concat(productSN);
  6518. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6519. if (resultMesR != 0)
  6520. {
  6521. result = 4;
  6522. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6523. }
  6524. }
  6525. #endregion 存储绑定数据到 边线MES系统中
  6526. #region 产品从 来源载具(二穴载具)中删除
  6527. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6528. {
  6529. // 删除
  6530. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6531. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6532. }
  6533. else
  6534. {
  6535. string data_new = string.Join(".", cavitySNs);
  6536. // 删除再插入
  6537. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6538. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6539. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6540. }
  6541. #endregion 产品从 来源载具(二穴载具)中删除
  6542. // MES_Flag 为MES报错
  6543. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6544. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6545. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6546. writeToPLC_Flag.Name = "c1MES_FLAG";
  6547. writeToPLC_Flag.Adress = 2150;
  6548. writeToPLC_Flag.Value = result;
  6549. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6550. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6551. }
  6552. catch (Exception ex)
  6553. {
  6554. stopwatch2.Restart();
  6555. // MES_Flag 为4上位机报错
  6556. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6557. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6558. writeToPLC_Flag.Name = "c1MES_FLAG";
  6559. writeToPLC_Flag.Adress = 2150;
  6560. writeToPLC_Flag.Value = (short)4;
  6561. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6562. stopwatch2.Stop();
  6563. string str = ex.StackTrace;
  6564. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6565. }
  6566. stopwatch1.Stop();
  6567. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6568. }
  6569. /// <summary>
  6570. /// [S3] 值板机- 节拍接口
  6571. /// </summary>
  6572. /// <param name="plcNo">PLC编号</param>
  6573. /// <param name="stationNameStr">工站全称</param>
  6574. private void S3节拍接口(int plcNo, string stationNameStr)
  6575. {
  6576. Stopwatch stopwatch1 = new Stopwatch();
  6577. Stopwatch stopwatch2 = new Stopwatch();
  6578. string resultStr = string.Empty;
  6579. try
  6580. {
  6581. stopwatch1.Start();
  6582. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6583. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6584. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6585. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6586. if (!actionBool)
  6587. {
  6588. stopwatch2.Start();
  6589. // MES_Flag
  6590. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6591. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6592. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6593. writeToPLC_Flag1.Adress = 2204;
  6594. writeToPLC_Flag1.Value = (short)4;
  6595. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6596. stopwatch2.Stop();
  6597. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6598. return;
  6599. }
  6600. string c1OEEPartNo = string.Empty; // 物料码
  6601. if (string.IsNullOrEmpty(c1OEEProductSN))
  6602. {
  6603. stopwatch2.Start();
  6604. // MES_Flag
  6605. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6606. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6607. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6608. writeToPLC_Flag1.Adress = 2204;
  6609. writeToPLC_Flag1.Value = (short)1;
  6610. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6611. stopwatch2.Stop();
  6612. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6613. return;
  6614. }
  6615. else
  6616. { // 查产品SN
  6617. c1OEEPartNo = "Test"; // ZS
  6618. }
  6619. short c1OEEMES_FLAG = 0;
  6620. // 上传OEE
  6621. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6622. c1OEEMES_FLAG = result.Item1;
  6623. resultStr = result.Item2;
  6624. stopwatch2.Start();
  6625. // MES_Flag
  6626. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6627. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6628. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6629. writeToPLC_Flag.Adress = 2204;
  6630. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6631. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6632. stopwatch2.Stop();
  6633. }
  6634. catch (Exception ex)
  6635. {
  6636. string str = ex.StackTrace;
  6637. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6638. // MES_Flag
  6639. stopwatch2.Start();
  6640. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6641. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6642. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6643. writeToPLC_Flag.Adress = 2204;
  6644. writeToPLC_Flag.Value = (short)4;
  6645. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6646. stopwatch2.Stop();
  6647. }
  6648. stopwatch1.Stop();
  6649. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6650. }
  6651. #endregion [S3] 值板机
  6652. #endregion PLC3 刘永村
  6653. #region PLC4 刘果段
  6654. #region [S4] 取放桁架
  6655. /// <summary>
  6656. /// S4工位的数据- 触发信号上次的值
  6657. /// </summary>
  6658. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6659. /// <summary>
  6660. /// S4工位的数据(含触发信号)
  6661. /// </summary>
  6662. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6663. /// <summary>
  6664. /// S4工位的数据- 回写点位
  6665. /// </summary>
  6666. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6667. /// <summary>
  6668. /// [S4] 取放桁架
  6669. /// </summary>
  6670. /// <param name="plcNo">PLC编号</param>
  6671. //private void ReadStation_S4(int plcNo)
  6672. //{
  6673. // // [S1] Tray盘上料装备
  6674. // // [S2] FCT
  6675. // // [S3] 值板机
  6676. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6677. // // [S5] Tray盘下料装备
  6678. // /// 上位机心跳
  6679. // /// 获取设备报警数据与状态信息
  6680. // string stationCode = "[S4_1]";
  6681. // string stationName = "载具下线装备";
  6682. // string stationNameStr = stationCode + stationName;
  6683. // string stationCode2 = "[S4_2]";
  6684. // string stationName2 = "桁架";
  6685. // string stationNameStr2 = stationCode2 + stationName2;
  6686. // string stationCode3 = "[S4_3]";
  6687. // string stationName3 = "提升机1";
  6688. // string stationNameStr3 = stationCode3 + stationName3;
  6689. // string stationCode4 = "[S4_4]";
  6690. // string stationName4 = "提升机2";
  6691. // string stationNameStr4 = stationCode4 + stationName4;
  6692. // string stationCode5 = "[S4_5]";
  6693. // string stationName5 = "载具上线装备";
  6694. // string stationNameStr5 = stationCode5 + stationName5;
  6695. // #region 创建字典
  6696. // // 触发信号字典 赋值
  6697. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6698. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6699. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6700. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6701. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6702. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6703. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6704. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6705. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6706. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6707. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6708. // // PLC数据字典 赋值
  6709. // // 载具下线装备(弹夹上线)
  6710. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6711. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6712. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6713. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6714. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6715. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6716. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6717. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6718. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6719. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6720. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6721. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6722. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6723. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6724. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6725. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6726. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6727. // s4PLCData.Add("d1Result", 0); // 产品结果
  6728. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6729. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6730. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6731. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6732. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6733. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6734. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6735. // // 真空标机(提升机)
  6736. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6737. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6738. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6739. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6740. // s4PLCData.Add("d3Result", 0); // 产品结果
  6741. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6742. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6743. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6744. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6745. // s4PLCData.Add("d4Result", 0); // 产品结果
  6746. // // 载具上线装备(弹夹下线)
  6747. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6748. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6749. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6750. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6751. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6752. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6753. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6754. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6755. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6756. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6757. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6758. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6759. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6760. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6761. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6762. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6763. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6764. // s4PLCData.Add("d5Result", 0); // 产品结果
  6765. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6766. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6767. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6768. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6769. // #endregion 创建字典
  6770. // while (IsRun)
  6771. // {
  6772. // try
  6773. // {
  6774. // if (!GlobalContext._IsCon_Funs4)
  6775. // {
  6776. // UpdatePLCMonitor(1, plcNo, 0);
  6777. // continue;
  6778. // }
  6779. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6780. // {
  6781. // Stopwatch stopwatch1 = new Stopwatch();
  6782. // Stopwatch stopwatch2 = new Stopwatch();
  6783. // stopwatch1.Start();
  6784. // stopwatch2.Start();
  6785. // #region 一次性读取所有数据
  6786. // // 载具下线装备(弹夹上线)
  6787. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6788. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6789. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6790. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6791. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6792. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6793. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6794. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6795. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6796. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6797. // int[] datas = data1.Concat(data2).ToArray();
  6798. // datas = datas.Concat(data3).ToArray();
  6799. // datas = datas.Concat(data4).ToArray();
  6800. // datas = datas.Concat(data5).ToArray();
  6801. // datas = datas.Concat(data6).ToArray();
  6802. // datas = datas.Concat(data7).ToArray();
  6803. // datas = datas.Concat(data8).ToArray();
  6804. // datas = datas.Concat(data9).ToArray();
  6805. // datas = datas.Concat(data10).ToArray();
  6806. // // 载具下线装备(弹夹上线)
  6807. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6808. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6809. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6810. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6811. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6812. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6813. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6814. // s4PLCData["d1MES_FLAG"] = datas[65];
  6815. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6816. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6817. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6818. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6819. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6820. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6821. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6822. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6823. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6824. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6825. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6826. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6827. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6828. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6829. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6830. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6831. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6832. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6833. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6834. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6835. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6836. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6837. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6838. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6839. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6840. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6841. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6842. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6843. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6844. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6845. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6846. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6847. // s4PLCData["d1Result"] = datas[386];
  6848. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6849. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6850. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6851. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6852. // s4PLCData["d1OEEType"] = datas[419];
  6853. // // 桁架(查询标机中弹夹的状态)
  6854. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6855. // s4PLCData["d2BulletclipStates"] = datas[431];
  6856. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6857. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6858. // // 真空标机
  6859. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6860. // s4PLCData["d3MES_FLAG"] = datas[463];
  6861. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6862. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6863. // s4PLCData["d3Result"] = datas[484];
  6864. // s4PLCData["d3Type"] = datas[485];
  6865. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6866. // s4PLCData["d4MES_FLAG"] = datas[496];
  6867. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6868. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6869. // s4PLCData["d4Result"] = datas[517];
  6870. // s4PLCData["d4Type"] = datas[518];
  6871. // // 载具上线装备(弹夹下线)
  6872. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6873. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6874. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6875. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6876. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6877. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6878. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6879. // s4PLCData["d5MES_FLAG"] = datas[591];
  6880. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6881. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6882. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6883. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6884. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6885. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6886. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6887. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6888. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6889. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6890. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6891. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6892. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6893. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6894. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6895. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6896. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6897. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6898. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6899. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6900. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6901. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6902. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6903. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6904. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6905. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6906. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6907. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6908. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6909. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6910. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6911. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6912. // s4PLCData["d5Result"] = datas[912];
  6913. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  6914. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  6915. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  6916. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  6917. // s4PLCData["d5OEEType"] = datas[945];
  6918. // #endregion 一次性读取所有数据
  6919. // stopwatch2.Stop();
  6920. // #region 回写操作,写后清空flag
  6921. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  6922. // #endregion 回写操作,写后清空flag
  6923. // // N801A-S4_1 弹夹扫码
  6924. // #region N801A-S4_1 弹夹扫码
  6925. // try
  6926. // {
  6927. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  6928. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  6929. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  6930. // {
  6931. // if (d1BulletclipScanCode == 1) // 0->1
  6932. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6933. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  6934. // }
  6935. // }
  6936. // catch (Exception ex)
  6937. // {
  6938. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  6939. // string str = ex.StackTrace;
  6940. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6941. // }
  6942. // #endregion N801A-S4_1 弹夹扫码
  6943. // // N801A-S4_1 载具扫码
  6944. // #region N801A-S4_1 载具扫码
  6945. // try
  6946. // {
  6947. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  6948. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  6949. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  6950. // {
  6951. // if (d1VehicleScanCode == 1) // 0->1
  6952. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6953. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  6954. // }
  6955. // }
  6956. // catch (Exception ex)
  6957. // {
  6958. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  6959. // string str = ex.StackTrace;
  6960. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6961. // }
  6962. // #endregion N801A-S4_1 载具扫码
  6963. // // N801A-S4_1 出站接口
  6964. // #region N801A-S4_1 出站接口
  6965. // try
  6966. // {
  6967. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  6968. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  6969. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  6970. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  6971. // {
  6972. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  6973. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6974. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  6975. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  6976. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  6977. // }
  6978. // }
  6979. // catch (Exception ex)
  6980. // {
  6981. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  6982. // string str = ex.StackTrace;
  6983. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6984. // }
  6985. // #endregion N801A-S4_1 出站接口
  6986. // // N801A-S4_1 节拍接口
  6987. // #region N801A-S4_1 节拍接口
  6988. // try
  6989. // {
  6990. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  6991. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  6992. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  6993. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  6994. // {
  6995. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  6996. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6997. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  6998. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  6999. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  7000. // }
  7001. // }
  7002. // catch (Exception ex)
  7003. // {
  7004. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7005. // string str = ex.StackTrace;
  7006. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7007. // }
  7008. // #endregion N801A-S4_1 节拍接口
  7009. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  7010. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  7011. // try
  7012. // {
  7013. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  7014. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  7015. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  7016. // {
  7017. // if (d2BulletclipScanCode == 1) // 0->1
  7018. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  7019. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  7020. // }
  7021. // }
  7022. // catch (Exception ex)
  7023. // {
  7024. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7025. // string str = ex.StackTrace;
  7026. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7027. // }
  7028. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  7029. // // N801A-S4_3 真空标机1 数据
  7030. // #region N801A-S4_3 真空标机1
  7031. // try
  7032. // {
  7033. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  7034. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  7035. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  7036. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  7037. // {
  7038. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  7039. // {
  7040. // int stationType = (int)s4PLCData["d3Type"];
  7041. // if (stationType == 1)
  7042. // {
  7043. // // S4_3进站接口
  7044. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  7045. // }
  7046. // else if (stationType == 2)
  7047. // {
  7048. // // S4_3出站接口
  7049. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  7050. // }
  7051. // }
  7052. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  7053. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  7054. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  7055. // }
  7056. // }
  7057. // catch (Exception ex)
  7058. // {
  7059. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7060. // string str = ex.StackTrace;
  7061. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7062. // }
  7063. // #endregion N801A-S4_3 真空标机1
  7064. // // N801A-S4_4 真空标机2 数据
  7065. // #region N801A-S4_4 真空标机2
  7066. // try
  7067. // {
  7068. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  7069. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  7070. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  7071. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  7072. // {
  7073. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  7074. // {
  7075. // int stationType = (int)s4PLCData["d4Type"];
  7076. // if (stationType == 1)
  7077. // {
  7078. // // S4_4进站接口
  7079. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  7080. // }
  7081. // else if (stationType == 2)
  7082. // {
  7083. // // S4_4出站接口
  7084. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  7085. // }
  7086. // }
  7087. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  7088. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  7089. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  7090. // }
  7091. // }
  7092. // catch (Exception ex)
  7093. // {
  7094. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7095. // string str = ex.StackTrace;
  7096. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7097. // }
  7098. // #endregion N801A-S4_4 真空标机2
  7099. // // N801A-S4_5 弹夹扫码 数据
  7100. // #region N801A-S4_5 弹夹扫码
  7101. // try
  7102. // {
  7103. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7104. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7105. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7106. // {
  7107. // if (d5BulletclipScanCode == 1) // 0->1
  7108. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7109. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7110. // }
  7111. // }
  7112. // catch (Exception ex)
  7113. // {
  7114. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7115. // string str = ex.StackTrace;
  7116. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7117. // }
  7118. // #endregion N801A-S4_5 弹夹扫码
  7119. // // N801A-S4_5 载具扫码 数据
  7120. // #region N801A-S4_5 载具扫码
  7121. // try
  7122. // {
  7123. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7124. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7125. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7126. // {
  7127. // if (d5VehicleScanCode == 1) // 0->1
  7128. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7129. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7130. // }
  7131. // }
  7132. // catch (Exception ex)
  7133. // {
  7134. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7135. // string str = ex.StackTrace;
  7136. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7137. // }
  7138. // #endregion N801A-S4_5 载具扫码
  7139. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7140. // #region N801A-S4_5 出站接口
  7141. // try
  7142. // {
  7143. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7144. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7145. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7146. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7147. // {
  7148. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7149. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7150. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7151. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7152. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7153. // }
  7154. // }
  7155. // catch (Exception ex)
  7156. // {
  7157. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7158. // string str = ex.StackTrace;
  7159. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7160. // }
  7161. // #endregion N801A-S4_5 出站接口
  7162. // // N801A-S4_5 节拍接口 数据
  7163. // #region N801A-S4_5 节拍接口
  7164. // try
  7165. // {
  7166. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7167. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7168. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7169. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7170. // {
  7171. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7172. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7173. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7174. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7175. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7176. // }
  7177. // }
  7178. // catch (Exception ex)
  7179. // {
  7180. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7181. // string str = ex.StackTrace;
  7182. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7183. // }
  7184. // #endregion N801A-S4_5 节拍接口
  7185. // #region 心跳
  7186. // try
  7187. // {
  7188. // short states = 0;
  7189. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7190. // }
  7191. // catch (Exception ex)
  7192. // {
  7193. // string str = ex.StackTrace;
  7194. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7195. // }
  7196. // #endregion 心跳
  7197. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7198. // stopwatch1.Stop();
  7199. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7200. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7201. // }
  7202. // else
  7203. // {
  7204. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7205. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7206. // Funs[plcNo].Connect();
  7207. // }
  7208. // }
  7209. // catch (Exception ex)
  7210. // {
  7211. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7212. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7213. // Funs[plcNo].ReConnect();
  7214. // }
  7215. // Thread.Sleep(IntervalReadPLC);
  7216. // }
  7217. //}
  7218. /// <summary>
  7219. /// [S4] 取放桁架 - S4_1弹夹扫码
  7220. /// </summary>
  7221. /// <param name="plcNo">PLC编号</param>
  7222. /// <param name="stationNameStr">工站全称</param>
  7223. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7224. {
  7225. Stopwatch stopwatch1 = new Stopwatch();
  7226. Stopwatch stopwatch2 = new Stopwatch();
  7227. try
  7228. {
  7229. stopwatch1.Start();
  7230. // ZS 弹夹扫码
  7231. string d1BulletclipCode = " "; // 扫到的码
  7232. short d1BulletclipScanCode = 2;
  7233. stopwatch2.Start();
  7234. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7235. //// MES_Flag
  7236. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7237. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7238. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7239. writeToPLC_Flag.Adress = 2002;
  7240. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7241. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7242. {
  7243. Name = "d1BulletclipCode",
  7244. Adress = 2003,
  7245. ValueType = PLCValueType.String,
  7246. ValueTypeStrLength = 20,
  7247. Value = d1BulletclipCode
  7248. });
  7249. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7250. stopwatch2.Stop();
  7251. }
  7252. catch (Exception ex)
  7253. {
  7254. string str = ex.StackTrace;
  7255. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7256. stopwatch2.Start();
  7257. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7258. //// MES_Flag
  7259. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7260. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7261. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7262. writeToPLC_Flag.Adress = 2002;
  7263. writeToPLC_Flag.Value = (short)6;
  7264. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7265. {
  7266. Name = "d1BulletclipCode",
  7267. Adress = 2003,
  7268. ValueType = PLCValueType.String,
  7269. ValueTypeStrLength = 20,
  7270. Value = " "
  7271. });
  7272. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7273. stopwatch2.Stop();
  7274. }
  7275. stopwatch1.Stop();
  7276. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7277. }
  7278. /// <summary>
  7279. /// [S4] 取放桁架 - S4_1载具扫码
  7280. /// </summary>
  7281. /// <param name="plcNo">PLC编号</param>
  7282. /// <param name="stationNameStr">工站全称</param>
  7283. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7284. {
  7285. Stopwatch stopwatch1 = new Stopwatch();
  7286. Stopwatch stopwatch2 = new Stopwatch();
  7287. try
  7288. {
  7289. stopwatch1.Start();
  7290. // ZS 载具扫码
  7291. string d1VehicleCode = ""; // 扫到的码
  7292. short d1VehicleScanCode = 2;
  7293. #region 进站
  7294. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7295. {
  7296. #region 查询载具上的产品信息
  7297. string cavityData = string.Empty;
  7298. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7299. if (string.IsNullOrEmpty(cavityData))
  7300. cavityData = "";
  7301. if (snResult != 0)
  7302. {
  7303. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7304. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7305. writeToPLC_Flag1.Adress = 2033;
  7306. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7307. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7308. {
  7309. Name = "d1VehicleCode",
  7310. Adress = 2034,
  7311. ValueType = PLCValueType.String,
  7312. ValueTypeStrLength = 20,
  7313. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7314. });
  7315. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7316. stopwatch1.Stop();
  7317. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7318. return;
  7319. }
  7320. string[] cavitySNs = cavityData.Split('.');
  7321. string partNo = "";
  7322. if (cavitySNs != null && cavitySNs.Length >= 1)
  7323. {
  7324. partNo = cavitySNs[0];
  7325. }
  7326. #endregion 查询载具上的产品信息
  7327. List<TestItem> item = new List<TestItem>();
  7328. item.Add(new TestItem()
  7329. {
  7330. Parameter_name = "载具码",
  7331. Parameter_value = d1VehicleCode,
  7332. });
  7333. item.Add(new TestItem()
  7334. {
  7335. Parameter_name = "载具穴号",
  7336. Parameter_value = "1",
  7337. });
  7338. stopwatch2.Start();
  7339. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7340. stopwatch2.Stop();
  7341. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7342. }
  7343. #endregion 进站
  7344. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7345. //// MES_Flag
  7346. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7347. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7348. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7349. writeToPLC_Flag.Adress = 2033;
  7350. writeToPLC_Flag.Value = d1VehicleScanCode;
  7351. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7352. {
  7353. Name = "d1VehicleCode",
  7354. Adress = 2034,
  7355. ValueType = PLCValueType.String,
  7356. ValueTypeStrLength = 20,
  7357. Value = d1VehicleCode
  7358. });
  7359. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7360. }
  7361. catch (Exception ex)
  7362. {
  7363. string str = ex.StackTrace;
  7364. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7365. stopwatch2.Start();
  7366. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7367. //// MES_Flag
  7368. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7369. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7370. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7371. writeToPLC_Flag.Adress = 2033;
  7372. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7373. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7374. {
  7375. Name = "d1VehicleCode",
  7376. Adress = 2034,
  7377. ValueType = PLCValueType.String,
  7378. ValueTypeStrLength = 20,
  7379. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7380. });
  7381. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7382. stopwatch2.Stop();
  7383. }
  7384. stopwatch1.Stop();
  7385. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7386. }
  7387. // 上次采集到的SN
  7388. //private string sn_S4_1出站接口 = string.Empty;
  7389. /// <summary>
  7390. /// [S4] 取放桁架 - S4_1出站接口
  7391. /// </summary>
  7392. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7393. {
  7394. Stopwatch stopwatch1 = new Stopwatch();
  7395. Stopwatch stopwatch2 = new Stopwatch();
  7396. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7397. string stationNameStr = stationCode + stationName;
  7398. string processItem = stationName; // 测试项目
  7399. try
  7400. {
  7401. stopwatch1.Start();
  7402. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7403. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7404. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7405. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7406. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7407. sn = sn.Replace("\0", "");
  7408. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7409. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7410. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7411. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7412. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7413. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7414. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7415. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7416. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7417. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7418. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7419. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7420. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7421. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7422. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7423. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7424. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7425. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7426. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7427. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7428. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7429. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7430. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7431. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7432. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7433. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7434. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7435. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7436. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7437. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7438. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7439. bool pass = d1Result == 1;
  7440. // 存 载具SN列表
  7441. List<string> vehicleCodes = new List<string>()
  7442. {
  7443. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7444. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7445. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7446. };
  7447. // 统一查 产品SN列表
  7448. List<string> partNos = new List<string>();
  7449. foreach (string vehicleCode in vehicleCodes)
  7450. {
  7451. if (string.IsNullOrEmpty(vehicleCode))
  7452. partNos.Add("");
  7453. else
  7454. {
  7455. string partNo = "";
  7456. #region 查询载具上的产品信息
  7457. string cavityData = string.Empty;
  7458. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7459. if (string.IsNullOrEmpty(cavityData))
  7460. cavityData = "";
  7461. if (snResult != 0)
  7462. {
  7463. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7464. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7465. writeToPLC_Flag1.Adress = 2065;
  7466. writeToPLC_Flag1.Value = (short)4;
  7467. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7468. stopwatch1.Stop();
  7469. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7470. return;
  7471. }
  7472. string[] cavitySNs = cavityData.Split('.');
  7473. if (cavitySNs != null && cavitySNs.Length >= 1)
  7474. partNo = cavitySNs[0];
  7475. #endregion 查询载具上的产品信息
  7476. partNos.Add(partNo);
  7477. }
  7478. }
  7479. // 统一上传
  7480. stopwatch2.Start();
  7481. List<int> results = new List<int>();
  7482. for (int i = 0; i < partNos.Count; i++)
  7483. {
  7484. string index = (i + 1).ToString(); // 弹夹穴号
  7485. if (string.IsNullOrEmpty(partNos[i]))
  7486. results.Add(1);
  7487. else
  7488. {
  7489. List<TestItem> items1 = new List<TestItem>();
  7490. items1.Add(new TestItem()
  7491. {
  7492. Parameter_name = "弹夹码",
  7493. Parameter_value = sn,
  7494. Parameter_unit = ""
  7495. });
  7496. items1.Add(new TestItem()
  7497. {
  7498. Parameter_name = "弹夹穴号",
  7499. Parameter_value = index,
  7500. Parameter_unit = ""
  7501. });
  7502. items1.Add(new TestItem()
  7503. {
  7504. Parameter_name = "载具码",
  7505. Parameter_value = vehicleCodes[i],
  7506. Parameter_unit = ""
  7507. });
  7508. items1.Add(new TestItem()
  7509. {
  7510. Parameter_name = "载具穴号",
  7511. Parameter_value = "1",
  7512. Parameter_unit = ""
  7513. });
  7514. items1.Add(new TestItem()
  7515. {
  7516. Parameter_name = "产品结果",
  7517. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7518. Parameter_unit = ""
  7519. });
  7520. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7521. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7522. results.Add(result1);
  7523. }
  7524. }
  7525. short result = 0;
  7526. if (results.All(a => a == 1))
  7527. result = 1;
  7528. else if (results.Contains(3))
  7529. result = 3;
  7530. else if (results.Contains(2))
  7531. result = 2;
  7532. else if (results.Contains(4))
  7533. result = 4;
  7534. else
  7535. result = 4;
  7536. stopwatch2.Stop();
  7537. #region 存储绑定数据到 边线MES系统中
  7538. if (result == 1)
  7539. {
  7540. string data = string.Join(".", vehicleCodes);
  7541. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7542. if (resultMesR != 0)
  7543. {
  7544. result = 4;
  7545. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7546. }
  7547. }
  7548. #endregion 存储绑定数据到 边线MES系统中
  7549. // MES_Flag 为4MES报错
  7550. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7551. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7552. writeToPLC_Flag.Name = "d1MES_FLAG";
  7553. writeToPLC_Flag.Adress = 2065;
  7554. writeToPLC_Flag.Value = result;
  7555. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7556. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7557. }
  7558. catch (Exception ex)
  7559. {
  7560. stopwatch2.Restart();
  7561. // MES_Flag 为4上位机报错
  7562. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7563. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7564. writeToPLC_Flag.Name = "d1MES_FLAG";
  7565. writeToPLC_Flag.Adress = 2065;
  7566. writeToPLC_Flag.Value = (short)4;
  7567. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7568. stopwatch2.Stop();
  7569. string str = ex.StackTrace;
  7570. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7571. }
  7572. stopwatch1.Stop();
  7573. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7574. }
  7575. /// <summary>
  7576. /// [S4] 取放桁架 - S4_1节拍接口
  7577. /// </summary>
  7578. /// <param name="plcNo">PLC编号</param>
  7579. /// <param name="stationNameStr">工站全称</param>
  7580. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7581. {
  7582. Stopwatch stopwatch1 = new Stopwatch();
  7583. Stopwatch stopwatch2 = new Stopwatch();
  7584. string resultStr = string.Empty;
  7585. try
  7586. {
  7587. stopwatch1.Start();
  7588. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7589. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7590. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7591. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7592. if (!actionBool)
  7593. {
  7594. stopwatch2.Start();
  7595. // MES_Flag
  7596. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7597. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7598. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7599. writeToPLC_Flag1.Adress = 2398;
  7600. writeToPLC_Flag1.Value = (short)4;
  7601. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7602. stopwatch2.Stop();
  7603. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7604. return;
  7605. }
  7606. string d1OEEPartNo = string.Empty; // 物料码
  7607. if (string.IsNullOrEmpty(d1OEEProductSN))
  7608. {
  7609. stopwatch2.Start();
  7610. // MES_Flag
  7611. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7612. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7613. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7614. writeToPLC_Flag1.Adress = 2398;
  7615. writeToPLC_Flag1.Value = (short)1;
  7616. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7617. stopwatch2.Stop();
  7618. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7619. return;
  7620. }
  7621. else
  7622. { // 查产品SN ZS
  7623. d1OEEPartNo = "Test";
  7624. }
  7625. short d1OEEMES_FLAG = 0;
  7626. // 上传OEE
  7627. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7628. d1OEEMES_FLAG = result.Item1;
  7629. resultStr = result.Item2;
  7630. stopwatch2.Start();
  7631. // MES_Flag
  7632. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7633. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7634. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7635. writeToPLC_Flag.Adress = 2398;
  7636. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7637. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7638. stopwatch2.Stop();
  7639. }
  7640. catch (Exception ex)
  7641. {
  7642. string str = ex.StackTrace;
  7643. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7644. // MES_Flag
  7645. stopwatch2.Start();
  7646. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7647. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7648. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7649. writeToPLC_Flag.Adress = 2398;
  7650. writeToPLC_Flag.Value = (short)4;
  7651. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7652. stopwatch2.Stop();
  7653. }
  7654. stopwatch1.Stop();
  7655. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7656. }
  7657. /// <summary>
  7658. /// [S4] 取放桁架 - S4_2桁架
  7659. /// </summary>
  7660. /// <param name="plcNo">PLC编号</param>
  7661. /// <param name="stationNameStr">工站全称</param>
  7662. private void S4_2桁架(int plcNo, string stationNameStr)
  7663. {
  7664. Stopwatch stopwatch1 = new Stopwatch();
  7665. Stopwatch stopwatch2 = new Stopwatch();
  7666. try
  7667. {
  7668. stopwatch1.Start();
  7669. // ZS 弹夹扫码
  7670. string d2BulletclipCode = " "; // 扫到的码
  7671. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7672. short d2BulletclipScanCode = 2;
  7673. stopwatch2.Start();
  7674. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7675. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7676. //// MES_Flag
  7677. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7678. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7679. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7680. writeToPLC_Flag.Adress = 2430;
  7681. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7682. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7683. {
  7684. Name = "d2BulletclipCode",
  7685. Adress = 2432,
  7686. ValueType = PLCValueType.String,
  7687. ValueTypeStrLength = 20,
  7688. Value = d2BulletclipCode
  7689. });
  7690. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7691. {
  7692. Name = "d2BulletclipStates",
  7693. Adress = 2431,
  7694. ValueType = PLCValueType.Short,
  7695. Value = d2BulletclipStates
  7696. });
  7697. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7698. stopwatch2.Stop();
  7699. }
  7700. catch (Exception ex)
  7701. {
  7702. string str = ex.StackTrace;
  7703. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7704. stopwatch2.Start();
  7705. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7706. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7707. // MES_Flag
  7708. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7709. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7710. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7711. writeToPLC_Flag.Adress = 2430;
  7712. writeToPLC_Flag.Value = (short)6;
  7713. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7714. {
  7715. Name = "d2BulletclipCode",
  7716. Adress = 2432,
  7717. ValueType = PLCValueType.String,
  7718. ValueTypeStrLength = 20,
  7719. Value = " "
  7720. });
  7721. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7722. {
  7723. Name = "d2BulletclipStates",
  7724. Adress = 2431,
  7725. ValueType = PLCValueType.Short,
  7726. Value = (short)0
  7727. });
  7728. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7729. stopwatch2.Stop();
  7730. }
  7731. stopwatch1.Stop();
  7732. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7733. }
  7734. // 上次采集到的SN
  7735. //private string sn_S4_3进站接口 = string.Empty;
  7736. /// <summary>
  7737. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7738. /// </summary>
  7739. private void S4_3进站接口(int plcNo, string stationNameStr)
  7740. {
  7741. Stopwatch stopwatch1 = new Stopwatch();
  7742. Stopwatch stopwatch2 = new Stopwatch();
  7743. try
  7744. {
  7745. stopwatch1.Start();
  7746. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7747. sn = sn.Replace("\0", "");
  7748. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7749. #region 查询15个载具码
  7750. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7751. string vehicleData = string.Empty;
  7752. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7753. if (string.IsNullOrEmpty(vehicleData))
  7754. vehicleData = "";
  7755. if (snResult != 0)
  7756. {
  7757. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7758. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7759. writeToPLC_Flag1.Adress = 2463;
  7760. writeToPLC_Flag1.Value = (short)4;
  7761. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7762. stopwatch1.Stop();
  7763. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7764. return;
  7765. }
  7766. string[] cavitySNs = vehicleData.Split('.');
  7767. if (cavitySNs != null && cavitySNs.Length > 0)
  7768. {
  7769. for (int i = 0; i < cavitySNs.Length; i++)
  7770. {
  7771. if (string.IsNullOrEmpty(cavitySNs[i]))
  7772. vehicleCodes.Add("");
  7773. else
  7774. vehicleCodes.Add(cavitySNs[i]);
  7775. }
  7776. }
  7777. #endregion 查询15个载具码
  7778. #region 查询15个产品SN
  7779. List<string> portNos = new List<string>(); // 15个产品SN
  7780. foreach (string vehicleCode in vehicleCodes)
  7781. {
  7782. if (string.IsNullOrEmpty(vehicleCode))
  7783. portNos.Add("");
  7784. else
  7785. {
  7786. // 查询
  7787. string cavityData = string.Empty;
  7788. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7789. if (string.IsNullOrEmpty(cavityData))
  7790. cavityData = "";
  7791. if (snResult1 != 0)
  7792. {
  7793. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7794. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7795. writeToPLC_Flag1.Adress = 2463;
  7796. writeToPLC_Flag1.Value = (short)4;
  7797. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7798. stopwatch1.Stop();
  7799. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7800. return;
  7801. }
  7802. string[] partSNs = cavityData.Split('.');
  7803. if (partSNs != null && partSNs.Length >= 1)
  7804. portNos.Add(partSNs[0]);
  7805. else
  7806. portNos.Add("");
  7807. }
  7808. }
  7809. #endregion 查询15个产品SN
  7810. // 调用MES进站(最多15个)
  7811. stopwatch2.Start();
  7812. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7813. for (int i = 0; i < vehicleCodes.Count; i++)
  7814. {
  7815. // 循环进站
  7816. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7817. {
  7818. // 产品SN(物料码)校验
  7819. string portNo = portNos[i];
  7820. List<TestItem> item = new List<TestItem>();
  7821. item.Add(new TestItem()
  7822. {
  7823. Parameter_name = "弹夹码",
  7824. Parameter_value = sn,
  7825. });
  7826. item.Add(new TestItem()
  7827. {
  7828. Parameter_name = "弹夹穴位",
  7829. Parameter_value = (i + 1).ToString(),
  7830. });
  7831. item.Add(new TestItem()
  7832. {
  7833. Parameter_name = "载具码",
  7834. Parameter_value = vehicleCodes[i],
  7835. });
  7836. item.Add(new TestItem()
  7837. {
  7838. Parameter_name = "载具穴号",
  7839. Parameter_value = "1",
  7840. });
  7841. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7842. }
  7843. }
  7844. stopwatch2.Stop();
  7845. short result = 0;
  7846. bool haveMesWarn = results.Contains(5);
  7847. bool havePCWarn = results.Contains(6);
  7848. if (haveMesWarn)
  7849. result = 2; // 5->2
  7850. else if (havePCWarn)
  7851. result = 6; // 6->4
  7852. else
  7853. result = 1;
  7854. // MES_Flag 为4MES报错
  7855. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7856. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7857. writeToPLC_Flag.Name = "d3MES_FLAG";
  7858. writeToPLC_Flag.Adress = 2463;
  7859. writeToPLC_Flag.Value = result;
  7860. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7861. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7862. }
  7863. catch (Exception ex)
  7864. {
  7865. stopwatch2.Stop();
  7866. // MES_Flag 为4上位机报错
  7867. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7868. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7869. writeToPLC_Flag.Name = "d3MES_FLAG";
  7870. writeToPLC_Flag.Adress = 2463;
  7871. writeToPLC_Flag.Value = (short)4;
  7872. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7873. string str = ex.StackTrace;
  7874. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7875. }
  7876. stopwatch1.Stop();
  7877. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7878. }
  7879. // 上次采集到的SN
  7880. //private string sn_S4_3出站接口 = string.Empty;
  7881. /// <summary>
  7882. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7883. /// </summary>
  7884. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7885. {
  7886. Stopwatch stopwatch1 = new Stopwatch();
  7887. Stopwatch stopwatch2 = new Stopwatch();
  7888. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7889. string stationNameStr = stationCode + stationName;
  7890. string processItem = stationName; // 测试项目
  7891. try
  7892. {
  7893. stopwatch1.Start();
  7894. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7895. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7896. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7897. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7898. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7899. sn = sn.Replace("\0", "");
  7900. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7901. bool isPass = d3Result == 1; // 产品结果 bool
  7902. #region 查询15个载具码
  7903. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7904. string vehicleData = string.Empty;
  7905. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7906. if (string.IsNullOrEmpty(vehicleData))
  7907. vehicleData = "";
  7908. if (snResult1 != 0)
  7909. {
  7910. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7911. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7912. writeToPLC_Flag1.Adress = 2463;
  7913. writeToPLC_Flag1.Value = (short)4;
  7914. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7915. stopwatch1.Stop();
  7916. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7917. return;
  7918. }
  7919. string[] cavitySNs = vehicleData.Split('.');
  7920. if (cavitySNs != null && cavitySNs.Length > 0)
  7921. {
  7922. for (int i = 0; i < cavitySNs.Length; i++)
  7923. {
  7924. if (string.IsNullOrEmpty(cavitySNs[i]))
  7925. vehicleCodes.Add("");
  7926. else
  7927. vehicleCodes.Add(cavitySNs[i]);
  7928. }
  7929. }
  7930. #endregion 查询15个载具码
  7931. // 统一查 产品SN列表
  7932. List<string> partNos = new List<string>();
  7933. foreach (string vehicleCode in vehicleCodes)
  7934. {
  7935. if (string.IsNullOrEmpty(vehicleCode))
  7936. partNos.Add("");
  7937. else
  7938. {
  7939. string partNo = "";
  7940. #region 查询载具上的产品信息
  7941. string cavityData = string.Empty;
  7942. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7943. if (string.IsNullOrEmpty(cavityData))
  7944. cavityData = "";
  7945. if (snResult != 0)
  7946. {
  7947. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7948. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7949. writeToPLC_Flag1.Adress = 2463;
  7950. writeToPLC_Flag1.Value = (short)4;
  7951. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7952. stopwatch1.Stop();
  7953. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7954. return;
  7955. }
  7956. string[] partSNs = cavityData.Split('.');
  7957. if (partSNs != null && partSNs.Length >= 1)
  7958. partNo = partSNs[0];
  7959. #endregion 查询载具上的产品信息
  7960. partNos.Add(partNo);
  7961. }
  7962. }
  7963. // 统一上传 - 调用MES出站
  7964. stopwatch2.Start();
  7965. List<int> results = new List<int>();
  7966. for (int i = 0; i < partNos.Count; i++)
  7967. {
  7968. string index = (i + 1).ToString(); // 弹夹穴号
  7969. if (string.IsNullOrEmpty(partNos[i]))
  7970. results.Add(1);
  7971. else
  7972. {
  7973. List<TestItem> items1 = new List<TestItem>();
  7974. items1.Add(new TestItem()
  7975. {
  7976. Parameter_name = "弹夹码",
  7977. Parameter_value = sn,
  7978. Parameter_unit = ""
  7979. });
  7980. items1.Add(new TestItem()
  7981. {
  7982. Parameter_name = "弹夹穴号",
  7983. Parameter_value = index,
  7984. Parameter_unit = ""
  7985. });
  7986. items1.Add(new TestItem()
  7987. {
  7988. Parameter_name = "载具码",
  7989. Parameter_value = vehicleCodes[i],
  7990. Parameter_unit = ""
  7991. });
  7992. items1.Add(new TestItem()
  7993. {
  7994. Parameter_name = "载具穴号",
  7995. Parameter_value = "1",
  7996. Parameter_unit = ""
  7997. });
  7998. items1.Add(new TestItem()
  7999. {
  8000. Parameter_name = "产品结果",
  8001. Parameter_value = d3Result == 1 ? "OK" : "NG",
  8002. Parameter_unit = ""
  8003. });
  8004. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8005. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8006. results.Add(result1);
  8007. }
  8008. }
  8009. short result = 0;
  8010. if (results.All(a => a == 1))
  8011. result = 1;
  8012. else if (results.Contains(3))
  8013. result = 3;
  8014. else if (results.Contains(2))
  8015. result = 2;
  8016. else if (results.Contains(4))
  8017. result = 4;
  8018. else
  8019. result = 4;
  8020. stopwatch2.Stop();
  8021. // MES_Flag 为4MES报错
  8022. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8023. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8024. writeToPLC_Flag.Name = "d3MES_FLAG";
  8025. writeToPLC_Flag.Adress = 2463;
  8026. writeToPLC_Flag.Value = result;
  8027. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8028. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8029. }
  8030. catch (Exception ex)
  8031. {
  8032. stopwatch2.Restart();
  8033. // MES_Flag 为4上位机报错
  8034. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  8035. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8036. writeToPLC_Flag.Name = "d3MES_FLAG";
  8037. writeToPLC_Flag.Adress = 2463;
  8038. writeToPLC_Flag.Value = (short)4;
  8039. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8040. string str = ex.StackTrace;
  8041. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8042. stopwatch2.Stop();
  8043. }
  8044. stopwatch1.Stop();
  8045. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8046. }
  8047. // 上次采集到的SN
  8048. //private string sn_S4_4进站接口 = string.Empty;
  8049. /// <summary>
  8050. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  8051. /// </summary>
  8052. private void S4_4进站接口(int plcNo, string stationNameStr)
  8053. {
  8054. Stopwatch stopwatch1 = new Stopwatch();
  8055. Stopwatch stopwatch2 = new Stopwatch();
  8056. try
  8057. {
  8058. stopwatch1.Start();
  8059. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8060. sn = sn.Replace("\0", "");
  8061. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8062. #region 查询15个载具码
  8063. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8064. string vehicleData = string.Empty;
  8065. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8066. if (string.IsNullOrEmpty(vehicleData))
  8067. vehicleData = "";
  8068. if (snResult != 0)
  8069. {
  8070. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8071. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8072. writeToPLC_Flag1.Adress = 2463;
  8073. writeToPLC_Flag1.Value = (short)4;
  8074. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8075. stopwatch1.Stop();
  8076. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8077. return;
  8078. }
  8079. string[] cavitySNs = vehicleData.Split('.');
  8080. if (cavitySNs != null && cavitySNs.Length > 0)
  8081. {
  8082. for (int i = 0; i < cavitySNs.Length; i++)
  8083. {
  8084. if (string.IsNullOrEmpty(cavitySNs[i]))
  8085. vehicleCodes.Add("");
  8086. else
  8087. vehicleCodes.Add(cavitySNs[i]);
  8088. }
  8089. }
  8090. #endregion 查询15个载具码
  8091. #region 查询15个产品SN
  8092. List<string> portNos = new List<string>(); // 15个产品SN
  8093. foreach (string vehicleCode in vehicleCodes)
  8094. {
  8095. if (string.IsNullOrEmpty(vehicleCode))
  8096. portNos.Add("");
  8097. else
  8098. {
  8099. // 查询
  8100. string cavityData = string.Empty;
  8101. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8102. if (string.IsNullOrEmpty(cavityData))
  8103. cavityData = "";
  8104. if (snResult1 != 0)
  8105. {
  8106. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8107. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8108. writeToPLC_Flag1.Adress = 2463;
  8109. writeToPLC_Flag1.Value = (short)4;
  8110. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8111. stopwatch1.Stop();
  8112. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8113. return;
  8114. }
  8115. string[] partSNs = cavityData.Split('.');
  8116. if (partSNs != null && partSNs.Length >= 1)
  8117. portNos.Add(partSNs[0]);
  8118. else
  8119. portNos.Add("");
  8120. }
  8121. }
  8122. #endregion 查询15个产品SN
  8123. // 调用MES进站(最多15个)
  8124. stopwatch2.Start();
  8125. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8126. for (int i = 0; i < vehicleCodes.Count; i++)
  8127. {
  8128. // 循环进站
  8129. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8130. {
  8131. // 产品SN(物料码)校验
  8132. string portNo = portNos[i];
  8133. List<TestItem> item = new List<TestItem>();
  8134. item.Add(new TestItem()
  8135. {
  8136. Parameter_name = "弹夹码",
  8137. Parameter_value = sn,
  8138. });
  8139. item.Add(new TestItem()
  8140. {
  8141. Parameter_name = "弹夹穴位",
  8142. Parameter_value = (i + 1).ToString(),
  8143. });
  8144. item.Add(new TestItem()
  8145. {
  8146. Parameter_name = "载具码",
  8147. Parameter_value = vehicleCodes[i],
  8148. });
  8149. item.Add(new TestItem()
  8150. {
  8151. Parameter_name = "载具穴号",
  8152. Parameter_value = "1",
  8153. });
  8154. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8155. }
  8156. }
  8157. stopwatch2.Stop();
  8158. short result = 0;
  8159. bool haveMesWarn = results.Contains(5);
  8160. bool havePCWarn = results.Contains(6);
  8161. if (haveMesWarn)
  8162. result = 2; // 5->2
  8163. else if (havePCWarn)
  8164. result = 6; // 6->4
  8165. else
  8166. result = 1;
  8167. // MES_Flag 为4MES报错
  8168. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8169. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8170. writeToPLC_Flag.Name = "d4MES_FLAG";
  8171. writeToPLC_Flag.Adress = 2496;
  8172. writeToPLC_Flag.Value = result;
  8173. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8174. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8175. }
  8176. catch (Exception ex)
  8177. {
  8178. stopwatch2.Stop();
  8179. // MES_Flag 为4上位机报错
  8180. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8181. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8182. writeToPLC_Flag.Name = "d4MES_FLAG";
  8183. writeToPLC_Flag.Adress = 2496;
  8184. writeToPLC_Flag.Value = (short)4;
  8185. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8186. string str = ex.StackTrace;
  8187. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8188. }
  8189. stopwatch1.Stop();
  8190. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8191. }
  8192. // 上次采集到的SN
  8193. //private string sn_S4_4出站接口 = string.Empty;
  8194. /// <summary>
  8195. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8196. /// </summary>
  8197. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8198. {
  8199. Stopwatch stopwatch1 = new Stopwatch();
  8200. Stopwatch stopwatch2 = new Stopwatch();
  8201. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8202. string stationNameStr = stationCode + stationName;
  8203. string processItem = stationName; // 测试项目
  8204. try
  8205. {
  8206. stopwatch1.Start();
  8207. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8208. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8209. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8210. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8211. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8212. sn = sn.Replace("\0", "");
  8213. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8214. bool isPass = d4Result == 1; // 产品结果 bool
  8215. #region 查询15个载具码
  8216. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8217. string vehicleData = string.Empty;
  8218. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8219. if (string.IsNullOrEmpty(vehicleData))
  8220. vehicleData = "";
  8221. if (snResult1 != 0)
  8222. {
  8223. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8224. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8225. writeToPLC_Flag1.Adress = 2496;
  8226. writeToPLC_Flag1.Value = (short)4;
  8227. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8228. stopwatch1.Stop();
  8229. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8230. return;
  8231. }
  8232. string[] cavitySNs = vehicleData.Split('.');
  8233. if (cavitySNs != null && cavitySNs.Length > 0)
  8234. {
  8235. for (int i = 0; i < cavitySNs.Length; i++)
  8236. {
  8237. if (string.IsNullOrEmpty(cavitySNs[i]))
  8238. vehicleCodes.Add("");
  8239. else
  8240. vehicleCodes.Add(cavitySNs[i]);
  8241. }
  8242. }
  8243. #endregion 查询15个载具码
  8244. // 统一查 产品SN列表
  8245. List<string> partNos = new List<string>();
  8246. foreach (string vehicleCode in vehicleCodes)
  8247. {
  8248. if (string.IsNullOrEmpty(vehicleCode))
  8249. partNos.Add("");
  8250. else
  8251. {
  8252. string partNo = "";
  8253. #region 查询载具上的产品信息
  8254. string cavityData = string.Empty;
  8255. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8256. if (string.IsNullOrEmpty(cavityData))
  8257. cavityData = "";
  8258. if (snResult != 0)
  8259. {
  8260. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8261. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8262. writeToPLC_Flag1.Adress = 2496;
  8263. writeToPLC_Flag1.Value = (short)4;
  8264. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8265. stopwatch1.Stop();
  8266. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8267. return;
  8268. }
  8269. string[] partSNs = cavityData.Split('.');
  8270. if (partSNs != null && partSNs.Length >= 1)
  8271. partNo = partSNs[0];
  8272. #endregion 查询载具上的产品信息
  8273. partNos.Add(partNo);
  8274. }
  8275. }
  8276. // 调用MES出站
  8277. stopwatch2.Start();
  8278. // 统一上传
  8279. List<int> results = new List<int>();
  8280. for (int i = 0; i < partNos.Count; i++)
  8281. {
  8282. string index = (i + 1).ToString(); // 弹夹穴号
  8283. if (string.IsNullOrEmpty(partNos[i]))
  8284. results.Add(1);
  8285. else
  8286. {
  8287. List<TestItem> items1 = new List<TestItem>();
  8288. items1.Add(new TestItem()
  8289. {
  8290. Parameter_name = "弹夹码",
  8291. Parameter_value = sn,
  8292. Parameter_unit = ""
  8293. });
  8294. items1.Add(new TestItem()
  8295. {
  8296. Parameter_name = "弹夹穴号",
  8297. Parameter_value = index,
  8298. Parameter_unit = ""
  8299. });
  8300. items1.Add(new TestItem()
  8301. {
  8302. Parameter_name = "载具码",
  8303. Parameter_value = vehicleCodes[i],
  8304. Parameter_unit = ""
  8305. });
  8306. items1.Add(new TestItem()
  8307. {
  8308. Parameter_name = "载具穴号",
  8309. Parameter_value = "1",
  8310. Parameter_unit = ""
  8311. });
  8312. items1.Add(new TestItem()
  8313. {
  8314. Parameter_name = "产品结果",
  8315. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8316. Parameter_unit = ""
  8317. });
  8318. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8319. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8320. results.Add(result1);
  8321. }
  8322. }
  8323. short result = 0;
  8324. if (results.All(a => a == 1))
  8325. result = 1;
  8326. else if (results.Contains(3))
  8327. result = 3;
  8328. else if (results.Contains(2))
  8329. result = 2;
  8330. else if (results.Contains(4))
  8331. result = 4;
  8332. else
  8333. result = 4;
  8334. stopwatch2.Stop();
  8335. // MES_Flag 为4MES报错
  8336. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8337. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8338. writeToPLC_Flag.Name = "d4MES_FLAG";
  8339. writeToPLC_Flag.Adress = 2496;
  8340. writeToPLC_Flag.Value = result;
  8341. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8342. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8343. }
  8344. catch (Exception ex)
  8345. {
  8346. stopwatch2.Restart();
  8347. // MES_Flag 为4上位机报错
  8348. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8349. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8350. writeToPLC_Flag.Name = "d4MES_FLAG";
  8351. writeToPLC_Flag.Adress = 2496;
  8352. writeToPLC_Flag.Value = (short)4;
  8353. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8354. string str = ex.StackTrace;
  8355. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8356. stopwatch2.Stop();
  8357. }
  8358. stopwatch1.Stop();
  8359. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8360. }
  8361. /// <summary>
  8362. /// [S4] 取放桁架 - S4_5弹夹扫码
  8363. /// </summary>
  8364. /// <param name="plcNo">PLC编号</param>
  8365. /// <param name="stationNameStr">工站全称</param>
  8366. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8367. {
  8368. Stopwatch stopwatch1 = new Stopwatch();
  8369. Stopwatch stopwatch2 = new Stopwatch();
  8370. try
  8371. {
  8372. stopwatch1.Start();
  8373. // ZS 弹夹扫码
  8374. string d5BulletclipCode = " "; // 扫到的码
  8375. short d5BulletclipScanCode = 2;
  8376. stopwatch2.Start();
  8377. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8378. //// MES_Flag
  8379. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8380. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8381. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8382. writeToPLC_Flag.Adress = 2528;
  8383. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8384. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8385. {
  8386. Name = "d5BulletclipCode",
  8387. Adress = 2529,
  8388. ValueType = PLCValueType.String,
  8389. ValueTypeStrLength = 20,
  8390. Value = d5BulletclipCode
  8391. });
  8392. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8393. stopwatch2.Stop();
  8394. }
  8395. catch (Exception ex)
  8396. {
  8397. string str = ex.StackTrace;
  8398. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8399. stopwatch2.Start();
  8400. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8401. //// MES_Flag
  8402. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8403. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8404. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8405. writeToPLC_Flag.Adress = 2528;
  8406. writeToPLC_Flag.Value = (short)6;
  8407. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8408. {
  8409. Name = "d5BulletclipCode",
  8410. Adress = 2529,
  8411. ValueType = PLCValueType.String,
  8412. ValueTypeStrLength = 20,
  8413. Value = " "
  8414. });
  8415. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8416. stopwatch2.Stop();
  8417. }
  8418. stopwatch1.Stop();
  8419. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8420. }
  8421. /// <summary>
  8422. /// [S4] 取放桁架 - S4_5载具扫码
  8423. /// </summary>
  8424. /// <param name="plcNo">PLC编号</param>
  8425. /// <param name="stationNameStr">工站全称</param>
  8426. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8427. {
  8428. Stopwatch stopwatch1 = new Stopwatch();
  8429. Stopwatch stopwatch2 = new Stopwatch();
  8430. try
  8431. {
  8432. stopwatch1.Start();
  8433. // ZS 载具扫码
  8434. string d5VehicleCode = " "; // 扫到的码
  8435. short d5VehicleScanCode = 2;
  8436. #region 进站
  8437. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8438. {
  8439. // 查产品SN
  8440. #region 查询载具上的产品信息
  8441. string cavityData = string.Empty;
  8442. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8443. if (string.IsNullOrEmpty(cavityData))
  8444. cavityData = "";
  8445. if (snResult != 0)
  8446. {
  8447. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8448. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8449. writeToPLC_Flag1.Adress = 2559;
  8450. writeToPLC_Flag1.Value = (short)6;
  8451. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8452. {
  8453. Name = "d5VehicleCode",
  8454. Adress = 2560,
  8455. ValueType = PLCValueType.String,
  8456. ValueTypeStrLength = 20,
  8457. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8458. });
  8459. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8460. stopwatch1.Stop();
  8461. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8462. return;
  8463. }
  8464. string[] cavitySNs = cavityData.Split('.');
  8465. string partNo = "";
  8466. if (cavitySNs != null && cavitySNs.Length >= 1)
  8467. {
  8468. partNo = cavitySNs[0];
  8469. }
  8470. #endregion 查询载具上的产品信息
  8471. List<TestItem> item = new List<TestItem>();
  8472. item.Add(new TestItem()
  8473. {
  8474. Parameter_name = "载具码",
  8475. Parameter_value = d5VehicleCode,
  8476. });
  8477. item.Add(new TestItem()
  8478. {
  8479. Parameter_name = "载具穴号",
  8480. Parameter_value = "1",
  8481. });
  8482. stopwatch2.Start();
  8483. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8484. stopwatch2.Stop();
  8485. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8486. }
  8487. #endregion 进站
  8488. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8489. //// MES_Flag
  8490. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8491. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8492. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8493. writeToPLC_Flag.Adress = 2559;
  8494. writeToPLC_Flag.Value = d5VehicleScanCode;
  8495. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8496. {
  8497. Name = "d5VehicleCode",
  8498. Adress = 2560,
  8499. ValueType = PLCValueType.String,
  8500. ValueTypeStrLength = 20,
  8501. Value = d5VehicleCode
  8502. });
  8503. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8504. }
  8505. catch (Exception ex)
  8506. {
  8507. string str = ex.StackTrace;
  8508. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8509. stopwatch2.Start();
  8510. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8511. //// MES_Flag
  8512. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8513. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8514. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8515. writeToPLC_Flag.Adress = 2559;
  8516. writeToPLC_Flag.Value = (short)6;
  8517. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8518. {
  8519. Name = "d5VehicleCode",
  8520. Adress = 2560,
  8521. ValueType = PLCValueType.String,
  8522. ValueTypeStrLength = 20,
  8523. Value = " "
  8524. });
  8525. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8526. stopwatch2.Stop();
  8527. }
  8528. stopwatch1.Stop();
  8529. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8530. }
  8531. // 上次采集到的SN
  8532. //private string sn_S4_5出站接口 = string.Empty;
  8533. /// <summary>
  8534. /// [S4] 取放桁架 - S4_5出站接口
  8535. /// </summary>
  8536. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8537. {
  8538. Stopwatch stopwatch1 = new Stopwatch();
  8539. Stopwatch stopwatch2 = new Stopwatch();
  8540. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8541. string stationNameStr = stationCode + stationName;
  8542. string processItem = stationName; // 测试项目
  8543. try
  8544. {
  8545. stopwatch1.Start();
  8546. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8547. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8548. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8549. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8550. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8551. sn = sn.Replace("\0", "");
  8552. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8553. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8554. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8555. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8556. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8557. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8558. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8559. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8560. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8561. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8562. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8563. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8564. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8565. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8566. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8567. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8568. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8569. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8570. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8571. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8572. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8573. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8574. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8575. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8576. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8577. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8578. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8579. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8580. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8581. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8582. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8583. bool pass = d5Result == 1;
  8584. // 存 载具SN列表
  8585. List<string> vehicleCodes = new List<string>()
  8586. {
  8587. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8588. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8589. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8590. };
  8591. // 统一查 产品SN列表
  8592. List<string> partNos = new List<string>();
  8593. foreach (string vehicleCode in vehicleCodes)
  8594. {
  8595. if (string.IsNullOrEmpty(vehicleCode))
  8596. partNos.Add("");
  8597. else
  8598. {
  8599. string partNo = "";
  8600. #region 查询载具上的产品信息
  8601. string cavityData = string.Empty;
  8602. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8603. if (string.IsNullOrEmpty(cavityData))
  8604. cavityData = "";
  8605. if (snResult != 0)
  8606. {
  8607. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8608. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8609. writeToPLC_Flag1.Adress = 2591;
  8610. writeToPLC_Flag1.Value = (short)4;
  8611. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8612. stopwatch1.Stop();
  8613. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8614. return;
  8615. }
  8616. string[] cavitySNs = cavityData.Split('.');
  8617. if (cavitySNs != null && cavitySNs.Length >= 1)
  8618. partNo = cavitySNs[0];
  8619. #endregion 查询载具上的产品信息
  8620. partNos.Add(partNo);
  8621. }
  8622. }
  8623. // 统一上传
  8624. stopwatch2.Start();
  8625. List<int> results = new List<int>();
  8626. for (int i = 0; i < partNos.Count; i++)
  8627. {
  8628. string index = (i + 1).ToString(); // 弹夹穴号
  8629. if (string.IsNullOrEmpty(partNos[i]))
  8630. results.Add(1);
  8631. else
  8632. {
  8633. List<TestItem> items1 = new List<TestItem>();
  8634. items1.Add(new TestItem()
  8635. {
  8636. Parameter_name = "弹夹码",
  8637. Parameter_value = sn,
  8638. Parameter_unit = ""
  8639. });
  8640. items1.Add(new TestItem()
  8641. {
  8642. Parameter_name = "弹夹穴号",
  8643. Parameter_value = index,
  8644. Parameter_unit = ""
  8645. });
  8646. items1.Add(new TestItem()
  8647. {
  8648. Parameter_name = "载具码",
  8649. Parameter_value = vehicleCodes[i],
  8650. Parameter_unit = ""
  8651. });
  8652. items1.Add(new TestItem()
  8653. {
  8654. Parameter_name = "载具穴号",
  8655. Parameter_value = "1",
  8656. Parameter_unit = ""
  8657. });
  8658. items1.Add(new TestItem()
  8659. {
  8660. Parameter_name = "产品结果",
  8661. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8662. Parameter_unit = ""
  8663. });
  8664. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8665. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8666. results.Add(result1);
  8667. }
  8668. }
  8669. short result = 0;
  8670. if (results.All(a => a == 1))
  8671. result = 1;
  8672. else if (results.Contains(3))
  8673. result = 3;
  8674. else if (results.Contains(2))
  8675. result = 2;
  8676. else if (results.Contains(4))
  8677. result = 4;
  8678. else
  8679. result = 4;
  8680. stopwatch2.Stop();
  8681. #region 存储绑定数据到 边线MES系统中
  8682. if (result == 1)
  8683. {
  8684. // 删除绑定信息
  8685. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8686. if (resultMesR != 0)
  8687. {
  8688. result = 4;
  8689. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8690. }
  8691. }
  8692. #endregion 存储绑定数据到 边线MES系统中
  8693. // MES_Flag 为4MES报错
  8694. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8695. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8696. writeToPLC_Flag.Name = "d5MES_FLAG";
  8697. writeToPLC_Flag.Adress = 2591;
  8698. writeToPLC_Flag.Value = result;
  8699. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8700. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8701. }
  8702. catch (Exception ex)
  8703. {
  8704. stopwatch2.Restart();
  8705. // MES_Flag 为4上位机报错
  8706. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8707. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8708. writeToPLC_Flag.Name = "d5MES_FLAG";
  8709. writeToPLC_Flag.Adress = 2591;
  8710. writeToPLC_Flag.Value = (short)4;
  8711. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8712. stopwatch2.Stop();
  8713. string str = ex.StackTrace;
  8714. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8715. }
  8716. stopwatch1.Stop();
  8717. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8718. }
  8719. /// <summary>
  8720. /// [S4] 取放桁架 - S4_5节拍接口
  8721. /// </summary>
  8722. /// <param name="plcNo">PLC编号</param>
  8723. /// <param name="stationNameStr">工站全称</param>
  8724. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8725. {
  8726. Stopwatch stopwatch1 = new Stopwatch();
  8727. Stopwatch stopwatch2 = new Stopwatch();
  8728. string resultStr = string.Empty;
  8729. try
  8730. {
  8731. stopwatch1.Start();
  8732. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8733. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8734. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8735. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8736. if (!actionBool)
  8737. {
  8738. stopwatch2.Start();
  8739. // MES_Flag
  8740. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8741. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8742. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8743. writeToPLC_Flag1.Adress = 2924;
  8744. writeToPLC_Flag1.Value = (short)4;
  8745. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8746. stopwatch2.Stop();
  8747. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8748. return;
  8749. }
  8750. string d5OEEPartNo = string.Empty; // 物料码
  8751. if (string.IsNullOrEmpty(d5OEEProductSN))
  8752. {
  8753. stopwatch2.Start();
  8754. // MES_Flag
  8755. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8756. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8757. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8758. writeToPLC_Flag1.Adress = 2924;
  8759. writeToPLC_Flag1.Value = (short)1;
  8760. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8761. stopwatch2.Stop();
  8762. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8763. return;
  8764. }
  8765. else
  8766. { // 查产品SN
  8767. d5OEEPartNo = "Test"; // ZS
  8768. }
  8769. short d5OEEMES_FLAG = 0;
  8770. // 上传OEE
  8771. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8772. d5OEEMES_FLAG = result.Item1;
  8773. resultStr = result.Item2;
  8774. stopwatch2.Start();
  8775. // MES_Flag
  8776. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8777. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8778. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8779. writeToPLC_Flag.Adress = 2924;
  8780. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8781. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8782. stopwatch2.Stop();
  8783. }
  8784. catch (Exception ex)
  8785. {
  8786. string str = ex.StackTrace;
  8787. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8788. // MES_Flag
  8789. stopwatch2.Start();
  8790. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8791. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8792. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8793. writeToPLC_Flag.Adress = 2924;
  8794. writeToPLC_Flag.Value = (short)4;
  8795. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8796. stopwatch2.Stop();
  8797. }
  8798. stopwatch1.Stop();
  8799. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8800. }
  8801. #endregion [S4] 取放桁架
  8802. #endregion PLC4 刘果段
  8803. #region PLC5 张超凡
  8804. #region [S5] Tray盘下料装备
  8805. /// <summary>
  8806. /// S5工位的数据- 触发信号上次的值
  8807. /// </summary>
  8808. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8809. /// <summary>
  8810. /// S5工位的数据(含触发信号)
  8811. /// </summary>
  8812. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8813. /// <summary>
  8814. /// S5工位的数据- 回写点位
  8815. /// </summary>
  8816. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8817. /// <summary>
  8818. /// [S5] Tray盘下料装备
  8819. /// </summary>
  8820. /// <param name="plcNo">PLC编号</param>
  8821. //private void ReadStation_S5(int plcNo)
  8822. //{
  8823. // // [S1] Tray盘上料装备
  8824. // // [S2] FCT
  8825. // // [S3] 值板机
  8826. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8827. // // [S5] Tray盘下料装备
  8828. // /// 上位机心跳
  8829. // /// 获取设备报警数据与状态信息
  8830. // string stationCode = "[S5]";
  8831. // string stationName = "Tray盘下料装备";
  8832. // string stationNameStr = stationCode + stationName;
  8833. // #region 创建字典
  8834. // // 触发信号字典 赋值
  8835. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8836. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8837. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8838. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8839. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8840. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8841. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8842. // // PLC数据字典 赋值
  8843. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8844. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8845. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8846. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8847. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8848. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8849. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8850. // s5PLCData.Add("e1Result", 0); // 产品结果
  8851. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8852. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8853. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8854. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8855. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8856. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8857. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8858. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8859. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8860. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8861. // #endregion 创建字典
  8862. // while (IsRun)
  8863. // {
  8864. // try
  8865. // {
  8866. // if (!GlobalContext._IsCon_Funs5)
  8867. // {
  8868. // UpdatePLCMonitor(1, plcNo, 0);
  8869. // continue;
  8870. // }
  8871. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8872. // {
  8873. // Stopwatch stopwatch1 = new Stopwatch();
  8874. // Stopwatch stopwatch2 = new Stopwatch();
  8875. // stopwatch1.Start();
  8876. // stopwatch2.Start();
  8877. // #region 一次性读取所有数据
  8878. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8879. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8880. // int[] datas = data1.Concat(data2).ToArray();
  8881. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8882. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8883. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8884. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8885. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8886. // s5PLCData["e1MES_FLAG"] = datas[35];
  8887. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8888. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8889. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8890. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8891. // s5PLCData["e1Result"] = datas[76];
  8892. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8893. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8894. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8895. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8896. // s5PLCData["e1OEEType"] = datas[109];
  8897. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8898. // s5PLCData["e1AGVUpStart"] = datas[121];
  8899. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8900. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8901. // s5PLCData["e1AGVDownStart"] = datas[134];
  8902. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8903. // #endregion 一次性读取所有数据
  8904. // stopwatch2.Stop();
  8905. // #region 回写操作,写后清空flag
  8906. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8907. // #endregion 回写操作,写后清空flag
  8908. // #region 进站校验
  8909. // try
  8910. // {
  8911. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8912. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8913. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  8914. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  8915. // {
  8916. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  8917. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8918. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  8919. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8920. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  8921. // }
  8922. // }
  8923. // catch (Exception ex)
  8924. // {
  8925. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8926. // string str = ex.StackTrace;
  8927. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8928. // }
  8929. // #endregion 进站校验
  8930. // #region 出站接口
  8931. // try
  8932. // {
  8933. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  8934. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  8935. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  8936. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  8937. // {
  8938. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  8939. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8940. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  8941. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  8942. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  8943. // }
  8944. // }
  8945. // catch (Exception ex)
  8946. // {
  8947. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  8948. // string str = ex.StackTrace;
  8949. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8950. // }
  8951. // #endregion 出站接口
  8952. // #region 节拍接口
  8953. // try
  8954. // {
  8955. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  8956. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  8957. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  8958. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  8959. // {
  8960. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  8961. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8962. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  8963. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  8964. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  8965. // }
  8966. // }
  8967. // catch (Exception ex)
  8968. // {
  8969. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  8970. // string str = ex.StackTrace;
  8971. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8972. // }
  8973. // #endregion 节拍接口
  8974. // #region AGV上料
  8975. // // AGV上料叫AGV信号
  8976. // try
  8977. // {
  8978. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  8979. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  8980. // if (e1AGVUpCall != e1AGVUpCallOld)
  8981. // {
  8982. // if (e1AGVUpCall == 1) // 0->1
  8983. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  8984. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  8985. // }
  8986. // }
  8987. // catch (Exception ex)
  8988. // {
  8989. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  8990. // string str = ex.StackTrace;
  8991. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8992. // }
  8993. // // AGV上料完成信号
  8994. // try
  8995. // {
  8996. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  8997. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  8998. // if (e1AGVUpEnd != e1AGVUpEndOld)
  8999. // {
  9000. // if (e1AGVUpEnd == 1) // 0->1
  9001. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  9002. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  9003. // }
  9004. // }
  9005. // catch (Exception ex)
  9006. // {
  9007. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9008. // string str = ex.StackTrace;
  9009. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9010. // }
  9011. // #endregion AGV上料
  9012. // #region AGV下料
  9013. // // AGV下料叫agv信号
  9014. // try
  9015. // {
  9016. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  9017. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  9018. // if (e1AGVDownCall != e1AGVDownCallOld)
  9019. // {
  9020. // if (e1AGVDownCall == 1) // 0->1
  9021. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  9022. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  9023. // }
  9024. // }
  9025. // catch (Exception ex)
  9026. // {
  9027. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9028. // string str = ex.StackTrace;
  9029. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9030. // }
  9031. // // AGV下料完成信号
  9032. // try
  9033. // {
  9034. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  9035. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  9036. // if (e1AGVDownEnd != e1AGVDownEndOld)
  9037. // {
  9038. // if (e1AGVDownEnd == 1) // 0->1
  9039. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  9040. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  9041. // }
  9042. // }
  9043. // catch (Exception ex)
  9044. // {
  9045. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9046. // string str = ex.StackTrace;
  9047. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9048. // }
  9049. // #endregion AGV下料
  9050. // #region 心跳
  9051. // try
  9052. // {
  9053. // short states = 0;
  9054. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9055. // }
  9056. // catch (Exception ex)
  9057. // {
  9058. // string str = ex.StackTrace;
  9059. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9060. // }
  9061. // #endregion 心跳
  9062. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9063. // stopwatch1.Stop();
  9064. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9065. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9066. // }
  9067. // else
  9068. // {
  9069. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9070. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9071. // Funs[plcNo].Connect();
  9072. // }
  9073. // }
  9074. // catch (Exception ex)
  9075. // {
  9076. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9077. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9078. // Funs[plcNo].ReConnect();
  9079. // }
  9080. // Thread.Sleep(IntervalReadPLC);
  9081. // }
  9082. //}
  9083. /// <summary>
  9084. /// [S5] Tray盘下料装备 - 进站校验
  9085. /// </summary>
  9086. /// <param name="plcNo">PLC编号</param>
  9087. /// <param name="stationNameStr">工站全称</param>
  9088. private void S5进站校验(int plcNo, string stationNameStr)
  9089. {
  9090. Stopwatch stopwatch1 = new Stopwatch();
  9091. Stopwatch stopwatch2 = new Stopwatch();
  9092. try
  9093. {
  9094. stopwatch1.Start();
  9095. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9096. sn = sn.Replace("\0", "");
  9097. // 获取产品SN By 载具码
  9098. #region 查询载具上的产品信息
  9099. string cavityData = string.Empty;
  9100. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9101. if (string.IsNullOrEmpty(cavityData))
  9102. cavityData = "";
  9103. if (snResult != 0)
  9104. {
  9105. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9106. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9107. writeToPLC_Flag1.Adress = 2003;
  9108. writeToPLC_Flag1.Value = (short)6;
  9109. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9110. stopwatch1.Stop();
  9111. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9112. return;
  9113. }
  9114. string[] cavitySNs = cavityData.Split('.');
  9115. string partNo = string.Empty;
  9116. if (cavitySNs != null && cavitySNs.Length >= 1)
  9117. partNo = cavitySNs[0];
  9118. #endregion 查询载具上的产品信息
  9119. // 产品SN(物料码)校验
  9120. List<TestItem> item = new List<TestItem>();
  9121. item.Add(new TestItem()
  9122. {
  9123. Parameter_name = "载具码",
  9124. Parameter_value = sn,
  9125. });
  9126. item.Add(new TestItem()
  9127. {
  9128. Parameter_name = "载具穴号",
  9129. Parameter_value = "1",
  9130. });
  9131. stopwatch2.Start();
  9132. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9133. stopwatch2.Stop();
  9134. short e1MES_FLAG_Check = (short)result;
  9135. // MES_Flag
  9136. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9137. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9138. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9139. writeToPLC_Flag.Adress = 2003;
  9140. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9141. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9142. }
  9143. catch (Exception ex)
  9144. {
  9145. string str = ex.StackTrace;
  9146. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9147. // MES_Flag
  9148. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9149. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9150. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9151. writeToPLC_Flag.Adress = 2003;
  9152. writeToPLC_Flag.Value = (short)6;
  9153. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9154. }
  9155. stopwatch1.Stop();
  9156. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9157. }
  9158. /// <summary>
  9159. /// [S5] Tray盘下料装备 - 出站接口
  9160. /// </summary>
  9161. /// <param name="plcNo"></param>
  9162. /// <param name="stationCode"></param>
  9163. /// <param name="stationName"></param>
  9164. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9165. {
  9166. Stopwatch stopwatch1 = new Stopwatch();
  9167. Stopwatch stopwatch2 = new Stopwatch();
  9168. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9169. string stationNameStr = stationCode + stationName;
  9170. string processItem = stationName; // 测试项目
  9171. try
  9172. {
  9173. stopwatch1.Start();
  9174. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9175. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9176. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9177. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9178. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9179. sn = sn.Replace("\0", "");
  9180. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9181. //partNo = partNo.Replace("\0", "");
  9182. #region 查询载具上的产品信息
  9183. string cavityData = string.Empty;
  9184. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9185. if (string.IsNullOrEmpty(cavityData))
  9186. cavityData = "";
  9187. if (snResult != 0)
  9188. {
  9189. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9190. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9191. writeToPLC_Flag1.Adress = 2035;
  9192. writeToPLC_Flag1.Value = (short)4;
  9193. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9194. stopwatch1.Stop();
  9195. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9196. return;
  9197. }
  9198. string[] cavitySNs = cavityData.Split('.');
  9199. string partNo = string.Empty;
  9200. if (cavitySNs != null && cavitySNs.Length >= 1)
  9201. partNo = cavitySNs[0];
  9202. #endregion 查询载具上的产品信息
  9203. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9204. bool pass = e1Result == 1;
  9205. stopwatch2.Start();
  9206. // 上传MES
  9207. List<TestItem> items = new List<TestItem>();
  9208. items.Add(new TestItem()
  9209. {
  9210. Parameter_name = "载具码",
  9211. Parameter_value = sn,
  9212. Parameter_unit = ""
  9213. });
  9214. items.Add(new TestItem()
  9215. {
  9216. Parameter_name = "载具穴号",
  9217. Parameter_value = "1",
  9218. Parameter_unit = ""
  9219. });
  9220. items.Add(new TestItem()
  9221. {
  9222. Parameter_name = "产品结果",
  9223. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9224. Parameter_unit = ""
  9225. });
  9226. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  9227. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9228. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9229. short result = result1 == 1 ? (short)1 : (short)3;
  9230. stopwatch2.Stop();
  9231. #region 存储绑定数据到 边线MES系统中
  9232. if (result == 1)
  9233. {
  9234. // 删除绑定信息
  9235. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9236. if (resultMesR != 0)
  9237. {
  9238. result = 4;
  9239. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9240. }
  9241. }
  9242. #endregion 存储绑定数据到 边线MES系统中
  9243. // MES_Flag 为MES报错
  9244. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9245. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9246. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9247. writeToPLC_Flag.Name = "e1MES_FLAG";
  9248. writeToPLC_Flag.Adress = 2035;
  9249. writeToPLC_Flag.Value = result;
  9250. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9251. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9252. }
  9253. catch (Exception ex)
  9254. {
  9255. stopwatch2.Restart();
  9256. // MES_Flag 为4上位机报错
  9257. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9258. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9259. writeToPLC_Flag.Name = "e1MES_FLAG";
  9260. writeToPLC_Flag.Adress = 2035;
  9261. writeToPLC_Flag.Value = (short)4;
  9262. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9263. stopwatch2.Stop();
  9264. string str = ex.StackTrace;
  9265. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9266. }
  9267. stopwatch1.Stop();
  9268. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9269. }
  9270. /// <summary>
  9271. /// [S5] Tray盘下料装备 - 节拍接口
  9272. /// </summary>
  9273. /// <param name="plcNo">PLC编号</param>
  9274. /// <param name="stationNameStr">工站全称</param>
  9275. private void S5节拍接口(int plcNo, string stationNameStr)
  9276. {
  9277. Stopwatch stopwatch1 = new Stopwatch();
  9278. Stopwatch stopwatch2 = new Stopwatch();
  9279. string resultStr = string.Empty;
  9280. try
  9281. {
  9282. stopwatch1.Start();
  9283. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9284. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9285. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9286. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9287. if (!actionBool)
  9288. {
  9289. stopwatch2.Start();
  9290. // MES_Flag
  9291. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9292. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9293. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9294. writeToPLC_Flag1.Adress = 2088;
  9295. writeToPLC_Flag1.Value = (short)4;
  9296. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9297. stopwatch2.Stop();
  9298. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9299. return;
  9300. }
  9301. string e1OEEPartNo = string.Empty; // 物料码
  9302. if (string.IsNullOrEmpty(e1OEEProductSN))
  9303. {
  9304. stopwatch2.Start();
  9305. // MES_Flag
  9306. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9307. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9308. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9309. writeToPLC_Flag1.Adress = 2088;
  9310. writeToPLC_Flag1.Value = (short)1;
  9311. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9312. stopwatch2.Stop();
  9313. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9314. return;
  9315. }
  9316. else
  9317. { // 查产品SN
  9318. e1OEEPartNo = "Test"; // ZS
  9319. }
  9320. short e1OEEMES_FLAG = 0;
  9321. // 上传OEE
  9322. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9323. e1OEEMES_FLAG = result.Item1;
  9324. resultStr = result.Item2;
  9325. stopwatch2.Start();
  9326. // MES_Flag
  9327. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9328. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9329. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9330. writeToPLC_Flag.Adress = 2088;
  9331. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9332. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9333. stopwatch2.Stop();
  9334. }
  9335. catch (Exception ex)
  9336. {
  9337. string str = ex.StackTrace;
  9338. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9339. // MES_Flag
  9340. stopwatch2.Start();
  9341. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9342. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9343. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9344. writeToPLC_Flag.Adress = 2088;
  9345. writeToPLC_Flag.Value = (short)4;
  9346. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9347. stopwatch2.Stop();
  9348. }
  9349. stopwatch1.Stop();
  9350. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9351. }
  9352. /// <summary>
  9353. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9354. /// </summary>
  9355. /// <param name="plcNo">PLC编号</param>
  9356. /// <param name="stationNameStr">工站全称</param>
  9357. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9358. {
  9359. Stopwatch stopwatch1 = new Stopwatch();
  9360. Stopwatch stopwatch2 = new Stopwatch();
  9361. try
  9362. {
  9363. stopwatch1.Start();
  9364. // ZS 呼叫AGV
  9365. short e1AGVUpCall = 2;
  9366. stopwatch2.Start();
  9367. // e1AGVUpCall
  9368. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9369. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9370. writeToPLC_Flag.Name = "e1AGVUpCall";
  9371. writeToPLC_Flag.Adress = 2120;
  9372. writeToPLC_Flag.Value = e1AGVUpCall;
  9373. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9374. stopwatch2.Stop();
  9375. }
  9376. catch (Exception ex)
  9377. {
  9378. string str = ex.StackTrace;
  9379. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9380. // e1AGVUpCall
  9381. stopwatch2.Start();
  9382. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9383. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9384. writeToPLC_Flag.Name = "e1AGVUpCall";
  9385. writeToPLC_Flag.Adress = 2120;
  9386. writeToPLC_Flag.Value = (short)4;
  9387. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9388. stopwatch2.Stop();
  9389. }
  9390. stopwatch1.Stop();
  9391. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9392. }
  9393. /// <summary>
  9394. /// [S5] Tray盘下料装备 - AGV上料完成
  9395. /// </summary>
  9396. /// <param name="plcNo">PLC编号</param>
  9397. /// <param name="stationNameStr">工站全称</param>
  9398. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9399. {
  9400. Stopwatch stopwatch1 = new Stopwatch();
  9401. Stopwatch stopwatch2 = new Stopwatch();
  9402. try
  9403. {
  9404. stopwatch1.Start();
  9405. // ZS AGV上料完成,让小车离开
  9406. short e1AGVUpEnd = 2;
  9407. stopwatch2.Start();
  9408. // e1AGVUpEnd
  9409. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9410. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9411. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9412. writeToPLC_Flag.Adress = 2122;
  9413. writeToPLC_Flag.Value = e1AGVUpEnd;
  9414. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9415. stopwatch2.Stop();
  9416. }
  9417. catch (Exception ex)
  9418. {
  9419. string str = ex.StackTrace;
  9420. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9421. // e1AGVUpEnd
  9422. stopwatch2.Start();
  9423. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9424. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9425. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9426. writeToPLC_Flag.Adress = 2122;
  9427. writeToPLC_Flag.Value = (short)4;
  9428. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9429. stopwatch2.Stop();
  9430. }
  9431. stopwatch1.Stop();
  9432. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9433. }
  9434. /// <summary>
  9435. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9436. /// </summary>
  9437. /// <param name="plcNo">PLC编号</param>
  9438. /// <param name="stationNameStr">工站全称</param>
  9439. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9440. {
  9441. Stopwatch stopwatch1 = new Stopwatch();
  9442. Stopwatch stopwatch2 = new Stopwatch();
  9443. try
  9444. {
  9445. stopwatch1.Start();
  9446. // ZS 呼叫AGV
  9447. short e1AGVDownCall = 2;
  9448. stopwatch2.Start();
  9449. // e1AGVDownCall
  9450. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9451. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9452. writeToPLC_Flag.Name = "e1AGVDownCall";
  9453. writeToPLC_Flag.Adress = 2133;
  9454. writeToPLC_Flag.Value = e1AGVDownCall;
  9455. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9456. stopwatch2.Stop();
  9457. }
  9458. catch (Exception ex)
  9459. {
  9460. string str = ex.StackTrace;
  9461. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9462. // e1AGVDownCall
  9463. stopwatch2.Start();
  9464. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9465. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9466. writeToPLC_Flag.Name = "e1AGVDownCall";
  9467. writeToPLC_Flag.Adress = 2133;
  9468. writeToPLC_Flag.Value = (short)4;
  9469. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9470. stopwatch2.Stop();
  9471. }
  9472. stopwatch1.Stop();
  9473. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9474. }
  9475. /// <summary>
  9476. /// [S5] Tray盘下料装备 - AGV下料完成
  9477. /// </summary>
  9478. /// <param name="plcNo">PLC编号</param>
  9479. /// <param name="stationNameStr">工站全称</param>
  9480. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9481. {
  9482. Stopwatch stopwatch1 = new Stopwatch();
  9483. Stopwatch stopwatch2 = new Stopwatch();
  9484. try
  9485. {
  9486. stopwatch1.Start();
  9487. // ZS AGV上料完成,让小车离开
  9488. short e1AGVDownEnd = 2;
  9489. stopwatch2.Start();
  9490. // e1AGVDownEnd
  9491. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9492. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9493. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9494. writeToPLC_Flag.Adress = 2135;
  9495. writeToPLC_Flag.Value = e1AGVDownEnd;
  9496. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9497. stopwatch2.Stop();
  9498. }
  9499. catch (Exception ex)
  9500. {
  9501. string str = ex.StackTrace;
  9502. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9503. // e1AGVDownEnd
  9504. stopwatch2.Start();
  9505. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9506. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9507. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9508. writeToPLC_Flag.Adress = 2135;
  9509. writeToPLC_Flag.Value = (short)4;
  9510. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9511. stopwatch2.Stop();
  9512. }
  9513. stopwatch1.Stop();
  9514. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9515. }
  9516. #endregion [S5] Tray盘下料装备
  9517. #endregion PLC5 张超凡
  9518. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9519. /// <summary>
  9520. /// PLC读取到的数据 -添加数据
  9521. /// </summary>
  9522. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9523. {
  9524. if (sxPlcData.ContainsKey(newKey))
  9525. sxPlcData[newKey] = newValue;
  9526. else
  9527. sxPlcData.Add(newKey, newValue);
  9528. }
  9529. /// <summary>
  9530. /// PLC需要写入的数据 -添加数据
  9531. /// </summary>
  9532. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9533. {
  9534. if (sxPLCWriteData.ContainsKey(newKey))
  9535. sxPLCWriteData[newKey] = newValue;
  9536. else
  9537. sxPLCWriteData.Add(newKey, newValue);
  9538. }
  9539. /// <summary>
  9540. /// PLC回写操作,写后清空flag
  9541. /// </summary>
  9542. /// <param name="modbusClient">modbus对象</param>
  9543. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9544. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9545. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9546. {
  9547. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9548. {
  9549. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9550. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9551. {
  9552. string mesFlagName = pLCWriteDatas[i].Name;
  9553. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9554. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9555. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9556. {
  9557. // 先回写数据
  9558. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9559. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9560. {
  9561. int mesDataAdress = writeToPLCDatas[j].Adress;
  9562. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9563. switch (mesDataType)
  9564. {
  9565. case PLCValueType.Short:
  9566. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9567. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9568. break;
  9569. case PLCValueType.String:
  9570. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9571. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9572. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9573. break;
  9574. }
  9575. }
  9576. // 再回写信号
  9577. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9578. // 存储读取数据的字典
  9579. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9580. // 存储写入数据的字典 - 清空写入值
  9581. pLCWriteDatas[i].Value = (short)0;
  9582. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9583. }
  9584. }
  9585. }
  9586. }
  9587. /// <summary>
  9588. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9589. /// </summary>
  9590. /// <param name="no">3</param>
  9591. /// <param name="stationCode">设备编号</param>
  9592. /// <param name="stationNameStr">设备名称</param>
  9593. /// <param name="plcOrder">车间订单号</param>
  9594. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9595. {
  9596. try
  9597. {
  9598. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9599. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9600. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9601. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9602. int result1 = 0;
  9603. switch (stationCode)
  9604. {
  9605. case 2:
  9606. case 3:
  9607. case 4:
  9608. case 6:
  9609. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9610. break;
  9611. case 102:
  9612. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9613. break;
  9614. case 103:
  9615. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9616. break;
  9617. case 104:
  9618. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9619. break;
  9620. case 106:
  9621. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9622. break;
  9623. default:
  9624. // MES_Flag 为“6未找到正确设备编号”
  9625. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9626. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9627. return;
  9628. }
  9629. short result = result1 == 1 ? (short)1 : (short)2;
  9630. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9631. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9632. }
  9633. catch (Exception ex)
  9634. {
  9635. // MES_Flag 为2上位机报错
  9636. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9637. string str = ex.StackTrace;
  9638. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9639. }
  9640. }
  9641. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9642. #region UI刷新
  9643. /// <summary>
  9644. /// 更新商品信息的UI + 下发产品信息(SN)
  9645. /// </summary>
  9646. private void UpdateProductInfo()
  9647. {
  9648. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9649. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9650. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9651. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9652. }
  9653. /// <summary>
  9654. /// 更新PLC连接状态的UI
  9655. /// </summary>
  9656. /// <param name="no">PLC编号</param>
  9657. /// <param name="status">状态</param>
  9658. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9659. {
  9660. if (this != null && !this.IsDisposed)
  9661. {
  9662. switch (imgNo)
  9663. {
  9664. case 1:
  9665. this.BeginInvoke(new Action(() =>
  9666. {
  9667. picPLC.Image = imageListState.Images[status];
  9668. }));
  9669. break;
  9670. case 2:
  9671. this.BeginInvoke(new Action(() =>
  9672. {
  9673. pictureBox2.Image = imageListState.Images[status];
  9674. }));
  9675. break;
  9676. case 3:
  9677. this.BeginInvoke(new Action(() =>
  9678. {
  9679. pictureBox3.Image = imageListState.Images[status];
  9680. }));
  9681. break;
  9682. case 4:
  9683. this.BeginInvoke(new Action(() =>
  9684. {
  9685. pictureBox4.Image = imageListState.Images[status];
  9686. }));
  9687. break;
  9688. case 5:
  9689. this.BeginInvoke(new Action(() =>
  9690. {
  9691. pictureBox5.Image = imageListState.Images[status];
  9692. }));
  9693. break;
  9694. case 6:
  9695. this.BeginInvoke(new Action(() =>
  9696. {
  9697. pictureBox6.Image = imageListState.Images[status];
  9698. }));
  9699. break;
  9700. case 7:
  9701. this.BeginInvoke(new Action(() =>
  9702. {
  9703. pictureBox7.Image = imageListState.Images[status];
  9704. }));
  9705. break;
  9706. case 8:
  9707. this.BeginInvoke(new Action(() =>
  9708. {
  9709. pictureBox8.Image = imageListState.Images[status];
  9710. }));
  9711. break;
  9712. default:
  9713. break;
  9714. }
  9715. }
  9716. Task.Run(() => // 更新PLC交互页的指示灯
  9717. {
  9718. try
  9719. {
  9720. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9721. {
  9722. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9723. }
  9724. }
  9725. catch { }
  9726. });
  9727. }
  9728. #endregion UI刷新
  9729. #region 日志
  9730. /// <summary>
  9731. /// 添加各工位运行日志(同步至PLC交互页面)
  9732. /// </summary>
  9733. /// <param name="stationNameStr">工站名称</param>
  9734. /// <param name="logType">日志类型</param>
  9735. /// <param name="message">日志内容</param>
  9736. /// <param name="snNumber">产品数字SN</param>
  9737. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9738. {
  9739. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9740. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9741. ))
  9742. {
  9743. AddMessage(logType, message); // 首页展示+日志记录
  9744. }
  9745. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9746. {
  9747. StationName = stationNameStr,
  9748. SnNumber = snNumber,
  9749. Message = message,
  9750. CreateTime = DateTime.Now
  9751. };
  9752. // PLC交互页展示
  9753. Task.Run(() =>
  9754. {
  9755. try
  9756. {
  9757. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9758. {
  9759. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9760. }
  9761. }
  9762. catch { }
  9763. });
  9764. }
  9765. /// <summary>
  9766. /// 添加运行日志
  9767. /// </summary>
  9768. /// <param name="logType">日志类型</param>
  9769. /// <param name="message">日志内容</param>
  9770. public void AddMessage(LogType logType, string message)
  9771. {
  9772. OnMessage(logType, message);
  9773. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9774. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9775. string msgShow = time + "--> " + message + "\r\n";
  9776. this.BeginInvoke(new Action(() =>
  9777. {
  9778. systemLog.Rows.Insert(0, date, time, message);
  9779. if (systemLog.Rows.Count >= 100)
  9780. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9781. }));
  9782. }
  9783. /// <summary>
  9784. /// 添加运行日志-保存
  9785. /// </summary>
  9786. /// <param name="logType">日志类型</param>
  9787. /// <param name="message">日志内容</param>
  9788. private void OnMessage(LogType logType, string msg)
  9789. {
  9790. MessageEvent?.Invoke(logType, msg);
  9791. }
  9792. /// <summary>
  9793. /// 保存PLC写入日志
  9794. /// </summary>
  9795. /// <param name="logType"></param>
  9796. /// <param name="logValue"></param>
  9797. private void WritePLCLog(LogType logType, string logValue)
  9798. {
  9799. switch ((int)logType)
  9800. {
  9801. case 0:
  9802. _PLCLogNet.WriteDebug(logValue);
  9803. break;
  9804. case 1:
  9805. _PLCLogNet.WriteInfo(logValue);
  9806. break;
  9807. case 2:
  9808. _PLCLogNet.WriteWarn(logValue);
  9809. break;
  9810. case 3:
  9811. _PLCLogNet.WriteError(logValue);
  9812. break;
  9813. default:
  9814. _PLCLogNet.WriteFatal(logValue);
  9815. break;
  9816. }
  9817. }
  9818. /// <summary>
  9819. /// IOT Mqtt回调方法- With DataId
  9820. /// </summary>
  9821. /// <param name="id"></param>
  9822. /// <param name="v"></param>
  9823. /// <param name="dataId"></param>
  9824. public void CallbackWithDataId(string id, string msg, string dataId)
  9825. {
  9826. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9827. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9828. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9829. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9830. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9831. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9832. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9833. }
  9834. /// <summary>
  9835. /// AGV Mqtt回调方法- 记录Log并处理数据
  9836. /// </summary>
  9837. /// <param name="obj"></param>
  9838. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9839. {
  9840. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9841. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9842. // 接收到的信息
  9843. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9844. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9845. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9846. {
  9847. }
  9848. }
  9849. #endregion 日志
  9850. /// <summary>
  9851. /// 实例化报警字典
  9852. /// </summary>
  9853. private void InitalDicAlarm()
  9854. {
  9855. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9856. List<Alarm> keyValues1 = new List<Alarm>
  9857. {
  9858. #region 第一组报警(电机)
  9859. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9860. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9861. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9862. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9863. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9864. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9865. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9866. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9867. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9868. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9869. #endregion 第一组报警(电机)
  9870. #region 第二组报警(气缸)
  9871. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9872. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9873. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9874. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9875. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9876. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9877. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9878. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9879. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9880. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9881. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9882. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9883. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9884. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9885. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9886. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9887. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9888. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9889. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9890. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9891. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9892. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9893. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9894. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9895. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9896. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9897. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9898. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9899. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9900. #endregion 第二组报警(气缸)
  9901. #region 第三组报警(其他故障)
  9902. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9903. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9904. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9905. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9906. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9907. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9908. #endregion 第三组报警(其他故障)
  9909. };
  9910. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9911. #endregion 第一个工站(这里使用线体代替工位)
  9912. # region 第二个工站-原来的写法(废弃)
  9913. //keyValues = new Dictionary<int, AlarmData[]>();
  9914. ////1
  9915. //dicAlarmName = new Dictionary<int, Alarm>();
  9916. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  9917. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  9918. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  9919. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  9920. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  9921. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9922. //for (int i = 0; i < dicAlarmName.Count; i++)
  9923. //{
  9924. // alarmDatas[i] = new AlarmData();
  9925. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9926. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9927. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9928. // alarmDatas[i].AlarmType = 1;
  9929. //}
  9930. //keyValues.Add(1, alarmDatas);
  9931. ////2
  9932. //dicAlarmName = new Dictionary<int, Alarm>();
  9933. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  9934. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  9935. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  9936. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  9937. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  9938. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  9939. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  9940. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  9941. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9942. //for (int i = 0; i < dicAlarmName.Count; i++)
  9943. //{
  9944. // alarmDatas[i] = new AlarmData();
  9945. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9946. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9947. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9948. // alarmDatas[i].AlarmType = 2;
  9949. //}
  9950. //keyValues.Add(2, alarmDatas);
  9951. ////3
  9952. //dicAlarmName = new Dictionary<int, Alarm>();
  9953. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  9954. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  9955. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  9956. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  9957. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9958. //for (int i = 0; i < dicAlarmName.Count; i++)
  9959. //{
  9960. // alarmDatas[i] = new AlarmData();
  9961. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  9962. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9963. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9964. // alarmDatas[i].AlarmType = 3;
  9965. //}
  9966. //keyValues.Add(3, alarmDatas);
  9967. //DicAlarms.Add(2, keyValues);
  9968. #endregion 第二个工站-原来的写法(废弃)
  9969. }
  9970. }
  9971. }