Form_Home.cs 593 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206
  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. /*
  42. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  43. */
  44. namespace MainForm
  45. {
  46. /// <summary>
  47. /// 记录日志的委托
  48. /// </summary>
  49. /// <param name="logType">日志类型</param>
  50. /// <param name="message">日志信息</param>
  51. public delegate void HomeMessageHandler(LogType logType, string message);
  52. /// <summary>
  53. /// 主页窗体
  54. /// </summary>
  55. public partial class Form_Home : Form
  56. {
  57. #region 常量
  58. //文本常量
  59. private const string Head = "开始采集";
  60. private const string Tail = "采集完成";
  61. private const string Body = "工位出站数据";
  62. private const string BodyCheck = "工位点检数据";
  63. private const string BodyRun = "整线运行数据";
  64. private const string BodyAlarm = "整线报警数据";
  65. #endregion 常量
  66. #region 变量
  67. /// <summary>
  68. /// 委托-记录日志的方法
  69. /// </summary>
  70. public event HomeMessageHandler MessageEvent;
  71. /// <summary>
  72. /// 日志接口
  73. /// </summary>
  74. ILogNet _PLCLogNet;
  75. /// <summary>
  76. /// 用于记录IOT MQTT日志
  77. /// </summary>
  78. ILogNet _IOTMqttLogNet;
  79. /// <summary>
  80. /// 用于记录AGV MQTT日志
  81. /// </summary>
  82. ILogNet _AGVMqttLogNet;
  83. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  84. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  85. // 间隔时间
  86. private int IntervalReadPLC = 300; //ms 读PLC
  87. private int IntervalMonitorMES = 1000; //ms MES心跳
  88. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  89. // 软件状态
  90. private bool IsRun = true;
  91. #region PLC 与 TCP对象
  92. // 定义一个字典,存plc对象(通讯)
  93. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  94. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  95. // 定义TCPClient对象列表
  96. Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  97. // 定义MQTTHelper对象
  98. MQTTHelper _MQTTHelper = new MQTTHelper();
  99. #endregion PLC 与 TCP对象
  100. /// <summary>
  101. /// 上次的设备运行信息
  102. /// </summary>
  103. private string lineWorkingData1_OldStr = string.Empty;
  104. /// <summary>
  105. /// 设备报警字典-当前结果
  106. /// Dictionary<工位代码,List<报警信息>>
  107. /// </summary>
  108. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  109. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  110. #endregion 变量
  111. #region 窗体基础事件
  112. /// <summary>
  113. /// 初始化
  114. /// </summary>
  115. public Form_Home()
  116. {
  117. InitializeComponent();
  118. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  119. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  120. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  121. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  122. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  123. }
  124. /// <summary>
  125. /// 窗体加载事件
  126. /// </summary>
  127. private void Form_Home_Load(object sender, EventArgs e)
  128. {
  129. try
  130. {
  131. AddMessage(LogType.Info, "开始初始化程序");
  132. InitalDicAlarm(); // 实例化报警字典
  133. //组建plc对象字典
  134. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  135. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  136. if (GlobalContext.IsUsePLC1)
  137. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  138. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  139. if (GlobalContext.IsUsePLC2)
  140. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  141. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  142. if (GlobalContext.IsUsePLC3)
  143. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  144. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  145. if (GlobalContext.IsUsePLC4)
  146. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  147. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  148. if (GlobalContext.IsUsePLC5)
  149. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  150. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  151. if (GlobalContext.IsUsePLC6)
  152. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  153. if (GlobalContext.IsUsePLC7)
  154. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  155. if (GlobalContext.IsUsePLC8)
  156. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  157. if (GlobalContext.IsUsePLC9)
  158. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  159. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  160. {
  161. if (plcEIP != null)
  162. {
  163. try
  164. {
  165. (int, string) result = plcEIP.Connect();
  166. }
  167. catch (Exception ex)
  168. {
  169. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  170. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  171. }
  172. }
  173. }
  174. /*
  175. //plc1Alarm.Connect();
  176. foreach (ModbusClientHelper modbusClient in Funs.Values)
  177. {
  178. if (modbusClient != null)
  179. {
  180. try
  181. {
  182. modbusClient.Connect();
  183. }
  184. catch (Exception ex)
  185. {
  186. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  187. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  188. }
  189. }
  190. }
  191. */
  192. // 采集任务
  193. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  194. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  195. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  196. if (GlobalContext.IsUsePLC1)
  197. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  198. if (GlobalContext.IsUsePLC2)
  199. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  200. if (GlobalContext.IsUsePLC3)
  201. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  202. if (GlobalContext.IsUsePLC4)
  203. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  204. if (GlobalContext.IsUsePLC5)
  205. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  206. if (GlobalContext.IsUsePLC6)
  207. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  208. if (GlobalContext.IsUsePLC7)
  209. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  210. if (GlobalContext.IsUsePLC8)
  211. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  212. if (GlobalContext.IsUsePLC9)
  213. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  214. #region 初始化
  215. try
  216. {
  217. // 开启边线MES(绑定/查询数据)
  218. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  219. //if (mesRoute == 0)
  220. //{
  221. // //picMESStatus.Image = imageListState.Images[1];
  222. // //GlobalContext.MESIsConnect = true;
  223. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  224. //}
  225. //else
  226. //{
  227. // //picMESStatus.Image = imageListState.Images[0];
  228. // //GlobalContext.MESIsConnect = false;
  229. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  230. //}
  231. // 开启MES(Http)
  232. if (GlobalContext.IsUseMES)
  233. {
  234. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  235. if (mesret)
  236. {
  237. picMESStatus.Image = imageListState.Images[1];
  238. GlobalContext.MESIsConnect = true;
  239. AddMessage(LogType.Info, "小米MES初始连接成功!");
  240. }
  241. else
  242. {
  243. picMESStatus.Image = imageListState.Images[0];
  244. GlobalContext.MESIsConnect = false;
  245. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  246. }
  247. }
  248. // 开启IOT(MQTT)
  249. if (GlobalContext.IsUseIot)
  250. {
  251. string addr = GlobalContext.MQTTServerHost;
  252. int port = GlobalContext.MQTTServerPort;
  253. //生产环境需要修改
  254. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  255. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  256. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  257. {
  258. picIot.Image = imageListState.Images[1];
  259. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  260. // 设置回调函数
  261. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  262. // 配置参数
  263. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  264. // fds
  265. param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
  266. param.parameter.fds.appId = "Auto-Soft";
  267. param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
  268. // mes
  269. param.parameter.mes.address = GlobalContext.ServerIp;
  270. param.parameter.mes.appId = GlobalContext.MESAppId;
  271. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  272. // mqtt
  273. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  274. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  275. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  276. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  277. // 设备配置
  278. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  279. if (GlobalContext.IsUsePLC1)
  280. {
  281. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  282. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  283. }
  284. if (GlobalContext.IsUsePLC2)
  285. {
  286. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  287. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  288. }
  289. if (GlobalContext.IsUsePLC3)
  290. {
  291. param.parameter.equipment.deviceCode = GlobalContext.S3_device_code; // 装备编码
  292. param.parameter.equipment.stationCode = GlobalContext.S3_station; // ⼯位Id
  293. }
  294. if (GlobalContext.IsUsePLC4)
  295. {
  296. param.parameter.equipment.deviceCode = GlobalContext.S4_1_device_code; // 装备编码
  297. param.parameter.equipment.stationCode = GlobalContext.S4_1_station; // ⼯位Id
  298. }
  299. if (GlobalContext.IsUsePLC5)
  300. {
  301. param.parameter.equipment.deviceCode = GlobalContext.S5_device_code; // 装备编码
  302. param.parameter.equipment.stationCode = GlobalContext.S5_station; // ⼯位Id
  303. }
  304. if (GlobalContext.IsUsePLC6)
  305. {
  306. param.parameter.equipment.deviceCode = GlobalContext.S6_device_code; // 装备编码
  307. param.parameter.equipment.stationCode = GlobalContext.S6_station; // ⼯位Id
  308. }
  309. if (GlobalContext.IsUsePLC7)
  310. {
  311. param.parameter.equipment.deviceCode = GlobalContext.S7_device_code; // 装备编码
  312. param.parameter.equipment.stationCode = GlobalContext.S7_station; // ⼯位Id
  313. }
  314. if (GlobalContext.IsUsePLC8)
  315. {
  316. param.parameter.equipment.deviceCode = GlobalContext.S8_device_code; // 装备编码
  317. param.parameter.equipment.stationCode = GlobalContext.S8_station; // ⼯位Id
  318. }
  319. if (GlobalContext.IsUsePLC9)
  320. {
  321. param.parameter.equipment.deviceCode = GlobalContext.S9_device_code; // 装备编码
  322. param.parameter.equipment.stationCode = GlobalContext.S9_station; // ⼯位Id
  323. }
  324. param.parameter.equipment.project = GlobalContext.Project_Code;
  325. param.parameter.equipment.productMode = "debug";
  326. //
  327. param.parameter.other.logLevel = 0;
  328. param.parameter.other.LogPath = "D:\\Test";
  329. XiaomiMqttClient_Extend.ParameterConfig(param);
  330. }
  331. else
  332. {
  333. picIot.Image = imageListState.Images[0];
  334. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  335. }
  336. }
  337. // 开启AGV(Http与MQTT)
  338. if (GlobalContext.IsUseAGV)
  339. {
  340. // AGV HTTP
  341. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  342. if (mesret1)
  343. {
  344. picAgvHttp.Image = imageListState.Images[1];
  345. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  346. }
  347. else
  348. {
  349. picAgvHttp.Image = imageListState.Images[0];
  350. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  351. }
  352. string agvMqttIp = GlobalContext.MQTTServerHost;
  353. int agvMqttPort = GlobalContext.MQTTServerPort;
  354. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  355. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  356. // AGV MQTT
  357. if (result_MQTT.ResultCode == 1)
  358. {
  359. picAgvMqtt.Image = imageListState.Images[1];
  360. GlobalContext.AGVMQTTIsConnect = true;
  361. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  362. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  363. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  364. }
  365. else
  366. {
  367. picAgvMqtt.Image = imageListState.Images[0];
  368. GlobalContext.AGVMQTTIsConnect = false;
  369. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  370. }
  371. }
  372. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  373. Task.Run(MonitorMESConnect);
  374. // 查询PLC连接状态
  375. foreach (int plcNo in FunsEip.Keys)
  376. {
  377. bool connected = FunsEip[plcNo].IsConnected;
  378. if (connected)
  379. {
  380. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  381. AddMessage(LogType.Info, msg);
  382. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  383. }
  384. else
  385. {
  386. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  387. AddMessage(LogType.Info, msg);
  388. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  389. }
  390. }
  391. // PLC4时 初始化扫码器TCP
  392. //if (GlobalContext.IsUsePLC4)
  393. // HpTCPClientInit();
  394. // 开启PLC的业务处理线程-监听PLC点位+状态
  395. foreach (Task task in TaskReadProcess)
  396. {
  397. if (task != null)
  398. task.Start();
  399. }
  400. //// 开启“获取线体报警数据”的线程
  401. //TaskReadAlarm.Start();
  402. ////下传MES信息给1工位(先判断下plc对象数量)
  403. //if (Funs.Count > 1)
  404. // DownLoadProductInfo(1);
  405. AddMessage(LogType.Info, "程序初始化完成");
  406. }
  407. catch (Exception ex)
  408. {
  409. string str = ex.StackTrace;
  410. this.BeginInvoke(new Action(() =>
  411. {
  412. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  413. }));
  414. }
  415. #endregion
  416. }
  417. catch (Exception ex)
  418. {
  419. string str = ex.StackTrace;
  420. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  421. if (ex.Message != null && ex.Message.Contains("timed out"))
  422. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  423. else
  424. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  425. }
  426. }
  427. /// <summary>
  428. /// 窗体关闭事件
  429. /// </summary>
  430. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  431. {
  432. Closed2();
  433. }
  434. public void Closed2()
  435. {
  436. try
  437. {
  438. IsRun = false;
  439. Thread.Sleep(IntervalReadPLC);
  440. // 断开TCP
  441. int count = _HPSocket_TcpClients.Count();
  442. for (int i = 0; i < count; i++)
  443. {
  444. try
  445. {
  446. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  447. {
  448. _HPSocket_TcpClients[i].Stop();
  449. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  450. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  451. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  452. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  453. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  454. }
  455. }
  456. catch { }
  457. }
  458. // 关闭Iot
  459. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  460. // 关闭AGV Mqtt
  461. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  462. }
  463. catch { }
  464. }
  465. #endregion 窗体基础事件
  466. #region 监控MES状态
  467. /// <summary>
  468. /// 监控MES连接状态
  469. /// </summary>
  470. private void MonitorMESConnect()
  471. {
  472. while (IsRun) // 运行被控线程
  473. {
  474. try
  475. {
  476. // 开启MES(Http)
  477. if (GlobalContext.IsUseMES)
  478. {
  479. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  480. if (mesret)
  481. {
  482. picMESStatus.Image = imageListState.Images[1];
  483. GlobalContext.MESIsConnect = true;
  484. }
  485. else
  486. {
  487. picMESStatus.Image = imageListState.Images[0];
  488. GlobalContext.MESIsConnect = false;
  489. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  490. }
  491. }
  492. // 开启IOT(MQTT)
  493. if (GlobalContext.IsUseIot)
  494. {
  495. bool iIot = XiaomiMqttClient.IsOpen;
  496. if (iIot)
  497. picIot.Image = imageListState.Images[1];
  498. else
  499. {
  500. picIot.Image = imageListState.Images[0];
  501. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  502. }
  503. }
  504. // 开启AGV(Http与MQTT)
  505. if (GlobalContext.IsUseAGV)
  506. {
  507. // AGV Http
  508. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  509. if (mesret1)
  510. picAgvHttp.Image = imageListState.Images[1];
  511. else
  512. {
  513. picAgvHttp.Image = imageListState.Images[0];
  514. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  515. }
  516. // AGV MQTT
  517. if (GlobalContext.AGVMQTTIsConnect)
  518. picAgvMqtt.Image = imageListState.Images[1];
  519. else
  520. {
  521. picAgvMqtt.Image = imageListState.Images[0];
  522. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  523. }
  524. }
  525. }
  526. catch (Exception ex)
  527. {
  528. string str = ex.StackTrace;
  529. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  530. }
  531. Thread.Sleep(IntervalMonitorMES);
  532. }
  533. }
  534. #endregion 监控MES连接状态
  535. #region 采集设备状态、运行数据、报警数据
  536. /// <summary>
  537. /// 请求设备状态 5000
  538. /// </summary>
  539. /// <param name="no">1</param>
  540. /// <param name="stationNameStr"></param>
  541. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  542. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  543. {
  544. try
  545. {
  546. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  547. {
  548. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  549. return result;
  550. }
  551. else
  552. {
  553. return 0;
  554. }
  555. }
  556. catch (Exception ex)
  557. {
  558. string str = ex.StackTrace;
  559. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  560. return 0;
  561. }
  562. }
  563. /// <summary>
  564. /// 检查是否可采集点检数据 - 不取新值
  565. /// 5000不为1时可点检
  566. /// </summary>
  567. /// <returns></returns>
  568. public bool CheckCanSpotcheck1(int deviceState)
  569. {
  570. //return true;
  571. //D5000 = 1,代表设备控制状态处于运行状态
  572. //D5000 = 2, 代表设备控制状态处于故障状态
  573. //D5000 = 3,代表设备控制状态处于缺料状态
  574. //D5000 = 4, 代表设备控制状态处于待机状态
  575. //D5000 = 5,代表设备控制状态处于维修状态
  576. return deviceState != 1;
  577. }
  578. /// <summary>
  579. /// 检查是否可采集产品数据 - 不取新值
  580. /// </summary>
  581. /// <returns></returns>
  582. public bool CheckCanCollData(int deviceState)
  583. {
  584. return deviceState == 0; // 点检时该值不为0
  585. }
  586. /// <summary>
  587. /// 获取设备报警数据与获取设备运行信息
  588. /// </summary>
  589. private async void ReadAlarmAllPLC()
  590. {
  591. // [S1] Tray盘上料装备(板测)
  592. // [S2] FCT(板测)
  593. // [S3] 值板机
  594. // [S4] 取放桁架
  595. // [S5] Tray盘下料装备
  596. /// 上位机心跳
  597. /// 获取设备报警数据与状态信息
  598. string stationNameStr = "获取设备报警数据与状态信息";
  599. while (IsRun)
  600. {
  601. try
  602. {
  603. if (!GlobalContext._IsCon_plc1Alarm)
  604. {
  605. UpdatePLCMonitor(1, -2, 0);
  606. continue;
  607. }
  608. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  609. {
  610. DateTime dtNow = DateTime.Now;
  611. #region 获取设备运行信息
  612. try
  613. {
  614. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  615. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  616. lineWorkingData1.LineName = GlobalContext.LineCode;
  617. //
  618. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  619. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  620. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  621. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  622. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  623. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  624. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  625. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  626. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  627. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  628. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  629. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  630. lineWorkingData1.CreateTime = DateTime.Now;
  631. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  632. // UI展示-展示到设备状态页
  633. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  634. {
  635. // 查询数据库最新一条数据,确定是不是更新
  636. string qSql = @"SELECT top(1) [GUID]
  637. ,[LineName]
  638. ,[BootTimeLong]
  639. ,[NormalTimeLong]
  640. ,[StandbyTimeLong]
  641. ,[FaultTimeLong]
  642. ,[MaterialShortageTimeLong]
  643. ,[MaintenanceTimeLong]
  644. ,[FaultNumber]
  645. ,[OutputNumber]
  646. ,[QualifiedNumber]
  647. ,[QualifiedRate]
  648. ,[DesignRhythm]
  649. ,[RealityRhythm]
  650. ,[CreateTime]
  651. FROM [LineWorkingData]
  652. where [CreateTime] > '{0}'
  653. and [LineName]='{1}'
  654. order by [CreateTime] desc
  655. ";
  656. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  657. var ds = SQLHelper_New.Query(qSql, null);
  658. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  659. {
  660. var dataDBlast = new LineWorkingData_ThisTime();
  661. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  662. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  663. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  664. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  665. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  666. {
  667. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  668. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  669. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  670. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  671. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  672. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  673. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  674. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  675. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  676. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  677. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  678. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  679. string usql = dataDBlast.ToStringUpdate();
  680. SQLHelper_New.ExecuteSQL(usql, null);
  681. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  682. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  683. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  684. }
  685. }
  686. else
  687. {
  688. // 插入
  689. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  690. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  691. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  692. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  693. }
  694. }
  695. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  696. {
  697. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  698. //// 本次开机设备运行情况
  699. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  700. //Task.Run(() =>
  701. //{
  702. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  703. // {
  704. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  705. // }
  706. //});
  707. // 本日设备运行情况
  708. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  709. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  710. {
  711. // 更新
  712. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  713. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  714. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  715. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  716. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  717. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  718. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  719. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  720. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  721. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  722. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  723. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  724. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  725. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  726. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  727. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  728. }
  729. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  730. {
  731. // 插入
  732. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  733. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  734. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  735. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  736. }
  737. await Task.Run(() =>
  738. {
  739. try
  740. {
  741. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  742. {
  743. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  744. }
  745. }
  746. catch { }
  747. });
  748. }
  749. }
  750. catch (Exception ex)
  751. {
  752. string str = ex.StackTrace;
  753. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  754. }
  755. #endregion 获取设备运行信息
  756. #region 报警数据
  757. try
  758. {
  759. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  760. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  761. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  762. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  763. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  764. {
  765. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  766. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  767. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  768. {
  769. isNeedUpdUI = true; // 需要更新历史报警UI信息
  770. // 记录
  771. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  772. switch (dicAlarms_Cur_PLC1[i].是否报警)
  773. {
  774. case true: // 报警
  775. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  776. {
  777. GUID = Guid.NewGuid().ToString(),
  778. LineName = GlobalContext.LineCode, // 线体
  779. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  780. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  781. StartTime = dtNow // 开始时间
  782. };
  783. // 传输到页面
  784. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  785. {
  786. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  787. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  788. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  789. 开始时间 = dtNow
  790. });
  791. // 新增到数据库
  792. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  793. SaveAlarmDataByDB(stationNameStr, data1, false);
  794. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  795. break;
  796. case false: // 消除报警
  797. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  798. {
  799. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  800. {
  801. GUID = Guid.NewGuid().ToString(),
  802. LineName = GlobalContext.LineCode, // 线体
  803. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  804. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  805. StartTime = dtNow, // 开始时间
  806. EndTime = dtNow, // 开始时间
  807. PersistTime = 1, // 耗时1s
  808. };
  809. // 新增
  810. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  811. SaveAlarmDataByDB(stationNameStr, data2, false);
  812. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  813. }
  814. else
  815. {
  816. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  817. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  818. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  819. // 修改
  820. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  821. SaveAlarmDataByDB(stationNameStr, data3, true);
  822. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  823. }
  824. break;
  825. default:
  826. break;
  827. }
  828. }
  829. }
  830. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  831. // 有新报警则更新
  832. if (isNeedUpdUI)
  833. {
  834. // UI展示 - 展示到设备状态页
  835. await Task.Run(() =>
  836. {
  837. try
  838. {
  839. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  840. {
  841. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  842. if (Form_Main.formDevAlarm.Visible)
  843. {
  844. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  845. }
  846. }
  847. }
  848. catch { }
  849. });
  850. }
  851. }
  852. catch (Exception ex)
  853. {
  854. string str = ex.StackTrace;
  855. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  856. }
  857. #endregion 报警数据
  858. UpdatePLCMonitor(1, -2, 1);
  859. }
  860. else
  861. {
  862. UpdatePLCMonitor(1, -2, 0);
  863. }
  864. }
  865. catch (Exception ex)
  866. {
  867. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  868. }
  869. Thread.Sleep(IntervalAlarm);
  870. }
  871. }
  872. #endregion 轮询PLC
  873. #region 下发订单信息
  874. ///// <summary>
  875. ///// 壳体上料(下发工单)的交互逻辑
  876. ///// </summary>
  877. ///// <param name="no"></param>
  878. ///// <exception cref="NotImplementedException"></exception>
  879. //private void ReadStation_DownOrderInfo(int plcNo)
  880. //{
  881. // // [S1] Tray盘上料装备(板测)
  882. // // [S2] FCT(板测)
  883. // // [S3] 值板机
  884. // // [S4] 取放桁架
  885. // // [S5] Tray盘下料装备
  886. // /// 上位机心跳
  887. // /// 获取设备报警数据与状态信息
  888. // string stationNameStr = "[S0]壳体上料";
  889. // while (IsRun)
  890. // {
  891. // try
  892. // {
  893. // if (!GlobalContext._IsCon_Funs1)
  894. // {
  895. // UpdatePLCMonitor(plcNo, 0);
  896. // continue;
  897. // }
  898. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  899. // {
  900. // #region 壳体上料(下发工单)
  901. // try
  902. // {
  903. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  904. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  905. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  906. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  907. // // 重置数据和信号
  908. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  909. // {
  910. // // 清空写给PLC的数据
  911. // int[] i497 = new int[1] { 0 };
  912. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  913. // // MES_Flag重置为0
  914. // int[] i500 = new int[1] { 0 };
  915. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  916. // }
  917. // }
  918. // catch (Exception ex)
  919. // {
  920. // string str = ex.StackTrace;
  921. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  922. // }
  923. // #endregion 壳体上料(下发工单)
  924. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  925. // }
  926. // else
  927. // {
  928. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  929. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  930. //
  931. // Funs[plcNo].Connect();
  932. // }
  933. // }
  934. // catch (Exception ex)
  935. // {
  936. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  937. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  938. //
  939. // Funs[plcNo].ReConnect();
  940. // }
  941. // Thread.Sleep(IntervalReadPLC);
  942. // }
  943. //}
  944. ///// <summary>
  945. ///// 下发订单信息到PLC
  946. ///// </summary>
  947. ///// <param name="no">PLC编号</param>
  948. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  949. //{
  950. // try
  951. // {
  952. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  953. // {
  954. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  955. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  956. // }
  957. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  958. // }
  959. // catch (Exception ex)
  960. // {
  961. // string str = ex.StackTrace;
  962. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  963. // }
  964. //}
  965. /// <summary>
  966. /// 下发清料信号
  967. /// </summary>
  968. /// <param name="no">PLC编号</param>
  969. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  970. {
  971. try
  972. {
  973. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  974. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  975. return true;
  976. }
  977. catch (Exception ex)
  978. {
  979. string str = ex.StackTrace;
  980. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  981. return false;
  982. }
  983. }
  984. #endregion 下发订单信息
  985. #region Xiaomi 贲流
  986. #region 公共方法
  987. private static bool ProgressState = false;
  988. private static readonly object lockObj = new object(); // 锁对象
  989. private static bool isCollectingFlagLeft;
  990. private static bool isCollectingFlagRight;
  991. private bool OpenDailogFalg = true;//是否开启扫码弹窗标识
  992. /// <summary>
  993. /// float[]转为string
  994. /// </summary>
  995. public string FloatArrayToString(float[] nScrewResults)
  996. {
  997. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  998. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  999. }
  1000. /// <summary>
  1001. /// short[]转为string
  1002. /// </summary>
  1003. public string ShortArrayToString(short[] nScrewResults)
  1004. {
  1005. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1006. return string.Join(",", nScrewResults);
  1007. }
  1008. /// <summary>
  1009. /// 写入PLC重复三次
  1010. /// </summary>
  1011. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  1012. {
  1013. int i = 0;
  1014. int nRet = 0;
  1015. string strRet = "";
  1016. try
  1017. {
  1018. while (i < 3) // 最多上传三次
  1019. {
  1020. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1021. if (nRet == 0) //成功
  1022. {
  1023. break;
  1024. }
  1025. else
  1026. {
  1027. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1028. i++;
  1029. }
  1030. }
  1031. return (nRet, strRet);
  1032. }
  1033. catch (Exception ex)
  1034. {
  1035. return (1, ex.Message);
  1036. }
  1037. }
  1038. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  1039. {
  1040. try
  1041. {
  1042. // 获取当前日期
  1043. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1044. // 构建保存路径
  1045. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1046. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  1047. // 确保目录存在
  1048. Directory.CreateDirectory(savePath);
  1049. // 文件名
  1050. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1051. string filePath = Path.Combine(savePath, fileName);
  1052. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1053. int count = Math.Min(14, fScrewTimes.Length);
  1054. using (StreamWriter sw = new StreamWriter(filePath))
  1055. {
  1056. for (int i = 0; i < count; i++)
  1057. {
  1058. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1059. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1060. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1061. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1062. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1063. }
  1064. }
  1065. return (0, "");
  1066. }
  1067. catch (Exception ex)
  1068. {
  1069. return (1, ex.Message);
  1070. }
  1071. }
  1072. public Dictionary<string, string> GetLastLineCompensation(string path,string direction,string sn)
  1073. {
  1074. // 创建字典存储补偿点及其对应的值
  1075. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1076. try
  1077. {
  1078. //string path = GlobalContext.MESLaserRPath;
  1079. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1080. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1081. string filename = $"Laser-{currentDate}-W0.txt";
  1082. // 拼接完整路径
  1083. string fullPath = Path.Combine(path, filename);
  1084. string lastNonEmptyLine = "";
  1085. // 判断文件是否存在
  1086. if (File.Exists(fullPath))
  1087. {
  1088. //读取文件内容
  1089. string[] lines = File.ReadAllLines(fullPath);
  1090. // 获取最后一行数据(忽略标题行)
  1091. if (lines.Length > 1)
  1092. {
  1093. string lastLine = "";
  1094. for (int i = lines.Length - 1; i > 0; i--)
  1095. {
  1096. if (!string.IsNullOrEmpty(lines[i]))
  1097. {
  1098. lastLine = lines[i];
  1099. break;
  1100. }
  1101. }
  1102. // 将最后一行按逗号分隔
  1103. string[] values = lastLine.Split(',');
  1104. values[1] = sn;
  1105. string key = "三点激光_"+ direction; // 构造键名
  1106. string value = string.Join(",", values); // 获取值并去除多余空格
  1107. compensationDict[key] = value;
  1108. //// 提取“1点补偿”到“6点补偿”的值
  1109. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1110. //{
  1111. // string key = $"{i - 1}点补偿"; // 构造键名
  1112. // string value = values[i].Trim(); // 获取值并去除多余空格
  1113. // compensationDict[key] = value;
  1114. //}
  1115. }
  1116. }
  1117. else
  1118. {
  1119. Console.WriteLine($"文件不存在: {fullPath}");
  1120. }
  1121. }
  1122. catch (Exception ex)
  1123. {
  1124. // 捕获异常并输出错误信息
  1125. Console.WriteLine($"发生错误: {ex.Message}");
  1126. }
  1127. return compensationDict;
  1128. }
  1129. public int PCBStationOutData(BarcodeSet_t Barcode,IoT_DataSet_t iotData)
  1130. {
  1131. int res = 0;
  1132. string jsonstr1 = "";
  1133. try
  1134. {
  1135. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1136. outRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备id(可配置)
  1137. outRequest_Body.stationId = GlobalContext.S5_station; // ⼯位ID(可配置)
  1138. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1139. outRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1140. outRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1141. int a1Result = (int)iotData.testStatus;
  1142. bool pass = a1Result == 1;
  1143. outRequest_Body.state = pass ? "PASS" : "FAIL"; ; // 出站条件 PASS或FAIL
  1144. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1145. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1146. jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1147. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1148. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1149. if (response != null && response.header.code == "200")
  1150. {
  1151. res = 1;
  1152. AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---成功!请求信息:" + jsonstr1 + ",返回信息:" + JsonConvert.SerializeObject(response.body));
  1153. }
  1154. else
  1155. {
  1156. res = 0;
  1157. AddMessage(LogType.Error, "上传PCB出站数据到MES服务器---失败!错误信息:"+ response.header.desc + ",请求信息:" + jsonstr1 + ",返回信息:" + JsonConvert.SerializeObject(response.body));
  1158. }
  1159. }
  1160. catch (Exception e)
  1161. {
  1162. res = 0;
  1163. AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---失败!请求信息:" + jsonstr1 + ",返回信息:" + e.Message);
  1164. }
  1165. return res;
  1166. }
  1167. /// <summary>
  1168. /// 调用进站接口并保存进站数据
  1169. /// </summary>
  1170. /// <param name="stationNameStr">工站信息</param>
  1171. /// <param name="workorder_code">工单号</param>
  1172. /// <param name="mtltmrk">型号(物料号)</param>
  1173. /// <param name="sn">产品SN</param>
  1174. /// <param name="items">进站数据</param>
  1175. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1176. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1177. {
  1178. int result = 0;
  1179. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1180. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1181. inRequest_Body.stationId = StationId; // ⼯位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 = sn; // 产品SN
  1185. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1186. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1187. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1188. StationIn stationIn = new StationIn()
  1189. {
  1190. Workorder_code = workorder_code, // 车间订单号
  1191. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1192. Sn = sn, // SN
  1193. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1194. Parameter_values = items, // 进站数据
  1195. Write_user = inRequest_Body.userId, // 员工Id
  1196. Test_time = inRequest_Body.clientTime // 进站时间
  1197. };
  1198. // 本地数据
  1199. string sql = stationIn.ToStringInsert(0);
  1200. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1201. result = ret == "成功" ? 1 : 6;
  1202. //await Task.Delay(200);
  1203. // 上传MES
  1204. if (GlobalContext.IsSendStationIn)
  1205. {
  1206. try
  1207. {
  1208. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1209. string resultJson = "";
  1210. string mesRet = string.Empty;
  1211. int i = 0;
  1212. while (i < 2) // 1009会多次尝试上传
  1213. {
  1214. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1215. resultJson = JsonConvert.SerializeObject(response);
  1216. if (response != null && response.header.code == "200")
  1217. break;
  1218. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1219. i++;
  1220. i++;
  1221. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1222. // 记录失败原因
  1223. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!请求参数:{json_Body},接口报错信息:" + mesRet);
  1224. }
  1225. if (response?.header?.code == "200")
  1226. {
  1227. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1228. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1229. result = ret_Upd == "成功" ? 1 : 6;
  1230. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,请求参数:{json_Body},返回参数:{resultJson}");
  1231. }
  1232. else
  1233. {
  1234. result = 5;
  1235. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!请求参数:{json_Body},接口报错信息:" + mesRet);
  1236. }
  1237. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1238. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1239. }
  1240. catch (Exception ex)
  1241. {
  1242. result = 6;
  1243. string str = ex.StackTrace;
  1244. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1245. }
  1246. }
  1247. return result;
  1248. }
  1249. /// <summary>
  1250. /// 选择如何记录出站数据
  1251. /// </summary>
  1252. /// <param name="items">出站数据</param>
  1253. /// <param name="equipmentCode">设备编号</param>
  1254. /// <param name="processItem">测试项目</param>
  1255. /// <param name="workorder_code">车间订单号</param>
  1256. /// <param name="batch_num">批次号</param>
  1257. /// <param name="mtltmrk">型号</param>
  1258. /// <param name="proDate">日期</param>
  1259. /// <param name="supplierCode">供应商代码</param>
  1260. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1261. /// <returns>上传成功时返回1;失败返回0</returns>
  1262. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1263. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1264. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode,string jsonParm, string direction="")
  1265. {
  1266. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1267. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm, direction);
  1268. }
  1269. /// <summary>
  1270. /// 添加出站数据(提交到MES+本地保存到数据库)
  1271. /// </summary>
  1272. /// <param name="items">出站数据</param>
  1273. /// <param name="equipmentCode">设备编号</param>
  1274. /// <param name="processItem">测试项目</param>
  1275. /// <param name="workorder_code">车间订单号</param>
  1276. /// <param name="batch_num">批次号</param>
  1277. /// <param name="mtltmrk">型号</param>
  1278. /// <param name="proDate">日期</param>
  1279. /// <param name="supplierCode">供应商代码</param>
  1280. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1281. /// <returns>上传成功时返回1;失败返回0</returns>
  1282. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1283. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1284. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode,string jsonParm,string direction="")
  1285. {
  1286. int upload = 0;
  1287. int result = 0;
  1288. ProcessData processData = new ProcessData()
  1289. {
  1290. Equipment_code = equipmentCode,
  1291. Workorder_code = workorder_code,
  1292. Batch_number = batch_num,
  1293. Sn = sn, // SN
  1294. Testitem = processItem,
  1295. Parameter_values = items,
  1296. Write_user = GlobalContext.CurrentUser,
  1297. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1298. };
  1299. // 本地数据
  1300. string sql = processData.ToStringInsert(upload);
  1301. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1302. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1303. // 上传MES
  1304. if (GlobalContext.IsSendProcessData)
  1305. {
  1306. try
  1307. {
  1308. string id = processData.ID.Copy();
  1309. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1310. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1311. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1312. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1313. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1314. outRequest_Body.unitSn = sn; // 产品SN
  1315. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1316. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1317. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1318. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1319. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1320. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1321. if (!string.IsNullOrEmpty(partBarcode))
  1322. {
  1323. outRequest_Body.unitData.keyMaterial.Add(
  1324. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1325. {
  1326. bindSort = 1,
  1327. materialSn = partBarcode
  1328. }); // 设备数据 - 部件码
  1329. }
  1330. //OP30站读txt数据
  1331. if (stationNameStr.Contains("CPAPHD"))
  1332. {
  1333. string path = "";
  1334. if (direction == "Left")
  1335. path = GlobalContext.MESLaserLPath;
  1336. else
  1337. path= GlobalContext.MESLaserRPath;
  1338. //字典存储数据
  1339. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction,sn);
  1340. foreach (var kvp in compensationDict)
  1341. {
  1342. outRequest_Body.unitData.processData.Add(
  1343. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1344. {
  1345. dataName = kvp.Key.ToString(),
  1346. dataValue = kvp.Value.ToString()
  1347. });
  1348. }
  1349. }
  1350. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1351. if (GlobalContext.IsSendProcessData)
  1352. {
  1353. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1354. string mesRet = string.Empty;
  1355. int i = 0;
  1356. while (i < 2) // 1009会多次尝试上传
  1357. {
  1358. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1359. if (response != null && response.header.code == "200")
  1360. {
  1361. OnMessage(LogType.Error, "上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" + JsonConvert.SerializeObject(response.body));
  1362. break;
  1363. }
  1364. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1365. i++;
  1366. i++;
  1367. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1368. // 记录失败原因
  1369. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1370. }
  1371. if (response?.header?.code == "200")
  1372. {
  1373. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1374. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1375. result = 1;
  1376. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1377. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1378. }
  1379. else
  1380. {
  1381. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1382. }
  1383. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1384. JsonConvert.SerializeObject(response), id);
  1385. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1386. }
  1387. }
  1388. catch (Exception ex)
  1389. {
  1390. string str = ex.StackTrace;
  1391. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1392. }
  1393. }
  1394. return result;
  1395. }
  1396. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1397. //{
  1398. // Stopwatch stopwatch = new Stopwatch();
  1399. // stopwatch.Start();
  1400. // try
  1401. // {
  1402. // // 初始化 AtlasScrew 实例
  1403. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1404. // atlasScrew1.Initial();
  1405. // // 存储结果的列表
  1406. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1407. // // 存储角度和扭力的字符串列表
  1408. // List<string> angleStrs = new List<string>();
  1409. // List<string> torqueStrs = new List<string>();
  1410. // // 上一次获取的数据
  1411. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1412. // while (isExitAtlasLeft) // 检查是否收集数据
  1413. // {
  1414. // // 获取当前数据
  1415. // var currentResult = atlasScrew1.GetResults();
  1416. // // 判断是否为新数据
  1417. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1418. // {
  1419. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1420. // // 更新角度和扭力的字符串列表
  1421. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1422. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1423. // // 计算角度、扭力、起始扭力和最大扭力
  1424. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1425. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1426. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1427. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1428. // // 将新数据添加到结果列表
  1429. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1430. // // 更新上一次获取的数据
  1431. // lastResult = currentResult;
  1432. // }
  1433. // // 等待一段时间后再次检查
  1434. // Thread.Sleep(20); // 轮询间隔时间
  1435. // // 如果触发了出站,则退出循环
  1436. // if (!isExitAtlasLeft)
  1437. // {
  1438. // break;
  1439. // }
  1440. // }
  1441. // // 生成文件名
  1442. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1443. // // 写入数据到文件
  1444. // using (StreamWriter writer = new StreamWriter(fileName))
  1445. // {
  1446. // // 写入标题行
  1447. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1448. // // 写入每一行数据
  1449. // foreach (var result in results)
  1450. // {
  1451. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1452. // }
  1453. // }
  1454. // stopwatch.Stop();
  1455. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1456. // }
  1457. // catch (Exception ex)
  1458. // {
  1459. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1460. // }
  1461. // finally
  1462. // {
  1463. // // 重置标志变量
  1464. // isExitAtlasLeft = false;
  1465. // }
  1466. //}
  1467. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1468. //{
  1469. // Stopwatch stopwatch = new Stopwatch();
  1470. // stopwatch.Start();
  1471. // try
  1472. // {
  1473. // // 初始化 AtlasScrew 实例
  1474. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1475. // atlasScrew2.Initial();
  1476. // // 存储结果的列表
  1477. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1478. // // 上一次获取的数据
  1479. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1480. // while (isExitAtlasRight) // 检查是否收集数据
  1481. // {
  1482. // // 获取当前数据
  1483. // var currentResult = atlasScrew2.GetResults();
  1484. // // 判断是否为新数据
  1485. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1486. // {
  1487. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1488. // // 将新数据写入PLC
  1489. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1490. // // 将新数据添加到结果列表
  1491. // results.Add(currentResult);
  1492. // // 更新上一次获取的数据
  1493. // lastResult = currentResult;
  1494. // }
  1495. // // 等待一段时间后再次检查
  1496. // Thread.Sleep(20); // 轮询间隔时间
  1497. // // 如果触发了出站,则退出循环
  1498. // if (!isExitAtlasRight)
  1499. // {
  1500. // break;
  1501. // }
  1502. // }
  1503. // // 将所有数据写入文件
  1504. // //WriteDataToFile(sn, direction, results);
  1505. // stopwatch.Stop();
  1506. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1507. // }
  1508. // catch (Exception ex)
  1509. // {
  1510. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1511. // }
  1512. // finally
  1513. // {
  1514. // // 重置标志变量
  1515. // isExitAtlasRight = false;
  1516. // }
  1517. //}
  1518. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1519. {
  1520. Stopwatch stopwatch = new Stopwatch();
  1521. stopwatch.Start();
  1522. int nRet = 0;
  1523. string strRet = "";
  1524. try
  1525. {
  1526. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1527. while (isCollectingFlagLeft)
  1528. {
  1529. // 从缓存中获取所有未处理的数据
  1530. var cachedData = atlasScrew.GetCachedDataLeft();
  1531. foreach (var currentResult in cachedData)
  1532. {
  1533. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1534. {
  1535. continue; // 跳过无效数据
  1536. }
  1537. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1538. // 写入PLC
  1539. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1540. {
  1541. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1542. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1543. };
  1544. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1545. if (nRet != 0)
  1546. {
  1547. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1548. }
  1549. else
  1550. {
  1551. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1552. }
  1553. // 构建保存路径
  1554. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1555. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1556. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1557. Directory.CreateDirectory(savePath); // 确保目录存在
  1558. // 构建文件名(以 SN + 序号命名)
  1559. string fileName = $"{sn}_{fileCounter}.txt";
  1560. string filePath = Path.Combine(savePath, fileName);
  1561. // 写入文件
  1562. using (StreamWriter writer = new StreamWriter(filePath))
  1563. {
  1564. writer.WriteLine("精度, 扭力");
  1565. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1566. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1567. {
  1568. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1569. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1570. writer.WriteLine($"{precision}, {torque}");
  1571. }
  1572. }
  1573. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1574. // 增加文件计数器
  1575. fileCounter++;
  1576. }
  1577. // 如果没有更多数据,则短暂休眠以节省资源
  1578. if (!cachedData.Any())
  1579. {
  1580. Thread.Sleep(10); // 根据需要调整休眠时间
  1581. }
  1582. // 如果触发了出站,则退出循环
  1583. if (!isCollectingFlagLeft)
  1584. {
  1585. break;
  1586. }
  1587. }
  1588. stopwatch.Stop();
  1589. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1590. }
  1591. catch (Exception ex)
  1592. {
  1593. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1594. }
  1595. finally
  1596. {
  1597. isCollectingFlagLeft = false;
  1598. }
  1599. }
  1600. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1601. {
  1602. Stopwatch stopwatch = new Stopwatch();
  1603. stopwatch.Start();
  1604. int nRet = 0;
  1605. string strRet = "";
  1606. try
  1607. {
  1608. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1609. while (isCollectingFlagRight)
  1610. {
  1611. // 从缓存中获取所有未处理的数据
  1612. var cachedData = atlasScrew.GetCachedDataLeft();
  1613. foreach (var currentResult in cachedData)
  1614. {
  1615. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1616. {
  1617. continue; // 跳过无效数据
  1618. }
  1619. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1620. // 写入PLC
  1621. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1622. {
  1623. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1624. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1625. };
  1626. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1627. if (nRet != 0)
  1628. {
  1629. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1630. }
  1631. else
  1632. {
  1633. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1634. }
  1635. // 构建保存路径
  1636. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1637. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1638. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1639. Directory.CreateDirectory(savePath); // 确保目录存在
  1640. // 构建文件名(以 SN + 序号命名)
  1641. string fileName = $"{sn}_{fileCounter}.txt";
  1642. string filePath = Path.Combine(savePath, fileName);
  1643. // 写入文件
  1644. using (StreamWriter writer = new StreamWriter(filePath))
  1645. {
  1646. writer.WriteLine("精度, 扭力");
  1647. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1648. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1649. {
  1650. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1651. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1652. writer.WriteLine($"{precision}, {torque}");
  1653. }
  1654. }
  1655. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1656. // 增加文件计数器
  1657. fileCounter++;
  1658. }
  1659. // 如果没有更多数据,则短暂休眠以节省资源
  1660. if (!cachedData.Any())
  1661. {
  1662. Thread.Sleep(10); // 根据需要调整休眠时间
  1663. }
  1664. // 如果触发了出站,则退出循环
  1665. if (!isCollectingFlagRight)
  1666. {
  1667. break;
  1668. }
  1669. }
  1670. stopwatch.Stop();
  1671. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1672. }
  1673. catch (Exception ex)
  1674. {
  1675. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1676. }
  1677. finally
  1678. {
  1679. isCollectingFlagRight = false;
  1680. }
  1681. }
  1682. #endregion
  1683. #region S1
  1684. /// <summary>
  1685. /// [S1] 壳体清洁上料装备
  1686. /// </summary>
  1687. /// <param name="plcNo">PLC编号</param>
  1688. private void ReadStation_S1(int plcNo)
  1689. {
  1690. string stationCode = "[OP10]";
  1691. string stationName = "壳体清洁上料";
  1692. string stationNameStr = stationCode + stationName;
  1693. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1694. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1695. string tagAgvCommName = "agvCommFrmPC";
  1696. string tagBarsetName = "BarcodeSet";
  1697. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1698. (int, string) result;
  1699. while (true)
  1700. {
  1701. try
  1702. {
  1703. if (!GlobalContext._IsCon_Funs1)
  1704. {
  1705. UpdatePLCMonitor(1, plcNo, 0);
  1706. continue;
  1707. }
  1708. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1709. {
  1710. Stopwatch stopwatch1 = new Stopwatch();
  1711. Stopwatch stopwatch2 = new Stopwatch();
  1712. stopwatch1.Start();
  1713. stopwatch2.Start();
  1714. #region 一次性读取所有数据
  1715. // 一次性读取所有数据
  1716. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1717. if (result.Item1 != 0)
  1718. {
  1719. //richTextBox1.AppendText("\n" + strRet);
  1720. }
  1721. else
  1722. {
  1723. //richTextBox1.AppendText("\n" + "读取成功");
  1724. }
  1725. #endregion 一次性读取所有数据
  1726. stopwatch2.Stop();
  1727. #region 进站
  1728. try
  1729. {
  1730. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1731. {
  1732. lock (lockObj)
  1733. {
  1734. if (!ProgressState)
  1735. {
  1736. ProgressState = true;
  1737. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1738. }
  1739. }
  1740. }
  1741. }
  1742. catch (Exception ex)
  1743. {
  1744. ProgressState = false;
  1745. string str = ex.StackTrace;
  1746. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1747. }
  1748. #endregion 进站
  1749. #region 出站
  1750. try
  1751. {
  1752. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1753. {
  1754. lock (lockObj)
  1755. {
  1756. if (!ProgressState)
  1757. {
  1758. ProgressState = true;
  1759. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1760. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1761. }
  1762. }
  1763. }
  1764. }
  1765. catch (Exception ex)
  1766. {
  1767. ProgressState = false;
  1768. string str = ex.StackTrace;
  1769. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1770. }
  1771. #endregion 出站
  1772. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1773. stopwatch1.Stop();
  1774. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1775. }
  1776. else
  1777. {
  1778. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1779. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1780. FunsEip[plcNo].Connect(); // 重连
  1781. }
  1782. }
  1783. catch (Exception ex)
  1784. {
  1785. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1786. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1787. }
  1788. Thread.Sleep(IntervalReadPLC);
  1789. }
  1790. }
  1791. /// <summary>
  1792. /// [S1] 壳体清洁上料 - 进站
  1793. /// </summary>
  1794. /// <param name="plcNo">PLC编号</param>
  1795. /// <param name="stationNameStr">工站全称</param>
  1796. /// <param name="stPLC_MesData"></param>
  1797. /// <param name="tagMesCommName"></param>
  1798. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1799. {
  1800. Stopwatch stopwatch1 = new Stopwatch();
  1801. Stopwatch stopwatch2 = new Stopwatch();
  1802. try
  1803. {
  1804. stopwatch1.Start();
  1805. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1806. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1807. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1808. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1809. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1810. if (string.IsNullOrEmpty(sn))
  1811. {
  1812. ProgressState = false;
  1813. return;
  1814. }
  1815. //正式生产就用PLC中取的
  1816. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1817. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1818. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1819. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1820. //绑定载具和产品
  1821. ResponseMessage message = new ResponseMessage();
  1822. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1823. if (message.result == false)
  1824. {
  1825. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1826. }
  1827. // 产品SN进站
  1828. List<TestItem> item = new List<TestItem>();
  1829. stopwatch2.Start();
  1830. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1831. stopwatch2.Stop();
  1832. //指令执行结果 1:OK 110:失败
  1833. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1834. //进站结果写入PLC
  1835. CommandFromPLC resultToPlC = new CommandFromPLC();
  1836. resultToPlC.cmd = 0;
  1837. resultToPlC.cmdParam = 0;
  1838. resultToPlC.cmdResult = mesResultFrmWeb;
  1839. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1840. }
  1841. catch (Exception ex)
  1842. {
  1843. string str = ex.StackTrace;
  1844. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1845. CommandFromPLC resultToPlC = new CommandFromPLC();
  1846. resultToPlC.cmd = 0;
  1847. resultToPlC.cmdParam = 0; //指令参数
  1848. resultToPlC.cmdResult = 110;
  1849. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1850. }
  1851. stopwatch1.Stop();
  1852. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1853. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1854. ProgressState = false;
  1855. }
  1856. /// <summary>
  1857. /// [S1] 壳体清洁上料 - 出站接口
  1858. /// </summary>
  1859. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1860. {
  1861. Stopwatch stopwatch1 = new Stopwatch();
  1862. Stopwatch stopwatch2 = new Stopwatch();
  1863. try
  1864. {
  1865. stopwatch1.Start();
  1866. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1867. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1868. string processItem = stationName; // 项目
  1869. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1870. string supplierCode = ""; // 供应商代码
  1871. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1872. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1873. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1874. string sn = string.Empty;
  1875. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1876. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1877. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1878. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1879. //a1Result = 1;
  1880. bool pass = a1Result == 1;
  1881. //根据载具码获取产品码
  1882. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1883. if (string.IsNullOrEmpty(strProductBarcode))
  1884. {
  1885. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1886. }
  1887. sn = strProductBarcode;
  1888. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1889. List<TestItem> items = new List<TestItem>();
  1890. items.Add(new TestItem()
  1891. {
  1892. Parameter_name = "载具码",
  1893. Parameter_value = CarrierBarcode,
  1894. Parameter_unit = ""
  1895. });
  1896. items.Add(new TestItem()
  1897. {
  1898. Parameter_name = "产品码",
  1899. Parameter_value = sn,
  1900. Parameter_unit = ""
  1901. });
  1902. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  1903. //出站接口
  1904. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1905. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  1906. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1907. stopwatch2.Start();
  1908. //进站结果写入PLC
  1909. CommandFromPLC resultToPlC = new CommandFromPLC();
  1910. resultToPlC.cmd = 0;
  1911. resultToPlC.cmdParam = 0; //指令参数
  1912. resultToPlC.cmdResult = mesResultFrmWeb;
  1913. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1914. stopwatch2.Stop();
  1915. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1916. //保存PLC返回MES数据到本地
  1917. ResponseMessage message = new ResponseMessage();
  1918. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1919. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1920. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1921. stPLC_MesData.mesData.nRemainCount);
  1922. if (message.result == false)
  1923. {
  1924. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1925. }
  1926. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1927. }
  1928. catch (Exception ex)
  1929. {
  1930. stopwatch2.Start();
  1931. CommandFromPLC resultToPlC = new CommandFromPLC();
  1932. resultToPlC.cmd = 0;
  1933. resultToPlC.cmdParam = 0; //指令参数
  1934. resultToPlC.cmdResult = 110;
  1935. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1936. stopwatch2.Stop();
  1937. string str = ex.StackTrace;
  1938. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1939. }
  1940. stopwatch1.Stop();
  1941. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1942. ProgressState = false;
  1943. }
  1944. #endregion
  1945. #region S2
  1946. /// <summary>
  1947. /// [S2] 上盖板上料装备
  1948. /// </summary>
  1949. /// <param name="plcNo">PLC编号</param>
  1950. private void ReadStation_S2(int plcNo)
  1951. {
  1952. string stationCode = "[OP20]";
  1953. string stationName = "上盖板上料装备";
  1954. string stationNameStr = stationCode + stationName;
  1955. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1956. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1957. string tagAgvCommName = "agvCommFrmPC";
  1958. string tagBarsetName = "BarcodeSet";
  1959. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1960. (int, string) result;
  1961. while (true)
  1962. {
  1963. try
  1964. {
  1965. if (!GlobalContext._IsCon_Funs2)
  1966. {
  1967. UpdatePLCMonitor(1, plcNo, 0);
  1968. continue;
  1969. }
  1970. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1971. {
  1972. Stopwatch stopwatch1 = new Stopwatch();
  1973. Stopwatch stopwatch2 = new Stopwatch();
  1974. stopwatch1.Start();
  1975. stopwatch2.Start();
  1976. #region 一次性读取所有数据
  1977. // 一次性读取所有数据
  1978. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1979. if (result.Item1 != 0)
  1980. {
  1981. //richTextBox1.AppendText("\n" + strRet);
  1982. }
  1983. else
  1984. {
  1985. //richTextBox1.AppendText("\n" + "读取成功");
  1986. }
  1987. #endregion 一次性读取所有数据
  1988. stopwatch2.Stop();
  1989. #region 进站
  1990. try
  1991. {
  1992. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1993. {
  1994. lock (lockObj)
  1995. {
  1996. if (!ProgressState)
  1997. {
  1998. ProgressState = true;
  1999. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2000. }
  2001. }
  2002. }
  2003. }
  2004. catch (Exception ex)
  2005. {
  2006. ProgressState = false;
  2007. string str = ex.StackTrace;
  2008. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2009. }
  2010. #endregion 进站
  2011. #region 出站
  2012. try
  2013. {
  2014. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2015. {
  2016. lock (lockObj)
  2017. {
  2018. if (!ProgressState)
  2019. {
  2020. ProgressState = true;
  2021. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2022. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  2023. }
  2024. }
  2025. }
  2026. }
  2027. catch (Exception ex)
  2028. {
  2029. ProgressState = false;
  2030. string str = ex.StackTrace;
  2031. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2032. }
  2033. #endregion 出站
  2034. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2035. stopwatch1.Stop();
  2036. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2037. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2038. }
  2039. else
  2040. {
  2041. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2042. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2043. FunsEip[plcNo].Connect();
  2044. }
  2045. }
  2046. catch (Exception ex)
  2047. {
  2048. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2049. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2050. //Funs[plcNo].ReConnect();
  2051. }
  2052. Thread.Sleep(IntervalReadPLC);
  2053. }
  2054. }
  2055. /// <summary>
  2056. /// [S2] 上盖板上料装备
  2057. /// </summary>
  2058. /// <param name="plcNo">PLC编号</param>
  2059. /// <param name="stationNameStr">工站全称</param>
  2060. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2061. {
  2062. Stopwatch stopwatch1 = new Stopwatch();
  2063. Stopwatch stopwatch2 = new Stopwatch();
  2064. try
  2065. {
  2066. stopwatch1.Start();
  2067. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2068. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  2069. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2070. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  2071. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  2072. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2073. //根据载具码获取产品码
  2074. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2075. if (string.IsNullOrEmpty(strProductBarcode))
  2076. {
  2077. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2078. }
  2079. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2080. //if (sn != strProductBarcode)
  2081. //{
  2082. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2083. //}
  2084. sn = strProductBarcode;
  2085. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2086. // 产品SN(物料码)校验
  2087. List<TestItem> item = new List<TestItem>();
  2088. stopwatch2.Start();
  2089. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2090. stopwatch2.Stop();
  2091. //指令执行结果 1:OK 110:失败
  2092. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2093. //进站结果写入PLC
  2094. CommandFromPLC resultToPlC = new CommandFromPLC();
  2095. resultToPlC.cmd = 0;
  2096. resultToPlC.cmdParam = 0; //指令参数
  2097. resultToPlC.cmdResult = mesResultFrmWeb;
  2098. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2099. }
  2100. catch (Exception ex)
  2101. {
  2102. string str = ex.StackTrace;
  2103. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2104. CommandFromPLC resultToPlC = new CommandFromPLC();
  2105. resultToPlC.cmd = 0;
  2106. resultToPlC.cmdParam = 0; //指令参数
  2107. resultToPlC.cmdResult = 110;
  2108. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2109. }
  2110. stopwatch1.Stop();
  2111. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2112. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2113. ProgressState = false;
  2114. }
  2115. /// <summary>
  2116. /// [S2] 上盖板上料装备 - 出站接口
  2117. /// </summary>
  2118. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2119. {
  2120. Stopwatch stopwatch1 = new Stopwatch();
  2121. Stopwatch stopwatch2 = new Stopwatch();
  2122. try
  2123. {
  2124. stopwatch1.Start();
  2125. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2126. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2127. string processItem = stationName; // 测试项目
  2128. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2129. string supplierCode = ""; // 供应商代码
  2130. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2131. string batch_num = GlobalContext.BatchNumber; // 批次号
  2132. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2133. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2134. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2135. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2136. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2137. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  2138. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2139. bool pass = a1Result == 1;
  2140. //根据载具码获取产品码
  2141. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2142. if (string.IsNullOrEmpty(strProductBarcode))
  2143. {
  2144. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2145. }
  2146. sn = strProductBarcode;
  2147. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2148. List<TestItem> items = new List<TestItem>();
  2149. items.Add(new TestItem()
  2150. {
  2151. Parameter_name = "载具码",
  2152. Parameter_value = CarrierBarcode,
  2153. Parameter_unit = ""
  2154. });
  2155. items.Add(new TestItem()
  2156. {
  2157. Parameter_name = "产品码",
  2158. Parameter_value = sn,
  2159. Parameter_unit = ""
  2160. });
  2161. items.Add(new TestItem()
  2162. {
  2163. Parameter_name = "部件码",
  2164. Parameter_value = PartBarcode,
  2165. Parameter_unit = ""
  2166. });
  2167. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  2168. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2169. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
  2170. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2171. stopwatch2.Start();
  2172. //进站结果写入PLC
  2173. CommandFromPLC resultToPlC = new CommandFromPLC();
  2174. resultToPlC.cmd = 0;
  2175. resultToPlC.cmdParam = 0; //指令参数
  2176. resultToPlC.cmdResult = mesResultFrmWeb;
  2177. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2178. stopwatch2.Stop();
  2179. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2180. //保存PLC返回MES数据到本地
  2181. ResponseMessage message = new ResponseMessage();
  2182. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  2183. if (message.result == false)
  2184. {
  2185. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2186. }
  2187. if (!string.IsNullOrEmpty(PartBarcode))
  2188. {
  2189. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2190. if (message.result == false)
  2191. {
  2192. AddMessage(LogType.Error, message.text);
  2193. }
  2194. }
  2195. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2196. }
  2197. catch (Exception ex)
  2198. {
  2199. stopwatch2.Start();
  2200. CommandFromPLC resultToPlC = new CommandFromPLC();
  2201. resultToPlC.cmd = 0;
  2202. resultToPlC.cmdParam = 0; //指令参数
  2203. resultToPlC.cmdResult = 110;
  2204. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2205. stopwatch2.Stop();
  2206. string str = ex.StackTrace;
  2207. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2208. }
  2209. stopwatch1.Stop();
  2210. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2211. ProgressState = false;
  2212. }
  2213. #endregion
  2214. #region S3
  2215. /// <summary>
  2216. /// [S3] 点散热胶装备
  2217. /// </summary>
  2218. /// <param name="plcNo">PLC编号</param>
  2219. private void ReadStation_S3(int plcNo)
  2220. {
  2221. string stationCode = "[OP30]";
  2222. string stationName = "点散热胶装备";
  2223. string stationNameStr = stationCode + stationName;
  2224. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2225. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2226. string tagAgvCommName = "agvCommFrmPC";
  2227. string tagBarsetName = "BarcodeSet";
  2228. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2229. (int, string) result;
  2230. #region 创建字典
  2231. // 触发信号字典 赋值
  2232. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2233. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2234. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2235. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2236. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2237. // PLC数据字典 赋值
  2238. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2239. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2240. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2241. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2242. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2243. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2244. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2245. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2246. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2247. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2248. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2249. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2250. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2251. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2252. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2253. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2254. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2255. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2256. s3PLCData.Add("c1Result", 0); // 产品结果
  2257. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2258. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2259. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2260. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2261. #endregion 创建字典
  2262. while (true)
  2263. {
  2264. try
  2265. {
  2266. if (!GlobalContext._IsCon_Funs2)
  2267. {
  2268. UpdatePLCMonitor(1, plcNo, 0);
  2269. continue;
  2270. }
  2271. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2272. {
  2273. Stopwatch stopwatch1 = new Stopwatch();
  2274. Stopwatch stopwatch2 = new Stopwatch();
  2275. stopwatch1.Start();
  2276. stopwatch2.Start();
  2277. #region 一次性读取所有数据
  2278. // 一次性读取所有数据
  2279. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2280. if (result.Item1 != 0)
  2281. {
  2282. //richTextBox1.AppendText("\n" + strRet);
  2283. }
  2284. else
  2285. {
  2286. //richTextBox1.AppendText("\n" + "读取成功");
  2287. }
  2288. #endregion 一次性读取所有数据
  2289. stopwatch2.Stop();
  2290. #region 左边进站
  2291. try
  2292. {
  2293. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2294. {
  2295. lock (lockObj)
  2296. {
  2297. if (!ProgressState)
  2298. {
  2299. ProgressState = true;
  2300. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2301. }
  2302. }
  2303. }
  2304. }
  2305. catch (Exception ex)
  2306. {
  2307. ProgressState = false;
  2308. string str = ex.StackTrace;
  2309. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2310. }
  2311. #endregion 左边进站
  2312. #region 左边出站
  2313. try
  2314. {
  2315. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2316. {
  2317. lock (lockObj)
  2318. {
  2319. if (!ProgressState)
  2320. {
  2321. ProgressState = true;
  2322. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2323. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  2324. }
  2325. }
  2326. }
  2327. }
  2328. catch (Exception ex)
  2329. {
  2330. ProgressState = false;
  2331. string str = ex.StackTrace;
  2332. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2333. }
  2334. #endregion 左边出站
  2335. #region 右边进站
  2336. try
  2337. {
  2338. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2339. {
  2340. lock (lockObj)
  2341. {
  2342. if (!ProgressState)
  2343. {
  2344. ProgressState = true;
  2345. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2346. }
  2347. }
  2348. }
  2349. }
  2350. catch (Exception ex)
  2351. {
  2352. ProgressState = false;
  2353. string str = ex.StackTrace;
  2354. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2355. }
  2356. #endregion 右边进站
  2357. #region 右边出站
  2358. try
  2359. {
  2360. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2361. {
  2362. lock (lockObj)
  2363. {
  2364. if (!ProgressState)
  2365. {
  2366. ProgressState = true;
  2367. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2368. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  2369. }
  2370. }
  2371. }
  2372. }
  2373. catch (Exception ex)
  2374. {
  2375. string str = ex.StackTrace;
  2376. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2377. }
  2378. #endregion 右边出站
  2379. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2380. stopwatch1.Stop();
  2381. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2382. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2383. }
  2384. else
  2385. {
  2386. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2387. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2388. FunsEip[plcNo].Connect();
  2389. }
  2390. }
  2391. catch (Exception ex)
  2392. {
  2393. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2394. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2395. //Funs[plcNo].ReConnect();
  2396. }
  2397. Thread.Sleep(IntervalReadPLC);
  2398. }
  2399. }
  2400. /// <summary>
  2401. /// [S3] 点散热胶装备 - 进站
  2402. /// </summary>
  2403. /// <param name="plcNo">PLC编号</param>
  2404. /// <param name="stationNameStr">工站全称</param>
  2405. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2406. {
  2407. Stopwatch stopwatch1 = new Stopwatch();
  2408. Stopwatch stopwatch2 = new Stopwatch();
  2409. try
  2410. {
  2411. stopwatch1.Start();
  2412. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2413. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2414. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2415. string StationId=string.Empty;
  2416. if (direction=="Left")
  2417. {
  2418. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2419. }
  2420. if (direction == "Right")
  2421. {
  2422. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2423. }
  2424. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2425. //载具码验证产品码
  2426. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2427. if (string.IsNullOrEmpty(strProductBarcode))
  2428. {
  2429. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2430. }
  2431. sn = strProductBarcode;
  2432. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2433. // 产品SN(物料码)校验
  2434. List<TestItem> item = new List<TestItem>();
  2435. stopwatch2.Start();
  2436. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2437. stopwatch2.Stop();
  2438. //指令执行结果 1:OK 110:失败
  2439. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2440. //进站结果写入PLC
  2441. CommandFromPLC resultToPlC = new CommandFromPLC();
  2442. resultToPlC.cmd = 0;
  2443. resultToPlC.cmdParam = 0; //指令参数
  2444. resultToPlC.cmdResult = mesResultFrmWeb;
  2445. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2446. }
  2447. catch (Exception ex)
  2448. {
  2449. string str = ex.StackTrace;
  2450. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2451. CommandFromPLC resultToPlC = new CommandFromPLC();
  2452. resultToPlC.cmd = 0;
  2453. resultToPlC.cmdParam = 0; //指令参数
  2454. resultToPlC.cmdResult = 110;
  2455. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2456. }
  2457. stopwatch1.Stop();
  2458. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2459. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2460. ProgressState = false;
  2461. }
  2462. /// <summary>
  2463. /// [S3] 点散热胶装备 - 出站
  2464. /// </summary>
  2465. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2466. {
  2467. Stopwatch stopwatch1 = new Stopwatch();
  2468. Stopwatch stopwatch2 = new Stopwatch();
  2469. try
  2470. {
  2471. stopwatch1.Start();
  2472. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2473. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2474. string processItem = stationName; // 测试项目
  2475. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2476. string supplierCode = ""; // 供应商代码
  2477. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2478. string batch_num = GlobalContext.BatchNumber; // 批次号
  2479. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2480. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2481. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2482. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2483. string StationId = string.Empty;
  2484. if (direction == "Left")
  2485. {
  2486. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2487. }
  2488. if (direction == "Right")
  2489. {
  2490. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2491. }
  2492. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2493. bool pass = a1Result == 1;
  2494. //根据载具码获取产品码
  2495. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2496. if (string.IsNullOrEmpty(strProductBarcode))
  2497. {
  2498. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2499. }
  2500. sn = strProductBarcode;
  2501. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2502. List<TestItem> items = new List<TestItem>();
  2503. items.Add(new TestItem()
  2504. {
  2505. Parameter_name = "载具码",
  2506. Parameter_value = CarrierBarcode,
  2507. Parameter_unit = ""
  2508. });
  2509. items.Add(new TestItem()
  2510. {
  2511. Parameter_name = "产品码",
  2512. Parameter_value = sn,
  2513. Parameter_unit = ""
  2514. });
  2515. int result1 = 1;
  2516. //if (direction == "Right")
  2517. //{
  2518. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  2519. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2520. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson, direction);
  2521. //}
  2522. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2523. stopwatch2.Start();
  2524. //进站结果写入PLC
  2525. CommandFromPLC resultToPlC = new CommandFromPLC();
  2526. resultToPlC.cmd = 0;
  2527. resultToPlC.cmdParam = 0; //指令参数
  2528. resultToPlC.cmdResult = mesResultFrmWeb;
  2529. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2530. stopwatch2.Stop();
  2531. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2532. //保存PLC返回MES数据到本地
  2533. ResponseMessage message = new ResponseMessage();
  2534. if (direction == "Left")
  2535. {
  2536. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2537. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2538. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2539. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2540. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2541. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2542. if (message.result == false)
  2543. {
  2544. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2545. }
  2546. }
  2547. if (direction == "Right")
  2548. {
  2549. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2550. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2551. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2552. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2553. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2554. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2555. if (message.result == false)
  2556. {
  2557. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2558. }
  2559. }
  2560. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2561. }
  2562. catch (Exception ex)
  2563. {
  2564. stopwatch2.Start();
  2565. CommandFromPLC resultToPlC = new CommandFromPLC();
  2566. resultToPlC.cmd = 0;
  2567. resultToPlC.cmdParam = 0; //指令参数
  2568. resultToPlC.cmdResult = 110;
  2569. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2570. stopwatch2.Stop();
  2571. string str = ex.StackTrace;
  2572. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2573. }
  2574. stopwatch1.Stop();
  2575. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2576. ProgressState = false;
  2577. }
  2578. #endregion S3
  2579. #region S4
  2580. /// <summary>
  2581. /// [S4] 点胶检测设备
  2582. /// </summary>
  2583. /// <param name="plcNo">PLC编号</param>
  2584. private void ReadStation_S4(int plcNo)
  2585. {
  2586. string stationCode = "[OP40]";
  2587. string stationName = "胶线检测";
  2588. string stationNameStr = stationCode + stationName;
  2589. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2590. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2591. string tagAgvCommName = "agvCommFrmPC";
  2592. string tagBarsetName = "BarcodeSet";
  2593. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2594. (int, string) result;
  2595. while (true)
  2596. {
  2597. try
  2598. {
  2599. if (!GlobalContext._IsCon_Funs1)
  2600. {
  2601. UpdatePLCMonitor(1, plcNo, 0);
  2602. continue;
  2603. }
  2604. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2605. {
  2606. Stopwatch stopwatch1 = new Stopwatch();
  2607. Stopwatch stopwatch2 = new Stopwatch();
  2608. stopwatch1.Start();
  2609. stopwatch2.Start();
  2610. #region 一次性读取所有数据
  2611. // 一次性读取所有数据
  2612. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2613. if (result.Item1 != 0)
  2614. {
  2615. //richTextBox1.AppendText("\n" + strRet);
  2616. }
  2617. else
  2618. {
  2619. //richTextBox1.AppendText("\n" + "读取成功");
  2620. }
  2621. #endregion 一次性读取所有数据
  2622. stopwatch2.Stop();
  2623. #region 进站
  2624. try
  2625. {
  2626. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2627. {
  2628. lock (lockObj)
  2629. {
  2630. if (!ProgressState)
  2631. {
  2632. ProgressState = true;
  2633. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2634. }
  2635. }
  2636. }
  2637. }
  2638. catch (Exception ex)
  2639. {
  2640. ProgressState = false;
  2641. string str = ex.StackTrace;
  2642. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2643. }
  2644. #endregion 进站
  2645. #region 出站
  2646. try
  2647. {
  2648. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2649. {
  2650. lock (lockObj)
  2651. {
  2652. if (!ProgressState)
  2653. {
  2654. ProgressState = true;
  2655. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2656. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2657. }
  2658. }
  2659. }
  2660. }
  2661. catch (Exception ex)
  2662. {
  2663. string str = ex.StackTrace;
  2664. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2665. }
  2666. #endregion 出站
  2667. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2668. stopwatch1.Stop();
  2669. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2670. }
  2671. else
  2672. {
  2673. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2674. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2675. FunsEip[plcNo].Connect(); // 重连
  2676. }
  2677. }
  2678. catch (Exception ex)
  2679. {
  2680. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2681. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2682. }
  2683. Thread.Sleep(IntervalReadPLC);
  2684. }
  2685. }
  2686. /// <summary>
  2687. /// [S4] 点胶检测设备 - 进站
  2688. /// </summary>
  2689. /// <param name="plcNo">PLC编号</param>
  2690. /// <param name="stationNameStr">工站全称</param>
  2691. /// <param name="stPLC_MesData"></param>
  2692. /// <param name="tagMesCommName"></param>
  2693. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2694. {
  2695. Stopwatch stopwatch1 = new Stopwatch();
  2696. Stopwatch stopwatch2 = new Stopwatch();
  2697. try
  2698. {
  2699. stopwatch1.Start();
  2700. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2701. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2702. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2703. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2704. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2705. //载具码验证产品码
  2706. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2707. if (string.IsNullOrEmpty(strProductBarcode))
  2708. {
  2709. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2710. }
  2711. sn = strProductBarcode;
  2712. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2713. // 产品SN(物料码)校验
  2714. List<TestItem> item = new List<TestItem>();
  2715. stopwatch2.Start();
  2716. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2717. stopwatch2.Stop();
  2718. //指令执行结果 1:OK 110:失败
  2719. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2720. //进站结果写入PLC
  2721. CommandFromPLC resultToPlC = new CommandFromPLC();
  2722. resultToPlC.cmd = 0;
  2723. resultToPlC.cmdParam = 0; //指令参数
  2724. resultToPlC.cmdResult = mesResultFrmWeb;
  2725. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2726. }
  2727. catch (Exception ex)
  2728. {
  2729. string str = ex.StackTrace;
  2730. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2731. CommandFromPLC resultToPlC = new CommandFromPLC();
  2732. resultToPlC.cmd = 0;
  2733. resultToPlC.cmdParam = 0; //指令参数
  2734. resultToPlC.cmdResult = 110;
  2735. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2736. }
  2737. stopwatch1.Stop();
  2738. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2739. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2740. ProgressState = false;
  2741. }
  2742. /// <summary>
  2743. /// [S4] 点胶检测设备 - 出站接口
  2744. /// </summary>
  2745. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2746. {
  2747. Stopwatch stopwatch1 = new Stopwatch();
  2748. Stopwatch stopwatch2 = new Stopwatch();
  2749. try
  2750. {
  2751. stopwatch1.Start();
  2752. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2753. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2754. string processItem = stationName; // 测试项目
  2755. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2756. string supplierCode = ""; // 供应商代码
  2757. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2758. string batch_num = GlobalContext.BatchNumber; // 批次号
  2759. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2760. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2761. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2762. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2763. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2764. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2765. bool pass = a1Result == 1;
  2766. //根据载具码获取产品码
  2767. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2768. if (string.IsNullOrEmpty(strProductBarcode))
  2769. {
  2770. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2771. }
  2772. sn = strProductBarcode;
  2773. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2774. List<TestItem> items = new List<TestItem>();
  2775. items.Add(new TestItem()
  2776. {
  2777. Parameter_name = "载具码",
  2778. Parameter_value = CarrierBarcode,
  2779. Parameter_unit = ""
  2780. });
  2781. items.Add(new TestItem()
  2782. {
  2783. Parameter_name = "产品码",
  2784. Parameter_value = sn,
  2785. Parameter_unit = ""
  2786. });
  2787. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  2788. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2789. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  2790. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2791. stopwatch2.Start();
  2792. //进站结果写入PLC
  2793. CommandFromPLC resultToPlC = new CommandFromPLC();
  2794. resultToPlC.cmd = 0;
  2795. resultToPlC.cmdParam = 0; //指令参数
  2796. resultToPlC.cmdResult = mesResultFrmWeb;
  2797. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2798. stopwatch2.Stop();
  2799. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2800. //保存PLC返回MES数据到本地
  2801. ResponseMessage message = new ResponseMessage();
  2802. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2803. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2804. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2805. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2806. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2807. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2808. if (message.result == false)
  2809. {
  2810. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2811. }
  2812. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2813. }
  2814. catch (Exception ex)
  2815. {
  2816. stopwatch2.Start();
  2817. CommandFromPLC resultToPlC = new CommandFromPLC();
  2818. resultToPlC.cmd = 0;
  2819. resultToPlC.cmdParam = 0; //指令参数
  2820. resultToPlC.cmdResult = 110;
  2821. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2822. stopwatch2.Stop();
  2823. string str = ex.StackTrace;
  2824. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2825. }
  2826. stopwatch1.Stop();
  2827. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2828. ProgressState = false;
  2829. }
  2830. #endregion
  2831. #region S5
  2832. /// <summary>
  2833. /// [S5] 点胶检测设备
  2834. /// </summary>
  2835. /// <param name="plcNo">PLC编号</param>
  2836. private void ReadStation_S5(int plcNo)
  2837. {
  2838. string stationCode = "[OP50]";
  2839. string stationName = "ADD板上料组装装备";
  2840. string stationNameStr = stationCode + stationName;
  2841. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2842. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2843. string tagAgvCommName = "agvCommFrmPC";
  2844. string tagBarsetName = "BarcodeSet";
  2845. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2846. (int, string) result;
  2847. while (true)
  2848. {
  2849. try
  2850. {
  2851. if (!GlobalContext._IsCon_Funs1)
  2852. {
  2853. UpdatePLCMonitor(1, plcNo, 0);
  2854. continue;
  2855. }
  2856. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2857. {
  2858. Stopwatch stopwatch1 = new Stopwatch();
  2859. Stopwatch stopwatch2 = new Stopwatch();
  2860. stopwatch1.Start();
  2861. stopwatch2.Start();
  2862. #region 一次性读取所有数据
  2863. // 一次性读取所有数据
  2864. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2865. if (result.Item1 != 0)
  2866. {
  2867. //richTextBox1.AppendText("\n" + strRet);
  2868. }
  2869. else
  2870. {
  2871. #region PCB出站
  2872. //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000243";
  2873. S5_PCB出站(stPLC_MesData, plcNo, stationNameStr, tagBaseName,tagMesCommName);
  2874. #endregion
  2875. }
  2876. #endregion 一次性读取所有数据
  2877. stopwatch2.Stop();
  2878. #region 进站
  2879. try
  2880. {
  2881. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2882. {
  2883. lock (lockObj)
  2884. {
  2885. if (!ProgressState)
  2886. {
  2887. ProgressState = true;
  2888. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2889. }
  2890. }
  2891. }
  2892. }
  2893. catch (Exception ex)
  2894. {
  2895. ProgressState = false;
  2896. string str = ex.StackTrace;
  2897. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2898. }
  2899. #endregion 进站
  2900. #region 出站
  2901. try
  2902. {
  2903. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2904. {
  2905. lock (lockObj)
  2906. {
  2907. if (!ProgressState)
  2908. {
  2909. ProgressState = true;
  2910. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2911. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2912. }
  2913. }
  2914. }
  2915. }
  2916. catch (Exception ex)
  2917. {
  2918. ProgressState = false;
  2919. string str = ex.StackTrace;
  2920. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2921. }
  2922. #endregion 出站
  2923. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2924. stopwatch1.Stop();
  2925. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2926. }
  2927. else
  2928. {
  2929. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2930. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2931. FunsEip[plcNo].Connect(); // 重连
  2932. }
  2933. }
  2934. catch (Exception ex)
  2935. {
  2936. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2937. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2938. }
  2939. Thread.Sleep(IntervalReadPLC);
  2940. }
  2941. }
  2942. /// <summary>
  2943. /// [S5] 点胶检测设备 - 进站
  2944. /// </summary>
  2945. /// <param name="plcNo">PLC编号</param>
  2946. /// <param name="stationNameStr">工站全称</param>
  2947. /// <param name="stPLC_MesData"></param>
  2948. /// <param name="tagMesCommName"></param>
  2949. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2950. {
  2951. Stopwatch stopwatch1 = new Stopwatch();
  2952. Stopwatch stopwatch2 = new Stopwatch();
  2953. try
  2954. {
  2955. stopwatch1.Start();
  2956. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2957. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2958. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2959. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2960. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2961. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  2962. //载具码验证产品码 //载具码验证产品码
  2963. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2964. if (string.IsNullOrEmpty(strProductBarcode))
  2965. {
  2966. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2967. }
  2968. sn = strProductBarcode;
  2969. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2970. // 产品SN(物料码)校验
  2971. List<TestItem> item = new List<TestItem>();
  2972. stopwatch2.Start();
  2973. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2974. stopwatch2.Stop();
  2975. //指令执行结果 1:OK 110:失败
  2976. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2977. //进站结果写入PLC
  2978. CommandFromPLC resultToPlC = new CommandFromPLC();
  2979. resultToPlC.cmd = 0;
  2980. resultToPlC.cmdParam = 0; //指令参数
  2981. resultToPlC.cmdResult = mesResultFrmWeb;
  2982. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2983. }
  2984. catch (Exception ex)
  2985. {
  2986. string str = ex.StackTrace;
  2987. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2988. CommandFromPLC resultToPlC = new CommandFromPLC();
  2989. resultToPlC.cmd = 0;
  2990. resultToPlC.cmdParam = 0; //指令参数
  2991. resultToPlC.cmdResult = 110;
  2992. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2993. }
  2994. stopwatch1.Stop();
  2995. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2996. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2997. ProgressState = false;
  2998. }
  2999. /// <summary>
  3000. /// [S5] 点胶检测设备 - 出站接口
  3001. /// </summary>
  3002. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3003. {
  3004. Stopwatch stopwatch1 = new Stopwatch();
  3005. Stopwatch stopwatch2 = new Stopwatch();
  3006. try
  3007. {
  3008. stopwatch1.Start();
  3009. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3010. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3011. string processItem = stationName; // 测试项目
  3012. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3013. string supplierCode = ""; // 供应商代码
  3014. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3015. string batch_num = GlobalContext.BatchNumber; // 批次号
  3016. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3017. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3018. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  3019. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3020. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  3021. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  3022. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  3023. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3024. bool pass = a1Result == 1;
  3025. //根据载具码获取产品码
  3026. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3027. if (string.IsNullOrEmpty(strProductBarcode))
  3028. {
  3029. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3030. }
  3031. sn = strProductBarcode;
  3032. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  3033. List<TestItem> items = new List<TestItem>();
  3034. items.Add(new TestItem()
  3035. {
  3036. Parameter_name = "载具码",
  3037. Parameter_value = CarrierBarcode,
  3038. Parameter_unit = ""
  3039. });
  3040. items.Add(new TestItem()
  3041. {
  3042. Parameter_name = "产品码",
  3043. Parameter_value = sn,
  3044. Parameter_unit = ""
  3045. });
  3046. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3047. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3048. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
  3049. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3050. stopwatch2.Start();
  3051. //进站结果写入PLC
  3052. CommandFromPLC resultToPlC = new CommandFromPLC();
  3053. resultToPlC.cmd = 0;
  3054. resultToPlC.cmdParam = 0; //指令参数
  3055. resultToPlC.cmdResult = mesResultFrmWeb;
  3056. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3057. stopwatch2.Stop();
  3058. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3059. //保存PLC返回MES数据到本地
  3060. ResponseMessage message = new ResponseMessage();
  3061. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  3062. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  3063. if (message.result == false)
  3064. {
  3065. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3066. }
  3067. //保存部件码信息
  3068. if (!string.IsNullOrEmpty(PartBarcode))
  3069. {
  3070. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  3071. if (message.result == false)
  3072. {
  3073. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  3074. }
  3075. }
  3076. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3077. }
  3078. catch (Exception ex)
  3079. {
  3080. stopwatch2.Start();
  3081. CommandFromPLC resultToPlC = new CommandFromPLC();
  3082. resultToPlC.cmd = 0;
  3083. resultToPlC.cmdParam = 0; //指令参数
  3084. resultToPlC.cmdResult = 110;
  3085. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3086. stopwatch2.Stop();
  3087. string str = ex.StackTrace;
  3088. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3089. }
  3090. stopwatch1.Stop();
  3091. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3092. ProgressState = false;
  3093. }
  3094. private void S5_PCB出站(OP50_MesData_t stPLC_MesData,int plcNo,string stationNameStr,string tagBaseName,string tagMesCommName) {
  3095. if (stPLC_MesData.BarcodeSet.strPCBBarcode.Replace("\r", "") != "ERROR")
  3096. {
  3097. int res = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  3098. CommandFromPLC resultToPlC = new CommandFromPLC();
  3099. resultToPlC.cmd = 0;
  3100. resultToPlC.cmdParam = 0; //指令参数
  3101. if (res == 1)
  3102. {
  3103. resultToPlC.cmdResult = 2;
  3104. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  3105. }
  3106. else
  3107. {
  3108. resultToPlC.cmdResult = 120;
  3109. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  3110. }
  3111. }
  3112. else
  3113. {
  3114. return;
  3115. }
  3116. }
  3117. #endregion
  3118. #region S6
  3119. /// <summary>
  3120. /// [S6] 顶盖装配设备
  3121. /// </summary>
  3122. /// <param name="plcNo">PLC编号</param>
  3123. private void ReadStation_S6(int plcNo)
  3124. {
  3125. string stationCode = "[OP60]";
  3126. string stationName = "组上盖板";
  3127. string stationNameStr = stationCode + stationName;
  3128. string tagBaseName = "g_OP60_MES"; //标签变量名称
  3129. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3130. string tagAgvCommName = "agvCommFrmPC";
  3131. string tagBarsetName = "BarcodeSet";
  3132. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  3133. (int, string) result;
  3134. while (true)
  3135. {
  3136. try
  3137. {
  3138. if (!GlobalContext._IsCon_Funs1)
  3139. {
  3140. UpdatePLCMonitor(1, plcNo, 0);
  3141. continue;
  3142. }
  3143. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3144. {
  3145. Stopwatch stopwatch1 = new Stopwatch();
  3146. Stopwatch stopwatch2 = new Stopwatch();
  3147. stopwatch1.Start();
  3148. stopwatch2.Start();
  3149. #region 一次性读取所有数据
  3150. // 一次性读取所有数据
  3151. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3152. if (result.Item1 != 0)
  3153. {
  3154. //richTextBox1.AppendText("\n" + strRet);
  3155. }
  3156. else
  3157. {
  3158. //richTextBox1.AppendText("\n" + "读取成功");
  3159. }
  3160. #endregion 一次性读取所有数据
  3161. stopwatch2.Stop();
  3162. #region 进站
  3163. try
  3164. {
  3165. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3166. {
  3167. lock (lockObj)
  3168. {
  3169. if (!ProgressState)
  3170. {
  3171. ProgressState = true;
  3172. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3173. }
  3174. }
  3175. }
  3176. }
  3177. catch (Exception ex)
  3178. {
  3179. ProgressState = false;
  3180. string str = ex.StackTrace;
  3181. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3182. }
  3183. #endregion 进站
  3184. #region 出站
  3185. try
  3186. {
  3187. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3188. {
  3189. lock (lockObj)
  3190. {
  3191. if (!ProgressState)
  3192. {
  3193. ProgressState = true; ;
  3194. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3195. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3196. }
  3197. }
  3198. }
  3199. }
  3200. catch (Exception ex)
  3201. {
  3202. ProgressState = false;
  3203. string str = ex.StackTrace;
  3204. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3205. }
  3206. #endregion 出站
  3207. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3208. stopwatch1.Stop();
  3209. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3210. }
  3211. else
  3212. {
  3213. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3214. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3215. FunsEip[plcNo].Connect(); // 重连
  3216. }
  3217. }
  3218. catch (Exception ex)
  3219. {
  3220. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3221. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3222. }
  3223. Thread.Sleep(IntervalReadPLC);
  3224. }
  3225. }
  3226. /// <summary>
  3227. /// [S6] 顶盖装配设备 - 进站
  3228. /// </summary>
  3229. /// <param name="plcNo">PLC编号</param>
  3230. /// <param name="stationNameStr">工站全称</param>
  3231. /// <param name="stPLC_MesData"></param>
  3232. /// <param name="tagMesCommName"></param>
  3233. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3234. {
  3235. Stopwatch stopwatch1 = new Stopwatch();
  3236. Stopwatch stopwatch2 = new Stopwatch();
  3237. try
  3238. {
  3239. stopwatch1.Start();
  3240. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3241. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3242. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3243. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3244. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3245. //strCarrierBarcode = "N801A-003";
  3246. //载具码验证产品码
  3247. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3248. if (string.IsNullOrEmpty(strProductBarcode))
  3249. {
  3250. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3251. }
  3252. sn = strProductBarcode;
  3253. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3254. if (OpenDailogFalg)
  3255. {
  3256. using (var dialog = new BandBarodeDialog())
  3257. {
  3258. dialog._CarrierBarcode = strCarrierBarcode;
  3259. dialog._ProductBarcode = sn;
  3260. var rs = dialog.ShowDialog();
  3261. if (rs == DialogResult.OK)
  3262. {
  3263. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  3264. OpenDailogFalg = false;//关闭扫码
  3265. }
  3266. else {
  3267. ProgressState = false;
  3268. return;
  3269. }
  3270. }
  3271. }
  3272. // 产品SN(物料码)校验
  3273. List<TestItem> item = new List<TestItem>();
  3274. stopwatch2.Start();
  3275. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3276. stopwatch2.Stop();
  3277. //指令执行结果 1:OK 110:失败
  3278. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3279. //进站结果写入PLC
  3280. CommandFromPLC resultToPlC = new CommandFromPLC();
  3281. resultToPlC.cmd = 0;
  3282. resultToPlC.cmdParam = 0; //指令参数
  3283. resultToPlC.cmdResult = mesResultFrmWeb;
  3284. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3285. }
  3286. catch (Exception ex)
  3287. {
  3288. string str = ex.StackTrace;
  3289. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3290. CommandFromPLC resultToPlC = new CommandFromPLC();
  3291. resultToPlC.cmd = 0;
  3292. resultToPlC.cmdParam = 0; //指令参数
  3293. resultToPlC.cmdResult = 110;
  3294. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3295. }
  3296. stopwatch1.Stop();
  3297. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3298. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3299. ProgressState = false;
  3300. OpenDailogFalg = true; //开启下一个物料的扫码
  3301. }
  3302. /// <summary>
  3303. /// [S6] 顶盖装配设备 - 出站接口
  3304. /// </summary>
  3305. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3306. {
  3307. Stopwatch stopwatch1 = new Stopwatch();
  3308. Stopwatch stopwatch2 = new Stopwatch();
  3309. try
  3310. {
  3311. stopwatch1.Start();
  3312. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3313. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3314. string processItem = stationName; // 测试项目
  3315. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3316. string supplierCode = ""; // 供应商代码
  3317. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3318. string batch_num = GlobalContext.BatchNumber; // 批次号
  3319. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3320. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3321. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3322. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3323. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3324. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3325. bool pass = a1Result == 1;
  3326. //根据载具码获取产品码
  3327. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3328. if (string.IsNullOrEmpty(strProductBarcode))
  3329. {
  3330. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3331. }
  3332. sn = strProductBarcode;
  3333. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3334. List<TestItem> items = new List<TestItem>();
  3335. items.Add(new TestItem()
  3336. {
  3337. Parameter_name = "载具码",
  3338. Parameter_value = CarrierBarcode,
  3339. Parameter_unit = ""
  3340. });
  3341. items.Add(new TestItem()
  3342. {
  3343. Parameter_name = "产品码",
  3344. Parameter_value = sn,
  3345. Parameter_unit = ""
  3346. });
  3347. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3348. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3349. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  3350. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3351. stopwatch2.Start();
  3352. //进站结果写入PLC
  3353. CommandFromPLC resultToPlC = new CommandFromPLC();
  3354. resultToPlC.cmd = 0;
  3355. resultToPlC.cmdParam = 0; //指令参数
  3356. resultToPlC.cmdResult = mesResultFrmWeb;
  3357. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3358. stopwatch2.Stop();
  3359. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3360. //保存PLC返回MES数据到本地
  3361. ResponseMessage message = new ResponseMessage();
  3362. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3363. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3364. if (message.result == false)
  3365. {
  3366. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3367. }
  3368. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3369. }
  3370. catch (Exception ex)
  3371. {
  3372. stopwatch2.Start();
  3373. CommandFromPLC resultToPlC = new CommandFromPLC();
  3374. resultToPlC.cmd = 0;
  3375. resultToPlC.cmdParam = 0; //指令参数
  3376. resultToPlC.cmdResult = 110;
  3377. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3378. stopwatch2.Stop();
  3379. string str = ex.StackTrace;
  3380. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3381. }
  3382. stopwatch1.Stop();
  3383. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3384. ProgressState = false;
  3385. }
  3386. #endregion
  3387. #region S7
  3388. /// <summary>
  3389. /// [S7] 锁螺丝设备
  3390. /// </summary>
  3391. /// <param name="plcNo">PLC编号</param>
  3392. private void ReadStation_S7(int plcNo)
  3393. {
  3394. string stationCode = "[OP70]";
  3395. string stationName = "上盖板锁螺丝";
  3396. string stationNameStr = stationCode + stationName;
  3397. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3398. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3399. string tagAgvCommName = "agvCommFrmPC";
  3400. string tagBarsetName = "BarcodeSet";
  3401. string tagScrewDataset = "screwDataset";
  3402. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3403. (int, string) result;
  3404. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3405. atlasScrewLeft.Initial();
  3406. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3407. atlasScrewRight.Initial();
  3408. while (true)
  3409. {
  3410. try
  3411. {
  3412. if (!GlobalContext._IsCon_Funs1)
  3413. {
  3414. UpdatePLCMonitor(1, plcNo, 0);
  3415. continue;
  3416. }
  3417. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3418. {
  3419. Stopwatch stopwatch1 = new Stopwatch();
  3420. Stopwatch stopwatch2 = new Stopwatch();
  3421. stopwatch1.Start();
  3422. stopwatch2.Start();
  3423. #region 一次性读取所有数据
  3424. // 一次性读取所有数据
  3425. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3426. if (result.Item1 != 0)
  3427. {
  3428. //richTextBox1.AppendText("\n" + strRet);
  3429. }
  3430. else
  3431. {
  3432. //richTextBox1.AppendText("\n" + "读取成功");
  3433. }
  3434. #endregion 一次性读取所有数据
  3435. stopwatch2.Stop();
  3436. #region 左边进站
  3437. try
  3438. {
  3439. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3440. {
  3441. lock (lockObj)
  3442. {
  3443. if (!ProgressState)
  3444. {
  3445. ProgressState = true;
  3446. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3447. }
  3448. }
  3449. }
  3450. }
  3451. catch (Exception ex)
  3452. {
  3453. ProgressState = false;
  3454. string str = ex.StackTrace;
  3455. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3456. }
  3457. #endregion 左边进站
  3458. #region 左边出站
  3459. try
  3460. {
  3461. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3462. {
  3463. lock (lockObj)
  3464. {
  3465. if (!ProgressState)
  3466. {
  3467. ProgressState = true;
  3468. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3469. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3470. }
  3471. }
  3472. }
  3473. }
  3474. catch (Exception ex)
  3475. {
  3476. ProgressState = false;
  3477. string str = ex.StackTrace;
  3478. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3479. }
  3480. #endregion 左边出站
  3481. #region 右边进站
  3482. try
  3483. {
  3484. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3485. {
  3486. lock (lockObj)
  3487. {
  3488. if (!ProgressState)
  3489. {
  3490. ProgressState = true;
  3491. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3492. }
  3493. }
  3494. }
  3495. }
  3496. catch (Exception ex)
  3497. {
  3498. ProgressState = false;
  3499. string str = ex.StackTrace;
  3500. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3501. }
  3502. #endregion 右边进站
  3503. #region 右边出站
  3504. try
  3505. {
  3506. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3507. {
  3508. lock (lockObj)
  3509. {
  3510. if (!ProgressState)
  3511. {
  3512. ProgressState = true;
  3513. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3514. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3515. }
  3516. }
  3517. }
  3518. }
  3519. catch (Exception ex)
  3520. {
  3521. ProgressState = false;
  3522. string str = ex.StackTrace;
  3523. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3524. }
  3525. #endregion 右边出站
  3526. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3527. stopwatch1.Stop();
  3528. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3529. }
  3530. else
  3531. {
  3532. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3533. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3534. FunsEip[plcNo].Connect(); // 重连
  3535. }
  3536. }
  3537. catch (Exception ex)
  3538. {
  3539. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3540. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3541. }
  3542. Thread.Sleep(IntervalReadPLC);
  3543. }
  3544. }
  3545. /// <summary>
  3546. /// [S7] 锁螺丝设备 - 进站
  3547. /// </summary>
  3548. /// <param name="plcNo">PLC编号</param>
  3549. /// <param name="stationNameStr">工站全称</param>
  3550. /// <param name="stPLC_MesData"></param>
  3551. /// <param name="tagMesCommName"></param>
  3552. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3553. {
  3554. Stopwatch stopwatch1 = new Stopwatch();
  3555. Stopwatch stopwatch2 = new Stopwatch();
  3556. string atlasSn=string.Empty;
  3557. try
  3558. {
  3559. stopwatch1.Start();
  3560. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3561. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3562. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3563. string StationId = string.Empty; // 工位ID(可配置)
  3564. if (direction == "Left")
  3565. {
  3566. StationId = GlobalContext.S7_StationId_1;
  3567. }
  3568. if (direction == "Right")
  3569. {
  3570. StationId = GlobalContext.S7_StationId_2;
  3571. }
  3572. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3573. //载具码验证产品码
  3574. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3575. if (string.IsNullOrEmpty(strProductBarcode))
  3576. {
  3577. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3578. }
  3579. sn = strProductBarcode;
  3580. atlasSn= strProductBarcode;
  3581. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3582. if (direction == "Left")
  3583. {
  3584. isCollectingFlagLeft = false;//采集螺丝数据结束
  3585. }
  3586. if (direction == "Right")
  3587. {
  3588. isCollectingFlagRight = false;//采集螺丝数据结束
  3589. }
  3590. // 产品SN(物料码)校验
  3591. List<TestItem> item = new List<TestItem>();
  3592. stopwatch2.Start();
  3593. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3594. stopwatch2.Stop();
  3595. //指令执行结果 1:OK 110:失败
  3596. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3597. //进站结果写入PLC
  3598. CommandFromPLC resultToPlC = new CommandFromPLC();
  3599. resultToPlC.cmd = 0;
  3600. resultToPlC.cmdParam = 0; //指令参数
  3601. resultToPlC.cmdResult = mesResultFrmWeb;
  3602. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3603. }
  3604. catch (Exception ex)
  3605. {
  3606. string str = ex.StackTrace;
  3607. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3608. CommandFromPLC resultToPlC = new CommandFromPLC();
  3609. resultToPlC.cmd = 0;
  3610. resultToPlC.cmdParam = 0; //指令参数
  3611. resultToPlC.cmdResult = 110;
  3612. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3613. }
  3614. stopwatch1.Stop();
  3615. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3616. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3617. ProgressState = false;
  3618. //开始采集螺丝数据
  3619. if (direction == "Left")
  3620. {
  3621. isCollectingFlagLeft = true;
  3622. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3623. }
  3624. if (direction == "Right")
  3625. {
  3626. isCollectingFlagRight = true;
  3627. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3628. }
  3629. }
  3630. /// <summary>
  3631. /// [S7] 锁螺丝设备 - 出站
  3632. /// </summary>
  3633. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3634. {
  3635. Stopwatch stopwatch1 = new Stopwatch();
  3636. Stopwatch stopwatch2 = new Stopwatch();
  3637. try
  3638. {
  3639. stopwatch1.Start();
  3640. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3641. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3642. string processItem = stationName; // 测试项目
  3643. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3644. string supplierCode = ""; // 供应商代码
  3645. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3646. string batch_num = GlobalContext.BatchNumber; // 批次号
  3647. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3648. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3649. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3650. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3651. string StationId = string.Empty; // 工位ID(可配置)
  3652. if (direction == "Left")
  3653. {
  3654. StationId = GlobalContext.S7_StationId_1;
  3655. }
  3656. if (direction == "Right")
  3657. {
  3658. StationId = GlobalContext.S7_StationId_2;
  3659. }
  3660. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3661. //a1Result = 1;
  3662. bool pass = a1Result == 1;
  3663. //根据载具码获取产品码
  3664. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3665. if (string.IsNullOrEmpty(strProductBarcode))
  3666. {
  3667. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3668. }
  3669. sn = strProductBarcode;
  3670. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3671. List<TestItem> items = new List<TestItem>();
  3672. items.Add(new TestItem()
  3673. {
  3674. Parameter_name = "载具码",
  3675. Parameter_value = CarrierBarcode,
  3676. Parameter_unit = ""
  3677. });
  3678. items.Add(new TestItem()
  3679. {
  3680. Parameter_name = "产品码",
  3681. Parameter_value = sn,
  3682. Parameter_unit = ""
  3683. });
  3684. int result1 = 1;
  3685. //if (direction == "Right")
  3686. //{
  3687. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3688. SwitctProcessData(stationNameStr, items, equipmentCode, processItem , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode
  3689. , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  3690. //}
  3691. //if (direction == "Left")
  3692. //{
  3693. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3694. //}
  3695. //if (direction == "Right")
  3696. //{
  3697. // isCollectingFlagRight = false;//采集螺丝数据结束
  3698. //}
  3699. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3700. stopwatch2.Start();
  3701. //进站结果写入PLC
  3702. CommandFromPLC resultToPlC = new CommandFromPLC();
  3703. resultToPlC.cmd = 0;
  3704. resultToPlC.cmdParam = 0; //指令参数
  3705. resultToPlC.cmdResult = mesResultFrmWeb;
  3706. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3707. stopwatch2.Stop();
  3708. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3709. //保存PLC返回MES数据到本地
  3710. ResponseMessage message = new ResponseMessage();
  3711. if (direction == "Left")
  3712. {
  3713. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3714. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3715. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3716. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3717. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3718. if (message.result == false)
  3719. {
  3720. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3721. }
  3722. }
  3723. if (direction == "Right")
  3724. {
  3725. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3726. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3727. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3728. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3729. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3730. if (message.result == false)
  3731. {
  3732. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3733. }
  3734. }
  3735. //保存螺丝数据到txt
  3736. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3737. if (result.Item1 != 0)
  3738. {
  3739. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3740. }
  3741. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3742. }
  3743. catch (Exception ex)
  3744. {
  3745. stopwatch2.Start();
  3746. CommandFromPLC resultToPlC = new CommandFromPLC();
  3747. resultToPlC.cmd = 0;
  3748. resultToPlC.cmdParam = 0; //指令参数
  3749. resultToPlC.cmdResult = 110;
  3750. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3751. stopwatch2.Stop();
  3752. string str = ex.StackTrace;
  3753. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3754. }
  3755. stopwatch1.Stop();
  3756. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3757. ProgressState = false;
  3758. }
  3759. #endregion
  3760. #region S8
  3761. /// <summary>
  3762. /// [S8] 3D螺丝高度检测设备
  3763. /// </summary>
  3764. /// <param name="plcNo">PLC编号</param>
  3765. private void ReadStation_S8(int plcNo)
  3766. {
  3767. string stationCode = "[OP80]";
  3768. string stationName = "NG下料";
  3769. string stationNameStr = stationCode + stationName;
  3770. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3771. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3772. string tagAgvCommName = "agvCommFrmPC";
  3773. string tagBarsetName = "BarcodeSet";
  3774. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3775. (int, string) result;
  3776. while (true)
  3777. {
  3778. try
  3779. {
  3780. if (!GlobalContext._IsCon_Funs1)
  3781. {
  3782. UpdatePLCMonitor(1, plcNo, 0);
  3783. continue;
  3784. }
  3785. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3786. {
  3787. Stopwatch stopwatch1 = new Stopwatch();
  3788. Stopwatch stopwatch2 = new Stopwatch();
  3789. stopwatch1.Start();
  3790. stopwatch2.Start();
  3791. #region 一次性读取所有数据
  3792. // 一次性读取所有数据
  3793. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3794. if (result.Item1 != 0)
  3795. {
  3796. //richTextBox1.AppendText("\n" + strRet);
  3797. }
  3798. else
  3799. {
  3800. //richTextBox1.AppendText("\n" + "读取成功");
  3801. }
  3802. #endregion 一次性读取所有数据
  3803. stopwatch2.Stop();
  3804. #region 进站
  3805. try
  3806. {
  3807. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3808. {
  3809. lock (lockObj)
  3810. {
  3811. if (!ProgressState)
  3812. {
  3813. ProgressState = true;
  3814. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3815. }
  3816. }
  3817. }
  3818. }
  3819. catch (Exception ex)
  3820. {
  3821. ProgressState = false;
  3822. string str = ex.StackTrace;
  3823. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3824. }
  3825. #endregion 进站
  3826. #region 出站
  3827. try
  3828. {
  3829. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3830. {
  3831. lock (lockObj)
  3832. {
  3833. if (!ProgressState)
  3834. {
  3835. ProgressState = true;
  3836. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3837. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3838. }
  3839. }
  3840. }
  3841. }
  3842. catch (Exception ex)
  3843. {
  3844. ProgressState = false;
  3845. string str = ex.StackTrace;
  3846. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3847. }
  3848. #endregion 出站
  3849. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3850. stopwatch1.Stop();
  3851. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3852. }
  3853. else
  3854. {
  3855. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3856. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3857. FunsEip[plcNo].Connect(); // 重连
  3858. }
  3859. }
  3860. catch (Exception ex)
  3861. {
  3862. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3863. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3864. }
  3865. Thread.Sleep(IntervalReadPLC);
  3866. }
  3867. }
  3868. /// <summary>
  3869. /// [S8] 3D螺丝高度检测设备 - 进站
  3870. /// </summary>
  3871. /// <param name="plcNo">PLC编号</param>
  3872. /// <param name="stationNameStr">工站全称</param>
  3873. /// <param name="stPLC_MesData"></param>
  3874. /// <param name="tagMesCommName"></param>
  3875. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3876. {
  3877. Stopwatch stopwatch1 = new Stopwatch();
  3878. Stopwatch stopwatch2 = new Stopwatch();
  3879. try
  3880. {
  3881. stopwatch1.Start();
  3882. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3883. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3884. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3885. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3886. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3887. //载具码验证产品码
  3888. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3889. if (string.IsNullOrEmpty(strProductBarcode))
  3890. {
  3891. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3892. }
  3893. sn = strProductBarcode;
  3894. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3895. // 产品SN(物料码)校验
  3896. List<TestItem> item = new List<TestItem>();
  3897. stopwatch2.Start();
  3898. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3899. stopwatch2.Stop();
  3900. //指令执行结果 1:OK 110:失败
  3901. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3902. //进站结果写入PLC
  3903. CommandFromPLC resultToPlC = new CommandFromPLC();
  3904. resultToPlC.cmd = 0;
  3905. resultToPlC.cmdParam = 0; //指令参数
  3906. resultToPlC.cmdResult = mesResultFrmWeb;
  3907. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3908. }
  3909. catch (Exception ex)
  3910. {
  3911. string str = ex.StackTrace;
  3912. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3913. CommandFromPLC resultToPlC = new CommandFromPLC();
  3914. resultToPlC.cmd = 0;
  3915. resultToPlC.cmdParam = 0; //指令参数
  3916. resultToPlC.cmdResult = 110;
  3917. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3918. }
  3919. stopwatch1.Stop();
  3920. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3921. ProgressState = false;
  3922. }
  3923. /// <summary>
  3924. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3925. /// </summary>
  3926. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3927. {
  3928. Stopwatch stopwatch1 = new Stopwatch();
  3929. Stopwatch stopwatch2 = new Stopwatch();
  3930. try
  3931. {
  3932. stopwatch1.Start();
  3933. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3934. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3935. string processItem = stationName; // 测试项目
  3936. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3937. string supplierCode = ""; // 供应商代码
  3938. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3939. string batch_num = GlobalContext.BatchNumber; // 批次号
  3940. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3941. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3942. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3943. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3944. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3945. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3946. bool pass = a1Result == 1;
  3947. //根据载具码获取产品码
  3948. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3949. if (string.IsNullOrEmpty(strProductBarcode))
  3950. {
  3951. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3952. }
  3953. sn = strProductBarcode;
  3954. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3955. List<TestItem> items = new List<TestItem>();
  3956. items.Add(new TestItem()
  3957. {
  3958. Parameter_name = "载具码",
  3959. Parameter_value = CarrierBarcode,
  3960. Parameter_unit = ""
  3961. });
  3962. items.Add(new TestItem()
  3963. {
  3964. Parameter_name = "产品码",
  3965. Parameter_value = sn,
  3966. Parameter_unit = ""
  3967. });
  3968. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3969. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3970. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  3971. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3972. stopwatch2.Start();
  3973. //进站结果写入PLC
  3974. CommandFromPLC resultToPlC = new CommandFromPLC();
  3975. resultToPlC.cmd = 0;
  3976. resultToPlC.cmdParam = 0; //指令参数
  3977. resultToPlC.cmdResult = mesResultFrmWeb;
  3978. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3979. stopwatch2.Stop();
  3980. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3981. //保存PLC返回MES数据到本地
  3982. ResponseMessage message = new ResponseMessage();
  3983. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3984. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3985. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3986. if (message.result == false)
  3987. {
  3988. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3989. }
  3990. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3991. }
  3992. catch (Exception ex)
  3993. {
  3994. stopwatch2.Start();
  3995. CommandFromPLC resultToPlC = new CommandFromPLC();
  3996. resultToPlC.cmd = 0;
  3997. resultToPlC.cmdParam = 0; //指令参数
  3998. resultToPlC.cmdResult = 110;
  3999. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4000. stopwatch2.Stop();
  4001. string str = ex.StackTrace;
  4002. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4003. }
  4004. stopwatch1.Stop();
  4005. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4006. ProgressState = false;
  4007. }
  4008. #endregion
  4009. #region S9
  4010. /// <summary>
  4011. /// [S9] 下料设备
  4012. /// </summary>
  4013. /// <param name="plcNo">PLC编号</param>
  4014. private void ReadStation_S9(int plcNo)
  4015. {
  4016. string stationCode = "[OP90]";
  4017. string stationName = "半成品下料";
  4018. string stationNameStr = stationCode + stationName;
  4019. string tagBaseName = "g_OP90_MES"; //标签变量名称
  4020. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4021. string tagAgvCommName = "agvCommFrmPC";
  4022. string tagBarsetName = "BarcodeSet";
  4023. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  4024. (int, string) result;
  4025. while (true)
  4026. {
  4027. try
  4028. {
  4029. if (!GlobalContext._IsCon_Funs1)
  4030. {
  4031. UpdatePLCMonitor(1, plcNo, 0);
  4032. continue;
  4033. }
  4034. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4035. {
  4036. Stopwatch stopwatch1 = new Stopwatch();
  4037. Stopwatch stopwatch2 = new Stopwatch();
  4038. stopwatch1.Start();
  4039. stopwatch2.Start();
  4040. #region 一次性读取所有数据
  4041. // 一次性读取所有数据
  4042. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4043. if (result.Item1 != 0)
  4044. {
  4045. //richTextBox1.AppendText("\n" + strRet);
  4046. }
  4047. else
  4048. {
  4049. //richTextBox1.AppendText("\n" + "读取成功");
  4050. }
  4051. #endregion 一次性读取所有数据
  4052. stopwatch2.Stop();
  4053. #region 进站
  4054. try
  4055. {
  4056. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4057. {
  4058. lock (lockObj)
  4059. {
  4060. if (!ProgressState)
  4061. {
  4062. ProgressState = true;
  4063. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  4064. }
  4065. }
  4066. }
  4067. }
  4068. catch (Exception ex)
  4069. {
  4070. ProgressState = false;
  4071. string str = ex.StackTrace;
  4072. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4073. }
  4074. #endregion 进站
  4075. #region 出站
  4076. try
  4077. {
  4078. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4079. {
  4080. lock (lockObj)
  4081. {
  4082. if (!ProgressState)
  4083. {
  4084. ProgressState = true;
  4085. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  4086. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4087. }
  4088. }
  4089. }
  4090. }
  4091. catch (Exception ex)
  4092. {
  4093. ProgressState = false;
  4094. string str = ex.StackTrace;
  4095. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4096. }
  4097. #endregion 出站
  4098. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4099. stopwatch1.Stop();
  4100. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4101. }
  4102. else
  4103. {
  4104. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4105. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4106. FunsEip[plcNo].Connect(); // 重连
  4107. }
  4108. }
  4109. catch (Exception ex)
  4110. {
  4111. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4112. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4113. }
  4114. Thread.Sleep(IntervalReadPLC);
  4115. }
  4116. }
  4117. /// <summary>
  4118. /// [S9] 下料设备 - 进站
  4119. /// </summary>
  4120. /// <param name="plcNo">PLC编号</param>
  4121. /// <param name="stationNameStr">工站全称</param>
  4122. /// <param name="stPLC_MesData"></param>
  4123. /// <param name="tagMesCommName"></param>
  4124. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  4125. {
  4126. Stopwatch stopwatch1 = new Stopwatch();
  4127. Stopwatch stopwatch2 = new Stopwatch();
  4128. try
  4129. {
  4130. stopwatch1.Start();
  4131. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4132. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4133. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  4134. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  4135. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4136. //载具码验证产品码
  4137. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4138. if (string.IsNullOrEmpty(strProductBarcode))
  4139. {
  4140. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4141. }
  4142. sn = strProductBarcode;
  4143. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4144. // 产品SN(物料码)校验
  4145. List<TestItem> item = new List<TestItem>();
  4146. stopwatch2.Start();
  4147. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  4148. stopwatch2.Stop();
  4149. //指令执行结果 1:OK 110:失败
  4150. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4151. //进站结果写入PLC
  4152. CommandFromPLC resultToPlC = new CommandFromPLC();
  4153. resultToPlC.cmd = 0;
  4154. resultToPlC.cmdParam = 0; //指令参数
  4155. resultToPlC.cmdResult = mesResultFrmWeb;
  4156. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4157. }
  4158. catch (Exception ex)
  4159. {
  4160. string str = ex.StackTrace;
  4161. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4162. CommandFromPLC resultToPlC = new CommandFromPLC();
  4163. resultToPlC.cmd = 0;
  4164. resultToPlC.cmdParam = 0; //指令参数
  4165. resultToPlC.cmdResult = 110;
  4166. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4167. }
  4168. stopwatch1.Stop();
  4169. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4170. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4171. ProgressState = false;
  4172. }
  4173. /// <summary>
  4174. /// [S9] 下料设备 - 出站接口
  4175. /// </summary>
  4176. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  4177. {
  4178. Stopwatch stopwatch1 = new Stopwatch();
  4179. Stopwatch stopwatch2 = new Stopwatch();
  4180. try
  4181. {
  4182. stopwatch1.Start();
  4183. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4184. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4185. string processItem = stationName; // 测试项目
  4186. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4187. string supplierCode = ""; // 供应商代码
  4188. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4189. string batch_num = GlobalContext.BatchNumber; // 批次号
  4190. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4191. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4192. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4193. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  4194. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  4195. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4196. bool pass = a1Result == 1;
  4197. //根据载具码获取产品码
  4198. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4199. if (string.IsNullOrEmpty(strProductBarcode))
  4200. {
  4201. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4202. }
  4203. sn = strProductBarcode;
  4204. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4205. List<TestItem> items = new List<TestItem>();
  4206. items.Add(new TestItem()
  4207. {
  4208. Parameter_name = "载具码",
  4209. Parameter_value = CarrierBarcode,
  4210. Parameter_unit = ""
  4211. });
  4212. items.Add(new TestItem()
  4213. {
  4214. Parameter_name = "产品码",
  4215. Parameter_value = sn,
  4216. Parameter_unit = ""
  4217. });
  4218. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4219. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4220. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  4221. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4222. stopwatch2.Start();
  4223. //进站结果写入PLC
  4224. CommandFromPLC resultToPlC = new CommandFromPLC();
  4225. resultToPlC.cmd = 0;
  4226. resultToPlC.cmdParam = 0; //指令参数
  4227. resultToPlC.cmdResult = mesResultFrmWeb;
  4228. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4229. stopwatch2.Stop();
  4230. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4231. //保存PLC返回MES数据到本地
  4232. ResponseMessage message = new ResponseMessage();
  4233. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4234. if (message.result == false)
  4235. {
  4236. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4237. }
  4238. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4239. if (result1 == 1)
  4240. {
  4241. //载具码解除绑定
  4242. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4243. if (message.result == false)
  4244. {
  4245. AddMessage(LogType.Error, message.text);
  4246. }
  4247. }
  4248. }
  4249. catch (Exception ex)
  4250. {
  4251. stopwatch2.Start();
  4252. CommandFromPLC resultToPlC = new CommandFromPLC();
  4253. resultToPlC.cmd = 0;
  4254. resultToPlC.cmdParam = 0; //指令参数
  4255. resultToPlC.cmdResult = 110;
  4256. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4257. stopwatch2.Stop();
  4258. string str = ex.StackTrace;
  4259. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4260. }
  4261. stopwatch1.Stop();
  4262. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4263. ProgressState = false;
  4264. }
  4265. #endregion
  4266. #endregion Xiaomi
  4267. #region PLC1 张超凡
  4268. #region [S1] Tray盘上料装备(板测)
  4269. /// <summary>
  4270. /// S1工位的数据- 触发信号上次的值
  4271. /// </summary>
  4272. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4273. /// <summary>
  4274. /// S1工位的数据(含触发信号)
  4275. /// </summary>
  4276. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4277. /// <summary>
  4278. /// S1工位的数据- 回写点位
  4279. /// </summary>
  4280. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4281. ///// <summary>
  4282. ///// 触发信号
  4283. ///// </summary>
  4284. //private ManualResetEvent[] MreTasks;
  4285. /// <summary>
  4286. /// [S1] Tray盘上料装备(板测)
  4287. /// </summary>
  4288. /// <param name="plcNo">PLC编号</param>
  4289. //private void ReadStation_S1(int plcNo)
  4290. //{
  4291. // // [S1] Tray盘上料装备
  4292. // // [S2] FCT
  4293. // // [S3] 值板机
  4294. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4295. // // [S5] Tray盘下料装备
  4296. // string stationCode = "[S1]";
  4297. // string stationName = "Tray盘上料装备";
  4298. // string stationNameStr = stationCode + stationName;
  4299. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4300. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4301. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4302. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4303. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4304. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4305. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4306. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4307. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4308. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4309. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4310. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4311. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4312. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4313. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4314. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4315. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4316. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4317. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4318. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4319. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4320. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4321. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4322. // s1PLCData.Add("a1Result", 0); // 产品结果
  4323. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4324. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4325. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4326. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4327. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4328. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4329. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4330. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4331. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4332. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4333. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4334. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4335. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4336. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4337. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4338. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4339. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4340. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4341. // while (IsRun)
  4342. // {
  4343. // try
  4344. // {
  4345. // if (!GlobalContext._IsCon_Funs1)
  4346. // {
  4347. // UpdatePLCMonitor(1, plcNo, 0);
  4348. // continue;
  4349. // }
  4350. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4351. // {
  4352. // Stopwatch stopwatch1 = new Stopwatch();
  4353. // Stopwatch stopwatch2 = new Stopwatch();
  4354. // stopwatch1.Start();
  4355. // stopwatch2.Start();
  4356. // #region 一次性读取所有数据
  4357. // // 一次性读取所有数据
  4358. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4359. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4360. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4361. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4362. // int[] datas = data1.Concat(data2).ToArray();
  4363. // datas = datas.Concat(data3).ToArray();
  4364. // datas = datas.Concat(data4).ToArray();
  4365. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4366. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4367. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4368. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4369. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4370. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4371. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4372. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4373. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4374. // s1PLCData["a1MES_FLAG"] = datas[109];
  4375. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4376. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4377. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4378. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4379. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4380. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4381. // s1PLCData["a1Result"] = datas[170];
  4382. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4383. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4384. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4385. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4386. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4387. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4388. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4389. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4390. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4391. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4392. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4393. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4394. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4395. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4396. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4397. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4398. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4399. // s1PLCData["a1AGVUpStart"] = datas[308];
  4400. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4401. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4402. // s1PLCData["a1AGVDownStart"] = datas[321];
  4403. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4404. // #endregion 一次性读取所有数据
  4405. // stopwatch2.Stop();
  4406. // #region 回写操作,写后清空flag
  4407. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4408. // #endregion 回写操作,写后清空flag
  4409. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4410. // try
  4411. // {
  4412. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4413. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4414. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4415. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4416. // {
  4417. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4418. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4419. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4420. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4421. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4422. // }
  4423. // }
  4424. // catch (Exception ex)
  4425. // {
  4426. // // 6代表上位机报警
  4427. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4428. // string str = ex.StackTrace;
  4429. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4430. // }
  4431. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4432. // #region 上料进站校验
  4433. // try
  4434. // {
  4435. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4436. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4437. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4438. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4439. // {
  4440. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4441. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4442. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4443. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4444. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4445. // }
  4446. // }
  4447. // catch (Exception ex)
  4448. // {
  4449. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4450. // string str = ex.StackTrace;
  4451. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4452. // }
  4453. // #endregion 上料进站校验
  4454. // #region Tray盘上料装备-出站接口
  4455. // try
  4456. // {
  4457. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4458. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4459. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4460. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4461. // {
  4462. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4463. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4464. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4465. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4466. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4467. // }
  4468. // }
  4469. // catch (Exception ex)
  4470. // {
  4471. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4472. // string str = ex.StackTrace;
  4473. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4474. // }
  4475. // #endregion Tray盘上料装备-出站接口
  4476. // #region Tray盘上料装备-将SN发给ICT标机
  4477. // try
  4478. // {
  4479. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4480. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4481. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4482. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4483. // {
  4484. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4485. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4486. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4487. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4488. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4489. // }
  4490. // }
  4491. // catch (Exception ex)
  4492. // {
  4493. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4494. // string str = ex.StackTrace;
  4495. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4496. // }
  4497. // #endregion Tray盘上料装备-将SN发给ICT标机
  4498. // #region Tray盘上料装备-点检数据
  4499. // //try
  4500. // //{
  4501. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4502. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4503. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4504. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4505. // // if (pLC_Flag && !mES_Flag) // 1 0
  4506. // // {
  4507. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4508. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4509. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4510. // // }
  4511. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4512. // // {
  4513. // // // 清空写给PLC的数据
  4514. // // // MES_Flag重置为0
  4515. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4516. // // }
  4517. // //}
  4518. // //catch (Exception ex)
  4519. // //{
  4520. // // // MES_Flag 为2上位机报错
  4521. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  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 Tray盘上料装备-点检数据
  4526. // #region 节拍接口
  4527. // try
  4528. // {
  4529. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4530. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4531. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4532. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4533. // {
  4534. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4535. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4536. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4537. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4538. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4539. // }
  4540. // }
  4541. // catch (Exception ex)
  4542. // {
  4543. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  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 AGV上料
  4549. // // AGV上料叫AGV信号
  4550. // try
  4551. // {
  4552. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4553. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4554. // if (a1AGVUpCall != a1AGVUpCallOld)
  4555. // {
  4556. // if (a1AGVUpCall == 1) // 0->1
  4557. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4558. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4559. // }
  4560. // }
  4561. // catch (Exception ex)
  4562. // {
  4563. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4564. // string str = ex.StackTrace;
  4565. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4566. // }
  4567. // // AGV上料完成信号
  4568. // try
  4569. // {
  4570. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4571. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4572. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4573. // {
  4574. // if (a1AGVUpEnd == 1) // 0->1
  4575. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4576. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4577. // }
  4578. // }
  4579. // catch (Exception ex)
  4580. // {
  4581. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4582. // string str = ex.StackTrace;
  4583. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4584. // }
  4585. // #endregion AGV上料
  4586. // #region AGV下料
  4587. // // AGV下料叫agv信号
  4588. // try
  4589. // {
  4590. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4591. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4592. // if (a1AGVDownCall != a1AGVDownCallOld)
  4593. // {
  4594. // if (a1AGVDownCall == 1) // 0->1
  4595. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4596. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4597. // }
  4598. // }
  4599. // catch (Exception ex)
  4600. // {
  4601. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4602. // string str = ex.StackTrace;
  4603. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4604. // }
  4605. // // AGV下料完成信号
  4606. // try
  4607. // {
  4608. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4609. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4610. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4611. // {
  4612. // if (a1AGVDownEnd == 1) // 0->1
  4613. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4614. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4615. // }
  4616. // }
  4617. // catch (Exception ex)
  4618. // {
  4619. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4620. // string str = ex.StackTrace;
  4621. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4622. // }
  4623. // #endregion AGV下料
  4624. // #region 心跳
  4625. // try
  4626. // {
  4627. // short states = 0;
  4628. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4629. // }
  4630. // catch (Exception ex)
  4631. // {
  4632. // string str = ex.StackTrace;
  4633. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4634. // }
  4635. // #endregion 心跳
  4636. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4637. // stopwatch1.Stop();
  4638. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4639. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4640. // }
  4641. // else
  4642. // {
  4643. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4644. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4645. // Funs[plcNo].Connect(); // 重连
  4646. // }
  4647. // }
  4648. // catch (Exception ex)
  4649. // {
  4650. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4651. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4652. // Funs[plcNo].ReConnect();
  4653. // }
  4654. // Thread.Sleep(IntervalReadPLC);
  4655. // }
  4656. //}
  4657. /// <summary>
  4658. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4659. /// </summary>
  4660. /// <param name="plcNo">PLC编号</param>
  4661. /// <param name="stationNameStr">工站全称</param>
  4662. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4663. {
  4664. Stopwatch stopwatch1 = new Stopwatch();
  4665. Stopwatch stopwatch2 = new Stopwatch();
  4666. try
  4667. {
  4668. stopwatch1.Start();
  4669. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4670. sn = sn.Replace("\0", "");
  4671. #region 查询载具上的产品信息
  4672. string cavityData = string.Empty;
  4673. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4674. if (string.IsNullOrEmpty(cavityData))
  4675. cavityData = "";
  4676. if (snResult != 0)
  4677. {
  4678. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4679. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4680. writeToPLC_Flag1.Adress = 2003;
  4681. writeToPLC_Flag1.Value = (short)6;
  4682. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4683. stopwatch1.Stop();
  4684. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4685. return;
  4686. }
  4687. #endregion 查询载具上的产品信息
  4688. string[] cavitySNs = cavityData.Split('.');
  4689. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4690. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4691. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4692. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4693. if (cavitySNs != null && cavitySNs.Length >= 2)
  4694. {
  4695. a1CavitySN1_VehicleStates = cavitySNs[0];
  4696. a1CavitySN2_VehicleStates = cavitySNs[1];
  4697. a1CavityResult1_VehicleStates = 2;
  4698. a1CavityResult2_VehicleStates = 2;
  4699. }
  4700. if (a1CavitySN1_VehicleStates == "假产品")
  4701. a1CavityResult1_VehicleStates = 3;
  4702. if (a1CavitySN2_VehicleStates == "假产品")
  4703. a1CavityResult2_VehicleStates = 3;
  4704. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4705. // 回写
  4706. stopwatch2.Start();
  4707. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4708. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4709. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4710. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4711. //// MES_Flag
  4712. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4713. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4714. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4715. writeToPLC_Flag.Adress = 2003;
  4716. writeToPLC_Flag.Value = mES_Flag;
  4717. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4718. {
  4719. Name = "a1CavitySN1_VehicleStates",
  4720. Adress = 2024,
  4721. ValueType = PLCValueType.String,
  4722. ValueTypeStrLength = 20,
  4723. Value = a1CavitySN1_VehicleStates
  4724. });
  4725. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4726. {
  4727. Name = "a1CavitySN2_VehicleStates",
  4728. Adress = 2044,
  4729. ValueType = PLCValueType.String,
  4730. ValueTypeStrLength = 20,
  4731. Value = a1CavitySN2_VehicleStates
  4732. });
  4733. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4734. {
  4735. Name = "a1CavityResult1_VehicleStates",
  4736. Adress = 2064,
  4737. ValueType = PLCValueType.Short,
  4738. Value = a1CavityResult1_VehicleStates
  4739. });
  4740. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4741. {
  4742. Name = "a1CavityResult2_VehicleStates",
  4743. Adress = 2065,
  4744. ValueType = PLCValueType.Short,
  4745. Value = a1CavityResult2_VehicleStates
  4746. });
  4747. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4748. stopwatch2.Stop();
  4749. }
  4750. catch (Exception ex)
  4751. {
  4752. string str = ex.StackTrace;
  4753. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4754. // MES_Flag
  4755. stopwatch2.Start();
  4756. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4757. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4758. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4759. writeToPLC_Flag.Adress = 2003;
  4760. writeToPLC_Flag.Value = (short)6;
  4761. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4762. stopwatch2.Stop();
  4763. }
  4764. stopwatch1.Stop();
  4765. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4766. }
  4767. /// <summary>
  4768. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4769. /// </summary>
  4770. /// <param name="plcNo">PLC编号</param>
  4771. /// <param name="stationNameStr">工站全称</param>
  4772. private void S1上料进站校验(int plcNo, string stationNameStr)
  4773. {
  4774. Stopwatch stopwatch1 = new Stopwatch();
  4775. Stopwatch stopwatch2 = new Stopwatch();
  4776. try
  4777. {
  4778. stopwatch1.Start();
  4779. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4780. sn = sn.Replace("\0", "");
  4781. // 保存进站数据+调用进站MES接口
  4782. List<TestItem> item = new List<TestItem>();
  4783. stopwatch2.Start();
  4784. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4785. stopwatch2.Stop();
  4786. short a1MES_FLAG_Check = (short)result;
  4787. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4788. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4789. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4790. writeToPLC_Flag.Adress = 2077;
  4791. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4792. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4793. }
  4794. catch (Exception ex)
  4795. {
  4796. string str = ex.StackTrace;
  4797. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4798. // MES_Flag
  4799. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4800. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4801. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4802. writeToPLC_Flag.Adress = 2077;
  4803. writeToPLC_Flag.Value = (short)6;
  4804. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4805. }
  4806. stopwatch1.Stop();
  4807. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4808. }
  4809. /// <summary>
  4810. /// [S1] Tray盘上料装备(板测)- 出站接口
  4811. /// </summary>
  4812. /// <param name="plcNo"></param>
  4813. /// <param name="stationCode"></param>
  4814. /// <param name="stationName"></param>
  4815. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4816. {
  4817. Stopwatch stopwatch1 = new Stopwatch();
  4818. Stopwatch stopwatch2 = new Stopwatch();
  4819. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4820. string stationNameStr = stationCode + stationName;
  4821. string processItem = stationName; // 测试项目
  4822. try
  4823. {
  4824. stopwatch1.Start();
  4825. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4826. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4827. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4828. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4829. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4830. sn = sn.Replace("\0", "");
  4831. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4832. partNo1 = partNo1.Replace("\0", "");
  4833. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4834. partNo2 = partNo2.Replace("\0", "");
  4835. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4836. bool pass = a1Result == 1;
  4837. stopwatch2.Start();
  4838. // 产品1
  4839. List<TestItem> items = new List<TestItem>();
  4840. items.Add(new TestItem()
  4841. {
  4842. Parameter_name = "载具码",
  4843. Parameter_value = sn,
  4844. Parameter_unit = ""
  4845. });
  4846. items.Add(new TestItem()
  4847. {
  4848. Parameter_name = "载具穴号",
  4849. Parameter_value = "1",
  4850. Parameter_unit = ""
  4851. });
  4852. items.Add(new TestItem()
  4853. {
  4854. Parameter_name = "产品结果",
  4855. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4856. Parameter_unit = ""
  4857. });
  4858. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  4859. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4860. // 产品2
  4861. items = new List<TestItem>();
  4862. items.Add(new TestItem()
  4863. {
  4864. Parameter_name = "载具码",
  4865. Parameter_value = sn,
  4866. Parameter_unit = ""
  4867. });
  4868. items.Add(new TestItem()
  4869. {
  4870. Parameter_name = "载具穴号",
  4871. Parameter_value = "2",
  4872. Parameter_unit = ""
  4873. });
  4874. items.Add(new TestItem()
  4875. {
  4876. Parameter_name = "产品结果",
  4877. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4878. Parameter_unit = ""
  4879. });
  4880. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  4881. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4882. short result = 0;
  4883. List<int> results = new List<int>() { result1, result2 };
  4884. if (result1 == 1 && result2 == 1)
  4885. result = 1;
  4886. else if (results.Contains(3))
  4887. result = 3;
  4888. else if (results.Contains(2))
  4889. result = 2;
  4890. else if (results.Contains(4))
  4891. result = 4;
  4892. else
  4893. result = 4;
  4894. stopwatch2.Stop();
  4895. #region 存储绑定数据到 边线MES系统中
  4896. if (result == 1)
  4897. {
  4898. string data = string.Concat(partNo1, ".", partNo2);
  4899. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4900. if (resultMesR != 0)
  4901. {
  4902. result = 4;
  4903. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4904. }
  4905. }
  4906. #endregion 存储绑定数据到 边线MES系统中
  4907. // MES_Flag 为MES报错
  4908. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4909. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4910. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4911. writeToPLC_Flag.Name = "a1MES_FLAG";
  4912. writeToPLC_Flag.Adress = 2109;
  4913. writeToPLC_Flag.Value = result;
  4914. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4915. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4916. }
  4917. catch (Exception ex)
  4918. {
  4919. stopwatch2.Restart();
  4920. // MES_Flag 为4上位机报错
  4921. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4922. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4923. writeToPLC_Flag.Name = "a1MES_FLAG";
  4924. writeToPLC_Flag.Adress = 2109;
  4925. writeToPLC_Flag.Value = (short)4;
  4926. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4927. stopwatch2.Stop();
  4928. string str = ex.StackTrace;
  4929. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4930. }
  4931. stopwatch1.Stop();
  4932. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4933. }
  4934. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4935. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4936. //{
  4937. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4938. // string stationNameStr = stationCode + stationName;
  4939. // string processItem = stationName; // 测试项目
  4940. // try
  4941. // {
  4942. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4943. // string accno = "1"; // 工序编号
  4944. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4945. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4946. // List<OneCheckItem> items = new List<OneCheckItem>()
  4947. // {
  4948. // new OneCheckItem()
  4949. // {
  4950. // Onecheck_name="胶圈装配行程设定上限",
  4951. // Onecheck_content="上限值",
  4952. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4953. // },
  4954. // };
  4955. // OneCheckData oneCheckData = new OneCheckData()
  4956. // {
  4957. // Line_code = GlobalContext.LineCode,
  4958. // Line_name = GlobalContext.LineName,
  4959. // Equipment_code = equipmentCode,
  4960. // Equipment_name = equipmentCode,
  4961. // Workorder_code = workorder_code,
  4962. // Procedure_code = accno,
  4963. // Procedure_name = processItem,
  4964. // Oneckeck_values = items,
  4965. // Onecheck_empcode = "",
  4966. // Onecheck_empname = "",
  4967. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4968. // };
  4969. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4970. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4971. // short result = result1 == 1 ? (short)1 : (short)2;
  4972. // // MES_Flag 为4MES报错
  4973. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4974. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4975. // }
  4976. // catch (Exception ex)
  4977. // {
  4978. // // MES_Flag 为2上位机报错
  4979. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4980. // string str = ex.StackTrace;
  4981. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4982. // }
  4983. //}
  4984. // ReadStation_S1_2 节拍接口+AGV
  4985. /// <summary>
  4986. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4987. /// </summary>
  4988. /// <param name="plcNo">PLC编号</param>
  4989. /// <param name="stationNameStr">工站全称</param>
  4990. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4991. {
  4992. Stopwatch stopwatch1 = new Stopwatch();
  4993. Stopwatch stopwatch2 = new Stopwatch();
  4994. try
  4995. {
  4996. stopwatch1.Start();
  4997. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4998. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4999. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  5000. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  5001. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  5002. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  5003. // ZS 将SN发给ICT标机(串口)
  5004. short a1MES_FLAG_ICT = 1;
  5005. stopwatch2.Start();
  5006. // MES_Flag
  5007. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  5008. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5009. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  5010. writeToPLC_Flag.Adress = 2182;
  5011. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  5012. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  5013. stopwatch2.Stop();
  5014. }
  5015. catch (Exception ex)
  5016. {
  5017. string str = ex.StackTrace;
  5018. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5019. stopwatch2.Start();
  5020. // MES_Flag
  5021. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  5022. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5023. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  5024. writeToPLC_Flag.Adress = 2182;
  5025. writeToPLC_Flag.Value = (short)4;
  5026. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  5027. stopwatch2.Stop();
  5028. }
  5029. stopwatch1.Stop();
  5030. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5031. }
  5032. /// <summary>
  5033. /// [S1] Tray盘上料装备(板测)- 节拍接口
  5034. /// </summary>
  5035. /// <param name="plcNo">PLC编号</param>
  5036. /// <param name="stationNameStr">工站全称</param>
  5037. private void S1节拍接口(int plcNo, string stationNameStr)
  5038. {
  5039. Stopwatch stopwatch1 = new Stopwatch();
  5040. Stopwatch stopwatch2 = new Stopwatch();
  5041. string resultStr = string.Empty;
  5042. try
  5043. {
  5044. stopwatch1.Start();
  5045. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  5046. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  5047. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  5048. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  5049. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  5050. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  5051. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  5052. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5053. if (!actionBool)
  5054. {
  5055. stopwatch2.Start();
  5056. // MES_Flag
  5057. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5058. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5059. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  5060. writeToPLC_Flag1.Adress = 2254;
  5061. writeToPLC_Flag1.Value = (short)1;
  5062. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  5063. stopwatch2.Stop();
  5064. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5065. return;
  5066. }
  5067. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  5068. {
  5069. stopwatch2.Start();
  5070. // MES_Flag
  5071. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5072. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  5073. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  5074. writeToPLC_Flag2.Adress = 2254;
  5075. writeToPLC_Flag2.Value = (short)1;
  5076. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  5077. stopwatch2.Stop();
  5078. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5079. return;
  5080. }
  5081. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  5082. { // 查产品SN
  5083. a1OEEPartNo = "Test"; // ZS
  5084. }
  5085. short a1OEEMES_FLAG = 0;
  5086. // 上传OEE
  5087. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  5088. a1OEEMES_FLAG = result.Item1;
  5089. resultStr = result.Item2;
  5090. stopwatch2.Start();
  5091. // MES_Flag
  5092. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5093. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5094. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5095. writeToPLC_Flag.Adress = 2254;
  5096. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  5097. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5098. stopwatch2.Stop();
  5099. }
  5100. catch (Exception ex)
  5101. {
  5102. string str = ex.StackTrace;
  5103. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5104. // MES_Flag
  5105. stopwatch2.Start();
  5106. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  5107. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5108. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  5109. writeToPLC_Flag.Adress = 2254;
  5110. writeToPLC_Flag.Value = (short)4;
  5111. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  5112. stopwatch2.Stop();
  5113. }
  5114. stopwatch1.Stop();
  5115. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5116. }
  5117. /// <summary>
  5118. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  5119. /// </summary>
  5120. /// <param name="plcNo">PLC编号</param>
  5121. /// <param name="stationNameStr">工站全称</param>
  5122. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  5123. {
  5124. Stopwatch stopwatch1 = new Stopwatch();
  5125. Stopwatch stopwatch2 = new Stopwatch();
  5126. try
  5127. {
  5128. stopwatch1.Start();
  5129. // ZS 呼叫AGV
  5130. short a1AGVUpCall = 2;
  5131. stopwatch2.Start();
  5132. // a1AGVUpCall
  5133. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5134. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5135. writeToPLC_Flag.Name = "a1AGVUpCall";
  5136. writeToPLC_Flag.Adress = 2307;
  5137. writeToPLC_Flag.Value = a1AGVUpCall;
  5138. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5139. stopwatch2.Stop();
  5140. }
  5141. catch (Exception ex)
  5142. {
  5143. string str = ex.StackTrace;
  5144. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5145. // a1AGVUpCall
  5146. stopwatch2.Start();
  5147. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  5148. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5149. writeToPLC_Flag.Name = "a1AGVUpCall";
  5150. writeToPLC_Flag.Adress = 2307;
  5151. writeToPLC_Flag.Value = (short)4;
  5152. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  5153. stopwatch2.Stop();
  5154. }
  5155. stopwatch1.Stop();
  5156. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5157. }
  5158. /// <summary>
  5159. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  5160. /// </summary>
  5161. /// <param name="plcNo">PLC编号</param>
  5162. /// <param name="stationNameStr">工站全称</param>
  5163. private void S1AGV上料完成(int plcNo, string stationNameStr)
  5164. {
  5165. Stopwatch stopwatch1 = new Stopwatch();
  5166. Stopwatch stopwatch2 = new Stopwatch();
  5167. try
  5168. {
  5169. stopwatch1.Start();
  5170. // ZS AGV上料完成,让小车离开
  5171. short a1AGVUpEnd = 2;
  5172. stopwatch2.Start();
  5173. // a1AGVUpEnd
  5174. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5175. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5176. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5177. writeToPLC_Flag.Adress = 2309;
  5178. writeToPLC_Flag.Value = a1AGVUpEnd;
  5179. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5180. stopwatch2.Stop();
  5181. }
  5182. catch (Exception ex)
  5183. {
  5184. string str = ex.StackTrace;
  5185. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5186. // a1AGVUpEnd
  5187. stopwatch2.Start();
  5188. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  5189. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5190. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5191. writeToPLC_Flag.Adress = 2309;
  5192. writeToPLC_Flag.Value = (short)4;
  5193. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5194. stopwatch2.Stop();
  5195. }
  5196. stopwatch1.Stop();
  5197. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5198. }
  5199. /// <summary>
  5200. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  5201. /// </summary>
  5202. /// <param name="plcNo">PLC编号</param>
  5203. /// <param name="stationNameStr">工站全称</param>
  5204. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  5205. {
  5206. Stopwatch stopwatch1 = new Stopwatch();
  5207. Stopwatch stopwatch2 = new Stopwatch();
  5208. try
  5209. {
  5210. stopwatch1.Start();
  5211. // ZS 呼叫AGV
  5212. short a1AGVDownCall = 2;
  5213. stopwatch2.Start();
  5214. // a1AGVDownCall
  5215. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5216. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5217. writeToPLC_Flag.Name = "a1AGVDownCall";
  5218. writeToPLC_Flag.Adress = 2320;
  5219. writeToPLC_Flag.Value = a1AGVDownCall;
  5220. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5221. stopwatch2.Stop();
  5222. }
  5223. catch (Exception ex)
  5224. {
  5225. string str = ex.StackTrace;
  5226. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5227. // a1AGVDownCall
  5228. stopwatch2.Start();
  5229. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5230. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5231. writeToPLC_Flag.Name = "a1AGVDownCall";
  5232. writeToPLC_Flag.Adress = 2320;
  5233. writeToPLC_Flag.Value = (short)4;
  5234. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5235. stopwatch2.Stop();
  5236. }
  5237. stopwatch1.Stop();
  5238. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5239. }
  5240. /// <summary>
  5241. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5242. /// </summary>
  5243. /// <param name="plcNo">PLC编号</param>
  5244. /// <param name="stationNameStr">工站全称</param>
  5245. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5246. {
  5247. Stopwatch stopwatch1 = new Stopwatch();
  5248. Stopwatch stopwatch2 = new Stopwatch();
  5249. try
  5250. {
  5251. stopwatch1.Start();
  5252. // ZS AGV上料完成,让小车离开
  5253. short a1AGVDownEnd = 2;
  5254. stopwatch2.Start();
  5255. // a1AGVDownEnd
  5256. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5257. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5258. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5259. writeToPLC_Flag.Adress = 2322;
  5260. writeToPLC_Flag.Value = a1AGVDownEnd;
  5261. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5262. stopwatch2.Stop();
  5263. }
  5264. catch (Exception ex)
  5265. {
  5266. string str = ex.StackTrace;
  5267. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5268. // a1AGVDownEnd
  5269. stopwatch2.Start();
  5270. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5271. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5272. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5273. writeToPLC_Flag.Adress = 2322;
  5274. writeToPLC_Flag.Value = (short)4;
  5275. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5276. stopwatch2.Stop();
  5277. }
  5278. stopwatch1.Stop();
  5279. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5280. }
  5281. #endregion [S1] Tray盘上料装备(板测)
  5282. #endregion PLC1 张超凡
  5283. #region PLC2 李晓奇
  5284. #region [S2] FCT(板测)
  5285. /// <summary>
  5286. /// S2工位的数据- 触发信号上次的值
  5287. /// </summary>
  5288. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5289. /// <summary>
  5290. /// S2工位的数据(含触发信号)
  5291. /// </summary>
  5292. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5293. /// <summary>
  5294. /// S2工位的数据- 回写点位
  5295. /// </summary>
  5296. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5297. /// <summary>
  5298. /// [S2] FCT(板测)
  5299. /// </summary>
  5300. /// <param name="plcNo">PLC编号</param>
  5301. //private void ReadStation_S2(int plcNo)
  5302. //{
  5303. // // [S1] Tray盘上料装备
  5304. // // [S2] FCT
  5305. // // [S3] 值板机
  5306. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5307. // // [S5] Tray盘下料装备
  5308. // /// 上位机心跳
  5309. // /// 获取设备报警数据与状态信息
  5310. // string stationCode = "[S2]";
  5311. // string stationName = "FCT";
  5312. // string stationNameStr = stationCode + stationName;
  5313. // #region 创建字典
  5314. // // 触发信号字典 赋值
  5315. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5316. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5317. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5318. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5319. // // PLC数据字典 赋值
  5320. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5321. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5322. // s2PLCData.Add("b1ProductSN_Check", 0);
  5323. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5324. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5325. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5326. // s2PLCData.Add("b1ProductSN_Bind", "");
  5327. // s2PLCData.Add("b1Part1SN_Bind", "");
  5328. // s2PLCData.Add("b1Part2SN_Bind", "");
  5329. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5330. // s2PLCData.Add("b1MES_FLAG", 0);
  5331. // s2PLCData.Add("b1ProductSN", 0);
  5332. // s2PLCData.Add("b1Part1Result", 0);
  5333. // s2PLCData.Add("b1Part2Result", 0);
  5334. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5335. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5336. // s2PLCData.Add("b1OEEProductSN", "");
  5337. // s2PLCData.Add("b1OEEType", 0);
  5338. // #endregion 创建字典
  5339. // while (IsRun)
  5340. // {
  5341. // try
  5342. // {
  5343. // if (!GlobalContext._IsCon_Funs2)
  5344. // {
  5345. // UpdatePLCMonitor(1, plcNo, 0);
  5346. // continue;
  5347. // }
  5348. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5349. // {
  5350. // Stopwatch stopwatch1 = new Stopwatch();
  5351. // Stopwatch stopwatch2 = new Stopwatch();
  5352. // stopwatch1.Start();
  5353. // stopwatch2.Start();
  5354. // #region 一次性读取所有数据
  5355. // // 一次性读取所有数据
  5356. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5357. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5358. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5359. // int[] datas = data1.Concat(data2).ToArray();
  5360. // datas = datas.Concat(data3).ToArray();
  5361. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5362. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5363. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5364. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5365. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5366. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5367. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5368. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5369. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5370. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5371. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5372. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5373. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5374. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5375. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5376. // s2PLCData["b1MES_FLAG"] = datas[169];
  5377. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5378. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5379. // s2PLCData["b1Part1Result"] = datas[190];
  5380. // s2PLCData["b1Part2Result"] = datas[191];
  5381. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5382. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5383. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5384. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5385. // s2PLCData["b1OEEType"] = datas[224];
  5386. // #endregion 一次性读取所有数据
  5387. // stopwatch2.Stop();
  5388. // #region 回写操作,写后清空flag
  5389. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5390. // #endregion 回写操作,写后清空flag
  5391. // #region 进站校验
  5392. // try
  5393. // {
  5394. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5395. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5396. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5397. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5398. // {
  5399. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5400. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5401. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5402. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5403. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5404. // }
  5405. // }
  5406. // catch (Exception ex)
  5407. // {
  5408. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5409. // string str = ex.StackTrace;
  5410. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5411. // }
  5412. // #endregion 进站校验
  5413. // #region 二穴载具解绑/绑定(产品换载具)
  5414. // try
  5415. // {
  5416. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5417. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5418. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5419. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5420. // {
  5421. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5422. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5423. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5424. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5425. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5426. // }
  5427. // }
  5428. // catch (Exception ex)
  5429. // {
  5430. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5431. // string str = ex.StackTrace;
  5432. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5433. // }
  5434. // #endregion 二穴载具解绑/绑定(产品换载具)
  5435. // #region FCT-出站接口
  5436. // try
  5437. // {
  5438. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5439. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5440. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5441. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5442. // {
  5443. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5444. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5445. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5446. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5447. // }
  5448. // }
  5449. // catch (Exception ex)
  5450. // {
  5451. // // MES_Flag 为6上位机报错
  5452. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5453. // string str = ex.StackTrace;
  5454. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5455. // }
  5456. // #endregion FCT-出站接口
  5457. // #region 节拍接口
  5458. // try
  5459. // {
  5460. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5461. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5462. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5463. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5464. // {
  5465. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5466. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5467. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5468. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5469. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5470. // }
  5471. // }
  5472. // catch (Exception ex)
  5473. // {
  5474. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5475. // string str = ex.StackTrace;
  5476. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5477. // }
  5478. // #endregion 节拍接口
  5479. // #region 心跳
  5480. // try
  5481. // {
  5482. // short states = 0;
  5483. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5484. // }
  5485. // catch (Exception ex)
  5486. // {
  5487. // string str = ex.StackTrace;
  5488. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5489. // }
  5490. // #endregion 心跳
  5491. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5492. // stopwatch1.Stop();
  5493. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5494. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5495. // }
  5496. // else
  5497. // {
  5498. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5499. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5500. // Funs[plcNo].Connect();
  5501. // }
  5502. // }
  5503. // catch (Exception ex)
  5504. // {
  5505. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5506. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5507. // Funs[plcNo].ReConnect();
  5508. // }
  5509. // Thread.Sleep(IntervalReadPLC);
  5510. // }
  5511. //}
  5512. /// <summary>
  5513. /// [S2] FCT(板测)- 进站校验
  5514. /// </summary>
  5515. /// <param name="plcNo">PLC编号</param>
  5516. /// <param name="stationNameStr">工站全称</param>
  5517. private void S2进站校验(int plcNo, string stationNameStr)
  5518. {
  5519. Stopwatch stopwatch1 = new Stopwatch();
  5520. Stopwatch stopwatch2 = new Stopwatch();
  5521. try
  5522. {
  5523. stopwatch1.Start();
  5524. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5525. sn = sn.Replace("\0", "");
  5526. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5527. // 查询物料码By载具码 并判断是不是假产品
  5528. string cavityData = string.Empty;
  5529. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5530. if (string.IsNullOrEmpty(cavityData))
  5531. cavityData = "";
  5532. if (snResult != 0)
  5533. {
  5534. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5535. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5536. writeToPLC_Flag1.Adress = 2003;
  5537. writeToPLC_Flag1.Value = (short)6;
  5538. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5539. stopwatch1.Stop();
  5540. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5541. return;
  5542. }
  5543. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5544. string[] cavitySNs = cavityData.Split('.');
  5545. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5546. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5547. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5548. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5549. if (cavitySNs != null && cavitySNs.Length >= 2)
  5550. {
  5551. b1Part1SN_Check = cavitySNs[0];
  5552. b1Part2SN_Check = cavitySNs[1];
  5553. b1Part1Result_Check = 2;
  5554. b1Part2Result_Check = 2;
  5555. }
  5556. if (b1Part1SN_Check == "假产品")
  5557. b1Part1Result_Check = 3;
  5558. if (b1Part2SN_Check == "假产品")
  5559. b1Part2Result_Check = 3;
  5560. // 调用MES进站
  5561. stopwatch2.Start();
  5562. // 调用MES进站 - 产品1
  5563. List<TestItem> item;
  5564. int result1 = b1Part1Result_Check;
  5565. if (result1 != 3)
  5566. {
  5567. item = new List<TestItem>();
  5568. item.Add(new TestItem()
  5569. {
  5570. Parameter_name = "载具码",
  5571. Parameter_value = sn,
  5572. });
  5573. item.Add(new TestItem()
  5574. {
  5575. Parameter_name = "载具穴号",
  5576. Parameter_value = "1",
  5577. });
  5578. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5579. }
  5580. // 调用MES进站 - 产品2
  5581. int result2 = b1Part2Result_Check;
  5582. if (result2 != 3)
  5583. {
  5584. item = new List<TestItem>();
  5585. item.Add(new TestItem()
  5586. {
  5587. Parameter_name = "载具码",
  5588. Parameter_value = sn,
  5589. });
  5590. item.Add(new TestItem()
  5591. {
  5592. Parameter_name = "载具穴号",
  5593. Parameter_value = "2",
  5594. });
  5595. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5596. }
  5597. stopwatch2.Stop();
  5598. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5599. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5600. int result = result1;
  5601. if (result == 1)
  5602. result = result2;
  5603. short b1MES_FLAG_Check = (short)result;
  5604. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5605. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5606. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5607. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5608. //// MES_Flag
  5609. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5610. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5611. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5612. writeToPLC_Flag.Adress = 2003;
  5613. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5614. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5615. {
  5616. Name = "b1Part1SN_Check",
  5617. Adress = 2024,
  5618. ValueType = PLCValueType.String,
  5619. ValueTypeStrLength = 20,
  5620. Value = b1Part1SN_Check
  5621. });
  5622. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5623. {
  5624. Name = "b1Part2SN_Check",
  5625. Adress = 2044,
  5626. ValueType = PLCValueType.String,
  5627. ValueTypeStrLength = 20,
  5628. Value = b1Part2SN_Check
  5629. });
  5630. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5631. {
  5632. Name = "b1Part1Result_Check",
  5633. Adress = 2064,
  5634. ValueType = PLCValueType.Short,
  5635. Value = b1Part1Result_Check
  5636. });
  5637. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5638. {
  5639. Name = "b1Part2Result_Check",
  5640. Adress = 2065,
  5641. ValueType = PLCValueType.Short,
  5642. Value = b1Part2Result_Check
  5643. });
  5644. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5645. }
  5646. catch (Exception ex)
  5647. {
  5648. string str = ex.StackTrace;
  5649. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5650. // MES_Flag
  5651. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5652. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5653. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5654. writeToPLC_Flag.Adress = 2003;
  5655. writeToPLC_Flag.Value = (short)6;
  5656. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5657. }
  5658. stopwatch1.Stop();
  5659. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5660. }
  5661. /// <summary>
  5662. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5663. /// </summary>
  5664. /// <param name="plcNo">PLC编号</param>
  5665. /// <param name="stationNameStr">工站全称</param>
  5666. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5667. {
  5668. Stopwatch stopwatch1 = new Stopwatch();
  5669. Stopwatch stopwatch2 = new Stopwatch();
  5670. try
  5671. {
  5672. stopwatch1.Start();
  5673. // 产品换载具
  5674. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5675. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5676. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5677. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5678. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5679. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5680. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5681. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5682. stopwatch2.Start();
  5683. #region 查询载具上的产品信息
  5684. //string cavityData = string.Empty;
  5685. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5686. //if (string.IsNullOrEmpty(cavityData))
  5687. // cavityData = "";
  5688. //if (snResult != 0)
  5689. //{
  5690. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5691. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5692. // writeToPLC_Flag.Adress = 2077;
  5693. // writeToPLC_Flag.Value = (short)6;
  5694. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5695. // stopwatch1.Stop();
  5696. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5697. // return;
  5698. //}
  5699. #endregion 查询载具上的产品信息
  5700. #region 解绑(边线MES系统)
  5701. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5702. if (snResult != 0)
  5703. {
  5704. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5705. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5706. writeToPLC_Flag1.Adress = 2077;
  5707. writeToPLC_Flag1.Value = (short)6;
  5708. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5709. stopwatch1.Stop();
  5710. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5711. return;
  5712. }
  5713. #endregion 解绑(边线MES系统)
  5714. #region 存储绑定数据到 边线MES系统中
  5715. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5716. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5717. if (snResult != 0)
  5718. {
  5719. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5720. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5721. writeToPLC_Flag1.Adress = 2077;
  5722. writeToPLC_Flag1.Value = (short)6;
  5723. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5724. stopwatch1.Stop();
  5725. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5726. return;
  5727. }
  5728. #endregion 存储绑定数据到 边线MES系统中
  5729. stopwatch2.Stop();
  5730. short b1MES_FLAG_Unbind = 1;
  5731. // MES_Flag
  5732. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5733. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5734. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5735. writeToPLC_Flag.Adress = 2077;
  5736. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5737. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5738. }
  5739. catch (Exception ex)
  5740. {
  5741. string str = ex.StackTrace;
  5742. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5743. // MES_Flag
  5744. stopwatch2.Start();
  5745. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5746. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5747. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5748. writeToPLC_Flag.Adress = 2077;
  5749. writeToPLC_Flag.Value = (short)6;
  5750. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5751. stopwatch2.Stop();
  5752. }
  5753. stopwatch1.Stop();
  5754. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5755. }
  5756. //// 上次采集到的SN
  5757. //private string sn_FCT = string.Empty;
  5758. /// <summary>
  5759. /// [S2] FCT(板测)- 出站数据
  5760. /// </summary>
  5761. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5762. {
  5763. Stopwatch stopwatch1 = new Stopwatch();
  5764. Stopwatch stopwatch2 = new Stopwatch();
  5765. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5766. string stationNameStr = stationCode + stationName;
  5767. string processItem = stationName; // 测试项目
  5768. try
  5769. {
  5770. stopwatch1.Start();
  5771. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5772. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5773. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5774. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5775. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5776. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5777. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5778. bool pass1 = b1Part1Result == 1;
  5779. bool pass2 = b1Part2Result == 1;
  5780. #region 根据 载具SN 查 物料SN
  5781. string cavityData = string.Empty;
  5782. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5783. if (string.IsNullOrEmpty(cavityData))
  5784. cavityData = "";
  5785. if (snResult != 0)
  5786. {
  5787. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5788. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5789. writeToPLC_Flag1.Adress = 2169;
  5790. writeToPLC_Flag1.Value = (short)4;
  5791. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5792. stopwatch1.Stop();
  5793. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5794. return;
  5795. }
  5796. #endregion 根据 载具SN 查 物料SN
  5797. string[] cavitySNs = cavityData.Split('.');
  5798. string b1ProductSN1 = string.Empty;
  5799. string b1ProductSN2 = string.Empty;
  5800. if (cavitySNs != null && cavitySNs.Length >= 2)
  5801. {
  5802. b1ProductSN1 = cavitySNs[0];
  5803. b1ProductSN2 = cavitySNs[1];
  5804. }
  5805. stopwatch2.Start();
  5806. // 产品1
  5807. int result1 = 0;
  5808. if (b1ProductSN1 == "假产品")
  5809. result1 = 1;
  5810. else
  5811. {
  5812. List<TestItem> items1 = new List<TestItem>();
  5813. items1.Add(new TestItem()
  5814. {
  5815. Parameter_name = "载具码",
  5816. Parameter_value = b1ProductSN.ToString(),
  5817. Parameter_unit = ""
  5818. });
  5819. items1.Add(new TestItem()
  5820. {
  5821. Parameter_name = "载具穴号",
  5822. Parameter_value = "1",
  5823. Parameter_unit = ""
  5824. });
  5825. items1.Add(new TestItem()
  5826. {
  5827. Parameter_name = "产品结果",
  5828. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5829. Parameter_unit = ""
  5830. });
  5831. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  5832. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5833. }
  5834. // 产品2
  5835. int result2 = 0;
  5836. if (b1ProductSN1 == "假产品")
  5837. result2 = 1;
  5838. else
  5839. {
  5840. List<TestItem> items2 = new List<TestItem>();
  5841. items2.Add(new TestItem()
  5842. {
  5843. Parameter_name = "载具码",
  5844. Parameter_value = b1ProductSN.ToString(),
  5845. Parameter_unit = ""
  5846. });
  5847. items2.Add(new TestItem()
  5848. {
  5849. Parameter_name = "载具穴号",
  5850. Parameter_value = "2",
  5851. Parameter_unit = ""
  5852. });
  5853. items2.Add(new TestItem()
  5854. {
  5855. Parameter_name = "产品结果",
  5856. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5857. Parameter_unit = ""
  5858. });
  5859. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  5860. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5861. }
  5862. short result = 0;
  5863. List<int> results = new List<int>() { result1, result2 };
  5864. if (result1 == 1 && result2 == 1)
  5865. result = 1;
  5866. else if (results.Contains(3))
  5867. result = 3;
  5868. else if (results.Contains(2))
  5869. result = 2;
  5870. else if (results.Contains(4))
  5871. result = 4;
  5872. else
  5873. result = 4;
  5874. stopwatch2.Stop();
  5875. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5876. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5877. writeToPLC_Flag.Name = "b1MES_FLAG";
  5878. writeToPLC_Flag.Adress = 2169;
  5879. writeToPLC_Flag.Value = result;
  5880. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5881. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5882. }
  5883. catch (Exception ex)
  5884. {
  5885. stopwatch2.Restart();
  5886. // MES_Flag 为4上位机报错
  5887. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5888. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5889. writeToPLC_Flag.Name = "b1MES_FLAG";
  5890. writeToPLC_Flag.Adress = 2169;
  5891. writeToPLC_Flag.Value = (short)4;
  5892. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5893. stopwatch2.Stop();
  5894. string str = ex.StackTrace;
  5895. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5896. }
  5897. stopwatch1.Stop();
  5898. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5899. }
  5900. /// <summary>
  5901. /// [S2] FCT(板测)- 节拍接口
  5902. /// </summary>
  5903. /// <param name="plcNo">PLC编号</param>
  5904. /// <param name="stationNameStr">工站全称</param>
  5905. private void S2节拍接口(int plcNo, string stationNameStr)
  5906. {
  5907. Stopwatch stopwatch1 = new Stopwatch();
  5908. Stopwatch stopwatch2 = new Stopwatch();
  5909. string resultStr = string.Empty;
  5910. try
  5911. {
  5912. stopwatch1.Start();
  5913. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5914. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5915. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5916. if (!actionBool)
  5917. {
  5918. stopwatch2.Start();
  5919. // MES_Flag
  5920. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5921. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5922. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5923. writeToPLC_Flag1.Adress = 2203;
  5924. writeToPLC_Flag1.Value = (short)4;
  5925. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5926. stopwatch2.Stop();
  5927. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5928. return;
  5929. }
  5930. string b1OEEPartNo = string.Empty; // 物料码
  5931. if (string.IsNullOrEmpty(b1OEEProductSN))
  5932. {
  5933. stopwatch2.Start();
  5934. // MES_Flag
  5935. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5936. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5937. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5938. writeToPLC_Flag1.Adress = 2203;
  5939. writeToPLC_Flag1.Value = (short)1;
  5940. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5941. stopwatch2.Stop();
  5942. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5943. return;
  5944. }
  5945. else
  5946. { // 查产品SN
  5947. b1OEEPartNo = "Test"; // ZS
  5948. }
  5949. short b1OEEMES_FLAG = 0;
  5950. // 上传OEE
  5951. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5952. b1OEEMES_FLAG = result.Item1;
  5953. resultStr = result.Item2;
  5954. stopwatch2.Start();
  5955. // MES_Flag
  5956. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5957. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5958. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5959. writeToPLC_Flag.Adress = 2203;
  5960. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5961. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5962. stopwatch2.Stop();
  5963. }
  5964. catch (Exception ex)
  5965. {
  5966. string str = ex.StackTrace;
  5967. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5968. // MES_Flag
  5969. stopwatch2.Start();
  5970. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5971. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5972. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5973. writeToPLC_Flag.Adress = 2203;
  5974. writeToPLC_Flag.Value = (short)4;
  5975. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5976. stopwatch2.Stop();
  5977. }
  5978. stopwatch1.Stop();
  5979. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5980. }
  5981. #endregion [S2] FCT(板测)
  5982. #endregion PLC2 李晓奇
  5983. #region PLC3 刘永村
  5984. #region [S3] 值板机
  5985. /// <summary>
  5986. /// S3工位的数据- 触发信号上次的值
  5987. /// </summary>
  5988. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5989. /// <summary>
  5990. /// S3工位的数据(含触发信号)
  5991. /// </summary>
  5992. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5993. /// <summary>
  5994. /// S3工位的数据- 回写点位
  5995. /// </summary>
  5996. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5997. /// <summary>
  5998. /// [S3] 值板机
  5999. /// </summary>
  6000. /// <param name="plcNo">PLC编号</param>
  6001. //private void ReadStation_S3(int plcNo)
  6002. //{
  6003. // // [S1] Tray盘上料装备
  6004. // // [S2] FCT
  6005. // // [S3] 值板机
  6006. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6007. // // [S5] Tray盘下料装备
  6008. // /// 上位机心跳
  6009. // /// 获取设备报警数据与状态信息
  6010. // string stationCode = "[S3]";
  6011. // string stationName = "值板机";
  6012. // string stationNameStr = stationCode + stationName;
  6013. // #region 创建字典
  6014. // // 触发信号字典 赋值
  6015. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  6016. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  6017. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  6018. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6019. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6020. // // PLC数据字典 赋值
  6021. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  6022. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  6023. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  6024. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  6025. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  6026. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  6027. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6028. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  6029. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  6030. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  6031. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  6032. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  6033. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6034. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6035. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  6036. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  6037. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  6038. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6039. // s3PLCData.Add("c1Result", 0); // 产品结果
  6040. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6041. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  6042. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  6043. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  6044. // #endregion 创建字典
  6045. // while (IsRun)
  6046. // {
  6047. // try
  6048. // {
  6049. // if (!GlobalContext._IsCon_Funs3)
  6050. // {
  6051. // UpdatePLCMonitor(1, plcNo, 0);
  6052. // continue;
  6053. // }
  6054. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6055. // {
  6056. // Stopwatch stopwatch1 = new Stopwatch();
  6057. // Stopwatch stopwatch2 = new Stopwatch();
  6058. // stopwatch1.Start();
  6059. // stopwatch2.Start();
  6060. // #region 一次性读取所有数据
  6061. // // 一次性读取所有数据
  6062. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  6063. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6064. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6065. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  6066. // int[] datas = data1.Concat(data2).ToArray();
  6067. // datas = datas.Concat(data3).ToArray();
  6068. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  6069. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  6070. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  6071. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  6072. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  6073. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  6074. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6075. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  6076. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  6077. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  6078. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6079. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6080. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  6081. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  6082. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  6083. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  6084. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6085. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  6086. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  6087. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  6088. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  6089. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  6090. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  6091. // #endregion 一次性读取所有数据
  6092. // stopwatch2.Stop();
  6093. // #region 回写操作,写后清空flag
  6094. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  6095. // #endregion 回写操作,写后清空flag
  6096. // #region S3进站校验
  6097. // try
  6098. // {
  6099. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  6100. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  6101. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  6102. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  6103. // {
  6104. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  6105. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6106. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  6107. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6108. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  6109. // }
  6110. // }
  6111. // catch (Exception ex)
  6112. // {
  6113. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6114. // string str = ex.StackTrace;
  6115. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6116. // }
  6117. // #endregion S3进站校验
  6118. // #region S3二穴载具解绑
  6119. // try
  6120. // {
  6121. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  6122. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  6123. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  6124. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  6125. // {
  6126. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6127. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  6128. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  6129. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  6130. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  6131. // }
  6132. // }
  6133. // catch (Exception ex)
  6134. // {
  6135. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  6136. // string str = ex.StackTrace;
  6137. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6138. // }
  6139. // #endregion S3二穴载具解绑
  6140. // #region S3二穴载具绑定
  6141. // try
  6142. // {
  6143. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  6144. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  6145. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  6146. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  6147. // {
  6148. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  6149. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  6150. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  6151. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  6152. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  6153. // }
  6154. // }
  6155. // catch (Exception ex)
  6156. // {
  6157. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6158. // string str = ex.StackTrace;
  6159. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6160. // }
  6161. // #endregion S3二穴载具绑定
  6162. // #region S3出站接口(+一穴载具绑定)
  6163. // try
  6164. // {
  6165. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  6166. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  6167. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  6168. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  6169. // {
  6170. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  6171. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6172. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  6173. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  6174. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  6175. // }
  6176. // }
  6177. // catch (Exception ex)
  6178. // {
  6179. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  6180. // string str = ex.StackTrace;
  6181. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6182. // }
  6183. // #endregion S3出站接口(+一穴载具绑定)
  6184. // #region S3节拍接口
  6185. // try
  6186. // {
  6187. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  6188. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  6189. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  6190. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  6191. // {
  6192. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  6193. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6194. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  6195. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  6196. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  6197. // }
  6198. // }
  6199. // catch (Exception ex)
  6200. // {
  6201. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6202. // string str = ex.StackTrace;
  6203. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6204. // }
  6205. // #endregion S3节拍接口
  6206. // #region 心跳
  6207. // try
  6208. // {
  6209. // short states = 0;
  6210. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6211. // }
  6212. // catch (Exception ex)
  6213. // {
  6214. // string str = ex.StackTrace;
  6215. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6216. // }
  6217. // #endregion 心跳
  6218. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6219. // stopwatch1.Stop();
  6220. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6221. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6222. // }
  6223. // else
  6224. // {
  6225. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6226. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6227. // Funs[plcNo].Connect();
  6228. // }
  6229. // }
  6230. // catch (Exception ex)
  6231. // {
  6232. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6233. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6234. // Funs[plcNo].ReConnect();
  6235. // }
  6236. // Thread.Sleep(IntervalReadPLC);
  6237. // }
  6238. //}
  6239. /// <summary>
  6240. /// [S3] 值板机- 进站校验
  6241. /// </summary>
  6242. /// <param name="plcNo">PLC编号</param>
  6243. /// <param name="stationNameStr">工站全称</param>
  6244. private void S3进站校验(int plcNo, string stationNameStr)
  6245. {
  6246. Stopwatch stopwatch1 = new Stopwatch();
  6247. Stopwatch stopwatch2 = new Stopwatch();
  6248. try
  6249. {
  6250. stopwatch1.Start();
  6251. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6252. sn = sn.Replace("\0", "");
  6253. #region 查询载具上的产品信息
  6254. string cavityData = string.Empty;
  6255. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6256. if (string.IsNullOrEmpty(cavityData))
  6257. cavityData = "";
  6258. if (snResult != 0)
  6259. {
  6260. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6261. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6262. writeToPLC_Flag1.Adress = 2003;
  6263. writeToPLC_Flag1.Value = (short)6;
  6264. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6265. stopwatch1.Stop();
  6266. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6267. return;
  6268. }
  6269. #endregion 查询载具上的产品信息
  6270. string[] cavitySNs = cavityData.Split('.');
  6271. string part1Str = ""; // 产品1的SN码
  6272. string part2Str = ""; // 产品2的SN码
  6273. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6274. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6275. if (cavitySNs != null && cavitySNs.Length >= 2)
  6276. {
  6277. part1Str = cavitySNs[0];
  6278. part2Str = cavitySNs[1];
  6279. c1Part1Result_Check = 2;
  6280. c1Part2Result_Check = 2;
  6281. }
  6282. if (part1Str == "假产品")
  6283. c1Part1Result_Check = 3;
  6284. if (part2Str == "假产品")
  6285. c1Part2Result_Check = 3;
  6286. // 调用MES进站
  6287. stopwatch2.Start();
  6288. // 调用MES进站 - 产品1
  6289. List<TestItem> item;
  6290. int result1 = c1Part1Result_Check;
  6291. if (result1 != 3)
  6292. {
  6293. item = new List<TestItem>();
  6294. item.Add(new TestItem()
  6295. {
  6296. Parameter_name = "载具码",
  6297. Parameter_value = sn,
  6298. });
  6299. item.Add(new TestItem()
  6300. {
  6301. Parameter_name = "载具穴号",
  6302. Parameter_value = "1",
  6303. });
  6304. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6305. }
  6306. // 调用MES进站 - 产品2
  6307. int result2 = c1Part2Result_Check;
  6308. if (result2 != 3)
  6309. {
  6310. item = new List<TestItem>();
  6311. item.Add(new TestItem()
  6312. {
  6313. Parameter_name = "载具码",
  6314. Parameter_value = sn,
  6315. });
  6316. item.Add(new TestItem()
  6317. {
  6318. Parameter_name = "载具穴号",
  6319. Parameter_value = "2",
  6320. });
  6321. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6322. }
  6323. stopwatch2.Stop();
  6324. if (result1 == 2)
  6325. c1Part1Result_Check = 2;
  6326. if (result2 == 2)
  6327. c1Part2Result_Check = 2;
  6328. int result = result1;
  6329. if (result == 1)
  6330. result = result2;
  6331. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6332. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6333. short c1MES_FLAG_Check = (short)result;
  6334. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6335. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6336. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6337. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6338. //// MES_Flag
  6339. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6340. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6341. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6342. writeToPLC_Flag.Adress = 2003;
  6343. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6344. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6345. {
  6346. Name = "c1Part1Result_Check",
  6347. Adress = 2024,
  6348. ValueType = PLCValueType.Short,
  6349. Value = c1Part1Result_Check
  6350. });
  6351. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6352. {
  6353. Name = "c1Part2Result_Check",
  6354. Adress = 2025,
  6355. ValueType = PLCValueType.Short,
  6356. Value = c1Part2Result_Check
  6357. });
  6358. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6359. {
  6360. Name = "c1Part1Num_Check",
  6361. Adress = 2026,
  6362. ValueType = PLCValueType.Short,
  6363. Value = c1Part1Num_Check
  6364. });
  6365. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6366. {
  6367. Name = "c1Part2Num_Check",
  6368. Adress = 2027,
  6369. ValueType = PLCValueType.Short,
  6370. Value = c1Part2Num_Check
  6371. });
  6372. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6373. }
  6374. catch (Exception ex)
  6375. {
  6376. string str = ex.StackTrace;
  6377. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6378. // MES_Flag
  6379. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6380. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6381. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6382. writeToPLC_Flag.Adress = 2003;
  6383. writeToPLC_Flag.Value = (short)6;
  6384. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6385. }
  6386. stopwatch1.Stop();
  6387. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6388. }
  6389. /// <summary>
  6390. /// [S3] 值板机 - 二穴载具解绑
  6391. /// </summary>
  6392. /// <param name="plcNo">PLC编号</param>
  6393. /// <param name="stationNameStr">工站全称</param>
  6394. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6395. {
  6396. Stopwatch stopwatch1 = new Stopwatch();
  6397. Stopwatch stopwatch2 = new Stopwatch();
  6398. try
  6399. {
  6400. stopwatch1.Start();
  6401. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6402. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6403. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6404. // 解绑
  6405. #region 查询载具上的产品信息
  6406. string cavityData = string.Empty;
  6407. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6408. if (string.IsNullOrEmpty(cavityData))
  6409. cavityData = "";
  6410. if (snResult != 0)
  6411. {
  6412. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6413. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6414. writeToPLC_Flag1.Adress = 2082;
  6415. writeToPLC_Flag1.Value = (short)6;
  6416. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6417. stopwatch1.Stop();
  6418. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6419. return;
  6420. }
  6421. #endregion 查询载具上的产品信息
  6422. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6423. #region 解绑
  6424. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6425. {
  6426. // 删除
  6427. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6428. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6429. }
  6430. else
  6431. {
  6432. string data_new = string.Join(".", cavitySNs);
  6433. // 删除再插入
  6434. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6435. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6436. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6437. }
  6438. #endregion 解绑
  6439. short c1MES_FLAG_Unbind = 1;
  6440. stopwatch2.Start();
  6441. // MES_Flag
  6442. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6443. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6444. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6445. writeToPLC_Flag.Adress = 2082;
  6446. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6447. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6448. stopwatch2.Stop();
  6449. }
  6450. catch (Exception ex)
  6451. {
  6452. string str = ex.StackTrace;
  6453. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6454. // MES_Flag
  6455. stopwatch2.Start();
  6456. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6457. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6458. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6459. writeToPLC_Flag.Adress = 2082;
  6460. writeToPLC_Flag.Value = (short)6;
  6461. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6462. stopwatch2.Stop();
  6463. }
  6464. stopwatch1.Stop();
  6465. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6466. }
  6467. /// <summary>
  6468. /// [S3] 值板机 - 二穴载具绑定
  6469. /// </summary>
  6470. /// <param name="plcNo">PLC编号</param>
  6471. /// <param name="stationNameStr">工站全称</param>
  6472. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6473. {
  6474. Stopwatch stopwatch1 = new Stopwatch();
  6475. Stopwatch stopwatch2 = new Stopwatch();
  6476. try
  6477. {
  6478. stopwatch1.Start();
  6479. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6480. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6481. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6482. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6483. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6484. stopwatch2.Start();
  6485. #region 查询载具上的产品信息
  6486. string cavityData = string.Empty;
  6487. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6488. if (string.IsNullOrEmpty(cavityData))
  6489. cavityData = "";
  6490. if (snResult != 0)
  6491. {
  6492. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6493. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6494. writeToPLC_Flag1.Adress = 2115;
  6495. writeToPLC_Flag1.Value = (short)6;
  6496. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6497. stopwatch1.Stop();
  6498. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6499. return;
  6500. }
  6501. #endregion 查询载具上的产品信息
  6502. // 产品换载具
  6503. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6504. string partSn1 = "";
  6505. string partSn2 = "";
  6506. if (cavitySNs != null && cavitySNs.Length >= 2)
  6507. {
  6508. partSn1 = cavitySNs[0];
  6509. partSn2 = cavitySNs[1];
  6510. }
  6511. string data_new = string.Empty;
  6512. // 是否是两个穴位交换
  6513. if (c1CavityReverse_Bind == 1)
  6514. {
  6515. // 交换
  6516. data_new = string.Concat(partSn2, ".", partSn1);
  6517. }
  6518. else
  6519. { // 不交换
  6520. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6521. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6522. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6523. data_new = string.Join(".", cavitySNs);
  6524. }
  6525. // 删除再插入
  6526. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6527. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6528. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6529. stopwatch2.Stop();
  6530. short c1MES_FLAG_Bind = 1;
  6531. // MES_Flag
  6532. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6533. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6534. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6535. writeToPLC_Flag.Adress = 2115;
  6536. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6537. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6538. }
  6539. catch (Exception ex)
  6540. {
  6541. string str = ex.StackTrace;
  6542. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6543. // MES_Flag
  6544. stopwatch2.Start();
  6545. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6546. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6547. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6548. writeToPLC_Flag.Adress = 2115;
  6549. writeToPLC_Flag.Value = (short)6;
  6550. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6551. stopwatch2.Stop();
  6552. }
  6553. stopwatch1.Stop();
  6554. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6555. }
  6556. //// 上次采集到的SN
  6557. //private string sn_值板机 = string.Empty;
  6558. /// <summary>
  6559. /// [S3] 值板机 - 出站接口
  6560. /// </summary>
  6561. /// <param name="plcNo">PLC编号</param>
  6562. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6563. {
  6564. Stopwatch stopwatch1 = new Stopwatch();
  6565. Stopwatch stopwatch2 = new Stopwatch();
  6566. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6567. string stationNameStr = stationCode + stationName;
  6568. string processItem = stationName; // 测试项目
  6569. try
  6570. {
  6571. stopwatch1.Start();
  6572. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6573. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6574. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6575. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6576. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6577. sn = sn.Replace("\0", "");
  6578. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6579. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6580. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6581. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6582. bool pass = c1Result == 1;
  6583. // 查sn
  6584. #region 查询载具上的产品信息
  6585. string cavityData = string.Empty;
  6586. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6587. if (string.IsNullOrEmpty(cavityData))
  6588. cavityData = "";
  6589. if (snResult != 0)
  6590. {
  6591. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6592. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6593. writeToPLC_Flag1.Adress = 2150;
  6594. writeToPLC_Flag1.Value = (short)4;
  6595. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6596. stopwatch1.Stop();
  6597. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6598. return;
  6599. }
  6600. #endregion 查询载具上的产品信息
  6601. string[] cavitySNs = cavityData.Split('.');
  6602. string productSN = "";
  6603. if (cavitySNs != null && cavitySNs.Length >= 2)
  6604. {
  6605. productSN = cavitySNs[c1VehicleCavity];
  6606. cavitySNs[c1VehicleCavity] = "";
  6607. }
  6608. stopwatch2.Start();
  6609. List<TestItem> items = new List<TestItem>();
  6610. items.Add(new TestItem()
  6611. {
  6612. Parameter_name = "二穴载具码",
  6613. Parameter_value = c1ProductSN_Check,
  6614. Parameter_unit = ""
  6615. });
  6616. items.Add(new TestItem()
  6617. {
  6618. Parameter_name = "二穴载具穴号",
  6619. Parameter_value = c1VehicleCavity.ToString(),
  6620. Parameter_unit = ""
  6621. });
  6622. items.Add(new TestItem()
  6623. {
  6624. Parameter_name = "一穴载具码",
  6625. Parameter_value = sn,
  6626. Parameter_unit = ""
  6627. });
  6628. items.Add(new TestItem()
  6629. {
  6630. Parameter_name = "一穴载具穴号",
  6631. Parameter_value = "1",
  6632. Parameter_unit = ""
  6633. });
  6634. items.Add(new TestItem()
  6635. {
  6636. Parameter_name = "产品结果",
  6637. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6638. Parameter_unit = ""
  6639. });
  6640. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  6641. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6642. short result = (short)result1;
  6643. stopwatch2.Stop();
  6644. #region 存储绑定数据到 边线MES系统中
  6645. if (result == 1)
  6646. {
  6647. string data = string.Concat(productSN);
  6648. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6649. if (resultMesR != 0)
  6650. {
  6651. result = 4;
  6652. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6653. }
  6654. }
  6655. #endregion 存储绑定数据到 边线MES系统中
  6656. #region 产品从 来源载具(二穴载具)中删除
  6657. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6658. {
  6659. // 删除
  6660. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6661. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6662. }
  6663. else
  6664. {
  6665. string data_new = string.Join(".", cavitySNs);
  6666. // 删除再插入
  6667. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6668. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6669. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6670. }
  6671. #endregion 产品从 来源载具(二穴载具)中删除
  6672. // MES_Flag 为MES报错
  6673. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6674. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6675. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6676. writeToPLC_Flag.Name = "c1MES_FLAG";
  6677. writeToPLC_Flag.Adress = 2150;
  6678. writeToPLC_Flag.Value = result;
  6679. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6680. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6681. }
  6682. catch (Exception ex)
  6683. {
  6684. stopwatch2.Restart();
  6685. // MES_Flag 为4上位机报错
  6686. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6687. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6688. writeToPLC_Flag.Name = "c1MES_FLAG";
  6689. writeToPLC_Flag.Adress = 2150;
  6690. writeToPLC_Flag.Value = (short)4;
  6691. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6692. stopwatch2.Stop();
  6693. string str = ex.StackTrace;
  6694. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6695. }
  6696. stopwatch1.Stop();
  6697. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6698. }
  6699. /// <summary>
  6700. /// [S3] 值板机- 节拍接口
  6701. /// </summary>
  6702. /// <param name="plcNo">PLC编号</param>
  6703. /// <param name="stationNameStr">工站全称</param>
  6704. private void S3节拍接口(int plcNo, string stationNameStr)
  6705. {
  6706. Stopwatch stopwatch1 = new Stopwatch();
  6707. Stopwatch stopwatch2 = new Stopwatch();
  6708. string resultStr = string.Empty;
  6709. try
  6710. {
  6711. stopwatch1.Start();
  6712. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6713. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6714. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6715. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6716. if (!actionBool)
  6717. {
  6718. stopwatch2.Start();
  6719. // MES_Flag
  6720. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6721. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6722. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6723. writeToPLC_Flag1.Adress = 2204;
  6724. writeToPLC_Flag1.Value = (short)4;
  6725. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6726. stopwatch2.Stop();
  6727. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6728. return;
  6729. }
  6730. string c1OEEPartNo = string.Empty; // 物料码
  6731. if (string.IsNullOrEmpty(c1OEEProductSN))
  6732. {
  6733. stopwatch2.Start();
  6734. // MES_Flag
  6735. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6736. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6737. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6738. writeToPLC_Flag1.Adress = 2204;
  6739. writeToPLC_Flag1.Value = (short)1;
  6740. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6741. stopwatch2.Stop();
  6742. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6743. return;
  6744. }
  6745. else
  6746. { // 查产品SN
  6747. c1OEEPartNo = "Test"; // ZS
  6748. }
  6749. short c1OEEMES_FLAG = 0;
  6750. // 上传OEE
  6751. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6752. c1OEEMES_FLAG = result.Item1;
  6753. resultStr = result.Item2;
  6754. stopwatch2.Start();
  6755. // MES_Flag
  6756. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6757. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6758. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6759. writeToPLC_Flag.Adress = 2204;
  6760. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6761. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6762. stopwatch2.Stop();
  6763. }
  6764. catch (Exception ex)
  6765. {
  6766. string str = ex.StackTrace;
  6767. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6768. // MES_Flag
  6769. stopwatch2.Start();
  6770. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6771. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6772. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6773. writeToPLC_Flag.Adress = 2204;
  6774. writeToPLC_Flag.Value = (short)4;
  6775. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6776. stopwatch2.Stop();
  6777. }
  6778. stopwatch1.Stop();
  6779. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6780. }
  6781. #endregion [S3] 值板机
  6782. #endregion PLC3 刘永村
  6783. #region PLC4 刘果段
  6784. #region [S4] 取放桁架
  6785. /// <summary>
  6786. /// S4工位的数据- 触发信号上次的值
  6787. /// </summary>
  6788. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6789. /// <summary>
  6790. /// S4工位的数据(含触发信号)
  6791. /// </summary>
  6792. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6793. /// <summary>
  6794. /// S4工位的数据- 回写点位
  6795. /// </summary>
  6796. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6797. /// <summary>
  6798. /// [S4] 取放桁架
  6799. /// </summary>
  6800. /// <param name="plcNo">PLC编号</param>
  6801. //private void ReadStation_S4(int plcNo)
  6802. //{
  6803. // // [S1] Tray盘上料装备
  6804. // // [S2] FCT
  6805. // // [S3] 值板机
  6806. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6807. // // [S5] Tray盘下料装备
  6808. // /// 上位机心跳
  6809. // /// 获取设备报警数据与状态信息
  6810. // string stationCode = "[S4_1]";
  6811. // string stationName = "载具下线装备";
  6812. // string stationNameStr = stationCode + stationName;
  6813. // string stationCode2 = "[S4_2]";
  6814. // string stationName2 = "桁架";
  6815. // string stationNameStr2 = stationCode2 + stationName2;
  6816. // string stationCode3 = "[S4_3]";
  6817. // string stationName3 = "提升机1";
  6818. // string stationNameStr3 = stationCode3 + stationName3;
  6819. // string stationCode4 = "[S4_4]";
  6820. // string stationName4 = "提升机2";
  6821. // string stationNameStr4 = stationCode4 + stationName4;
  6822. // string stationCode5 = "[S4_5]";
  6823. // string stationName5 = "载具上线装备";
  6824. // string stationNameStr5 = stationCode5 + stationName5;
  6825. // #region 创建字典
  6826. // // 触发信号字典 赋值
  6827. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6828. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6829. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6830. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6831. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6832. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6833. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6834. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6835. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6836. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6837. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6838. // // PLC数据字典 赋值
  6839. // // 载具下线装备(弹夹上线)
  6840. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6841. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6842. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6843. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6844. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6845. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6846. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6847. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6848. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6849. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6850. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6851. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6852. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6853. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6854. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6855. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6856. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6857. // s4PLCData.Add("d1Result", 0); // 产品结果
  6858. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6859. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6860. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6861. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6862. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6863. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6864. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6865. // // 真空标机(提升机)
  6866. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6867. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6868. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6869. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6870. // s4PLCData.Add("d3Result", 0); // 产品结果
  6871. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6872. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6873. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6874. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6875. // s4PLCData.Add("d4Result", 0); // 产品结果
  6876. // // 载具上线装备(弹夹下线)
  6877. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6878. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6879. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6880. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6881. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6882. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6883. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6884. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6885. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6886. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6887. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6888. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6889. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6890. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6891. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6892. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6893. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6894. // s4PLCData.Add("d5Result", 0); // 产品结果
  6895. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6896. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6897. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6898. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6899. // #endregion 创建字典
  6900. // while (IsRun)
  6901. // {
  6902. // try
  6903. // {
  6904. // if (!GlobalContext._IsCon_Funs4)
  6905. // {
  6906. // UpdatePLCMonitor(1, plcNo, 0);
  6907. // continue;
  6908. // }
  6909. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6910. // {
  6911. // Stopwatch stopwatch1 = new Stopwatch();
  6912. // Stopwatch stopwatch2 = new Stopwatch();
  6913. // stopwatch1.Start();
  6914. // stopwatch2.Start();
  6915. // #region 一次性读取所有数据
  6916. // // 载具下线装备(弹夹上线)
  6917. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6918. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6919. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6920. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6921. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6922. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6923. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6924. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6925. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6926. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6927. // int[] datas = data1.Concat(data2).ToArray();
  6928. // datas = datas.Concat(data3).ToArray();
  6929. // datas = datas.Concat(data4).ToArray();
  6930. // datas = datas.Concat(data5).ToArray();
  6931. // datas = datas.Concat(data6).ToArray();
  6932. // datas = datas.Concat(data7).ToArray();
  6933. // datas = datas.Concat(data8).ToArray();
  6934. // datas = datas.Concat(data9).ToArray();
  6935. // datas = datas.Concat(data10).ToArray();
  6936. // // 载具下线装备(弹夹上线)
  6937. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6938. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6939. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6940. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6941. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6942. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6943. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6944. // s4PLCData["d1MES_FLAG"] = datas[65];
  6945. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6946. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6947. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6948. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6949. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6950. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6951. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6952. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6953. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6954. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6955. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6956. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6957. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6958. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6959. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6960. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6961. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6962. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6963. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6964. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6965. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6966. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6967. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6968. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6969. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6970. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6971. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6972. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6973. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6974. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6975. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6976. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6977. // s4PLCData["d1Result"] = datas[386];
  6978. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6979. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6980. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6981. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6982. // s4PLCData["d1OEEType"] = datas[419];
  6983. // // 桁架(查询标机中弹夹的状态)
  6984. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6985. // s4PLCData["d2BulletclipStates"] = datas[431];
  6986. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6987. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6988. // // 真空标机
  6989. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6990. // s4PLCData["d3MES_FLAG"] = datas[463];
  6991. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6992. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6993. // s4PLCData["d3Result"] = datas[484];
  6994. // s4PLCData["d3Type"] = datas[485];
  6995. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6996. // s4PLCData["d4MES_FLAG"] = datas[496];
  6997. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6998. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6999. // s4PLCData["d4Result"] = datas[517];
  7000. // s4PLCData["d4Type"] = datas[518];
  7001. // // 载具上线装备(弹夹下线)
  7002. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  7003. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  7004. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  7005. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  7006. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  7007. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  7008. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  7009. // s4PLCData["d5MES_FLAG"] = datas[591];
  7010. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  7011. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  7012. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  7013. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  7014. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  7015. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  7016. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  7017. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  7018. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  7019. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  7020. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  7021. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  7022. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  7023. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  7024. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  7025. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  7026. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  7027. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  7028. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  7029. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  7030. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  7031. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  7032. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  7033. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  7034. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  7035. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  7036. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  7037. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  7038. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  7039. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  7040. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  7041. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  7042. // s4PLCData["d5Result"] = datas[912];
  7043. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  7044. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  7045. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  7046. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  7047. // s4PLCData["d5OEEType"] = datas[945];
  7048. // #endregion 一次性读取所有数据
  7049. // stopwatch2.Stop();
  7050. // #region 回写操作,写后清空flag
  7051. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  7052. // #endregion 回写操作,写后清空flag
  7053. // // N801A-S4_1 弹夹扫码
  7054. // #region N801A-S4_1 弹夹扫码
  7055. // try
  7056. // {
  7057. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  7058. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  7059. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  7060. // {
  7061. // if (d1BulletclipScanCode == 1) // 0->1
  7062. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  7063. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  7064. // }
  7065. // }
  7066. // catch (Exception ex)
  7067. // {
  7068. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7069. // string str = ex.StackTrace;
  7070. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7071. // }
  7072. // #endregion N801A-S4_1 弹夹扫码
  7073. // // N801A-S4_1 载具扫码
  7074. // #region N801A-S4_1 载具扫码
  7075. // try
  7076. // {
  7077. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  7078. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  7079. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  7080. // {
  7081. // if (d1VehicleScanCode == 1) // 0->1
  7082. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  7083. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  7084. // }
  7085. // }
  7086. // catch (Exception ex)
  7087. // {
  7088. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7089. // string str = ex.StackTrace;
  7090. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7091. // }
  7092. // #endregion N801A-S4_1 载具扫码
  7093. // // N801A-S4_1 出站接口
  7094. // #region N801A-S4_1 出站接口
  7095. // try
  7096. // {
  7097. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  7098. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  7099. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  7100. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  7101. // {
  7102. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  7103. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7104. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  7105. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  7106. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  7107. // }
  7108. // }
  7109. // catch (Exception ex)
  7110. // {
  7111. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  7112. // string str = ex.StackTrace;
  7113. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7114. // }
  7115. // #endregion N801A-S4_1 出站接口
  7116. // // N801A-S4_1 节拍接口
  7117. // #region N801A-S4_1 节拍接口
  7118. // try
  7119. // {
  7120. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  7121. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  7122. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  7123. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  7124. // {
  7125. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  7126. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7127. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  7128. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  7129. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  7130. // }
  7131. // }
  7132. // catch (Exception ex)
  7133. // {
  7134. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7135. // string str = ex.StackTrace;
  7136. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7137. // }
  7138. // #endregion N801A-S4_1 节拍接口
  7139. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  7140. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  7141. // try
  7142. // {
  7143. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  7144. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  7145. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  7146. // {
  7147. // if (d2BulletclipScanCode == 1) // 0->1
  7148. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  7149. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  7150. // }
  7151. // }
  7152. // catch (Exception ex)
  7153. // {
  7154. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7155. // string str = ex.StackTrace;
  7156. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7157. // }
  7158. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  7159. // // N801A-S4_3 真空标机1 数据
  7160. // #region N801A-S4_3 真空标机1
  7161. // try
  7162. // {
  7163. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  7164. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  7165. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  7166. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  7167. // {
  7168. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  7169. // {
  7170. // int stationType = (int)s4PLCData["d3Type"];
  7171. // if (stationType == 1)
  7172. // {
  7173. // // S4_3进站接口
  7174. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  7175. // }
  7176. // else if (stationType == 2)
  7177. // {
  7178. // // S4_3出站接口
  7179. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  7180. // }
  7181. // }
  7182. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  7183. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  7184. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  7185. // }
  7186. // }
  7187. // catch (Exception ex)
  7188. // {
  7189. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7190. // string str = ex.StackTrace;
  7191. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7192. // }
  7193. // #endregion N801A-S4_3 真空标机1
  7194. // // N801A-S4_4 真空标机2 数据
  7195. // #region N801A-S4_4 真空标机2
  7196. // try
  7197. // {
  7198. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  7199. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  7200. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  7201. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  7202. // {
  7203. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  7204. // {
  7205. // int stationType = (int)s4PLCData["d4Type"];
  7206. // if (stationType == 1)
  7207. // {
  7208. // // S4_4进站接口
  7209. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  7210. // }
  7211. // else if (stationType == 2)
  7212. // {
  7213. // // S4_4出站接口
  7214. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  7215. // }
  7216. // }
  7217. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  7218. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  7219. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  7220. // }
  7221. // }
  7222. // catch (Exception ex)
  7223. // {
  7224. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7225. // string str = ex.StackTrace;
  7226. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7227. // }
  7228. // #endregion N801A-S4_4 真空标机2
  7229. // // N801A-S4_5 弹夹扫码 数据
  7230. // #region N801A-S4_5 弹夹扫码
  7231. // try
  7232. // {
  7233. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7234. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7235. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7236. // {
  7237. // if (d5BulletclipScanCode == 1) // 0->1
  7238. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7239. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7240. // }
  7241. // }
  7242. // catch (Exception ex)
  7243. // {
  7244. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7245. // string str = ex.StackTrace;
  7246. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7247. // }
  7248. // #endregion N801A-S4_5 弹夹扫码
  7249. // // N801A-S4_5 载具扫码 数据
  7250. // #region N801A-S4_5 载具扫码
  7251. // try
  7252. // {
  7253. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7254. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7255. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7256. // {
  7257. // if (d5VehicleScanCode == 1) // 0->1
  7258. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7259. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7260. // }
  7261. // }
  7262. // catch (Exception ex)
  7263. // {
  7264. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7265. // string str = ex.StackTrace;
  7266. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7267. // }
  7268. // #endregion N801A-S4_5 载具扫码
  7269. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7270. // #region N801A-S4_5 出站接口
  7271. // try
  7272. // {
  7273. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7274. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7275. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7276. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7277. // {
  7278. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7279. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7280. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7281. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7282. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7283. // }
  7284. // }
  7285. // catch (Exception ex)
  7286. // {
  7287. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7288. // string str = ex.StackTrace;
  7289. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7290. // }
  7291. // #endregion N801A-S4_5 出站接口
  7292. // // N801A-S4_5 节拍接口 数据
  7293. // #region N801A-S4_5 节拍接口
  7294. // try
  7295. // {
  7296. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7297. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7298. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7299. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7300. // {
  7301. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7302. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7303. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7304. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7305. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7306. // }
  7307. // }
  7308. // catch (Exception ex)
  7309. // {
  7310. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7311. // string str = ex.StackTrace;
  7312. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7313. // }
  7314. // #endregion N801A-S4_5 节拍接口
  7315. // #region 心跳
  7316. // try
  7317. // {
  7318. // short states = 0;
  7319. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7320. // }
  7321. // catch (Exception ex)
  7322. // {
  7323. // string str = ex.StackTrace;
  7324. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7325. // }
  7326. // #endregion 心跳
  7327. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7328. // stopwatch1.Stop();
  7329. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7330. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7331. // }
  7332. // else
  7333. // {
  7334. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7335. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7336. // Funs[plcNo].Connect();
  7337. // }
  7338. // }
  7339. // catch (Exception ex)
  7340. // {
  7341. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7342. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7343. // Funs[plcNo].ReConnect();
  7344. // }
  7345. // Thread.Sleep(IntervalReadPLC);
  7346. // }
  7347. //}
  7348. /// <summary>
  7349. /// [S4] 取放桁架 - S4_1弹夹扫码
  7350. /// </summary>
  7351. /// <param name="plcNo">PLC编号</param>
  7352. /// <param name="stationNameStr">工站全称</param>
  7353. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7354. {
  7355. Stopwatch stopwatch1 = new Stopwatch();
  7356. Stopwatch stopwatch2 = new Stopwatch();
  7357. try
  7358. {
  7359. stopwatch1.Start();
  7360. // ZS 弹夹扫码
  7361. string d1BulletclipCode = " "; // 扫到的码
  7362. short d1BulletclipScanCode = 2;
  7363. stopwatch2.Start();
  7364. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7365. //// MES_Flag
  7366. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7367. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7368. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7369. writeToPLC_Flag.Adress = 2002;
  7370. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7371. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7372. {
  7373. Name = "d1BulletclipCode",
  7374. Adress = 2003,
  7375. ValueType = PLCValueType.String,
  7376. ValueTypeStrLength = 20,
  7377. Value = d1BulletclipCode
  7378. });
  7379. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7380. stopwatch2.Stop();
  7381. }
  7382. catch (Exception ex)
  7383. {
  7384. string str = ex.StackTrace;
  7385. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7386. stopwatch2.Start();
  7387. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7388. //// MES_Flag
  7389. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7390. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7391. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7392. writeToPLC_Flag.Adress = 2002;
  7393. writeToPLC_Flag.Value = (short)6;
  7394. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7395. {
  7396. Name = "d1BulletclipCode",
  7397. Adress = 2003,
  7398. ValueType = PLCValueType.String,
  7399. ValueTypeStrLength = 20,
  7400. Value = " "
  7401. });
  7402. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7403. stopwatch2.Stop();
  7404. }
  7405. stopwatch1.Stop();
  7406. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7407. }
  7408. /// <summary>
  7409. /// [S4] 取放桁架 - S4_1载具扫码
  7410. /// </summary>
  7411. /// <param name="plcNo">PLC编号</param>
  7412. /// <param name="stationNameStr">工站全称</param>
  7413. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7414. {
  7415. Stopwatch stopwatch1 = new Stopwatch();
  7416. Stopwatch stopwatch2 = new Stopwatch();
  7417. try
  7418. {
  7419. stopwatch1.Start();
  7420. // ZS 载具扫码
  7421. string d1VehicleCode = ""; // 扫到的码
  7422. short d1VehicleScanCode = 2;
  7423. #region 进站
  7424. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7425. {
  7426. #region 查询载具上的产品信息
  7427. string cavityData = string.Empty;
  7428. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7429. if (string.IsNullOrEmpty(cavityData))
  7430. cavityData = "";
  7431. if (snResult != 0)
  7432. {
  7433. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7434. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7435. writeToPLC_Flag1.Adress = 2033;
  7436. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7437. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7438. {
  7439. Name = "d1VehicleCode",
  7440. Adress = 2034,
  7441. ValueType = PLCValueType.String,
  7442. ValueTypeStrLength = 20,
  7443. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7444. });
  7445. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7446. stopwatch1.Stop();
  7447. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7448. return;
  7449. }
  7450. string[] cavitySNs = cavityData.Split('.');
  7451. string partNo = "";
  7452. if (cavitySNs != null && cavitySNs.Length >= 1)
  7453. {
  7454. partNo = cavitySNs[0];
  7455. }
  7456. #endregion 查询载具上的产品信息
  7457. List<TestItem> item = new List<TestItem>();
  7458. item.Add(new TestItem()
  7459. {
  7460. Parameter_name = "载具码",
  7461. Parameter_value = d1VehicleCode,
  7462. });
  7463. item.Add(new TestItem()
  7464. {
  7465. Parameter_name = "载具穴号",
  7466. Parameter_value = "1",
  7467. });
  7468. stopwatch2.Start();
  7469. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7470. stopwatch2.Stop();
  7471. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7472. }
  7473. #endregion 进站
  7474. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7475. //// MES_Flag
  7476. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7477. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7478. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7479. writeToPLC_Flag.Adress = 2033;
  7480. writeToPLC_Flag.Value = d1VehicleScanCode;
  7481. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7482. {
  7483. Name = "d1VehicleCode",
  7484. Adress = 2034,
  7485. ValueType = PLCValueType.String,
  7486. ValueTypeStrLength = 20,
  7487. Value = d1VehicleCode
  7488. });
  7489. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7490. }
  7491. catch (Exception ex)
  7492. {
  7493. string str = ex.StackTrace;
  7494. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7495. stopwatch2.Start();
  7496. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7497. //// MES_Flag
  7498. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7499. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7500. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7501. writeToPLC_Flag.Adress = 2033;
  7502. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7503. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7504. {
  7505. Name = "d1VehicleCode",
  7506. Adress = 2034,
  7507. ValueType = PLCValueType.String,
  7508. ValueTypeStrLength = 20,
  7509. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7510. });
  7511. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7512. stopwatch2.Stop();
  7513. }
  7514. stopwatch1.Stop();
  7515. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7516. }
  7517. // 上次采集到的SN
  7518. //private string sn_S4_1出站接口 = string.Empty;
  7519. /// <summary>
  7520. /// [S4] 取放桁架 - S4_1出站接口
  7521. /// </summary>
  7522. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7523. {
  7524. Stopwatch stopwatch1 = new Stopwatch();
  7525. Stopwatch stopwatch2 = new Stopwatch();
  7526. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7527. string stationNameStr = stationCode + stationName;
  7528. string processItem = stationName; // 测试项目
  7529. try
  7530. {
  7531. stopwatch1.Start();
  7532. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7533. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7534. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7535. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7536. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7537. sn = sn.Replace("\0", "");
  7538. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7539. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7540. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7541. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7542. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7543. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7544. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7545. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7546. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7547. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7548. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7549. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7550. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7551. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7552. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7553. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7554. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7555. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7556. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7557. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7558. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7559. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7560. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7561. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7562. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7563. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7564. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7565. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7566. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7567. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7568. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7569. bool pass = d1Result == 1;
  7570. // 存 载具SN列表
  7571. List<string> vehicleCodes = new List<string>()
  7572. {
  7573. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7574. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7575. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7576. };
  7577. // 统一查 产品SN列表
  7578. List<string> partNos = new List<string>();
  7579. foreach (string vehicleCode in vehicleCodes)
  7580. {
  7581. if (string.IsNullOrEmpty(vehicleCode))
  7582. partNos.Add("");
  7583. else
  7584. {
  7585. string partNo = "";
  7586. #region 查询载具上的产品信息
  7587. string cavityData = string.Empty;
  7588. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7589. if (string.IsNullOrEmpty(cavityData))
  7590. cavityData = "";
  7591. if (snResult != 0)
  7592. {
  7593. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7594. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7595. writeToPLC_Flag1.Adress = 2065;
  7596. writeToPLC_Flag1.Value = (short)4;
  7597. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7598. stopwatch1.Stop();
  7599. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7600. return;
  7601. }
  7602. string[] cavitySNs = cavityData.Split('.');
  7603. if (cavitySNs != null && cavitySNs.Length >= 1)
  7604. partNo = cavitySNs[0];
  7605. #endregion 查询载具上的产品信息
  7606. partNos.Add(partNo);
  7607. }
  7608. }
  7609. // 统一上传
  7610. stopwatch2.Start();
  7611. List<int> results = new List<int>();
  7612. for (int i = 0; i < partNos.Count; i++)
  7613. {
  7614. string index = (i + 1).ToString(); // 弹夹穴号
  7615. if (string.IsNullOrEmpty(partNos[i]))
  7616. results.Add(1);
  7617. else
  7618. {
  7619. List<TestItem> items1 = new List<TestItem>();
  7620. items1.Add(new TestItem()
  7621. {
  7622. Parameter_name = "弹夹码",
  7623. Parameter_value = sn,
  7624. Parameter_unit = ""
  7625. });
  7626. items1.Add(new TestItem()
  7627. {
  7628. Parameter_name = "弹夹穴号",
  7629. Parameter_value = index,
  7630. Parameter_unit = ""
  7631. });
  7632. items1.Add(new TestItem()
  7633. {
  7634. Parameter_name = "载具码",
  7635. Parameter_value = vehicleCodes[i],
  7636. Parameter_unit = ""
  7637. });
  7638. items1.Add(new TestItem()
  7639. {
  7640. Parameter_name = "载具穴号",
  7641. Parameter_value = "1",
  7642. Parameter_unit = ""
  7643. });
  7644. items1.Add(new TestItem()
  7645. {
  7646. Parameter_name = "产品结果",
  7647. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7648. Parameter_unit = ""
  7649. });
  7650. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  7651. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7652. results.Add(result1);
  7653. }
  7654. }
  7655. short result = 0;
  7656. if (results.All(a => a == 1))
  7657. result = 1;
  7658. else if (results.Contains(3))
  7659. result = 3;
  7660. else if (results.Contains(2))
  7661. result = 2;
  7662. else if (results.Contains(4))
  7663. result = 4;
  7664. else
  7665. result = 4;
  7666. stopwatch2.Stop();
  7667. #region 存储绑定数据到 边线MES系统中
  7668. if (result == 1)
  7669. {
  7670. string data = string.Join(".", vehicleCodes);
  7671. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7672. if (resultMesR != 0)
  7673. {
  7674. result = 4;
  7675. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7676. }
  7677. }
  7678. #endregion 存储绑定数据到 边线MES系统中
  7679. // MES_Flag 为4MES报错
  7680. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7681. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7682. writeToPLC_Flag.Name = "d1MES_FLAG";
  7683. writeToPLC_Flag.Adress = 2065;
  7684. writeToPLC_Flag.Value = result;
  7685. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7686. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7687. }
  7688. catch (Exception ex)
  7689. {
  7690. stopwatch2.Restart();
  7691. // MES_Flag 为4上位机报错
  7692. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7693. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7694. writeToPLC_Flag.Name = "d1MES_FLAG";
  7695. writeToPLC_Flag.Adress = 2065;
  7696. writeToPLC_Flag.Value = (short)4;
  7697. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7698. stopwatch2.Stop();
  7699. string str = ex.StackTrace;
  7700. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7701. }
  7702. stopwatch1.Stop();
  7703. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7704. }
  7705. /// <summary>
  7706. /// [S4] 取放桁架 - S4_1节拍接口
  7707. /// </summary>
  7708. /// <param name="plcNo">PLC编号</param>
  7709. /// <param name="stationNameStr">工站全称</param>
  7710. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7711. {
  7712. Stopwatch stopwatch1 = new Stopwatch();
  7713. Stopwatch stopwatch2 = new Stopwatch();
  7714. string resultStr = string.Empty;
  7715. try
  7716. {
  7717. stopwatch1.Start();
  7718. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7719. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7720. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7721. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7722. if (!actionBool)
  7723. {
  7724. stopwatch2.Start();
  7725. // MES_Flag
  7726. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7727. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7728. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7729. writeToPLC_Flag1.Adress = 2398;
  7730. writeToPLC_Flag1.Value = (short)4;
  7731. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7732. stopwatch2.Stop();
  7733. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7734. return;
  7735. }
  7736. string d1OEEPartNo = string.Empty; // 物料码
  7737. if (string.IsNullOrEmpty(d1OEEProductSN))
  7738. {
  7739. stopwatch2.Start();
  7740. // MES_Flag
  7741. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7742. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7743. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7744. writeToPLC_Flag1.Adress = 2398;
  7745. writeToPLC_Flag1.Value = (short)1;
  7746. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7747. stopwatch2.Stop();
  7748. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7749. return;
  7750. }
  7751. else
  7752. { // 查产品SN ZS
  7753. d1OEEPartNo = "Test";
  7754. }
  7755. short d1OEEMES_FLAG = 0;
  7756. // 上传OEE
  7757. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7758. d1OEEMES_FLAG = result.Item1;
  7759. resultStr = result.Item2;
  7760. stopwatch2.Start();
  7761. // MES_Flag
  7762. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7763. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7764. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7765. writeToPLC_Flag.Adress = 2398;
  7766. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7767. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7768. stopwatch2.Stop();
  7769. }
  7770. catch (Exception ex)
  7771. {
  7772. string str = ex.StackTrace;
  7773. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7774. // MES_Flag
  7775. stopwatch2.Start();
  7776. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7777. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7778. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7779. writeToPLC_Flag.Adress = 2398;
  7780. writeToPLC_Flag.Value = (short)4;
  7781. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7782. stopwatch2.Stop();
  7783. }
  7784. stopwatch1.Stop();
  7785. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7786. }
  7787. /// <summary>
  7788. /// [S4] 取放桁架 - S4_2桁架
  7789. /// </summary>
  7790. /// <param name="plcNo">PLC编号</param>
  7791. /// <param name="stationNameStr">工站全称</param>
  7792. private void S4_2桁架(int plcNo, string stationNameStr)
  7793. {
  7794. Stopwatch stopwatch1 = new Stopwatch();
  7795. Stopwatch stopwatch2 = new Stopwatch();
  7796. try
  7797. {
  7798. stopwatch1.Start();
  7799. // ZS 弹夹扫码
  7800. string d2BulletclipCode = " "; // 扫到的码
  7801. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7802. short d2BulletclipScanCode = 2;
  7803. stopwatch2.Start();
  7804. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7805. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7806. //// MES_Flag
  7807. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7808. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7809. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7810. writeToPLC_Flag.Adress = 2430;
  7811. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7812. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7813. {
  7814. Name = "d2BulletclipCode",
  7815. Adress = 2432,
  7816. ValueType = PLCValueType.String,
  7817. ValueTypeStrLength = 20,
  7818. Value = d2BulletclipCode
  7819. });
  7820. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7821. {
  7822. Name = "d2BulletclipStates",
  7823. Adress = 2431,
  7824. ValueType = PLCValueType.Short,
  7825. Value = d2BulletclipStates
  7826. });
  7827. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7828. stopwatch2.Stop();
  7829. }
  7830. catch (Exception ex)
  7831. {
  7832. string str = ex.StackTrace;
  7833. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7834. stopwatch2.Start();
  7835. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7836. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7837. // MES_Flag
  7838. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7839. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7840. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7841. writeToPLC_Flag.Adress = 2430;
  7842. writeToPLC_Flag.Value = (short)6;
  7843. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7844. {
  7845. Name = "d2BulletclipCode",
  7846. Adress = 2432,
  7847. ValueType = PLCValueType.String,
  7848. ValueTypeStrLength = 20,
  7849. Value = " "
  7850. });
  7851. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7852. {
  7853. Name = "d2BulletclipStates",
  7854. Adress = 2431,
  7855. ValueType = PLCValueType.Short,
  7856. Value = (short)0
  7857. });
  7858. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7859. stopwatch2.Stop();
  7860. }
  7861. stopwatch1.Stop();
  7862. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7863. }
  7864. // 上次采集到的SN
  7865. //private string sn_S4_3进站接口 = string.Empty;
  7866. /// <summary>
  7867. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7868. /// </summary>
  7869. private void S4_3进站接口(int plcNo, string stationNameStr)
  7870. {
  7871. Stopwatch stopwatch1 = new Stopwatch();
  7872. Stopwatch stopwatch2 = new Stopwatch();
  7873. try
  7874. {
  7875. stopwatch1.Start();
  7876. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7877. sn = sn.Replace("\0", "");
  7878. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7879. #region 查询15个载具码
  7880. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7881. string vehicleData = string.Empty;
  7882. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7883. if (string.IsNullOrEmpty(vehicleData))
  7884. vehicleData = "";
  7885. if (snResult != 0)
  7886. {
  7887. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7888. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7889. writeToPLC_Flag1.Adress = 2463;
  7890. writeToPLC_Flag1.Value = (short)4;
  7891. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7892. stopwatch1.Stop();
  7893. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7894. return;
  7895. }
  7896. string[] cavitySNs = vehicleData.Split('.');
  7897. if (cavitySNs != null && cavitySNs.Length > 0)
  7898. {
  7899. for (int i = 0; i < cavitySNs.Length; i++)
  7900. {
  7901. if (string.IsNullOrEmpty(cavitySNs[i]))
  7902. vehicleCodes.Add("");
  7903. else
  7904. vehicleCodes.Add(cavitySNs[i]);
  7905. }
  7906. }
  7907. #endregion 查询15个载具码
  7908. #region 查询15个产品SN
  7909. List<string> portNos = new List<string>(); // 15个产品SN
  7910. foreach (string vehicleCode in vehicleCodes)
  7911. {
  7912. if (string.IsNullOrEmpty(vehicleCode))
  7913. portNos.Add("");
  7914. else
  7915. {
  7916. // 查询
  7917. string cavityData = string.Empty;
  7918. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7919. if (string.IsNullOrEmpty(cavityData))
  7920. cavityData = "";
  7921. if (snResult1 != 0)
  7922. {
  7923. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7924. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7925. writeToPLC_Flag1.Adress = 2463;
  7926. writeToPLC_Flag1.Value = (short)4;
  7927. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7928. stopwatch1.Stop();
  7929. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7930. return;
  7931. }
  7932. string[] partSNs = cavityData.Split('.');
  7933. if (partSNs != null && partSNs.Length >= 1)
  7934. portNos.Add(partSNs[0]);
  7935. else
  7936. portNos.Add("");
  7937. }
  7938. }
  7939. #endregion 查询15个产品SN
  7940. // 调用MES进站(最多15个)
  7941. stopwatch2.Start();
  7942. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7943. for (int i = 0; i < vehicleCodes.Count; i++)
  7944. {
  7945. // 循环进站
  7946. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7947. {
  7948. // 产品SN(物料码)校验
  7949. string portNo = portNos[i];
  7950. List<TestItem> item = new List<TestItem>();
  7951. item.Add(new TestItem()
  7952. {
  7953. Parameter_name = "弹夹码",
  7954. Parameter_value = sn,
  7955. });
  7956. item.Add(new TestItem()
  7957. {
  7958. Parameter_name = "弹夹穴位",
  7959. Parameter_value = (i + 1).ToString(),
  7960. });
  7961. item.Add(new TestItem()
  7962. {
  7963. Parameter_name = "载具码",
  7964. Parameter_value = vehicleCodes[i],
  7965. });
  7966. item.Add(new TestItem()
  7967. {
  7968. Parameter_name = "载具穴号",
  7969. Parameter_value = "1",
  7970. });
  7971. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7972. }
  7973. }
  7974. stopwatch2.Stop();
  7975. short result = 0;
  7976. bool haveMesWarn = results.Contains(5);
  7977. bool havePCWarn = results.Contains(6);
  7978. if (haveMesWarn)
  7979. result = 2; // 5->2
  7980. else if (havePCWarn)
  7981. result = 6; // 6->4
  7982. else
  7983. result = 1;
  7984. // MES_Flag 为4MES报错
  7985. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7986. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7987. writeToPLC_Flag.Name = "d3MES_FLAG";
  7988. writeToPLC_Flag.Adress = 2463;
  7989. writeToPLC_Flag.Value = result;
  7990. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7991. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7992. }
  7993. catch (Exception ex)
  7994. {
  7995. stopwatch2.Stop();
  7996. // MES_Flag 为4上位机报错
  7997. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7998. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7999. writeToPLC_Flag.Name = "d3MES_FLAG";
  8000. writeToPLC_Flag.Adress = 2463;
  8001. writeToPLC_Flag.Value = (short)4;
  8002. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8003. string str = ex.StackTrace;
  8004. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8005. }
  8006. stopwatch1.Stop();
  8007. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8008. }
  8009. // 上次采集到的SN
  8010. //private string sn_S4_3出站接口 = string.Empty;
  8011. /// <summary>
  8012. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  8013. /// </summary>
  8014. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  8015. {
  8016. Stopwatch stopwatch1 = new Stopwatch();
  8017. Stopwatch stopwatch2 = new Stopwatch();
  8018. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8019. string stationNameStr = stationCode + stationName;
  8020. string processItem = stationName; // 测试项目
  8021. try
  8022. {
  8023. stopwatch1.Start();
  8024. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8025. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8026. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8027. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8028. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  8029. sn = sn.Replace("\0", "");
  8030. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  8031. bool isPass = d3Result == 1; // 产品结果 bool
  8032. #region 查询15个载具码
  8033. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8034. string vehicleData = string.Empty;
  8035. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8036. if (string.IsNullOrEmpty(vehicleData))
  8037. vehicleData = "";
  8038. if (snResult1 != 0)
  8039. {
  8040. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8041. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8042. writeToPLC_Flag1.Adress = 2463;
  8043. writeToPLC_Flag1.Value = (short)4;
  8044. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8045. stopwatch1.Stop();
  8046. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8047. return;
  8048. }
  8049. string[] cavitySNs = vehicleData.Split('.');
  8050. if (cavitySNs != null && cavitySNs.Length > 0)
  8051. {
  8052. for (int i = 0; i < cavitySNs.Length; i++)
  8053. {
  8054. if (string.IsNullOrEmpty(cavitySNs[i]))
  8055. vehicleCodes.Add("");
  8056. else
  8057. vehicleCodes.Add(cavitySNs[i]);
  8058. }
  8059. }
  8060. #endregion 查询15个载具码
  8061. // 统一查 产品SN列表
  8062. List<string> partNos = new List<string>();
  8063. foreach (string vehicleCode in vehicleCodes)
  8064. {
  8065. if (string.IsNullOrEmpty(vehicleCode))
  8066. partNos.Add("");
  8067. else
  8068. {
  8069. string partNo = "";
  8070. #region 查询载具上的产品信息
  8071. string cavityData = string.Empty;
  8072. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8073. if (string.IsNullOrEmpty(cavityData))
  8074. cavityData = "";
  8075. if (snResult != 0)
  8076. {
  8077. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8078. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8079. writeToPLC_Flag1.Adress = 2463;
  8080. writeToPLC_Flag1.Value = (short)4;
  8081. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8082. stopwatch1.Stop();
  8083. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8084. return;
  8085. }
  8086. string[] partSNs = cavityData.Split('.');
  8087. if (partSNs != null && partSNs.Length >= 1)
  8088. partNo = partSNs[0];
  8089. #endregion 查询载具上的产品信息
  8090. partNos.Add(partNo);
  8091. }
  8092. }
  8093. // 统一上传 - 调用MES出站
  8094. stopwatch2.Start();
  8095. List<int> results = new List<int>();
  8096. for (int i = 0; i < partNos.Count; i++)
  8097. {
  8098. string index = (i + 1).ToString(); // 弹夹穴号
  8099. if (string.IsNullOrEmpty(partNos[i]))
  8100. results.Add(1);
  8101. else
  8102. {
  8103. List<TestItem> items1 = new List<TestItem>();
  8104. items1.Add(new TestItem()
  8105. {
  8106. Parameter_name = "弹夹码",
  8107. Parameter_value = sn,
  8108. Parameter_unit = ""
  8109. });
  8110. items1.Add(new TestItem()
  8111. {
  8112. Parameter_name = "弹夹穴号",
  8113. Parameter_value = index,
  8114. Parameter_unit = ""
  8115. });
  8116. items1.Add(new TestItem()
  8117. {
  8118. Parameter_name = "载具码",
  8119. Parameter_value = vehicleCodes[i],
  8120. Parameter_unit = ""
  8121. });
  8122. items1.Add(new TestItem()
  8123. {
  8124. Parameter_name = "载具穴号",
  8125. Parameter_value = "1",
  8126. Parameter_unit = ""
  8127. });
  8128. items1.Add(new TestItem()
  8129. {
  8130. Parameter_name = "产品结果",
  8131. Parameter_value = d3Result == 1 ? "OK" : "NG",
  8132. Parameter_unit = ""
  8133. });
  8134. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8135. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8136. results.Add(result1);
  8137. }
  8138. }
  8139. short result = 0;
  8140. if (results.All(a => a == 1))
  8141. result = 1;
  8142. else if (results.Contains(3))
  8143. result = 3;
  8144. else if (results.Contains(2))
  8145. result = 2;
  8146. else if (results.Contains(4))
  8147. result = 4;
  8148. else
  8149. result = 4;
  8150. stopwatch2.Stop();
  8151. // MES_Flag 为4MES报错
  8152. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8153. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8154. writeToPLC_Flag.Name = "d3MES_FLAG";
  8155. writeToPLC_Flag.Adress = 2463;
  8156. writeToPLC_Flag.Value = result;
  8157. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8158. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8159. }
  8160. catch (Exception ex)
  8161. {
  8162. stopwatch2.Restart();
  8163. // MES_Flag 为4上位机报错
  8164. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  8165. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8166. writeToPLC_Flag.Name = "d3MES_FLAG";
  8167. writeToPLC_Flag.Adress = 2463;
  8168. writeToPLC_Flag.Value = (short)4;
  8169. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  8170. string str = ex.StackTrace;
  8171. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8172. stopwatch2.Stop();
  8173. }
  8174. stopwatch1.Stop();
  8175. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8176. }
  8177. // 上次采集到的SN
  8178. //private string sn_S4_4进站接口 = string.Empty;
  8179. /// <summary>
  8180. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  8181. /// </summary>
  8182. private void S4_4进站接口(int plcNo, string stationNameStr)
  8183. {
  8184. Stopwatch stopwatch1 = new Stopwatch();
  8185. Stopwatch stopwatch2 = new Stopwatch();
  8186. try
  8187. {
  8188. stopwatch1.Start();
  8189. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8190. sn = sn.Replace("\0", "");
  8191. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8192. #region 查询15个载具码
  8193. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8194. string vehicleData = string.Empty;
  8195. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8196. if (string.IsNullOrEmpty(vehicleData))
  8197. vehicleData = "";
  8198. if (snResult != 0)
  8199. {
  8200. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8201. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8202. writeToPLC_Flag1.Adress = 2463;
  8203. writeToPLC_Flag1.Value = (short)4;
  8204. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8205. stopwatch1.Stop();
  8206. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8207. return;
  8208. }
  8209. string[] cavitySNs = vehicleData.Split('.');
  8210. if (cavitySNs != null && cavitySNs.Length > 0)
  8211. {
  8212. for (int i = 0; i < cavitySNs.Length; i++)
  8213. {
  8214. if (string.IsNullOrEmpty(cavitySNs[i]))
  8215. vehicleCodes.Add("");
  8216. else
  8217. vehicleCodes.Add(cavitySNs[i]);
  8218. }
  8219. }
  8220. #endregion 查询15个载具码
  8221. #region 查询15个产品SN
  8222. List<string> portNos = new List<string>(); // 15个产品SN
  8223. foreach (string vehicleCode in vehicleCodes)
  8224. {
  8225. if (string.IsNullOrEmpty(vehicleCode))
  8226. portNos.Add("");
  8227. else
  8228. {
  8229. // 查询
  8230. string cavityData = string.Empty;
  8231. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8232. if (string.IsNullOrEmpty(cavityData))
  8233. cavityData = "";
  8234. if (snResult1 != 0)
  8235. {
  8236. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8237. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8238. writeToPLC_Flag1.Adress = 2463;
  8239. writeToPLC_Flag1.Value = (short)4;
  8240. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8241. stopwatch1.Stop();
  8242. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8243. return;
  8244. }
  8245. string[] partSNs = cavityData.Split('.');
  8246. if (partSNs != null && partSNs.Length >= 1)
  8247. portNos.Add(partSNs[0]);
  8248. else
  8249. portNos.Add("");
  8250. }
  8251. }
  8252. #endregion 查询15个产品SN
  8253. // 调用MES进站(最多15个)
  8254. stopwatch2.Start();
  8255. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8256. for (int i = 0; i < vehicleCodes.Count; i++)
  8257. {
  8258. // 循环进站
  8259. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8260. {
  8261. // 产品SN(物料码)校验
  8262. string portNo = portNos[i];
  8263. List<TestItem> item = new List<TestItem>();
  8264. item.Add(new TestItem()
  8265. {
  8266. Parameter_name = "弹夹码",
  8267. Parameter_value = sn,
  8268. });
  8269. item.Add(new TestItem()
  8270. {
  8271. Parameter_name = "弹夹穴位",
  8272. Parameter_value = (i + 1).ToString(),
  8273. });
  8274. item.Add(new TestItem()
  8275. {
  8276. Parameter_name = "载具码",
  8277. Parameter_value = vehicleCodes[i],
  8278. });
  8279. item.Add(new TestItem()
  8280. {
  8281. Parameter_name = "载具穴号",
  8282. Parameter_value = "1",
  8283. });
  8284. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8285. }
  8286. }
  8287. stopwatch2.Stop();
  8288. short result = 0;
  8289. bool haveMesWarn = results.Contains(5);
  8290. bool havePCWarn = results.Contains(6);
  8291. if (haveMesWarn)
  8292. result = 2; // 5->2
  8293. else if (havePCWarn)
  8294. result = 6; // 6->4
  8295. else
  8296. result = 1;
  8297. // MES_Flag 为4MES报错
  8298. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8299. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8300. writeToPLC_Flag.Name = "d4MES_FLAG";
  8301. writeToPLC_Flag.Adress = 2496;
  8302. writeToPLC_Flag.Value = result;
  8303. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8304. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8305. }
  8306. catch (Exception ex)
  8307. {
  8308. stopwatch2.Stop();
  8309. // MES_Flag 为4上位机报错
  8310. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8311. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8312. writeToPLC_Flag.Name = "d4MES_FLAG";
  8313. writeToPLC_Flag.Adress = 2496;
  8314. writeToPLC_Flag.Value = (short)4;
  8315. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8316. string str = ex.StackTrace;
  8317. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8318. }
  8319. stopwatch1.Stop();
  8320. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8321. }
  8322. // 上次采集到的SN
  8323. //private string sn_S4_4出站接口 = string.Empty;
  8324. /// <summary>
  8325. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8326. /// </summary>
  8327. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8328. {
  8329. Stopwatch stopwatch1 = new Stopwatch();
  8330. Stopwatch stopwatch2 = new Stopwatch();
  8331. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8332. string stationNameStr = stationCode + stationName;
  8333. string processItem = stationName; // 测试项目
  8334. try
  8335. {
  8336. stopwatch1.Start();
  8337. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8338. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8339. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8340. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8341. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8342. sn = sn.Replace("\0", "");
  8343. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8344. bool isPass = d4Result == 1; // 产品结果 bool
  8345. #region 查询15个载具码
  8346. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8347. string vehicleData = string.Empty;
  8348. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8349. if (string.IsNullOrEmpty(vehicleData))
  8350. vehicleData = "";
  8351. if (snResult1 != 0)
  8352. {
  8353. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8354. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8355. writeToPLC_Flag1.Adress = 2496;
  8356. writeToPLC_Flag1.Value = (short)4;
  8357. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8358. stopwatch1.Stop();
  8359. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8360. return;
  8361. }
  8362. string[] cavitySNs = vehicleData.Split('.');
  8363. if (cavitySNs != null && cavitySNs.Length > 0)
  8364. {
  8365. for (int i = 0; i < cavitySNs.Length; i++)
  8366. {
  8367. if (string.IsNullOrEmpty(cavitySNs[i]))
  8368. vehicleCodes.Add("");
  8369. else
  8370. vehicleCodes.Add(cavitySNs[i]);
  8371. }
  8372. }
  8373. #endregion 查询15个载具码
  8374. // 统一查 产品SN列表
  8375. List<string> partNos = new List<string>();
  8376. foreach (string vehicleCode in vehicleCodes)
  8377. {
  8378. if (string.IsNullOrEmpty(vehicleCode))
  8379. partNos.Add("");
  8380. else
  8381. {
  8382. string partNo = "";
  8383. #region 查询载具上的产品信息
  8384. string cavityData = string.Empty;
  8385. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8386. if (string.IsNullOrEmpty(cavityData))
  8387. cavityData = "";
  8388. if (snResult != 0)
  8389. {
  8390. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8391. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8392. writeToPLC_Flag1.Adress = 2496;
  8393. writeToPLC_Flag1.Value = (short)4;
  8394. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8395. stopwatch1.Stop();
  8396. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8397. return;
  8398. }
  8399. string[] partSNs = cavityData.Split('.');
  8400. if (partSNs != null && partSNs.Length >= 1)
  8401. partNo = partSNs[0];
  8402. #endregion 查询载具上的产品信息
  8403. partNos.Add(partNo);
  8404. }
  8405. }
  8406. // 调用MES出站
  8407. stopwatch2.Start();
  8408. // 统一上传
  8409. List<int> results = new List<int>();
  8410. for (int i = 0; i < partNos.Count; i++)
  8411. {
  8412. string index = (i + 1).ToString(); // 弹夹穴号
  8413. if (string.IsNullOrEmpty(partNos[i]))
  8414. results.Add(1);
  8415. else
  8416. {
  8417. List<TestItem> items1 = new List<TestItem>();
  8418. items1.Add(new TestItem()
  8419. {
  8420. Parameter_name = "弹夹码",
  8421. Parameter_value = sn,
  8422. Parameter_unit = ""
  8423. });
  8424. items1.Add(new TestItem()
  8425. {
  8426. Parameter_name = "弹夹穴号",
  8427. Parameter_value = index,
  8428. Parameter_unit = ""
  8429. });
  8430. items1.Add(new TestItem()
  8431. {
  8432. Parameter_name = "载具码",
  8433. Parameter_value = vehicleCodes[i],
  8434. Parameter_unit = ""
  8435. });
  8436. items1.Add(new TestItem()
  8437. {
  8438. Parameter_name = "载具穴号",
  8439. Parameter_value = "1",
  8440. Parameter_unit = ""
  8441. });
  8442. items1.Add(new TestItem()
  8443. {
  8444. Parameter_name = "产品结果",
  8445. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8446. Parameter_unit = ""
  8447. });
  8448. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8449. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8450. results.Add(result1);
  8451. }
  8452. }
  8453. short result = 0;
  8454. if (results.All(a => a == 1))
  8455. result = 1;
  8456. else if (results.Contains(3))
  8457. result = 3;
  8458. else if (results.Contains(2))
  8459. result = 2;
  8460. else if (results.Contains(4))
  8461. result = 4;
  8462. else
  8463. result = 4;
  8464. stopwatch2.Stop();
  8465. // MES_Flag 为4MES报错
  8466. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8467. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8468. writeToPLC_Flag.Name = "d4MES_FLAG";
  8469. writeToPLC_Flag.Adress = 2496;
  8470. writeToPLC_Flag.Value = result;
  8471. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8472. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8473. }
  8474. catch (Exception ex)
  8475. {
  8476. stopwatch2.Restart();
  8477. // MES_Flag 为4上位机报错
  8478. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8479. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8480. writeToPLC_Flag.Name = "d4MES_FLAG";
  8481. writeToPLC_Flag.Adress = 2496;
  8482. writeToPLC_Flag.Value = (short)4;
  8483. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8484. string str = ex.StackTrace;
  8485. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8486. stopwatch2.Stop();
  8487. }
  8488. stopwatch1.Stop();
  8489. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8490. }
  8491. /// <summary>
  8492. /// [S4] 取放桁架 - S4_5弹夹扫码
  8493. /// </summary>
  8494. /// <param name="plcNo">PLC编号</param>
  8495. /// <param name="stationNameStr">工站全称</param>
  8496. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8497. {
  8498. Stopwatch stopwatch1 = new Stopwatch();
  8499. Stopwatch stopwatch2 = new Stopwatch();
  8500. try
  8501. {
  8502. stopwatch1.Start();
  8503. // ZS 弹夹扫码
  8504. string d5BulletclipCode = " "; // 扫到的码
  8505. short d5BulletclipScanCode = 2;
  8506. stopwatch2.Start();
  8507. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8508. //// MES_Flag
  8509. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8510. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8511. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8512. writeToPLC_Flag.Adress = 2528;
  8513. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8514. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8515. {
  8516. Name = "d5BulletclipCode",
  8517. Adress = 2529,
  8518. ValueType = PLCValueType.String,
  8519. ValueTypeStrLength = 20,
  8520. Value = d5BulletclipCode
  8521. });
  8522. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8523. stopwatch2.Stop();
  8524. }
  8525. catch (Exception ex)
  8526. {
  8527. string str = ex.StackTrace;
  8528. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8529. stopwatch2.Start();
  8530. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8531. //// MES_Flag
  8532. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8533. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8534. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8535. writeToPLC_Flag.Adress = 2528;
  8536. writeToPLC_Flag.Value = (short)6;
  8537. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8538. {
  8539. Name = "d5BulletclipCode",
  8540. Adress = 2529,
  8541. ValueType = PLCValueType.String,
  8542. ValueTypeStrLength = 20,
  8543. Value = " "
  8544. });
  8545. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8546. stopwatch2.Stop();
  8547. }
  8548. stopwatch1.Stop();
  8549. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8550. }
  8551. /// <summary>
  8552. /// [S4] 取放桁架 - S4_5载具扫码
  8553. /// </summary>
  8554. /// <param name="plcNo">PLC编号</param>
  8555. /// <param name="stationNameStr">工站全称</param>
  8556. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8557. {
  8558. Stopwatch stopwatch1 = new Stopwatch();
  8559. Stopwatch stopwatch2 = new Stopwatch();
  8560. try
  8561. {
  8562. stopwatch1.Start();
  8563. // ZS 载具扫码
  8564. string d5VehicleCode = " "; // 扫到的码
  8565. short d5VehicleScanCode = 2;
  8566. #region 进站
  8567. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8568. {
  8569. // 查产品SN
  8570. #region 查询载具上的产品信息
  8571. string cavityData = string.Empty;
  8572. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8573. if (string.IsNullOrEmpty(cavityData))
  8574. cavityData = "";
  8575. if (snResult != 0)
  8576. {
  8577. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8578. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8579. writeToPLC_Flag1.Adress = 2559;
  8580. writeToPLC_Flag1.Value = (short)6;
  8581. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8582. {
  8583. Name = "d5VehicleCode",
  8584. Adress = 2560,
  8585. ValueType = PLCValueType.String,
  8586. ValueTypeStrLength = 20,
  8587. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8588. });
  8589. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8590. stopwatch1.Stop();
  8591. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8592. return;
  8593. }
  8594. string[] cavitySNs = cavityData.Split('.');
  8595. string partNo = "";
  8596. if (cavitySNs != null && cavitySNs.Length >= 1)
  8597. {
  8598. partNo = cavitySNs[0];
  8599. }
  8600. #endregion 查询载具上的产品信息
  8601. List<TestItem> item = new List<TestItem>();
  8602. item.Add(new TestItem()
  8603. {
  8604. Parameter_name = "载具码",
  8605. Parameter_value = d5VehicleCode,
  8606. });
  8607. item.Add(new TestItem()
  8608. {
  8609. Parameter_name = "载具穴号",
  8610. Parameter_value = "1",
  8611. });
  8612. stopwatch2.Start();
  8613. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8614. stopwatch2.Stop();
  8615. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8616. }
  8617. #endregion 进站
  8618. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8619. //// MES_Flag
  8620. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8621. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8622. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8623. writeToPLC_Flag.Adress = 2559;
  8624. writeToPLC_Flag.Value = d5VehicleScanCode;
  8625. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8626. {
  8627. Name = "d5VehicleCode",
  8628. Adress = 2560,
  8629. ValueType = PLCValueType.String,
  8630. ValueTypeStrLength = 20,
  8631. Value = d5VehicleCode
  8632. });
  8633. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8634. }
  8635. catch (Exception ex)
  8636. {
  8637. string str = ex.StackTrace;
  8638. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8639. stopwatch2.Start();
  8640. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8641. //// MES_Flag
  8642. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8643. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8644. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8645. writeToPLC_Flag.Adress = 2559;
  8646. writeToPLC_Flag.Value = (short)6;
  8647. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8648. {
  8649. Name = "d5VehicleCode",
  8650. Adress = 2560,
  8651. ValueType = PLCValueType.String,
  8652. ValueTypeStrLength = 20,
  8653. Value = " "
  8654. });
  8655. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8656. stopwatch2.Stop();
  8657. }
  8658. stopwatch1.Stop();
  8659. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8660. }
  8661. // 上次采集到的SN
  8662. //private string sn_S4_5出站接口 = string.Empty;
  8663. /// <summary>
  8664. /// [S4] 取放桁架 - S4_5出站接口
  8665. /// </summary>
  8666. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8667. {
  8668. Stopwatch stopwatch1 = new Stopwatch();
  8669. Stopwatch stopwatch2 = new Stopwatch();
  8670. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8671. string stationNameStr = stationCode + stationName;
  8672. string processItem = stationName; // 测试项目
  8673. try
  8674. {
  8675. stopwatch1.Start();
  8676. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8677. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8678. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8679. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8680. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8681. sn = sn.Replace("\0", "");
  8682. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8683. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8684. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8685. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8686. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8687. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8688. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8689. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8690. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8691. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8692. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8693. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8694. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8695. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8696. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8697. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8698. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8699. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8700. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8701. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8702. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8703. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8704. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8705. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8706. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8707. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8708. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8709. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8710. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8711. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8712. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8713. bool pass = d5Result == 1;
  8714. // 存 载具SN列表
  8715. List<string> vehicleCodes = new List<string>()
  8716. {
  8717. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8718. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8719. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8720. };
  8721. // 统一查 产品SN列表
  8722. List<string> partNos = new List<string>();
  8723. foreach (string vehicleCode in vehicleCodes)
  8724. {
  8725. if (string.IsNullOrEmpty(vehicleCode))
  8726. partNos.Add("");
  8727. else
  8728. {
  8729. string partNo = "";
  8730. #region 查询载具上的产品信息
  8731. string cavityData = string.Empty;
  8732. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8733. if (string.IsNullOrEmpty(cavityData))
  8734. cavityData = "";
  8735. if (snResult != 0)
  8736. {
  8737. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8738. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8739. writeToPLC_Flag1.Adress = 2591;
  8740. writeToPLC_Flag1.Value = (short)4;
  8741. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8742. stopwatch1.Stop();
  8743. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8744. return;
  8745. }
  8746. string[] cavitySNs = cavityData.Split('.');
  8747. if (cavitySNs != null && cavitySNs.Length >= 1)
  8748. partNo = cavitySNs[0];
  8749. #endregion 查询载具上的产品信息
  8750. partNos.Add(partNo);
  8751. }
  8752. }
  8753. // 统一上传
  8754. stopwatch2.Start();
  8755. List<int> results = new List<int>();
  8756. for (int i = 0; i < partNos.Count; i++)
  8757. {
  8758. string index = (i + 1).ToString(); // 弹夹穴号
  8759. if (string.IsNullOrEmpty(partNos[i]))
  8760. results.Add(1);
  8761. else
  8762. {
  8763. List<TestItem> items1 = new List<TestItem>();
  8764. items1.Add(new TestItem()
  8765. {
  8766. Parameter_name = "弹夹码",
  8767. Parameter_value = sn,
  8768. Parameter_unit = ""
  8769. });
  8770. items1.Add(new TestItem()
  8771. {
  8772. Parameter_name = "弹夹穴号",
  8773. Parameter_value = index,
  8774. Parameter_unit = ""
  8775. });
  8776. items1.Add(new TestItem()
  8777. {
  8778. Parameter_name = "载具码",
  8779. Parameter_value = vehicleCodes[i],
  8780. Parameter_unit = ""
  8781. });
  8782. items1.Add(new TestItem()
  8783. {
  8784. Parameter_name = "载具穴号",
  8785. Parameter_value = "1",
  8786. Parameter_unit = ""
  8787. });
  8788. items1.Add(new TestItem()
  8789. {
  8790. Parameter_name = "产品结果",
  8791. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8792. Parameter_unit = ""
  8793. });
  8794. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8795. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8796. results.Add(result1);
  8797. }
  8798. }
  8799. short result = 0;
  8800. if (results.All(a => a == 1))
  8801. result = 1;
  8802. else if (results.Contains(3))
  8803. result = 3;
  8804. else if (results.Contains(2))
  8805. result = 2;
  8806. else if (results.Contains(4))
  8807. result = 4;
  8808. else
  8809. result = 4;
  8810. stopwatch2.Stop();
  8811. #region 存储绑定数据到 边线MES系统中
  8812. if (result == 1)
  8813. {
  8814. // 删除绑定信息
  8815. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8816. if (resultMesR != 0)
  8817. {
  8818. result = 4;
  8819. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8820. }
  8821. }
  8822. #endregion 存储绑定数据到 边线MES系统中
  8823. // MES_Flag 为4MES报错
  8824. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8825. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8826. writeToPLC_Flag.Name = "d5MES_FLAG";
  8827. writeToPLC_Flag.Adress = 2591;
  8828. writeToPLC_Flag.Value = result;
  8829. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8830. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8831. }
  8832. catch (Exception ex)
  8833. {
  8834. stopwatch2.Restart();
  8835. // MES_Flag 为4上位机报错
  8836. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8837. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8838. writeToPLC_Flag.Name = "d5MES_FLAG";
  8839. writeToPLC_Flag.Adress = 2591;
  8840. writeToPLC_Flag.Value = (short)4;
  8841. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8842. stopwatch2.Stop();
  8843. string str = ex.StackTrace;
  8844. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8845. }
  8846. stopwatch1.Stop();
  8847. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8848. }
  8849. /// <summary>
  8850. /// [S4] 取放桁架 - S4_5节拍接口
  8851. /// </summary>
  8852. /// <param name="plcNo">PLC编号</param>
  8853. /// <param name="stationNameStr">工站全称</param>
  8854. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8855. {
  8856. Stopwatch stopwatch1 = new Stopwatch();
  8857. Stopwatch stopwatch2 = new Stopwatch();
  8858. string resultStr = string.Empty;
  8859. try
  8860. {
  8861. stopwatch1.Start();
  8862. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8863. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8864. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8865. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8866. if (!actionBool)
  8867. {
  8868. stopwatch2.Start();
  8869. // MES_Flag
  8870. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8871. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8872. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8873. writeToPLC_Flag1.Adress = 2924;
  8874. writeToPLC_Flag1.Value = (short)4;
  8875. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8876. stopwatch2.Stop();
  8877. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8878. return;
  8879. }
  8880. string d5OEEPartNo = string.Empty; // 物料码
  8881. if (string.IsNullOrEmpty(d5OEEProductSN))
  8882. {
  8883. stopwatch2.Start();
  8884. // MES_Flag
  8885. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8886. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8887. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8888. writeToPLC_Flag1.Adress = 2924;
  8889. writeToPLC_Flag1.Value = (short)1;
  8890. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8891. stopwatch2.Stop();
  8892. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8893. return;
  8894. }
  8895. else
  8896. { // 查产品SN
  8897. d5OEEPartNo = "Test"; // ZS
  8898. }
  8899. short d5OEEMES_FLAG = 0;
  8900. // 上传OEE
  8901. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8902. d5OEEMES_FLAG = result.Item1;
  8903. resultStr = result.Item2;
  8904. stopwatch2.Start();
  8905. // MES_Flag
  8906. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8907. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8908. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8909. writeToPLC_Flag.Adress = 2924;
  8910. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8911. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8912. stopwatch2.Stop();
  8913. }
  8914. catch (Exception ex)
  8915. {
  8916. string str = ex.StackTrace;
  8917. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8918. // MES_Flag
  8919. stopwatch2.Start();
  8920. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8921. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8922. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8923. writeToPLC_Flag.Adress = 2924;
  8924. writeToPLC_Flag.Value = (short)4;
  8925. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8926. stopwatch2.Stop();
  8927. }
  8928. stopwatch1.Stop();
  8929. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8930. }
  8931. #endregion [S4] 取放桁架
  8932. #endregion PLC4 刘果段
  8933. #region PLC5 张超凡
  8934. #region [S5] Tray盘下料装备
  8935. /// <summary>
  8936. /// S5工位的数据- 触发信号上次的值
  8937. /// </summary>
  8938. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8939. /// <summary>
  8940. /// S5工位的数据(含触发信号)
  8941. /// </summary>
  8942. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8943. /// <summary>
  8944. /// S5工位的数据- 回写点位
  8945. /// </summary>
  8946. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8947. /// <summary>
  8948. /// [S5] Tray盘下料装备
  8949. /// </summary>
  8950. /// <param name="plcNo">PLC编号</param>
  8951. //private void ReadStation_S5(int plcNo)
  8952. //{
  8953. // // [S1] Tray盘上料装备
  8954. // // [S2] FCT
  8955. // // [S3] 值板机
  8956. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8957. // // [S5] Tray盘下料装备
  8958. // /// 上位机心跳
  8959. // /// 获取设备报警数据与状态信息
  8960. // string stationCode = "[S5]";
  8961. // string stationName = "Tray盘下料装备";
  8962. // string stationNameStr = stationCode + stationName;
  8963. // #region 创建字典
  8964. // // 触发信号字典 赋值
  8965. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8966. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8967. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8968. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8969. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8970. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8971. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8972. // // PLC数据字典 赋值
  8973. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8974. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8975. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8976. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8977. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8978. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8979. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8980. // s5PLCData.Add("e1Result", 0); // 产品结果
  8981. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8982. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8983. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8984. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8985. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8986. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8987. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8988. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8989. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8990. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8991. // #endregion 创建字典
  8992. // while (IsRun)
  8993. // {
  8994. // try
  8995. // {
  8996. // if (!GlobalContext._IsCon_Funs5)
  8997. // {
  8998. // UpdatePLCMonitor(1, plcNo, 0);
  8999. // continue;
  9000. // }
  9001. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9002. // {
  9003. // Stopwatch stopwatch1 = new Stopwatch();
  9004. // Stopwatch stopwatch2 = new Stopwatch();
  9005. // stopwatch1.Start();
  9006. // stopwatch2.Start();
  9007. // #region 一次性读取所有数据
  9008. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9009. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  9010. // int[] datas = data1.Concat(data2).ToArray();
  9011. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  9012. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  9013. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  9014. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  9015. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  9016. // s5PLCData["e1MES_FLAG"] = datas[35];
  9017. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  9018. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  9019. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  9020. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  9021. // s5PLCData["e1Result"] = datas[76];
  9022. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  9023. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  9024. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  9025. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  9026. // s5PLCData["e1OEEType"] = datas[109];
  9027. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  9028. // s5PLCData["e1AGVUpStart"] = datas[121];
  9029. // s5PLCData["e1AGVUpEnd"] = datas[122];
  9030. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  9031. // s5PLCData["e1AGVDownStart"] = datas[134];
  9032. // s5PLCData["e1AGVDownEnd"] = datas[135];
  9033. // #endregion 一次性读取所有数据
  9034. // stopwatch2.Stop();
  9035. // #region 回写操作,写后清空flag
  9036. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  9037. // #endregion 回写操作,写后清空flag
  9038. // #region 进站校验
  9039. // try
  9040. // {
  9041. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  9042. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  9043. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  9044. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  9045. // {
  9046. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  9047. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  9048. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  9049. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  9050. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  9051. // }
  9052. // }
  9053. // catch (Exception ex)
  9054. // {
  9055. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9056. // string str = ex.StackTrace;
  9057. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9058. // }
  9059. // #endregion 进站校验
  9060. // #region 出站接口
  9061. // try
  9062. // {
  9063. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  9064. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  9065. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  9066. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  9067. // {
  9068. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  9069. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9070. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  9071. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  9072. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  9073. // }
  9074. // }
  9075. // catch (Exception ex)
  9076. // {
  9077. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  9078. // string str = ex.StackTrace;
  9079. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9080. // }
  9081. // #endregion 出站接口
  9082. // #region 节拍接口
  9083. // try
  9084. // {
  9085. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  9086. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  9087. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  9088. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  9089. // {
  9090. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  9091. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9092. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  9093. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  9094. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  9095. // }
  9096. // }
  9097. // catch (Exception ex)
  9098. // {
  9099. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9100. // string str = ex.StackTrace;
  9101. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9102. // }
  9103. // #endregion 节拍接口
  9104. // #region AGV上料
  9105. // // AGV上料叫AGV信号
  9106. // try
  9107. // {
  9108. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  9109. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  9110. // if (e1AGVUpCall != e1AGVUpCallOld)
  9111. // {
  9112. // if (e1AGVUpCall == 1) // 0->1
  9113. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  9114. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  9115. // }
  9116. // }
  9117. // catch (Exception ex)
  9118. // {
  9119. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9120. // string str = ex.StackTrace;
  9121. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9122. // }
  9123. // // AGV上料完成信号
  9124. // try
  9125. // {
  9126. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  9127. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  9128. // if (e1AGVUpEnd != e1AGVUpEndOld)
  9129. // {
  9130. // if (e1AGVUpEnd == 1) // 0->1
  9131. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  9132. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  9133. // }
  9134. // }
  9135. // catch (Exception ex)
  9136. // {
  9137. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9138. // string str = ex.StackTrace;
  9139. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9140. // }
  9141. // #endregion AGV上料
  9142. // #region AGV下料
  9143. // // AGV下料叫agv信号
  9144. // try
  9145. // {
  9146. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  9147. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  9148. // if (e1AGVDownCall != e1AGVDownCallOld)
  9149. // {
  9150. // if (e1AGVDownCall == 1) // 0->1
  9151. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  9152. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  9153. // }
  9154. // }
  9155. // catch (Exception ex)
  9156. // {
  9157. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9158. // string str = ex.StackTrace;
  9159. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9160. // }
  9161. // // AGV下料完成信号
  9162. // try
  9163. // {
  9164. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  9165. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  9166. // if (e1AGVDownEnd != e1AGVDownEndOld)
  9167. // {
  9168. // if (e1AGVDownEnd == 1) // 0->1
  9169. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  9170. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  9171. // }
  9172. // }
  9173. // catch (Exception ex)
  9174. // {
  9175. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9176. // string str = ex.StackTrace;
  9177. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9178. // }
  9179. // #endregion AGV下料
  9180. // #region 心跳
  9181. // try
  9182. // {
  9183. // short states = 0;
  9184. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9185. // }
  9186. // catch (Exception ex)
  9187. // {
  9188. // string str = ex.StackTrace;
  9189. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9190. // }
  9191. // #endregion 心跳
  9192. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9193. // stopwatch1.Stop();
  9194. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9195. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9196. // }
  9197. // else
  9198. // {
  9199. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9200. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9201. // Funs[plcNo].Connect();
  9202. // }
  9203. // }
  9204. // catch (Exception ex)
  9205. // {
  9206. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9207. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9208. // Funs[plcNo].ReConnect();
  9209. // }
  9210. // Thread.Sleep(IntervalReadPLC);
  9211. // }
  9212. //}
  9213. /// <summary>
  9214. /// [S5] Tray盘下料装备 - 进站校验
  9215. /// </summary>
  9216. /// <param name="plcNo">PLC编号</param>
  9217. /// <param name="stationNameStr">工站全称</param>
  9218. private void S5进站校验(int plcNo, string stationNameStr)
  9219. {
  9220. Stopwatch stopwatch1 = new Stopwatch();
  9221. Stopwatch stopwatch2 = new Stopwatch();
  9222. try
  9223. {
  9224. stopwatch1.Start();
  9225. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9226. sn = sn.Replace("\0", "");
  9227. // 获取产品SN By 载具码
  9228. #region 查询载具上的产品信息
  9229. string cavityData = string.Empty;
  9230. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9231. if (string.IsNullOrEmpty(cavityData))
  9232. cavityData = "";
  9233. if (snResult != 0)
  9234. {
  9235. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9236. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9237. writeToPLC_Flag1.Adress = 2003;
  9238. writeToPLC_Flag1.Value = (short)6;
  9239. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9240. stopwatch1.Stop();
  9241. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9242. return;
  9243. }
  9244. string[] cavitySNs = cavityData.Split('.');
  9245. string partNo = string.Empty;
  9246. if (cavitySNs != null && cavitySNs.Length >= 1)
  9247. partNo = cavitySNs[0];
  9248. #endregion 查询载具上的产品信息
  9249. // 产品SN(物料码)校验
  9250. List<TestItem> item = new List<TestItem>();
  9251. item.Add(new TestItem()
  9252. {
  9253. Parameter_name = "载具码",
  9254. Parameter_value = sn,
  9255. });
  9256. item.Add(new TestItem()
  9257. {
  9258. Parameter_name = "载具穴号",
  9259. Parameter_value = "1",
  9260. });
  9261. stopwatch2.Start();
  9262. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9263. stopwatch2.Stop();
  9264. short e1MES_FLAG_Check = (short)result;
  9265. // MES_Flag
  9266. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9267. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9268. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9269. writeToPLC_Flag.Adress = 2003;
  9270. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9271. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9272. }
  9273. catch (Exception ex)
  9274. {
  9275. string str = ex.StackTrace;
  9276. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9277. // MES_Flag
  9278. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9279. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9280. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9281. writeToPLC_Flag.Adress = 2003;
  9282. writeToPLC_Flag.Value = (short)6;
  9283. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9284. }
  9285. stopwatch1.Stop();
  9286. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9287. }
  9288. /// <summary>
  9289. /// [S5] Tray盘下料装备 - 出站接口
  9290. /// </summary>
  9291. /// <param name="plcNo"></param>
  9292. /// <param name="stationCode"></param>
  9293. /// <param name="stationName"></param>
  9294. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9295. {
  9296. Stopwatch stopwatch1 = new Stopwatch();
  9297. Stopwatch stopwatch2 = new Stopwatch();
  9298. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9299. string stationNameStr = stationCode + stationName;
  9300. string processItem = stationName; // 测试项目
  9301. try
  9302. {
  9303. stopwatch1.Start();
  9304. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9305. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9306. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9307. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9308. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9309. sn = sn.Replace("\0", "");
  9310. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9311. //partNo = partNo.Replace("\0", "");
  9312. #region 查询载具上的产品信息
  9313. string cavityData = string.Empty;
  9314. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9315. if (string.IsNullOrEmpty(cavityData))
  9316. cavityData = "";
  9317. if (snResult != 0)
  9318. {
  9319. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9320. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9321. writeToPLC_Flag1.Adress = 2035;
  9322. writeToPLC_Flag1.Value = (short)4;
  9323. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9324. stopwatch1.Stop();
  9325. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9326. return;
  9327. }
  9328. string[] cavitySNs = cavityData.Split('.');
  9329. string partNo = string.Empty;
  9330. if (cavitySNs != null && cavitySNs.Length >= 1)
  9331. partNo = cavitySNs[0];
  9332. #endregion 查询载具上的产品信息
  9333. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9334. bool pass = e1Result == 1;
  9335. stopwatch2.Start();
  9336. // 上传MES
  9337. List<TestItem> items = new List<TestItem>();
  9338. items.Add(new TestItem()
  9339. {
  9340. Parameter_name = "载具码",
  9341. Parameter_value = sn,
  9342. Parameter_unit = ""
  9343. });
  9344. items.Add(new TestItem()
  9345. {
  9346. Parameter_name = "载具穴号",
  9347. Parameter_value = "1",
  9348. Parameter_unit = ""
  9349. });
  9350. items.Add(new TestItem()
  9351. {
  9352. Parameter_name = "产品结果",
  9353. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9354. Parameter_unit = ""
  9355. });
  9356. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  9357. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9358. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9359. short result = result1 == 1 ? (short)1 : (short)3;
  9360. stopwatch2.Stop();
  9361. #region 存储绑定数据到 边线MES系统中
  9362. if (result == 1)
  9363. {
  9364. // 删除绑定信息
  9365. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9366. if (resultMesR != 0)
  9367. {
  9368. result = 4;
  9369. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9370. }
  9371. }
  9372. #endregion 存储绑定数据到 边线MES系统中
  9373. // MES_Flag 为MES报错
  9374. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9375. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9376. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9377. writeToPLC_Flag.Name = "e1MES_FLAG";
  9378. writeToPLC_Flag.Adress = 2035;
  9379. writeToPLC_Flag.Value = result;
  9380. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9381. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9382. }
  9383. catch (Exception ex)
  9384. {
  9385. stopwatch2.Restart();
  9386. // MES_Flag 为4上位机报错
  9387. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9388. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9389. writeToPLC_Flag.Name = "e1MES_FLAG";
  9390. writeToPLC_Flag.Adress = 2035;
  9391. writeToPLC_Flag.Value = (short)4;
  9392. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9393. stopwatch2.Stop();
  9394. string str = ex.StackTrace;
  9395. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9396. }
  9397. stopwatch1.Stop();
  9398. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9399. }
  9400. /// <summary>
  9401. /// [S5] Tray盘下料装备 - 节拍接口
  9402. /// </summary>
  9403. /// <param name="plcNo">PLC编号</param>
  9404. /// <param name="stationNameStr">工站全称</param>
  9405. private void S5节拍接口(int plcNo, string stationNameStr)
  9406. {
  9407. Stopwatch stopwatch1 = new Stopwatch();
  9408. Stopwatch stopwatch2 = new Stopwatch();
  9409. string resultStr = string.Empty;
  9410. try
  9411. {
  9412. stopwatch1.Start();
  9413. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9414. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9415. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9416. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9417. if (!actionBool)
  9418. {
  9419. stopwatch2.Start();
  9420. // MES_Flag
  9421. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9422. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9423. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9424. writeToPLC_Flag1.Adress = 2088;
  9425. writeToPLC_Flag1.Value = (short)4;
  9426. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9427. stopwatch2.Stop();
  9428. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9429. return;
  9430. }
  9431. string e1OEEPartNo = string.Empty; // 物料码
  9432. if (string.IsNullOrEmpty(e1OEEProductSN))
  9433. {
  9434. stopwatch2.Start();
  9435. // MES_Flag
  9436. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9437. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9438. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9439. writeToPLC_Flag1.Adress = 2088;
  9440. writeToPLC_Flag1.Value = (short)1;
  9441. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9442. stopwatch2.Stop();
  9443. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9444. return;
  9445. }
  9446. else
  9447. { // 查产品SN
  9448. e1OEEPartNo = "Test"; // ZS
  9449. }
  9450. short e1OEEMES_FLAG = 0;
  9451. // 上传OEE
  9452. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9453. e1OEEMES_FLAG = result.Item1;
  9454. resultStr = result.Item2;
  9455. stopwatch2.Start();
  9456. // MES_Flag
  9457. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9458. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9459. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9460. writeToPLC_Flag.Adress = 2088;
  9461. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9462. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9463. stopwatch2.Stop();
  9464. }
  9465. catch (Exception ex)
  9466. {
  9467. string str = ex.StackTrace;
  9468. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9469. // MES_Flag
  9470. stopwatch2.Start();
  9471. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9472. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9473. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9474. writeToPLC_Flag.Adress = 2088;
  9475. writeToPLC_Flag.Value = (short)4;
  9476. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9477. stopwatch2.Stop();
  9478. }
  9479. stopwatch1.Stop();
  9480. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9481. }
  9482. /// <summary>
  9483. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9484. /// </summary>
  9485. /// <param name="plcNo">PLC编号</param>
  9486. /// <param name="stationNameStr">工站全称</param>
  9487. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9488. {
  9489. Stopwatch stopwatch1 = new Stopwatch();
  9490. Stopwatch stopwatch2 = new Stopwatch();
  9491. try
  9492. {
  9493. stopwatch1.Start();
  9494. // ZS 呼叫AGV
  9495. short e1AGVUpCall = 2;
  9496. stopwatch2.Start();
  9497. // e1AGVUpCall
  9498. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9499. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9500. writeToPLC_Flag.Name = "e1AGVUpCall";
  9501. writeToPLC_Flag.Adress = 2120;
  9502. writeToPLC_Flag.Value = e1AGVUpCall;
  9503. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9504. stopwatch2.Stop();
  9505. }
  9506. catch (Exception ex)
  9507. {
  9508. string str = ex.StackTrace;
  9509. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9510. // e1AGVUpCall
  9511. stopwatch2.Start();
  9512. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9513. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9514. writeToPLC_Flag.Name = "e1AGVUpCall";
  9515. writeToPLC_Flag.Adress = 2120;
  9516. writeToPLC_Flag.Value = (short)4;
  9517. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9518. stopwatch2.Stop();
  9519. }
  9520. stopwatch1.Stop();
  9521. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9522. }
  9523. /// <summary>
  9524. /// [S5] Tray盘下料装备 - AGV上料完成
  9525. /// </summary>
  9526. /// <param name="plcNo">PLC编号</param>
  9527. /// <param name="stationNameStr">工站全称</param>
  9528. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9529. {
  9530. Stopwatch stopwatch1 = new Stopwatch();
  9531. Stopwatch stopwatch2 = new Stopwatch();
  9532. try
  9533. {
  9534. stopwatch1.Start();
  9535. // ZS AGV上料完成,让小车离开
  9536. short e1AGVUpEnd = 2;
  9537. stopwatch2.Start();
  9538. // e1AGVUpEnd
  9539. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9540. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9541. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9542. writeToPLC_Flag.Adress = 2122;
  9543. writeToPLC_Flag.Value = e1AGVUpEnd;
  9544. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9545. stopwatch2.Stop();
  9546. }
  9547. catch (Exception ex)
  9548. {
  9549. string str = ex.StackTrace;
  9550. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9551. // e1AGVUpEnd
  9552. stopwatch2.Start();
  9553. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9554. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9555. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9556. writeToPLC_Flag.Adress = 2122;
  9557. writeToPLC_Flag.Value = (short)4;
  9558. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9559. stopwatch2.Stop();
  9560. }
  9561. stopwatch1.Stop();
  9562. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9563. }
  9564. /// <summary>
  9565. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9566. /// </summary>
  9567. /// <param name="plcNo">PLC编号</param>
  9568. /// <param name="stationNameStr">工站全称</param>
  9569. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9570. {
  9571. Stopwatch stopwatch1 = new Stopwatch();
  9572. Stopwatch stopwatch2 = new Stopwatch();
  9573. try
  9574. {
  9575. stopwatch1.Start();
  9576. // ZS 呼叫AGV
  9577. short e1AGVDownCall = 2;
  9578. stopwatch2.Start();
  9579. // e1AGVDownCall
  9580. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9581. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9582. writeToPLC_Flag.Name = "e1AGVDownCall";
  9583. writeToPLC_Flag.Adress = 2133;
  9584. writeToPLC_Flag.Value = e1AGVDownCall;
  9585. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9586. stopwatch2.Stop();
  9587. }
  9588. catch (Exception ex)
  9589. {
  9590. string str = ex.StackTrace;
  9591. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9592. // e1AGVDownCall
  9593. stopwatch2.Start();
  9594. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9595. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9596. writeToPLC_Flag.Name = "e1AGVDownCall";
  9597. writeToPLC_Flag.Adress = 2133;
  9598. writeToPLC_Flag.Value = (short)4;
  9599. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9600. stopwatch2.Stop();
  9601. }
  9602. stopwatch1.Stop();
  9603. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9604. }
  9605. /// <summary>
  9606. /// [S5] Tray盘下料装备 - AGV下料完成
  9607. /// </summary>
  9608. /// <param name="plcNo">PLC编号</param>
  9609. /// <param name="stationNameStr">工站全称</param>
  9610. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9611. {
  9612. Stopwatch stopwatch1 = new Stopwatch();
  9613. Stopwatch stopwatch2 = new Stopwatch();
  9614. try
  9615. {
  9616. stopwatch1.Start();
  9617. // ZS AGV上料完成,让小车离开
  9618. short e1AGVDownEnd = 2;
  9619. stopwatch2.Start();
  9620. // e1AGVDownEnd
  9621. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9622. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9623. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9624. writeToPLC_Flag.Adress = 2135;
  9625. writeToPLC_Flag.Value = e1AGVDownEnd;
  9626. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9627. stopwatch2.Stop();
  9628. }
  9629. catch (Exception ex)
  9630. {
  9631. string str = ex.StackTrace;
  9632. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9633. // e1AGVDownEnd
  9634. stopwatch2.Start();
  9635. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9636. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9637. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9638. writeToPLC_Flag.Adress = 2135;
  9639. writeToPLC_Flag.Value = (short)4;
  9640. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9641. stopwatch2.Stop();
  9642. }
  9643. stopwatch1.Stop();
  9644. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9645. }
  9646. #endregion [S5] Tray盘下料装备
  9647. #endregion PLC5 张超凡
  9648. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9649. /// <summary>
  9650. /// PLC读取到的数据 -添加数据
  9651. /// </summary>
  9652. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9653. {
  9654. if (sxPlcData.ContainsKey(newKey))
  9655. sxPlcData[newKey] = newValue;
  9656. else
  9657. sxPlcData.Add(newKey, newValue);
  9658. }
  9659. /// <summary>
  9660. /// PLC需要写入的数据 -添加数据
  9661. /// </summary>
  9662. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9663. {
  9664. if (sxPLCWriteData.ContainsKey(newKey))
  9665. sxPLCWriteData[newKey] = newValue;
  9666. else
  9667. sxPLCWriteData.Add(newKey, newValue);
  9668. }
  9669. /// <summary>
  9670. /// PLC回写操作,写后清空flag
  9671. /// </summary>
  9672. /// <param name="modbusClient">modbus对象</param>
  9673. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9674. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9675. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9676. {
  9677. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9678. {
  9679. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9680. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9681. {
  9682. string mesFlagName = pLCWriteDatas[i].Name;
  9683. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9684. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9685. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9686. {
  9687. // 先回写数据
  9688. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9689. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9690. {
  9691. int mesDataAdress = writeToPLCDatas[j].Adress;
  9692. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9693. switch (mesDataType)
  9694. {
  9695. case PLCValueType.Short:
  9696. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9697. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9698. break;
  9699. case PLCValueType.String:
  9700. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9701. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9702. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9703. break;
  9704. }
  9705. }
  9706. // 再回写信号
  9707. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9708. // 存储读取数据的字典
  9709. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9710. // 存储写入数据的字典 - 清空写入值
  9711. pLCWriteDatas[i].Value = (short)0;
  9712. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9713. }
  9714. }
  9715. }
  9716. }
  9717. /// <summary>
  9718. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9719. /// </summary>
  9720. /// <param name="no">3</param>
  9721. /// <param name="stationCode">设备编号</param>
  9722. /// <param name="stationNameStr">设备名称</param>
  9723. /// <param name="plcOrder">车间订单号</param>
  9724. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9725. {
  9726. try
  9727. {
  9728. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9729. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9730. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9731. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9732. int result1 = 0;
  9733. switch (stationCode)
  9734. {
  9735. case 2:
  9736. case 3:
  9737. case 4:
  9738. case 6:
  9739. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9740. break;
  9741. case 102:
  9742. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9743. break;
  9744. case 103:
  9745. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9746. break;
  9747. case 104:
  9748. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9749. break;
  9750. case 106:
  9751. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9752. break;
  9753. default:
  9754. // MES_Flag 为“6未找到正确设备编号”
  9755. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9756. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9757. return;
  9758. }
  9759. short result = result1 == 1 ? (short)1 : (short)2;
  9760. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9761. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9762. }
  9763. catch (Exception ex)
  9764. {
  9765. // MES_Flag 为2上位机报错
  9766. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9767. string str = ex.StackTrace;
  9768. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9769. }
  9770. }
  9771. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9772. #region UI刷新
  9773. /// <summary>
  9774. /// 更新商品信息的UI + 下发产品信息(SN)
  9775. /// </summary>
  9776. private void UpdateProductInfo()
  9777. {
  9778. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9779. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9780. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9781. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9782. }
  9783. /// <summary>
  9784. /// 更新PLC连接状态的UI
  9785. /// </summary>
  9786. /// <param name="no">PLC编号</param>
  9787. /// <param name="status">状态</param>
  9788. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9789. {
  9790. if (this != null && !this.IsDisposed)
  9791. {
  9792. switch (imgNo)
  9793. {
  9794. case 1:
  9795. this.BeginInvoke(new Action(() =>
  9796. {
  9797. picPLC.Image = imageListState.Images[status];
  9798. }));
  9799. break;
  9800. case 2:
  9801. this.BeginInvoke(new Action(() =>
  9802. {
  9803. pictureBox2.Image = imageListState.Images[status];
  9804. }));
  9805. break;
  9806. case 3:
  9807. this.BeginInvoke(new Action(() =>
  9808. {
  9809. pictureBox3.Image = imageListState.Images[status];
  9810. }));
  9811. break;
  9812. case 4:
  9813. this.BeginInvoke(new Action(() =>
  9814. {
  9815. pictureBox4.Image = imageListState.Images[status];
  9816. }));
  9817. break;
  9818. case 5:
  9819. this.BeginInvoke(new Action(() =>
  9820. {
  9821. pictureBox5.Image = imageListState.Images[status];
  9822. }));
  9823. break;
  9824. case 6:
  9825. this.BeginInvoke(new Action(() =>
  9826. {
  9827. pictureBox6.Image = imageListState.Images[status];
  9828. }));
  9829. break;
  9830. case 7:
  9831. this.BeginInvoke(new Action(() =>
  9832. {
  9833. pictureBox7.Image = imageListState.Images[status];
  9834. }));
  9835. break;
  9836. case 8:
  9837. this.BeginInvoke(new Action(() =>
  9838. {
  9839. pictureBox8.Image = imageListState.Images[status];
  9840. }));
  9841. break;
  9842. default:
  9843. break;
  9844. }
  9845. }
  9846. Task.Run(() => // 更新PLC交互页的指示灯
  9847. {
  9848. try
  9849. {
  9850. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9851. {
  9852. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9853. }
  9854. }
  9855. catch { }
  9856. });
  9857. }
  9858. #endregion UI刷新
  9859. #region 日志
  9860. /// <summary>
  9861. /// 添加各工位运行日志(同步至PLC交互页面)
  9862. /// </summary>
  9863. /// <param name="stationNameStr">工站名称</param>
  9864. /// <param name="logType">日志类型</param>
  9865. /// <param name="message">日志内容</param>
  9866. /// <param name="snNumber">产品数字SN</param>
  9867. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9868. {
  9869. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9870. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9871. ))
  9872. {
  9873. AddMessage(logType, message); // 首页展示+日志记录
  9874. }
  9875. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9876. {
  9877. StationName = stationNameStr,
  9878. SnNumber = snNumber,
  9879. Message = message,
  9880. CreateTime = DateTime.Now
  9881. };
  9882. // PLC交互页展示
  9883. Task.Run(() =>
  9884. {
  9885. try
  9886. {
  9887. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9888. {
  9889. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9890. }
  9891. }
  9892. catch { }
  9893. });
  9894. }
  9895. /// <summary>
  9896. /// 添加运行日志
  9897. /// </summary>
  9898. /// <param name="logType">日志类型</param>
  9899. /// <param name="message">日志内容</param>
  9900. public void AddMessage(LogType logType, string message)
  9901. {
  9902. OnMessage(logType, message);
  9903. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9904. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9905. string msgShow = time + "--> " + message + "\r\n";
  9906. this.BeginInvoke(new Action(() =>
  9907. {
  9908. systemLog.Rows.Insert(0, date, time, message);
  9909. if (systemLog.Rows.Count >= 100)
  9910. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9911. }));
  9912. }
  9913. /// <summary>
  9914. /// 添加运行日志-保存
  9915. /// </summary>
  9916. /// <param name="logType">日志类型</param>
  9917. /// <param name="message">日志内容</param>
  9918. private void OnMessage(LogType logType, string msg)
  9919. {
  9920. MessageEvent?.Invoke(logType, msg);
  9921. }
  9922. /// <summary>
  9923. /// 保存PLC写入日志
  9924. /// </summary>
  9925. /// <param name="logType"></param>
  9926. /// <param name="logValue"></param>
  9927. private void WritePLCLog(LogType logType, string logValue)
  9928. {
  9929. switch ((int)logType)
  9930. {
  9931. case 0:
  9932. _PLCLogNet.WriteDebug(logValue);
  9933. break;
  9934. case 1:
  9935. _PLCLogNet.WriteInfo(logValue);
  9936. break;
  9937. case 2:
  9938. _PLCLogNet.WriteWarn(logValue);
  9939. break;
  9940. case 3:
  9941. _PLCLogNet.WriteError(logValue);
  9942. break;
  9943. default:
  9944. _PLCLogNet.WriteFatal(logValue);
  9945. break;
  9946. }
  9947. }
  9948. /// <summary>
  9949. /// IOT Mqtt回调方法- With DataId
  9950. /// </summary>
  9951. /// <param name="id"></param>
  9952. /// <param name="v"></param>
  9953. /// <param name="dataId"></param>
  9954. public void CallbackWithDataId(string id, string msg, string dataId)
  9955. {
  9956. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9957. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9958. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9959. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9960. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9961. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9962. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9963. }
  9964. /// <summary>
  9965. /// AGV Mqtt回调方法- 记录Log并处理数据
  9966. /// </summary>
  9967. /// <param name="obj"></param>
  9968. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9969. {
  9970. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9971. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9972. // 接收到的信息
  9973. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9974. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9975. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9976. {
  9977. }
  9978. }
  9979. #endregion 日志
  9980. /// <summary>
  9981. /// 实例化报警字典
  9982. /// </summary>
  9983. private void InitalDicAlarm()
  9984. {
  9985. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9986. List<Alarm> keyValues1 = new List<Alarm>
  9987. {
  9988. #region 第一组报警(电机)
  9989. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9990. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9991. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9992. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9993. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9994. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9995. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9996. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9997. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9998. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9999. #endregion 第一组报警(电机)
  10000. #region 第二组报警(气缸)
  10001. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  10002. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  10003. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  10004. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  10005. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  10006. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  10007. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  10008. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  10009. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  10010. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  10011. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  10012. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  10013. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  10014. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  10015. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  10016. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  10017. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  10018. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  10019. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  10020. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  10021. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  10022. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  10023. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  10024. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  10025. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  10026. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  10027. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  10028. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  10029. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  10030. #endregion 第二组报警(气缸)
  10031. #region 第三组报警(其他故障)
  10032. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  10033. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  10034. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  10035. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  10036. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  10037. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  10038. #endregion 第三组报警(其他故障)
  10039. };
  10040. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  10041. #endregion 第一个工站(这里使用线体代替工位)
  10042. # region 第二个工站-原来的写法(废弃)
  10043. //keyValues = new Dictionary<int, AlarmData[]>();
  10044. ////1
  10045. //dicAlarmName = new Dictionary<int, Alarm>();
  10046. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  10047. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  10048. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  10049. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  10050. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  10051. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10052. //for (int i = 0; i < dicAlarmName.Count; i++)
  10053. //{
  10054. // alarmDatas[i] = new AlarmData();
  10055. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  10056. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10057. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10058. // alarmDatas[i].AlarmType = 1;
  10059. //}
  10060. //keyValues.Add(1, alarmDatas);
  10061. ////2
  10062. //dicAlarmName = new Dictionary<int, Alarm>();
  10063. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  10064. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  10065. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  10066. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  10067. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  10068. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  10069. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  10070. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  10071. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10072. //for (int i = 0; i < dicAlarmName.Count; i++)
  10073. //{
  10074. // alarmDatas[i] = new AlarmData();
  10075. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  10076. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10077. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10078. // alarmDatas[i].AlarmType = 2;
  10079. //}
  10080. //keyValues.Add(2, alarmDatas);
  10081. ////3
  10082. //dicAlarmName = new Dictionary<int, Alarm>();
  10083. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  10084. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  10085. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  10086. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  10087. //alarmDatas = new AlarmData[dicAlarmName.Count];
  10088. //for (int i = 0; i < dicAlarmName.Count; i++)
  10089. //{
  10090. // alarmDatas[i] = new AlarmData();
  10091. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  10092. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  10093. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  10094. // alarmDatas[i].AlarmType = 3;
  10095. //}
  10096. //keyValues.Add(3, alarmDatas);
  10097. //DicAlarms.Add(2, keyValues);
  10098. #endregion 第二个工站-原来的写法(废弃)
  10099. }
  10100. private void button1_Click(object sender, EventArgs e)
  10101. {
  10102. OpenDailogFalg=true;
  10103. if (OpenDailogFalg)
  10104. {
  10105. using (var dialog = new BandBarodeDialog())
  10106. {
  10107. string strCarrierBarcode = "N801A-003";
  10108. dialog._CarrierBarcode = strCarrierBarcode;
  10109. string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  10110. dialog._ProductBarcode = sn;
  10111. var rs = dialog.ShowDialog();
  10112. if (rs == DialogResult.OK)
  10113. {
  10114. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  10115. OpenDailogFalg = false;//关闭扫码
  10116. }
  10117. }
  10118. }
  10119. }
  10120. }
  10121. }