Form_Home.cs 587 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050
  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. //// 开启iot的线程
  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. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  618. {
  619. if (plcEIP != null)
  620. {
  621. if (plcEIP.IsConnected)
  622. {
  623. #region 主页展示设备运行状态并上传到IOT中
  624. switch (xmDeviceState)
  625. {
  626. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  627. _DeviceStates = "未初始化状态";
  628. lblDeviceStates.Text = _DeviceStates;
  629. break;
  630. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  631. _DeviceStates = "初始化状态";
  632. lblDeviceStates.Text = _DeviceStates;
  633. break;
  634. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  635. _DeviceStates = "初始化完成状态";
  636. lblDeviceStates.Text = _DeviceStates;
  637. break;
  638. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  639. _DeviceStates = "运行状态";
  640. lblDeviceStates.Text = _DeviceStates;
  641. break;
  642. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  643. _DeviceStates = "暂停状态";
  644. lblDeviceStates.Text = _DeviceStates;
  645. break;
  646. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  647. _DeviceStates = "故障状态";
  648. lblDeviceStates.Text = _DeviceStates;
  649. break;
  650. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  651. _DeviceStates = "警报状态";
  652. lblDeviceStates.Text = _DeviceStates;
  653. break;
  654. }
  655. if (!_DeviceStates.Equals(_DeviceStates_Old))
  656. {
  657. var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceState); // 上传+保存
  658. if (iotResult.Item1 == 1)
  659. {
  660. _DeviceStates_Old = _DeviceStates;
  661. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_上传设备状态到Iot成功!");
  662. }
  663. else
  664. AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  665. }
  666. #endregion 主页展示设备运行状态并上传到IOT中
  667. }
  668. }
  669. }
  670. //if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  671. //{
  672. // DateTime dtNow = DateTime.Now;
  673. // //#region 获取设备运行信息
  674. // //try
  675. // //{
  676. // // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  677. // // lineWorkingData1.GUID = Guid.NewGuid().ToString();
  678. // // lineWorkingData1.LineName = GlobalContext.LineCode;
  679. // // //
  680. // // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  681. // // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  682. // // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  683. // // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  684. // // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  685. // // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  686. // // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  687. // // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  688. // // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  689. // // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  690. // // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  691. // // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  692. // // lineWorkingData1.CreateTime = DateTime.Now;
  693. // // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  694. // // // UI展示-展示到设备状态页
  695. // // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  696. // // {
  697. // // // 查询数据库最新一条数据,确定是不是更新
  698. // // string qSql = @"SELECT top(1) [GUID]
  699. // // ,[LineName]
  700. // // ,[BootTimeLong]
  701. // // ,[NormalTimeLong]
  702. // // ,[StandbyTimeLong]
  703. // // ,[FaultTimeLong]
  704. // // ,[MaterialShortageTimeLong]
  705. // // ,[MaintenanceTimeLong]
  706. // // ,[FaultNumber]
  707. // // ,[OutputNumber]
  708. // // ,[QualifiedNumber]
  709. // // ,[QualifiedRate]
  710. // // ,[DesignRhythm]
  711. // // ,[RealityRhythm]
  712. // // ,[CreateTime]
  713. // // FROM [LineWorkingData]
  714. // // where [CreateTime] > '{0}'
  715. // // and [LineName]='{1}'
  716. // // order by [CreateTime] desc
  717. // // ";
  718. // // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  719. // // var ds = SQLHelper_New.Query(qSql, null);
  720. // // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  721. // // {
  722. // // var dataDBlast = new LineWorkingData_ThisTime();
  723. // // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  724. // // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  725. // // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  726. // // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  727. // // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  728. // // {
  729. // // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  730. // // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  731. // // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  732. // // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  733. // // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  734. // // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  735. // // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  736. // // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  737. // // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  738. // // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  739. // // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  740. // // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  741. // // string usql = dataDBlast.ToStringUpdate();
  742. // // SQLHelper_New.ExecuteSQL(usql, null);
  743. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  744. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  745. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  746. // // }
  747. // // }
  748. // // else
  749. // // {
  750. // // // 插入
  751. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  752. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  753. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  754. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  755. // // }
  756. // // }
  757. // // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  758. // // {
  759. // // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  760. // // //// 本次开机设备运行情况
  761. // // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  762. // // //Task.Run(() =>
  763. // // //{
  764. // // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  765. // // // {
  766. // // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  767. // // // }
  768. // // //});
  769. // // // 本日设备运行情况
  770. // // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  771. // // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  772. // // {
  773. // // // 更新
  774. // // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  775. // // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  776. // // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  777. // // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  778. // // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  779. // // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  780. // // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  781. // // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  782. // // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  783. // // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  784. // // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  785. // // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  786. // // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  787. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  788. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  789. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  790. // // }
  791. // // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  792. // // {
  793. // // // 插入
  794. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  795. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  796. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  797. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  798. // // }
  799. // // await Task.Run(() =>
  800. // // {
  801. // // try
  802. // // {
  803. // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  804. // // {
  805. // // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  806. // // }
  807. // // }
  808. // // catch { }
  809. // // });
  810. // // }
  811. // //}
  812. // //catch (Exception ex)
  813. // //{
  814. // // string str = ex.StackTrace;
  815. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  816. // //}
  817. // //#endregion 获取设备运行信息
  818. // #region 报警数据
  819. // try
  820. // {
  821. // List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  822. // bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  823. // // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  824. // var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  825. // for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  826. // {
  827. // short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  828. // dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  829. // if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  830. // {
  831. // isNeedUpdUI = true; // 需要更新历史报警UI信息
  832. // // 记录
  833. // dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  834. // switch (dicAlarms_Cur_PLC1[i].是否报警)
  835. // {
  836. // case true: // 报警
  837. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  838. // {
  839. // GUID = Guid.NewGuid().ToString(),
  840. // LineName = GlobalContext.LineCode, // 线体
  841. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  842. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  843. // StartTime = dtNow // 开始时间
  844. // };
  845. // // 传输到页面
  846. // deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  847. // {
  848. // 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  849. // 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  850. // 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  851. // 开始时间 = dtNow
  852. // });
  853. // // 新增到数据库
  854. // var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  855. // SaveAlarmDataByDB(stationNameStr, data1, false);
  856. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  857. // break;
  858. // case false: // 消除报警
  859. // if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  860. // {
  861. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  862. // {
  863. // GUID = Guid.NewGuid().ToString(),
  864. // LineName = GlobalContext.LineCode, // 线体
  865. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  866. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  867. // StartTime = dtNow, // 开始时间
  868. // EndTime = dtNow, // 开始时间
  869. // PersistTime = 1, // 耗时1s
  870. // };
  871. // // 新增
  872. // var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  873. // SaveAlarmDataByDB(stationNameStr, data2, false);
  874. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  875. // }
  876. // else
  877. // {
  878. // dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  879. // dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  880. // - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  881. // // 修改
  882. // var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  883. // SaveAlarmDataByDB(stationNameStr, data3, true);
  884. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  885. // }
  886. // break;
  887. // default:
  888. // break;
  889. // }
  890. // }
  891. // }
  892. // DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  893. // // 有新报警则更新
  894. // if (isNeedUpdUI)
  895. // {
  896. // // UI展示 - 展示到设备状态页
  897. // await Task.Run(() =>
  898. // {
  899. // try
  900. // {
  901. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  902. // {
  903. // Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  904. // if (Form_Main.formDevAlarm.Visible)
  905. // {
  906. // Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  907. // }
  908. // }
  909. // }
  910. // catch { }
  911. // });
  912. // }
  913. // }
  914. // catch (Exception ex)
  915. // {
  916. // string str = ex.StackTrace;
  917. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  918. // }
  919. // #endregion 报警数据
  920. // UpdatePLCMonitor(1, -2, 1);
  921. //}
  922. //else
  923. //{
  924. // UpdatePLCMonitor(1, -2, 0);
  925. //}
  926. }
  927. catch (Exception ex)
  928. {
  929. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  930. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  931. }
  932. Thread.Sleep(IntervalAlarm);
  933. }
  934. }
  935. #endregion 轮询PLC
  936. #region 下发订单信息
  937. ///// <summary>
  938. ///// 壳体上料(下发工单)的交互逻辑
  939. ///// </summary>
  940. ///// <param name="no"></param>
  941. ///// <exception cref="NotImplementedException"></exception>
  942. //private void ReadStation_DownOrderInfo(int plcNo)
  943. //{
  944. // // [S1] Tray盘上料装备(板测)
  945. // // [S2] FCT(板测)
  946. // // [S3] 值板机
  947. // // [S4] 取放桁架
  948. // // [S5] Tray盘下料装备
  949. // /// 上位机心跳
  950. // /// 获取设备报警数据与状态信息
  951. // string stationNameStr = "[S0]壳体上料";
  952. // while (IsRun)
  953. // {
  954. // try
  955. // {
  956. // if (!GlobalContext._IsCon_Funs1)
  957. // {
  958. // UpdatePLCMonitor(plcNo, 0);
  959. // continue;
  960. // }
  961. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  962. // {
  963. // #region 壳体上料(下发工单)
  964. // try
  965. // {
  966. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  967. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  968. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  969. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  970. // // 重置数据和信号
  971. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  972. // {
  973. // // 清空写给PLC的数据
  974. // int[] i497 = new int[1] { 0 };
  975. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  976. // // MES_Flag重置为0
  977. // int[] i500 = new int[1] { 0 };
  978. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  979. // }
  980. // }
  981. // catch (Exception ex)
  982. // {
  983. // string str = ex.StackTrace;
  984. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  985. // }
  986. // #endregion 壳体上料(下发工单)
  987. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  988. // }
  989. // else
  990. // {
  991. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  992. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  993. //
  994. // Funs[plcNo].Connect();
  995. // }
  996. // }
  997. // catch (Exception ex)
  998. // {
  999. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1000. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1001. //
  1002. // Funs[plcNo].ReConnect();
  1003. // }
  1004. // Thread.Sleep(IntervalReadPLC);
  1005. // }
  1006. //}
  1007. ///// <summary>
  1008. ///// 下发订单信息到PLC
  1009. ///// </summary>
  1010. ///// <param name="no">PLC编号</param>
  1011. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  1012. //{
  1013. // try
  1014. // {
  1015. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  1016. // {
  1017. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  1018. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  1019. // }
  1020. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  1021. // }
  1022. // catch (Exception ex)
  1023. // {
  1024. // string str = ex.StackTrace;
  1025. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1026. // }
  1027. //}
  1028. /// <summary>
  1029. /// 下发清料信号
  1030. /// </summary>
  1031. /// <param name="no">PLC编号</param>
  1032. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  1033. {
  1034. try
  1035. {
  1036. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  1037. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  1038. return true;
  1039. }
  1040. catch (Exception ex)
  1041. {
  1042. string str = ex.StackTrace;
  1043. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1044. return false;
  1045. }
  1046. }
  1047. #endregion 下发订单信息
  1048. #region Xiaomi 贲流
  1049. #region 公共方法
  1050. private static bool ProgressState = false;
  1051. private static readonly object lockObj = new object(); // 锁对象
  1052. private static bool isCollectingFlagLeft;
  1053. private static bool isCollectingFlagRight;
  1054. /// <summary>
  1055. /// float[]转为string
  1056. /// </summary>
  1057. public string FloatArrayToString(float[] nScrewResults)
  1058. {
  1059. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1060. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1061. }
  1062. /// <summary>
  1063. /// short[]转为string
  1064. /// </summary>
  1065. public string ShortArrayToString(short[] nScrewResults)
  1066. {
  1067. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1068. return string.Join(",", nScrewResults);
  1069. }
  1070. /// <summary>
  1071. /// 写入PLC重复三次
  1072. /// </summary>
  1073. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  1074. {
  1075. int i = 0;
  1076. int nRet = 0;
  1077. string strRet = "";
  1078. try
  1079. {
  1080. while (i < 3) // 最多上传三次
  1081. {
  1082. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1083. if (nRet == 0) //成功
  1084. {
  1085. break;
  1086. }
  1087. else
  1088. {
  1089. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1090. i++;
  1091. }
  1092. }
  1093. return (nRet, strRet);
  1094. }
  1095. catch (Exception ex)
  1096. {
  1097. return (1, ex.Message);
  1098. }
  1099. }
  1100. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  1101. {
  1102. try
  1103. {
  1104. // 获取当前日期
  1105. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1106. // 构建保存路径
  1107. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1108. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  1109. // 确保目录存在
  1110. Directory.CreateDirectory(savePath);
  1111. // 文件名
  1112. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1113. string filePath = Path.Combine(savePath, fileName);
  1114. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1115. int count = Math.Min(14, fScrewTimes.Length);
  1116. using (StreamWriter sw = new StreamWriter(filePath))
  1117. {
  1118. for (int i = 0; i < count; i++)
  1119. {
  1120. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1121. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1122. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1123. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1124. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1125. }
  1126. }
  1127. return (0, "");
  1128. }
  1129. catch (Exception ex)
  1130. {
  1131. return (1, ex.Message);
  1132. }
  1133. }
  1134. /// <summary>
  1135. /// 调用进站接口并保存进站数据
  1136. /// </summary>
  1137. /// <param name="stationNameStr">工站信息</param>
  1138. /// <param name="workorder_code">工单号</param>
  1139. /// <param name="mtltmrk">型号(物料号)</param>
  1140. /// <param name="sn">产品SN</param>
  1141. /// <param name="items">进站数据</param>
  1142. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1143. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1144. {
  1145. int result = 0;
  1146. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1147. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1148. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1149. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1150. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1151. inRequest_Body.unitSn = sn; // 产品SN
  1152. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1153. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1154. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1155. StationIn stationIn = new StationIn()
  1156. {
  1157. Workorder_code = workorder_code, // 车间订单号
  1158. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1159. Sn = sn, // SN
  1160. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1161. Parameter_values = items, // 进站数据
  1162. Write_user = inRequest_Body.userId, // 员工Id
  1163. Test_time = inRequest_Body.clientTime // 进站时间
  1164. };
  1165. // 本地数据
  1166. string sql = stationIn.ToStringInsert(0);
  1167. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1168. result = ret == "成功" ? 1 : 6;
  1169. //await Task.Delay(200);
  1170. // 上传MES
  1171. if (GlobalContext.IsSendStationIn)
  1172. {
  1173. try
  1174. {
  1175. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1176. string mesRet = string.Empty;
  1177. int i = 0;
  1178. while (i < 2) // 1009会多次尝试上传
  1179. {
  1180. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1181. if (response != null && response.header.code == "200")
  1182. break;
  1183. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1184. i++;
  1185. i++;
  1186. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1187. // 记录失败原因
  1188. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1189. }
  1190. if (response?.header?.code == "200")
  1191. {
  1192. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1193. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1194. result = ret_Upd == "成功" ? 1 : 6;
  1195. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1196. }
  1197. else
  1198. {
  1199. result = 5;
  1200. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1201. }
  1202. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1203. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1204. }
  1205. catch (Exception ex)
  1206. {
  1207. result = 6;
  1208. string str = ex.StackTrace;
  1209. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1210. }
  1211. }
  1212. return result;
  1213. }
  1214. /// <summary>
  1215. /// 选择如何记录出站数据
  1216. /// </summary>
  1217. /// <param name="items">出站数据</param>
  1218. /// <param name="equipmentCode">设备编号</param>
  1219. /// <param name="processItem">测试项目</param>
  1220. /// <param name="workorder_code">车间订单号</param>
  1221. /// <param name="batch_num">批次号</param>
  1222. /// <param name="mtltmrk">型号</param>
  1223. /// <param name="proDate">日期</param>
  1224. /// <param name="supplierCode">供应商代码</param>
  1225. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1226. /// <returns>上传成功时返回1;失败返回0</returns>
  1227. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1228. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1229. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode)
  1230. {
  1231. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1232. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode);
  1233. }
  1234. /// <summary>
  1235. /// 添加出站数据(提交到MES+本地保存到数据库)
  1236. /// </summary>
  1237. /// <param name="items">出站数据</param>
  1238. /// <param name="equipmentCode">设备编号</param>
  1239. /// <param name="processItem">测试项目</param>
  1240. /// <param name="workorder_code">车间订单号</param>
  1241. /// <param name="batch_num">批次号</param>
  1242. /// <param name="mtltmrk">型号</param>
  1243. /// <param name="proDate">日期</param>
  1244. /// <param name="supplierCode">供应商代码</param>
  1245. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1246. /// <returns>上传成功时返回1;失败返回0</returns>
  1247. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1248. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1249. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode)
  1250. {
  1251. int upload = 0;
  1252. int result = 0;
  1253. ProcessData processData = new ProcessData()
  1254. {
  1255. Equipment_code = equipmentCode,
  1256. Workorder_code = workorder_code,
  1257. Batch_number = batch_num,
  1258. Sn = sn, // SN
  1259. Testitem = processItem,
  1260. Parameter_values = items,
  1261. Write_user = GlobalContext.CurrentUser,
  1262. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1263. };
  1264. // 本地数据
  1265. string sql = processData.ToStringInsert(upload);
  1266. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1267. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1268. // 上传MES
  1269. if (GlobalContext.IsSendProcessData)
  1270. {
  1271. try
  1272. {
  1273. string id = processData.ID.Copy();
  1274. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1275. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1276. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1277. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1278. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1279. outRequest_Body.unitSn = sn; // 产品SN
  1280. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1281. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1282. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1283. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1284. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1285. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1286. if (!string.IsNullOrEmpty(partBarcode))
  1287. {
  1288. outRequest_Body.unitData.keyMaterial.Add(
  1289. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1290. {
  1291. bindSort = 1,
  1292. materialSn = partBarcode
  1293. }); // 设备数据 - 部件码
  1294. }
  1295. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1296. if (GlobalContext.IsSendProcessData)
  1297. {
  1298. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1299. string mesRet = string.Empty;
  1300. int i = 0;
  1301. while (i < 2) // 1009会多次尝试上传
  1302. {
  1303. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1304. if (response != null && response.header.code == "200")
  1305. break;
  1306. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1307. i++;
  1308. i++;
  1309. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1310. // 记录失败原因
  1311. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1312. }
  1313. if (response?.header?.code == "200")
  1314. {
  1315. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1316. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1317. result = 1;
  1318. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1319. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1320. }
  1321. else
  1322. {
  1323. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1324. }
  1325. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1326. JsonConvert.SerializeObject(response), id);
  1327. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1328. }
  1329. }
  1330. catch (Exception ex)
  1331. {
  1332. string str = ex.StackTrace;
  1333. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1334. }
  1335. }
  1336. return result;
  1337. }
  1338. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1339. //{
  1340. // Stopwatch stopwatch = new Stopwatch();
  1341. // stopwatch.Start();
  1342. // try
  1343. // {
  1344. // // 初始化 AtlasScrew 实例
  1345. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1346. // atlasScrew1.Initial();
  1347. // // 存储结果的列表
  1348. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1349. // // 存储角度和扭力的字符串列表
  1350. // List<string> angleStrs = new List<string>();
  1351. // List<string> torqueStrs = new List<string>();
  1352. // // 上一次获取的数据
  1353. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1354. // while (isExitAtlasLeft) // 检查是否收集数据
  1355. // {
  1356. // // 获取当前数据
  1357. // var currentResult = atlasScrew1.GetResults();
  1358. // // 判断是否为新数据
  1359. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1360. // {
  1361. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1362. // // 更新角度和扭力的字符串列表
  1363. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1364. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1365. // // 计算角度、扭力、起始扭力和最大扭力
  1366. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1367. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1368. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1369. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1370. // // 将新数据添加到结果列表
  1371. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1372. // // 更新上一次获取的数据
  1373. // lastResult = currentResult;
  1374. // }
  1375. // // 等待一段时间后再次检查
  1376. // Thread.Sleep(20); // 轮询间隔时间
  1377. // // 如果触发了出站,则退出循环
  1378. // if (!isExitAtlasLeft)
  1379. // {
  1380. // break;
  1381. // }
  1382. // }
  1383. // // 生成文件名
  1384. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1385. // // 写入数据到文件
  1386. // using (StreamWriter writer = new StreamWriter(fileName))
  1387. // {
  1388. // // 写入标题行
  1389. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1390. // // 写入每一行数据
  1391. // foreach (var result in results)
  1392. // {
  1393. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1394. // }
  1395. // }
  1396. // stopwatch.Stop();
  1397. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1398. // }
  1399. // catch (Exception ex)
  1400. // {
  1401. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1402. // }
  1403. // finally
  1404. // {
  1405. // // 重置标志变量
  1406. // isExitAtlasLeft = false;
  1407. // }
  1408. //}
  1409. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1410. //{
  1411. // Stopwatch stopwatch = new Stopwatch();
  1412. // stopwatch.Start();
  1413. // try
  1414. // {
  1415. // // 初始化 AtlasScrew 实例
  1416. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1417. // atlasScrew2.Initial();
  1418. // // 存储结果的列表
  1419. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1420. // // 上一次获取的数据
  1421. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1422. // while (isExitAtlasRight) // 检查是否收集数据
  1423. // {
  1424. // // 获取当前数据
  1425. // var currentResult = atlasScrew2.GetResults();
  1426. // // 判断是否为新数据
  1427. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1428. // {
  1429. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1430. // // 将新数据写入PLC
  1431. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1432. // // 将新数据添加到结果列表
  1433. // results.Add(currentResult);
  1434. // // 更新上一次获取的数据
  1435. // lastResult = currentResult;
  1436. // }
  1437. // // 等待一段时间后再次检查
  1438. // Thread.Sleep(20); // 轮询间隔时间
  1439. // // 如果触发了出站,则退出循环
  1440. // if (!isExitAtlasRight)
  1441. // {
  1442. // break;
  1443. // }
  1444. // }
  1445. // // 将所有数据写入文件
  1446. // //WriteDataToFile(sn, direction, results);
  1447. // stopwatch.Stop();
  1448. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1449. // }
  1450. // catch (Exception ex)
  1451. // {
  1452. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1453. // }
  1454. // finally
  1455. // {
  1456. // // 重置标志变量
  1457. // isExitAtlasRight = false;
  1458. // }
  1459. //}
  1460. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1461. {
  1462. Stopwatch stopwatch = new Stopwatch();
  1463. stopwatch.Start();
  1464. int nRet = 0;
  1465. string strRet = "";
  1466. try
  1467. {
  1468. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1469. while (isCollectingFlagLeft)
  1470. {
  1471. // 从缓存中获取所有未处理的数据
  1472. var cachedData = atlasScrew.GetCachedDataLeft();
  1473. foreach (var currentResult in cachedData)
  1474. {
  1475. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1476. {
  1477. continue; // 跳过无效数据
  1478. }
  1479. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1480. // 写入PLC
  1481. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1482. {
  1483. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1484. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1485. };
  1486. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1487. if (nRet != 0)
  1488. {
  1489. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1490. }
  1491. else
  1492. {
  1493. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1494. }
  1495. // 构建保存路径
  1496. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1497. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1498. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1499. Directory.CreateDirectory(savePath); // 确保目录存在
  1500. // 构建文件名(以 SN + 序号命名)
  1501. string fileName = $"{sn}_{fileCounter}.txt";
  1502. string filePath = Path.Combine(savePath, fileName);
  1503. // 写入文件
  1504. using (StreamWriter writer = new StreamWriter(filePath))
  1505. {
  1506. writer.WriteLine("精度, 扭力");
  1507. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1508. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1509. {
  1510. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1511. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1512. writer.WriteLine($"{precision}, {torque}");
  1513. }
  1514. }
  1515. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1516. // 增加文件计数器
  1517. fileCounter++;
  1518. }
  1519. // 如果没有更多数据,则短暂休眠以节省资源
  1520. if (!cachedData.Any())
  1521. {
  1522. Thread.Sleep(10); // 根据需要调整休眠时间
  1523. }
  1524. // 如果触发了出站,则退出循环
  1525. if (!isCollectingFlagLeft)
  1526. {
  1527. break;
  1528. }
  1529. }
  1530. stopwatch.Stop();
  1531. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1532. }
  1533. catch (Exception ex)
  1534. {
  1535. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1536. }
  1537. finally
  1538. {
  1539. isCollectingFlagLeft = false;
  1540. }
  1541. }
  1542. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1543. {
  1544. Stopwatch stopwatch = new Stopwatch();
  1545. stopwatch.Start();
  1546. int nRet = 0;
  1547. string strRet = "";
  1548. try
  1549. {
  1550. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1551. while (isCollectingFlagRight)
  1552. {
  1553. // 从缓存中获取所有未处理的数据
  1554. var cachedData = atlasScrew.GetCachedDataLeft();
  1555. foreach (var currentResult in cachedData)
  1556. {
  1557. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1558. {
  1559. continue; // 跳过无效数据
  1560. }
  1561. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1562. // 写入PLC
  1563. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1564. {
  1565. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1566. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1567. };
  1568. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1569. if (nRet != 0)
  1570. {
  1571. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1572. }
  1573. else
  1574. {
  1575. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1576. }
  1577. // 构建保存路径
  1578. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1579. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1580. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1581. Directory.CreateDirectory(savePath); // 确保目录存在
  1582. // 构建文件名(以 SN + 序号命名)
  1583. string fileName = $"{sn}_{fileCounter}.txt";
  1584. string filePath = Path.Combine(savePath, fileName);
  1585. // 写入文件
  1586. using (StreamWriter writer = new StreamWriter(filePath))
  1587. {
  1588. writer.WriteLine("精度, 扭力");
  1589. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1590. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1591. {
  1592. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1593. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1594. writer.WriteLine($"{precision}, {torque}");
  1595. }
  1596. }
  1597. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1598. // 增加文件计数器
  1599. fileCounter++;
  1600. }
  1601. // 如果没有更多数据,则短暂休眠以节省资源
  1602. if (!cachedData.Any())
  1603. {
  1604. Thread.Sleep(10); // 根据需要调整休眠时间
  1605. }
  1606. // 如果触发了出站,则退出循环
  1607. if (!isCollectingFlagRight)
  1608. {
  1609. break;
  1610. }
  1611. }
  1612. stopwatch.Stop();
  1613. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1614. }
  1615. catch (Exception ex)
  1616. {
  1617. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1618. }
  1619. finally
  1620. {
  1621. isCollectingFlagRight = false;
  1622. }
  1623. }
  1624. #endregion
  1625. #region S1
  1626. /// <summary>
  1627. /// [S1] 壳体清洁上料装备
  1628. /// </summary>
  1629. /// <param name="plcNo">PLC编号</param>
  1630. private void ReadStation_S1(int plcNo)
  1631. {
  1632. string stationCode = "[OP10]";
  1633. string stationName = "壳体清洁上料";
  1634. string stationNameStr = stationCode + stationName;
  1635. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1636. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1637. string tagAgvCommName = "agvCommFrmPC";
  1638. string tagBarsetName = "BarcodeSet";
  1639. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1640. (int, string) result;
  1641. while (true)
  1642. {
  1643. try
  1644. {
  1645. if (!GlobalContext._IsCon_Funs1)
  1646. {
  1647. UpdatePLCMonitor(1, plcNo, 0);
  1648. continue;
  1649. }
  1650. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1651. {
  1652. Stopwatch stopwatch1 = new Stopwatch();
  1653. Stopwatch stopwatch2 = new Stopwatch();
  1654. stopwatch1.Start();
  1655. stopwatch2.Start();
  1656. #region 一次性读取所有数据
  1657. // 一次性读取所有数据
  1658. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1659. if (result.Item1 != 0)
  1660. {
  1661. //richTextBox1.AppendText("\n" + strRet);
  1662. }
  1663. else
  1664. {
  1665. //richTextBox1.AppendText("\n" + "读取成功");
  1666. }
  1667. #endregion 一次性读取所有数据
  1668. stopwatch2.Stop();
  1669. #region 进站
  1670. try
  1671. {
  1672. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1673. {
  1674. lock (lockObj)
  1675. {
  1676. if (!ProgressState)
  1677. {
  1678. ProgressState = true;
  1679. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1680. }
  1681. }
  1682. }
  1683. }
  1684. catch (Exception ex)
  1685. {
  1686. ProgressState = false;
  1687. string str = ex.StackTrace;
  1688. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1689. }
  1690. #endregion 进站
  1691. #region 出站
  1692. try
  1693. {
  1694. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1695. {
  1696. lock (lockObj)
  1697. {
  1698. if (!ProgressState)
  1699. {
  1700. ProgressState = true;
  1701. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1702. }
  1703. }
  1704. }
  1705. }
  1706. catch (Exception ex)
  1707. {
  1708. ProgressState = false;
  1709. string str = ex.StackTrace;
  1710. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1711. }
  1712. #endregion 进站
  1713. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1714. stopwatch1.Stop();
  1715. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1716. }
  1717. else
  1718. {
  1719. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1720. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1721. FunsEip[plcNo].Connect(); // 重连
  1722. }
  1723. }
  1724. catch (Exception ex)
  1725. {
  1726. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1727. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1728. }
  1729. Thread.Sleep(IntervalReadPLC);
  1730. }
  1731. }
  1732. /// <summary>
  1733. /// [S1] 壳体清洁上料 - 进站
  1734. /// </summary>
  1735. /// <param name="plcNo">PLC编号</param>
  1736. /// <param name="stationNameStr">工站全称</param>
  1737. /// <param name="stPLC_MesData"></param>
  1738. /// <param name="tagMesCommName"></param>
  1739. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1740. {
  1741. Stopwatch stopwatch1 = new Stopwatch();
  1742. Stopwatch stopwatch2 = new Stopwatch();
  1743. try
  1744. {
  1745. stopwatch1.Start();
  1746. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1747. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1748. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1749. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1750. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1751. if (string.IsNullOrEmpty(sn))
  1752. {
  1753. ProgressState = false;
  1754. return;
  1755. }
  1756. //正式生产就用PLC中取的
  1757. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1758. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1759. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1760. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1761. //绑定载具和产品
  1762. ResponseMessage message = new ResponseMessage();
  1763. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1764. if (message.result == false)
  1765. {
  1766. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1767. }
  1768. // 产品SN进站
  1769. List<TestItem> item = new List<TestItem>();
  1770. stopwatch2.Start();
  1771. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1772. stopwatch2.Stop();
  1773. //指令执行结果 1:OK 110:失败
  1774. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1775. //进站结果写入PLC
  1776. CommandFromPLC resultToPlC = new CommandFromPLC();
  1777. resultToPlC.cmd = 0;
  1778. resultToPlC.cmdParam = 0;
  1779. resultToPlC.cmdResult = mesResultFrmWeb;
  1780. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1781. }
  1782. catch (Exception ex)
  1783. {
  1784. string str = ex.StackTrace;
  1785. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1786. CommandFromPLC resultToPlC = new CommandFromPLC();
  1787. resultToPlC.cmd = 0;
  1788. resultToPlC.cmdParam = 0; //指令参数
  1789. resultToPlC.cmdResult = 110;
  1790. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1791. }
  1792. stopwatch1.Stop();
  1793. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1794. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1795. ProgressState = false;
  1796. }
  1797. /// <summary>
  1798. /// [S1] 壳体清洁上料 - 出站接口
  1799. /// </summary>
  1800. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1801. {
  1802. Stopwatch stopwatch1 = new Stopwatch();
  1803. Stopwatch stopwatch2 = new Stopwatch();
  1804. try
  1805. {
  1806. stopwatch1.Start();
  1807. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1808. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1809. string processItem = stationName; // 项目
  1810. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1811. string supplierCode = ""; // 供应商代码
  1812. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1813. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1814. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1815. string sn = string.Empty;
  1816. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1817. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1818. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1819. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1820. a1Result = 1;
  1821. bool pass = a1Result == 1;
  1822. //根据载具码获取产品码
  1823. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1824. if (string.IsNullOrEmpty(strProductBarcode))
  1825. {
  1826. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1827. }
  1828. sn = strProductBarcode;
  1829. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1830. List<TestItem> items = new List<TestItem>();
  1831. items.Add(new TestItem()
  1832. {
  1833. Parameter_name = "载具码",
  1834. Parameter_value = CarrierBarcode,
  1835. Parameter_unit = ""
  1836. });
  1837. items.Add(new TestItem()
  1838. {
  1839. Parameter_name = "产品码",
  1840. Parameter_value = sn,
  1841. Parameter_unit = ""
  1842. });
  1843. //出站接口
  1844. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1845. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1846. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1847. stopwatch2.Start();
  1848. //进站结果写入PLC
  1849. CommandFromPLC resultToPlC = new CommandFromPLC();
  1850. resultToPlC.cmd = 0;
  1851. resultToPlC.cmdParam = 0; //指令参数
  1852. resultToPlC.cmdResult = mesResultFrmWeb;
  1853. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1854. stopwatch2.Stop();
  1855. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1856. //保存PLC返回MES数据到本地
  1857. ResponseMessage message = new ResponseMessage();
  1858. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1859. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1860. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1861. stPLC_MesData.mesData.nRemainCount);
  1862. if (message.result == false)
  1863. {
  1864. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1865. }
  1866. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1867. }
  1868. catch (Exception ex)
  1869. {
  1870. stopwatch2.Start();
  1871. CommandFromPLC resultToPlC = new CommandFromPLC();
  1872. resultToPlC.cmd = 0;
  1873. resultToPlC.cmdParam = 0; //指令参数
  1874. resultToPlC.cmdResult = 110;
  1875. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1876. stopwatch2.Stop();
  1877. string str = ex.StackTrace;
  1878. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1879. }
  1880. stopwatch1.Stop();
  1881. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1882. ProgressState = false;
  1883. }
  1884. #endregion
  1885. #region S2
  1886. /// <summary>
  1887. /// [S2] 上盖板上料装备
  1888. /// </summary>
  1889. /// <param name="plcNo">PLC编号</param>
  1890. private void ReadStation_S2(int plcNo)
  1891. {
  1892. string stationCode = "[OP20]";
  1893. string stationName = "上盖板上料装备";
  1894. string stationNameStr = stationCode + stationName;
  1895. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1896. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1897. string tagAgvCommName = "agvCommFrmPC";
  1898. string tagBarsetName = "BarcodeSet";
  1899. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1900. (int, string) result;
  1901. while (true)
  1902. {
  1903. try
  1904. {
  1905. if (!GlobalContext._IsCon_Funs2)
  1906. {
  1907. UpdatePLCMonitor(1, plcNo, 0);
  1908. continue;
  1909. }
  1910. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1911. {
  1912. Stopwatch stopwatch1 = new Stopwatch();
  1913. Stopwatch stopwatch2 = new Stopwatch();
  1914. stopwatch1.Start();
  1915. stopwatch2.Start();
  1916. #region 一次性读取所有数据
  1917. // 一次性读取所有数据
  1918. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1919. if (result.Item1 != 0)
  1920. {
  1921. //richTextBox1.AppendText("\n" + strRet);
  1922. }
  1923. else
  1924. {
  1925. //richTextBox1.AppendText("\n" + "读取成功");
  1926. }
  1927. #endregion 一次性读取所有数据
  1928. stopwatch2.Stop();
  1929. #region 进站
  1930. try
  1931. {
  1932. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1933. {
  1934. lock (lockObj)
  1935. {
  1936. if (!ProgressState)
  1937. {
  1938. ProgressState = true;
  1939. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1940. }
  1941. }
  1942. }
  1943. }
  1944. catch (Exception ex)
  1945. {
  1946. ProgressState = false;
  1947. string str = ex.StackTrace;
  1948. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1949. }
  1950. #endregion 进站
  1951. #region 出站
  1952. try
  1953. {
  1954. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1955. {
  1956. lock (lockObj)
  1957. {
  1958. if (!ProgressState)
  1959. {
  1960. ProgressState = true;
  1961. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1962. }
  1963. }
  1964. }
  1965. }
  1966. catch (Exception ex)
  1967. {
  1968. ProgressState = false;
  1969. string str = ex.StackTrace;
  1970. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1971. }
  1972. #endregion 进站
  1973. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1974. stopwatch1.Stop();
  1975. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1976. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1977. }
  1978. else
  1979. {
  1980. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1981. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1982. FunsEip[plcNo].Connect();
  1983. }
  1984. }
  1985. catch (Exception ex)
  1986. {
  1987. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1988. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1989. //Funs[plcNo].ReConnect();
  1990. }
  1991. Thread.Sleep(IntervalReadPLC);
  1992. }
  1993. }
  1994. /// <summary>
  1995. /// [S2] 上盖板上料装备
  1996. /// </summary>
  1997. /// <param name="plcNo">PLC编号</param>
  1998. /// <param name="stationNameStr">工站全称</param>
  1999. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2000. {
  2001. Stopwatch stopwatch1 = new Stopwatch();
  2002. Stopwatch stopwatch2 = new Stopwatch();
  2003. try
  2004. {
  2005. stopwatch1.Start();
  2006. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2007. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  2008. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2009. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  2010. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  2011. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2012. //根据载具码获取产品码
  2013. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2014. if (string.IsNullOrEmpty(strProductBarcode))
  2015. {
  2016. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2017. }
  2018. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2019. //if (sn != strProductBarcode)
  2020. //{
  2021. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2022. //}
  2023. sn = strProductBarcode;
  2024. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2025. // 产品SN(物料码)校验
  2026. List<TestItem> item = new List<TestItem>();
  2027. stopwatch2.Start();
  2028. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2029. stopwatch2.Stop();
  2030. //指令执行结果 1:OK 110:失败
  2031. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2032. //进站结果写入PLC
  2033. CommandFromPLC resultToPlC = new CommandFromPLC();
  2034. resultToPlC.cmd = 0;
  2035. resultToPlC.cmdParam = 0; //指令参数
  2036. resultToPlC.cmdResult = mesResultFrmWeb;
  2037. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2038. }
  2039. catch (Exception ex)
  2040. {
  2041. string str = ex.StackTrace;
  2042. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2043. CommandFromPLC resultToPlC = new CommandFromPLC();
  2044. resultToPlC.cmd = 0;
  2045. resultToPlC.cmdParam = 0; //指令参数
  2046. resultToPlC.cmdResult = 110;
  2047. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2048. }
  2049. stopwatch1.Stop();
  2050. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2051. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2052. ProgressState = false;
  2053. }
  2054. /// <summary>
  2055. /// [S2] 上盖板上料装备 - 出站接口
  2056. /// </summary>
  2057. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2058. {
  2059. Stopwatch stopwatch1 = new Stopwatch();
  2060. Stopwatch stopwatch2 = new Stopwatch();
  2061. try
  2062. {
  2063. stopwatch1.Start();
  2064. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2065. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2066. string processItem = stationName; // 测试项目
  2067. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2068. string supplierCode = ""; // 供应商代码
  2069. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2070. string batch_num = GlobalContext.BatchNumber; // 批次号
  2071. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2072. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2073. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2074. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2075. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2076. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  2077. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2078. bool pass = a1Result == 1;
  2079. //根据载具码获取产品码
  2080. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2081. if (string.IsNullOrEmpty(strProductBarcode))
  2082. {
  2083. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2084. }
  2085. sn = strProductBarcode;
  2086. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2087. List<TestItem> items = new List<TestItem>();
  2088. items.Add(new TestItem()
  2089. {
  2090. Parameter_name = "载具码",
  2091. Parameter_value = CarrierBarcode,
  2092. Parameter_unit = ""
  2093. });
  2094. items.Add(new TestItem()
  2095. {
  2096. Parameter_name = "产品码",
  2097. Parameter_value = sn,
  2098. Parameter_unit = ""
  2099. });
  2100. items.Add(new TestItem()
  2101. {
  2102. Parameter_name = "部件码",
  2103. Parameter_value = PartBarcode,
  2104. Parameter_unit = ""
  2105. });
  2106. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2107. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2108. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2109. stopwatch2.Start();
  2110. //进站结果写入PLC
  2111. CommandFromPLC resultToPlC = new CommandFromPLC();
  2112. resultToPlC.cmd = 0;
  2113. resultToPlC.cmdParam = 0; //指令参数
  2114. resultToPlC.cmdResult = mesResultFrmWeb;
  2115. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2116. stopwatch2.Stop();
  2117. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2118. //保存PLC返回MES数据到本地
  2119. ResponseMessage message = new ResponseMessage();
  2120. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  2121. if (message.result == false)
  2122. {
  2123. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2124. }
  2125. if (!string.IsNullOrEmpty(PartBarcode))
  2126. {
  2127. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2128. if (message.result == false)
  2129. {
  2130. AddMessage(LogType.Error, message.text);
  2131. }
  2132. }
  2133. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2134. }
  2135. catch (Exception ex)
  2136. {
  2137. stopwatch2.Start();
  2138. CommandFromPLC resultToPlC = new CommandFromPLC();
  2139. resultToPlC.cmd = 0;
  2140. resultToPlC.cmdParam = 0; //指令参数
  2141. resultToPlC.cmdResult = 110;
  2142. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2143. stopwatch2.Stop();
  2144. string str = ex.StackTrace;
  2145. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2146. }
  2147. stopwatch1.Stop();
  2148. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2149. ProgressState = false;
  2150. }
  2151. #endregion
  2152. #region S3
  2153. /// <summary>
  2154. /// [S3] 点散热胶装备
  2155. /// </summary>
  2156. /// <param name="plcNo">PLC编号</param>
  2157. private void ReadStation_S3(int plcNo)
  2158. {
  2159. string stationCode = "[OP30]";
  2160. string stationName = "点散热胶装备";
  2161. string stationNameStr = stationCode + stationName;
  2162. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2163. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2164. string tagAgvCommName = "agvCommFrmPC";
  2165. string tagBarsetName = "BarcodeSet";
  2166. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2167. (int, string) result;
  2168. #region 创建字典
  2169. // 触发信号字典 赋值
  2170. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2171. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2172. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2173. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2174. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2175. // PLC数据字典 赋值
  2176. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2177. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2178. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2179. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2180. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2181. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2182. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2183. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2184. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2185. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2186. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2187. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2188. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2189. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2190. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2191. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2192. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2193. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2194. s3PLCData.Add("c1Result", 0); // 产品结果
  2195. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2196. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2197. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2198. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2199. #endregion 创建字典
  2200. while (true)
  2201. {
  2202. try
  2203. {
  2204. if (!GlobalContext._IsCon_Funs2)
  2205. {
  2206. UpdatePLCMonitor(1, plcNo, 0);
  2207. continue;
  2208. }
  2209. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2210. {
  2211. Stopwatch stopwatch1 = new Stopwatch();
  2212. Stopwatch stopwatch2 = new Stopwatch();
  2213. stopwatch1.Start();
  2214. stopwatch2.Start();
  2215. #region 一次性读取所有数据
  2216. // 一次性读取所有数据
  2217. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2218. if (result.Item1 != 0)
  2219. {
  2220. //richTextBox1.AppendText("\n" + strRet);
  2221. }
  2222. else
  2223. {
  2224. //richTextBox1.AppendText("\n" + "读取成功");
  2225. }
  2226. #endregion 一次性读取所有数据
  2227. stopwatch2.Stop();
  2228. #region 左边进站
  2229. try
  2230. {
  2231. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2232. {
  2233. lock (lockObj)
  2234. {
  2235. if (!ProgressState)
  2236. {
  2237. ProgressState = true;
  2238. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2239. }
  2240. }
  2241. }
  2242. }
  2243. catch (Exception ex)
  2244. {
  2245. ProgressState = false;
  2246. string str = ex.StackTrace;
  2247. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2248. }
  2249. #endregion 左边进站
  2250. #region 左边出站
  2251. try
  2252. {
  2253. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2254. {
  2255. lock (lockObj)
  2256. {
  2257. if (!ProgressState)
  2258. {
  2259. ProgressState = true;
  2260. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2261. }
  2262. }
  2263. }
  2264. }
  2265. catch (Exception ex)
  2266. {
  2267. ProgressState = false;
  2268. string str = ex.StackTrace;
  2269. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2270. }
  2271. #endregion 左边出站
  2272. #region 右边进站
  2273. try
  2274. {
  2275. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2276. {
  2277. lock (lockObj)
  2278. {
  2279. if (!ProgressState)
  2280. {
  2281. ProgressState = true;
  2282. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2283. }
  2284. }
  2285. }
  2286. }
  2287. catch (Exception ex)
  2288. {
  2289. ProgressState = false;
  2290. string str = ex.StackTrace;
  2291. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2292. }
  2293. #endregion 右边进站
  2294. #region 右边出站
  2295. try
  2296. {
  2297. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2298. {
  2299. lock (lockObj)
  2300. {
  2301. if (!ProgressState)
  2302. {
  2303. ProgressState = true;
  2304. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2305. }
  2306. }
  2307. }
  2308. }
  2309. catch (Exception ex)
  2310. {
  2311. string str = ex.StackTrace;
  2312. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2313. }
  2314. #endregion 右边出站
  2315. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2316. stopwatch1.Stop();
  2317. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2318. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2319. }
  2320. else
  2321. {
  2322. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2323. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2324. FunsEip[plcNo].Connect();
  2325. }
  2326. }
  2327. catch (Exception ex)
  2328. {
  2329. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2330. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2331. //Funs[plcNo].ReConnect();
  2332. }
  2333. Thread.Sleep(IntervalReadPLC);
  2334. }
  2335. }
  2336. /// <summary>
  2337. /// [S3] 点散热胶装备 - 进站
  2338. /// </summary>
  2339. /// <param name="plcNo">PLC编号</param>
  2340. /// <param name="stationNameStr">工站全称</param>
  2341. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2342. {
  2343. Stopwatch stopwatch1 = new Stopwatch();
  2344. Stopwatch stopwatch2 = new Stopwatch();
  2345. try
  2346. {
  2347. stopwatch1.Start();
  2348. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2349. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2350. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2351. string StationId=string.Empty;
  2352. if (direction=="Left")
  2353. {
  2354. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2355. }
  2356. if (direction == "Right")
  2357. {
  2358. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2359. }
  2360. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2361. //载具码验证产品码
  2362. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2363. if (string.IsNullOrEmpty(strProductBarcode))
  2364. {
  2365. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2366. }
  2367. sn = strProductBarcode;
  2368. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2369. // 产品SN(物料码)校验
  2370. List<TestItem> item = new List<TestItem>();
  2371. stopwatch2.Start();
  2372. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2373. stopwatch2.Stop();
  2374. //指令执行结果 1:OK 110:失败
  2375. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2376. //进站结果写入PLC
  2377. CommandFromPLC resultToPlC = new CommandFromPLC();
  2378. resultToPlC.cmd = 0;
  2379. resultToPlC.cmdParam = 0; //指令参数
  2380. resultToPlC.cmdResult = mesResultFrmWeb;
  2381. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2382. }
  2383. catch (Exception ex)
  2384. {
  2385. string str = ex.StackTrace;
  2386. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2387. CommandFromPLC resultToPlC = new CommandFromPLC();
  2388. resultToPlC.cmd = 0;
  2389. resultToPlC.cmdParam = 0; //指令参数
  2390. resultToPlC.cmdResult = 110;
  2391. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2392. }
  2393. stopwatch1.Stop();
  2394. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2395. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2396. ProgressState = false;
  2397. }
  2398. /// <summary>
  2399. /// [S3] 点散热胶装备 - 出站
  2400. /// </summary>
  2401. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2402. {
  2403. Stopwatch stopwatch1 = new Stopwatch();
  2404. Stopwatch stopwatch2 = new Stopwatch();
  2405. try
  2406. {
  2407. stopwatch1.Start();
  2408. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2409. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2410. string processItem = stationName; // 测试项目
  2411. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2412. string supplierCode = ""; // 供应商代码
  2413. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2414. string batch_num = GlobalContext.BatchNumber; // 批次号
  2415. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2416. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2417. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2418. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2419. string StationId = string.Empty;
  2420. if (direction == "Left")
  2421. {
  2422. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2423. }
  2424. if (direction == "Right")
  2425. {
  2426. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2427. }
  2428. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2429. bool pass = a1Result == 1;
  2430. //根据载具码获取产品码
  2431. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2432. if (string.IsNullOrEmpty(strProductBarcode))
  2433. {
  2434. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2435. }
  2436. sn = strProductBarcode;
  2437. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2438. List<TestItem> items = new List<TestItem>();
  2439. items.Add(new TestItem()
  2440. {
  2441. Parameter_name = "载具码",
  2442. Parameter_value = CarrierBarcode,
  2443. Parameter_unit = ""
  2444. });
  2445. items.Add(new TestItem()
  2446. {
  2447. Parameter_name = "产品码",
  2448. Parameter_value = sn,
  2449. Parameter_unit = ""
  2450. });
  2451. int result1 = 1;
  2452. if (direction == "Right")
  2453. {
  2454. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2455. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2456. }
  2457. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2458. stopwatch2.Start();
  2459. //进站结果写入PLC
  2460. CommandFromPLC resultToPlC = new CommandFromPLC();
  2461. resultToPlC.cmd = 0;
  2462. resultToPlC.cmdParam = 0; //指令参数
  2463. resultToPlC.cmdResult = mesResultFrmWeb;
  2464. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2465. stopwatch2.Stop();
  2466. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2467. //保存PLC返回MES数据到本地
  2468. ResponseMessage message = new ResponseMessage();
  2469. if (direction == "Left")
  2470. {
  2471. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2472. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2473. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2474. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2475. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2476. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2477. if (message.result == false)
  2478. {
  2479. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2480. }
  2481. }
  2482. if (direction == "Right")
  2483. {
  2484. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2485. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2486. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2487. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2488. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2489. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2490. if (message.result == false)
  2491. {
  2492. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2493. }
  2494. }
  2495. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2496. }
  2497. catch (Exception ex)
  2498. {
  2499. stopwatch2.Start();
  2500. CommandFromPLC resultToPlC = new CommandFromPLC();
  2501. resultToPlC.cmd = 0;
  2502. resultToPlC.cmdParam = 0; //指令参数
  2503. resultToPlC.cmdResult = 110;
  2504. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2505. stopwatch2.Stop();
  2506. string str = ex.StackTrace;
  2507. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2508. }
  2509. stopwatch1.Stop();
  2510. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2511. ProgressState = false;
  2512. }
  2513. #endregion S3
  2514. #region S4
  2515. /// <summary>
  2516. /// [S4] 点胶检测设备
  2517. /// </summary>
  2518. /// <param name="plcNo">PLC编号</param>
  2519. private void ReadStation_S4(int plcNo)
  2520. {
  2521. string stationCode = "[OP40]";
  2522. string stationName = "胶线检测";
  2523. string stationNameStr = stationCode + stationName;
  2524. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2525. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2526. string tagAgvCommName = "agvCommFrmPC";
  2527. string tagBarsetName = "BarcodeSet";
  2528. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2529. (int, string) result;
  2530. while (true)
  2531. {
  2532. try
  2533. {
  2534. if (!GlobalContext._IsCon_Funs1)
  2535. {
  2536. UpdatePLCMonitor(1, plcNo, 0);
  2537. continue;
  2538. }
  2539. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2540. {
  2541. Stopwatch stopwatch1 = new Stopwatch();
  2542. Stopwatch stopwatch2 = new Stopwatch();
  2543. stopwatch1.Start();
  2544. stopwatch2.Start();
  2545. #region 一次性读取所有数据
  2546. // 一次性读取所有数据
  2547. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2548. if (result.Item1 != 0)
  2549. {
  2550. //richTextBox1.AppendText("\n" + strRet);
  2551. }
  2552. else
  2553. {
  2554. //richTextBox1.AppendText("\n" + "读取成功");
  2555. }
  2556. #endregion 一次性读取所有数据
  2557. stopwatch2.Stop();
  2558. #region 进站
  2559. try
  2560. {
  2561. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2562. {
  2563. lock (lockObj)
  2564. {
  2565. if (!ProgressState)
  2566. {
  2567. ProgressState = true;
  2568. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2569. }
  2570. }
  2571. }
  2572. }
  2573. catch (Exception ex)
  2574. {
  2575. ProgressState = false;
  2576. string str = ex.StackTrace;
  2577. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2578. }
  2579. #endregion 进站
  2580. #region 出站
  2581. try
  2582. {
  2583. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2584. {
  2585. lock (lockObj)
  2586. {
  2587. if (!ProgressState)
  2588. {
  2589. ProgressState = true;
  2590. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2591. }
  2592. }
  2593. }
  2594. }
  2595. catch (Exception ex)
  2596. {
  2597. string str = ex.StackTrace;
  2598. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2599. }
  2600. #endregion 进站
  2601. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2602. stopwatch1.Stop();
  2603. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2604. }
  2605. else
  2606. {
  2607. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2608. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2609. FunsEip[plcNo].Connect(); // 重连
  2610. }
  2611. }
  2612. catch (Exception ex)
  2613. {
  2614. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2615. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2616. }
  2617. Thread.Sleep(IntervalReadPLC);
  2618. }
  2619. }
  2620. /// <summary>
  2621. /// [S4] 点胶检测设备 - 进站
  2622. /// </summary>
  2623. /// <param name="plcNo">PLC编号</param>
  2624. /// <param name="stationNameStr">工站全称</param>
  2625. /// <param name="stPLC_MesData"></param>
  2626. /// <param name="tagMesCommName"></param>
  2627. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2628. {
  2629. Stopwatch stopwatch1 = new Stopwatch();
  2630. Stopwatch stopwatch2 = new Stopwatch();
  2631. try
  2632. {
  2633. stopwatch1.Start();
  2634. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2635. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2636. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2637. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2638. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2639. //载具码验证产品码
  2640. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2641. if (string.IsNullOrEmpty(strProductBarcode))
  2642. {
  2643. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2644. }
  2645. sn = strProductBarcode;
  2646. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2647. // 产品SN(物料码)校验
  2648. List<TestItem> item = new List<TestItem>();
  2649. stopwatch2.Start();
  2650. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2651. stopwatch2.Stop();
  2652. //指令执行结果 1:OK 110:失败
  2653. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2654. //进站结果写入PLC
  2655. CommandFromPLC resultToPlC = new CommandFromPLC();
  2656. resultToPlC.cmd = 0;
  2657. resultToPlC.cmdParam = 0; //指令参数
  2658. resultToPlC.cmdResult = mesResultFrmWeb;
  2659. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2660. }
  2661. catch (Exception ex)
  2662. {
  2663. string str = ex.StackTrace;
  2664. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2665. CommandFromPLC resultToPlC = new CommandFromPLC();
  2666. resultToPlC.cmd = 0;
  2667. resultToPlC.cmdParam = 0; //指令参数
  2668. resultToPlC.cmdResult = 110;
  2669. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2670. }
  2671. stopwatch1.Stop();
  2672. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2673. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2674. ProgressState = false;
  2675. }
  2676. /// <summary>
  2677. /// [S4] 点胶检测设备 - 出站接口
  2678. /// </summary>
  2679. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2680. {
  2681. Stopwatch stopwatch1 = new Stopwatch();
  2682. Stopwatch stopwatch2 = new Stopwatch();
  2683. try
  2684. {
  2685. stopwatch1.Start();
  2686. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2687. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2688. string processItem = stationName; // 测试项目
  2689. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2690. string supplierCode = ""; // 供应商代码
  2691. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2692. string batch_num = GlobalContext.BatchNumber; // 批次号
  2693. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2694. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2695. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2696. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2697. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2698. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2699. bool pass = a1Result == 1;
  2700. //根据载具码获取产品码
  2701. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2702. if (string.IsNullOrEmpty(strProductBarcode))
  2703. {
  2704. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2705. }
  2706. sn = strProductBarcode;
  2707. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2708. List<TestItem> items = new List<TestItem>();
  2709. items.Add(new TestItem()
  2710. {
  2711. Parameter_name = "载具码",
  2712. Parameter_value = CarrierBarcode,
  2713. Parameter_unit = ""
  2714. });
  2715. items.Add(new TestItem()
  2716. {
  2717. Parameter_name = "产品码",
  2718. Parameter_value = sn,
  2719. Parameter_unit = ""
  2720. });
  2721. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2722. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2723. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2724. stopwatch2.Start();
  2725. //进站结果写入PLC
  2726. CommandFromPLC resultToPlC = new CommandFromPLC();
  2727. resultToPlC.cmd = 0;
  2728. resultToPlC.cmdParam = 0; //指令参数
  2729. resultToPlC.cmdResult = mesResultFrmWeb;
  2730. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2731. stopwatch2.Stop();
  2732. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2733. //保存PLC返回MES数据到本地
  2734. ResponseMessage message = new ResponseMessage();
  2735. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2736. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2737. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2738. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2739. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2740. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2741. if (message.result == false)
  2742. {
  2743. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2744. }
  2745. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2746. }
  2747. catch (Exception ex)
  2748. {
  2749. stopwatch2.Start();
  2750. CommandFromPLC resultToPlC = new CommandFromPLC();
  2751. resultToPlC.cmd = 0;
  2752. resultToPlC.cmdParam = 0; //指令参数
  2753. resultToPlC.cmdResult = 110;
  2754. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2755. stopwatch2.Stop();
  2756. string str = ex.StackTrace;
  2757. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2758. }
  2759. stopwatch1.Stop();
  2760. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2761. ProgressState = false;
  2762. }
  2763. #endregion
  2764. #region S5
  2765. /// <summary>
  2766. /// [S5] 点胶检测设备
  2767. /// </summary>
  2768. /// <param name="plcNo">PLC编号</param>
  2769. private void ReadStation_S5(int plcNo)
  2770. {
  2771. string stationCode = "[OP50]";
  2772. string stationName = "ADD板上料组装装备";
  2773. string stationNameStr = stationCode + stationName;
  2774. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2775. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2776. string tagAgvCommName = "agvCommFrmPC";
  2777. string tagBarsetName = "BarcodeSet";
  2778. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2779. (int, string) result;
  2780. while (true)
  2781. {
  2782. try
  2783. {
  2784. if (!GlobalContext._IsCon_Funs1)
  2785. {
  2786. UpdatePLCMonitor(1, plcNo, 0);
  2787. continue;
  2788. }
  2789. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2790. {
  2791. Stopwatch stopwatch1 = new Stopwatch();
  2792. Stopwatch stopwatch2 = new Stopwatch();
  2793. stopwatch1.Start();
  2794. stopwatch2.Start();
  2795. #region 一次性读取所有数据
  2796. // 一次性读取所有数据
  2797. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2798. if (result.Item1 != 0)
  2799. {
  2800. //richTextBox1.AppendText("\n" + strRet);
  2801. }
  2802. else
  2803. {
  2804. //richTextBox1.AppendText("\n" + "读取成功");
  2805. }
  2806. #endregion 一次性读取所有数据
  2807. stopwatch2.Stop();
  2808. #region 进站
  2809. try
  2810. {
  2811. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2812. {
  2813. lock (lockObj)
  2814. {
  2815. if (!ProgressState)
  2816. {
  2817. ProgressState = true;
  2818. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2819. }
  2820. }
  2821. }
  2822. }
  2823. catch (Exception ex)
  2824. {
  2825. ProgressState = false;
  2826. string str = ex.StackTrace;
  2827. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2828. }
  2829. #endregion 进站
  2830. #region 出站
  2831. try
  2832. {
  2833. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2834. {
  2835. lock (lockObj)
  2836. {
  2837. if (!ProgressState)
  2838. {
  2839. ProgressState = true;
  2840. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2841. }
  2842. }
  2843. }
  2844. }
  2845. catch (Exception ex)
  2846. {
  2847. ProgressState = false;
  2848. string str = ex.StackTrace;
  2849. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2850. }
  2851. #endregion 进站
  2852. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2853. stopwatch1.Stop();
  2854. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2855. }
  2856. else
  2857. {
  2858. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2859. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2860. FunsEip[plcNo].Connect(); // 重连
  2861. }
  2862. }
  2863. catch (Exception ex)
  2864. {
  2865. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2866. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2867. }
  2868. Thread.Sleep(IntervalReadPLC);
  2869. }
  2870. }
  2871. /// <summary>
  2872. /// [S5] 点胶检测设备 - 进站
  2873. /// </summary>
  2874. /// <param name="plcNo">PLC编号</param>
  2875. /// <param name="stationNameStr">工站全称</param>
  2876. /// <param name="stPLC_MesData"></param>
  2877. /// <param name="tagMesCommName"></param>
  2878. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2879. {
  2880. Stopwatch stopwatch1 = new Stopwatch();
  2881. Stopwatch stopwatch2 = new Stopwatch();
  2882. try
  2883. {
  2884. stopwatch1.Start();
  2885. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2886. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2887. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2888. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2889. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2890. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2891. //载具码验证产品码 //载具码验证产品码
  2892. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2893. if (string.IsNullOrEmpty(strProductBarcode))
  2894. {
  2895. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2896. }
  2897. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2898. //if (sn != strProductBarcode)
  2899. //{
  2900. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2901. //}
  2902. sn = strProductBarcode;
  2903. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2904. // 产品SN(物料码)校验
  2905. List<TestItem> item = new List<TestItem>();
  2906. stopwatch2.Start();
  2907. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2908. stopwatch2.Stop();
  2909. //指令执行结果 1:OK 110:失败
  2910. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2911. //进站结果写入PLC
  2912. CommandFromPLC resultToPlC = new CommandFromPLC();
  2913. resultToPlC.cmd = 0;
  2914. resultToPlC.cmdParam = 0; //指令参数
  2915. resultToPlC.cmdResult = mesResultFrmWeb;
  2916. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2917. }
  2918. catch (Exception ex)
  2919. {
  2920. string str = ex.StackTrace;
  2921. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2922. CommandFromPLC resultToPlC = new CommandFromPLC();
  2923. resultToPlC.cmd = 0;
  2924. resultToPlC.cmdParam = 0; //指令参数
  2925. resultToPlC.cmdResult = 110;
  2926. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2927. }
  2928. stopwatch1.Stop();
  2929. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2930. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2931. ProgressState = false;
  2932. }
  2933. /// <summary>
  2934. /// [S5] 点胶检测设备 - 出站接口
  2935. /// </summary>
  2936. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2937. {
  2938. Stopwatch stopwatch1 = new Stopwatch();
  2939. Stopwatch stopwatch2 = new Stopwatch();
  2940. try
  2941. {
  2942. stopwatch1.Start();
  2943. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2944. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2945. string processItem = stationName; // 测试项目
  2946. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2947. string supplierCode = ""; // 供应商代码
  2948. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2949. string batch_num = GlobalContext.BatchNumber; // 批次号
  2950. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2951. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2952. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2953. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2954. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2955. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2956. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2957. bool pass = a1Result == 1;
  2958. //根据载具码获取产品码
  2959. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2960. if (string.IsNullOrEmpty(strProductBarcode))
  2961. {
  2962. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2963. }
  2964. sn = strProductBarcode;
  2965. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2966. List<TestItem> items = new List<TestItem>();
  2967. items.Add(new TestItem()
  2968. {
  2969. Parameter_name = "载具码",
  2970. Parameter_value = CarrierBarcode,
  2971. Parameter_unit = ""
  2972. });
  2973. items.Add(new TestItem()
  2974. {
  2975. Parameter_name = "产品码",
  2976. Parameter_value = sn,
  2977. Parameter_unit = ""
  2978. });
  2979. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2980. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2981. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2982. stopwatch2.Start();
  2983. //进站结果写入PLC
  2984. CommandFromPLC resultToPlC = new CommandFromPLC();
  2985. resultToPlC.cmd = 0;
  2986. resultToPlC.cmdParam = 0; //指令参数
  2987. resultToPlC.cmdResult = mesResultFrmWeb;
  2988. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2989. stopwatch2.Stop();
  2990. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2991. //保存PLC返回MES数据到本地
  2992. ResponseMessage message = new ResponseMessage();
  2993. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  2994. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  2995. if (message.result == false)
  2996. {
  2997. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2998. }
  2999. //保存部件码信息
  3000. if (!string.IsNullOrEmpty(PartBarcode))
  3001. {
  3002. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  3003. if (message.result == false)
  3004. {
  3005. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  3006. }
  3007. }
  3008. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3009. }
  3010. catch (Exception ex)
  3011. {
  3012. stopwatch2.Start();
  3013. CommandFromPLC resultToPlC = new CommandFromPLC();
  3014. resultToPlC.cmd = 0;
  3015. resultToPlC.cmdParam = 0; //指令参数
  3016. resultToPlC.cmdResult = 110;
  3017. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3018. stopwatch2.Stop();
  3019. string str = ex.StackTrace;
  3020. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3021. }
  3022. stopwatch1.Stop();
  3023. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3024. ProgressState = false;
  3025. }
  3026. #endregion
  3027. #region S6
  3028. /// <summary>
  3029. /// [S6] 顶盖装配设备
  3030. /// </summary>
  3031. /// <param name="plcNo">PLC编号</param>
  3032. private void ReadStation_S6(int plcNo)
  3033. {
  3034. string stationCode = "[OP60]";
  3035. string stationName = "组上盖板";
  3036. string stationNameStr = stationCode + stationName;
  3037. string tagBaseName = "g_OP60_MES"; //标签变量名称
  3038. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3039. string tagAgvCommName = "agvCommFrmPC";
  3040. string tagBarsetName = "BarcodeSet";
  3041. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  3042. (int, string) result;
  3043. while (true)
  3044. {
  3045. try
  3046. {
  3047. if (!GlobalContext._IsCon_Funs1)
  3048. {
  3049. UpdatePLCMonitor(1, plcNo, 0);
  3050. continue;
  3051. }
  3052. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3053. {
  3054. Stopwatch stopwatch1 = new Stopwatch();
  3055. Stopwatch stopwatch2 = new Stopwatch();
  3056. stopwatch1.Start();
  3057. stopwatch2.Start();
  3058. #region 一次性读取所有数据
  3059. // 一次性读取所有数据
  3060. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3061. if (result.Item1 != 0)
  3062. {
  3063. //richTextBox1.AppendText("\n" + strRet);
  3064. }
  3065. else
  3066. {
  3067. //richTextBox1.AppendText("\n" + "读取成功");
  3068. }
  3069. #endregion 一次性读取所有数据
  3070. stopwatch2.Stop();
  3071. #region 进站
  3072. try
  3073. {
  3074. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3075. {
  3076. lock (lockObj)
  3077. {
  3078. if (!ProgressState)
  3079. {
  3080. ProgressState = true;
  3081. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3082. }
  3083. }
  3084. }
  3085. }
  3086. catch (Exception ex)
  3087. {
  3088. ProgressState = false;
  3089. string str = ex.StackTrace;
  3090. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3091. }
  3092. #endregion 进站
  3093. #region 出站
  3094. try
  3095. {
  3096. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3097. {
  3098. lock (lockObj)
  3099. {
  3100. if (!ProgressState)
  3101. {
  3102. ProgressState = true; ;
  3103. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3104. }
  3105. }
  3106. }
  3107. }
  3108. catch (Exception ex)
  3109. {
  3110. ProgressState = false;
  3111. string str = ex.StackTrace;
  3112. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3113. }
  3114. #endregion 进站
  3115. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3116. stopwatch1.Stop();
  3117. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3118. }
  3119. else
  3120. {
  3121. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3122. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3123. FunsEip[plcNo].Connect(); // 重连
  3124. }
  3125. }
  3126. catch (Exception ex)
  3127. {
  3128. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3129. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3130. }
  3131. Thread.Sleep(IntervalReadPLC);
  3132. }
  3133. }
  3134. /// <summary>
  3135. /// [S6] 顶盖装配设备 - 进站
  3136. /// </summary>
  3137. /// <param name="plcNo">PLC编号</param>
  3138. /// <param name="stationNameStr">工站全称</param>
  3139. /// <param name="stPLC_MesData"></param>
  3140. /// <param name="tagMesCommName"></param>
  3141. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3142. {
  3143. Stopwatch stopwatch1 = new Stopwatch();
  3144. Stopwatch stopwatch2 = new Stopwatch();
  3145. try
  3146. {
  3147. stopwatch1.Start();
  3148. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3149. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3150. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3151. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3152. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3153. //载具码验证产品码
  3154. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3155. if (string.IsNullOrEmpty(strProductBarcode))
  3156. {
  3157. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3158. }
  3159. sn = strProductBarcode;
  3160. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3161. // 产品SN(物料码)校验
  3162. List<TestItem> item = new List<TestItem>();
  3163. stopwatch2.Start();
  3164. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3165. stopwatch2.Stop();
  3166. //指令执行结果 1:OK 110:失败
  3167. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3168. //进站结果写入PLC
  3169. CommandFromPLC resultToPlC = new CommandFromPLC();
  3170. resultToPlC.cmd = 0;
  3171. resultToPlC.cmdParam = 0; //指令参数
  3172. resultToPlC.cmdResult = mesResultFrmWeb;
  3173. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3174. }
  3175. catch (Exception ex)
  3176. {
  3177. string str = ex.StackTrace;
  3178. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3179. CommandFromPLC resultToPlC = new CommandFromPLC();
  3180. resultToPlC.cmd = 0;
  3181. resultToPlC.cmdParam = 0; //指令参数
  3182. resultToPlC.cmdResult = 110;
  3183. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3184. }
  3185. stopwatch1.Stop();
  3186. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3187. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3188. ProgressState = false;
  3189. }
  3190. /// <summary>
  3191. /// [S6] 顶盖装配设备 - 出站接口
  3192. /// </summary>
  3193. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3194. {
  3195. Stopwatch stopwatch1 = new Stopwatch();
  3196. Stopwatch stopwatch2 = new Stopwatch();
  3197. try
  3198. {
  3199. stopwatch1.Start();
  3200. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3201. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3202. string processItem = stationName; // 测试项目
  3203. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3204. string supplierCode = ""; // 供应商代码
  3205. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3206. string batch_num = GlobalContext.BatchNumber; // 批次号
  3207. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3208. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3209. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3210. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3211. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3212. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3213. bool pass = a1Result == 1;
  3214. //根据载具码获取产品码
  3215. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3216. if (string.IsNullOrEmpty(strProductBarcode))
  3217. {
  3218. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3219. }
  3220. sn = strProductBarcode;
  3221. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3222. List<TestItem> items = new List<TestItem>();
  3223. items.Add(new TestItem()
  3224. {
  3225. Parameter_name = "载具码",
  3226. Parameter_value = CarrierBarcode,
  3227. Parameter_unit = ""
  3228. });
  3229. items.Add(new TestItem()
  3230. {
  3231. Parameter_name = "产品码",
  3232. Parameter_value = sn,
  3233. Parameter_unit = ""
  3234. });
  3235. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3236. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3237. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3238. stopwatch2.Start();
  3239. //进站结果写入PLC
  3240. CommandFromPLC resultToPlC = new CommandFromPLC();
  3241. resultToPlC.cmd = 0;
  3242. resultToPlC.cmdParam = 0; //指令参数
  3243. resultToPlC.cmdResult = mesResultFrmWeb;
  3244. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3245. stopwatch2.Stop();
  3246. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3247. //保存PLC返回MES数据到本地
  3248. ResponseMessage message = new ResponseMessage();
  3249. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3250. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3251. if (message.result == false)
  3252. {
  3253. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3254. }
  3255. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3256. }
  3257. catch (Exception ex)
  3258. {
  3259. stopwatch2.Start();
  3260. CommandFromPLC resultToPlC = new CommandFromPLC();
  3261. resultToPlC.cmd = 0;
  3262. resultToPlC.cmdParam = 0; //指令参数
  3263. resultToPlC.cmdResult = 110;
  3264. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3265. stopwatch2.Stop();
  3266. string str = ex.StackTrace;
  3267. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3268. }
  3269. stopwatch1.Stop();
  3270. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3271. ProgressState = false;
  3272. }
  3273. #endregion
  3274. #region S7
  3275. /// <summary>
  3276. /// [S7] 锁螺丝设备
  3277. /// </summary>
  3278. /// <param name="plcNo">PLC编号</param>
  3279. private void ReadStation_S7(int plcNo)
  3280. {
  3281. string stationCode = "[OP70]";
  3282. string stationName = "上盖板锁螺丝";
  3283. string stationNameStr = stationCode + stationName;
  3284. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3285. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3286. string tagAgvCommName = "agvCommFrmPC";
  3287. string tagBarsetName = "BarcodeSet";
  3288. string tagScrewDataset = "screwDataset";
  3289. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3290. (int, string) result;
  3291. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3292. atlasScrewLeft.Initial();
  3293. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3294. atlasScrewRight.Initial();
  3295. while (true)
  3296. {
  3297. try
  3298. {
  3299. if (!GlobalContext._IsCon_Funs1)
  3300. {
  3301. UpdatePLCMonitor(1, plcNo, 0);
  3302. continue;
  3303. }
  3304. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3305. {
  3306. Stopwatch stopwatch1 = new Stopwatch();
  3307. Stopwatch stopwatch2 = new Stopwatch();
  3308. stopwatch1.Start();
  3309. stopwatch2.Start();
  3310. #region 一次性读取所有数据
  3311. // 一次性读取所有数据
  3312. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3313. if (result.Item1 != 0)
  3314. {
  3315. //richTextBox1.AppendText("\n" + strRet);
  3316. }
  3317. else
  3318. {
  3319. //richTextBox1.AppendText("\n" + "读取成功");
  3320. }
  3321. #endregion 一次性读取所有数据
  3322. stopwatch2.Stop();
  3323. #region 左边进站
  3324. try
  3325. {
  3326. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3327. {
  3328. lock (lockObj)
  3329. {
  3330. if (!ProgressState)
  3331. {
  3332. ProgressState = true;
  3333. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3334. }
  3335. }
  3336. }
  3337. }
  3338. catch (Exception ex)
  3339. {
  3340. ProgressState = false;
  3341. string str = ex.StackTrace;
  3342. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3343. }
  3344. #endregion 左边进站
  3345. #region 左边出站
  3346. try
  3347. {
  3348. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3349. {
  3350. lock (lockObj)
  3351. {
  3352. if (!ProgressState)
  3353. {
  3354. ProgressState = true;
  3355. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3356. }
  3357. }
  3358. }
  3359. }
  3360. catch (Exception ex)
  3361. {
  3362. ProgressState = false;
  3363. string str = ex.StackTrace;
  3364. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3365. }
  3366. #endregion 左边出站
  3367. #region 右边进站
  3368. try
  3369. {
  3370. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3371. {
  3372. lock (lockObj)
  3373. {
  3374. if (!ProgressState)
  3375. {
  3376. ProgressState = true;
  3377. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3378. }
  3379. }
  3380. }
  3381. }
  3382. catch (Exception ex)
  3383. {
  3384. ProgressState = false;
  3385. string str = ex.StackTrace;
  3386. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3387. }
  3388. #endregion 右边进站
  3389. #region 右边出站
  3390. try
  3391. {
  3392. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3393. {
  3394. lock (lockObj)
  3395. {
  3396. if (!ProgressState)
  3397. {
  3398. ProgressState = true;
  3399. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3400. }
  3401. }
  3402. }
  3403. }
  3404. catch (Exception ex)
  3405. {
  3406. ProgressState = false;
  3407. string str = ex.StackTrace;
  3408. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3409. }
  3410. #endregion 右边出站
  3411. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3412. stopwatch1.Stop();
  3413. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3414. }
  3415. else
  3416. {
  3417. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3418. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3419. FunsEip[plcNo].Connect(); // 重连
  3420. }
  3421. }
  3422. catch (Exception ex)
  3423. {
  3424. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3425. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3426. }
  3427. Thread.Sleep(IntervalReadPLC);
  3428. }
  3429. }
  3430. /// <summary>
  3431. /// [S7] 锁螺丝设备 - 进站
  3432. /// </summary>
  3433. /// <param name="plcNo">PLC编号</param>
  3434. /// <param name="stationNameStr">工站全称</param>
  3435. /// <param name="stPLC_MesData"></param>
  3436. /// <param name="tagMesCommName"></param>
  3437. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3438. {
  3439. Stopwatch stopwatch1 = new Stopwatch();
  3440. Stopwatch stopwatch2 = new Stopwatch();
  3441. string atlasSn=string.Empty;
  3442. try
  3443. {
  3444. stopwatch1.Start();
  3445. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3446. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3447. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3448. string StationId = string.Empty; // 工位ID(可配置)
  3449. if (direction == "Left")
  3450. {
  3451. StationId = GlobalContext.S7_StationId_1;
  3452. }
  3453. if (direction == "Right")
  3454. {
  3455. StationId = GlobalContext.S7_StationId_2;
  3456. }
  3457. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3458. //载具码验证产品码
  3459. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3460. if (string.IsNullOrEmpty(strProductBarcode))
  3461. {
  3462. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3463. }
  3464. sn = strProductBarcode;
  3465. atlasSn= strProductBarcode;
  3466. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3467. if (direction == "Left")
  3468. {
  3469. isCollectingFlagLeft = false;//采集螺丝数据结束
  3470. }
  3471. if (direction == "Right")
  3472. {
  3473. isCollectingFlagRight = false;//采集螺丝数据结束
  3474. }
  3475. // 产品SN(物料码)校验
  3476. List<TestItem> item = new List<TestItem>();
  3477. stopwatch2.Start();
  3478. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3479. stopwatch2.Stop();
  3480. //指令执行结果 1:OK 110:失败
  3481. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3482. //进站结果写入PLC
  3483. CommandFromPLC resultToPlC = new CommandFromPLC();
  3484. resultToPlC.cmd = 0;
  3485. resultToPlC.cmdParam = 0; //指令参数
  3486. resultToPlC.cmdResult = mesResultFrmWeb;
  3487. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3488. }
  3489. catch (Exception ex)
  3490. {
  3491. string str = ex.StackTrace;
  3492. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3493. CommandFromPLC resultToPlC = new CommandFromPLC();
  3494. resultToPlC.cmd = 0;
  3495. resultToPlC.cmdParam = 0; //指令参数
  3496. resultToPlC.cmdResult = 110;
  3497. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3498. }
  3499. stopwatch1.Stop();
  3500. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3501. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3502. ProgressState = false;
  3503. //开始采集螺丝数据
  3504. if (direction == "Left")
  3505. {
  3506. isCollectingFlagLeft = true;
  3507. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3508. }
  3509. if (direction == "Right")
  3510. {
  3511. isCollectingFlagRight = true;
  3512. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3513. }
  3514. }
  3515. /// <summary>
  3516. /// [S7] 锁螺丝设备 - 出站
  3517. /// </summary>
  3518. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3519. {
  3520. Stopwatch stopwatch1 = new Stopwatch();
  3521. Stopwatch stopwatch2 = new Stopwatch();
  3522. try
  3523. {
  3524. stopwatch1.Start();
  3525. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3526. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3527. string processItem = stationName; // 测试项目
  3528. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3529. string supplierCode = ""; // 供应商代码
  3530. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3531. string batch_num = GlobalContext.BatchNumber; // 批次号
  3532. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3533. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3534. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3535. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3536. string StationId = string.Empty; // 工位ID(可配置)
  3537. if (direction == "Left")
  3538. {
  3539. StationId = GlobalContext.S7_StationId_1;
  3540. }
  3541. if (direction == "Right")
  3542. {
  3543. StationId = GlobalContext.S7_StationId_2;
  3544. }
  3545. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3546. a1Result = 1;
  3547. bool pass = a1Result == 1;
  3548. //根据载具码获取产品码
  3549. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3550. if (string.IsNullOrEmpty(strProductBarcode))
  3551. {
  3552. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3553. }
  3554. sn = strProductBarcode;
  3555. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3556. List<TestItem> items = new List<TestItem>();
  3557. items.Add(new TestItem()
  3558. {
  3559. Parameter_name = "载具码",
  3560. Parameter_value = CarrierBarcode,
  3561. Parameter_unit = ""
  3562. });
  3563. items.Add(new TestItem()
  3564. {
  3565. Parameter_name = "产品码",
  3566. Parameter_value = sn,
  3567. Parameter_unit = ""
  3568. });
  3569. int result1 = 1;
  3570. if (direction == "Right")
  3571. {
  3572. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3573. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3574. }
  3575. //if (direction == "Left")
  3576. //{
  3577. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3578. //}
  3579. //if (direction == "Right")
  3580. //{
  3581. // isCollectingFlagRight = false;//采集螺丝数据结束
  3582. //}
  3583. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3584. stopwatch2.Start();
  3585. //进站结果写入PLC
  3586. CommandFromPLC resultToPlC = new CommandFromPLC();
  3587. resultToPlC.cmd = 0;
  3588. resultToPlC.cmdParam = 0; //指令参数
  3589. resultToPlC.cmdResult = mesResultFrmWeb;
  3590. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3591. stopwatch2.Stop();
  3592. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3593. //保存PLC返回MES数据到本地
  3594. ResponseMessage message = new ResponseMessage();
  3595. if (direction == "Left")
  3596. {
  3597. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3598. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3599. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3600. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3601. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3602. if (message.result == false)
  3603. {
  3604. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3605. }
  3606. }
  3607. if (direction == "Right")
  3608. {
  3609. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3610. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3611. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3612. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3613. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3614. if (message.result == false)
  3615. {
  3616. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3617. }
  3618. }
  3619. //保存螺丝数据到txt
  3620. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3621. if (result.Item1 != 0)
  3622. {
  3623. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3624. }
  3625. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3626. }
  3627. catch (Exception ex)
  3628. {
  3629. stopwatch2.Start();
  3630. CommandFromPLC resultToPlC = new CommandFromPLC();
  3631. resultToPlC.cmd = 0;
  3632. resultToPlC.cmdParam = 0; //指令参数
  3633. resultToPlC.cmdResult = 110;
  3634. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3635. stopwatch2.Stop();
  3636. string str = ex.StackTrace;
  3637. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3638. }
  3639. stopwatch1.Stop();
  3640. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3641. ProgressState = false;
  3642. }
  3643. #endregion
  3644. #region S8
  3645. /// <summary>
  3646. /// [S8] 3D螺丝高度检测设备
  3647. /// </summary>
  3648. /// <param name="plcNo">PLC编号</param>
  3649. private void ReadStation_S8(int plcNo)
  3650. {
  3651. string stationCode = "[OP80]";
  3652. string stationName = "NG下料";
  3653. string stationNameStr = stationCode + stationName;
  3654. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3655. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3656. string tagAgvCommName = "agvCommFrmPC";
  3657. string tagBarsetName = "BarcodeSet";
  3658. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3659. (int, string) result;
  3660. while (true)
  3661. {
  3662. try
  3663. {
  3664. if (!GlobalContext._IsCon_Funs1)
  3665. {
  3666. UpdatePLCMonitor(1, plcNo, 0);
  3667. continue;
  3668. }
  3669. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3670. {
  3671. Stopwatch stopwatch1 = new Stopwatch();
  3672. Stopwatch stopwatch2 = new Stopwatch();
  3673. stopwatch1.Start();
  3674. stopwatch2.Start();
  3675. #region 一次性读取所有数据
  3676. // 一次性读取所有数据
  3677. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3678. if (result.Item1 != 0)
  3679. {
  3680. //richTextBox1.AppendText("\n" + strRet);
  3681. }
  3682. else
  3683. {
  3684. //richTextBox1.AppendText("\n" + "读取成功");
  3685. }
  3686. #endregion 一次性读取所有数据
  3687. stopwatch2.Stop();
  3688. #region 进站
  3689. try
  3690. {
  3691. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3692. {
  3693. lock (lockObj)
  3694. {
  3695. if (!ProgressState)
  3696. {
  3697. ProgressState = true;
  3698. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3699. }
  3700. }
  3701. }
  3702. }
  3703. catch (Exception ex)
  3704. {
  3705. ProgressState = false;
  3706. string str = ex.StackTrace;
  3707. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3708. }
  3709. #endregion 进站
  3710. #region 出站
  3711. try
  3712. {
  3713. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3714. {
  3715. lock (lockObj)
  3716. {
  3717. if (!ProgressState)
  3718. {
  3719. ProgressState = true;
  3720. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3721. }
  3722. }
  3723. }
  3724. }
  3725. catch (Exception ex)
  3726. {
  3727. ProgressState = false;
  3728. string str = ex.StackTrace;
  3729. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3730. }
  3731. #endregion 进站
  3732. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3733. stopwatch1.Stop();
  3734. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3735. }
  3736. else
  3737. {
  3738. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3739. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3740. FunsEip[plcNo].Connect(); // 重连
  3741. }
  3742. }
  3743. catch (Exception ex)
  3744. {
  3745. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3746. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3747. }
  3748. Thread.Sleep(IntervalReadPLC);
  3749. }
  3750. }
  3751. /// <summary>
  3752. /// [S8] 3D螺丝高度检测设备 - 进站
  3753. /// </summary>
  3754. /// <param name="plcNo">PLC编号</param>
  3755. /// <param name="stationNameStr">工站全称</param>
  3756. /// <param name="stPLC_MesData"></param>
  3757. /// <param name="tagMesCommName"></param>
  3758. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3759. {
  3760. Stopwatch stopwatch1 = new Stopwatch();
  3761. Stopwatch stopwatch2 = new Stopwatch();
  3762. try
  3763. {
  3764. stopwatch1.Start();
  3765. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3766. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3767. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3768. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3769. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3770. //载具码验证产品码
  3771. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3772. if (string.IsNullOrEmpty(strProductBarcode))
  3773. {
  3774. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3775. }
  3776. sn = strProductBarcode;
  3777. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3778. // 产品SN(物料码)校验
  3779. List<TestItem> item = new List<TestItem>();
  3780. stopwatch2.Start();
  3781. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3782. stopwatch2.Stop();
  3783. //指令执行结果 1:OK 110:失败
  3784. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3785. //进站结果写入PLC
  3786. CommandFromPLC resultToPlC = new CommandFromPLC();
  3787. resultToPlC.cmd = 0;
  3788. resultToPlC.cmdParam = 0; //指令参数
  3789. resultToPlC.cmdResult = mesResultFrmWeb;
  3790. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3791. }
  3792. catch (Exception ex)
  3793. {
  3794. string str = ex.StackTrace;
  3795. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3796. CommandFromPLC resultToPlC = new CommandFromPLC();
  3797. resultToPlC.cmd = 0;
  3798. resultToPlC.cmdParam = 0; //指令参数
  3799. resultToPlC.cmdResult = 110;
  3800. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3801. }
  3802. stopwatch1.Stop();
  3803. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3804. ProgressState = false;
  3805. }
  3806. /// <summary>
  3807. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3808. /// </summary>
  3809. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3810. {
  3811. Stopwatch stopwatch1 = new Stopwatch();
  3812. Stopwatch stopwatch2 = new Stopwatch();
  3813. try
  3814. {
  3815. stopwatch1.Start();
  3816. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3817. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3818. string processItem = stationName; // 测试项目
  3819. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3820. string supplierCode = ""; // 供应商代码
  3821. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3822. string batch_num = GlobalContext.BatchNumber; // 批次号
  3823. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3824. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3825. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3826. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3827. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3828. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3829. bool pass = a1Result == 1;
  3830. //根据载具码获取产品码
  3831. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3832. if (string.IsNullOrEmpty(strProductBarcode))
  3833. {
  3834. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3835. }
  3836. sn = strProductBarcode;
  3837. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3838. List<TestItem> items = new List<TestItem>();
  3839. items.Add(new TestItem()
  3840. {
  3841. Parameter_name = "载具码",
  3842. Parameter_value = CarrierBarcode,
  3843. Parameter_unit = ""
  3844. });
  3845. items.Add(new TestItem()
  3846. {
  3847. Parameter_name = "产品码",
  3848. Parameter_value = sn,
  3849. Parameter_unit = ""
  3850. });
  3851. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3852. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3853. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3854. stopwatch2.Start();
  3855. //进站结果写入PLC
  3856. CommandFromPLC resultToPlC = new CommandFromPLC();
  3857. resultToPlC.cmd = 0;
  3858. resultToPlC.cmdParam = 0; //指令参数
  3859. resultToPlC.cmdResult = mesResultFrmWeb;
  3860. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3861. stopwatch2.Stop();
  3862. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3863. //保存PLC返回MES数据到本地
  3864. ResponseMessage message = new ResponseMessage();
  3865. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3866. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3867. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3868. if (message.result == false)
  3869. {
  3870. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3871. }
  3872. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3873. }
  3874. catch (Exception ex)
  3875. {
  3876. stopwatch2.Start();
  3877. CommandFromPLC resultToPlC = new CommandFromPLC();
  3878. resultToPlC.cmd = 0;
  3879. resultToPlC.cmdParam = 0; //指令参数
  3880. resultToPlC.cmdResult = 110;
  3881. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3882. stopwatch2.Stop();
  3883. string str = ex.StackTrace;
  3884. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3885. }
  3886. stopwatch1.Stop();
  3887. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3888. ProgressState = false;
  3889. }
  3890. #endregion
  3891. #region S9
  3892. /// <summary>
  3893. /// [S9] 下料设备
  3894. /// </summary>
  3895. /// <param name="plcNo">PLC编号</param>
  3896. private void ReadStation_S9(int plcNo)
  3897. {
  3898. string stationCode = "[OP90]";
  3899. string stationName = "半成品下料";
  3900. string stationNameStr = stationCode + stationName;
  3901. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3902. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3903. string tagAgvCommName = "agvCommFrmPC";
  3904. string tagBarsetName = "BarcodeSet";
  3905. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3906. (int, string) result;
  3907. while (true)
  3908. {
  3909. try
  3910. {
  3911. if (!GlobalContext._IsCon_Funs1)
  3912. {
  3913. UpdatePLCMonitor(1, plcNo, 0);
  3914. continue;
  3915. }
  3916. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3917. {
  3918. Stopwatch stopwatch1 = new Stopwatch();
  3919. Stopwatch stopwatch2 = new Stopwatch();
  3920. stopwatch1.Start();
  3921. stopwatch2.Start();
  3922. #region 一次性读取所有数据
  3923. // 一次性读取所有数据
  3924. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3925. if (result.Item1 != 0)
  3926. {
  3927. //richTextBox1.AppendText("\n" + strRet);
  3928. }
  3929. else
  3930. {
  3931. //richTextBox1.AppendText("\n" + "读取成功");
  3932. }
  3933. #endregion 一次性读取所有数据
  3934. stopwatch2.Stop();
  3935. #region 进站
  3936. try
  3937. {
  3938. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3939. {
  3940. lock (lockObj)
  3941. {
  3942. if (!ProgressState)
  3943. {
  3944. ProgressState = true;
  3945. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3946. }
  3947. }
  3948. }
  3949. }
  3950. catch (Exception ex)
  3951. {
  3952. ProgressState = false;
  3953. string str = ex.StackTrace;
  3954. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3955. }
  3956. #endregion 进站
  3957. #region 出站
  3958. try
  3959. {
  3960. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3961. {
  3962. lock (lockObj)
  3963. {
  3964. if (!ProgressState)
  3965. {
  3966. ProgressState = true;
  3967. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3968. }
  3969. }
  3970. }
  3971. }
  3972. catch (Exception ex)
  3973. {
  3974. ProgressState = false;
  3975. string str = ex.StackTrace;
  3976. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3977. }
  3978. #endregion 进站
  3979. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3980. stopwatch1.Stop();
  3981. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3982. }
  3983. else
  3984. {
  3985. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3986. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3987. FunsEip[plcNo].Connect(); // 重连
  3988. }
  3989. }
  3990. catch (Exception ex)
  3991. {
  3992. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3993. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3994. }
  3995. Thread.Sleep(IntervalReadPLC);
  3996. }
  3997. }
  3998. /// <summary>
  3999. /// [S9] 下料设备 - 进站
  4000. /// </summary>
  4001. /// <param name="plcNo">PLC编号</param>
  4002. /// <param name="stationNameStr">工站全称</param>
  4003. /// <param name="stPLC_MesData"></param>
  4004. /// <param name="tagMesCommName"></param>
  4005. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  4006. {
  4007. Stopwatch stopwatch1 = new Stopwatch();
  4008. Stopwatch stopwatch2 = new Stopwatch();
  4009. try
  4010. {
  4011. stopwatch1.Start();
  4012. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4013. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4014. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  4015. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  4016. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4017. //载具码验证产品码
  4018. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4019. if (string.IsNullOrEmpty(strProductBarcode))
  4020. {
  4021. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4022. }
  4023. sn = strProductBarcode;
  4024. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4025. // 产品SN(物料码)校验
  4026. List<TestItem> item = new List<TestItem>();
  4027. stopwatch2.Start();
  4028. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  4029. stopwatch2.Stop();
  4030. //指令执行结果 1:OK 110:失败
  4031. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4032. //进站结果写入PLC
  4033. CommandFromPLC resultToPlC = new CommandFromPLC();
  4034. resultToPlC.cmd = 0;
  4035. resultToPlC.cmdParam = 0; //指令参数
  4036. resultToPlC.cmdResult = mesResultFrmWeb;
  4037. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4038. }
  4039. catch (Exception ex)
  4040. {
  4041. string str = ex.StackTrace;
  4042. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4043. CommandFromPLC resultToPlC = new CommandFromPLC();
  4044. resultToPlC.cmd = 0;
  4045. resultToPlC.cmdParam = 0; //指令参数
  4046. resultToPlC.cmdResult = 110;
  4047. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4048. }
  4049. stopwatch1.Stop();
  4050. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4051. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4052. ProgressState = false;
  4053. }
  4054. /// <summary>
  4055. /// [S9] 下料设备 - 出站接口
  4056. /// </summary>
  4057. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  4058. {
  4059. Stopwatch stopwatch1 = new Stopwatch();
  4060. Stopwatch stopwatch2 = new Stopwatch();
  4061. try
  4062. {
  4063. stopwatch1.Start();
  4064. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4065. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4066. string processItem = stationName; // 测试项目
  4067. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4068. string supplierCode = ""; // 供应商代码
  4069. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4070. string batch_num = GlobalContext.BatchNumber; // 批次号
  4071. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4072. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4073. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4074. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  4075. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  4076. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4077. bool pass = a1Result == 1;
  4078. //根据载具码获取产品码
  4079. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4080. if (string.IsNullOrEmpty(strProductBarcode))
  4081. {
  4082. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4083. }
  4084. sn = strProductBarcode;
  4085. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4086. List<TestItem> items = new List<TestItem>();
  4087. items.Add(new TestItem()
  4088. {
  4089. Parameter_name = "载具码",
  4090. Parameter_value = CarrierBarcode,
  4091. Parameter_unit = ""
  4092. });
  4093. items.Add(new TestItem()
  4094. {
  4095. Parameter_name = "产品码",
  4096. Parameter_value = sn,
  4097. Parameter_unit = ""
  4098. });
  4099. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4100. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  4101. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4102. stopwatch2.Start();
  4103. //进站结果写入PLC
  4104. CommandFromPLC resultToPlC = new CommandFromPLC();
  4105. resultToPlC.cmd = 0;
  4106. resultToPlC.cmdParam = 0; //指令参数
  4107. resultToPlC.cmdResult = mesResultFrmWeb;
  4108. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4109. stopwatch2.Stop();
  4110. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4111. //保存PLC返回MES数据到本地
  4112. ResponseMessage message = new ResponseMessage();
  4113. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4114. if (message.result == false)
  4115. {
  4116. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4117. }
  4118. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4119. if (result1 == 1)
  4120. {
  4121. //载具码解除绑定
  4122. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4123. if (message.result == false)
  4124. {
  4125. AddMessage(LogType.Error, message.text);
  4126. }
  4127. }
  4128. }
  4129. catch (Exception ex)
  4130. {
  4131. stopwatch2.Start();
  4132. CommandFromPLC resultToPlC = new CommandFromPLC();
  4133. resultToPlC.cmd = 0;
  4134. resultToPlC.cmdParam = 0; //指令参数
  4135. resultToPlC.cmdResult = 110;
  4136. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4137. stopwatch2.Stop();
  4138. string str = ex.StackTrace;
  4139. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4140. }
  4141. stopwatch1.Stop();
  4142. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4143. ProgressState = false;
  4144. }
  4145. #endregion
  4146. #endregion Xiaomi
  4147. #region PLC1 张超凡
  4148. #region [S1] Tray盘上料装备(板测)
  4149. /// <summary>
  4150. /// S1工位的数据- 触发信号上次的值
  4151. /// </summary>
  4152. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4153. /// <summary>
  4154. /// S1工位的数据(含触发信号)
  4155. /// </summary>
  4156. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4157. /// <summary>
  4158. /// S1工位的数据- 回写点位
  4159. /// </summary>
  4160. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4161. ///// <summary>
  4162. ///// 触发信号
  4163. ///// </summary>
  4164. //private ManualResetEvent[] MreTasks;
  4165. /// <summary>
  4166. /// [S1] Tray盘上料装备(板测)
  4167. /// </summary>
  4168. /// <param name="plcNo">PLC编号</param>
  4169. //private void ReadStation_S1(int plcNo)
  4170. //{
  4171. // // [S1] Tray盘上料装备
  4172. // // [S2] FCT
  4173. // // [S3] 值板机
  4174. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4175. // // [S5] Tray盘下料装备
  4176. // string stationCode = "[S1]";
  4177. // string stationName = "Tray盘上料装备";
  4178. // string stationNameStr = stationCode + stationName;
  4179. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4180. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4181. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4182. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4183. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4184. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4185. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4186. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4187. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4188. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4189. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4190. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4191. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4192. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4193. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4194. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4195. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4196. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4197. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4198. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4199. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4200. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4201. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4202. // s1PLCData.Add("a1Result", 0); // 产品结果
  4203. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4204. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4205. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4206. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4207. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4208. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4209. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4210. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4211. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4212. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4213. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4214. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4215. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4216. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4217. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4218. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4219. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4220. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4221. // while (IsRun)
  4222. // {
  4223. // try
  4224. // {
  4225. // if (!GlobalContext._IsCon_Funs1)
  4226. // {
  4227. // UpdatePLCMonitor(1, plcNo, 0);
  4228. // continue;
  4229. // }
  4230. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4231. // {
  4232. // Stopwatch stopwatch1 = new Stopwatch();
  4233. // Stopwatch stopwatch2 = new Stopwatch();
  4234. // stopwatch1.Start();
  4235. // stopwatch2.Start();
  4236. // #region 一次性读取所有数据
  4237. // // 一次性读取所有数据
  4238. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4239. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4240. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4241. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4242. // int[] datas = data1.Concat(data2).ToArray();
  4243. // datas = datas.Concat(data3).ToArray();
  4244. // datas = datas.Concat(data4).ToArray();
  4245. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4246. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4247. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4248. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4249. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4250. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4251. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4252. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4253. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4254. // s1PLCData["a1MES_FLAG"] = datas[109];
  4255. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4256. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4257. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4258. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4259. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4260. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4261. // s1PLCData["a1Result"] = datas[170];
  4262. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4263. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4264. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4265. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4266. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4267. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4268. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4269. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4270. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4271. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4272. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4273. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4274. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4275. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4276. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4277. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4278. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4279. // s1PLCData["a1AGVUpStart"] = datas[308];
  4280. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4281. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4282. // s1PLCData["a1AGVDownStart"] = datas[321];
  4283. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4284. // #endregion 一次性读取所有数据
  4285. // stopwatch2.Stop();
  4286. // #region 回写操作,写后清空flag
  4287. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4288. // #endregion 回写操作,写后清空flag
  4289. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4290. // try
  4291. // {
  4292. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4293. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4294. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4295. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4296. // {
  4297. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4298. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4299. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4300. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4301. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4302. // }
  4303. // }
  4304. // catch (Exception ex)
  4305. // {
  4306. // // 6代表上位机报警
  4307. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4308. // string str = ex.StackTrace;
  4309. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4310. // }
  4311. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4312. // #region 上料进站校验
  4313. // try
  4314. // {
  4315. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4316. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4317. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4318. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4319. // {
  4320. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4321. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4322. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4323. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4324. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4325. // }
  4326. // }
  4327. // catch (Exception ex)
  4328. // {
  4329. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4330. // string str = ex.StackTrace;
  4331. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4332. // }
  4333. // #endregion 上料进站校验
  4334. // #region Tray盘上料装备-出站接口
  4335. // try
  4336. // {
  4337. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4338. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4339. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4340. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4341. // {
  4342. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4343. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4344. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4345. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4346. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4347. // }
  4348. // }
  4349. // catch (Exception ex)
  4350. // {
  4351. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4352. // string str = ex.StackTrace;
  4353. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4354. // }
  4355. // #endregion Tray盘上料装备-出站接口
  4356. // #region Tray盘上料装备-将SN发给ICT标机
  4357. // try
  4358. // {
  4359. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4360. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4361. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4362. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4363. // {
  4364. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4365. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4366. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4367. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4368. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4369. // }
  4370. // }
  4371. // catch (Exception ex)
  4372. // {
  4373. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4374. // string str = ex.StackTrace;
  4375. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4376. // }
  4377. // #endregion Tray盘上料装备-将SN发给ICT标机
  4378. // #region Tray盘上料装备-点检数据
  4379. // //try
  4380. // //{
  4381. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4382. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4383. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4384. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4385. // // if (pLC_Flag && !mES_Flag) // 1 0
  4386. // // {
  4387. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4388. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4389. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4390. // // }
  4391. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4392. // // {
  4393. // // // 清空写给PLC的数据
  4394. // // // MES_Flag重置为0
  4395. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4396. // // }
  4397. // //}
  4398. // //catch (Exception ex)
  4399. // //{
  4400. // // // MES_Flag 为2上位机报错
  4401. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4402. // // string str = ex.StackTrace;
  4403. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4404. // //}
  4405. // #endregion Tray盘上料装备-点检数据
  4406. // #region 节拍接口
  4407. // try
  4408. // {
  4409. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4410. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4411. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4412. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4413. // {
  4414. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4415. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4416. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4417. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4418. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4419. // }
  4420. // }
  4421. // catch (Exception ex)
  4422. // {
  4423. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4424. // string str = ex.StackTrace;
  4425. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4426. // }
  4427. // #endregion 节拍接口
  4428. // #region AGV上料
  4429. // // AGV上料叫AGV信号
  4430. // try
  4431. // {
  4432. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4433. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4434. // if (a1AGVUpCall != a1AGVUpCallOld)
  4435. // {
  4436. // if (a1AGVUpCall == 1) // 0->1
  4437. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4438. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4439. // }
  4440. // }
  4441. // catch (Exception ex)
  4442. // {
  4443. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4444. // string str = ex.StackTrace;
  4445. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4446. // }
  4447. // // AGV上料完成信号
  4448. // try
  4449. // {
  4450. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4451. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4452. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4453. // {
  4454. // if (a1AGVUpEnd == 1) // 0->1
  4455. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4456. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4457. // }
  4458. // }
  4459. // catch (Exception ex)
  4460. // {
  4461. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4462. // string str = ex.StackTrace;
  4463. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4464. // }
  4465. // #endregion AGV上料
  4466. // #region AGV下料
  4467. // // AGV下料叫agv信号
  4468. // try
  4469. // {
  4470. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4471. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4472. // if (a1AGVDownCall != a1AGVDownCallOld)
  4473. // {
  4474. // if (a1AGVDownCall == 1) // 0->1
  4475. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4476. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4477. // }
  4478. // }
  4479. // catch (Exception ex)
  4480. // {
  4481. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4482. // string str = ex.StackTrace;
  4483. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4484. // }
  4485. // // AGV下料完成信号
  4486. // try
  4487. // {
  4488. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4489. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4490. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4491. // {
  4492. // if (a1AGVDownEnd == 1) // 0->1
  4493. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4494. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4495. // }
  4496. // }
  4497. // catch (Exception ex)
  4498. // {
  4499. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4500. // string str = ex.StackTrace;
  4501. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4502. // }
  4503. // #endregion AGV下料
  4504. // #region 心跳
  4505. // try
  4506. // {
  4507. // short states = 0;
  4508. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4509. // }
  4510. // catch (Exception ex)
  4511. // {
  4512. // string str = ex.StackTrace;
  4513. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4514. // }
  4515. // #endregion 心跳
  4516. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4517. // stopwatch1.Stop();
  4518. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4519. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4520. // }
  4521. // else
  4522. // {
  4523. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4524. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4525. // Funs[plcNo].Connect(); // 重连
  4526. // }
  4527. // }
  4528. // catch (Exception ex)
  4529. // {
  4530. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4531. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4532. // Funs[plcNo].ReConnect();
  4533. // }
  4534. // Thread.Sleep(IntervalReadPLC);
  4535. // }
  4536. //}
  4537. /// <summary>
  4538. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4539. /// </summary>
  4540. /// <param name="plcNo">PLC编号</param>
  4541. /// <param name="stationNameStr">工站全称</param>
  4542. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4543. {
  4544. Stopwatch stopwatch1 = new Stopwatch();
  4545. Stopwatch stopwatch2 = new Stopwatch();
  4546. try
  4547. {
  4548. stopwatch1.Start();
  4549. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4550. sn = sn.Replace("\0", "");
  4551. #region 查询载具上的产品信息
  4552. string cavityData = string.Empty;
  4553. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4554. if (string.IsNullOrEmpty(cavityData))
  4555. cavityData = "";
  4556. if (snResult != 0)
  4557. {
  4558. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4559. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4560. writeToPLC_Flag1.Adress = 2003;
  4561. writeToPLC_Flag1.Value = (short)6;
  4562. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4563. stopwatch1.Stop();
  4564. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4565. return;
  4566. }
  4567. #endregion 查询载具上的产品信息
  4568. string[] cavitySNs = cavityData.Split('.');
  4569. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4570. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4571. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4572. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4573. if (cavitySNs != null && cavitySNs.Length >= 2)
  4574. {
  4575. a1CavitySN1_VehicleStates = cavitySNs[0];
  4576. a1CavitySN2_VehicleStates = cavitySNs[1];
  4577. a1CavityResult1_VehicleStates = 2;
  4578. a1CavityResult2_VehicleStates = 2;
  4579. }
  4580. if (a1CavitySN1_VehicleStates == "假产品")
  4581. a1CavityResult1_VehicleStates = 3;
  4582. if (a1CavitySN2_VehicleStates == "假产品")
  4583. a1CavityResult2_VehicleStates = 3;
  4584. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4585. // 回写
  4586. stopwatch2.Start();
  4587. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4588. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4589. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4590. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4591. //// MES_Flag
  4592. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4593. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4594. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4595. writeToPLC_Flag.Adress = 2003;
  4596. writeToPLC_Flag.Value = mES_Flag;
  4597. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4598. {
  4599. Name = "a1CavitySN1_VehicleStates",
  4600. Adress = 2024,
  4601. ValueType = PLCValueType.String,
  4602. ValueTypeStrLength = 20,
  4603. Value = a1CavitySN1_VehicleStates
  4604. });
  4605. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4606. {
  4607. Name = "a1CavitySN2_VehicleStates",
  4608. Adress = 2044,
  4609. ValueType = PLCValueType.String,
  4610. ValueTypeStrLength = 20,
  4611. Value = a1CavitySN2_VehicleStates
  4612. });
  4613. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4614. {
  4615. Name = "a1CavityResult1_VehicleStates",
  4616. Adress = 2064,
  4617. ValueType = PLCValueType.Short,
  4618. Value = a1CavityResult1_VehicleStates
  4619. });
  4620. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4621. {
  4622. Name = "a1CavityResult2_VehicleStates",
  4623. Adress = 2065,
  4624. ValueType = PLCValueType.Short,
  4625. Value = a1CavityResult2_VehicleStates
  4626. });
  4627. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4628. stopwatch2.Stop();
  4629. }
  4630. catch (Exception ex)
  4631. {
  4632. string str = ex.StackTrace;
  4633. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4634. // MES_Flag
  4635. stopwatch2.Start();
  4636. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4637. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4638. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4639. writeToPLC_Flag.Adress = 2003;
  4640. writeToPLC_Flag.Value = (short)6;
  4641. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4642. stopwatch2.Stop();
  4643. }
  4644. stopwatch1.Stop();
  4645. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4646. }
  4647. /// <summary>
  4648. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4649. /// </summary>
  4650. /// <param name="plcNo">PLC编号</param>
  4651. /// <param name="stationNameStr">工站全称</param>
  4652. private void S1上料进站校验(int plcNo, string stationNameStr)
  4653. {
  4654. Stopwatch stopwatch1 = new Stopwatch();
  4655. Stopwatch stopwatch2 = new Stopwatch();
  4656. try
  4657. {
  4658. stopwatch1.Start();
  4659. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4660. sn = sn.Replace("\0", "");
  4661. // 保存进站数据+调用进站MES接口
  4662. List<TestItem> item = new List<TestItem>();
  4663. stopwatch2.Start();
  4664. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4665. stopwatch2.Stop();
  4666. short a1MES_FLAG_Check = (short)result;
  4667. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4668. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4669. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4670. writeToPLC_Flag.Adress = 2077;
  4671. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4672. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4673. }
  4674. catch (Exception ex)
  4675. {
  4676. string str = ex.StackTrace;
  4677. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4678. // MES_Flag
  4679. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4680. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4681. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4682. writeToPLC_Flag.Adress = 2077;
  4683. writeToPLC_Flag.Value = (short)6;
  4684. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4685. }
  4686. stopwatch1.Stop();
  4687. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4688. }
  4689. /// <summary>
  4690. /// [S1] Tray盘上料装备(板测)- 出站接口
  4691. /// </summary>
  4692. /// <param name="plcNo"></param>
  4693. /// <param name="stationCode"></param>
  4694. /// <param name="stationName"></param>
  4695. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4696. {
  4697. Stopwatch stopwatch1 = new Stopwatch();
  4698. Stopwatch stopwatch2 = new Stopwatch();
  4699. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4700. string stationNameStr = stationCode + stationName;
  4701. string processItem = stationName; // 测试项目
  4702. try
  4703. {
  4704. stopwatch1.Start();
  4705. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4706. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4707. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4708. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4709. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4710. sn = sn.Replace("\0", "");
  4711. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4712. partNo1 = partNo1.Replace("\0", "");
  4713. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4714. partNo2 = partNo2.Replace("\0", "");
  4715. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4716. bool pass = a1Result == 1;
  4717. stopwatch2.Start();
  4718. // 产品1
  4719. List<TestItem> items = new List<TestItem>();
  4720. items.Add(new TestItem()
  4721. {
  4722. Parameter_name = "载具码",
  4723. Parameter_value = sn,
  4724. Parameter_unit = ""
  4725. });
  4726. items.Add(new TestItem()
  4727. {
  4728. Parameter_name = "载具穴号",
  4729. Parameter_value = "1",
  4730. Parameter_unit = ""
  4731. });
  4732. items.Add(new TestItem()
  4733. {
  4734. Parameter_name = "产品结果",
  4735. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4736. Parameter_unit = ""
  4737. });
  4738. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4739. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4740. // 产品2
  4741. items = new List<TestItem>();
  4742. items.Add(new TestItem()
  4743. {
  4744. Parameter_name = "载具码",
  4745. Parameter_value = sn,
  4746. Parameter_unit = ""
  4747. });
  4748. items.Add(new TestItem()
  4749. {
  4750. Parameter_name = "载具穴号",
  4751. Parameter_value = "2",
  4752. Parameter_unit = ""
  4753. });
  4754. items.Add(new TestItem()
  4755. {
  4756. Parameter_name = "产品结果",
  4757. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4758. Parameter_unit = ""
  4759. });
  4760. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4761. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4762. short result = 0;
  4763. List<int> results = new List<int>() { result1, result2 };
  4764. if (result1 == 1 && result2 == 1)
  4765. result = 1;
  4766. else if (results.Contains(3))
  4767. result = 3;
  4768. else if (results.Contains(2))
  4769. result = 2;
  4770. else if (results.Contains(4))
  4771. result = 4;
  4772. else
  4773. result = 4;
  4774. stopwatch2.Stop();
  4775. #region 存储绑定数据到 边线MES系统中
  4776. if (result == 1)
  4777. {
  4778. string data = string.Concat(partNo1, ".", partNo2);
  4779. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4780. if (resultMesR != 0)
  4781. {
  4782. result = 4;
  4783. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4784. }
  4785. }
  4786. #endregion 存储绑定数据到 边线MES系统中
  4787. // MES_Flag 为MES报错
  4788. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4789. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4790. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4791. writeToPLC_Flag.Name = "a1MES_FLAG";
  4792. writeToPLC_Flag.Adress = 2109;
  4793. writeToPLC_Flag.Value = result;
  4794. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4795. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4796. }
  4797. catch (Exception ex)
  4798. {
  4799. stopwatch2.Restart();
  4800. // MES_Flag 为4上位机报错
  4801. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4802. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4803. writeToPLC_Flag.Name = "a1MES_FLAG";
  4804. writeToPLC_Flag.Adress = 2109;
  4805. writeToPLC_Flag.Value = (short)4;
  4806. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4807. stopwatch2.Stop();
  4808. string str = ex.StackTrace;
  4809. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4810. }
  4811. stopwatch1.Stop();
  4812. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4813. }
  4814. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4815. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4816. //{
  4817. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4818. // string stationNameStr = stationCode + stationName;
  4819. // string processItem = stationName; // 测试项目
  4820. // try
  4821. // {
  4822. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4823. // string accno = "1"; // 工序编号
  4824. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4825. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4826. // List<OneCheckItem> items = new List<OneCheckItem>()
  4827. // {
  4828. // new OneCheckItem()
  4829. // {
  4830. // Onecheck_name="胶圈装配行程设定上限",
  4831. // Onecheck_content="上限值",
  4832. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4833. // },
  4834. // };
  4835. // OneCheckData oneCheckData = new OneCheckData()
  4836. // {
  4837. // Line_code = GlobalContext.LineCode,
  4838. // Line_name = GlobalContext.LineName,
  4839. // Equipment_code = equipmentCode,
  4840. // Equipment_name = equipmentCode,
  4841. // Workorder_code = workorder_code,
  4842. // Procedure_code = accno,
  4843. // Procedure_name = processItem,
  4844. // Oneckeck_values = items,
  4845. // Onecheck_empcode = "",
  4846. // Onecheck_empname = "",
  4847. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4848. // };
  4849. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4850. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4851. // short result = result1 == 1 ? (short)1 : (short)2;
  4852. // // MES_Flag 为4MES报错
  4853. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4854. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4855. // }
  4856. // catch (Exception ex)
  4857. // {
  4858. // // MES_Flag 为2上位机报错
  4859. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4860. // string str = ex.StackTrace;
  4861. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4862. // }
  4863. //}
  4864. // ReadStation_S1_2 节拍接口+AGV
  4865. /// <summary>
  4866. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4867. /// </summary>
  4868. /// <param name="plcNo">PLC编号</param>
  4869. /// <param name="stationNameStr">工站全称</param>
  4870. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4871. {
  4872. Stopwatch stopwatch1 = new Stopwatch();
  4873. Stopwatch stopwatch2 = new Stopwatch();
  4874. try
  4875. {
  4876. stopwatch1.Start();
  4877. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4878. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4879. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4880. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4881. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4882. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4883. // ZS 将SN发给ICT标机(串口)
  4884. short a1MES_FLAG_ICT = 1;
  4885. stopwatch2.Start();
  4886. // MES_Flag
  4887. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4888. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4889. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4890. writeToPLC_Flag.Adress = 2182;
  4891. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4892. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4893. stopwatch2.Stop();
  4894. }
  4895. catch (Exception ex)
  4896. {
  4897. string str = ex.StackTrace;
  4898. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4899. stopwatch2.Start();
  4900. // MES_Flag
  4901. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4902. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4903. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4904. writeToPLC_Flag.Adress = 2182;
  4905. writeToPLC_Flag.Value = (short)4;
  4906. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4907. stopwatch2.Stop();
  4908. }
  4909. stopwatch1.Stop();
  4910. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4911. }
  4912. /// <summary>
  4913. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4914. /// </summary>
  4915. /// <param name="plcNo">PLC编号</param>
  4916. /// <param name="stationNameStr">工站全称</param>
  4917. private void S1节拍接口(int plcNo, string stationNameStr)
  4918. {
  4919. Stopwatch stopwatch1 = new Stopwatch();
  4920. Stopwatch stopwatch2 = new Stopwatch();
  4921. string resultStr = string.Empty;
  4922. try
  4923. {
  4924. stopwatch1.Start();
  4925. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4926. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4927. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4928. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4929. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4930. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4931. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  4932. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4933. if (!actionBool)
  4934. {
  4935. stopwatch2.Start();
  4936. // MES_Flag
  4937. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4938. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4939. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  4940. writeToPLC_Flag1.Adress = 2254;
  4941. writeToPLC_Flag1.Value = (short)1;
  4942. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  4943. stopwatch2.Stop();
  4944. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4945. return;
  4946. }
  4947. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  4948. {
  4949. stopwatch2.Start();
  4950. // MES_Flag
  4951. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4952. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  4953. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  4954. writeToPLC_Flag2.Adress = 2254;
  4955. writeToPLC_Flag2.Value = (short)1;
  4956. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  4957. stopwatch2.Stop();
  4958. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4959. return;
  4960. }
  4961. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  4962. { // 查产品SN
  4963. a1OEEPartNo = "Test"; // ZS
  4964. }
  4965. short a1OEEMES_FLAG = 0;
  4966. // 上传OEE
  4967. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  4968. a1OEEMES_FLAG = result.Item1;
  4969. resultStr = result.Item2;
  4970. stopwatch2.Start();
  4971. // MES_Flag
  4972. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4973. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4974. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4975. writeToPLC_Flag.Adress = 2254;
  4976. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  4977. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4978. stopwatch2.Stop();
  4979. }
  4980. catch (Exception ex)
  4981. {
  4982. string str = ex.StackTrace;
  4983. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4984. // MES_Flag
  4985. stopwatch2.Start();
  4986. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4987. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4988. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4989. writeToPLC_Flag.Adress = 2254;
  4990. writeToPLC_Flag.Value = (short)4;
  4991. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4992. stopwatch2.Stop();
  4993. }
  4994. stopwatch1.Stop();
  4995. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4996. }
  4997. /// <summary>
  4998. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  4999. /// </summary>
  5000. /// <param name="plcNo">PLC编号</param>
  5001. /// <param name="stationNameStr">工站全称</param>
  5002. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  5003. {
  5004. Stopwatch stopwatch1 = new Stopwatch();
  5005. Stopwatch stopwatch2 = new Stopwatch();
  5006. try
  5007. {
  5008. stopwatch1.Start();
  5009. // ZS 呼叫AGV
  5010. short a1AGVUpCall = 2;
  5011. stopwatch2.Start();
  5012. // a1AGVUpCall
  5013. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5014. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5015. writeToPLC_Flag.Name = "a1AGVUpCall";
  5016. writeToPLC_Flag.Adress = 2307;
  5017. writeToPLC_Flag.Value = a1AGVUpCall;
  5018. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5019. stopwatch2.Stop();
  5020. }
  5021. catch (Exception ex)
  5022. {
  5023. string str = ex.StackTrace;
  5024. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5025. // a1AGVUpCall
  5026. stopwatch2.Start();
  5027. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  5028. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5029. writeToPLC_Flag.Name = "a1AGVUpCall";
  5030. writeToPLC_Flag.Adress = 2307;
  5031. writeToPLC_Flag.Value = (short)4;
  5032. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5033. stopwatch2.Stop();
  5034. }
  5035. stopwatch1.Stop();
  5036. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5037. }
  5038. /// <summary>
  5039. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  5040. /// </summary>
  5041. /// <param name="plcNo">PLC编号</param>
  5042. /// <param name="stationNameStr">工站全称</param>
  5043. private void S1AGV上料完成(int plcNo, string stationNameStr)
  5044. {
  5045. Stopwatch stopwatch1 = new Stopwatch();
  5046. Stopwatch stopwatch2 = new Stopwatch();
  5047. try
  5048. {
  5049. stopwatch1.Start();
  5050. // ZS AGV上料完成,让小车离开
  5051. short a1AGVUpEnd = 2;
  5052. stopwatch2.Start();
  5053. // a1AGVUpEnd
  5054. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5055. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5056. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5057. writeToPLC_Flag.Adress = 2309;
  5058. writeToPLC_Flag.Value = a1AGVUpEnd;
  5059. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5060. stopwatch2.Stop();
  5061. }
  5062. catch (Exception ex)
  5063. {
  5064. string str = ex.StackTrace;
  5065. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5066. // a1AGVUpEnd
  5067. stopwatch2.Start();
  5068. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  5069. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5070. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5071. writeToPLC_Flag.Adress = 2309;
  5072. writeToPLC_Flag.Value = (short)4;
  5073. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5074. stopwatch2.Stop();
  5075. }
  5076. stopwatch1.Stop();
  5077. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5078. }
  5079. /// <summary>
  5080. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  5081. /// </summary>
  5082. /// <param name="plcNo">PLC编号</param>
  5083. /// <param name="stationNameStr">工站全称</param>
  5084. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  5085. {
  5086. Stopwatch stopwatch1 = new Stopwatch();
  5087. Stopwatch stopwatch2 = new Stopwatch();
  5088. try
  5089. {
  5090. stopwatch1.Start();
  5091. // ZS 呼叫AGV
  5092. short a1AGVDownCall = 2;
  5093. stopwatch2.Start();
  5094. // a1AGVDownCall
  5095. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5096. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5097. writeToPLC_Flag.Name = "a1AGVDownCall";
  5098. writeToPLC_Flag.Adress = 2320;
  5099. writeToPLC_Flag.Value = a1AGVDownCall;
  5100. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5101. stopwatch2.Stop();
  5102. }
  5103. catch (Exception ex)
  5104. {
  5105. string str = ex.StackTrace;
  5106. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5107. // a1AGVDownCall
  5108. stopwatch2.Start();
  5109. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5110. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5111. writeToPLC_Flag.Name = "a1AGVDownCall";
  5112. writeToPLC_Flag.Adress = 2320;
  5113. writeToPLC_Flag.Value = (short)4;
  5114. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5115. stopwatch2.Stop();
  5116. }
  5117. stopwatch1.Stop();
  5118. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5119. }
  5120. /// <summary>
  5121. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5122. /// </summary>
  5123. /// <param name="plcNo">PLC编号</param>
  5124. /// <param name="stationNameStr">工站全称</param>
  5125. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5126. {
  5127. Stopwatch stopwatch1 = new Stopwatch();
  5128. Stopwatch stopwatch2 = new Stopwatch();
  5129. try
  5130. {
  5131. stopwatch1.Start();
  5132. // ZS AGV上料完成,让小车离开
  5133. short a1AGVDownEnd = 2;
  5134. stopwatch2.Start();
  5135. // a1AGVDownEnd
  5136. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5137. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5138. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5139. writeToPLC_Flag.Adress = 2322;
  5140. writeToPLC_Flag.Value = a1AGVDownEnd;
  5141. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5142. stopwatch2.Stop();
  5143. }
  5144. catch (Exception ex)
  5145. {
  5146. string str = ex.StackTrace;
  5147. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5148. // a1AGVDownEnd
  5149. stopwatch2.Start();
  5150. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5151. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5152. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5153. writeToPLC_Flag.Adress = 2322;
  5154. writeToPLC_Flag.Value = (short)4;
  5155. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5156. stopwatch2.Stop();
  5157. }
  5158. stopwatch1.Stop();
  5159. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5160. }
  5161. #endregion [S1] Tray盘上料装备(板测)
  5162. #endregion PLC1 张超凡
  5163. #region PLC2 李晓奇
  5164. #region [S2] FCT(板测)
  5165. /// <summary>
  5166. /// S2工位的数据- 触发信号上次的值
  5167. /// </summary>
  5168. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5169. /// <summary>
  5170. /// S2工位的数据(含触发信号)
  5171. /// </summary>
  5172. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5173. /// <summary>
  5174. /// S2工位的数据- 回写点位
  5175. /// </summary>
  5176. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5177. /// <summary>
  5178. /// [S2] FCT(板测)
  5179. /// </summary>
  5180. /// <param name="plcNo">PLC编号</param>
  5181. //private void ReadStation_S2(int plcNo)
  5182. //{
  5183. // // [S1] Tray盘上料装备
  5184. // // [S2] FCT
  5185. // // [S3] 值板机
  5186. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5187. // // [S5] Tray盘下料装备
  5188. // /// 上位机心跳
  5189. // /// 获取设备报警数据与状态信息
  5190. // string stationCode = "[S2]";
  5191. // string stationName = "FCT";
  5192. // string stationNameStr = stationCode + stationName;
  5193. // #region 创建字典
  5194. // // 触发信号字典 赋值
  5195. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5196. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5197. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5198. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5199. // // PLC数据字典 赋值
  5200. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5201. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5202. // s2PLCData.Add("b1ProductSN_Check", 0);
  5203. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5204. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5205. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5206. // s2PLCData.Add("b1ProductSN_Bind", "");
  5207. // s2PLCData.Add("b1Part1SN_Bind", "");
  5208. // s2PLCData.Add("b1Part2SN_Bind", "");
  5209. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5210. // s2PLCData.Add("b1MES_FLAG", 0);
  5211. // s2PLCData.Add("b1ProductSN", 0);
  5212. // s2PLCData.Add("b1Part1Result", 0);
  5213. // s2PLCData.Add("b1Part2Result", 0);
  5214. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5215. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5216. // s2PLCData.Add("b1OEEProductSN", "");
  5217. // s2PLCData.Add("b1OEEType", 0);
  5218. // #endregion 创建字典
  5219. // while (IsRun)
  5220. // {
  5221. // try
  5222. // {
  5223. // if (!GlobalContext._IsCon_Funs2)
  5224. // {
  5225. // UpdatePLCMonitor(1, plcNo, 0);
  5226. // continue;
  5227. // }
  5228. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5229. // {
  5230. // Stopwatch stopwatch1 = new Stopwatch();
  5231. // Stopwatch stopwatch2 = new Stopwatch();
  5232. // stopwatch1.Start();
  5233. // stopwatch2.Start();
  5234. // #region 一次性读取所有数据
  5235. // // 一次性读取所有数据
  5236. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5237. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5238. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5239. // int[] datas = data1.Concat(data2).ToArray();
  5240. // datas = datas.Concat(data3).ToArray();
  5241. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5242. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5243. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5244. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5245. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5246. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5247. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5248. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5249. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5250. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5251. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5252. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5253. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5254. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5255. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5256. // s2PLCData["b1MES_FLAG"] = datas[169];
  5257. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5258. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5259. // s2PLCData["b1Part1Result"] = datas[190];
  5260. // s2PLCData["b1Part2Result"] = datas[191];
  5261. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5262. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5263. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5264. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5265. // s2PLCData["b1OEEType"] = datas[224];
  5266. // #endregion 一次性读取所有数据
  5267. // stopwatch2.Stop();
  5268. // #region 回写操作,写后清空flag
  5269. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5270. // #endregion 回写操作,写后清空flag
  5271. // #region 进站校验
  5272. // try
  5273. // {
  5274. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5275. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5276. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5277. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5278. // {
  5279. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5280. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5281. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5282. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5283. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5284. // }
  5285. // }
  5286. // catch (Exception ex)
  5287. // {
  5288. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5289. // string str = ex.StackTrace;
  5290. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5291. // }
  5292. // #endregion 进站校验
  5293. // #region 二穴载具解绑/绑定(产品换载具)
  5294. // try
  5295. // {
  5296. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5297. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5298. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5299. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5300. // {
  5301. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5302. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5303. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5304. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5305. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5306. // }
  5307. // }
  5308. // catch (Exception ex)
  5309. // {
  5310. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5311. // string str = ex.StackTrace;
  5312. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5313. // }
  5314. // #endregion 二穴载具解绑/绑定(产品换载具)
  5315. // #region FCT-出站接口
  5316. // try
  5317. // {
  5318. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5319. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5320. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5321. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5322. // {
  5323. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5324. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5325. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5326. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5327. // }
  5328. // }
  5329. // catch (Exception ex)
  5330. // {
  5331. // // MES_Flag 为6上位机报错
  5332. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5333. // string str = ex.StackTrace;
  5334. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5335. // }
  5336. // #endregion FCT-出站接口
  5337. // #region 节拍接口
  5338. // try
  5339. // {
  5340. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5341. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5342. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5343. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5344. // {
  5345. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5346. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5347. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5348. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5349. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5350. // }
  5351. // }
  5352. // catch (Exception ex)
  5353. // {
  5354. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5355. // string str = ex.StackTrace;
  5356. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5357. // }
  5358. // #endregion 节拍接口
  5359. // #region 心跳
  5360. // try
  5361. // {
  5362. // short states = 0;
  5363. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5364. // }
  5365. // catch (Exception ex)
  5366. // {
  5367. // string str = ex.StackTrace;
  5368. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5369. // }
  5370. // #endregion 心跳
  5371. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5372. // stopwatch1.Stop();
  5373. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5374. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5375. // }
  5376. // else
  5377. // {
  5378. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5379. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5380. // Funs[plcNo].Connect();
  5381. // }
  5382. // }
  5383. // catch (Exception ex)
  5384. // {
  5385. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5386. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5387. // Funs[plcNo].ReConnect();
  5388. // }
  5389. // Thread.Sleep(IntervalReadPLC);
  5390. // }
  5391. //}
  5392. /// <summary>
  5393. /// [S2] FCT(板测)- 进站校验
  5394. /// </summary>
  5395. /// <param name="plcNo">PLC编号</param>
  5396. /// <param name="stationNameStr">工站全称</param>
  5397. private void S2进站校验(int plcNo, string stationNameStr)
  5398. {
  5399. Stopwatch stopwatch1 = new Stopwatch();
  5400. Stopwatch stopwatch2 = new Stopwatch();
  5401. try
  5402. {
  5403. stopwatch1.Start();
  5404. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5405. sn = sn.Replace("\0", "");
  5406. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5407. // 查询物料码By载具码 并判断是不是假产品
  5408. string cavityData = string.Empty;
  5409. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5410. if (string.IsNullOrEmpty(cavityData))
  5411. cavityData = "";
  5412. if (snResult != 0)
  5413. {
  5414. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5415. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5416. writeToPLC_Flag1.Adress = 2003;
  5417. writeToPLC_Flag1.Value = (short)6;
  5418. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5419. stopwatch1.Stop();
  5420. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5421. return;
  5422. }
  5423. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5424. string[] cavitySNs = cavityData.Split('.');
  5425. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5426. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5427. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5428. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5429. if (cavitySNs != null && cavitySNs.Length >= 2)
  5430. {
  5431. b1Part1SN_Check = cavitySNs[0];
  5432. b1Part2SN_Check = cavitySNs[1];
  5433. b1Part1Result_Check = 2;
  5434. b1Part2Result_Check = 2;
  5435. }
  5436. if (b1Part1SN_Check == "假产品")
  5437. b1Part1Result_Check = 3;
  5438. if (b1Part2SN_Check == "假产品")
  5439. b1Part2Result_Check = 3;
  5440. // 调用MES进站
  5441. stopwatch2.Start();
  5442. // 调用MES进站 - 产品1
  5443. List<TestItem> item;
  5444. int result1 = b1Part1Result_Check;
  5445. if (result1 != 3)
  5446. {
  5447. item = new List<TestItem>();
  5448. item.Add(new TestItem()
  5449. {
  5450. Parameter_name = "载具码",
  5451. Parameter_value = sn,
  5452. });
  5453. item.Add(new TestItem()
  5454. {
  5455. Parameter_name = "载具穴号",
  5456. Parameter_value = "1",
  5457. });
  5458. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5459. }
  5460. // 调用MES进站 - 产品2
  5461. int result2 = b1Part2Result_Check;
  5462. if (result2 != 3)
  5463. {
  5464. item = new List<TestItem>();
  5465. item.Add(new TestItem()
  5466. {
  5467. Parameter_name = "载具码",
  5468. Parameter_value = sn,
  5469. });
  5470. item.Add(new TestItem()
  5471. {
  5472. Parameter_name = "载具穴号",
  5473. Parameter_value = "2",
  5474. });
  5475. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5476. }
  5477. stopwatch2.Stop();
  5478. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5479. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5480. int result = result1;
  5481. if (result == 1)
  5482. result = result2;
  5483. short b1MES_FLAG_Check = (short)result;
  5484. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5485. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5486. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5487. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5488. //// MES_Flag
  5489. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5490. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5491. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5492. writeToPLC_Flag.Adress = 2003;
  5493. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5494. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5495. {
  5496. Name = "b1Part1SN_Check",
  5497. Adress = 2024,
  5498. ValueType = PLCValueType.String,
  5499. ValueTypeStrLength = 20,
  5500. Value = b1Part1SN_Check
  5501. });
  5502. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5503. {
  5504. Name = "b1Part2SN_Check",
  5505. Adress = 2044,
  5506. ValueType = PLCValueType.String,
  5507. ValueTypeStrLength = 20,
  5508. Value = b1Part2SN_Check
  5509. });
  5510. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5511. {
  5512. Name = "b1Part1Result_Check",
  5513. Adress = 2064,
  5514. ValueType = PLCValueType.Short,
  5515. Value = b1Part1Result_Check
  5516. });
  5517. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5518. {
  5519. Name = "b1Part2Result_Check",
  5520. Adress = 2065,
  5521. ValueType = PLCValueType.Short,
  5522. Value = b1Part2Result_Check
  5523. });
  5524. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5525. }
  5526. catch (Exception ex)
  5527. {
  5528. string str = ex.StackTrace;
  5529. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5530. // MES_Flag
  5531. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5532. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5533. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5534. writeToPLC_Flag.Adress = 2003;
  5535. writeToPLC_Flag.Value = (short)6;
  5536. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5537. }
  5538. stopwatch1.Stop();
  5539. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5540. }
  5541. /// <summary>
  5542. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5543. /// </summary>
  5544. /// <param name="plcNo">PLC编号</param>
  5545. /// <param name="stationNameStr">工站全称</param>
  5546. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5547. {
  5548. Stopwatch stopwatch1 = new Stopwatch();
  5549. Stopwatch stopwatch2 = new Stopwatch();
  5550. try
  5551. {
  5552. stopwatch1.Start();
  5553. // 产品换载具
  5554. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5555. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5556. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5557. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5558. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5559. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5560. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5561. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5562. stopwatch2.Start();
  5563. #region 查询载具上的产品信息
  5564. //string cavityData = string.Empty;
  5565. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5566. //if (string.IsNullOrEmpty(cavityData))
  5567. // cavityData = "";
  5568. //if (snResult != 0)
  5569. //{
  5570. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5571. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5572. // writeToPLC_Flag.Adress = 2077;
  5573. // writeToPLC_Flag.Value = (short)6;
  5574. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5575. // stopwatch1.Stop();
  5576. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5577. // return;
  5578. //}
  5579. #endregion 查询载具上的产品信息
  5580. #region 解绑(边线MES系统)
  5581. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5582. if (snResult != 0)
  5583. {
  5584. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5585. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5586. writeToPLC_Flag1.Adress = 2077;
  5587. writeToPLC_Flag1.Value = (short)6;
  5588. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5589. stopwatch1.Stop();
  5590. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5591. return;
  5592. }
  5593. #endregion 解绑(边线MES系统)
  5594. #region 存储绑定数据到 边线MES系统中
  5595. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5596. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5597. if (snResult != 0)
  5598. {
  5599. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5600. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5601. writeToPLC_Flag1.Adress = 2077;
  5602. writeToPLC_Flag1.Value = (short)6;
  5603. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5604. stopwatch1.Stop();
  5605. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5606. return;
  5607. }
  5608. #endregion 存储绑定数据到 边线MES系统中
  5609. stopwatch2.Stop();
  5610. short b1MES_FLAG_Unbind = 1;
  5611. // MES_Flag
  5612. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5613. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5614. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5615. writeToPLC_Flag.Adress = 2077;
  5616. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5617. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5618. }
  5619. catch (Exception ex)
  5620. {
  5621. string str = ex.StackTrace;
  5622. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5623. // MES_Flag
  5624. stopwatch2.Start();
  5625. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5626. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5627. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5628. writeToPLC_Flag.Adress = 2077;
  5629. writeToPLC_Flag.Value = (short)6;
  5630. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5631. stopwatch2.Stop();
  5632. }
  5633. stopwatch1.Stop();
  5634. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5635. }
  5636. //// 上次采集到的SN
  5637. //private string sn_FCT = string.Empty;
  5638. /// <summary>
  5639. /// [S2] FCT(板测)- 出站数据
  5640. /// </summary>
  5641. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5642. {
  5643. Stopwatch stopwatch1 = new Stopwatch();
  5644. Stopwatch stopwatch2 = new Stopwatch();
  5645. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5646. string stationNameStr = stationCode + stationName;
  5647. string processItem = stationName; // 测试项目
  5648. try
  5649. {
  5650. stopwatch1.Start();
  5651. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5652. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5653. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5654. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5655. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5656. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5657. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5658. bool pass1 = b1Part1Result == 1;
  5659. bool pass2 = b1Part2Result == 1;
  5660. #region 根据 载具SN 查 物料SN
  5661. string cavityData = string.Empty;
  5662. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5663. if (string.IsNullOrEmpty(cavityData))
  5664. cavityData = "";
  5665. if (snResult != 0)
  5666. {
  5667. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5668. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5669. writeToPLC_Flag1.Adress = 2169;
  5670. writeToPLC_Flag1.Value = (short)4;
  5671. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5672. stopwatch1.Stop();
  5673. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5674. return;
  5675. }
  5676. #endregion 根据 载具SN 查 物料SN
  5677. string[] cavitySNs = cavityData.Split('.');
  5678. string b1ProductSN1 = string.Empty;
  5679. string b1ProductSN2 = string.Empty;
  5680. if (cavitySNs != null && cavitySNs.Length >= 2)
  5681. {
  5682. b1ProductSN1 = cavitySNs[0];
  5683. b1ProductSN2 = cavitySNs[1];
  5684. }
  5685. stopwatch2.Start();
  5686. // 产品1
  5687. int result1 = 0;
  5688. if (b1ProductSN1 == "假产品")
  5689. result1 = 1;
  5690. else
  5691. {
  5692. List<TestItem> items1 = new List<TestItem>();
  5693. items1.Add(new TestItem()
  5694. {
  5695. Parameter_name = "载具码",
  5696. Parameter_value = b1ProductSN.ToString(),
  5697. Parameter_unit = ""
  5698. });
  5699. items1.Add(new TestItem()
  5700. {
  5701. Parameter_name = "载具穴号",
  5702. Parameter_value = "1",
  5703. Parameter_unit = ""
  5704. });
  5705. items1.Add(new TestItem()
  5706. {
  5707. Parameter_name = "产品结果",
  5708. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5709. Parameter_unit = ""
  5710. });
  5711. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5712. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5713. }
  5714. // 产品2
  5715. int result2 = 0;
  5716. if (b1ProductSN1 == "假产品")
  5717. result2 = 1;
  5718. else
  5719. {
  5720. List<TestItem> items2 = new List<TestItem>();
  5721. items2.Add(new TestItem()
  5722. {
  5723. Parameter_name = "载具码",
  5724. Parameter_value = b1ProductSN.ToString(),
  5725. Parameter_unit = ""
  5726. });
  5727. items2.Add(new TestItem()
  5728. {
  5729. Parameter_name = "载具穴号",
  5730. Parameter_value = "2",
  5731. Parameter_unit = ""
  5732. });
  5733. items2.Add(new TestItem()
  5734. {
  5735. Parameter_name = "产品结果",
  5736. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5737. Parameter_unit = ""
  5738. });
  5739. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5740. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5741. }
  5742. short result = 0;
  5743. List<int> results = new List<int>() { result1, result2 };
  5744. if (result1 == 1 && result2 == 1)
  5745. result = 1;
  5746. else if (results.Contains(3))
  5747. result = 3;
  5748. else if (results.Contains(2))
  5749. result = 2;
  5750. else if (results.Contains(4))
  5751. result = 4;
  5752. else
  5753. result = 4;
  5754. stopwatch2.Stop();
  5755. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5756. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5757. writeToPLC_Flag.Name = "b1MES_FLAG";
  5758. writeToPLC_Flag.Adress = 2169;
  5759. writeToPLC_Flag.Value = result;
  5760. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5761. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5762. }
  5763. catch (Exception ex)
  5764. {
  5765. stopwatch2.Restart();
  5766. // MES_Flag 为4上位机报错
  5767. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5768. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5769. writeToPLC_Flag.Name = "b1MES_FLAG";
  5770. writeToPLC_Flag.Adress = 2169;
  5771. writeToPLC_Flag.Value = (short)4;
  5772. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5773. stopwatch2.Stop();
  5774. string str = ex.StackTrace;
  5775. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5776. }
  5777. stopwatch1.Stop();
  5778. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5779. }
  5780. /// <summary>
  5781. /// [S2] FCT(板测)- 节拍接口
  5782. /// </summary>
  5783. /// <param name="plcNo">PLC编号</param>
  5784. /// <param name="stationNameStr">工站全称</param>
  5785. private void S2节拍接口(int plcNo, string stationNameStr)
  5786. {
  5787. Stopwatch stopwatch1 = new Stopwatch();
  5788. Stopwatch stopwatch2 = new Stopwatch();
  5789. string resultStr = string.Empty;
  5790. try
  5791. {
  5792. stopwatch1.Start();
  5793. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5794. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5795. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5796. if (!actionBool)
  5797. {
  5798. stopwatch2.Start();
  5799. // MES_Flag
  5800. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5801. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5802. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5803. writeToPLC_Flag1.Adress = 2203;
  5804. writeToPLC_Flag1.Value = (short)4;
  5805. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5806. stopwatch2.Stop();
  5807. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5808. return;
  5809. }
  5810. string b1OEEPartNo = string.Empty; // 物料码
  5811. if (string.IsNullOrEmpty(b1OEEProductSN))
  5812. {
  5813. stopwatch2.Start();
  5814. // MES_Flag
  5815. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5816. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5817. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5818. writeToPLC_Flag1.Adress = 2203;
  5819. writeToPLC_Flag1.Value = (short)1;
  5820. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5821. stopwatch2.Stop();
  5822. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5823. return;
  5824. }
  5825. else
  5826. { // 查产品SN
  5827. b1OEEPartNo = "Test"; // ZS
  5828. }
  5829. short b1OEEMES_FLAG = 0;
  5830. // 上传OEE
  5831. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5832. b1OEEMES_FLAG = result.Item1;
  5833. resultStr = result.Item2;
  5834. stopwatch2.Start();
  5835. // MES_Flag
  5836. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5837. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5838. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5839. writeToPLC_Flag.Adress = 2203;
  5840. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5841. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5842. stopwatch2.Stop();
  5843. }
  5844. catch (Exception ex)
  5845. {
  5846. string str = ex.StackTrace;
  5847. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5848. // MES_Flag
  5849. stopwatch2.Start();
  5850. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5851. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5852. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5853. writeToPLC_Flag.Adress = 2203;
  5854. writeToPLC_Flag.Value = (short)4;
  5855. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5856. stopwatch2.Stop();
  5857. }
  5858. stopwatch1.Stop();
  5859. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5860. }
  5861. #endregion [S2] FCT(板测)
  5862. #endregion PLC2 李晓奇
  5863. #region PLC3 刘永村
  5864. #region [S3] 值板机
  5865. /// <summary>
  5866. /// S3工位的数据- 触发信号上次的值
  5867. /// </summary>
  5868. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5869. /// <summary>
  5870. /// S3工位的数据(含触发信号)
  5871. /// </summary>
  5872. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5873. /// <summary>
  5874. /// S3工位的数据- 回写点位
  5875. /// </summary>
  5876. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5877. /// <summary>
  5878. /// [S3] 值板机
  5879. /// </summary>
  5880. /// <param name="plcNo">PLC编号</param>
  5881. //private void ReadStation_S3(int plcNo)
  5882. //{
  5883. // // [S1] Tray盘上料装备
  5884. // // [S2] FCT
  5885. // // [S3] 值板机
  5886. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5887. // // [S5] Tray盘下料装备
  5888. // /// 上位机心跳
  5889. // /// 获取设备报警数据与状态信息
  5890. // string stationCode = "[S3]";
  5891. // string stationName = "值板机";
  5892. // string stationNameStr = stationCode + stationName;
  5893. // #region 创建字典
  5894. // // 触发信号字典 赋值
  5895. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5896. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5897. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5898. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5899. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5900. // // PLC数据字典 赋值
  5901. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5902. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5903. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5904. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5905. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5906. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5907. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5908. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5909. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5910. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5911. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5912. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5913. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5914. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5915. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5916. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5917. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5918. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5919. // s3PLCData.Add("c1Result", 0); // 产品结果
  5920. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5921. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5922. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5923. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  5924. // #endregion 创建字典
  5925. // while (IsRun)
  5926. // {
  5927. // try
  5928. // {
  5929. // if (!GlobalContext._IsCon_Funs3)
  5930. // {
  5931. // UpdatePLCMonitor(1, plcNo, 0);
  5932. // continue;
  5933. // }
  5934. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5935. // {
  5936. // Stopwatch stopwatch1 = new Stopwatch();
  5937. // Stopwatch stopwatch2 = new Stopwatch();
  5938. // stopwatch1.Start();
  5939. // stopwatch2.Start();
  5940. // #region 一次性读取所有数据
  5941. // // 一次性读取所有数据
  5942. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  5943. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  5944. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  5945. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  5946. // int[] datas = data1.Concat(data2).ToArray();
  5947. // datas = datas.Concat(data3).ToArray();
  5948. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  5949. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  5950. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5951. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  5952. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  5953. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  5954. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5955. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  5956. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  5957. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  5958. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  5959. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5960. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  5961. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  5962. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  5963. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  5964. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5965. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  5966. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  5967. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  5968. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  5969. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  5970. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  5971. // #endregion 一次性读取所有数据
  5972. // stopwatch2.Stop();
  5973. // #region 回写操作,写后清空flag
  5974. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  5975. // #endregion 回写操作,写后清空flag
  5976. // #region S3进站校验
  5977. // try
  5978. // {
  5979. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  5980. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  5981. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  5982. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  5983. // {
  5984. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  5985. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5986. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  5987. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5988. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  5989. // }
  5990. // }
  5991. // catch (Exception ex)
  5992. // {
  5993. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5994. // string str = ex.StackTrace;
  5995. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5996. // }
  5997. // #endregion S3进站校验
  5998. // #region S3二穴载具解绑
  5999. // try
  6000. // {
  6001. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  6002. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  6003. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  6004. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  6005. // {
  6006. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6007. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  6008. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  6009. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  6010. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  6011. // }
  6012. // }
  6013. // catch (Exception ex)
  6014. // {
  6015. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  6016. // string str = ex.StackTrace;
  6017. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6018. // }
  6019. // #endregion S3二穴载具解绑
  6020. // #region S3二穴载具绑定
  6021. // try
  6022. // {
  6023. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  6024. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  6025. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  6026. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  6027. // {
  6028. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6029. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  6030. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  6031. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  6032. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  6033. // }
  6034. // }
  6035. // catch (Exception ex)
  6036. // {
  6037. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6038. // string str = ex.StackTrace;
  6039. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6040. // }
  6041. // #endregion S3二穴载具绑定
  6042. // #region S3出站接口(+一穴载具绑定)
  6043. // try
  6044. // {
  6045. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  6046. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  6047. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  6048. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  6049. // {
  6050. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  6051. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6052. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  6053. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  6054. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  6055. // }
  6056. // }
  6057. // catch (Exception ex)
  6058. // {
  6059. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  6060. // string str = ex.StackTrace;
  6061. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6062. // }
  6063. // #endregion S3出站接口(+一穴载具绑定)
  6064. // #region S3节拍接口
  6065. // try
  6066. // {
  6067. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  6068. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  6069. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  6070. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  6071. // {
  6072. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  6073. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6074. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  6075. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  6076. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  6077. // }
  6078. // }
  6079. // catch (Exception ex)
  6080. // {
  6081. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6082. // string str = ex.StackTrace;
  6083. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6084. // }
  6085. // #endregion S3节拍接口
  6086. // #region 心跳
  6087. // try
  6088. // {
  6089. // short states = 0;
  6090. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6091. // }
  6092. // catch (Exception ex)
  6093. // {
  6094. // string str = ex.StackTrace;
  6095. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6096. // }
  6097. // #endregion 心跳
  6098. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6099. // stopwatch1.Stop();
  6100. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6101. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6102. // }
  6103. // else
  6104. // {
  6105. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6106. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6107. // Funs[plcNo].Connect();
  6108. // }
  6109. // }
  6110. // catch (Exception ex)
  6111. // {
  6112. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6113. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6114. // Funs[plcNo].ReConnect();
  6115. // }
  6116. // Thread.Sleep(IntervalReadPLC);
  6117. // }
  6118. //}
  6119. /// <summary>
  6120. /// [S3] 值板机- 进站校验
  6121. /// </summary>
  6122. /// <param name="plcNo">PLC编号</param>
  6123. /// <param name="stationNameStr">工站全称</param>
  6124. private void S3进站校验(int plcNo, string stationNameStr)
  6125. {
  6126. Stopwatch stopwatch1 = new Stopwatch();
  6127. Stopwatch stopwatch2 = new Stopwatch();
  6128. try
  6129. {
  6130. stopwatch1.Start();
  6131. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6132. sn = sn.Replace("\0", "");
  6133. #region 查询载具上的产品信息
  6134. string cavityData = string.Empty;
  6135. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6136. if (string.IsNullOrEmpty(cavityData))
  6137. cavityData = "";
  6138. if (snResult != 0)
  6139. {
  6140. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6141. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6142. writeToPLC_Flag1.Adress = 2003;
  6143. writeToPLC_Flag1.Value = (short)6;
  6144. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6145. stopwatch1.Stop();
  6146. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6147. return;
  6148. }
  6149. #endregion 查询载具上的产品信息
  6150. string[] cavitySNs = cavityData.Split('.');
  6151. string part1Str = ""; // 产品1的SN码
  6152. string part2Str = ""; // 产品2的SN码
  6153. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6154. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6155. if (cavitySNs != null && cavitySNs.Length >= 2)
  6156. {
  6157. part1Str = cavitySNs[0];
  6158. part2Str = cavitySNs[1];
  6159. c1Part1Result_Check = 2;
  6160. c1Part2Result_Check = 2;
  6161. }
  6162. if (part1Str == "假产品")
  6163. c1Part1Result_Check = 3;
  6164. if (part2Str == "假产品")
  6165. c1Part2Result_Check = 3;
  6166. // 调用MES进站
  6167. stopwatch2.Start();
  6168. // 调用MES进站 - 产品1
  6169. List<TestItem> item;
  6170. int result1 = c1Part1Result_Check;
  6171. if (result1 != 3)
  6172. {
  6173. item = new List<TestItem>();
  6174. item.Add(new TestItem()
  6175. {
  6176. Parameter_name = "载具码",
  6177. Parameter_value = sn,
  6178. });
  6179. item.Add(new TestItem()
  6180. {
  6181. Parameter_name = "载具穴号",
  6182. Parameter_value = "1",
  6183. });
  6184. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6185. }
  6186. // 调用MES进站 - 产品2
  6187. int result2 = c1Part2Result_Check;
  6188. if (result2 != 3)
  6189. {
  6190. item = new List<TestItem>();
  6191. item.Add(new TestItem()
  6192. {
  6193. Parameter_name = "载具码",
  6194. Parameter_value = sn,
  6195. });
  6196. item.Add(new TestItem()
  6197. {
  6198. Parameter_name = "载具穴号",
  6199. Parameter_value = "2",
  6200. });
  6201. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6202. }
  6203. stopwatch2.Stop();
  6204. if (result1 == 2)
  6205. c1Part1Result_Check = 2;
  6206. if (result2 == 2)
  6207. c1Part2Result_Check = 2;
  6208. int result = result1;
  6209. if (result == 1)
  6210. result = result2;
  6211. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6212. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6213. short c1MES_FLAG_Check = (short)result;
  6214. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6215. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6216. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6217. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6218. //// MES_Flag
  6219. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6220. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6221. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6222. writeToPLC_Flag.Adress = 2003;
  6223. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6224. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6225. {
  6226. Name = "c1Part1Result_Check",
  6227. Adress = 2024,
  6228. ValueType = PLCValueType.Short,
  6229. Value = c1Part1Result_Check
  6230. });
  6231. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6232. {
  6233. Name = "c1Part2Result_Check",
  6234. Adress = 2025,
  6235. ValueType = PLCValueType.Short,
  6236. Value = c1Part2Result_Check
  6237. });
  6238. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6239. {
  6240. Name = "c1Part1Num_Check",
  6241. Adress = 2026,
  6242. ValueType = PLCValueType.Short,
  6243. Value = c1Part1Num_Check
  6244. });
  6245. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6246. {
  6247. Name = "c1Part2Num_Check",
  6248. Adress = 2027,
  6249. ValueType = PLCValueType.Short,
  6250. Value = c1Part2Num_Check
  6251. });
  6252. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6253. }
  6254. catch (Exception ex)
  6255. {
  6256. string str = ex.StackTrace;
  6257. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6258. // MES_Flag
  6259. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6260. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6261. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6262. writeToPLC_Flag.Adress = 2003;
  6263. writeToPLC_Flag.Value = (short)6;
  6264. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6265. }
  6266. stopwatch1.Stop();
  6267. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6268. }
  6269. /// <summary>
  6270. /// [S3] 值板机 - 二穴载具解绑
  6271. /// </summary>
  6272. /// <param name="plcNo">PLC编号</param>
  6273. /// <param name="stationNameStr">工站全称</param>
  6274. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6275. {
  6276. Stopwatch stopwatch1 = new Stopwatch();
  6277. Stopwatch stopwatch2 = new Stopwatch();
  6278. try
  6279. {
  6280. stopwatch1.Start();
  6281. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6282. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6283. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6284. // 解绑
  6285. #region 查询载具上的产品信息
  6286. string cavityData = string.Empty;
  6287. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6288. if (string.IsNullOrEmpty(cavityData))
  6289. cavityData = "";
  6290. if (snResult != 0)
  6291. {
  6292. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6293. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6294. writeToPLC_Flag1.Adress = 2082;
  6295. writeToPLC_Flag1.Value = (short)6;
  6296. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6297. stopwatch1.Stop();
  6298. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6299. return;
  6300. }
  6301. #endregion 查询载具上的产品信息
  6302. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6303. #region 解绑
  6304. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6305. {
  6306. // 删除
  6307. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6308. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6309. }
  6310. else
  6311. {
  6312. string data_new = string.Join(".", cavitySNs);
  6313. // 删除再插入
  6314. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6315. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6316. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6317. }
  6318. #endregion 解绑
  6319. short c1MES_FLAG_Unbind = 1;
  6320. stopwatch2.Start();
  6321. // MES_Flag
  6322. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6323. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6324. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6325. writeToPLC_Flag.Adress = 2082;
  6326. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6327. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6328. stopwatch2.Stop();
  6329. }
  6330. catch (Exception ex)
  6331. {
  6332. string str = ex.StackTrace;
  6333. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6334. // MES_Flag
  6335. stopwatch2.Start();
  6336. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6337. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6338. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6339. writeToPLC_Flag.Adress = 2082;
  6340. writeToPLC_Flag.Value = (short)6;
  6341. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6342. stopwatch2.Stop();
  6343. }
  6344. stopwatch1.Stop();
  6345. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6346. }
  6347. /// <summary>
  6348. /// [S3] 值板机 - 二穴载具绑定
  6349. /// </summary>
  6350. /// <param name="plcNo">PLC编号</param>
  6351. /// <param name="stationNameStr">工站全称</param>
  6352. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6353. {
  6354. Stopwatch stopwatch1 = new Stopwatch();
  6355. Stopwatch stopwatch2 = new Stopwatch();
  6356. try
  6357. {
  6358. stopwatch1.Start();
  6359. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6360. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6361. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6362. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6363. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6364. stopwatch2.Start();
  6365. #region 查询载具上的产品信息
  6366. string cavityData = string.Empty;
  6367. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6368. if (string.IsNullOrEmpty(cavityData))
  6369. cavityData = "";
  6370. if (snResult != 0)
  6371. {
  6372. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6373. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6374. writeToPLC_Flag1.Adress = 2115;
  6375. writeToPLC_Flag1.Value = (short)6;
  6376. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6377. stopwatch1.Stop();
  6378. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6379. return;
  6380. }
  6381. #endregion 查询载具上的产品信息
  6382. // 产品换载具
  6383. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6384. string partSn1 = "";
  6385. string partSn2 = "";
  6386. if (cavitySNs != null && cavitySNs.Length >= 2)
  6387. {
  6388. partSn1 = cavitySNs[0];
  6389. partSn2 = cavitySNs[1];
  6390. }
  6391. string data_new = string.Empty;
  6392. // 是否是两个穴位交换
  6393. if (c1CavityReverse_Bind == 1)
  6394. {
  6395. // 交换
  6396. data_new = string.Concat(partSn2, ".", partSn1);
  6397. }
  6398. else
  6399. { // 不交换
  6400. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6401. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6402. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6403. data_new = string.Join(".", cavitySNs);
  6404. }
  6405. // 删除再插入
  6406. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6407. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6408. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6409. stopwatch2.Stop();
  6410. short c1MES_FLAG_Bind = 1;
  6411. // MES_Flag
  6412. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6413. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6414. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6415. writeToPLC_Flag.Adress = 2115;
  6416. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6417. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6418. }
  6419. catch (Exception ex)
  6420. {
  6421. string str = ex.StackTrace;
  6422. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6423. // MES_Flag
  6424. stopwatch2.Start();
  6425. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6426. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6427. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6428. writeToPLC_Flag.Adress = 2115;
  6429. writeToPLC_Flag.Value = (short)6;
  6430. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6431. stopwatch2.Stop();
  6432. }
  6433. stopwatch1.Stop();
  6434. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6435. }
  6436. //// 上次采集到的SN
  6437. //private string sn_值板机 = string.Empty;
  6438. /// <summary>
  6439. /// [S3] 值板机 - 出站接口
  6440. /// </summary>
  6441. /// <param name="plcNo">PLC编号</param>
  6442. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6443. {
  6444. Stopwatch stopwatch1 = new Stopwatch();
  6445. Stopwatch stopwatch2 = new Stopwatch();
  6446. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6447. string stationNameStr = stationCode + stationName;
  6448. string processItem = stationName; // 测试项目
  6449. try
  6450. {
  6451. stopwatch1.Start();
  6452. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6453. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6454. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6455. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6456. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6457. sn = sn.Replace("\0", "");
  6458. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6459. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6460. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6461. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6462. bool pass = c1Result == 1;
  6463. // 查sn
  6464. #region 查询载具上的产品信息
  6465. string cavityData = string.Empty;
  6466. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6467. if (string.IsNullOrEmpty(cavityData))
  6468. cavityData = "";
  6469. if (snResult != 0)
  6470. {
  6471. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6472. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6473. writeToPLC_Flag1.Adress = 2150;
  6474. writeToPLC_Flag1.Value = (short)4;
  6475. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6476. stopwatch1.Stop();
  6477. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6478. return;
  6479. }
  6480. #endregion 查询载具上的产品信息
  6481. string[] cavitySNs = cavityData.Split('.');
  6482. string productSN = "";
  6483. if (cavitySNs != null && cavitySNs.Length >= 2)
  6484. {
  6485. productSN = cavitySNs[c1VehicleCavity];
  6486. cavitySNs[c1VehicleCavity] = "";
  6487. }
  6488. stopwatch2.Start();
  6489. List<TestItem> items = new List<TestItem>();
  6490. items.Add(new TestItem()
  6491. {
  6492. Parameter_name = "二穴载具码",
  6493. Parameter_value = c1ProductSN_Check,
  6494. Parameter_unit = ""
  6495. });
  6496. items.Add(new TestItem()
  6497. {
  6498. Parameter_name = "二穴载具穴号",
  6499. Parameter_value = c1VehicleCavity.ToString(),
  6500. Parameter_unit = ""
  6501. });
  6502. items.Add(new TestItem()
  6503. {
  6504. Parameter_name = "一穴载具码",
  6505. Parameter_value = sn,
  6506. Parameter_unit = ""
  6507. });
  6508. items.Add(new TestItem()
  6509. {
  6510. Parameter_name = "一穴载具穴号",
  6511. Parameter_value = "1",
  6512. Parameter_unit = ""
  6513. });
  6514. items.Add(new TestItem()
  6515. {
  6516. Parameter_name = "产品结果",
  6517. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6518. Parameter_unit = ""
  6519. });
  6520. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6521. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6522. short result = (short)result1;
  6523. stopwatch2.Stop();
  6524. #region 存储绑定数据到 边线MES系统中
  6525. if (result == 1)
  6526. {
  6527. string data = string.Concat(productSN);
  6528. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6529. if (resultMesR != 0)
  6530. {
  6531. result = 4;
  6532. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6533. }
  6534. }
  6535. #endregion 存储绑定数据到 边线MES系统中
  6536. #region 产品从 来源载具(二穴载具)中删除
  6537. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6538. {
  6539. // 删除
  6540. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6541. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6542. }
  6543. else
  6544. {
  6545. string data_new = string.Join(".", cavitySNs);
  6546. // 删除再插入
  6547. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6548. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6549. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6550. }
  6551. #endregion 产品从 来源载具(二穴载具)中删除
  6552. // MES_Flag 为MES报错
  6553. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6554. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6555. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6556. writeToPLC_Flag.Name = "c1MES_FLAG";
  6557. writeToPLC_Flag.Adress = 2150;
  6558. writeToPLC_Flag.Value = result;
  6559. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6560. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6561. }
  6562. catch (Exception ex)
  6563. {
  6564. stopwatch2.Restart();
  6565. // MES_Flag 为4上位机报错
  6566. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6567. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6568. writeToPLC_Flag.Name = "c1MES_FLAG";
  6569. writeToPLC_Flag.Adress = 2150;
  6570. writeToPLC_Flag.Value = (short)4;
  6571. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6572. stopwatch2.Stop();
  6573. string str = ex.StackTrace;
  6574. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6575. }
  6576. stopwatch1.Stop();
  6577. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6578. }
  6579. /// <summary>
  6580. /// [S3] 值板机- 节拍接口
  6581. /// </summary>
  6582. /// <param name="plcNo">PLC编号</param>
  6583. /// <param name="stationNameStr">工站全称</param>
  6584. private void S3节拍接口(int plcNo, string stationNameStr)
  6585. {
  6586. Stopwatch stopwatch1 = new Stopwatch();
  6587. Stopwatch stopwatch2 = new Stopwatch();
  6588. string resultStr = string.Empty;
  6589. try
  6590. {
  6591. stopwatch1.Start();
  6592. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6593. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6594. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6595. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6596. if (!actionBool)
  6597. {
  6598. stopwatch2.Start();
  6599. // MES_Flag
  6600. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6601. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6602. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6603. writeToPLC_Flag1.Adress = 2204;
  6604. writeToPLC_Flag1.Value = (short)4;
  6605. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6606. stopwatch2.Stop();
  6607. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6608. return;
  6609. }
  6610. string c1OEEPartNo = string.Empty; // 物料码
  6611. if (string.IsNullOrEmpty(c1OEEProductSN))
  6612. {
  6613. stopwatch2.Start();
  6614. // MES_Flag
  6615. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6616. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6617. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6618. writeToPLC_Flag1.Adress = 2204;
  6619. writeToPLC_Flag1.Value = (short)1;
  6620. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6621. stopwatch2.Stop();
  6622. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6623. return;
  6624. }
  6625. else
  6626. { // 查产品SN
  6627. c1OEEPartNo = "Test"; // ZS
  6628. }
  6629. short c1OEEMES_FLAG = 0;
  6630. // 上传OEE
  6631. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6632. c1OEEMES_FLAG = result.Item1;
  6633. resultStr = result.Item2;
  6634. stopwatch2.Start();
  6635. // MES_Flag
  6636. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6637. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6638. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6639. writeToPLC_Flag.Adress = 2204;
  6640. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6641. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6642. stopwatch2.Stop();
  6643. }
  6644. catch (Exception ex)
  6645. {
  6646. string str = ex.StackTrace;
  6647. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6648. // MES_Flag
  6649. stopwatch2.Start();
  6650. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6651. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6652. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6653. writeToPLC_Flag.Adress = 2204;
  6654. writeToPLC_Flag.Value = (short)4;
  6655. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6656. stopwatch2.Stop();
  6657. }
  6658. stopwatch1.Stop();
  6659. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6660. }
  6661. #endregion [S3] 值板机
  6662. #endregion PLC3 刘永村
  6663. #region PLC4 刘果段
  6664. #region [S4] 取放桁架
  6665. /// <summary>
  6666. /// S4工位的数据- 触发信号上次的值
  6667. /// </summary>
  6668. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6669. /// <summary>
  6670. /// S4工位的数据(含触发信号)
  6671. /// </summary>
  6672. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6673. /// <summary>
  6674. /// S4工位的数据- 回写点位
  6675. /// </summary>
  6676. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6677. /// <summary>
  6678. /// [S4] 取放桁架
  6679. /// </summary>
  6680. /// <param name="plcNo">PLC编号</param>
  6681. //private void ReadStation_S4(int plcNo)
  6682. //{
  6683. // // [S1] Tray盘上料装备
  6684. // // [S2] FCT
  6685. // // [S3] 值板机
  6686. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6687. // // [S5] Tray盘下料装备
  6688. // /// 上位机心跳
  6689. // /// 获取设备报警数据与状态信息
  6690. // string stationCode = "[S4_1]";
  6691. // string stationName = "载具下线装备";
  6692. // string stationNameStr = stationCode + stationName;
  6693. // string stationCode2 = "[S4_2]";
  6694. // string stationName2 = "桁架";
  6695. // string stationNameStr2 = stationCode2 + stationName2;
  6696. // string stationCode3 = "[S4_3]";
  6697. // string stationName3 = "提升机1";
  6698. // string stationNameStr3 = stationCode3 + stationName3;
  6699. // string stationCode4 = "[S4_4]";
  6700. // string stationName4 = "提升机2";
  6701. // string stationNameStr4 = stationCode4 + stationName4;
  6702. // string stationCode5 = "[S4_5]";
  6703. // string stationName5 = "载具上线装备";
  6704. // string stationNameStr5 = stationCode5 + stationName5;
  6705. // #region 创建字典
  6706. // // 触发信号字典 赋值
  6707. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6708. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6709. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6710. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6711. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6712. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6713. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6714. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6715. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6716. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6717. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6718. // // PLC数据字典 赋值
  6719. // // 载具下线装备(弹夹上线)
  6720. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6721. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6722. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6723. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6724. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6725. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6726. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6727. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6728. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6729. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6730. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6731. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6732. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6733. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6734. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6735. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6736. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6737. // s4PLCData.Add("d1Result", 0); // 产品结果
  6738. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6739. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6740. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6741. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6742. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6743. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6744. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6745. // // 真空标机(提升机)
  6746. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6747. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6748. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6749. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6750. // s4PLCData.Add("d3Result", 0); // 产品结果
  6751. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6752. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6753. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6754. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6755. // s4PLCData.Add("d4Result", 0); // 产品结果
  6756. // // 载具上线装备(弹夹下线)
  6757. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6758. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6759. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6760. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6761. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6762. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6763. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6764. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6765. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6766. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6767. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6768. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6769. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6770. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6771. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6772. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6773. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6774. // s4PLCData.Add("d5Result", 0); // 产品结果
  6775. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6776. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6777. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6778. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6779. // #endregion 创建字典
  6780. // while (IsRun)
  6781. // {
  6782. // try
  6783. // {
  6784. // if (!GlobalContext._IsCon_Funs4)
  6785. // {
  6786. // UpdatePLCMonitor(1, plcNo, 0);
  6787. // continue;
  6788. // }
  6789. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6790. // {
  6791. // Stopwatch stopwatch1 = new Stopwatch();
  6792. // Stopwatch stopwatch2 = new Stopwatch();
  6793. // stopwatch1.Start();
  6794. // stopwatch2.Start();
  6795. // #region 一次性读取所有数据
  6796. // // 载具下线装备(弹夹上线)
  6797. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6798. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6799. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6800. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6801. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6802. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6803. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6804. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6805. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6806. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6807. // int[] datas = data1.Concat(data2).ToArray();
  6808. // datas = datas.Concat(data3).ToArray();
  6809. // datas = datas.Concat(data4).ToArray();
  6810. // datas = datas.Concat(data5).ToArray();
  6811. // datas = datas.Concat(data6).ToArray();
  6812. // datas = datas.Concat(data7).ToArray();
  6813. // datas = datas.Concat(data8).ToArray();
  6814. // datas = datas.Concat(data9).ToArray();
  6815. // datas = datas.Concat(data10).ToArray();
  6816. // // 载具下线装备(弹夹上线)
  6817. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6818. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6819. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6820. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6821. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6822. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6823. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6824. // s4PLCData["d1MES_FLAG"] = datas[65];
  6825. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6826. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6827. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6828. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6829. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6830. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6831. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6832. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6833. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6834. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6835. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6836. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6837. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6838. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6839. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6840. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6841. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6842. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6843. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6844. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6845. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6846. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6847. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6848. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6849. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6850. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6851. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6852. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6853. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6854. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6855. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6856. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6857. // s4PLCData["d1Result"] = datas[386];
  6858. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6859. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6860. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6861. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6862. // s4PLCData["d1OEEType"] = datas[419];
  6863. // // 桁架(查询标机中弹夹的状态)
  6864. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6865. // s4PLCData["d2BulletclipStates"] = datas[431];
  6866. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6867. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6868. // // 真空标机
  6869. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6870. // s4PLCData["d3MES_FLAG"] = datas[463];
  6871. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6872. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6873. // s4PLCData["d3Result"] = datas[484];
  6874. // s4PLCData["d3Type"] = datas[485];
  6875. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6876. // s4PLCData["d4MES_FLAG"] = datas[496];
  6877. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6878. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6879. // s4PLCData["d4Result"] = datas[517];
  6880. // s4PLCData["d4Type"] = datas[518];
  6881. // // 载具上线装备(弹夹下线)
  6882. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6883. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6884. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6885. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6886. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6887. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6888. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6889. // s4PLCData["d5MES_FLAG"] = datas[591];
  6890. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6891. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6892. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6893. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6894. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6895. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6896. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6897. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6898. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6899. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6900. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6901. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6902. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6903. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6904. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6905. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6906. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6907. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6908. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6909. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6910. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6911. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6912. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6913. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6914. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6915. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6916. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6917. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6918. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6919. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6920. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6921. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6922. // s4PLCData["d5Result"] = datas[912];
  6923. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  6924. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  6925. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  6926. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  6927. // s4PLCData["d5OEEType"] = datas[945];
  6928. // #endregion 一次性读取所有数据
  6929. // stopwatch2.Stop();
  6930. // #region 回写操作,写后清空flag
  6931. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  6932. // #endregion 回写操作,写后清空flag
  6933. // // N801A-S4_1 弹夹扫码
  6934. // #region N801A-S4_1 弹夹扫码
  6935. // try
  6936. // {
  6937. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  6938. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  6939. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  6940. // {
  6941. // if (d1BulletclipScanCode == 1) // 0->1
  6942. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6943. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  6944. // }
  6945. // }
  6946. // catch (Exception ex)
  6947. // {
  6948. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  6949. // string str = ex.StackTrace;
  6950. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6951. // }
  6952. // #endregion N801A-S4_1 弹夹扫码
  6953. // // N801A-S4_1 载具扫码
  6954. // #region N801A-S4_1 载具扫码
  6955. // try
  6956. // {
  6957. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  6958. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  6959. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  6960. // {
  6961. // if (d1VehicleScanCode == 1) // 0->1
  6962. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6963. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  6964. // }
  6965. // }
  6966. // catch (Exception ex)
  6967. // {
  6968. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  6969. // string str = ex.StackTrace;
  6970. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6971. // }
  6972. // #endregion N801A-S4_1 载具扫码
  6973. // // N801A-S4_1 出站接口
  6974. // #region N801A-S4_1 出站接口
  6975. // try
  6976. // {
  6977. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  6978. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  6979. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  6980. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  6981. // {
  6982. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  6983. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6984. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  6985. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  6986. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  6987. // }
  6988. // }
  6989. // catch (Exception ex)
  6990. // {
  6991. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  6992. // string str = ex.StackTrace;
  6993. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6994. // }
  6995. // #endregion N801A-S4_1 出站接口
  6996. // // N801A-S4_1 节拍接口
  6997. // #region N801A-S4_1 节拍接口
  6998. // try
  6999. // {
  7000. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  7001. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  7002. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  7003. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  7004. // {
  7005. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  7006. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7007. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  7008. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  7009. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  7010. // }
  7011. // }
  7012. // catch (Exception ex)
  7013. // {
  7014. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7015. // string str = ex.StackTrace;
  7016. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7017. // }
  7018. // #endregion N801A-S4_1 节拍接口
  7019. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  7020. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  7021. // try
  7022. // {
  7023. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  7024. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  7025. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  7026. // {
  7027. // if (d2BulletclipScanCode == 1) // 0->1
  7028. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  7029. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  7030. // }
  7031. // }
  7032. // catch (Exception ex)
  7033. // {
  7034. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7035. // string str = ex.StackTrace;
  7036. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7037. // }
  7038. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  7039. // // N801A-S4_3 真空标机1 数据
  7040. // #region N801A-S4_3 真空标机1
  7041. // try
  7042. // {
  7043. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  7044. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  7045. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  7046. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  7047. // {
  7048. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  7049. // {
  7050. // int stationType = (int)s4PLCData["d3Type"];
  7051. // if (stationType == 1)
  7052. // {
  7053. // // S4_3进站接口
  7054. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  7055. // }
  7056. // else if (stationType == 2)
  7057. // {
  7058. // // S4_3出站接口
  7059. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  7060. // }
  7061. // }
  7062. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  7063. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  7064. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  7065. // }
  7066. // }
  7067. // catch (Exception ex)
  7068. // {
  7069. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7070. // string str = ex.StackTrace;
  7071. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7072. // }
  7073. // #endregion N801A-S4_3 真空标机1
  7074. // // N801A-S4_4 真空标机2 数据
  7075. // #region N801A-S4_4 真空标机2
  7076. // try
  7077. // {
  7078. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  7079. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  7080. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  7081. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  7082. // {
  7083. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  7084. // {
  7085. // int stationType = (int)s4PLCData["d4Type"];
  7086. // if (stationType == 1)
  7087. // {
  7088. // // S4_4进站接口
  7089. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  7090. // }
  7091. // else if (stationType == 2)
  7092. // {
  7093. // // S4_4出站接口
  7094. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  7095. // }
  7096. // }
  7097. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  7098. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  7099. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  7100. // }
  7101. // }
  7102. // catch (Exception ex)
  7103. // {
  7104. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7105. // string str = ex.StackTrace;
  7106. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7107. // }
  7108. // #endregion N801A-S4_4 真空标机2
  7109. // // N801A-S4_5 弹夹扫码 数据
  7110. // #region N801A-S4_5 弹夹扫码
  7111. // try
  7112. // {
  7113. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7114. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7115. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7116. // {
  7117. // if (d5BulletclipScanCode == 1) // 0->1
  7118. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7119. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7120. // }
  7121. // }
  7122. // catch (Exception ex)
  7123. // {
  7124. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7125. // string str = ex.StackTrace;
  7126. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7127. // }
  7128. // #endregion N801A-S4_5 弹夹扫码
  7129. // // N801A-S4_5 载具扫码 数据
  7130. // #region N801A-S4_5 载具扫码
  7131. // try
  7132. // {
  7133. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7134. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7135. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7136. // {
  7137. // if (d5VehicleScanCode == 1) // 0->1
  7138. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7139. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7140. // }
  7141. // }
  7142. // catch (Exception ex)
  7143. // {
  7144. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7145. // string str = ex.StackTrace;
  7146. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7147. // }
  7148. // #endregion N801A-S4_5 载具扫码
  7149. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7150. // #region N801A-S4_5 出站接口
  7151. // try
  7152. // {
  7153. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7154. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7155. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7156. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7157. // {
  7158. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7159. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7160. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7161. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7162. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7163. // }
  7164. // }
  7165. // catch (Exception ex)
  7166. // {
  7167. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7168. // string str = ex.StackTrace;
  7169. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7170. // }
  7171. // #endregion N801A-S4_5 出站接口
  7172. // // N801A-S4_5 节拍接口 数据
  7173. // #region N801A-S4_5 节拍接口
  7174. // try
  7175. // {
  7176. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7177. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7178. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7179. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7180. // {
  7181. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7182. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7183. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7184. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7185. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7186. // }
  7187. // }
  7188. // catch (Exception ex)
  7189. // {
  7190. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7191. // string str = ex.StackTrace;
  7192. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7193. // }
  7194. // #endregion N801A-S4_5 节拍接口
  7195. // #region 心跳
  7196. // try
  7197. // {
  7198. // short states = 0;
  7199. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7200. // }
  7201. // catch (Exception ex)
  7202. // {
  7203. // string str = ex.StackTrace;
  7204. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7205. // }
  7206. // #endregion 心跳
  7207. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7208. // stopwatch1.Stop();
  7209. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7210. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7211. // }
  7212. // else
  7213. // {
  7214. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7215. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7216. // Funs[plcNo].Connect();
  7217. // }
  7218. // }
  7219. // catch (Exception ex)
  7220. // {
  7221. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7222. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7223. // Funs[plcNo].ReConnect();
  7224. // }
  7225. // Thread.Sleep(IntervalReadPLC);
  7226. // }
  7227. //}
  7228. /// <summary>
  7229. /// [S4] 取放桁架 - S4_1弹夹扫码
  7230. /// </summary>
  7231. /// <param name="plcNo">PLC编号</param>
  7232. /// <param name="stationNameStr">工站全称</param>
  7233. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7234. {
  7235. Stopwatch stopwatch1 = new Stopwatch();
  7236. Stopwatch stopwatch2 = new Stopwatch();
  7237. try
  7238. {
  7239. stopwatch1.Start();
  7240. // ZS 弹夹扫码
  7241. string d1BulletclipCode = " "; // 扫到的码
  7242. short d1BulletclipScanCode = 2;
  7243. stopwatch2.Start();
  7244. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7245. //// MES_Flag
  7246. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7247. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7248. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7249. writeToPLC_Flag.Adress = 2002;
  7250. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7251. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7252. {
  7253. Name = "d1BulletclipCode",
  7254. Adress = 2003,
  7255. ValueType = PLCValueType.String,
  7256. ValueTypeStrLength = 20,
  7257. Value = d1BulletclipCode
  7258. });
  7259. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7260. stopwatch2.Stop();
  7261. }
  7262. catch (Exception ex)
  7263. {
  7264. string str = ex.StackTrace;
  7265. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7266. stopwatch2.Start();
  7267. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7268. //// MES_Flag
  7269. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7270. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7271. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7272. writeToPLC_Flag.Adress = 2002;
  7273. writeToPLC_Flag.Value = (short)6;
  7274. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7275. {
  7276. Name = "d1BulletclipCode",
  7277. Adress = 2003,
  7278. ValueType = PLCValueType.String,
  7279. ValueTypeStrLength = 20,
  7280. Value = " "
  7281. });
  7282. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7283. stopwatch2.Stop();
  7284. }
  7285. stopwatch1.Stop();
  7286. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7287. }
  7288. /// <summary>
  7289. /// [S4] 取放桁架 - S4_1载具扫码
  7290. /// </summary>
  7291. /// <param name="plcNo">PLC编号</param>
  7292. /// <param name="stationNameStr">工站全称</param>
  7293. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7294. {
  7295. Stopwatch stopwatch1 = new Stopwatch();
  7296. Stopwatch stopwatch2 = new Stopwatch();
  7297. try
  7298. {
  7299. stopwatch1.Start();
  7300. // ZS 载具扫码
  7301. string d1VehicleCode = ""; // 扫到的码
  7302. short d1VehicleScanCode = 2;
  7303. #region 进站
  7304. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7305. {
  7306. #region 查询载具上的产品信息
  7307. string cavityData = string.Empty;
  7308. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7309. if (string.IsNullOrEmpty(cavityData))
  7310. cavityData = "";
  7311. if (snResult != 0)
  7312. {
  7313. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7314. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7315. writeToPLC_Flag1.Adress = 2033;
  7316. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7317. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7318. {
  7319. Name = "d1VehicleCode",
  7320. Adress = 2034,
  7321. ValueType = PLCValueType.String,
  7322. ValueTypeStrLength = 20,
  7323. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7324. });
  7325. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7326. stopwatch1.Stop();
  7327. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7328. return;
  7329. }
  7330. string[] cavitySNs = cavityData.Split('.');
  7331. string partNo = "";
  7332. if (cavitySNs != null && cavitySNs.Length >= 1)
  7333. {
  7334. partNo = cavitySNs[0];
  7335. }
  7336. #endregion 查询载具上的产品信息
  7337. List<TestItem> item = new List<TestItem>();
  7338. item.Add(new TestItem()
  7339. {
  7340. Parameter_name = "载具码",
  7341. Parameter_value = d1VehicleCode,
  7342. });
  7343. item.Add(new TestItem()
  7344. {
  7345. Parameter_name = "载具穴号",
  7346. Parameter_value = "1",
  7347. });
  7348. stopwatch2.Start();
  7349. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7350. stopwatch2.Stop();
  7351. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7352. }
  7353. #endregion 进站
  7354. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7355. //// MES_Flag
  7356. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7357. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7358. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7359. writeToPLC_Flag.Adress = 2033;
  7360. writeToPLC_Flag.Value = d1VehicleScanCode;
  7361. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7362. {
  7363. Name = "d1VehicleCode",
  7364. Adress = 2034,
  7365. ValueType = PLCValueType.String,
  7366. ValueTypeStrLength = 20,
  7367. Value = d1VehicleCode
  7368. });
  7369. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7370. }
  7371. catch (Exception ex)
  7372. {
  7373. string str = ex.StackTrace;
  7374. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7375. stopwatch2.Start();
  7376. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7377. //// MES_Flag
  7378. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7379. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7380. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7381. writeToPLC_Flag.Adress = 2033;
  7382. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7383. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7384. {
  7385. Name = "d1VehicleCode",
  7386. Adress = 2034,
  7387. ValueType = PLCValueType.String,
  7388. ValueTypeStrLength = 20,
  7389. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7390. });
  7391. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7392. stopwatch2.Stop();
  7393. }
  7394. stopwatch1.Stop();
  7395. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7396. }
  7397. // 上次采集到的SN
  7398. //private string sn_S4_1出站接口 = string.Empty;
  7399. /// <summary>
  7400. /// [S4] 取放桁架 - S4_1出站接口
  7401. /// </summary>
  7402. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7403. {
  7404. Stopwatch stopwatch1 = new Stopwatch();
  7405. Stopwatch stopwatch2 = new Stopwatch();
  7406. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7407. string stationNameStr = stationCode + stationName;
  7408. string processItem = stationName; // 测试项目
  7409. try
  7410. {
  7411. stopwatch1.Start();
  7412. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7413. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7414. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7415. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7416. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7417. sn = sn.Replace("\0", "");
  7418. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7419. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7420. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7421. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7422. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7423. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7424. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7425. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7426. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7427. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7428. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7429. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7430. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7431. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7432. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7433. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7434. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7435. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7436. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7437. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7438. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7439. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7440. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7441. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7442. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7443. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7444. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7445. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7446. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7447. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7448. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7449. bool pass = d1Result == 1;
  7450. // 存 载具SN列表
  7451. List<string> vehicleCodes = new List<string>()
  7452. {
  7453. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7454. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7455. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7456. };
  7457. // 统一查 产品SN列表
  7458. List<string> partNos = new List<string>();
  7459. foreach (string vehicleCode in vehicleCodes)
  7460. {
  7461. if (string.IsNullOrEmpty(vehicleCode))
  7462. partNos.Add("");
  7463. else
  7464. {
  7465. string partNo = "";
  7466. #region 查询载具上的产品信息
  7467. string cavityData = string.Empty;
  7468. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7469. if (string.IsNullOrEmpty(cavityData))
  7470. cavityData = "";
  7471. if (snResult != 0)
  7472. {
  7473. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7474. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7475. writeToPLC_Flag1.Adress = 2065;
  7476. writeToPLC_Flag1.Value = (short)4;
  7477. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7478. stopwatch1.Stop();
  7479. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7480. return;
  7481. }
  7482. string[] cavitySNs = cavityData.Split('.');
  7483. if (cavitySNs != null && cavitySNs.Length >= 1)
  7484. partNo = cavitySNs[0];
  7485. #endregion 查询载具上的产品信息
  7486. partNos.Add(partNo);
  7487. }
  7488. }
  7489. // 统一上传
  7490. stopwatch2.Start();
  7491. List<int> results = new List<int>();
  7492. for (int i = 0; i < partNos.Count; i++)
  7493. {
  7494. string index = (i + 1).ToString(); // 弹夹穴号
  7495. if (string.IsNullOrEmpty(partNos[i]))
  7496. results.Add(1);
  7497. else
  7498. {
  7499. List<TestItem> items1 = new List<TestItem>();
  7500. items1.Add(new TestItem()
  7501. {
  7502. Parameter_name = "弹夹码",
  7503. Parameter_value = sn,
  7504. Parameter_unit = ""
  7505. });
  7506. items1.Add(new TestItem()
  7507. {
  7508. Parameter_name = "弹夹穴号",
  7509. Parameter_value = index,
  7510. Parameter_unit = ""
  7511. });
  7512. items1.Add(new TestItem()
  7513. {
  7514. Parameter_name = "载具码",
  7515. Parameter_value = vehicleCodes[i],
  7516. Parameter_unit = ""
  7517. });
  7518. items1.Add(new TestItem()
  7519. {
  7520. Parameter_name = "载具穴号",
  7521. Parameter_value = "1",
  7522. Parameter_unit = ""
  7523. });
  7524. items1.Add(new TestItem()
  7525. {
  7526. Parameter_name = "产品结果",
  7527. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7528. Parameter_unit = ""
  7529. });
  7530. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7531. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7532. results.Add(result1);
  7533. }
  7534. }
  7535. short result = 0;
  7536. if (results.All(a => a == 1))
  7537. result = 1;
  7538. else if (results.Contains(3))
  7539. result = 3;
  7540. else if (results.Contains(2))
  7541. result = 2;
  7542. else if (results.Contains(4))
  7543. result = 4;
  7544. else
  7545. result = 4;
  7546. stopwatch2.Stop();
  7547. #region 存储绑定数据到 边线MES系统中
  7548. if (result == 1)
  7549. {
  7550. string data = string.Join(".", vehicleCodes);
  7551. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7552. if (resultMesR != 0)
  7553. {
  7554. result = 4;
  7555. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7556. }
  7557. }
  7558. #endregion 存储绑定数据到 边线MES系统中
  7559. // MES_Flag 为4MES报错
  7560. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7561. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7562. writeToPLC_Flag.Name = "d1MES_FLAG";
  7563. writeToPLC_Flag.Adress = 2065;
  7564. writeToPLC_Flag.Value = result;
  7565. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7566. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7567. }
  7568. catch (Exception ex)
  7569. {
  7570. stopwatch2.Restart();
  7571. // MES_Flag 为4上位机报错
  7572. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7573. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7574. writeToPLC_Flag.Name = "d1MES_FLAG";
  7575. writeToPLC_Flag.Adress = 2065;
  7576. writeToPLC_Flag.Value = (short)4;
  7577. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7578. stopwatch2.Stop();
  7579. string str = ex.StackTrace;
  7580. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7581. }
  7582. stopwatch1.Stop();
  7583. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7584. }
  7585. /// <summary>
  7586. /// [S4] 取放桁架 - S4_1节拍接口
  7587. /// </summary>
  7588. /// <param name="plcNo">PLC编号</param>
  7589. /// <param name="stationNameStr">工站全称</param>
  7590. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7591. {
  7592. Stopwatch stopwatch1 = new Stopwatch();
  7593. Stopwatch stopwatch2 = new Stopwatch();
  7594. string resultStr = string.Empty;
  7595. try
  7596. {
  7597. stopwatch1.Start();
  7598. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7599. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7600. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7601. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7602. if (!actionBool)
  7603. {
  7604. stopwatch2.Start();
  7605. // MES_Flag
  7606. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7607. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7608. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7609. writeToPLC_Flag1.Adress = 2398;
  7610. writeToPLC_Flag1.Value = (short)4;
  7611. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7612. stopwatch2.Stop();
  7613. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7614. return;
  7615. }
  7616. string d1OEEPartNo = string.Empty; // 物料码
  7617. if (string.IsNullOrEmpty(d1OEEProductSN))
  7618. {
  7619. stopwatch2.Start();
  7620. // MES_Flag
  7621. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7622. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7623. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7624. writeToPLC_Flag1.Adress = 2398;
  7625. writeToPLC_Flag1.Value = (short)1;
  7626. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7627. stopwatch2.Stop();
  7628. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7629. return;
  7630. }
  7631. else
  7632. { // 查产品SN ZS
  7633. d1OEEPartNo = "Test";
  7634. }
  7635. short d1OEEMES_FLAG = 0;
  7636. // 上传OEE
  7637. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7638. d1OEEMES_FLAG = result.Item1;
  7639. resultStr = result.Item2;
  7640. stopwatch2.Start();
  7641. // MES_Flag
  7642. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7643. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7644. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7645. writeToPLC_Flag.Adress = 2398;
  7646. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7647. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7648. stopwatch2.Stop();
  7649. }
  7650. catch (Exception ex)
  7651. {
  7652. string str = ex.StackTrace;
  7653. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7654. // MES_Flag
  7655. stopwatch2.Start();
  7656. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7657. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7658. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7659. writeToPLC_Flag.Adress = 2398;
  7660. writeToPLC_Flag.Value = (short)4;
  7661. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7662. stopwatch2.Stop();
  7663. }
  7664. stopwatch1.Stop();
  7665. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7666. }
  7667. /// <summary>
  7668. /// [S4] 取放桁架 - S4_2桁架
  7669. /// </summary>
  7670. /// <param name="plcNo">PLC编号</param>
  7671. /// <param name="stationNameStr">工站全称</param>
  7672. private void S4_2桁架(int plcNo, string stationNameStr)
  7673. {
  7674. Stopwatch stopwatch1 = new Stopwatch();
  7675. Stopwatch stopwatch2 = new Stopwatch();
  7676. try
  7677. {
  7678. stopwatch1.Start();
  7679. // ZS 弹夹扫码
  7680. string d2BulletclipCode = " "; // 扫到的码
  7681. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7682. short d2BulletclipScanCode = 2;
  7683. stopwatch2.Start();
  7684. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7685. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7686. //// MES_Flag
  7687. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7688. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7689. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7690. writeToPLC_Flag.Adress = 2430;
  7691. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7692. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7693. {
  7694. Name = "d2BulletclipCode",
  7695. Adress = 2432,
  7696. ValueType = PLCValueType.String,
  7697. ValueTypeStrLength = 20,
  7698. Value = d2BulletclipCode
  7699. });
  7700. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7701. {
  7702. Name = "d2BulletclipStates",
  7703. Adress = 2431,
  7704. ValueType = PLCValueType.Short,
  7705. Value = d2BulletclipStates
  7706. });
  7707. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7708. stopwatch2.Stop();
  7709. }
  7710. catch (Exception ex)
  7711. {
  7712. string str = ex.StackTrace;
  7713. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7714. stopwatch2.Start();
  7715. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7716. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7717. // MES_Flag
  7718. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7719. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7720. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7721. writeToPLC_Flag.Adress = 2430;
  7722. writeToPLC_Flag.Value = (short)6;
  7723. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7724. {
  7725. Name = "d2BulletclipCode",
  7726. Adress = 2432,
  7727. ValueType = PLCValueType.String,
  7728. ValueTypeStrLength = 20,
  7729. Value = " "
  7730. });
  7731. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7732. {
  7733. Name = "d2BulletclipStates",
  7734. Adress = 2431,
  7735. ValueType = PLCValueType.Short,
  7736. Value = (short)0
  7737. });
  7738. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7739. stopwatch2.Stop();
  7740. }
  7741. stopwatch1.Stop();
  7742. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7743. }
  7744. // 上次采集到的SN
  7745. //private string sn_S4_3进站接口 = string.Empty;
  7746. /// <summary>
  7747. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7748. /// </summary>
  7749. private void S4_3进站接口(int plcNo, string stationNameStr)
  7750. {
  7751. Stopwatch stopwatch1 = new Stopwatch();
  7752. Stopwatch stopwatch2 = new Stopwatch();
  7753. try
  7754. {
  7755. stopwatch1.Start();
  7756. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7757. sn = sn.Replace("\0", "");
  7758. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7759. #region 查询15个载具码
  7760. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7761. string vehicleData = string.Empty;
  7762. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7763. if (string.IsNullOrEmpty(vehicleData))
  7764. vehicleData = "";
  7765. if (snResult != 0)
  7766. {
  7767. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7768. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7769. writeToPLC_Flag1.Adress = 2463;
  7770. writeToPLC_Flag1.Value = (short)4;
  7771. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7772. stopwatch1.Stop();
  7773. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7774. return;
  7775. }
  7776. string[] cavitySNs = vehicleData.Split('.');
  7777. if (cavitySNs != null && cavitySNs.Length > 0)
  7778. {
  7779. for (int i = 0; i < cavitySNs.Length; i++)
  7780. {
  7781. if (string.IsNullOrEmpty(cavitySNs[i]))
  7782. vehicleCodes.Add("");
  7783. else
  7784. vehicleCodes.Add(cavitySNs[i]);
  7785. }
  7786. }
  7787. #endregion 查询15个载具码
  7788. #region 查询15个产品SN
  7789. List<string> portNos = new List<string>(); // 15个产品SN
  7790. foreach (string vehicleCode in vehicleCodes)
  7791. {
  7792. if (string.IsNullOrEmpty(vehicleCode))
  7793. portNos.Add("");
  7794. else
  7795. {
  7796. // 查询
  7797. string cavityData = string.Empty;
  7798. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7799. if (string.IsNullOrEmpty(cavityData))
  7800. cavityData = "";
  7801. if (snResult1 != 0)
  7802. {
  7803. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7804. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7805. writeToPLC_Flag1.Adress = 2463;
  7806. writeToPLC_Flag1.Value = (short)4;
  7807. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7808. stopwatch1.Stop();
  7809. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7810. return;
  7811. }
  7812. string[] partSNs = cavityData.Split('.');
  7813. if (partSNs != null && partSNs.Length >= 1)
  7814. portNos.Add(partSNs[0]);
  7815. else
  7816. portNos.Add("");
  7817. }
  7818. }
  7819. #endregion 查询15个产品SN
  7820. // 调用MES进站(最多15个)
  7821. stopwatch2.Start();
  7822. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7823. for (int i = 0; i < vehicleCodes.Count; i++)
  7824. {
  7825. // 循环进站
  7826. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7827. {
  7828. // 产品SN(物料码)校验
  7829. string portNo = portNos[i];
  7830. List<TestItem> item = new List<TestItem>();
  7831. item.Add(new TestItem()
  7832. {
  7833. Parameter_name = "弹夹码",
  7834. Parameter_value = sn,
  7835. });
  7836. item.Add(new TestItem()
  7837. {
  7838. Parameter_name = "弹夹穴位",
  7839. Parameter_value = (i + 1).ToString(),
  7840. });
  7841. item.Add(new TestItem()
  7842. {
  7843. Parameter_name = "载具码",
  7844. Parameter_value = vehicleCodes[i],
  7845. });
  7846. item.Add(new TestItem()
  7847. {
  7848. Parameter_name = "载具穴号",
  7849. Parameter_value = "1",
  7850. });
  7851. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7852. }
  7853. }
  7854. stopwatch2.Stop();
  7855. short result = 0;
  7856. bool haveMesWarn = results.Contains(5);
  7857. bool havePCWarn = results.Contains(6);
  7858. if (haveMesWarn)
  7859. result = 2; // 5->2
  7860. else if (havePCWarn)
  7861. result = 6; // 6->4
  7862. else
  7863. result = 1;
  7864. // MES_Flag 为4MES报错
  7865. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7866. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7867. writeToPLC_Flag.Name = "d3MES_FLAG";
  7868. writeToPLC_Flag.Adress = 2463;
  7869. writeToPLC_Flag.Value = result;
  7870. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7871. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7872. }
  7873. catch (Exception ex)
  7874. {
  7875. stopwatch2.Stop();
  7876. // MES_Flag 为4上位机报错
  7877. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7878. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7879. writeToPLC_Flag.Name = "d3MES_FLAG";
  7880. writeToPLC_Flag.Adress = 2463;
  7881. writeToPLC_Flag.Value = (short)4;
  7882. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7883. string str = ex.StackTrace;
  7884. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7885. }
  7886. stopwatch1.Stop();
  7887. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7888. }
  7889. // 上次采集到的SN
  7890. //private string sn_S4_3出站接口 = string.Empty;
  7891. /// <summary>
  7892. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7893. /// </summary>
  7894. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7895. {
  7896. Stopwatch stopwatch1 = new Stopwatch();
  7897. Stopwatch stopwatch2 = new Stopwatch();
  7898. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7899. string stationNameStr = stationCode + stationName;
  7900. string processItem = stationName; // 测试项目
  7901. try
  7902. {
  7903. stopwatch1.Start();
  7904. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7905. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7906. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7907. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7908. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7909. sn = sn.Replace("\0", "");
  7910. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7911. bool isPass = d3Result == 1; // 产品结果 bool
  7912. #region 查询15个载具码
  7913. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7914. string vehicleData = string.Empty;
  7915. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7916. if (string.IsNullOrEmpty(vehicleData))
  7917. vehicleData = "";
  7918. if (snResult1 != 0)
  7919. {
  7920. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7921. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7922. writeToPLC_Flag1.Adress = 2463;
  7923. writeToPLC_Flag1.Value = (short)4;
  7924. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7925. stopwatch1.Stop();
  7926. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7927. return;
  7928. }
  7929. string[] cavitySNs = vehicleData.Split('.');
  7930. if (cavitySNs != null && cavitySNs.Length > 0)
  7931. {
  7932. for (int i = 0; i < cavitySNs.Length; i++)
  7933. {
  7934. if (string.IsNullOrEmpty(cavitySNs[i]))
  7935. vehicleCodes.Add("");
  7936. else
  7937. vehicleCodes.Add(cavitySNs[i]);
  7938. }
  7939. }
  7940. #endregion 查询15个载具码
  7941. // 统一查 产品SN列表
  7942. List<string> partNos = new List<string>();
  7943. foreach (string vehicleCode in vehicleCodes)
  7944. {
  7945. if (string.IsNullOrEmpty(vehicleCode))
  7946. partNos.Add("");
  7947. else
  7948. {
  7949. string partNo = "";
  7950. #region 查询载具上的产品信息
  7951. string cavityData = string.Empty;
  7952. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7953. if (string.IsNullOrEmpty(cavityData))
  7954. cavityData = "";
  7955. if (snResult != 0)
  7956. {
  7957. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7958. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7959. writeToPLC_Flag1.Adress = 2463;
  7960. writeToPLC_Flag1.Value = (short)4;
  7961. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7962. stopwatch1.Stop();
  7963. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7964. return;
  7965. }
  7966. string[] partSNs = cavityData.Split('.');
  7967. if (partSNs != null && partSNs.Length >= 1)
  7968. partNo = partSNs[0];
  7969. #endregion 查询载具上的产品信息
  7970. partNos.Add(partNo);
  7971. }
  7972. }
  7973. // 统一上传 - 调用MES出站
  7974. stopwatch2.Start();
  7975. List<int> results = new List<int>();
  7976. for (int i = 0; i < partNos.Count; i++)
  7977. {
  7978. string index = (i + 1).ToString(); // 弹夹穴号
  7979. if (string.IsNullOrEmpty(partNos[i]))
  7980. results.Add(1);
  7981. else
  7982. {
  7983. List<TestItem> items1 = new List<TestItem>();
  7984. items1.Add(new TestItem()
  7985. {
  7986. Parameter_name = "弹夹码",
  7987. Parameter_value = sn,
  7988. Parameter_unit = ""
  7989. });
  7990. items1.Add(new TestItem()
  7991. {
  7992. Parameter_name = "弹夹穴号",
  7993. Parameter_value = index,
  7994. Parameter_unit = ""
  7995. });
  7996. items1.Add(new TestItem()
  7997. {
  7998. Parameter_name = "载具码",
  7999. Parameter_value = vehicleCodes[i],
  8000. Parameter_unit = ""
  8001. });
  8002. items1.Add(new TestItem()
  8003. {
  8004. Parameter_name = "载具穴号",
  8005. Parameter_value = "1",
  8006. Parameter_unit = ""
  8007. });
  8008. items1.Add(new TestItem()
  8009. {
  8010. Parameter_name = "产品结果",
  8011. Parameter_value = d3Result == 1 ? "OK" : "NG",
  8012. Parameter_unit = ""
  8013. });
  8014. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8015. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8016. results.Add(result1);
  8017. }
  8018. }
  8019. short result = 0;
  8020. if (results.All(a => a == 1))
  8021. result = 1;
  8022. else if (results.Contains(3))
  8023. result = 3;
  8024. else if (results.Contains(2))
  8025. result = 2;
  8026. else if (results.Contains(4))
  8027. result = 4;
  8028. else
  8029. result = 4;
  8030. stopwatch2.Stop();
  8031. // MES_Flag 为4MES报错
  8032. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8033. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8034. writeToPLC_Flag.Name = "d3MES_FLAG";
  8035. writeToPLC_Flag.Adress = 2463;
  8036. writeToPLC_Flag.Value = result;
  8037. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8038. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8039. }
  8040. catch (Exception ex)
  8041. {
  8042. stopwatch2.Restart();
  8043. // MES_Flag 为4上位机报错
  8044. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  8045. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8046. writeToPLC_Flag.Name = "d3MES_FLAG";
  8047. writeToPLC_Flag.Adress = 2463;
  8048. writeToPLC_Flag.Value = (short)4;
  8049. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8050. string str = ex.StackTrace;
  8051. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8052. stopwatch2.Stop();
  8053. }
  8054. stopwatch1.Stop();
  8055. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8056. }
  8057. // 上次采集到的SN
  8058. //private string sn_S4_4进站接口 = string.Empty;
  8059. /// <summary>
  8060. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  8061. /// </summary>
  8062. private void S4_4进站接口(int plcNo, string stationNameStr)
  8063. {
  8064. Stopwatch stopwatch1 = new Stopwatch();
  8065. Stopwatch stopwatch2 = new Stopwatch();
  8066. try
  8067. {
  8068. stopwatch1.Start();
  8069. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8070. sn = sn.Replace("\0", "");
  8071. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8072. #region 查询15个载具码
  8073. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8074. string vehicleData = string.Empty;
  8075. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8076. if (string.IsNullOrEmpty(vehicleData))
  8077. vehicleData = "";
  8078. if (snResult != 0)
  8079. {
  8080. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8081. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8082. writeToPLC_Flag1.Adress = 2463;
  8083. writeToPLC_Flag1.Value = (short)4;
  8084. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8085. stopwatch1.Stop();
  8086. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8087. return;
  8088. }
  8089. string[] cavitySNs = vehicleData.Split('.');
  8090. if (cavitySNs != null && cavitySNs.Length > 0)
  8091. {
  8092. for (int i = 0; i < cavitySNs.Length; i++)
  8093. {
  8094. if (string.IsNullOrEmpty(cavitySNs[i]))
  8095. vehicleCodes.Add("");
  8096. else
  8097. vehicleCodes.Add(cavitySNs[i]);
  8098. }
  8099. }
  8100. #endregion 查询15个载具码
  8101. #region 查询15个产品SN
  8102. List<string> portNos = new List<string>(); // 15个产品SN
  8103. foreach (string vehicleCode in vehicleCodes)
  8104. {
  8105. if (string.IsNullOrEmpty(vehicleCode))
  8106. portNos.Add("");
  8107. else
  8108. {
  8109. // 查询
  8110. string cavityData = string.Empty;
  8111. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8112. if (string.IsNullOrEmpty(cavityData))
  8113. cavityData = "";
  8114. if (snResult1 != 0)
  8115. {
  8116. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8117. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8118. writeToPLC_Flag1.Adress = 2463;
  8119. writeToPLC_Flag1.Value = (short)4;
  8120. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8121. stopwatch1.Stop();
  8122. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8123. return;
  8124. }
  8125. string[] partSNs = cavityData.Split('.');
  8126. if (partSNs != null && partSNs.Length >= 1)
  8127. portNos.Add(partSNs[0]);
  8128. else
  8129. portNos.Add("");
  8130. }
  8131. }
  8132. #endregion 查询15个产品SN
  8133. // 调用MES进站(最多15个)
  8134. stopwatch2.Start();
  8135. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8136. for (int i = 0; i < vehicleCodes.Count; i++)
  8137. {
  8138. // 循环进站
  8139. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8140. {
  8141. // 产品SN(物料码)校验
  8142. string portNo = portNos[i];
  8143. List<TestItem> item = new List<TestItem>();
  8144. item.Add(new TestItem()
  8145. {
  8146. Parameter_name = "弹夹码",
  8147. Parameter_value = sn,
  8148. });
  8149. item.Add(new TestItem()
  8150. {
  8151. Parameter_name = "弹夹穴位",
  8152. Parameter_value = (i + 1).ToString(),
  8153. });
  8154. item.Add(new TestItem()
  8155. {
  8156. Parameter_name = "载具码",
  8157. Parameter_value = vehicleCodes[i],
  8158. });
  8159. item.Add(new TestItem()
  8160. {
  8161. Parameter_name = "载具穴号",
  8162. Parameter_value = "1",
  8163. });
  8164. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8165. }
  8166. }
  8167. stopwatch2.Stop();
  8168. short result = 0;
  8169. bool haveMesWarn = results.Contains(5);
  8170. bool havePCWarn = results.Contains(6);
  8171. if (haveMesWarn)
  8172. result = 2; // 5->2
  8173. else if (havePCWarn)
  8174. result = 6; // 6->4
  8175. else
  8176. result = 1;
  8177. // MES_Flag 为4MES报错
  8178. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8179. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8180. writeToPLC_Flag.Name = "d4MES_FLAG";
  8181. writeToPLC_Flag.Adress = 2496;
  8182. writeToPLC_Flag.Value = result;
  8183. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8184. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8185. }
  8186. catch (Exception ex)
  8187. {
  8188. stopwatch2.Stop();
  8189. // MES_Flag 为4上位机报错
  8190. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8191. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8192. writeToPLC_Flag.Name = "d4MES_FLAG";
  8193. writeToPLC_Flag.Adress = 2496;
  8194. writeToPLC_Flag.Value = (short)4;
  8195. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8196. string str = ex.StackTrace;
  8197. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8198. }
  8199. stopwatch1.Stop();
  8200. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8201. }
  8202. // 上次采集到的SN
  8203. //private string sn_S4_4出站接口 = string.Empty;
  8204. /// <summary>
  8205. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8206. /// </summary>
  8207. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8208. {
  8209. Stopwatch stopwatch1 = new Stopwatch();
  8210. Stopwatch stopwatch2 = new Stopwatch();
  8211. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8212. string stationNameStr = stationCode + stationName;
  8213. string processItem = stationName; // 测试项目
  8214. try
  8215. {
  8216. stopwatch1.Start();
  8217. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8218. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8219. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8220. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8221. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8222. sn = sn.Replace("\0", "");
  8223. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8224. bool isPass = d4Result == 1; // 产品结果 bool
  8225. #region 查询15个载具码
  8226. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8227. string vehicleData = string.Empty;
  8228. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8229. if (string.IsNullOrEmpty(vehicleData))
  8230. vehicleData = "";
  8231. if (snResult1 != 0)
  8232. {
  8233. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8234. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8235. writeToPLC_Flag1.Adress = 2496;
  8236. writeToPLC_Flag1.Value = (short)4;
  8237. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8238. stopwatch1.Stop();
  8239. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8240. return;
  8241. }
  8242. string[] cavitySNs = vehicleData.Split('.');
  8243. if (cavitySNs != null && cavitySNs.Length > 0)
  8244. {
  8245. for (int i = 0; i < cavitySNs.Length; i++)
  8246. {
  8247. if (string.IsNullOrEmpty(cavitySNs[i]))
  8248. vehicleCodes.Add("");
  8249. else
  8250. vehicleCodes.Add(cavitySNs[i]);
  8251. }
  8252. }
  8253. #endregion 查询15个载具码
  8254. // 统一查 产品SN列表
  8255. List<string> partNos = new List<string>();
  8256. foreach (string vehicleCode in vehicleCodes)
  8257. {
  8258. if (string.IsNullOrEmpty(vehicleCode))
  8259. partNos.Add("");
  8260. else
  8261. {
  8262. string partNo = "";
  8263. #region 查询载具上的产品信息
  8264. string cavityData = string.Empty;
  8265. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8266. if (string.IsNullOrEmpty(cavityData))
  8267. cavityData = "";
  8268. if (snResult != 0)
  8269. {
  8270. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8271. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8272. writeToPLC_Flag1.Adress = 2496;
  8273. writeToPLC_Flag1.Value = (short)4;
  8274. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8275. stopwatch1.Stop();
  8276. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8277. return;
  8278. }
  8279. string[] partSNs = cavityData.Split('.');
  8280. if (partSNs != null && partSNs.Length >= 1)
  8281. partNo = partSNs[0];
  8282. #endregion 查询载具上的产品信息
  8283. partNos.Add(partNo);
  8284. }
  8285. }
  8286. // 调用MES出站
  8287. stopwatch2.Start();
  8288. // 统一上传
  8289. List<int> results = new List<int>();
  8290. for (int i = 0; i < partNos.Count; i++)
  8291. {
  8292. string index = (i + 1).ToString(); // 弹夹穴号
  8293. if (string.IsNullOrEmpty(partNos[i]))
  8294. results.Add(1);
  8295. else
  8296. {
  8297. List<TestItem> items1 = new List<TestItem>();
  8298. items1.Add(new TestItem()
  8299. {
  8300. Parameter_name = "弹夹码",
  8301. Parameter_value = sn,
  8302. Parameter_unit = ""
  8303. });
  8304. items1.Add(new TestItem()
  8305. {
  8306. Parameter_name = "弹夹穴号",
  8307. Parameter_value = index,
  8308. Parameter_unit = ""
  8309. });
  8310. items1.Add(new TestItem()
  8311. {
  8312. Parameter_name = "载具码",
  8313. Parameter_value = vehicleCodes[i],
  8314. Parameter_unit = ""
  8315. });
  8316. items1.Add(new TestItem()
  8317. {
  8318. Parameter_name = "载具穴号",
  8319. Parameter_value = "1",
  8320. Parameter_unit = ""
  8321. });
  8322. items1.Add(new TestItem()
  8323. {
  8324. Parameter_name = "产品结果",
  8325. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8326. Parameter_unit = ""
  8327. });
  8328. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8329. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8330. results.Add(result1);
  8331. }
  8332. }
  8333. short result = 0;
  8334. if (results.All(a => a == 1))
  8335. result = 1;
  8336. else if (results.Contains(3))
  8337. result = 3;
  8338. else if (results.Contains(2))
  8339. result = 2;
  8340. else if (results.Contains(4))
  8341. result = 4;
  8342. else
  8343. result = 4;
  8344. stopwatch2.Stop();
  8345. // MES_Flag 为4MES报错
  8346. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8347. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8348. writeToPLC_Flag.Name = "d4MES_FLAG";
  8349. writeToPLC_Flag.Adress = 2496;
  8350. writeToPLC_Flag.Value = result;
  8351. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8352. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8353. }
  8354. catch (Exception ex)
  8355. {
  8356. stopwatch2.Restart();
  8357. // MES_Flag 为4上位机报错
  8358. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8359. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8360. writeToPLC_Flag.Name = "d4MES_FLAG";
  8361. writeToPLC_Flag.Adress = 2496;
  8362. writeToPLC_Flag.Value = (short)4;
  8363. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8364. string str = ex.StackTrace;
  8365. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8366. stopwatch2.Stop();
  8367. }
  8368. stopwatch1.Stop();
  8369. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8370. }
  8371. /// <summary>
  8372. /// [S4] 取放桁架 - S4_5弹夹扫码
  8373. /// </summary>
  8374. /// <param name="plcNo">PLC编号</param>
  8375. /// <param name="stationNameStr">工站全称</param>
  8376. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8377. {
  8378. Stopwatch stopwatch1 = new Stopwatch();
  8379. Stopwatch stopwatch2 = new Stopwatch();
  8380. try
  8381. {
  8382. stopwatch1.Start();
  8383. // ZS 弹夹扫码
  8384. string d5BulletclipCode = " "; // 扫到的码
  8385. short d5BulletclipScanCode = 2;
  8386. stopwatch2.Start();
  8387. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8388. //// MES_Flag
  8389. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8390. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8391. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8392. writeToPLC_Flag.Adress = 2528;
  8393. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8394. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8395. {
  8396. Name = "d5BulletclipCode",
  8397. Adress = 2529,
  8398. ValueType = PLCValueType.String,
  8399. ValueTypeStrLength = 20,
  8400. Value = d5BulletclipCode
  8401. });
  8402. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8403. stopwatch2.Stop();
  8404. }
  8405. catch (Exception ex)
  8406. {
  8407. string str = ex.StackTrace;
  8408. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8409. stopwatch2.Start();
  8410. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8411. //// MES_Flag
  8412. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8413. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8414. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8415. writeToPLC_Flag.Adress = 2528;
  8416. writeToPLC_Flag.Value = (short)6;
  8417. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8418. {
  8419. Name = "d5BulletclipCode",
  8420. Adress = 2529,
  8421. ValueType = PLCValueType.String,
  8422. ValueTypeStrLength = 20,
  8423. Value = " "
  8424. });
  8425. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8426. stopwatch2.Stop();
  8427. }
  8428. stopwatch1.Stop();
  8429. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8430. }
  8431. /// <summary>
  8432. /// [S4] 取放桁架 - S4_5载具扫码
  8433. /// </summary>
  8434. /// <param name="plcNo">PLC编号</param>
  8435. /// <param name="stationNameStr">工站全称</param>
  8436. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8437. {
  8438. Stopwatch stopwatch1 = new Stopwatch();
  8439. Stopwatch stopwatch2 = new Stopwatch();
  8440. try
  8441. {
  8442. stopwatch1.Start();
  8443. // ZS 载具扫码
  8444. string d5VehicleCode = " "; // 扫到的码
  8445. short d5VehicleScanCode = 2;
  8446. #region 进站
  8447. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8448. {
  8449. // 查产品SN
  8450. #region 查询载具上的产品信息
  8451. string cavityData = string.Empty;
  8452. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8453. if (string.IsNullOrEmpty(cavityData))
  8454. cavityData = "";
  8455. if (snResult != 0)
  8456. {
  8457. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8458. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8459. writeToPLC_Flag1.Adress = 2559;
  8460. writeToPLC_Flag1.Value = (short)6;
  8461. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8462. {
  8463. Name = "d5VehicleCode",
  8464. Adress = 2560,
  8465. ValueType = PLCValueType.String,
  8466. ValueTypeStrLength = 20,
  8467. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8468. });
  8469. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8470. stopwatch1.Stop();
  8471. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8472. return;
  8473. }
  8474. string[] cavitySNs = cavityData.Split('.');
  8475. string partNo = "";
  8476. if (cavitySNs != null && cavitySNs.Length >= 1)
  8477. {
  8478. partNo = cavitySNs[0];
  8479. }
  8480. #endregion 查询载具上的产品信息
  8481. List<TestItem> item = new List<TestItem>();
  8482. item.Add(new TestItem()
  8483. {
  8484. Parameter_name = "载具码",
  8485. Parameter_value = d5VehicleCode,
  8486. });
  8487. item.Add(new TestItem()
  8488. {
  8489. Parameter_name = "载具穴号",
  8490. Parameter_value = "1",
  8491. });
  8492. stopwatch2.Start();
  8493. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8494. stopwatch2.Stop();
  8495. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8496. }
  8497. #endregion 进站
  8498. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8499. //// MES_Flag
  8500. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8501. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8502. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8503. writeToPLC_Flag.Adress = 2559;
  8504. writeToPLC_Flag.Value = d5VehicleScanCode;
  8505. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8506. {
  8507. Name = "d5VehicleCode",
  8508. Adress = 2560,
  8509. ValueType = PLCValueType.String,
  8510. ValueTypeStrLength = 20,
  8511. Value = d5VehicleCode
  8512. });
  8513. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8514. }
  8515. catch (Exception ex)
  8516. {
  8517. string str = ex.StackTrace;
  8518. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8519. stopwatch2.Start();
  8520. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8521. //// MES_Flag
  8522. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8523. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8524. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8525. writeToPLC_Flag.Adress = 2559;
  8526. writeToPLC_Flag.Value = (short)6;
  8527. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8528. {
  8529. Name = "d5VehicleCode",
  8530. Adress = 2560,
  8531. ValueType = PLCValueType.String,
  8532. ValueTypeStrLength = 20,
  8533. Value = " "
  8534. });
  8535. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8536. stopwatch2.Stop();
  8537. }
  8538. stopwatch1.Stop();
  8539. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8540. }
  8541. // 上次采集到的SN
  8542. //private string sn_S4_5出站接口 = string.Empty;
  8543. /// <summary>
  8544. /// [S4] 取放桁架 - S4_5出站接口
  8545. /// </summary>
  8546. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8547. {
  8548. Stopwatch stopwatch1 = new Stopwatch();
  8549. Stopwatch stopwatch2 = new Stopwatch();
  8550. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8551. string stationNameStr = stationCode + stationName;
  8552. string processItem = stationName; // 测试项目
  8553. try
  8554. {
  8555. stopwatch1.Start();
  8556. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8557. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8558. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8559. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8560. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8561. sn = sn.Replace("\0", "");
  8562. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8563. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8564. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8565. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8566. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8567. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8568. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8569. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8570. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8571. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8572. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8573. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8574. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8575. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8576. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8577. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8578. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8579. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8580. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8581. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8582. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8583. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8584. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8585. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8586. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8587. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8588. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8589. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8590. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8591. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8592. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8593. bool pass = d5Result == 1;
  8594. // 存 载具SN列表
  8595. List<string> vehicleCodes = new List<string>()
  8596. {
  8597. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8598. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8599. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8600. };
  8601. // 统一查 产品SN列表
  8602. List<string> partNos = new List<string>();
  8603. foreach (string vehicleCode in vehicleCodes)
  8604. {
  8605. if (string.IsNullOrEmpty(vehicleCode))
  8606. partNos.Add("");
  8607. else
  8608. {
  8609. string partNo = "";
  8610. #region 查询载具上的产品信息
  8611. string cavityData = string.Empty;
  8612. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8613. if (string.IsNullOrEmpty(cavityData))
  8614. cavityData = "";
  8615. if (snResult != 0)
  8616. {
  8617. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8618. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8619. writeToPLC_Flag1.Adress = 2591;
  8620. writeToPLC_Flag1.Value = (short)4;
  8621. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8622. stopwatch1.Stop();
  8623. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8624. return;
  8625. }
  8626. string[] cavitySNs = cavityData.Split('.');
  8627. if (cavitySNs != null && cavitySNs.Length >= 1)
  8628. partNo = cavitySNs[0];
  8629. #endregion 查询载具上的产品信息
  8630. partNos.Add(partNo);
  8631. }
  8632. }
  8633. // 统一上传
  8634. stopwatch2.Start();
  8635. List<int> results = new List<int>();
  8636. for (int i = 0; i < partNos.Count; i++)
  8637. {
  8638. string index = (i + 1).ToString(); // 弹夹穴号
  8639. if (string.IsNullOrEmpty(partNos[i]))
  8640. results.Add(1);
  8641. else
  8642. {
  8643. List<TestItem> items1 = new List<TestItem>();
  8644. items1.Add(new TestItem()
  8645. {
  8646. Parameter_name = "弹夹码",
  8647. Parameter_value = sn,
  8648. Parameter_unit = ""
  8649. });
  8650. items1.Add(new TestItem()
  8651. {
  8652. Parameter_name = "弹夹穴号",
  8653. Parameter_value = index,
  8654. Parameter_unit = ""
  8655. });
  8656. items1.Add(new TestItem()
  8657. {
  8658. Parameter_name = "载具码",
  8659. Parameter_value = vehicleCodes[i],
  8660. Parameter_unit = ""
  8661. });
  8662. items1.Add(new TestItem()
  8663. {
  8664. Parameter_name = "载具穴号",
  8665. Parameter_value = "1",
  8666. Parameter_unit = ""
  8667. });
  8668. items1.Add(new TestItem()
  8669. {
  8670. Parameter_name = "产品结果",
  8671. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8672. Parameter_unit = ""
  8673. });
  8674. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8675. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8676. results.Add(result1);
  8677. }
  8678. }
  8679. short result = 0;
  8680. if (results.All(a => a == 1))
  8681. result = 1;
  8682. else if (results.Contains(3))
  8683. result = 3;
  8684. else if (results.Contains(2))
  8685. result = 2;
  8686. else if (results.Contains(4))
  8687. result = 4;
  8688. else
  8689. result = 4;
  8690. stopwatch2.Stop();
  8691. #region 存储绑定数据到 边线MES系统中
  8692. if (result == 1)
  8693. {
  8694. // 删除绑定信息
  8695. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8696. if (resultMesR != 0)
  8697. {
  8698. result = 4;
  8699. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8700. }
  8701. }
  8702. #endregion 存储绑定数据到 边线MES系统中
  8703. // MES_Flag 为4MES报错
  8704. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8705. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8706. writeToPLC_Flag.Name = "d5MES_FLAG";
  8707. writeToPLC_Flag.Adress = 2591;
  8708. writeToPLC_Flag.Value = result;
  8709. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8710. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8711. }
  8712. catch (Exception ex)
  8713. {
  8714. stopwatch2.Restart();
  8715. // MES_Flag 为4上位机报错
  8716. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8717. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8718. writeToPLC_Flag.Name = "d5MES_FLAG";
  8719. writeToPLC_Flag.Adress = 2591;
  8720. writeToPLC_Flag.Value = (short)4;
  8721. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8722. stopwatch2.Stop();
  8723. string str = ex.StackTrace;
  8724. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8725. }
  8726. stopwatch1.Stop();
  8727. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8728. }
  8729. /// <summary>
  8730. /// [S4] 取放桁架 - S4_5节拍接口
  8731. /// </summary>
  8732. /// <param name="plcNo">PLC编号</param>
  8733. /// <param name="stationNameStr">工站全称</param>
  8734. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8735. {
  8736. Stopwatch stopwatch1 = new Stopwatch();
  8737. Stopwatch stopwatch2 = new Stopwatch();
  8738. string resultStr = string.Empty;
  8739. try
  8740. {
  8741. stopwatch1.Start();
  8742. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8743. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8744. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8745. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8746. if (!actionBool)
  8747. {
  8748. stopwatch2.Start();
  8749. // MES_Flag
  8750. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8751. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8752. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8753. writeToPLC_Flag1.Adress = 2924;
  8754. writeToPLC_Flag1.Value = (short)4;
  8755. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8756. stopwatch2.Stop();
  8757. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8758. return;
  8759. }
  8760. string d5OEEPartNo = string.Empty; // 物料码
  8761. if (string.IsNullOrEmpty(d5OEEProductSN))
  8762. {
  8763. stopwatch2.Start();
  8764. // MES_Flag
  8765. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8766. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8767. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8768. writeToPLC_Flag1.Adress = 2924;
  8769. writeToPLC_Flag1.Value = (short)1;
  8770. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8771. stopwatch2.Stop();
  8772. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8773. return;
  8774. }
  8775. else
  8776. { // 查产品SN
  8777. d5OEEPartNo = "Test"; // ZS
  8778. }
  8779. short d5OEEMES_FLAG = 0;
  8780. // 上传OEE
  8781. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8782. d5OEEMES_FLAG = result.Item1;
  8783. resultStr = result.Item2;
  8784. stopwatch2.Start();
  8785. // MES_Flag
  8786. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8787. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8788. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8789. writeToPLC_Flag.Adress = 2924;
  8790. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8791. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8792. stopwatch2.Stop();
  8793. }
  8794. catch (Exception ex)
  8795. {
  8796. string str = ex.StackTrace;
  8797. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8798. // MES_Flag
  8799. stopwatch2.Start();
  8800. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8801. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8802. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8803. writeToPLC_Flag.Adress = 2924;
  8804. writeToPLC_Flag.Value = (short)4;
  8805. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8806. stopwatch2.Stop();
  8807. }
  8808. stopwatch1.Stop();
  8809. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8810. }
  8811. #endregion [S4] 取放桁架
  8812. #endregion PLC4 刘果段
  8813. #region PLC5 张超凡
  8814. #region [S5] Tray盘下料装备
  8815. /// <summary>
  8816. /// S5工位的数据- 触发信号上次的值
  8817. /// </summary>
  8818. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8819. /// <summary>
  8820. /// S5工位的数据(含触发信号)
  8821. /// </summary>
  8822. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8823. /// <summary>
  8824. /// S5工位的数据- 回写点位
  8825. /// </summary>
  8826. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8827. /// <summary>
  8828. /// [S5] Tray盘下料装备
  8829. /// </summary>
  8830. /// <param name="plcNo">PLC编号</param>
  8831. //private void ReadStation_S5(int plcNo)
  8832. //{
  8833. // // [S1] Tray盘上料装备
  8834. // // [S2] FCT
  8835. // // [S3] 值板机
  8836. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8837. // // [S5] Tray盘下料装备
  8838. // /// 上位机心跳
  8839. // /// 获取设备报警数据与状态信息
  8840. // string stationCode = "[S5]";
  8841. // string stationName = "Tray盘下料装备";
  8842. // string stationNameStr = stationCode + stationName;
  8843. // #region 创建字典
  8844. // // 触发信号字典 赋值
  8845. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8846. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8847. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8848. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8849. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8850. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8851. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8852. // // PLC数据字典 赋值
  8853. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8854. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8855. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8856. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8857. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8858. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8859. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8860. // s5PLCData.Add("e1Result", 0); // 产品结果
  8861. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8862. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8863. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8864. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8865. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8866. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8867. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8868. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8869. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8870. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8871. // #endregion 创建字典
  8872. // while (IsRun)
  8873. // {
  8874. // try
  8875. // {
  8876. // if (!GlobalContext._IsCon_Funs5)
  8877. // {
  8878. // UpdatePLCMonitor(1, plcNo, 0);
  8879. // continue;
  8880. // }
  8881. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8882. // {
  8883. // Stopwatch stopwatch1 = new Stopwatch();
  8884. // Stopwatch stopwatch2 = new Stopwatch();
  8885. // stopwatch1.Start();
  8886. // stopwatch2.Start();
  8887. // #region 一次性读取所有数据
  8888. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8889. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8890. // int[] datas = data1.Concat(data2).ToArray();
  8891. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8892. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8893. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8894. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8895. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8896. // s5PLCData["e1MES_FLAG"] = datas[35];
  8897. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8898. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8899. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8900. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8901. // s5PLCData["e1Result"] = datas[76];
  8902. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8903. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8904. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8905. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8906. // s5PLCData["e1OEEType"] = datas[109];
  8907. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8908. // s5PLCData["e1AGVUpStart"] = datas[121];
  8909. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8910. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8911. // s5PLCData["e1AGVDownStart"] = datas[134];
  8912. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8913. // #endregion 一次性读取所有数据
  8914. // stopwatch2.Stop();
  8915. // #region 回写操作,写后清空flag
  8916. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8917. // #endregion 回写操作,写后清空flag
  8918. // #region 进站校验
  8919. // try
  8920. // {
  8921. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8922. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8923. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  8924. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  8925. // {
  8926. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  8927. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8928. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  8929. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8930. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  8931. // }
  8932. // }
  8933. // catch (Exception ex)
  8934. // {
  8935. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8936. // string str = ex.StackTrace;
  8937. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8938. // }
  8939. // #endregion 进站校验
  8940. // #region 出站接口
  8941. // try
  8942. // {
  8943. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  8944. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  8945. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  8946. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  8947. // {
  8948. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  8949. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8950. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  8951. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  8952. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  8953. // }
  8954. // }
  8955. // catch (Exception ex)
  8956. // {
  8957. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  8958. // string str = ex.StackTrace;
  8959. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8960. // }
  8961. // #endregion 出站接口
  8962. // #region 节拍接口
  8963. // try
  8964. // {
  8965. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  8966. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  8967. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  8968. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  8969. // {
  8970. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  8971. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8972. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  8973. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  8974. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  8975. // }
  8976. // }
  8977. // catch (Exception ex)
  8978. // {
  8979. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  8980. // string str = ex.StackTrace;
  8981. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8982. // }
  8983. // #endregion 节拍接口
  8984. // #region AGV上料
  8985. // // AGV上料叫AGV信号
  8986. // try
  8987. // {
  8988. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  8989. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  8990. // if (e1AGVUpCall != e1AGVUpCallOld)
  8991. // {
  8992. // if (e1AGVUpCall == 1) // 0->1
  8993. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  8994. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  8995. // }
  8996. // }
  8997. // catch (Exception ex)
  8998. // {
  8999. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9000. // string str = ex.StackTrace;
  9001. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9002. // }
  9003. // // AGV上料完成信号
  9004. // try
  9005. // {
  9006. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  9007. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  9008. // if (e1AGVUpEnd != e1AGVUpEndOld)
  9009. // {
  9010. // if (e1AGVUpEnd == 1) // 0->1
  9011. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  9012. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  9013. // }
  9014. // }
  9015. // catch (Exception ex)
  9016. // {
  9017. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9018. // string str = ex.StackTrace;
  9019. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9020. // }
  9021. // #endregion AGV上料
  9022. // #region AGV下料
  9023. // // AGV下料叫agv信号
  9024. // try
  9025. // {
  9026. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  9027. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  9028. // if (e1AGVDownCall != e1AGVDownCallOld)
  9029. // {
  9030. // if (e1AGVDownCall == 1) // 0->1
  9031. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  9032. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  9033. // }
  9034. // }
  9035. // catch (Exception ex)
  9036. // {
  9037. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9038. // string str = ex.StackTrace;
  9039. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9040. // }
  9041. // // AGV下料完成信号
  9042. // try
  9043. // {
  9044. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  9045. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  9046. // if (e1AGVDownEnd != e1AGVDownEndOld)
  9047. // {
  9048. // if (e1AGVDownEnd == 1) // 0->1
  9049. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  9050. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  9051. // }
  9052. // }
  9053. // catch (Exception ex)
  9054. // {
  9055. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9056. // string str = ex.StackTrace;
  9057. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9058. // }
  9059. // #endregion AGV下料
  9060. // #region 心跳
  9061. // try
  9062. // {
  9063. // short states = 0;
  9064. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9065. // }
  9066. // catch (Exception ex)
  9067. // {
  9068. // string str = ex.StackTrace;
  9069. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9070. // }
  9071. // #endregion 心跳
  9072. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9073. // stopwatch1.Stop();
  9074. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9075. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9076. // }
  9077. // else
  9078. // {
  9079. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9080. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9081. // Funs[plcNo].Connect();
  9082. // }
  9083. // }
  9084. // catch (Exception ex)
  9085. // {
  9086. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9087. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9088. // Funs[plcNo].ReConnect();
  9089. // }
  9090. // Thread.Sleep(IntervalReadPLC);
  9091. // }
  9092. //}
  9093. /// <summary>
  9094. /// [S5] Tray盘下料装备 - 进站校验
  9095. /// </summary>
  9096. /// <param name="plcNo">PLC编号</param>
  9097. /// <param name="stationNameStr">工站全称</param>
  9098. private void S5进站校验(int plcNo, string stationNameStr)
  9099. {
  9100. Stopwatch stopwatch1 = new Stopwatch();
  9101. Stopwatch stopwatch2 = new Stopwatch();
  9102. try
  9103. {
  9104. stopwatch1.Start();
  9105. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9106. sn = sn.Replace("\0", "");
  9107. // 获取产品SN By 载具码
  9108. #region 查询载具上的产品信息
  9109. string cavityData = string.Empty;
  9110. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9111. if (string.IsNullOrEmpty(cavityData))
  9112. cavityData = "";
  9113. if (snResult != 0)
  9114. {
  9115. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9116. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9117. writeToPLC_Flag1.Adress = 2003;
  9118. writeToPLC_Flag1.Value = (short)6;
  9119. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9120. stopwatch1.Stop();
  9121. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9122. return;
  9123. }
  9124. string[] cavitySNs = cavityData.Split('.');
  9125. string partNo = string.Empty;
  9126. if (cavitySNs != null && cavitySNs.Length >= 1)
  9127. partNo = cavitySNs[0];
  9128. #endregion 查询载具上的产品信息
  9129. // 产品SN(物料码)校验
  9130. List<TestItem> item = new List<TestItem>();
  9131. item.Add(new TestItem()
  9132. {
  9133. Parameter_name = "载具码",
  9134. Parameter_value = sn,
  9135. });
  9136. item.Add(new TestItem()
  9137. {
  9138. Parameter_name = "载具穴号",
  9139. Parameter_value = "1",
  9140. });
  9141. stopwatch2.Start();
  9142. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9143. stopwatch2.Stop();
  9144. short e1MES_FLAG_Check = (short)result;
  9145. // MES_Flag
  9146. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9147. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9148. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9149. writeToPLC_Flag.Adress = 2003;
  9150. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9151. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9152. }
  9153. catch (Exception ex)
  9154. {
  9155. string str = ex.StackTrace;
  9156. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9157. // MES_Flag
  9158. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9159. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9160. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9161. writeToPLC_Flag.Adress = 2003;
  9162. writeToPLC_Flag.Value = (short)6;
  9163. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9164. }
  9165. stopwatch1.Stop();
  9166. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9167. }
  9168. /// <summary>
  9169. /// [S5] Tray盘下料装备 - 出站接口
  9170. /// </summary>
  9171. /// <param name="plcNo"></param>
  9172. /// <param name="stationCode"></param>
  9173. /// <param name="stationName"></param>
  9174. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9175. {
  9176. Stopwatch stopwatch1 = new Stopwatch();
  9177. Stopwatch stopwatch2 = new Stopwatch();
  9178. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9179. string stationNameStr = stationCode + stationName;
  9180. string processItem = stationName; // 测试项目
  9181. try
  9182. {
  9183. stopwatch1.Start();
  9184. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9185. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9186. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9187. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9188. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9189. sn = sn.Replace("\0", "");
  9190. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9191. //partNo = partNo.Replace("\0", "");
  9192. #region 查询载具上的产品信息
  9193. string cavityData = string.Empty;
  9194. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9195. if (string.IsNullOrEmpty(cavityData))
  9196. cavityData = "";
  9197. if (snResult != 0)
  9198. {
  9199. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9200. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9201. writeToPLC_Flag1.Adress = 2035;
  9202. writeToPLC_Flag1.Value = (short)4;
  9203. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9204. stopwatch1.Stop();
  9205. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9206. return;
  9207. }
  9208. string[] cavitySNs = cavityData.Split('.');
  9209. string partNo = string.Empty;
  9210. if (cavitySNs != null && cavitySNs.Length >= 1)
  9211. partNo = cavitySNs[0];
  9212. #endregion 查询载具上的产品信息
  9213. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9214. bool pass = e1Result == 1;
  9215. stopwatch2.Start();
  9216. // 上传MES
  9217. List<TestItem> items = new List<TestItem>();
  9218. items.Add(new TestItem()
  9219. {
  9220. Parameter_name = "载具码",
  9221. Parameter_value = sn,
  9222. Parameter_unit = ""
  9223. });
  9224. items.Add(new TestItem()
  9225. {
  9226. Parameter_name = "载具穴号",
  9227. Parameter_value = "1",
  9228. Parameter_unit = ""
  9229. });
  9230. items.Add(new TestItem()
  9231. {
  9232. Parameter_name = "产品结果",
  9233. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9234. Parameter_unit = ""
  9235. });
  9236. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  9237. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9238. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9239. short result = result1 == 1 ? (short)1 : (short)3;
  9240. stopwatch2.Stop();
  9241. #region 存储绑定数据到 边线MES系统中
  9242. if (result == 1)
  9243. {
  9244. // 删除绑定信息
  9245. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9246. if (resultMesR != 0)
  9247. {
  9248. result = 4;
  9249. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9250. }
  9251. }
  9252. #endregion 存储绑定数据到 边线MES系统中
  9253. // MES_Flag 为MES报错
  9254. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9255. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9256. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9257. writeToPLC_Flag.Name = "e1MES_FLAG";
  9258. writeToPLC_Flag.Adress = 2035;
  9259. writeToPLC_Flag.Value = result;
  9260. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9261. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9262. }
  9263. catch (Exception ex)
  9264. {
  9265. stopwatch2.Restart();
  9266. // MES_Flag 为4上位机报错
  9267. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9268. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9269. writeToPLC_Flag.Name = "e1MES_FLAG";
  9270. writeToPLC_Flag.Adress = 2035;
  9271. writeToPLC_Flag.Value = (short)4;
  9272. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9273. stopwatch2.Stop();
  9274. string str = ex.StackTrace;
  9275. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9276. }
  9277. stopwatch1.Stop();
  9278. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9279. }
  9280. /// <summary>
  9281. /// [S5] Tray盘下料装备 - 节拍接口
  9282. /// </summary>
  9283. /// <param name="plcNo">PLC编号</param>
  9284. /// <param name="stationNameStr">工站全称</param>
  9285. private void S5节拍接口(int plcNo, string stationNameStr)
  9286. {
  9287. Stopwatch stopwatch1 = new Stopwatch();
  9288. Stopwatch stopwatch2 = new Stopwatch();
  9289. string resultStr = string.Empty;
  9290. try
  9291. {
  9292. stopwatch1.Start();
  9293. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9294. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9295. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9296. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9297. if (!actionBool)
  9298. {
  9299. stopwatch2.Start();
  9300. // MES_Flag
  9301. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9302. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9303. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9304. writeToPLC_Flag1.Adress = 2088;
  9305. writeToPLC_Flag1.Value = (short)4;
  9306. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9307. stopwatch2.Stop();
  9308. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9309. return;
  9310. }
  9311. string e1OEEPartNo = string.Empty; // 物料码
  9312. if (string.IsNullOrEmpty(e1OEEProductSN))
  9313. {
  9314. stopwatch2.Start();
  9315. // MES_Flag
  9316. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9317. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9318. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9319. writeToPLC_Flag1.Adress = 2088;
  9320. writeToPLC_Flag1.Value = (short)1;
  9321. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9322. stopwatch2.Stop();
  9323. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9324. return;
  9325. }
  9326. else
  9327. { // 查产品SN
  9328. e1OEEPartNo = "Test"; // ZS
  9329. }
  9330. short e1OEEMES_FLAG = 0;
  9331. // 上传OEE
  9332. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9333. e1OEEMES_FLAG = result.Item1;
  9334. resultStr = result.Item2;
  9335. stopwatch2.Start();
  9336. // MES_Flag
  9337. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9338. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9339. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9340. writeToPLC_Flag.Adress = 2088;
  9341. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9342. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9343. stopwatch2.Stop();
  9344. }
  9345. catch (Exception ex)
  9346. {
  9347. string str = ex.StackTrace;
  9348. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9349. // MES_Flag
  9350. stopwatch2.Start();
  9351. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9352. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9353. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9354. writeToPLC_Flag.Adress = 2088;
  9355. writeToPLC_Flag.Value = (short)4;
  9356. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9357. stopwatch2.Stop();
  9358. }
  9359. stopwatch1.Stop();
  9360. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9361. }
  9362. /// <summary>
  9363. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9364. /// </summary>
  9365. /// <param name="plcNo">PLC编号</param>
  9366. /// <param name="stationNameStr">工站全称</param>
  9367. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9368. {
  9369. Stopwatch stopwatch1 = new Stopwatch();
  9370. Stopwatch stopwatch2 = new Stopwatch();
  9371. try
  9372. {
  9373. stopwatch1.Start();
  9374. // ZS 呼叫AGV
  9375. short e1AGVUpCall = 2;
  9376. stopwatch2.Start();
  9377. // e1AGVUpCall
  9378. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9379. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9380. writeToPLC_Flag.Name = "e1AGVUpCall";
  9381. writeToPLC_Flag.Adress = 2120;
  9382. writeToPLC_Flag.Value = e1AGVUpCall;
  9383. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9384. stopwatch2.Stop();
  9385. }
  9386. catch (Exception ex)
  9387. {
  9388. string str = ex.StackTrace;
  9389. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9390. // e1AGVUpCall
  9391. stopwatch2.Start();
  9392. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9393. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9394. writeToPLC_Flag.Name = "e1AGVUpCall";
  9395. writeToPLC_Flag.Adress = 2120;
  9396. writeToPLC_Flag.Value = (short)4;
  9397. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9398. stopwatch2.Stop();
  9399. }
  9400. stopwatch1.Stop();
  9401. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9402. }
  9403. /// <summary>
  9404. /// [S5] Tray盘下料装备 - AGV上料完成
  9405. /// </summary>
  9406. /// <param name="plcNo">PLC编号</param>
  9407. /// <param name="stationNameStr">工站全称</param>
  9408. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9409. {
  9410. Stopwatch stopwatch1 = new Stopwatch();
  9411. Stopwatch stopwatch2 = new Stopwatch();
  9412. try
  9413. {
  9414. stopwatch1.Start();
  9415. // ZS AGV上料完成,让小车离开
  9416. short e1AGVUpEnd = 2;
  9417. stopwatch2.Start();
  9418. // e1AGVUpEnd
  9419. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9420. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9421. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9422. writeToPLC_Flag.Adress = 2122;
  9423. writeToPLC_Flag.Value = e1AGVUpEnd;
  9424. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9425. stopwatch2.Stop();
  9426. }
  9427. catch (Exception ex)
  9428. {
  9429. string str = ex.StackTrace;
  9430. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9431. // e1AGVUpEnd
  9432. stopwatch2.Start();
  9433. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9434. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9435. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9436. writeToPLC_Flag.Adress = 2122;
  9437. writeToPLC_Flag.Value = (short)4;
  9438. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9439. stopwatch2.Stop();
  9440. }
  9441. stopwatch1.Stop();
  9442. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9443. }
  9444. /// <summary>
  9445. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9446. /// </summary>
  9447. /// <param name="plcNo">PLC编号</param>
  9448. /// <param name="stationNameStr">工站全称</param>
  9449. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9450. {
  9451. Stopwatch stopwatch1 = new Stopwatch();
  9452. Stopwatch stopwatch2 = new Stopwatch();
  9453. try
  9454. {
  9455. stopwatch1.Start();
  9456. // ZS 呼叫AGV
  9457. short e1AGVDownCall = 2;
  9458. stopwatch2.Start();
  9459. // e1AGVDownCall
  9460. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9461. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9462. writeToPLC_Flag.Name = "e1AGVDownCall";
  9463. writeToPLC_Flag.Adress = 2133;
  9464. writeToPLC_Flag.Value = e1AGVDownCall;
  9465. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9466. stopwatch2.Stop();
  9467. }
  9468. catch (Exception ex)
  9469. {
  9470. string str = ex.StackTrace;
  9471. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9472. // e1AGVDownCall
  9473. stopwatch2.Start();
  9474. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9475. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9476. writeToPLC_Flag.Name = "e1AGVDownCall";
  9477. writeToPLC_Flag.Adress = 2133;
  9478. writeToPLC_Flag.Value = (short)4;
  9479. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9480. stopwatch2.Stop();
  9481. }
  9482. stopwatch1.Stop();
  9483. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9484. }
  9485. /// <summary>
  9486. /// [S5] Tray盘下料装备 - AGV下料完成
  9487. /// </summary>
  9488. /// <param name="plcNo">PLC编号</param>
  9489. /// <param name="stationNameStr">工站全称</param>
  9490. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9491. {
  9492. Stopwatch stopwatch1 = new Stopwatch();
  9493. Stopwatch stopwatch2 = new Stopwatch();
  9494. try
  9495. {
  9496. stopwatch1.Start();
  9497. // ZS AGV上料完成,让小车离开
  9498. short e1AGVDownEnd = 2;
  9499. stopwatch2.Start();
  9500. // e1AGVDownEnd
  9501. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9502. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9503. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9504. writeToPLC_Flag.Adress = 2135;
  9505. writeToPLC_Flag.Value = e1AGVDownEnd;
  9506. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9507. stopwatch2.Stop();
  9508. }
  9509. catch (Exception ex)
  9510. {
  9511. string str = ex.StackTrace;
  9512. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9513. // e1AGVDownEnd
  9514. stopwatch2.Start();
  9515. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9516. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9517. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9518. writeToPLC_Flag.Adress = 2135;
  9519. writeToPLC_Flag.Value = (short)4;
  9520. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9521. stopwatch2.Stop();
  9522. }
  9523. stopwatch1.Stop();
  9524. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9525. }
  9526. #endregion [S5] Tray盘下料装备
  9527. #endregion PLC5 张超凡
  9528. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9529. /// <summary>
  9530. /// PLC读取到的数据 -添加数据
  9531. /// </summary>
  9532. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9533. {
  9534. if (sxPlcData.ContainsKey(newKey))
  9535. sxPlcData[newKey] = newValue;
  9536. else
  9537. sxPlcData.Add(newKey, newValue);
  9538. }
  9539. /// <summary>
  9540. /// PLC需要写入的数据 -添加数据
  9541. /// </summary>
  9542. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9543. {
  9544. if (sxPLCWriteData.ContainsKey(newKey))
  9545. sxPLCWriteData[newKey] = newValue;
  9546. else
  9547. sxPLCWriteData.Add(newKey, newValue);
  9548. }
  9549. /// <summary>
  9550. /// PLC回写操作,写后清空flag
  9551. /// </summary>
  9552. /// <param name="modbusClient">modbus对象</param>
  9553. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9554. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9555. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9556. {
  9557. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9558. {
  9559. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9560. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9561. {
  9562. string mesFlagName = pLCWriteDatas[i].Name;
  9563. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9564. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9565. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9566. {
  9567. // 先回写数据
  9568. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9569. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9570. {
  9571. int mesDataAdress = writeToPLCDatas[j].Adress;
  9572. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9573. switch (mesDataType)
  9574. {
  9575. case PLCValueType.Short:
  9576. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9577. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9578. break;
  9579. case PLCValueType.String:
  9580. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9581. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9582. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9583. break;
  9584. }
  9585. }
  9586. // 再回写信号
  9587. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9588. // 存储读取数据的字典
  9589. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9590. // 存储写入数据的字典 - 清空写入值
  9591. pLCWriteDatas[i].Value = (short)0;
  9592. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9593. }
  9594. }
  9595. }
  9596. }
  9597. /// <summary>
  9598. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9599. /// </summary>
  9600. /// <param name="no">3</param>
  9601. /// <param name="stationCode">设备编号</param>
  9602. /// <param name="stationNameStr">设备名称</param>
  9603. /// <param name="plcOrder">车间订单号</param>
  9604. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9605. {
  9606. try
  9607. {
  9608. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9609. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9610. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9611. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9612. int result1 = 0;
  9613. switch (stationCode)
  9614. {
  9615. case 2:
  9616. case 3:
  9617. case 4:
  9618. case 6:
  9619. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9620. break;
  9621. case 102:
  9622. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9623. break;
  9624. case 103:
  9625. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9626. break;
  9627. case 104:
  9628. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9629. break;
  9630. case 106:
  9631. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9632. break;
  9633. default:
  9634. // MES_Flag 为“6未找到正确设备编号”
  9635. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9636. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9637. return;
  9638. }
  9639. short result = result1 == 1 ? (short)1 : (short)2;
  9640. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9641. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9642. }
  9643. catch (Exception ex)
  9644. {
  9645. // MES_Flag 为2上位机报错
  9646. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9647. string str = ex.StackTrace;
  9648. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9649. }
  9650. }
  9651. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9652. #region UI刷新
  9653. /// <summary>
  9654. /// 更新商品信息的UI + 下发产品信息(SN)
  9655. /// </summary>
  9656. private void UpdateProductInfo()
  9657. {
  9658. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9659. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9660. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9661. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9662. }
  9663. /// <summary>
  9664. /// 更新PLC连接状态的UI
  9665. /// </summary>
  9666. /// <param name="no">PLC编号</param>
  9667. /// <param name="status">状态</param>
  9668. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9669. {
  9670. if (this != null && !this.IsDisposed)
  9671. {
  9672. switch (imgNo)
  9673. {
  9674. case 1:
  9675. this.BeginInvoke(new Action(() =>
  9676. {
  9677. picPLC.Image = imageListState.Images[status];
  9678. }));
  9679. break;
  9680. case 2:
  9681. this.BeginInvoke(new Action(() =>
  9682. {
  9683. pictureBox2.Image = imageListState.Images[status];
  9684. }));
  9685. break;
  9686. case 3:
  9687. this.BeginInvoke(new Action(() =>
  9688. {
  9689. pictureBox3.Image = imageListState.Images[status];
  9690. }));
  9691. break;
  9692. case 4:
  9693. this.BeginInvoke(new Action(() =>
  9694. {
  9695. pictureBox4.Image = imageListState.Images[status];
  9696. }));
  9697. break;
  9698. case 5:
  9699. this.BeginInvoke(new Action(() =>
  9700. {
  9701. pictureBox5.Image = imageListState.Images[status];
  9702. }));
  9703. break;
  9704. case 6:
  9705. this.BeginInvoke(new Action(() =>
  9706. {
  9707. pictureBox6.Image = imageListState.Images[status];
  9708. }));
  9709. break;
  9710. case 7:
  9711. this.BeginInvoke(new Action(() =>
  9712. {
  9713. pictureBox7.Image = imageListState.Images[status];
  9714. }));
  9715. break;
  9716. case 8:
  9717. this.BeginInvoke(new Action(() =>
  9718. {
  9719. pictureBox8.Image = imageListState.Images[status];
  9720. }));
  9721. break;
  9722. default:
  9723. break;
  9724. }
  9725. }
  9726. Task.Run(() => // 更新PLC交互页的指示灯
  9727. {
  9728. try
  9729. {
  9730. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9731. {
  9732. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9733. }
  9734. }
  9735. catch { }
  9736. });
  9737. }
  9738. #endregion UI刷新
  9739. #region 日志
  9740. /// <summary>
  9741. /// 添加各工位运行日志(同步至PLC交互页面)
  9742. /// </summary>
  9743. /// <param name="stationNameStr">工站名称</param>
  9744. /// <param name="logType">日志类型</param>
  9745. /// <param name="message">日志内容</param>
  9746. /// <param name="snNumber">产品数字SN</param>
  9747. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9748. {
  9749. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9750. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9751. ))
  9752. {
  9753. AddMessage(logType, message); // 首页展示+日志记录
  9754. }
  9755. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9756. {
  9757. StationName = stationNameStr,
  9758. SnNumber = snNumber,
  9759. Message = message,
  9760. CreateTime = DateTime.Now
  9761. };
  9762. // PLC交互页展示
  9763. Task.Run(() =>
  9764. {
  9765. try
  9766. {
  9767. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9768. {
  9769. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9770. }
  9771. }
  9772. catch { }
  9773. });
  9774. }
  9775. /// <summary>
  9776. /// 添加运行日志
  9777. /// </summary>
  9778. /// <param name="logType">日志类型</param>
  9779. /// <param name="message">日志内容</param>
  9780. public void AddMessage(LogType logType, string message)
  9781. {
  9782. OnMessage(logType, message);
  9783. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9784. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9785. string msgShow = time + "--> " + message + "\r\n";
  9786. this.BeginInvoke(new Action(() =>
  9787. {
  9788. systemLog.Rows.Insert(0, date, time, message);
  9789. if (systemLog.Rows.Count >= 100)
  9790. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9791. }));
  9792. }
  9793. /// <summary>
  9794. /// 添加运行日志-保存
  9795. /// </summary>
  9796. /// <param name="logType">日志类型</param>
  9797. /// <param name="message">日志内容</param>
  9798. private void OnMessage(LogType logType, string msg)
  9799. {
  9800. MessageEvent?.Invoke(logType, msg);
  9801. }
  9802. /// <summary>
  9803. /// 保存PLC写入日志
  9804. /// </summary>
  9805. /// <param name="logType"></param>
  9806. /// <param name="logValue"></param>
  9807. private void WritePLCLog(LogType logType, string logValue)
  9808. {
  9809. switch ((int)logType)
  9810. {
  9811. case 0:
  9812. _PLCLogNet.WriteDebug(logValue);
  9813. break;
  9814. case 1:
  9815. _PLCLogNet.WriteInfo(logValue);
  9816. break;
  9817. case 2:
  9818. _PLCLogNet.WriteWarn(logValue);
  9819. break;
  9820. case 3:
  9821. _PLCLogNet.WriteError(logValue);
  9822. break;
  9823. default:
  9824. _PLCLogNet.WriteFatal(logValue);
  9825. break;
  9826. }
  9827. }
  9828. /// <summary>
  9829. /// IOT Mqtt回调方法- With DataId
  9830. /// </summary>
  9831. /// <param name="id"></param>
  9832. /// <param name="v"></param>
  9833. /// <param name="dataId"></param>
  9834. public void CallbackWithDataId(string id, string msg, string dataId)
  9835. {
  9836. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9837. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9838. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9839. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9840. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9841. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9842. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9843. }
  9844. /// <summary>
  9845. /// AGV Mqtt回调方法- 记录Log并处理数据
  9846. /// </summary>
  9847. /// <param name="obj"></param>
  9848. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9849. {
  9850. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9851. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9852. // 接收到的信息
  9853. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9854. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9855. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9856. {
  9857. }
  9858. }
  9859. #endregion 日志
  9860. /// <summary>
  9861. /// 实例化报警字典
  9862. /// </summary>
  9863. private void InitalDicAlarm()
  9864. {
  9865. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9866. List<Alarm> keyValues1 = new List<Alarm>
  9867. {
  9868. #region 第一组报警(电机)
  9869. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9870. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9871. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9872. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9873. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9874. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9875. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9876. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9877. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9878. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9879. #endregion 第一组报警(电机)
  9880. #region 第二组报警(气缸)
  9881. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9882. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9883. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9884. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9885. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9886. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9887. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9888. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9889. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9890. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9891. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9892. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9893. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9894. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9895. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9896. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9897. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9898. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9899. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9900. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9901. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9902. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9903. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9904. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9905. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9906. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9907. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9908. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9909. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9910. #endregion 第二组报警(气缸)
  9911. #region 第三组报警(其他故障)
  9912. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9913. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9914. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9915. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9916. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9917. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9918. #endregion 第三组报警(其他故障)
  9919. };
  9920. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9921. #endregion 第一个工站(这里使用线体代替工位)
  9922. # region 第二个工站-原来的写法(废弃)
  9923. //keyValues = new Dictionary<int, AlarmData[]>();
  9924. ////1
  9925. //dicAlarmName = new Dictionary<int, Alarm>();
  9926. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  9927. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  9928. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  9929. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  9930. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  9931. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9932. //for (int i = 0; i < dicAlarmName.Count; i++)
  9933. //{
  9934. // alarmDatas[i] = new AlarmData();
  9935. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9936. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9937. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9938. // alarmDatas[i].AlarmType = 1;
  9939. //}
  9940. //keyValues.Add(1, alarmDatas);
  9941. ////2
  9942. //dicAlarmName = new Dictionary<int, Alarm>();
  9943. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  9944. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  9945. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  9946. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  9947. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  9948. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  9949. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  9950. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  9951. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9952. //for (int i = 0; i < dicAlarmName.Count; i++)
  9953. //{
  9954. // alarmDatas[i] = new AlarmData();
  9955. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9956. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9957. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9958. // alarmDatas[i].AlarmType = 2;
  9959. //}
  9960. //keyValues.Add(2, alarmDatas);
  9961. ////3
  9962. //dicAlarmName = new Dictionary<int, Alarm>();
  9963. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  9964. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  9965. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  9966. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  9967. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9968. //for (int i = 0; i < dicAlarmName.Count; i++)
  9969. //{
  9970. // alarmDatas[i] = new AlarmData();
  9971. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  9972. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9973. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9974. // alarmDatas[i].AlarmType = 3;
  9975. //}
  9976. //keyValues.Add(3, alarmDatas);
  9977. //DicAlarms.Add(2, keyValues);
  9978. #endregion 第二个工站-原来的写法(废弃)
  9979. }
  9980. }
  9981. }