Form_Home.cs 598 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
  40. using static MainForm.ClassFile.XiaomiClass.MesHelper;
  41. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  42. /*
  43. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  44. */
  45. namespace MainForm
  46. {
  47. /// <summary>
  48. /// 记录日志的委托
  49. /// </summary>
  50. /// <param name="logType">日志类型</param>
  51. /// <param name="message">日志信息</param>
  52. public delegate void HomeMessageHandler(LogType logType, string message);
  53. /// <summary>
  54. /// 主页窗体
  55. /// </summary>
  56. public partial class Form_Home : Form
  57. {
  58. #region 常量
  59. //文本常量
  60. private const string Head = "开始采集";
  61. private const string Tail = "采集完成";
  62. private const string Body = "工位出站数据";
  63. private const string BodyCheck = "工位点检数据";
  64. private const string BodyRun = "整线运行数据";
  65. private const string BodyAlarm = "整线报警数据";
  66. #endregion 常量
  67. #region 变量
  68. /// <summary>
  69. /// 委托-记录日志的方法
  70. /// </summary>
  71. public event HomeMessageHandler MessageEvent;
  72. /// <summary>
  73. /// 日志接口
  74. /// </summary>
  75. ILogNet _PLCLogNet;
  76. /// <summary>
  77. /// 用于记录IOT MQTT日志
  78. /// </summary>
  79. ILogNet _IOTMqttLogNet;
  80. /// <summary>
  81. /// 用于记录AGV MQTT日志
  82. /// </summary>
  83. ILogNet _AGVMqttLogNet;
  84. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  85. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  86. // 间隔时间
  87. private int IntervalReadPLC = 300; //ms 读PLC
  88. private int IntervalMonitorMES = 1000; //ms MES心跳
  89. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  90. // 软件状态
  91. private bool IsRun = true;
  92. #region PLC 与 TCP对象
  93. // 定义一个字典,存plc对象(通讯)
  94. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  95. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  96. // 定义TCPClient对象列表
  97. Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  98. // 定义MQTTHelper对象
  99. MQTTHelper _MQTTHelper = new MQTTHelper();
  100. #endregion PLC 与 TCP对象
  101. /// <summary>
  102. /// 上次的设备运行信息
  103. /// </summary>
  104. private string lineWorkingData1_OldStr = string.Empty;
  105. /// <summary>
  106. /// 设备报警字典-当前结果
  107. /// Dictionary<工位代码,List<报警信息>>
  108. /// </summary>
  109. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  110. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  111. #endregion 变量
  112. #region 窗体基础事件
  113. /// <summary>
  114. /// 初始化
  115. /// </summary>
  116. public Form_Home()
  117. {
  118. InitializeComponent();
  119. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  120. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  121. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  122. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  123. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  124. }
  125. /// <summary>
  126. /// 窗体加载事件
  127. /// </summary>
  128. private void Form_Home_Load(object sender, EventArgs e)
  129. {
  130. try
  131. {
  132. AddMessage(LogType.Info, "开始初始化程序");
  133. InitalDicAlarm(); // 实例化报警字典
  134. //组建plc对象字典
  135. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  136. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  137. if (GlobalContext.IsUsePLC1)
  138. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  139. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  140. if (GlobalContext.IsUsePLC2)
  141. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  142. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  143. if (GlobalContext.IsUsePLC3)
  144. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  145. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  146. if (GlobalContext.IsUsePLC4)
  147. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  148. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  149. if (GlobalContext.IsUsePLC5)
  150. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  151. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  152. if (GlobalContext.IsUsePLC6)
  153. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  154. if (GlobalContext.IsUsePLC7)
  155. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  156. if (GlobalContext.IsUsePLC8)
  157. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  158. if (GlobalContext.IsUsePLC9)
  159. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  160. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  161. {
  162. if (plcEIP != null)
  163. {
  164. try
  165. {
  166. (int, string) result = plcEIP.Connect();
  167. }
  168. catch (Exception ex)
  169. {
  170. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  171. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  172. }
  173. }
  174. }
  175. /*
  176. //plc1Alarm.Connect();
  177. foreach (ModbusClientHelper modbusClient in Funs.Values)
  178. {
  179. if (modbusClient != null)
  180. {
  181. try
  182. {
  183. modbusClient.Connect();
  184. }
  185. catch (Exception ex)
  186. {
  187. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  188. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  189. }
  190. }
  191. }
  192. */
  193. // 采集任务
  194. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  195. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  196. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  197. if (GlobalContext.IsUsePLC1)
  198. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  199. if (GlobalContext.IsUsePLC2)
  200. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  201. if (GlobalContext.IsUsePLC3)
  202. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  203. if (GlobalContext.IsUsePLC4)
  204. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  205. if (GlobalContext.IsUsePLC5)
  206. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  207. if (GlobalContext.IsUsePLC6)
  208. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  209. if (GlobalContext.IsUsePLC7)
  210. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  211. if (GlobalContext.IsUsePLC8)
  212. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  213. if (GlobalContext.IsUsePLC9)
  214. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  215. #region 初始化
  216. try
  217. {
  218. // 开启边线MES(绑定/查询数据)
  219. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  220. //if (mesRoute == 0)
  221. //{
  222. // //picMESStatus.Image = imageListState.Images[1];
  223. // //GlobalContext.MESIsConnect = true;
  224. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  225. //}
  226. //else
  227. //{
  228. // //picMESStatus.Image = imageListState.Images[0];
  229. // //GlobalContext.MESIsConnect = false;
  230. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  231. //}
  232. // 开启MES(Http)
  233. if (GlobalContext.IsUseMES)
  234. {
  235. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  236. if (mesret)
  237. {
  238. picMESStatus.Image = imageListState.Images[1];
  239. GlobalContext.MESIsConnect = true;
  240. AddMessage(LogType.Info, "小米MES初始连接成功!");
  241. }
  242. else
  243. {
  244. picMESStatus.Image = imageListState.Images[0];
  245. GlobalContext.MESIsConnect = false;
  246. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  247. }
  248. }
  249. // 开启IOT(MQTT)
  250. if (GlobalContext.IsUseIot)
  251. {
  252. string addr = GlobalContext.MQTTServerHost;
  253. int port = GlobalContext.MQTTServerPort;
  254. //生产环境需要修改
  255. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  256. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  257. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  258. {
  259. picIot.Image = imageListState.Images[1];
  260. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  261. // 设置回调函数
  262. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  263. // 配置参数
  264. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  265. // fds
  266. param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
  267. param.parameter.fds.appId = "Auto-Soft";
  268. param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
  269. // mes
  270. param.parameter.mes.address = GlobalContext.ServerIp;
  271. param.parameter.mes.appId = GlobalContext.MESAppId;
  272. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  273. // mqtt
  274. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  275. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  276. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  277. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  278. // 设备配置
  279. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  280. if (GlobalContext.IsUsePLC1)
  281. {
  282. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  283. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  284. }
  285. if (GlobalContext.IsUsePLC2)
  286. {
  287. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  288. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  289. }
  290. if (GlobalContext.IsUsePLC3)
  291. {
  292. param.parameter.equipment.deviceCode = GlobalContext.S3_device_code; // 装备编码
  293. param.parameter.equipment.stationCode = GlobalContext.S3_station; // ⼯位Id
  294. }
  295. if (GlobalContext.IsUsePLC4)
  296. {
  297. param.parameter.equipment.deviceCode = GlobalContext.S4_1_device_code; // 装备编码
  298. param.parameter.equipment.stationCode = GlobalContext.S4_1_station; // ⼯位Id
  299. }
  300. if (GlobalContext.IsUsePLC5)
  301. {
  302. param.parameter.equipment.deviceCode = GlobalContext.S5_device_code; // 装备编码
  303. param.parameter.equipment.stationCode = GlobalContext.S5_station; // ⼯位Id
  304. }
  305. if (GlobalContext.IsUsePLC6)
  306. {
  307. param.parameter.equipment.deviceCode = GlobalContext.S6_device_code; // 装备编码
  308. param.parameter.equipment.stationCode = GlobalContext.S6_station; // ⼯位Id
  309. }
  310. if (GlobalContext.IsUsePLC7)
  311. {
  312. param.parameter.equipment.deviceCode = GlobalContext.S7_device_code; // 装备编码
  313. param.parameter.equipment.stationCode = GlobalContext.S7_station; // ⼯位Id
  314. }
  315. if (GlobalContext.IsUsePLC8)
  316. {
  317. param.parameter.equipment.deviceCode = GlobalContext.S8_device_code; // 装备编码
  318. param.parameter.equipment.stationCode = GlobalContext.S8_station; // ⼯位Id
  319. }
  320. if (GlobalContext.IsUsePLC9)
  321. {
  322. param.parameter.equipment.deviceCode = GlobalContext.S9_device_code; // 装备编码
  323. param.parameter.equipment.stationCode = GlobalContext.S9_station; // ⼯位Id
  324. }
  325. param.parameter.equipment.project = GlobalContext.Project_Code;
  326. param.parameter.equipment.productMode = "debug";
  327. //
  328. param.parameter.other.logLevel = 0;
  329. param.parameter.other.LogPath = "D:\\Test";
  330. XiaomiMqttClient_Extend.ParameterConfig(param);
  331. }
  332. else
  333. {
  334. picIot.Image = imageListState.Images[0];
  335. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  336. }
  337. }
  338. // 开启AGV(Http与MQTT)
  339. if (GlobalContext.IsUseAGV)
  340. {
  341. // AGV HTTP
  342. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  343. if (mesret1)
  344. {
  345. picAgvHttp.Image = imageListState.Images[1];
  346. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  347. }
  348. else
  349. {
  350. picAgvHttp.Image = imageListState.Images[0];
  351. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  352. }
  353. string agvMqttIp = GlobalContext.MQTTServerHost;
  354. int agvMqttPort = GlobalContext.MQTTServerPort;
  355. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  356. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  357. // AGV MQTT
  358. if (result_MQTT.ResultCode == 1)
  359. {
  360. picAgvMqtt.Image = imageListState.Images[1];
  361. GlobalContext.AGVMQTTIsConnect = true;
  362. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  363. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  364. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  365. }
  366. else
  367. {
  368. picAgvMqtt.Image = imageListState.Images[0];
  369. GlobalContext.AGVMQTTIsConnect = false;
  370. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  371. }
  372. }
  373. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  374. Task.Run(MonitorMESConnect);
  375. // 查询PLC连接状态
  376. foreach (int plcNo in FunsEip.Keys)
  377. {
  378. bool connected = FunsEip[plcNo].IsConnected;
  379. if (connected)
  380. {
  381. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  382. AddMessage(LogType.Info, msg);
  383. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  384. }
  385. else
  386. {
  387. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  388. AddMessage(LogType.Info, msg);
  389. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  390. }
  391. }
  392. // PLC4时 初始化扫码器TCP
  393. //if (GlobalContext.IsUsePLC4)
  394. // HpTCPClientInit();
  395. // 开启PLC的业务处理线程-监听PLC点位+状态
  396. foreach (Task task in TaskReadProcess)
  397. {
  398. if (task != null)
  399. task.Start();
  400. }
  401. //// 开启“获取线体报警数据”的线程
  402. //TaskReadAlarm.Start();
  403. ////下传MES信息给1工位(先判断下plc对象数量)
  404. //if (Funs.Count > 1)
  405. // DownLoadProductInfo(1);
  406. AddMessage(LogType.Info, "程序初始化完成");
  407. }
  408. catch (Exception ex)
  409. {
  410. string str = ex.StackTrace;
  411. this.BeginInvoke(new Action(() =>
  412. {
  413. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  414. }));
  415. }
  416. #endregion
  417. }
  418. catch (Exception ex)
  419. {
  420. string str = ex.StackTrace;
  421. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  422. if (ex.Message != null && ex.Message.Contains("timed out"))
  423. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  424. else
  425. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  426. }
  427. }
  428. /// <summary>
  429. /// 窗体关闭事件
  430. /// </summary>
  431. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  432. {
  433. Closed2();
  434. }
  435. public void Closed2()
  436. {
  437. try
  438. {
  439. IsRun = false;
  440. Thread.Sleep(IntervalReadPLC);
  441. // 断开TCP
  442. int count = _HPSocket_TcpClients.Count();
  443. for (int i = 0; i < count; i++)
  444. {
  445. try
  446. {
  447. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  448. {
  449. _HPSocket_TcpClients[i].Stop();
  450. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  451. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  452. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  453. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  454. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  455. }
  456. }
  457. catch { }
  458. }
  459. // 关闭Iot
  460. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  461. // 关闭AGV Mqtt
  462. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  463. }
  464. catch { }
  465. }
  466. #endregion 窗体基础事件
  467. #region 监控MES状态
  468. /// <summary>
  469. /// 监控MES连接状态
  470. /// </summary>
  471. private void MonitorMESConnect()
  472. {
  473. while (IsRun) // 运行被控线程
  474. {
  475. try
  476. {
  477. // 开启MES(Http)
  478. if (GlobalContext.IsUseMES)
  479. {
  480. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  481. if (mesret)
  482. {
  483. picMESStatus.Image = imageListState.Images[1];
  484. GlobalContext.MESIsConnect = true;
  485. }
  486. else
  487. {
  488. picMESStatus.Image = imageListState.Images[0];
  489. GlobalContext.MESIsConnect = false;
  490. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  491. }
  492. }
  493. // 开启IOT(MQTT)
  494. if (GlobalContext.IsUseIot)
  495. {
  496. bool iIot = XiaomiMqttClient.IsOpen;
  497. if (iIot)
  498. picIot.Image = imageListState.Images[1];
  499. else
  500. {
  501. picIot.Image = imageListState.Images[0];
  502. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  503. }
  504. }
  505. // 开启AGV(Http与MQTT)
  506. if (GlobalContext.IsUseAGV)
  507. {
  508. // AGV Http
  509. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  510. if (mesret1)
  511. picAgvHttp.Image = imageListState.Images[1];
  512. else
  513. {
  514. picAgvHttp.Image = imageListState.Images[0];
  515. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  516. }
  517. // AGV MQTT
  518. if (GlobalContext.AGVMQTTIsConnect)
  519. picAgvMqtt.Image = imageListState.Images[1];
  520. else
  521. {
  522. picAgvMqtt.Image = imageListState.Images[0];
  523. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  524. }
  525. }
  526. }
  527. catch (Exception ex)
  528. {
  529. string str = ex.StackTrace;
  530. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  531. }
  532. Thread.Sleep(IntervalMonitorMES);
  533. }
  534. }
  535. #endregion 监控MES连接状态
  536. #region 采集设备状态、运行数据、报警数据
  537. /// <summary>
  538. /// 请求设备状态 5000
  539. /// </summary>
  540. /// <param name="no">1</param>
  541. /// <param name="stationNameStr"></param>
  542. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  543. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  544. {
  545. try
  546. {
  547. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  548. {
  549. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  550. return result;
  551. }
  552. else
  553. {
  554. return 0;
  555. }
  556. }
  557. catch (Exception ex)
  558. {
  559. string str = ex.StackTrace;
  560. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  561. return 0;
  562. }
  563. }
  564. /// <summary>
  565. /// 检查是否可采集点检数据 - 不取新值
  566. /// 5000不为1时可点检
  567. /// </summary>
  568. /// <returns></returns>
  569. public bool CheckCanSpotcheck1(int deviceState)
  570. {
  571. //return true;
  572. //D5000 = 1,代表设备控制状态处于运行状态
  573. //D5000 = 2, 代表设备控制状态处于故障状态
  574. //D5000 = 3,代表设备控制状态处于缺料状态
  575. //D5000 = 4, 代表设备控制状态处于待机状态
  576. //D5000 = 5,代表设备控制状态处于维修状态
  577. return deviceState != 1;
  578. }
  579. /// <summary>
  580. /// 检查是否可采集产品数据 - 不取新值
  581. /// </summary>
  582. /// <returns></returns>
  583. public bool CheckCanCollData(int deviceState)
  584. {
  585. return deviceState == 0; // 点检时该值不为0
  586. }
  587. /// <summary>
  588. /// 获取设备报警数据与获取设备运行信息
  589. /// </summary>
  590. private async void ReadAlarmAllPLC()
  591. {
  592. // [S1] Tray盘上料装备(板测)
  593. // [S2] FCT(板测)
  594. // [S3] 值板机
  595. // [S4] 取放桁架
  596. // [S5] Tray盘下料装备
  597. /// 上位机心跳
  598. /// 获取设备报警数据与状态信息
  599. string stationNameStr = "获取设备报警数据与状态信息";
  600. while (IsRun)
  601. {
  602. try
  603. {
  604. if (!GlobalContext._IsCon_plc1Alarm)
  605. {
  606. UpdatePLCMonitor(1, -2, 0);
  607. continue;
  608. }
  609. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  610. {
  611. DateTime dtNow = DateTime.Now;
  612. #region 获取设备运行信息
  613. try
  614. {
  615. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  616. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  617. lineWorkingData1.LineName = GlobalContext.LineCode;
  618. //
  619. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  620. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  621. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  622. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  623. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  624. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  625. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  626. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  627. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  628. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  629. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  630. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  631. lineWorkingData1.CreateTime = DateTime.Now;
  632. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  633. // UI展示-展示到设备状态页
  634. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  635. {
  636. // 查询数据库最新一条数据,确定是不是更新
  637. string qSql = @"SELECT top(1) [GUID]
  638. ,[LineName]
  639. ,[BootTimeLong]
  640. ,[NormalTimeLong]
  641. ,[StandbyTimeLong]
  642. ,[FaultTimeLong]
  643. ,[MaterialShortageTimeLong]
  644. ,[MaintenanceTimeLong]
  645. ,[FaultNumber]
  646. ,[OutputNumber]
  647. ,[QualifiedNumber]
  648. ,[QualifiedRate]
  649. ,[DesignRhythm]
  650. ,[RealityRhythm]
  651. ,[CreateTime]
  652. FROM [LineWorkingData]
  653. where [CreateTime] > '{0}'
  654. and [LineName]='{1}'
  655. order by [CreateTime] desc
  656. ";
  657. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  658. var ds = SQLHelper_New.Query(qSql, null);
  659. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  660. {
  661. var dataDBlast = new LineWorkingData_ThisTime();
  662. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  663. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  664. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  665. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  666. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  667. {
  668. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  669. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  670. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  671. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  672. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  673. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  674. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  675. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  676. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  677. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  678. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  679. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  680. string usql = dataDBlast.ToStringUpdate();
  681. SQLHelper_New.ExecuteSQL(usql, null);
  682. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  683. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  684. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  685. }
  686. }
  687. else
  688. {
  689. // 插入
  690. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  691. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  692. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  693. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  694. }
  695. }
  696. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  697. {
  698. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  699. //// 本次开机设备运行情况
  700. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  701. //Task.Run(() =>
  702. //{
  703. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  704. // {
  705. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  706. // }
  707. //});
  708. // 本日设备运行情况
  709. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  710. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  711. {
  712. // 更新
  713. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  714. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  715. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  716. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  717. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  718. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  719. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  720. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  721. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  722. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  723. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  724. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  725. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  726. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  727. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  728. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  729. }
  730. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  731. {
  732. // 插入
  733. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  734. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  735. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  736. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  737. }
  738. await Task.Run(() =>
  739. {
  740. try
  741. {
  742. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  743. {
  744. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  745. }
  746. }
  747. catch { }
  748. });
  749. }
  750. }
  751. catch (Exception ex)
  752. {
  753. string str = ex.StackTrace;
  754. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  755. }
  756. #endregion 获取设备运行信息
  757. #region 报警数据
  758. try
  759. {
  760. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  761. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  762. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  763. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  764. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  765. {
  766. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  767. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  768. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  769. {
  770. isNeedUpdUI = true; // 需要更新历史报警UI信息
  771. // 记录
  772. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  773. switch (dicAlarms_Cur_PLC1[i].是否报警)
  774. {
  775. case true: // 报警
  776. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  777. {
  778. GUID = Guid.NewGuid().ToString(),
  779. LineName = GlobalContext.LineCode, // 线体
  780. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  781. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  782. StartTime = dtNow // 开始时间
  783. };
  784. // 传输到页面
  785. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  786. {
  787. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  788. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  789. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  790. 开始时间 = dtNow
  791. });
  792. // 新增到数据库
  793. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  794. SaveAlarmDataByDB(stationNameStr, data1, false);
  795. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  796. break;
  797. case false: // 消除报警
  798. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  799. {
  800. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  801. {
  802. GUID = Guid.NewGuid().ToString(),
  803. LineName = GlobalContext.LineCode, // 线体
  804. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  805. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  806. StartTime = dtNow, // 开始时间
  807. EndTime = dtNow, // 开始时间
  808. PersistTime = 1, // 耗时1s
  809. };
  810. // 新增
  811. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  812. SaveAlarmDataByDB(stationNameStr, data2, false);
  813. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  814. }
  815. else
  816. {
  817. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  818. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  819. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  820. // 修改
  821. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  822. SaveAlarmDataByDB(stationNameStr, data3, true);
  823. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  824. }
  825. break;
  826. default:
  827. break;
  828. }
  829. }
  830. }
  831. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  832. // 有新报警则更新
  833. if (isNeedUpdUI)
  834. {
  835. // UI展示 - 展示到设备状态页
  836. await Task.Run(() =>
  837. {
  838. try
  839. {
  840. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  841. {
  842. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  843. if (Form_Main.formDevAlarm.Visible)
  844. {
  845. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  846. }
  847. }
  848. }
  849. catch { }
  850. });
  851. }
  852. }
  853. catch (Exception ex)
  854. {
  855. string str = ex.StackTrace;
  856. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  857. }
  858. #endregion 报警数据
  859. UpdatePLCMonitor(1, -2, 1);
  860. }
  861. else
  862. {
  863. UpdatePLCMonitor(1, -2, 0);
  864. }
  865. }
  866. catch (Exception ex)
  867. {
  868. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  869. }
  870. Thread.Sleep(IntervalAlarm);
  871. }
  872. }
  873. #endregion 轮询PLC
  874. #region 下发订单信息
  875. ///// <summary>
  876. ///// 壳体上料(下发工单)的交互逻辑
  877. ///// </summary>
  878. ///// <param name="no"></param>
  879. ///// <exception cref="NotImplementedException"></exception>
  880. //private void ReadStation_DownOrderInfo(int plcNo)
  881. //{
  882. // // [S1] Tray盘上料装备(板测)
  883. // // [S2] FCT(板测)
  884. // // [S3] 值板机
  885. // // [S4] 取放桁架
  886. // // [S5] Tray盘下料装备
  887. // /// 上位机心跳
  888. // /// 获取设备报警数据与状态信息
  889. // string stationNameStr = "[S0]壳体上料";
  890. // while (IsRun)
  891. // {
  892. // try
  893. // {
  894. // if (!GlobalContext._IsCon_Funs1)
  895. // {
  896. // UpdatePLCMonitor(plcNo, 0);
  897. // continue;
  898. // }
  899. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  900. // {
  901. // #region 壳体上料(下发工单)
  902. // try
  903. // {
  904. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  905. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  906. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  907. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  908. // // 重置数据和信号
  909. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  910. // {
  911. // // 清空写给PLC的数据
  912. // int[] i497 = new int[1] { 0 };
  913. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  914. // // MES_Flag重置为0
  915. // int[] i500 = new int[1] { 0 };
  916. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  917. // }
  918. // }
  919. // catch (Exception ex)
  920. // {
  921. // string str = ex.StackTrace;
  922. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  923. // }
  924. // #endregion 壳体上料(下发工单)
  925. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  926. // }
  927. // else
  928. // {
  929. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  930. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  931. //
  932. // Funs[plcNo].Connect();
  933. // }
  934. // }
  935. // catch (Exception ex)
  936. // {
  937. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  938. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  939. //
  940. // Funs[plcNo].ReConnect();
  941. // }
  942. // Thread.Sleep(IntervalReadPLC);
  943. // }
  944. //}
  945. ///// <summary>
  946. ///// 下发订单信息到PLC
  947. ///// </summary>
  948. ///// <param name="no">PLC编号</param>
  949. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  950. //{
  951. // try
  952. // {
  953. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  954. // {
  955. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  956. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  957. // }
  958. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  959. // }
  960. // catch (Exception ex)
  961. // {
  962. // string str = ex.StackTrace;
  963. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  964. // }
  965. //}
  966. /// <summary>
  967. /// 下发清料信号
  968. /// </summary>
  969. /// <param name="no">PLC编号</param>
  970. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  971. {
  972. try
  973. {
  974. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  975. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  976. return true;
  977. }
  978. catch (Exception ex)
  979. {
  980. string str = ex.StackTrace;
  981. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  982. return false;
  983. }
  984. }
  985. #endregion 下发订单信息
  986. #region Xiaomi 贲流
  987. #region 公共方法
  988. private static bool ProgressState = false;
  989. private static readonly object lockObj = new object(); // 锁对象
  990. private static bool isCollectingFlagLeft;
  991. private static bool isCollectingFlagRight;
  992. private bool OpenDailogFalg = true;//是否开启扫码弹窗标识
  993. /// <summary>
  994. /// float[]转为string
  995. /// </summary>
  996. public string FloatArrayToString(float[] nScrewResults)
  997. {
  998. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  999. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1000. }
  1001. /// <summary>
  1002. /// short[]转为string
  1003. /// </summary>
  1004. public string ShortArrayToString(short[] nScrewResults)
  1005. {
  1006. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1007. return string.Join(",", nScrewResults);
  1008. }
  1009. /// <summary>
  1010. /// 写入PLC重复三次
  1011. /// </summary>
  1012. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  1013. {
  1014. int i = 0;
  1015. int nRet = 0;
  1016. string strRet = "";
  1017. try
  1018. {
  1019. while (i < 3) // 最多上传三次
  1020. {
  1021. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1022. if (nRet == 0) //成功
  1023. {
  1024. break;
  1025. }
  1026. else
  1027. {
  1028. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1029. i++;
  1030. }
  1031. }
  1032. return (nRet, strRet);
  1033. }
  1034. catch (Exception ex)
  1035. {
  1036. return (1, ex.Message);
  1037. }
  1038. }
  1039. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  1040. {
  1041. try
  1042. {
  1043. // 获取当前日期
  1044. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1045. // 构建保存路径
  1046. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1047. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  1048. // 确保目录存在
  1049. Directory.CreateDirectory(savePath);
  1050. // 文件名
  1051. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1052. string filePath = Path.Combine(savePath, fileName);
  1053. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1054. int count = Math.Min(14, fScrewTimes.Length);
  1055. using (StreamWriter sw = new StreamWriter(filePath))
  1056. {
  1057. for (int i = 0; i < count; i++)
  1058. {
  1059. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1060. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1061. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1062. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1063. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1064. }
  1065. }
  1066. return (0, "");
  1067. }
  1068. catch (Exception ex)
  1069. {
  1070. return (1, ex.Message);
  1071. }
  1072. }
  1073. public Dictionary<string, string> GetLastLineCompensation(string path,string direction,string sn)
  1074. {
  1075. // 创建字典存储补偿点及其对应的值
  1076. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1077. try
  1078. {
  1079. //string path = GlobalContext.MESLaserRPath;
  1080. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1081. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1082. string filename = $"Laser-{currentDate}-W0.txt";
  1083. // 拼接完整路径
  1084. string fullPath = Path.Combine(path, filename);
  1085. string lastNonEmptyLine = "";
  1086. // 判断文件是否存在
  1087. if (File.Exists(fullPath))
  1088. {
  1089. //读取文件内容
  1090. string[] lines = File.ReadAllLines(fullPath);
  1091. // 获取最后一行数据(忽略标题行)
  1092. if (lines.Length > 1)
  1093. {
  1094. string lastLine = "";
  1095. for (int i = lines.Length - 1; i > 0; i--)
  1096. {
  1097. if (!string.IsNullOrEmpty(lines[i]))
  1098. {
  1099. lastLine = lines[i];
  1100. break;
  1101. }
  1102. }
  1103. // 将最后一行按逗号分隔
  1104. string[] values = lastLine.Split(',');
  1105. values[1] = sn;
  1106. string key = "三点激光_"+ direction; // 构造键名
  1107. string value = string.Join(",", values); // 获取值并去除多余空格
  1108. compensationDict[key] = value;
  1109. //// 提取“1点补偿”到“6点补偿”的值
  1110. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1111. //{
  1112. // string key = $"{i - 1}点补偿"; // 构造键名
  1113. // string value = values[i].Trim(); // 获取值并去除多余空格
  1114. // compensationDict[key] = value;
  1115. //}
  1116. }
  1117. }
  1118. else
  1119. {
  1120. Console.WriteLine($"文件不存在: {fullPath}");
  1121. }
  1122. }
  1123. catch (Exception ex)
  1124. {
  1125. // 捕获异常并输出错误信息
  1126. Console.WriteLine($"发生错误: {ex.Message}");
  1127. }
  1128. return compensationDict;
  1129. }
  1130. public int PCBStationOutData(BarcodeSet_t Barcode,IoT_DataSet_t iotData)
  1131. {
  1132. int res = 0;
  1133. string jsonstr1 = "";
  1134. try
  1135. {
  1136. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1137. outRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备id(可配置)
  1138. outRequest_Body.stationId = GlobalContext.S5_station; // ⼯位ID(可配置)
  1139. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1140. outRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1141. outRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1142. int a1Result = (int)iotData.testStatus;
  1143. //bool pass = a1Result == 1;
  1144. //outRequest_Body.state = pass ? "PASS" : "FAIL"; ; // 出站条件 PASS或FAIL
  1145. outRequest_Body.state = "PASS";
  1146. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1147. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1148. XmStationOut_KeyMaterial keyMaterial = new XmStationOut_KeyMaterial();
  1149. keyMaterial.bindSort = 1;
  1150. keyMaterial.materialSn = Barcode.strProductBarcode;
  1151. outRequest_Body.unitData.keyMaterial.Add(keyMaterial); // 产品码
  1152. jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1153. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1154. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1155. if (response != null && response.header.code == "200")
  1156. {
  1157. res = 1;
  1158. AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---成功!请求信息:" + jsonstr1 + ",返回信息:" + JsonConvert.SerializeObject(response.body));
  1159. }
  1160. else
  1161. {
  1162. res = 0;
  1163. AddMessage(LogType.Error, "上传PCB出站数据到MES服务器---失败!错误信息:"+ response.header.desc + ",请求信息:" + jsonstr1 + ",返回信息:" + JsonConvert.SerializeObject(response.body));
  1164. }
  1165. }
  1166. catch (Exception e)
  1167. {
  1168. res = 0;
  1169. AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---失败!请求信息:" + jsonstr1 + ",返回信息:" + e.Message);
  1170. }
  1171. return res;
  1172. }
  1173. public int PCBStationInData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1174. {
  1175. int res = 0;
  1176. string json_Body = "";
  1177. try
  1178. {
  1179. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1180. inRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  1181. inRequest_Body.stationId = GlobalContext.S5_station; // ⼯位ID(可配置)
  1182. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1183. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1184. inRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1185. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1186. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1187. json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1188. var response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1189. string resultJson = JsonConvert.SerializeObject(response);
  1190. if (response != null && response.header.code == "200")
  1191. {
  1192. res = 1;
  1193. AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---成功!请求信息:" + json_Body + ",返回信息:" + JsonConvert.SerializeObject(response.body));
  1194. }
  1195. else
  1196. {
  1197. res = 0;
  1198. AddMessage(LogType.Error, "上传PCB进站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + json_Body + ",返回信息:" + JsonConvert.SerializeObject(response.body));
  1199. }
  1200. }
  1201. catch (Exception e)
  1202. {
  1203. res = 0;
  1204. AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---失败!请求信息:" + json_Body + ",返回信息:" + e.Message);
  1205. }
  1206. return res;
  1207. }
  1208. /// <summary>
  1209. /// 调用进站接口并保存进站数据
  1210. /// </summary>
  1211. /// <param name="stationNameStr">工站信息</param>
  1212. /// <param name="workorder_code">工单号</param>
  1213. /// <param name="mtltmrk">型号(物料号)</param>
  1214. /// <param name="sn">产品SN</param>
  1215. /// <param name="items">进站数据</param>
  1216. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1217. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1218. {
  1219. int result = 0;
  1220. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1221. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1222. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1223. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1224. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1225. inRequest_Body.unitSn = sn; // 产品SN
  1226. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1227. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1228. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1229. StationIn stationIn = new StationIn()
  1230. {
  1231. Workorder_code = workorder_code, // 车间订单号
  1232. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1233. Sn = sn, // SN
  1234. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1235. Parameter_values = items, // 进站数据
  1236. Write_user = inRequest_Body.userId, // 员工Id
  1237. Test_time = inRequest_Body.clientTime // 进站时间
  1238. };
  1239. // 本地数据
  1240. string sql = stationIn.ToStringInsert(0);
  1241. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1242. result = ret == "成功" ? 1 : 6;
  1243. //await Task.Delay(200);
  1244. // 上传MES
  1245. if (GlobalContext.IsSendStationIn)
  1246. {
  1247. try
  1248. {
  1249. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1250. string resultJson = "";
  1251. string mesRet = string.Empty;
  1252. int i = 0;
  1253. while (i < 2) // 1009会多次尝试上传
  1254. {
  1255. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1256. resultJson = JsonConvert.SerializeObject(response);
  1257. if (response != null && response.header.code == "200")
  1258. break;
  1259. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1260. i++;
  1261. i++;
  1262. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1263. // 记录失败原因
  1264. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!请求参数:{json_Body},接口报错信息:" + mesRet);
  1265. }
  1266. if (response?.header?.code == "200")
  1267. {
  1268. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1269. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1270. result = ret_Upd == "成功" ? 1 : 6;
  1271. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,请求参数:{json_Body},返回参数:{resultJson}");
  1272. }
  1273. else
  1274. {
  1275. result = 5;
  1276. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!请求参数:{json_Body},接口报错信息:" + mesRet);
  1277. }
  1278. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1279. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1280. }
  1281. catch (Exception ex)
  1282. {
  1283. result = 6;
  1284. string str = ex.StackTrace;
  1285. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1286. }
  1287. }
  1288. return result;
  1289. }
  1290. /// <summary>
  1291. /// 选择如何记录出站数据
  1292. /// </summary>
  1293. /// <param name="items">出站数据</param>
  1294. /// <param name="equipmentCode">设备编号</param>
  1295. /// <param name="processItem">测试项目</param>
  1296. /// <param name="workorder_code">车间订单号</param>
  1297. /// <param name="batch_num">批次号</param>
  1298. /// <param name="mtltmrk">型号</param>
  1299. /// <param name="proDate">日期</param>
  1300. /// <param name="supplierCode">供应商代码</param>
  1301. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1302. /// <returns>上传成功时返回1;失败返回0</returns>
  1303. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1304. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1305. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode,string jsonParm, string direction="")
  1306. {
  1307. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1308. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm, direction);
  1309. }
  1310. /// <summary>
  1311. /// 添加出站数据(提交到MES+本地保存到数据库)
  1312. /// </summary>
  1313. /// <param name="items">出站数据</param>
  1314. /// <param name="equipmentCode">设备编号</param>
  1315. /// <param name="processItem">测试项目</param>
  1316. /// <param name="workorder_code">车间订单号</param>
  1317. /// <param name="batch_num">批次号</param>
  1318. /// <param name="mtltmrk">型号</param>
  1319. /// <param name="proDate">日期</param>
  1320. /// <param name="supplierCode">供应商代码</param>
  1321. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1322. /// <returns>上传成功时返回1;失败返回0</returns>
  1323. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1324. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1325. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode,string jsonParm,string direction="")
  1326. {
  1327. int upload = 0;
  1328. int result = 0;
  1329. ProcessData processData = new ProcessData()
  1330. {
  1331. Equipment_code = equipmentCode,
  1332. Workorder_code = workorder_code,
  1333. Batch_number = batch_num,
  1334. Sn = sn, // SN
  1335. Testitem = processItem,
  1336. Parameter_values = items,
  1337. Write_user = GlobalContext.CurrentUser,
  1338. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1339. };
  1340. // 本地数据
  1341. string sql = processData.ToStringInsert(upload);
  1342. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1343. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1344. // 上传MES
  1345. if (GlobalContext.IsSendProcessData)
  1346. {
  1347. try
  1348. {
  1349. string id = processData.ID.Copy();
  1350. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1351. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1352. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1353. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1354. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1355. outRequest_Body.unitSn = sn; // 产品SN
  1356. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1357. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1358. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1359. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1360. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1361. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1362. if (!string.IsNullOrEmpty(partBarcode))
  1363. {
  1364. outRequest_Body.unitData.keyMaterial.Add(
  1365. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1366. {
  1367. bindSort = 1,
  1368. materialSn = partBarcode
  1369. }); // 设备数据 - 部件码
  1370. }
  1371. //OP30站读txt数据
  1372. if (stationNameStr.Contains("CPAPHD"))
  1373. {
  1374. string path = "";
  1375. if (direction == "Left")
  1376. path = GlobalContext.MESLaserLPath;
  1377. else
  1378. path= GlobalContext.MESLaserRPath;
  1379. //字典存储数据
  1380. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction,sn);
  1381. foreach (var kvp in compensationDict)
  1382. {
  1383. outRequest_Body.unitData.processData.Add(
  1384. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1385. {
  1386. dataName = kvp.Key.ToString(),
  1387. dataValue = kvp.Value.ToString()
  1388. });
  1389. }
  1390. }
  1391. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1392. if (GlobalContext.IsSendProcessData)
  1393. {
  1394. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1395. string mesRet = string.Empty;
  1396. int i = 0;
  1397. while (i < 2) // 1009会多次尝试上传
  1398. {
  1399. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1400. if (response != null && response.header.code == "200")
  1401. {
  1402. OnMessage(LogType.Error, "上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" + JsonConvert.SerializeObject(response.body));
  1403. break;
  1404. }
  1405. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1406. i++;
  1407. i++;
  1408. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1409. // 记录失败原因
  1410. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1411. }
  1412. if (response?.header?.code == "200")
  1413. {
  1414. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1415. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1416. result = 1;
  1417. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1418. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1419. }
  1420. else
  1421. {
  1422. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1423. }
  1424. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1425. JsonConvert.SerializeObject(response), id);
  1426. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1427. }
  1428. }
  1429. catch (Exception ex)
  1430. {
  1431. string str = ex.StackTrace;
  1432. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1433. }
  1434. }
  1435. return result;
  1436. }
  1437. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1438. //{
  1439. // Stopwatch stopwatch = new Stopwatch();
  1440. // stopwatch.Start();
  1441. // try
  1442. // {
  1443. // // 初始化 AtlasScrew 实例
  1444. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1445. // atlasScrew1.Initial();
  1446. // // 存储结果的列表
  1447. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1448. // // 存储角度和扭力的字符串列表
  1449. // List<string> angleStrs = new List<string>();
  1450. // List<string> torqueStrs = new List<string>();
  1451. // // 上一次获取的数据
  1452. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1453. // while (isExitAtlasLeft) // 检查是否收集数据
  1454. // {
  1455. // // 获取当前数据
  1456. // var currentResult = atlasScrew1.GetResults();
  1457. // // 判断是否为新数据
  1458. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1459. // {
  1460. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1461. // // 更新角度和扭力的字符串列表
  1462. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1463. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1464. // // 计算角度、扭力、起始扭力和最大扭力
  1465. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1466. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1467. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1468. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1469. // // 将新数据添加到结果列表
  1470. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1471. // // 更新上一次获取的数据
  1472. // lastResult = currentResult;
  1473. // }
  1474. // // 等待一段时间后再次检查
  1475. // Thread.Sleep(20); // 轮询间隔时间
  1476. // // 如果触发了出站,则退出循环
  1477. // if (!isExitAtlasLeft)
  1478. // {
  1479. // break;
  1480. // }
  1481. // }
  1482. // // 生成文件名
  1483. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1484. // // 写入数据到文件
  1485. // using (StreamWriter writer = new StreamWriter(fileName))
  1486. // {
  1487. // // 写入标题行
  1488. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1489. // // 写入每一行数据
  1490. // foreach (var result in results)
  1491. // {
  1492. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1493. // }
  1494. // }
  1495. // stopwatch.Stop();
  1496. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1497. // }
  1498. // catch (Exception ex)
  1499. // {
  1500. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1501. // }
  1502. // finally
  1503. // {
  1504. // // 重置标志变量
  1505. // isExitAtlasLeft = false;
  1506. // }
  1507. //}
  1508. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1509. //{
  1510. // Stopwatch stopwatch = new Stopwatch();
  1511. // stopwatch.Start();
  1512. // try
  1513. // {
  1514. // // 初始化 AtlasScrew 实例
  1515. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1516. // atlasScrew2.Initial();
  1517. // // 存储结果的列表
  1518. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1519. // // 上一次获取的数据
  1520. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1521. // while (isExitAtlasRight) // 检查是否收集数据
  1522. // {
  1523. // // 获取当前数据
  1524. // var currentResult = atlasScrew2.GetResults();
  1525. // // 判断是否为新数据
  1526. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1527. // {
  1528. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1529. // // 将新数据写入PLC
  1530. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1531. // // 将新数据添加到结果列表
  1532. // results.Add(currentResult);
  1533. // // 更新上一次获取的数据
  1534. // lastResult = currentResult;
  1535. // }
  1536. // // 等待一段时间后再次检查
  1537. // Thread.Sleep(20); // 轮询间隔时间
  1538. // // 如果触发了出站,则退出循环
  1539. // if (!isExitAtlasRight)
  1540. // {
  1541. // break;
  1542. // }
  1543. // }
  1544. // // 将所有数据写入文件
  1545. // //WriteDataToFile(sn, direction, results);
  1546. // stopwatch.Stop();
  1547. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1548. // }
  1549. // catch (Exception ex)
  1550. // {
  1551. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1552. // }
  1553. // finally
  1554. // {
  1555. // // 重置标志变量
  1556. // isExitAtlasRight = false;
  1557. // }
  1558. //}
  1559. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1560. {
  1561. Stopwatch stopwatch = new Stopwatch();
  1562. stopwatch.Start();
  1563. int nRet = 0;
  1564. string strRet = "";
  1565. try
  1566. {
  1567. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1568. while (isCollectingFlagLeft)
  1569. {
  1570. // 从缓存中获取所有未处理的数据
  1571. var cachedData = atlasScrew.GetCachedDataLeft();
  1572. foreach (var currentResult in cachedData)
  1573. {
  1574. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1575. {
  1576. continue; // 跳过无效数据
  1577. }
  1578. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1579. // 写入PLC
  1580. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1581. {
  1582. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1583. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1584. };
  1585. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1586. if (nRet != 0)
  1587. {
  1588. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1589. }
  1590. else
  1591. {
  1592. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1593. }
  1594. // 构建保存路径
  1595. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1596. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1597. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1598. Directory.CreateDirectory(savePath); // 确保目录存在
  1599. // 构建文件名(以 SN + 序号命名)
  1600. string fileName = $"{sn}_{fileCounter}.txt";
  1601. string filePath = Path.Combine(savePath, fileName);
  1602. // 写入文件
  1603. using (StreamWriter writer = new StreamWriter(filePath))
  1604. {
  1605. writer.WriteLine("精度, 扭力");
  1606. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1607. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1608. {
  1609. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1610. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1611. writer.WriteLine($"{precision}, {torque}");
  1612. }
  1613. }
  1614. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1615. // 增加文件计数器
  1616. fileCounter++;
  1617. }
  1618. // 如果没有更多数据,则短暂休眠以节省资源
  1619. if (!cachedData.Any())
  1620. {
  1621. Thread.Sleep(10); // 根据需要调整休眠时间
  1622. }
  1623. // 如果触发了出站,则退出循环
  1624. if (!isCollectingFlagLeft)
  1625. {
  1626. break;
  1627. }
  1628. }
  1629. stopwatch.Stop();
  1630. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1631. }
  1632. catch (Exception ex)
  1633. {
  1634. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1635. }
  1636. finally
  1637. {
  1638. isCollectingFlagLeft = false;
  1639. }
  1640. }
  1641. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1642. {
  1643. Stopwatch stopwatch = new Stopwatch();
  1644. stopwatch.Start();
  1645. int nRet = 0;
  1646. string strRet = "";
  1647. try
  1648. {
  1649. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1650. while (isCollectingFlagRight)
  1651. {
  1652. // 从缓存中获取所有未处理的数据
  1653. var cachedData = atlasScrew.GetCachedDataLeft();
  1654. foreach (var currentResult in cachedData)
  1655. {
  1656. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1657. {
  1658. continue; // 跳过无效数据
  1659. }
  1660. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1661. // 写入PLC
  1662. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1663. {
  1664. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1665. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1666. };
  1667. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1668. if (nRet != 0)
  1669. {
  1670. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1671. }
  1672. else
  1673. {
  1674. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1675. }
  1676. // 构建保存路径
  1677. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1678. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1679. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1680. Directory.CreateDirectory(savePath); // 确保目录存在
  1681. // 构建文件名(以 SN + 序号命名)
  1682. string fileName = $"{sn}_{fileCounter}.txt";
  1683. string filePath = Path.Combine(savePath, fileName);
  1684. // 写入文件
  1685. using (StreamWriter writer = new StreamWriter(filePath))
  1686. {
  1687. writer.WriteLine("精度, 扭力");
  1688. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1689. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1690. {
  1691. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1692. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1693. writer.WriteLine($"{precision}, {torque}");
  1694. }
  1695. }
  1696. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1697. // 增加文件计数器
  1698. fileCounter++;
  1699. }
  1700. // 如果没有更多数据,则短暂休眠以节省资源
  1701. if (!cachedData.Any())
  1702. {
  1703. Thread.Sleep(10); // 根据需要调整休眠时间
  1704. }
  1705. // 如果触发了出站,则退出循环
  1706. if (!isCollectingFlagRight)
  1707. {
  1708. break;
  1709. }
  1710. }
  1711. stopwatch.Stop();
  1712. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1713. }
  1714. catch (Exception ex)
  1715. {
  1716. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1717. }
  1718. finally
  1719. {
  1720. isCollectingFlagRight = false;
  1721. }
  1722. }
  1723. #endregion
  1724. #region S1
  1725. /// <summary>
  1726. /// [S1] 壳体清洁上料装备
  1727. /// </summary>
  1728. /// <param name="plcNo">PLC编号</param>
  1729. private void ReadStation_S1(int plcNo)
  1730. {
  1731. string stationCode = "[OP10]";
  1732. string stationName = "壳体清洁上料";
  1733. string stationNameStr = stationCode + stationName;
  1734. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1735. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1736. string tagAgvCommName = "agvCommFrmPC";
  1737. string tagBarsetName = "BarcodeSet";
  1738. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1739. (int, string) result;
  1740. while (true)
  1741. {
  1742. try
  1743. {
  1744. if (!GlobalContext._IsCon_Funs1)
  1745. {
  1746. UpdatePLCMonitor(1, plcNo, 0);
  1747. continue;
  1748. }
  1749. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1750. {
  1751. Stopwatch stopwatch1 = new Stopwatch();
  1752. Stopwatch stopwatch2 = new Stopwatch();
  1753. stopwatch1.Start();
  1754. stopwatch2.Start();
  1755. #region 一次性读取所有数据
  1756. // 一次性读取所有数据
  1757. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1758. if (result.Item1 != 0)
  1759. {
  1760. //richTextBox1.AppendText("\n" + strRet);
  1761. }
  1762. else
  1763. {
  1764. //richTextBox1.AppendText("\n" + "读取成功");
  1765. }
  1766. #endregion 一次性读取所有数据
  1767. stopwatch2.Stop();
  1768. #region 进站
  1769. try
  1770. {
  1771. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1772. {
  1773. lock (lockObj)
  1774. {
  1775. if (!ProgressState)
  1776. {
  1777. ProgressState = true;
  1778. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1779. }
  1780. }
  1781. }
  1782. }
  1783. catch (Exception ex)
  1784. {
  1785. ProgressState = false;
  1786. string str = ex.StackTrace;
  1787. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1788. }
  1789. #endregion 进站
  1790. #region 出站
  1791. try
  1792. {
  1793. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1794. {
  1795. lock (lockObj)
  1796. {
  1797. if (!ProgressState)
  1798. {
  1799. ProgressState = true;
  1800. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1801. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1802. }
  1803. }
  1804. }
  1805. }
  1806. catch (Exception ex)
  1807. {
  1808. ProgressState = false;
  1809. string str = ex.StackTrace;
  1810. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1811. }
  1812. #endregion 出站
  1813. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1814. stopwatch1.Stop();
  1815. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1816. }
  1817. else
  1818. {
  1819. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1820. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1821. FunsEip[plcNo].Connect(); // 重连
  1822. }
  1823. }
  1824. catch (Exception ex)
  1825. {
  1826. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1827. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1828. }
  1829. Thread.Sleep(IntervalReadPLC);
  1830. }
  1831. }
  1832. /// <summary>
  1833. /// [S1] 壳体清洁上料 - 进站
  1834. /// </summary>
  1835. /// <param name="plcNo">PLC编号</param>
  1836. /// <param name="stationNameStr">工站全称</param>
  1837. /// <param name="stPLC_MesData"></param>
  1838. /// <param name="tagMesCommName"></param>
  1839. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1840. {
  1841. Stopwatch stopwatch1 = new Stopwatch();
  1842. Stopwatch stopwatch2 = new Stopwatch();
  1843. try
  1844. {
  1845. stopwatch1.Start();
  1846. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1847. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1848. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1849. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1850. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1851. if (string.IsNullOrEmpty(sn))
  1852. {
  1853. ProgressState = false;
  1854. return;
  1855. }
  1856. //正式生产就用PLC中取的
  1857. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1858. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1859. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1860. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1861. //绑定载具和产品
  1862. ResponseMessage message = new ResponseMessage();
  1863. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1864. if (message.result == false)
  1865. {
  1866. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1867. }
  1868. // 产品SN进站
  1869. List<TestItem> item = new List<TestItem>();
  1870. stopwatch2.Start();
  1871. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1872. stopwatch2.Stop();
  1873. //指令执行结果 1:OK 110:失败
  1874. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1875. //进站结果写入PLC
  1876. CommandFromPLC resultToPlC = new CommandFromPLC();
  1877. resultToPlC.cmd = 0;
  1878. resultToPlC.cmdParam = 0;
  1879. resultToPlC.cmdResult = mesResultFrmWeb;
  1880. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1881. }
  1882. catch (Exception ex)
  1883. {
  1884. string str = ex.StackTrace;
  1885. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1886. CommandFromPLC resultToPlC = new CommandFromPLC();
  1887. resultToPlC.cmd = 0;
  1888. resultToPlC.cmdParam = 0; //指令参数
  1889. resultToPlC.cmdResult = 110;
  1890. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1891. }
  1892. stopwatch1.Stop();
  1893. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1894. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1895. ProgressState = false;
  1896. }
  1897. /// <summary>
  1898. /// [S1] 壳体清洁上料 - 出站接口
  1899. /// </summary>
  1900. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1901. {
  1902. Stopwatch stopwatch1 = new Stopwatch();
  1903. Stopwatch stopwatch2 = new Stopwatch();
  1904. try
  1905. {
  1906. stopwatch1.Start();
  1907. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1908. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1909. string processItem = stationName; // 项目
  1910. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1911. string supplierCode = ""; // 供应商代码
  1912. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1913. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1914. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1915. string sn = string.Empty;
  1916. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1917. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1918. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1919. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1920. //a1Result = 1;
  1921. bool pass = a1Result == 1;
  1922. //根据载具码获取产品码
  1923. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1924. if (string.IsNullOrEmpty(strProductBarcode))
  1925. {
  1926. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1927. }
  1928. sn = strProductBarcode;
  1929. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1930. List<TestItem> items = new List<TestItem>();
  1931. items.Add(new TestItem()
  1932. {
  1933. Parameter_name = "载具码",
  1934. Parameter_value = CarrierBarcode,
  1935. Parameter_unit = ""
  1936. });
  1937. items.Add(new TestItem()
  1938. {
  1939. Parameter_name = "产品码",
  1940. Parameter_value = sn,
  1941. Parameter_unit = ""
  1942. });
  1943. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  1944. //出站接口
  1945. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1946. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  1947. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1948. stopwatch2.Start();
  1949. //进站结果写入PLC
  1950. CommandFromPLC resultToPlC = new CommandFromPLC();
  1951. resultToPlC.cmd = 0;
  1952. resultToPlC.cmdParam = 0; //指令参数
  1953. resultToPlC.cmdResult = mesResultFrmWeb;
  1954. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1955. stopwatch2.Stop();
  1956. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1957. //保存PLC返回MES数据到本地
  1958. ResponseMessage message = new ResponseMessage();
  1959. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1960. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1961. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1962. stPLC_MesData.mesData.nRemainCount);
  1963. if (message.result == false)
  1964. {
  1965. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1966. }
  1967. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1968. }
  1969. catch (Exception ex)
  1970. {
  1971. stopwatch2.Start();
  1972. CommandFromPLC resultToPlC = new CommandFromPLC();
  1973. resultToPlC.cmd = 0;
  1974. resultToPlC.cmdParam = 0; //指令参数
  1975. resultToPlC.cmdResult = 110;
  1976. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1977. stopwatch2.Stop();
  1978. string str = ex.StackTrace;
  1979. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1980. }
  1981. stopwatch1.Stop();
  1982. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1983. ProgressState = false;
  1984. }
  1985. #endregion
  1986. #region S2
  1987. /// <summary>
  1988. /// [S2] 上盖板上料装备
  1989. /// </summary>
  1990. /// <param name="plcNo">PLC编号</param>
  1991. private void ReadStation_S2(int plcNo)
  1992. {
  1993. string stationCode = "[OP20]";
  1994. string stationName = "上盖板上料装备";
  1995. string stationNameStr = stationCode + stationName;
  1996. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1997. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1998. string tagAgvCommName = "agvCommFrmPC";
  1999. string tagBarsetName = "BarcodeSet";
  2000. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  2001. (int, string) result;
  2002. while (true)
  2003. {
  2004. try
  2005. {
  2006. if (!GlobalContext._IsCon_Funs2)
  2007. {
  2008. UpdatePLCMonitor(1, plcNo, 0);
  2009. continue;
  2010. }
  2011. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2012. {
  2013. Stopwatch stopwatch1 = new Stopwatch();
  2014. Stopwatch stopwatch2 = new Stopwatch();
  2015. stopwatch1.Start();
  2016. stopwatch2.Start();
  2017. #region 一次性读取所有数据
  2018. // 一次性读取所有数据
  2019. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2020. if (result.Item1 != 0)
  2021. {
  2022. //richTextBox1.AppendText("\n" + strRet);
  2023. }
  2024. else
  2025. {
  2026. //richTextBox1.AppendText("\n" + "读取成功");
  2027. }
  2028. #endregion 一次性读取所有数据
  2029. stopwatch2.Stop();
  2030. #region 进站
  2031. try
  2032. {
  2033. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2034. {
  2035. lock (lockObj)
  2036. {
  2037. if (!ProgressState)
  2038. {
  2039. ProgressState = true;
  2040. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2041. }
  2042. }
  2043. }
  2044. }
  2045. catch (Exception ex)
  2046. {
  2047. ProgressState = false;
  2048. string str = ex.StackTrace;
  2049. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2050. }
  2051. #endregion 进站
  2052. #region 出站
  2053. try
  2054. {
  2055. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2056. {
  2057. lock (lockObj)
  2058. {
  2059. if (!ProgressState)
  2060. {
  2061. ProgressState = true;
  2062. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2063. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  2064. }
  2065. }
  2066. }
  2067. }
  2068. catch (Exception ex)
  2069. {
  2070. ProgressState = false;
  2071. string str = ex.StackTrace;
  2072. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2073. }
  2074. #endregion 出站
  2075. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2076. stopwatch1.Stop();
  2077. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2078. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2079. }
  2080. else
  2081. {
  2082. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2083. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2084. FunsEip[plcNo].Connect();
  2085. }
  2086. }
  2087. catch (Exception ex)
  2088. {
  2089. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2090. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2091. //Funs[plcNo].ReConnect();
  2092. }
  2093. Thread.Sleep(IntervalReadPLC);
  2094. }
  2095. }
  2096. /// <summary>
  2097. /// [S2] 上盖板上料装备
  2098. /// </summary>
  2099. /// <param name="plcNo">PLC编号</param>
  2100. /// <param name="stationNameStr">工站全称</param>
  2101. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2102. {
  2103. Stopwatch stopwatch1 = new Stopwatch();
  2104. Stopwatch stopwatch2 = new Stopwatch();
  2105. try
  2106. {
  2107. stopwatch1.Start();
  2108. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2109. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  2110. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2111. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  2112. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  2113. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2114. //根据载具码获取产品码
  2115. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2116. if (string.IsNullOrEmpty(strProductBarcode))
  2117. {
  2118. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2119. }
  2120. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2121. //if (sn != strProductBarcode)
  2122. //{
  2123. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2124. //}
  2125. sn = strProductBarcode;
  2126. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2127. // 产品SN(物料码)校验
  2128. List<TestItem> item = new List<TestItem>();
  2129. stopwatch2.Start();
  2130. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2131. stopwatch2.Stop();
  2132. //指令执行结果 1:OK 110:失败
  2133. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2134. //进站结果写入PLC
  2135. CommandFromPLC resultToPlC = new CommandFromPLC();
  2136. resultToPlC.cmd = 0;
  2137. resultToPlC.cmdParam = 0; //指令参数
  2138. resultToPlC.cmdResult = mesResultFrmWeb;
  2139. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2140. }
  2141. catch (Exception ex)
  2142. {
  2143. string str = ex.StackTrace;
  2144. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2145. CommandFromPLC resultToPlC = new CommandFromPLC();
  2146. resultToPlC.cmd = 0;
  2147. resultToPlC.cmdParam = 0; //指令参数
  2148. resultToPlC.cmdResult = 110;
  2149. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2150. }
  2151. stopwatch1.Stop();
  2152. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2153. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2154. ProgressState = false;
  2155. }
  2156. /// <summary>
  2157. /// [S2] 上盖板上料装备 - 出站接口
  2158. /// </summary>
  2159. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2160. {
  2161. Stopwatch stopwatch1 = new Stopwatch();
  2162. Stopwatch stopwatch2 = new Stopwatch();
  2163. try
  2164. {
  2165. stopwatch1.Start();
  2166. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2167. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2168. string processItem = stationName; // 测试项目
  2169. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2170. string supplierCode = ""; // 供应商代码
  2171. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2172. string batch_num = GlobalContext.BatchNumber; // 批次号
  2173. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2174. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2175. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2176. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2177. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2178. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  2179. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2180. bool pass = a1Result == 1;
  2181. //根据载具码获取产品码
  2182. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2183. if (string.IsNullOrEmpty(strProductBarcode))
  2184. {
  2185. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2186. }
  2187. sn = strProductBarcode;
  2188. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2189. List<TestItem> items = new List<TestItem>();
  2190. items.Add(new TestItem()
  2191. {
  2192. Parameter_name = "载具码",
  2193. Parameter_value = CarrierBarcode,
  2194. Parameter_unit = ""
  2195. });
  2196. items.Add(new TestItem()
  2197. {
  2198. Parameter_name = "产品码",
  2199. Parameter_value = sn,
  2200. Parameter_unit = ""
  2201. });
  2202. items.Add(new TestItem()
  2203. {
  2204. Parameter_name = "部件码",
  2205. Parameter_value = PartBarcode,
  2206. Parameter_unit = ""
  2207. });
  2208. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  2209. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2210. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
  2211. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2212. stopwatch2.Start();
  2213. //进站结果写入PLC
  2214. CommandFromPLC resultToPlC = new CommandFromPLC();
  2215. resultToPlC.cmd = 0;
  2216. resultToPlC.cmdParam = 0; //指令参数
  2217. resultToPlC.cmdResult = mesResultFrmWeb;
  2218. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2219. stopwatch2.Stop();
  2220. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2221. //保存PLC返回MES数据到本地
  2222. ResponseMessage message = new ResponseMessage();
  2223. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  2224. if (message.result == false)
  2225. {
  2226. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2227. }
  2228. if (!string.IsNullOrEmpty(PartBarcode))
  2229. {
  2230. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2231. if (message.result == false)
  2232. {
  2233. AddMessage(LogType.Error, message.text);
  2234. }
  2235. }
  2236. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2237. }
  2238. catch (Exception ex)
  2239. {
  2240. stopwatch2.Start();
  2241. CommandFromPLC resultToPlC = new CommandFromPLC();
  2242. resultToPlC.cmd = 0;
  2243. resultToPlC.cmdParam = 0; //指令参数
  2244. resultToPlC.cmdResult = 110;
  2245. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2246. stopwatch2.Stop();
  2247. string str = ex.StackTrace;
  2248. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2249. }
  2250. stopwatch1.Stop();
  2251. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2252. ProgressState = false;
  2253. }
  2254. #endregion
  2255. #region S3
  2256. /// <summary>
  2257. /// [S3] 点散热胶装备
  2258. /// </summary>
  2259. /// <param name="plcNo">PLC编号</param>
  2260. private void ReadStation_S3(int plcNo)
  2261. {
  2262. string stationCode = "[OP30]";
  2263. string stationName = "点散热胶装备";
  2264. string stationNameStr = stationCode + stationName;
  2265. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2266. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2267. string tagAgvCommName = "agvCommFrmPC";
  2268. string tagBarsetName = "BarcodeSet";
  2269. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2270. (int, string) result;
  2271. #region 创建字典
  2272. // 触发信号字典 赋值
  2273. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2274. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2275. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2276. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2277. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2278. // PLC数据字典 赋值
  2279. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2280. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2281. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2282. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2283. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2284. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2285. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2286. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2287. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2288. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2289. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2290. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2291. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2292. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2293. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2294. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2295. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2296. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2297. s3PLCData.Add("c1Result", 0); // 产品结果
  2298. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2299. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2300. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2301. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2302. #endregion 创建字典
  2303. while (true)
  2304. {
  2305. try
  2306. {
  2307. if (!GlobalContext._IsCon_Funs2)
  2308. {
  2309. UpdatePLCMonitor(1, plcNo, 0);
  2310. continue;
  2311. }
  2312. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2313. {
  2314. Stopwatch stopwatch1 = new Stopwatch();
  2315. Stopwatch stopwatch2 = new Stopwatch();
  2316. stopwatch1.Start();
  2317. stopwatch2.Start();
  2318. #region 一次性读取所有数据
  2319. // 一次性读取所有数据
  2320. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2321. if (result.Item1 != 0)
  2322. {
  2323. //richTextBox1.AppendText("\n" + strRet);
  2324. }
  2325. else
  2326. {
  2327. //richTextBox1.AppendText("\n" + "读取成功");
  2328. }
  2329. #endregion 一次性读取所有数据
  2330. stopwatch2.Stop();
  2331. #region 左边进站
  2332. try
  2333. {
  2334. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2335. {
  2336. lock (lockObj)
  2337. {
  2338. if (!ProgressState)
  2339. {
  2340. ProgressState = true;
  2341. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2342. }
  2343. }
  2344. }
  2345. }
  2346. catch (Exception ex)
  2347. {
  2348. ProgressState = false;
  2349. string str = ex.StackTrace;
  2350. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2351. }
  2352. #endregion 左边进站
  2353. #region 左边出站
  2354. try
  2355. {
  2356. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2357. {
  2358. lock (lockObj)
  2359. {
  2360. if (!ProgressState)
  2361. {
  2362. ProgressState = true;
  2363. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2364. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  2365. }
  2366. }
  2367. }
  2368. }
  2369. catch (Exception ex)
  2370. {
  2371. ProgressState = false;
  2372. string str = ex.StackTrace;
  2373. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2374. }
  2375. #endregion 左边出站
  2376. #region 右边进站
  2377. try
  2378. {
  2379. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2380. {
  2381. lock (lockObj)
  2382. {
  2383. if (!ProgressState)
  2384. {
  2385. ProgressState = true;
  2386. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2387. }
  2388. }
  2389. }
  2390. }
  2391. catch (Exception ex)
  2392. {
  2393. ProgressState = false;
  2394. string str = ex.StackTrace;
  2395. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2396. }
  2397. #endregion 右边进站
  2398. #region 右边出站
  2399. try
  2400. {
  2401. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2402. {
  2403. lock (lockObj)
  2404. {
  2405. if (!ProgressState)
  2406. {
  2407. ProgressState = true;
  2408. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2409. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  2410. }
  2411. }
  2412. }
  2413. }
  2414. catch (Exception ex)
  2415. {
  2416. string str = ex.StackTrace;
  2417. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2418. }
  2419. #endregion 右边出站
  2420. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2421. stopwatch1.Stop();
  2422. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2423. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2424. }
  2425. else
  2426. {
  2427. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2428. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2429. FunsEip[plcNo].Connect();
  2430. }
  2431. }
  2432. catch (Exception ex)
  2433. {
  2434. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2435. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2436. //Funs[plcNo].ReConnect();
  2437. }
  2438. Thread.Sleep(IntervalReadPLC);
  2439. }
  2440. }
  2441. /// <summary>
  2442. /// [S3] 点散热胶装备 - 进站
  2443. /// </summary>
  2444. /// <param name="plcNo">PLC编号</param>
  2445. /// <param name="stationNameStr">工站全称</param>
  2446. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2447. {
  2448. Stopwatch stopwatch1 = new Stopwatch();
  2449. Stopwatch stopwatch2 = new Stopwatch();
  2450. try
  2451. {
  2452. stopwatch1.Start();
  2453. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2454. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2455. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2456. string StationId=string.Empty;
  2457. if (direction=="Left")
  2458. {
  2459. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2460. }
  2461. if (direction == "Right")
  2462. {
  2463. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2464. }
  2465. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2466. //载具码验证产品码
  2467. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2468. if (string.IsNullOrEmpty(strProductBarcode))
  2469. {
  2470. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2471. }
  2472. sn = strProductBarcode;
  2473. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2474. // 产品SN(物料码)校验
  2475. List<TestItem> item = new List<TestItem>();
  2476. stopwatch2.Start();
  2477. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2478. stopwatch2.Stop();
  2479. //指令执行结果 1:OK 110:失败
  2480. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2481. //进站结果写入PLC
  2482. CommandFromPLC resultToPlC = new CommandFromPLC();
  2483. resultToPlC.cmd = 0;
  2484. resultToPlC.cmdParam = 0; //指令参数
  2485. resultToPlC.cmdResult = mesResultFrmWeb;
  2486. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2487. }
  2488. catch (Exception ex)
  2489. {
  2490. string str = ex.StackTrace;
  2491. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2492. CommandFromPLC resultToPlC = new CommandFromPLC();
  2493. resultToPlC.cmd = 0;
  2494. resultToPlC.cmdParam = 0; //指令参数
  2495. resultToPlC.cmdResult = 110;
  2496. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2497. }
  2498. stopwatch1.Stop();
  2499. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2500. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2501. ProgressState = false;
  2502. }
  2503. /// <summary>
  2504. /// [S3] 点散热胶装备 - 出站
  2505. /// </summary>
  2506. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2507. {
  2508. Stopwatch stopwatch1 = new Stopwatch();
  2509. Stopwatch stopwatch2 = new Stopwatch();
  2510. try
  2511. {
  2512. stopwatch1.Start();
  2513. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2514. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2515. string processItem = stationName; // 测试项目
  2516. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2517. string supplierCode = ""; // 供应商代码
  2518. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2519. string batch_num = GlobalContext.BatchNumber; // 批次号
  2520. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2521. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2522. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2523. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2524. string StationId = string.Empty;
  2525. if (direction == "Left")
  2526. {
  2527. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2528. }
  2529. if (direction == "Right")
  2530. {
  2531. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2532. }
  2533. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2534. bool pass = a1Result == 1;
  2535. //根据载具码获取产品码
  2536. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2537. if (string.IsNullOrEmpty(strProductBarcode))
  2538. {
  2539. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2540. }
  2541. sn = strProductBarcode;
  2542. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2543. List<TestItem> items = new List<TestItem>();
  2544. items.Add(new TestItem()
  2545. {
  2546. Parameter_name = "载具码",
  2547. Parameter_value = CarrierBarcode,
  2548. Parameter_unit = ""
  2549. });
  2550. items.Add(new TestItem()
  2551. {
  2552. Parameter_name = "产品码",
  2553. Parameter_value = sn,
  2554. Parameter_unit = ""
  2555. });
  2556. int result1 = 1;
  2557. //if (direction == "Right")
  2558. //{
  2559. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  2560. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2561. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson, direction);
  2562. //}
  2563. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2564. stopwatch2.Start();
  2565. //进站结果写入PLC
  2566. CommandFromPLC resultToPlC = new CommandFromPLC();
  2567. resultToPlC.cmd = 0;
  2568. resultToPlC.cmdParam = 0; //指令参数
  2569. resultToPlC.cmdResult = mesResultFrmWeb;
  2570. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2571. stopwatch2.Stop();
  2572. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2573. //保存PLC返回MES数据到本地
  2574. ResponseMessage message = new ResponseMessage();
  2575. if (direction == "Left")
  2576. {
  2577. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2578. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2579. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2580. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2581. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2582. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2583. if (message.result == false)
  2584. {
  2585. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2586. }
  2587. }
  2588. if (direction == "Right")
  2589. {
  2590. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2591. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2592. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2593. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2594. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2595. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2596. if (message.result == false)
  2597. {
  2598. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2599. }
  2600. }
  2601. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2602. }
  2603. catch (Exception ex)
  2604. {
  2605. stopwatch2.Start();
  2606. CommandFromPLC resultToPlC = new CommandFromPLC();
  2607. resultToPlC.cmd = 0;
  2608. resultToPlC.cmdParam = 0; //指令参数
  2609. resultToPlC.cmdResult = 110;
  2610. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2611. stopwatch2.Stop();
  2612. string str = ex.StackTrace;
  2613. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2614. }
  2615. stopwatch1.Stop();
  2616. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2617. ProgressState = false;
  2618. }
  2619. #endregion S3
  2620. #region S4
  2621. /// <summary>
  2622. /// [S4] 点胶检测设备
  2623. /// </summary>
  2624. /// <param name="plcNo">PLC编号</param>
  2625. private void ReadStation_S4(int plcNo)
  2626. {
  2627. string stationCode = "[OP40]";
  2628. string stationName = "胶线检测";
  2629. string stationNameStr = stationCode + stationName;
  2630. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2631. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2632. string tagAgvCommName = "agvCommFrmPC";
  2633. string tagBarsetName = "BarcodeSet";
  2634. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2635. (int, string) result;
  2636. while (true)
  2637. {
  2638. try
  2639. {
  2640. if (!GlobalContext._IsCon_Funs1)
  2641. {
  2642. UpdatePLCMonitor(1, plcNo, 0);
  2643. continue;
  2644. }
  2645. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2646. {
  2647. Stopwatch stopwatch1 = new Stopwatch();
  2648. Stopwatch stopwatch2 = new Stopwatch();
  2649. stopwatch1.Start();
  2650. stopwatch2.Start();
  2651. #region 一次性读取所有数据
  2652. // 一次性读取所有数据
  2653. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2654. if (result.Item1 != 0)
  2655. {
  2656. //richTextBox1.AppendText("\n" + strRet);
  2657. }
  2658. else
  2659. {
  2660. //richTextBox1.AppendText("\n" + "读取成功");
  2661. }
  2662. #endregion 一次性读取所有数据
  2663. stopwatch2.Stop();
  2664. #region 进站
  2665. try
  2666. {
  2667. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2668. {
  2669. lock (lockObj)
  2670. {
  2671. if (!ProgressState)
  2672. {
  2673. ProgressState = true;
  2674. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2675. }
  2676. }
  2677. }
  2678. }
  2679. catch (Exception ex)
  2680. {
  2681. ProgressState = false;
  2682. string str = ex.StackTrace;
  2683. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2684. }
  2685. #endregion 进站
  2686. #region 出站
  2687. try
  2688. {
  2689. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2690. {
  2691. lock (lockObj)
  2692. {
  2693. if (!ProgressState)
  2694. {
  2695. ProgressState = true;
  2696. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2697. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2698. }
  2699. }
  2700. }
  2701. }
  2702. catch (Exception ex)
  2703. {
  2704. string str = ex.StackTrace;
  2705. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2706. }
  2707. #endregion 出站
  2708. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2709. stopwatch1.Stop();
  2710. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2711. }
  2712. else
  2713. {
  2714. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2715. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2716. FunsEip[plcNo].Connect(); // 重连
  2717. }
  2718. }
  2719. catch (Exception ex)
  2720. {
  2721. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2722. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2723. }
  2724. Thread.Sleep(IntervalReadPLC);
  2725. }
  2726. }
  2727. /// <summary>
  2728. /// [S4] 点胶检测设备 - 进站
  2729. /// </summary>
  2730. /// <param name="plcNo">PLC编号</param>
  2731. /// <param name="stationNameStr">工站全称</param>
  2732. /// <param name="stPLC_MesData"></param>
  2733. /// <param name="tagMesCommName"></param>
  2734. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2735. {
  2736. Stopwatch stopwatch1 = new Stopwatch();
  2737. Stopwatch stopwatch2 = new Stopwatch();
  2738. try
  2739. {
  2740. stopwatch1.Start();
  2741. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2742. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2743. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2744. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2745. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2746. //载具码验证产品码
  2747. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2748. if (string.IsNullOrEmpty(strProductBarcode))
  2749. {
  2750. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2751. }
  2752. sn = strProductBarcode;
  2753. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2754. // 产品SN(物料码)校验
  2755. List<TestItem> item = new List<TestItem>();
  2756. stopwatch2.Start();
  2757. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2758. stopwatch2.Stop();
  2759. //指令执行结果 1:OK 110:失败
  2760. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2761. //进站结果写入PLC
  2762. CommandFromPLC resultToPlC = new CommandFromPLC();
  2763. resultToPlC.cmd = 0;
  2764. resultToPlC.cmdParam = 0; //指令参数
  2765. resultToPlC.cmdResult = mesResultFrmWeb;
  2766. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2767. }
  2768. catch (Exception ex)
  2769. {
  2770. string str = ex.StackTrace;
  2771. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2772. CommandFromPLC resultToPlC = new CommandFromPLC();
  2773. resultToPlC.cmd = 0;
  2774. resultToPlC.cmdParam = 0; //指令参数
  2775. resultToPlC.cmdResult = 110;
  2776. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2777. }
  2778. stopwatch1.Stop();
  2779. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2780. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2781. ProgressState = false;
  2782. }
  2783. /// <summary>
  2784. /// [S4] 点胶检测设备 - 出站接口
  2785. /// </summary>
  2786. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2787. {
  2788. Stopwatch stopwatch1 = new Stopwatch();
  2789. Stopwatch stopwatch2 = new Stopwatch();
  2790. try
  2791. {
  2792. stopwatch1.Start();
  2793. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2794. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2795. string processItem = stationName; // 测试项目
  2796. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2797. string supplierCode = ""; // 供应商代码
  2798. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2799. string batch_num = GlobalContext.BatchNumber; // 批次号
  2800. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2801. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2802. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2803. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2804. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2805. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2806. bool pass = a1Result == 1;
  2807. //根据载具码获取产品码
  2808. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2809. if (string.IsNullOrEmpty(strProductBarcode))
  2810. {
  2811. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2812. }
  2813. sn = strProductBarcode;
  2814. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2815. List<TestItem> items = new List<TestItem>();
  2816. items.Add(new TestItem()
  2817. {
  2818. Parameter_name = "载具码",
  2819. Parameter_value = CarrierBarcode,
  2820. Parameter_unit = ""
  2821. });
  2822. items.Add(new TestItem()
  2823. {
  2824. Parameter_name = "产品码",
  2825. Parameter_value = sn,
  2826. Parameter_unit = ""
  2827. });
  2828. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  2829. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2830. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  2831. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2832. stopwatch2.Start();
  2833. //进站结果写入PLC
  2834. CommandFromPLC resultToPlC = new CommandFromPLC();
  2835. resultToPlC.cmd = 0;
  2836. resultToPlC.cmdParam = 0; //指令参数
  2837. resultToPlC.cmdResult = mesResultFrmWeb;
  2838. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2839. stopwatch2.Stop();
  2840. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2841. //保存PLC返回MES数据到本地
  2842. ResponseMessage message = new ResponseMessage();
  2843. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2844. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2845. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2846. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2847. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2848. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2849. if (message.result == false)
  2850. {
  2851. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2852. }
  2853. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2854. }
  2855. catch (Exception ex)
  2856. {
  2857. stopwatch2.Start();
  2858. CommandFromPLC resultToPlC = new CommandFromPLC();
  2859. resultToPlC.cmd = 0;
  2860. resultToPlC.cmdParam = 0; //指令参数
  2861. resultToPlC.cmdResult = 110;
  2862. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2863. stopwatch2.Stop();
  2864. string str = ex.StackTrace;
  2865. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2866. }
  2867. stopwatch1.Stop();
  2868. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2869. ProgressState = false;
  2870. }
  2871. #endregion
  2872. #region S5
  2873. private static bool isPCBStation = false;//控制PCB是否进出站的标识
  2874. /// <summary>
  2875. /// [S5] 点胶检测设备
  2876. /// </summary>
  2877. /// <param name="plcNo">PLC编号</param>
  2878. private void ReadStation_S5(int plcNo)
  2879. {
  2880. string stationCode = "[OP50]";
  2881. string stationName = "ADD板上料组装装备";
  2882. string stationNameStr = stationCode + stationName;
  2883. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2884. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2885. string tagAgvCommName = "agvCommFrmPC";
  2886. string tagBarsetName = "BarcodeSet";
  2887. string pcbBarcode = "";
  2888. string pcbBarcodeOld = "";
  2889. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2890. (int, string) result;
  2891. while (true)
  2892. {
  2893. try
  2894. {
  2895. if (!GlobalContext._IsCon_Funs1)
  2896. {
  2897. UpdatePLCMonitor(1, plcNo, 0);
  2898. continue;
  2899. }
  2900. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2901. {
  2902. Stopwatch stopwatch1 = new Stopwatch();
  2903. Stopwatch stopwatch2 = new Stopwatch();
  2904. stopwatch1.Start();
  2905. stopwatch2.Start();
  2906. #region 一次性读取所有数据
  2907. // 一次性读取所有数据
  2908. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2909. if (result.Item1 != 0)
  2910. {
  2911. //richTextBox1.AppendText("\n" + strRet);
  2912. }
  2913. else
  2914. {
  2915. #region PCB出站
  2916. //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
  2917. pcbBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  2918. if (pcbBarcode!= pcbBarcodeOld)
  2919. {
  2920. isPCBStation = true;
  2921. }
  2922. if (isPCBStation)
  2923. {
  2924. var r = S5_PCB进出站(stPLC_MesData, plcNo, stationNameStr, tagBaseName, tagMesCommName);
  2925. if (r > 0)
  2926. {
  2927. isPCBStation = false;
  2928. pcbBarcodeOld = pcbBarcode;
  2929. }
  2930. }
  2931. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  2932. #endregion
  2933. }
  2934. #endregion 一次性读取所有数据
  2935. stopwatch2.Stop();
  2936. #region 进站
  2937. try
  2938. {
  2939. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2940. {
  2941. lock (lockObj)
  2942. {
  2943. if (!ProgressState)
  2944. {
  2945. ProgressState = true;
  2946. isPCBStation = true;//开启PCB进出站
  2947. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2948. }
  2949. }
  2950. }
  2951. }
  2952. catch (Exception ex)
  2953. {
  2954. ProgressState = false;
  2955. string str = ex.StackTrace;
  2956. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2957. }
  2958. #endregion 进站
  2959. #region 出站
  2960. try
  2961. {
  2962. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2963. {
  2964. lock (lockObj)
  2965. {
  2966. if (!ProgressState)
  2967. {
  2968. ProgressState = true;
  2969. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2970. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2971. }
  2972. }
  2973. }
  2974. }
  2975. catch (Exception ex)
  2976. {
  2977. ProgressState = false;
  2978. string str = ex.StackTrace;
  2979. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2980. }
  2981. #endregion 出站
  2982. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2983. stopwatch1.Stop();
  2984. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2985. }
  2986. else
  2987. {
  2988. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2989. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2990. FunsEip[plcNo].Connect(); // 重连
  2991. }
  2992. }
  2993. catch (Exception ex)
  2994. {
  2995. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2996. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2997. }
  2998. Thread.Sleep(IntervalReadPLC);
  2999. }
  3000. }
  3001. /// <summary>
  3002. /// [S5] 点胶检测设备 - 进站
  3003. /// </summary>
  3004. /// <param name="plcNo">PLC编号</param>
  3005. /// <param name="stationNameStr">工站全称</param>
  3006. /// <param name="stPLC_MesData"></param>
  3007. /// <param name="tagMesCommName"></param>
  3008. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3009. {
  3010. Stopwatch stopwatch1 = new Stopwatch();
  3011. Stopwatch stopwatch2 = new Stopwatch();
  3012. try
  3013. {
  3014. stopwatch1.Start();
  3015. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3016. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3017. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3018. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  3019. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  3020. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  3021. //载具码验证产品码 //载具码验证产品码
  3022. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3023. if (string.IsNullOrEmpty(strProductBarcode))
  3024. {
  3025. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3026. }
  3027. sn = strProductBarcode;
  3028. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3029. // 产品SN(物料码)校验
  3030. List<TestItem> item = new List<TestItem>();
  3031. stopwatch2.Start();
  3032. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3033. stopwatch2.Stop();
  3034. //指令执行结果 1:OK 110:失败
  3035. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3036. //进站结果写入PLC
  3037. CommandFromPLC resultToPlC = new CommandFromPLC();
  3038. resultToPlC.cmd = 0;
  3039. resultToPlC.cmdParam = 0; //指令参数
  3040. resultToPlC.cmdResult = mesResultFrmWeb;
  3041. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3042. }
  3043. catch (Exception ex)
  3044. {
  3045. string str = ex.StackTrace;
  3046. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3047. CommandFromPLC resultToPlC = new CommandFromPLC();
  3048. resultToPlC.cmd = 0;
  3049. resultToPlC.cmdParam = 0; //指令参数
  3050. resultToPlC.cmdResult = 110;
  3051. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3052. }
  3053. stopwatch1.Stop();
  3054. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3055. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3056. ProgressState = false;
  3057. }
  3058. /// <summary>
  3059. /// [S5] 点胶检测设备 - 出站接口
  3060. /// </summary>
  3061. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3062. {
  3063. Stopwatch stopwatch1 = new Stopwatch();
  3064. Stopwatch stopwatch2 = new Stopwatch();
  3065. try
  3066. {
  3067. stopwatch1.Start();
  3068. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3069. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3070. string processItem = stationName; // 测试项目
  3071. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3072. string supplierCode = ""; // 供应商代码
  3073. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3074. string batch_num = GlobalContext.BatchNumber; // 批次号
  3075. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3076. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3077. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  3078. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3079. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  3080. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  3081. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  3082. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3083. bool pass = a1Result == 1;
  3084. //根据载具码获取产品码
  3085. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3086. if (string.IsNullOrEmpty(strProductBarcode))
  3087. {
  3088. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3089. }
  3090. sn = strProductBarcode;
  3091. //数据库绑定载具和PCB
  3092. ResponseMessage message = new ResponseMessage();
  3093. message = SQLHelper.PCBCarrierBind(CarrierBarcode, pcbBarcode);
  3094. if (message.result == false)
  3095. {
  3096. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  3097. }
  3098. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  3099. List<TestItem> items = new List<TestItem>();
  3100. items.Add(new TestItem()
  3101. {
  3102. Parameter_name = "载具码",
  3103. Parameter_value = CarrierBarcode,
  3104. Parameter_unit = ""
  3105. });
  3106. items.Add(new TestItem()
  3107. {
  3108. Parameter_name = "产品码",
  3109. Parameter_value = sn,
  3110. Parameter_unit = ""
  3111. });
  3112. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3113. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3114. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
  3115. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3116. stopwatch2.Start();
  3117. //进站结果写入PLC
  3118. CommandFromPLC resultToPlC = new CommandFromPLC();
  3119. resultToPlC.cmd = 0;
  3120. resultToPlC.cmdParam = 0; //指令参数
  3121. resultToPlC.cmdResult = mesResultFrmWeb;
  3122. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3123. stopwatch2.Stop();
  3124. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3125. //保存PLC返回MES数据到本地
  3126. //ResponseMessage message = new ResponseMessage();
  3127. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  3128. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  3129. if (message.result == false)
  3130. {
  3131. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3132. }
  3133. //保存部件码信息
  3134. if (!string.IsNullOrEmpty(PartBarcode))
  3135. {
  3136. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  3137. if (message.result == false)
  3138. {
  3139. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  3140. }
  3141. }
  3142. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3143. }
  3144. catch (Exception ex)
  3145. {
  3146. stopwatch2.Start();
  3147. CommandFromPLC resultToPlC = new CommandFromPLC();
  3148. resultToPlC.cmd = 0;
  3149. resultToPlC.cmdParam = 0; //指令参数
  3150. resultToPlC.cmdResult = 110;
  3151. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3152. stopwatch2.Stop();
  3153. string str = ex.StackTrace;
  3154. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3155. }
  3156. stopwatch1.Stop();
  3157. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3158. ProgressState = false;
  3159. }
  3160. private int S5_PCB进出站(OP50_MesData_t stPLC_MesData,int plcNo,string stationNameStr,string tagBaseName,string tagMesCommName) {
  3161. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode.Replace("\r", "");
  3162. stPLC_MesData.BarcodeSet.strPCBBarcode = PCBBarcode;//特殊字符处理
  3163. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  3164. {
  3165. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  3166. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  3167. CommandFromPLC resultToPlC = new CommandFromPLC();
  3168. resultToPlC.cmd = 0;
  3169. resultToPlC.cmdParam = 0; //指令参数
  3170. if (GlobalContext.IsSendStationIn)
  3171. {
  3172. #region 出站
  3173. int res1 = PCBStationInData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  3174. if (res1 == 1)
  3175. {
  3176. resultToPlC.cmdResult = 2;//OK
  3177. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  3178. }
  3179. else
  3180. {
  3181. resultToPlC.cmdResult = 120;
  3182. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  3183. return 2;
  3184. }
  3185. #endregion
  3186. #region 出站
  3187. int res2 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  3188. if (res2 == 1)
  3189. {
  3190. resultToPlC.cmdResult = 2;//OK
  3191. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  3192. return 1;
  3193. }
  3194. else
  3195. {
  3196. resultToPlC.cmdResult = 120;
  3197. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  3198. return 2;
  3199. }
  3200. #endregion
  3201. }
  3202. else {
  3203. return 2;
  3204. }
  3205. }
  3206. else
  3207. {
  3208. return 2;
  3209. }
  3210. }
  3211. #endregion
  3212. #region S6
  3213. /// <summary>
  3214. /// [S6] 顶盖装配设备
  3215. /// </summary>
  3216. /// <param name="plcNo">PLC编号</param>
  3217. private void ReadStation_S6(int plcNo)
  3218. {
  3219. string stationCode = "[OP60]";
  3220. string stationName = "组上盖板";
  3221. string stationNameStr = stationCode + stationName;
  3222. string tagBaseName = "g_OP60_MES"; //标签变量名称
  3223. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3224. string tagAgvCommName = "agvCommFrmPC";
  3225. string tagBarsetName = "BarcodeSet";
  3226. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  3227. (int, string) result;
  3228. while (true)
  3229. {
  3230. try
  3231. {
  3232. if (!GlobalContext._IsCon_Funs1)
  3233. {
  3234. UpdatePLCMonitor(1, plcNo, 0);
  3235. continue;
  3236. }
  3237. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3238. {
  3239. Stopwatch stopwatch1 = new Stopwatch();
  3240. Stopwatch stopwatch2 = new Stopwatch();
  3241. stopwatch1.Start();
  3242. stopwatch2.Start();
  3243. #region 一次性读取所有数据
  3244. // 一次性读取所有数据
  3245. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3246. if (result.Item1 != 0)
  3247. {
  3248. //richTextBox1.AppendText("\n" + strRet);
  3249. }
  3250. else
  3251. {
  3252. //richTextBox1.AppendText("\n" + "读取成功");
  3253. }
  3254. #endregion 一次性读取所有数据
  3255. stopwatch2.Stop();
  3256. #region 进站
  3257. try
  3258. {
  3259. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3260. {
  3261. lock (lockObj)
  3262. {
  3263. if (!ProgressState)
  3264. {
  3265. ProgressState = true;
  3266. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3267. }
  3268. }
  3269. }
  3270. }
  3271. catch (Exception ex)
  3272. {
  3273. ProgressState = false;
  3274. string str = ex.StackTrace;
  3275. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3276. }
  3277. #endregion 进站
  3278. #region 出站
  3279. try
  3280. {
  3281. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3282. {
  3283. lock (lockObj)
  3284. {
  3285. if (!ProgressState)
  3286. {
  3287. ProgressState = true; ;
  3288. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3289. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3290. }
  3291. }
  3292. }
  3293. }
  3294. catch (Exception ex)
  3295. {
  3296. ProgressState = false;
  3297. string str = ex.StackTrace;
  3298. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3299. }
  3300. #endregion 出站
  3301. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3302. stopwatch1.Stop();
  3303. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3304. }
  3305. else
  3306. {
  3307. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3308. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3309. FunsEip[plcNo].Connect(); // 重连
  3310. }
  3311. }
  3312. catch (Exception ex)
  3313. {
  3314. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3315. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3316. }
  3317. Thread.Sleep(IntervalReadPLC);
  3318. }
  3319. }
  3320. /// <summary>
  3321. /// [S6] 顶盖装配设备 - 进站
  3322. /// </summary>
  3323. /// <param name="plcNo">PLC编号</param>
  3324. /// <param name="stationNameStr">工站全称</param>
  3325. /// <param name="stPLC_MesData"></param>
  3326. /// <param name="tagMesCommName"></param>
  3327. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3328. {
  3329. Stopwatch stopwatch1 = new Stopwatch();
  3330. Stopwatch stopwatch2 = new Stopwatch();
  3331. try
  3332. {
  3333. stopwatch1.Start();
  3334. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3335. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3336. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3337. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3338. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3339. //strCarrierBarcode = "N801A-003";
  3340. //载具码验证产品码
  3341. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3342. if (string.IsNullOrEmpty(strProductBarcode))
  3343. {
  3344. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3345. }
  3346. sn = strProductBarcode;
  3347. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3348. if (OpenDailogFalg)
  3349. {
  3350. using (var dialog = new BandBarodeDialog())
  3351. {
  3352. dialog._CarrierBarcode = strCarrierBarcode;
  3353. dialog._ProductBarcode = sn;
  3354. var rs = dialog.ShowDialog();
  3355. if (rs == DialogResult.OK)
  3356. {
  3357. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  3358. OpenDailogFalg = false;//关闭扫码
  3359. }
  3360. else {
  3361. ProgressState = false;
  3362. return;
  3363. }
  3364. }
  3365. }
  3366. // 产品SN(物料码)校验
  3367. List<TestItem> item = new List<TestItem>();
  3368. stopwatch2.Start();
  3369. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3370. stopwatch2.Stop();
  3371. //指令执行结果 1:OK 110:失败
  3372. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3373. //进站结果写入PLC
  3374. CommandFromPLC resultToPlC = new CommandFromPLC();
  3375. resultToPlC.cmd = 0;
  3376. resultToPlC.cmdParam = 0; //指令参数
  3377. resultToPlC.cmdResult = mesResultFrmWeb;
  3378. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3379. }
  3380. catch (Exception ex)
  3381. {
  3382. string str = ex.StackTrace;
  3383. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3384. CommandFromPLC resultToPlC = new CommandFromPLC();
  3385. resultToPlC.cmd = 0;
  3386. resultToPlC.cmdParam = 0; //指令参数
  3387. resultToPlC.cmdResult = 110;
  3388. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3389. }
  3390. stopwatch1.Stop();
  3391. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3392. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3393. ProgressState = false;
  3394. OpenDailogFalg = true; //开启下一个物料的扫码
  3395. }
  3396. /// <summary>
  3397. /// [S6] 顶盖装配设备 - 出站接口
  3398. /// </summary>
  3399. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3400. {
  3401. Stopwatch stopwatch1 = new Stopwatch();
  3402. Stopwatch stopwatch2 = new Stopwatch();
  3403. try
  3404. {
  3405. stopwatch1.Start();
  3406. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3407. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3408. string processItem = stationName; // 测试项目
  3409. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3410. string supplierCode = ""; // 供应商代码
  3411. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3412. string batch_num = GlobalContext.BatchNumber; // 批次号
  3413. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3414. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3415. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3416. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3417. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3418. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3419. bool pass = a1Result == 1;
  3420. //根据载具码获取产品码
  3421. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3422. if (string.IsNullOrEmpty(strProductBarcode))
  3423. {
  3424. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3425. }
  3426. sn = strProductBarcode;
  3427. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3428. List<TestItem> items = new List<TestItem>();
  3429. items.Add(new TestItem()
  3430. {
  3431. Parameter_name = "载具码",
  3432. Parameter_value = CarrierBarcode,
  3433. Parameter_unit = ""
  3434. });
  3435. items.Add(new TestItem()
  3436. {
  3437. Parameter_name = "产品码",
  3438. Parameter_value = sn,
  3439. Parameter_unit = ""
  3440. });
  3441. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3442. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3443. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  3444. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3445. stopwatch2.Start();
  3446. //进站结果写入PLC
  3447. CommandFromPLC resultToPlC = new CommandFromPLC();
  3448. resultToPlC.cmd = 0;
  3449. resultToPlC.cmdParam = 0; //指令参数
  3450. resultToPlC.cmdResult = mesResultFrmWeb;
  3451. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3452. stopwatch2.Stop();
  3453. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3454. //保存PLC返回MES数据到本地
  3455. ResponseMessage message = new ResponseMessage();
  3456. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3457. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3458. if (message.result == false)
  3459. {
  3460. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3461. }
  3462. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3463. }
  3464. catch (Exception ex)
  3465. {
  3466. stopwatch2.Start();
  3467. CommandFromPLC resultToPlC = new CommandFromPLC();
  3468. resultToPlC.cmd = 0;
  3469. resultToPlC.cmdParam = 0; //指令参数
  3470. resultToPlC.cmdResult = 110;
  3471. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3472. stopwatch2.Stop();
  3473. string str = ex.StackTrace;
  3474. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3475. }
  3476. stopwatch1.Stop();
  3477. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3478. ProgressState = false;
  3479. }
  3480. #endregion
  3481. #region S7
  3482. /// <summary>
  3483. /// [S7] 锁螺丝设备
  3484. /// </summary>
  3485. /// <param name="plcNo">PLC编号</param>
  3486. private void ReadStation_S7(int plcNo)
  3487. {
  3488. string stationCode = "[OP70]";
  3489. string stationName = "上盖板锁螺丝";
  3490. string stationNameStr = stationCode + stationName;
  3491. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3492. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3493. string tagAgvCommName = "agvCommFrmPC";
  3494. string tagBarsetName = "BarcodeSet";
  3495. string tagScrewDataset = "screwDataset";
  3496. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3497. (int, string) result;
  3498. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3499. atlasScrewLeft.Initial();
  3500. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3501. atlasScrewRight.Initial();
  3502. while (true)
  3503. {
  3504. try
  3505. {
  3506. if (!GlobalContext._IsCon_Funs1)
  3507. {
  3508. UpdatePLCMonitor(1, plcNo, 0);
  3509. continue;
  3510. }
  3511. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3512. {
  3513. Stopwatch stopwatch1 = new Stopwatch();
  3514. Stopwatch stopwatch2 = new Stopwatch();
  3515. stopwatch1.Start();
  3516. stopwatch2.Start();
  3517. #region 一次性读取所有数据
  3518. // 一次性读取所有数据
  3519. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3520. if (result.Item1 != 0)
  3521. {
  3522. //richTextBox1.AppendText("\n" + strRet);
  3523. }
  3524. else
  3525. {
  3526. //richTextBox1.AppendText("\n" + "读取成功");
  3527. }
  3528. #endregion 一次性读取所有数据
  3529. stopwatch2.Stop();
  3530. #region 左边进站
  3531. try
  3532. {
  3533. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3534. {
  3535. lock (lockObj)
  3536. {
  3537. if (!ProgressState)
  3538. {
  3539. ProgressState = true;
  3540. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3541. }
  3542. }
  3543. }
  3544. }
  3545. catch (Exception ex)
  3546. {
  3547. ProgressState = false;
  3548. string str = ex.StackTrace;
  3549. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3550. }
  3551. #endregion 左边进站
  3552. #region 左边出站
  3553. try
  3554. {
  3555. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3556. {
  3557. lock (lockObj)
  3558. {
  3559. if (!ProgressState)
  3560. {
  3561. ProgressState = true;
  3562. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3563. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3564. }
  3565. }
  3566. }
  3567. }
  3568. catch (Exception ex)
  3569. {
  3570. ProgressState = false;
  3571. string str = ex.StackTrace;
  3572. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3573. }
  3574. #endregion 左边出站
  3575. #region 右边进站
  3576. try
  3577. {
  3578. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3579. {
  3580. lock (lockObj)
  3581. {
  3582. if (!ProgressState)
  3583. {
  3584. ProgressState = true;
  3585. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3586. }
  3587. }
  3588. }
  3589. }
  3590. catch (Exception ex)
  3591. {
  3592. ProgressState = false;
  3593. string str = ex.StackTrace;
  3594. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3595. }
  3596. #endregion 右边进站
  3597. #region 右边出站
  3598. try
  3599. {
  3600. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3601. {
  3602. lock (lockObj)
  3603. {
  3604. if (!ProgressState)
  3605. {
  3606. ProgressState = true;
  3607. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3608. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3609. }
  3610. }
  3611. }
  3612. }
  3613. catch (Exception ex)
  3614. {
  3615. ProgressState = false;
  3616. string str = ex.StackTrace;
  3617. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3618. }
  3619. #endregion 右边出站
  3620. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3621. stopwatch1.Stop();
  3622. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3623. }
  3624. else
  3625. {
  3626. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3627. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3628. FunsEip[plcNo].Connect(); // 重连
  3629. }
  3630. }
  3631. catch (Exception ex)
  3632. {
  3633. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3634. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3635. }
  3636. Thread.Sleep(IntervalReadPLC);
  3637. }
  3638. }
  3639. /// <summary>
  3640. /// [S7] 锁螺丝设备 - 进站
  3641. /// </summary>
  3642. /// <param name="plcNo">PLC编号</param>
  3643. /// <param name="stationNameStr">工站全称</param>
  3644. /// <param name="stPLC_MesData"></param>
  3645. /// <param name="tagMesCommName"></param>
  3646. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3647. {
  3648. Stopwatch stopwatch1 = new Stopwatch();
  3649. Stopwatch stopwatch2 = new Stopwatch();
  3650. string atlasSn=string.Empty;
  3651. try
  3652. {
  3653. stopwatch1.Start();
  3654. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3655. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3656. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3657. string StationId = string.Empty; // 工位ID(可配置)
  3658. if (direction == "Left")
  3659. {
  3660. StationId = GlobalContext.S7_StationId_1;
  3661. }
  3662. if (direction == "Right")
  3663. {
  3664. StationId = GlobalContext.S7_StationId_2;
  3665. }
  3666. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3667. //载具码验证产品码
  3668. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3669. if (string.IsNullOrEmpty(strProductBarcode))
  3670. {
  3671. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3672. }
  3673. sn = strProductBarcode;
  3674. atlasSn= strProductBarcode;
  3675. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3676. if (direction == "Left")
  3677. {
  3678. isCollectingFlagLeft = false;//采集螺丝数据结束
  3679. }
  3680. if (direction == "Right")
  3681. {
  3682. isCollectingFlagRight = false;//采集螺丝数据结束
  3683. }
  3684. // 产品SN(物料码)校验
  3685. List<TestItem> item = new List<TestItem>();
  3686. stopwatch2.Start();
  3687. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3688. stopwatch2.Stop();
  3689. //指令执行结果 1:OK 110:失败
  3690. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3691. //进站结果写入PLC
  3692. CommandFromPLC resultToPlC = new CommandFromPLC();
  3693. resultToPlC.cmd = 0;
  3694. resultToPlC.cmdParam = 0; //指令参数
  3695. resultToPlC.cmdResult = mesResultFrmWeb;
  3696. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3697. }
  3698. catch (Exception ex)
  3699. {
  3700. string str = ex.StackTrace;
  3701. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3702. CommandFromPLC resultToPlC = new CommandFromPLC();
  3703. resultToPlC.cmd = 0;
  3704. resultToPlC.cmdParam = 0; //指令参数
  3705. resultToPlC.cmdResult = 110;
  3706. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3707. }
  3708. stopwatch1.Stop();
  3709. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3710. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3711. ProgressState = false;
  3712. //开始采集螺丝数据
  3713. if (direction == "Left")
  3714. {
  3715. isCollectingFlagLeft = true;
  3716. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3717. }
  3718. if (direction == "Right")
  3719. {
  3720. isCollectingFlagRight = true;
  3721. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3722. }
  3723. }
  3724. /// <summary>
  3725. /// [S7] 锁螺丝设备 - 出站
  3726. /// </summary>
  3727. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3728. {
  3729. Stopwatch stopwatch1 = new Stopwatch();
  3730. Stopwatch stopwatch2 = new Stopwatch();
  3731. try
  3732. {
  3733. stopwatch1.Start();
  3734. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3735. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3736. string processItem = stationName; // 测试项目
  3737. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3738. string supplierCode = ""; // 供应商代码
  3739. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3740. string batch_num = GlobalContext.BatchNumber; // 批次号
  3741. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3742. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3743. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3744. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3745. string StationId = string.Empty; // 工位ID(可配置)
  3746. if (direction == "Left")
  3747. {
  3748. StationId = GlobalContext.S7_StationId_1;
  3749. }
  3750. if (direction == "Right")
  3751. {
  3752. StationId = GlobalContext.S7_StationId_2;
  3753. }
  3754. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3755. //a1Result = 1;
  3756. bool pass = a1Result == 1;
  3757. //根据载具码获取产品码
  3758. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3759. if (string.IsNullOrEmpty(strProductBarcode))
  3760. {
  3761. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3762. }
  3763. sn = strProductBarcode;
  3764. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3765. List<TestItem> items = new List<TestItem>();
  3766. items.Add(new TestItem()
  3767. {
  3768. Parameter_name = "载具码",
  3769. Parameter_value = CarrierBarcode,
  3770. Parameter_unit = ""
  3771. });
  3772. items.Add(new TestItem()
  3773. {
  3774. Parameter_name = "产品码",
  3775. Parameter_value = sn,
  3776. Parameter_unit = ""
  3777. });
  3778. int result1 = 1;
  3779. //if (direction == "Right")
  3780. //{
  3781. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3782. SwitctProcessData(stationNameStr, items, equipmentCode, processItem , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode
  3783. , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  3784. //}
  3785. //if (direction == "Left")
  3786. //{
  3787. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3788. //}
  3789. //if (direction == "Right")
  3790. //{
  3791. // isCollectingFlagRight = false;//采集螺丝数据结束
  3792. //}
  3793. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3794. stopwatch2.Start();
  3795. //进站结果写入PLC
  3796. CommandFromPLC resultToPlC = new CommandFromPLC();
  3797. resultToPlC.cmd = 0;
  3798. resultToPlC.cmdParam = 0; //指令参数
  3799. resultToPlC.cmdResult = mesResultFrmWeb;
  3800. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3801. stopwatch2.Stop();
  3802. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3803. //保存PLC返回MES数据到本地
  3804. ResponseMessage message = new ResponseMessage();
  3805. if (direction == "Left")
  3806. {
  3807. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3808. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3809. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3810. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3811. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3812. if (message.result == false)
  3813. {
  3814. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3815. }
  3816. }
  3817. if (direction == "Right")
  3818. {
  3819. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3820. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3821. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3822. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3823. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3824. if (message.result == false)
  3825. {
  3826. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3827. }
  3828. }
  3829. //保存螺丝数据到txt
  3830. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3831. if (result.Item1 != 0)
  3832. {
  3833. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3834. }
  3835. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3836. }
  3837. catch (Exception ex)
  3838. {
  3839. stopwatch2.Start();
  3840. CommandFromPLC resultToPlC = new CommandFromPLC();
  3841. resultToPlC.cmd = 0;
  3842. resultToPlC.cmdParam = 0; //指令参数
  3843. resultToPlC.cmdResult = 110;
  3844. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3845. stopwatch2.Stop();
  3846. string str = ex.StackTrace;
  3847. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3848. }
  3849. stopwatch1.Stop();
  3850. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3851. ProgressState = false;
  3852. }
  3853. #endregion
  3854. #region S8
  3855. /// <summary>
  3856. /// [S8] 3D螺丝高度检测设备
  3857. /// </summary>
  3858. /// <param name="plcNo">PLC编号</param>
  3859. private void ReadStation_S8(int plcNo)
  3860. {
  3861. string stationCode = "[OP80]";
  3862. string stationName = "NG下料";
  3863. string stationNameStr = stationCode + stationName;
  3864. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3865. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3866. string tagAgvCommName = "agvCommFrmPC";
  3867. string tagBarsetName = "BarcodeSet";
  3868. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3869. (int, string) result;
  3870. while (true)
  3871. {
  3872. try
  3873. {
  3874. if (!GlobalContext._IsCon_Funs1)
  3875. {
  3876. UpdatePLCMonitor(1, plcNo, 0);
  3877. continue;
  3878. }
  3879. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3880. {
  3881. Stopwatch stopwatch1 = new Stopwatch();
  3882. Stopwatch stopwatch2 = new Stopwatch();
  3883. stopwatch1.Start();
  3884. stopwatch2.Start();
  3885. #region 一次性读取所有数据
  3886. // 一次性读取所有数据
  3887. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3888. if (result.Item1 != 0)
  3889. {
  3890. //richTextBox1.AppendText("\n" + strRet);
  3891. }
  3892. else
  3893. {
  3894. //richTextBox1.AppendText("\n" + "读取成功");
  3895. }
  3896. #endregion 一次性读取所有数据
  3897. stopwatch2.Stop();
  3898. #region 进站
  3899. try
  3900. {
  3901. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3902. {
  3903. lock (lockObj)
  3904. {
  3905. if (!ProgressState)
  3906. {
  3907. ProgressState = true;
  3908. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3909. }
  3910. }
  3911. }
  3912. }
  3913. catch (Exception ex)
  3914. {
  3915. ProgressState = false;
  3916. string str = ex.StackTrace;
  3917. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3918. }
  3919. #endregion 进站
  3920. #region 出站
  3921. try
  3922. {
  3923. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3924. {
  3925. lock (lockObj)
  3926. {
  3927. if (!ProgressState)
  3928. {
  3929. ProgressState = true;
  3930. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3931. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3932. }
  3933. }
  3934. }
  3935. }
  3936. catch (Exception ex)
  3937. {
  3938. ProgressState = false;
  3939. string str = ex.StackTrace;
  3940. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3941. }
  3942. #endregion 出站
  3943. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3944. stopwatch1.Stop();
  3945. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3946. }
  3947. else
  3948. {
  3949. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3950. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3951. FunsEip[plcNo].Connect(); // 重连
  3952. }
  3953. }
  3954. catch (Exception ex)
  3955. {
  3956. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3957. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3958. }
  3959. Thread.Sleep(IntervalReadPLC);
  3960. }
  3961. }
  3962. /// <summary>
  3963. /// [S8] 3D螺丝高度检测设备 - 进站
  3964. /// </summary>
  3965. /// <param name="plcNo">PLC编号</param>
  3966. /// <param name="stationNameStr">工站全称</param>
  3967. /// <param name="stPLC_MesData"></param>
  3968. /// <param name="tagMesCommName"></param>
  3969. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3970. {
  3971. Stopwatch stopwatch1 = new Stopwatch();
  3972. Stopwatch stopwatch2 = new Stopwatch();
  3973. try
  3974. {
  3975. stopwatch1.Start();
  3976. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3977. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3978. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3979. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3980. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3981. //载具码验证产品码
  3982. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3983. if (string.IsNullOrEmpty(strProductBarcode))
  3984. {
  3985. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3986. }
  3987. sn = strProductBarcode;
  3988. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3989. // 产品SN(物料码)校验
  3990. List<TestItem> item = new List<TestItem>();
  3991. stopwatch2.Start();
  3992. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3993. stopwatch2.Stop();
  3994. //指令执行结果 1:OK 110:失败
  3995. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3996. //进站结果写入PLC
  3997. CommandFromPLC resultToPlC = new CommandFromPLC();
  3998. resultToPlC.cmd = 0;
  3999. resultToPlC.cmdParam = 0; //指令参数
  4000. resultToPlC.cmdResult = mesResultFrmWeb;
  4001. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4002. }
  4003. catch (Exception ex)
  4004. {
  4005. string str = ex.StackTrace;
  4006. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4007. CommandFromPLC resultToPlC = new CommandFromPLC();
  4008. resultToPlC.cmd = 0;
  4009. resultToPlC.cmdParam = 0; //指令参数
  4010. resultToPlC.cmdResult = 110;
  4011. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4012. }
  4013. stopwatch1.Stop();
  4014. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4015. ProgressState = false;
  4016. }
  4017. /// <summary>
  4018. /// [S8] 3D螺丝高度检测设备 - 出站接口
  4019. /// </summary>
  4020. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  4021. {
  4022. Stopwatch stopwatch1 = new Stopwatch();
  4023. Stopwatch stopwatch2 = new Stopwatch();
  4024. try
  4025. {
  4026. stopwatch1.Start();
  4027. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4028. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4029. string processItem = stationName; // 测试项目
  4030. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4031. string supplierCode = ""; // 供应商代码
  4032. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4033. string batch_num = GlobalContext.BatchNumber; // 批次号
  4034. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4035. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4036. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4037. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  4038. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  4039. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4040. bool pass = a1Result == 1;
  4041. //根据载具码获取产品码
  4042. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4043. if (string.IsNullOrEmpty(strProductBarcode))
  4044. {
  4045. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4046. }
  4047. sn = strProductBarcode;
  4048. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4049. List<TestItem> items = new List<TestItem>();
  4050. items.Add(new TestItem()
  4051. {
  4052. Parameter_name = "载具码",
  4053. Parameter_value = CarrierBarcode,
  4054. Parameter_unit = ""
  4055. });
  4056. items.Add(new TestItem()
  4057. {
  4058. Parameter_name = "产品码",
  4059. Parameter_value = sn,
  4060. Parameter_unit = ""
  4061. });
  4062. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4063. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4064. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  4065. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4066. stopwatch2.Start();
  4067. //进站结果写入PLC
  4068. CommandFromPLC resultToPlC = new CommandFromPLC();
  4069. resultToPlC.cmd = 0;
  4070. resultToPlC.cmdParam = 0; //指令参数
  4071. resultToPlC.cmdResult = mesResultFrmWeb;
  4072. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4073. stopwatch2.Stop();
  4074. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4075. //保存PLC返回MES数据到本地
  4076. ResponseMessage message = new ResponseMessage();
  4077. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  4078. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  4079. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  4080. if (message.result == false)
  4081. {
  4082. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4083. }
  4084. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4085. }
  4086. catch (Exception ex)
  4087. {
  4088. stopwatch2.Start();
  4089. CommandFromPLC resultToPlC = new CommandFromPLC();
  4090. resultToPlC.cmd = 0;
  4091. resultToPlC.cmdParam = 0; //指令参数
  4092. resultToPlC.cmdResult = 110;
  4093. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4094. stopwatch2.Stop();
  4095. string str = ex.StackTrace;
  4096. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4097. }
  4098. stopwatch1.Stop();
  4099. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4100. ProgressState = false;
  4101. }
  4102. #endregion
  4103. #region S9
  4104. /// <summary>
  4105. /// [S9] 下料设备
  4106. /// </summary>
  4107. /// <param name="plcNo">PLC编号</param>
  4108. private void ReadStation_S9(int plcNo)
  4109. {
  4110. string stationCode = "[OP90]";
  4111. string stationName = "半成品下料";
  4112. string stationNameStr = stationCode + stationName;
  4113. string tagBaseName = "g_OP90_MES"; //标签变量名称
  4114. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4115. string tagAgvCommName = "agvCommFrmPC";
  4116. string tagBarsetName = "BarcodeSet";
  4117. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  4118. (int, string) result;
  4119. while (true)
  4120. {
  4121. try
  4122. {
  4123. if (!GlobalContext._IsCon_Funs1)
  4124. {
  4125. UpdatePLCMonitor(1, plcNo, 0);
  4126. continue;
  4127. }
  4128. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4129. {
  4130. Stopwatch stopwatch1 = new Stopwatch();
  4131. Stopwatch stopwatch2 = new Stopwatch();
  4132. stopwatch1.Start();
  4133. stopwatch2.Start();
  4134. #region 一次性读取所有数据
  4135. // 一次性读取所有数据
  4136. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4137. if (result.Item1 != 0)
  4138. {
  4139. //richTextBox1.AppendText("\n" + strRet);
  4140. }
  4141. else
  4142. {
  4143. //richTextBox1.AppendText("\n" + "读取成功");
  4144. }
  4145. #endregion 一次性读取所有数据
  4146. stopwatch2.Stop();
  4147. #region 进站
  4148. try
  4149. {
  4150. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4151. {
  4152. lock (lockObj)
  4153. {
  4154. if (!ProgressState)
  4155. {
  4156. ProgressState = true;
  4157. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  4158. }
  4159. }
  4160. }
  4161. }
  4162. catch (Exception ex)
  4163. {
  4164. ProgressState = false;
  4165. string str = ex.StackTrace;
  4166. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4167. }
  4168. #endregion 进站
  4169. #region 出站
  4170. try
  4171. {
  4172. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4173. {
  4174. lock (lockObj)
  4175. {
  4176. if (!ProgressState)
  4177. {
  4178. ProgressState = true;
  4179. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  4180. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4181. }
  4182. }
  4183. }
  4184. }
  4185. catch (Exception ex)
  4186. {
  4187. ProgressState = false;
  4188. string str = ex.StackTrace;
  4189. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4190. }
  4191. #endregion 出站
  4192. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4193. stopwatch1.Stop();
  4194. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4195. }
  4196. else
  4197. {
  4198. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4199. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4200. FunsEip[plcNo].Connect(); // 重连
  4201. }
  4202. }
  4203. catch (Exception ex)
  4204. {
  4205. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4206. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4207. }
  4208. Thread.Sleep(IntervalReadPLC);
  4209. }
  4210. }
  4211. /// <summary>
  4212. /// [S9] 下料设备 - 进站
  4213. /// </summary>
  4214. /// <param name="plcNo">PLC编号</param>
  4215. /// <param name="stationNameStr">工站全称</param>
  4216. /// <param name="stPLC_MesData"></param>
  4217. /// <param name="tagMesCommName"></param>
  4218. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  4219. {
  4220. Stopwatch stopwatch1 = new Stopwatch();
  4221. Stopwatch stopwatch2 = new Stopwatch();
  4222. try
  4223. {
  4224. stopwatch1.Start();
  4225. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4226. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4227. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  4228. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  4229. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4230. //载具码验证产品码
  4231. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4232. if (string.IsNullOrEmpty(strProductBarcode))
  4233. {
  4234. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4235. }
  4236. sn = strProductBarcode;
  4237. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4238. // 产品SN(物料码)校验
  4239. List<TestItem> item = new List<TestItem>();
  4240. stopwatch2.Start();
  4241. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  4242. stopwatch2.Stop();
  4243. //指令执行结果 1:OK 110:失败
  4244. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4245. //进站结果写入PLC
  4246. CommandFromPLC resultToPlC = new CommandFromPLC();
  4247. resultToPlC.cmd = 0;
  4248. resultToPlC.cmdParam = 0; //指令参数
  4249. resultToPlC.cmdResult = mesResultFrmWeb;
  4250. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4251. }
  4252. catch (Exception ex)
  4253. {
  4254. string str = ex.StackTrace;
  4255. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4256. CommandFromPLC resultToPlC = new CommandFromPLC();
  4257. resultToPlC.cmd = 0;
  4258. resultToPlC.cmdParam = 0; //指令参数
  4259. resultToPlC.cmdResult = 110;
  4260. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4261. }
  4262. stopwatch1.Stop();
  4263. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4264. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4265. ProgressState = false;
  4266. }
  4267. /// <summary>
  4268. /// [S9] 下料设备 - 出站接口
  4269. /// </summary>
  4270. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  4271. {
  4272. Stopwatch stopwatch1 = new Stopwatch();
  4273. Stopwatch stopwatch2 = new Stopwatch();
  4274. try
  4275. {
  4276. stopwatch1.Start();
  4277. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4278. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4279. string processItem = stationName; // 测试项目
  4280. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4281. string supplierCode = ""; // 供应商代码
  4282. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4283. string batch_num = GlobalContext.BatchNumber; // 批次号
  4284. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4285. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4286. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4287. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  4288. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  4289. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4290. bool pass = a1Result == 1;
  4291. //根据载具码获取产品码
  4292. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4293. if (string.IsNullOrEmpty(strProductBarcode))
  4294. {
  4295. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4296. }
  4297. sn = strProductBarcode;
  4298. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4299. List<TestItem> items = new List<TestItem>();
  4300. items.Add(new TestItem()
  4301. {
  4302. Parameter_name = "载具码",
  4303. Parameter_value = CarrierBarcode,
  4304. Parameter_unit = ""
  4305. });
  4306. items.Add(new TestItem()
  4307. {
  4308. Parameter_name = "产品码",
  4309. Parameter_value = sn,
  4310. Parameter_unit = ""
  4311. });
  4312. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4313. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4314. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  4315. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4316. stopwatch2.Start();
  4317. //进站结果写入PLC
  4318. CommandFromPLC resultToPlC = new CommandFromPLC();
  4319. resultToPlC.cmd = 0;
  4320. resultToPlC.cmdParam = 0; //指令参数
  4321. resultToPlC.cmdResult = mesResultFrmWeb;
  4322. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4323. stopwatch2.Stop();
  4324. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4325. //保存PLC返回MES数据到本地
  4326. ResponseMessage message = new ResponseMessage();
  4327. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4328. if (message.result == false)
  4329. {
  4330. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4331. }
  4332. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4333. if (result1 == 1)
  4334. {
  4335. //载具码解除绑定
  4336. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4337. if (message.result == false)
  4338. {
  4339. AddMessage(LogType.Error, message.text);
  4340. }
  4341. }
  4342. }
  4343. catch (Exception ex)
  4344. {
  4345. stopwatch2.Start();
  4346. CommandFromPLC resultToPlC = new CommandFromPLC();
  4347. resultToPlC.cmd = 0;
  4348. resultToPlC.cmdParam = 0; //指令参数
  4349. resultToPlC.cmdResult = 110;
  4350. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4351. stopwatch2.Stop();
  4352. string str = ex.StackTrace;
  4353. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4354. }
  4355. stopwatch1.Stop();
  4356. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4357. ProgressState = false;
  4358. }
  4359. #endregion
  4360. #endregion Xiaomi
  4361. #region PLC1 张超凡
  4362. #region [S1] Tray盘上料装备(板测)
  4363. /// <summary>
  4364. /// S1工位的数据- 触发信号上次的值
  4365. /// </summary>
  4366. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4367. /// <summary>
  4368. /// S1工位的数据(含触发信号)
  4369. /// </summary>
  4370. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4371. /// <summary>
  4372. /// S1工位的数据- 回写点位
  4373. /// </summary>
  4374. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4375. ///// <summary>
  4376. ///// 触发信号
  4377. ///// </summary>
  4378. //private ManualResetEvent[] MreTasks;
  4379. /// <summary>
  4380. /// [S1] Tray盘上料装备(板测)
  4381. /// </summary>
  4382. /// <param name="plcNo">PLC编号</param>
  4383. //private void ReadStation_S1(int plcNo)
  4384. //{
  4385. // // [S1] Tray盘上料装备
  4386. // // [S2] FCT
  4387. // // [S3] 值板机
  4388. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4389. // // [S5] Tray盘下料装备
  4390. // string stationCode = "[S1]";
  4391. // string stationName = "Tray盘上料装备";
  4392. // string stationNameStr = stationCode + stationName;
  4393. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4394. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4395. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4396. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4397. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4398. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4399. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4400. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4401. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4402. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4403. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4404. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4405. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4406. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4407. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4408. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4409. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4410. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4411. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4412. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4413. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4414. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4415. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4416. // s1PLCData.Add("a1Result", 0); // 产品结果
  4417. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4418. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4419. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4420. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4421. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4422. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4423. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4424. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4425. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4426. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4427. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4428. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4429. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4430. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4431. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4432. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4433. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4434. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4435. // while (IsRun)
  4436. // {
  4437. // try
  4438. // {
  4439. // if (!GlobalContext._IsCon_Funs1)
  4440. // {
  4441. // UpdatePLCMonitor(1, plcNo, 0);
  4442. // continue;
  4443. // }
  4444. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4445. // {
  4446. // Stopwatch stopwatch1 = new Stopwatch();
  4447. // Stopwatch stopwatch2 = new Stopwatch();
  4448. // stopwatch1.Start();
  4449. // stopwatch2.Start();
  4450. // #region 一次性读取所有数据
  4451. // // 一次性读取所有数据
  4452. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4453. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4454. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4455. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4456. // int[] datas = data1.Concat(data2).ToArray();
  4457. // datas = datas.Concat(data3).ToArray();
  4458. // datas = datas.Concat(data4).ToArray();
  4459. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4460. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4461. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4462. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4463. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4464. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4465. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4466. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4467. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4468. // s1PLCData["a1MES_FLAG"] = datas[109];
  4469. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4470. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4471. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4472. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4473. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4474. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4475. // s1PLCData["a1Result"] = datas[170];
  4476. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4477. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4478. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4479. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4480. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4481. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4482. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4483. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4484. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4485. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4486. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4487. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4488. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4489. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4490. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4491. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4492. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4493. // s1PLCData["a1AGVUpStart"] = datas[308];
  4494. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4495. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4496. // s1PLCData["a1AGVDownStart"] = datas[321];
  4497. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4498. // #endregion 一次性读取所有数据
  4499. // stopwatch2.Stop();
  4500. // #region 回写操作,写后清空flag
  4501. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4502. // #endregion 回写操作,写后清空flag
  4503. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4504. // try
  4505. // {
  4506. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4507. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4508. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4509. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4510. // {
  4511. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4512. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4513. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4514. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4515. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4516. // }
  4517. // }
  4518. // catch (Exception ex)
  4519. // {
  4520. // // 6代表上位机报警
  4521. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4522. // string str = ex.StackTrace;
  4523. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4524. // }
  4525. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4526. // #region 上料进站校验
  4527. // try
  4528. // {
  4529. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4530. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4531. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4532. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4533. // {
  4534. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4535. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4536. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4537. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4538. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4539. // }
  4540. // }
  4541. // catch (Exception ex)
  4542. // {
  4543. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4544. // string str = ex.StackTrace;
  4545. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4546. // }
  4547. // #endregion 上料进站校验
  4548. // #region Tray盘上料装备-出站接口
  4549. // try
  4550. // {
  4551. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4552. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4553. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4554. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4555. // {
  4556. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4557. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4558. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4559. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4560. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4561. // }
  4562. // }
  4563. // catch (Exception ex)
  4564. // {
  4565. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4566. // string str = ex.StackTrace;
  4567. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4568. // }
  4569. // #endregion Tray盘上料装备-出站接口
  4570. // #region Tray盘上料装备-将SN发给ICT标机
  4571. // try
  4572. // {
  4573. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4574. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4575. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4576. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4577. // {
  4578. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4579. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4580. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4581. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4582. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4583. // }
  4584. // }
  4585. // catch (Exception ex)
  4586. // {
  4587. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4588. // string str = ex.StackTrace;
  4589. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4590. // }
  4591. // #endregion Tray盘上料装备-将SN发给ICT标机
  4592. // #region Tray盘上料装备-点检数据
  4593. // //try
  4594. // //{
  4595. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4596. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4597. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4598. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4599. // // if (pLC_Flag && !mES_Flag) // 1 0
  4600. // // {
  4601. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4602. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4603. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4604. // // }
  4605. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4606. // // {
  4607. // // // 清空写给PLC的数据
  4608. // // // MES_Flag重置为0
  4609. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4610. // // }
  4611. // //}
  4612. // //catch (Exception ex)
  4613. // //{
  4614. // // // MES_Flag 为2上位机报错
  4615. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4616. // // string str = ex.StackTrace;
  4617. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4618. // //}
  4619. // #endregion Tray盘上料装备-点检数据
  4620. // #region 节拍接口
  4621. // try
  4622. // {
  4623. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4624. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4625. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4626. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4627. // {
  4628. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4629. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4630. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4631. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4632. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4633. // }
  4634. // }
  4635. // catch (Exception ex)
  4636. // {
  4637. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4638. // string str = ex.StackTrace;
  4639. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4640. // }
  4641. // #endregion 节拍接口
  4642. // #region AGV上料
  4643. // // AGV上料叫AGV信号
  4644. // try
  4645. // {
  4646. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4647. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4648. // if (a1AGVUpCall != a1AGVUpCallOld)
  4649. // {
  4650. // if (a1AGVUpCall == 1) // 0->1
  4651. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4652. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4653. // }
  4654. // }
  4655. // catch (Exception ex)
  4656. // {
  4657. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4658. // string str = ex.StackTrace;
  4659. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4660. // }
  4661. // // AGV上料完成信号
  4662. // try
  4663. // {
  4664. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4665. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4666. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4667. // {
  4668. // if (a1AGVUpEnd == 1) // 0->1
  4669. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4670. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4671. // }
  4672. // }
  4673. // catch (Exception ex)
  4674. // {
  4675. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4676. // string str = ex.StackTrace;
  4677. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4678. // }
  4679. // #endregion AGV上料
  4680. // #region AGV下料
  4681. // // AGV下料叫agv信号
  4682. // try
  4683. // {
  4684. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4685. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4686. // if (a1AGVDownCall != a1AGVDownCallOld)
  4687. // {
  4688. // if (a1AGVDownCall == 1) // 0->1
  4689. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4690. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4691. // }
  4692. // }
  4693. // catch (Exception ex)
  4694. // {
  4695. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4696. // string str = ex.StackTrace;
  4697. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4698. // }
  4699. // // AGV下料完成信号
  4700. // try
  4701. // {
  4702. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4703. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4704. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4705. // {
  4706. // if (a1AGVDownEnd == 1) // 0->1
  4707. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4708. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4709. // }
  4710. // }
  4711. // catch (Exception ex)
  4712. // {
  4713. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4714. // string str = ex.StackTrace;
  4715. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4716. // }
  4717. // #endregion AGV下料
  4718. // #region 心跳
  4719. // try
  4720. // {
  4721. // short states = 0;
  4722. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4723. // }
  4724. // catch (Exception ex)
  4725. // {
  4726. // string str = ex.StackTrace;
  4727. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4728. // }
  4729. // #endregion 心跳
  4730. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4731. // stopwatch1.Stop();
  4732. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4733. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4734. // }
  4735. // else
  4736. // {
  4737. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4738. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4739. // Funs[plcNo].Connect(); // 重连
  4740. // }
  4741. // }
  4742. // catch (Exception ex)
  4743. // {
  4744. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4745. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4746. // Funs[plcNo].ReConnect();
  4747. // }
  4748. // Thread.Sleep(IntervalReadPLC);
  4749. // }
  4750. //}
  4751. /// <summary>
  4752. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4753. /// </summary>
  4754. /// <param name="plcNo">PLC编号</param>
  4755. /// <param name="stationNameStr">工站全称</param>
  4756. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4757. {
  4758. Stopwatch stopwatch1 = new Stopwatch();
  4759. Stopwatch stopwatch2 = new Stopwatch();
  4760. try
  4761. {
  4762. stopwatch1.Start();
  4763. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4764. sn = sn.Replace("\0", "");
  4765. #region 查询载具上的产品信息
  4766. string cavityData = string.Empty;
  4767. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4768. if (string.IsNullOrEmpty(cavityData))
  4769. cavityData = "";
  4770. if (snResult != 0)
  4771. {
  4772. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4773. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4774. writeToPLC_Flag1.Adress = 2003;
  4775. writeToPLC_Flag1.Value = (short)6;
  4776. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4777. stopwatch1.Stop();
  4778. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4779. return;
  4780. }
  4781. #endregion 查询载具上的产品信息
  4782. string[] cavitySNs = cavityData.Split('.');
  4783. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4784. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4785. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4786. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4787. if (cavitySNs != null && cavitySNs.Length >= 2)
  4788. {
  4789. a1CavitySN1_VehicleStates = cavitySNs[0];
  4790. a1CavitySN2_VehicleStates = cavitySNs[1];
  4791. a1CavityResult1_VehicleStates = 2;
  4792. a1CavityResult2_VehicleStates = 2;
  4793. }
  4794. if (a1CavitySN1_VehicleStates == "假产品")
  4795. a1CavityResult1_VehicleStates = 3;
  4796. if (a1CavitySN2_VehicleStates == "假产品")
  4797. a1CavityResult2_VehicleStates = 3;
  4798. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4799. // 回写
  4800. stopwatch2.Start();
  4801. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4802. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4803. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4804. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4805. //// MES_Flag
  4806. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4807. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4808. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4809. writeToPLC_Flag.Adress = 2003;
  4810. writeToPLC_Flag.Value = mES_Flag;
  4811. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4812. {
  4813. Name = "a1CavitySN1_VehicleStates",
  4814. Adress = 2024,
  4815. ValueType = PLCValueType.String,
  4816. ValueTypeStrLength = 20,
  4817. Value = a1CavitySN1_VehicleStates
  4818. });
  4819. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4820. {
  4821. Name = "a1CavitySN2_VehicleStates",
  4822. Adress = 2044,
  4823. ValueType = PLCValueType.String,
  4824. ValueTypeStrLength = 20,
  4825. Value = a1CavitySN2_VehicleStates
  4826. });
  4827. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4828. {
  4829. Name = "a1CavityResult1_VehicleStates",
  4830. Adress = 2064,
  4831. ValueType = PLCValueType.Short,
  4832. Value = a1CavityResult1_VehicleStates
  4833. });
  4834. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4835. {
  4836. Name = "a1CavityResult2_VehicleStates",
  4837. Adress = 2065,
  4838. ValueType = PLCValueType.Short,
  4839. Value = a1CavityResult2_VehicleStates
  4840. });
  4841. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4842. stopwatch2.Stop();
  4843. }
  4844. catch (Exception ex)
  4845. {
  4846. string str = ex.StackTrace;
  4847. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4848. // MES_Flag
  4849. stopwatch2.Start();
  4850. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4851. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4852. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4853. writeToPLC_Flag.Adress = 2003;
  4854. writeToPLC_Flag.Value = (short)6;
  4855. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4856. stopwatch2.Stop();
  4857. }
  4858. stopwatch1.Stop();
  4859. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4860. }
  4861. /// <summary>
  4862. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4863. /// </summary>
  4864. /// <param name="plcNo">PLC编号</param>
  4865. /// <param name="stationNameStr">工站全称</param>
  4866. private void S1上料进站校验(int plcNo, string stationNameStr)
  4867. {
  4868. Stopwatch stopwatch1 = new Stopwatch();
  4869. Stopwatch stopwatch2 = new Stopwatch();
  4870. try
  4871. {
  4872. stopwatch1.Start();
  4873. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4874. sn = sn.Replace("\0", "");
  4875. // 保存进站数据+调用进站MES接口
  4876. List<TestItem> item = new List<TestItem>();
  4877. stopwatch2.Start();
  4878. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4879. stopwatch2.Stop();
  4880. short a1MES_FLAG_Check = (short)result;
  4881. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4882. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4883. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4884. writeToPLC_Flag.Adress = 2077;
  4885. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4886. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4887. }
  4888. catch (Exception ex)
  4889. {
  4890. string str = ex.StackTrace;
  4891. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4892. // MES_Flag
  4893. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4894. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4895. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4896. writeToPLC_Flag.Adress = 2077;
  4897. writeToPLC_Flag.Value = (short)6;
  4898. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4899. }
  4900. stopwatch1.Stop();
  4901. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4902. }
  4903. /// <summary>
  4904. /// [S1] Tray盘上料装备(板测)- 出站接口
  4905. /// </summary>
  4906. /// <param name="plcNo"></param>
  4907. /// <param name="stationCode"></param>
  4908. /// <param name="stationName"></param>
  4909. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4910. {
  4911. Stopwatch stopwatch1 = new Stopwatch();
  4912. Stopwatch stopwatch2 = new Stopwatch();
  4913. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4914. string stationNameStr = stationCode + stationName;
  4915. string processItem = stationName; // 测试项目
  4916. try
  4917. {
  4918. stopwatch1.Start();
  4919. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4920. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4921. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4922. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4923. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4924. sn = sn.Replace("\0", "");
  4925. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4926. partNo1 = partNo1.Replace("\0", "");
  4927. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4928. partNo2 = partNo2.Replace("\0", "");
  4929. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4930. bool pass = a1Result == 1;
  4931. stopwatch2.Start();
  4932. // 产品1
  4933. List<TestItem> items = new List<TestItem>();
  4934. items.Add(new TestItem()
  4935. {
  4936. Parameter_name = "载具码",
  4937. Parameter_value = sn,
  4938. Parameter_unit = ""
  4939. });
  4940. items.Add(new TestItem()
  4941. {
  4942. Parameter_name = "载具穴号",
  4943. Parameter_value = "1",
  4944. Parameter_unit = ""
  4945. });
  4946. items.Add(new TestItem()
  4947. {
  4948. Parameter_name = "产品结果",
  4949. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4950. Parameter_unit = ""
  4951. });
  4952. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  4953. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4954. // 产品2
  4955. items = new List<TestItem>();
  4956. items.Add(new TestItem()
  4957. {
  4958. Parameter_name = "载具码",
  4959. Parameter_value = sn,
  4960. Parameter_unit = ""
  4961. });
  4962. items.Add(new TestItem()
  4963. {
  4964. Parameter_name = "载具穴号",
  4965. Parameter_value = "2",
  4966. Parameter_unit = ""
  4967. });
  4968. items.Add(new TestItem()
  4969. {
  4970. Parameter_name = "产品结果",
  4971. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4972. Parameter_unit = ""
  4973. });
  4974. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  4975. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4976. short result = 0;
  4977. List<int> results = new List<int>() { result1, result2 };
  4978. if (result1 == 1 && result2 == 1)
  4979. result = 1;
  4980. else if (results.Contains(3))
  4981. result = 3;
  4982. else if (results.Contains(2))
  4983. result = 2;
  4984. else if (results.Contains(4))
  4985. result = 4;
  4986. else
  4987. result = 4;
  4988. stopwatch2.Stop();
  4989. #region 存储绑定数据到 边线MES系统中
  4990. if (result == 1)
  4991. {
  4992. string data = string.Concat(partNo1, ".", partNo2);
  4993. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4994. if (resultMesR != 0)
  4995. {
  4996. result = 4;
  4997. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4998. }
  4999. }
  5000. #endregion 存储绑定数据到 边线MES系统中
  5001. // MES_Flag 为MES报错
  5002. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5003. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  5004. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5005. writeToPLC_Flag.Name = "a1MES_FLAG";
  5006. writeToPLC_Flag.Adress = 2109;
  5007. writeToPLC_Flag.Value = result;
  5008. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  5009. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5010. }
  5011. catch (Exception ex)
  5012. {
  5013. stopwatch2.Restart();
  5014. // MES_Flag 为4上位机报错
  5015. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  5016. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5017. writeToPLC_Flag.Name = "a1MES_FLAG";
  5018. writeToPLC_Flag.Adress = 2109;
  5019. writeToPLC_Flag.Value = (short)4;
  5020. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  5021. stopwatch2.Stop();
  5022. string str = ex.StackTrace;
  5023. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5024. }
  5025. stopwatch1.Stop();
  5026. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5027. }
  5028. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  5029. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  5030. //{
  5031. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5032. // string stationNameStr = stationCode + stationName;
  5033. // string processItem = stationName; // 测试项目
  5034. // try
  5035. // {
  5036. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5037. // string accno = "1"; // 工序编号
  5038. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  5039. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  5040. // List<OneCheckItem> items = new List<OneCheckItem>()
  5041. // {
  5042. // new OneCheckItem()
  5043. // {
  5044. // Onecheck_name="胶圈装配行程设定上限",
  5045. // Onecheck_content="上限值",
  5046. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  5047. // },
  5048. // };
  5049. // OneCheckData oneCheckData = new OneCheckData()
  5050. // {
  5051. // Line_code = GlobalContext.LineCode,
  5052. // Line_name = GlobalContext.LineName,
  5053. // Equipment_code = equipmentCode,
  5054. // Equipment_name = equipmentCode,
  5055. // Workorder_code = workorder_code,
  5056. // Procedure_code = accno,
  5057. // Procedure_name = processItem,
  5058. // Oneckeck_values = items,
  5059. // Onecheck_empcode = "",
  5060. // Onecheck_empname = "",
  5061. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  5062. // };
  5063. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  5064. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  5065. // short result = result1 == 1 ? (short)1 : (short)2;
  5066. // // MES_Flag 为4MES报错
  5067. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  5068. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5069. // }
  5070. // catch (Exception ex)
  5071. // {
  5072. // // MES_Flag 为2上位机报错
  5073. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  5074. // string str = ex.StackTrace;
  5075. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5076. // }
  5077. //}
  5078. // ReadStation_S1_2 节拍接口+AGV
  5079. /// <summary>
  5080. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  5081. /// </summary>
  5082. /// <param name="plcNo">PLC编号</param>
  5083. /// <param name="stationNameStr">工站全称</param>
  5084. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  5085. {
  5086. Stopwatch stopwatch1 = new Stopwatch();
  5087. Stopwatch stopwatch2 = new Stopwatch();
  5088. try
  5089. {
  5090. stopwatch1.Start();
  5091. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  5092. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  5093. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  5094. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  5095. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  5096. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  5097. // ZS 将SN发给ICT标机(串口)
  5098. short a1MES_FLAG_ICT = 1;
  5099. stopwatch2.Start();
  5100. // MES_Flag
  5101. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  5102. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5103. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  5104. writeToPLC_Flag.Adress = 2182;
  5105. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  5106. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  5107. stopwatch2.Stop();
  5108. }
  5109. catch (Exception ex)
  5110. {
  5111. string str = ex.StackTrace;
  5112. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5113. stopwatch2.Start();
  5114. // MES_Flag
  5115. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  5116. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5117. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  5118. writeToPLC_Flag.Adress = 2182;
  5119. writeToPLC_Flag.Value = (short)4;
  5120. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  5121. stopwatch2.Stop();
  5122. }
  5123. stopwatch1.Stop();
  5124. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5125. }
  5126. /// <summary>
  5127. /// [S1] Tray盘上料装备(板测)- 节拍接口
  5128. /// </summary>
  5129. /// <param name="plcNo">PLC编号</param>
  5130. /// <param name="stationNameStr">工站全称</param>
  5131. private void S1节拍接口(int plcNo, string stationNameStr)
  5132. {
  5133. Stopwatch stopwatch1 = new Stopwatch();
  5134. Stopwatch stopwatch2 = new Stopwatch();
  5135. string resultStr = string.Empty;
  5136. try
  5137. {
  5138. stopwatch1.Start();
  5139. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  5140. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  5141. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  5142. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  5143. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  5144. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  5145. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  5146. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5147. if (!actionBool)
  5148. {
  5149. stopwatch2.Start();
  5150. // MES_Flag
  5151. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5152. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5153. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  5154. writeToPLC_Flag1.Adress = 2254;
  5155. writeToPLC_Flag1.Value = (short)1;
  5156. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  5157. stopwatch2.Stop();
  5158. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5159. return;
  5160. }
  5161. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  5162. {
  5163. stopwatch2.Start();
  5164. // MES_Flag
  5165. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5166. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  5167. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  5168. writeToPLC_Flag2.Adress = 2254;
  5169. writeToPLC_Flag2.Value = (short)1;
  5170. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  5171. stopwatch2.Stop();
  5172. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5173. return;
  5174. }
  5175. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  5176. { // 查产品SN
  5177. a1OEEPartNo = "Test"; // ZS
  5178. }
  5179. short a1OEEMES_FLAG = 0;
  5180. // 上传OEE
  5181. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  5182. a1OEEMES_FLAG = result.Item1;
  5183. resultStr = result.Item2;
  5184. stopwatch2.Start();
  5185. // MES_Flag
  5186. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5187. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5188. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5189. writeToPLC_Flag.Adress = 2254;
  5190. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  5191. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5192. stopwatch2.Stop();
  5193. }
  5194. catch (Exception ex)
  5195. {
  5196. string str = ex.StackTrace;
  5197. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5198. // MES_Flag
  5199. stopwatch2.Start();
  5200. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  5201. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5202. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5203. writeToPLC_Flag.Adress = 2254;
  5204. writeToPLC_Flag.Value = (short)4;
  5205. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5206. stopwatch2.Stop();
  5207. }
  5208. stopwatch1.Stop();
  5209. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5210. }
  5211. /// <summary>
  5212. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  5213. /// </summary>
  5214. /// <param name="plcNo">PLC编号</param>
  5215. /// <param name="stationNameStr">工站全称</param>
  5216. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  5217. {
  5218. Stopwatch stopwatch1 = new Stopwatch();
  5219. Stopwatch stopwatch2 = new Stopwatch();
  5220. try
  5221. {
  5222. stopwatch1.Start();
  5223. // ZS 呼叫AGV
  5224. short a1AGVUpCall = 2;
  5225. stopwatch2.Start();
  5226. // a1AGVUpCall
  5227. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5228. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5229. writeToPLC_Flag.Name = "a1AGVUpCall";
  5230. writeToPLC_Flag.Adress = 2307;
  5231. writeToPLC_Flag.Value = a1AGVUpCall;
  5232. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5233. stopwatch2.Stop();
  5234. }
  5235. catch (Exception ex)
  5236. {
  5237. string str = ex.StackTrace;
  5238. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5239. // a1AGVUpCall
  5240. stopwatch2.Start();
  5241. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  5242. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5243. writeToPLC_Flag.Name = "a1AGVUpCall";
  5244. writeToPLC_Flag.Adress = 2307;
  5245. writeToPLC_Flag.Value = (short)4;
  5246. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5247. stopwatch2.Stop();
  5248. }
  5249. stopwatch1.Stop();
  5250. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5251. }
  5252. /// <summary>
  5253. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  5254. /// </summary>
  5255. /// <param name="plcNo">PLC编号</param>
  5256. /// <param name="stationNameStr">工站全称</param>
  5257. private void S1AGV上料完成(int plcNo, string stationNameStr)
  5258. {
  5259. Stopwatch stopwatch1 = new Stopwatch();
  5260. Stopwatch stopwatch2 = new Stopwatch();
  5261. try
  5262. {
  5263. stopwatch1.Start();
  5264. // ZS AGV上料完成,让小车离开
  5265. short a1AGVUpEnd = 2;
  5266. stopwatch2.Start();
  5267. // a1AGVUpEnd
  5268. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5269. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5270. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5271. writeToPLC_Flag.Adress = 2309;
  5272. writeToPLC_Flag.Value = a1AGVUpEnd;
  5273. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5274. stopwatch2.Stop();
  5275. }
  5276. catch (Exception ex)
  5277. {
  5278. string str = ex.StackTrace;
  5279. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5280. // a1AGVUpEnd
  5281. stopwatch2.Start();
  5282. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  5283. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5284. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5285. writeToPLC_Flag.Adress = 2309;
  5286. writeToPLC_Flag.Value = (short)4;
  5287. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5288. stopwatch2.Stop();
  5289. }
  5290. stopwatch1.Stop();
  5291. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5292. }
  5293. /// <summary>
  5294. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  5295. /// </summary>
  5296. /// <param name="plcNo">PLC编号</param>
  5297. /// <param name="stationNameStr">工站全称</param>
  5298. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  5299. {
  5300. Stopwatch stopwatch1 = new Stopwatch();
  5301. Stopwatch stopwatch2 = new Stopwatch();
  5302. try
  5303. {
  5304. stopwatch1.Start();
  5305. // ZS 呼叫AGV
  5306. short a1AGVDownCall = 2;
  5307. stopwatch2.Start();
  5308. // a1AGVDownCall
  5309. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5310. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5311. writeToPLC_Flag.Name = "a1AGVDownCall";
  5312. writeToPLC_Flag.Adress = 2320;
  5313. writeToPLC_Flag.Value = a1AGVDownCall;
  5314. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5315. stopwatch2.Stop();
  5316. }
  5317. catch (Exception ex)
  5318. {
  5319. string str = ex.StackTrace;
  5320. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5321. // a1AGVDownCall
  5322. stopwatch2.Start();
  5323. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5324. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5325. writeToPLC_Flag.Name = "a1AGVDownCall";
  5326. writeToPLC_Flag.Adress = 2320;
  5327. writeToPLC_Flag.Value = (short)4;
  5328. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5329. stopwatch2.Stop();
  5330. }
  5331. stopwatch1.Stop();
  5332. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5333. }
  5334. /// <summary>
  5335. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5336. /// </summary>
  5337. /// <param name="plcNo">PLC编号</param>
  5338. /// <param name="stationNameStr">工站全称</param>
  5339. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5340. {
  5341. Stopwatch stopwatch1 = new Stopwatch();
  5342. Stopwatch stopwatch2 = new Stopwatch();
  5343. try
  5344. {
  5345. stopwatch1.Start();
  5346. // ZS AGV上料完成,让小车离开
  5347. short a1AGVDownEnd = 2;
  5348. stopwatch2.Start();
  5349. // a1AGVDownEnd
  5350. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5351. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5352. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5353. writeToPLC_Flag.Adress = 2322;
  5354. writeToPLC_Flag.Value = a1AGVDownEnd;
  5355. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5356. stopwatch2.Stop();
  5357. }
  5358. catch (Exception ex)
  5359. {
  5360. string str = ex.StackTrace;
  5361. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5362. // a1AGVDownEnd
  5363. stopwatch2.Start();
  5364. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5365. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5366. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5367. writeToPLC_Flag.Adress = 2322;
  5368. writeToPLC_Flag.Value = (short)4;
  5369. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5370. stopwatch2.Stop();
  5371. }
  5372. stopwatch1.Stop();
  5373. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5374. }
  5375. #endregion [S1] Tray盘上料装备(板测)
  5376. #endregion PLC1 张超凡
  5377. #region PLC2 李晓奇
  5378. #region [S2] FCT(板测)
  5379. /// <summary>
  5380. /// S2工位的数据- 触发信号上次的值
  5381. /// </summary>
  5382. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5383. /// <summary>
  5384. /// S2工位的数据(含触发信号)
  5385. /// </summary>
  5386. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5387. /// <summary>
  5388. /// S2工位的数据- 回写点位
  5389. /// </summary>
  5390. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5391. /// <summary>
  5392. /// [S2] FCT(板测)
  5393. /// </summary>
  5394. /// <param name="plcNo">PLC编号</param>
  5395. //private void ReadStation_S2(int plcNo)
  5396. //{
  5397. // // [S1] Tray盘上料装备
  5398. // // [S2] FCT
  5399. // // [S3] 值板机
  5400. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5401. // // [S5] Tray盘下料装备
  5402. // /// 上位机心跳
  5403. // /// 获取设备报警数据与状态信息
  5404. // string stationCode = "[S2]";
  5405. // string stationName = "FCT";
  5406. // string stationNameStr = stationCode + stationName;
  5407. // #region 创建字典
  5408. // // 触发信号字典 赋值
  5409. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5410. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5411. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5412. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5413. // // PLC数据字典 赋值
  5414. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5415. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5416. // s2PLCData.Add("b1ProductSN_Check", 0);
  5417. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5418. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5419. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5420. // s2PLCData.Add("b1ProductSN_Bind", "");
  5421. // s2PLCData.Add("b1Part1SN_Bind", "");
  5422. // s2PLCData.Add("b1Part2SN_Bind", "");
  5423. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5424. // s2PLCData.Add("b1MES_FLAG", 0);
  5425. // s2PLCData.Add("b1ProductSN", 0);
  5426. // s2PLCData.Add("b1Part1Result", 0);
  5427. // s2PLCData.Add("b1Part2Result", 0);
  5428. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5429. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5430. // s2PLCData.Add("b1OEEProductSN", "");
  5431. // s2PLCData.Add("b1OEEType", 0);
  5432. // #endregion 创建字典
  5433. // while (IsRun)
  5434. // {
  5435. // try
  5436. // {
  5437. // if (!GlobalContext._IsCon_Funs2)
  5438. // {
  5439. // UpdatePLCMonitor(1, plcNo, 0);
  5440. // continue;
  5441. // }
  5442. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5443. // {
  5444. // Stopwatch stopwatch1 = new Stopwatch();
  5445. // Stopwatch stopwatch2 = new Stopwatch();
  5446. // stopwatch1.Start();
  5447. // stopwatch2.Start();
  5448. // #region 一次性读取所有数据
  5449. // // 一次性读取所有数据
  5450. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5451. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5452. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5453. // int[] datas = data1.Concat(data2).ToArray();
  5454. // datas = datas.Concat(data3).ToArray();
  5455. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5456. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5457. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5458. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5459. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5460. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5461. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5462. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5463. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5464. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5465. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5466. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5467. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5468. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5469. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5470. // s2PLCData["b1MES_FLAG"] = datas[169];
  5471. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5472. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5473. // s2PLCData["b1Part1Result"] = datas[190];
  5474. // s2PLCData["b1Part2Result"] = datas[191];
  5475. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5476. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5477. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5478. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5479. // s2PLCData["b1OEEType"] = datas[224];
  5480. // #endregion 一次性读取所有数据
  5481. // stopwatch2.Stop();
  5482. // #region 回写操作,写后清空flag
  5483. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5484. // #endregion 回写操作,写后清空flag
  5485. // #region 进站校验
  5486. // try
  5487. // {
  5488. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5489. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5490. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5491. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5492. // {
  5493. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5494. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5495. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5496. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5497. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5498. // }
  5499. // }
  5500. // catch (Exception ex)
  5501. // {
  5502. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5503. // string str = ex.StackTrace;
  5504. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5505. // }
  5506. // #endregion 进站校验
  5507. // #region 二穴载具解绑/绑定(产品换载具)
  5508. // try
  5509. // {
  5510. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5511. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5512. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5513. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5514. // {
  5515. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5516. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5517. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5518. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5519. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5520. // }
  5521. // }
  5522. // catch (Exception ex)
  5523. // {
  5524. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5525. // string str = ex.StackTrace;
  5526. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5527. // }
  5528. // #endregion 二穴载具解绑/绑定(产品换载具)
  5529. // #region FCT-出站接口
  5530. // try
  5531. // {
  5532. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5533. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5534. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5535. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5536. // {
  5537. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5538. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5539. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5540. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5541. // }
  5542. // }
  5543. // catch (Exception ex)
  5544. // {
  5545. // // MES_Flag 为6上位机报错
  5546. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5547. // string str = ex.StackTrace;
  5548. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5549. // }
  5550. // #endregion FCT-出站接口
  5551. // #region 节拍接口
  5552. // try
  5553. // {
  5554. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5555. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5556. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5557. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5558. // {
  5559. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5560. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5561. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5562. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5563. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5564. // }
  5565. // }
  5566. // catch (Exception ex)
  5567. // {
  5568. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5569. // string str = ex.StackTrace;
  5570. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5571. // }
  5572. // #endregion 节拍接口
  5573. // #region 心跳
  5574. // try
  5575. // {
  5576. // short states = 0;
  5577. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5578. // }
  5579. // catch (Exception ex)
  5580. // {
  5581. // string str = ex.StackTrace;
  5582. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5583. // }
  5584. // #endregion 心跳
  5585. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5586. // stopwatch1.Stop();
  5587. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5588. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5589. // }
  5590. // else
  5591. // {
  5592. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5593. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5594. // Funs[plcNo].Connect();
  5595. // }
  5596. // }
  5597. // catch (Exception ex)
  5598. // {
  5599. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5600. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5601. // Funs[plcNo].ReConnect();
  5602. // }
  5603. // Thread.Sleep(IntervalReadPLC);
  5604. // }
  5605. //}
  5606. /// <summary>
  5607. /// [S2] FCT(板测)- 进站校验
  5608. /// </summary>
  5609. /// <param name="plcNo">PLC编号</param>
  5610. /// <param name="stationNameStr">工站全称</param>
  5611. private void S2进站校验(int plcNo, string stationNameStr)
  5612. {
  5613. Stopwatch stopwatch1 = new Stopwatch();
  5614. Stopwatch stopwatch2 = new Stopwatch();
  5615. try
  5616. {
  5617. stopwatch1.Start();
  5618. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5619. sn = sn.Replace("\0", "");
  5620. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5621. // 查询物料码By载具码 并判断是不是假产品
  5622. string cavityData = string.Empty;
  5623. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5624. if (string.IsNullOrEmpty(cavityData))
  5625. cavityData = "";
  5626. if (snResult != 0)
  5627. {
  5628. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5629. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5630. writeToPLC_Flag1.Adress = 2003;
  5631. writeToPLC_Flag1.Value = (short)6;
  5632. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5633. stopwatch1.Stop();
  5634. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5635. return;
  5636. }
  5637. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5638. string[] cavitySNs = cavityData.Split('.');
  5639. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5640. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5641. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5642. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5643. if (cavitySNs != null && cavitySNs.Length >= 2)
  5644. {
  5645. b1Part1SN_Check = cavitySNs[0];
  5646. b1Part2SN_Check = cavitySNs[1];
  5647. b1Part1Result_Check = 2;
  5648. b1Part2Result_Check = 2;
  5649. }
  5650. if (b1Part1SN_Check == "假产品")
  5651. b1Part1Result_Check = 3;
  5652. if (b1Part2SN_Check == "假产品")
  5653. b1Part2Result_Check = 3;
  5654. // 调用MES进站
  5655. stopwatch2.Start();
  5656. // 调用MES进站 - 产品1
  5657. List<TestItem> item;
  5658. int result1 = b1Part1Result_Check;
  5659. if (result1 != 3)
  5660. {
  5661. item = new List<TestItem>();
  5662. item.Add(new TestItem()
  5663. {
  5664. Parameter_name = "载具码",
  5665. Parameter_value = sn,
  5666. });
  5667. item.Add(new TestItem()
  5668. {
  5669. Parameter_name = "载具穴号",
  5670. Parameter_value = "1",
  5671. });
  5672. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5673. }
  5674. // 调用MES进站 - 产品2
  5675. int result2 = b1Part2Result_Check;
  5676. if (result2 != 3)
  5677. {
  5678. item = new List<TestItem>();
  5679. item.Add(new TestItem()
  5680. {
  5681. Parameter_name = "载具码",
  5682. Parameter_value = sn,
  5683. });
  5684. item.Add(new TestItem()
  5685. {
  5686. Parameter_name = "载具穴号",
  5687. Parameter_value = "2",
  5688. });
  5689. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5690. }
  5691. stopwatch2.Stop();
  5692. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5693. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5694. int result = result1;
  5695. if (result == 1)
  5696. result = result2;
  5697. short b1MES_FLAG_Check = (short)result;
  5698. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5699. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5700. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5701. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5702. //// MES_Flag
  5703. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5704. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5705. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5706. writeToPLC_Flag.Adress = 2003;
  5707. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5708. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5709. {
  5710. Name = "b1Part1SN_Check",
  5711. Adress = 2024,
  5712. ValueType = PLCValueType.String,
  5713. ValueTypeStrLength = 20,
  5714. Value = b1Part1SN_Check
  5715. });
  5716. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5717. {
  5718. Name = "b1Part2SN_Check",
  5719. Adress = 2044,
  5720. ValueType = PLCValueType.String,
  5721. ValueTypeStrLength = 20,
  5722. Value = b1Part2SN_Check
  5723. });
  5724. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5725. {
  5726. Name = "b1Part1Result_Check",
  5727. Adress = 2064,
  5728. ValueType = PLCValueType.Short,
  5729. Value = b1Part1Result_Check
  5730. });
  5731. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5732. {
  5733. Name = "b1Part2Result_Check",
  5734. Adress = 2065,
  5735. ValueType = PLCValueType.Short,
  5736. Value = b1Part2Result_Check
  5737. });
  5738. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5739. }
  5740. catch (Exception ex)
  5741. {
  5742. string str = ex.StackTrace;
  5743. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5744. // MES_Flag
  5745. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5746. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5747. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5748. writeToPLC_Flag.Adress = 2003;
  5749. writeToPLC_Flag.Value = (short)6;
  5750. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5751. }
  5752. stopwatch1.Stop();
  5753. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5754. }
  5755. /// <summary>
  5756. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5757. /// </summary>
  5758. /// <param name="plcNo">PLC编号</param>
  5759. /// <param name="stationNameStr">工站全称</param>
  5760. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5761. {
  5762. Stopwatch stopwatch1 = new Stopwatch();
  5763. Stopwatch stopwatch2 = new Stopwatch();
  5764. try
  5765. {
  5766. stopwatch1.Start();
  5767. // 产品换载具
  5768. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5769. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5770. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5771. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5772. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5773. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5774. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5775. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5776. stopwatch2.Start();
  5777. #region 查询载具上的产品信息
  5778. //string cavityData = string.Empty;
  5779. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5780. //if (string.IsNullOrEmpty(cavityData))
  5781. // cavityData = "";
  5782. //if (snResult != 0)
  5783. //{
  5784. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5785. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5786. // writeToPLC_Flag.Adress = 2077;
  5787. // writeToPLC_Flag.Value = (short)6;
  5788. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5789. // stopwatch1.Stop();
  5790. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5791. // return;
  5792. //}
  5793. #endregion 查询载具上的产品信息
  5794. #region 解绑(边线MES系统)
  5795. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5796. if (snResult != 0)
  5797. {
  5798. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5799. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5800. writeToPLC_Flag1.Adress = 2077;
  5801. writeToPLC_Flag1.Value = (short)6;
  5802. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5803. stopwatch1.Stop();
  5804. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5805. return;
  5806. }
  5807. #endregion 解绑(边线MES系统)
  5808. #region 存储绑定数据到 边线MES系统中
  5809. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5810. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5811. if (snResult != 0)
  5812. {
  5813. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5814. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5815. writeToPLC_Flag1.Adress = 2077;
  5816. writeToPLC_Flag1.Value = (short)6;
  5817. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5818. stopwatch1.Stop();
  5819. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5820. return;
  5821. }
  5822. #endregion 存储绑定数据到 边线MES系统中
  5823. stopwatch2.Stop();
  5824. short b1MES_FLAG_Unbind = 1;
  5825. // MES_Flag
  5826. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5827. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5828. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5829. writeToPLC_Flag.Adress = 2077;
  5830. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5831. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5832. }
  5833. catch (Exception ex)
  5834. {
  5835. string str = ex.StackTrace;
  5836. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5837. // MES_Flag
  5838. stopwatch2.Start();
  5839. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5840. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5841. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5842. writeToPLC_Flag.Adress = 2077;
  5843. writeToPLC_Flag.Value = (short)6;
  5844. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5845. stopwatch2.Stop();
  5846. }
  5847. stopwatch1.Stop();
  5848. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5849. }
  5850. //// 上次采集到的SN
  5851. //private string sn_FCT = string.Empty;
  5852. /// <summary>
  5853. /// [S2] FCT(板测)- 出站数据
  5854. /// </summary>
  5855. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5856. {
  5857. Stopwatch stopwatch1 = new Stopwatch();
  5858. Stopwatch stopwatch2 = new Stopwatch();
  5859. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5860. string stationNameStr = stationCode + stationName;
  5861. string processItem = stationName; // 测试项目
  5862. try
  5863. {
  5864. stopwatch1.Start();
  5865. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5866. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5867. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5868. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5869. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5870. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5871. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5872. bool pass1 = b1Part1Result == 1;
  5873. bool pass2 = b1Part2Result == 1;
  5874. #region 根据 载具SN 查 物料SN
  5875. string cavityData = string.Empty;
  5876. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5877. if (string.IsNullOrEmpty(cavityData))
  5878. cavityData = "";
  5879. if (snResult != 0)
  5880. {
  5881. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5882. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5883. writeToPLC_Flag1.Adress = 2169;
  5884. writeToPLC_Flag1.Value = (short)4;
  5885. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5886. stopwatch1.Stop();
  5887. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5888. return;
  5889. }
  5890. #endregion 根据 载具SN 查 物料SN
  5891. string[] cavitySNs = cavityData.Split('.');
  5892. string b1ProductSN1 = string.Empty;
  5893. string b1ProductSN2 = string.Empty;
  5894. if (cavitySNs != null && cavitySNs.Length >= 2)
  5895. {
  5896. b1ProductSN1 = cavitySNs[0];
  5897. b1ProductSN2 = cavitySNs[1];
  5898. }
  5899. stopwatch2.Start();
  5900. // 产品1
  5901. int result1 = 0;
  5902. if (b1ProductSN1 == "假产品")
  5903. result1 = 1;
  5904. else
  5905. {
  5906. List<TestItem> items1 = new List<TestItem>();
  5907. items1.Add(new TestItem()
  5908. {
  5909. Parameter_name = "载具码",
  5910. Parameter_value = b1ProductSN.ToString(),
  5911. Parameter_unit = ""
  5912. });
  5913. items1.Add(new TestItem()
  5914. {
  5915. Parameter_name = "载具穴号",
  5916. Parameter_value = "1",
  5917. Parameter_unit = ""
  5918. });
  5919. items1.Add(new TestItem()
  5920. {
  5921. Parameter_name = "产品结果",
  5922. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5923. Parameter_unit = ""
  5924. });
  5925. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  5926. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5927. }
  5928. // 产品2
  5929. int result2 = 0;
  5930. if (b1ProductSN1 == "假产品")
  5931. result2 = 1;
  5932. else
  5933. {
  5934. List<TestItem> items2 = new List<TestItem>();
  5935. items2.Add(new TestItem()
  5936. {
  5937. Parameter_name = "载具码",
  5938. Parameter_value = b1ProductSN.ToString(),
  5939. Parameter_unit = ""
  5940. });
  5941. items2.Add(new TestItem()
  5942. {
  5943. Parameter_name = "载具穴号",
  5944. Parameter_value = "2",
  5945. Parameter_unit = ""
  5946. });
  5947. items2.Add(new TestItem()
  5948. {
  5949. Parameter_name = "产品结果",
  5950. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5951. Parameter_unit = ""
  5952. });
  5953. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  5954. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5955. }
  5956. short result = 0;
  5957. List<int> results = new List<int>() { result1, result2 };
  5958. if (result1 == 1 && result2 == 1)
  5959. result = 1;
  5960. else if (results.Contains(3))
  5961. result = 3;
  5962. else if (results.Contains(2))
  5963. result = 2;
  5964. else if (results.Contains(4))
  5965. result = 4;
  5966. else
  5967. result = 4;
  5968. stopwatch2.Stop();
  5969. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5970. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5971. writeToPLC_Flag.Name = "b1MES_FLAG";
  5972. writeToPLC_Flag.Adress = 2169;
  5973. writeToPLC_Flag.Value = result;
  5974. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5975. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5976. }
  5977. catch (Exception ex)
  5978. {
  5979. stopwatch2.Restart();
  5980. // MES_Flag 为4上位机报错
  5981. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5982. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5983. writeToPLC_Flag.Name = "b1MES_FLAG";
  5984. writeToPLC_Flag.Adress = 2169;
  5985. writeToPLC_Flag.Value = (short)4;
  5986. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5987. stopwatch2.Stop();
  5988. string str = ex.StackTrace;
  5989. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5990. }
  5991. stopwatch1.Stop();
  5992. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5993. }
  5994. /// <summary>
  5995. /// [S2] FCT(板测)- 节拍接口
  5996. /// </summary>
  5997. /// <param name="plcNo">PLC编号</param>
  5998. /// <param name="stationNameStr">工站全称</param>
  5999. private void S2节拍接口(int plcNo, string stationNameStr)
  6000. {
  6001. Stopwatch stopwatch1 = new Stopwatch();
  6002. Stopwatch stopwatch2 = new Stopwatch();
  6003. string resultStr = string.Empty;
  6004. try
  6005. {
  6006. stopwatch1.Start();
  6007. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  6008. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  6009. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6010. if (!actionBool)
  6011. {
  6012. stopwatch2.Start();
  6013. // MES_Flag
  6014. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6015. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6016. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  6017. writeToPLC_Flag1.Adress = 2203;
  6018. writeToPLC_Flag1.Value = (short)4;
  6019. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  6020. stopwatch2.Stop();
  6021. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6022. return;
  6023. }
  6024. string b1OEEPartNo = string.Empty; // 物料码
  6025. if (string.IsNullOrEmpty(b1OEEProductSN))
  6026. {
  6027. stopwatch2.Start();
  6028. // MES_Flag
  6029. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6030. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6031. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  6032. writeToPLC_Flag1.Adress = 2203;
  6033. writeToPLC_Flag1.Value = (short)1;
  6034. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  6035. stopwatch2.Stop();
  6036. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6037. return;
  6038. }
  6039. else
  6040. { // 查产品SN
  6041. b1OEEPartNo = "Test"; // ZS
  6042. }
  6043. short b1OEEMES_FLAG = 0;
  6044. // 上传OEE
  6045. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  6046. b1OEEMES_FLAG = result.Item1;
  6047. resultStr = result.Item2;
  6048. stopwatch2.Start();
  6049. // MES_Flag
  6050. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6051. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6052. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  6053. writeToPLC_Flag.Adress = 2203;
  6054. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  6055. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  6056. stopwatch2.Stop();
  6057. }
  6058. catch (Exception ex)
  6059. {
  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. // MES_Flag
  6063. stopwatch2.Start();
  6064. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  6065. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6066. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  6067. writeToPLC_Flag.Adress = 2203;
  6068. writeToPLC_Flag.Value = (short)4;
  6069. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  6070. stopwatch2.Stop();
  6071. }
  6072. stopwatch1.Stop();
  6073. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6074. }
  6075. #endregion [S2] FCT(板测)
  6076. #endregion PLC2 李晓奇
  6077. #region PLC3 刘永村
  6078. #region [S3] 值板机
  6079. /// <summary>
  6080. /// S3工位的数据- 触发信号上次的值
  6081. /// </summary>
  6082. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  6083. /// <summary>
  6084. /// S3工位的数据(含触发信号)
  6085. /// </summary>
  6086. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  6087. /// <summary>
  6088. /// S3工位的数据- 回写点位
  6089. /// </summary>
  6090. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6091. /// <summary>
  6092. /// [S3] 值板机
  6093. /// </summary>
  6094. /// <param name="plcNo">PLC编号</param>
  6095. //private void ReadStation_S3(int plcNo)
  6096. //{
  6097. // // [S1] Tray盘上料装备
  6098. // // [S2] FCT
  6099. // // [S3] 值板机
  6100. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6101. // // [S5] Tray盘下料装备
  6102. // /// 上位机心跳
  6103. // /// 获取设备报警数据与状态信息
  6104. // string stationCode = "[S3]";
  6105. // string stationName = "值板机";
  6106. // string stationNameStr = stationCode + stationName;
  6107. // #region 创建字典
  6108. // // 触发信号字典 赋值
  6109. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  6110. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  6111. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  6112. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6113. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6114. // // PLC数据字典 赋值
  6115. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  6116. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  6117. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  6118. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  6119. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  6120. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  6121. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6122. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  6123. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  6124. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  6125. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  6126. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  6127. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6128. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6129. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  6130. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  6131. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  6132. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6133. // s3PLCData.Add("c1Result", 0); // 产品结果
  6134. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6135. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  6136. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  6137. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  6138. // #endregion 创建字典
  6139. // while (IsRun)
  6140. // {
  6141. // try
  6142. // {
  6143. // if (!GlobalContext._IsCon_Funs3)
  6144. // {
  6145. // UpdatePLCMonitor(1, plcNo, 0);
  6146. // continue;
  6147. // }
  6148. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6149. // {
  6150. // Stopwatch stopwatch1 = new Stopwatch();
  6151. // Stopwatch stopwatch2 = new Stopwatch();
  6152. // stopwatch1.Start();
  6153. // stopwatch2.Start();
  6154. // #region 一次性读取所有数据
  6155. // // 一次性读取所有数据
  6156. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  6157. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6158. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6159. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  6160. // int[] datas = data1.Concat(data2).ToArray();
  6161. // datas = datas.Concat(data3).ToArray();
  6162. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  6163. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  6164. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  6165. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  6166. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  6167. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  6168. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6169. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  6170. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  6171. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  6172. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6173. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6174. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  6175. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  6176. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  6177. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  6178. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6179. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  6180. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  6181. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  6182. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  6183. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  6184. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  6185. // #endregion 一次性读取所有数据
  6186. // stopwatch2.Stop();
  6187. // #region 回写操作,写后清空flag
  6188. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  6189. // #endregion 回写操作,写后清空flag
  6190. // #region S3进站校验
  6191. // try
  6192. // {
  6193. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  6194. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  6195. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  6196. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  6197. // {
  6198. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  6199. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6200. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  6201. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6202. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  6203. // }
  6204. // }
  6205. // catch (Exception ex)
  6206. // {
  6207. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6208. // string str = ex.StackTrace;
  6209. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6210. // }
  6211. // #endregion S3进站校验
  6212. // #region S3二穴载具解绑
  6213. // try
  6214. // {
  6215. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  6216. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  6217. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  6218. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  6219. // {
  6220. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6221. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  6222. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  6223. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  6224. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  6225. // }
  6226. // }
  6227. // catch (Exception ex)
  6228. // {
  6229. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  6230. // string str = ex.StackTrace;
  6231. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6232. // }
  6233. // #endregion S3二穴载具解绑
  6234. // #region S3二穴载具绑定
  6235. // try
  6236. // {
  6237. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  6238. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  6239. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  6240. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  6241. // {
  6242. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6243. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  6244. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  6245. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  6246. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  6247. // }
  6248. // }
  6249. // catch (Exception ex)
  6250. // {
  6251. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6252. // string str = ex.StackTrace;
  6253. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6254. // }
  6255. // #endregion S3二穴载具绑定
  6256. // #region S3出站接口(+一穴载具绑定)
  6257. // try
  6258. // {
  6259. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  6260. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  6261. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  6262. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  6263. // {
  6264. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  6265. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6266. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  6267. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  6268. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  6269. // }
  6270. // }
  6271. // catch (Exception ex)
  6272. // {
  6273. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  6274. // string str = ex.StackTrace;
  6275. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6276. // }
  6277. // #endregion S3出站接口(+一穴载具绑定)
  6278. // #region S3节拍接口
  6279. // try
  6280. // {
  6281. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  6282. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  6283. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  6284. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  6285. // {
  6286. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  6287. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6288. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  6289. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  6290. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  6291. // }
  6292. // }
  6293. // catch (Exception ex)
  6294. // {
  6295. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6296. // string str = ex.StackTrace;
  6297. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6298. // }
  6299. // #endregion S3节拍接口
  6300. // #region 心跳
  6301. // try
  6302. // {
  6303. // short states = 0;
  6304. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6305. // }
  6306. // catch (Exception ex)
  6307. // {
  6308. // string str = ex.StackTrace;
  6309. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6310. // }
  6311. // #endregion 心跳
  6312. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6313. // stopwatch1.Stop();
  6314. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6315. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6316. // }
  6317. // else
  6318. // {
  6319. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6320. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6321. // Funs[plcNo].Connect();
  6322. // }
  6323. // }
  6324. // catch (Exception ex)
  6325. // {
  6326. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6327. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6328. // Funs[plcNo].ReConnect();
  6329. // }
  6330. // Thread.Sleep(IntervalReadPLC);
  6331. // }
  6332. //}
  6333. /// <summary>
  6334. /// [S3] 值板机- 进站校验
  6335. /// </summary>
  6336. /// <param name="plcNo">PLC编号</param>
  6337. /// <param name="stationNameStr">工站全称</param>
  6338. private void S3进站校验(int plcNo, string stationNameStr)
  6339. {
  6340. Stopwatch stopwatch1 = new Stopwatch();
  6341. Stopwatch stopwatch2 = new Stopwatch();
  6342. try
  6343. {
  6344. stopwatch1.Start();
  6345. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6346. sn = sn.Replace("\0", "");
  6347. #region 查询载具上的产品信息
  6348. string cavityData = string.Empty;
  6349. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6350. if (string.IsNullOrEmpty(cavityData))
  6351. cavityData = "";
  6352. if (snResult != 0)
  6353. {
  6354. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6355. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6356. writeToPLC_Flag1.Adress = 2003;
  6357. writeToPLC_Flag1.Value = (short)6;
  6358. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6359. stopwatch1.Stop();
  6360. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6361. return;
  6362. }
  6363. #endregion 查询载具上的产品信息
  6364. string[] cavitySNs = cavityData.Split('.');
  6365. string part1Str = ""; // 产品1的SN码
  6366. string part2Str = ""; // 产品2的SN码
  6367. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6368. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6369. if (cavitySNs != null && cavitySNs.Length >= 2)
  6370. {
  6371. part1Str = cavitySNs[0];
  6372. part2Str = cavitySNs[1];
  6373. c1Part1Result_Check = 2;
  6374. c1Part2Result_Check = 2;
  6375. }
  6376. if (part1Str == "假产品")
  6377. c1Part1Result_Check = 3;
  6378. if (part2Str == "假产品")
  6379. c1Part2Result_Check = 3;
  6380. // 调用MES进站
  6381. stopwatch2.Start();
  6382. // 调用MES进站 - 产品1
  6383. List<TestItem> item;
  6384. int result1 = c1Part1Result_Check;
  6385. if (result1 != 3)
  6386. {
  6387. item = new List<TestItem>();
  6388. item.Add(new TestItem()
  6389. {
  6390. Parameter_name = "载具码",
  6391. Parameter_value = sn,
  6392. });
  6393. item.Add(new TestItem()
  6394. {
  6395. Parameter_name = "载具穴号",
  6396. Parameter_value = "1",
  6397. });
  6398. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6399. }
  6400. // 调用MES进站 - 产品2
  6401. int result2 = c1Part2Result_Check;
  6402. if (result2 != 3)
  6403. {
  6404. item = new List<TestItem>();
  6405. item.Add(new TestItem()
  6406. {
  6407. Parameter_name = "载具码",
  6408. Parameter_value = sn,
  6409. });
  6410. item.Add(new TestItem()
  6411. {
  6412. Parameter_name = "载具穴号",
  6413. Parameter_value = "2",
  6414. });
  6415. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6416. }
  6417. stopwatch2.Stop();
  6418. if (result1 == 2)
  6419. c1Part1Result_Check = 2;
  6420. if (result2 == 2)
  6421. c1Part2Result_Check = 2;
  6422. int result = result1;
  6423. if (result == 1)
  6424. result = result2;
  6425. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6426. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6427. short c1MES_FLAG_Check = (short)result;
  6428. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6429. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6430. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6431. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6432. //// MES_Flag
  6433. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6434. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6435. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6436. writeToPLC_Flag.Adress = 2003;
  6437. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6438. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6439. {
  6440. Name = "c1Part1Result_Check",
  6441. Adress = 2024,
  6442. ValueType = PLCValueType.Short,
  6443. Value = c1Part1Result_Check
  6444. });
  6445. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6446. {
  6447. Name = "c1Part2Result_Check",
  6448. Adress = 2025,
  6449. ValueType = PLCValueType.Short,
  6450. Value = c1Part2Result_Check
  6451. });
  6452. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6453. {
  6454. Name = "c1Part1Num_Check",
  6455. Adress = 2026,
  6456. ValueType = PLCValueType.Short,
  6457. Value = c1Part1Num_Check
  6458. });
  6459. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6460. {
  6461. Name = "c1Part2Num_Check",
  6462. Adress = 2027,
  6463. ValueType = PLCValueType.Short,
  6464. Value = c1Part2Num_Check
  6465. });
  6466. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6467. }
  6468. catch (Exception ex)
  6469. {
  6470. string str = ex.StackTrace;
  6471. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6472. // MES_Flag
  6473. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6474. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6475. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6476. writeToPLC_Flag.Adress = 2003;
  6477. writeToPLC_Flag.Value = (short)6;
  6478. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6479. }
  6480. stopwatch1.Stop();
  6481. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6482. }
  6483. /// <summary>
  6484. /// [S3] 值板机 - 二穴载具解绑
  6485. /// </summary>
  6486. /// <param name="plcNo">PLC编号</param>
  6487. /// <param name="stationNameStr">工站全称</param>
  6488. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6489. {
  6490. Stopwatch stopwatch1 = new Stopwatch();
  6491. Stopwatch stopwatch2 = new Stopwatch();
  6492. try
  6493. {
  6494. stopwatch1.Start();
  6495. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6496. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6497. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6498. // 解绑
  6499. #region 查询载具上的产品信息
  6500. string cavityData = string.Empty;
  6501. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6502. if (string.IsNullOrEmpty(cavityData))
  6503. cavityData = "";
  6504. if (snResult != 0)
  6505. {
  6506. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6507. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6508. writeToPLC_Flag1.Adress = 2082;
  6509. writeToPLC_Flag1.Value = (short)6;
  6510. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6511. stopwatch1.Stop();
  6512. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6513. return;
  6514. }
  6515. #endregion 查询载具上的产品信息
  6516. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6517. #region 解绑
  6518. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6519. {
  6520. // 删除
  6521. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6522. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6523. }
  6524. else
  6525. {
  6526. string data_new = string.Join(".", cavitySNs);
  6527. // 删除再插入
  6528. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6529. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6530. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6531. }
  6532. #endregion 解绑
  6533. short c1MES_FLAG_Unbind = 1;
  6534. stopwatch2.Start();
  6535. // MES_Flag
  6536. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6537. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6538. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6539. writeToPLC_Flag.Adress = 2082;
  6540. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6541. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6542. stopwatch2.Stop();
  6543. }
  6544. catch (Exception ex)
  6545. {
  6546. string str = ex.StackTrace;
  6547. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6548. // MES_Flag
  6549. stopwatch2.Start();
  6550. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6551. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6552. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6553. writeToPLC_Flag.Adress = 2082;
  6554. writeToPLC_Flag.Value = (short)6;
  6555. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6556. stopwatch2.Stop();
  6557. }
  6558. stopwatch1.Stop();
  6559. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6560. }
  6561. /// <summary>
  6562. /// [S3] 值板机 - 二穴载具绑定
  6563. /// </summary>
  6564. /// <param name="plcNo">PLC编号</param>
  6565. /// <param name="stationNameStr">工站全称</param>
  6566. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6567. {
  6568. Stopwatch stopwatch1 = new Stopwatch();
  6569. Stopwatch stopwatch2 = new Stopwatch();
  6570. try
  6571. {
  6572. stopwatch1.Start();
  6573. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6574. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6575. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6576. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6577. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6578. stopwatch2.Start();
  6579. #region 查询载具上的产品信息
  6580. string cavityData = string.Empty;
  6581. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6582. if (string.IsNullOrEmpty(cavityData))
  6583. cavityData = "";
  6584. if (snResult != 0)
  6585. {
  6586. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6587. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6588. writeToPLC_Flag1.Adress = 2115;
  6589. writeToPLC_Flag1.Value = (short)6;
  6590. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6591. stopwatch1.Stop();
  6592. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6593. return;
  6594. }
  6595. #endregion 查询载具上的产品信息
  6596. // 产品换载具
  6597. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6598. string partSn1 = "";
  6599. string partSn2 = "";
  6600. if (cavitySNs != null && cavitySNs.Length >= 2)
  6601. {
  6602. partSn1 = cavitySNs[0];
  6603. partSn2 = cavitySNs[1];
  6604. }
  6605. string data_new = string.Empty;
  6606. // 是否是两个穴位交换
  6607. if (c1CavityReverse_Bind == 1)
  6608. {
  6609. // 交换
  6610. data_new = string.Concat(partSn2, ".", partSn1);
  6611. }
  6612. else
  6613. { // 不交换
  6614. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6615. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6616. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6617. data_new = string.Join(".", cavitySNs);
  6618. }
  6619. // 删除再插入
  6620. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6621. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6622. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6623. stopwatch2.Stop();
  6624. short c1MES_FLAG_Bind = 1;
  6625. // MES_Flag
  6626. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6627. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6628. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6629. writeToPLC_Flag.Adress = 2115;
  6630. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6631. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6632. }
  6633. catch (Exception ex)
  6634. {
  6635. string str = ex.StackTrace;
  6636. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6637. // MES_Flag
  6638. stopwatch2.Start();
  6639. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6640. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6641. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6642. writeToPLC_Flag.Adress = 2115;
  6643. writeToPLC_Flag.Value = (short)6;
  6644. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6645. stopwatch2.Stop();
  6646. }
  6647. stopwatch1.Stop();
  6648. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6649. }
  6650. //// 上次采集到的SN
  6651. //private string sn_值板机 = string.Empty;
  6652. /// <summary>
  6653. /// [S3] 值板机 - 出站接口
  6654. /// </summary>
  6655. /// <param name="plcNo">PLC编号</param>
  6656. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6657. {
  6658. Stopwatch stopwatch1 = new Stopwatch();
  6659. Stopwatch stopwatch2 = new Stopwatch();
  6660. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6661. string stationNameStr = stationCode + stationName;
  6662. string processItem = stationName; // 测试项目
  6663. try
  6664. {
  6665. stopwatch1.Start();
  6666. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6667. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6668. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6669. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6670. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6671. sn = sn.Replace("\0", "");
  6672. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6673. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6674. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6675. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6676. bool pass = c1Result == 1;
  6677. // 查sn
  6678. #region 查询载具上的产品信息
  6679. string cavityData = string.Empty;
  6680. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6681. if (string.IsNullOrEmpty(cavityData))
  6682. cavityData = "";
  6683. if (snResult != 0)
  6684. {
  6685. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6686. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6687. writeToPLC_Flag1.Adress = 2150;
  6688. writeToPLC_Flag1.Value = (short)4;
  6689. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6690. stopwatch1.Stop();
  6691. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6692. return;
  6693. }
  6694. #endregion 查询载具上的产品信息
  6695. string[] cavitySNs = cavityData.Split('.');
  6696. string productSN = "";
  6697. if (cavitySNs != null && cavitySNs.Length >= 2)
  6698. {
  6699. productSN = cavitySNs[c1VehicleCavity];
  6700. cavitySNs[c1VehicleCavity] = "";
  6701. }
  6702. stopwatch2.Start();
  6703. List<TestItem> items = new List<TestItem>();
  6704. items.Add(new TestItem()
  6705. {
  6706. Parameter_name = "二穴载具码",
  6707. Parameter_value = c1ProductSN_Check,
  6708. Parameter_unit = ""
  6709. });
  6710. items.Add(new TestItem()
  6711. {
  6712. Parameter_name = "二穴载具穴号",
  6713. Parameter_value = c1VehicleCavity.ToString(),
  6714. Parameter_unit = ""
  6715. });
  6716. items.Add(new TestItem()
  6717. {
  6718. Parameter_name = "一穴载具码",
  6719. Parameter_value = sn,
  6720. Parameter_unit = ""
  6721. });
  6722. items.Add(new TestItem()
  6723. {
  6724. Parameter_name = "一穴载具穴号",
  6725. Parameter_value = "1",
  6726. Parameter_unit = ""
  6727. });
  6728. items.Add(new TestItem()
  6729. {
  6730. Parameter_name = "产品结果",
  6731. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6732. Parameter_unit = ""
  6733. });
  6734. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  6735. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6736. short result = (short)result1;
  6737. stopwatch2.Stop();
  6738. #region 存储绑定数据到 边线MES系统中
  6739. if (result == 1)
  6740. {
  6741. string data = string.Concat(productSN);
  6742. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6743. if (resultMesR != 0)
  6744. {
  6745. result = 4;
  6746. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6747. }
  6748. }
  6749. #endregion 存储绑定数据到 边线MES系统中
  6750. #region 产品从 来源载具(二穴载具)中删除
  6751. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6752. {
  6753. // 删除
  6754. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6755. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6756. }
  6757. else
  6758. {
  6759. string data_new = string.Join(".", cavitySNs);
  6760. // 删除再插入
  6761. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6762. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6763. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6764. }
  6765. #endregion 产品从 来源载具(二穴载具)中删除
  6766. // MES_Flag 为MES报错
  6767. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6768. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6769. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6770. writeToPLC_Flag.Name = "c1MES_FLAG";
  6771. writeToPLC_Flag.Adress = 2150;
  6772. writeToPLC_Flag.Value = result;
  6773. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6774. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6775. }
  6776. catch (Exception ex)
  6777. {
  6778. stopwatch2.Restart();
  6779. // MES_Flag 为4上位机报错
  6780. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6781. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6782. writeToPLC_Flag.Name = "c1MES_FLAG";
  6783. writeToPLC_Flag.Adress = 2150;
  6784. writeToPLC_Flag.Value = (short)4;
  6785. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6786. stopwatch2.Stop();
  6787. string str = ex.StackTrace;
  6788. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6789. }
  6790. stopwatch1.Stop();
  6791. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6792. }
  6793. /// <summary>
  6794. /// [S3] 值板机- 节拍接口
  6795. /// </summary>
  6796. /// <param name="plcNo">PLC编号</param>
  6797. /// <param name="stationNameStr">工站全称</param>
  6798. private void S3节拍接口(int plcNo, string stationNameStr)
  6799. {
  6800. Stopwatch stopwatch1 = new Stopwatch();
  6801. Stopwatch stopwatch2 = new Stopwatch();
  6802. string resultStr = string.Empty;
  6803. try
  6804. {
  6805. stopwatch1.Start();
  6806. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6807. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6808. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6809. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6810. if (!actionBool)
  6811. {
  6812. stopwatch2.Start();
  6813. // MES_Flag
  6814. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6815. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6816. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6817. writeToPLC_Flag1.Adress = 2204;
  6818. writeToPLC_Flag1.Value = (short)4;
  6819. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6820. stopwatch2.Stop();
  6821. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6822. return;
  6823. }
  6824. string c1OEEPartNo = string.Empty; // 物料码
  6825. if (string.IsNullOrEmpty(c1OEEProductSN))
  6826. {
  6827. stopwatch2.Start();
  6828. // MES_Flag
  6829. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6830. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6831. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6832. writeToPLC_Flag1.Adress = 2204;
  6833. writeToPLC_Flag1.Value = (short)1;
  6834. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6835. stopwatch2.Stop();
  6836. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6837. return;
  6838. }
  6839. else
  6840. { // 查产品SN
  6841. c1OEEPartNo = "Test"; // ZS
  6842. }
  6843. short c1OEEMES_FLAG = 0;
  6844. // 上传OEE
  6845. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6846. c1OEEMES_FLAG = result.Item1;
  6847. resultStr = result.Item2;
  6848. stopwatch2.Start();
  6849. // MES_Flag
  6850. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6851. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6852. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6853. writeToPLC_Flag.Adress = 2204;
  6854. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6855. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6856. stopwatch2.Stop();
  6857. }
  6858. catch (Exception ex)
  6859. {
  6860. string str = ex.StackTrace;
  6861. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6862. // MES_Flag
  6863. stopwatch2.Start();
  6864. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6865. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6866. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6867. writeToPLC_Flag.Adress = 2204;
  6868. writeToPLC_Flag.Value = (short)4;
  6869. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6870. stopwatch2.Stop();
  6871. }
  6872. stopwatch1.Stop();
  6873. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6874. }
  6875. #endregion [S3] 值板机
  6876. #endregion PLC3 刘永村
  6877. #region PLC4 刘果段
  6878. #region [S4] 取放桁架
  6879. /// <summary>
  6880. /// S4工位的数据- 触发信号上次的值
  6881. /// </summary>
  6882. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6883. /// <summary>
  6884. /// S4工位的数据(含触发信号)
  6885. /// </summary>
  6886. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6887. /// <summary>
  6888. /// S4工位的数据- 回写点位
  6889. /// </summary>
  6890. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6891. /// <summary>
  6892. /// [S4] 取放桁架
  6893. /// </summary>
  6894. /// <param name="plcNo">PLC编号</param>
  6895. //private void ReadStation_S4(int plcNo)
  6896. //{
  6897. // // [S1] Tray盘上料装备
  6898. // // [S2] FCT
  6899. // // [S3] 值板机
  6900. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6901. // // [S5] Tray盘下料装备
  6902. // /// 上位机心跳
  6903. // /// 获取设备报警数据与状态信息
  6904. // string stationCode = "[S4_1]";
  6905. // string stationName = "载具下线装备";
  6906. // string stationNameStr = stationCode + stationName;
  6907. // string stationCode2 = "[S4_2]";
  6908. // string stationName2 = "桁架";
  6909. // string stationNameStr2 = stationCode2 + stationName2;
  6910. // string stationCode3 = "[S4_3]";
  6911. // string stationName3 = "提升机1";
  6912. // string stationNameStr3 = stationCode3 + stationName3;
  6913. // string stationCode4 = "[S4_4]";
  6914. // string stationName4 = "提升机2";
  6915. // string stationNameStr4 = stationCode4 + stationName4;
  6916. // string stationCode5 = "[S4_5]";
  6917. // string stationName5 = "载具上线装备";
  6918. // string stationNameStr5 = stationCode5 + stationName5;
  6919. // #region 创建字典
  6920. // // 触发信号字典 赋值
  6921. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6922. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6923. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6924. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6925. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6926. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6927. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6928. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6929. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6930. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6931. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6932. // // PLC数据字典 赋值
  6933. // // 载具下线装备(弹夹上线)
  6934. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6935. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6936. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6937. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6938. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6939. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6940. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6941. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6942. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6943. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6944. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6945. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6946. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6947. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6948. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6949. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6950. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6951. // s4PLCData.Add("d1Result", 0); // 产品结果
  6952. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6953. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6954. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6955. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6956. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6957. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6958. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6959. // // 真空标机(提升机)
  6960. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6961. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6962. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6963. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6964. // s4PLCData.Add("d3Result", 0); // 产品结果
  6965. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6966. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6967. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6968. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6969. // s4PLCData.Add("d4Result", 0); // 产品结果
  6970. // // 载具上线装备(弹夹下线)
  6971. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6972. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6973. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6974. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6975. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6976. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6977. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6978. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6979. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6980. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6981. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6982. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6983. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6984. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6985. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6986. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6987. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6988. // s4PLCData.Add("d5Result", 0); // 产品结果
  6989. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6990. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6991. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6992. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6993. // #endregion 创建字典
  6994. // while (IsRun)
  6995. // {
  6996. // try
  6997. // {
  6998. // if (!GlobalContext._IsCon_Funs4)
  6999. // {
  7000. // UpdatePLCMonitor(1, plcNo, 0);
  7001. // continue;
  7002. // }
  7003. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  7004. // {
  7005. // Stopwatch stopwatch1 = new Stopwatch();
  7006. // Stopwatch stopwatch2 = new Stopwatch();
  7007. // stopwatch1.Start();
  7008. // stopwatch2.Start();
  7009. // #region 一次性读取所有数据
  7010. // // 载具下线装备(弹夹上线)
  7011. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  7012. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  7013. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  7014. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  7015. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  7016. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  7017. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  7018. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  7019. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  7020. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  7021. // int[] datas = data1.Concat(data2).ToArray();
  7022. // datas = datas.Concat(data3).ToArray();
  7023. // datas = datas.Concat(data4).ToArray();
  7024. // datas = datas.Concat(data5).ToArray();
  7025. // datas = datas.Concat(data6).ToArray();
  7026. // datas = datas.Concat(data7).ToArray();
  7027. // datas = datas.Concat(data8).ToArray();
  7028. // datas = datas.Concat(data9).ToArray();
  7029. // datas = datas.Concat(data10).ToArray();
  7030. // // 载具下线装备(弹夹上线)
  7031. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  7032. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  7033. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  7034. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  7035. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  7036. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  7037. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  7038. // s4PLCData["d1MES_FLAG"] = datas[65];
  7039. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  7040. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  7041. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  7042. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  7043. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  7044. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  7045. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  7046. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  7047. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  7048. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  7049. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  7050. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  7051. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  7052. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  7053. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  7054. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  7055. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  7056. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  7057. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  7058. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  7059. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  7060. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  7061. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  7062. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  7063. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  7064. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  7065. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  7066. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  7067. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  7068. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  7069. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  7070. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  7071. // s4PLCData["d1Result"] = datas[386];
  7072. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  7073. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  7074. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  7075. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  7076. // s4PLCData["d1OEEType"] = datas[419];
  7077. // // 桁架(查询标机中弹夹的状态)
  7078. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  7079. // s4PLCData["d2BulletclipStates"] = datas[431];
  7080. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  7081. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  7082. // // 真空标机
  7083. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  7084. // s4PLCData["d3MES_FLAG"] = datas[463];
  7085. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  7086. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  7087. // s4PLCData["d3Result"] = datas[484];
  7088. // s4PLCData["d3Type"] = datas[485];
  7089. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  7090. // s4PLCData["d4MES_FLAG"] = datas[496];
  7091. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  7092. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  7093. // s4PLCData["d4Result"] = datas[517];
  7094. // s4PLCData["d4Type"] = datas[518];
  7095. // // 载具上线装备(弹夹下线)
  7096. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  7097. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  7098. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  7099. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  7100. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  7101. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  7102. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  7103. // s4PLCData["d5MES_FLAG"] = datas[591];
  7104. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  7105. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  7106. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  7107. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  7108. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  7109. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  7110. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  7111. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  7112. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  7113. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  7114. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  7115. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  7116. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  7117. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  7118. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  7119. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  7120. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  7121. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  7122. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  7123. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  7124. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  7125. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  7126. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  7127. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  7128. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  7129. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  7130. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  7131. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  7132. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  7133. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  7134. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  7135. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  7136. // s4PLCData["d5Result"] = datas[912];
  7137. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  7138. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  7139. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  7140. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  7141. // s4PLCData["d5OEEType"] = datas[945];
  7142. // #endregion 一次性读取所有数据
  7143. // stopwatch2.Stop();
  7144. // #region 回写操作,写后清空flag
  7145. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  7146. // #endregion 回写操作,写后清空flag
  7147. // // N801A-S4_1 弹夹扫码
  7148. // #region N801A-S4_1 弹夹扫码
  7149. // try
  7150. // {
  7151. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  7152. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  7153. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  7154. // {
  7155. // if (d1BulletclipScanCode == 1) // 0->1
  7156. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  7157. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  7158. // }
  7159. // }
  7160. // catch (Exception ex)
  7161. // {
  7162. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7163. // string str = ex.StackTrace;
  7164. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7165. // }
  7166. // #endregion N801A-S4_1 弹夹扫码
  7167. // // N801A-S4_1 载具扫码
  7168. // #region N801A-S4_1 载具扫码
  7169. // try
  7170. // {
  7171. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  7172. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  7173. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  7174. // {
  7175. // if (d1VehicleScanCode == 1) // 0->1
  7176. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  7177. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  7178. // }
  7179. // }
  7180. // catch (Exception ex)
  7181. // {
  7182. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7183. // string str = ex.StackTrace;
  7184. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7185. // }
  7186. // #endregion N801A-S4_1 载具扫码
  7187. // // N801A-S4_1 出站接口
  7188. // #region N801A-S4_1 出站接口
  7189. // try
  7190. // {
  7191. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  7192. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  7193. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  7194. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  7195. // {
  7196. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  7197. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7198. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  7199. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  7200. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  7201. // }
  7202. // }
  7203. // catch (Exception ex)
  7204. // {
  7205. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  7206. // string str = ex.StackTrace;
  7207. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7208. // }
  7209. // #endregion N801A-S4_1 出站接口
  7210. // // N801A-S4_1 节拍接口
  7211. // #region N801A-S4_1 节拍接口
  7212. // try
  7213. // {
  7214. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  7215. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  7216. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  7217. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  7218. // {
  7219. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  7220. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7221. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  7222. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  7223. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  7224. // }
  7225. // }
  7226. // catch (Exception ex)
  7227. // {
  7228. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7229. // string str = ex.StackTrace;
  7230. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7231. // }
  7232. // #endregion N801A-S4_1 节拍接口
  7233. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  7234. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  7235. // try
  7236. // {
  7237. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  7238. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  7239. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  7240. // {
  7241. // if (d2BulletclipScanCode == 1) // 0->1
  7242. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  7243. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  7244. // }
  7245. // }
  7246. // catch (Exception ex)
  7247. // {
  7248. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7249. // string str = ex.StackTrace;
  7250. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7251. // }
  7252. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  7253. // // N801A-S4_3 真空标机1 数据
  7254. // #region N801A-S4_3 真空标机1
  7255. // try
  7256. // {
  7257. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  7258. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  7259. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  7260. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  7261. // {
  7262. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  7263. // {
  7264. // int stationType = (int)s4PLCData["d3Type"];
  7265. // if (stationType == 1)
  7266. // {
  7267. // // S4_3进站接口
  7268. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  7269. // }
  7270. // else if (stationType == 2)
  7271. // {
  7272. // // S4_3出站接口
  7273. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  7274. // }
  7275. // }
  7276. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  7277. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  7278. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  7279. // }
  7280. // }
  7281. // catch (Exception ex)
  7282. // {
  7283. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7284. // string str = ex.StackTrace;
  7285. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7286. // }
  7287. // #endregion N801A-S4_3 真空标机1
  7288. // // N801A-S4_4 真空标机2 数据
  7289. // #region N801A-S4_4 真空标机2
  7290. // try
  7291. // {
  7292. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  7293. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  7294. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  7295. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  7296. // {
  7297. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  7298. // {
  7299. // int stationType = (int)s4PLCData["d4Type"];
  7300. // if (stationType == 1)
  7301. // {
  7302. // // S4_4进站接口
  7303. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  7304. // }
  7305. // else if (stationType == 2)
  7306. // {
  7307. // // S4_4出站接口
  7308. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  7309. // }
  7310. // }
  7311. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  7312. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  7313. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  7314. // }
  7315. // }
  7316. // catch (Exception ex)
  7317. // {
  7318. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7319. // string str = ex.StackTrace;
  7320. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7321. // }
  7322. // #endregion N801A-S4_4 真空标机2
  7323. // // N801A-S4_5 弹夹扫码 数据
  7324. // #region N801A-S4_5 弹夹扫码
  7325. // try
  7326. // {
  7327. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7328. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7329. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7330. // {
  7331. // if (d5BulletclipScanCode == 1) // 0->1
  7332. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7333. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7334. // }
  7335. // }
  7336. // catch (Exception ex)
  7337. // {
  7338. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7339. // string str = ex.StackTrace;
  7340. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7341. // }
  7342. // #endregion N801A-S4_5 弹夹扫码
  7343. // // N801A-S4_5 载具扫码 数据
  7344. // #region N801A-S4_5 载具扫码
  7345. // try
  7346. // {
  7347. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7348. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7349. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7350. // {
  7351. // if (d5VehicleScanCode == 1) // 0->1
  7352. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7353. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7354. // }
  7355. // }
  7356. // catch (Exception ex)
  7357. // {
  7358. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7359. // string str = ex.StackTrace;
  7360. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7361. // }
  7362. // #endregion N801A-S4_5 载具扫码
  7363. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7364. // #region N801A-S4_5 出站接口
  7365. // try
  7366. // {
  7367. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7368. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7369. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7370. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7371. // {
  7372. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7373. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7374. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7375. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7376. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7377. // }
  7378. // }
  7379. // catch (Exception ex)
  7380. // {
  7381. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7382. // string str = ex.StackTrace;
  7383. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7384. // }
  7385. // #endregion N801A-S4_5 出站接口
  7386. // // N801A-S4_5 节拍接口 数据
  7387. // #region N801A-S4_5 节拍接口
  7388. // try
  7389. // {
  7390. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7391. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7392. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7393. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7394. // {
  7395. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7396. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7397. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7398. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7399. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7400. // }
  7401. // }
  7402. // catch (Exception ex)
  7403. // {
  7404. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7405. // string str = ex.StackTrace;
  7406. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7407. // }
  7408. // #endregion N801A-S4_5 节拍接口
  7409. // #region 心跳
  7410. // try
  7411. // {
  7412. // short states = 0;
  7413. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7414. // }
  7415. // catch (Exception ex)
  7416. // {
  7417. // string str = ex.StackTrace;
  7418. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7419. // }
  7420. // #endregion 心跳
  7421. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7422. // stopwatch1.Stop();
  7423. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7424. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7425. // }
  7426. // else
  7427. // {
  7428. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7429. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7430. // Funs[plcNo].Connect();
  7431. // }
  7432. // }
  7433. // catch (Exception ex)
  7434. // {
  7435. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7436. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7437. // Funs[plcNo].ReConnect();
  7438. // }
  7439. // Thread.Sleep(IntervalReadPLC);
  7440. // }
  7441. //}
  7442. /// <summary>
  7443. /// [S4] 取放桁架 - S4_1弹夹扫码
  7444. /// </summary>
  7445. /// <param name="plcNo">PLC编号</param>
  7446. /// <param name="stationNameStr">工站全称</param>
  7447. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7448. {
  7449. Stopwatch stopwatch1 = new Stopwatch();
  7450. Stopwatch stopwatch2 = new Stopwatch();
  7451. try
  7452. {
  7453. stopwatch1.Start();
  7454. // ZS 弹夹扫码
  7455. string d1BulletclipCode = " "; // 扫到的码
  7456. short d1BulletclipScanCode = 2;
  7457. stopwatch2.Start();
  7458. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7459. //// MES_Flag
  7460. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7461. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7462. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7463. writeToPLC_Flag.Adress = 2002;
  7464. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7465. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7466. {
  7467. Name = "d1BulletclipCode",
  7468. Adress = 2003,
  7469. ValueType = PLCValueType.String,
  7470. ValueTypeStrLength = 20,
  7471. Value = d1BulletclipCode
  7472. });
  7473. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7474. stopwatch2.Stop();
  7475. }
  7476. catch (Exception ex)
  7477. {
  7478. string str = ex.StackTrace;
  7479. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7480. stopwatch2.Start();
  7481. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7482. //// MES_Flag
  7483. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7484. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7485. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7486. writeToPLC_Flag.Adress = 2002;
  7487. writeToPLC_Flag.Value = (short)6;
  7488. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7489. {
  7490. Name = "d1BulletclipCode",
  7491. Adress = 2003,
  7492. ValueType = PLCValueType.String,
  7493. ValueTypeStrLength = 20,
  7494. Value = " "
  7495. });
  7496. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7497. stopwatch2.Stop();
  7498. }
  7499. stopwatch1.Stop();
  7500. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7501. }
  7502. /// <summary>
  7503. /// [S4] 取放桁架 - S4_1载具扫码
  7504. /// </summary>
  7505. /// <param name="plcNo">PLC编号</param>
  7506. /// <param name="stationNameStr">工站全称</param>
  7507. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7508. {
  7509. Stopwatch stopwatch1 = new Stopwatch();
  7510. Stopwatch stopwatch2 = new Stopwatch();
  7511. try
  7512. {
  7513. stopwatch1.Start();
  7514. // ZS 载具扫码
  7515. string d1VehicleCode = ""; // 扫到的码
  7516. short d1VehicleScanCode = 2;
  7517. #region 进站
  7518. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7519. {
  7520. #region 查询载具上的产品信息
  7521. string cavityData = string.Empty;
  7522. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7523. if (string.IsNullOrEmpty(cavityData))
  7524. cavityData = "";
  7525. if (snResult != 0)
  7526. {
  7527. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7528. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7529. writeToPLC_Flag1.Adress = 2033;
  7530. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7531. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7532. {
  7533. Name = "d1VehicleCode",
  7534. Adress = 2034,
  7535. ValueType = PLCValueType.String,
  7536. ValueTypeStrLength = 20,
  7537. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7538. });
  7539. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7540. stopwatch1.Stop();
  7541. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7542. return;
  7543. }
  7544. string[] cavitySNs = cavityData.Split('.');
  7545. string partNo = "";
  7546. if (cavitySNs != null && cavitySNs.Length >= 1)
  7547. {
  7548. partNo = cavitySNs[0];
  7549. }
  7550. #endregion 查询载具上的产品信息
  7551. List<TestItem> item = new List<TestItem>();
  7552. item.Add(new TestItem()
  7553. {
  7554. Parameter_name = "载具码",
  7555. Parameter_value = d1VehicleCode,
  7556. });
  7557. item.Add(new TestItem()
  7558. {
  7559. Parameter_name = "载具穴号",
  7560. Parameter_value = "1",
  7561. });
  7562. stopwatch2.Start();
  7563. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7564. stopwatch2.Stop();
  7565. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7566. }
  7567. #endregion 进站
  7568. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7569. //// MES_Flag
  7570. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7571. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7572. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7573. writeToPLC_Flag.Adress = 2033;
  7574. writeToPLC_Flag.Value = d1VehicleScanCode;
  7575. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7576. {
  7577. Name = "d1VehicleCode",
  7578. Adress = 2034,
  7579. ValueType = PLCValueType.String,
  7580. ValueTypeStrLength = 20,
  7581. Value = d1VehicleCode
  7582. });
  7583. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7584. }
  7585. catch (Exception ex)
  7586. {
  7587. string str = ex.StackTrace;
  7588. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7589. stopwatch2.Start();
  7590. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7591. //// MES_Flag
  7592. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7593. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7594. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7595. writeToPLC_Flag.Adress = 2033;
  7596. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7597. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7598. {
  7599. Name = "d1VehicleCode",
  7600. Adress = 2034,
  7601. ValueType = PLCValueType.String,
  7602. ValueTypeStrLength = 20,
  7603. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7604. });
  7605. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7606. stopwatch2.Stop();
  7607. }
  7608. stopwatch1.Stop();
  7609. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7610. }
  7611. // 上次采集到的SN
  7612. //private string sn_S4_1出站接口 = string.Empty;
  7613. /// <summary>
  7614. /// [S4] 取放桁架 - S4_1出站接口
  7615. /// </summary>
  7616. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7617. {
  7618. Stopwatch stopwatch1 = new Stopwatch();
  7619. Stopwatch stopwatch2 = new Stopwatch();
  7620. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7621. string stationNameStr = stationCode + stationName;
  7622. string processItem = stationName; // 测试项目
  7623. try
  7624. {
  7625. stopwatch1.Start();
  7626. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7627. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7628. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7629. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7630. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7631. sn = sn.Replace("\0", "");
  7632. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7633. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7634. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7635. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7636. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7637. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7638. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7639. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7640. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7641. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7642. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7643. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7644. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7645. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7646. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7647. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7648. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7649. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7650. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7651. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7652. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7653. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7654. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7655. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7656. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7657. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7658. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7659. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7660. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7661. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7662. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7663. bool pass = d1Result == 1;
  7664. // 存 载具SN列表
  7665. List<string> vehicleCodes = new List<string>()
  7666. {
  7667. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7668. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7669. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7670. };
  7671. // 统一查 产品SN列表
  7672. List<string> partNos = new List<string>();
  7673. foreach (string vehicleCode in vehicleCodes)
  7674. {
  7675. if (string.IsNullOrEmpty(vehicleCode))
  7676. partNos.Add("");
  7677. else
  7678. {
  7679. string partNo = "";
  7680. #region 查询载具上的产品信息
  7681. string cavityData = string.Empty;
  7682. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7683. if (string.IsNullOrEmpty(cavityData))
  7684. cavityData = "";
  7685. if (snResult != 0)
  7686. {
  7687. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7688. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7689. writeToPLC_Flag1.Adress = 2065;
  7690. writeToPLC_Flag1.Value = (short)4;
  7691. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7692. stopwatch1.Stop();
  7693. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7694. return;
  7695. }
  7696. string[] cavitySNs = cavityData.Split('.');
  7697. if (cavitySNs != null && cavitySNs.Length >= 1)
  7698. partNo = cavitySNs[0];
  7699. #endregion 查询载具上的产品信息
  7700. partNos.Add(partNo);
  7701. }
  7702. }
  7703. // 统一上传
  7704. stopwatch2.Start();
  7705. List<int> results = new List<int>();
  7706. for (int i = 0; i < partNos.Count; i++)
  7707. {
  7708. string index = (i + 1).ToString(); // 弹夹穴号
  7709. if (string.IsNullOrEmpty(partNos[i]))
  7710. results.Add(1);
  7711. else
  7712. {
  7713. List<TestItem> items1 = new List<TestItem>();
  7714. items1.Add(new TestItem()
  7715. {
  7716. Parameter_name = "弹夹码",
  7717. Parameter_value = sn,
  7718. Parameter_unit = ""
  7719. });
  7720. items1.Add(new TestItem()
  7721. {
  7722. Parameter_name = "弹夹穴号",
  7723. Parameter_value = index,
  7724. Parameter_unit = ""
  7725. });
  7726. items1.Add(new TestItem()
  7727. {
  7728. Parameter_name = "载具码",
  7729. Parameter_value = vehicleCodes[i],
  7730. Parameter_unit = ""
  7731. });
  7732. items1.Add(new TestItem()
  7733. {
  7734. Parameter_name = "载具穴号",
  7735. Parameter_value = "1",
  7736. Parameter_unit = ""
  7737. });
  7738. items1.Add(new TestItem()
  7739. {
  7740. Parameter_name = "产品结果",
  7741. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7742. Parameter_unit = ""
  7743. });
  7744. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  7745. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7746. results.Add(result1);
  7747. }
  7748. }
  7749. short result = 0;
  7750. if (results.All(a => a == 1))
  7751. result = 1;
  7752. else if (results.Contains(3))
  7753. result = 3;
  7754. else if (results.Contains(2))
  7755. result = 2;
  7756. else if (results.Contains(4))
  7757. result = 4;
  7758. else
  7759. result = 4;
  7760. stopwatch2.Stop();
  7761. #region 存储绑定数据到 边线MES系统中
  7762. if (result == 1)
  7763. {
  7764. string data = string.Join(".", vehicleCodes);
  7765. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7766. if (resultMesR != 0)
  7767. {
  7768. result = 4;
  7769. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7770. }
  7771. }
  7772. #endregion 存储绑定数据到 边线MES系统中
  7773. // MES_Flag 为4MES报错
  7774. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7775. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7776. writeToPLC_Flag.Name = "d1MES_FLAG";
  7777. writeToPLC_Flag.Adress = 2065;
  7778. writeToPLC_Flag.Value = result;
  7779. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7780. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7781. }
  7782. catch (Exception ex)
  7783. {
  7784. stopwatch2.Restart();
  7785. // MES_Flag 为4上位机报错
  7786. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7787. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7788. writeToPLC_Flag.Name = "d1MES_FLAG";
  7789. writeToPLC_Flag.Adress = 2065;
  7790. writeToPLC_Flag.Value = (short)4;
  7791. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7792. stopwatch2.Stop();
  7793. string str = ex.StackTrace;
  7794. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7795. }
  7796. stopwatch1.Stop();
  7797. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7798. }
  7799. /// <summary>
  7800. /// [S4] 取放桁架 - S4_1节拍接口
  7801. /// </summary>
  7802. /// <param name="plcNo">PLC编号</param>
  7803. /// <param name="stationNameStr">工站全称</param>
  7804. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7805. {
  7806. Stopwatch stopwatch1 = new Stopwatch();
  7807. Stopwatch stopwatch2 = new Stopwatch();
  7808. string resultStr = string.Empty;
  7809. try
  7810. {
  7811. stopwatch1.Start();
  7812. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7813. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7814. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7815. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7816. if (!actionBool)
  7817. {
  7818. stopwatch2.Start();
  7819. // MES_Flag
  7820. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7821. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7822. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7823. writeToPLC_Flag1.Adress = 2398;
  7824. writeToPLC_Flag1.Value = (short)4;
  7825. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7826. stopwatch2.Stop();
  7827. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7828. return;
  7829. }
  7830. string d1OEEPartNo = string.Empty; // 物料码
  7831. if (string.IsNullOrEmpty(d1OEEProductSN))
  7832. {
  7833. stopwatch2.Start();
  7834. // MES_Flag
  7835. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7836. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7837. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7838. writeToPLC_Flag1.Adress = 2398;
  7839. writeToPLC_Flag1.Value = (short)1;
  7840. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7841. stopwatch2.Stop();
  7842. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7843. return;
  7844. }
  7845. else
  7846. { // 查产品SN ZS
  7847. d1OEEPartNo = "Test";
  7848. }
  7849. short d1OEEMES_FLAG = 0;
  7850. // 上传OEE
  7851. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7852. d1OEEMES_FLAG = result.Item1;
  7853. resultStr = result.Item2;
  7854. stopwatch2.Start();
  7855. // MES_Flag
  7856. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7857. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7858. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7859. writeToPLC_Flag.Adress = 2398;
  7860. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7861. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7862. stopwatch2.Stop();
  7863. }
  7864. catch (Exception ex)
  7865. {
  7866. string str = ex.StackTrace;
  7867. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7868. // MES_Flag
  7869. stopwatch2.Start();
  7870. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7871. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7872. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7873. writeToPLC_Flag.Adress = 2398;
  7874. writeToPLC_Flag.Value = (short)4;
  7875. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7876. stopwatch2.Stop();
  7877. }
  7878. stopwatch1.Stop();
  7879. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7880. }
  7881. /// <summary>
  7882. /// [S4] 取放桁架 - S4_2桁架
  7883. /// </summary>
  7884. /// <param name="plcNo">PLC编号</param>
  7885. /// <param name="stationNameStr">工站全称</param>
  7886. private void S4_2桁架(int plcNo, string stationNameStr)
  7887. {
  7888. Stopwatch stopwatch1 = new Stopwatch();
  7889. Stopwatch stopwatch2 = new Stopwatch();
  7890. try
  7891. {
  7892. stopwatch1.Start();
  7893. // ZS 弹夹扫码
  7894. string d2BulletclipCode = " "; // 扫到的码
  7895. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7896. short d2BulletclipScanCode = 2;
  7897. stopwatch2.Start();
  7898. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7899. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7900. //// MES_Flag
  7901. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7902. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7903. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7904. writeToPLC_Flag.Adress = 2430;
  7905. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7906. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7907. {
  7908. Name = "d2BulletclipCode",
  7909. Adress = 2432,
  7910. ValueType = PLCValueType.String,
  7911. ValueTypeStrLength = 20,
  7912. Value = d2BulletclipCode
  7913. });
  7914. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7915. {
  7916. Name = "d2BulletclipStates",
  7917. Adress = 2431,
  7918. ValueType = PLCValueType.Short,
  7919. Value = d2BulletclipStates
  7920. });
  7921. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7922. stopwatch2.Stop();
  7923. }
  7924. catch (Exception ex)
  7925. {
  7926. string str = ex.StackTrace;
  7927. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7928. stopwatch2.Start();
  7929. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7930. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7931. // MES_Flag
  7932. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7933. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7934. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7935. writeToPLC_Flag.Adress = 2430;
  7936. writeToPLC_Flag.Value = (short)6;
  7937. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7938. {
  7939. Name = "d2BulletclipCode",
  7940. Adress = 2432,
  7941. ValueType = PLCValueType.String,
  7942. ValueTypeStrLength = 20,
  7943. Value = " "
  7944. });
  7945. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7946. {
  7947. Name = "d2BulletclipStates",
  7948. Adress = 2431,
  7949. ValueType = PLCValueType.Short,
  7950. Value = (short)0
  7951. });
  7952. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7953. stopwatch2.Stop();
  7954. }
  7955. stopwatch1.Stop();
  7956. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7957. }
  7958. // 上次采集到的SN
  7959. //private string sn_S4_3进站接口 = string.Empty;
  7960. /// <summary>
  7961. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7962. /// </summary>
  7963. private void S4_3进站接口(int plcNo, string stationNameStr)
  7964. {
  7965. Stopwatch stopwatch1 = new Stopwatch();
  7966. Stopwatch stopwatch2 = new Stopwatch();
  7967. try
  7968. {
  7969. stopwatch1.Start();
  7970. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7971. sn = sn.Replace("\0", "");
  7972. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7973. #region 查询15个载具码
  7974. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7975. string vehicleData = string.Empty;
  7976. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7977. if (string.IsNullOrEmpty(vehicleData))
  7978. vehicleData = "";
  7979. if (snResult != 0)
  7980. {
  7981. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7982. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7983. writeToPLC_Flag1.Adress = 2463;
  7984. writeToPLC_Flag1.Value = (short)4;
  7985. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7986. stopwatch1.Stop();
  7987. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7988. return;
  7989. }
  7990. string[] cavitySNs = vehicleData.Split('.');
  7991. if (cavitySNs != null && cavitySNs.Length > 0)
  7992. {
  7993. for (int i = 0; i < cavitySNs.Length; i++)
  7994. {
  7995. if (string.IsNullOrEmpty(cavitySNs[i]))
  7996. vehicleCodes.Add("");
  7997. else
  7998. vehicleCodes.Add(cavitySNs[i]);
  7999. }
  8000. }
  8001. #endregion 查询15个载具码
  8002. #region 查询15个产品SN
  8003. List<string> portNos = new List<string>(); // 15个产品SN
  8004. foreach (string vehicleCode in vehicleCodes)
  8005. {
  8006. if (string.IsNullOrEmpty(vehicleCode))
  8007. portNos.Add("");
  8008. else
  8009. {
  8010. // 查询
  8011. string cavityData = string.Empty;
  8012. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8013. if (string.IsNullOrEmpty(cavityData))
  8014. cavityData = "";
  8015. if (snResult1 != 0)
  8016. {
  8017. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8018. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8019. writeToPLC_Flag1.Adress = 2463;
  8020. writeToPLC_Flag1.Value = (short)4;
  8021. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8022. stopwatch1.Stop();
  8023. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8024. return;
  8025. }
  8026. string[] partSNs = cavityData.Split('.');
  8027. if (partSNs != null && partSNs.Length >= 1)
  8028. portNos.Add(partSNs[0]);
  8029. else
  8030. portNos.Add("");
  8031. }
  8032. }
  8033. #endregion 查询15个产品SN
  8034. // 调用MES进站(最多15个)
  8035. stopwatch2.Start();
  8036. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8037. for (int i = 0; i < vehicleCodes.Count; i++)
  8038. {
  8039. // 循环进站
  8040. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8041. {
  8042. // 产品SN(物料码)校验
  8043. string portNo = portNos[i];
  8044. List<TestItem> item = new List<TestItem>();
  8045. item.Add(new TestItem()
  8046. {
  8047. Parameter_name = "弹夹码",
  8048. Parameter_value = sn,
  8049. });
  8050. item.Add(new TestItem()
  8051. {
  8052. Parameter_name = "弹夹穴位",
  8053. Parameter_value = (i + 1).ToString(),
  8054. });
  8055. item.Add(new TestItem()
  8056. {
  8057. Parameter_name = "载具码",
  8058. Parameter_value = vehicleCodes[i],
  8059. });
  8060. item.Add(new TestItem()
  8061. {
  8062. Parameter_name = "载具穴号",
  8063. Parameter_value = "1",
  8064. });
  8065. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8066. }
  8067. }
  8068. stopwatch2.Stop();
  8069. short result = 0;
  8070. bool haveMesWarn = results.Contains(5);
  8071. bool havePCWarn = results.Contains(6);
  8072. if (haveMesWarn)
  8073. result = 2; // 5->2
  8074. else if (havePCWarn)
  8075. result = 6; // 6->4
  8076. else
  8077. result = 1;
  8078. // MES_Flag 为4MES报错
  8079. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8080. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8081. writeToPLC_Flag.Name = "d3MES_FLAG";
  8082. writeToPLC_Flag.Adress = 2463;
  8083. writeToPLC_Flag.Value = result;
  8084. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8085. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8086. }
  8087. catch (Exception ex)
  8088. {
  8089. stopwatch2.Stop();
  8090. // MES_Flag 为4上位机报错
  8091. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  8092. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8093. writeToPLC_Flag.Name = "d3MES_FLAG";
  8094. writeToPLC_Flag.Adress = 2463;
  8095. writeToPLC_Flag.Value = (short)4;
  8096. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8097. string str = ex.StackTrace;
  8098. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8099. }
  8100. stopwatch1.Stop();
  8101. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8102. }
  8103. // 上次采集到的SN
  8104. //private string sn_S4_3出站接口 = string.Empty;
  8105. /// <summary>
  8106. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  8107. /// </summary>
  8108. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  8109. {
  8110. Stopwatch stopwatch1 = new Stopwatch();
  8111. Stopwatch stopwatch2 = new Stopwatch();
  8112. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8113. string stationNameStr = stationCode + stationName;
  8114. string processItem = stationName; // 测试项目
  8115. try
  8116. {
  8117. stopwatch1.Start();
  8118. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8119. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8120. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8121. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8122. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  8123. sn = sn.Replace("\0", "");
  8124. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  8125. bool isPass = d3Result == 1; // 产品结果 bool
  8126. #region 查询15个载具码
  8127. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8128. string vehicleData = string.Empty;
  8129. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8130. if (string.IsNullOrEmpty(vehicleData))
  8131. vehicleData = "";
  8132. if (snResult1 != 0)
  8133. {
  8134. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8135. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8136. writeToPLC_Flag1.Adress = 2463;
  8137. writeToPLC_Flag1.Value = (short)4;
  8138. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8139. stopwatch1.Stop();
  8140. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8141. return;
  8142. }
  8143. string[] cavitySNs = vehicleData.Split('.');
  8144. if (cavitySNs != null && cavitySNs.Length > 0)
  8145. {
  8146. for (int i = 0; i < cavitySNs.Length; i++)
  8147. {
  8148. if (string.IsNullOrEmpty(cavitySNs[i]))
  8149. vehicleCodes.Add("");
  8150. else
  8151. vehicleCodes.Add(cavitySNs[i]);
  8152. }
  8153. }
  8154. #endregion 查询15个载具码
  8155. // 统一查 产品SN列表
  8156. List<string> partNos = new List<string>();
  8157. foreach (string vehicleCode in vehicleCodes)
  8158. {
  8159. if (string.IsNullOrEmpty(vehicleCode))
  8160. partNos.Add("");
  8161. else
  8162. {
  8163. string partNo = "";
  8164. #region 查询载具上的产品信息
  8165. string cavityData = string.Empty;
  8166. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8167. if (string.IsNullOrEmpty(cavityData))
  8168. cavityData = "";
  8169. if (snResult != 0)
  8170. {
  8171. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8172. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8173. writeToPLC_Flag1.Adress = 2463;
  8174. writeToPLC_Flag1.Value = (short)4;
  8175. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8176. stopwatch1.Stop();
  8177. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8178. return;
  8179. }
  8180. string[] partSNs = cavityData.Split('.');
  8181. if (partSNs != null && partSNs.Length >= 1)
  8182. partNo = partSNs[0];
  8183. #endregion 查询载具上的产品信息
  8184. partNos.Add(partNo);
  8185. }
  8186. }
  8187. // 统一上传 - 调用MES出站
  8188. stopwatch2.Start();
  8189. List<int> results = new List<int>();
  8190. for (int i = 0; i < partNos.Count; i++)
  8191. {
  8192. string index = (i + 1).ToString(); // 弹夹穴号
  8193. if (string.IsNullOrEmpty(partNos[i]))
  8194. results.Add(1);
  8195. else
  8196. {
  8197. List<TestItem> items1 = new List<TestItem>();
  8198. items1.Add(new TestItem()
  8199. {
  8200. Parameter_name = "弹夹码",
  8201. Parameter_value = sn,
  8202. Parameter_unit = ""
  8203. });
  8204. items1.Add(new TestItem()
  8205. {
  8206. Parameter_name = "弹夹穴号",
  8207. Parameter_value = index,
  8208. Parameter_unit = ""
  8209. });
  8210. items1.Add(new TestItem()
  8211. {
  8212. Parameter_name = "载具码",
  8213. Parameter_value = vehicleCodes[i],
  8214. Parameter_unit = ""
  8215. });
  8216. items1.Add(new TestItem()
  8217. {
  8218. Parameter_name = "载具穴号",
  8219. Parameter_value = "1",
  8220. Parameter_unit = ""
  8221. });
  8222. items1.Add(new TestItem()
  8223. {
  8224. Parameter_name = "产品结果",
  8225. Parameter_value = d3Result == 1 ? "OK" : "NG",
  8226. Parameter_unit = ""
  8227. });
  8228. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8229. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8230. results.Add(result1);
  8231. }
  8232. }
  8233. short result = 0;
  8234. if (results.All(a => a == 1))
  8235. result = 1;
  8236. else if (results.Contains(3))
  8237. result = 3;
  8238. else if (results.Contains(2))
  8239. result = 2;
  8240. else if (results.Contains(4))
  8241. result = 4;
  8242. else
  8243. result = 4;
  8244. stopwatch2.Stop();
  8245. // MES_Flag 为4MES报错
  8246. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8247. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8248. writeToPLC_Flag.Name = "d3MES_FLAG";
  8249. writeToPLC_Flag.Adress = 2463;
  8250. writeToPLC_Flag.Value = result;
  8251. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8252. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8253. }
  8254. catch (Exception ex)
  8255. {
  8256. stopwatch2.Restart();
  8257. // MES_Flag 为4上位机报错
  8258. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  8259. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8260. writeToPLC_Flag.Name = "d3MES_FLAG";
  8261. writeToPLC_Flag.Adress = 2463;
  8262. writeToPLC_Flag.Value = (short)4;
  8263. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8264. string str = ex.StackTrace;
  8265. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8266. stopwatch2.Stop();
  8267. }
  8268. stopwatch1.Stop();
  8269. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8270. }
  8271. // 上次采集到的SN
  8272. //private string sn_S4_4进站接口 = string.Empty;
  8273. /// <summary>
  8274. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  8275. /// </summary>
  8276. private void S4_4进站接口(int plcNo, string stationNameStr)
  8277. {
  8278. Stopwatch stopwatch1 = new Stopwatch();
  8279. Stopwatch stopwatch2 = new Stopwatch();
  8280. try
  8281. {
  8282. stopwatch1.Start();
  8283. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8284. sn = sn.Replace("\0", "");
  8285. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8286. #region 查询15个载具码
  8287. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8288. string vehicleData = string.Empty;
  8289. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8290. if (string.IsNullOrEmpty(vehicleData))
  8291. vehicleData = "";
  8292. if (snResult != 0)
  8293. {
  8294. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8295. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8296. writeToPLC_Flag1.Adress = 2463;
  8297. writeToPLC_Flag1.Value = (short)4;
  8298. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8299. stopwatch1.Stop();
  8300. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8301. return;
  8302. }
  8303. string[] cavitySNs = vehicleData.Split('.');
  8304. if (cavitySNs != null && cavitySNs.Length > 0)
  8305. {
  8306. for (int i = 0; i < cavitySNs.Length; i++)
  8307. {
  8308. if (string.IsNullOrEmpty(cavitySNs[i]))
  8309. vehicleCodes.Add("");
  8310. else
  8311. vehicleCodes.Add(cavitySNs[i]);
  8312. }
  8313. }
  8314. #endregion 查询15个载具码
  8315. #region 查询15个产品SN
  8316. List<string> portNos = new List<string>(); // 15个产品SN
  8317. foreach (string vehicleCode in vehicleCodes)
  8318. {
  8319. if (string.IsNullOrEmpty(vehicleCode))
  8320. portNos.Add("");
  8321. else
  8322. {
  8323. // 查询
  8324. string cavityData = string.Empty;
  8325. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8326. if (string.IsNullOrEmpty(cavityData))
  8327. cavityData = "";
  8328. if (snResult1 != 0)
  8329. {
  8330. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8331. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8332. writeToPLC_Flag1.Adress = 2463;
  8333. writeToPLC_Flag1.Value = (short)4;
  8334. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8335. stopwatch1.Stop();
  8336. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8337. return;
  8338. }
  8339. string[] partSNs = cavityData.Split('.');
  8340. if (partSNs != null && partSNs.Length >= 1)
  8341. portNos.Add(partSNs[0]);
  8342. else
  8343. portNos.Add("");
  8344. }
  8345. }
  8346. #endregion 查询15个产品SN
  8347. // 调用MES进站(最多15个)
  8348. stopwatch2.Start();
  8349. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8350. for (int i = 0; i < vehicleCodes.Count; i++)
  8351. {
  8352. // 循环进站
  8353. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8354. {
  8355. // 产品SN(物料码)校验
  8356. string portNo = portNos[i];
  8357. List<TestItem> item = new List<TestItem>();
  8358. item.Add(new TestItem()
  8359. {
  8360. Parameter_name = "弹夹码",
  8361. Parameter_value = sn,
  8362. });
  8363. item.Add(new TestItem()
  8364. {
  8365. Parameter_name = "弹夹穴位",
  8366. Parameter_value = (i + 1).ToString(),
  8367. });
  8368. item.Add(new TestItem()
  8369. {
  8370. Parameter_name = "载具码",
  8371. Parameter_value = vehicleCodes[i],
  8372. });
  8373. item.Add(new TestItem()
  8374. {
  8375. Parameter_name = "载具穴号",
  8376. Parameter_value = "1",
  8377. });
  8378. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8379. }
  8380. }
  8381. stopwatch2.Stop();
  8382. short result = 0;
  8383. bool haveMesWarn = results.Contains(5);
  8384. bool havePCWarn = results.Contains(6);
  8385. if (haveMesWarn)
  8386. result = 2; // 5->2
  8387. else if (havePCWarn)
  8388. result = 6; // 6->4
  8389. else
  8390. result = 1;
  8391. // MES_Flag 为4MES报错
  8392. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8393. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8394. writeToPLC_Flag.Name = "d4MES_FLAG";
  8395. writeToPLC_Flag.Adress = 2496;
  8396. writeToPLC_Flag.Value = result;
  8397. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8398. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8399. }
  8400. catch (Exception ex)
  8401. {
  8402. stopwatch2.Stop();
  8403. // MES_Flag 为4上位机报错
  8404. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8405. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8406. writeToPLC_Flag.Name = "d4MES_FLAG";
  8407. writeToPLC_Flag.Adress = 2496;
  8408. writeToPLC_Flag.Value = (short)4;
  8409. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8410. string str = ex.StackTrace;
  8411. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8412. }
  8413. stopwatch1.Stop();
  8414. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8415. }
  8416. // 上次采集到的SN
  8417. //private string sn_S4_4出站接口 = string.Empty;
  8418. /// <summary>
  8419. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8420. /// </summary>
  8421. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8422. {
  8423. Stopwatch stopwatch1 = new Stopwatch();
  8424. Stopwatch stopwatch2 = new Stopwatch();
  8425. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8426. string stationNameStr = stationCode + stationName;
  8427. string processItem = stationName; // 测试项目
  8428. try
  8429. {
  8430. stopwatch1.Start();
  8431. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8432. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8433. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8434. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8435. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8436. sn = sn.Replace("\0", "");
  8437. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8438. bool isPass = d4Result == 1; // 产品结果 bool
  8439. #region 查询15个载具码
  8440. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8441. string vehicleData = string.Empty;
  8442. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8443. if (string.IsNullOrEmpty(vehicleData))
  8444. vehicleData = "";
  8445. if (snResult1 != 0)
  8446. {
  8447. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8448. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8449. writeToPLC_Flag1.Adress = 2496;
  8450. writeToPLC_Flag1.Value = (short)4;
  8451. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8452. stopwatch1.Stop();
  8453. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8454. return;
  8455. }
  8456. string[] cavitySNs = vehicleData.Split('.');
  8457. if (cavitySNs != null && cavitySNs.Length > 0)
  8458. {
  8459. for (int i = 0; i < cavitySNs.Length; i++)
  8460. {
  8461. if (string.IsNullOrEmpty(cavitySNs[i]))
  8462. vehicleCodes.Add("");
  8463. else
  8464. vehicleCodes.Add(cavitySNs[i]);
  8465. }
  8466. }
  8467. #endregion 查询15个载具码
  8468. // 统一查 产品SN列表
  8469. List<string> partNos = new List<string>();
  8470. foreach (string vehicleCode in vehicleCodes)
  8471. {
  8472. if (string.IsNullOrEmpty(vehicleCode))
  8473. partNos.Add("");
  8474. else
  8475. {
  8476. string partNo = "";
  8477. #region 查询载具上的产品信息
  8478. string cavityData = string.Empty;
  8479. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8480. if (string.IsNullOrEmpty(cavityData))
  8481. cavityData = "";
  8482. if (snResult != 0)
  8483. {
  8484. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8485. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8486. writeToPLC_Flag1.Adress = 2496;
  8487. writeToPLC_Flag1.Value = (short)4;
  8488. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8489. stopwatch1.Stop();
  8490. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8491. return;
  8492. }
  8493. string[] partSNs = cavityData.Split('.');
  8494. if (partSNs != null && partSNs.Length >= 1)
  8495. partNo = partSNs[0];
  8496. #endregion 查询载具上的产品信息
  8497. partNos.Add(partNo);
  8498. }
  8499. }
  8500. // 调用MES出站
  8501. stopwatch2.Start();
  8502. // 统一上传
  8503. List<int> results = new List<int>();
  8504. for (int i = 0; i < partNos.Count; i++)
  8505. {
  8506. string index = (i + 1).ToString(); // 弹夹穴号
  8507. if (string.IsNullOrEmpty(partNos[i]))
  8508. results.Add(1);
  8509. else
  8510. {
  8511. List<TestItem> items1 = new List<TestItem>();
  8512. items1.Add(new TestItem()
  8513. {
  8514. Parameter_name = "弹夹码",
  8515. Parameter_value = sn,
  8516. Parameter_unit = ""
  8517. });
  8518. items1.Add(new TestItem()
  8519. {
  8520. Parameter_name = "弹夹穴号",
  8521. Parameter_value = index,
  8522. Parameter_unit = ""
  8523. });
  8524. items1.Add(new TestItem()
  8525. {
  8526. Parameter_name = "载具码",
  8527. Parameter_value = vehicleCodes[i],
  8528. Parameter_unit = ""
  8529. });
  8530. items1.Add(new TestItem()
  8531. {
  8532. Parameter_name = "载具穴号",
  8533. Parameter_value = "1",
  8534. Parameter_unit = ""
  8535. });
  8536. items1.Add(new TestItem()
  8537. {
  8538. Parameter_name = "产品结果",
  8539. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8540. Parameter_unit = ""
  8541. });
  8542. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8543. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8544. results.Add(result1);
  8545. }
  8546. }
  8547. short result = 0;
  8548. if (results.All(a => a == 1))
  8549. result = 1;
  8550. else if (results.Contains(3))
  8551. result = 3;
  8552. else if (results.Contains(2))
  8553. result = 2;
  8554. else if (results.Contains(4))
  8555. result = 4;
  8556. else
  8557. result = 4;
  8558. stopwatch2.Stop();
  8559. // MES_Flag 为4MES报错
  8560. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8561. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8562. writeToPLC_Flag.Name = "d4MES_FLAG";
  8563. writeToPLC_Flag.Adress = 2496;
  8564. writeToPLC_Flag.Value = result;
  8565. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8566. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8567. }
  8568. catch (Exception ex)
  8569. {
  8570. stopwatch2.Restart();
  8571. // MES_Flag 为4上位机报错
  8572. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8573. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8574. writeToPLC_Flag.Name = "d4MES_FLAG";
  8575. writeToPLC_Flag.Adress = 2496;
  8576. writeToPLC_Flag.Value = (short)4;
  8577. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8578. string str = ex.StackTrace;
  8579. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8580. stopwatch2.Stop();
  8581. }
  8582. stopwatch1.Stop();
  8583. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8584. }
  8585. /// <summary>
  8586. /// [S4] 取放桁架 - S4_5弹夹扫码
  8587. /// </summary>
  8588. /// <param name="plcNo">PLC编号</param>
  8589. /// <param name="stationNameStr">工站全称</param>
  8590. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8591. {
  8592. Stopwatch stopwatch1 = new Stopwatch();
  8593. Stopwatch stopwatch2 = new Stopwatch();
  8594. try
  8595. {
  8596. stopwatch1.Start();
  8597. // ZS 弹夹扫码
  8598. string d5BulletclipCode = " "; // 扫到的码
  8599. short d5BulletclipScanCode = 2;
  8600. stopwatch2.Start();
  8601. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8602. //// MES_Flag
  8603. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8604. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8605. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8606. writeToPLC_Flag.Adress = 2528;
  8607. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8608. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8609. {
  8610. Name = "d5BulletclipCode",
  8611. Adress = 2529,
  8612. ValueType = PLCValueType.String,
  8613. ValueTypeStrLength = 20,
  8614. Value = d5BulletclipCode
  8615. });
  8616. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8617. stopwatch2.Stop();
  8618. }
  8619. catch (Exception ex)
  8620. {
  8621. string str = ex.StackTrace;
  8622. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8623. stopwatch2.Start();
  8624. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8625. //// MES_Flag
  8626. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8627. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8628. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8629. writeToPLC_Flag.Adress = 2528;
  8630. writeToPLC_Flag.Value = (short)6;
  8631. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8632. {
  8633. Name = "d5BulletclipCode",
  8634. Adress = 2529,
  8635. ValueType = PLCValueType.String,
  8636. ValueTypeStrLength = 20,
  8637. Value = " "
  8638. });
  8639. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8640. stopwatch2.Stop();
  8641. }
  8642. stopwatch1.Stop();
  8643. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8644. }
  8645. /// <summary>
  8646. /// [S4] 取放桁架 - S4_5载具扫码
  8647. /// </summary>
  8648. /// <param name="plcNo">PLC编号</param>
  8649. /// <param name="stationNameStr">工站全称</param>
  8650. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8651. {
  8652. Stopwatch stopwatch1 = new Stopwatch();
  8653. Stopwatch stopwatch2 = new Stopwatch();
  8654. try
  8655. {
  8656. stopwatch1.Start();
  8657. // ZS 载具扫码
  8658. string d5VehicleCode = " "; // 扫到的码
  8659. short d5VehicleScanCode = 2;
  8660. #region 进站
  8661. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8662. {
  8663. // 查产品SN
  8664. #region 查询载具上的产品信息
  8665. string cavityData = string.Empty;
  8666. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8667. if (string.IsNullOrEmpty(cavityData))
  8668. cavityData = "";
  8669. if (snResult != 0)
  8670. {
  8671. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8672. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8673. writeToPLC_Flag1.Adress = 2559;
  8674. writeToPLC_Flag1.Value = (short)6;
  8675. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8676. {
  8677. Name = "d5VehicleCode",
  8678. Adress = 2560,
  8679. ValueType = PLCValueType.String,
  8680. ValueTypeStrLength = 20,
  8681. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8682. });
  8683. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8684. stopwatch1.Stop();
  8685. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8686. return;
  8687. }
  8688. string[] cavitySNs = cavityData.Split('.');
  8689. string partNo = "";
  8690. if (cavitySNs != null && cavitySNs.Length >= 1)
  8691. {
  8692. partNo = cavitySNs[0];
  8693. }
  8694. #endregion 查询载具上的产品信息
  8695. List<TestItem> item = new List<TestItem>();
  8696. item.Add(new TestItem()
  8697. {
  8698. Parameter_name = "载具码",
  8699. Parameter_value = d5VehicleCode,
  8700. });
  8701. item.Add(new TestItem()
  8702. {
  8703. Parameter_name = "载具穴号",
  8704. Parameter_value = "1",
  8705. });
  8706. stopwatch2.Start();
  8707. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8708. stopwatch2.Stop();
  8709. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8710. }
  8711. #endregion 进站
  8712. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8713. //// MES_Flag
  8714. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8715. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8716. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8717. writeToPLC_Flag.Adress = 2559;
  8718. writeToPLC_Flag.Value = d5VehicleScanCode;
  8719. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8720. {
  8721. Name = "d5VehicleCode",
  8722. Adress = 2560,
  8723. ValueType = PLCValueType.String,
  8724. ValueTypeStrLength = 20,
  8725. Value = d5VehicleCode
  8726. });
  8727. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8728. }
  8729. catch (Exception ex)
  8730. {
  8731. string str = ex.StackTrace;
  8732. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8733. stopwatch2.Start();
  8734. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8735. //// MES_Flag
  8736. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8737. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8738. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8739. writeToPLC_Flag.Adress = 2559;
  8740. writeToPLC_Flag.Value = (short)6;
  8741. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8742. {
  8743. Name = "d5VehicleCode",
  8744. Adress = 2560,
  8745. ValueType = PLCValueType.String,
  8746. ValueTypeStrLength = 20,
  8747. Value = " "
  8748. });
  8749. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8750. stopwatch2.Stop();
  8751. }
  8752. stopwatch1.Stop();
  8753. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8754. }
  8755. // 上次采集到的SN
  8756. //private string sn_S4_5出站接口 = string.Empty;
  8757. /// <summary>
  8758. /// [S4] 取放桁架 - S4_5出站接口
  8759. /// </summary>
  8760. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8761. {
  8762. Stopwatch stopwatch1 = new Stopwatch();
  8763. Stopwatch stopwatch2 = new Stopwatch();
  8764. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8765. string stationNameStr = stationCode + stationName;
  8766. string processItem = stationName; // 测试项目
  8767. try
  8768. {
  8769. stopwatch1.Start();
  8770. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8771. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8772. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8773. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8774. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8775. sn = sn.Replace("\0", "");
  8776. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8777. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8778. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8779. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8780. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8781. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8782. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8783. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8784. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8785. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8786. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8787. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8788. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8789. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8790. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8791. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8792. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8793. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8794. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8795. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8796. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8797. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8798. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8799. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8800. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8801. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8802. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8803. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8804. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8805. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8806. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8807. bool pass = d5Result == 1;
  8808. // 存 载具SN列表
  8809. List<string> vehicleCodes = new List<string>()
  8810. {
  8811. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8812. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8813. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8814. };
  8815. // 统一查 产品SN列表
  8816. List<string> partNos = new List<string>();
  8817. foreach (string vehicleCode in vehicleCodes)
  8818. {
  8819. if (string.IsNullOrEmpty(vehicleCode))
  8820. partNos.Add("");
  8821. else
  8822. {
  8823. string partNo = "";
  8824. #region 查询载具上的产品信息
  8825. string cavityData = string.Empty;
  8826. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8827. if (string.IsNullOrEmpty(cavityData))
  8828. cavityData = "";
  8829. if (snResult != 0)
  8830. {
  8831. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8832. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8833. writeToPLC_Flag1.Adress = 2591;
  8834. writeToPLC_Flag1.Value = (short)4;
  8835. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8836. stopwatch1.Stop();
  8837. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8838. return;
  8839. }
  8840. string[] cavitySNs = cavityData.Split('.');
  8841. if (cavitySNs != null && cavitySNs.Length >= 1)
  8842. partNo = cavitySNs[0];
  8843. #endregion 查询载具上的产品信息
  8844. partNos.Add(partNo);
  8845. }
  8846. }
  8847. // 统一上传
  8848. stopwatch2.Start();
  8849. List<int> results = new List<int>();
  8850. for (int i = 0; i < partNos.Count; i++)
  8851. {
  8852. string index = (i + 1).ToString(); // 弹夹穴号
  8853. if (string.IsNullOrEmpty(partNos[i]))
  8854. results.Add(1);
  8855. else
  8856. {
  8857. List<TestItem> items1 = new List<TestItem>();
  8858. items1.Add(new TestItem()
  8859. {
  8860. Parameter_name = "弹夹码",
  8861. Parameter_value = sn,
  8862. Parameter_unit = ""
  8863. });
  8864. items1.Add(new TestItem()
  8865. {
  8866. Parameter_name = "弹夹穴号",
  8867. Parameter_value = index,
  8868. Parameter_unit = ""
  8869. });
  8870. items1.Add(new TestItem()
  8871. {
  8872. Parameter_name = "载具码",
  8873. Parameter_value = vehicleCodes[i],
  8874. Parameter_unit = ""
  8875. });
  8876. items1.Add(new TestItem()
  8877. {
  8878. Parameter_name = "载具穴号",
  8879. Parameter_value = "1",
  8880. Parameter_unit = ""
  8881. });
  8882. items1.Add(new TestItem()
  8883. {
  8884. Parameter_name = "产品结果",
  8885. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8886. Parameter_unit = ""
  8887. });
  8888. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8889. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8890. results.Add(result1);
  8891. }
  8892. }
  8893. short result = 0;
  8894. if (results.All(a => a == 1))
  8895. result = 1;
  8896. else if (results.Contains(3))
  8897. result = 3;
  8898. else if (results.Contains(2))
  8899. result = 2;
  8900. else if (results.Contains(4))
  8901. result = 4;
  8902. else
  8903. result = 4;
  8904. stopwatch2.Stop();
  8905. #region 存储绑定数据到 边线MES系统中
  8906. if (result == 1)
  8907. {
  8908. // 删除绑定信息
  8909. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8910. if (resultMesR != 0)
  8911. {
  8912. result = 4;
  8913. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8914. }
  8915. }
  8916. #endregion 存储绑定数据到 边线MES系统中
  8917. // MES_Flag 为4MES报错
  8918. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8919. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8920. writeToPLC_Flag.Name = "d5MES_FLAG";
  8921. writeToPLC_Flag.Adress = 2591;
  8922. writeToPLC_Flag.Value = result;
  8923. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8924. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8925. }
  8926. catch (Exception ex)
  8927. {
  8928. stopwatch2.Restart();
  8929. // MES_Flag 为4上位机报错
  8930. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8931. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8932. writeToPLC_Flag.Name = "d5MES_FLAG";
  8933. writeToPLC_Flag.Adress = 2591;
  8934. writeToPLC_Flag.Value = (short)4;
  8935. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8936. stopwatch2.Stop();
  8937. string str = ex.StackTrace;
  8938. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8939. }
  8940. stopwatch1.Stop();
  8941. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8942. }
  8943. /// <summary>
  8944. /// [S4] 取放桁架 - S4_5节拍接口
  8945. /// </summary>
  8946. /// <param name="plcNo">PLC编号</param>
  8947. /// <param name="stationNameStr">工站全称</param>
  8948. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8949. {
  8950. Stopwatch stopwatch1 = new Stopwatch();
  8951. Stopwatch stopwatch2 = new Stopwatch();
  8952. string resultStr = string.Empty;
  8953. try
  8954. {
  8955. stopwatch1.Start();
  8956. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8957. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8958. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8959. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8960. if (!actionBool)
  8961. {
  8962. stopwatch2.Start();
  8963. // MES_Flag
  8964. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8965. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8966. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8967. writeToPLC_Flag1.Adress = 2924;
  8968. writeToPLC_Flag1.Value = (short)4;
  8969. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8970. stopwatch2.Stop();
  8971. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8972. return;
  8973. }
  8974. string d5OEEPartNo = string.Empty; // 物料码
  8975. if (string.IsNullOrEmpty(d5OEEProductSN))
  8976. {
  8977. stopwatch2.Start();
  8978. // MES_Flag
  8979. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8980. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8981. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8982. writeToPLC_Flag1.Adress = 2924;
  8983. writeToPLC_Flag1.Value = (short)1;
  8984. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8985. stopwatch2.Stop();
  8986. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8987. return;
  8988. }
  8989. else
  8990. { // 查产品SN
  8991. d5OEEPartNo = "Test"; // ZS
  8992. }
  8993. short d5OEEMES_FLAG = 0;
  8994. // 上传OEE
  8995. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8996. d5OEEMES_FLAG = result.Item1;
  8997. resultStr = result.Item2;
  8998. stopwatch2.Start();
  8999. // MES_Flag
  9000. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9001. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9002. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  9003. writeToPLC_Flag.Adress = 2924;
  9004. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  9005. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  9006. stopwatch2.Stop();
  9007. }
  9008. catch (Exception ex)
  9009. {
  9010. string str = ex.StackTrace;
  9011. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9012. // MES_Flag
  9013. stopwatch2.Start();
  9014. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  9015. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9016. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  9017. writeToPLC_Flag.Adress = 2924;
  9018. writeToPLC_Flag.Value = (short)4;
  9019. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  9020. stopwatch2.Stop();
  9021. }
  9022. stopwatch1.Stop();
  9023. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9024. }
  9025. #endregion [S4] 取放桁架
  9026. #endregion PLC4 刘果段
  9027. #region PLC5 张超凡
  9028. #region [S5] Tray盘下料装备
  9029. /// <summary>
  9030. /// S5工位的数据- 触发信号上次的值
  9031. /// </summary>
  9032. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  9033. /// <summary>
  9034. /// S5工位的数据(含触发信号)
  9035. /// </summary>
  9036. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  9037. /// <summary>
  9038. /// S5工位的数据- 回写点位
  9039. /// </summary>
  9040. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  9041. /// <summary>
  9042. /// [S5] Tray盘下料装备
  9043. /// </summary>
  9044. /// <param name="plcNo">PLC编号</param>
  9045. //private void ReadStation_S5(int plcNo)
  9046. //{
  9047. // // [S1] Tray盘上料装备
  9048. // // [S2] FCT
  9049. // // [S3] 值板机
  9050. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  9051. // // [S5] Tray盘下料装备
  9052. // /// 上位机心跳
  9053. // /// 获取设备报警数据与状态信息
  9054. // string stationCode = "[S5]";
  9055. // string stationName = "Tray盘下料装备";
  9056. // string stationNameStr = stationCode + stationName;
  9057. // #region 创建字典
  9058. // // 触发信号字典 赋值
  9059. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  9060. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9061. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9062. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  9063. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  9064. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  9065. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  9066. // // PLC数据字典 赋值
  9067. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  9068. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  9069. // s5PLCData.Add("e1ProductSN_Check", ""); //
  9070. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9071. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  9072. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  9073. // s5PLCData.Add("e1PartNo", ""); // 物料码
  9074. // s5PLCData.Add("e1Result", 0); // 产品结果
  9075. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9076. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  9077. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  9078. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  9079. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  9080. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  9081. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  9082. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  9083. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  9084. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  9085. // #endregion 创建字典
  9086. // while (IsRun)
  9087. // {
  9088. // try
  9089. // {
  9090. // if (!GlobalContext._IsCon_Funs5)
  9091. // {
  9092. // UpdatePLCMonitor(1, plcNo, 0);
  9093. // continue;
  9094. // }
  9095. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9096. // {
  9097. // Stopwatch stopwatch1 = new Stopwatch();
  9098. // Stopwatch stopwatch2 = new Stopwatch();
  9099. // stopwatch1.Start();
  9100. // stopwatch2.Start();
  9101. // #region 一次性读取所有数据
  9102. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9103. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  9104. // int[] datas = data1.Concat(data2).ToArray();
  9105. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  9106. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  9107. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  9108. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  9109. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  9110. // s5PLCData["e1MES_FLAG"] = datas[35];
  9111. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  9112. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  9113. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  9114. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  9115. // s5PLCData["e1Result"] = datas[76];
  9116. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  9117. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  9118. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  9119. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  9120. // s5PLCData["e1OEEType"] = datas[109];
  9121. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  9122. // s5PLCData["e1AGVUpStart"] = datas[121];
  9123. // s5PLCData["e1AGVUpEnd"] = datas[122];
  9124. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  9125. // s5PLCData["e1AGVDownStart"] = datas[134];
  9126. // s5PLCData["e1AGVDownEnd"] = datas[135];
  9127. // #endregion 一次性读取所有数据
  9128. // stopwatch2.Stop();
  9129. // #region 回写操作,写后清空flag
  9130. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  9131. // #endregion 回写操作,写后清空flag
  9132. // #region 进站校验
  9133. // try
  9134. // {
  9135. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  9136. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  9137. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  9138. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  9139. // {
  9140. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  9141. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  9142. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  9143. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  9144. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  9145. // }
  9146. // }
  9147. // catch (Exception ex)
  9148. // {
  9149. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9150. // string str = ex.StackTrace;
  9151. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9152. // }
  9153. // #endregion 进站校验
  9154. // #region 出站接口
  9155. // try
  9156. // {
  9157. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  9158. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  9159. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  9160. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  9161. // {
  9162. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  9163. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9164. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  9165. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  9166. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  9167. // }
  9168. // }
  9169. // catch (Exception ex)
  9170. // {
  9171. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  9172. // string str = ex.StackTrace;
  9173. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9174. // }
  9175. // #endregion 出站接口
  9176. // #region 节拍接口
  9177. // try
  9178. // {
  9179. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  9180. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  9181. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  9182. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  9183. // {
  9184. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  9185. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9186. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  9187. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  9188. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  9189. // }
  9190. // }
  9191. // catch (Exception ex)
  9192. // {
  9193. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9194. // string str = ex.StackTrace;
  9195. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9196. // }
  9197. // #endregion 节拍接口
  9198. // #region AGV上料
  9199. // // AGV上料叫AGV信号
  9200. // try
  9201. // {
  9202. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  9203. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  9204. // if (e1AGVUpCall != e1AGVUpCallOld)
  9205. // {
  9206. // if (e1AGVUpCall == 1) // 0->1
  9207. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  9208. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  9209. // }
  9210. // }
  9211. // catch (Exception ex)
  9212. // {
  9213. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9214. // string str = ex.StackTrace;
  9215. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9216. // }
  9217. // // AGV上料完成信号
  9218. // try
  9219. // {
  9220. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  9221. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  9222. // if (e1AGVUpEnd != e1AGVUpEndOld)
  9223. // {
  9224. // if (e1AGVUpEnd == 1) // 0->1
  9225. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  9226. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  9227. // }
  9228. // }
  9229. // catch (Exception ex)
  9230. // {
  9231. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9232. // string str = ex.StackTrace;
  9233. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9234. // }
  9235. // #endregion AGV上料
  9236. // #region AGV下料
  9237. // // AGV下料叫agv信号
  9238. // try
  9239. // {
  9240. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  9241. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  9242. // if (e1AGVDownCall != e1AGVDownCallOld)
  9243. // {
  9244. // if (e1AGVDownCall == 1) // 0->1
  9245. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  9246. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  9247. // }
  9248. // }
  9249. // catch (Exception ex)
  9250. // {
  9251. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9252. // string str = ex.StackTrace;
  9253. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9254. // }
  9255. // // AGV下料完成信号
  9256. // try
  9257. // {
  9258. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  9259. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  9260. // if (e1AGVDownEnd != e1AGVDownEndOld)
  9261. // {
  9262. // if (e1AGVDownEnd == 1) // 0->1
  9263. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  9264. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  9265. // }
  9266. // }
  9267. // catch (Exception ex)
  9268. // {
  9269. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9270. // string str = ex.StackTrace;
  9271. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9272. // }
  9273. // #endregion AGV下料
  9274. // #region 心跳
  9275. // try
  9276. // {
  9277. // short states = 0;
  9278. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9279. // }
  9280. // catch (Exception ex)
  9281. // {
  9282. // string str = ex.StackTrace;
  9283. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9284. // }
  9285. // #endregion 心跳
  9286. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9287. // stopwatch1.Stop();
  9288. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9289. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9290. // }
  9291. // else
  9292. // {
  9293. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9294. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9295. // Funs[plcNo].Connect();
  9296. // }
  9297. // }
  9298. // catch (Exception ex)
  9299. // {
  9300. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9301. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9302. // Funs[plcNo].ReConnect();
  9303. // }
  9304. // Thread.Sleep(IntervalReadPLC);
  9305. // }
  9306. //}
  9307. /// <summary>
  9308. /// [S5] Tray盘下料装备 - 进站校验
  9309. /// </summary>
  9310. /// <param name="plcNo">PLC编号</param>
  9311. /// <param name="stationNameStr">工站全称</param>
  9312. private void S5进站校验(int plcNo, string stationNameStr)
  9313. {
  9314. Stopwatch stopwatch1 = new Stopwatch();
  9315. Stopwatch stopwatch2 = new Stopwatch();
  9316. try
  9317. {
  9318. stopwatch1.Start();
  9319. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9320. sn = sn.Replace("\0", "");
  9321. // 获取产品SN By 载具码
  9322. #region 查询载具上的产品信息
  9323. string cavityData = string.Empty;
  9324. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9325. if (string.IsNullOrEmpty(cavityData))
  9326. cavityData = "";
  9327. if (snResult != 0)
  9328. {
  9329. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9330. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9331. writeToPLC_Flag1.Adress = 2003;
  9332. writeToPLC_Flag1.Value = (short)6;
  9333. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9334. stopwatch1.Stop();
  9335. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9336. return;
  9337. }
  9338. string[] cavitySNs = cavityData.Split('.');
  9339. string partNo = string.Empty;
  9340. if (cavitySNs != null && cavitySNs.Length >= 1)
  9341. partNo = cavitySNs[0];
  9342. #endregion 查询载具上的产品信息
  9343. // 产品SN(物料码)校验
  9344. List<TestItem> item = new List<TestItem>();
  9345. item.Add(new TestItem()
  9346. {
  9347. Parameter_name = "载具码",
  9348. Parameter_value = sn,
  9349. });
  9350. item.Add(new TestItem()
  9351. {
  9352. Parameter_name = "载具穴号",
  9353. Parameter_value = "1",
  9354. });
  9355. stopwatch2.Start();
  9356. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9357. stopwatch2.Stop();
  9358. short e1MES_FLAG_Check = (short)result;
  9359. // MES_Flag
  9360. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9361. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9362. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9363. writeToPLC_Flag.Adress = 2003;
  9364. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9365. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9366. }
  9367. catch (Exception ex)
  9368. {
  9369. string str = ex.StackTrace;
  9370. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9371. // MES_Flag
  9372. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9373. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9374. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9375. writeToPLC_Flag.Adress = 2003;
  9376. writeToPLC_Flag.Value = (short)6;
  9377. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9378. }
  9379. stopwatch1.Stop();
  9380. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9381. }
  9382. /// <summary>
  9383. /// [S5] Tray盘下料装备 - 出站接口
  9384. /// </summary>
  9385. /// <param name="plcNo"></param>
  9386. /// <param name="stationCode"></param>
  9387. /// <param name="stationName"></param>
  9388. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9389. {
  9390. Stopwatch stopwatch1 = new Stopwatch();
  9391. Stopwatch stopwatch2 = new Stopwatch();
  9392. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9393. string stationNameStr = stationCode + stationName;
  9394. string processItem = stationName; // 测试项目
  9395. try
  9396. {
  9397. stopwatch1.Start();
  9398. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9399. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9400. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9401. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9402. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9403. sn = sn.Replace("\0", "");
  9404. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9405. //partNo = partNo.Replace("\0", "");
  9406. #region 查询载具上的产品信息
  9407. string cavityData = string.Empty;
  9408. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9409. if (string.IsNullOrEmpty(cavityData))
  9410. cavityData = "";
  9411. if (snResult != 0)
  9412. {
  9413. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9414. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9415. writeToPLC_Flag1.Adress = 2035;
  9416. writeToPLC_Flag1.Value = (short)4;
  9417. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9418. stopwatch1.Stop();
  9419. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9420. return;
  9421. }
  9422. string[] cavitySNs = cavityData.Split('.');
  9423. string partNo = string.Empty;
  9424. if (cavitySNs != null && cavitySNs.Length >= 1)
  9425. partNo = cavitySNs[0];
  9426. #endregion 查询载具上的产品信息
  9427. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9428. bool pass = e1Result == 1;
  9429. stopwatch2.Start();
  9430. // 上传MES
  9431. List<TestItem> items = new List<TestItem>();
  9432. items.Add(new TestItem()
  9433. {
  9434. Parameter_name = "载具码",
  9435. Parameter_value = sn,
  9436. Parameter_unit = ""
  9437. });
  9438. items.Add(new TestItem()
  9439. {
  9440. Parameter_name = "载具穴号",
  9441. Parameter_value = "1",
  9442. Parameter_unit = ""
  9443. });
  9444. items.Add(new TestItem()
  9445. {
  9446. Parameter_name = "产品结果",
  9447. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9448. Parameter_unit = ""
  9449. });
  9450. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  9451. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9452. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9453. short result = result1 == 1 ? (short)1 : (short)3;
  9454. stopwatch2.Stop();
  9455. #region 存储绑定数据到 边线MES系统中
  9456. if (result == 1)
  9457. {
  9458. // 删除绑定信息
  9459. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9460. if (resultMesR != 0)
  9461. {
  9462. result = 4;
  9463. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9464. }
  9465. }
  9466. #endregion 存储绑定数据到 边线MES系统中
  9467. // MES_Flag 为MES报错
  9468. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9469. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9470. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9471. writeToPLC_Flag.Name = "e1MES_FLAG";
  9472. writeToPLC_Flag.Adress = 2035;
  9473. writeToPLC_Flag.Value = result;
  9474. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9475. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9476. }
  9477. catch (Exception ex)
  9478. {
  9479. stopwatch2.Restart();
  9480. // MES_Flag 为4上位机报错
  9481. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9482. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9483. writeToPLC_Flag.Name = "e1MES_FLAG";
  9484. writeToPLC_Flag.Adress = 2035;
  9485. writeToPLC_Flag.Value = (short)4;
  9486. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9487. stopwatch2.Stop();
  9488. string str = ex.StackTrace;
  9489. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9490. }
  9491. stopwatch1.Stop();
  9492. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9493. }
  9494. /// <summary>
  9495. /// [S5] Tray盘下料装备 - 节拍接口
  9496. /// </summary>
  9497. /// <param name="plcNo">PLC编号</param>
  9498. /// <param name="stationNameStr">工站全称</param>
  9499. private void S5节拍接口(int plcNo, string stationNameStr)
  9500. {
  9501. Stopwatch stopwatch1 = new Stopwatch();
  9502. Stopwatch stopwatch2 = new Stopwatch();
  9503. string resultStr = string.Empty;
  9504. try
  9505. {
  9506. stopwatch1.Start();
  9507. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9508. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9509. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9510. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9511. if (!actionBool)
  9512. {
  9513. stopwatch2.Start();
  9514. // MES_Flag
  9515. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9516. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9517. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9518. writeToPLC_Flag1.Adress = 2088;
  9519. writeToPLC_Flag1.Value = (short)4;
  9520. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9521. stopwatch2.Stop();
  9522. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9523. return;
  9524. }
  9525. string e1OEEPartNo = string.Empty; // 物料码
  9526. if (string.IsNullOrEmpty(e1OEEProductSN))
  9527. {
  9528. stopwatch2.Start();
  9529. // MES_Flag
  9530. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9531. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9532. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9533. writeToPLC_Flag1.Adress = 2088;
  9534. writeToPLC_Flag1.Value = (short)1;
  9535. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9536. stopwatch2.Stop();
  9537. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9538. return;
  9539. }
  9540. else
  9541. { // 查产品SN
  9542. e1OEEPartNo = "Test"; // ZS
  9543. }
  9544. short e1OEEMES_FLAG = 0;
  9545. // 上传OEE
  9546. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9547. e1OEEMES_FLAG = result.Item1;
  9548. resultStr = result.Item2;
  9549. stopwatch2.Start();
  9550. // MES_Flag
  9551. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9552. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9553. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9554. writeToPLC_Flag.Adress = 2088;
  9555. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9556. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9557. stopwatch2.Stop();
  9558. }
  9559. catch (Exception ex)
  9560. {
  9561. string str = ex.StackTrace;
  9562. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9563. // MES_Flag
  9564. stopwatch2.Start();
  9565. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9566. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9567. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9568. writeToPLC_Flag.Adress = 2088;
  9569. writeToPLC_Flag.Value = (short)4;
  9570. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9571. stopwatch2.Stop();
  9572. }
  9573. stopwatch1.Stop();
  9574. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9575. }
  9576. /// <summary>
  9577. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9578. /// </summary>
  9579. /// <param name="plcNo">PLC编号</param>
  9580. /// <param name="stationNameStr">工站全称</param>
  9581. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9582. {
  9583. Stopwatch stopwatch1 = new Stopwatch();
  9584. Stopwatch stopwatch2 = new Stopwatch();
  9585. try
  9586. {
  9587. stopwatch1.Start();
  9588. // ZS 呼叫AGV
  9589. short e1AGVUpCall = 2;
  9590. stopwatch2.Start();
  9591. // e1AGVUpCall
  9592. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9593. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9594. writeToPLC_Flag.Name = "e1AGVUpCall";
  9595. writeToPLC_Flag.Adress = 2120;
  9596. writeToPLC_Flag.Value = e1AGVUpCall;
  9597. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9598. stopwatch2.Stop();
  9599. }
  9600. catch (Exception ex)
  9601. {
  9602. string str = ex.StackTrace;
  9603. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9604. // e1AGVUpCall
  9605. stopwatch2.Start();
  9606. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9607. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9608. writeToPLC_Flag.Name = "e1AGVUpCall";
  9609. writeToPLC_Flag.Adress = 2120;
  9610. writeToPLC_Flag.Value = (short)4;
  9611. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9612. stopwatch2.Stop();
  9613. }
  9614. stopwatch1.Stop();
  9615. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9616. }
  9617. /// <summary>
  9618. /// [S5] Tray盘下料装备 - AGV上料完成
  9619. /// </summary>
  9620. /// <param name="plcNo">PLC编号</param>
  9621. /// <param name="stationNameStr">工站全称</param>
  9622. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9623. {
  9624. Stopwatch stopwatch1 = new Stopwatch();
  9625. Stopwatch stopwatch2 = new Stopwatch();
  9626. try
  9627. {
  9628. stopwatch1.Start();
  9629. // ZS AGV上料完成,让小车离开
  9630. short e1AGVUpEnd = 2;
  9631. stopwatch2.Start();
  9632. // e1AGVUpEnd
  9633. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9634. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9635. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9636. writeToPLC_Flag.Adress = 2122;
  9637. writeToPLC_Flag.Value = e1AGVUpEnd;
  9638. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9639. stopwatch2.Stop();
  9640. }
  9641. catch (Exception ex)
  9642. {
  9643. string str = ex.StackTrace;
  9644. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9645. // e1AGVUpEnd
  9646. stopwatch2.Start();
  9647. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9648. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9649. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9650. writeToPLC_Flag.Adress = 2122;
  9651. writeToPLC_Flag.Value = (short)4;
  9652. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9653. stopwatch2.Stop();
  9654. }
  9655. stopwatch1.Stop();
  9656. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9657. }
  9658. /// <summary>
  9659. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9660. /// </summary>
  9661. /// <param name="plcNo">PLC编号</param>
  9662. /// <param name="stationNameStr">工站全称</param>
  9663. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9664. {
  9665. Stopwatch stopwatch1 = new Stopwatch();
  9666. Stopwatch stopwatch2 = new Stopwatch();
  9667. try
  9668. {
  9669. stopwatch1.Start();
  9670. // ZS 呼叫AGV
  9671. short e1AGVDownCall = 2;
  9672. stopwatch2.Start();
  9673. // e1AGVDownCall
  9674. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9675. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9676. writeToPLC_Flag.Name = "e1AGVDownCall";
  9677. writeToPLC_Flag.Adress = 2133;
  9678. writeToPLC_Flag.Value = e1AGVDownCall;
  9679. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9680. stopwatch2.Stop();
  9681. }
  9682. catch (Exception ex)
  9683. {
  9684. string str = ex.StackTrace;
  9685. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9686. // e1AGVDownCall
  9687. stopwatch2.Start();
  9688. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9689. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9690. writeToPLC_Flag.Name = "e1AGVDownCall";
  9691. writeToPLC_Flag.Adress = 2133;
  9692. writeToPLC_Flag.Value = (short)4;
  9693. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9694. stopwatch2.Stop();
  9695. }
  9696. stopwatch1.Stop();
  9697. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9698. }
  9699. /// <summary>
  9700. /// [S5] Tray盘下料装备 - AGV下料完成
  9701. /// </summary>
  9702. /// <param name="plcNo">PLC编号</param>
  9703. /// <param name="stationNameStr">工站全称</param>
  9704. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9705. {
  9706. Stopwatch stopwatch1 = new Stopwatch();
  9707. Stopwatch stopwatch2 = new Stopwatch();
  9708. try
  9709. {
  9710. stopwatch1.Start();
  9711. // ZS AGV上料完成,让小车离开
  9712. short e1AGVDownEnd = 2;
  9713. stopwatch2.Start();
  9714. // e1AGVDownEnd
  9715. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9716. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9717. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9718. writeToPLC_Flag.Adress = 2135;
  9719. writeToPLC_Flag.Value = e1AGVDownEnd;
  9720. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9721. stopwatch2.Stop();
  9722. }
  9723. catch (Exception ex)
  9724. {
  9725. string str = ex.StackTrace;
  9726. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9727. // e1AGVDownEnd
  9728. stopwatch2.Start();
  9729. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9730. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9731. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9732. writeToPLC_Flag.Adress = 2135;
  9733. writeToPLC_Flag.Value = (short)4;
  9734. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9735. stopwatch2.Stop();
  9736. }
  9737. stopwatch1.Stop();
  9738. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9739. }
  9740. #endregion [S5] Tray盘下料装备
  9741. #endregion PLC5 张超凡
  9742. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9743. /// <summary>
  9744. /// PLC读取到的数据 -添加数据
  9745. /// </summary>
  9746. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9747. {
  9748. if (sxPlcData.ContainsKey(newKey))
  9749. sxPlcData[newKey] = newValue;
  9750. else
  9751. sxPlcData.Add(newKey, newValue);
  9752. }
  9753. /// <summary>
  9754. /// PLC需要写入的数据 -添加数据
  9755. /// </summary>
  9756. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9757. {
  9758. if (sxPLCWriteData.ContainsKey(newKey))
  9759. sxPLCWriteData[newKey] = newValue;
  9760. else
  9761. sxPLCWriteData.Add(newKey, newValue);
  9762. }
  9763. /// <summary>
  9764. /// PLC回写操作,写后清空flag
  9765. /// </summary>
  9766. /// <param name="modbusClient">modbus对象</param>
  9767. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9768. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9769. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9770. {
  9771. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9772. {
  9773. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9774. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9775. {
  9776. string mesFlagName = pLCWriteDatas[i].Name;
  9777. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9778. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9779. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9780. {
  9781. // 先回写数据
  9782. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9783. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9784. {
  9785. int mesDataAdress = writeToPLCDatas[j].Adress;
  9786. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9787. switch (mesDataType)
  9788. {
  9789. case PLCValueType.Short:
  9790. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9791. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9792. break;
  9793. case PLCValueType.String:
  9794. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9795. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9796. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9797. break;
  9798. }
  9799. }
  9800. // 再回写信号
  9801. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9802. // 存储读取数据的字典
  9803. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9804. // 存储写入数据的字典 - 清空写入值
  9805. pLCWriteDatas[i].Value = (short)0;
  9806. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9807. }
  9808. }
  9809. }
  9810. }
  9811. /// <summary>
  9812. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9813. /// </summary>
  9814. /// <param name="no">3</param>
  9815. /// <param name="stationCode">设备编号</param>
  9816. /// <param name="stationNameStr">设备名称</param>
  9817. /// <param name="plcOrder">车间订单号</param>
  9818. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9819. {
  9820. try
  9821. {
  9822. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9823. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9824. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9825. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9826. int result1 = 0;
  9827. switch (stationCode)
  9828. {
  9829. case 2:
  9830. case 3:
  9831. case 4:
  9832. case 6:
  9833. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9834. break;
  9835. case 102:
  9836. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9837. break;
  9838. case 103:
  9839. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9840. break;
  9841. case 104:
  9842. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9843. break;
  9844. case 106:
  9845. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9846. break;
  9847. default:
  9848. // MES_Flag 为“6未找到正确设备编号”
  9849. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9850. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9851. return;
  9852. }
  9853. short result = result1 == 1 ? (short)1 : (short)2;
  9854. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9855. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9856. }
  9857. catch (Exception ex)
  9858. {
  9859. // MES_Flag 为2上位机报错
  9860. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9861. string str = ex.StackTrace;
  9862. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9863. }
  9864. }
  9865. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9866. #region UI刷新
  9867. /// <summary>
  9868. /// 更新商品信息的UI + 下发产品信息(SN)
  9869. /// </summary>
  9870. private void UpdateProductInfo()
  9871. {
  9872. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9873. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9874. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9875. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9876. }
  9877. /// <summary>
  9878. /// 更新PLC连接状态的UI
  9879. /// </summary>
  9880. /// <param name="no">PLC编号</param>
  9881. /// <param name="status">状态</param>
  9882. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9883. {
  9884. if (this != null && !this.IsDisposed)
  9885. {
  9886. switch (imgNo)
  9887. {
  9888. case 1:
  9889. this.BeginInvoke(new Action(() =>
  9890. {
  9891. picPLC.Image = imageListState.Images[status];
  9892. }));
  9893. break;
  9894. case 2:
  9895. this.BeginInvoke(new Action(() =>
  9896. {
  9897. pictureBox2.Image = imageListState.Images[status];
  9898. }));
  9899. break;
  9900. case 3:
  9901. this.BeginInvoke(new Action(() =>
  9902. {
  9903. pictureBox3.Image = imageListState.Images[status];
  9904. }));
  9905. break;
  9906. case 4:
  9907. this.BeginInvoke(new Action(() =>
  9908. {
  9909. pictureBox4.Image = imageListState.Images[status];
  9910. }));
  9911. break;
  9912. case 5:
  9913. this.BeginInvoke(new Action(() =>
  9914. {
  9915. pictureBox5.Image = imageListState.Images[status];
  9916. }));
  9917. break;
  9918. case 6:
  9919. this.BeginInvoke(new Action(() =>
  9920. {
  9921. pictureBox6.Image = imageListState.Images[status];
  9922. }));
  9923. break;
  9924. case 7:
  9925. this.BeginInvoke(new Action(() =>
  9926. {
  9927. pictureBox7.Image = imageListState.Images[status];
  9928. }));
  9929. break;
  9930. case 8:
  9931. this.BeginInvoke(new Action(() =>
  9932. {
  9933. pictureBox8.Image = imageListState.Images[status];
  9934. }));
  9935. break;
  9936. default:
  9937. break;
  9938. }
  9939. }
  9940. Task.Run(() => // 更新PLC交互页的指示灯
  9941. {
  9942. try
  9943. {
  9944. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9945. {
  9946. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9947. }
  9948. }
  9949. catch { }
  9950. });
  9951. }
  9952. #endregion UI刷新
  9953. #region 日志
  9954. /// <summary>
  9955. /// 添加各工位运行日志(同步至PLC交互页面)
  9956. /// </summary>
  9957. /// <param name="stationNameStr">工站名称</param>
  9958. /// <param name="logType">日志类型</param>
  9959. /// <param name="message">日志内容</param>
  9960. /// <param name="snNumber">产品数字SN</param>
  9961. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9962. {
  9963. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9964. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9965. ))
  9966. {
  9967. AddMessage(logType, message); // 首页展示+日志记录
  9968. }
  9969. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9970. {
  9971. StationName = stationNameStr,
  9972. SnNumber = snNumber,
  9973. Message = message,
  9974. CreateTime = DateTime.Now
  9975. };
  9976. // PLC交互页展示
  9977. Task.Run(() =>
  9978. {
  9979. try
  9980. {
  9981. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9982. {
  9983. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9984. }
  9985. }
  9986. catch { }
  9987. });
  9988. }
  9989. /// <summary>
  9990. /// 添加运行日志
  9991. /// </summary>
  9992. /// <param name="logType">日志类型</param>
  9993. /// <param name="message">日志内容</param>
  9994. public void AddMessage(LogType logType, string message)
  9995. {
  9996. OnMessage(logType, message);
  9997. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9998. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9999. string msgShow = time + "--> " + message + "\r\n";
  10000. this.BeginInvoke(new Action(() =>
  10001. {
  10002. systemLog.Rows.Insert(0, date, time, message);
  10003. if (systemLog.Rows.Count >= 100)
  10004. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  10005. }));
  10006. }
  10007. /// <summary>
  10008. /// 添加运行日志-保存
  10009. /// </summary>
  10010. /// <param name="logType">日志类型</param>
  10011. /// <param name="message">日志内容</param>
  10012. private void OnMessage(LogType logType, string msg)
  10013. {
  10014. MessageEvent?.Invoke(logType, msg);
  10015. }
  10016. /// <summary>
  10017. /// 保存PLC写入日志
  10018. /// </summary>
  10019. /// <param name="logType"></param>
  10020. /// <param name="logValue"></param>
  10021. private void WritePLCLog(LogType logType, string logValue)
  10022. {
  10023. switch ((int)logType)
  10024. {
  10025. case 0:
  10026. _PLCLogNet.WriteDebug(logValue);
  10027. break;
  10028. case 1:
  10029. _PLCLogNet.WriteInfo(logValue);
  10030. break;
  10031. case 2:
  10032. _PLCLogNet.WriteWarn(logValue);
  10033. break;
  10034. case 3:
  10035. _PLCLogNet.WriteError(logValue);
  10036. break;
  10037. default:
  10038. _PLCLogNet.WriteFatal(logValue);
  10039. break;
  10040. }
  10041. }
  10042. /// <summary>
  10043. /// IOT Mqtt回调方法- With DataId
  10044. /// </summary>
  10045. /// <param name="id"></param>
  10046. /// <param name="v"></param>
  10047. /// <param name="dataId"></param>
  10048. public void CallbackWithDataId(string id, string msg, string dataId)
  10049. {
  10050. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  10051. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  10052. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  10053. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  10054. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  10055. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  10056. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  10057. }
  10058. /// <summary>
  10059. /// AGV Mqtt回调方法- 记录Log并处理数据
  10060. /// </summary>
  10061. /// <param name="obj"></param>
  10062. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  10063. {
  10064. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  10065. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  10066. // 接收到的信息
  10067. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  10068. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  10069. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  10070. {
  10071. }
  10072. }
  10073. #endregion 日志
  10074. /// <summary>
  10075. /// 实例化报警字典
  10076. /// </summary>
  10077. private void InitalDicAlarm()
  10078. {
  10079. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  10080. List<Alarm> keyValues1 = new List<Alarm>
  10081. {
  10082. #region 第一组报警(电机)
  10083. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  10084. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  10085. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  10086. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  10087. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  10088. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  10089. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  10090. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  10091. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  10092. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  10093. #endregion 第一组报警(电机)
  10094. #region 第二组报警(气缸)
  10095. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  10096. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  10097. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  10098. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  10099. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  10100. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  10101. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  10102. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  10103. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  10104. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  10105. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  10106. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  10107. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  10108. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  10109. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  10110. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  10111. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  10112. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  10113. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  10114. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  10115. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  10116. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  10117. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  10118. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  10119. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  10120. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  10121. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  10122. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  10123. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  10124. #endregion 第二组报警(气缸)
  10125. #region 第三组报警(其他故障)
  10126. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  10127. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  10128. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  10129. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  10130. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  10131. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  10132. #endregion 第三组报警(其他故障)
  10133. };
  10134. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  10135. #endregion 第一个工站(这里使用线体代替工位)
  10136. # region 第二个工站-原来的写法(废弃)
  10137. //keyValues = new Dictionary<int, AlarmData[]>();
  10138. ////1
  10139. //dicAlarmName = new Dictionary<int, Alarm>();
  10140. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  10141. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  10142. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  10143. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  10144. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  10145. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10146. //for (int i = 0; i < dicAlarmName.Count; i++)
  10147. //{
  10148. // alarmDatas[i] = new AlarmData();
  10149. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  10150. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10151. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10152. // alarmDatas[i].AlarmType = 1;
  10153. //}
  10154. //keyValues.Add(1, alarmDatas);
  10155. ////2
  10156. //dicAlarmName = new Dictionary<int, Alarm>();
  10157. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  10158. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  10159. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  10160. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  10161. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  10162. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  10163. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  10164. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  10165. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10166. //for (int i = 0; i < dicAlarmName.Count; i++)
  10167. //{
  10168. // alarmDatas[i] = new AlarmData();
  10169. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  10170. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10171. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10172. // alarmDatas[i].AlarmType = 2;
  10173. //}
  10174. //keyValues.Add(2, alarmDatas);
  10175. ////3
  10176. //dicAlarmName = new Dictionary<int, Alarm>();
  10177. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  10178. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  10179. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  10180. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  10181. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10182. //for (int i = 0; i < dicAlarmName.Count; i++)
  10183. //{
  10184. // alarmDatas[i] = new AlarmData();
  10185. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  10186. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10187. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10188. // alarmDatas[i].AlarmType = 3;
  10189. //}
  10190. //keyValues.Add(3, alarmDatas);
  10191. //DicAlarms.Add(2, keyValues);
  10192. #endregion 第二个工站-原来的写法(废弃)
  10193. }
  10194. private void button1_Click(object sender, EventArgs e)
  10195. {
  10196. OpenDailogFalg=true;
  10197. if (OpenDailogFalg)
  10198. {
  10199. using (var dialog = new BandBarodeDialog())
  10200. {
  10201. string strCarrierBarcode = "N801A-003";
  10202. dialog._CarrierBarcode = strCarrierBarcode;
  10203. string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  10204. dialog._ProductBarcode = sn;
  10205. var rs = dialog.ShowDialog();
  10206. if (rs == DialogResult.OK)
  10207. {
  10208. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  10209. OpenDailogFalg = false;//关闭扫码
  10210. }
  10211. }
  10212. }
  10213. }
  10214. }
  10215. }